dom/workers/test/fileReaderSyncErrors_worker.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/workers/test/fileReaderSyncErrors_worker.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +/**
     1.5 + * Delegates "is" evaluation back to main thread.
     1.6 + */
     1.7 +function is(actual, expected, message) {
     1.8 +  var rtnObj = new Object();
     1.9 +  rtnObj.actual = actual;
    1.10 +  rtnObj.expected = expected;
    1.11 +  rtnObj.message = message;
    1.12 +  postMessage(rtnObj);
    1.13 +}
    1.14 +
    1.15 +/**
    1.16 + * Tries to write to property.
    1.17 + */
    1.18 +function writeProperty(file, property) {
    1.19 +  try {
    1.20 +    var oldValue = file[property];
    1.21 +    file[property] = -1;
    1.22 +    is(false, true, "Should have thrown an exception setting a read only property.");
    1.23 +  } catch (ex) {
    1.24 +    is(true, true, "Should have thrown an exception setting a read only property.");
    1.25 +  }
    1.26 +}
    1.27 +
    1.28 +/**
    1.29 + * Passes junk arguments to FileReaderSync methods and expects an exception to
    1.30 + * be thrown.
    1.31 + */
    1.32 +function fileReaderJunkArgument(blob) {
    1.33 +  var fileReader = new FileReaderSync();
    1.34 +
    1.35 +  try {
    1.36 +    fileReader.readAsBinaryString(blob);
    1.37 +    is(false, true, "Should have thrown an exception calling readAsBinaryString.");
    1.38 +  } catch(ex) {
    1.39 +    is(true, true, "Should have thrown an exception.");
    1.40 +  }
    1.41 +
    1.42 +  try {
    1.43 +    fileReader.readAsDataURL(blob);
    1.44 +    is(false, true, "Should have thrown an exception calling readAsDataURL.");
    1.45 +  } catch(ex) {
    1.46 +    is(true, true, "Should have thrown an exception.");
    1.47 +  }
    1.48 +
    1.49 +  try {
    1.50 +    fileReader.readAsArrayBuffer(blob);
    1.51 +    is(false, true, "Should have thrown an exception calling readAsArrayBuffer.");
    1.52 +  } catch(ex) {
    1.53 +    is(true, true, "Should have thrown an exception.");
    1.54 +  }
    1.55 +
    1.56 +  try {
    1.57 +    fileReader.readAsText(blob);
    1.58 +    is(false, true, "Should have thrown an exception calling readAsText.");
    1.59 +  } catch(ex) {
    1.60 +    is(true, true, "Should have thrown an exception.");
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +onmessage = function(event) {
    1.65 +  var file = event.data;
    1.66 +
    1.67 +  // Test read only properties.
    1.68 +  writeProperty(file, "size");
    1.69 +  writeProperty(file, "type");
    1.70 +  writeProperty(file, "name");
    1.71 +  writeProperty(file, "mozFullPath");
    1.72 +
    1.73 +  // Bad types.
    1.74 +  fileReaderJunkArgument(undefined);
    1.75 +  fileReaderJunkArgument(-1);
    1.76 +  fileReaderJunkArgument(1);
    1.77 +  fileReaderJunkArgument(new Object());
    1.78 +  fileReaderJunkArgument("hello");
    1.79 +
    1.80 +    // Post undefined to indicate that testing has finished.
    1.81 +  postMessage(undefined);
    1.82 +};

mercurial