toolkit/components/places/tests/bookmarks/test_818584-discard-duplicate-backups.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     3  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /**
     6  * Checks that automatically created bookmark backups are discarded if they are
     7  * duplicate of an existing ones.
     8  */
     9 function run_test() {
    10   run_next_test();
    11 }
    13 add_task(function() {
    14   // Create a backup for yesterday in the backups folder.
    15   let backupFolder = yield PlacesBackups.getBackupFolder();
    16   let dateObj = new Date();
    17   dateObj.setDate(dateObj.getDate() - 1);
    18   let oldBackupName = PlacesBackups.getFilenameForDate(dateObj);
    19   let oldBackup = OS.Path.join(backupFolder, oldBackupName);
    20   let {count: count, hash: hash} = yield BookmarkJSONUtils.exportToFile(oldBackup);
    21   do_check_true(count > 0);
    22   do_check_eq(hash.length, 24);
    23   oldBackupName = oldBackupName.replace(/\.json/, "_" + count + "_" + hash + ".json");
    24   yield OS.File.move(oldBackup, OS.Path.join(backupFolder, oldBackupName));
    26   // Create a backup.
    27   // This should just rename the existing backup, so in the end there should be
    28   // only one backup with today's date.
    29   yield PlacesBackups.create();
    31   // Get the hash of the generated backup
    32   let backupFiles = yield PlacesBackups.getBackupFiles();
    33   do_check_eq(backupFiles.length, 1);
    35   let matches = OS.Path.basename(backupFiles[0]).match(PlacesBackups.filenamesRegex);
    36   do_check_eq(matches[1], new Date().toLocaleFormat("%Y-%m-%d"));
    37   do_check_eq(matches[2], count);
    38   do_check_eq(matches[3], hash);
    40   // Add a bookmark and create another backup.
    41   let bookmarkId = PlacesUtils.bookmarks.insertBookmark(PlacesUtils.bookmarks.bookmarksMenuFolder,
    42                                                         uri("http://foo.com"),
    43                                                         PlacesUtils.bookmarks.DEFAULT_INDEX,
    44                                                         "foo");
    45   // We must enforce a backup since one for today already exists.  The forced
    46   // backup will replace the existing one.
    47   yield PlacesBackups.create(undefined, true);
    48   do_check_eq(backupFiles.length, 1);
    49   recentBackup = yield PlacesBackups.getMostRecentBackup();
    50   do_check_neq(recentBackup, OS.Path.join(backupFolder, oldBackupName));
    51   matches = OS.Path.basename(recentBackup).match(PlacesBackups.filenamesRegex);
    52   do_check_eq(matches[1], new Date().toLocaleFormat("%Y-%m-%d"));
    53   do_check_eq(matches[2], count + 1);
    54   do_check_neq(matches[3], hash);
    56   // Clean up
    57   PlacesUtils.bookmarks.removeItem(bookmarkId);
    58   yield PlacesBackups.create(0);
    59 });

mercurial