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 "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/command_updater.h" |
9 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_commands.h" | 12 #include "chrome/browser/ui/browser_commands.h" |
12 #include "chrome/browser/ui/browser_window_state.h" | 13 #include "chrome/browser/ui/browser_window_state.h" |
| 14 #include "chrome/common/pref_names.h" |
13 #include "chrome/test/base/browser_with_test_window_test.h" | 15 #include "chrome/test/base/browser_with_test_window_test.h" |
14 #include "chrome/test/base/test_browser_window.h" | 16 #include "chrome/test/base/test_browser_window.h" |
15 #include "chrome/test/base/testing_browser_process.h" | 17 #include "chrome/test/base/testing_browser_process.h" |
16 #include "chrome/test/base/testing_profile_manager.h" | 18 #include "chrome/test/base/testing_profile_manager.h" |
17 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
18 #include "ui/base/keycodes/keyboard_codes.h" | 20 #include "ui/base/keycodes/keyboard_codes.h" |
19 | 21 |
20 typedef BrowserWithTestWindowTest BrowserCommandControllerTest; | 22 typedef BrowserWithTestWindowTest BrowserCommandControllerTest; |
21 | 23 |
22 TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKey) { | 24 TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKey) { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU)); | 313 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_DEVELOPER_MENU)); |
312 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK)); | 314 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FEEDBACK)); |
313 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); | 315 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
314 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); | 316 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
315 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES)); | 317 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_EDIT_SEARCH_ENGINES)); |
316 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS)); | 318 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_VIEW_PASSWORDS)); |
317 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT)); | 319 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_ABOUT)); |
318 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU)); | 320 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_APP_MENU)); |
319 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); | 321 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); |
320 } | 322 } |
| 323 |
| 324 TEST_F(BrowserCommandControllerTest, |
| 325 IncognitoModeOnSigninAllowedPrefChange) { |
| 326 TestingProfileManager testing_profile_manager( |
| 327 TestingBrowserProcess::GetGlobal()); |
| 328 ASSERT_TRUE(testing_profile_manager.SetUp()); |
| 329 |
| 330 // Set up a profile with an off the record profile. |
| 331 TestingProfile* profile2 = new TestingProfile(); |
| 332 profile2->set_incognito(true); |
| 333 TestingProfile* profile1 = |
| 334 testing_profile_manager.CreateTestingProfile("p1"); |
| 335 profile2->SetOriginalProfile(profile1); |
| 336 EXPECT_EQ(profile2->GetOriginalProfile(), profile1); |
| 337 profile1->SetOffTheRecordProfile(profile2); |
| 338 // Create a new browser based on the off the record profile. |
| 339 Browser::CreateParams profile_params(profile2, |
| 340 chrome::HOST_DESKTOP_TYPE_NATIVE); |
| 341 scoped_ptr<Browser> browser2( |
| 342 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); |
| 343 |
| 344 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); |
| 345 chrome::BrowserCommandController* command_controller = |
| 346 new chrome::BrowserCommandController(browser2.get(), profile_manager); |
| 347 const CommandUpdater* command_updater = command_controller->command_updater(); |
| 348 |
| 349 // Check that the SYNC_SETUP command is updated on preference change. |
| 350 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
| 351 profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
| 352 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
| 353 delete command_controller; |
| 354 browser2.reset(); |
| 355 testing_profile_manager.DeleteTestingProfile("p1"); |
| 356 } |
| 357 |
| 358 TEST_F(BrowserCommandControllerTest, |
| 359 OnSigninAllowedPrefChange) { |
| 360 TestingProfileManager testing_profile_manager( |
| 361 TestingBrowserProcess::GetGlobal()); |
| 362 ASSERT_TRUE(testing_profile_manager.SetUp()); |
| 363 ProfileManager* profile_manager = testing_profile_manager.profile_manager(); |
| 364 chrome::BrowserCommandController command_controller(browser(), |
| 365 profile_manager); |
| 366 const CommandUpdater* command_updater = command_controller.command_updater(); |
| 367 |
| 368 // Check that the SYNC_SETUP command is updated on preference change. |
| 369 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
| 370 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
| 371 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
| 372 } |
OLD | NEW |