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

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: 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 side-by-side diff with in-line comments
Download patch
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..703d4a6d7230d4a75807be652ac2e039699bc32c
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/chromium/service-worker-mixed-response.html
@@ -0,0 +1,133 @@
+<!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.
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.
+
+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 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.
+// response 'O'.
+// - 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.
+// 'service-worker-mixed-response.php' in the same origin server and returns
+// the response.
+// - If |first_byte| is 'cross', the SW fetches the request 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 genetates and returns the second byte
+// response 'g'.
+// - If |second_byte| is 'same', the SW fetches the request to
+// 'service-worker-mixed-response.php' in the same origin server and returns
+// the response.
+// - If |second_byte| is 'cross', the SW fetches the request 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 cross-origin and it is not same as the
+// origin of the first response, the response must be treated as an error.
falken 2015/07/07 03:23:11 Nice explanation.
+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.
+ 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 (should_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', '', true),
+ audio_test(f, 'same', 'gen', 'gen', true),
+ audio_test(f, 'same', 'gen', 'same', true),
+ audio_test(f, 'same', 'gen', 'cross', false),
+ audio_test(f, 'same', 'same', '', true),
+ audio_test(f, 'same', 'same', 'gen', true),
+ audio_test(f, 'same', 'same', 'same', true),
+ audio_test(f, 'same', 'same', 'cross', false),
+ audio_test(f, 'same', 'cross', '', true),
+ audio_test(f, 'same', 'cross', 'gen', true),
+ audio_test(f, 'same', 'cross', 'same', true),
+ audio_test(f, 'same', 'cross', 'cross', true),
+ 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', true),
+ audio_test(f, 'cross', 'cross', 'same', true),
+ audio_test(f, 'cross', 'cross', 'cross', true)]);
falken 2015/07/07 03:23:10 Wow, exhaustive test.
+ })
+ .then(function() {
+ frame.remove();
+ return service_worker_unregister_and_done(t, SCOPE);
+ });
+ }, 'Tests for Service Worker generated mixed responses.');
+</script>
+</body>

Powered by Google App Engine
This is Rietveld 408576698