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

Side by Side Diff: chrome/browser/services/gcm/push_messaging_browsertest.cc

Issue 914373003: Exceptions for Web Notifications and the Push API by default. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the AndroidWebViewTest assert Created 5 years, 10 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
« no previous file with comments | « base/android/build_info.h ('k') | chrome/browser/services/gcm/push_messaging_service_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 #include "components/content_settings/core/common/content_settings_types.h" 25 #include "components/content_settings/core/common/content_settings_types.h"
26 #include "components/gcm_driver/gcm_client.h" 26 #include "components/gcm_driver/gcm_client.h"
27 #include "components/infobars/core/confirm_infobar_delegate.h" 27 #include "components/infobars/core/confirm_infobar_delegate.h"
28 #include "components/infobars/core/infobar.h" 28 #include "components/infobars/core/infobar.h"
29 #include "components/infobars/core/infobar_manager.h" 29 #include "components/infobars/core/infobar_manager.h"
30 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
31 #include "content/public/common/content_switches.h" 31 #include "content/public/common/content_switches.h"
32 #include "content/public/test/browser_test_utils.h" 32 #include "content/public/test/browser_test_utils.h"
33 #include "ui/base/window_open_disposition.h" 33 #include "ui/base/window_open_disposition.h"
34 34
35 #if defined(OS_ANDROID)
36 #include "base/android/build_info.h"
37 #endif
38
35 namespace gcm { 39 namespace gcm {
36 40
37 namespace { 41 namespace {
38 // Responds to a confirm infobar by accepting or cancelling it. Responds to at 42 // Responds to a confirm infobar by accepting or cancelling it. Responds to at
39 // most one infobar. 43 // most one infobar.
40 class InfoBarResponder : public infobars::InfoBarManager::Observer { 44 class InfoBarResponder : public infobars::InfoBarManager::Observer {
41 public: 45 public:
42 InfoBarResponder(Browser* browser, bool accept) 46 InfoBarResponder(Browser* browser, bool accept)
43 : infobar_service_(InfoBarService::FromWebContents( 47 : infobar_service_(InfoBarService::FromWebContents(
44 browser->tab_strip_model()->GetActiveWebContents())), 48 browser->tab_strip_model()->GetActiveWebContents())),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 waiting_ = true; 130 waiting_ = true;
127 while (!done_) 131 while (!done_)
128 content::RunMessageLoop(); 132 content::RunMessageLoop();
129 } 133 }
130 134
131 private: 135 private:
132 bool done_; 136 bool done_;
133 bool waiting_; 137 bool waiting_;
134 }; 138 };
135 139
140 // The Push API depends on Web Notifications, which is only available on Android
141 // Jelly Bean and later.
142 bool IsPushSupported() {
143 #if defined(OS_ANDROID)
144 if (base::android::BuildInfo::GetInstance()->sdk_int() <
145 base::android::SDK_VERSION_JELLY_BEAN) {
146 DVLOG(0) << "The Push API is only supported in Android 4.1 and later.";
147 return false;
148 }
149 #endif
150 return true;
151 }
152
136 } // namespace 153 } // namespace
137 154
138 class PushMessagingBrowserTest : public InProcessBrowserTest { 155 class PushMessagingBrowserTest : public InProcessBrowserTest {
139 public: 156 public:
140 PushMessagingBrowserTest() : gcm_service_(nullptr) {} 157 PushMessagingBrowserTest() : gcm_service_(nullptr) {}
141 ~PushMessagingBrowserTest() override {} 158 ~PushMessagingBrowserTest() override {}
142 159
143 // InProcessBrowserTest: 160 // InProcessBrowserTest:
144 void SetUpCommandLine(base::CommandLine* command_line) override { 161 void SetUpCommandLine(base::CommandLine* command_line) override {
145 command_line->AppendSwitch( 162 command_line->AppendSwitch(
146 switches::kEnableExperimentalWebPlatformFeatures); 163 switches::kEnableExperimentalWebPlatformFeatures);
147 command_line->AppendSwitch( 164 command_line->AppendSwitch(switches::kEnablePushMessagePayload);
148 switches::kEnablePushMessagePayload);
149
150 InProcessBrowserTest::SetUpCommandLine(command_line); 165 InProcessBrowserTest::SetUpCommandLine(command_line);
151 } 166 }
152 167
153 // InProcessBrowserTest: 168 // InProcessBrowserTest:
154 void SetUp() override { 169 void SetUp() override {
155 https_server_.reset(new net::SpawnedTestServer( 170 https_server_.reset(new net::SpawnedTestServer(
156 net::SpawnedTestServer::TYPE_HTTPS, 171 net::SpawnedTestServer::TYPE_HTTPS,
157 net::BaseTestServer::SSLOptions( 172 net::BaseTestServer::SSLOptions(
158 net::BaseTestServer::SSLOptions::CERT_OK), 173 net::BaseTestServer::SSLOptions::CERT_OK),
159 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/")))); 174 base::FilePath(FILE_PATH_LITERAL("chrome/test/data/"))));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 }; 264 };
250 265
251 class PushMessagingBadManifestBrowserTest : public PushMessagingBrowserTest { 266 class PushMessagingBadManifestBrowserTest : public PushMessagingBrowserTest {
252 std::string GetTestURL() override { 267 std::string GetTestURL() override {
253 return "files/push_messaging/test_bad_manifest.html"; 268 return "files/push_messaging/test_bad_manifest.html";
254 } 269 }
255 }; 270 };
256 271
257 IN_PROC_BROWSER_TEST_F(PushMessagingBadManifestBrowserTest, 272 IN_PROC_BROWSER_TEST_F(PushMessagingBadManifestBrowserTest,
258 RegisterFailsNotVisibleMessages) { 273 RegisterFailsNotVisibleMessages) {
274 if (!IsPushSupported())
275 return;
276
259 std::string script_result; 277 std::string script_result;
260 278
261 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 279 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
262 ASSERT_EQ("ok - service worker registered", script_result); 280 ASSERT_EQ("ok - service worker registered", script_result);
263 ASSERT_TRUE(RunScript("registerPush()", &script_result)); 281 ASSERT_TRUE(RunScript("registerPush()", &script_result));
264 EXPECT_EQ("AbortError - Registration failed - permission denied", 282 EXPECT_EQ("AbortError - Registration failed - permission denied",
265 script_result); 283 script_result);
266 } 284 }
267 285
268 void PushMessagingBrowserTest::TryToRegisterSuccessfully( 286 void PushMessagingBrowserTest::TryToRegisterSuccessfully(
(...skipping 16 matching lines...) Expand all
285 int64 service_worker_registration_id) { 303 int64 service_worker_registration_id) {
286 GURL origin = https_server()->GetURL("").GetOrigin(); 304 GURL origin = https_server()->GetURL("").GetOrigin();
287 PushMessagingApplicationId application_id = PushMessagingApplicationId::Get( 305 PushMessagingApplicationId application_id = PushMessagingApplicationId::Get(
288 browser()->profile(), origin, service_worker_registration_id); 306 browser()->profile(), origin, service_worker_registration_id);
289 EXPECT_TRUE(application_id.IsValid()); 307 EXPECT_TRUE(application_id.IsValid());
290 return application_id; 308 return application_id;
291 } 309 }
292 310
293 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 311 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
294 RegisterSuccessNotificationsGranted) { 312 RegisterSuccessNotificationsGranted) {
313 if (!IsPushSupported())
314 return;
315
295 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 316 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
296 317
297 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); 318 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL);
298 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); 319 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id());
299 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 320 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
300 } 321 }
301 322
302 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 323 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
303 RegisterSuccessNotificationsPrompt) { 324 RegisterSuccessNotificationsPrompt) {
325 if (!IsPushSupported())
326 return;
327
304 std::string script_result; 328 std::string script_result;
305 329
306 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 330 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
307 ASSERT_EQ("ok - service worker registered", script_result); 331 ASSERT_EQ("ok - service worker registered", script_result);
308 332
309 InfoBarResponder accepting_responder(browser(), true); 333 InfoBarResponder accepting_responder(browser(), true);
310 ASSERT_TRUE(RunScript("registerPush()", &script_result)); 334 ASSERT_TRUE(RunScript("registerPush()", &script_result));
311 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1-0", script_result); 335 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1-0", script_result);
312 336
313 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); 337 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL);
314 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); 338 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id());
315 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 339 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
316 } 340 }
317 341
318 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 342 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
319 RegisterFailureNotificationsBlocked) { 343 RegisterFailureNotificationsBlocked) {
344 if (!IsPushSupported())
345 return;
346
320 std::string script_result; 347 std::string script_result;
321 348
322 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 349 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
323 ASSERT_EQ("ok - service worker registered", script_result); 350 ASSERT_EQ("ok - service worker registered", script_result);
324 351
325 InfoBarResponder cancelling_responder(browser(), false); 352 InfoBarResponder cancelling_responder(browser(), false);
326 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result)); 353 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result));
327 ASSERT_EQ("permission status - denied", script_result); 354 ASSERT_EQ("permission status - denied", script_result);
328 355
329 ASSERT_TRUE(RunScript("registerPush()", &script_result)); 356 ASSERT_TRUE(RunScript("registerPush()", &script_result));
330 EXPECT_EQ("AbortError - Registration failed - permission denied", 357 EXPECT_EQ("AbortError - Registration failed - permission denied",
331 script_result); 358 script_result);
332 } 359 }
333 360
334 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterFailureNoManifest) { 361 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterFailureNoManifest) {
362 if (!IsPushSupported())
363 return;
364
335 std::string script_result; 365 std::string script_result;
336 366
337 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 367 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
338 ASSERT_EQ("ok - service worker registered", script_result); 368 ASSERT_EQ("ok - service worker registered", script_result);
339 369
340 InfoBarResponder accepting_responder(browser(), true); 370 InfoBarResponder accepting_responder(browser(), true);
341 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result)); 371 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result));
342 ASSERT_EQ("permission status - granted", script_result); 372 ASSERT_EQ("permission status - granted", script_result);
343 373
344 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); 374 ASSERT_TRUE(RunScript("removeManifest()", &script_result));
345 ASSERT_EQ("manifest removed", script_result); 375 ASSERT_EQ("manifest removed", script_result);
346 376
347 ASSERT_TRUE(RunScript("registerPush()", &script_result)); 377 ASSERT_TRUE(RunScript("registerPush()", &script_result));
348 EXPECT_EQ("AbortError - Registration failed - no sender id provided", 378 EXPECT_EQ("AbortError - Registration failed - no sender id provided",
349 script_result); 379 script_result);
350 } 380 }
351 381
352 // TODO(johnme): Test registering from a worker - see https://crbug.com/437298. 382 // TODO(johnme): Test registering from a worker - see https://crbug.com/437298.
353 383
354 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterPersisted) { 384 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, RegisterPersisted) {
385 if (!IsPushSupported())
386 return;
387
355 std::string script_result; 388 std::string script_result;
356 389
357 // First, test that Service Worker registration IDs are assigned in order of 390 // First, test that Service Worker registration IDs are assigned in order of
358 // registering the Service Workers, and the (fake) push registration ids are 391 // registering the Service Workers, and the (fake) push registration ids are
359 // assigned in order of push registration (even when these orders are 392 // assigned in order of push registration (even when these orders are
360 // different). 393 // different).
361 394
362 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 395 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
363 PushMessagingApplicationId app_id_sw0 = GetServiceWorkerAppId(0LL); 396 PushMessagingApplicationId app_id_sw0 = GetServiceWorkerAppId(0LL);
364 EXPECT_EQ(app_id_sw0.app_id_guid, gcm_service()->last_registered_app_id()); 397 EXPECT_EQ(app_id_sw0.app_id_guid, gcm_service()->last_registered_app_id());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 LoadTestPage("files/push_messaging/subscope2/test.html"); 432 LoadTestPage("files/push_messaging/subscope2/test.html");
400 TryToRegisterSuccessfully("1-1" /* expected_push_registration_id */); 433 TryToRegisterSuccessfully("1-1" /* expected_push_registration_id */);
401 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id()); 434 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id());
402 435
403 LoadTestPage(); 436 LoadTestPage();
404 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 437 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
405 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id()); 438 EXPECT_EQ(app_id_sw1.app_id_guid, gcm_service()->last_registered_app_id());
406 } 439 }
407 440
408 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { 441 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) {
442 if (!IsPushSupported())
443 return;
444
409 std::string script_result; 445 std::string script_result;
410 446
411 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 447 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
412 448
413 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); 449 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL);
414 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); 450 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id());
415 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 451 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
416 452
417 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 453 ASSERT_TRUE(RunScript("isControlled()", &script_result));
418 ASSERT_EQ("false - is not controlled", script_result); 454 ASSERT_EQ("false - is not controlled", script_result);
419 455
420 LoadTestPage(); // Reload to become controlled. 456 LoadTestPage(); // Reload to become controlled.
421 457
422 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 458 ASSERT_TRUE(RunScript("isControlled()", &script_result));
423 ASSERT_EQ("true - is controlled", script_result); 459 ASSERT_EQ("true - is controlled", script_result);
424 460
425 GCMClient::IncomingMessage message; 461 GCMClient::IncomingMessage message;
426 message.data["data"] = "testdata"; 462 message.data["data"] = "testdata";
427 push_service()->OnMessage(app_id.app_id_guid, message); 463 push_service()->OnMessage(app_id.app_id_guid, message);
428 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); 464 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result));
429 EXPECT_EQ("testdata", script_result); 465 EXPECT_EQ("testdata", script_result);
430 } 466 }
431 467
432 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { 468 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) {
469 if (!IsPushSupported())
470 return;
471
433 std::string script_result; 472 std::string script_result;
434 473
435 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 474 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
436 475
437 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); 476 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL);
438 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); 477 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id());
439 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 478 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
440 479
441 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 480 ASSERT_TRUE(RunScript("isControlled()", &script_result));
442 ASSERT_EQ("false - is not controlled", script_result); 481 ASSERT_EQ("false - is not controlled", script_result);
(...skipping 19 matching lines...) Expand all
462 501
463 callback.WaitUntilSatisfied(); 502 callback.WaitUntilSatisfied();
464 EXPECT_EQ(app_id.app_id_guid, callback.app_id()); 503 EXPECT_EQ(app_id.app_id_guid, callback.app_id());
465 504
466 // No push data should have been received. 505 // No push data should have been received.
467 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); 506 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result));
468 EXPECT_EQ("null", script_result); 507 EXPECT_EQ("null", script_result);
469 } 508 }
470 509
471 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoPermission) { 510 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoPermission) {
511 if (!IsPushSupported())
512 return;
513
472 std::string script_result; 514 std::string script_result;
473 515
474 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 516 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
475 517
476 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); 518 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL);
477 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); 519 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id());
478 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 520 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
479 521
480 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 522 ASSERT_TRUE(RunScript("isControlled()", &script_result));
481 ASSERT_EQ("false - is not controlled", script_result); 523 ASSERT_EQ("false - is not controlled", script_result);
(...skipping 21 matching lines...) Expand all
503 EXPECT_EQ(app_id.app_id_guid, callback.app_id()); 545 EXPECT_EQ(app_id.app_id_guid, callback.app_id());
504 546
505 // No push data should have been received. 547 // No push data should have been received.
506 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); 548 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result));
507 EXPECT_EQ("null", script_result); 549 EXPECT_EQ("null", script_result);
508 } 550 }
509 551
510 #if defined(ENABLE_NOTIFICATIONS) 552 #if defined(ENABLE_NOTIFICATIONS)
511 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 553 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
512 PushEventEnforcesUserVisibleNotification) { 554 PushEventEnforcesUserVisibleNotification) {
555 if (!IsPushSupported())
556 return;
557
513 std::string script_result; 558 std::string script_result;
514 559
515 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 560 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
516 561
517 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); 562 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL);
518 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); 563 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id());
519 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 564 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
520 565
521 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 566 ASSERT_TRUE(RunScript("isControlled()", &script_result));
522 ASSERT_EQ("false - is not controlled", script_result); 567 ASSERT_EQ("false - is not controlled", script_result);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 // allow the next one to mistakenly not show a notification. 639 // allow the next one to mistakenly not show a notification.
595 message.data["data"] = "testdata"; 640 message.data["data"] = "testdata";
596 push_service()->OnMessage(app_id.app_id_guid, message); 641 push_service()->OnMessage(app_id.app_id_guid, message);
597 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); 642 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents));
598 EXPECT_EQ("testdata", script_result); 643 EXPECT_EQ("testdata", script_result);
599 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); 644 EXPECT_EQ(0u, notification_manager()->GetNotificationCount());
600 } 645 }
601 646
602 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 647 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
603 PushEventNotificationWithoutEventWaitUntil) { 648 PushEventNotificationWithoutEventWaitUntil) {
649 if (!IsPushSupported())
650 return;
651
604 std::string script_result; 652 std::string script_result;
605 content::WebContents* web_contents = 653 content::WebContents* web_contents =
606 browser()->tab_strip_model()->GetActiveWebContents(); 654 browser()->tab_strip_model()->GetActiveWebContents();
607 655
608 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 656 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
609 657
610 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL); 658 PushMessagingApplicationId app_id = GetServiceWorkerAppId(0LL);
611 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id()); 659 EXPECT_EQ(app_id.app_id_guid, gcm_service()->last_registered_app_id());
612 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 660 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
613 661
(...skipping 21 matching lines...) Expand all
635 EXPECT_EQ(base::ASCIIToUTF16("push_test_tag"), 683 EXPECT_EQ(base::ASCIIToUTF16("push_test_tag"),
636 notification_manager()->GetNotificationAt(0).replace_id()); 684 notification_manager()->GetNotificationAt(0).replace_id());
637 685
638 // Verify that the renderer process hasn't crashed. 686 // Verify that the renderer process hasn't crashed.
639 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 687 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
640 EXPECT_EQ("permission status - granted", script_result); 688 EXPECT_EQ("permission status - granted", script_result);
641 } 689 }
642 #endif 690 #endif
643 691
644 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDefault) { 692 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDefault) {
693 if (!IsPushSupported())
694 return;
695
645 std::string script_result; 696 std::string script_result;
646 697
647 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 698 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
648 ASSERT_EQ("ok - service worker registered", script_result); 699 ASSERT_EQ("ok - service worker registered", script_result);
649 700
650 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 701 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
651 ASSERT_EQ("permission status - default", script_result); 702 ASSERT_EQ("permission status - default", script_result);
652 } 703 }
653 704
654 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysGranted) { 705 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysGranted) {
706 if (!IsPushSupported())
707 return;
708
655 std::string script_result; 709 std::string script_result;
656 710
657 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 711 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
658 ASSERT_EQ("ok - service worker registered", script_result); 712 ASSERT_EQ("ok - service worker registered", script_result);
659 713
660 InfoBarResponder accepting_responder(browser(), true); 714 InfoBarResponder accepting_responder(browser(), true);
661 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result)); 715 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result));
662 EXPECT_EQ("permission status - granted", script_result); 716 EXPECT_EQ("permission status - granted", script_result);
663 717
664 ASSERT_TRUE(RunScript("registerPush()", &script_result)); 718 ASSERT_TRUE(RunScript("registerPush()", &script_result));
665 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1-0", script_result); 719 EXPECT_EQ(std::string(kPushMessagingEndpoint) + " - 1-0", script_result);
666 720
667 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 721 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
668 EXPECT_EQ("permission status - granted", script_result); 722 EXPECT_EQ("permission status - granted", script_result);
669 } 723 }
670 724
671 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDenied) { 725 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, HasPermissionSaysDenied) {
726 if (!IsPushSupported())
727 return;
728
672 std::string script_result; 729 std::string script_result;
673 730
674 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 731 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
675 ASSERT_EQ("ok - service worker registered", script_result); 732 ASSERT_EQ("ok - service worker registered", script_result);
676 733
677 InfoBarResponder cancelling_responder(browser(), false); 734 InfoBarResponder cancelling_responder(browser(), false);
678 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result)); 735 ASSERT_TRUE(RunScript("requestNotificationPermission();", &script_result));
679 EXPECT_EQ("permission status - denied", script_result); 736 EXPECT_EQ("permission status - denied", script_result);
680 737
681 ASSERT_TRUE(RunScript("registerPush()", &script_result)); 738 ASSERT_TRUE(RunScript("registerPush()", &script_result));
682 EXPECT_EQ("AbortError - Registration failed - permission denied", 739 EXPECT_EQ("AbortError - Registration failed - permission denied",
683 script_result); 740 script_result);
684 741
685 ASSERT_TRUE(RunScript("hasPermission()", &script_result)); 742 ASSERT_TRUE(RunScript("hasPermission()", &script_result));
686 EXPECT_EQ("permission status - denied", script_result); 743 EXPECT_EQ("permission status - denied", script_result);
687 } 744 }
688 745
689 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterSuccess) { 746 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterSuccess) {
747 if (!IsPushSupported())
748 return;
749
690 std::string script_result; 750 std::string script_result;
691 751
692 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 752 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
693 753
694 gcm_service()->AddExpectedUnregisterResponse(GCMClient::SUCCESS); 754 gcm_service()->AddExpectedUnregisterResponse(GCMClient::SUCCESS);
695 755
696 ASSERT_TRUE(RunScript("unregister()", &script_result)); 756 ASSERT_TRUE(RunScript("unregister()", &script_result));
697 EXPECT_EQ("unregister result: true", script_result); 757 EXPECT_EQ("unregister result: true", script_result);
698 } 758 }
699 759
700 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterNetworkError) { 760 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterNetworkError) {
761 if (!IsPushSupported())
762 return;
763
701 std::string script_result; 764 std::string script_result;
702 765
703 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 766 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
704 767
705 gcm_service()->AddExpectedUnregisterResponse(GCMClient::NETWORK_ERROR); 768 gcm_service()->AddExpectedUnregisterResponse(GCMClient::NETWORK_ERROR);
706 769
707 ASSERT_TRUE(RunScript("unregister()", &script_result)); 770 ASSERT_TRUE(RunScript("unregister()", &script_result));
708 EXPECT_EQ("unregister error: " 771 EXPECT_EQ("unregister error: "
709 "NetworkError: Failed to connect to the push server.", 772 "NetworkError: Failed to connect to the push server.",
710 script_result); 773 script_result);
711 } 774 }
712 775
713 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterUnknownError) { 776 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnregisterUnknownError) {
777 if (!IsPushSupported())
778 return;
779
714 std::string script_result; 780 std::string script_result;
715 781
716 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */); 782 TryToRegisterSuccessfully("1-0" /* expected_push_registration_id */);
717 783
718 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR); 784 gcm_service()->AddExpectedUnregisterResponse(GCMClient::UNKNOWN_ERROR);
719 785
720 ASSERT_TRUE(RunScript("unregister()", &script_result)); 786 ASSERT_TRUE(RunScript("unregister()", &script_result));
721 EXPECT_EQ("unregister error: " 787 EXPECT_EQ("unregister error: "
722 "UnknownError: Unexpected error while trying to unregister from the" 788 "UnknownError: Unexpected error while trying to unregister from the"
723 " push server.", script_result); 789 " push server.", script_result);
724 } 790 }
725 791
792 #if defined(OS_ANDROID)
793 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushUnavailableOnAndroidICS) {
794 // This test should only run on Android ICS to confirm that the Push API
795 // is not available on that version of Android.
796 if (IsPushSupported())
797 return;
798
799 std::string script_result;
800 ASSERT_TRUE(RunScript("window.PushManager", &script_result));
801 EXPECT_EQ("undefined", script_result);
802 }
803 #endif
804
726 } // namespace gcm 805 } // namespace gcm
OLDNEW
« no previous file with comments | « base/android/build_info.h ('k') | chrome/browser/services/gcm/push_messaging_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698