xpcom/tests/unit/test_file_renameTo.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.

     1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 const Cc = Components.classes;
     7 const Ci = Components.interfaces;
     9 function run_test()
    10 {
    11   // Create the base directory.
    12   let base = Cc['@mozilla.org/file/directory_service;1']
    13              .getService(Ci.nsIProperties)
    14              .get('TmpD', Ci.nsILocalFile);
    15   base.append('renameTesting');
    16   if (base.exists()) {
    17     base.remove(true);
    18   }
    19   base.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt('0777', 8));
    21   // Create a sub directory under the base.
    22   let subdir = base.clone();
    23   subdir.append('subdir');
    24   subdir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt('0777', 8));
    26   // Create a file under the sub directory.
    27   let tempFile = subdir.clone();
    28   tempFile.append('file0.txt');
    29   tempFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt('0777', 8));
    31   // Test renameTo in the base directory
    32   tempFile.renameTo(null, 'file1.txt');
    33   do_check_true(exists(subdir, 'file1.txt'));
    35   // Test moving across directories
    36   tempFile = subdir.clone();
    37   tempFile.append('file1.txt');
    38   tempFile.renameTo(base, '');
    39   do_check_true(exists(base, 'file1.txt'));
    41   // Test moving across directories and renaming at the same time
    42   tempFile = base.clone();
    43   tempFile.append('file1.txt');
    44   tempFile.renameTo(subdir, 'file2.txt');
    45   do_check_true(exists(subdir, 'file2.txt'));
    47   // Test moving a directory
    48   subdir.renameTo(base, 'renamed');
    49   do_check_true(exists(base, 'renamed'));
    50   let renamed = base.clone();
    51   renamed.append('renamed');
    52   do_check_true(exists(renamed, 'file2.txt'));
    54   base.remove(true);
    55 }
    57 function exists(parent, filename) {
    58   let file = parent.clone();
    59   file.append(filename);
    60   return file.exists();
    61 }

mercurial