| Index: third_party/WebKit/LayoutTests/http/tests/inspector/service-workers/service-workers-force-update-on-page-load.html
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/inspector/service-workers/service-workers-force-update-on-page-load.html b/third_party/WebKit/LayoutTests/http/tests/inspector/service-workers/service-workers-force-update-on-page-load.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8ec4799be8f555fc93f6b7f5494292ff29bc8ae4
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/http/tests/inspector/service-workers/service-workers-force-update-on-page-load.html
|
| @@ -0,0 +1,115 @@
|
| +<html>
|
| +<head>
|
| +<script src="../inspector-test.js"></script>
|
| +<script src="service-workers-test.js"></script>
|
| +<script src="../resources-test.js"></script>
|
| +<script>
|
| +
|
| +function loadIframe(resolve, reject, url)
|
| +{
|
| + var frame = document.createElement('iframe');
|
| + frame.src = url;
|
| + frame.onload = function() { resolve(frame.contentDocument.body.textContent); };
|
| + document.body.appendChild(frame);
|
| +}
|
| +
|
| +function test()
|
| +{
|
| + var scriptURL = "http://127.0.0.1:8000/inspector/service-workers/resources/force-update-on-page-load-worker.php";
|
| + var scope = "http://127.0.0.1:8000/inspector/service-workers/resources/service-worker-force-update-on-page-load/";
|
| +
|
| + function waitForWorkerActivated(scope) {
|
| + return new Promise(function(resolve) {
|
| + InspectorTest.addSniffer(WebInspector.ServiceWorkersView.prototype, "_updateRegistration", registrationUpdated, false);
|
| + function registrationUpdated(registration)
|
| + {
|
| + if (registration.scopeURL == scope) {
|
| + for (var version of registration.versions.values()) {
|
| + if (version.isRunning() && version.isActivated()) {
|
| + resolve();
|
| + return;
|
| + }
|
| + }
|
| + }
|
| + InspectorTest.addSniffer(WebInspector.ServiceWorkersView.prototype, "_updateRegistration", registrationUpdated, false);
|
| + }});
|
| + }
|
| + function installNewWorkerDetector(scope) {
|
| + var workerIdSet = {};
|
| + InspectorTest.addSniffer(WebInspector.ServiceWorkersView.prototype, "_updateRegistration", registrationUpdated, true);
|
| + function registrationUpdated(registration)
|
| + {
|
| + if (registration.scopeURL == scope) {
|
| + for (var version of registration.versions.values()) {
|
| + if (!workerIdSet[version.id] && version.isRunning() && version.isActivated()) {
|
| + workerIdSet[version.id] = true;
|
| + InspectorTest.addResult("A new ServiceWorker is activated.");
|
| + }
|
| + }
|
| + }
|
| + }
|
| + }
|
| + var lastTextContent = "";
|
| + installNewWorkerDetector(scope);
|
| + WebInspector.inspectorView.showPanel("sources")
|
| + .then(function(){
|
| + return waitForWorkerActivated(scope);
|
| + })
|
| + .then(function(){
|
| + InspectorTest.addResult("The first ServiceWorker is activated.");
|
| + return InspectorTest.invokePageFunctionPromise("loadIframe", [scope])
|
| + })
|
| + .then(function(textContent) {
|
| + InspectorTest.addResult("The first frame loaded.");
|
| + lastTextContent = textContent;
|
| + return InspectorTest.invokePageFunctionPromise("loadIframe", [scope]);
|
| + })
|
| + .then(function(textContent) {
|
| + InspectorTest.addResult("The second frame loaded.");
|
| + InspectorTest.assertEquals(lastTextContent, textContent, "The content of the second frame must be same as the first one.");
|
| + lastTextContent = textContent;
|
| + InspectorTest.addResult("Check \"Force update on page load\" check box");
|
| + WebInspector.panels.sources.sidebarPanes.serviceWorkers.expand();
|
| + for (var element of WebInspector.panels.sources.sidebarPanes.serviceWorkers._versionIdCheckBoxMap.values()) {
|
| + element.click();
|
| + }
|
| + return InspectorTest.invokePageFunctionPromise("loadIframe", [scope]);
|
| + })
|
| + .then(function(textContent) {
|
| + InspectorTest.addResult("The third frame loaded. The second worker must be activated before here.");
|
| + InspectorTest.assertTrue(lastTextContent != textContent, "The content of the third frame must be different from the second one.");
|
| + lastTextContent = textContent;
|
| + return InspectorTest.invokePageFunctionPromise("loadIframe", [scope]);
|
| + })
|
| + .then(function(textContent) {
|
| + InspectorTest.addResult("The fourth frame loaded. The third worker must be activated before here.");
|
| + InspectorTest.assertTrue(lastTextContent != textContent, "The content of the fourth frame must be different from the third one.");
|
| + lastTextContent = textContent;
|
| + InspectorTest.addResult("Uncheck \"Force update on page load\" check box");
|
| + for (var element of WebInspector.panels.sources.sidebarPanes.serviceWorkers._versionIdCheckBoxMap.values()) {
|
| + element.click();
|
| + }
|
| + return InspectorTest.invokePageFunctionPromise("loadIframe", [scope]);
|
| + })
|
| + .then(function(textContent) {
|
| + InspectorTest.addResult("The fifth frame loaded.");
|
| + InspectorTest.assertEquals(lastTextContent, textContent, "The content of the fifth frame must be same as the fourth one.");
|
| + InspectorTest.deleteServiceWorkerRegistration(scope);
|
| + InspectorTest.completeTest();
|
| + })
|
| + .catch(function(exception) {
|
| + InspectorTest.addResult("Error");
|
| + InspectorTest.addResult(exception);
|
| + InspectorTest.deleteServiceWorkerRegistration(scope);
|
| + InspectorTest.completeTest();
|
| + });
|
| + WebInspector.panels.resources.serviceWorkersTreeElement.select();
|
| + InspectorTest.registerServiceWorker(scriptURL, scope);
|
| +}
|
| +
|
| +</script>
|
| +</head>
|
| +<body onload="runTest()">
|
| +<p>Tests "Force update on page load" checkbox<p>
|
| +</body>
|
| +</html>
|
|
|