2 <title>Name look-up tests of Window interface
</title>
3 <!-- TODO(yukishiino): Change the name look-up behavior of Window and fix all these tests. -->
4 <script src=
"../../../resources/testharness.js"></script>
5 <script src=
"../../../resources/testharnessreport.js"></script>
6 <div id=
"container"></div>
9 var container
= document
.getElementById('container');
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 shadowed by named properties.");
17 }, "Named access test. Window's members should have priority over named properties.");
20 // Window's prototype chain must be
21 // window --> Window.prototype --> "WindowProperties" --> EventTarget.prototype
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.");
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 WindowProperties 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.");
39 assert_true(window
.hasOwnProperty('onclick'), "Window's event handlers should be own properties.");
40 assert_true(window
.hasOwnProperty('alert'), "Window's methods should be own properties.");
41 }, "Window's members should be own members.");
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.");