mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Updated the TKUnit class. Added missing http tests.
This commit is contained in:
@@ -89,8 +89,57 @@ export var wait = function(ms)
|
||||
Foundation.NSRunLoop.currentRunLoop().runUntilDate(Foundation.NSDate.dateWithTimeIntervalSinceNow(ms / 1000));
|
||||
}
|
||||
else if (Application.android) {
|
||||
java.lang.Thread.sleep(long(ms));
|
||||
java.lang.Thread.yield();
|
||||
// java.lang.Thread.sleep(long(ms));
|
||||
// java.lang.Thread.yield();
|
||||
// TODO: Not yet fully implemented
|
||||
// doModal();
|
||||
}
|
||||
}
|
||||
|
||||
var doModal = function () {
|
||||
var clsMsgQueue = java.lang.Class.forName("android.os.MessageQueue");
|
||||
var clsMsg = java.lang.Class.forName("android.os.Message");
|
||||
|
||||
var nextMethod: java.lang.reflect.Method;
|
||||
var methods = clsMsgQueue.getDeclaredMethods();
|
||||
var i;
|
||||
for (i = 0; i < methods.length; i++) {
|
||||
if (methods[i].getName() === "next") {
|
||||
nextMethod = methods[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nextMethod.setAccessible(true);
|
||||
|
||||
var targetField;
|
||||
var fields = clsMsg.getDeclaredFields();
|
||||
for (i = 0; i < fields.length; i++) {
|
||||
if (fields[i].getName() === "target") {
|
||||
targetField = fields[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
targetField.setAccessible(true);
|
||||
|
||||
var quitModal = false;
|
||||
var queue = android.os.Looper.myQueue();
|
||||
|
||||
var msg;
|
||||
var obj = new Array(0);
|
||||
while (!quitModal) {
|
||||
msg = nextMethod.invoke(queue, [{}]);
|
||||
if (msg) {
|
||||
var target = targetField.get(msg);
|
||||
if (!target) {
|
||||
// No target is a magic identifier for the quit message.
|
||||
quitModal = true;
|
||||
} else {
|
||||
target.dispatchMessage(msg);
|
||||
}
|
||||
msg.recycle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,77 @@
|
||||
|
||||
import TKUnit = require("Tests/TKUnit");
|
||||
import http = require("http/http");
|
||||
import http_request = require("http/http_request");
|
||||
|
||||
export var test_getString_isDefined = function () {
|
||||
TKUnit.assert(typeof (http.getString) !== "undefined", "Method http.getString() should be defined!");
|
||||
};
|
||||
|
||||
export var test_getString = function () {
|
||||
http.getString("http://httpbin.org/get").then(function (result) {
|
||||
TKUnit.assert(typeof (result) === "string", "Result from getString() should be string!");
|
||||
});
|
||||
};
|
||||
|
||||
export var test_getString_fail = function () {
|
||||
http.getString("hgfttp://httpbin.org/get").fail(function (e) { TKUnit.assert(e instanceof Error, "Result from getString().fail() should be Error!"); });
|
||||
};
|
||||
|
||||
export var test_getJSON_isDefined = function () {
|
||||
TKUnit.assert(typeof (http.getJSON) !== "undefined", "Method http.getJSON() should be defined!");
|
||||
};
|
||||
|
||||
export var test_getJSON = function () {
|
||||
http.getJSON("http://httpbin.org/get").then(function (result) {
|
||||
TKUnit.assert(typeof (JSON.stringify(result)) === "string", "Result from getJSON() should be valid JSON object!");
|
||||
});
|
||||
};
|
||||
|
||||
export var test_getJSON_fail = function () {
|
||||
http.getJSON("hgfttp://httpbin.org/get").fail(function (e) { TKUnit.assert(e instanceof Error, "Result from getJSON().fail() should be Error!"); });
|
||||
};
|
||||
|
||||
export var test_getImage_isDefined = function () {
|
||||
TKUnit.assert(typeof (http.getImage) !== "undefined", "Method http.getImage() should be defined!");
|
||||
};
|
||||
|
||||
export var test_getImage = function () {
|
||||
http.getImage("http://www.google.com/images/errors/logo_sm_2.png").then(function (result) {
|
||||
TKUnit.assert(result instanceof require("Image").Image, "Result from getImage() should be valid Image object!");
|
||||
});
|
||||
};
|
||||
|
||||
export var test_getImage_fail = function () {
|
||||
http.getImage("htadvtp://www.google.com/images/errors/logo_sm_2.png").fail(function (e) {
|
||||
TKUnit.assert(e instanceof Error, "Result from getImage().fail() should be Error!");
|
||||
});
|
||||
};
|
||||
|
||||
export var test_request_isDefined = function () {
|
||||
TKUnit.assert(typeof (http["request"]) !== "undefined", "Method http.request() should be defined!");
|
||||
};
|
||||
|
||||
export var test_request_shouldFailIfOptionsUrlIsNotDefined = function () {
|
||||
http_request.request({ url: undefined, method: undefined }).fail(function (e) { TKUnit.assert(e instanceof Error, "Result from request().fail() should be Error!"); });
|
||||
};
|
||||
|
||||
export var test_request_shouldFailIfOptionsMethodIsNotDefined = function () {
|
||||
http_request.request({ url: "http://httpbin.org/get", method: undefined }).fail(function (e) { TKUnit.assert(e instanceof Error, "Result from request().fail() should be Error!"); });
|
||||
};
|
||||
|
||||
export var test_request_responseStatusCodeShouldBeDefined = function () {
|
||||
http_request.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
|
||||
TKUnit.assert(typeof (response.statusCode) !== "undefined", "response.statusCode should be defined!");
|
||||
});
|
||||
};
|
||||
|
||||
export var test_request_responseHeadersCodeShouldBeDefined = function () {
|
||||
http_request.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
|
||||
TKUnit.assert(typeof (response.headers) !== "undefined", "response.headers should be defined!");
|
||||
});
|
||||
};
|
||||
|
||||
export var test_request_responseContentShouldBeDefined = function () {
|
||||
http_request.request({ url: "http://httpbin.org/get", method: "GET" }).then(function (response) {
|
||||
TKUnit.assert(typeof (response.content) !== "undefined", "response.content should be defined!");
|
||||
});
|
||||
};
|
||||
@@ -25,7 +25,7 @@ export function request(options: http.HttpRequestOptions): promises.Promise<http
|
||||
raw: data,
|
||||
toString: () => { return null },
|
||||
toJSON: () => { return null },
|
||||
toImage: () => { return require("Image/image").Image.imageFromNativeBitmap(data); }
|
||||
toImage: () => { return require("Image/image").fromNativeBitmap(data); }
|
||||
},
|
||||
statusCode: 0,
|
||||
headers: {}
|
||||
|
||||
Reference in New Issue
Block a user