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