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 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const Cr = Components.results;
8 const CC = Components.Constructor;
9 const Ci = Components.interfaces;
11 const MAX_TIME_DIFFERENCE = 2500;
12 const MILLIS_PER_DAY = 1000 * 60 * 60 * 24;
14 var LocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath");
16 function run_test()
17 {
18 test_toplevel_parent_is_null();
19 test_normalize_crash_if_media_missing();
20 test_file_modification_time();
21 test_directory_modification_time();
22 test_diskSpaceAvailable();
23 }
25 function test_toplevel_parent_is_null()
26 {
27 try
28 {
29 var lf = new LocalFile("C:\\");
31 // not required by API, but a property on which the implementation of
32 // parent == null relies for correctness
33 do_check_true(lf.path.length == 2);
35 do_check_true(lf.parent === null);
36 }
37 catch (e)
38 {
39 // not Windows
40 do_check_eq(e.result, Cr.NS_ERROR_FILE_UNRECOGNIZED_PATH);
41 }
42 }
44 function test_normalize_crash_if_media_missing()
45 {
46 const a="a".charCodeAt(0);
47 const z="z".charCodeAt(0);
48 for (var i = a; i <= z; ++i)
49 {
50 try
51 {
52 LocalFile(String.fromCharCode(i)+":.\\test").normalize();
53 }
54 catch (e)
55 {
56 }
57 }
58 }
60 // Tests that changing a file's modification time is possible
61 function test_file_modification_time()
62 {
63 var file = do_get_profile();
64 file.append("testfile");
66 // Should never happen but get rid of it anyway
67 if (file.exists())
68 file.remove(true);
70 var now = Date.now();
71 file.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0644);
72 do_check_true(file.exists());
74 // Modification time may be out by up to 2 seconds on FAT filesystems. Test
75 // with a bit of leeway, close enough probably means it is correct.
76 var diff = Math.abs(file.lastModifiedTime - now);
77 do_check_true(diff < MAX_TIME_DIFFERENCE);
79 var yesterday = now - MILLIS_PER_DAY;
80 file.lastModifiedTime = yesterday;
82 diff = Math.abs(file.lastModifiedTime - yesterday);
83 do_check_true(diff < MAX_TIME_DIFFERENCE);
85 var tomorrow = now - MILLIS_PER_DAY;
86 file.lastModifiedTime = tomorrow;
88 diff = Math.abs(file.lastModifiedTime - tomorrow);
89 do_check_true(diff < MAX_TIME_DIFFERENCE);
91 var bug377307 = 1172950238000;
92 file.lastModifiedTime = bug377307;
94 diff = Math.abs(file.lastModifiedTime - bug377307);
95 do_check_true(diff < MAX_TIME_DIFFERENCE);
97 file.remove(true);
98 }
100 // Tests that changing a directory's modification time is possible
101 function test_directory_modification_time()
102 {
103 var dir = do_get_profile();
104 dir.append("testdir");
106 // Should never happen but get rid of it anyway
107 if (dir.exists())
108 dir.remove(true);
110 var now = Date.now();
111 dir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
112 do_check_true(dir.exists());
114 // Modification time may be out by up to 2 seconds on FAT filesystems. Test
115 // with a bit of leeway, close enough probably means it is correct.
116 var diff = Math.abs(dir.lastModifiedTime - now);
117 do_check_true(diff < MAX_TIME_DIFFERENCE);
119 var yesterday = now - MILLIS_PER_DAY;
120 dir.lastModifiedTime = yesterday;
122 diff = Math.abs(dir.lastModifiedTime - yesterday);
123 do_check_true(diff < MAX_TIME_DIFFERENCE);
125 var tomorrow = now - MILLIS_PER_DAY;
126 dir.lastModifiedTime = tomorrow;
128 diff = Math.abs(dir.lastModifiedTime - tomorrow);
129 do_check_true(diff < MAX_TIME_DIFFERENCE);
131 dir.remove(true);
132 }
134 function test_diskSpaceAvailable()
135 {
136 let file = do_get_profile();
137 file.QueryInterface(Ci.nsILocalFile);
139 let bytes = file.diskSpaceAvailable;
140 do_check_true(bytes > 0);
142 file.append("testfile");
143 if (file.exists())
144 file.remove(true);
145 file.create(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("644", 8));
147 bytes = file.diskSpaceAvailable;
148 do_check_true(bytes > 0);
150 file.remove(true);
151 }