blob: d92ba22b8c9b4cee889aa3aefdf8d0eedd35e3f7 [file] [log] [blame]
<!DOCTYPE html>
<title>Name look-up tests of Window interface</title>
<!-- TODO(yukishiino): Change the name look-up behavior of Window and fix all these tests. -->
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<div id="container"></div>
<script>
var global = this;
var container = document.getElementById('container');
test(function() {
var originalAlert = window.alert;
var iframe = document.createElement('iframe');
iframe.name = 'alert';
container.appendChild(iframe);
assert_equals(window.alert, originalAlert, "window.alert shouldn't be shadowed by named properties.");
}, "Named access test. Window's members should have priority over named properties.");
test(function() {
// Window's prototype chain must be
// window --> Window.prototype --> "WindowProperties" --> EventTarget.prototype
assert_equals(window.__proto__, Window.prototype);
assert_class_string(window.__proto__.__proto__, 'WindowProperties');
assert_equals(window.__proto__.__proto__.__proto__, EventTarget.prototype);
}, "WindowProperties object should exist.");
test(function() {
var anchor = document.createElement('a');
anchor.id = 'myAnchor';
container.appendChild(anchor);
assert_equals(window.myAnchor, anchor, "Named access should work when WindowProperties is available.");
// Look up the prototype chain and observe that the anchor is defined on the
// named properties object, no lower or higher.
assert_equals(window.__proto__.myAnchor, anchor, "Named access should work on Window.prototype");
assert_equals(window.__proto__.__proto__.myAnchor, anchor, "Named access should work on named properties object");
assert_equals(window.__proto__.__proto__.__proto__.myAnchor, undefined, "Named access does not work on EventTarget.prototype");
assert_equals(window.__proto__.__proto__.__proto__.__proto__.myAnchor, undefined, "Named access does not work on Object.prototype");
}, "WindowProperties object should provide named access.");
test(function() {
assert_true(window.hasOwnProperty('onclick'), "Window's event handlers should be own properties.");
assert_true(window.hasOwnProperty('alert'), "Window's methods should be own properties.");
}, "Window's members should be own members.");
// This test needs to run in the global scope.
assert_false(!!window.onclick, "window.onclick is not yet set.");
var wasMyOnClickCalled = false;
var myOnClick = function() { wasMyOnClickCalled = true; };
var onclick = myOnClick;
assert_equals(window.onclick, myOnClick, "var declaration should be ignored, and window.onclick should be updated.");
window.dispatchEvent(new Event('click'));
assert_true(wasMyOnClickCalled, "myOnClick should have been called.");
</script>
</html>