gecko/toolkit/components/places/tests/bookmarks/test_417228-exclude-from-backup.js
Jim Blandy 4d6a633bba Bug 914753: Make Emacs file variable header lines correct, or at least consistent. DONTBUILD r=ehsan
The -*- file variable lines -*- establish per-file settings that Emacs will
pick up. This patch makes the following changes to those lines (and touches
nothing else):

 - Never set the buffer's mode.

   Years ago, Emacs did not have a good JavaScript mode, so it made sense
   to use Java or C++ mode in .js files. However, Emacs has had js-mode for
   years now; it's perfectly serviceable, and is available and enabled by
   default in all major Emacs packagings.

   Selecting a mode in the -*- file variable line -*- is almost always the
   wrong thing to do anyway. It overrides Emacs's default choice, which is
   (now) reasonable; and even worse, it overrides settings the user might
   have made in their '.emacs' file for that file extension. It's only
   useful when there's something specific about that particular file that
   makes a particular mode appropriate.

 - Correctly propagate settings that establish the correct indentation
   level for this file: c-basic-offset and js2-basic-offset should be
   js-indent-level. Whatever value they're given should be preserved;
   different parts of our tree use different indentation styles.

 - We don't use tabs in Mozilla JS code. Always set indent-tabs-mode: nil.
   Remove tab-width: settings, at least in files that don't contain tab
   characters.

 - Remove js2-mode settings that belong in the user's .emacs file, like
   js2-skip-preprocessor-directives.
2014-06-24 22:12:07 -07:00

142 lines
5.3 KiB
JavaScript

/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const EXCLUDE_FROM_BACKUP_ANNO = "places/excludeFromBackup";
// Menu, Toolbar, Unsorted, Tags
const PLACES_ROOTS_COUNT = 4;
var tests = [];
/*
Backup/restore tests example:
var myTest = {
populate: function () { ... add bookmarks ... },
validate: function () { ... query for your bookmarks ... }
}
this.push(myTest);
*/
var test = {
populate: function populate() {
// check initial size
var rootNode = PlacesUtils.getFolderContents(PlacesUtils.placesRootId,
false, false).root;
do_check_eq(rootNode.childCount, PLACES_ROOTS_COUNT );
rootNode.containerOpen = false;
var idx = PlacesUtils.bookmarks.DEFAULT_INDEX;
// create a root to be restore
this._restoreRootTitle = "restore root";
var restoreRootId = PlacesUtils.bookmarks
.createFolder(PlacesUtils.placesRootId,
this._restoreRootTitle, idx);
// add a test bookmark
this._restoreRootURI = uri("http://restore.uri");
PlacesUtils.bookmarks.insertBookmark(restoreRootId, this._restoreRootURI,
idx, "restore uri");
// add a test bookmark to be exclude
this._restoreRootExcludeURI = uri("http://exclude.uri");
var exItemId = PlacesUtils.bookmarks
.insertBookmark(restoreRootId,
this._restoreRootExcludeURI,
idx, "exclude uri");
// Annotate the bookmark for exclusion.
PlacesUtils.annotations.setItemAnnotation(exItemId,
EXCLUDE_FROM_BACKUP_ANNO, 1, 0,
PlacesUtils.annotations.EXPIRE_NEVER);
// create a root to be exclude
this._excludeRootTitle = "exclude root";
this._excludeRootId = PlacesUtils.bookmarks
.createFolder(PlacesUtils.placesRootId,
this._excludeRootTitle, idx);
// Annotate the root for exclusion.
PlacesUtils.annotations.setItemAnnotation(this._excludeRootId,
EXCLUDE_FROM_BACKUP_ANNO, 1, 0,
PlacesUtils.annotations.EXPIRE_NEVER);
// add a test bookmark exclude by exclusion of its parent
PlacesUtils.bookmarks.insertBookmark(this._excludeRootId,
this._restoreRootExcludeURI,
idx, "exclude uri");
},
validate: function validate(aEmptyBookmarks) {
var rootNode = PlacesUtils.getFolderContents(PlacesUtils.placesRootId,
false, false).root;
if (!aEmptyBookmarks) {
// since restore does not remove backup exclude items both
// roots should still exist.
do_check_eq(rootNode.childCount, PLACES_ROOTS_COUNT + 2);
// open exclude root and check it still contains one item
var restoreRootIndex = PLACES_ROOTS_COUNT;
var excludeRootIndex = PLACES_ROOTS_COUNT+1;
var excludeRootNode = rootNode.getChild(excludeRootIndex);
do_check_eq(this._excludeRootTitle, excludeRootNode.title);
excludeRootNode.QueryInterface(Ci.nsINavHistoryQueryResultNode);
excludeRootNode.containerOpen = true;
do_check_eq(excludeRootNode.childCount, 1);
var excludeRootChildNode = excludeRootNode.getChild(0);
do_check_eq(excludeRootChildNode.uri, this._restoreRootExcludeURI.spec);
excludeRootNode.containerOpen = false;
}
else {
// exclude root should not exist anymore
do_check_eq(rootNode.childCount, PLACES_ROOTS_COUNT + 1);
var restoreRootIndex = PLACES_ROOTS_COUNT;
}
var restoreRootNode = rootNode.getChild(restoreRootIndex);
do_check_eq(this._restoreRootTitle, restoreRootNode.title);
restoreRootNode.QueryInterface(Ci.nsINavHistoryQueryResultNode);
restoreRootNode.containerOpen = true;
do_check_eq(restoreRootNode.childCount, 1);
var restoreRootChildNode = restoreRootNode.getChild(0);
do_check_eq(restoreRootChildNode.uri, this._restoreRootURI.spec);
restoreRootNode.containerOpen = false;
rootNode.containerOpen = false;
}
}
function run_test() {
run_next_test();
}
add_task(function() {
// make json file
let jsonFile = OS.Path.join(OS.Constants.Path.profileDir, "bookmarks.json");
// populate db
test.populate();
yield BookmarkJSONUtils.exportToFile(jsonFile);
// restore json file
yield BookmarkJSONUtils.importFromFile(jsonFile, true);
// validate without removing all bookmarks
// restore do not remove backup exclude entries
test.validate(false);
// cleanup
remove_all_bookmarks();
// manually remove the excluded root
PlacesUtils.bookmarks.removeItem(test._excludeRootId);
// restore json file
yield BookmarkJSONUtils.importFromFile(jsonFile, true);
// validate after a complete bookmarks cleanup
test.validate(true);
// clean up
yield OS.File.remove(jsonFile);
});