browser_ui_history_sidebar.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) 2008
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dietrich Ayala <dietrich@mozilla.com>
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 
38 /*
39 Tests the performance of opening the History
40 sidebar in all the available views.
41 */
42 
43 /*********************** begin header **********************/
45 
46 const TEST_IDENTIFIER = "ui-perf-test";
47 const TEST_SUITE = "places";
48 
49 const Cc = Components.classes;
50 const Ci = Components.interfaces;
51 const Cr = Components.results;
52 
53 var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
54  getService(Ci.nsIWindowMediator);
55 var win = wm.getMostRecentWindow("navigator:browser");
56 var ios = Cc["@mozilla.org/network/io-service;1"].
57  getService(Ci.nsIIOService);
58 var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
59  getService(Ci.nsINavHistoryService);
60 var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
61  getService(Ci.nsINavBookmarksService);
62 
63 var sidebar = document.getElementById("sidebar");
64 
65 function add_visit(aURI, aDate) {
66  var visitId = hs.addVisit(aURI,
67  aDate,
68  null, // no referrer
69  hs.TRANSITION_TYPED, // user typed in URL bar
70  false, // not redirect
71  0);
72  return visitId;
73 }
74 
75 function add_bookmark(aURI) {
76  var bId = bs.insertBookmark(bs.unfiledBookmarksFolder, aURI,
77  bs.DEFAULT_INDEX, "bookmark/" + aURI.spec);
78  return bId;
79 }
80 
81 function make_test_report(testName, result, units) {
82  return [TEST_IDENTIFIER, TEST_SUITE, testName, result, units||"ms"].join(":");
83 }
84 
85 // Each test is an obj w/ a name property and run method
86 var ptests = [];
87 
88 /*********************** end header **********************/
89 
90 const TEST_REPEAT_COUNT = 10;
91 
92 // test duration of history sidebar opening
93 // default: bydayandsite
94 ptests.push({
95  name: "open_history_sidebar_bydayandsite",
96  times: [],
97  run: function() {
98  var self = this;
99  var start = Date.now();
100  sidebar.addEventListener("load", function(aEvent) {
101  sidebar.removeEventListener("load", arguments.callee, true);
102  executeSoon(function() {
103  var duration = Date.now() - start;
104  toggleSidebar("viewHistorySidebar", false);
105  self.times.push(duration);
106  if (self.times.length == TEST_REPEAT_COUNT)
107  self.finish();
108  else
109  self.run();
110  });
111  }, true);
112  toggleSidebar("viewHistorySidebar", true);
113  },
114  finish: function() {
115  processTestResult(this);
116  runNextTest();
117  }
118 });
119 
120 // bysite
121 ptests.push({
122  name: "history_sidebar_bysite",
123  times: [],
124  run: function() {
125  var self = this;
126  var start = Date.now();
127  sidebar.addEventListener("load", function() {
128  sidebar.removeEventListener("load", arguments.callee, true);
129  executeSoon(function() {
130  var duration = Date.now() - start;
131  sidebar.contentDocument.getElementById("bysite").doCommand();
132  toggleSidebar("viewHistorySidebar", false);
133  self.times.push(duration);
134  if (self.times.length == TEST_REPEAT_COUNT)
135  self.finish();
136  else
137  self.run();
138  });
139  }, true);
140  toggleSidebar("viewHistorySidebar", true);
141  },
142  finish: function() {
143  processTestResult(this);
144  runNextTest();
145  }
146 });
147 
148 // byday
149 ptests.push({
150  name: "history_sidebar_byday",
151  times: [],
152  run: function() {
153  var self = this;
154  var start = Date.now();
155  sidebar.addEventListener("load", function() {
156  sidebar.removeEventListener("load", arguments.callee, true);
157  executeSoon(function() {
158  var duration = Date.now() - start;
159  sidebar.contentDocument.getElementById("byday").doCommand();
160  toggleSidebar("viewHistorySidebar", false);
161  self.times.push(duration);
162  if (self.times.length == TEST_REPEAT_COUNT)
163  self.finish();
164  else
165  self.run();
166  });
167  }, true);
168  toggleSidebar("viewHistorySidebar", true);
169  },
170  finish: function() {
171  processTestResult(this);
172  runNextTest();
173  }
174 });
175 
176 // byvisited
177 ptests.push({
178  name: "history_sidebar_byvisited",
179  times: [],
180  run: function() {
181  var self = this;
182  var start = Date.now();
183  sidebar.addEventListener("load", function() {
184  sidebar.removeEventListener("load", arguments.callee, true);
185  executeSoon(function() {
186  var duration = Date.now() - start;
187  sidebar.contentDocument.getElementById("byvisited").doCommand();
188  toggleSidebar("viewHistorySidebar", false);
189  self.times.push(duration);
190  if (self.times.length == TEST_REPEAT_COUNT)
191  self.finish();
192  else
193  self.run();
194  });
195  }, true);
196  toggleSidebar("viewHistorySidebar", true);
197  },
198  finish: function() {
199  processTestResult(this);
200  runNextTest();
201  }
202 });
203 
204 // bylastvisited
205 ptests.push({
206  name: "history_sidebar_bylastvisited",
207  times: [],
208  run: function() {
209  var self = this;
210  var start = Date.now();
211  sidebar.addEventListener("load", function() {
212  sidebar.removeEventListener("load", arguments.callee, true);
213  executeSoon(function() {
214  var duration = Date.now() - start;
215  sidebar.contentDocument.getElementById("bylastvisited").doCommand();
216  toggleSidebar("viewHistorySidebar", false);
217  self.times.push(duration);
218  if (self.times.length == TEST_REPEAT_COUNT)
219  self.finish();
220  else
221  self.run();
222  });
223  }, true);
224  toggleSidebar("viewHistorySidebar", true);
225  },
226  finish: function() {
227  processTestResult(this);
228  runNextTest();
229  }
230 });
231 
232 function processTestResult(aTest) {
233  aTest.times.sort(); // sort the scores
234  aTest.times.pop(); // remove worst
235  aTest.times.shift(); // remove best
236  var totalDuration = aTest.times.reduce(function(time, total){ return time + total; });
237  var avgDuration = totalDuration/aTest.times.length;
238  var report = make_test_report(aTest.name, avgDuration);
239  ok(true, report);
240 }
241 
242 function test() {
243  // kick off tests
244  runNextTest();
245 }
246 
247 function runNextTest() {
248  if (ptests.length > 0)
249  ptests.shift().run();
250  else
251  finish();
252 }
function start(ch)
var total
function processTestResult(aTest)
function test()
const TEST_SUITE
const TEST_IDENTIFIER
function runNextTest()
getService(Ci.sbIFaceplateManager)
_hideDatepicker duration
waitForExplicitFinish()
return null
Definition: FeedWriter.js:1143
return!aWindow arguments!aWindow arguments[0]
function make_test_report(testName, result, units)
const TEST_REPEAT_COUNT
function add_bookmark(aURI)
function add_visit(aURI, aDate)