OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 } | 133 } |
134 | 134 |
135 private: | 135 private: |
136 scoped_ptr<net::SpawnedTestServer> https_server_; | 136 scoped_ptr<net::SpawnedTestServer> https_server_; |
137 FakeGCMProfileService* gcm_service_; | 137 FakeGCMProfileService* gcm_service_; |
138 | 138 |
139 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); | 139 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); |
140 }; | 140 }; |
141 | 141 |
142 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterSuccess) { | 142 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterSuccess) { |
143 std::string script_result; | 143 std::string script_result; |
Michael van Ouwerkerk
2014/11/13 18:35:51
Nit: newline after this.
Miguel Garcia
2014/11/14 11:34:35
Done.
| |
144 | 144 InfoBarResponder accepting_responder(browser(), true); |
johnme
2014/11/13 18:50:06
Nit: it's probably more idiomatic to call register
Miguel Garcia
2014/11/14 11:34:35
Done.
| |
145 ASSERT_TRUE(RunScript("requestPermission();", &script_result)); | |
Michael van Ouwerkerk
2014/11/13 18:35:51
Nit: you can omit the semicolon after requestPermi
Miguel Garcia
2014/11/14 11:34:35
Done.
| |
146 ASSERT_EQ("permission status - granted", script_result); | |
Michael van Ouwerkerk
2014/11/13 18:35:51
Nit: insert newline after this.
Miguel Garcia
2014/11/14 11:34:35
Done.
| |
145 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 147 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
146 ASSERT_EQ("ok - service worker registered", script_result); | 148 ASSERT_EQ("ok - service worker registered", script_result); |
147 | 149 |
148 InfoBarResponder accepting_responder(browser(), true); | |
149 | |
150 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | 150 ASSERT_TRUE(RunScript("registerPush()", &script_result)); |
151 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result); | 151 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result); |
152 | 152 |
153 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L); | 153 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L); |
154 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); | 154 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); |
155 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 155 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
156 } | 156 } |
157 | 157 |
158 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterFailureNoPermission) { | 158 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
159 RegisterFailureNoPushPermission) { | |
159 std::string script_result; | 160 std::string script_result; |
Michael van Ouwerkerk
2014/11/13 18:35:51
Nit: newline after this.
Miguel Garcia
2014/11/14 11:34:35
Done.
| |
161 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | |
162 ASSERT_EQ("ok - service worker registered", script_result); | |
163 | |
164 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | |
165 EXPECT_EQ("AbortError - Registration failed - permission denied", | |
166 script_result); | |
167 } | |
168 | |
169 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | |
170 RegisterFailureNotificationsBlocked) { | |
171 std::string script_result; | |
Michael van Ouwerkerk
2014/11/13 18:35:51
Nit: newline after this.
Miguel Garcia
2014/11/14 11:34:36
Done.
| |
172 InfoBarResponder cancelling_responder(browser(), false); | |
173 | |
174 ASSERT_TRUE(RunScript("requestPermission();", &script_result)); | |
175 ASSERT_EQ("permission status - denied", script_result); | |
160 | 176 |
161 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 177 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
162 ASSERT_EQ("ok - service worker registered", script_result); | 178 ASSERT_EQ("ok - service worker registered", script_result); |
163 | 179 |
164 InfoBarResponder cancelling_responder(browser(), false); | |
165 | |
166 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | 180 ASSERT_TRUE(RunScript("registerPush()", &script_result)); |
167 EXPECT_EQ("AbortError - Registration failed - permission denied", | 181 EXPECT_EQ("AbortError - Registration failed - permission denied", |
168 script_result); | 182 script_result); |
169 } | 183 } |
170 | 184 |
171 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterFailureNoSenderId) { | 185 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterFailureNoSenderId) { |
172 std::string script_result; | 186 std::string script_result; |
173 | 187 |
188 InfoBarResponder accepting_responder(browser(), true); | |
189 ASSERT_TRUE(RunScript("requestPermission();", &script_result)); | |
190 ASSERT_EQ("permission status - granted", script_result); | |
191 | |
174 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 192 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
175 ASSERT_EQ("ok - service worker registered", script_result); | 193 ASSERT_EQ("ok - service worker registered", script_result); |
176 | 194 |
177 InfoBarResponder accepting_responder(browser(), true); | |
178 | |
179 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); | 195 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); |
180 ASSERT_EQ("manifest removed", script_result); | 196 ASSERT_EQ("manifest removed", script_result); |
181 | 197 |
182 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | 198 ASSERT_TRUE(RunScript("registerPush()", &script_result)); |
183 EXPECT_EQ("AbortError - Registration failed - no sender id provided", | 199 EXPECT_EQ("AbortError - Registration failed - no sender id provided", |
184 script_result); | 200 script_result); |
185 } | 201 } |
186 | 202 |
187 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { | 203 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { |
188 std::string script_result; | 204 std::string script_result; |
Michael van Ouwerkerk
2014/11/13 18:35:51
Nit: insert newline after this.
Miguel Garcia
2014/11/14 11:34:35
Done.
| |
205 InfoBarResponder accepting_responder(browser(), true); | |
206 ASSERT_TRUE(RunScript("requestPermission();", &script_result)); | |
Michael van Ouwerkerk
2014/11/13 18:35:51
Insert after this:
ASSERT_EQ("permission status -
Miguel Garcia
2014/11/14 11:34:35
Done.
| |
189 | 207 |
190 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); | 208 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); |
191 ASSERT_EQ("ok - service worker registered", script_result); | 209 ASSERT_EQ("ok - service worker registered", script_result); |
192 | 210 |
193 InfoBarResponder accepting_responder(browser(), true); | |
194 | |
195 ASSERT_TRUE(RunScript("registerPush()", &script_result)); | 211 ASSERT_TRUE(RunScript("registerPush()", &script_result)); |
196 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result); | 212 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1", script_result); |
197 | 213 |
198 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L); | 214 PushMessagingApplicationId app_id(https_server()->GetURL(""), 0L); |
199 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); | 215 EXPECT_EQ(app_id.ToString(), gcm_service()->last_registered_app_id()); |
200 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); | 216 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); |
201 | 217 |
202 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 218 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
203 ASSERT_EQ("false - is not controlled", script_result); | 219 ASSERT_EQ("false - is not controlled", script_result); |
204 | 220 |
205 loadTestPage(); // Reload to become controlled. | 221 loadTestPage(); // Reload to become controlled. |
206 | 222 |
207 ASSERT_TRUE(RunScript("isControlled()", &script_result)); | 223 ASSERT_TRUE(RunScript("isControlled()", &script_result)); |
208 ASSERT_EQ("true - is controlled", script_result); | 224 ASSERT_EQ("true - is controlled", script_result); |
209 | 225 |
210 GCMClient::IncomingMessage message; | 226 GCMClient::IncomingMessage message; |
211 GCMClient::MessageData messageData; | 227 GCMClient::MessageData messageData; |
212 messageData.insert(std::pair<std::string, std::string>("data", "testdata")); | 228 messageData.insert(std::pair<std::string, std::string>("data", "testdata")); |
213 message.data = messageData; | 229 message.data = messageData; |
214 push_service()->OnMessage(app_id.ToString(), message); | 230 push_service()->OnMessage(app_id.ToString(), message); |
215 ASSERT_TRUE(RunScript("pushData.get()", &script_result)); | 231 ASSERT_TRUE(RunScript("pushData.get()", &script_result)); |
216 EXPECT_EQ("testdata", script_result); | 232 EXPECT_EQ("testdata", script_result); |
217 } | 233 } |
218 | 234 |
219 } // namespace gcm | 235 } // namespace gcm |
OLD | NEW |