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" | 8 #include "apps/app_window_registry.h" |
| 9 #include "apps/ui/apps_client.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 11 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
11 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
13 #include "chrome/test/base/browser_with_test_window_test.h" | 14 #include "chrome/test/base/browser_with_test_window_test.h" |
14 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
15 #include "chrome/test/base/testing_profile_manager.h" | 16 #include "chrome/test/base/testing_profile_manager.h" |
16 #include "components/power/origin_power_map.h" | 17 #include "components/power/origin_power_map.h" |
17 #include "components/power/origin_power_map_factory.h" | 18 #include "components/power/origin_power_map_factory.h" |
18 #include "content/public/browser/site_instance.h" | 19 #include "content/public/browser/site_instance.h" |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 std::string error; | 279 std::string error; |
279 char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 280 char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
280 scoped_refptr<extensions::Extension> extension( | 281 scoped_refptr<extensions::Extension> extension( |
281 extensions::Extension::Create(extension_path, | 282 extensions::Extension::Create(extension_path, |
282 extensions::Manifest::INTERNAL, | 283 extensions::Manifest::INTERNAL, |
283 manifest, | 284 manifest, |
284 extensions::Extension::NO_FLAGS, | 285 extensions::Extension::NO_FLAGS, |
285 kTestAppId, | 286 kTestAppId, |
286 &error)); | 287 &error)); |
287 EXPECT_TRUE(extension.get()) << error; | 288 EXPECT_TRUE(extension.get()) << error; |
| 289 // Increment the apps count to avoid a DCHECK later. |
| 290 apps::AppsClient::Get()->IncrementKeepAliveCount(); |
288 | 291 |
289 Profile* current_profile = | 292 Profile* current_profile = |
290 profile_manager_->CreateTestingProfile("Test user"); | 293 profile_manager_->CreateTestingProfile("Test user"); |
291 GURL url("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); | 294 GURL url("chrome-extension://aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); |
292 apps::AppWindow* window = | 295 apps::AppWindow* window = |
293 new apps::AppWindow(current_profile, new ChromeAppDelegate(), extension); | 296 new apps::AppWindow(current_profile, new ChromeAppDelegate(), extension); |
294 scoped_ptr<content::WebContents> web_contents( | 297 content::WebContents* web_contents( |
295 content::WebContents::Create(content::WebContents::CreateParams( | 298 content::WebContents::Create(content::WebContents::CreateParams( |
296 current_profile, | 299 current_profile, |
297 content::SiteInstance::CreateForURL(current_profile, url)))); | 300 content::SiteInstance::CreateForURL(current_profile, url)))); |
298 window->SetAppWindowContentsForTesting(scoped_ptr<apps::AppWindowContents>( | 301 window->SetAppWindowContentsForTesting(scoped_ptr<apps::AppWindowContents>( |
299 new TestAppWindowContents(web_contents.get()))); | 302 new TestAppWindowContents(web_contents))); |
300 apps::AppWindowRegistry* app_registry = | 303 apps::AppWindowRegistry* app_registry = |
301 apps::AppWindowRegistry::Get(current_profile); | 304 apps::AppWindowRegistry::Get(current_profile); |
302 app_registry->AddAppWindow(window); | 305 app_registry->AddAppWindow(window); |
303 | 306 |
304 collector->set_cpu_usage_callback_for_testing( | 307 collector->set_cpu_usage_callback_for_testing( |
305 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, | 308 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, |
306 base::Unretained(this), | 309 base::Unretained(this), |
307 5)); | 310 5)); |
308 collector->UpdatePowerConsumptionForTesting(); | 311 collector->UpdatePowerConsumptionForTesting(); |
309 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); | 312 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); |
310 | 313 |
311 app_registry->RemoveAppWindow(window); | 314 // Clear the AppWindowContents before trying to close. |
| 315 window->SetAppWindowContentsForTesting(scoped_ptr<apps::AppWindowContents>()); |
| 316 window->OnNativeClose(); |
312 collector->UpdatePowerConsumptionForTesting(); | 317 collector->UpdatePowerConsumptionForTesting(); |
313 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); | 318 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); |
314 } | 319 } |
OLD | NEW |