Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / navigator-detached-no-crash.html
blobdc3895e63cf1e76e6408a3a88dfb8717f28e4080
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script>
6 </head>
7 <body>
8 <iframe id="subframe" src="about:blank"></iframe>
9 <script>
11 var testNavigatorOnLoad = async_test("Accessing a navigator object that just got removed does not crash.")
12 var testNavigatorLater = async_test("Accessing a navigator object that got removed some time before does not crash.")
14 // Reference to the removed navigator object.
15 var oldNav = null;
17 function gc() {
18 if (window.GCController) {
19 GCController.collect();
20 } else {
21 for (var i = 0; i < 10000; i++) {
22 var s = new String("abc");
27 function test() {
28 // Keep a reference of the navigator and remove the frame.
29 oldNav = window.frames[0].navigator;
30 var frame = document.getElementById("subframe");
31 frame.parentNode.removeChild(frame);
33 if (window.GCController)
34 window.GCController.collect();
36 // Check once immediately.
37 testNavigatorOnLoad.step(function() {
38 check_navigator();
39 });
40 testNavigatorOnLoad.done();
42 gc();
44 // Check one more time later, when the frame is likely to be destroyed.
45 setTimeout(function() {
46 testNavigatorLater.step(function() {
47 check_navigator();
48 });
49 testNavigatorLater.done();
50 }, 200);
53 function check_navigator() {
54 for (p in oldNav) {
55 if (typeof oldNav[p] == 'function') {
56 try {
57 var v = oldNav[p]();
58 assert_true(true, "navigator."+p+"() is OK");
59 } catch(err) {
60 // Some function call will asserts, the assert shouldn't make the test fail.
61 assert_true(true, "navigator."+p+"() threw err "+err);
63 } else {
64 var v = oldNav[p];
65 assert_true(true, "navigator."+p+" is OK");
70 window.addEventListener('load', test);
72 </script>
74 </body>
75 </html>