Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 var tests = [];
9 /*
11 Backup/restore tests example:
13 var myTest = {
14 populate: function () { ... add bookmarks ... },
15 validate: function () { ... query for your bookmarks ... }
16 }
18 this.push(myTest);
20 */
22 var quotesTest = {
23 _folderTitle: '"quoted folder"',
24 _folderId: null,
26 populate: function () {
27 this._folderId =
28 PlacesUtils.bookmarks.createFolder(PlacesUtils.toolbarFolderId,
29 this._folderTitle,
30 PlacesUtils.bookmarks.DEFAULT_INDEX);
31 },
33 clean: function () {
34 PlacesUtils.bookmarks.removeItem(this._folderId);
35 },
37 validate: function () {
38 var query = PlacesUtils.history.getNewQuery();
39 query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1);
40 var result = PlacesUtils.history.executeQuery(query, PlacesUtils.history.getNewQueryOptions());
42 var toolbar = result.root;
43 toolbar.containerOpen = true;
45 // test for our quoted folder
46 do_check_true(toolbar.childCount, 1);
47 var folderNode = toolbar.getChild(0);
48 do_check_eq(folderNode.type, folderNode.RESULT_TYPE_FOLDER);
49 do_check_eq(folderNode.title, this._folderTitle);
51 // clean up
52 toolbar.containerOpen = false;
53 }
54 }
55 tests.push(quotesTest);
57 function run_test() {
58 run_next_test();
59 }
61 add_task(function () {
62 // make json file
63 let jsonFile = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.json");
65 // populate db
66 tests.forEach(function(aTest) {
67 aTest.populate();
68 // sanity
69 aTest.validate();
70 });
72 // export json to file
73 yield BookmarkJSONUtils.exportToFile(jsonFile);
75 // clean
76 tests.forEach(function(aTest) {
77 aTest.clean();
78 });
80 // restore json file
81 yield BookmarkJSONUtils.importFromFile(jsonFile, true);
83 // validate
84 tests.forEach(function(aTest) {
85 aTest.validate();
86 });
88 // clean up
89 yield OS.File.remove(jsonFile);
91 });