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 searching for add-ons works correctly michael@0: michael@0: const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; michael@0: const SEARCH_URL = TESTROOT + "browser_searching.xml"; michael@0: const NO_MATCH_URL = TESTROOT + "browser_searching_empty.xml"; michael@0: michael@0: const QUERY = "SEARCH"; michael@0: const NO_MATCH_QUERY = "NOMATCHQUERY"; michael@0: const REMOTE_TO_INSTALL = "remote1"; michael@0: const REMOTE_INSTALL_URL = TESTROOT + "addons/browser_searching.xpi"; michael@0: michael@0: var gManagerWindow; michael@0: var gCategoryUtilities; michael@0: var gProvider; michael@0: var gServer; michael@0: var gAddonInstalled = false; michael@0: michael@0: function test() { michael@0: requestLongerTimeout(2); michael@0: // Turn on searching for this test michael@0: Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); michael@0: Services.prefs.setBoolPref(PREF_STRICT_COMPAT, true); michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: gProvider = new MockProvider(); michael@0: michael@0: gProvider.createAddons([{ michael@0: id: "addon1@tests.mozilla.org", michael@0: name: "PASS - f", michael@0: description: "Test description - SEARCH", michael@0: size: 3, michael@0: version: "1.0", michael@0: updateDate: new Date(2010, 4, 2, 0, 0, 1) michael@0: }, { michael@0: id: "fail-addon1@tests.mozilla.org", michael@0: name: "FAIL", michael@0: description: "Does not match query" michael@0: }, { michael@0: id: "addon2@tests.mozilla.org", michael@0: name: "PASS - c", michael@0: description: "Test description - reSEARCHing SEARCH SEARCH", michael@0: size: 6, michael@0: version: "2.0", michael@0: updateDate: new Date(2010, 4, 2, 0, 0, 0) michael@0: }]); michael@0: michael@0: var installs = gProvider.createInstalls([{ michael@0: name: "PASS - a - SEARCHing", michael@0: sourceURI: "http://example.com/install1.xpi" michael@0: }, { michael@0: name: "PASS - g - reSEARCHing SEARCH", michael@0: sourceURI: "http://example.com/install2.xpi" michael@0: }, { michael@0: // Does not match query michael@0: name: "FAIL", michael@0: sourceURI: "http://example.com/fail-install1.xpi" michael@0: }]); michael@0: michael@0: for (let install of installs ) michael@0: install.install(); 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, function() { michael@0: var installedAddon = get_addon_item(REMOTE_TO_INSTALL).mAddon; michael@0: installedAddon.uninstall(); michael@0: michael@0: AddonManager.getAllInstalls(function(aInstallsList) { michael@0: for (var install of aInstallsList) { michael@0: var sourceURI = install.sourceURI.spec; michael@0: if (sourceURI == REMOTE_INSTALL_URL || michael@0: sourceURI.match(/^http:\/\/example\.com\/(.+)\.xpi$/) != null) michael@0: install.cancel(); michael@0: } michael@0: michael@0: finish(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function getAnonymousElementByAttribute(aElement, aName, aValue) { michael@0: return gManagerWindow.document.getAnonymousElementByAttribute(aElement, michael@0: aName, michael@0: aValue); 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: var url = (aQuery == NO_MATCH_QUERY) ? NO_MATCH_URL : SEARCH_URL; michael@0: Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, 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: check_is_searching(false); 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: * Return results of a search michael@0: * michael@0: * @return Array of objects, each containing the name and item of a specific michael@0: * result michael@0: */ michael@0: function get_actual_results() { michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: var rows = list.getElementsByTagName("richlistitem"); michael@0: michael@0: var results = []; michael@0: for (var item of rows) { michael@0: michael@0: // Only consider items that are currently showing michael@0: var style = gManagerWindow.document.defaultView.getComputedStyle(item, ""); michael@0: if (style.display == "none" || style.visibility != "visible") michael@0: continue; michael@0: michael@0: if (item.mInstall || item.isPending("install")) { michael@0: var sourceURI = item.mInstall.sourceURI.spec; michael@0: if (sourceURI == REMOTE_INSTALL_URL) { michael@0: results.push({name: REMOTE_TO_INSTALL, item: item}); michael@0: continue; michael@0: } michael@0: michael@0: var result = sourceURI.match(/^http:\/\/example\.com\/(.+)\.xpi$/); michael@0: if (result != null) { michael@0: is(item.mInstall.name.indexOf("PASS"), 0, "Install name should start with PASS"); michael@0: results.push({name: result[1], item: item}); michael@0: continue; michael@0: } michael@0: } michael@0: else if (item.mAddon) { michael@0: var result = item.mAddon.id.match(/^(.+)@tests\.mozilla\.org$/); michael@0: if (result != null) { michael@0: is(item.mAddon.name.indexOf("PASS"), 0, "Addon name should start with PASS"); michael@0: results.push({name: result[1], item: item}); michael@0: continue; michael@0: } michael@0: } michael@0: else { michael@0: ok(false, "Found an item in the list that was neither installing or installed"); michael@0: } michael@0: } michael@0: michael@0: return results; michael@0: } michael@0: michael@0: /* michael@0: * Returns expected results when searching for QUERY with default ordering michael@0: * michael@0: * @param aSortBy michael@0: * How the results are sorted (e.g. "name") michael@0: * @param aLocalExpected michael@0: * Boolean representing if local results are expected michael@0: * @return A pair: [array of results with an expected order, michael@0: * array of results with unknown order] michael@0: */ michael@0: function get_expected_results(aSortBy, aLocalExpected) { michael@0: var expectedOrder = null, unknownOrder = null; michael@0: switch (aSortBy) { michael@0: case "relevancescore": michael@0: expectedOrder = [ "addon2" , "remote1", "install2", "addon1", michael@0: "install1", "remote2", "remote3" , "remote4" ]; michael@0: unknownOrder = []; michael@0: break; michael@0: case "name": michael@0: // Defaults to ascending order michael@0: expectedOrder = [ "install1", "remote1", "addon2" , "remote2", michael@0: "remote3" , "addon1" , "install2", "remote4" ]; michael@0: unknownOrder = []; michael@0: break; michael@0: case "dateUpdated": michael@0: expectedOrder = [ "addon1", "addon2" ]; michael@0: // Updated date not available for installs and remote add-ons michael@0: unknownOrder = [ "install1", "install2", "remote1", michael@0: "remote2" , "remote3" , "remote4" ]; michael@0: break; michael@0: default: michael@0: ok(false, "Should recognize sortBy when checking the order of items"); michael@0: } michael@0: michael@0: // Only keep expected results michael@0: function filterResults(aId) { michael@0: // Include REMOTE_TO_INSTALL as a local add-on if it has been installed michael@0: if (gAddonInstalled && aId == REMOTE_TO_INSTALL) michael@0: return aLocalExpected; michael@0: michael@0: if (aId.indexOf("addon") == 0 || aId.indexOf("install") == 0) michael@0: return aLocalExpected; michael@0: if (aId.indexOf("remote") == 0) michael@0: return !aLocalExpected; michael@0: michael@0: return false; michael@0: } michael@0: michael@0: michael@0: return [expectedOrder.filter(filterResults), michael@0: unknownOrder.filter(filterResults)] michael@0: } michael@0: michael@0: /* michael@0: * Check that the actual and expected results are the same michael@0: * michael@0: * @param aQuery michael@0: * The search query used michael@0: * @param aSortBy michael@0: * How the results are sorted (e.g. "name") michael@0: * @param aReverseOrder michael@0: * Boolean representing if the results are in reverse default order michael@0: * @param aShowLocal michael@0: * Boolean representing if local results are being shown michael@0: */ michael@0: function check_results(aQuery, aSortBy, aReverseOrder, aShowLocal) { michael@0: michael@0: var xpinstall_enabled = true; michael@0: try { michael@0: xpinstall_enabled = Services.prefs.getBoolPref(PREF_XPI_ENABLED); michael@0: } michael@0: catch (e) {}; michael@0: michael@0: // When XPI Instalation is disabled, those buttons are hidden and unused michael@0: if (xpinstall_enabled) { michael@0: var localFilterSelected = gManagerWindow.document.getElementById("search-filter-local").selected; michael@0: var remoteFilterSelected = gManagerWindow.document.getElementById("search-filter-remote").selected; michael@0: is(localFilterSelected, aShowLocal, "Local filter should be selected if showing local items"); michael@0: is(remoteFilterSelected, !aShowLocal, "Remote filter should be selected if showing remote items"); michael@0: } michael@0: michael@0: // Get expected order assuming default order michael@0: var expectedOrder = [], unknownOrder = []; michael@0: if (aQuery == QUERY) michael@0: [expectedOrder, unknownOrder] = get_expected_results(aSortBy, aShowLocal); michael@0: michael@0: // Get actual order of results michael@0: var actualResults = get_actual_results(); michael@0: var actualOrder = [result.name for each(result in actualResults)]; michael@0: michael@0: // Reverse array of actual results if supposed to be in reverse order. michael@0: // Reverse actualOrder instead of expectedOrder so can always check michael@0: // expectedOrder before unknownOrder michael@0: if (aReverseOrder) michael@0: actualOrder.reverse(); michael@0: michael@0: // Check actual vs. expected list of results michael@0: var totalExpectedResults = expectedOrder.length + unknownOrder.length; michael@0: is(actualOrder.length, totalExpectedResults, "Should get correct number of results"); michael@0: michael@0: // Check the "first" and "last" attributes are set correctly michael@0: for (let i = 0; i < actualResults.length; i++) { michael@0: if (i == 0) { michael@0: is(actualResults[0].item.hasAttribute("first"), true, michael@0: "First item should have 'first' attribute set"); michael@0: is(actualResults[0].item.hasAttribute("last"), false, michael@0: "First item should not have 'last' attribute set"); michael@0: } else if (i == (actualResults.length - 1)) { michael@0: is(actualResults[actualResults.length - 1].item.hasAttribute("first"), false, michael@0: "Last item should not have 'first' attribute set"); michael@0: is(actualResults[actualResults.length - 1].item.hasAttribute("last"), true, michael@0: "Last item should have 'last' attribute set"); michael@0: } else { michael@0: is(actualResults[i].item.hasAttribute("first"), false, michael@0: "Item " + i + " should not have 'first' attribute set"); michael@0: is(actualResults[i].item.hasAttribute("last"), false, michael@0: "Item " + i + " should not have 'last' attribute set"); michael@0: } michael@0: } michael@0: michael@0: var i = 0; michael@0: for (; i < expectedOrder.length; i++) michael@0: is(actualOrder[i], expectedOrder[i], "Should have seen expected item"); michael@0: michael@0: // Items with data that is unknown can appear in any order among themselves, michael@0: // so just check that these items exist michael@0: for (; i < actualOrder.length; i++) { michael@0: var unknownOrderIndex = unknownOrder.indexOf(actualOrder[i]); michael@0: ok(unknownOrderIndex >= 0, "Should expect to see item with data that is unknown"); michael@0: unknownOrder[unknownOrderIndex] = null; michael@0: } michael@0: michael@0: // Check status of empty notice michael@0: var emptyNotice = gManagerWindow.document.getElementById("search-list-empty"); michael@0: is(emptyNotice.hidden, totalExpectedResults > 0, michael@0: "Empty notice should be hidden only if expecting shown items"); michael@0: } michael@0: michael@0: /* michael@0: * Check results of a search with different filterings michael@0: * michael@0: * @param aQuery michael@0: * The search query used michael@0: * @param aSortBy michael@0: * How the results are sorted (e.g. "name") michael@0: * @param aReverseOrder michael@0: * Boolean representing if the results are in reverse default order michael@0: * @param aLocalOnly michael@0: * Boolean representing if the results are local only, can be undefined michael@0: */ michael@0: function check_filtered_results(aQuery, aSortBy, aReverseOrder, aLocalOnly) { michael@0: var localFilter = gManagerWindow.document.getElementById("search-filter-local"); michael@0: var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); michael@0: michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: list.ensureElementIsVisible(localFilter); michael@0: michael@0: // Check with showing local add-ons michael@0: EventUtils.synthesizeMouseAtCenter(localFilter, { }, gManagerWindow); michael@0: check_results(aQuery, aSortBy, aReverseOrder, true); michael@0: michael@0: // Check with showing remote add-ons michael@0: aLocalOnly = aLocalOnly || false; michael@0: EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); michael@0: check_results(aQuery, aSortBy, aReverseOrder, aLocalOnly); 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 (var 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: /* michael@0: * Get item for a specific install by name michael@0: * michael@0: * @param aName michael@0: * The name of the install to search for michael@0: * @return Row of install if found, null otherwise michael@0: */ michael@0: function get_install_item(aName) { michael@0: var sourceURI = "http://example.com/" + aName + ".xpi"; michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: var rows = list.getElementsByTagName("richlistitem"); michael@0: for (var row of rows) { michael@0: if (row.mInstall && row.mInstall.sourceURI.spec == sourceURI) michael@0: return row; michael@0: } michael@0: michael@0: return null; michael@0: } michael@0: michael@0: /* michael@0: * Gets the install button for a specific item michael@0: * michael@0: * @param aItem michael@0: * The item to get the install button for michael@0: * @return The install button for aItem michael@0: */ michael@0: function get_install_button(aItem) { michael@0: isnot(aItem, null, "Item should not be null when checking state of install button"); michael@0: var installStatus = getAnonymousElementByAttribute(aItem, "anonid", "install-status"); michael@0: return getAnonymousElementByAttribute(installStatus, "anonid", "install-remote-btn"); michael@0: } michael@0: michael@0: michael@0: // Tests that searching for the empty string does nothing when not in the search view michael@0: add_test(function() { michael@0: is(gCategoryUtilities.isTypeVisible("search"), false, "Search category should initially be hidden"); michael@0: michael@0: var selectedCategory = gCategoryUtilities.selectedCategory; michael@0: isnot(selectedCategory, "search", "Selected type should not initially be the search view"); michael@0: search("", true, run_next_test, selectedCategory); michael@0: }); michael@0: michael@0: // Tests that the results from a query are sorted by relevancescore in descending order. michael@0: // Also test that double clicking non-install items goes to the detail view, and that michael@0: // only remote items have install buttons showing michael@0: add_test(function() { michael@0: search(QUERY, false, function() { michael@0: check_filtered_results(QUERY, "relevancescore", false); michael@0: michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: var results = get_actual_results(); michael@0: for (var result of results) { michael@0: var installBtn = get_install_button(result.item); michael@0: is(installBtn.hidden, result.name.indexOf("remote") != 0, michael@0: "Install button should only be showing for remote items"); michael@0: } michael@0: michael@0: var currentIndex = -1; michael@0: function run_next_double_click_test() { michael@0: currentIndex++; michael@0: if (currentIndex >= results.length) { michael@0: run_next_test(); michael@0: return; michael@0: } michael@0: michael@0: var result = results[currentIndex]; michael@0: if (result.name.indexOf("install") == 0) { michael@0: run_next_double_click_test(); michael@0: return; michael@0: } michael@0: michael@0: var item = result.item; michael@0: list.ensureElementIsVisible(item); michael@0: EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow); michael@0: EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow); michael@0: wait_for_view_load(gManagerWindow, function() { michael@0: var name = gManagerWindow.document.getElementById("detail-name").textContent; michael@0: is(name, item.mAddon.name, "Name in detail view should be correct"); michael@0: var version = gManagerWindow.document.getElementById("detail-version").value; michael@0: is(version, item.mAddon.version, "Version in detail view should be correct"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(gManagerWindow.document.getElementById("category-search"), michael@0: { }, gManagerWindow); michael@0: wait_for_view_load(gManagerWindow, run_next_double_click_test); michael@0: }); michael@0: } michael@0: michael@0: run_next_double_click_test(); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that the sorters and filters correctly manipulate the results michael@0: add_test(function() { michael@0: var sorters = gManagerWindow.document.getElementById("search-sorters"); michael@0: var originalHandler = sorters.handler; michael@0: michael@0: var sorterNames = ["name", "dateUpdated"]; michael@0: var buttonIds = ["name-btn", "date-btn"]; michael@0: var currentIndex = 0; michael@0: var currentReversed = false; michael@0: michael@0: function run_sort_test() { michael@0: if (currentIndex >= sorterNames.length) { michael@0: sorters.handler = originalHandler; michael@0: run_next_test(); michael@0: return; michael@0: } michael@0: michael@0: // Simulate clicking on a specific sorter michael@0: var buttonId = buttonIds[currentIndex]; michael@0: var sorter = getAnonymousElementByAttribute(sorters, "anonid", buttonId); michael@0: is_element_visible(sorter); michael@0: EventUtils.synthesizeMouseAtCenter(sorter, { }, gManagerWindow); michael@0: } michael@0: michael@0: sorters.handler = { michael@0: onSortChanged: function(aSortBy, aAscending) { michael@0: if (originalHandler && "onSortChanged" in originalHandler) michael@0: originalHandler.onSortChanged(aSortBy, aAscending); michael@0: michael@0: check_filtered_results(QUERY, sorterNames[currentIndex], currentReversed); michael@0: michael@0: if (currentReversed) michael@0: currentIndex++; michael@0: currentReversed = !currentReversed; michael@0: michael@0: run_sort_test(); michael@0: } michael@0: }; michael@0: michael@0: check_filtered_results(QUERY, "relevancescore", false); michael@0: run_sort_test(); michael@0: }); michael@0: michael@0: // Tests that searching for the empty string does nothing when in search view michael@0: add_test(function() { michael@0: search("", true, function() { michael@0: check_filtered_results(QUERY, "dateUpdated", true); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that clicking a different category hides the search query michael@0: add_test(function() { michael@0: gCategoryUtilities.openType("extension", function() { michael@0: is(gCategoryUtilities.isTypeVisible("search"), false, "Search category should be hidden"); michael@0: is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension"); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that re-searching for query doesn't actually complete a new search, michael@0: // and the last sort is still used michael@0: add_test(function() { michael@0: search(QUERY, true, function() { michael@0: check_filtered_results(QUERY, "dateUpdated", true); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that getting zero results works correctly michael@0: add_test(function() { michael@0: search(NO_MATCH_QUERY, false, function() { michael@0: check_filtered_results(NO_MATCH_QUERY, "relevancescore", false); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that installing a remote add-on works michael@0: add_test(function() { michael@0: var installBtn = null; michael@0: michael@0: var listener = { michael@0: onInstallEnded: function(aInstall, aAddon) { michael@0: // Don't immediately consider the installed add-on as local because michael@0: // if the user was filtering out local add-ons, the installed add-on michael@0: // would vanish. Only consider add-on as local on new searches. michael@0: michael@0: aInstall.removeListener(this); michael@0: michael@0: is(installBtn.hidden, true, "Install button should be hidden after install ended"); michael@0: check_filtered_results(QUERY, "relevancescore", false); michael@0: run_next_test(); michael@0: } michael@0: } michael@0: michael@0: search(QUERY, false, function() { michael@0: var list = gManagerWindow.document.getElementById("search-list"); michael@0: var remoteItem = get_addon_item(REMOTE_TO_INSTALL); michael@0: list.ensureElementIsVisible(remoteItem); michael@0: michael@0: installBtn = get_install_button(remoteItem); michael@0: is(installBtn.hidden, false, "Install button should be showing before install"); michael@0: remoteItem.mAddon.install.addListener(listener); michael@0: EventUtils.synthesizeMouseAtCenter(installBtn, { }, gManagerWindow); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that re-searching for query results in correct results michael@0: add_test(function() { michael@0: // Select a different category michael@0: gCategoryUtilities.openType("extension", function() { michael@0: is(gCategoryUtilities.isTypeVisible("search"), false, "Search category should be hidden"); michael@0: is(gCategoryUtilities.selectedCategory, "extension", "View should have changed to extension"); michael@0: michael@0: var installBtn = get_install_button(get_addon_item(REMOTE_TO_INSTALL)); michael@0: is(installBtn.hidden, true, "Install button should be hidden for installed item"); michael@0: michael@0: search(QUERY, true, function() { michael@0: check_filtered_results(QUERY, "relevancescore", false); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that incompatible add-ons are shown with a warning if compatibility checking is disabled michael@0: add_test(function() { michael@0: AddonManager.checkCompatibility = false; michael@0: search("incompatible", false, function() { michael@0: var item = get_addon_item("remote5"); michael@0: is_element_visible(item, "Incompatible addon should be visible"); michael@0: is(item.getAttribute("notification"), "warning", "Compatibility warning should be shown"); michael@0: michael@0: item = get_addon_item("remote6"); michael@0: is(item, null, "Addon incompatible with the product should not be visible"); michael@0: michael@0: AddonManager.checkCompatibility = true; michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: // Tests that compatible-by-default addons are shown if strict compatibility checking is disabled michael@0: add_test(function() { michael@0: restart_manager(gManagerWindow, null, function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: michael@0: Services.prefs.setBoolPref(PREF_STRICT_COMPAT, false); michael@0: search("incompatible", false, function() { michael@0: var item = get_addon_item("remote5"); michael@0: is_element_visible(item, "Incompatible addon should be visible"); michael@0: isnot(item.getAttribute("notification"), "warning", "Compatibility warning should not be shown"); michael@0: michael@0: var item = get_addon_item("remote6"); michael@0: is(item, null, "Addon incompatible with the product should not be visible"); michael@0: michael@0: Services.prefs.setBoolPref(PREF_STRICT_COMPAT, true); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: michael@0: // Tests that restarting the manager doesn't change search results michael@0: add_test(function() { michael@0: restart_manager(gManagerWindow, null, function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: michael@0: // We never restore to the search pane michael@0: is(gCategoryUtilities.selectedCategory, "discover", "View should have changed to discover"); michael@0: michael@0: // Installed add-on is considered local on new search michael@0: gAddonInstalled = true; michael@0: michael@0: search(QUERY, false, function() { michael@0: check_filtered_results(QUERY, "relevancescore", false); michael@0: michael@0: var installBtn = get_install_button(get_addon_item(REMOTE_TO_INSTALL)); michael@0: is(installBtn.hidden, true, "Install button should be hidden for installed item"); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: }); michael@0: michael@0: function bug_815120_test_search(aLocalOnly) { michael@0: restart_manager(gManagerWindow, "addons://list/extension", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: michael@0: // Installed add-on is considered local on new search michael@0: gAddonInstalled = true; michael@0: michael@0: // The search buttons should be hidden in the LocalOnly setup michael@0: var localFilterButton = aWindow.document.getElementById("search-filter-local"); michael@0: is(aLocalOnly, is_hidden(localFilterButton), "Local filter button visibility does not match, aLocalOnly = " + aLocalOnly); michael@0: michael@0: var remoteFilterButton = aWindow.document.getElementById("search-filter-remote"); michael@0: is(aLocalOnly, is_hidden(remoteFilterButton), "Remote filter button visibility does not match, aLocalOnly = " + aLocalOnly); michael@0: michael@0: search(QUERY, false, function() { michael@0: check_filtered_results(QUERY, "relevancescore", false, aLocalOnly); michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: // Tests for Bug 815120 michael@0: add_test(function() { michael@0: Services.prefs.setBoolPref(PREF_XPI_ENABLED, false); michael@0: bug_815120_test_search(true); michael@0: }); michael@0: michael@0: add_test(function() { michael@0: Services.prefs.setBoolPref(PREF_XPI_ENABLED, true); michael@0: bug_815120_test_search(false); michael@0: }); michael@0: