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

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

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

mercurial