mirror of https://github.com/axmolengine/axmol.git
Avoids function name conflict, and uses `http://httpbin.org/gzip` to test gzip functionality since only httpbin.org was added to exception list in Info.plist. (#16933)
This commit is contained in:
parent
636a253981
commit
f26cc15373
|
@ -24,34 +24,6 @@
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
//some utils functions
|
|
||||||
function ensureLeftAligned (label) {
|
|
||||||
label.anchorX = 0;
|
|
||||||
label.anchorY = 1;
|
|
||||||
label.textAlign = cc.TEXT_ALIGNMENT_LEFT;
|
|
||||||
}
|
|
||||||
|
|
||||||
function streamXHREventsToLabel ( xhr, label, textbox, method ) {
|
|
||||||
// Simple events
|
|
||||||
['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'].forEach(function (eventname) {
|
|
||||||
xhr["on" + eventname] = function () {
|
|
||||||
label.string += "\nEvent : " + eventname
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Special event
|
|
||||||
xhr.onreadystatechange = function () {
|
|
||||||
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
|
|
||||||
var httpStatus = xhr.statusText;
|
|
||||||
var response = xhr.responseText.substring(0, 100) + "...";
|
|
||||||
textbox.string = method + " Response (100 chars):\n"
|
|
||||||
textbox.string += response
|
|
||||||
label.string += "\nStatus: Got " + method + " response! " + httpStatus
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var XHRArrayBufferTestScene = TestScene.extend({
|
var XHRArrayBufferTestScene = TestScene.extend({
|
||||||
ctor:function () {
|
ctor:function () {
|
||||||
this._super(true);
|
this._super(true);
|
||||||
|
@ -81,24 +53,52 @@ var XHRArrayBufferTestLayer = cc.Layer.extend({
|
||||||
this.sendPostArrayBuffer();
|
this.sendPostArrayBuffer();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
//some utils functions
|
||||||
|
ensureLeftAligned: function(label) {
|
||||||
|
label.anchorX = 0;
|
||||||
|
label.anchorY = 1;
|
||||||
|
label.textAlign = cc.TEXT_ALIGNMENT_LEFT;
|
||||||
|
},
|
||||||
|
|
||||||
|
streamXHREventsToLabel: function( xhr, label, textbox, method, title ) {
|
||||||
|
// Simple events
|
||||||
|
['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'].forEach(function (eventname) {
|
||||||
|
xhr["on" + eventname] = function () {
|
||||||
|
label.string += "\nEvent : " + eventname;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Special event
|
||||||
|
xhr.onreadystatechange = function () {
|
||||||
|
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
|
||||||
|
var httpStatus = xhr.statusText;
|
||||||
|
var response = xhr.responseText.substring(0, 100) + "...";
|
||||||
|
cc.log("title:" + title + ", response:\n" + xhr.responseText);
|
||||||
|
textbox.string = method + " Response (100 chars):\n";
|
||||||
|
textbox.string += response;
|
||||||
|
label.string += "\nStatus: Got " + method + " response! " + httpStatus;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
sendPostArrayBuffer: function() {
|
sendPostArrayBuffer: function() {
|
||||||
var statusPostLabel = new cc.LabelTTF("Status:", "Thonburi", 12);
|
var statusPostLabel = new cc.LabelTTF("Status:", "Thonburi", 12);
|
||||||
this.addChild(statusPostLabel, 1);
|
this.addChild(statusPostLabel, 1);
|
||||||
|
|
||||||
statusPostLabel.x = 10;
|
statusPostLabel.x = 10;
|
||||||
statusPostLabel.y = winSize.height - 100;
|
statusPostLabel.y = winSize.height - 100;
|
||||||
ensureLeftAligned(statusPostLabel);
|
this.ensureLeftAligned(statusPostLabel);
|
||||||
statusPostLabel.setString("Status: Send Post Request to httpbin.org with ArrayBuffer");
|
statusPostLabel.setString("Status: Send Post Request to httpbin.org with ArrayBuffer");
|
||||||
|
|
||||||
|
|
||||||
var responseLabel = new cc.LabelTTF("", "Thonburi", 16);
|
var responseLabel = new cc.LabelTTF("", "Thonburi", 16);
|
||||||
this.addChild(responseLabel, 1);
|
this.addChild(responseLabel, 1);
|
||||||
ensureLeftAligned(responseLabel);
|
this.ensureLeftAligned(responseLabel);
|
||||||
responseLabel.x = 10;
|
responseLabel.x = 10;
|
||||||
responseLabel.y = winSize.height / 2;
|
responseLabel.y = winSize.height / 2;
|
||||||
|
|
||||||
var xhr = cc.loader.getXMLHttpRequest();
|
var xhr = cc.loader.getXMLHttpRequest();
|
||||||
streamXHREventsToLabel(xhr, statusPostLabel, responseLabel, "POST");
|
this.streamXHREventsToLabel(xhr, statusPostLabel, responseLabel, "POST", "sendPostArrayBuffer");
|
||||||
|
|
||||||
xhr.open("POST", "http://httpbin.org/post");
|
xhr.open("POST", "http://httpbin.org/post");
|
||||||
//set Content-type "text/plain" to post ArrayBuffer or ArrayBufferView
|
//set Content-type "text/plain" to post ArrayBuffer or ArrayBufferView
|
||||||
|
|
|
@ -24,34 +24,6 @@
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
//some utils functions
|
|
||||||
function ensureLeftAligned (label) {
|
|
||||||
label.anchorX = 0;
|
|
||||||
label.anchorY = 1;
|
|
||||||
label.textAlign = cc.TEXT_ALIGNMENT_LEFT;
|
|
||||||
}
|
|
||||||
|
|
||||||
function streamXHREventsToLabel ( xhr, label, textbox, method ) {
|
|
||||||
// Simple events
|
|
||||||
['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'].forEach(function (eventname) {
|
|
||||||
xhr["on" + eventname] = function () {
|
|
||||||
label.string += "\nEvent : " + eventname;
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// Special event
|
|
||||||
xhr.onreadystatechange = function () {
|
|
||||||
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
|
|
||||||
var httpStatus = xhr.statusText;
|
|
||||||
var response = xhr.responseText.substring(0, 100) + "...";
|
|
||||||
textbox.string = method + " Response (100 chars):\n";
|
|
||||||
textbox.string += response;
|
|
||||||
label.string += "\nStatus: Got " + method + " response! " + httpStatus;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var XHRTestScene = TestScene.extend({
|
var XHRTestScene = TestScene.extend({
|
||||||
ctor:function () {
|
ctor:function () {
|
||||||
this._super(true);
|
this._super(true);
|
||||||
|
@ -83,33 +55,56 @@ var XHRTestLayer = cc.Layer.extend({
|
||||||
this.sendPostForms();
|
this.sendPostForms();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ensureLeftAligned: function(label) {
|
||||||
|
label.anchorX = 0;
|
||||||
|
label.anchorY = 1;
|
||||||
|
label.textAlign = cc.TEXT_ALIGNMENT_LEFT;
|
||||||
|
},
|
||||||
|
|
||||||
|
streamXHREventsToLabel: function( xhr, label, textbox, method, title ) {
|
||||||
|
// Simple events
|
||||||
|
['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'].forEach(function (eventname) {
|
||||||
|
xhr["on" + eventname] = function () {
|
||||||
|
label.string += "\nEvent : " + eventname;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Special event
|
||||||
|
xhr.onreadystatechange = function () {
|
||||||
|
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
|
||||||
|
var httpStatus = xhr.statusText;
|
||||||
|
var response = xhr.responseText.substring(0, 100) + "...";
|
||||||
|
cc.log("title:" + title + ", response:\n" + xhr.responseText);
|
||||||
|
textbox.string = method + " Response (100 chars):\n";
|
||||||
|
textbox.string += response;
|
||||||
|
label.string += "\nStatus: Got " + method + " response! " + httpStatus;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
sendGetRequest: function() {
|
sendGetRequest: function() {
|
||||||
var statusGetLabel = new cc.LabelTTF("Status:", "Thonburi", 12);
|
var statusGetLabel = new cc.LabelTTF("Status:", "Thonburi", 12);
|
||||||
this.addChild(statusGetLabel, 1);
|
this.addChild(statusGetLabel, 1);
|
||||||
|
|
||||||
statusGetLabel.x = 10;
|
statusGetLabel.x = 10;
|
||||||
statusGetLabel.y = winSize.height - 100;
|
statusGetLabel.y = winSize.height - 100;
|
||||||
ensureLeftAligned(statusGetLabel);
|
this.ensureLeftAligned(statusGetLabel);
|
||||||
statusGetLabel.setString("Status: Send Get Request to httpbin.org");
|
statusGetLabel.setString("Status: Send Get Request to httpbin.org");
|
||||||
|
|
||||||
var responseLabel = new cc.LabelTTF("", "Thonburi", 16);
|
var responseLabel = new cc.LabelTTF("", "Thonburi", 16);
|
||||||
this.addChild(responseLabel, 1);
|
this.addChild(responseLabel, 1);
|
||||||
|
|
||||||
ensureLeftAligned(responseLabel);
|
this.ensureLeftAligned(responseLabel);
|
||||||
responseLabel.x = 10;
|
responseLabel.x = 10;
|
||||||
responseLabel.y = winSize.height / 2;
|
responseLabel.y = winSize.height / 2;
|
||||||
|
|
||||||
var xhr = cc.loader.getXMLHttpRequest();
|
var xhr = cc.loader.getXMLHttpRequest();
|
||||||
streamXHREventsToLabel(xhr, statusGetLabel, responseLabel, "GET");
|
this.streamXHREventsToLabel(xhr, statusGetLabel, responseLabel, "GET", "sendGetRequest");
|
||||||
// 5 seconds for timeout
|
// 5 seconds for timeout
|
||||||
xhr.timeout = 5000;
|
xhr.timeout = 5000;
|
||||||
|
|
||||||
//set arguments with <URL>?xxx=xxx&yyy=yyy
|
//set arguments with <URL>?xxx=xxx&yyy=yyy
|
||||||
if(cc.sys.isNative){
|
xhr.open("GET", "http://httpbin.org/gzip", true);
|
||||||
xhr.open("GET", "http://geek.csdn.net/news/detail/33683", true);
|
|
||||||
}else{
|
|
||||||
xhr.open("GET", "http://httpbin.org/get?show_env=1", true);
|
|
||||||
}
|
|
||||||
xhr.setRequestHeader("Accept-Encoding","gzip,deflate");
|
xhr.setRequestHeader("Accept-Encoding","gzip,deflate");
|
||||||
|
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
@ -121,18 +116,18 @@ var XHRTestLayer = cc.Layer.extend({
|
||||||
|
|
||||||
statusPostLabel.x = winSize.width / 10 * 3;
|
statusPostLabel.x = winSize.width / 10 * 3;
|
||||||
statusPostLabel.y = winSize.height - 100;
|
statusPostLabel.y = winSize.height - 100;
|
||||||
ensureLeftAligned(statusPostLabel);
|
this.ensureLeftAligned(statusPostLabel);
|
||||||
statusPostLabel.setString("Status: Send Post Request to httpbin.org with plain text");
|
statusPostLabel.setString("Status: Send Post Request to httpbin.org with plain text");
|
||||||
|
|
||||||
|
|
||||||
var responseLabel = new cc.LabelTTF("", "Thonburi", 16);
|
var responseLabel = new cc.LabelTTF("", "Thonburi", 16);
|
||||||
this.addChild(responseLabel, 1);
|
this.addChild(responseLabel, 1);
|
||||||
ensureLeftAligned(responseLabel);
|
this.ensureLeftAligned(responseLabel);
|
||||||
responseLabel.x = winSize.width / 10 * 3;
|
responseLabel.x = winSize.width / 10 * 3;
|
||||||
responseLabel.y = winSize.height / 2;
|
responseLabel.y = winSize.height / 2;
|
||||||
|
|
||||||
var xhr = cc.loader.getXMLHttpRequest();
|
var xhr = cc.loader.getXMLHttpRequest();
|
||||||
streamXHREventsToLabel(xhr, statusPostLabel, responseLabel, "POST");
|
this.streamXHREventsToLabel(xhr, statusPostLabel, responseLabel, "POST", "sendPostPlainText");
|
||||||
|
|
||||||
xhr.open("POST", "http://httpbin.org/post");
|
xhr.open("POST", "http://httpbin.org/post");
|
||||||
|
|
||||||
|
@ -147,18 +142,18 @@ var XHRTestLayer = cc.Layer.extend({
|
||||||
|
|
||||||
statusPostLabel.x = winSize.width / 10 * 7;
|
statusPostLabel.x = winSize.width / 10 * 7;
|
||||||
statusPostLabel.y = winSize.height - 100;
|
statusPostLabel.y = winSize.height - 100;
|
||||||
ensureLeftAligned(statusPostLabel);
|
this.ensureLeftAligned(statusPostLabel);
|
||||||
statusPostLabel.setString("Status: Send Post Request to httpbin.org width form data");
|
statusPostLabel.setString("Status: Send Post Request to httpbin.org width form data");
|
||||||
|
|
||||||
var responseLabel = new cc.LabelTTF("", "Thonburi", 16);
|
var responseLabel = new cc.LabelTTF("", "Thonburi", 16);
|
||||||
this.addChild(responseLabel, 1);
|
this.addChild(responseLabel, 1);
|
||||||
|
|
||||||
ensureLeftAligned(responseLabel);
|
this.ensureLeftAligned(responseLabel);
|
||||||
responseLabel.x = winSize.width / 10 * 7;
|
responseLabel.x = winSize.width / 10 * 7;
|
||||||
responseLabel.y = winSize.height / 2;
|
responseLabel.y = winSize.height / 2;
|
||||||
|
|
||||||
var xhr = cc.loader.getXMLHttpRequest();
|
var xhr = cc.loader.getXMLHttpRequest();
|
||||||
streamXHREventsToLabel(xhr, statusPostLabel, responseLabel, "POST");
|
this.streamXHREventsToLabel(xhr, statusPostLabel, responseLabel, "POST", "sendPostForms");
|
||||||
|
|
||||||
xhr.open("POST", "http://httpbin.org/post");
|
xhr.open("POST", "http://httpbin.org/post");
|
||||||
//set Content-Type "application/x-www-form-urlencoded" to post form data
|
//set Content-Type "application/x-www-form-urlencoded" to post form data
|
||||||
|
@ -185,4 +180,4 @@ var runXHRTest = function () {
|
||||||
var pLayer = new XHRTestLayer();
|
var pLayer = new XHRTestLayer();
|
||||||
pScene.addChild(pLayer);
|
pScene.addChild(pLayer);
|
||||||
cc.director.runScene(pScene);
|
cc.director.runScene(pScene);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue