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 "build/build_config.h" | 18 #include "build/build_config.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 20 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
21 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 21 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
22 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 22 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
23 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 23 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
24 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 24 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
25 #include "chrome/browser/notifications/message_center_display_service.h" | |
25 #include "chrome/browser/notifications/notification_test_util.h" | 26 #include "chrome/browser/notifications/notification_test_util.h" |
26 #include "chrome/browser/notifications/platform_notification_service_impl.h" | 27 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" | 29 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" |
29 #include "chrome/browser/push_messaging/push_messaging_constants.h" | 30 #include "chrome/browser/push_messaging/push_messaging_constants.h" |
30 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" | 31 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
31 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 32 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
32 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 33 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
33 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 34 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
34 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 108 |
108 // InProcessBrowserTest: | 109 // InProcessBrowserTest: |
109 void SetUp() override { | 110 void SetUp() override { |
110 https_server_.reset( | 111 https_server_.reset( |
111 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); | 112 new net::EmbeddedTestServer(net::EmbeddedTestServer::TYPE_HTTPS)); |
112 https_server_->ServeFilesFromSourceDirectory("chrome/test/data"); | 113 https_server_->ServeFilesFromSourceDirectory("chrome/test/data"); |
113 ASSERT_TRUE(https_server_->Start()); | 114 ASSERT_TRUE(https_server_->Start()); |
114 | 115 |
115 #if defined(ENABLE_NOTIFICATIONS) | 116 #if defined(ENABLE_NOTIFICATIONS) |
116 notification_manager_.reset(new StubNotificationUIManager); | 117 notification_manager_.reset(new StubNotificationUIManager); |
117 notification_service()->SetNotificationUIManagerForTesting( | |
118 notification_manager()); | |
119 #endif | 118 #endif |
120 | 119 |
121 InProcessBrowserTest::SetUp(); | 120 InProcessBrowserTest::SetUp(); |
122 } | 121 } |
123 | 122 |
124 void SetUpCommandLine(base::CommandLine* command_line) override { | 123 void SetUpCommandLine(base::CommandLine* command_line) override { |
125 // Enable experimental features for subscription restrictions. | 124 // Enable experimental features for subscription restrictions. |
126 command_line->AppendSwitch( | 125 command_line->AppendSwitch( |
127 switches::kEnableExperimentalWebPlatformFeatures); | 126 switches::kEnableExperimentalWebPlatformFeatures); |
128 InProcessBrowserTest::SetUpCommandLine(command_line); | 127 InProcessBrowserTest::SetUpCommandLine(command_line); |
129 } | 128 } |
130 | 129 |
131 // InProcessBrowserTest: | 130 // InProcessBrowserTest: |
132 void SetUpOnMainThread() override { | 131 void SetUpOnMainThread() override { |
133 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( | 132 gcm_service_ = static_cast<gcm::FakeGCMProfileService*>( |
134 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 133 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
135 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); | 134 GetBrowser()->profile(), &gcm::FakeGCMProfileService::Build)); |
136 gcm_service_->set_collect(true); | 135 gcm_service_->set_collect(true); |
137 push_service_ = | 136 push_service_ = |
138 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile()); | 137 PushMessagingServiceFactory::GetForProfile(GetBrowser()->profile()); |
138 #if defined(ENABLE_NOTIFICATIONS) | |
139 display_service_.reset(new MessageCenterDisplayService( | |
140 GetBrowser()->profile(), notification_manager_.get())); | |
141 notification_service()->SetNotificationDisplayServiceForTesting( | |
142 display_service_.get()); | |
143 #endif | |
139 | 144 |
140 LoadTestPage(); | 145 LoadTestPage(); |
141 | |
142 InProcessBrowserTest::SetUpOnMainThread(); | 146 InProcessBrowserTest::SetUpOnMainThread(); |
143 } | 147 } |
144 | 148 |
145 void RestartPushService() { | 149 void RestartPushService() { |
146 Profile* profile = GetBrowser()->profile(); | 150 Profile* profile = GetBrowser()->profile(); |
147 PushMessagingServiceFactory::GetInstance()->SetTestingFactory(profile, | 151 PushMessagingServiceFactory::GetInstance()->SetTestingFactory(profile, |
148 nullptr); | 152 nullptr); |
149 ASSERT_EQ(nullptr, PushMessagingServiceFactory::GetForProfile(profile)); | 153 ASSERT_EQ(nullptr, PushMessagingServiceFactory::GetForProfile(profile)); |
150 PushMessagingServiceFactory::GetInstance()->RestoreFactoryForTests(profile); | 154 PushMessagingServiceFactory::GetInstance()->RestoreFactoryForTests(profile); |
151 PushMessagingServiceImpl::InitializeForProfile(profile); | 155 PushMessagingServiceImpl::InitializeForProfile(profile); |
152 push_service_ = PushMessagingServiceFactory::GetForProfile(profile); | 156 push_service_ = PushMessagingServiceFactory::GetForProfile(profile); |
153 } | 157 } |
154 | 158 |
155 // InProcessBrowserTest: | 159 // InProcessBrowserTest: |
156 void TearDown() override { | 160 void TearDown() override { |
157 #if defined(ENABLE_NOTIFICATIONS) | 161 #if defined(ENABLE_NOTIFICATIONS) |
158 notification_service()->SetNotificationUIManagerForTesting(nullptr); | 162 notification_service()->SetNotificationDisplayServiceForTesting(nullptr); |
159 #endif | 163 #endif |
160 | 164 |
161 InProcessBrowserTest::TearDown(); | 165 InProcessBrowserTest::TearDown(); |
162 } | 166 } |
163 | 167 |
164 void LoadTestPage(const std::string& path) { | 168 void LoadTestPage(const std::string& path) { |
165 ui_test_utils::NavigateToURL(GetBrowser(), https_server_->GetURL(path)); | 169 ui_test_utils::NavigateToURL(GetBrowser(), https_server_->GetURL(path)); |
166 } | 170 } |
167 | 171 |
168 void LoadTestPage() { LoadTestPage(GetTestURL()); } | 172 void LoadTestPage() { LoadTestPage(GetTestURL()); } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 protected: | 242 protected: |
239 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } | 243 virtual std::string GetTestURL() { return "/push_messaging/test.html"; } |
240 | 244 |
241 virtual Browser* GetBrowser() const { return browser(); } | 245 virtual Browser* GetBrowser() const { return browser(); } |
242 | 246 |
243 private: | 247 private: |
244 std::unique_ptr<net::EmbeddedTestServer> https_server_; | 248 std::unique_ptr<net::EmbeddedTestServer> https_server_; |
245 gcm::FakeGCMProfileService* gcm_service_; | 249 gcm::FakeGCMProfileService* gcm_service_; |
246 PushMessagingServiceImpl* push_service_; | 250 PushMessagingServiceImpl* push_service_; |
247 | 251 |
248 #if defined(ENABLE_NOTIFICATIONS) | 252 #if defined(ENABLE_NOTIFICATIONS) |
Peter Beverloo
2016/04/20 17:34:08
On a tangent, now that iOS doesn't use //chrome an
Miguel Garcia
2016/04/21 14:32:10
Acknowledged.
| |
249 std::unique_ptr<StubNotificationUIManager> notification_manager_; | 253 std::unique_ptr<StubNotificationUIManager> notification_manager_; |
254 std::unique_ptr<MessageCenterDisplayService> display_service_; | |
250 #endif | 255 #endif |
251 | 256 |
252 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); | 257 DISALLOW_COPY_AND_ASSIGN(PushMessagingBrowserTest); |
253 }; | 258 }; |
254 | 259 |
255 class PushMessagingBrowserTestEmptySubscriptionOptions | 260 class PushMessagingBrowserTestEmptySubscriptionOptions |
256 : public PushMessagingBrowserTest { | 261 : public PushMessagingBrowserTest { |
257 std::string GetTestURL() override { | 262 std::string GetTestURL() override { |
258 return "/push_messaging/test_no_subscription_options.html"; | 263 return "/push_messaging/test_no_subscription_options.html"; |
259 } | 264 } |
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1450 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1455 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1451 | 1456 |
1452 // After dropping the last subscription background mode is still inactive. | 1457 // After dropping the last subscription background mode is still inactive. |
1453 std::string script_result; | 1458 std::string script_result; |
1454 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); | 1459 gcm_service()->AddExpectedUnregisterResponse(gcm::GCMClient::SUCCESS); |
1455 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); | 1460 ASSERT_TRUE(RunScript("unsubscribePush()", &script_result)); |
1456 EXPECT_EQ("unsubscribe result: true", script_result); | 1461 EXPECT_EQ("unsubscribe result: true", script_result); |
1457 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); | 1462 ASSERT_FALSE(background_mode_manager->IsBackgroundModeActive()); |
1458 } | 1463 } |
1459 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) | 1464 #endif // BUILDFLAG(ENABLE_BACKGROUND) && !defined(OS_CHROMEOS) |
OLD | NEW |