Add MIME sniffing for SW test and make redirect tests not to rely on MIME sniffing

Bug: 771118, 764224
Change-Id: Ia7a942644736c21412535a9d01bb183794c202cb
Reviewed-on: https://chromium-review.googlesource.com/697484
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Tsuyoshi Horo <horo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#506004}
diff --git a/service-workers/service-worker/mime-sniffing.https.html b/service-workers/service-worker/mime-sniffing.https.html
new file mode 100644
index 0000000..8175bcd
--- /dev/null
+++ b/service-workers/service-worker/mime-sniffing.https.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<title>Service Worker: MIME sniffing</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<script>
+promise_test(t => {
+    const SCOPE = 'resources/blank.html?mime-sniffing';
+    const SCRIPT = 'resources/mime-sniffing-worker.js';
+    return service_worker_unregister_and_register(t, SCRIPT, SCOPE)
+      .then(registration => {
+          add_completion_callback(() => registration.unregister());
+          return wait_for_state(t, registration.installing, 'activated');
+        })
+      .then(_ => with_iframe(SCOPE))
+      .then(frame => {
+          add_completion_callback(() => frame.remove());
+          assert_equals(frame.contentWindow.document.body.innerText, 'test');
+          const h1 = frame.contentWindow.document.getElementById('testid');
+          assert_equals(h1.innerText,'test');
+        });
+  }, 'The response from service worker should be correctly MIME siniffed.');
+</script>
diff --git a/service-workers/service-worker/resources/mime-sniffing-worker.js b/service-workers/service-worker/resources/mime-sniffing-worker.js
new file mode 100644
index 0000000..0466280
--- /dev/null
+++ b/service-workers/service-worker/resources/mime-sniffing-worker.js
@@ -0,0 +1,5 @@
+self.addEventListener('fetch', function(event) {
+    var res = new Response('<!DOCTYPE html>\n<h1 id=\'testid\'>test</h1>');
+    res.headers.delete('content-type');
+    event.respondWith(res);
+  });
diff --git a/service-workers/service-worker/resources/navigation-redirect-out-scope.py b/service-workers/service-worker/resources/navigation-redirect-out-scope.py
index 0cd5ef1..907cefa 100644
--- a/service-workers/service-worker/resources/navigation-redirect-out-scope.py
+++ b/service-workers/service-worker/resources/navigation-redirect-out-scope.py
@@ -8,7 +8,7 @@
     if "noLocationRedirect" in request.GET:
         status = 302
 
-    return status, [], '''
+    return status, [("content-type", "text/html")], '''
 <!DOCTYPE html>
 <script>
   window.parent.postMessage(
diff --git a/service-workers/service-worker/resources/navigation-redirect-scope1.py b/service-workers/service-worker/resources/navigation-redirect-scope1.py
index 0cd5ef1..907cefa 100644
--- a/service-workers/service-worker/resources/navigation-redirect-scope1.py
+++ b/service-workers/service-worker/resources/navigation-redirect-scope1.py
@@ -8,7 +8,7 @@
     if "noLocationRedirect" in request.GET:
         status = 302
 
-    return status, [], '''
+    return status, [("content-type", "text/html")], '''
 <!DOCTYPE html>
 <script>
   window.parent.postMessage(
diff --git a/service-workers/service-worker/resources/navigation-redirect-scope2.py b/service-workers/service-worker/resources/navigation-redirect-scope2.py
index 0cd5ef1..907cefa 100644
--- a/service-workers/service-worker/resources/navigation-redirect-scope2.py
+++ b/service-workers/service-worker/resources/navigation-redirect-scope2.py
@@ -8,7 +8,7 @@
     if "noLocationRedirect" in request.GET:
         status = 302
 
-    return status, [], '''
+    return status, [("content-type", "text/html")], '''
 <!DOCTYPE html>
 <script>
   window.parent.postMessage(