1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/bookmarks/test_458683.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,131 @@ 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 +var tests = []; 1.11 + 1.12 +// Get database connection 1.13 +try { 1.14 + var mDBConn = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase) 1.15 + .DBConnection; 1.16 +} 1.17 +catch(ex) { 1.18 + do_throw("Could not get database connection\n"); 1.19 +} 1.20 + 1.21 +/* 1.22 + This test is: 1.23 + - don't block while doing backup and restore if tag containers contain 1.24 + bogus items (separators, folders) 1.25 +*/ 1.26 + 1.27 +var invalidTagChildTest = { 1.28 + _itemTitle: "invalid uri", 1.29 + _itemUrl: "http://test.mozilla.org/", 1.30 + _itemId: -1, 1.31 + _tag: "testTag", 1.32 + _tagItemId: -1, 1.33 + 1.34 + populate: function () { 1.35 + // add a valid bookmark 1.36 + this._itemId = PlacesUtils.bookmarks 1.37 + .insertBookmark(PlacesUtils.toolbarFolderId, 1.38 + PlacesUtils._uri(this._itemUrl), 1.39 + PlacesUtils.bookmarks.DEFAULT_INDEX, 1.40 + this._itemTitle); 1.41 + 1.42 + // create a tag 1.43 + PlacesUtils.tagging.tagURI(PlacesUtils._uri(this._itemUrl), [this._tag]); 1.44 + // get tag folder id 1.45 + var options = PlacesUtils.history.getNewQueryOptions(); 1.46 + var query = PlacesUtils.history.getNewQuery(); 1.47 + query.setFolders([PlacesUtils.bookmarks.tagsFolder], 1); 1.48 + var result = PlacesUtils.history.executeQuery(query, options); 1.49 + var tagRoot = result.root; 1.50 + tagRoot.containerOpen = true; 1.51 + do_check_eq(tagRoot.childCount, 1); 1.52 + var tagNode = tagRoot.getChild(0) 1.53 + .QueryInterface(Ci.nsINavHistoryContainerResultNode); 1.54 + this._tagItemId = tagNode.itemId; 1.55 + tagRoot.containerOpen = false; 1.56 + 1.57 + // add a separator and a folder inside tag folder 1.58 + PlacesUtils.bookmarks.insertSeparator(this._tagItemId, 1.59 + PlacesUtils.bookmarks.DEFAULT_INDEX); 1.60 + PlacesUtils.bookmarks.createFolder(this._tagItemId, 1.61 + "test folder", 1.62 + PlacesUtils.bookmarks.DEFAULT_INDEX); 1.63 + 1.64 + // add a separator and a folder inside tag root 1.65 + PlacesUtils.bookmarks.insertSeparator(PlacesUtils.bookmarks.tagsFolder, 1.66 + PlacesUtils.bookmarks.DEFAULT_INDEX); 1.67 + PlacesUtils.bookmarks.createFolder(PlacesUtils.bookmarks.tagsFolder, 1.68 + "test tags root folder", 1.69 + PlacesUtils.bookmarks.DEFAULT_INDEX); 1.70 + }, 1.71 + 1.72 + clean: function () { 1.73 + PlacesUtils.tagging.untagURI(PlacesUtils._uri(this._itemUrl), [this._tag]); 1.74 + PlacesUtils.bookmarks.removeItem(this._itemId); 1.75 + }, 1.76 + 1.77 + validate: function () { 1.78 + var query = PlacesUtils.history.getNewQuery(); 1.79 + query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1); 1.80 + var options = PlacesUtils.history.getNewQueryOptions(); 1.81 + var result = PlacesUtils.history.executeQuery(query, options); 1.82 + 1.83 + var toolbar = result.root; 1.84 + toolbar.containerOpen = true; 1.85 + 1.86 + // test for our bookmark 1.87 + do_check_eq(toolbar.childCount, 1); 1.88 + for (var i = 0; i < toolbar.childCount; i++) { 1.89 + var folderNode = toolbar.getChild(0); 1.90 + do_check_eq(folderNode.type, folderNode.RESULT_TYPE_URI); 1.91 + do_check_eq(folderNode.title, this._itemTitle); 1.92 + } 1.93 + toolbar.containerOpen = false; 1.94 + 1.95 + // test for our tag 1.96 + var tags = PlacesUtils.tagging.getTagsForURI(PlacesUtils._uri(this._itemUrl)); 1.97 + do_check_eq(tags.length, 1); 1.98 + do_check_eq(tags[0], this._tag); 1.99 + } 1.100 +} 1.101 +tests.push(invalidTagChildTest); 1.102 + 1.103 +function run_test() { 1.104 + run_next_test() 1.105 +} 1.106 + 1.107 +add_task(function () { 1.108 + let jsonFile = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.json"); 1.109 + 1.110 + // populate db 1.111 + tests.forEach(function(aTest) { 1.112 + aTest.populate(); 1.113 + // sanity 1.114 + aTest.validate(); 1.115 + }); 1.116 + 1.117 + yield BookmarkJSONUtils.exportToFile(jsonFile); 1.118 + 1.119 + // clean 1.120 + tests.forEach(function(aTest) { 1.121 + aTest.clean(); 1.122 + }); 1.123 + 1.124 + // restore json file 1.125 + yield BookmarkJSONUtils.importFromFile(jsonFile, true); 1.126 + 1.127 + // validate 1.128 + tests.forEach(function(aTest) { 1.129 + aTest.validate(); 1.130 + }); 1.131 + 1.132 + // clean up 1.133 + yield OS.File.remove(jsonFile); 1.134 +});