mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Merged master onto feature/docs
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import TKUnit = require("./TKUnit");
|
||||
import platform = require("platform");
|
||||
var timer = require("timer/timer");
|
||||
import timer = require("timer");
|
||||
|
||||
// >> timer-require
|
||||
// require("globals");
|
||||
@@ -8,122 +7,108 @@ var timer = require("timer/timer");
|
||||
// var timer = require("timer");
|
||||
// << timer-require
|
||||
|
||||
export var test_setTimeout_isDefined = function () {
|
||||
export function test_setTimeout_isDefined() {
|
||||
TKUnit.assert(typeof (timer.setTimeout) !== "undefined", "Method timer.setTimeout() should be defined!");
|
||||
};
|
||||
|
||||
export var test_clearTimeout_isDefined = function () {
|
||||
export function test_clearTimeout_isDefined() {
|
||||
TKUnit.assert(typeof (timer.clearTimeout) !== "undefined", "Method timer.clearTimeout() should be defined!");
|
||||
};
|
||||
|
||||
export var test_setInterval_isDefined = function () {
|
||||
export function test_setInterval_isDefined() {
|
||||
TKUnit.assert(typeof (timer.setInterval) !== "undefined", "Method timer.setInterval() should be defined!");
|
||||
};
|
||||
|
||||
export var test_clearInterval_isDefined = function () {
|
||||
export function test_clearInterval_isDefined() {
|
||||
TKUnit.assert(typeof (timer.clearInterval) !== "undefined", "Method timer.clearInterval() should be defined!");
|
||||
};
|
||||
|
||||
export var test_setTimeout = function () {
|
||||
var completed: boolean;
|
||||
var isReady = function () { return completed; }
|
||||
export function test_setTimeout() {
|
||||
let completed: boolean;
|
||||
|
||||
// >> timer-set-zero
|
||||
timer.setTimeout(function () {
|
||||
timer.setTimeout(() => {
|
||||
// >> (hide)
|
||||
completed = true;
|
||||
// << (hide)
|
||||
});
|
||||
// << timer-set-zero
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 0.5);
|
||||
TKUnit.waitUntilReady(() => completed, 0.5);
|
||||
TKUnit.assert(completed, "Callback should be called!");
|
||||
};
|
||||
|
||||
export var test_setTimeout_callbackCalledAfterSpecifiedTime = function () {
|
||||
var completed: boolean;
|
||||
var isReady = function () { return completed; }
|
||||
export function test_setTimeout_callbackCalledAfterSpecifiedTime() {
|
||||
let completed = false;
|
||||
|
||||
// >> timer-set-fivehundred
|
||||
timer.setTimeout(function () {
|
||||
timer.setTimeout(() => {
|
||||
// >> (hide)
|
||||
completed = true;
|
||||
// << (hide)
|
||||
}, 500);
|
||||
}, 10);
|
||||
// << timer-set-fivehundred
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 1);
|
||||
TKUnit.waitUntilReady(() => completed, 1);
|
||||
TKUnit.assert(completed, "Callback should be called after specified time!");
|
||||
};
|
||||
|
||||
export var test_setTimeout_callbackNotCalled = function () {
|
||||
var completed: boolean;
|
||||
var isReady = function () { return completed; }
|
||||
export function test_setTimeout_callbackNotCalled() {
|
||||
let completed = false;
|
||||
timer.setTimeout(() => completed = true, 50);
|
||||
|
||||
timer.setTimeout(function () {
|
||||
completed = true;
|
||||
}, 1000);
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 0.5);
|
||||
TKUnit.waitUntilReady(() => completed, 0.01);
|
||||
TKUnit.assert(!completed, "Callback should be called after specified time!");
|
||||
};
|
||||
|
||||
export var test_setTimeout_shouldReturnNumber = function () {
|
||||
var id = timer.setTimeout(function () {
|
||||
export function test_setTimeout_shouldReturnNumber() {
|
||||
let id = timer.setTimeout(() => {
|
||||
//
|
||||
});
|
||||
TKUnit.assert(typeof id === "number", "Callback should return number!");
|
||||
};
|
||||
|
||||
export var test_setTimeout_callbackShouldBeCleared = function () {
|
||||
// This test is very unstable in iOS, because the platform does not guarantee the
|
||||
// callback will be cleared on time. Better skip it for iOS.
|
||||
if (platform.device.os === platform.platformNames.ios) {
|
||||
return;
|
||||
}
|
||||
|
||||
var completed: boolean;
|
||||
var isReady = function () { return completed; }
|
||||
export function test_setTimeout_callbackShouldBeCleared() {
|
||||
let completed = false;
|
||||
|
||||
// >> timer-set-twothousands
|
||||
var id = timer.setTimeout(function () {
|
||||
let id = timer.setTimeout(() => {
|
||||
// >> (hide)
|
||||
completed = true;
|
||||
// << (hide)
|
||||
}, 2000);
|
||||
}, 50);
|
||||
// << timer-set-twothousands
|
||||
|
||||
//// Clear timeout with specified id.
|
||||
timer.clearTimeout(id);
|
||||
|
||||
// << timer-set-twothousands
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 3);
|
||||
TKUnit.waitUntilReady(() => completed, 0.060);
|
||||
TKUnit.assert(!completed, "Callback should be cleared when clearTimeout() is executed for specified id!");
|
||||
};
|
||||
|
||||
export var test_setInterval_callbackCalledDuringPeriod = function () {
|
||||
var counter = 0;
|
||||
var expected = 4;
|
||||
var isReady = function () { return counter >= expected; }
|
||||
export function test_setInterval_callbackCalledDuringPeriod() {
|
||||
let counter = 0;
|
||||
let expected = 4;
|
||||
|
||||
// >> timer-set-expression
|
||||
timer.setInterval(function () {
|
||||
timer.setInterval(() => {
|
||||
// >> (hide)
|
||||
counter++;
|
||||
// << (hide)
|
||||
}, 100);
|
||||
// << timer-set-expression
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 0.5);
|
||||
TKUnit.assert(isReady(), "Callback should be raised at least" + expected + "times! Callback raised " + counter + " times.");
|
||||
TKUnit.waitUntilReady(() => counter >= expected, 0.5);
|
||||
TKUnit.assert(counter >= expected, "Callback should be raised at least" + expected + "times! Callback raised " + counter + " times.");
|
||||
};
|
||||
|
||||
export var test_setInterval_callbackShouldBeCleared = function () {
|
||||
var counter = 0;
|
||||
var isReady = function () { return false; }
|
||||
export function test_setInterval_callbackShouldBeCleared() {
|
||||
let counter = 0;
|
||||
|
||||
// >> timer-set-interval
|
||||
var id = timer.setInterval(function () {
|
||||
let id = timer.setInterval(() => {
|
||||
// >> (hide)
|
||||
counter++;
|
||||
// << (hide)
|
||||
@@ -131,6 +116,6 @@ export var test_setInterval_callbackShouldBeCleared = function () {
|
||||
}, 100);
|
||||
// << timer-set-interval
|
||||
|
||||
TKUnit.waitUntilReady(isReady, 0.5);
|
||||
TKUnit.waitUntilReady(() => false, 0.5);
|
||||
TKUnit.assert(counter === 1, "Callback should be raised only once!");
|
||||
};
|
||||
Reference in New Issue
Block a user