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 | // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- |
michael@0 | 2 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | var HistoryTestHelper = { |
michael@0 | 8 | _originalNavHistoryService: null, |
michael@0 | 9 | _startView: null, |
michael@0 | 10 | MockNavHistoryService: { |
michael@0 | 11 | getNewQueryOptions: function () { |
michael@0 | 12 | return {}; |
michael@0 | 13 | }, |
michael@0 | 14 | getNewQuery: function () { |
michael@0 | 15 | return { |
michael@0 | 16 | setFolders: function(){} |
michael@0 | 17 | }; |
michael@0 | 18 | }, |
michael@0 | 19 | executeQuery: function () { |
michael@0 | 20 | return { |
michael@0 | 21 | root: { |
michael@0 | 22 | get childCount() { |
michael@0 | 23 | return Object.keys(HistoryTestHelper._nodes).length; |
michael@0 | 24 | }, |
michael@0 | 25 | |
michael@0 | 26 | getChild: function (aIndex) HistoryTestHelper._nodes[Object.keys(HistoryTestHelper._nodes)[aIndex]] |
michael@0 | 27 | } |
michael@0 | 28 | } |
michael@0 | 29 | } |
michael@0 | 30 | }, |
michael@0 | 31 | |
michael@0 | 32 | _originalHistoryService: null, |
michael@0 | 33 | MockHistoryService: { |
michael@0 | 34 | removePage: function (aURI) { |
michael@0 | 35 | delete HistoryTestHelper._nodes[aURI.spec]; |
michael@0 | 36 | |
michael@0 | 37 | // Simulate observer notification |
michael@0 | 38 | HistoryTestHelper._startView.onDeleteURI(aURI); |
michael@0 | 39 | }, |
michael@0 | 40 | }, |
michael@0 | 41 | |
michael@0 | 42 | Node: function (aTitle, aURISpec) { |
michael@0 | 43 | this.title = aTitle; |
michael@0 | 44 | this.uri = aURISpec; |
michael@0 | 45 | this.pinned = true |
michael@0 | 46 | }, |
michael@0 | 47 | |
michael@0 | 48 | _nodes: null, |
michael@0 | 49 | createNodes: function (aMany) { |
michael@0 | 50 | this._nodes = {}; |
michael@0 | 51 | for (let i=0; i<aMany; i++) { |
michael@0 | 52 | let title = "mock-history-" + i; |
michael@0 | 53 | let uri = "http://" + title + ".com.br/"; |
michael@0 | 54 | |
michael@0 | 55 | this._nodes[uri] = new this.Node(title, uri); |
michael@0 | 56 | } |
michael@0 | 57 | }, |
michael@0 | 58 | |
michael@0 | 59 | _originalPinHelper: null, |
michael@0 | 60 | MockPinHelper: { |
michael@0 | 61 | isPinned: function (aItem) HistoryTestHelper._nodes[aItem].pinned, |
michael@0 | 62 | setUnpinned: function (aItem) HistoryTestHelper._nodes[aItem].pinned = false, |
michael@0 | 63 | setPinned: function (aItem) HistoryTestHelper._nodes[aItem].pinned = true, |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | setup: function setup() { |
michael@0 | 67 | this._startView = Browser.selectedBrowser.contentWindow.HistoryStartView._view; |
michael@0 | 68 | |
michael@0 | 69 | // Just enough items so that there will be one less then the limit |
michael@0 | 70 | // after removing 4 items. |
michael@0 | 71 | this.createNodes(this._startView.maxTiles + 3); |
michael@0 | 72 | |
michael@0 | 73 | this._originalNavHistoryService = this._startView._navHistoryService; |
michael@0 | 74 | this._startView._navHistoryService = this.MockNavHistoryService; |
michael@0 | 75 | |
michael@0 | 76 | this._originalHistoryService = this._startView._historyService; |
michael@0 | 77 | this._startView._historyService= this.MockHistoryService; |
michael@0 | 78 | |
michael@0 | 79 | this._originalPinHelper = this._startView._pinHelper; |
michael@0 | 80 | this._startView._pinHelper = this.MockPinHelper; |
michael@0 | 81 | |
michael@0 | 82 | this._startView._set.clearAll(); |
michael@0 | 83 | this._startView.populateGrid(); |
michael@0 | 84 | }, |
michael@0 | 85 | |
michael@0 | 86 | restore: function () { |
michael@0 | 87 | this._startView._navHistoryService = this._originalNavHistoryService; |
michael@0 | 88 | this._startView._historyService= this._originalHistoryService; |
michael@0 | 89 | this._startView._pinHelper = this._originalPinHelper; |
michael@0 | 90 | |
michael@0 | 91 | this._startView._set.clearAll(); |
michael@0 | 92 | this._startView.populateGrid(); |
michael@0 | 93 | } |
michael@0 | 94 | }; |