toolkit/components/places/tests/bookmarks/test_477583_json-backup-in-future.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     7 function run_test() {
     8   do_test_pending();
    10   Task.spawn(function() {
    11     let backupFolder = yield PlacesBackups.getBackupFolder();
    12     let bookmarksBackupDir = new FileUtils.File(backupFolder);
    13     // Remove all files from backups folder.
    14     let files = bookmarksBackupDir.directoryEntries;
    15     while (files.hasMoreElements()) {
    16       let entry = files.getNext().QueryInterface(Ci.nsIFile);
    17       entry.remove(false);
    18     }
    20     // Create a json dummy backup in the future.
    21     let dateObj = new Date();
    22     dateObj.setYear(dateObj.getFullYear() + 1);
    23     let name = PlacesBackups.getFilenameForDate(dateObj);
    24     do_check_eq(name, "bookmarks-" + dateObj.toLocaleFormat("%Y-%m-%d") + ".json");
    25     let files = bookmarksBackupDir.directoryEntries;
    26     while (files.hasMoreElements()) {
    27       let entry = files.getNext().QueryInterface(Ci.nsIFile);
    28       if (PlacesBackups.filenamesRegex.test(entry.leafName))
    29         entry.remove(false);
    30     }
    32     let futureBackupFile = bookmarksBackupDir.clone();
    33     futureBackupFile.append(name);
    34     futureBackupFile.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0600);
    35     do_check_true(futureBackupFile.exists());
    37     do_check_eq((yield PlacesBackups.getBackupFiles()).length, 0);
    39     yield PlacesBackups.create();
    40     // Check that a backup for today has been created.
    41     do_check_eq((yield PlacesBackups.getBackupFiles()).length, 1);
    42     let mostRecentBackupFile = yield PlacesBackups.getMostRecentBackup();
    43     do_check_neq(mostRecentBackupFile, null);
    44     let todayFilename = PlacesBackups.getFilenameForDate();
    45     do_check_true(PlacesBackups.filenamesRegex.test(OS.Path.basename(mostRecentBackupFile)));
    47     // Check that future backup has been removed.
    48     do_check_false(futureBackupFile.exists());
    50     // Cleanup.
    51     mostRecentBackupFile = new FileUtils.File(mostRecentBackupFile);
    52     mostRecentBackupFile.remove(false);
    53     do_check_false(mostRecentBackupFile.exists());
    55     do_test_finished()
    56   });
    57 }

mercurial