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

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

Powered by Google App Engine
This is Rietveld 408576698