|
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/. */ |
|
6 |
|
7 var tests = []; |
|
8 |
|
9 /* |
|
10 |
|
11 Backup/restore tests example: |
|
12 |
|
13 var myTest = { |
|
14 populate: function () { ... add bookmarks ... }, |
|
15 validate: function () { ... query for your bookmarks ... } |
|
16 } |
|
17 |
|
18 this.push(myTest); |
|
19 |
|
20 */ |
|
21 |
|
22 var quotesTest = { |
|
23 _folderTitle: '"quoted folder"', |
|
24 _folderId: null, |
|
25 |
|
26 populate: function () { |
|
27 this._folderId = |
|
28 PlacesUtils.bookmarks.createFolder(PlacesUtils.toolbarFolderId, |
|
29 this._folderTitle, |
|
30 PlacesUtils.bookmarks.DEFAULT_INDEX); |
|
31 }, |
|
32 |
|
33 clean: function () { |
|
34 PlacesUtils.bookmarks.removeItem(this._folderId); |
|
35 }, |
|
36 |
|
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()); |
|
41 |
|
42 var toolbar = result.root; |
|
43 toolbar.containerOpen = true; |
|
44 |
|
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); |
|
50 |
|
51 // clean up |
|
52 toolbar.containerOpen = false; |
|
53 } |
|
54 } |
|
55 tests.push(quotesTest); |
|
56 |
|
57 function run_test() { |
|
58 run_next_test(); |
|
59 } |
|
60 |
|
61 add_task(function () { |
|
62 // make json file |
|
63 let jsonFile = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.json"); |
|
64 |
|
65 // populate db |
|
66 tests.forEach(function(aTest) { |
|
67 aTest.populate(); |
|
68 // sanity |
|
69 aTest.validate(); |
|
70 }); |
|
71 |
|
72 // export json to file |
|
73 yield BookmarkJSONUtils.exportToFile(jsonFile); |
|
74 |
|
75 // clean |
|
76 tests.forEach(function(aTest) { |
|
77 aTest.clean(); |
|
78 }); |
|
79 |
|
80 // restore json file |
|
81 yield BookmarkJSONUtils.importFromFile(jsonFile, true); |
|
82 |
|
83 // validate |
|
84 tests.forEach(function(aTest) { |
|
85 aTest.validate(); |
|
86 }); |
|
87 |
|
88 // clean up |
|
89 yield OS.File.remove(jsonFile); |
|
90 |
|
91 }); |