OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Name look-up tests of Window interface</title> |
| 3 <!-- TODO(yukishiino): Change the name look-up behavior of Window and fix all th
ese tests. --> |
| 4 <script src="../../../resources/testharness.js"></script> |
| 5 <script src="../../../resources/testharnessreport.js"></script> |
| 6 <div id="container"></div> |
| 7 <script> |
| 8 var global = this; |
| 9 var container = document.getElementById('container'); |
| 10 |
| 11 test(function() { |
| 12 var originalAlert = window.alert; |
| 13 var iframe = document.createElement('iframe'); |
| 14 iframe.name = 'alert'; |
| 15 container.appendChild(iframe); |
| 16 assert_equals(window.alert, originalAlert, "window.alert shouldn't be shadow
ed by named properties."); |
| 17 }, "Named access test. Window's members should have priority over named propert
ies."); |
| 18 |
| 19 test(function() { |
| 20 // Window's prototype chain must be |
| 21 // window --> Window.prototype --> "WindowProperties" --> EventTarget.protot
ype |
| 22 assert_equals(window.__proto__, Window.prototype); |
| 23 assert_class_string(window.__proto__.__proto__, 'WindowProperties'); |
| 24 assert_equals(window.__proto__.__proto__.__proto__, EventTarget.prototype); |
| 25 }, "WindowProperties object should exist."); |
| 26 |
| 27 test(function() { |
| 28 var anchor = document.createElement('a'); |
| 29 anchor.id = 'myAnchor'; |
| 30 container.appendChild(anchor); |
| 31 assert_equals(window.myAnchor, anchor, "Named access should work when Window
Properties is available."); |
| 32 // Remove the WindowProperties object from the prototype chain. This means, |
| 33 // 'window' no longer supports named access. |
| 34 Window.prototype.__proto__ = EventTarget.prototype; |
| 35 assert_equals(window.myAnchor, undefined, "Named access shouldn't work when
WindowProperties is not available."); |
| 36 }, "WindowProperties object should provide named access."); |
| 37 |
| 38 test(function() { |
| 39 assert_true(window.hasOwnProperty('onclick'), "Window's event handlers shoul
d be own properties."); |
| 40 assert_true(window.hasOwnProperty('alert'), "Window's methods should be own
properties."); |
| 41 }, "Window's members should be own members."); |
| 42 |
| 43 // This test needs to run in the global scope. |
| 44 assert_false(!!window.onclick, "window.onclick is not yet set."); |
| 45 var wasMyOnClickCalled = false; |
| 46 var myOnClick = function() { wasMyOnClickCalled = true; }; |
| 47 var onclick = myOnClick; |
| 48 assert_equals(window.onclick, myOnClick, "var declaration should be ignored, and
window.onclick should be updated."); |
| 49 window.dispatchEvent(new Event('click')); |
| 50 assert_true(wasMyOnClickCalled, "myOnClick should have been called."); |
| 51 </script> |
| 52 </html> |
OLD | NEW |