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