1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_bug714593.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,140 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// Tests that installed addons in the search view load inline prefs properly 1.9 + 1.10 +const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; 1.11 +const NO_MATCH_URL = TESTROOT + "browser_searching_empty.xml"; 1.12 + 1.13 +var gManagerWindow; 1.14 +var gCategoryUtilities; 1.15 +var gProvider; 1.16 + 1.17 +function test() { 1.18 + // Turn on searching for this test 1.19 + Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); 1.20 + 1.21 + waitForExplicitFinish(); 1.22 + 1.23 + gProvider = new MockProvider(); 1.24 + 1.25 + gProvider.createAddons([{ 1.26 + id: "inlinesettings2@tests.mozilla.org", 1.27 + name: "Inline Settings (Regular)", 1.28 + version: "1", 1.29 + optionsURL: CHROMEROOT + "options.xul", 1.30 + optionsType: AddonManager.OPTIONS_TYPE_INLINE 1.31 + }]); 1.32 + 1.33 + open_manager("addons://list/extension", function(aWindow) { 1.34 + gManagerWindow = aWindow; 1.35 + gCategoryUtilities = new CategoryUtilities(gManagerWindow); 1.36 + run_next_test(); 1.37 + }); 1.38 +} 1.39 + 1.40 +function end_test() { 1.41 + close_manager(gManagerWindow, finish); 1.42 +} 1.43 + 1.44 +/* 1.45 + * Checks whether or not the Add-ons Manager is currently searching 1.46 + * 1.47 + * @param aExpectedSearching 1.48 + * The expected isSearching state 1.49 + */ 1.50 +function check_is_searching(aExpectedSearching) { 1.51 + var loading = gManagerWindow.document.getElementById("search-loading"); 1.52 + is(!is_hidden(loading), aExpectedSearching, 1.53 + "Search throbber should be showing iff currently searching"); 1.54 +} 1.55 + 1.56 +/* 1.57 + * Completes a search 1.58 + * 1.59 + * @param aQuery 1.60 + * The query to search for 1.61 + * @param aFinishImmediately 1.62 + * Boolean representing whether or not the search is expected to 1.63 + * finish immediately 1.64 + * @param aCallback 1.65 + * The callback to call when the search is done 1.66 + * @param aCategoryType 1.67 + * The expected selected category after the search is done. 1.68 + * Optional and defaults to "search" 1.69 + */ 1.70 +function search(aQuery, aFinishImmediately, aCallback, aCategoryType) { 1.71 + // Point search to the correct xml test file 1.72 + Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, NO_MATCH_URL); 1.73 + 1.74 + aCategoryType = aCategoryType ? aCategoryType : "search"; 1.75 + 1.76 + var searchBox = gManagerWindow.document.getElementById("header-search"); 1.77 + searchBox.value = aQuery; 1.78 + 1.79 + EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); 1.80 + EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); 1.81 + 1.82 + var finishImmediately = true; 1.83 + wait_for_view_load(gManagerWindow, function() { 1.84 + is(gCategoryUtilities.selectedCategory, aCategoryType, "Expected category view should be selected"); 1.85 + is(gCategoryUtilities.isTypeVisible("search"), aCategoryType == "search", 1.86 + "Search category should only be visible if it is the current view"); 1.87 + is(finishImmediately, aFinishImmediately, "Search should finish immediately only if expected"); 1.88 + 1.89 + aCallback(); 1.90 + }); 1.91 + 1.92 + finishImmediately = false 1.93 + if (!aFinishImmediately) 1.94 + check_is_searching(true); 1.95 +} 1.96 + 1.97 +/* 1.98 + * Get item for a specific add-on by name 1.99 + * 1.100 + * @param aName 1.101 + * The name of the add-on to search for 1.102 + * @return Row of add-on if found, null otherwise 1.103 + */ 1.104 +function get_addon_item(aName) { 1.105 + var id = aName + "@tests.mozilla.org"; 1.106 + var list = gManagerWindow.document.getElementById("search-list"); 1.107 + var rows = list.getElementsByTagName("richlistitem"); 1.108 + for (let row of rows) { 1.109 + if (row.mAddon && row.mAddon.id == id) 1.110 + return row; 1.111 + } 1.112 + 1.113 + return null; 1.114 +} 1.115 + 1.116 +add_test(function() { 1.117 + search("settings", false, function() { 1.118 + var localFilter = gManagerWindow.document.getElementById("search-filter-local"); 1.119 + EventUtils.synthesizeMouseAtCenter(localFilter, { }, gManagerWindow); 1.120 + 1.121 + var item = get_addon_item("inlinesettings2"); 1.122 + // Force the XBL binding to apply. 1.123 + item.clientTop; 1.124 + var button = gManagerWindow.document.getAnonymousElementByAttribute(item, "anonid", "preferences-btn"); 1.125 + is_element_visible(button, "Preferences button should be visible"); 1.126 + 1.127 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.128 + wait_for_view_load(gManagerWindow, function() { 1.129 + is(gManagerWindow.gViewController.currentViewObj, gManagerWindow.gDetailView, "View should have changed to detail"); 1.130 + 1.131 + var searchCategory = gManagerWindow.document.getElementById("category-search"); 1.132 + EventUtils.synthesizeMouseAtCenter(searchCategory, { }, gManagerWindow); 1.133 + wait_for_view_load(gManagerWindow, function() { 1.134 + is(gManagerWindow.gViewController.currentViewObj, gManagerWindow.gSearchView, "View should have changed back to search"); 1.135 + 1.136 + // Reset filter to remote to avoid breaking later tests. 1.137 + var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); 1.138 + EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); 1.139 + run_next_test(); 1.140 + }); 1.141 + }); 1.142 + }); 1.143 +});