Bug 1200337 - Part 2: Add a Web Platform Test to check the visibility of default headers during interception, r=bkelly
authorMichael Layzell <michael@thelayzells.com>
Wed, 02 Sep 2015 12:49:37 -0400
changeset 294776 10343dcbe03d370fd57a261c6833c9928956bb33
parent 294775 86fd2ab7d9f62ea6a7cb85ac6f49e440d66ffe68
child 294777 ee0f02a2fc74fc1bd77f9b47119cbed05a882048
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1200337
milestone43.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 1200337 - Part 2: Add a Web Platform Test to check the visibility of default headers during interception, r=bkelly
testing/web-platform/mozilla/meta/MANIFEST.json
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/meta/MANIFEST.json
+++ b/testing/web-platform/mozilla/meta/MANIFEST.json
@@ -161,16 +161,22 @@
           }
         ],
         "service-workers/service-worker/fetch-frame-resource.https.html": [
           {
             "path": "service-workers/service-worker/fetch-frame-resource.https.html",
             "url": "/_mozilla/service-workers/service-worker/fetch-frame-resource.https.html"
           }
         ],
+        "service-workers/service-worker/fetch-header-visibility.https.html": [
+          {
+            "path": "service-workers/service-worker/fetch-header-visibility.https.html",
+            "url": "/_mozilla/service-workers/service-worker/fetch-header-visibility.https.html"
+          }
+        ],
         "service-workers/service-worker/fetch-mixed-content-to-inscope.https.html": [
           {
             "path": "service-workers/service-worker/fetch-mixed-content-to-inscope.https.html",
             "url": "/_mozilla/service-workers/service-worker/fetch-mixed-content-to-inscope.https.html"
           }
         ],
         "service-workers/service-worker/fetch-mixed-content-to-outscope.https.html": [
           {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/fetch-header-visibility.https.html
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<title>Service Worker: Visibility of headers during fetch.</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/get-host-info.sub.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<body>
+<script>
+  var worker = 'resources/fetch-rewrite-worker.js';
+  var path = base_path() + 'resources/fetch-access-control.py';
+  var host_info = get_host_info();
+
+  async_test(function(t) {
+    var scope = 'resources/fetch-header-visibility-iframe.html';
+    service_worker_unregister_and_register(t, worker, scope)
+      .then(function(reg) {
+        return wait_for_state(t, reg.installing, 'activated');
+      })
+      .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;
+          function onMessage(e) {
+            if (e.data == 'PASS') {
+              remaining--;
+              if (remaining == 0) {
+                resolve();
+              } else {
+                return;
+              }
+            } else {
+              reject(e.data);
+            }
+
+            window.removeEventListener('message', onMessage);
+          }
+          window.addEventListener('message', onMessage);
+        });
+      })
+      .then(function(result) {
+        return service_worker_unregister_and_done(t, scope);
+      })
+      .catch(unreached_rejection(t));
+  }, 'Visibility of defaulted headers during interception');
+</script>
+</body>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/resources/fetch-header-visibility-iframe.html
@@ -0,0 +1,35 @@
+<script src="../resources/get-host-info.sub.js"></script>
+<script src="test-helpers.sub.js?pipe=sub"></script>
+<script>
+  var host_info = get_host_info();
+  var uri = document.location + '?check-ua-header';
+
+  var headers = new Headers();
+  headers.set('User-Agent', 'custom_ua');
+
+  // Check the custom UA case
+  fetch(uri, { headers: headers }).then(function(response) {
+    return response.text();
+  }).then(function(text) {
+    if (text == 'custom_ua') {
+      parent.postMessage('PASS', '*');
+    } else {
+      parent.postMessage('withUA FAIL - expected "custom_ua", got "' + text + '"', '*');
+    }
+  }).catch(function(err) {
+    parent.postMessage('withUA FAIL - unexpected error: ' + err, '*');
+  });
+
+  // Check the default UA case
+  fetch(uri, {}).then(function(response) {
+    return response.text();
+  }).then(function(text) {
+    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, '*');
+  });
+</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
@@ -42,21 +42,32 @@ self.addEventListener('fetch', function(
     }
     if (params['generate-png']) {
       var binary = atob(
           'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAA' +
           'RnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAAhSURBVDhPY3wro/Kf' +
           'gQLABKXJBqMGjBoAAqMGDLwBDAwAEsoCTFWunmQAAAAASUVORK5CYII=');
       var array = new Uint8Array(binary.length);
       for(var i = 0; i < binary.length; i++) {
-        array[i] = binary.charCodeAt(i)
+        array[i] = binary.charCodeAt(i);
       };
       event.respondWith(new Response(new Blob([array], {type: 'image/png'})));
       return;
     }
+    if (params['check-ua-header']) {
+      var ua = event.request.headers.get('User-Agent');
+      if (ua) {
+        // 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;
+    }
     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) {