Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // Tests that installed addons in the search view load inline prefs properly |
michael@0 | 6 | |
michael@0 | 7 | const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url"; |
michael@0 | 8 | const NO_MATCH_URL = TESTROOT + "browser_searching_empty.xml"; |
michael@0 | 9 | |
michael@0 | 10 | var gManagerWindow; |
michael@0 | 11 | var gCategoryUtilities; |
michael@0 | 12 | var gProvider; |
michael@0 | 13 | |
michael@0 | 14 | function test() { |
michael@0 | 15 | // Turn on searching for this test |
michael@0 | 16 | Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); |
michael@0 | 17 | |
michael@0 | 18 | waitForExplicitFinish(); |
michael@0 | 19 | |
michael@0 | 20 | gProvider = new MockProvider(); |
michael@0 | 21 | |
michael@0 | 22 | gProvider.createAddons([{ |
michael@0 | 23 | id: "inlinesettings2@tests.mozilla.org", |
michael@0 | 24 | name: "Inline Settings (Regular)", |
michael@0 | 25 | version: "1", |
michael@0 | 26 | optionsURL: CHROMEROOT + "options.xul", |
michael@0 | 27 | optionsType: AddonManager.OPTIONS_TYPE_INLINE |
michael@0 | 28 | }]); |
michael@0 | 29 | |
michael@0 | 30 | open_manager("addons://list/extension", function(aWindow) { |
michael@0 | 31 | gManagerWindow = aWindow; |
michael@0 | 32 | gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
michael@0 | 33 | run_next_test(); |
michael@0 | 34 | }); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | function end_test() { |
michael@0 | 38 | close_manager(gManagerWindow, finish); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | /* |
michael@0 | 42 | * Checks whether or not the Add-ons Manager is currently searching |
michael@0 | 43 | * |
michael@0 | 44 | * @param aExpectedSearching |
michael@0 | 45 | * The expected isSearching state |
michael@0 | 46 | */ |
michael@0 | 47 | function check_is_searching(aExpectedSearching) { |
michael@0 | 48 | var loading = gManagerWindow.document.getElementById("search-loading"); |
michael@0 | 49 | is(!is_hidden(loading), aExpectedSearching, |
michael@0 | 50 | "Search throbber should be showing iff currently searching"); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | /* |
michael@0 | 54 | * Completes a search |
michael@0 | 55 | * |
michael@0 | 56 | * @param aQuery |
michael@0 | 57 | * The query to search for |
michael@0 | 58 | * @param aFinishImmediately |
michael@0 | 59 | * Boolean representing whether or not the search is expected to |
michael@0 | 60 | * finish immediately |
michael@0 | 61 | * @param aCallback |
michael@0 | 62 | * The callback to call when the search is done |
michael@0 | 63 | * @param aCategoryType |
michael@0 | 64 | * The expected selected category after the search is done. |
michael@0 | 65 | * Optional and defaults to "search" |
michael@0 | 66 | */ |
michael@0 | 67 | function search(aQuery, aFinishImmediately, aCallback, aCategoryType) { |
michael@0 | 68 | // Point search to the correct xml test file |
michael@0 | 69 | Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, NO_MATCH_URL); |
michael@0 | 70 | |
michael@0 | 71 | aCategoryType = aCategoryType ? aCategoryType : "search"; |
michael@0 | 72 | |
michael@0 | 73 | var searchBox = gManagerWindow.document.getElementById("header-search"); |
michael@0 | 74 | searchBox.value = aQuery; |
michael@0 | 75 | |
michael@0 | 76 | EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); |
michael@0 | 77 | EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); |
michael@0 | 78 | |
michael@0 | 79 | var finishImmediately = true; |
michael@0 | 80 | wait_for_view_load(gManagerWindow, function() { |
michael@0 | 81 | is(gCategoryUtilities.selectedCategory, aCategoryType, "Expected category view should be selected"); |
michael@0 | 82 | is(gCategoryUtilities.isTypeVisible("search"), aCategoryType == "search", |
michael@0 | 83 | "Search category should only be visible if it is the current view"); |
michael@0 | 84 | is(finishImmediately, aFinishImmediately, "Search should finish immediately only if expected"); |
michael@0 | 85 | |
michael@0 | 86 | aCallback(); |
michael@0 | 87 | }); |
michael@0 | 88 | |
michael@0 | 89 | finishImmediately = false |
michael@0 | 90 | if (!aFinishImmediately) |
michael@0 | 91 | check_is_searching(true); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | /* |
michael@0 | 95 | * Get item for a specific add-on by name |
michael@0 | 96 | * |
michael@0 | 97 | * @param aName |
michael@0 | 98 | * The name of the add-on to search for |
michael@0 | 99 | * @return Row of add-on if found, null otherwise |
michael@0 | 100 | */ |
michael@0 | 101 | function get_addon_item(aName) { |
michael@0 | 102 | var id = aName + "@tests.mozilla.org"; |
michael@0 | 103 | var list = gManagerWindow.document.getElementById("search-list"); |
michael@0 | 104 | var rows = list.getElementsByTagName("richlistitem"); |
michael@0 | 105 | for (let row of rows) { |
michael@0 | 106 | if (row.mAddon && row.mAddon.id == id) |
michael@0 | 107 | return row; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | return null; |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | add_test(function() { |
michael@0 | 114 | search("settings", false, function() { |
michael@0 | 115 | var localFilter = gManagerWindow.document.getElementById("search-filter-local"); |
michael@0 | 116 | EventUtils.synthesizeMouseAtCenter(localFilter, { }, gManagerWindow); |
michael@0 | 117 | |
michael@0 | 118 | var item = get_addon_item("inlinesettings2"); |
michael@0 | 119 | // Force the XBL binding to apply. |
michael@0 | 120 | item.clientTop; |
michael@0 | 121 | var button = gManagerWindow.document.getAnonymousElementByAttribute(item, "anonid", "preferences-btn"); |
michael@0 | 122 | is_element_visible(button, "Preferences button should be visible"); |
michael@0 | 123 | |
michael@0 | 124 | EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); |
michael@0 | 125 | wait_for_view_load(gManagerWindow, function() { |
michael@0 | 126 | is(gManagerWindow.gViewController.currentViewObj, gManagerWindow.gDetailView, "View should have changed to detail"); |
michael@0 | 127 | |
michael@0 | 128 | var searchCategory = gManagerWindow.document.getElementById("category-search"); |
michael@0 | 129 | EventUtils.synthesizeMouseAtCenter(searchCategory, { }, gManagerWindow); |
michael@0 | 130 | wait_for_view_load(gManagerWindow, function() { |
michael@0 | 131 | is(gManagerWindow.gViewController.currentViewObj, gManagerWindow.gSearchView, "View should have changed back to search"); |
michael@0 | 132 | |
michael@0 | 133 | // Reset filter to remote to avoid breaking later tests. |
michael@0 | 134 | var remoteFilter = gManagerWindow.document.getElementById("search-filter-remote"); |
michael@0 | 135 | EventUtils.synthesizeMouseAtCenter(remoteFilter, { }, gManagerWindow); |
michael@0 | 136 | run_next_test(); |
michael@0 | 137 | }); |
michael@0 | 138 | }); |
michael@0 | 139 | }); |
michael@0 | 140 | }); |