1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/unit/test_421180.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 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 +// Get bookmarks service 1.11 +try { 1.12 + var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. 1.13 + getService(Ci.nsINavBookmarksService); 1.14 +} 1.15 +catch(ex) { 1.16 + do_throw("Could not get bookmarks service\n"); 1.17 +} 1.18 + 1.19 +// Get database connection 1.20 +try { 1.21 + var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"]. 1.22 + getService(Ci.nsINavHistoryService); 1.23 + var mDBConn = histsvc.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection; 1.24 +} 1.25 +catch(ex) { 1.26 + do_throw("Could not get database connection\n"); 1.27 +} 1.28 + 1.29 +add_test(function test_keywordRemovedOnUniqueItemRemoval() { 1.30 + var bookmarkedURI = uri("http://foo.bar"); 1.31 + var keyword = "testkeyword"; 1.32 + 1.33 + // TEST 1 1.34 + // 1. add a bookmark 1.35 + // 2. add a keyword to it 1.36 + // 3. remove bookmark 1.37 + // 4. check that keyword has gone 1.38 + var bookmarkId = bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, 1.39 + bookmarkedURI, 1.40 + bmsvc.DEFAULT_INDEX, 1.41 + "A bookmark"); 1.42 + bmsvc.setKeywordForBookmark(bookmarkId, keyword); 1.43 + // remove bookmark 1.44 + bmsvc.removeItem(bookmarkId); 1.45 + 1.46 + promiseAsyncUpdates().then(function() { 1.47 + // Check that keyword has been removed from the database. 1.48 + // The removal is asynchronous. 1.49 + var sql = "SELECT id FROM moz_keywords WHERE keyword = ?1"; 1.50 + var stmt = mDBConn.createStatement(sql); 1.51 + stmt.bindByIndex(0, keyword); 1.52 + do_check_false(stmt.executeStep()); 1.53 + stmt.finalize(); 1.54 + 1.55 + run_next_test(); 1.56 + }); 1.57 +}); 1.58 + 1.59 +add_test(function test_keywordNotRemovedOnNonUniqueItemRemoval() { 1.60 + var bookmarkedURI = uri("http://foo.bar"); 1.61 + var keyword = "testkeyword"; 1.62 + 1.63 + // TEST 2 1.64 + // 1. add 2 bookmarks 1.65 + // 2. add the same keyword to them 1.66 + // 3. remove first bookmark 1.67 + // 4. check that keyword is still there 1.68 + var bookmarkId1 = bmsvc.insertBookmark(bmsvc.bookmarksMenuFolder, 1.69 + bookmarkedURI, 1.70 + bmsvc.DEFAULT_INDEX, 1.71 + "A bookmark"); 1.72 + bmsvc.setKeywordForBookmark(bookmarkId1, keyword); 1.73 + 1.74 + var bookmarkId2 = bmsvc.insertBookmark(bmsvc.toolbarFolder, 1.75 + bookmarkedURI, 1.76 + bmsvc.DEFAULT_INDEX, 1.77 + keyword); 1.78 + bmsvc.setKeywordForBookmark(bookmarkId2, keyword); 1.79 + 1.80 + // remove first bookmark 1.81 + bmsvc.removeItem(bookmarkId1); 1.82 + 1.83 + promiseAsyncUpdates().then(function() { 1.84 + // check that keyword is still there 1.85 + var sql = "SELECT id FROM moz_keywords WHERE keyword = ?1"; 1.86 + var stmt = mDBConn.createStatement(sql); 1.87 + stmt.bindByIndex(0, keyword); 1.88 + do_check_true(stmt.executeStep()); 1.89 + stmt.finalize(); 1.90 + 1.91 + run_next_test(); 1.92 + }); 1.93 +}); 1.94 + 1.95 +function run_test() { 1.96 + run_next_test(); 1.97 +}