2 * Copyright 2016 Jacek Caban for CodeWeavers
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.
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.
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
20 var head = document.getElementsByTagName("head")[0];
22 /* Dynamically created script element is downloaded as soon as src property is set,
23 * but it doesn't block document onload event. */
24 var detached_elem_executed = false;
25 var detached_elem = document.createElement("script");
26 detached_elem.src = "jsstream.php?detached_script";
28 async_test("detached_script_elem", function() {
29 var oncomplete_called = false;
30 detached_elem.onreadystatechange = guard(function() {
31 if(detached_elem.readyState == "complete") {
32 ok(detached_elem_executed, "detached element not executed before readyState complete");
33 oncomplete_called = true;
38 ok(!detached_elem_executed, "detached element executed");
39 if(detached_elem.readyState == "loaded") {
40 head.appendChild(detached_elem);
41 ok(detached_elem_executed, "detached element not yet executed");
42 ok(detached_elem.readyState == "complete", "detached_elem.readyState = " + detached_elem.readyState + " expected complete");
43 ok(!oncomplete_called, "oncomplete not called");
47 external.writeStream("detached_script", 'detached_elem_executed = true;');
50 /* Dynamically created script elements are evaluated as soon as they are loaded, no matter
51 * how they are ordered in the tree. */
52 var attached_elem1_executed = false;
53 var attached_elem1 = document.createElement("script");
54 attached_elem1.src = "jsstream.php?attached_script1";
55 head.appendChild(attached_elem1);
57 var attached_elem2_executed = false;
58 var attached_elem2 = document.createElement("script");
59 attached_elem2.src = "jsstream.php?attached_script2";
60 head.appendChild(attached_elem2);
62 async_test("attached_script_elem", function() {
63 attached_elem1.onreadystatechange = guard(function() {
64 ok(attached_elem1.readyState == "loaded", "attached_elem1.readyState = " + attached_elem2.readyState);
65 ok(attached_elem1_executed, "attached element 1 not executed before readyState complete");
69 attached_elem2.onreadystatechange = guard(function() {
70 ok(attached_elem2.readyState == "loaded", "attached_elem2.readyState = " + attached_elem2.readyState);
71 ok(attached_elem2_executed, "attached element 2 not executed before readyState complete");
73 external.writeStream("attached_script1", 'attached_elem1_executed = true;');
76 external.writeStream("attached_script2", 'attached_elem2_executed = true;');
79 async_test("append_script", function() {
80 var elem = document.createElement("script");
81 var ready_states = "";
83 elem.onreadystatechange = guard(function() {
84 ready_states += elem.readyState + ",";
85 if(elem.readyState == "loaded")
89 document.body.appendChild(elem);
90 elem.src = "jsstream.php?simple";
91 external.writeStream("simple", " ");
94 function unexpected_load(e) {
95 ok(false, "onload event before executing script");
99 var elem = document.createElement("script");
100 document.head.appendChild(elem);
101 elem.src = "jsstream.php?blockload";
103 window.addEventListener("load", unexpected_load, true);
105 setTimeout(guard(function() {
106 external.writeStream("blockload", "window.removeEventListener('load', unexpected_load, true);");