browser/metro/base/tests/mochitest/helpers/BookmarksHelper.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 BookmarksTestHelper = {
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(BookmarksTestHelper._nodes).length;
michael@0 24 },
michael@0 25
michael@0 26 getChild: function (aIndex) BookmarksTestHelper._nodes[Object.keys(BookmarksTestHelper._nodes)[aIndex]]
michael@0 27 }
michael@0 28 }
michael@0 29 }
michael@0 30 },
michael@0 31
michael@0 32 _originalBookmarkService: null,
michael@0 33 MockBookmarkService: {
michael@0 34 getItemIndex: function (aIndex) aIndex,
michael@0 35 getBookmarkURI: function (aId) BookmarksTestHelper._nodes[aId].uri,
michael@0 36 getItemTitle: function (aId) BookmarksTestHelper._nodes[aId].title,
michael@0 37 removeItem: function (aId) {
michael@0 38 delete BookmarksTestHelper._nodes[aId];
michael@0 39
michael@0 40 // Simulate observer notification
michael@0 41 BookmarksTestHelper._startView._changes.onItemRemoved(aId, BookmarksTestHelper._startView._root);
michael@0 42 },
michael@0 43 },
michael@0 44
michael@0 45 Node: function (aTitle, aId) {
michael@0 46 this.type = this.RESULT_TYPE_URI = 0;
michael@0 47 this.title = aTitle;
michael@0 48 this.itemId = aId;
michael@0 49 this.uri = "http://" + aTitle + ".com.br";
michael@0 50 this.pinned = true
michael@0 51 },
michael@0 52
michael@0 53 _nodes: null,
michael@0 54 createNodes: function (aMany) {
michael@0 55 this._nodes = {};
michael@0 56 for (let i=0; i<aMany; i++) {
michael@0 57 this._nodes[i] = new this.Node("Mock-Bookmark" + i, i);
michael@0 58 }
michael@0 59 },
michael@0 60
michael@0 61 _originalPinHelper: null,
michael@0 62 MockPinHelper: {
michael@0 63 isPinned: function (aItem) BookmarksTestHelper._nodes[aItem].pinned,
michael@0 64 setUnpinned: function (aItem) BookmarksTestHelper._nodes[aItem].pinned = false,
michael@0 65 setPinned: function (aItem) BookmarksTestHelper._nodes[aItem].pinned = true,
michael@0 66 },
michael@0 67
michael@0 68 _originalUpdateFavicon: null,
michael@0 69 setup: function setup() {
michael@0 70 this._startView = Browser.selectedBrowser.contentWindow.BookmarksStartView._view;
michael@0 71
michael@0 72 // Just enough items so that there will be one less then the limit
michael@0 73 // after removing 4 items.
michael@0 74 this.createNodes(this._startView.maxTiles + 3);
michael@0 75
michael@0 76 this._originalNavHistoryService = this._startView._navHistoryService;
michael@0 77 this._startView._navHistoryService = this.MockNavHistoryService;
michael@0 78
michael@0 79 this._originalBookmarkService = this._startView._bookmarkService;
michael@0 80 this._startView._bookmarkService= this.MockBookmarkService;
michael@0 81
michael@0 82 this._originalPinHelper = this._startView._pinHelper;
michael@0 83 this._startView._pinHelper = this.MockPinHelper;
michael@0 84
michael@0 85 this._originalUpdateFavicon = this._startView._updateFavicon;
michael@0 86 this._startView._updateFavicon = function () {};
michael@0 87
michael@0 88 this._startView.clearBookmarks();
michael@0 89 this._startView.getBookmarks();
michael@0 90 },
michael@0 91
michael@0 92 restore: function () {
michael@0 93 this._startView._navHistoryService = this._originalNavHistoryService;
michael@0 94 this._startView._bookmarkService= this._originalBookmarkService;
michael@0 95 this._startView._pinHelper = this._originalPinHelper;
michael@0 96 this._startView._updateFavicon = this._originalUpdateFavicon;
michael@0 97
michael@0 98 this._startView.clearBookmarks();
michael@0 99 this._startView.getBookmarks();
michael@0 100 }
michael@0 101 };

mercurial