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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_browsertest.cc

Issue 1816123002: Add testing for subscription from service workers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review comments incorporated and all tests working 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 // 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 #include "content/public/test/browser_test_utils.h" 48 #include "content/public/test/browser_test_utils.h"
49 #include "content/public/test/test_utils.h" 49 #include "content/public/test/test_utils.h"
50 #include "net/test/embedded_test_server/embedded_test_server.h" 50 #include "net/test/embedded_test_server/embedded_test_server.h"
51 #include "ui/base/window_open_disposition.h" 51 #include "ui/base/window_open_disposition.h"
52 52
53 #if BUILDFLAG(ENABLE_BACKGROUND) 53 #if BUILDFLAG(ENABLE_BACKGROUND)
54 #include "chrome/browser/background/background_mode_manager.h" 54 #include "chrome/browser/background/background_mode_manager.h"
55 #endif 55 #endif
56 56
57 namespace { 57 namespace {
58
59 // NIST P-256 public key made available to tests. Must be an uncompressed
60 // point in accordance with SEC1 2.3.3.
61 const uint8_t kApplicationServerKey[65] = {
62 0x04, 0x55, 0x52, 0x6A, 0xA5, 0x6E, 0x8E, 0xAA, 0x47, 0x97, 0x36,
63 0x10, 0xC1, 0x66, 0x3C, 0x1E, 0x65, 0xBF, 0xA1, 0x7B, 0xEE, 0x48,
64 0xC9, 0xC6, 0xBB, 0xBF, 0x02, 0x18, 0x53, 0x72, 0x1D, 0x0C, 0x7B,
65 0xA9, 0xE3, 0x11, 0xB7, 0x03, 0x52, 0x21, 0xD3, 0x71, 0x90, 0x13,
66 0xA8, 0xC1, 0xCF, 0xED, 0x20, 0xF7, 0x1F, 0xD1, 0x7F, 0xF2, 0x76,
67 0xB6, 0x01, 0x20, 0xD8, 0x35, 0xA5, 0xD9, 0x3C, 0x43, 0xFD};
68
58 // Class to instantiate on the stack that is meant to be used with 69 // Class to instantiate on the stack that is meant to be used with
59 // FakeGCMProfileService. The ::Run() method follows the signature of 70 // FakeGCMProfileService. The ::Run() method follows the signature of
60 // FakeGCMProfileService::UnregisterCallback. 71 // FakeGCMProfileService::UnregisterCallback.
61 class UnregistrationCallback { 72 class UnregistrationCallback {
62 public: 73 public:
63 UnregistrationCallback() 74 UnregistrationCallback()
64 : message_loop_runner_(new content::MessageLoopRunner) {} 75 : message_loop_runner_(new content::MessageLoopRunner) {}
65 76
66 void Run(const std::string& app_id) { 77 void Run(const std::string& app_id) {
67 app_id_ = app_id; 78 app_id_ = app_id;
(...skipping 26 matching lines...) Expand all
94 #if defined(ENABLE_NOTIFICATIONS) 105 #if defined(ENABLE_NOTIFICATIONS)
95 notification_manager_.reset(new StubNotificationUIManager); 106 notification_manager_.reset(new StubNotificationUIManager);
96 notification_service()->SetNotificationUIManagerForTesting( 107 notification_service()->SetNotificationUIManagerForTesting(
97 notification_manager()); 108 notification_manager());
98 #endif 109 #endif
99 110
100 InProcessBrowserTest::SetUp(); 111 InProcessBrowserTest::SetUp();
101 } 112 }
102 113
103 void SetUpCommandLine(base::CommandLine* command_line) override { 114 void SetUpCommandLine(base::CommandLine* command_line) override {
104 // Enable experiemntal features for subscription restrictions. 115 // Enable experimental features for subscription restrictions.
105 command_line->AppendSwitch( 116 command_line->AppendSwitch(
106 switches::kEnableExperimentalWebPlatformFeatures); 117 switches::kEnableExperimentalWebPlatformFeatures);
107 InProcessBrowserTest::SetUpCommandLine(command_line); 118 InProcessBrowserTest::SetUpCommandLine(command_line);
108 } 119 }
109 120
110 // InProcessBrowserTest: 121 // InProcessBrowserTest:
111 void SetUpOnMainThread() override { 122 void SetUpOnMainThread() override {
112 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( 123 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>(
113 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( 124 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse(
114 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); 125 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build));
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 const std::string& expected_push_subscription_info, 269 const std::string& expected_push_subscription_info,
259 bool use_key) { 270 bool use_key) {
260 std::string script_result; 271 std::string script_result;
261 272
262 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); 273 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result));
263 EXPECT_EQ("ok - service worker registered", script_result); 274 EXPECT_EQ("ok - service worker registered", script_result);
264 275
265 RequestAndAcceptPermission(); 276 RequestAndAcceptPermission();
266 277
267 if (use_key) { 278 if (use_key) {
268 EXPECT_TRUE(RunScript("subscribePush()", &script_result)); 279 ASSERT_TRUE(RunScript("removeManifest()", &script_result));
280 ASSERT_EQ("manifest removed", script_result);
281
282 EXPECT_TRUE(RunScript("documentSubscribePush()", &script_result));
269 } else { 283 } else {
270 // Test backwards compatibility with old ID based subscriptions. 284 // Test backwards compatibility with old ID based subscriptions.
271 EXPECT_TRUE(RunScript("subscribePushWithoutKey()", &script_result)); 285 EXPECT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
272 } 286 }
273 287
274 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_info), 288 EXPECT_EQ(GetEndpointForSubscriptionId(expected_push_subscription_info),
275 script_result); 289 script_result);
276 } 290 }
277 291
278 PushMessagingAppIdentifier 292 PushMessagingAppIdentifier
279 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration( 293 PushMessagingBrowserTest::GetAppIdentifierForServiceWorkerRegistration(
280 int64_t service_worker_registration_id) { 294 int64_t service_worker_registration_id) {
281 GURL origin = https_server()->GetURL("/").GetOrigin(); 295 GURL origin = https_server()->GetURL("/").GetOrigin();
(...skipping 23 matching lines...) Expand all
305 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 319 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]);
306 } 320 }
307 321
308 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 322 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
309 SubscribeSuccessNotificationsGranted) { 323 SubscribeSuccessNotificationsGranted) {
310 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 324 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
311 325
312 PushMessagingAppIdentifier app_identifier = 326 PushMessagingAppIdentifier app_identifier =
313 GetAppIdentifierForServiceWorkerRegistration(0LL); 327 GetAppIdentifierForServiceWorkerRegistration(0LL);
314 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); 328 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
315 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 329 EXPECT_EQ(reinterpret_cast<const char*>(kApplicationServerKey),
Michael van Ouwerkerk 2016/03/30 09:50:04 nit: a small helper function like "getTestApplicat
harkness 2016/03/30 10:51:49 Done.
330 gcm_service()->last_registered_sender_ids()[0]);
316 } 331 }
317 332
318 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 333 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
319 SubscribeSuccessNotificationsPrompt) { 334 SubscribeSuccessNotificationsPrompt) {
320 std::string script_result; 335 std::string script_result;
321 336
322 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 337 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
323 ASSERT_EQ("ok - service worker registered", script_result); 338 ASSERT_EQ("ok - service worker registered", script_result);
324 339
325 GetPermissionBubbleManager()->set_auto_response_for_test( 340 GetPermissionBubbleManager()->set_auto_response_for_test(
326 PermissionBubbleManager::ACCEPT_ALL); 341 PermissionBubbleManager::ACCEPT_ALL);
327 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); 342 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result));
328 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); 343 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result);
329 344
330 PushMessagingAppIdentifier app_identifier = 345 PushMessagingAppIdentifier app_identifier =
331 GetAppIdentifierForServiceWorkerRegistration(0LL); 346 GetAppIdentifierForServiceWorkerRegistration(0LL);
332 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); 347 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
333 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 348 EXPECT_EQ(reinterpret_cast<const char*>(kApplicationServerKey),
349 gcm_service()->last_registered_sender_ids()[0]);
334 } 350 }
335 351
336 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) { 352 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) {
337 std::string script_result; 353 std::string script_result;
338 354
339 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 355 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
340 ASSERT_EQ("ok - service worker registered", script_result); 356 ASSERT_EQ("ok - service worker registered", script_result);
341 357
342 RequestAndAcceptPermission(); 358 RequestAndAcceptPermission();
343 359
344 ASSERT_TRUE(RunScript("subscribePushBadKey()", &script_result)); 360 ASSERT_TRUE(RunScript("documentSubscribePushBadKey()", &script_result));
345 EXPECT_EQ( 361 EXPECT_EQ(
346 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': " 362 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': "
347 "The provided applicationServerKey is not valid.", 363 "The provided applicationServerKey is not valid.",
348 script_result); 364 script_result);
349 } 365 }
350 366
351 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 367 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
352 SubscribeFailureNotificationsBlocked) { 368 SubscribeFailureNotificationsBlocked) {
353 std::string script_result; 369 std::string script_result;
354 370
355 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 371 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
356 ASSERT_EQ("ok - service worker registered", script_result); 372 ASSERT_EQ("ok - service worker registered", script_result);
357 373
358 RequestAndDenyPermission(); 374 RequestAndDenyPermission();
359 375
360 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); 376 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result));
361 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", 377 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied",
362 script_result); 378 script_result);
363 } 379 }
364 380
365 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoManifest) { 381 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoManifest) {
366 std::string script_result; 382 std::string script_result;
367 383
368 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 384 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
369 ASSERT_EQ("ok - service worker registered", script_result); 385 ASSERT_EQ("ok - service worker registered", script_result);
370 386
371 RequestAndAcceptPermission(); 387 RequestAndAcceptPermission();
372 388
373 ASSERT_TRUE(RunScript("removeManifest()", &script_result)); 389 ASSERT_TRUE(RunScript("removeManifest()", &script_result));
374 ASSERT_EQ("manifest removed", script_result); 390 ASSERT_EQ("manifest removed", script_result);
375 391
376 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); 392 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
377 EXPECT_EQ("AbortError - Registration failed - manifest empty or missing", 393 EXPECT_EQ("AbortError - Registration failed - manifest empty or missing",
378 script_result); 394 script_result);
379 } 395 }
380 396
381 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoSenderId) { 397 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureNoSenderId) {
382 std::string script_result; 398 std::string script_result;
383 399
384 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 400 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
385 ASSERT_EQ("ok - service worker registered", script_result); 401 ASSERT_EQ("ok - service worker registered", script_result);
386 402
387 RequestAndAcceptPermission(); 403 RequestAndAcceptPermission();
388 404
389 ASSERT_TRUE(RunScript("swapManifestNoSenderId()", &script_result)); 405 ASSERT_TRUE(RunScript("swapManifestNoSenderId()", &script_result));
390 ASSERT_EQ("sender id removed from manifest", script_result); 406 ASSERT_EQ("sender id removed from manifest", script_result);
391 407
392 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); 408 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
393 EXPECT_EQ( 409 EXPECT_EQ(
394 "AbortError - Registration failed - gcm_sender_id not found in manifest", 410 "AbortError - Registration failed - gcm_sender_id not found in manifest",
395 script_result); 411 script_result);
396 } 412 }
397 413
398 // TODO(johnme): Test subscribing from a worker - see https://crbug.com/437298.
399
400 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions, 414 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTestEmptySubscriptionOptions,
401 RegisterFailureEmptyPushSubscriptionOptions) { 415 RegisterFailureEmptyPushSubscriptionOptions) {
402 std::string script_result; 416 std::string script_result;
403 417
404 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 418 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
405 ASSERT_EQ("ok - service worker registered", script_result); 419 ASSERT_EQ("ok - service worker registered", script_result);
406 420
407 RequestAndAcceptPermission(); 421 RequestAndAcceptPermission();
408 422
409 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); 423 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result));
410 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", 424 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied",
411 script_result); 425 script_result);
412 } 426 }
413 427
428 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorker) {
429 std::string script_result;
430
431 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
432 ASSERT_EQ("ok - service worker registered", script_result);
433
434 RequestAndAcceptPermission();
435
436 LoadTestPage(); // Reload to become controlled.
437
438 ASSERT_TRUE(RunScript("isControlled()", &script_result));
439 ASSERT_EQ("true - is controlled", script_result);
440
441 // Try to subscribe from a worker without a key. This should fail.
442 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
443 EXPECT_EQ(
444 "AbortError - Registration failed - gcm_sender_id not found in manifest",
445 script_result);
446 // Now run the subscribe from the service worker with a key. This
447 // should succeed, and write the key to the datastore.
448 ASSERT_TRUE(RunScript("workerSubscribePush()", &script_result));
449 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result);
450
451 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
452 EXPECT_EQ("unsubscribe result: true", script_result);
453 EXPECT_NE(push_service(), GetAppHandler());
454
455 // Now run the subscribe from the service worker without a key.
456 // In this case, the key will be read from the datastore.
457 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
458 EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result);
459
460 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
461 EXPECT_EQ("unsubscribe result: true", script_result);
462 EXPECT_NE(push_service(), GetAppHandler());
463 }
464
465 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeWorkerUsingManifest) {
466 std::string script_result;
467
468 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
469 ASSERT_EQ("ok - service worker registered", script_result);
470
471 RequestAndAcceptPermission();
472
473 LoadTestPage(); // Reload to become controlled.
474
475 ASSERT_TRUE(RunScript("isControlled()", &script_result));
476 ASSERT_EQ("true - is controlled", script_result);
477
478 // Try to subscribe from a worker without a key. This should fail.
479 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
480 EXPECT_EQ(
481 "AbortError - Registration failed - gcm_sender_id not found in manifest",
482 script_result);
483 EXPECT_NE(push_service(), GetAppHandler());
484
485 // Run the subscription from the document without a key, this will
486 // trigger the code to read the manifest and will write to the datastore.
487 ASSERT_TRUE(RunScript("documentSubscribePushWithoutKey()", &script_result));
488 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result);
489
490 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
491 EXPECT_EQ("unsubscribe result: true", script_result);
492 EXPECT_NE(push_service(), GetAppHandler());
493
494 // Now run the subscribe from the service worker without a key.
495 // In this case, the key will be read from the datastore.
Michael van Ouwerkerk 2016/03/30 09:50:04 nit: be a bit more explicit by calling out this is
harkness 2016/03/30 10:51:49 Done.
496 ASSERT_TRUE(RunScript("workerSubscribePushNoKey()", &script_result));
497 EXPECT_EQ(GetEndpointForSubscriptionId("1-1"), script_result);
498
499 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
500 EXPECT_EQ("unsubscribe result: true", script_result);
501 EXPECT_NE(push_service(), GetAppHandler());
502 }
503
414 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003). 504 // Disabled on Windows and Linux due to flakiness (http://crbug.com/554003).
415 #if defined(OS_WIN) || defined(OS_LINUX) 505 #if defined(OS_WIN) || defined(OS_LINUX)
416 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted 506 #define MAYBE_SubscribePersisted DISABLED_SubscribePersisted
417 #else 507 #else
418 #define MAYBE_SubscribePersisted SubscribePersisted 508 #define MAYBE_SubscribePersisted SubscribePersisted
419 #endif 509 #endif
420 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) { 510 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, MAYBE_SubscribePersisted) {
421 std::string script_result; 511 std::string script_result;
422 512
423 // First, test that Service Worker registration IDs are assigned in order of 513 // First, test that Service Worker registration IDs are assigned in order of
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 589 }
500 590
501 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) { 591 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventSuccess) {
502 std::string script_result; 592 std::string script_result;
503 593
504 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 594 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
505 595
506 PushMessagingAppIdentifier app_identifier = 596 PushMessagingAppIdentifier app_identifier =
507 GetAppIdentifierForServiceWorkerRegistration(0LL); 597 GetAppIdentifierForServiceWorkerRegistration(0LL);
508 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); 598 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
509 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 599 EXPECT_EQ(reinterpret_cast<const char*>(kApplicationServerKey),
600 gcm_service()->last_registered_sender_ids()[0]);
510 601
511 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 602 ASSERT_TRUE(RunScript("isControlled()", &script_result));
512 ASSERT_EQ("false - is not controlled", script_result); 603 ASSERT_EQ("false - is not controlled", script_result);
513 604
514 LoadTestPage(); // Reload to become controlled. 605 LoadTestPage(); // Reload to become controlled.
515 606
516 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 607 ASSERT_TRUE(RunScript("isControlled()", &script_result));
517 ASSERT_EQ("true - is controlled", script_result); 608 ASSERT_EQ("true - is controlled", script_result);
518 609
519 gcm::IncomingMessage message; 610 gcm::IncomingMessage message;
520 message.sender_id = "1234567890"; 611 message.sender_id =
612 std::string(reinterpret_cast<const char*>(kApplicationServerKey));
521 message.raw_data = "testdata"; 613 message.raw_data = "testdata";
522 message.decrypted = true; 614 message.decrypted = true;
523 push_service()->OnMessage(app_identifier.app_id(), message); 615 push_service()->OnMessage(app_identifier.app_id(), message);
524 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); 616 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result));
525 EXPECT_EQ("testdata", script_result); 617 EXPECT_EQ("testdata", script_result);
526 } 618 }
527 619
528 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) { 620 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) {
529 std::string script_result; 621 std::string script_result;
530 622
531 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 623 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
532 624
533 PushMessagingAppIdentifier app_identifier = 625 PushMessagingAppIdentifier app_identifier =
534 GetAppIdentifierForServiceWorkerRegistration(0LL); 626 GetAppIdentifierForServiceWorkerRegistration(0LL);
535 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); 627 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
536 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 628 EXPECT_EQ(reinterpret_cast<const char*>(kApplicationServerKey),
629 gcm_service()->last_registered_sender_ids()[0]);
537 630
538 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 631 ASSERT_TRUE(RunScript("isControlled()", &script_result));
539 ASSERT_EQ("false - is not controlled", script_result); 632 ASSERT_EQ("false - is not controlled", script_result);
540 633
541 LoadTestPage(); // Reload to become controlled. 634 LoadTestPage(); // Reload to become controlled.
542 635
543 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 636 ASSERT_TRUE(RunScript("isControlled()", &script_result));
544 ASSERT_EQ("true - is controlled", script_result); 637 ASSERT_EQ("true - is controlled", script_result);
545 638
546 gcm::IncomingMessage message; 639 gcm::IncomingMessage message;
547 message.sender_id = "1234567890"; 640 message.sender_id =
641 std::string(reinterpret_cast<const char*>(kApplicationServerKey));
548 message.decrypted = false; 642 message.decrypted = false;
549 643
550 push_service()->OnMessage(app_identifier.app_id(), message); 644 push_service()->OnMessage(app_identifier.app_id(), message);
551 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); 645 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result));
552 EXPECT_EQ("[NULL]", script_result); 646 EXPECT_EQ("[NULL]", script_result);
553 } 647 }
554 648
555 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) { 649 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventNoServiceWorker) {
556 std::string script_result; 650 std::string script_result;
557 651
558 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 652 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
559 653
560 PushMessagingAppIdentifier app_identifier = 654 PushMessagingAppIdentifier app_identifier =
561 GetAppIdentifierForServiceWorkerRegistration(0LL); 655 GetAppIdentifierForServiceWorkerRegistration(0LL);
562 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); 656 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
563 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 657 EXPECT_EQ(reinterpret_cast<const char*>(kApplicationServerKey),
658 gcm_service()->last_registered_sender_ids()[0]);
564 659
565 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 660 ASSERT_TRUE(RunScript("isControlled()", &script_result));
566 ASSERT_EQ("false - is not controlled", script_result); 661 ASSERT_EQ("false - is not controlled", script_result);
567 662
568 LoadTestPage(); // Reload to become controlled. 663 LoadTestPage(); // Reload to become controlled.
569 664
570 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 665 ASSERT_TRUE(RunScript("isControlled()", &script_result));
571 ASSERT_EQ("true - is controlled", script_result); 666 ASSERT_EQ("true - is controlled", script_result);
572 667
573 // Unregister service worker. Sending a message should now fail. 668 // Unregister service worker. Sending a message should now fail.
574 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); 669 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result));
575 ASSERT_EQ("service worker unregistration status: true", script_result); 670 ASSERT_EQ("service worker unregistration status: true", script_result);
576 671
577 // When the push service will receive it next message, given that there is no 672 // When the push service will receive it next message, given that there is no
578 // SW available, it should unregister |app_identifier.app_id()|. 673 // SW available, it should unregister |app_identifier.app_id()|.
579 UnregistrationCallback callback; 674 UnregistrationCallback callback;
580 gcm_service()->SetUnregisterCallback( 675 gcm_service()->SetUnregisterCallback(
581 base::Bind(&UnregistrationCallback::Run, base::Unretained(&callback))); 676 base::Bind(&UnregistrationCallback::Run, base::Unretained(&callback)));
582 677
583 gcm::IncomingMessage message; 678 gcm::IncomingMessage message;
584 message.sender_id = "1234567890"; 679 message.sender_id =
680 std::string(reinterpret_cast<const char*>(kApplicationServerKey));
585 message.raw_data = "testdata"; 681 message.raw_data = "testdata";
586 message.decrypted = true; 682 message.decrypted = true;
587 push_service()->OnMessage(app_identifier.app_id(), message); 683 push_service()->OnMessage(app_identifier.app_id(), message);
588 684
589 callback.WaitUntilSatisfied(); 685 callback.WaitUntilSatisfied();
590 EXPECT_EQ(app_identifier.app_id(), callback.app_id()); 686 EXPECT_EQ(app_identifier.app_id(), callback.app_id());
591 687
592 // No push data should have been received. 688 // No push data should have been received.
593 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); 689 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result));
594 EXPECT_EQ("null", script_result); 690 EXPECT_EQ("null", script_result);
595 } 691 }
596 692
597 #if defined(ENABLE_NOTIFICATIONS) 693 #if defined(ENABLE_NOTIFICATIONS)
598 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 694 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
599 PushEventEnforcesUserVisibleNotification) { 695 PushEventEnforcesUserVisibleNotification) {
600 std::string script_result; 696 std::string script_result;
601 697
602 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 698 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
603 699
604 PushMessagingAppIdentifier app_identifier = 700 PushMessagingAppIdentifier app_identifier =
605 GetAppIdentifierForServiceWorkerRegistration(0LL); 701 GetAppIdentifierForServiceWorkerRegistration(0LL);
606 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); 702 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
607 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 703 EXPECT_EQ(reinterpret_cast<const char*>(kApplicationServerKey),
704 gcm_service()->last_registered_sender_ids()[0]);
608 705
609 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 706 ASSERT_TRUE(RunScript("isControlled()", &script_result));
610 ASSERT_EQ("false - is not controlled", script_result); 707 ASSERT_EQ("false - is not controlled", script_result);
611 708
612 LoadTestPage(); // Reload to become controlled. 709 LoadTestPage(); // Reload to become controlled.
613 710
614 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 711 ASSERT_TRUE(RunScript("isControlled()", &script_result));
615 ASSERT_EQ("true - is controlled", script_result); 712 ASSERT_EQ("true - is controlled", script_result);
616 713
617 notification_manager()->CancelAll(); 714 notification_manager()->CancelAll();
618 ASSERT_EQ(0u, notification_manager()->GetNotificationCount()); 715 ASSERT_EQ(0u, notification_manager()->GetNotificationCount());
619 716
620 // We'll need to specify the web_contents in which to eval script, since we're 717 // We'll need to specify the web_contents in which to eval script, since we're
621 // going to run script in a background tab. 718 // going to run script in a background tab.
622 content::WebContents* web_contents = 719 content::WebContents* web_contents =
623 GetBrowser()->tab_strip_model()->GetActiveWebContents(); 720 GetBrowser()->tab_strip_model()->GetActiveWebContents();
624 721
625 // If the site is visible in an active tab, we should not force a notification 722 // If the site is visible in an active tab, we should not force a notification
626 // to be shown. Try it twice, since we allow one mistake per 10 push events. 723 // to be shown. Try it twice, since we allow one mistake per 10 push events.
627 gcm::IncomingMessage message; 724 gcm::IncomingMessage message;
628 message.sender_id = "1234567890"; 725 message.sender_id =
726 std::string(reinterpret_cast<const char*>(kApplicationServerKey));
629 message.decrypted = true; 727 message.decrypted = true;
630 for (int n = 0; n < 2; n++) { 728 for (int n = 0; n < 2; n++) {
631 message.raw_data = "testdata"; 729 message.raw_data = "testdata";
632 SendMessageAndWaitUntilHandled(app_identifier, message); 730 SendMessageAndWaitUntilHandled(app_identifier, message);
633 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); 731 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result));
634 EXPECT_EQ("testdata", script_result); 732 EXPECT_EQ("testdata", script_result);
635 EXPECT_EQ(0u, notification_manager()->GetNotificationCount()); 733 EXPECT_EQ(0u, notification_manager()->GetNotificationCount());
636 } 734 }
637 735
638 // Open a blank foreground tab so site is no longer visible. 736 // Open a blank foreground tab so site is no longer visible.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 802
705 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 803 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
706 PushEventEnforcesUserVisibleNotificationAfterQueue) { 804 PushEventEnforcesUserVisibleNotificationAfterQueue) {
707 std::string script_result; 805 std::string script_result;
708 806
709 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 807 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
710 808
711 PushMessagingAppIdentifier app_identifier = 809 PushMessagingAppIdentifier app_identifier =
712 GetAppIdentifierForServiceWorkerRegistration(0LL); 810 GetAppIdentifierForServiceWorkerRegistration(0LL);
713 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); 811 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
714 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 812 EXPECT_EQ(reinterpret_cast<const char*>(kApplicationServerKey),
813 gcm_service()->last_registered_sender_ids()[0]);
715 814
716 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 815 ASSERT_TRUE(RunScript("isControlled()", &script_result));
717 ASSERT_EQ("false - is not controlled", script_result); 816 ASSERT_EQ("false - is not controlled", script_result);
718 817
719 LoadTestPage(); // Reload to become controlled. 818 LoadTestPage(); // Reload to become controlled.
720 819
721 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 820 ASSERT_TRUE(RunScript("isControlled()", &script_result));
722 ASSERT_EQ("true - is controlled", script_result); 821 ASSERT_EQ("true - is controlled", script_result);
723 822
724 // Fire off two push messages in sequence, only the second one of which will 823 // Fire off two push messages in sequence, only the second one of which will
725 // display a notification. The additional round-trip and I/O required by the 824 // display a notification. The additional round-trip and I/O required by the
726 // second message, which shows a notification, should give us a reasonable 825 // second message, which shows a notification, should give us a reasonable
727 // confidence that the ordering will be maintained. 826 // confidence that the ordering will be maintained.
728 827
729 std::vector<size_t> number_of_notifications_shown; 828 std::vector<size_t> number_of_notifications_shown;
730 829
731 gcm::IncomingMessage message; 830 gcm::IncomingMessage message;
732 message.sender_id = "1234567890"; 831 message.sender_id =
832 std::string(reinterpret_cast<const char*>(kApplicationServerKey));
733 message.decrypted = true; 833 message.decrypted = true;
734 834
735 { 835 {
736 base::RunLoop run_loop; 836 base::RunLoop run_loop;
737 push_service()->SetMessageCallbackForTesting(base::Bind( 837 push_service()->SetMessageCallbackForTesting(base::Bind(
738 &PushMessagingBrowserTest::OnDeliveryFinished, base::Unretained(this), 838 &PushMessagingBrowserTest::OnDeliveryFinished, base::Unretained(this),
739 &number_of_notifications_shown, 839 &number_of_notifications_shown,
740 base::BarrierClosure(2 /* num_closures */, run_loop.QuitClosure()))); 840 base::BarrierClosure(2 /* num_closures */, run_loop.QuitClosure())));
741 841
742 message.raw_data = "testdata"; 842 message.raw_data = "testdata";
(...skipping 14 matching lines...) Expand all
757 PushEventNotificationWithoutEventWaitUntil) { 857 PushEventNotificationWithoutEventWaitUntil) {
758 std::string script_result; 858 std::string script_result;
759 content::WebContents* web_contents = 859 content::WebContents* web_contents =
760 GetBrowser()->tab_strip_model()->GetActiveWebContents(); 860 GetBrowser()->tab_strip_model()->GetActiveWebContents();
761 861
762 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 862 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
763 863
764 PushMessagingAppIdentifier app_identifier = 864 PushMessagingAppIdentifier app_identifier =
765 GetAppIdentifierForServiceWorkerRegistration(0LL); 865 GetAppIdentifierForServiceWorkerRegistration(0LL);
766 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id()); 866 EXPECT_EQ(app_identifier.app_id(), gcm_service()->last_registered_app_id());
767 EXPECT_EQ("1234567890", gcm_service()->last_registered_sender_ids()[0]); 867 EXPECT_EQ(reinterpret_cast<const char*>(kApplicationServerKey),
868 gcm_service()->last_registered_sender_ids()[0]);
768 869
769 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 870 ASSERT_TRUE(RunScript("isControlled()", &script_result));
770 ASSERT_EQ("false - is not controlled", script_result); 871 ASSERT_EQ("false - is not controlled", script_result);
771 872
772 LoadTestPage(); // Reload to become controlled. 873 LoadTestPage(); // Reload to become controlled.
773 874
774 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 875 ASSERT_TRUE(RunScript("isControlled()", &script_result));
775 ASSERT_EQ("true - is controlled", script_result); 876 ASSERT_EQ("true - is controlled", script_result);
776 877
777 scoped_refptr<content::MessageLoopRunner> message_loop_runner = 878 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
778 new content::MessageLoopRunner; 879 new content::MessageLoopRunner;
779 notification_manager()->SetNotificationAddedCallback( 880 notification_manager()->SetNotificationAddedCallback(
780 message_loop_runner->QuitClosure()); 881 message_loop_runner->QuitClosure());
781 882
782 gcm::IncomingMessage message; 883 gcm::IncomingMessage message;
783 message.sender_id = "1234567890"; 884 message.sender_id =
885 std::string(reinterpret_cast<const char*>(kApplicationServerKey));
784 message.raw_data = "shownotification-without-waituntil"; 886 message.raw_data = "shownotification-without-waituntil";
785 message.decrypted = true; 887 message.decrypted = true;
786 push_service()->OnMessage(app_identifier.app_id(), message); 888 push_service()->OnMessage(app_identifier.app_id(), message);
787 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); 889 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents));
788 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result); 890 EXPECT_EQ("immediate:shownotification-without-waituntil", script_result);
789 891
790 message_loop_runner->Run(); 892 message_loop_runner->Run();
791 893
792 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); 894 ASSERT_EQ(1u, notification_manager()->GetNotificationCount());
793 EXPECT_EQ("push_test_tag", 895 EXPECT_EQ("push_test_tag",
(...skipping 16 matching lines...) Expand all
810 } 912 }
811 913
812 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysGranted) { 914 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysGranted) {
813 std::string script_result; 915 std::string script_result;
814 916
815 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 917 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
816 ASSERT_EQ("ok - service worker registered", script_result); 918 ASSERT_EQ("ok - service worker registered", script_result);
817 919
818 RequestAndAcceptPermission(); 920 RequestAndAcceptPermission();
819 921
820 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); 922 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result));
821 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result); 923 EXPECT_EQ(GetEndpointForSubscriptionId("1-0"), script_result);
822 924
823 ASSERT_TRUE(RunScript("permissionState()", &script_result)); 925 ASSERT_TRUE(RunScript("permissionState()", &script_result));
824 EXPECT_EQ("permission status - granted", script_result); 926 EXPECT_EQ("permission status - granted", script_result);
825 } 927 }
826 928
827 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysDenied) { 929 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PermissionStateSaysDenied) {
828 std::string script_result; 930 std::string script_result;
829 931
830 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 932 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
831 ASSERT_EQ("ok - service worker registered", script_result); 933 ASSERT_EQ("ok - service worker registered", script_result);
832 934
833 RequestAndDenyPermission(); 935 RequestAndDenyPermission();
834 936
835 ASSERT_TRUE(RunScript("subscribePush()", &script_result)); 937 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result));
836 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied", 938 EXPECT_EQ("PermissionDeniedError - Registration failed - permission denied",
837 script_result); 939 script_result);
838 940
839 ASSERT_TRUE(RunScript("permissionState()", &script_result)); 941 ASSERT_TRUE(RunScript("permissionState()", &script_result));
840 EXPECT_EQ("permission status - denied", script_result); 942 EXPECT_EQ("permission status - denied", script_result);
841 } 943 }
842 944
843 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) { 945 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, UnsubscribeSuccess) {
844 std::string script_result; 946 std::string script_result;
845 947
846 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result)); 948 EXPECT_TRUE(RunScript("registerServiceWorker()", &script_result));
847 EXPECT_EQ("ok - service worker registered", script_result); 949 EXPECT_EQ("ok - service worker registered", script_result);
848 950
849 // Resolves true if there was a subscription. 951 // Resolves true if there was a subscription.
850 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 952 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false);
851 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); 953 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS);
852 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 954 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
853 EXPECT_EQ("unsubscribe result: true", script_result); 955 EXPECT_EQ("unsubscribe result: true", script_result);
854 956
855 // Resolves false if there was no longer a subscription. 957 // Resolves false if there was no longer a subscription.
856 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 958 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
857 EXPECT_EQ("unsubscribe result: false", script_result); 959 EXPECT_EQ("unsubscribe result: false", script_result);
858 960
859 // Doesn't reject if there was a network error (deactivates subscription 961 // Doesn't reject if there was a network error (deactivates subscription
860 // locally anyway). 962 // locally anyway).
861 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */); 963 TryToSubscribeSuccessfully("1-1" /* expected_push_subscription_id */, false);
862 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR); 964 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::NETWORK_ERROR);
863 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 965 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
864 EXPECT_EQ("unsubscribe result: true", script_result); 966 EXPECT_EQ("unsubscribe result: true", script_result);
865 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); 967 ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
866 EXPECT_EQ("false - not subscribed", script_result); 968 EXPECT_EQ("false - not subscribed", script_result);
867 969
868 // Doesn't reject if there were other push service errors (deactivates 970 // Doesn't reject if there were other push service errors (deactivates
869 // subscription locally anyway). 971 // subscription locally anyway).
870 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */); 972 TryToSubscribeSuccessfully("1-2" /* expected_push_subscription_id */, false);
871 gcm_service()->AddExpectedUnregisterResponse( 973 gcm_service()->AddExpectedUnregisterResponse(
872 gcm::GCMClient::INVALID_PARAMETER); 974 gcm::GCMClient::INVALID_PARAMETER);
873 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 975 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
874 EXPECT_EQ("unsubscribe result: true", script_result); 976 EXPECT_EQ("unsubscribe result: true", script_result);
875 977
876 // Unsubscribing (with an existing reference to a PushSubscription), after 978 // Unsubscribing (with an existing reference to a PushSubscription), after
877 // unregistering the Service Worker, just means push subscription isn't found. 979 // unregistering the Service Worker, just means push subscription isn't found.
878 TryToSubscribeSuccessfully("1-3" /* expected_push_subscription_id */); 980 TryToSubscribeSuccessfully("1-3" /* expected_push_subscription_id */, false);
879 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result)); 981 ASSERT_TRUE(RunScript("unregisterServiceWorker()", &script_result));
880 ASSERT_EQ("service worker unregistration status: true", script_result); 982 ASSERT_EQ("service worker unregistration status: true", script_result);
881 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 983 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
882 EXPECT_EQ("unsubscribe result: false", script_result); 984 EXPECT_EQ("unsubscribe result: false", script_result);
883 } 985 }
884 986
885 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 987 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
886 GlobalResetPushPermissionUnsubscribes) { 988 GlobalResetPushPermissionUnsubscribes) {
887 std::string script_result; 989 std::string script_result;
888 990
889 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 991 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */);
890 992
891 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); 993 ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
892 EXPECT_EQ("true - subscribed", script_result); 994 EXPECT_EQ("true - subscribed", script_result);
893 995
894 ASSERT_TRUE(RunScript("permissionState()", &script_result)); 996 ASSERT_TRUE(RunScript("permissionState()", &script_result));
895 EXPECT_EQ("permission status - granted", script_result); 997 EXPECT_EQ("permission status - granted", script_result);
896 998
897 scoped_refptr<content::MessageLoopRunner> message_loop_runner = 999 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
898 new content::MessageLoopRunner; 1000 new content::MessageLoopRunner;
899 push_service()->SetContentSettingChangedCallbackForTesting( 1001 push_service()->SetContentSettingChangedCallbackForTesting(
900 message_loop_runner->QuitClosure()); 1002 message_loop_runner->QuitClosure());
901 1003
902 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) 1004 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile())
903 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); 1005 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
904 1006
1007 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile())
1008 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
1009
905 message_loop_runner->Run(); 1010 message_loop_runner->Run();
906 1011
907 ASSERT_TRUE(RunScript("permissionState()", &script_result)); 1012 ASSERT_TRUE(RunScript("permissionState()", &script_result));
908 EXPECT_EQ("permission status - prompt", script_result); 1013 EXPECT_EQ("permission status - prompt", script_result);
909 1014
910 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); 1015 ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
911 EXPECT_EQ("false - not subscribed", script_result); 1016 EXPECT_EQ("false - not subscribed", script_result);
912 } 1017 }
913 1018
914 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 1019 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
(...skipping 11 matching lines...) Expand all
926 scoped_refptr<content::MessageLoopRunner> message_loop_runner = 1031 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
927 new content::MessageLoopRunner; 1032 new content::MessageLoopRunner;
928 push_service()->SetContentSettingChangedCallbackForTesting( 1033 push_service()->SetContentSettingChangedCallbackForTesting(
929 message_loop_runner->QuitClosure()); 1034 message_loop_runner->QuitClosure());
930 1035
931 GURL origin = https_server()->GetURL("/").GetOrigin(); 1036 GURL origin = https_server()->GetURL("/").GetOrigin();
932 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) 1037 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile())
933 ->SetContentSettingDefaultScope(origin, origin, 1038 ->SetContentSettingDefaultScope(origin, origin,
934 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 1039 CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
935 std::string(), CONTENT_SETTING_DEFAULT); 1040 std::string(), CONTENT_SETTING_DEFAULT);
1041 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile())
1042 ->SetContentSettingDefaultScope(origin, origin,
1043 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
1044 std::string(), CONTENT_SETTING_DEFAULT);
936 1045
937 message_loop_runner->Run(); 1046 message_loop_runner->Run();
938 1047
939 ASSERT_TRUE(RunScript("permissionState()", &script_result)); 1048 ASSERT_TRUE(RunScript("permissionState()", &script_result));
940 EXPECT_EQ("permission status - prompt", script_result); 1049 EXPECT_EQ("permission status - prompt", script_result);
941 1050
942 ASSERT_TRUE(RunScript("hasSubscription()", &script_result)); 1051 ASSERT_TRUE(RunScript("hasSubscription()", &script_result));
943 EXPECT_EQ("false - not subscribed", script_result); 1052 EXPECT_EQ("false - not subscribed", script_result);
944 } 1053 }
945 1054
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 observer.BlockUntilCompletion(); 1294 observer.BlockUntilCompletion();
1186 1295
1187 base::RunLoop run_loop; 1296 base::RunLoop run_loop;
1188 push_service()->SetContentSettingChangedCallbackForTesting( 1297 push_service()->SetContentSettingChangedCallbackForTesting(
1189 run_loop.QuitClosure()); 1298 run_loop.QuitClosure());
1190 1299
1191 // This shouldn't (asynchronously) cause a DCHECK. 1300 // This shouldn't (asynchronously) cause a DCHECK.
1192 // TODO(johnme): Get this test running on Android, which has a different 1301 // TODO(johnme): Get this test running on Android, which has a different
1193 // codepath due to sender_id being required for unsubscribing there. 1302 // codepath due to sender_id being required for unsubscribing there.
1194 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile()) 1303 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile())
1304 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
1305 HostContentSettingsMapFactory::GetForProfile(GetBrowser()->profile())
1195 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); 1306 ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
1196 1307
1197 run_loop.Run(); 1308 run_loop.Run();
1198 1309
1199 // |app_identifier| should no longer be stored in prefs. 1310 // |app_identifier| should no longer be stored in prefs.
1200 PushMessagingAppIdentifier stored_app_identifier2 = 1311 PushMessagingAppIdentifier stored_app_identifier2 =
1201 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(), 1312 PushMessagingAppIdentifier::FindByAppId(GetBrowser()->profile(),
1202 app_identifier.app_id()); 1313 app_identifier.app_id());
1203 EXPECT_TRUE(stored_app_identifier2.is_null()); 1314 EXPECT_TRUE(stored_app_identifier2.is_null());
1204 } 1315 }
1205 1316
1206 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, EncryptionKeyUniqueness) { 1317 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, EncryptionKeyUniqueness) {
1207 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); 1318 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */, false);
1208 1319
1209 std::string first_public_key; 1320 std::string first_public_key;
1210 ASSERT_TRUE(RunScript("GetP256dh()", &first_public_key)); 1321 ASSERT_TRUE(RunScript("GetP256dh()", &first_public_key));
1211 EXPECT_GE(first_public_key.size(), 32u); 1322 EXPECT_GE(first_public_key.size(), 32u);
1212 1323
1213 std::string script_result; 1324 std::string script_result;
1214 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); 1325 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS);
1215 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 1326 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
1216 EXPECT_EQ("unsubscribe result: true", script_result); 1327 EXPECT_EQ("unsubscribe result: true", script_result);
1217 1328
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 1446 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1336 1447
1337 // After dropping the last subscription background mode is still inactive. 1448 // After dropping the last subscription background mode is still inactive.
1338 std::string script_result; 1449 std::string script_result;
1339 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); 1450 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS);
1340 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 1451 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
1341 EXPECT_EQ("unsubscribe result: true", script_result); 1452 EXPECT_EQ("unsubscribe result: true", script_result);
1342 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 1453 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1343 } 1454 }
1344 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) 1455 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698