toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/places/tests/bookmarks/test_818593-store-backup-metadata.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/**
     1.9 + * To confirm that metadata i.e. bookmark count is set and retrieved for
    1.10 + * automatic backups.
    1.11 + */
    1.12 +function run_test() {
    1.13 +  run_next_test();
    1.14 +}
    1.15 +
    1.16 +add_task(function test_saveBookmarksToJSONFile_and_create()
    1.17 +{
    1.18 +  // Add a bookmark
    1.19 +  let uri = NetUtil.newURI("http://getfirefox.com/");
    1.20 +  let bookmarkId =
    1.21 +    PlacesUtils.bookmarks.insertBookmark(
    1.22 +      PlacesUtils.unfiledBookmarksFolderId, uri,
    1.23 +      PlacesUtils.bookmarks.DEFAULT_INDEX, "Get Firefox!");
    1.24 +
    1.25 +  // Test saveBookmarksToJSONFile()
    1.26 +  let backupFile = FileUtils.getFile("TmpD", ["bookmarks.json"]);
    1.27 +  backupFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, parseInt("0600", 8));
    1.28 +
    1.29 +  let nodeCount = yield PlacesBackups.saveBookmarksToJSONFile(backupFile, true);
    1.30 +  do_check_true(nodeCount > 0);
    1.31 +  do_check_true(backupFile.exists());
    1.32 +  do_check_eq(backupFile.leafName, "bookmarks.json");
    1.33 +
    1.34 +  // Ensure the backup would be copied to our backups folder when the original
    1.35 +  // backup is saved somewhere else.
    1.36 +  let recentBackup = yield PlacesBackups.getMostRecentBackup();
    1.37 +  let matches = OS.Path.basename(recentBackup).match(PlacesBackups.filenamesRegex);
    1.38 +  do_check_eq(matches[2], nodeCount);
    1.39 +  do_check_eq(matches[3].length, 24);
    1.40 +
    1.41 +  // Clear all backups in our backups folder.
    1.42 +  yield PlacesBackups.create(0);
    1.43 +  do_check_eq((yield PlacesBackups.getBackupFiles()).length, 0);
    1.44 +
    1.45 +  // Test create() which saves bookmarks with metadata on the filename.
    1.46 +  yield PlacesBackups.create();
    1.47 +  do_check_eq((yield PlacesBackups.getBackupFiles()).length, 1);
    1.48 +
    1.49 +  mostRecentBackupFile = yield PlacesBackups.getMostRecentBackup();
    1.50 +  do_check_neq(mostRecentBackupFile, null);
    1.51 +  matches = OS.Path.basename(recentBackup).match(PlacesBackups.filenamesRegex);
    1.52 +  do_check_eq(matches[2], nodeCount);
    1.53 +  do_check_eq(matches[3].length, 24);
    1.54 +
    1.55 +  // Cleanup
    1.56 +  backupFile.remove(false);
    1.57 +  yield PlacesBackups.create(0);
    1.58 +  PlacesUtils.bookmarks.removeItem(bookmarkId);
    1.59 +});
    1.60 +

mercurial