toolkit/mozapps/extensions/test/browser/browser_bug714593.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial