toolkit/components/places/tests/unit/test_405497.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/unit/test_405497.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    1.11 +
    1.12 +var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
    1.13 +         getService(Ci.nsINavHistoryService);
    1.14 +var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    1.15 +         getService(Ci.nsINavBookmarksService);
    1.16 +
    1.17 +/**
    1.18 + * The callback object for runInBatchMode.
    1.19 + *
    1.20 + * @param aService
    1.21 + *        Takes a reference to the history service or the bookmark service.
    1.22 + *        This determines which service should be called when calling the second
    1.23 + *        runInBatchMode the second time.
    1.24 + */
    1.25 +function callback(aService)
    1.26 +{
    1.27 +  this.callCount = 0;
    1.28 +  this.service = aService;
    1.29 +}
    1.30 +callback.prototype = {
    1.31 +  //////////////////////////////////////////////////////////////////////////////
    1.32 +  //// nsINavHistoryBatchCallback
    1.33 +
    1.34 +  runBatched: function(aUserData)
    1.35 +  {
    1.36 +    this.callCount++;
    1.37 +
    1.38 +    if (this.callCount == 1) {
    1.39 +      // We want to call run in batched once more.
    1.40 +      this.service.runInBatchMode(this, null);
    1.41 +      return;
    1.42 +    }
    1.43 +
    1.44 +    do_check_eq(this.callCount, 2);
    1.45 +    do_test_finished();
    1.46 +  },
    1.47 +
    1.48 +  //////////////////////////////////////////////////////////////////////////////
    1.49 +  //// nsISupports
    1.50 +
    1.51 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsINavHistoryBatchCallback])
    1.52 +};
    1.53 +
    1.54 +function run_test() {
    1.55 +  // checking the history service
    1.56 +  do_test_pending();
    1.57 +  hs.runInBatchMode(new callback(hs), null);
    1.58 +
    1.59 +  // checking the bookmark service
    1.60 +  do_test_pending();
    1.61 +  bs.runInBatchMode(new callback(bs), null);
    1.62 +}

mercurial