Bug 1202532 - The callback argument of windows.update() is optional. r=billm

This commit is contained in:
Edgar Chen 2015-09-07 18:55:00 +08:00
parent 7b504b5d6c
commit b625123cb0
3 changed files with 57 additions and 2 deletions

View File

@ -60,7 +60,7 @@ extensions.registerAPI((extension, context) => {
runSafe(context, callback, WindowManager.convert(extension, window, getInfo));
},
getAll: function(getAll, callback) {
getAll: function(getInfo, callback) {
let e = Services.wm.getEnumerator("navigator:browser");
let windows = [];
while (e.hasMoreElements()) {
@ -131,7 +131,10 @@ extensions.registerAPI((extension, context) => {
Services.focus.activeWindow = window;
}
// TODO: All the other properties...
runSafe(context, callback, WindowManager.convert(extension, window));
if (callback) {
runSafe(context, callback, WindowManager.convert(extension, window));
}
},
remove: function(windowId, callback) {

View File

@ -6,3 +6,4 @@ skip-if = os == 'android' || buildapp == 'b2g' || os == 'mac'
[browser_ext_tabs_executeScript.js]
[browser_ext_tabs_query.js]
[browser_ext_tabs_update.js]
[browser_ext_windows_update.js]

View File

@ -0,0 +1,51 @@
add_task(function* () {
function promiseWaitForFocus(aWindow) {
return new Promise(function(aResolve, aReject) {
waitForFocus(function() {
ok(Services.focus.activeWindow === aWindow, "correct window focused");
aResolve();
}, aWindow);
});
}
let window1 = window;
let window2 = yield BrowserTestUtils.openNewBrowserWindow();
Services.focus.activeWindow = window2;
yield promiseWaitForFocus(window2);
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["windows"]
},
background: function() {
browser.windows.getAll(undefined, function(wins) {
browser.test.assertEq(wins.length, 2, "should have two windows");
// Sort the unfocused window to the lower index.
wins.sort(function(win1, win2) {
if (win1.focused === win2.focused) {
return 0;
}
return win1.focused ? 1 : -1;
});
browser.windows.update(wins[0].id, {focused: true}, function() {
browser.test.sendMessage("check");
});
});
},
});
yield extension.startup();
yield extension.awaitMessage("check");
yield promiseWaitForFocus(window1);
yield extension.unload();
yield BrowserTestUtils.closeWindow(window2);
});