1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/metro/base/tests/mochitest/helpers/BookmarksHelper.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 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 BookmarksTestHelper = { 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(BookmarksTestHelper._nodes).length; 1.27 + }, 1.28 + 1.29 + getChild: function (aIndex) BookmarksTestHelper._nodes[Object.keys(BookmarksTestHelper._nodes)[aIndex]] 1.30 + } 1.31 + } 1.32 + } 1.33 + }, 1.34 + 1.35 + _originalBookmarkService: null, 1.36 + MockBookmarkService: { 1.37 + getItemIndex: function (aIndex) aIndex, 1.38 + getBookmarkURI: function (aId) BookmarksTestHelper._nodes[aId].uri, 1.39 + getItemTitle: function (aId) BookmarksTestHelper._nodes[aId].title, 1.40 + removeItem: function (aId) { 1.41 + delete BookmarksTestHelper._nodes[aId]; 1.42 + 1.43 + // Simulate observer notification 1.44 + BookmarksTestHelper._startView._changes.onItemRemoved(aId, BookmarksTestHelper._startView._root); 1.45 + }, 1.46 + }, 1.47 + 1.48 + Node: function (aTitle, aId) { 1.49 + this.type = this.RESULT_TYPE_URI = 0; 1.50 + this.title = aTitle; 1.51 + this.itemId = aId; 1.52 + this.uri = "http://" + aTitle + ".com.br"; 1.53 + this.pinned = true 1.54 + }, 1.55 + 1.56 + _nodes: null, 1.57 + createNodes: function (aMany) { 1.58 + this._nodes = {}; 1.59 + for (let i=0; i<aMany; i++) { 1.60 + this._nodes[i] = new this.Node("Mock-Bookmark" + i, i); 1.61 + } 1.62 + }, 1.63 + 1.64 + _originalPinHelper: null, 1.65 + MockPinHelper: { 1.66 + isPinned: function (aItem) BookmarksTestHelper._nodes[aItem].pinned, 1.67 + setUnpinned: function (aItem) BookmarksTestHelper._nodes[aItem].pinned = false, 1.68 + setPinned: function (aItem) BookmarksTestHelper._nodes[aItem].pinned = true, 1.69 + }, 1.70 + 1.71 + _originalUpdateFavicon: null, 1.72 + setup: function setup() { 1.73 + this._startView = Browser.selectedBrowser.contentWindow.BookmarksStartView._view; 1.74 + 1.75 + // Just enough items so that there will be one less then the limit 1.76 + // after removing 4 items. 1.77 + this.createNodes(this._startView.maxTiles + 3); 1.78 + 1.79 + this._originalNavHistoryService = this._startView._navHistoryService; 1.80 + this._startView._navHistoryService = this.MockNavHistoryService; 1.81 + 1.82 + this._originalBookmarkService = this._startView._bookmarkService; 1.83 + this._startView._bookmarkService= this.MockBookmarkService; 1.84 + 1.85 + this._originalPinHelper = this._startView._pinHelper; 1.86 + this._startView._pinHelper = this.MockPinHelper; 1.87 + 1.88 + this._originalUpdateFavicon = this._startView._updateFavicon; 1.89 + this._startView._updateFavicon = function () {}; 1.90 + 1.91 + this._startView.clearBookmarks(); 1.92 + this._startView.getBookmarks(); 1.93 + }, 1.94 + 1.95 + restore: function () { 1.96 + this._startView._navHistoryService = this._originalNavHistoryService; 1.97 + this._startView._bookmarkService= this._originalBookmarkService; 1.98 + this._startView._pinHelper = this._originalPinHelper; 1.99 + this._startView._updateFavicon = this._originalUpdateFavicon; 1.100 + 1.101 + this._startView.clearBookmarks(); 1.102 + this._startView.getBookmarks(); 1.103 + } 1.104 +};