browser_history_sidebar_search.js
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is mozilla.org code.
15  *
16  * The Initial Developer of the Original Code is
17  * Mozilla Corporation.
18  * Portions created by the Initial Developer are Copyright (C) 2009
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Marco Bonardo <mak77@bonardo.net>
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
42 const Cc = Components.classes;
43 const Ci = Components.interfaces;
44 const Cr = Components.results;
45 
46 var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
47  getService(Ci.nsINavHistoryService);
48 var bh = hs.QueryInterface(Ci.nsIBrowserHistory);
49 var ios = Cc["@mozilla.org/network/io-service;1"].
50  getService(Ci.nsIIOService);
51 function uri(spec) {
52  return ios.newURI(spec, null, null);
53 }
54 
55 var sidebar = document.getElementById("sidebar");
56 
57 function add_visit(aURI, aDate) {
58  var visitId = hs.addVisit(aURI,
59  aDate,
60  null, // no referrer
61  hs.TRANSITION_TYPED, // user typed in URL bar
62  false, // not redirect
63  0);
64  return visitId;
65 }
66 
67 // Visited pages listed by descending visit date.
68 var pages = [
69  "http://sidebar.mozilla.org/a",
70  "http://sidebar.mozilla.org/b",
71  "http://sidebar.mozilla.org/c",
72  "http://www.mozilla.org/d",
73 ];
74 // Number of pages that will be filtered out by the search.
75 const FILTERED_COUNT = 1;
76 
77 function test() {
79 
80  // Cleanup.
81  bh.removeAllPages();
82 
83  // Add some visited page.
84  var time = Date.now();
85  for (var i = 0; i < pages.length; i++) {
86  add_visit(uri(pages[i]), (time - i) * 1000);
87  }
88 
89  sidebar.addEventListener("load", function() {
90  sidebar.removeEventListener("load", arguments.callee, true);
91  executeSoon(function() {
92  // Set "by last visited" in the sidebar (sort by visit date descendind).
93  sidebar.contentDocument.getElementById("bylastvisited").doCommand();
94  check_sidebar_tree_order(pages.length);
95  var searchBox = sidebar.contentDocument.getElementById("search-box");
96  ok(searchBox, "search box is in context");
97  searchBox.value = "sidebar.mozilla";
98  searchBox.doCommand();
100  searchBox.value = "";
101  searchBox.doCommand();
102  check_sidebar_tree_order(pages.length);
103 
104  // Cleanup.
105  toggleSidebar("viewHistorySidebar", false);
106  bh.removeAllPages();
107 
108  finish();
109  });
110  }, true);
111  toggleSidebar("viewHistorySidebar", true);
112 }
113 
114 function check_sidebar_tree_order(aExpectedRows) {
115  var tree = sidebar.contentDocument.getElementById("historyTree");
116  var treeView = tree.view;
117  var rc = treeView.rowCount;
118  is(rc, aExpectedRows, "All expected tree rows are present");
119  var columns = tree.columns;
120  is(columns.count, 1, "There should be only 1 column in the sidebar");
121  for (var r = 0; r < rc; r++) {
122  var node = treeView.nodeForTreeIndex(r);
123  is(node.uri, pages[r], "Node is in correct position based on its visit date");
124  }
125 }
function uri(spec)
function add_visit(aURI, aDate)
getService(Ci.sbIFaceplateManager)
function test()
waitForExplicitFinish()
var columns
function check_sidebar_tree_order(aExpectedRows)
return null
Definition: FeedWriter.js:1143
let node
return!aWindow arguments!aWindow arguments[0]
_getSelectedPageStyle s i
var treeView