gecko-dev/dom/push/test/test_try_registering_offline_disabled.html
Andrew McCreight 5dec0e0beb Bug 1432992, part 1 - Remove definitions of Ci, Cr, Cc, and Cu. r=florian
This patch was autogenerated by my decomponents.py

It covers almost every file with the extension js, jsm, html, py,
xhtml, or xul.

It removes blank lines after removed lines, when the removed lines are
preceded by either blank lines or the start of a new block. The "start
of a new block" is defined fairly hackily: either the line starts with
//, ends with */, ends with {, <![CDATA[, """ or '''. The first two
cover comments, the third one covers JS, the fourth covers JS embedded
in XUL, and the final two cover JS embedded in Python. This also
applies if the removed line was the first line of the file.

It covers the pattern matching cases like "var {classes: Cc,
interfaces: Ci, utils: Cu, results: Cr} = Components;". It'll remove
the entire thing if they are all either Ci, Cr, Cc or Cu, or it will
remove the appropriate ones and leave the residue behind. If there's
only one behind, then it will turn it into a normal, non-pattern
matching variable definition. (For instance, "const { classes: Cc,
Constructor: CC, interfaces: Ci, utils: Cu } = Components" becomes
"const CC = Components.Constructor".)

MozReview-Commit-ID: DeSHcClQ7cG

--HG--
extra : rebase_source : d9c41878036c1ef7766ef5e91a7005025bc1d72b
2018-02-06 09:36:57 -08:00

