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

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

Issue 2361113002: Push API: Don't unsubscribe when finding Service Worker fails (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | content/browser/push_messaging/push_messaging_router.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 <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
11 #include "base/barrier_closure.h" 11 #include "base/barrier_closure.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "base/test/histogram_tester.h"
18 #include "build/build_config.h" 19 #include "build/build_config.h"
19 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/browsing_data/browsing_data_helper.h" 21 #include "chrome/browser/browsing_data/browsing_data_helper.h"
21 #include "chrome/browser/browsing_data/browsing_data_remover.h" 22 #include "chrome/browser/browsing_data/browsing_data_remover.h"
22 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 23 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
23 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" 24 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
24 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 25 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
25 #include "chrome/browser/engagement/site_engagement_service.h" 26 #include "chrome/browser/engagement/site_engagement_service.h"
26 #include "chrome/browser/lifetime/keep_alive_registry.h" 27 #include "chrome/browser/lifetime/keep_alive_registry.h"
27 #include "chrome/browser/lifetime/keep_alive_types.h" 28 #include "chrome/browser/lifetime/keep_alive_types.h"
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 SiteEngagementService* service = 266 SiteEngagementService* service =
266 SiteEngagementService::Get(GetBrowser()->profile()); 267 SiteEngagementService::Get(GetBrowser()->profile());
267 service->ResetScoreForURL(url, score); 268 service->ResetScoreForURL(url, score);
268 } 269 }
269 270
270 protected: 271 protected:
271 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } 272 virtual std::string GetTestURL() { return "/push_messaging/test.html"; }
272 273
273 virtual Browser* GetBrowser() const { return browser(); } 274 virtual Browser* GetBrowser() const { return browser(); }
274 275
275 protected:
276 std::unique_ptr<net::EmbeddedTestServer> https_server_;
277 gcm::FakeGCMProfileService* gcm_service_; 276 gcm::FakeGCMProfileService* gcm_service_;
278 instance_id::FakeGCMDriverForInstanceID* gcm_driver_; 277 instance_id::FakeGCMDriverForInstanceID* gcm_driver_;
278 base::HistogramTester histogram_tester_;
279
280 private:
281 std::unique_ptr<net::EmbeddedTestServer> https_server_;
279 PushMessagingServiceImpl* push_service_; 282 PushMessagingServiceImpl* push_service_;
280 283
281 #if defined(ENABLE_NOTIFICATIONS) 284 #if defined(ENABLE_NOTIFICATIONS)
282 std::unique_ptr<StubNotificationUIManager> notification_manager_; 285 std::unique_ptr<StubNotificationUIManager> notification_manager_;
283 std::unique_ptr<MessageCenterDisplayService> display_service_; 286 std::unique_ptr<MessageCenterDisplayService> display_service_;
284 #endif 287 #endif
285 288
286 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); 289 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest);
287 }; 290 };
288 291
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 730
728 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); 731 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false));
729 gcm::IncomingMessage message; 732 gcm::IncomingMessage message;
730 message.sender_id = GetTestApplicationServerKey(); 733 message.sender_id = GetTestApplicationServerKey();
731 message.raw_data = "testdata"; 734 message.raw_data = "testdata";
732 message.decrypted = true; 735 message.decrypted = true;
733 push_service()->OnMessage(app_identifier.app_id(), message); 736 push_service()->OnMessage(app_identifier.app_id(), message);
734 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true)); 737 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true));
735 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result)); 738 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result));
736 EXPECT_EQ("testdata", script_result); 739 EXPECT_EQ("testdata", script_result);
740
741 // Check that we record this case in UMA.
742 histogram_tester_.ExpectUniqueSample(
743 "PushMessaging.DeliveryStatus.FindServiceWorker",
744 0 /* SERVICE_WORKER_OK */, 1);
745 histogram_tester_.ExpectUniqueSample(
746 "PushMessaging.DeliveryStatus.ServiceWorkerEvent",
747 0 /* SERVICE_WORKER_OK */, 1);
748 histogram_tester_.ExpectUniqueSample(
749 "PushMessaging.DeliveryStatus",
750 content::PUSH_DELIVERY_STATUS_SUCCESS, 1);
737 } 751 }
738 752
739 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) { 753 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, PushEventWithoutPayload) {
740 std::string script_result; 754 std::string script_result;
741 755
742 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); 756 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully());
743 PushMessagingAppIdentifier app_identifier = 757 PushMessagingAppIdentifier app_identifier =
744 GetAppIdentifierForServiceWorkerRegistration(0LL); 758 GetAppIdentifierForServiceWorkerRegistration(0LL);
745 759
746 ASSERT_TRUE(RunScript("isControlled()", &script_result)); 760 ASSERT_TRUE(RunScript("isControlled()", &script_result));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 message.decrypted = true; 833 message.decrypted = true;
820 834
821 base::RunLoop run_loop; 835 base::RunLoop run_loop;
822 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure()); 836 push_service()->SetMessageCallbackForTesting(run_loop.QuitClosure());
823 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); 837 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false));
824 push_service()->OnMessage(app_identifier.app_id(), message); 838 push_service()->OnMessage(app_identifier.app_id(), message);
825 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true)); 839 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(true));
826 run_loop.Run(); 840 run_loop.Run();
827 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false)); 841 EXPECT_TRUE(IsRegisteredKeepAliveEqualTo(false));
828 842
843 // Check that we record this case in UMA.
844 histogram_tester_.ExpectUniqueSample(
845 "PushMessaging.DeliveryStatus.FindServiceWorker",
846 5 /* SERVICE_WORKER_ERROR_NOT_FOUND */, 1);
847 histogram_tester_.ExpectTotalCount(
848 "PushMessaging.DeliveryStatus.ServiceWorkerEvent", 0);
849 histogram_tester_.ExpectUniqueSample(
850 "PushMessaging.DeliveryStatus",
851 content::PUSH_DELIVERY_STATUS_NO_SERVICE_WORKER, 1);
852
829 // Now the push service has received a message and failed to find its service 853 // Now the push service has received a message and failed to find its service
830 // worker, it should have automatically unsubscribed app_identifier.app_id(). 854 // worker, it should have automatically unsubscribed app_identifier.app_id().
831 PushMessagingAppIdentifier app_identifier3 = 855 PushMessagingAppIdentifier app_identifier3 =
832 PushMessagingAppIdentifier::FindByServiceWorker( 856 PushMessagingAppIdentifier::FindByServiceWorker(
833 GetBrowser()->profile(), origin, 857 GetBrowser()->profile(), origin,
834 0LL /* service_worker_registration_id */); 858 0LL /* service_worker_registration_id */);
835 EXPECT_TRUE(app_identifier3.is_null()); 859 EXPECT_TRUE(app_identifier3.is_null());
836 860
837 // No push data should have been received. 861 // No push data should have been received.
838 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result)); 862 ASSERT_TRUE(RunScript("resultQueue.popImmediately()", &script_result));
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
1667 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully()); 1691 ASSERT_NO_FATAL_FAILURE(SubscribeSuccessfully());
1668 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 1692 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1669 1693
1670 // After dropping the last subscription background mode is still inactive. 1694 // After dropping the last subscription background mode is still inactive.
1671 std::string script_result; 1695 std::string script_result;
1672 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); 1696 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result));
1673 EXPECT_EQ("unsubscribe result: true", script_result); 1697 EXPECT_EQ("unsubscribe result: true", script_result);
1674 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); 1698 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive());
1675 } 1699 }
1676 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) 1700 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « no previous file | content/browser/push_messaging/push_messaging_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698