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

Side by Side Diff: chrome/test/data/extensions/api_test/gcm/functions/send.js

Issue 129113002: Move GcmApi test cases into separate subdir in order to use RunExtensionTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 onload = function() {
6 function createMessage() {
7 return {
8 messageId: "message-id",
9 destinationId: "destination-id",
10 timeToLive: 2419200,
11 data: {
12 "key1": "value1",
13 "key2": "value"
14 }
15 };
16 }
17
18 function successfulSend(message) {
19 chrome.gcm.send(message, function(messageId) {
20 chrome.test.assertEq(message.messageId, messageId);
21 chrome.test.succeed();
22 });
23 }
24
25 function unsuccessfulSend(message) {
26 try {
27 chrome.gcm.send(message, function(messageId) {
28 chrome.test.fail(message);
29 });
30 } catch(e) {
31 chrome.test.succeed();
32 }
33 }
34
35 function scenario(messageMutations, send) {
36 var message = createMessage();
37 messageMutations.forEach(function(mutation) {
38 mutation(message);
39 });
40 send(message);
41 }
42
43 function expectSuccessWhen() {
44 scenario(Array.prototype.slice.call(arguments), successfulSend);
45 }
46
47 function expectFailureWhen() {
48 scenario(Array.prototype.slice.call(arguments), unsuccessfulSend);
49 }
50
51 chrome.test.runTests([
52 function successWhenHappyPath() {
53 expectSuccessWhen(/* no changes to message here */);
54 },
55 function successWhenTtlIsZero() {
56 expectSuccessWhen(function(message) { message.timeToLive = 0; });
57 },
58 function successWhenTtlIsMissing() {
59 expectSuccessWhen(function(message) { delete message.timeToLive; });
60 },
61 function failureWhenTtlIsNegative() {
62 expectFailureWhen(function(message) { message.timeToLive = -1; });
63 },
64 function failureWhenTtlIsTooLarge() {
65 expectFailureWhen(function(message) { message.timeToLive = 24192001; });
66 },
67 function failureWhenMessageIdMissing() {
68 expectFailureWhen(function(message) { delete message.messageId; });
69 },
70 function failureWhenMessageIdIsEmpty() {
71 expectFailureWhen(function(message) { message.messageId = ""; });
72 },
73 function failureWhenDestinationIdMissing() {
74 expectFailureWhen(function(message) { delete message.destinationId; });
75 },
76 function failureWhenDestinationIdIsEmpty() {
77 expectFailureWhen(function(message) { message.destinationId = ""; });
78 },
79 function failureWhenDataIsMissing() {
80 expectFailureWhen(function(message) { delete message.data; });
81 },
82 function failureWhenDataIsEmpty() {
83 expectFailureWhen(function(message) { message.data = {}; });
84 },
85 function failureWhenDataKeyIsEmpty() {
86 expectFailureWhen(function(message) { message.data[""] = "value"; });
87 },
88 function successWhenDataKeyHasGoogDotInIt() {
89 expectSuccessWhen(function(message) {
90 message.data["something.goog."] = "value";
91 });
92 },
93 function failureWhenDataKeyIsGoogDot() {
94 expectFailureWhen(function(message) { message.data["goog."] = "value"; });
95 },
96 function failureWhenDataKeyIsGoogDotPrefixed() {
97 expectFailureWhen(function(message) {
98 message.data["goog.something"] = "value";
99 });
100 },
101 function successWhenDataKeyHasGoogleInIt() {
102 expectSuccessWhen(function(message) {
103 message.data["somthing.google"] = "value";
104 });
105 },
106 function failureWhenDataKeyIsGoogle() {
107 expectFailureWhen(function(message) {
108 message.data["google"] = "value";
109 });
110 },
111 function failureWhenDataKeyIsGooglePrefixed() {
112 expectFailureWhen(function(message) {
113 message.data["googleSomething"] = "value";
114 });
115 },
116 function failureWhenMessageIsTooLarge() {
117 expectFailureWhen(function(message) {
118 function generateString(base, len) {
119 // Generates a string of size |len| by concatenating |base| multiple
120 // times and trimming to |len|.
121 while (base.length < len) base += base;
122 return base.substring(0, len);
123 }
124
125 var source = "abcdefghijklmnopqrstuvwxyz";
126 // Creates 8 * (256 + 256) == 4096 bytes of message data which together
127 // with data put in by default is more than allowed max.
128 var entries = 8;
129 while (entries > 0) {
130 var s = generateString(source + entries, 256);
131 message.data[s] = s;
132 --entries;
133 }
134 });
135 }
136 ]);
137 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698