diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-11 07:03:16 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-11 07:03:16 -0500 |
commit | 203eb0f61a09372310a2a8fb57e169cb3f47800b (patch) | |
tree | 8490329d3dae4de3c7ffd127bce1f65fdc009abd /toolkit/mozapps/extensions/test/browser/browser_bug591465.js | |
parent | e45706ca3acbb6530419433212becc61d5953a2d (diff) | |
parent | 8f6d3dab81c7f8f97ef197e26ab9439b09735b8f (diff) | |
download | UXP-203eb0f61a09372310a2a8fb57e169cb3f47800b.tar UXP-203eb0f61a09372310a2a8fb57e169cb3f47800b.tar.gz UXP-203eb0f61a09372310a2a8fb57e169cb3f47800b.tar.lz UXP-203eb0f61a09372310a2a8fb57e169cb3f47800b.tar.xz UXP-203eb0f61a09372310a2a8fb57e169cb3f47800b.zip |
Merge branch 'ext-work'FF_Checkpoint_1
Diffstat (limited to 'toolkit/mozapps/extensions/test/browser/browser_bug591465.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/browser/browser_bug591465.js | 512 |
1 files changed, 512 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/browser/browser_bug591465.js b/toolkit/mozapps/extensions/test/browser/browser_bug591465.js new file mode 100644 index 000000000..2380deee1 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/browser_bug591465.js @@ -0,0 +1,512 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Bug 591465 - Context menu of add-ons miss context related state change entries + + +let tempScope = {}; +Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm", tempScope); +let LightweightThemeManager = tempScope.LightweightThemeManager; + + +const PREF_GETADDONS_MAXRESULTS = "extensions.getAddons.maxResults"; +const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; +const SEARCH_URL = TESTROOT + "browser_bug591465.xml"; +const SEARCH_QUERY = "SEARCH"; + +var gManagerWindow; +var gProvider; +var gContextMenu; +var gLWTheme = { + id: "4", + version: "1", + name: "Bling", + description: "SO MUCH BLING!", + author: "Pixel Pusher", + homepageURL: "http://mochi.test:8888/data/index.html", + headerURL: "http://mochi.test:8888/data/header.png", + footerURL: "http://mochi.test:8888/data/footer.png", + previewURL: "http://mochi.test:8888/data/preview.png", + iconURL: "http://mochi.test:8888/data/icon.png" + }; + + +function test() { + waitForExplicitFinish(); + + gProvider = new MockProvider(); + + gProvider.createAddons([{ + id: "addon1@tests.mozilla.org", + name: "addon 1", + version: "1.0" + }, { + id: "addon2@tests.mozilla.org", + name: "addon 2", + version: "1.0", + _userDisabled: true + }, { + id: "theme1@tests.mozilla.org", + name: "theme 1", + version: "1.0", + type: "theme" + }, { + id: "theme2@tests.mozilla.org", + name: "theme 2", + version: "1.0", + type: "theme", + _userDisabled: true + }, { + id: "theme3@tests.mozilla.org", + name: "theme 3", + version: "1.0", + type: "theme", + permissions: 0 + }]); + + + open_manager("addons://list/extension", function(aWindow) { + gManagerWindow = aWindow; + gContextMenu = aWindow.document.getElementById("addonitem-popup"); + run_next_test(); + }); +} + + +function end_test() { + close_manager(gManagerWindow, finish); +} + + +function check_contextmenu(aIsTheme, aIsEnabled, aIsRemote, aIsDetails, aIsSingleItemCase) { + if (aIsTheme || aIsEnabled || aIsRemote) + is_element_hidden(gManagerWindow.document.getElementById("menuitem_enableItem"), + "'Enable' should be hidden"); + else + is_element_visible(gManagerWindow.document.getElementById("menuitem_enableItem"), + "'Enable' should be visible"); + + if (aIsTheme || !aIsEnabled || aIsRemote) + is_element_hidden(gManagerWindow.document.getElementById("menuitem_disableItem"), + "'Disable' should be hidden"); + else + is_element_visible(gManagerWindow.document.getElementById("menuitem_disableItem"), + "'Disable' should be visible"); + + if (!aIsTheme || aIsEnabled || aIsRemote || aIsSingleItemCase) + is_element_hidden(gManagerWindow.document.getElementById("menuitem_enableTheme"), + "'Wear Theme' should be hidden"); + else + is_element_visible(gManagerWindow.document.getElementById("menuitem_enableTheme"), + "'Wear Theme' should be visible"); + + if (!aIsTheme || !aIsEnabled || aIsRemote || aIsSingleItemCase) + is_element_hidden(gManagerWindow.document.getElementById("menuitem_disableTheme"), + "'Stop Wearing Theme' should be hidden"); + else + is_element_visible(gManagerWindow.document.getElementById("menuitem_disableTheme"), + "'Stop Wearing Theme' should be visible"); + + if (aIsRemote) + is_element_visible(gManagerWindow.document.getElementById("menuitem_installItem"), + "'Install' should be visible"); + else + is_element_hidden(gManagerWindow.document.getElementById("menuitem_installItem"), + "'Install' should be hidden"); + + if (aIsDetails) + is_element_hidden(gManagerWindow.document.getElementById("menuitem_showDetails"), + "'Show More Information' should be hidden in details view"); + else + is_element_visible(gManagerWindow.document.getElementById("menuitem_showDetails"), + "'Show More Information' should be visible in list view"); + + if (aIsSingleItemCase) + is_element_hidden(gManagerWindow.document.getElementById("addonitem-menuseparator"), + "Menu separator should be hidden with only one menu item"); + else + is_element_visible(gManagerWindow.document.getElementById("addonitem-menuseparator"), + "Menu separator should be visible with multiple menu items"); + +} + + +add_test(function() { + var el = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); + isnot(el, null, "Should have found addon element"); + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(false, true, false, false, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on enabled extension item"); + el.parentNode.ensureElementIsVisible(el); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); +}); + +add_test(function() { + var el = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); + isnot(el, null, "Should have found addon element"); + el.mAddon.userDisabled = true; + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(false, false, false, false, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on newly disabled extension item"); + el.parentNode.ensureElementIsVisible(el); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); +}); + +add_test(function() { + var el = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); + isnot(el, null, "Should have found addon element"); + el.mAddon.userDisabled = false; + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(false, true, false, false, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on newly enabled extension item"); + el.parentNode.ensureElementIsVisible(el); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); +}); + +add_test(function() { + var el = get_addon_element(gManagerWindow, "addon2@tests.mozilla.org"); + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(false, false, false, false, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on disabled extension item"); + el.parentNode.ensureElementIsVisible(el); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); +}); + + +add_test(function() { + gManagerWindow.loadView("addons://list/theme"); + wait_for_view_load(gManagerWindow, function() { + var el = get_addon_element(gManagerWindow, "theme1@tests.mozilla.org"); + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(true, true, false, false, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on enabled theme item"); + el.parentNode.ensureElementIsVisible(el); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); + }); +}); + + +add_test(function() { + var el = get_addon_element(gManagerWindow, "theme2@tests.mozilla.org"); + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(true, false, false, false, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on disabled theme item"); + el.parentNode.ensureElementIsVisible(el); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); +}); + + +add_test(function() { + LightweightThemeManager.currentTheme = gLWTheme; + + var el = get_addon_element(gManagerWindow, "4@personas.mozilla.org"); + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(true, true, false, false, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on enabled LW theme item"); + el.parentNode.ensureElementIsVisible(el); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); +}); + + +add_test(function() { + LightweightThemeManager.currentTheme = null; + + var el = get_addon_element(gManagerWindow, "4@personas.mozilla.org"); + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(true, false, false, false, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on disabled LW theme item"); + el.parentNode.ensureElementIsVisible(el); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); +}); + + +add_test(function() { + LightweightThemeManager.currentTheme = gLWTheme; + + gManagerWindow.loadView("addons://detail/4@personas.mozilla.org"); + wait_for_view_load(gManagerWindow, function() { + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(true, true, false, true, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on enabled LW theme, in detail view"); + var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); + }); +}); + + +add_test(function() { + LightweightThemeManager.currentTheme = null; + + gManagerWindow.loadView("addons://detail/4@personas.mozilla.org"); + wait_for_view_load(gManagerWindow, function() { + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(true, false, false, true, false); + + gContextMenu.hidePopup(); + + AddonManager.getAddonByID("4@personas.mozilla.org", function(aAddon) { + aAddon.uninstall(); + run_next_test(); + }); + }, false); + + info("Opening context menu on disabled LW theme, in detail view"); + var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); + }); +}); + + +add_test(function() { + gManagerWindow.loadView("addons://detail/addon1@tests.mozilla.org"); + wait_for_view_load(gManagerWindow, function() { + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(false, true, false, true, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on enabled extension, in detail view"); + var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); + }); +}); + + +add_test(function() { + gManagerWindow.loadView("addons://detail/addon2@tests.mozilla.org"); + wait_for_view_load(gManagerWindow, function() { + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(false, false, false, true, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on disabled extension, in detail view"); + var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); + }); +}); + + +add_test(function() { + gManagerWindow.loadView("addons://detail/theme1@tests.mozilla.org"); + wait_for_view_load(gManagerWindow, function() { + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(true, true, false, true, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on enabled theme, in detail view"); + var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); + }); +}); + + +add_test(function() { + gManagerWindow.loadView("addons://detail/theme2@tests.mozilla.org"); + wait_for_view_load(gManagerWindow, function() { + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(true, false, false, true, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on disabled theme, in detail view"); + var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); + }); +}); + +add_test(function() { + gManagerWindow.loadView("addons://detail/theme3@tests.mozilla.org"); + wait_for_view_load(gManagerWindow, function() { + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(true, true, false, true, true); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu with single menu item on enabled theme, in detail view"); + var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); + }); +}); + +add_test(function() { + info("Searching for remote addons"); + + Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL); + Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); + + var searchBox = gManagerWindow.document.getElementById("header-search"); + searchBox.value = SEARCH_QUERY; + + EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); + EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); + + wait_for_view_load(gManagerWindow, function() { + var filter = gManagerWindow.document.getElementById("search-filter-remote"); + EventUtils.synthesizeMouseAtCenter(filter, { }, gManagerWindow); + executeSoon(function() { + + var el = get_addon_element(gManagerWindow, "remote1@tests.mozilla.org"); + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(false, false, true, false, false); + + gContextMenu.hidePopup(); + run_next_test(); + }, false); + + info("Opening context menu on remote extension item"); + el.parentNode.ensureElementIsVisible(el); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); + + }); + }); +}); + + +add_test(function() { + gManagerWindow.loadView("addons://detail/remote1@tests.mozilla.org"); + wait_for_view_load(gManagerWindow, function() { + + gContextMenu.addEventListener("popupshown", function() { + gContextMenu.removeEventListener("popupshown", arguments.callee, false); + + check_contextmenu(false, false, true, true, false); + + gContextMenu.hidePopup(); + + // Delete the created install + AddonManager.getAllInstalls(function(aInstalls) { + is(aInstalls.length, 1, "Should be one available install"); + aInstalls[0].cancel(); + + run_next_test(); + }); + }, false); + + info("Opening context menu on remote extension, in detail view"); + var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container"); + EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow); + EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow); + }); +}); |