michael@0: /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var tests = []; michael@0: michael@0: /* michael@0: michael@0: Backup/restore tests example: michael@0: michael@0: var myTest = { michael@0: populate: function () { ... add bookmarks ... }, michael@0: validate: function () { ... query for your bookmarks ... } michael@0: } michael@0: michael@0: this.push(myTest); michael@0: michael@0: */ michael@0: michael@0: var quotesTest = { michael@0: _folderTitle: '"quoted folder"', michael@0: _folderId: null, michael@0: michael@0: populate: function () { michael@0: this._folderId = michael@0: PlacesUtils.bookmarks.createFolder(PlacesUtils.toolbarFolderId, michael@0: this._folderTitle, michael@0: PlacesUtils.bookmarks.DEFAULT_INDEX); michael@0: }, michael@0: michael@0: clean: function () { michael@0: PlacesUtils.bookmarks.removeItem(this._folderId); michael@0: }, michael@0: michael@0: validate: function () { michael@0: var query = PlacesUtils.history.getNewQuery(); michael@0: query.setFolders([PlacesUtils.bookmarks.toolbarFolder], 1); michael@0: var result = PlacesUtils.history.executeQuery(query, PlacesUtils.history.getNewQueryOptions()); michael@0: michael@0: var toolbar = result.root; michael@0: toolbar.containerOpen = true; michael@0: michael@0: // test for our quoted folder michael@0: do_check_true(toolbar.childCount, 1); michael@0: var folderNode = toolbar.getChild(0); michael@0: do_check_eq(folderNode.type, folderNode.RESULT_TYPE_FOLDER); michael@0: do_check_eq(folderNode.title, this._folderTitle); michael@0: michael@0: // clean up michael@0: toolbar.containerOpen = false; michael@0: } michael@0: } michael@0: tests.push(quotesTest); michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_task(function () { michael@0: // make json file michael@0: let jsonFile = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.json"); michael@0: michael@0: // populate db michael@0: tests.forEach(function(aTest) { michael@0: aTest.populate(); michael@0: // sanity michael@0: aTest.validate(); michael@0: }); michael@0: michael@0: // export json to file michael@0: yield BookmarkJSONUtils.exportToFile(jsonFile); michael@0: michael@0: // clean michael@0: tests.forEach(function(aTest) { michael@0: aTest.clean(); michael@0: }); michael@0: michael@0: // restore json file michael@0: yield BookmarkJSONUtils.importFromFile(jsonFile, true); michael@0: michael@0: // validate michael@0: tests.forEach(function(aTest) { michael@0: aTest.validate(); michael@0: }); michael@0: michael@0: // clean up michael@0: yield OS.File.remove(jsonFile); michael@0: michael@0: });