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/power/process_power_collector.h" | 5 #include "chrome/browser/power/process_power_collector.h" |
6 | 6 |
7 #include "apps/app_window_contents.h" | 7 #include "apps/app_window_contents.h" |
8 #include "apps/app_window_registry.h" | |
9 #include "apps/ui/apps_client.h" | |
10 #include "chrome/browser/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 9 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
12 #include "chrome/browser/ui/browser_commands.h" | 10 #include "chrome/browser/ui/browser_commands.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/test/base/browser_with_test_window_test.h" | 12 #include "chrome/test/base/browser_with_test_window_test.h" |
15 #include "chrome/test/base/testing_browser_process.h" | 13 #include "chrome/test/base/testing_browser_process.h" |
16 #include "chrome/test/base/testing_profile_manager.h" | 14 #include "chrome/test/base/testing_profile_manager.h" |
17 #include "components/power/origin_power_map.h" | 15 #include "components/power/origin_power_map.h" |
18 #include "components/power/origin_power_map_factory.h" | 16 #include "components/power/origin_power_map_factory.h" |
19 #include "content/public/browser/site_instance.h" | 17 #include "content/public/browser/site_instance.h" |
20 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
21 #include "content/public/test/mock_render_process_host.h" | 19 #include "content/public/test/mock_render_process_host.h" |
| 20 #include "extensions/browser/app_window/app_window_registry.h" |
| 21 #include "extensions/browser/app_window/apps_client.h" |
22 #include "extensions/browser/app_window/native_app_window.h" | 22 #include "extensions/browser/app_window/native_app_window.h" |
23 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
26 | 26 |
27 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
28 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 28 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
29 #endif | 29 #endif |
30 | 30 |
31 using power::OriginPowerMap; | 31 using power::OriginPowerMap; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 process_id) | 81 process_id) |
82 #endif | 82 #endif |
83 ); | 83 ); |
84 return proc_handle.Pass(); | 84 return proc_handle.Pass(); |
85 } | 85 } |
86 | 86 |
87 scoped_ptr<ProcessPowerCollector> collector; | 87 scoped_ptr<ProcessPowerCollector> collector; |
88 scoped_ptr<TestingProfileManager> profile_manager_; | 88 scoped_ptr<TestingProfileManager> profile_manager_; |
89 }; | 89 }; |
90 | 90 |
91 class TestAppWindowContents : public apps::AppWindowContents { | 91 class TestAppWindowContents : public extensions::AppWindowContents { |
92 public: | 92 public: |
93 explicit TestAppWindowContents(content::WebContents* web_contents) | 93 explicit TestAppWindowContents(content::WebContents* web_contents) |
94 : web_contents_(web_contents) {} | 94 : web_contents_(web_contents) {} |
95 | 95 |
96 // apps:AppWindowContents | 96 // apps:AppWindowContents |
97 virtual void Initialize(content::BrowserContext* context, | 97 virtual void Initialize(content::BrowserContext* context, |
98 const GURL& url) OVERRIDE {} | 98 const GURL& url) OVERRIDE {} |
99 virtual void LoadContents(int32 creator_process_id) OVERRIDE {} | 99 virtual void LoadContents(int32 creator_process_id) OVERRIDE {} |
100 virtual void NativeWindowChanged( | 100 virtual void NativeWindowChanged( |
101 extensions::NativeAppWindow* native_app_window) OVERRIDE {} | 101 extensions::NativeAppWindow* native_app_window) OVERRIDE {} |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 280 char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
281 scoped_refptr<extensions::Extension> extension( | 281 scoped_refptr<extensions::Extension> extension( |
282 extensions::Extension::Create(extension_path, | 282 extensions::Extension::Create(extension_path, |
283 extensions::Manifest::INTERNAL, | 283 extensions::Manifest::INTERNAL, |
284 manifest, | 284 manifest, |
285 extensions::Extension::NO_FLAGS, | 285 extensions::Extension::NO_FLAGS, |
286 kTestAppId, | 286 kTestAppId, |
287 &error)); | 287 &error)); |
288 EXPECT_TRUE(extension.get()) << error; | 288 EXPECT_TRUE(extension.get()) << error; |
289 // Increment the apps count to avoid a DCHECK later. | 289 // Increment the apps count to avoid a DCHECK later. |
290 apps::AppsClient::Get()->IncrementKeepAliveCount(); | 290 extensions::AppsClient::Get()->IncrementKeepAliveCount(); |
291 | 291 |
292 Profile* current_profile = | 292 Profile* current_profile = |
293 profile_manager_->CreateTestingProfile("Test user"); | 293 profile_manager_->CreateTestingProfile("Test user"); |
294 GURL url("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | 294 GURL url("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
295 apps::AppWindow* window = new apps::AppWindow( | 295 extensions::AppWindow* window = new extensions::AppWindow( |
296 current_profile, new ChromeAppDelegate(), extension.get()); | 296 current_profile, new ChromeAppDelegate(), extension.get()); |
297 content::WebContents* web_contents( | 297 content::WebContents* web_contents( |
298 content::WebContents::Create(content::WebContents::CreateParams( | 298 content::WebContents::Create(content::WebContents::CreateParams( |
299 current_profile, | 299 current_profile, |
300 content::SiteInstance::CreateForURL(current_profile, url)))); | 300 content::SiteInstance::CreateForURL(current_profile, url)))); |
301 window->SetAppWindowContentsForTesting(scoped_ptr<apps::AppWindowContents>( | 301 window->SetAppWindowContentsForTesting( |
302 new TestAppWindowContents(web_contents))); | 302 scoped_ptr<extensions::AppWindowContents>( |
303 apps::AppWindowRegistry* app_registry = | 303 new TestAppWindowContents(web_contents))); |
304 apps::AppWindowRegistry::Get(current_profile); | 304 extensions::AppWindowRegistry* app_registry = |
| 305 extensions::AppWindowRegistry::Get(current_profile); |
305 app_registry->AddAppWindow(window); | 306 app_registry->AddAppWindow(window); |
306 | 307 |
307 collector->set_cpu_usage_callback_for_testing( | 308 collector->set_cpu_usage_callback_for_testing( |
308 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, | 309 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, |
309 base::Unretained(this), | 310 base::Unretained(this), |
310 5)); | 311 5)); |
311 collector->UpdatePowerConsumptionForTesting(); | 312 collector->UpdatePowerConsumptionForTesting(); |
312 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); | 313 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); |
313 | 314 |
314 // Clear the AppWindowContents before trying to close. | 315 // Clear the AppWindowContents before trying to close. |
315 window->SetAppWindowContentsForTesting(scoped_ptr<apps::AppWindowContents>()); | 316 window->SetAppWindowContentsForTesting( |
| 317 scoped_ptr<extensions::AppWindowContents>()); |
316 window->OnNativeClose(); | 318 window->OnNativeClose(); |
317 collector->UpdatePowerConsumptionForTesting(); | 319 collector->UpdatePowerConsumptionForTesting(); |
318 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); | 320 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); |
319 } | 321 } |
OLD | NEW |