зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1169819 Add browser chrome test to validate SW force refresh. r=ehsan a=kwierso
This commit is contained in:
Родитель
11670de4f9
Коммит
3b1c0e6220
|
@ -122,6 +122,10 @@ MOCHITEST_CHROME_MANIFESTS += [
|
|||
'test/serviceworkers/chrome.ini'
|
||||
]
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += [
|
||||
'test/serviceworkers/browser.ini',
|
||||
]
|
||||
|
||||
XPCSHELL_TESTS_MANIFESTS += ['test/xpcshell/xpcshell.ini']
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[DEFAULT]
|
||||
support-files =
|
||||
browser_base_force_refresh.html
|
||||
browser_cached_force_refresh.html
|
||||
browser_force_refresh_worker.js
|
||||
|
||||
[browser_force_refresh.js]
|
||||
skip-if = e10s
|
|
@ -0,0 +1,30 @@
|
|||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
addEventListener('load', function(event) {
|
||||
navigator.serviceWorker.register('browser_force_refresh_worker.js').then(function(swr) {
|
||||
if (!swr) {
|
||||
return;
|
||||
}
|
||||
var custom = new Event('base-register', { bubbles: true });
|
||||
document.dispatchEvent(custom);
|
||||
});
|
||||
|
||||
navigator.serviceWorker.ready.then(function() {
|
||||
var custom = new Event('base-sw-ready', { bubbles: true });
|
||||
document.dispatchEvent(custom);
|
||||
});
|
||||
|
||||
var custom = new Event('base-load', { bubbles: true });
|
||||
document.dispatchEvent(custom);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,17 @@
|
|||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
addEventListener('load', function(event) {
|
||||
var custom = new Event('cached-load', { bubbles: true });
|
||||
document.dispatchEvent(custom);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,56 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
var gTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/",
|
||||
"http://mochi.test:8888/")
|
||||
|
||||
function refresh() {
|
||||
EventUtils.synthesizeKey('R', { ctrlKey: true });
|
||||
}
|
||||
|
||||
function forceRefresh() {
|
||||
EventUtils.synthesizeKey('R', { ctrlKey: true, shiftKey: true });
|
||||
}
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
SpecialPowers.pushPrefEnv({'set': [['dom.serviceWorkers.enabled', true],
|
||||
['dom.serviceWorkers.exemptFromPerDomainMax', true],
|
||||
['dom.serviceWorkers.testing.enabled', true],
|
||||
['dom.caches.enabled', true]]},
|
||||
function() {
|
||||
var url = gTestRoot + 'browser_base_force_refresh.html';
|
||||
var tab = gBrowser.addTab(url);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
ok(true);
|
||||
|
||||
var cachedLoad = false;
|
||||
|
||||
function eventHandler(event) {
|
||||
if (event.type === 'base-load') {
|
||||
if (cachedLoad) {
|
||||
gBrowser.removeTab(tab);
|
||||
executeSoon(finish);
|
||||
}
|
||||
} else if (event.type === 'base-register') {
|
||||
ok(!cachedLoad, 'cached load should not occur before base register');
|
||||
refresh();
|
||||
} else if (event.type === 'base-sw-ready') {
|
||||
ok(!cachedLoad, 'cached load should not occur before base ready');
|
||||
refresh();
|
||||
} else if (event.type === 'cached-load') {
|
||||
ok(!cachedLoad, 'cached load should not occur twice');
|
||||
cachedLoad = true;
|
||||
forceRefresh();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
addEventListener('base-load', eventHandler, true, true);
|
||||
addEventListener('base-register', eventHandler, true, true);
|
||||
addEventListener('base-sw-ready', eventHandler, true, true);
|
||||
addEventListener('cached-load', eventHandler, true, true);
|
||||
});
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
var name = 'browserRefresherCache';
|
||||
|
||||
self.addEventListener('install', function(event) {
|
||||
event.waitUntil(
|
||||
Promise.all([caches.open(name),
|
||||
fetch('./browser_cached_force_refresh.html')]).then(function(results) {
|
||||
var cache = results[0];
|
||||
var response = results[1];
|
||||
return cache.put('./browser_base_force_refresh.html', response);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', function (event) {
|
||||
event.respondWith(
|
||||
caches.open(name).then(function(cache) {
|
||||
return cache.match(event.request);
|
||||
}).then(function(response) {
|
||||
return response || fetch(event.request);
|
||||
})
|
||||
);
|
||||
});
|
Загрузка…
Ссылка в новой задаче