OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/browser_command_controller.h" | 5 #include "chrome/browser/ui/browser_command_controller.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/command_updater.h" | 10 #include "chrome/browser/command_updater.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 // Enable for tabbed browser. | 164 // Enable for tabbed browser. |
165 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); | 165 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); |
166 | 166 |
167 // Enabled for app windows. | 167 // Enabled for app windows. |
168 browser()->app_name_ = "app"; | 168 browser()->app_name_ = "app"; |
169 ASSERT_TRUE(browser()->is_app()); | 169 ASSERT_TRUE(browser()->is_app()); |
170 browser()->command_controller()->FullscreenStateChanged(); | 170 browser()->command_controller()->FullscreenStateChanged(); |
171 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); | 171 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); |
172 } | 172 } |
173 | 173 |
174 TEST_F(BrowserCommandControllerTest, OldAvatarMenuDisabledWhenOnlyOneProfile) { | 174 TEST_F(BrowserCommandControllerTest, OldAvatarMenuEnabledForOneOrMoreProfiles) { |
175 #if defined(OS_CHROMEOS) | 175 #if defined(OS_CHROMEOS) |
176 // TODO(nkostylev): Cleanup this code once multi-profiles are enabled by | 176 // TODO(nkostylev): Cleanup this code once multi-profiles are enabled by |
177 // default on CrOS. http://crbug.com/351655 | 177 // default on CrOS. http://crbug.com/351655 |
178 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles); | 178 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles); |
179 #endif | 179 #endif |
180 | 180 |
181 if (!profiles::IsMultipleProfilesEnabled()) | 181 if (!profiles::IsMultipleProfilesEnabled()) |
182 return; | 182 return; |
183 | 183 |
184 EXPECT_FALSE(switches::IsNewProfileManagement()); | 184 EXPECT_FALSE(switches::IsNewProfileManagement()); |
185 | 185 |
186 TestingProfileManager testing_profile_manager( | 186 TestingProfileManager testing_profile_manager( |
187 TestingBrowserProcess::GetGlobal()); | 187 TestingBrowserProcess::GetGlobal()); |
188 ASSERT_TRUE(testing_profile_manager.SetUp()); | 188 ASSERT_TRUE(testing_profile_manager.SetUp()); |
189 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); | 189 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); |
190 | 190 |
191 chrome::BrowserCommandController command_controller(browser(), | 191 chrome::BrowserCommandController command_controller(browser()); |
192 profile_manager); | |
193 const CommandUpdater* command_updater = command_controller.command_updater(); | 192 const CommandUpdater* command_updater = command_controller.command_updater(); |
194 | 193 |
| 194 bool enabled = true; |
| 195 #if defined(OS_CHROMEOS) |
| 196 // Chrome OS uses system tray menu to handle multi-profiles. |
| 197 enabled = false; |
| 198 #endif |
| 199 |
195 testing_profile_manager.CreateTestingProfile("p1"); | 200 testing_profile_manager.CreateTestingProfile("p1"); |
196 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); | 201 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); |
197 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 202 EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
198 | 203 |
199 testing_profile_manager.CreateTestingProfile("p2"); | 204 testing_profile_manager.CreateTestingProfile("p2"); |
200 ASSERT_EQ(2U, profile_manager->GetNumberOfProfiles()); | 205 ASSERT_EQ(2U, profile_manager->GetNumberOfProfiles()); |
201 #if defined(OS_CHROMEOS) | 206 EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
202 // Chrome OS uses system tray menu to handle multi-profiles. | |
203 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | |
204 #else | |
205 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | |
206 #endif | |
207 | 207 |
208 testing_profile_manager.DeleteTestingProfile("p1"); | 208 testing_profile_manager.DeleteTestingProfile("p1"); |
209 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); | 209 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); |
210 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 210 EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
211 | 211 |
212 testing_profile_manager.DeleteTestingProfile("p2"); | 212 testing_profile_manager.DeleteTestingProfile("p2"); |
213 } | 213 } |
214 | 214 |
215 TEST_F(BrowserCommandControllerTest, NewAvatarMenuEnabledWhenOnlyOneProfile) { | 215 TEST_F(BrowserCommandControllerTest, NewAvatarMenuEnabledWhenOnlyOneProfile) { |
216 #if defined(OS_CHROMEOS) | 216 #if defined(OS_CHROMEOS) |
217 // TODO(nkostylev): Cleanup this code once multi-profiles are enabled by | 217 // TODO(nkostylev): Cleanup this code once multi-profiles are enabled by |
218 // default on CrOS. http://crbug.com/351655 | 218 // default on CrOS. http://crbug.com/351655 |
219 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles); | 219 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles); |
220 #endif | 220 #endif |
221 | 221 |
222 if (!profiles::IsMultipleProfilesEnabled()) | 222 if (!profiles::IsMultipleProfilesEnabled()) |
223 return; | 223 return; |
224 | 224 |
225 // The command line is reset at the end of every test by the test suite. | 225 // The command line is reset at the end of every test by the test suite. |
226 CommandLine::ForCurrentProcess()->AppendSwitch( | 226 CommandLine::ForCurrentProcess()->AppendSwitch( |
227 switches::kNewProfileManagement); | 227 switches::kNewProfileManagement); |
228 EXPECT_TRUE(switches::IsNewProfileManagement()); | 228 EXPECT_TRUE(switches::IsNewProfileManagement()); |
229 | 229 |
230 TestingProfileManager testing_profile_manager( | 230 TestingProfileManager testing_profile_manager( |
231 TestingBrowserProcess::GetGlobal()); | 231 TestingBrowserProcess::GetGlobal()); |
232 ASSERT_TRUE(testing_profile_manager.SetUp()); | 232 ASSERT_TRUE(testing_profile_manager.SetUp()); |
233 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); | 233 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); |
234 | 234 |
235 chrome::BrowserCommandController command_controller(browser(), | 235 chrome::BrowserCommandController command_controller(browser()); |
236 profile_manager); | |
237 const CommandUpdater* command_updater = command_controller.command_updater(); | 236 const CommandUpdater* command_updater = command_controller.command_updater(); |
238 | 237 |
239 testing_profile_manager.CreateTestingProfile("p1"); | 238 testing_profile_manager.CreateTestingProfile("p1"); |
240 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); | 239 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); |
241 #if defined(OS_CHROMEOS) | 240 #if defined(OS_CHROMEOS) |
242 // Chrome OS uses system tray menu to handle multi-profiles. | 241 // Chrome OS uses system tray menu to handle multi-profiles. |
243 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 242 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
244 #else | 243 #else |
245 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 244 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
246 #endif | 245 #endif |
(...skipping 11 matching lines...) Expand all Loading... |
258 return; | 257 return; |
259 | 258 |
260 // The command line is reset at the end of every test by the test suite. | 259 // The command line is reset at the end of every test by the test suite. |
261 CommandLine::ForCurrentProcess()->AppendSwitch( | 260 CommandLine::ForCurrentProcess()->AppendSwitch( |
262 switches::kNewProfileManagement); | 261 switches::kNewProfileManagement); |
263 EXPECT_TRUE(switches::IsNewProfileManagement()); | 262 EXPECT_TRUE(switches::IsNewProfileManagement()); |
264 | 263 |
265 TestingProfileManager testing_profile_manager( | 264 TestingProfileManager testing_profile_manager( |
266 TestingBrowserProcess::GetGlobal()); | 265 TestingBrowserProcess::GetGlobal()); |
267 ASSERT_TRUE(testing_profile_manager.SetUp()); | 266 ASSERT_TRUE(testing_profile_manager.SetUp()); |
268 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); | |
269 | 267 |
270 // Set up guest a profile. | 268 // Set up guest a profile. |
271 TestingProfile::Builder guest_builder; | 269 TestingProfile::Builder guest_builder; |
272 guest_builder.SetIncognito(); // Guest profiles are off the record. | 270 guest_builder.SetIncognito(); // Guest profiles are off the record. |
273 guest_builder.SetGuestSession(); | 271 guest_builder.SetGuestSession(); |
274 guest_builder.SetPath(ProfileManager::GetGuestProfilePath()); | 272 guest_builder.SetPath(ProfileManager::GetGuestProfilePath()); |
275 scoped_ptr<TestingProfile>guest_profile = guest_builder.Build(); | 273 scoped_ptr<TestingProfile>guest_profile = guest_builder.Build(); |
276 | 274 |
277 ASSERT_TRUE(guest_profile->IsGuestSession()); | 275 ASSERT_TRUE(guest_profile->IsGuestSession()); |
278 | 276 |
279 // Create a new browser based on the guest profile. | 277 // Create a new browser based on the guest profile. |
280 Browser::CreateParams profile_params(guest_profile.get(), | 278 Browser::CreateParams profile_params(guest_profile.get(), |
281 chrome::GetActiveDesktop()); | 279 chrome::GetActiveDesktop()); |
282 scoped_ptr<Browser> guest_browser( | 280 scoped_ptr<Browser> guest_browser( |
283 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); | 281 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); |
284 chrome::BrowserCommandController command_controller(guest_browser.get(), | 282 chrome::BrowserCommandController command_controller(guest_browser.get()); |
285 profile_manager); | |
286 const CommandUpdater* command_updater = command_controller.command_updater(); | 283 const CommandUpdater* command_updater = command_controller.command_updater(); |
287 #if defined(OS_CHROMEOS) | 284 #if defined(OS_CHROMEOS) |
288 // Chrome OS uses system tray menu to handle multi-profiles. | 285 // Chrome OS uses system tray menu to handle multi-profiles. |
289 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 286 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
290 #else | 287 #else |
291 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 288 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
292 #endif | 289 #endif |
293 } | 290 } |
294 | 291 |
295 TEST_F(BrowserCommandControllerTest, AvatarMenuAlwaysDisabledInIncognitoMode) { | 292 TEST_F(BrowserCommandControllerTest, AvatarMenuAlwaysDisabledInIncognitoMode) { |
296 #if defined(OS_CHROMEOS) | 293 #if defined(OS_CHROMEOS) |
297 // TODO(nkostylev): Cleanup this code once multi-profiles are enabled by | 294 // TODO(nkostylev): Cleanup this code once multi-profiles are enabled by |
298 // default on CrOS. http://crbug.com/351655 | 295 // default on CrOS. http://crbug.com/351655 |
299 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles); | 296 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles); |
300 #endif | 297 #endif |
301 | 298 |
302 if (!profiles::IsMultipleProfilesEnabled()) | 299 if (!profiles::IsMultipleProfilesEnabled()) |
303 return; | 300 return; |
304 | 301 |
305 TestingProfileManager testing_profile_manager( | |
306 TestingBrowserProcess::GetGlobal()); | |
307 ASSERT_TRUE(testing_profile_manager.SetUp()); | |
308 | |
309 // Set up a profile with an off the record profile. | 302 // Set up a profile with an off the record profile. |
310 TestingProfile::Builder normal_builder; | 303 TestingProfile::Builder normal_builder; |
311 scoped_ptr<TestingProfile> original_profile = normal_builder.Build(); | 304 scoped_ptr<TestingProfile> original_profile = normal_builder.Build(); |
312 | 305 |
313 // Create a new browser based on the off the record profile. | 306 // Create a new browser based on the off the record profile. |
314 Browser::CreateParams profile_params( | 307 Browser::CreateParams profile_params( |
315 original_profile->GetOffTheRecordProfile(), chrome::GetActiveDesktop()); | 308 original_profile->GetOffTheRecordProfile(), chrome::GetActiveDesktop()); |
316 scoped_ptr<Browser> otr_browser( | 309 scoped_ptr<Browser> otr_browser( |
317 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); | 310 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); |
318 | 311 |
319 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); | 312 chrome::BrowserCommandController command_controller(otr_browser.get()); |
320 chrome::BrowserCommandController command_controller(otr_browser.get(), | |
321 profile_manager); | |
322 const CommandUpdater* command_updater = command_controller.command_updater(); | 313 const CommandUpdater* command_updater = command_controller.command_updater(); |
323 | 314 |
324 // The old style avatar menu should be disabled. | 315 // The old style avatar menu should be disabled. |
325 EXPECT_FALSE(switches::IsNewProfileManagement()); | 316 EXPECT_FALSE(switches::IsNewProfileManagement()); |
326 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 317 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
327 | 318 |
328 // The new style avatar menu should also be disabled. | 319 // The new style avatar menu should also be disabled. |
329 // The command line is reset at the end of every test by the test suite. | 320 // The command line is reset at the end of every test by the test suite. |
330 CommandLine::ForCurrentProcess()->AppendSwitch( | 321 CommandLine::ForCurrentProcess()->AppendSwitch( |
331 switches::kNewProfileManagement); | 322 switches::kNewProfileManagement); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 TestingProfile* testprofile = browser()->profile()->AsTestingProfile(); | 449 TestingProfile* testprofile = browser()->profile()->AsTestingProfile(); |
459 EXPECT_TRUE(testprofile); | 450 EXPECT_TRUE(testprofile); |
460 testprofile->SetGuestSession(true); | 451 testprofile->SetGuestSession(true); |
461 | 452 |
462 browser()->command_controller()->FullscreenStateChanged(); | 453 browser()->command_controller()->FullscreenStateChanged(); |
463 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); | 454 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
464 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); | 455 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
465 } | 456 } |
466 | 457 |
467 TEST_F(BrowserCommandControllerTest, IncognitoModeOnSigninAllowedPrefChange) { | 458 TEST_F(BrowserCommandControllerTest, IncognitoModeOnSigninAllowedPrefChange) { |
468 TestingProfileManager testing_profile_manager( | |
469 TestingBrowserProcess::GetGlobal()); | |
470 ASSERT_TRUE(testing_profile_manager.SetUp()); | |
471 | |
472 // Set up a profile with an off the record profile. | 459 // Set up a profile with an off the record profile. |
473 TestingProfile::Builder builder; | 460 TestingProfile::Builder builder; |
474 builder.SetIncognito(); | 461 builder.SetIncognito(); |
475 scoped_ptr<TestingProfile> profile2(builder.Build()); | 462 scoped_ptr<TestingProfile> profile2(builder.Build()); |
476 TestingProfile::Builder builder2; | 463 TestingProfile::Builder builder2; |
477 scoped_ptr<TestingProfile> profile1 = builder2.Build(); | 464 scoped_ptr<TestingProfile> profile1 = builder2.Build(); |
478 profile2->SetOriginalProfile(profile1.get()); | 465 profile2->SetOriginalProfile(profile1.get()); |
479 EXPECT_EQ(profile2->GetOriginalProfile(), profile1.get()); | 466 EXPECT_EQ(profile2->GetOriginalProfile(), profile1.get()); |
480 profile1->SetOffTheRecordProfile(profile2.PassAs<Profile>()); | 467 profile1->SetOffTheRecordProfile(profile2.PassAs<Profile>()); |
481 | 468 |
482 // Create a new browser based on the off the record profile. | 469 // Create a new browser based on the off the record profile. |
483 Browser::CreateParams profile_params(profile1->GetOffTheRecordProfile(), | 470 Browser::CreateParams profile_params(profile1->GetOffTheRecordProfile(), |
484 chrome::GetActiveDesktop()); | 471 chrome::GetActiveDesktop()); |
485 scoped_ptr<Browser> browser2( | 472 scoped_ptr<Browser> browser2( |
486 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); | 473 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); |
487 | 474 |
488 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); | 475 chrome::BrowserCommandController command_controller(browser2.get()); |
489 chrome::BrowserCommandController command_controller(browser2.get(), | |
490 profile_manager); | |
491 const CommandUpdater* command_updater = command_controller.command_updater(); | 476 const CommandUpdater* command_updater = command_controller.command_updater(); |
492 | 477 |
493 // Check that the SYNC_SETUP command is updated on preference change. | 478 // Check that the SYNC_SETUP command is updated on preference change. |
494 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 479 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
495 profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | 480 profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
496 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 481 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
497 } | 482 } |
498 | 483 |
499 TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) { | 484 TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) { |
500 TestingProfileManager testing_profile_manager( | 485 chrome::BrowserCommandController command_controller(browser()); |
501 TestingBrowserProcess::GetGlobal()); | |
502 ASSERT_TRUE(testing_profile_manager.SetUp()); | |
503 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); | |
504 chrome::BrowserCommandController command_controller(browser(), | |
505 profile_manager); | |
506 const CommandUpdater* command_updater = command_controller.command_updater(); | 486 const CommandUpdater* command_updater = command_controller.command_updater(); |
507 | 487 |
508 // Check that the SYNC_SETUP command is updated on preference change. | 488 // Check that the SYNC_SETUP command is updated on preference change. |
509 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 489 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
510 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | 490 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
511 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 491 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
512 } | 492 } |
OLD | NEW |