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_multiple_register_different_scope.html]
[test_subscription_change.html] [test_subscription_change.html]
[test_data.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] [test_serviceworker_lifetime.html]

View File

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

View File

@ -10,6 +10,7 @@ http://creativecommons.org/licenses/publicdomain/
<head> <head>
<title>Test for Bug 1150812</title> <title>Test for Bug 1150812</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> <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" /> <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<meta http-equiv="Content-type" content="text/html;charset=UTF-8"> <meta http-equiv="Content-type" content="text/html;charset=UTF-8">
</head> </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) { function offlineObserver(res) {
this._res = res; this._res = res;
} }
@ -110,16 +122,13 @@ http://creativecommons.org/licenses/publicdomain/
obsService.addObserver(SpecialPowers.wrapCallbackObject(new offlineObserver(res)), obsService.addObserver(SpecialPowers.wrapCallbackObject(new offlineObserver(res)),
"network:offline-status-changed", "network:offline-status-changed",
false); false);
var ioService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"] chromeScript.sendAsyncMessage("change-status", offline);
.getService(SpecialPowers.Ci.nsIIOService);
ioService.offline = offline;
}); });
} }
function changePushServerConnectionEnabled(enable) { function changePushServerConnectionEnabled(enable) {
debug("changePushServerConnectionEnabled"); debug("changePushServerConnectionEnabled");
SpecialPowers.pushPrefEnv({"set": [["dom.push.connection.enabled", enable]]}, SpecialPowers.setBoolPref("dom.push.connection.enabled", enable);
null);
} }
function unsubscribe(sub) { function unsubscribe(sub) {
@ -287,13 +296,7 @@ http://creativecommons.org/licenses/publicdomain/
.then(SimpleTest.finish); .then(SimpleTest.finish);
} }
SpecialPowers.pushPrefEnv({"set": [ setupPrefsAndMock(new MockWebSocket()).then(_ => runTest());
["dom.push.enabled", true],
["dom.push.connection.enabled", true],
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true]
]}, runTest);
SpecialPowers.addPermission("desktop-notification", true, document); SpecialPowers.addPermission("desktop-notification", true, document);
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
</script> </script>