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

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

Issue 2411733002: Check the format of an applicationServerKey when used to register a push subscription. (Closed)
Patch Set: Removed unneeded file Created 4 years, 2 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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 ASSERT_EQ("ok - service worker registered", script_result); 440 ASSERT_EQ("ok - service worker registered", script_result);
441 441
442 GetPermissionRequestManager()->set_auto_response_for_test( 442 GetPermissionRequestManager()->set_auto_response_for_test(
443 PermissionRequestManager::ACCEPT_ALL); 443 PermissionRequestManager::ACCEPT_ALL);
444 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result)); 444 ASSERT_TRUE(RunScript("documentSubscribePush()", &script_result));
445 // Both of these methods EXPECT that they succeed. 445 // Both of these methods EXPECT that they succeed.
446 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result)); 446 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result));
447 GetAppIdentifierForServiceWorkerRegistration(0LL); 447 GetAppIdentifierForServiceWorkerRegistration(0LL);
448 } 448 }
449 449
450 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureBadKey) { 450 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
451 SubscribeSuccessValidSenderID) {
451 std::string script_result; 452 std::string script_result;
452 453
453 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result)); 454 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
455 ASSERT_EQ("ok - service worker registered", script_result);
456
457 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
458
459 ASSERT_TRUE(
460 RunScript("documentSubscribePushValidSenderId()", &script_result));
461
462 // Subscriptions with a sender ID instead of a VAPID key should be given the
463 // non-VAPID endpoint, even if the sender ID was passed to the subscribe
464 // call.
465 ASSERT_NO_FATAL_FAILURE(EndpointToToken(script_result, false));
466 }
467
468 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureLongKey) {
Peter Beverloo 2016/10/11 15:10:41 The following three tests should be layout tests.
harkness 2016/10/14 13:53:55 Done.
469 std::string script_result;
470
471 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
472 ASSERT_EQ("ok - service worker registered", script_result);
473
474 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
475
476 ASSERT_TRUE(RunScript("documentSubscribePushLongKey()", &script_result));
477 EXPECT_EQ(
478 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': "
479 "The provided applicationServerKey is not valid.",
480 script_result);
481 }
482
483 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, SubscribeFailureShortKey) {
484 std::string script_result;
485
486 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
487 ASSERT_EQ("ok - service worker registered", script_result);
488
489 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
490
491 ASSERT_TRUE(RunScript("documentSubscribePushShortKey()", &script_result));
492 EXPECT_EQ(
493 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': "
494 "The provided applicationServerKey is not valid.",
495 script_result);
496 }
497
498 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
499 SubscribeFailureNonNumericKey) {
500 std::string script_result;
501
502 ASSERT_TRUE(RunScript("registerServiceWorker()", &script_result));
454 ASSERT_EQ("ok - service worker registered", script_result); 503 ASSERT_EQ("ok - service worker registered", script_result);
455 504
456 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission()); 505 ASSERT_NO_FATAL_FAILURE(RequestAndAcceptPermission());
457 506
458 ASSERT_TRUE(RunScript("documentSubscribePushBadKey()", &script_result)); 507 ASSERT_TRUE(
508 RunScript("documentSubscribePushNonNumericKey()", &script_result));
459 EXPECT_EQ( 509 EXPECT_EQ(
460 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': " 510 "InvalidAccessError - Failed to execute 'subscribe' on 'PushManager': "
461 "The provided applicationServerKey is not valid.", 511 "The provided applicationServerKey is not valid.",
462 script_result); 512 script_result);
463 } 513 }
464 514
465 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, 515 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest,
466 SubscribeFailureNotificationsBlocked) { 516 SubscribeFailureNotificationsBlocked) {
467 std::string script_result; 517 std::string script_result;
468 518
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1884 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); 1934 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully());
1885 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 1935 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1886 1936
1887 // After dropping the last subscription background mode is still inactive. 1937 // After dropping the last subscription background mode is still inactive.
1888 std::string script_result; 1938 std::string script_result;
1889 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 1939 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
1890 EXPECT_EQ("unsubscribe result: true", script_result); 1940 EXPECT_EQ("unsubscribe result: true", script_result);
1891 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 1941 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1892 } 1942 }
1893 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) 1943 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698