Backed out changeset 51468c2a2371 (bug 1353638)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Mon, 10 Apr 2017 14:54:21 +0200
changeset 379513 e4983d375870b3174ceee9823fa08aa60a4ba37b
parent 379512 2b1b20e6907ecc218cc19d5c6d976214edbdbe1c
child 379514 0d25d01521602c090c320eb85d04c61cf005a041
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1353638
milestone53.0
backs out51468c2a2371bac3093f108dacc5d04e06cfeb86
Backed out changeset 51468c2a2371 (bug 1353638)
testing/web-platform/meta/MANIFEST.json
testing/web-platform/tests/service-workers/service-worker/registration-useCache.https.html
testing/web-platform/tests/service-workers/service-worker/resources/update-max-aged-worker-imported-script.py
testing/web-platform/tests/service-workers/service-worker/resources/update-max-aged-worker.py
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -60146,16 +60146,26 @@
      {}
     ]
    ],
    "service-workers/service-worker/resources/unregister-controller-page.html": [
     [
      {}
     ]
    ],
+   "service-workers/service-worker/resources/update-max-aged-worker-imported-script.py": [
+    [
+     {}
+    ]
+   ],
+   "service-workers/service-worker/resources/update-max-aged-worker.py": [
+    [
+     {}
+    ]
+   ],
    "service-workers/service-worker/resources/update-nocookie-worker.py": [
     [
      {}
     ]
    ],
    "service-workers/service-worker/resources/update-recovery-worker.py": [
     [
      {}
@@ -117172,16 +117182,22 @@
     ]
    ],
    "service-workers/service-worker/registration-service-worker-attributes.https.html": [
     [
      "/service-workers/service-worker/registration-service-worker-attributes.https.html",
      {}
     ]
    ],
