dom/workers/test/fileReaderSyncErrors_worker.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.

     1 /**
     2  * Delegates "is" evaluation back to main thread.
     3  */
     4 function is(actual, expected, message) {
     5   var rtnObj = new Object();
     6   rtnObj.actual = actual;
     7   rtnObj.expected = expected;
     8   rtnObj.message = message;
     9   postMessage(rtnObj);
    10 }
    12 /**
    13  * Tries to write to property.
    14  */
    15 function writeProperty(file, property) {
    16   try {
    17     var oldValue = file[property];
    18     file[property] = -1;
    19     is(false, true, "Should have thrown an exception setting a read only property.");
    20   } catch (ex) {
    21     is(true, true, "Should have thrown an exception setting a read only property.");
    22   }
    23 }
    25 /**
    26  * Passes junk arguments to FileReaderSync methods and expects an exception to
    27  * be thrown.
    28  */
    29 function fileReaderJunkArgument(blob) {
    30   var fileReader = new FileReaderSync();
    32   try {
    33     fileReader.readAsBinaryString(blob);
    34     is(false, true, "Should have thrown an exception calling readAsBinaryString.");
    35   } catch(ex) {
    36     is(true, true, "Should have thrown an exception.");
    37   }
    39   try {
    40     fileReader.readAsDataURL(blob);
    41     is(false, true, "Should have thrown an exception calling readAsDataURL.");
    42   } catch(ex) {
    43     is(true, true, "Should have thrown an exception.");
    44   }
    46   try {
    47     fileReader.readAsArrayBuffer(blob);
    48     is(false, true, "Should have thrown an exception calling readAsArrayBuffer.");
    49   } catch(ex) {
    50     is(true, true, "Should have thrown an exception.");
    51   }
    53   try {
    54     fileReader.readAsText(blob);
    55     is(false, true, "Should have thrown an exception calling readAsText.");
    56   } catch(ex) {
    57     is(true, true, "Should have thrown an exception.");
    58   }
    59 }
    61 onmessage = function(event) {
    62   var file = event.data;
    64   // Test read only properties.
    65   writeProperty(file, "size");
    66   writeProperty(file, "type");
    67   writeProperty(file, "name");
    68   writeProperty(file, "mozFullPath");
    70   // Bad types.
    71   fileReaderJunkArgument(undefined);
    72   fileReaderJunkArgument(-1);
    73   fileReaderJunkArgument(1);
    74   fileReaderJunkArgument(new Object());
    75   fileReaderJunkArgument("hello");
    77     // Post undefined to indicate that testing has finished.
    78   postMessage(undefined);
    79 };

mercurial