Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/browser/power/process_power_collector_unittest.cc

Issue 1336823003: Move chrome::HostDesktopType to ui::HostDesktopType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@base_session_service_delegate_impl
Patch Set: Fix build on Mac and CrOS Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/apps/scoped_keep_alive.h" 7 #include "chrome/browser/apps/scoped_keep_alive.h"
8 #include "chrome/browser/profiles/profile_manager.h" 8 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/ui/apps/chrome_app_delegate.h" 9 #include "chrome/browser/ui/apps/chrome_app_delegate.h"
10 #include "chrome/browser/ui/browser_commands.h" 10 #include "chrome/browser/ui/browser_commands.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 collector->set_cpu_usage_callback_for_testing( 111 collector->set_cpu_usage_callback_for_testing(
112 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, 112 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant,
113 base::Unretained(this), 113 base::Unretained(this),
114 5)); 114 5));
115 EXPECT_DOUBLE_EQ(5, collector->UpdatePowerConsumptionForTesting()); 115 EXPECT_DOUBLE_EQ(5, collector->UpdatePowerConsumptionForTesting());
116 EXPECT_EQ(100, origin_power_map->GetPowerForOrigin(url)); 116 EXPECT_EQ(100, origin_power_map->GetPowerForOrigin(url));
117 } 117 }
118 118
119 TEST_F(BrowserProcessPowerTest, MultipleSites) { 119 TEST_F(BrowserProcessPowerTest, MultipleSites) {
120 Browser::CreateParams native_params(profile(), 120 Browser::CreateParams native_params(profile(), ui::HOST_DESKTOP_TYPE_NATIVE);
121 chrome::HOST_DESKTOP_TYPE_NATIVE);
122 GURL url1("http://www.google.com"); 121 GURL url1("http://www.google.com");
123 GURL url2("http://www.example.com"); 122 GURL url2("http://www.example.com");
124 GURL url3("https://www.google.com"); 123 GURL url3("https://www.google.com");
125 scoped_ptr<Browser> browser2( 124 scoped_ptr<Browser> browser2(
126 chrome::CreateBrowserWithTestWindowForParams(&native_params)); 125 chrome::CreateBrowserWithTestWindowForParams(&native_params));
127 scoped_ptr<Browser> browser3( 126 scoped_ptr<Browser> browser3(
128 chrome::CreateBrowserWithTestWindowForParams(&native_params)); 127 chrome::CreateBrowserWithTestWindowForParams(&native_params));
129 AddTab(browser(), url1); 128 AddTab(browser(), url1);
130 AddTab(browser2.get(), url2); 129 AddTab(browser2.get(), url2);
131 AddTab(browser3.get(), url3); 130 AddTab(browser3.get(), url3);
(...skipping 28 matching lines...) Expand all
160 // Close some tabs and verify that they are removed from the metrics map. 159 // Close some tabs and verify that they are removed from the metrics map.
161 chrome::CloseTab(browser2.get()); 160 chrome::CloseTab(browser2.get());
162 chrome::CloseTab(browser3.get()); 161 chrome::CloseTab(browser3.get());
163 162
164 collector->UpdatePowerConsumptionForTesting(); 163 collector->UpdatePowerConsumptionForTesting();
165 EXPECT_EQ(1u, metrics_map->size()); 164 EXPECT_EQ(1u, metrics_map->size());
166 } 165 }
167 166
168 TEST_F(BrowserProcessPowerTest, IncognitoDoesntRecordPowerUsage) { 167 TEST_F(BrowserProcessPowerTest, IncognitoDoesntRecordPowerUsage) {
169 Browser::CreateParams native_params(profile()->GetOffTheRecordProfile(), 168 Browser::CreateParams native_params(profile()->GetOffTheRecordProfile(),
170 chrome::HOST_DESKTOP_TYPE_NATIVE); 169 ui::HOST_DESKTOP_TYPE_NATIVE);
171 scoped_ptr<Browser> incognito_browser( 170 scoped_ptr<Browser> incognito_browser(
172 chrome::CreateBrowserWithTestWindowForParams(&native_params)); 171 chrome::CreateBrowserWithTestWindowForParams(&native_params));
173 GURL url("http://www.google.com"); 172 GURL url("http://www.google.com");
174 AddTab(browser(), url); 173 AddTab(browser(), url);
175 174
176 GURL hidden_url("http://foo.com"); 175 GURL hidden_url("http://foo.com");
177 AddTab(incognito_browser.get(), hidden_url); 176 AddTab(incognito_browser.get(), hidden_url);
178 177
179 // Create fake process numbers. 178 // Create fake process numbers.
180 GetProcess(browser())->SetProcessHandle(MakeProcessHandle(1).Pass()); 179 GetProcess(browser())->SetProcessHandle(MakeProcessHandle(1).Pass());
(...skipping 18 matching lines...) Expand all
199 // Verify that the incognito data was not stored. 198 // Verify that the incognito data was not stored.
200 EXPECT_EQ(100, origin_power_map->GetPowerForOrigin(url)); 199 EXPECT_EQ(100, origin_power_map->GetPowerForOrigin(url));
201 EXPECT_EQ(0, origin_power_map->GetPowerForOrigin(hidden_url)); 200 EXPECT_EQ(0, origin_power_map->GetPowerForOrigin(hidden_url));
202 201
203 chrome::CloseTab(incognito_browser.get()); 202 chrome::CloseTab(incognito_browser.get());
204 } 203 }
205 204
206 TEST_F(BrowserProcessPowerTest, MultipleProfilesRecordSeparately) { 205 TEST_F(BrowserProcessPowerTest, MultipleProfilesRecordSeparately) {
207 scoped_ptr<Profile> other_profile(CreateProfile()); 206 scoped_ptr<Profile> other_profile(CreateProfile());
208 Browser::CreateParams native_params(other_profile.get(), 207 Browser::CreateParams native_params(other_profile.get(),
209 chrome::HOST_DESKTOP_TYPE_NATIVE); 208 ui::HOST_DESKTOP_TYPE_NATIVE);
210 scoped_ptr<Browser> other_user( 209 scoped_ptr<Browser> other_user(
211 chrome::CreateBrowserWithTestWindowForParams(&native_params)); 210 chrome::CreateBrowserWithTestWindowForParams(&native_params));
212 211
213 GURL url("http://www.google.com"); 212 GURL url("http://www.google.com");
214 AddTab(browser(), url); 213 AddTab(browser(), url);
215 214
216 GURL hidden_url("http://foo.com"); 215 GURL hidden_url("http://foo.com");
217 AddTab(other_user.get(), hidden_url); 216 AddTab(other_user.get(), hidden_url);
218 217
219 // Create fake process numbers. 218 // Create fake process numbers.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant, 286 base::Bind(&BrowserProcessPowerTest::ReturnCpuAsConstant,
288 base::Unretained(this), 287 base::Unretained(this),
289 5)); 288 5));
290 collector->UpdatePowerConsumptionForTesting(); 289 collector->UpdatePowerConsumptionForTesting();
291 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size()); 290 EXPECT_EQ(1u, collector->metrics_map_for_testing()->size());
292 291
293 window->OnNativeClose(); 292 window->OnNativeClose();
294 collector->UpdatePowerConsumptionForTesting(); 293 collector->UpdatePowerConsumptionForTesting();
295 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size()); 294 EXPECT_EQ(0u, collector->metrics_map_for_testing()->size());
296 } 295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698