michael@0: /** michael@0: * Delegates "is" evaluation back to main thread. michael@0: */ michael@0: function is(actual, expected, message) { michael@0: var rtnObj = new Object(); michael@0: rtnObj.actual = actual; michael@0: rtnObj.expected = expected; michael@0: rtnObj.message = message; michael@0: postMessage(rtnObj); michael@0: } michael@0: michael@0: /** michael@0: * Tries to write to property. michael@0: */ michael@0: function writeProperty(file, property) { michael@0: try { michael@0: var oldValue = file[property]; michael@0: file[property] = -1; michael@0: is(false, true, "Should have thrown an exception setting a read only property."); michael@0: } catch (ex) { michael@0: is(true, true, "Should have thrown an exception setting a read only property."); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Passes junk arguments to FileReaderSync methods and expects an exception to michael@0: * be thrown. michael@0: */ michael@0: function fileReaderJunkArgument(blob) { michael@0: var fileReader = new FileReaderSync(); michael@0: michael@0: try { michael@0: fileReader.readAsBinaryString(blob); michael@0: is(false, true, "Should have thrown an exception calling readAsBinaryString."); michael@0: } catch(ex) { michael@0: is(true, true, "Should have thrown an exception."); michael@0: } michael@0: michael@0: try { michael@0: fileReader.readAsDataURL(blob); michael@0: is(false, true, "Should have thrown an exception calling readAsDataURL."); michael@0: } catch(ex) { michael@0: is(true, true, "Should have thrown an exception."); michael@0: } michael@0: michael@0: try { michael@0: fileReader.readAsArrayBuffer(blob); michael@0: is(false, true, "Should have thrown an exception calling readAsArrayBuffer."); michael@0: } catch(ex) { michael@0: is(true, true, "Should have thrown an exception."); michael@0: } michael@0: michael@0: try { michael@0: fileReader.readAsText(blob); michael@0: is(false, true, "Should have thrown an exception calling readAsText."); michael@0: } catch(ex) { michael@0: is(true, true, "Should have thrown an exception."); michael@0: } michael@0: } michael@0: michael@0: onmessage = function(event) { michael@0: var file = event.data; michael@0: michael@0: // Test read only properties. michael@0: writeProperty(file, "size"); michael@0: writeProperty(file, "type"); michael@0: writeProperty(file, "name"); michael@0: writeProperty(file, "mozFullPath"); michael@0: michael@0: // Bad types. michael@0: fileReaderJunkArgument(undefined); michael@0: fileReaderJunkArgument(-1); michael@0: fileReaderJunkArgument(1); michael@0: fileReaderJunkArgument(new Object()); michael@0: fileReaderJunkArgument("hello"); michael@0: michael@0: // Post undefined to indicate that testing has finished. michael@0: postMessage(undefined); michael@0: };