Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/push_messaging/resources/pushmessagedata-worker.js

Issue 1622553004: PartitionAlloc: Increase the number of pages per bucket (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 importScripts('../../serviceworker/resources/worker-testharness.js'); 1 importScripts('../../serviceworker/resources/worker-testharness.js');
2 importScripts('/resources/testharness-helpers.js'); 2 importScripts('/resources/testharness-helpers.js');
3 3
4 function createPushMessageData(data) 4 function createPushMessageData(data)
5 { 5 {
6 // The PushMessageData object does not expose a constructor, but we can get an object 6 // The PushMessageData object does not expose a constructor, but we can get an object
7 // initialized with our data by constructing a PushEvent. 7 // initialized with our data by constructing a PushEvent.
8 return new PushEvent('PushEvent', { data: data }).data; 8 return new PushEvent('PushEvent', { data: data }).data;
9 } 9 }
10 10
11 test(function() { 11 test(function() {
12 const textContents = 'Hello, world!'; 12 const textContents = 'Hello, world!';
13 13
14 var runTest = pushEvent => { 14 var runTest = pushEvent => {
15 assert_not_equals(pushEvent.data, null); 15 assert_not_equals(pushEvent.data, null);
16 assert_equals(pushEvent.data.text(), textContents); 16 assert_equals(pushEvent.data.text(), textContents);
17 }; 17 };
18 18
19 // JavaScript strings are UTF-16, whereas binary data for push message data will be 19 // JavaScript strings are UTF-16, whereas binary data for push message data will be
20 // encoded as UTF-8. Convert accordingly. 20 // encoded as UTF-8. Convert accordingly.
21 var bufferView = new TextEncoder('utf-8').encode(textContents); 21 var bufferView = new TextEncoder('utf-8').encode(textContents);
22 22
23 runTest(new PushEvent('PushEvent', { data: bufferView })); 23 runTest(new PushEvent('PushEvent', { data: bufferView }));
24 runTest(new PushEvent('PushEvent', { data: bufferView.buffer })); 24 runTest(new PushEvent('PushEvent', { data: bufferView.buffer }));
25 runTest(new PushEvent('PushEvent', { data: textContents })); 25 runTest(new PushEvent('PushEvent', { data: textContents }));
26 26
27 }, 'PushEvent can be initialized from ArrayBuffer, ArrayBufferView and USVString s.'); 27 }, 'PushEvent can be initialized from ArrayBuffer, ArrayBufferView and USVString s.');
28 28
29 test(function() { 29 test(function() {
30 var pushMessageData = createPushMessageData(); 30 assert_equals(createPushMessageData(undefined), null);
31 31
32 assert_equals(pushMessageData.arrayBuffer().byteLength, 0); 32 }, 'PushMessageData is null by default.');
33
34 assert_equals(pushMessageData.blob().size, 0);
35 assert_equals(pushMessageData.blob().type, '');
36
37 // PushMessageData.json() is specified to be identical to JSON.parse() with
38 // the message's data as the argument. JSON.parse('') throws an exception,
39 // so verify that calling json() without a body throws the same exception.
40 try {
41 pushMessageData.json();
42 assert_unreached('Expected an exception to be thrown.');
43 } catch (eventDataException) {
44 try {
45 JSON.parse('');
46 assert_unreached('Expected an exception to be thrown.');
47 } catch (jsonParseException) {
48 assert_equals(eventDataException.name, jsonParseException.name);
49 assert_equals(eventDataException.message, jsonParseException.message );
50 }
51 }
52
53 assert_equals(pushMessageData.text().length, 0);
54
55 }, 'PushMessageData is empty by default.');
56 33
57 test(function() { 34 test(function() {
58 const binaryContents = [1, 2, 3]; 35 const binaryContents = [1, 2, 3];
59 const textContents = 'FOOBAR'; 36 const textContents = 'FOOBAR';
60 37
61 var pushMessageDataBinary = createPushMessageData(new Uint8Array(binaryConte nts)), 38 var pushMessageDataBinary = createPushMessageData(new Uint8Array(binaryConte nts)),
62 pushMessageDataString = createPushMessageData(textContents); 39 pushMessageDataString = createPushMessageData(textContents);
63 40
64 var binaryBuffer = pushMessageDataBinary.arrayBuffer(), 41 var binaryBuffer = pushMessageDataBinary.arrayBuffer(),
65 binaryBufferView = new Uint8Array(binaryBuffer); 42 binaryBufferView = new Uint8Array(binaryBuffer);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 assert_throws(null, () => new PushMessageData(new ArrayBuffer(8))); 102 assert_throws(null, () => new PushMessageData(new ArrayBuffer(8)));
126 103
127 }, 'PushMessageData should not be constructable.'); 104 }, 'PushMessageData should not be constructable.');
128 105
129 test(function() { 106 test(function() {
130 var s = "e\u0328"; // 'e' + COMBINING OGONEK 107 var s = "e\u0328"; // 'e' + COMBINING OGONEK
131 var data = createPushMessageData(s); 108 var data = createPushMessageData(s);
132 assert_equals(data.text(), s, 'String should not be NFC-normalized.'); 109 assert_equals(data.text(), s, 'String should not be NFC-normalized.');
133 110
134 }, 'PushEventInit data is not normalized'); 111 }, 'PushEventInit data is not normalized');
OLDNEW
« no previous file with comments | « chrome/test/data/push_messaging/service_worker.js ('k') | third_party/WebKit/Source/modules/push_messaging/PushEvent.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698