mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 14:46:02 +00:00
Bug 662004 - Extensions preferences in a tab, r=Mossop
This commit is contained in:
parent
aad5947a89
commit
bdafba7da8
@ -1217,6 +1217,8 @@ var AddonManager = {
|
||||
OPTIONS_TYPE_DIALOG: 1,
|
||||
// Options will be displayed within the AM detail view
|
||||
OPTIONS_TYPE_INLINE: 2,
|
||||
// Options will be displayed in a new tab, if possible
|
||||
OPTIONS_TYPE_TAB: 3,
|
||||
|
||||
getInstallForURL: function AM_getInstallForURL(aUrl, aCallback, aMimetype,
|
||||
aHash, aName, aIconURL,
|
||||
|
@ -702,7 +702,8 @@ function loadManifestFromRDF(aUri, aStream) {
|
||||
addon.bootstrap = getRDFProperty(ds, root, "bootstrap") == "true";
|
||||
if (addon.optionsType &&
|
||||
addon.optionsType != AddonManager.OPTIONS_TYPE_DIALOG &&
|
||||
addon.optionsType != AddonManager.OPTIONS_TYPE_INLINE) {
|
||||
addon.optionsType != AddonManager.OPTIONS_TYPE_INLINE &&
|
||||
addon.optionsType != AddonManager.OPTIONS_TYPE_TAB) {
|
||||
throw new Error("Install manifest specifies unknown type: " + addon.optionsType);
|
||||
}
|
||||
}
|
||||
|
@ -939,6 +939,10 @@ var gViewController = {
|
||||
return;
|
||||
}
|
||||
var optionsURL = aAddon.optionsURL;
|
||||
if (aAddon.optionsType == AddonManager.OPTIONS_TYPE_TAB &&
|
||||
openOptionsInTab(optionsURL)) {
|
||||
return;
|
||||
}
|
||||
var windows = Services.wm.getEnumerator(null);
|
||||
while (windows.hasMoreElements()) {
|
||||
var win = windows.getNext();
|
||||
@ -1198,6 +1202,18 @@ var gViewController = {
|
||||
onEvent: function() {}
|
||||
};
|
||||
|
||||
function openOptionsInTab(optionsURL) {
|
||||
var mainWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShellTreeItem)
|
||||
.rootTreeItem.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIDOMWindow);
|
||||
if ("switchToTabHavingURI" in mainWindow) {
|
||||
mainWindow.switchToTabHavingURI(optionsURL, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function formatDate(aDate) {
|
||||
return Cc["@mozilla.org/intl/scriptabledateformat;1"]
|
||||
|
@ -88,6 +88,7 @@ _MAIN_TEST_FILES = \
|
||||
browser_openDialog.js \
|
||||
browser_types.js \
|
||||
browser_inlinesettings.js \
|
||||
browser_tabsettings.js \
|
||||
$(NULL)
|
||||
|
||||
_TEST_FILES = \
|
||||
|
100
toolkit/mozapps/extensions/test/browser/browser_tabsettings.js
Normal file
100
toolkit/mozapps/extensions/test/browser/browser_tabsettings.js
Normal file
@ -0,0 +1,100 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
// Tests various aspects of the details view
|
||||
|
||||
var gManagerWindow;
|
||||
var gCategoryUtilities;
|
||||
var gProvider;
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
gProvider = new MockProvider();
|
||||
|
||||
gProvider.createAddons([{
|
||||
id: "tabsettings@tests.mozilla.org",
|
||||
name: "Tab Settings",
|
||||
version: "1",
|
||||
optionsURL: CHROMEROOT + "addon_prefs.xul",
|
||||
optionsType: AddonManager.OPTIONS_TYPE_TAB
|
||||
}]);
|
||||
|
||||
open_manager("addons://list/extension", function(aWindow) {
|
||||
gManagerWindow = aWindow;
|
||||
gCategoryUtilities = new CategoryUtilities(gManagerWindow);
|
||||
|
||||
run_next_test();
|
||||
});
|
||||
}
|
||||
|
||||
function end_test() {
|
||||
close_manager(gManagerWindow, function() {
|
||||
finish();
|
||||
});
|
||||
}
|
||||
|
||||
add_test(function() {
|
||||
var addon = get_addon_element(gManagerWindow, "tabsettings@tests.mozilla.org");
|
||||
is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_TAB, "Options should be inline type");
|
||||
addon.parentNode.ensureElementIsVisible(addon);
|
||||
|
||||
var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn");
|
||||
is_element_visible(button, "Preferences button should be visible");
|
||||
|
||||
if (gUseInContentUI) {
|
||||
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
|
||||
|
||||
var browser = gBrowser.selectedTab.linkedBrowser;
|
||||
browser.addEventListener("DOMContentLoaded", function() {
|
||||
browser.removeEventListener("DOMContentLoaded", arguments.callee, false);
|
||||
is(browser.currentURI.spec, addon.mAddon.optionsURL, "New tab should have loaded the options URL");
|
||||
browser.contentWindow.close();
|
||||
run_next_test();
|
||||
}, false);
|
||||
return;
|
||||
}
|
||||
|
||||
let instantApply = Services.prefs.getBoolPref("browser.preferences.instantApply");
|
||||
|
||||
function observer(aSubject, aTopic, aData) {
|
||||
switch (aTopic) {
|
||||
case "domwindowclosed":
|
||||
// Give the preference window a chance to finish closing before
|
||||
// closing the add-ons manager.
|
||||
waitForFocus(function () {
|
||||
Services.ww.unregisterNotification(observer);
|
||||
run_next_test();
|
||||
});
|
||||
break;
|
||||
case "domwindowopened":
|
||||
let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
|
||||
waitForFocus(function () {
|
||||
// If the openDialog privileges are wrong a new browser window
|
||||
// will open, let the test proceed (and fail) rather than timeout.
|
||||
if (win.location != addon.mAddon.optionsURL &&
|
||||
win.location != "chrome://browser/content/browser.xul")
|
||||
return;
|
||||
|
||||
is(win.location, addon.mAddon.optionsURL,
|
||||
"The correct addon pref window should have opened");
|
||||
|
||||
let chromeFlags = win.QueryInterface(Ci.nsIInterfaceRequestor).
|
||||
getInterface(Ci.nsIWebNavigation).
|
||||
QueryInterface(Ci.nsIDocShellTreeItem).treeOwner.
|
||||
QueryInterface(Ci.nsIInterfaceRequestor).
|
||||
getInterface(Ci.nsIXULWindow).chromeFlags;
|
||||
ok(chromeFlags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_CHROME &&
|
||||
(instantApply || chromeFlags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_DIALOG),
|
||||
"Window was open as a chrome dialog.");
|
||||
|
||||
win.close();
|
||||
}, win);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Services.ww.registerNotification(observer);
|
||||
EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow);
|
||||
});
|
@ -270,6 +270,19 @@ function run_test() {
|
||||
name: "Test Addon 20"
|
||||
}, profileDir);
|
||||
|
||||
writeInstallRDFForExtension({
|
||||
id: "addon21@tests.mozilla.org",
|
||||
version: "1.0",
|
||||
optionsType: "3",
|
||||
optionsURL: "chrome://test/content/options.xul",
|
||||
targetApplications: [{
|
||||
id: "xpcshell@tests.mozilla.org",
|
||||
minVersion: "1",
|
||||
maxVersion: "1"
|
||||
}],
|
||||
name: "Test Addon 21"
|
||||
}, profileDir);
|
||||
|
||||
do_test_pending();
|
||||
startupManager();
|
||||
AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
|
||||
@ -291,9 +304,11 @@ function run_test() {
|
||||
"addon17@tests.mozilla.org",
|
||||
"addon18@tests.mozilla.org",
|
||||
"addon19@tests.mozilla.org",
|
||||
"addon20@tests.mozilla.org"],
|
||||
"addon20@tests.mozilla.org",
|
||||
"addon21@tests.mozilla.org"],
|
||||
function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20]) {
|
||||
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20,
|
||||
a21]) {
|
||||
|
||||
do_check_neq(a1, null);
|
||||
do_check_eq(a1.id, "addon1@tests.mozilla.org");
|
||||
@ -448,6 +463,14 @@ function run_test() {
|
||||
do_check_eq(a20.optionsURL, "chrome://test/content/options.xul");
|
||||
do_check_eq(a20.optionsType, AddonManager.OPTIONS_TYPE_DIALOG);
|
||||
|
||||
do_check_neq(a21, null);
|
||||
do_check_true(a21.isActive);
|
||||
do_check_false(a21.userDisabled);
|
||||
do_check_false(a21.appDisabled);
|
||||
do_check_true(a21.isCompatible);
|
||||
do_check_eq(a21.optionsURL, "chrome://test/content/options.xul");
|
||||
do_check_eq(a21.optionsType, AddonManager.OPTIONS_TYPE_TAB);
|
||||
|
||||
do_test_finished();
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user