Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / resources / js-test.js
index d244de9..87433c2 100644 (file)
@@ -6,6 +6,8 @@ if (self.testRunner) {
         testRunner.dumpAsText();
 }
 
+var isJsTest = true;
+
 var description, debug, successfullyParsed;
 
 var expectingError; // set by shouldHaveError()
@@ -206,7 +208,7 @@ function evalAndLog(_a, _quiet)
   return _av;
 }
 
-function shouldBe(_a, _b, quiet)
+function shouldBe(_a, _b, quiet, opt_tolerance)
 {
   if (typeof _a != "string" || typeof _b != "string")
     debug("WARN: shouldBe() expects string arguments");
@@ -221,7 +223,7 @@ function shouldBe(_a, _b, quiet)
 
   if (_exception)
     testFailed(_a + " should be " + _bv + ". Threw exception " + _exception);
-  else if (isResultCorrect(_av, _bv)) {
+  else if (isResultCorrect(_av, _bv) || (typeof opt_tolerance == 'number' && typeof _av == 'number' && Math.abs(_av - _bv) <= opt_tolerance)) {
     if (!quiet) {
         testPassed(_a + " is " + _b);
     }
@@ -423,7 +425,7 @@ function shouldBeEqualToNumber(a, b)
 
 function shouldBeEmptyString(a) { shouldBeEqualToString(a, ""); }
 
-function shouldEvaluateTo(actual, expected) {
+function shouldEvaluateTo(actual, expected, opt_tolerance) {
   // A general-purpose comparator.  'actual' should be a string to be
   // evaluated, as for shouldBe(). 'expected' may be any type and will be
   // used without being eval'ed.
@@ -445,7 +447,7 @@ function shouldEvaluateTo(actual, expected) {
   } else if (typeof expected == "object") {
     shouldBeTrue(actual + " == '" + expected + "'");
   } else if (typeof expected == "string") {
-    shouldBe(actual, expected);
+    shouldBe(actual, expected, undefined, opt_tolerance);
   } else if (typeof expected == "boolean") {
     shouldBe("typeof " + actual, "'boolean'");
     if (expected)
@@ -453,7 +455,10 @@ function shouldEvaluateTo(actual, expected) {
     else
       shouldBeFalse(actual);
   } else if (typeof expected == "number") {
-    shouldBe(actual, stringify(expected));
+    if (opt_tolerance)
+        shouldBeCloseTo(actual, expected, opt_tolerance);
+    else
+        shouldBe(actual, stringify(expected));
   } else {
     debug(expected + " is unknown type " + typeof expected);
     shouldBeTrue(actual, "'"  +expected.toString() + "'");
@@ -686,7 +691,8 @@ function shouldHaveHadError(message)
 // function.
 function asyncGC(callback) {
     GCController.collectAll();
-    setTimeout(callback, 0);
+    // FIXME: we need a better way of waiting for chromium events to happen
+    setTimeout(callback, 1);
 }
 
 function gc() {
@@ -710,7 +716,8 @@ function asyncMinorGC(callback) {
         GCController.minorCollect();
     else
         testFailed("Minor GC is available only when you enable the --expose-gc option in V8.");
-    setTimeout(callback, 0);
+    // FIXME: we need a better way of waiting for chromium events to happen
+    setTimeout(callback, 1);
 }
 
 function isSuccessfullyParsed()
@@ -721,6 +728,8 @@ function isSuccessfullyParsed()
     debug('<br /><span class="pass">TEST COMPLETE</span>');
 }
 
+var wasPostTestScriptParsed, wasFinishJSTestCalled, jsTestIsAsync;
+
 // It's possible for an async test to call finishJSTest() before js-test-post.js
 // has been parsed.
 function finishJSTest()