toolkit/components/osfile/tests/xpcshell/test_osfile_error.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 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 "use strict";
     6 let {OS: {File, Path, Constants}} = Components.utils.import("resource://gre/modules/osfile.jsm", {});
     7 Components.utils.import("resource://gre/modules/Task.jsm");
     9 function run_test() {
    10   run_next_test();
    11 }
    13 add_task(function* testFileError_with_writeAtomic() {
    14   let DEFAULT_CONTENTS = "default contents" + Math.random();
    15   let path = Path.join(Constants.Path.tmpDir,
    16                        "testFileError.tmp");
    17   yield File.remove(path);
    18   yield File.writeAtomic(path, DEFAULT_CONTENTS);
    19   let exception;
    20   try {
    21     yield File.writeAtomic(path, DEFAULT_CONTENTS, { noOverwrite: true });
    22   } catch (ex) {
    23     exception = ex;
    24   }
    25   do_check_true(exception instanceof File.Error);
    26   do_check_true(exception.path == path);
    27 });
    29 add_task(function* testFileError_with_makeDir() {
    30   let path = Path.join(Constants.Path.tmpDir,
    31                        "directory");
    32   yield File.removeDir(path);
    33   yield File.makeDir(path);
    34   let exception;
    35   try {
    36     yield File.makeDir(path, { ignoreExisting: false });
    37   } catch (ex) {
    38     exception = ex;
    39   }
    40   do_check_true(exception instanceof File.Error);
    41   do_check_true(exception.path == path);
    42 });
    44 add_task(function* testFileError_with_move() {
    45   let DEFAULT_CONTENTS = "default contents" + Math.random();
    46   let sourcePath = Path.join(Constants.Path.tmpDir,
    47                              "src.tmp");
    48   let destPath = Path.join(Constants.Path.tmpDir,
    49                            "dest.tmp");
    50   yield File.remove(sourcePath);
    51   yield File.remove(destPath);
    52   yield File.writeAtomic(sourcePath, DEFAULT_CONTENTS);
    53   yield File.writeAtomic(destPath, DEFAULT_CONTENTS);
    54   let exception;
    55   try {
    56     yield File.move(sourcePath, destPath, { noOverwrite: true });
    57   } catch (ex) {
    58     exception = ex;
    59   }
    60   do_print(exception);
    61   do_check_true(exception instanceof File.Error);
    62   do_check_true(exception.path == sourcePath);
    63 });

mercurial