| 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" |
| 11 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 11 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/profiles/profiles_state.h" | 13 #include "chrome/browser/profiles/profiles_state.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
| 16 #include "chrome/browser/ui/browser_window_state.h" | 16 #include "chrome/browser/ui/browser_window_state.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "chrome/test/base/browser_with_test_window_test.h" | 19 #include "chrome/test/base/browser_with_test_window_test.h" |
| 20 #include "chrome/test/base/test_browser_window.h" | 20 #include "chrome/test/base/test_browser_window.h" |
| 21 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 22 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 23 #include "chrome/test/base/testing_profile_manager.h" | 23 #include "chrome/test/base/testing_profile_manager.h" |
| 24 #include "components/signin/core/common/profile_management_switches.h" | 24 #include "components/signin/core/common/profile_management_switches.h" |
| 25 #include "content/public/browser/native_web_keyboard_event.h" | 25 #include "content/public/browser/native_web_keyboard_event.h" |
| 26 #include "ui/events/keycodes/keyboard_codes.h" | 26 #include "ui/events/keycodes/keyboard_codes.h" |
| 27 | 27 |
| 28 typedef BrowserWithTestWindowTest BrowserCommandControllerTest; | 28 typedef BrowserWithTestWindowTest BrowserCommandControllerTest; |
| 29 | 29 |
| 30 static void EnableNewProfileManagement() { |
| 31 #if defined(OS_ANDROID) |
| 32 DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch( |
| 33 switches::kDisableNewProfileManagement)); |
| 34 #else |
| 35 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 36 switches::kEnableNewProfileManagement); |
| 37 #endif |
| 38 } |
| 39 |
| 30 TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKey) { | 40 TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKey) { |
| 31 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
| 32 // F1-3 keys are reserved Chrome accelerators on Chrome OS. | 42 // F1-3 keys are reserved Chrome accelerators on Chrome OS. |
| 33 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( | 43 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( |
| 34 IDC_BACK, content::NativeWebKeyboardEvent( | 44 IDC_BACK, content::NativeWebKeyboardEvent( |
| 35 ui::ET_KEY_PRESSED, false, ui::VKEY_BROWSER_BACK, 0, 0))); | 45 ui::ET_KEY_PRESSED, false, ui::VKEY_BROWSER_BACK, 0, 0))); |
| 36 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( | 46 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( |
| 37 IDC_FORWARD, content::NativeWebKeyboardEvent( | 47 IDC_FORWARD, content::NativeWebKeyboardEvent( |
| 38 ui::ET_KEY_PRESSED, false, ui::VKEY_BROWSER_FORWARD, 0, 0))); | 48 ui::ET_KEY_PRESSED, false, ui::VKEY_BROWSER_FORWARD, 0, 0))); |
| 39 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( | 49 EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 214 EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
| 205 | 215 |
| 206 testing_profile_manager.DeleteTestingProfile("p2"); | 216 testing_profile_manager.DeleteTestingProfile("p2"); |
| 207 } | 217 } |
| 208 | 218 |
| 209 TEST_F(BrowserCommandControllerTest, NewAvatarMenuEnabledWhenOnlyOneProfile) { | 219 TEST_F(BrowserCommandControllerTest, NewAvatarMenuEnabledWhenOnlyOneProfile) { |
| 210 if (!profiles::IsMultipleProfilesEnabled()) | 220 if (!profiles::IsMultipleProfilesEnabled()) |
| 211 return; | 221 return; |
| 212 | 222 |
| 213 // The command line is reset at the end of every test by the test suite. | 223 // The command line is reset at the end of every test by the test suite. |
| 214 CommandLine::ForCurrentProcess()->AppendSwitch( | 224 EnableNewProfileManagement(); |
| 215 switches::kNewProfileManagement); | |
| 216 EXPECT_TRUE(switches::IsNewProfileManagement()); | 225 EXPECT_TRUE(switches::IsNewProfileManagement()); |
| 217 | 226 |
| 218 TestingProfileManager testing_profile_manager( | 227 TestingProfileManager testing_profile_manager( |
| 219 TestingBrowserProcess::GetGlobal()); | 228 TestingBrowserProcess::GetGlobal()); |
| 220 ASSERT_TRUE(testing_profile_manager.SetUp()); | 229 ASSERT_TRUE(testing_profile_manager.SetUp()); |
| 221 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); | 230 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); |
| 222 | 231 |
| 223 chrome::BrowserCommandController command_controller(browser()); | 232 chrome::BrowserCommandController command_controller(browser()); |
| 224 const CommandUpdater* command_updater = command_controller.command_updater(); | 233 const CommandUpdater* command_updater = command_controller.command_updater(); |
| 225 | 234 |
| 226 testing_profile_manager.CreateTestingProfile("p1"); | 235 testing_profile_manager.CreateTestingProfile("p1"); |
| 227 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); | 236 ASSERT_EQ(1U, profile_manager->GetNumberOfProfiles()); |
| 228 #if defined(OS_CHROMEOS) | 237 #if defined(OS_CHROMEOS) |
| 229 // Chrome OS uses system tray menu to handle multi-profiles. | 238 // Chrome OS uses system tray menu to handle multi-profiles. |
| 230 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 239 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
| 231 #else | 240 #else |
| 232 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 241 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
| 233 #endif | 242 #endif |
| 234 testing_profile_manager.DeleteTestingProfile("p1"); | 243 testing_profile_manager.DeleteTestingProfile("p1"); |
| 235 } | 244 } |
| 236 | 245 |
| 237 TEST_F(BrowserCommandControllerTest, NewAvatarMenuEnabledInGuestMode) { | 246 TEST_F(BrowserCommandControllerTest, NewAvatarMenuEnabledInGuestMode) { |
| 238 if (!profiles::IsMultipleProfilesEnabled()) | 247 if (!profiles::IsMultipleProfilesEnabled()) |
| 239 return; | 248 return; |
| 240 | 249 |
| 241 // The command line is reset at the end of every test by the test suite. | 250 // The command line is reset at the end of every test by the test suite. |
| 242 CommandLine::ForCurrentProcess()->AppendSwitch( | 251 EnableNewProfileManagement(); |
| 243 switches::kNewProfileManagement); | |
| 244 EXPECT_TRUE(switches::IsNewProfileManagement()); | 252 EXPECT_TRUE(switches::IsNewProfileManagement()); |
| 245 | 253 |
| 246 TestingProfileManager testing_profile_manager( | 254 TestingProfileManager testing_profile_manager( |
| 247 TestingBrowserProcess::GetGlobal()); | 255 TestingBrowserProcess::GetGlobal()); |
| 248 ASSERT_TRUE(testing_profile_manager.SetUp()); | 256 ASSERT_TRUE(testing_profile_manager.SetUp()); |
| 249 | 257 |
| 250 // Set up guest a profile. | 258 // Set up guest a profile. |
| 251 TestingProfile::Builder guest_builder; | 259 TestingProfile::Builder guest_builder; |
| 252 guest_builder.SetIncognito(); // Guest profiles are off the record. | 260 guest_builder.SetIncognito(); // Guest profiles are off the record. |
| 253 guest_builder.SetGuestSession(); | 261 guest_builder.SetGuestSession(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 295 |
| 288 chrome::BrowserCommandController command_controller(otr_browser.get()); | 296 chrome::BrowserCommandController command_controller(otr_browser.get()); |
| 289 const CommandUpdater* command_updater = command_controller.command_updater(); | 297 const CommandUpdater* command_updater = command_controller.command_updater(); |
| 290 | 298 |
| 291 // The old style avatar menu should be disabled. | 299 // The old style avatar menu should be disabled. |
| 292 EXPECT_FALSE(switches::IsNewProfileManagement()); | 300 EXPECT_FALSE(switches::IsNewProfileManagement()); |
| 293 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 301 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
| 294 | 302 |
| 295 // The new style avatar menu should also be disabled. | 303 // The new style avatar menu should also be disabled. |
| 296 // The command line is reset at the end of every test by the test suite. | 304 // The command line is reset at the end of every test by the test suite. |
| 297 CommandLine::ForCurrentProcess()->AppendSwitch( | 305 EnableNewProfileManagement(); |
| 298 switches::kNewProfileManagement); | |
| 299 EXPECT_TRUE(switches::IsNewProfileManagement()); | 306 EXPECT_TRUE(switches::IsNewProfileManagement()); |
| 300 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 307 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
| 301 } | 308 } |
| 302 | 309 |
| 303 ////////////////////////////////////////////////////////////////////////////// | 310 ////////////////////////////////////////////////////////////////////////////// |
| 304 | 311 |
| 305 // A test browser window that can toggle fullscreen state. | 312 // A test browser window that can toggle fullscreen state. |
| 306 class FullscreenTestBrowserWindow : public TestBrowserWindow { | 313 class FullscreenTestBrowserWindow : public TestBrowserWindow { |
| 307 public: | 314 public: |
| 308 FullscreenTestBrowserWindow() : fullscreen_(false) {} | 315 FullscreenTestBrowserWindow() : fullscreen_(false) {} |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 466 |
| 460 TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) { | 467 TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) { |
| 461 chrome::BrowserCommandController command_controller(browser()); | 468 chrome::BrowserCommandController command_controller(browser()); |
| 462 const CommandUpdater* command_updater = command_controller.command_updater(); | 469 const CommandUpdater* command_updater = command_controller.command_updater(); |
| 463 | 470 |
| 464 // Check that the SYNC_SETUP command is updated on preference change. | 471 // Check that the SYNC_SETUP command is updated on preference change. |
| 465 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 472 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
| 466 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | 473 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
| 467 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 474 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
| 468 } | 475 } |
| OLD | NEW |