Add (entirely incorrect) fetching of ServiceWorker scripts.
[WebKit-https.git] / LayoutTests / http / tests / workers / service / resources / registration-task-queue-scheduling-1.js
1 // This test makes sure that two different windows from two different domains who spam SW registrations get responses intertwined with each other
2 // as each registration should operate on its own task queue.
3
4 if (location.hostname != "127.0.0.1")
5     alert("This test must be initiated from the hostname 127.0.0.1");
6
7 window.onmessage = function(evt)
8 {
9         if (evt.data == "done") {
10                 alert("Error in popup window");
11                 finishSWTest();
12         } else if (evt.data == "responded") {
13                 if (!window.popupTimestamp)
14                         window.popupTimestamp = new Date();
15                 
16                 responded();
17         } else {
18                 alert("Unexpected event from popup window");
19                 finishSWTest();
20         }
21 }
22
23 function responded()
24 {
25         if (!window.thisTimestamp) {
26                 window.thisTimestamp = new Date();
27         
28                 if (window.popupTimestamp)
29                         alert("Registrations in second window should not have responded before the first");
30         
31                 return;
32         }
33         
34         if (!window.popupTimestamp) 
35                 return;
36                 
37         if (window.popupTimestamp < window.thisTimestamp)
38                 alert("Popup should not have popped up before this main window");
39         else
40                 alert("Done");
41         
42         finishSWTest();
43 }
44
45 for (var i = 0; i < 1000; ++i) {
46         navigator.serviceWorker.register("resources/empty-worker.js", { })
47         .then(function(r) {
48                 console.log("Original window resolved successfully (unexpected)")
49                 done();
50         }, function(e) {
51                 if (e+"" != "UnknownError: Script URL http://127.0.0.1:8000/workers/service/resources/empty-worker.js fetched with 41 characters, but we're not using the result yet") {
52                         alert("Unexpected error received from server: " + e);
53                         finishSWTest();
54                 }
55                 
56                 responded();
57         })
58 }
59
60 otherWindow = window.open("http://localhost:8000/workers/service/resources/registration-task-queue-scheduling-1-second-window.html", "other");