1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Test for SharedWorker</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
<script class="testbody" type="text/javascript;version=1.7">
"use strict";
const scrollbarPref = "layout.testing.overlay-scrollbars.always-visible";
const bfCacheEnabledPref = "browser.sessionhistory.cache_subframes";
const bfCacheDepthPref = "browser.sessionhistory.max_total_viewers";
const bfCacheDepth = 10;
const frameRelativeURL = "multi_sharedWorker_frame.html";
const storedData = "0123456789abcdefghijklmnopqrstuvwxyz";
let testGenerator = (function() {
SimpleTest.waitForExplicitFinish();
// Force scrollbar to always be shown. The scrollbar setting is
// necessary to avoid the fade-in/fade-out from evicting our document
// from the BF cache below. If bug 1049277 is fixed, then we can
// stop setting the scrollbar pref here.
SpecialPowers.pushPrefEnv({ set: [[scrollbarPref, true]] },
sendToGenerator);
yield undefined;
window.addEventListener("message", function(event) {
if (typeof(event.data) == "string") {
info(event.data);
} else {
sendToGenerator(event);
}
});
let frame = document.getElementById("frame");
frame.src = frameRelativeURL;
frame.onload = sendToGenerator;
yield undefined;
frame = frame.contentWindow;
frame.postMessage({ command: "retrieve" }, "*");
let event = yield undefined;
ok(event instanceof MessageEvent, "Got a MessageEvent");
is(event.source, frame, "Correct window got the event");
is(event.data.type, "result", "Got a result message");
is(event.data.data, undefined, "No data stored yet");
frame.postMessage({ command: "store", data: storedData }, "*");
frame.postMessage({ command: "retrieve" }, "*");
event = yield undefined;
ok(event instanceof MessageEvent, "Got a MessageEvent");
is(event.source, frame, "Correct window got the event");
is(event.data.type, "result", "Got a result message");
is(event.data.data, storedData, "Got stored data");
// Navigate when the bfcache is disabled.
info("Navigating to about:blank");
frame = document.getElementById("frame");
frame.onload = sendToGenerator;
frame.src = "about:blank";
frame.contentWindow.document.body.offsetTop;
yield undefined;
info("Navigating to " + frameRelativeURL);
frame.src = frameRelativeURL;
frame.contentWindow.document.body.offsetTop;
yield undefined;
frame = frame.contentWindow;
frame.postMessage({ command: "retrieve" }, "*");
event = yield undefined;
ok(event instanceof MessageEvent, "Got a MessageEvent");
is(event.source, frame, "Correct window got the event");
is(event.data.type, "result", "Got a result message");
is(event.data.data, undefined, "No data stored");
frame.postMessage({ command: "store", data: storedData }, "*");
frame.postMessage({ command: "retrieve" }, "*");
event = yield undefined;
ok(event instanceof MessageEvent, "Got a MessageEvent");
is(event.source, frame, "Correct window got the event");
is(event.data.type, "result", "Got a result message");
is(event.data.data, storedData, "Got stored data");
info("Enabling '" + bfCacheEnabledPref + "' pref");
SpecialPowers.pushPrefEnv({ set: [[bfCacheEnabledPref, true],
[bfCacheDepthPref, bfCacheDepth]] },
sendToGenerator);
yield undefined;
// Navigate when the bfcache is enabled.
frame = document.getElementById("frame");
frame.onload = sendToGenerator;
info("Navigating to about:blank");
frame.src = "about:blank";
frame.contentWindow.document.body.offsetTop;
yield undefined;
for (let i = 0; i < 3; i++) {
info("Running GC");
SpecialPowers.exactGC(sendToGenerator);
yield undefined;
info("Waiting the event queue to clear");
SpecialPowers.executeSoon(sendToGenerator);
yield undefined;
}
info("Navigating to " + frameRelativeURL);
frame.src = frameRelativeURL;
frame.contentWindow.document.body.offsetTop;
yield undefined;
frame = frame.contentWindow;
frame.postMessage({ command: "retrieve" }, "*");
event = yield undefined;
ok(event instanceof MessageEvent, "Got a MessageEvent");
is(event.source, frame, "Correct window got the event");
is(event.data.type, "result", "Got a result message");
is(event.data.data, storedData, "Still have data stored");
info("Resetting '" + bfCacheEnabledPref + "' pref");
SpecialPowers.popPrefEnv(sendToGenerator);
yield undefined;
window.removeEventListener("message", sendToGenerator);
SimpleTest.finish();
yield undefined;
})();
let sendToGenerator = testGenerator.send.bind(testGenerator);
</script>
</head>
<body onload="testGenerator.next();">
<iframe id="frame"></iframe>
</body>
</html>
|