| OLD | NEW |
| (Empty) |
| 1 importScripts('../../serviceworker/resources/worker-testharness.js'); | |
| 2 importScripts('/resources/testharness-helpers.js'); | |
| 3 | |
| 4 test(function() { | |
| 5 var data = new PushMessageData('Hello, world!'); | |
| 6 assert_equals(data.text(), 'Hello, world!'); | |
| 7 | |
| 8 }, 'PushMessageData can be constructed with a string parameter.'); | |
| 9 | |
| 10 test(function() { | |
| 11 var event = new PushEvent('PushEvent'); | |
| 12 | |
| 13 assert_equals(event.data.arrayBuffer().byteLength, 0); | |
| 14 | |
| 15 assert_equals(event.data.blob().size, 0); | |
| 16 assert_equals(event.data.blob().type, ''); | |
| 17 | |
| 18 // PushMessageData.json() is specified to be identical to JSON.parse() with | |
| 19 // the message's data as the argument. JSON.parse('') throws an exception, | |
| 20 // so verify that calling json() without a body throws the same exception. | |
| 21 try { | |
| 22 event.data.json(); | |
| 23 } catch (eventDataException) { | |
| 24 try { | |
| 25 JSON.parse(''); | |
| 26 } catch (jsonParseException) { | |
| 27 assert_equals(eventDataException.name, jsonParseException.name); | |
| 28 assert_equals(eventDataException.message, jsonParseException.message); | |
| 29 } | |
| 30 } | |
| 31 | |
| 32 assert_equals(event.data.text().length, 0); | |
| 33 | |
| 34 }, 'PushMessageData is empty by default, given a PushEvent constructor.'); | |
| 35 | |
| 36 test(function() { | |
| 37 var event = new PushEvent('PushEvent', { | |
| 38 data: new PushMessageData('FOOBAR') | |
| 39 }); | |
| 40 | |
| 41 var arrayBuffer = event.data.arrayBuffer(); | |
| 42 assert_equals(arrayBuffer.byteLength, 6); | |
| 43 | |
| 44 var int8Array = new Int8Array(arrayBuffer); | |
| 45 assert_equals(int8Array[0], 70); // F | |
| 46 assert_equals(int8Array[3], 66); // B | |
| 47 | |
| 48 }, 'Reading an ArrayBuffer from PushMessageData through the PushEvent constructo
r.'); | |
| 49 | |
| 50 async_test(function(test) { | |
| 51 var event = new PushEvent('PushEvent', { | |
| 52 data: new PushMessageData('FOOBAR') | |
| 53 }); | |
| 54 | |
| 55 var blob = event.data.blob(); | |
| 56 assert_equals(blob.size, 6); | |
| 57 assert_equals(blob.type, ''); | |
| 58 | |
| 59 var reader = new FileReader(); | |
| 60 reader.addEventListener('load', function() { | |
| 61 assert_equals(reader.result, 'FOOBAR'); | |
| 62 test.done(); | |
| 63 }); | |
| 64 | |
| 65 reader.readAsText(blob); | |
| 66 | |
| 67 }, 'Reading a Blob from PushMessageData through the PushEvent constructor.') | |
| 68 | |
| 69 test(function() { | |
| 70 var event = new PushEvent('PushEvent', { | |
| 71 data: new PushMessageData('[5, 6, 7]') | |
| 72 }); | |
| 73 | |
| 74 var array = event.data.json(); | |
| 75 assert_equals(array.length, 3); | |
| 76 assert_equals(array[1], 6); | |
| 77 | |
| 78 event = new PushEvent('PushEvent', { | |
| 79 data: new PushMessageData('{ "foo": { "bar": 42 } }') | |
| 80 }); | |
| 81 | |
| 82 assert_equals(event.data.json().foo.bar, 42); | |
| 83 | |
| 84 }, 'Reading JSON from PushMessageData through the PushEvent constructor.'); | |
| 85 | |
| 86 test(function() { | |
| 87 var event = new PushEvent('PushEvent', { | |
| 88 data: new PushMessageData('Hello, world!') | |
| 89 }); | |
| 90 | |
| 91 assert_equals(event.data.text(), 'Hello, world!'); | |
| 92 | |
| 93 }, 'Reading text from PushMessageData through the PushEvent constructor.'); | |
| OLD | NEW |