| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 return; | 239 return; |
| 240 | 240 |
| 241 // The command line is reset at the end of every test by the test suite. | 241 // The command line is reset at the end of every test by the test suite. |
| 242 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); | 242 switches::EnableNewAvatarMenuForTesting(CommandLine::ForCurrentProcess()); |
| 243 | 243 |
| 244 TestingProfileManager testing_profile_manager( | 244 TestingProfileManager testing_profile_manager( |
| 245 TestingBrowserProcess::GetGlobal()); | 245 TestingBrowserProcess::GetGlobal()); |
| 246 ASSERT_TRUE(testing_profile_manager.SetUp()); | 246 ASSERT_TRUE(testing_profile_manager.SetUp()); |
| 247 | 247 |
| 248 // Set up guest a profile. | 248 // Set up guest a profile. |
| 249 scoped_ptr<TestingProfile> original_profile = |
| 250 TestingProfile::Builder().Build(); |
| 249 TestingProfile::Builder guest_builder; | 251 TestingProfile::Builder guest_builder; |
| 250 guest_builder.SetIncognito(); // Guest profiles are off the record. | |
| 251 guest_builder.SetGuestSession(); | 252 guest_builder.SetGuestSession(); |
| 252 guest_builder.SetPath(ProfileManager::GetGuestProfilePath()); | 253 guest_builder.SetPath(ProfileManager::GetGuestProfilePath()); |
| 253 scoped_ptr<TestingProfile>guest_profile = guest_builder.Build(); | 254 // Browsers in Guest mode must be off the record profiles. |
| 255 TestingProfile* guest_profile = |
| 256 guest_builder.BuildIncognito(original_profile.get()); |
| 254 | 257 |
| 255 ASSERT_TRUE(guest_profile->IsGuestSession()); | 258 ASSERT_TRUE(guest_profile->IsGuestSession()); |
| 256 | 259 |
| 257 // Create a new browser based on the guest profile. | 260 // Create a new browser based on the guest profile. |
| 258 Browser::CreateParams profile_params(guest_profile.get(), | 261 Browser::CreateParams profile_params(guest_profile, |
| 259 chrome::GetActiveDesktop()); | 262 chrome::GetActiveDesktop()); |
| 260 scoped_ptr<Browser> guest_browser( | 263 scoped_ptr<Browser> guest_browser( |
| 261 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); | 264 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); |
| 262 chrome::BrowserCommandController command_controller(guest_browser.get()); | 265 chrome::BrowserCommandController command_controller(guest_browser.get()); |
| 263 const CommandUpdater* command_updater = command_controller.command_updater(); | 266 const CommandUpdater* command_updater = command_controller.command_updater(); |
| 264 #if defined(OS_CHROMEOS) | 267 #if defined(OS_CHROMEOS) |
| 265 // Chrome OS uses system tray menu to handle multi-profiles. | 268 // Chrome OS uses system tray menu to handle multi-profiles. |
| 266 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 269 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
| 267 #else | 270 #else |
| 268 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 271 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 EXPECT_TRUE(testprofile); | 426 EXPECT_TRUE(testprofile); |
| 424 testprofile->SetGuestSession(true); | 427 testprofile->SetGuestSession(true); |
| 425 | 428 |
| 426 browser()->command_controller()->FullscreenStateChanged(); | 429 browser()->command_controller()->FullscreenStateChanged(); |
| 427 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); | 430 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
| 428 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); | 431 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
| 429 } | 432 } |
| 430 | 433 |
| 431 TEST_F(BrowserCommandControllerTest, IncognitoModeOnSigninAllowedPrefChange) { | 434 TEST_F(BrowserCommandControllerTest, IncognitoModeOnSigninAllowedPrefChange) { |
| 432 // Set up a profile with an off the record profile. | 435 // Set up a profile with an off the record profile. |
| 433 TestingProfile::Builder builder; | 436 scoped_ptr<TestingProfile> profile1 = TestingProfile::Builder().Build(); |
| 434 builder.SetIncognito(); | 437 Profile* profile2 = profile1->GetOffTheRecordProfile(); |
| 435 scoped_ptr<TestingProfile> profile2(builder.Build()); | 438 |
| 436 TestingProfile::Builder builder2; | |
| 437 scoped_ptr<TestingProfile> profile1 = builder2.Build(); | |
| 438 profile2->SetOriginalProfile(profile1.get()); | |
| 439 EXPECT_EQ(profile2->GetOriginalProfile(), profile1.get()); | 439 EXPECT_EQ(profile2->GetOriginalProfile(), profile1.get()); |
| 440 profile1->SetOffTheRecordProfile(profile2.PassAs<Profile>()); | |
| 441 | 440 |
| 442 // Create a new browser based on the off the record profile. | 441 // Create a new browser based on the off the record profile. |
| 443 Browser::CreateParams profile_params(profile1->GetOffTheRecordProfile(), | 442 Browser::CreateParams profile_params(profile1->GetOffTheRecordProfile(), |
| 444 chrome::GetActiveDesktop()); | 443 chrome::GetActiveDesktop()); |
| 445 scoped_ptr<Browser> browser2( | 444 scoped_ptr<Browser> browser2( |
| 446 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); | 445 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); |
| 447 | 446 |
| 448 chrome::BrowserCommandController command_controller(browser2.get()); | 447 chrome::BrowserCommandController command_controller(browser2.get()); |
| 449 const CommandUpdater* command_updater = command_controller.command_updater(); | 448 const CommandUpdater* command_updater = command_controller.command_updater(); |
| 450 | 449 |
| 451 // Check that the SYNC_SETUP command is updated on preference change. | 450 // Check that the SYNC_SETUP command is updated on preference change. |
| 452 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 451 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
| 453 profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | 452 profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
| 454 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 453 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
| 455 } | 454 } |
| 456 | 455 |
| 457 TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) { | 456 TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) { |
| 458 chrome::BrowserCommandController command_controller(browser()); | 457 chrome::BrowserCommandController command_controller(browser()); |
| 459 const CommandUpdater* command_updater = command_controller.command_updater(); | 458 const CommandUpdater* command_updater = command_controller.command_updater(); |
| 460 | 459 |
| 461 // Check that the SYNC_SETUP command is updated on preference change. | 460 // Check that the SYNC_SETUP command is updated on preference change. |
| 462 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 461 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
| 463 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | 462 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
| 464 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 463 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
| 465 } | 464 } |
| OLD | NEW |