|
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 } |
|
11 |
|
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 } |
|
24 |
|
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(); |
|
31 |
|
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 } |
|
38 |
|
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 } |
|
45 |
|
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 } |
|
52 |
|
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 } |
|
60 |
|
61 onmessage = function(event) { |
|
62 var file = event.data; |
|
63 |
|
64 // Test read only properties. |
|
65 writeProperty(file, "size"); |
|
66 writeProperty(file, "type"); |
|
67 writeProperty(file, "name"); |
|
68 writeProperty(file, "mozFullPath"); |
|
69 |
|
70 // Bad types. |
|
71 fileReaderJunkArgument(undefined); |
|
72 fileReaderJunkArgument(-1); |
|
73 fileReaderJunkArgument(1); |
|
74 fileReaderJunkArgument(new Object()); |
|
75 fileReaderJunkArgument("hello"); |
|
76 |
|
77 // Post undefined to indicate that testing has finished. |
|
78 postMessage(undefined); |
|
79 }; |