Bug 1130084 - Allow runtimes to take infinite time to connect. r=past

This commit is contained in:
J. Ryan Stinnett 2015-03-24 09:31:51 -05:00
parent 7052785fe6
commit 789d420452
4 changed files with 74 additions and 6 deletions

View File

@ -302,9 +302,8 @@ let UI = {
},
busyUntil: function(promise, operationDescription) {
// Freeze the UI until the promise is resolved. A 30s timeout
// will unfreeze the UI, just in case the promise never gets
// resolved.
// Freeze the UI until the promise is resolved. A timeout will unfreeze the
// UI, just in case the promise never gets resolved.
this._busyPromise = promise;
this._busyOperationDescription = operationDescription;
this.setupBusyTimeout();
@ -469,7 +468,13 @@ let UI = {
// |busyUntil| will listen for rejections.
// Bug 1121100 may find a better way to silence these.
});
return this.busyUntil(promise, "Connecting to " + name);
promise = this.busyUntil(promise, "Connecting to " + name);
// Stop busy timeout for runtimes that take unknown or long amounts of time
// to connect.
if (runtime.prolongedConnection) {
this.cancelBusyTimeout();
}
return promise;
},
updateRuntimeButton: function() {

View File

@ -66,6 +66,10 @@ const Strings = Services.strings.createBundle("chrome://browser/locale/devtools/
* |name| field
* A user-visible label to identify the runtime that will be displayed in a
* runtime list.
* |prolongedConnection| field
* A boolean value which should be |true| if the connection process is
* expected to take a unknown or large amount of time. A UI may use this as a
* hint to skip timeouts or other time-based code paths.
* connect()
* Configure the passed |connection| object with any settings need to
* successfully connect to the runtime, and call the |connection|'s connect()
@ -446,6 +450,8 @@ function WiFiRuntime(deviceName) {
WiFiRuntime.prototype = {
type: RuntimeTypes.WIFI,
// Mark runtime as taking a long time to connect
prolongedConnection: true,
connect: function(connection) {
let service = discovery.getRemoteService("devtools", this.deviceName);
if (!service) {

View File

@ -37,6 +37,7 @@ SimpleTest.registerCleanupFunction(() => {
Services.prefs.clearUserPref("devtools.webide.autoinstallADBHelper");
Services.prefs.clearUserPref("devtools.webide.autoinstallFxdtAdapters");
Services.prefs.clearUserPref("devtools.webide.sidebars");
Services.prefs.clearUserPref("devtools.webide.busyTimeout");
});
function openWebIDE(autoInstallAddons) {

View File

@ -62,6 +62,30 @@
}
});
win.AppManager.runtimeList.usb.push({
connect: function(connection) {
let deferred = promise.defer();
return deferred.promise;
},
get name() {
return "infiniteRuntime";
}
});
win.AppManager.runtimeList.usb.push({
connect: function(connection) {
let deferred = promise.defer();
return deferred.promise;
},
prolongedConnection: true,
get name() {
return "prolongedRuntime";
}
});
win.AppManager.update("runtimelist");
let packagedAppLocation = getTestFilePath("app");
@ -71,7 +95,7 @@
let panelNode = win.document.querySelector("#runtime-panel");
let items = panelNode.querySelectorAll(".runtime-panel-item-usb");
is(items.length, 1, "Found one runtime button");
is(items.length, 3, "Found 3 runtime buttons");
let deferred = promise.defer();
win.AppManager.connection.once(
@ -104,7 +128,6 @@
ok(isPlayActive(), "play button is enabled 3");
ok(!isStopActive(), "stop button is disabled 3");
yield win.Cmds.disconnectRuntime();
is(Object.keys(DebuggerServer._connections).length, 0, "Disconnected");
@ -137,6 +160,39 @@
yield win.Cmds.disconnectRuntime();
Services.prefs.setIntPref("devtools.webide.busyTimeout", 100);
// Wait for error message since connection never completes
let errorDeferred = promise.defer();
win.UI.reportError = errorName => {
if (errorName === "error_operationTimeout") {
errorDeferred.resolve();
}
};
// Click the infinite runtime
items[1].click();
ok(win.document.querySelector("window").className, "busy", "UI is busy");
yield errorDeferred.promise;
// Check for unexpected error message since this is prolonged
let noErrorDeferred = promise.defer();
win.UI.reportError = errorName => {
if (errorName === "error_operationTimeout") {
noErrorDeferred.reject();
}
};
// Click the prolonged runtime
items[2].click();
ok(win.document.querySelector("window").className, "busy", "UI is busy");
setTimeout(() => {
noErrorDeferred.resolve();
}, 1000);
yield noErrorDeferred.promise;
SimpleTest.finish();
});