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