toolkit/components/places/tests/bookmarks/test_466303-json-remove-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 /* -*- 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 // Since PlacesBackups.getbackupFiles() is a lazy getter, these tests must
     8 // run in the given order, to avoid making it out-of-sync.
    10 add_task(function check_max_backups_is_respected() {
    11   // Get bookmarkBackups directory
    12   let backupFolder = yield PlacesBackups.getBackupFolder();
    14   // Create an html dummy backup in the past.
    15   let htmlPath = OS.Path.join(backupFolder, "bookmarks-2008-01-01.html");
    16   let htmlFile = yield OS.File.open(htmlPath, { truncate: true });
    17   htmlFile.close();
    18   do_check_true(yield OS.File.exists(htmlPath));
    20   // Create a json dummy backup in the past.
    21   let jsonPath = OS.Path.join(backupFolder, "bookmarks-2008-01-31.json");
    22   let jsonFile = yield OS.File.open(jsonPath, { truncate: true });
    23   jsonFile.close();
    24   do_check_true(yield OS.File.exists(jsonPath));
    26   // Export bookmarks to JSON.
    27   // Allow 2 backups, the older one should be removed.
    28   yield PlacesBackups.create(2);
    29   let backupFilename = PlacesBackups.getFilenameForDate();
    31   let count = 0;
    32   let lastBackupPath = null;
    33   let iterator = new OS.File.DirectoryIterator(backupFolder);
    34   try {
    35     yield iterator.forEach(aEntry => {
    36       count++;
    37       if (PlacesBackups.filenamesRegex.test(aEntry.name))
    38         lastBackupPath = aEntry.path;
    39     });
    40   } finally {
    41     iterator.close();
    42   }
    44   do_check_eq(count, 2);
    45   do_check_neq(lastBackupPath, null);
    46   do_check_false(yield OS.File.exists(htmlPath));
    47   do_check_true(yield OS.File.exists(jsonPath));
    48 });
    50 add_task(function check_max_backups_greater_than_backups() {
    51   // Get bookmarkBackups directory
    52   let backupFolder = yield PlacesBackups.getBackupFolder();
    54   // Export bookmarks to JSON.
    55   // Allow 3 backups, none should be removed.
    56   yield PlacesBackups.create(3);
    57   let backupFilename = PlacesBackups.getFilenameForDate();
    59   let count = 0;
    60   let lastBackupPath = null;
    61   let iterator = new OS.File.DirectoryIterator(backupFolder);
    62   try {
    63     yield iterator.forEach(aEntry => {
    64       count++;
    65       if (PlacesBackups.filenamesRegex.test(aEntry.name))
    66         lastBackupPath = aEntry.path;
    67     });
    68   } finally {
    69     iterator.close();
    70   }
    71   do_check_eq(count, 2);
    72   do_check_neq(lastBackupPath, null);
    73 });
    75 add_task(function check_max_backups_null() {
    76   // Get bookmarkBackups directory
    77   let backupFolder = yield PlacesBackups.getBackupFolder();
    79   // Export bookmarks to JSON.
    80   // Allow infinite backups, none should be removed, a new one is not created
    81   // since one for today already exists.
    82   yield PlacesBackups.create(null);
    83   let backupFilename = PlacesBackups.getFilenameForDate();
    85   let count = 0;
    86   let lastBackupPath = null;
    87   let iterator = new OS.File.DirectoryIterator(backupFolder);
    88   try {
    89     yield iterator.forEach(aEntry => {
    90       count++;
    91       if (PlacesBackups.filenamesRegex.test(aEntry.name))
    92         lastBackupPath = aEntry.path;
    93     });
    94   } finally {
    95     iterator.close();
    96   }
    97   do_check_eq(count, 2);
    98   do_check_neq(lastBackupPath, null);
    99 });
   101 add_task(function check_max_backups_undefined() {
   102   // Get bookmarkBackups directory
   103   let backupFolder = yield PlacesBackups.getBackupFolder();
   105   // Export bookmarks to JSON.
   106   // Allow infinite backups, none should be removed, a new one is not created
   107   // since one for today already exists.
   108   yield PlacesBackups.create();
   109   let backupFilename = PlacesBackups.getFilenameForDate();
   111   let count = 0;
   112   let lastBackupPath = null;
   113   let iterator = new OS.File.DirectoryIterator(backupFolder);
   114   try {
   115     yield iterator.forEach(aEntry => {
   116       count++;
   117       if (PlacesBackups.filenamesRegex.test(aEntry.name))
   118         lastBackupPath = aEntry.path;
   119     });
   120   } finally {
   121     iterator.close();
   122   }
   123   do_check_eq(count, 2);
   124   do_check_neq(lastBackupPath, null);
   125 });
   127 function run_test() {
   128   run_next_test();
   129 }

mercurial