+   "service-workers/service-worker/registration-useCache.https.html": [
+    [
+     "/service-workers/service-worker/registration-useCache.https.html",
+     {}
+    ]
+   ],
    "service-workers/service-worker/registration.https.html": [
     [
      "/service-workers/service-worker/registration.https.html",
      {}
     ]
    ],
    "service-workers/service-worker/rejections.https.html": [
     [
@@ -196849,16 +196865,24 @@
   "service-workers/service-worker/resources/testharness-helpers.js": [
    "15f29256ea90b9c4f91411e570d5dd1979ff73b2",
    "support"
   ],
   "service-workers/service-worker/resources/unregister-controller-page.html": [
    "feae7f538da58d45e38f6f26da5ce6af0c91857f",
    "support"
   ],
+  "service-workers/service-worker/resources/update-max-aged-worker-imported-script.py": [
+   "23fa131d0d35e0e5394100b4bfaa5ebf1a349b4b",
+   "support"
+  ],
+  "service-workers/service-worker/resources/update-max-aged-worker.py": [
+   "384ab2835ccb57316d59a911af57ba8638b26ad0",
+   "support"
+  ],
   "service-workers/service-worker/resources/update-nocookie-worker.py": [
    "0790be63a2023cccf03f84b2e5c8f5daa7958dd0",
    "support"
   ],
   "service-workers/service-worker/resources/update-recovery-worker.py": [
    "44f6bb6b7ce13d1c2f9b073c649a0ea2218c07ad",
    "support"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/registration-useCache.https.html
@@ -0,0 +1,223 @@
+<!DOCTYPE html>
+<title>Service Worker: Registration-useCache</title>
+<script src="/resources/testharness.js"></script>
+<script src="resources/testharness-helpers.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<script>
+
+function registerFirstServiceWorker(test, script, scope, useCache) {
+    var swr, sw;
+
+    var setting = {scope: scope};
+    if (useCache !== undefined) {
+        setting['useCache'] = useCache;
+    }
+
+    return Promise.resolve()
+        .then(() => navigator.serviceWorker.register(script, setting))
+        .then(registration => swr = registration)
+
+        .then(() => wait_for_update(test, swr))
+        .then(worker => sw = worker)
+
+        .then(() => getMessageFromServiceWorker(sw, 'normal'))
+        .then(() => wait_for_state(test, sw, 'activated'))
+        .then(() => assert_true((!!swr.active &&
+                                 !swr.waiting &&
+                                 !swr.installing),
+                                ('The active SW should be the only SW. ' +
+                                 '(a: ' + !!swr.active +
+                                 ',w: ' + !swr.waiting +
+                                 ',i: ' + !swr.installing + ')')))
+        .then(() => swr);
+}
+
+function getMessageFromServiceWorker(sw, httpRequestType, oldValues) {
+    var mainResolveFunction, importedResolveFunction;
+    var promises = [
+        new Promise(function(resolve) {mainResolveFunction = resolve}),
+        new Promise(function(resolve) {importedResolveFunction = resolve})
+    ];
+
+    var messageChannel = new MessageChannel();
+    messageChannel.port1.onmessage = e => {
+        if (httpRequestType) {
+          assert_equals(e.data.type, httpRequestType,
+                        "HTTP request type check.");
+        }
+
+        var compareOldValue = (httpRequestType === 'revalidate') && oldValues;
+        switch(e.data.from) {
+            case 'main':
+                if (compareOldValue) {
+                    assert_not_equals(e.data.value, oldValues[0],
+                                      'Values shouldn\'t be the same');
+                }
+                mainResolveFunction(e.data.value);
+                break;
+            case 'imported':
+                if (compareOldValue) {
+                    assert_not_equals(e.data.value, oldValues[1],
+                                      'Values shouldn\'t be the same');
+                }
+                importedResolveFunction(e.data.value);
+                break;
+        }
+    };
+
+    sw.postMessage({port: messageChannel.port2}, [messageChannel.port2]);
+    return Promise.all(promises);
+}
+
+function testAction(test, registration, action, shouldCreateSW) {
+    var testFunction = shouldCreateSW ? testActionDoesCreateSW
+                                      : testActionDoesNotCreateSW;
+
+    return Promise.resolve()
+        .then(() => testFunction(registration, action, test))
+        .then(() => registration);
+}
+
+function testActionDoesCreateSW(registration, action, test) {
+    var oldValues;
+
+    return Promise.resolve()
+        .then(() => getMessageFromServiceWorker(registration.active))
+        .then(values => oldValues = values)
+
+        .then(() => action())
+        .then(() => wait_for_update(test, registration))
+        .then(worker => getMessageFromServiceWorker(worker,
+                                                    'revalidate',
+                                                    oldValues));
+}
+
+function testActionDoesNotCreateSW(registration, action) {
+    return Promise.resolve()
+        .then(() => action())
+        .then(() => assert_true((!!registration.active &&
+                                 !registration.waiting &&
+                                 !registration.installing),
+                                ('The active SW should still be the only SW. ' +
+                                 '(a: ' + !!registration.active +
+                                 ',w: ' + !registration.waiting +
+                                 ',i: ' + !registration.installing + ')')));
+}
+
+promise_test(function(t) {
+    var script = 'resources/update-max-aged-worker.py' +
+                 '?Test=Test_with_useCache_default';
+    var scope = 'resources/blank.html';
+
+    return Promise.resolve()
+        .then(() => registerFirstServiceWorker(t, script, scope))
+        .then(r => testAction(t, r, r.update.bind(r), true))
+
+        // Tear down
+        .then(() => service_worker_unregister_and_done(t, scope));
+}, 'Test with useCache: default');
+
+promise_test(function(t) {
+    var script = 'resources/update-max-aged-worker.py' +
+                 '?Test=Test_with_useCache_true';
+    var scope = 'resources/blank.html';
+
+    return Promise.resolve()
+        .then(() => registerFirstServiceWorker(t, script, scope, true))
+        .then(r => testAction(t, r, r.update.bind(r), false))
+
+        // Tear down
+        .then(() => service_worker_unregister_and_done(t, scope));
+}, 'Test with useCache: true');
+
+promise_test(function(t) {
+    var script = 'resources/update-max-aged-worker.py' +
+                 '?Test=Test_with_useCache_false';
+    var scope = 'resources/blank.html';
+
+    return Promise.resolve()
+        .then(() => registerFirstServiceWorker(t, script, scope, false))
+        .then(r => testAction(t, r, r.update.bind(r), true))
+
+        // Tear down
+        .then(() => service_worker_unregister_and_done(t, scope));
+  }, 'Test with useCache: false');
+
+promise_test(function(t) {
+    var script = 'resources/update-max-aged-worker.py' +
+                 '?Test=Consecutive_registrations_with_useCache_settings_false_false';
+    var scope = 'resources/blank.html';
+
+    return Promise.resolve()
+        .then(() => registerFirstServiceWorker(t, script, scope, false))
+        .then(r => {
+            var action = navigator.serviceWorker.register.bind(
+                navigator.serviceWorker, script, {scope: scope,
+                                                  useCache: false});
+            return testAction(t, r, action, false);
+        })
+
+        // Tear down
+        .then(() => service_worker_unregister_and_done(t, scope))
+}, "Consecutive registrations with useCache settings(false, false)");
+
+promise_test(function(t) {
+    var script = 'resources/update-max-aged-worker.py' +
+                 '?Test=Consecutive_registrations_with_useCache_settings_false_true';
+    var scope = 'resources/blank.html';
+
+    return Promise.resolve()
+        .then(() => registerFirstServiceWorker(t, script, scope, false))
+        .then(r => testAction(t, r, r.update.bind(r), true))
+        .then(r => {
+            var action = navigator.serviceWorker.register.bind(
+                navigator.serviceWorker, script, {scope: scope,
+                                                  useCache: true});
+            return testAction(t, r, action, false);
+        })
+        .then(r => testAction(t, r, r.update.bind(r), false))
+
+        // Tear down
+        .then(() => service_worker_unregister_and_done(t, scope))
+}, "Consecutive registrations with useCache settings(false, true)");
+
+promise_test(function(t) {
+    var script = 'resources/update-max-aged-worker.py' +
+                 '?Test=Consecutive_registrations_with_useCache_settings_true_false';
+    var scope = 'resources/blank.html';
+
+    return Promise.resolve()
+        .then(() => registerFirstServiceWorker(t, script, scope, true))
+        .then(r => testAction(t, r, r.update.bind(r), false))
+        .then(r => {
+            var action = navigator.serviceWorker.register.bind(
+                navigator.serviceWorker, script, {scope: scope,
+                                                  useCache: false});
+            return testAction(t, r, action, true);
+        })
+        .then(r => testAction(t, r, r.update.bind(r), true))
+
+        // Tear down
+        .then(() => service_worker_unregister_and_done(t, scope));
+}, "Consecutive registrations with useCache settings(true, false)");
+
+promise_test(function(t) {
+    var script = 'resources/update-max-aged-worker.py' +
+                 '?Test=Consecutive_registrations_with_useCache_settings_true_true';
+    var scope = 'resources/blank.html';
+
+    return Promise.resolve()
+        .then(() => registerFirstServiceWorker(t, script, scope, true))
+        .then(r => {
+            var action = navigator.serviceWorker.register.bind(
+                navigator.serviceWorker, script, {scope: scope,
+                                                  useCache: true});
+            return testAction(t, r, action, false);
+        })
+
+        // Tear down
+        .then(() => service_worker_unregister_and_done(t, scope))
+}, "Consecutive registrations with useCache settings(true, true)");
+
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/resources/update-max-aged-worker-imported-script.py
@@ -0,0 +1,22 @@
+import time
+
+def main(request, response):
+    headers = [('Cache-Control', 'max-age=86400'),
+               ('Content-Type', 'application/javascript'),
+               ('Last-Modified', time.strftime("%a, %d %b %Y %H:%M:%S GMT",
+                                               time.gmtime()))]
+
+
+    revalidate = request.headers.has_key('if-modified-since');
+
+    body = '''
+    self.addEventListener('message', function(e) {
+        e.data.port.postMessage({
+            from: "imported",
+            type: "%s",
+            value: %s
+        });
+    });
+    ''' % ('revalidate' if revalidate else 'normal', time.time())
+
+    return headers, body
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/service-workers/service-worker/resources/update-max-aged-worker.py
@@ -0,0 +1,26 @@
+import time
+
+def main(request, response):
+    headers = [('Content-Type', 'application/javascript'),
+               ('Cache-Control', 'max-age=86400'),
+               ('Last-Modified', time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime()))]
+
+    test = '';
+    if 'Test' in request.GET:
+      test = request.GET['Test'];
+
+    revalidate = request.headers.has_key('if-modified-since');
+
+    body = '''
+    importScripts('update-max-aged-worker-imported-script.py?Test=%s');
+
+    self.addEventListener('message', function(e) {
+        e.data.port.postMessage({
+            from: "main",
+            type: "%s",
+            value: %s
+        });
+    });
+    ''' % (test, 'revalidate' if revalidate else 'normal', time.time())
+
+    return headers, body