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

Unified 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: third 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/http/tests/serviceworker/chromium/resources/service-worker-mixed-response-worker.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/serviceworker/chromium/service-worker-mixed-response.html
diff --git a/LayoutTests/http/tests/serviceworker/chromium/service-worker-mixed-response.html b/LayoutTests/http/tests/serviceworker/chromium/service-worker-mixed-response.html
new file mode 100644
index 0000000000000000000000000000000000000000..bd0e03361453c10e65747e98828dd6ff99804d55
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/chromium/service-worker-mixed-response.html
@@ -0,0 +1,134 @@
+<!DOCTYPE html>
+<title>Mixing response using ServiceWorker</title>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script src="../../resources/get-host-info.js"></script>
+<script src="../resources/test-helpers.js"></script>
+<body>
+<script>
+// We put this test file in chromium/ directory, because the behavior of mixing
+// multiple resources are not defined in the spec. See
+// https://github.com/slightlyoff/ServiceWorker/issues/703 for details.
+
+function create_failure_audio_test(frame, url) {
+ return new Promise(function(resolve, reject) {
+ var audio = frame.contentWindow.document.createElement('audio');
+ audio.oncanplay = function() {
+ reject('canplay event should not be fired. url: ' + url);
+ };
+ audio.onerror = resolve;
+ audio.src = url;
+ frame.contentWindow.document.body.appendChild(audio);
+ });
+}
+
+function create_success_audio_test(frame, url) {
+ return new Promise(function(resolve, reject) {
+ var audio = frame.contentWindow.document.createElement('audio');
+ audio.oncanplay = resolve;
+ audio.onerror = function(e) {
+ reject('error event should not be fired. url: ' + url);
+ };
+ audio.src = url;
+ frame.contentWindow.document.body.appendChild(audio);
+ });
+}
+
+// Creates a test case to check the following behavior:
+// 1. The audio element sends the first request.
+// - If |original| is 'same', the request is same-origin request.
+// - If |original| is 'cross', the request is cross-origin request.
+// 2. The Service Worker may intercept the request depending on |first_byte|.
+// - If |first_byte| is '', the SW doesn't intercept, and the native server
+// returns the all data response and the test finishes.
+// - If |first_byte| is 'gen', the SW generates and returns the first byte
+// response 'O'.
+// - If |first_byte| is 'same', the SW does a fetch to
+// 'service-worker-mixed-response.php' in the same origin server and returns
+// the response.
+// - If |first_byte| is 'cross', the SW does a fetch to
+// 'service-worker-mixed-response.php' in the cross origin server and
+// returns the response.
+// 3. The element sends the second request with "Range: bytes=1-" header.
+// 4. The Service Worker may intercept the request depending on |second_byte|.
+// - If |second_byte| is '', the SW doesn't intercept, and the native server
+// returns the remaining data response and the test finishes.
+// - If |second_byte| is 'gen', the SW generates and returns the second byte
+// response 'g'.
+// - If |second_byte| is 'same', the SW does a fetch to
+// 'service-worker-mixed-response.php' in the same origin server and returns
+// the response.
+// - If |second_byte| is 'cross', the SW does a fetch to
+// 'service-worker-mixed-response.php' in the cross origin server and
+// returns the response.
+// 5. The element sends the third request with "Range: bytes=2-" header.
+// 6. The native server returns the remaining data.
+//
+// When the audio element recieves the first response, it remembers the original
+// URL of it. And when it receives the succeeding response, it checks the origin
+// of the new response. If the origin is not same as the origin of the first
+// response, the response must be treated as an error.
+function audio_test(frame, original, first_byte, second_byte, expect_success) {
+ var url;
+ var HOST_INFO = get_host_info();
+ var AUDIO_PATH = '/media/resources/load-video.php?' +
+ 'name=../../../../media/content/silence.oga&type=audio/ogg';
+ if (original == 'same') {
+ url = HOST_INFO['HTTP_ORIGIN'] + AUDIO_PATH;
+ } else if (original == 'cross') {
+ url = HOST_INFO['HTTP_REMOTE_ORIGIN'] + AUDIO_PATH;
+ }
+ url += '&SW_FIRST=' + first_byte + '&SW_SECOND=' + second_byte;
+ if (expect_success) {
+ return create_success_audio_test(frame, url);
+ } else {
+ return create_failure_audio_test(frame, url);
+ }
+}
+
+promise_test(function(t) {
+ var SCOPE = 'resources/blank.html?/service-worker-mixed-response';
+ var SCRIPT = 'resources/service-worker-mixed-response-worker.js';
+ var frame;
+ return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
+ .then(function(registration) {
+ return wait_for_state(t, registration.installing, 'activated');
+ })
+ .then(function() { return with_iframe(SCOPE); })
+ .then(function(f) {
+ frame = f;
+ return Promise.all([
+ audio_test(f, 'same', '', '', true),
+ audio_test(f, 'same', 'gen', '', false),
+ audio_test(f, 'same', 'gen', 'gen', false),
+ audio_test(f, 'same', 'gen', 'same', false),
+ audio_test(f, 'same', 'gen', 'cross', false),
+ audio_test(f, 'same', 'same', '', true),
+ audio_test(f, 'same', 'same', 'gen', false),
+ audio_test(f, 'same', 'same', 'same', true),
+ audio_test(f, 'same', 'same', 'cross', false),
+ audio_test(f, 'same', 'cross', '', false),
+ audio_test(f, 'same', 'cross', 'gen', false),
+ audio_test(f, 'same', 'cross', 'same', false),
+ audio_test(f, 'same', 'cross', 'cross', false),
+ audio_test(f, 'cross', '', '', true),
+ audio_test(f, 'cross', 'gen', '', false),
+ audio_test(f, 'cross', 'gen', 'gen', false),
+ audio_test(f, 'cross', 'gen', 'same', false),
+ audio_test(f, 'cross', 'gen', 'cross', false),
+ audio_test(f, 'cross', 'same', '', false),
+ audio_test(f, 'cross', 'same', 'gen', false),
+ audio_test(f, 'cross', 'same', 'same', false),
+ audio_test(f, 'cross', 'same', 'cross', false),
+ audio_test(f, 'cross', 'cross', '', true),
+ audio_test(f, 'cross', 'cross', 'gen', false),
+ audio_test(f, 'cross', 'cross', 'same', false),
+ audio_test(f, 'cross', 'cross', 'cross', true)]);
+ })
+ .then(function() {
+ frame.remove();
+ return service_worker_unregister_and_done(t, SCOPE);
+ });
+ }, 'Tests for Service Worker generated mixed responses.');
+</script>
+</body>
« no previous file with comments | « LayoutTests/http/tests/serviceworker/chromium/resources/service-worker-mixed-response-worker.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698