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.

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

mercurial