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