michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests that installed addons in the search view load inline prefs properly michael@0: michael@0: const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; michael@0: const NO_MATCH_URL = TESTROOT + "browser_searching_empty.xml"; michael@0: michael@0: var gManagerWindow; michael@0: var gCategoryUtilities; michael@0: var gProvider; michael@0: michael@0: function test() { michael@0: // Turn on searching for this test michael@0: Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: gProvider = new MockProvider(); michael@0: michael@0: gProvider.createAddons([{ michael@0: id: "inlinesettings2@tests.mozilla.org", michael@0: name: "Inline Settings (Regular)", michael@0: version: "1", michael@0: optionsURL: CHROMEROOT + "options.xul", michael@0: optionsType: AddonManager.OPTIONS_TYPE_INLINE michael@0: }]); michael@0: michael@0: open_manager("addons://list/extension", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: close_manager(gManagerWindow, finish); michael@0: } michael@0: michael@0: /* michael@0: * Checks whether or not the Add-ons Manager is currently searching michael@0: * michael@0: * @param aExpectedSearching michael@0: * The expected isSearching state michael@0: */ michael@0: function check_is_searching(aExpectedSearching) { michael@0: var loading = gManagerWindow.document.getElementById("search-loading"); michael@0: is(!is_hidden(loading), aExpectedSearching, michael@0: "Search throbber should be showing iff currently searching"); michael@0: } michael@0: michael@0: /* michael@0: * Completes a search michael@0: * michael@0: * @param aQuery michael@0: * The query to search for michael@0: * @param aFinishImmediately michael@0: * Boolean representing whether or not the search is expected to michael@0: * finish immediately michael@0: * @param aCallback michael@0: * The callback to call when the search is done michael@0: * @param aCategoryType michael@0: * The expected selected category after the search is done. michael@0: * Optional and defaults to "search" michael@0: */ michael@0: function search(aQuery, aFinishImmediately, aCallback, aCategoryType) { michael@0: // Point search to the correct xml test file michael@0: Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, NO_MATCH_URL); michael@0: michael@0: aCategoryType = aCategoryType ? aCategoryType : "search"; michael@0: michael@0: var searchBox = gManagerWindow.document.getElementById("header-search"); michael@0: searchBox.value = aQuery; michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); michael@0: EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); michael@0: michael@0: var finishImmediately = true; michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: is(gCategoryUtilities.selectedCategory, aCategoryType, "Expected category view should be selected"); michael@0: is(gCategoryUtilities.isTypeVisible("search"), aCategoryType == "search", michael@0: "Search category should only be visible if it is the current view"); michael@0: is(finishImmediately, aFinishImmediately, "Search should finish immediately only if expected"); michael@0: michael@0: aCallback(); michael@0: }); michael@0: michael@0: finishImmediately = false michael@0: if (!aFinishImmediately) michael@0: check_is_searching(true); michael@0: } michael@0: michael@0: /* michael@0: * Get item for a specific add-on by name michael@0: * michael@0: * @param aName michael@0: * The name of the add-on to search for michael@0: * @return Row of add-on if found, null otherwise michael@0: */ michael@0: function get_addon_item(aName) { michael@0: var id = aName + "@tests.mozilla.org"; michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: var rows = list.getElementsByTagName("richlistitem"); michael@0: for (let row of rows) { michael@0: if (row.mAddon && row.mAddon.id == id) michael@0: return row; michael@0: } michael@0: michael@0: return null; michael@0: } michael@0: michael@0: add_test(function() { michael@0: search("settings", false, function() { michael@0: var localFilter = gManagerWindow.document.getElementById("search-filter-local"); michael@0: EventUtils.synthesizeMouseAtCenter(localFilter, { }, gManagerWindow); michael@0: michael@0: var item = get_addon_item("inlinesettings2"); michael@0: // Force the XBL binding to apply. michael@0: item.clientTop; michael@0: var button = gManagerWindow.document.getAnonymousElementByAttribute(item, "anonid", "preferences-btn"); michael@0: is_element_visible(button, "Preferences button should be visible"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: is(gManagerWindow.gViewController.currentViewObj, gManagerWindow.gDetailView, "View should have changed to detail"); michael@0: michael@0: var searchCategory = gManagerWindow.document.getElementById("category-search"); michael@0: EventUtils.synthesizeMouseAtCenter(searchCategory, { }, gManagerWindow); michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: is(gManagerWindow.gViewController.currentViewObj, gManagerWindow.gSearchView, "View should have changed back to search"); michael@0: michael@0: // Reset filter to remote to avoid breaking later tests. michael@0: var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); michael@0: EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: });