Sat, 03 Jan 2015 20:18:00 +0100
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 "use strict";
3 do_print("starting tests");
5 Components.utils.import("resource://gre/modules/osfile.jsm");
6 Components.utils.import("resource://gre/modules/Task.jsm");
8 /**
9 * A test to check that the |append| mode flag is correctly implemented.
10 * (see bug 925865)
11 */
13 function setup_mode(mode) {
14 // Complete mode.
15 let realMode = {
16 read: true,
17 write: true
18 };
19 for (let k in mode) {
20 realMode[k] = mode[k];
21 }
22 return realMode;
23 }
25 // Test append mode.
26 function test_append(mode) {
27 let path = OS.Path.join(OS.Constants.Path.tmpDir,
28 "test_osfile_async_append.tmp");
30 // Clear any left-over files from previous runs.
31 try {
32 yield OS.File.remove(path);
33 } catch (ex if ex.becauseNoSuchFile) {
34 // ignore
35 }
37 try {
38 mode = setup_mode(mode);
39 mode.append = true;
40 if (mode.trunc) {
41 // Pre-fill file with some data to see if |trunc| actually works.
42 yield OS.File.writeAtomic(path, new Uint8Array(500));
43 }
44 let file = yield OS.File.open(path, mode);
45 try {
46 yield file.write(new Uint8Array(1000));
47 yield file.setPosition(0, OS.File.POS_START);
48 yield file.read(100);
49 // Should be at offset 100, length 1000 now.
50 yield file.write(new Uint8Array(100));
51 // Should be at offset 1100, length 1100 now.
52 let stat = yield file.stat();
53 do_check_eq(1100, stat.size);
54 } finally {
55 yield file.close();
56 }
57 } catch(ex) {
58 try {
59 yield OS.File.remove(path);
60 } catch (ex if ex.becauseNoSuchFile) {
61 // ignore.
62 }
63 }
64 }
66 // Test no-append mode.
67 function test_no_append(mode) {
68 let path = OS.Path.join(OS.Constants.Path.tmpDir,
69 "test_osfile_async_noappend.tmp");
71 // Clear any left-over files from previous runs.
72 try {
73 yield OS.File.remove(path);
74 } catch (ex if ex.becauseNoSuchFile) {
75 // ignore
76 }
78 try {
79 mode = setup_mode(mode);
80 mode.append = false;
81 if (mode.trunc) {
82 // Pre-fill file with some data to see if |trunc| actually works.
83 yield OS.File.writeAtomic(path, new Uint8Array(500));
84 }
85 let file = yield OS.File.open(path, mode);
86 try {
87 yield file.write(new Uint8Array(1000));
88 yield file.setPosition(0, OS.File.POS_START);
89 yield file.read(100);
90 // Should be at offset 100, length 1000 now.
91 yield file.write(new Uint8Array(100));
92 // Should be at offset 200, length 1000 now.
93 let stat = yield file.stat();
94 do_check_eq(1000, stat.size);
95 } finally {
96 yield file.close();
97 }
98 } finally {
99 try {
100 yield OS.File.remove(path);
101 } catch (ex if ex.becauseNoSuchFile) {
102 // ignore.
103 }
104 }
105 }
107 let test_flags = [
108 {},
109 {create:true},
110 {trunc:true}
111 ];
112 function run_test() {
113 do_test_pending();
115 for (let t of test_flags) {
116 add_task(test_append.bind(null, t));
117 add_task(test_no_append.bind(null, t));
118 }
119 add_task(do_test_finished);
121 run_next_test();
122 }