2008-11-04 Anders Carlsson <andersca@apple.com>
[webkit/qt.git] / LayoutTests / fast / dom / resources / constructors-cached-navigate.js
blob0826bdd69b1f501fd5813c337fc4fd9a851225ad
1 if (window.layoutTestController)
2     layoutTestController.waitUntilDone();
4 var constructors = ["Image", "MessageChannel", "Option", "XMLHttpRequest", "Audio"];
6 window.onload = function () {
7     testFrame = document.getElementById("testFrame");
8     storedConstructors = [];
9     // Identity checks
10     for (var i = 0; i < constructors.length; i++) {
11         var constructor = constructors[i];
12         try {
13             shouldBe("testFrame.contentWindow." + constructor, "testFrame.contentWindow."+constructor);
14             shouldBeTrue("testFrame.contentWindow." + constructor + " !== window." + constructor);
15             testFrame.contentWindow[constructor].testProperty = "property set successfully";
16             shouldBe("testFrame.contentWindow." + constructor + ".testProperty", '"property set successfully"');
17             storedConstructors[constructor] = testFrame.contentWindow[constructor];
18         } catch (e) {
19             testFailed("Testing " + constructor + " threw " + e);
20         }
21     }
22     testFrame.onload = function() {
23         if (window.GCController)
24             GCController.collect();
26         // Test properties after load
27         for (var i = 0; i < constructors.length; i++) {
28             var constructor = constructors[i];
29             try {
30                 // Repeat the identity checks to be safe
31                 shouldBe("testFrame.contentWindow." + constructor, "testFrame.contentWindow."+constructor);
32                 shouldBeTrue("testFrame.contentWindow." + constructor + " !== window." + constructor);
33                 
34                 // Make sure that we haven't reused the constructors from the old document
35                 shouldBeTrue("testFrame.contentWindow." + constructor + " !== storedConstructors." + constructor);
36                 shouldBe("storedConstructors." + constructor + ".testProperty", '"property set successfully"');
38                 // Make sure we haven't kept anything over from the original document
39                 shouldBeUndefined("testFrame.contentWindow." + constructor + ".testProperty");
40                 // Make sure we're getting the same constructor as the frame does internally
41                 shouldBeTrue("testFrame.contentWindow." + constructor + ".cachedOnOwnerDocument");
42             } catch (e) {
43                 testFailed("Testing " + constructor + " threw " + e);
44             }
45         }
46         
47         if (window.layoutTestController)
48             layoutTestController.notifyDone();
49     };
50     testFrame.src = 'data:text/html,<script>var constructors = ["Image", "MessageChannel", "Option", "XMLHttpRequest", "Audio"];'
51                   + 'for(var i = 0; i < constructors.length; i++) if(window[constructors[i]])'
52                   + 'window[constructors[i]].cachedOnOwnerDocument = true;</script>';
55 successfullyParsed = true;