Bug 1164432 - Update test_try_registering_offline_disabled.html to use mock push server. r=kitcambridge, a=test-only

This commit is contained in:
William Chen 2016-03-19 00:35:57 -07:00
parent a3d8e5de7b
commit 3c7b3c8326
3 changed files with 23 additions and 17 deletions

View File

@ -18,6 +18,5 @@ skip-if = os == "android" || toolkit == "gonk"
[test_multiple_register_different_scope.html]
[test_subscription_change.html]
[test_data.html]
# Disabled for too many intermittent failures (bug 1164432)
# [test_try_registering_offline_disabled.html]
[test_try_registering_offline_disabled.html]
[test_serviceworker_lifetime.html]

View File

@ -85,13 +85,17 @@ var mockWebSocket;
addMessageListener("setup", function () {
mockWebSocket = new Promise((resolve, reject) => {
var mockSocket = null;
pushService.replaceServiceBackend({
serverURI: "wss://push.example.org/",
networkInfo: new MockNetworkInfo(),
makeWebSocket(uri) {
var socket = new MockWebSocketParent(uri);
resolve(socket);
return socket;
if (!mockSocket) {
mockSocket = new MockWebSocketParent(uri);
resolve(mockSocket);
}
return mockSocket;
}
});
});

View File

@ -10,6 +10,7 @@ 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>
@ -86,6 +87,17 @@ http://creativecommons.org/licenses/publicdomain/
});
}
// Load chrome script to change offline status in the
// parent process.
var chromeScript = SpecialPowers.loadChromeScript(_ => {
var { classes: Cc, interfaces: Ci } = Components;
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;
}
@ -110,16 +122,13 @@ http://creativecommons.org/licenses/publicdomain/
obsService.addObserver(SpecialPowers.wrapCallbackObject(new offlineObserver(res)),
"network:offline-status-changed",
false);
var ioService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
.getService(SpecialPowers.Ci.nsIIOService);
ioService.offline = offline;
chromeScript.sendAsyncMessage("change-status", offline);
});
}
function changePushServerConnectionEnabled(enable) {
debug("changePushServerConnectionEnabled");
SpecialPowers.pushPrefEnv({"set": [["dom.push.connection.enabled", enable]]},
null);
SpecialPowers.setBoolPref("dom.push.connection.enabled", enable);
}
function unsubscribe(sub) {
@ -287,13 +296,7 @@ http://creativecommons.org/licenses/publicdomain/
.then(SimpleTest.finish);
}
SpecialPowers.pushPrefEnv({"set": [
["dom.push.enabled", true],
["dom.push.connection.enabled", true],
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true]
]}, runTest);
setupPrefsAndMock(new MockWebSocket()).then(_ => runTest());
SpecialPowers.addPermission("desktop-notification", true, document);
SimpleTest.waitForExplicitFinish();
</script>