mshtml: Return failure in IHTMLDocument2::get_URL for detached documents.
[wine.git] / dlls / mshtml / tests / navigation.js
blob71bda9ea2a5784de09a91c49998721c1a35030d1
1 /*
2  * Copyright 2016 Jacek Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
19 function nav_parent_test() {
20     external.trace("Running _parent navigation tests...");
22     var iframe = document.getElementById("testframe");
23     var subframe = iframe.contentWindow.document.createElement("iframe");
25     subframe.onload = function() {
26         var doc = subframe.contentWindow.document;
27         doc.body.innerHTML = '<a href="blank2.html" id="aid" target="_parent">test</a>';
28         doc.getElementById("aid").click();
29     }
31     iframe.onload = function() {
32         iframe.onload = null;
33         var href = iframe.contentWindow.location.href;
34         ok(/.*blank2.html/.test(href), "Unexpected href " + href);
35         next_test();
36     }
38     iframe.contentWindow.document.body.appendChild(subframe);
39     subframe.src = "blank.html";
42 function window_navigate_test() {
43     external.trace("Running window.navigate() tests...");
45     var iframe = document.getElementById("testframe");
47     iframe.onload = function() {
48         iframe.onload = null;
49         var href = iframe.contentWindow.location.href;
50         ok(href === "about:blank", "Unexpected href " + href);
51         next_test();
52     }
54     iframe.contentWindow.navigate("about:blank");
57 function window_open_self_test() {
58     external.trace("Running window.open(_self) tests...");
60     var iframe = document.getElementById("testframe");
61     var iframe_window = iframe.contentWindow;
63     iframe.onload = function() {
64         iframe.onload = null;
65         var href = iframe.contentWindow.location.href;
66         ok(/.*blank.html\?window_open_self/.test(href), "Unexpected href " + href);
67         ok(iframe.contentWindow === iframe_window, "iframe.contentWindow !== iframe_window");
68         next_test();
69     }
71     iframe_window.open("blank.html?window_open_self", "_self");
74 function detached_src_test() {
75     var iframe = document.createElement("iframe");
76     var onload_called = false;
78     iframe.onload = function() {
79         onload_called = true;
80         next_test();
81     }
83     iframe.src = "blank.html";
84     document.body.appendChild(iframe);
85     ok(onload_called === false, "called onload too early?");
88 function detached_iframe_doc() {
89     document.body.innerHTML = "";
91     var iframe = document.createElement("iframe");
92     var origDoc;
94     function expect_exception(f, is_todo) {
95         try {
96             f();
97             todo_wine_if(is_todo).ok(false, "expected exception");
98         } catch(e) {}
99     }
101     iframe.onload = guard(function() {
102         origDoc = iframe.contentWindow.document;
103         iframe.onload = guard(function () {
104             var doc = iframe.contentWindow.document;
106             ok(/.*blank2.html/.test(doc.URL), "Unexpected iframe doc URL " + doc.URL);
108             if (doc.documentMode >= 9) {
109                 try {
110                     origDoc != null; // it's not allowed to even compare detached document
111                     todo_wine.
112                     ok(false, "expected exception");
113                 } catch(e) {}
114             } else {
115                 todo_wine.
116                 ok(doc === origDoc, "doc != origDoc");
117             }
119             expect_exception(function() { origDoc.onclick; }, true);
120             expect_exception(function() { origDoc.toString; }, true);
121             expect_exception(function() { origDoc.toString(); }, true);
122             expect_exception(function() { origDoc.URL; });
124             next_test();
125         });
126         iframe.src = "blank2.html";
127     });
129     iframe.src = "blank.html";
130     document.body.appendChild(iframe);
133 function init_test_iframe() {
134     var iframe = document.createElement("iframe");
136     iframe.onload = next_test;
137     iframe.id = "testframe";
138     iframe.src = "about:blank";
139     document.body.appendChild(iframe);
142 var tests = [
143     init_test_iframe,
144     nav_parent_test,
145     window_navigate_test,
146     window_open_self_test,
147     detached_src_test,
148     detached_iframe_doc