304 lines
9.4 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
Bug 1150812: Try to register when serviced if offline or connection is disabled.
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/
-->
<head>
<title>Test for Bug 1150812</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/dom/push/test/test_utils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
</head>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1150812">Mozilla Bug 1150812</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script class="testbody" type="text/javascript">
function debug(str) {
// console.log(str + "\n");
}
function registerServiceWorker() {
return navigator.serviceWorker.register("worker.js" + "?" + (Math.random()), {scope: "."})
.then(swr => waitForActive(swr));
}
function unregister(swr) {
return swr.unregister()
.then(result => {
ok(result, "Unregister should return true.");
}, err => {
dump("Unregistering the SW failed with " + err + "\n");
throw err;
});
}
function subscribe(swr) {
return swr.pushManager.subscribe()
.then(sub => {
ok(true, "successful registered for push notification");
return sub;
}, err => {
ok(false, "could not register for push notification");
throw err;
});
}
function subscribeFail(swr) {
return new Promise((res, rej) => {
swr.pushManager.subscribe()
.then(sub => {
ok(false, "successful registered for push notification");
throw "Should fail";
}, err => {
ok(true, "could not register for push notification");
res(swr);
});
});
}
function getEndpointExpectNull(swr) {
return swr.pushManager.getSubscription()
.then(pushSubscription => {
ok(pushSubscription == null, "getEndpoint should return null when app not subscribed.");
}, err => {
ok(false, "could not register for push notification");
throw err;
});
}
function getEndpoint(swr, subOld) {
return swr.pushManager.getSubscription()
.then(sub => {
ok(subOld.endpoint == sub.endpoint, "getEndpoint - Got the same endpoint back.");
return sub;
}, err => {
ok(false, "could not register for push notification");
throw err;
});
}
// Load chrome script to change offline status in the
// parent process.
var chromeScript = SpecialPowers.loadChromeScript(_ => {
var ioService = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
addMessageListener("change-status", function(offline) {
ioService.offline = offline;
});
});
function offlineObserver(res) {
this._res = res;
}
offlineObserver.prototype = {
_res: null,
observe: function(subject, topic, data) {
debug("observe: " + subject + " " + topic + " " + data);
if (topic === "network:offline-status-changed") {
var obsService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
obsService.removeObserver(this, topic);
this._res(null);
}
}
}
function changeOfflineState(offline) {
return new Promise(function(res, rej) {
var obsService = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
.getService(SpecialPowers.Ci.nsIObserverService);
obsService.addObserver(SpecialPowers.wrapCallbackObject(new offlineObserver(res)),
"network:offline-status-changed");
chromeScript.sendAsyncMessage("change-status", offline);
});
}
function changePushServerConnectionEnabled(enable) {
debug("changePushServerConnectionEnabled");
SpecialPowers.setBoolPref("dom.push.connection.enabled", enable);
}
function unsubscribe(sub) {
return sub.unsubscribe()
.then(_ => {ok(true, "Unsubscribed!");});
}
// go offline then go online
function runTest1() {
return registerServiceWorker()
.then(swr =>
getEndpointExpectNull(swr)
.then(_ => changeOfflineState(true))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changeOfflineState(false))
.then(_ => subscribe(swr))
.then(sub => getEndpoint(swr, sub)
.then(sub => unsubscribe(sub))
)
.then(_ => getEndpointExpectNull(swr))
.then(_ => unregister(swr))
)
.catch(err => {
ok(false, "Some test failed with error " + err);
})
}
// disable - enable push connection.
function runTest2() {
return registerServiceWorker()
.then(swr =>
getEndpointExpectNull(swr)
.then(_ => changePushServerConnectionEnabled(false))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changePushServerConnectionEnabled(true))
.then(_ => subscribe(swr))
.then(sub => getEndpoint(swr, sub)
.then(sub => unsubscribe(sub))
)
.then(_ => getEndpointExpectNull(swr))
.then(_ => unregister(swr))
)
.catch(err => {
ok(false, "Some test failed with error " + err);
})
}
// go offline - disable - enable - go online
function runTest3() {
return registerServiceWorker()
.then(swr =>
getEndpointExpectNull(swr)
.then(_ => changeOfflineState(true))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changePushServerConnectionEnabled(false))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changePushServerConnectionEnabled(true))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changeOfflineState(false))
.then(_ => subscribe(swr))
.then(sub => getEndpoint(swr, sub)
.then(sub => unsubscribe(sub))
)
.then(_ => getEndpointExpectNull(swr))
.then(_ => unregister(swr))
)
.catch(err => {
ok(false, "Some test failed with error " + err);
})
}
// disable - offline - online - enable.
function runTest4() {
return registerServiceWorker()
.then(swr =>
getEndpointExpectNull(swr)
.then(_ => changePushServerConnectionEnabled(false))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changeOfflineState(true))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changeOfflineState(false))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changePushServerConnectionEnabled(true))
.then(_ => subscribe(swr))
.then(sub => getEndpoint(swr, sub)
.then(sub => unsubscribe(sub))
)
.then(_ => getEndpointExpectNull(swr))
.then(_ => unregister(swr))
)
.catch(err => {
ok(false, "Some test failed with error " + err);
})
}
// go offline - disable - go online - enable
function runTest5() {
return registerServiceWorker()
.then(swr =>
getEndpointExpectNull(swr)
.then(_ => changeOfflineState(true))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changePushServerConnectionEnabled(false))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changeOfflineState(false))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changePushServerConnectionEnabled(true))
.then(_ => subscribe(swr))
.then(sub => getEndpoint(swr, sub)
.then(sub => unsubscribe(sub))
)
.then(_ => getEndpointExpectNull(swr))
.then(_ => unregister(swr))
)
.catch(err => {
ok(false, "Some test failed with error " + err);
})
}
// disable - go offline - enable - go online.
function runTest6() {
return registerServiceWorker()
.then(swr =>
getEndpointExpectNull(swr)
.then(_ => changePushServerConnectionEnabled(false))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changeOfflineState(true))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changePushServerConnectionEnabled(true))
.then(_ => subscribeFail(swr))
.then(_ => getEndpointExpectNull(swr))
.then(_ => changeOfflineState(false))
.then(_ => subscribe(swr))
.then(sub => getEndpoint(swr, sub)
.then(sub => unsubscribe(sub))
)
.then(_ => getEndpointExpectNull(swr))
.then(_ => unregister(swr))
)
.catch(err => {
ok(false, "Some test failed with error " + err);
})
}
function runTest() {
runTest1()
.then(_ => runTest2())
.then(_ => runTest3())
.then(_ => runTest4())
.then(_ => runTest5())
.then(_ => runTest6())
.then(SimpleTest.finish);
}
setupPrefsAndMockSocket(new MockWebSocket()).then(_ => runTest());
SpecialPowers.addPermission("desktop-notification", true, document);
SimpleTest.waitForExplicitFinish();
</script>
</body>
</html>