Bug 1217501 P3 Check Accept header visibility in service worker fetch event. r=ehsan
☠☠ backed out by 6c7c983bce46 ☠ ☠
authorBen Kelly <ben@wanderview.com>
Mon, 26 Oct 2015 08:25:16 -0700
changeset 304683 f00f079f712ba026c008a4f339a2e8bc8de996c3
parent 304682 86ac4feb0e38af9001d73b9b011427390a53e210
child 304684 0289fda8ff6b20da693f79e88f3a0bc9fc9747f9
push id1001
push userraliiev@mozilla.com
push dateMon, 18 Jan 2016 19:06:03 +0000
treeherdermozilla-release@8b89261f3ac4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1217501
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1217501 P3 Check Accept header visibility in service worker fetch event. r=ehsan
testing/web-platform/mozilla/tests/service-workers/service-worker/fetch-header-visibility.https.html
testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-header-visibility-iframe.html
testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-rewrite-worker.js
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/fetch-header-visibility.https.html
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/fetch-header-visibility.https.html
@@ -18,17 +18,17 @@
       })
       .then(function() {
         var frame = document.createElement('iframe');
         frame.src = scope;
         document.body.appendChild(frame);
 
         // Resolve a promise when we recieve 2 success messages
         return new Promise(function(resolve, reject) {
-          var remaining = 2;
+          var remaining = 4;
           function onMessage(e) {
             if (e.data == 'PASS') {
               remaining--;
               if (remaining == 0) {
                 resolve();
               } else {
                 return;
               }
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-header-visibility-iframe.html
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-header-visibility-iframe.html
@@ -27,9 +27,40 @@
     if (text == 'NO_UA') {
       parent.postMessage('PASS', '*');
     } else {
       parent.postMessage('noUA FAIL - expected "NO_UA", got "' + text + '"', '*');
     }
   }).catch(function(err) {
     parent.postMessage('noUA FAIL - unexpected error: ' + err, '*');
   });
+
+  var uri = document.location + '?check-accept-header';
+  var headers = new Headers();
+  headers.set('Accept', 'hmm');
+
+  // Check for custom accept header
+  fetch(uri, { headers: headers }).then(function(response) {
+    return response.text();
+  }).then(function(text) {
+    if (text === headers.get('Accept')) {
+      parent.postMessage('PASS', '*');
+    } else {
+      parent.postMessage('custom accept FAIL - expected ' + headers.get('Accept') +
+                         ' got "' + text + '"', '*');
+    }
+  }).catch(function(err) {
+    parent.postMessage('custom accept FAIL - unexpected error: ' + err, '*');
+  });
+
+  // Check for default accept header
+  fetch(uri).then(function(response) {
+    return response.text();
+  }).then(function(text) {
+    if (text === '*/*') {
+      parent.postMessage('PASS', '*');
+    } else {
+      parent.postMessage('accept FAIL - expected */* got "' + text + '"', '*');
+    }
+  }).catch(function(err) {
+    parent.postMessage('accept FAIL - unexpected error: ' + err, '*');
+  });
 </script>
--- a/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-rewrite-worker.js
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-rewrite-worker.js
@@ -58,16 +58,24 @@ self.addEventListener('fetch', function(
         // We have a user agent!
         event.respondWith(new Response(new Blob([ua])));
       } else {
         // We don't have a user-agent!
         event.respondWith(new Response(new Blob(["NO_UA"])));
       }
       return;
     }
+    if (params['check-accept-header']) {
+      var accept = event.request.headers.get('Accept');
+      if (accept) {
+        event.respondWith(new Response(accept));
+      } else {
+        event.respondWith(new Response('NO_ACCEPT'));
+      }
+    }
     event.respondWith(new Promise(function(resolve, reject) {
         var request = event.request;
         if (url) {
           request = new Request(url, init);
         }
         fetch(request).then(function(response) {
           var expectedType = params['expected_type'];
           if (expectedType && response.type !== expectedType) {