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

Side by Side Diff: LayoutTests/http/tests/serviceworker/chromium/service-worker-mixed-response.html

Issue 1226473002: Add LayoutTests for mixed range response handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporated falken's comment and refactored Created 5 years, 5 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>Mixing response using ServiceWorker</title>
3 <script src="../../resources/testharness.js"></script>
4 <script src="../../resources/testharnessreport.js"></script>
5 <script src="../../resources/get-host-info.js"></script>
6 <script src="../resources/test-helpers.js"></script>
7 <body>
8 <script>
9 // We put this test file in chromium/ directory, because the behavior of mixing
10 // multiple resources are not defined in the spec.
falken 2015/07/07 03:23:11 Does this mean if https://github.com/slightlyoff/S
horo 2015/07/07 10:08:11 yes. Added the URL to the comment.
11
12 function create_failure_audio_test(frame, url) {
13 return new Promise(function(resolve, reject) {
14 var audio = frame.contentWindow.document.createElement('audio');
15 audio.oncanplay = function() {
16 reject('canplay event should not be fired. url: ' + url);
17 };
18 audio.onerror = resolve;
19 audio.src = url;
20 frame.contentWindow.document.body.appendChild(audio);
21 });
22 }
23
24 function create_success_audio_test(frame, url) {
25 return new Promise(function(resolve, reject) {
26 var audio = frame.contentWindow.document.createElement('audio');
27 audio.oncanplay = resolve;
28 audio.onerror = function(e) {
29 reject('error event should not be fired. url: ' + url);
30 };
31 audio.src = url;
32 frame.contentWindow.document.body.appendChild(audio);
33 });
34 }
35
36 // Creates a test case to check the following behavior:
37 // 1. The audio element sends the first request.
38 // - If |original| is 'same', the request is same-origin request.
39 // - If |original| is 'cross', the request is cross-origin request.
40 // 2. The Service Worker may intercept the request depending on |first_byte|.
41 // - If |first_byte| is '', the SW doesn't intercept, and the native server
42 // returns the all data response and the test finishes.
43 // - If |first_byte| is 'gen', the SW genetates and returns the first byte
falken 2015/07/07 03:23:10 nit: generates (two places)
horo 2015/07/07 10:08:11 Done.
44 // response 'O'.
45 // - If |first_byte| is 'same', the SW fetches the request to
falken 2015/07/07 03:23:11 nit: "fetches the request" sounds like the SW gets
horo 2015/07/07 10:08:11 Done.
46 // 'service-worker-mixed-response.php' in the same origin server and returns
47 // the response.
48 // - If |first_byte| is 'cross', the SW fetches the request to
49 // 'service-worker-mixed-response.php' in the cross origin server and
50 // returns the response.
51 // 3. The element sends the second request with "Range: bytes=1-" header.
52 // 4. The Service Worker may intercept the request depending on |second_byte|.
53 // - If |second_byte| is '', the SW doesn't intercept, and the native server
54 // returns the remaining data response and the test finishes.
55 // - If |second_byte| is 'gen', the SW genetates and returns the second byte
56 // response 'g'.
57 // - If |second_byte| is 'same', the SW fetches the request to
58 // 'service-worker-mixed-response.php' in the same origin server and returns
59 // the response.
60 // - If |second_byte| is 'cross', the SW fetches the request to
61 // 'service-worker-mixed-response.php' in the cross origin server and
62 // returns the response.
63 // 5. The element sends the third request with "Range: bytes=2-" header.
64 // 6. The native server returns the remaining data.
65 //
66 // When the audio element recieves the first response, it remembers the original
67 // URL of it. And when it receives the succeeding response, it checks the origin
68 // of the new response. If the origin is cross-origin and it is not same as the
69 // origin of the first response, the response must be treated as an error.
falken 2015/07/07 03:23:11 Nice explanation.
70 function audio_test(frame, original, first_byte, second_byte, should_success) {
falken 2015/07/07 03:23:10 nit: expect_success is a bit more natural (as you'
horo 2015/07/07 10:08:11 Done.
71 var url;
72 var HOST_INFO = get_host_info();
73 var AUDIO_PATH = '/media/resources/load-video.php?' +
74 'name=../../../../media/content/silence.oga&type=audio/ogg';
75 if (original == 'same') {
76 url = HOST_INFO['HTTP_ORIGIN'] + AUDIO_PATH;
77 } else if (original == 'cross') {
78 url = HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH;
79 }
80 url += '&SW_FIRST=' + first_byte + '&SW_SECOND=' + second_byte;
81 if (should_success) {
82 return create_success_audio_test(frame, url);
83 } else {
84 return create_failure_audio_test(frame, url);
85 }
86 }
87
88 promise_test(function(t) {
89 var SCOPE = 'resources/blank.html?/service-worker-mixed-response';
90 var SCRIPT = 'resources/service-worker-mixed-response-worker.js';
91 var frame;
92 return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
93 .then(function(registration) {
94 return wait_for_state(t, registration.installing, 'activated');
95 })
96 .then(function() { return with_iframe(SCOPE); })
97 .then(function(f) {
98 frame = f;
99 return Promise.all([
100 audio_test(f, 'same', '', '', true),
101 audio_test(f, 'same', 'gen', '', true),
102 audio_test(f, 'same', 'gen', 'gen', true),
103 audio_test(f, 'same', 'gen', 'same', true),
104 audio_test(f, 'same', 'gen', 'cross', false),
105 audio_test(f, 'same', 'same', '', true),
106 audio_test(f, 'same', 'same', 'gen', true),
107 audio_test(f, 'same', 'same', 'same', true),
108 audio_test(f, 'same', 'same', 'cross', false),
109 audio_test(f, 'same', 'cross', '', true),
110 audio_test(f, 'same', 'cross', 'gen', true),
111 audio_test(f, 'same', 'cross', 'same', true),
112 audio_test(f, 'same', 'cross', 'cross', true),
113 audio_test(f, 'cross', '', '', true),
114 audio_test(f, 'cross', 'gen', '', false),
115 audio_test(f, 'cross', 'gen', 'gen', false),
116 audio_test(f, 'cross', 'gen', 'same', false),
117 audio_test(f, 'cross', 'gen', 'cross', false),
118 audio_test(f, 'cross', 'same', '', false),
119 audio_test(f, 'cross', 'same', 'gen', false),
120 audio_test(f, 'cross', 'same', 'same', false),
121 audio_test(f, 'cross', 'same', 'cross', false),
122 audio_test(f, 'cross', 'cross', '', true),
123 audio_test(f, 'cross', 'cross', 'gen', true),
124 audio_test(f, 'cross', 'cross', 'same', true),
125 audio_test(f, 'cross', 'cross', 'cross', true)]);
falken 2015/07/07 03:23:10 Wow, exhaustive test.
126 })
127 .then(function() {
128 frame.remove();
129 return service_worker_unregister_and_done(t, SCOPE);
130 });
131 }, 'Tests for Service Worker generated mixed responses.');
132 </script>
133 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698