Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Side by Side Diff: LayoutTests/http/tests/serviceworker/chromium/sandboxed-iframe-fetch-event.html

Issue 1208693003: Add LayoutTest for ServiceWorker's sandbox iframe handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add service_worker_unregister_and_done Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <title>ServiceWorker FetchEvent for sandboxed iframe.</title>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script src="../resources/test-helpers.js"></script>
6 <body>
7 <script>
8 var lastCallbackId = 0;
9 var callbacks = {};
10 function postMassageAndWaitResult(frame) {
11 return new Promise(function(resolve) {
12 var id = ++lastCallbackId;
13 callbacks[id] = resolve;
14 frame.contentWindow.postMessage({id:id}, '*');
15 });
16 }
17
18 window.onmessage = function (e) {
19 message = e.data;
20 var id = message['id'];
21 var calback = callbacks[id];
22 delete callbacks[id];
23 calback(message['result']);
24 };
25
26 promise_test(function(t) {
27 var SCOPE = 'resources/sandboxed-iframe-fetch-event-iframe.html';
28 var SCRIPT = 'resources/sandboxed-iframe-fetch-event-worker.js';
29 var frames = [];
30 var worker;
31 return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
32 .then(function(registration) {
33 worker = registration.installing;
34 return wait_for_state(t, registration.installing, 'activated');
35 })
36 .then(function() {
37 return with_iframe(SCOPE + '?iframe');
38 })
39 .then(function(frame) {
40 frames.push(frame);
41 return postMassageAndWaitResult(frame);
42 })
43 .then(function(result) {
44 assert_equals(result, 'done');
45 return with_sandboxed_iframe(SCOPE + '?script', 'allow-scripts');
46 })
47 .then(function(frame) {
48 frames.push(frame);
49 return postMassageAndWaitResult(frame);
50 })
51 .then(function(result) {
52 assert_equals(result, 'done');
53 return with_sandboxed_iframe(SCOPE + '?script-origin',
54 'allow-scripts allow-same-origin');
55 })
56 .then(function(frame) {
57 frames.push(frame);
58 return postMassageAndWaitResult(frame);
59 })
60 .then(function(result) {
61 assert_equals(result, 'done');
62 return new Promise(function(resolve) {
63 var channel = new MessageChannel();
64 channel.port1.onmessage = function(msg) {
65 resolve(msg);
66 };
67 worker.postMessage({port: channel.port2}, [channel.port2]);
68 });
69 })
70 .then(function(msg) {
71 for (var frame of frames) {
72 frame.remove();
73 }
74 var expected_base_url = new URL(SCOPE, location.href).href;
75 var requests = msg.data.requests;
76 assert_equals(requests.length, 8);
77 assert_equals(requests[0], expected_base_url + '?iframe');
78 assert_equals(requests[1], expected_base_url + '?iframe_fetch');
79 assert_equals(requests[2], expected_base_url + '?iframe_iframe');
80 assert_equals(requests[3],
81 expected_base_url + '?iframe_script-origin');
82 assert_equals(requests[4], expected_base_url + '?script-origin');
nhiroki 2015/06/26 01:01:37 Adding comments (or 3rd parameter to assert_equals
horo 2015/06/26 03:59:10 Done.
83 assert_equals(requests[5],
84 expected_base_url + '?script-origin_fetch');
85 assert_equals(requests[6],
86 expected_base_url + '?script-origin_iframe');
87 assert_equals(requests[7],
88 expected_base_url + '?script-origin_script-origin');
nhiroki 2015/06/26 01:01:37 nit: Can you add a blank line after line 88 for re
horo 2015/06/26 03:59:11 Done.
89 var clients = msg.data.clients;
90 assert_equals(clients.length, 6);
91 assert_equals(clients[0], expected_base_url + '?iframe');
92 assert_equals(clients[1], expected_base_url + '?iframe_iframe');
93 assert_equals(clients[2],
94 expected_base_url + '?iframe_script-origin');
95 assert_equals(clients[3], expected_base_url + '?script-origin');
96 assert_equals(clients[4],
97 expected_base_url + '?script-origin_iframe');
98 assert_equals(clients[5],
99 expected_base_url + '?script-origin_script-origin');
100 return service_worker_unregister_and_done(t, SCOPE);
101 });
102 }, 'ServiceWorker FetchEvent for sandboxed iframe.');
103 </script>
104 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698