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.

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

mercurial