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

Unified Diff: LayoutTests/http/tests/serviceworker/chromium/resources/service-worker-mixed-response-worker.js

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
Index: LayoutTests/http/tests/serviceworker/chromium/resources/service-worker-mixed-response-worker.js
diff --git a/LayoutTests/http/tests/serviceworker/chromium/resources/service-worker-mixed-response-worker.js b/LayoutTests/http/tests/serviceworker/chromium/resources/service-worker-mixed-response-worker.js
new file mode 100644
index 0000000000000000000000000000000000000000..39c81da2092e0e119f7ebba486956d7e3c1a0140
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/chromium/resources/service-worker-mixed-response-worker.js
@@ -0,0 +1,67 @@
+importScripts('../../../resources/get-host-info.js');
+
+var HOST_INFO = get_host_info();
+var PARTIAL_RESOURCE_PATH =
+ '/serviceworker/chromium/resources/service-worker-mixed-response.php';
+
+function get_query_params(url) {
+ var search = (new URL(url)).search;
+ if (!search) {
+ return {};
+ }
+ var ret = {};
+ var params = search.substring(1).split('&');
+ params.forEach(function(param) {
+ var element = param.split('=');
+ ret[decodeURIComponent(element[0])] = decodeURIComponent(element[1]);
+ });
+ return ret;
+}
+
+function generate_partial_byte_response(position) {
+ return new Response(
+ 'Ogg'.substr(position, 1),
+ {
+ status: 206,
+ headers: {
+ 'content-type': 'audio/ogg',
+ // 12983 is the file size of media/content/silence.oga.
+ 'content-range': 'bytes ' + position + '-' + position + '/12983'
+ }
+ });
+}
+
+function fetch_same_origin_partial_resource(position) {
+ return fetch(HOST_INFO['HTTP_ORIGIN'] + PARTIAL_RESOURCE_PATH +
+ '?position=' + position)
+}
+
+function fetch_cross_origin_partial_resource(position) {
+ return fetch(HOST_INFO['HTTP_REMOTE_ORIGIN'] + PARTIAL_RESOURCE_PATH +
+ '?position=' + position)
+}
+
+self.addEventListener('fetch', function(event) {
+ if (event.request.url.indexOf('blank.html') != -1) {
+ // The request is for the page load.
+ return;
+ }
+ var params = get_query_params(event.request.url);
+ if (event.request.headers.get('range') == 'bytes=0-') {
+ if (params['SW_FIRST'] == 'gen') {
+ event.respondWith(generate_partial_byte_response(0));
+ } else if (params['SW_FIRST'] == 'same') {
+ event.respondWith(fetch_same_origin_partial_resource(0));
+ } else if (params['SW_FIRST'] == 'cross') {
+ event.respondWith(fetch_cross_origin_partial_resource(0));
+ }
+ } else if (event.request.headers.get('range') == 'bytes=1-') {
+ if (params['SW_SECOND'] == 'gen') {
+ event.respondWith(generate_partial_byte_response(1));
+ } else if (params['SW_SECOND'] == 'same') {
+ event.respondWith(fetch_same_origin_partial_resource(1));
+ } else if (params['SW_SECOND'] == 'cross') {
+ event.respondWith(fetch_cross_origin_partial_resource(1));
+ }
+ }
+ });

Powered by Google App Engine
This is Rietveld 408576698