js/src/tests/js1_8_5/extensions/file-mapped-arraybuffers.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 // |reftest| skip-if(!xulRuntime.shell)
michael@0 2 // Any copyright is dedicated to the Public Domain.
michael@0 3 // http://creativecommons.org/licenses/publicdomain/
michael@0 4
michael@0 5 function viewToString(view)
michael@0 6 {
michael@0 7 return String.fromCharCode.apply(null, view);
michael@0 8 }
michael@0 9
michael@0 10 function assertThrows(f, wantException)
michael@0 11 {
michael@0 12 try {
michael@0 13 f();
michael@0 14 assertEq(true, false, "expected " + wantException + " exception");
michael@0 15 } catch (e) {
michael@0 16 assertEq(e.name, wantException.name, e.toString());
michael@0 17 }
michael@0 18 }
michael@0 19
michael@0 20 function test() {
michael@0 21 var filename = "file-mapped-arraybuffers.txt";
michael@0 22 var buffer = createMappedArrayBuffer(filename);
michael@0 23 var view = new Uint8Array(buffer);
michael@0 24 assertEq(viewToString(view), "01234567abcdefghijkl");
michael@0 25
michael@0 26 var buffer2 = createMappedArrayBuffer(filename, 8);
michael@0 27 view = new Uint8Array(buffer2);
michael@0 28 assertEq(viewToString(view), "abcdefghijkl");
michael@0 29
michael@0 30 var buffer3 = createMappedArrayBuffer(filename, 0, 8);
michael@0 31 view = new Uint8Array(buffer3);
michael@0 32 assertEq(viewToString(view), "01234567");
michael@0 33
michael@0 34 // Check that invalid sizes and offsets are caught
michael@0 35 assertThrows(() => createMappedArrayBuffer("empty.txt", 8), RangeError);
michael@0 36 assertThrows(() => createMappedArrayBuffer("empty.txt", 0, 8), Error);
michael@0 37 }
michael@0 38
michael@0 39 test();
michael@0 40 reportCompare(0, 0, 'ok');

mercurial