toolkit/components/places/tests/bookmarks/test_466303-json-remove-backups.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 // Since PlacesBackups.getbackupFiles() is a lazy getter, these tests must
michael@0 8 // run in the given order, to avoid making it out-of-sync.
michael@0 9
michael@0 10 add_task(function check_max_backups_is_respected() {
michael@0 11 // Get bookmarkBackups directory
michael@0 12 let backupFolder = yield PlacesBackups.getBackupFolder();
michael@0 13
michael@0 14 // Create an html dummy backup in the past.
michael@0 15 let htmlPath = OS.Path.join(backupFolder, "bookmarks-2008-01-01.html");
michael@0 16 let htmlFile = yield OS.File.open(htmlPath, { truncate: true });
michael@0 17 htmlFile.close();
michael@0 18 do_check_true(yield OS.File.exists(htmlPath));
michael@0 19
michael@0 20 // Create a json dummy backup in the past.
michael@0 21 let jsonPath = OS.Path.join(backupFolder, "bookmarks-2008-01-31.json");
michael@0 22 let jsonFile = yield OS.File.open(jsonPath, { truncate: true });
michael@0 23 jsonFile.close();
michael@0 24 do_check_true(yield OS.File.exists(jsonPath));
michael@0 25
michael@0 26 // Export bookmarks to JSON.
michael@0 27 // Allow 2 backups, the older one should be removed.
michael@0 28 yield PlacesBackups.create(2);
michael@0 29 let backupFilename = PlacesBackups.getFilenameForDate();
michael@0 30
michael@0 31 let count = 0;
michael@0 32 let lastBackupPath = null;
michael@0 33 let iterator = new OS.File.DirectoryIterator(backupFolder);
michael@0 34 try {
michael@0 35 yield iterator.forEach(aEntry => {
michael@0 36 count++;
michael@0 37 if (PlacesBackups.filenamesRegex.test(aEntry.name))
michael@0 38 lastBackupPath = aEntry.path;
michael@0 39 });
michael@0 40 } finally {
michael@0 41 iterator.close();
michael@0 42 }
michael@0 43
michael@0 44 do_check_eq(count, 2);
michael@0 45 do_check_neq(lastBackupPath, null);
michael@0 46 do_check_false(yield OS.File.exists(htmlPath));
michael@0 47 do_check_true(yield OS.File.exists(jsonPath));
michael@0 48 });
michael@0 49
michael@0 50 add_task(function check_max_backups_greater_than_backups() {
michael@0 51 // Get bookmarkBackups directory
michael@0 52 let backupFolder = yield PlacesBackups.getBackupFolder();
michael@0 53
michael@0 54 // Export bookmarks to JSON.
michael@0 55 // Allow 3 backups, none should be removed.
michael@0 56 yield PlacesBackups.create(3);
michael@0 57 let backupFilename = PlacesBackups.getFilenameForDate();
michael@0 58
michael@0 59 let count = 0;
michael@0 60 let lastBackupPath = null;
michael@0 61 let iterator = new OS.File.DirectoryIterator(backupFolder);
michael@0 62 try {
michael@0 63 yield iterator.forEach(aEntry => {
michael@0 64 count++;
michael@0 65 if (PlacesBackups.filenamesRegex.test(aEntry.name))
michael@0 66 lastBackupPath = aEntry.path;
michael@0 67 });
michael@0 68 } finally {
michael@0 69 iterator.close();
michael@0 70 }
michael@0 71 do_check_eq(count, 2);
michael@0 72 do_check_neq(lastBackupPath, null);
michael@0 73 });
michael@0 74
michael@0 75 add_task(function check_max_backups_null() {
michael@0 76 // Get bookmarkBackups directory
michael@0 77 let backupFolder = yield PlacesBackups.getBackupFolder();
michael@0 78
michael@0 79 // Export bookmarks to JSON.
michael@0 80 // Allow infinite backups, none should be removed, a new one is not created
michael@0 81 // since one for today already exists.
michael@0 82 yield PlacesBackups.create(null);
michael@0 83 let backupFilename = PlacesBackups.getFilenameForDate();
michael@0 84
michael@0 85 let count = 0;
michael@0 86 let lastBackupPath = null;
michael@0 87 let iterator = new OS.File.DirectoryIterator(backupFolder);
michael@0 88 try {
michael@0 89 yield iterator.forEach(aEntry => {
michael@0 90 count++;
michael@0 91 if (PlacesBackups.filenamesRegex.test(aEntry.name))
michael@0 92 lastBackupPath = aEntry.path;
michael@0 93 });
michael@0 94 } finally {
michael@0 95 iterator.close();
michael@0 96 }
michael@0 97 do_check_eq(count, 2);
michael@0 98 do_check_neq(lastBackupPath, null);
michael@0 99 });
michael@0 100
michael@0 101 add_task(function check_max_backups_undefined() {
michael@0 102 // Get bookmarkBackups directory
michael@0 103 let backupFolder = yield PlacesBackups.getBackupFolder();
michael@0 104
michael@0 105 // Export bookmarks to JSON.
michael@0 106 // Allow infinite backups, none should be removed, a new one is not created
michael@0 107 // since one for today already exists.
michael@0 108 yield PlacesBackups.create();
michael@0 109 let backupFilename = PlacesBackups.getFilenameForDate();
michael@0 110
michael@0 111 let count = 0;
michael@0 112 let lastBackupPath = null;
michael@0 113 let iterator = new OS.File.DirectoryIterator(backupFolder);
michael@0 114 try {
michael@0 115 yield iterator.forEach(aEntry => {
michael@0 116 count++;
michael@0 117 if (PlacesBackups.filenamesRegex.test(aEntry.name))
michael@0 118 lastBackupPath = aEntry.path;
michael@0 119 });
michael@0 120 } finally {
michael@0 121 iterator.close();
michael@0 122 }
michael@0 123 do_check_eq(count, 2);
michael@0 124 do_check_neq(lastBackupPath, null);
michael@0 125 });
michael@0 126
michael@0 127 function run_test() {
michael@0 128 run_next_test();
michael@0 129 }

mercurial