browser/metro/base/tests/mochitest/helpers/HistoryHelper.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 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           },
    26           getChild: function (aIndex) HistoryTestHelper._nodes[Object.keys(HistoryTestHelper._nodes)[aIndex]]
    27         }
    28       }
    29     }
    30   },
    32   _originalHistoryService: null,
    33   MockHistoryService: {
    34     removePage: function (aURI) {
    35       delete HistoryTestHelper._nodes[aURI.spec];
    37       // Simulate observer notification
    38       HistoryTestHelper._startView.onDeleteURI(aURI);
    39     },
    40   },
    42   Node: function (aTitle, aURISpec) {
    43     this.title = aTitle;
    44     this.uri = aURISpec;
    45     this.pinned = true
    46   },
    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/";
    55       this._nodes[uri] = new this.Node(title, uri);
    56     }
    57   },
    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   },
    66   setup: function setup() {
    67     this._startView = Browser.selectedBrowser.contentWindow.HistoryStartView._view;
    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);
    73     this._originalNavHistoryService = this._startView._navHistoryService;
    74     this._startView._navHistoryService = this.MockNavHistoryService;
    76     this._originalHistoryService = this._startView._historyService;
    77     this._startView._historyService= this.MockHistoryService;
    79     this._originalPinHelper = this._startView._pinHelper;
    80     this._startView._pinHelper = this.MockPinHelper;
    82     this._startView._set.clearAll();
    83     this._startView.populateGrid();
    84   },
    86   restore: function () {
    87     this._startView._navHistoryService = this._originalNavHistoryService;
    88     this._startView._historyService= this._originalHistoryService;
    89     this._startView._pinHelper = this._originalPinHelper;
    91     this._startView._set.clearAll();
    92     this._startView.populateGrid();
    93   }
    94 };

mercurial