-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bfcache] Unblock broadcastchannel on dedicated worker
Change-Id: Iea7fdd4024f54dd6306334437ba80030feb9a0bb
- Loading branch information
1 parent
d32b68c
commit 9578402
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...rowsing-the-web/back-forward-cache/dedicated-worker-broadcastchanel-evict-on-message.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!doctype html> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="/common/dispatcher/dispatcher.js"></script> | ||
<script src="resources/helper.sub.js"></script> | ||
<script> | ||
promise_test(async t => { | ||
const pageA = new RemoteContext(token()); | ||
const pageB = new RemoteContext(token()); | ||
const pageA2 = new RemoteContext(token()); | ||
|
||
const urlA = location.origin + executorPath + pageA.context_id; | ||
const urlB = originCrossSite + executorPath + pageB.context_id; | ||
const urlA2 = location.origin + executorPath + pageA2.context_id; | ||
|
||
window.open(urlA, '_blank', 'noopener'); | ||
await pageA.execute_script(waitForPageShow); | ||
|
||
await pageA.execute_script(() => { | ||
// Register a dedicated worker. | ||
let worker = new Worker('../resources/worker-with-broadcastchannel.js'); | ||
worker.postMessage({channelName: 'foo'}); | ||
}); | ||
|
||
window.open(urlA2, '_blank', 'noopener'); | ||
|
||
await pageA.execute_script( | ||
(url) => { | ||
prepareNavigation(() => { | ||
location.href = url; | ||
}); | ||
}, | ||
[urlB] | ||
); | ||
|
||
await pageB.execute_script(waitForPageShow); | ||
|
||
let messageLength = await pageA2.execute_script(() => { | ||
let messages = []; | ||
let channel = new BroadcastChannel('foo'); | ||
channel.addEventListener('message', event => { | ||
messages.push(event.data); | ||
}); | ||
channel.postMessage('yay'); | ||
return messages.length; | ||
}); | ||
// Assert that the message has not arrived when PageA is in bfcache. | ||
assert_true(messageLength == 0); | ||
|
||
await pageB.execute_script( | ||
() => { | ||
prepareNavigation(() => { history.back(); }); | ||
} | ||
); | ||
|
||
await pageA.execute_script(waitForPageShow); | ||
await assert_bfcached(pageA); | ||
|
||
// I would like to assert that the messages are now received. How???? | ||
|
||
}, 'PageA should.'); | ||
</script> |
34 changes: 34 additions & 0 deletions
34
html/browsers/browsing-the-web/back-forward-cache/dedicated-worker-broadcastchanel.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!doctype html> | ||
<meta name="timeout" content="long"> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/common/utils.js"></script> | ||
<script src="/common/dispatcher/dispatcher.js"></script> | ||
<script src="resources/helper.sub.js"></script> | ||
<script> | ||
promise_test(async t => { | ||
const pageA = new RemoteContext(token()); | ||
const pageB = new RemoteContext(token()); | ||
|
||
const urlA = location.origin + executorPath + pageA.context_id; | ||
const urlB = originCrossSite + executorPath + pageB.context_id; | ||
|
||
window.open(urlA, '_blank', 'noopener'); | ||
await pageA.execute_script(waitForPageShow); | ||
|
||
await pageA.execute_script(() => { | ||
// Create BroadcastChannel in main thread | ||
let channel = new BroadcastChannel('foo'); | ||
// Register a dedicated worker. | ||
let worker = new Worker('../resources/worker-with-broadcastchannel.js'); | ||
channel.addEventListener('message', event => { | ||
// Received from worker: event.data; | ||
}); | ||
worker.postMessage({channelName: 'foo'}); | ||
}); | ||
|
||
await navigateAndThenBack(pageA, pageB, urlB); | ||
await assert_bfcached(pageA); | ||
|
||
}, 'PageA should be restored from bfcache, even though the dedicated worker had an open broadcastchannel connection.'); | ||
</script> |
6 changes: 6 additions & 0 deletions
6
html/browsers/browsing-the-web/back-forward-cache/resources/worker-with-broadcastchannel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
self.addEventListener('message', event => { | ||
const channel = new BroadcastChannel(event.data.channelName); // Access shared channel | ||
channel.addEventListener('message', event => { | ||
channel.postMessage('Message received in worker: ' + event.data); | ||
}); | ||
}); |