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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 const NS_PLACES_INIT_COMPLETE_TOPIC = "places-init-complete";
     8 const NS_PLACES_DATABASE_LOCKED_TOPIC = "places-database-locked";
    10 function run_test() {
    11   do_test_pending();
    13   // Create an observer for the Places notifications
    14   var os = Cc["@mozilla.org/observer-service;1"].
    15          getService(Ci.nsIObserverService);
    16   var observer = {
    17     _lockedNotificationReceived: false,
    18     observe: function thn_observe(aSubject, aTopic, aData)
    19     {
    20       switch (aTopic) {
    21         case NS_PLACES_INIT_COMPLETE_TOPIC:
    22           do_check_true(this._lockedNotificationReceived);
    23           os.removeObserver(this, NS_PLACES_INIT_COMPLETE_TOPIC);
    24           os.removeObserver(this, NS_PLACES_DATABASE_LOCKED_TOPIC);
    25           do_test_finished();
    26           break;
    27         case NS_PLACES_DATABASE_LOCKED_TOPIC:
    28           if (this._lockedNotificationReceived)
    29             do_throw("Locked notification should be observed only one time");
    30           this._lockedNotificationReceived = true;
    31           break;
    32       }
    33     }
    34   };
    35   os.addObserver(observer, NS_PLACES_INIT_COMPLETE_TOPIC, false);
    36   os.addObserver(observer, NS_PLACES_DATABASE_LOCKED_TOPIC, false);
    38   // Create a dummy places.sqlite and open an unshared connection on it
    39   var dirSvc = Cc["@mozilla.org/file/directory_service;1"].
    40                getService(Ci.nsIProperties);
    41   var db = dirSvc.get('ProfD', Ci.nsIFile);
    42   db.append("places.sqlite");
    43   var storage = Cc["@mozilla.org/storage/service;1"].
    44                 getService(Ci.mozIStorageService);
    45   var dbConn = storage.openUnsharedDatabase(db);
    46   do_check_true(db.exists());
    48   // We need an exclusive lock on the db
    49   dbConn.executeSimpleSQL("PRAGMA locking_mode = EXCLUSIVE");
    50   // Exclusive locking is lazy applied, we need to make a write to activate it
    51   dbConn.executeSimpleSQL("PRAGMA USER_VERSION = 1");
    53   // Try to create history service while the db is locked
    54   try {
    55     var hs1 = Cc["@mozilla.org/browser/nav-history-service;1"].
    56               getService(Ci.nsINavHistoryService);
    57     do_throw("Creating an instance of history service on a locked db should throw");
    58   } catch (ex) {}
    60   // Close our connection and try to cleanup the file (could fail on Windows)
    61   dbConn.close();
    62   if (db.exists()) {
    63     try {
    64       db.remove(false);
    65     } catch(e) { dump("Unable to remove dummy places.sqlite"); }
    66   }
    68   // Create history service correctly
    69   try {
    70     var hs2 = Cc["@mozilla.org/browser/nav-history-service;1"].
    71               getService(Ci.nsINavHistoryService);
    72   } catch (ex) {
    73     do_throw("Creating an instance of history service on a not locked db should not throw");
    74   }
    75 }

mercurial