Index: LayoutTests/fast/dom/navigator-detached-no-crash.html |
diff --git a/LayoutTests/fast/dom/navigator-detached-no-crash.html b/LayoutTests/fast/dom/navigator-detached-no-crash.html |
index 11746724ef1c4003a3650c43a0c1ec5578b9e760..dc3895e63cf1e76e6408a3a88dfb8717f28e4080 100644 |
--- a/LayoutTests/fast/dom/navigator-detached-no-crash.html |
+++ b/LayoutTests/fast/dom/navigator-detached-no-crash.html |
@@ -1,86 +1,75 @@ |
+<!DOCTYPE html> |
<html> |
+<head> |
+<script src="../../resources/testharness.js"></script> |
+<script src="../../resources/testharnessreport.js"></script> |
+</head> |
+<body> |
+ <iframe id="subframe" src="about:blank"></iframe> |
<script> |
-if (window.testRunner) { |
- testRunner.dumpAsText(); |
- testRunner.waitUntilDone(); |
-} |
-function log(strings) { |
- var node = document.getElementById('result'); |
- for (var i in strings) { |
- node.innerHTML += strings[i] + '<br>'; |
- } |
-} |
+var testNavigatorOnLoad = async_test("Accessing a navigator object that just got removed does not crash.") |
+var testNavigatorLater = async_test("Accessing a navigator object that got removed some time before does not crash.") |
-function gc() |
-{ |
- if (window.GCController) { |
- GCController.collect(); |
- } else { |
- for (var i = 0; i < 10000; i++) { |
- var s = new String("abc"); |
- } |
+// Reference to the removed navigator object. |
+var oldNav = null; |
+ |
+function gc() { |
+ if (window.GCController) { |
+ GCController.collect(); |
+ } else { |
+ for (var i = 0; i < 10000; i++) { |
+ var s = new String("abc"); |
} |
+ } |
} |
-var old_nav; |
- |
function test() { |
- // remember the old navigator |
- old_nav = window.frames[0].navigator; |
- // detach the old navigator |
- var p = document.getElementById("subframe"); |
- p.parentNode.removeChild(p); |
+ // Keep a reference of the navigator and remove the frame. |
+ oldNav = window.frames[0].navigator; |
+ var frame = document.getElementById("subframe"); |
+ frame.parentNode.removeChild(frame); |
+ |
if (window.GCController) |
window.GCController.collect(); |
- // Check once immediately |
- check_navigator(); |
+ // Check once immediately. |
+ testNavigatorOnLoad.step(function() { |
+ check_navigator(); |
+ }); |
+ testNavigatorOnLoad.done(); |
gc(); |
// Check one more time later, when the frame is likely to be destroyed. |
- setTimeout(check_navigator_and_done, 200); |
-} |
- |
-function check_navigator_and_done() { |
- check_navigator(); |
- if (window.testRunner) |
- testRunner.notifyDone(); |
+ setTimeout(function() { |
+ testNavigatorLater.step(function() { |
+ check_navigator(); |
+ }); |
+ testNavigatorLater.done(); |
+ }, 200); |
eseidel
2014/06/02 18:23:16
Bleh! setTimeout tests = flaky tests. :(
mlamouri (slow - plz ping)
2014/06/02 18:36:09
I entirely agree but I prefer to not change the be
|
} |
function check_navigator() { |
- var strings = [ ]; |
- for (p in old_nav) { |
- if (p == 'geolocation' || p == 'webkitGetUserMedia') // Don't include Geolocation or the Media Stream API functions until most platforms have support. |
- continue; |
- |
- if (typeof old_nav[p] == 'function') { |
+ for (p in oldNav) { |
+ if (typeof oldNav[p] == 'function') { |
try { |
- var v = old_nav[p](); |
- // no crash, it is ok |
- strings.push("navigator."+p+"() is OK"); |
+ var v = oldNav[p](); |
+ assert_true(true, "navigator."+p+"() is OK"); |
} catch(err) { |
- // navigator.registerXXX will throw on invalid input. |
- strings.push("navigator."+p+"() threw err "+err); |
+ // Some function call will asserts, the assert shouldn't make the test fail. |
+ assert_true(true, "navigator."+p+"() threw err "+err); |
} |
} else { |
- var v = old_nav[p]; |
- // no crash, it is ok. |
- strings.push("navigator."+p+" is OK"); |
+ var v = oldNav[p]; |
+ assert_true(true, "navigator."+p+" is OK"); |
} |
} |
- strings.sort(); |
- log(strings); |
} |
+window.addEventListener('load', test); |
+ |
</script> |
-<body onload="test()"> |
-This tests that the navigator object of a deleted frame is disconnected |
-properly. Accessing fields or methods shouldn't crash the browser. |
-<br> |
-<iframe id="subframe" src="about:blank"></iframe> |
-<button onclick="check_navigator()">Check Navigator</button><br> |
-<div id="result"></div> |
+ |
</body> |
</html> |