toolkit/components/places/tests/unit/test_421180.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 // Get bookmarks service
michael@0 8 try {
michael@0 9 var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
michael@0 10 getService(Ci.nsINavBookmarksService);
michael@0 11 }
michael@0 12 catch(ex) {
michael@0 13 do_throw("Could not get bookmarks service\n");
michael@0 14 }
michael@0 15
michael@0 16 // Get database connection
michael@0 17 try {
michael@0 18 var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
michael@0 19 getService(Ci.nsINavHistoryService);
michael@0 20 var mDBConn = histsvc.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection;
michael@0 21 }
michael@0 22 catch(ex) {
michael@0 23 do_throw("Could not get database connection\n");
michael@0 24 }
michael@0 25
michael@0 26 add_test(function test_keywordRemovedOnUniqueItemRemoval() {
michael@0 27 var bookmarkedURI = uri("http://foo.bar");
michael@0 28 var keyword = "testkeyword";
michael@0 29
michael@0 30 // TEST 1
michael@0 31 // 1. add a bookmark
michael@0 32 // 2. add a keyword to it
michael@0 33 // 3. remove bookmark
michael@0 34 // 4. check that keyword has gone
michael@0 35 var bookmarkId = bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder,
michael@0 36 bookmarkedURI,
michael@0 37 bmsvc.DEFAULT_INDEX,
michael@0 38 "A bookmark");
michael@0 39 bmsvc.setKeywordForBookmark(bookmarkId, keyword);
michael@0 40 // remove bookmark
michael@0 41 bmsvc.removeItem(bookmarkId);
michael@0 42
michael@0 43 promiseAsyncUpdates().then(function() {
michael@0 44 // Check that keyword has been removed from the database.
michael@0 45 // The removal is asynchronous.
michael@0 46 var sql = "SELECT id FROM moz_keywords WHERE keyword = ?1";
michael@0 47 var stmt = mDBConn.createStatement(sql);
michael@0 48 stmt.bindByIndex(0, keyword);
michael@0 49 do_check_false(stmt.executeStep());
michael@0 50 stmt.finalize();
michael@0 51
michael@0 52 run_next_test();
michael@0 53 });
michael@0 54 });
michael@0 55
michael@0 56 add_test(function test_keywordNotRemovedOnNonUniqueItemRemoval() {
michael@0 57 var bookmarkedURI = uri("http://foo.bar");
michael@0 58 var keyword = "testkeyword";
michael@0 59
michael@0 60 // TEST 2
michael@0 61 // 1. add 2 bookmarks
michael@0 62 // 2. add the same keyword to them
michael@0 63 // 3. remove first bookmark
michael@0 64 // 4. check that keyword is still there
michael@0 65 var bookmarkId1 = bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder,
michael@0 66 bookmarkedURI,
michael@0 67 bmsvc.DEFAULT_INDEX,
michael@0 68 "A bookmark");
michael@0 69 bmsvc.setKeywordForBookmark(bookmarkId1, keyword);
michael@0 70
michael@0 71 var bookmarkId2 = bmsvc.insertBookmark(bmsvc.toolbarFolder,
michael@0 72 bookmarkedURI,
michael@0 73 bmsvc.DEFAULT_INDEX,
michael@0 74 keyword);
michael@0 75 bmsvc.setKeywordForBookmark(bookmarkId2, keyword);
michael@0 76
michael@0 77 // remove first bookmark
michael@0 78 bmsvc.removeItem(bookmarkId1);
michael@0 79
michael@0 80 promiseAsyncUpdates().then(function() {
michael@0 81 // check that keyword is still there
michael@0 82 var sql = "SELECT id FROM moz_keywords WHERE keyword = ?1";
michael@0 83 var stmt = mDBConn.createStatement(sql);
michael@0 84 stmt.bindByIndex(0, keyword);
michael@0 85 do_check_true(stmt.executeStep());
michael@0 86 stmt.finalize();
michael@0 87
michael@0 88 run_next_test();
michael@0 89 });
michael@0 90 });
michael@0 91
michael@0 92 function run_test() {
michael@0 93 run_next_test();
michael@0 94 }

mercurial