OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <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" | |
19 #include "build/build_config.h" | 18 #include "build/build_config.h" |
20 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 20 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
22 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 21 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
23 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 22 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
24 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 23 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
25 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 24 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
26 #include "chrome/browser/engagement/site_engagement_service.h" | 25 #include "chrome/browser/engagement/site_engagement_service.h" |
27 #include "chrome/browser/lifetime/keep_alive_registry.h" | 26 #include "chrome/browser/lifetime/keep_alive_registry.h" |
28 #include "chrome/browser/lifetime/keep_alive_types.h" | 27 #include "chrome/browser/lifetime/keep_alive_types.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 SiteEngagementService* service = | 263 SiteEngagementService* service = |
265 SiteEngagementService::Get(GetBrowser()->profile()); | 264 SiteEngagementService::Get(GetBrowser()->profile()); |
266 service->ResetScoreForURL(url, score); | 265 service->ResetScoreForURL(url, score); |
267 } | 266 } |
268 | 267 |
269 protected: | 268 protected: |
270 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } | 269 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } |
271 | 270 |
272 virtual Browser* GetBrowser() const { return browser(); } | 271 virtual Browser* GetBrowser() const { return browser(); } |
273 | 272 |
274 base::HistogramTester* GetHistogramTester() { return &histogram_tester_; } | |
275 | |
276 private: | 273 private: |
277 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 274 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
278 gcm::FakeGCMProfileService* gcm_service_; | 275 gcm::FakeGCMProfileService* gcm_service_; |
279 PushMessagingServiceImpl* push_service_; | 276 PushMessagingServiceImpl* push_service_; |
280 base::HistogramTester histogram_tester_; | |
281 | 277 |
282 #if defined(ENABLE_NOTIFICATIONS) | 278 #if defined(ENABLE_NOTIFICATIONS) |
283 std::unique_ptr<StubNotificationUIManager> notification_manager_; | 279 std::unique_ptr<StubNotificationUIManager> notification_manager_; |
284 std::unique_ptr<MessageCenterDisplayService> display_service_; | 280 std::unique_ptr<MessageCenterDisplayService> display_service_; |
285 #endif | 281 #endif |
286 | 282 |
287 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); | 283 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); |
288 }; | 284 }; |
289 | 285 |
290 class PushMessagingBrowserTestEmptySubscriptionOptions | 286 class PushMessagingBrowserTestEmptySubscriptionOptions |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); | 836 ASSERT_TRUE(RunScript("resultQueue.pop()", &script_result, web_contents)); |
841 EXPECT_EQ("shownotification", script_result); | 837 EXPECT_EQ("shownotification", script_result); |
842 | 838 |
843 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); | 839 ASSERT_EQ(1u, notification_manager()->GetNotificationCount()); |
844 { | 840 { |
845 const Notification& first_notification = | 841 const Notification& first_notification = |
846 notification_manager()->GetNotificationAt(0); | 842 notification_manager()->GetNotificationAt(0); |
847 | 843 |
848 EXPECT_NE(kPushMessagingForcedNotificationTag, first_notification.tag()); | 844 EXPECT_NE(kPushMessagingForcedNotificationTag, first_notification.tag()); |
849 } | 845 } |
850 | |
851 // Check that the UMA has been recorded correctly. | |
852 // There should be a total of 7 budget samples, spread across 3 buckets. The | |
853 // first four notifications (before any budget is consumed) have budget of 4, | |
854 // which is the starting SES. The next one has 2 (one hidden notification) and | |
855 // the final two have 0 (two hidden notifications. | |
856 std::vector<base::Bucket> buckets = | |
857 GetHistogramTester()->GetAllSamples("PushMessaging.BackgroundBudget"); | |
858 ASSERT_EQ(3.0, buckets.size()); | |
859 // First bucket is for 0 budget, which has 2 samples. | |
860 EXPECT_EQ(0, buckets[0].min); | |
861 EXPECT_EQ(2, buckets[0].count); | |
862 // Second bucket is for 2 budget, which has 1 sample. | |
863 EXPECT_EQ(2, buckets[1].min); | |
864 EXPECT_EQ(1, buckets[1].count); | |
865 // Final bucket is for 4 budget, which has 4 samples. | |
866 EXPECT_EQ(4, buckets[2].min); | |
867 EXPECT_EQ(4, buckets[2].count); | |
868 | |
869 std::vector<base::Bucket> no_budget_buckets = | |
870 GetHistogramTester()->GetAllSamples("PushMessaging.SESForNoBudgetOrigin"); | |
871 ASSERT_EQ(1.0, no_budget_buckets.size()); | |
872 EXPECT_EQ(4, no_budget_buckets[0].min); | |
873 EXPECT_EQ(2, no_budget_buckets[0].count); | |
874 | |
875 std::vector<base::Bucket> low_budget_buckets = | |
876 GetHistogramTester()->GetAllSamples( | |
877 "PushMessaging.SESForLowBudgetOrigin"); | |
878 ASSERT_EQ(1.0, low_budget_buckets.size()); | |
879 EXPECT_EQ(4, low_budget_buckets[0].min); | |
880 EXPECT_EQ(1, low_budget_buckets[0].count); | |
881 } | 846 } |
882 | 847 |
883 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, | 848 IN_PROC_BROWSER_TEST_F(PushMessagingBrowserTest, |
884 PushEventAllowSilentPushCommandLineFlag) { | 849 PushEventAllowSilentPushCommandLineFlag) { |
885 std::string script_result; | 850 std::string script_result; |
886 | 851 |
887 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); | 852 TryToSubscribeSuccessfully("1-0" /* expected_push_subscription_id */); |
888 | 853 |
889 PushMessagingAppIdentifier app_identifier = | 854 PushMessagingAppIdentifier app_identifier = |
890 GetAppIdentifierForServiceWorkerRegistration(0LL); | 855 GetAppIdentifierForServiceWorkerRegistration(0LL); |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1540 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1576 | 1541 |
1577 // After dropping the last subscription background mode is still inactive. | 1542 // After dropping the last subscription background mode is still inactive. |
1578 std::string script_result; | 1543 std::string script_result; |
1579 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1544 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
1580 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1545 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1581 EXPECT_EQ("unsubscribe result: true", script_result); | 1546 EXPECT_EQ("unsubscribe result: true", script_result); |
1582 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1547 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1583 } | 1548 } |
1584 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1549 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
OLD | NEW |