Index: LayoutTests/fast/dom/Window/lookup-behavior.html |
diff --git a/LayoutTests/fast/dom/Window/lookup-behavior.html b/LayoutTests/fast/dom/Window/lookup-behavior.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..f95904c853a87287115e9ca29d5638635deac758 |
--- /dev/null |
+++ b/LayoutTests/fast/dom/Window/lookup-behavior.html |
@@ -0,0 +1,52 @@ |
+<!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."); |
+ // Remove the WindowProperties object from the prototype chain. This means, |
+ // 'window' no longer supports named access. |
+ Window.prototype.__proto__ = EventTarget.prototype; |
+ assert_equals(window.myAnchor, undefined, "Named access shouldn't work when WindowProperties is not available."); |
+}, "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> |