1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/tests/mochitest/helpers/HistoryHelper.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- 1.5 +/* Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +var HistoryTestHelper = { 1.11 + _originalNavHistoryService: null, 1.12 + _startView: null, 1.13 + MockNavHistoryService: { 1.14 + getNewQueryOptions: function () { 1.15 + return {}; 1.16 + }, 1.17 + getNewQuery: function () { 1.18 + return { 1.19 + setFolders: function(){} 1.20 + }; 1.21 + }, 1.22 + executeQuery: function () { 1.23 + return { 1.24 + root: { 1.25 + get childCount() { 1.26 + return Object.keys(HistoryTestHelper._nodes).length; 1.27 + }, 1.28 + 1.29 + getChild: function (aIndex) HistoryTestHelper._nodes[Object.keys(HistoryTestHelper._nodes)[aIndex]] 1.30 + } 1.31 + } 1.32 + } 1.33 + }, 1.34 + 1.35 + _originalHistoryService: null, 1.36 + MockHistoryService: { 1.37 + removePage: function (aURI) { 1.38 + delete HistoryTestHelper._nodes[aURI.spec]; 1.39 + 1.40 + // Simulate observer notification 1.41 + HistoryTestHelper._startView.onDeleteURI(aURI); 1.42 + }, 1.43 + }, 1.44 + 1.45 + Node: function (aTitle, aURISpec) { 1.46 + this.title = aTitle; 1.47 + this.uri = aURISpec; 1.48 + this.pinned = true 1.49 + }, 1.50 + 1.51 + _nodes: null, 1.52 + createNodes: function (aMany) { 1.53 + this._nodes = {}; 1.54 + for (let i=0; i<aMany; i++) { 1.55 + let title = "mock-history-" + i; 1.56 + let uri = "http://" + title + ".com.br/"; 1.57 + 1.58 + this._nodes[uri] = new this.Node(title, uri); 1.59 + } 1.60 + }, 1.61 + 1.62 + _originalPinHelper: null, 1.63 + MockPinHelper: { 1.64 + isPinned: function (aItem) HistoryTestHelper._nodes[aItem].pinned, 1.65 + setUnpinned: function (aItem) HistoryTestHelper._nodes[aItem].pinned = false, 1.66 + setPinned: function (aItem) HistoryTestHelper._nodes[aItem].pinned = true, 1.67 + }, 1.68 + 1.69 + setup: function setup() { 1.70 + this._startView = Browser.selectedBrowser.contentWindow.HistoryStartView._view; 1.71 + 1.72 + // Just enough items so that there will be one less then the limit 1.73 + // after removing 4 items. 1.74 + this.createNodes(this._startView.maxTiles + 3); 1.75 + 1.76 + this._originalNavHistoryService = this._startView._navHistoryService; 1.77 + this._startView._navHistoryService = this.MockNavHistoryService; 1.78 + 1.79 + this._originalHistoryService = this._startView._historyService; 1.80 + this._startView._historyService= this.MockHistoryService; 1.81 + 1.82 + this._originalPinHelper = this._startView._pinHelper; 1.83 + this._startView._pinHelper = this.MockPinHelper; 1.84 + 1.85 + this._startView._set.clearAll(); 1.86 + this._startView.populateGrid(); 1.87 + }, 1.88 + 1.89 + restore: function () { 1.90 + this._startView._navHistoryService = this._originalNavHistoryService; 1.91 + this._startView._historyService= this._originalHistoryService; 1.92 + this._startView._pinHelper = this._originalPinHelper; 1.93 + 1.94 + this._startView._set.clearAll(); 1.95 + this._startView.populateGrid(); 1.96 + } 1.97 +};