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 "chrome/browser/chromeos/power/renderer_freezer.h" | 5 #include "chrome/browser/chromeos/power/renderer_freezer.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <string> | 8 #include <string> |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | 16 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
17 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
18 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 18 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/extensions/test_extension_system.h" | 20 #include "chrome/browser/extensions/test_extension_system.h" |
21 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
22 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
23 #include "chrome/test/base/testing_profile_manager.h" | 23 #include "chrome/test/base/testing_profile_manager.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 }; | 128 }; |
129 | 129 |
130 } // namespace | 130 } // namespace |
131 | 131 |
132 class RendererFreezerTest : public testing::Test { | 132 class RendererFreezerTest : public testing::Test { |
133 public: | 133 public: |
134 RendererFreezerTest() | 134 RendererFreezerTest() |
135 : power_manager_client_(new FakePowerManagerClient()), | 135 : power_manager_client_(new FakePowerManagerClient()), |
136 test_delegate_(new TestDelegate()) { | 136 test_delegate_(new TestDelegate()) { |
137 DBusThreadManager::GetSetterForTesting()->SetPowerManagerClient( | 137 DBusThreadManager::GetSetterForTesting()->SetPowerManagerClient( |
138 scoped_ptr<PowerManagerClient>(power_manager_client_)); | 138 std::unique_ptr<PowerManagerClient>(power_manager_client_)); |
139 } | 139 } |
140 | 140 |
141 ~RendererFreezerTest() override { | 141 ~RendererFreezerTest() override { |
142 renderer_freezer_.reset(); | 142 renderer_freezer_.reset(); |
143 | 143 |
144 DBusThreadManager::Shutdown(); | 144 DBusThreadManager::Shutdown(); |
145 } | 145 } |
146 | 146 |
147 protected: | 147 protected: |
148 void Init() { | 148 void Init() { |
149 renderer_freezer_.reset(new RendererFreezer( | 149 renderer_freezer_.reset(new RendererFreezer( |
150 scoped_ptr<RendererFreezer::Delegate>(test_delegate_))); | 150 std::unique_ptr<RendererFreezer::Delegate>(test_delegate_))); |
151 } | 151 } |
152 | 152 |
153 // Owned by DBusThreadManager. | 153 // Owned by DBusThreadManager. |
154 FakePowerManagerClient* power_manager_client_; | 154 FakePowerManagerClient* power_manager_client_; |
155 | 155 |
156 // Owned by |renderer_freezer_|. | 156 // Owned by |renderer_freezer_|. |
157 TestDelegate* test_delegate_; | 157 TestDelegate* test_delegate_; |
158 scoped_ptr<RendererFreezer> renderer_freezer_; | 158 std::unique_ptr<RendererFreezer> renderer_freezer_; |
159 | 159 |
160 private: | 160 private: |
161 content::TestBrowserThreadBundle browser_thread_bundle_; | 161 content::TestBrowserThreadBundle browser_thread_bundle_; |
162 | 162 |
163 DISALLOW_COPY_AND_ASSIGN(RendererFreezerTest); | 163 DISALLOW_COPY_AND_ASSIGN(RendererFreezerTest); |
164 }; | 164 }; |
165 | 165 |
166 // Tests that the RendererFreezer freezes renderers on suspend and thaws them on | 166 // Tests that the RendererFreezer freezes renderers on suspend and thaws them on |
167 // resume. | 167 // resume. |
168 TEST_F(RendererFreezerTest, SuspendResume) { | 168 TEST_F(RendererFreezerTest, SuspendResume) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 243 |
244 base::RunLoop().RunUntilIdle(); | 244 base::RunLoop().RunUntilIdle(); |
245 | 245 |
246 profile_manager_.reset(); | 246 profile_manager_.reset(); |
247 | 247 |
248 RendererFreezerTest::TearDown(); | 248 RendererFreezerTest::TearDown(); |
249 } | 249 } |
250 | 250 |
251 protected: | 251 protected: |
252 void CreateRenderProcessForExtension(extensions::Extension* extension) { | 252 void CreateRenderProcessForExtension(extensions::Extension* extension) { |
253 scoped_ptr<content::MockRenderProcessHostFactory> rph_factory( | 253 std::unique_ptr<content::MockRenderProcessHostFactory> rph_factory( |
254 new content::MockRenderProcessHostFactory()); | 254 new content::MockRenderProcessHostFactory()); |
255 scoped_refptr<content::SiteInstance> site_instance( | 255 scoped_refptr<content::SiteInstance> site_instance( |
256 extensions::ProcessManager::Get(profile_)->GetSiteInstanceForURL( | 256 extensions::ProcessManager::Get(profile_)->GetSiteInstanceForURL( |
257 extensions::BackgroundInfo::GetBackgroundURL(extension))); | 257 extensions::BackgroundInfo::GetBackgroundURL(extension))); |
258 scoped_ptr<content::RenderProcessHost> rph( | 258 std::unique_ptr<content::RenderProcessHost> rph( |
259 rph_factory->CreateRenderProcessHost(profile_, site_instance.get())); | 259 rph_factory->CreateRenderProcessHost(profile_, site_instance.get())); |
260 | 260 |
261 // Fake that the RenderProcessHost is hosting the gcm app. | 261 // Fake that the RenderProcessHost is hosting the gcm app. |
262 extensions::ProcessMap::Get(profile_) | 262 extensions::ProcessMap::Get(profile_) |
263 ->Insert(extension->id(), rph->GetID(), site_instance->GetId()); | 263 ->Insert(extension->id(), rph->GetID(), site_instance->GetId()); |
264 | 264 |
265 // Send the notification that the RenderProcessHost has been created. | 265 // Send the notification that the RenderProcessHost has been created. |
266 content::NotificationService::current()->Notify( | 266 content::NotificationService::current()->Notify( |
267 content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 267 content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
268 content::Source<content::RenderProcessHost>(rph.get()), | 268 content::Source<content::RenderProcessHost>(rph.get()), |
269 content::NotificationService::NoDetails()); | 269 content::NotificationService::NoDetails()); |
270 } | 270 } |
271 | 271 |
272 // Owned by |profile_manager_|. | 272 // Owned by |profile_manager_|. |
273 TestingProfile* profile_; | 273 TestingProfile* profile_; |
274 scoped_ptr<TestingProfileManager> profile_manager_; | 274 std::unique_ptr<TestingProfileManager> profile_manager_; |
275 | 275 |
276 private: | 276 private: |
277 // Chrome OS needs extra services to run in the following order. | 277 // Chrome OS needs extra services to run in the following order. |
278 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 278 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
279 chromeos::ScopedTestCrosSettings test_cros_settings_; | 279 chromeos::ScopedTestCrosSettings test_cros_settings_; |
280 chromeos::ScopedTestUserManager test_user_manager_; | 280 chromeos::ScopedTestUserManager test_user_manager_; |
281 | 281 |
282 DISALLOW_COPY_AND_ASSIGN(RendererFreezerTestWithExtensions); | 282 DISALLOW_COPY_AND_ASSIGN(RendererFreezerTestWithExtensions); |
283 }; | 283 }; |
284 | 284 |
285 // Tests that the RendererFreezer freezes renderers that are not hosting | 285 // Tests that the RendererFreezer freezes renderers that are not hosting |
286 // GCM extensions. | 286 // GCM extensions. |
287 TEST_F(RendererFreezerTestWithExtensions, FreezesNonExtensionRenderers) { | 287 TEST_F(RendererFreezerTestWithExtensions, FreezesNonExtensionRenderers) { |
288 Init(); | 288 Init(); |
289 | 289 |
290 // Create the mock RenderProcessHost. | 290 // Create the mock RenderProcessHost. |
291 scoped_ptr<content::MockRenderProcessHostFactory> rph_factory( | 291 std::unique_ptr<content::MockRenderProcessHostFactory> rph_factory( |
292 new content::MockRenderProcessHostFactory()); | 292 new content::MockRenderProcessHostFactory()); |
293 scoped_refptr<content::SiteInstance> site_instance( | 293 scoped_refptr<content::SiteInstance> site_instance( |
294 content::SiteInstance::Create(profile_)); | 294 content::SiteInstance::Create(profile_)); |
295 scoped_ptr<content::RenderProcessHost> rph( | 295 std::unique_ptr<content::RenderProcessHost> rph( |
296 rph_factory->CreateRenderProcessHost(profile_, site_instance.get())); | 296 rph_factory->CreateRenderProcessHost(profile_, site_instance.get())); |
297 | 297 |
298 // Send the notification that the RenderProcessHost has been created. | 298 // Send the notification that the RenderProcessHost has been created. |
299 content::NotificationService::current()->Notify( | 299 content::NotificationService::current()->Notify( |
300 content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 300 content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
301 content::Source<content::RenderProcessHost>(rph.get()), | 301 content::Source<content::RenderProcessHost>(rph.get()), |
302 content::NotificationService::NoDetails()); | 302 content::NotificationService::NoDetails()); |
303 | 303 |
304 EXPECT_EQ(kSetShouldFreezeRenderer, test_delegate_->GetActions()); | 304 EXPECT_EQ(kSetShouldFreezeRenderer, test_delegate_->GetActions()); |
305 } | 305 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 // Now install it and give it a renderer. | 368 // Now install it and give it a renderer. |
369 extensions::ExtensionSystem::Get(profile_) | 369 extensions::ExtensionSystem::Get(profile_) |
370 ->extension_service() | 370 ->extension_service() |
371 ->AddExtension(background_app.get()); | 371 ->AddExtension(background_app.get()); |
372 CreateRenderProcessForExtension(background_app.get()); | 372 CreateRenderProcessForExtension(background_app.get()); |
373 | 373 |
374 EXPECT_EQ(kSetShouldFreezeRenderer, test_delegate_->GetActions()); | 374 EXPECT_EQ(kSetShouldFreezeRenderer, test_delegate_->GetActions()); |
375 } | 375 } |
376 | 376 |
377 } // namespace chromeos | 377 } // namespace chromeos |
OLD | NEW |