1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/places/tests/bookmarks/test_424958-json-quoted-folders.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,91 @@ 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 +/* 1.13 + 1.14 +Backup/restore tests example: 1.15 + 1.16 +var myTest = { 1.17 + populate: function () { ... add bookmarks ... }, 1.18 + validate: function () { ... query for your bookmarks ... } 1.19 +} 1.20 + 1.21 +this.push(myTest); 1.22 + 1.23 +*/ 1.24 + 1.25 +var quotesTest = { 1.26 + _folderTitle: '"quoted folder"', 1.27 + _folderId: null, 1.28 + 1.29 + populate: function () { 1.30 + this._folderId = 1.31 + PlacesUtils.bookmarks.createFolder(PlacesUtils.toolbarFolderId, 1.32 + this._folderTitle, 1.33 + PlacesUtils.bookmarks.DEFAULT_INDEX); 1.34 + }, 1.35 + 1.36 + clean: function () { 1.37 + PlacesUtils.bookmarks.removeItem(this._folderId); 1.38 + }, 1.39 + 1.40 + validate: function () { 1.41 + var query = PlacesUtils.history.getNewQuery(); 1.42 + query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1); 1.43 + var result = PlacesUtils.history.executeQuery(query, PlacesUtils.history.getNewQueryOptions()); 1.44 + 1.45 + var toolbar = result.root; 1.46 + toolbar.containerOpen = true; 1.47 + 1.48 + // test for our quoted folder 1.49 + do_check_true(toolbar.childCount, 1); 1.50 + var folderNode = toolbar.getChild(0); 1.51 + do_check_eq(folderNode.type, folderNode.RESULT_TYPE_FOLDER); 1.52 + do_check_eq(folderNode.title, this._folderTitle); 1.53 + 1.54 + // clean up 1.55 + toolbar.containerOpen = false; 1.56 + } 1.57 +} 1.58 +tests.push(quotesTest); 1.59 + 1.60 +function run_test() { 1.61 + run_next_test(); 1.62 +} 1.63 + 1.64 +add_task(function () { 1.65 + // make json file 1.66 + let jsonFile = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.json"); 1.67 + 1.68 + // populate db 1.69 + tests.forEach(function(aTest) { 1.70 + aTest.populate(); 1.71 + // sanity 1.72 + aTest.validate(); 1.73 + }); 1.74 + 1.75 + // export json to file 1.76 + yield BookmarkJSONUtils.exportToFile(jsonFile); 1.77 + 1.78 + // clean 1.79 + tests.forEach(function(aTest) { 1.80 + aTest.clean(); 1.81 + }); 1.82 + 1.83 + // restore json file 1.84 + yield BookmarkJSONUtils.importFromFile(jsonFile, true); 1.85 + 1.86 + // validate 1.87 + tests.forEach(function(aTest) { 1.88 + aTest.validate(); 1.89 + }); 1.90 + 1.91 + // clean up 1.92 + yield OS.File.remove(jsonFile); 1.93 + 1.94 +});