toolkit/components/osfile/tests/xpcshell/test_open.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 Components.utils.import("resource://gre/modules/osfile.jsm");
michael@0 7
michael@0 8 function run_test() {
michael@0 9 run_next_test();
michael@0 10 }
michael@0 11
michael@0 12 /**
michael@0 13 * Test OS.File.open for reading:
michael@0 14 * - with an existing file (should succeed);
michael@0 15 * - with a non-existing file (should fail);
michael@0 16 * - with inconsistent arguments (should fail).
michael@0 17 */
michael@0 18 add_task(function() {
michael@0 19 // Attempt to open a file that does not exist, ensure that it yields the
michael@0 20 // appropriate error.
michael@0 21 try {
michael@0 22 let fd = yield OS.File.open(OS.Path.join(".", "This file does not exist"));
michael@0 23 do_check_true(false, "File opening 1 succeeded (it should fail)");
michael@0 24 } catch (err if err instanceof OS.File.Error && err.becauseNoSuchFile) {
michael@0 25 do_print("File opening 1 failed " + err);
michael@0 26 }
michael@0 27
michael@0 28 // Attempt to open a file with the wrong args, so that it fails before
michael@0 29 // serialization, ensure that it yields the appropriate error.
michael@0 30 do_print("Attempting to open a file with wrong arguments");
michael@0 31 try {
michael@0 32 let fd = yield OS.File.open(1, 2, 3);
michael@0 33 do_check_true(false, "File opening 2 succeeded (it should fail)" + fd);
michael@0 34 } catch (err) {
michael@0 35 do_print("File opening 2 failed " + err);
michael@0 36 do_check_false(err instanceof OS.File.Error,
michael@0 37 "File opening 2 returned something that is not a file error");
michael@0 38 do_check_true(err.constructor.name == "TypeError",
michael@0 39 "File opening 2 returned a TypeError");
michael@0 40 }
michael@0 41
michael@0 42 // Attempt to open a file correctly
michael@0 43 do_print("Attempting to open a file correctly");
michael@0 44 let openedFile = yield OS.File.open(OS.Path.join(do_get_cwd().path, "test_open.js"));
michael@0 45 do_print("File opened correctly");
michael@0 46
michael@0 47 do_print("Attempting to close a file correctly");
michael@0 48 yield openedFile.close();
michael@0 49
michael@0 50 do_print("Attempting to close a file again");
michael@0 51 yield openedFile.close();
michael@0 52 });
michael@0 53
michael@0 54 /**
michael@0 55 * Test the error thrown by OS.File.open when attempting to open a directory
michael@0 56 * that does not exist.
michael@0 57 */
michael@0 58 add_task(function test_error_attributes () {
michael@0 59
michael@0 60 let dir = OS.Path.join(do_get_profile().path, "test_osfileErrorAttrs");
michael@0 61 let fpath = OS.Path.join(dir, "test_error_attributes.txt");
michael@0 62
michael@0 63 try {
michael@0 64 yield OS.File.open(fpath, {truncate: true}, {});
michael@0 65 do_check_true(false, "Opening path suceeded (it should fail) " + fpath);
michael@0 66 } catch (err) {
michael@0 67 do_check_true(err instanceof OS.File.Error);
michael@0 68 do_check_true(err.becauseNoSuchFile);
michael@0 69 }
michael@0 70 });

mercurial