[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/ui/browser_command_controller.h" |
| 6 | |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 7 | #include "base/command_line.h" |
Lei Zhang | 1f46798c | 2021-05-26 01:35:18 | [diff] [blame] | 8 | #include "base/cxx17_backports.h" |
Nico Weber | 0cc7112 | 2019-07-29 17:30:40 | [diff] [blame] | 9 | #include "build/branding_buildflags.h" |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 10 | #include "build/build_config.h" |
Yuta Hijikata | 40b891d | 2020-11-27 09:05:01 | [diff] [blame] | 11 | #include "build/chromeos_buildflags.h" |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 12 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 13 | #include "chrome/browser/browser_process.h" |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 14 | #include "chrome/browser/command_updater.h" |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 15 | #include "chrome/browser/prefs/incognito_mode_prefs.h" |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 16 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | de71ae99 | 2013-07-18 03:30:38 | [diff] [blame] | 17 | #include "chrome/browser/profiles/profiles_state.h" |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 18 | #include "chrome/browser/ui/browser.h" |
[email protected] | bee96452 | 2012-11-20 01:56:53 | [diff] [blame] | 19 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 20 | #include "chrome/browser/ui/browser_window_state.h" |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 21 | #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" |
| 22 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
Rohit Agarwal | a14404f5 | 2021-06-14 11:50:44 | [diff] [blame] | 23 | #include "chrome/common/chrome_features.h" |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 24 | #include "chrome/common/chrome_switches.h" |
[email protected] | 074311a | 2013-02-28 23:14:09 | [diff] [blame] | 25 | #include "chrome/common/pref_names.h" |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 26 | #include "chrome/test/base/browser_with_test_window_test.h" |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 27 | #include "chrome/test/base/test_browser_window.h" |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 28 | #include "chrome/test/base/testing_browser_process.h" |
| 29 | #include "chrome/test/base/testing_profile_manager.h" |
Colin Blundell | 3517170e | 2019-07-11 08:16:34 | [diff] [blame] | 30 | #include "components/signin/public/base/signin_pref_names.h" |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 31 | #include "content/public/browser/native_web_keyboard_event.h" |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 32 | #include "ui/events/keycodes/dom/dom_code.h" |
[email protected] | 7e9acd08 | 2013-09-17 23:31:16 | [diff] [blame] | 33 | #include "ui/events/keycodes/keyboard_codes.h" |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 34 | |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 35 | typedef BrowserWithTestWindowTest BrowserCommandControllerTest; |
| 36 | |
| 37 | TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKey) { |
Yuta Hijikata | 40b891d | 2020-11-27 09:05:01 | [diff] [blame] | 38 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 39 | // F1-3 keys are reserved Chrome accelerators on Chrome OS. |
| 40 | EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( |
[email protected] | 397abd3 | 2013-08-21 05:44:19 | [diff] [blame] | 41 | IDC_BACK, content::NativeWebKeyboardEvent( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 42 | ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_BROWSER_BACK, |
| 43 | ui::DomCode::BROWSER_BACK, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 44 | EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 45 | IDC_FORWARD, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 46 | ui::ET_KEY_PRESSED, ui::VKEY_BROWSER_FORWARD, |
| 47 | ui::DomCode::BROWSER_FORWARD, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 48 | EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( |
[email protected] | 397abd3 | 2013-08-21 05:44:19 | [diff] [blame] | 49 | IDC_RELOAD, content::NativeWebKeyboardEvent( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 50 | ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_BROWSER_REFRESH, |
| 51 | ui::DomCode::BROWSER_REFRESH, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 52 | |
| 53 | // When there are modifier keys pressed, don't reserve. |
| 54 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
toyoshim | 7dad4b118 | 2016-04-01 14:28:05 | [diff] [blame] | 55 | IDC_RELOAD_BYPASSING_CACHE, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 56 | ui::ET_KEY_PRESSED, ui::VKEY_F3, |
| 57 | ui::DomCode::F3, ui::EF_SHIFT_DOWN)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 58 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
toyoshim | 7dad4b118 | 2016-04-01 14:28:05 | [diff] [blame] | 59 | IDC_RELOAD_BYPASSING_CACHE, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 60 | ui::ET_KEY_PRESSED, ui::VKEY_F3, |
| 61 | ui::DomCode::F3, ui::EF_CONTROL_DOWN)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 62 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
| 63 | IDC_FULLSCREEN, content::NativeWebKeyboardEvent( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 64 | ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_F4, |
| 65 | ui::DomCode::F4, ui::EF_SHIFT_DOWN)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 66 | |
| 67 | // F4-10 keys are not reserved since they are Ash accelerators. |
| 68 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 69 | -1, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 70 | ui::ET_KEY_PRESSED, ui::VKEY_F4, ui::DomCode::F4, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 71 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 72 | -1, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 73 | ui::ET_KEY_PRESSED, ui::VKEY_F5, ui::DomCode::F5, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 74 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 75 | -1, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 76 | ui::ET_KEY_PRESSED, ui::VKEY_F6, ui::DomCode::F6, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 77 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 78 | -1, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 79 | ui::ET_KEY_PRESSED, ui::VKEY_F7, ui::DomCode::F7, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 80 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 81 | -1, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 82 | ui::ET_KEY_PRESSED, ui::VKEY_F8, ui::DomCode::F8, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 83 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 84 | -1, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 85 | ui::ET_KEY_PRESSED, ui::VKEY_F9, ui::DomCode::F9, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 86 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 87 | -1, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 88 | ui::ET_KEY_PRESSED, ui::VKEY_F10, ui::DomCode::F10, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 89 | |
| 90 | // Shift+Control+Alt+F3 is also an Ash accelerator. Don't reserve it. |
| 91 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 92 | -1, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 93 | ui::ET_KEY_PRESSED, ui::VKEY_F3, ui::DomCode::F3, |
| 94 | ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)))); |
Yuta Hijikata | 40b891d | 2020-11-27 09:05:01 | [diff] [blame] | 95 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 96 | |
| 97 | #if defined(USE_AURA) |
| 98 | // Ctrl+n, Ctrl+w are reserved while Ctrl+f is not. |
| 99 | |
| 100 | // The content::NativeWebKeyboardEvent constructor is available only when |
| 101 | // USE_AURA is #defined. |
| 102 | EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 103 | IDC_NEW_WINDOW, content::NativeWebKeyboardEvent(ui::KeyEvent( |
kpschoedel | a281bf1 | 2016-01-07 15:08:19 | [diff] [blame] | 104 | ui::ET_KEY_PRESSED, ui::VKEY_N, ui::DomCode::US_N, |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 105 | ui::EF_CONTROL_DOWN)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 106 | EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 107 | IDC_CLOSE_TAB, content::NativeWebKeyboardEvent(ui::KeyEvent( |
kpschoedel | a281bf1 | 2016-01-07 15:08:19 | [diff] [blame] | 108 | ui::ET_KEY_PRESSED, ui::VKEY_W, ui::DomCode::US_W, |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 109 | ui::EF_CONTROL_DOWN)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 110 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
| 111 | IDC_FIND, content::NativeWebKeyboardEvent( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 112 | ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_F, |
kpschoedel | a281bf1 | 2016-01-07 15:08:19 | [diff] [blame] | 113 | ui::DomCode::US_F, ui::EF_CONTROL_DOWN)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 114 | #endif // USE_AURA |
| 115 | } |
| 116 | |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 117 | TEST_F(BrowserCommandControllerTest, IsReservedCommandOrKeyIsApp) { |
Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 118 | Browser::CreateParams params = Browser::CreateParams::CreateForApp( |
| 119 | "app", |
| 120 | /*trusted_source=*/true, browser()->window()->GetBounds(), profile(), |
| 121 | /*user_gesture=*/true); |
| 122 | params.window = browser()->window(); |
Ramin Halavati | 1a201c9 | 2020-10-29 12:45:16 | [diff] [blame] | 123 | set_browser(Browser::Create(params)); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 124 | |
Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 125 | ASSERT_TRUE(browser()->is_type_app()); |
| 126 | |
| 127 | // When is_type_app(), no keys are reserved. |
Yuta Hijikata | 40b891d | 2020-11-27 09:05:01 | [diff] [blame] | 128 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 129 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 130 | IDC_BACK, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 131 | ui::ET_KEY_PRESSED, ui::VKEY_F1, ui::DomCode::F1, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 132 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 133 | IDC_FORWARD, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 134 | ui::ET_KEY_PRESSED, ui::VKEY_F2, ui::DomCode::F2, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 135 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 136 | IDC_RELOAD, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 137 | ui::ET_KEY_PRESSED, ui::VKEY_F3, ui::DomCode::F3, 0)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 138 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 139 | -1, content::NativeWebKeyboardEvent(ui::KeyEvent( |
| 140 | ui::ET_KEY_PRESSED, ui::VKEY_F4, ui::DomCode::F4, 0)))); |
Yuta Hijikata | 40b891d | 2020-11-27 09:05:01 | [diff] [blame] | 141 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 142 | |
| 143 | #if defined(USE_AURA) |
| 144 | // The content::NativeWebKeyboardEvent constructor is available only when |
| 145 | // USE_AURA is #defined. |
| 146 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 147 | IDC_NEW_WINDOW, content::NativeWebKeyboardEvent(ui::KeyEvent( |
kpschoedel | a281bf1 | 2016-01-07 15:08:19 | [diff] [blame] | 148 | ui::ET_KEY_PRESSED, ui::VKEY_N, ui::DomCode::US_N, |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 149 | ui::EF_CONTROL_DOWN)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 150 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 151 | IDC_CLOSE_TAB, content::NativeWebKeyboardEvent(ui::KeyEvent( |
kpschoedel | a281bf1 | 2016-01-07 15:08:19 | [diff] [blame] | 152 | ui::ET_KEY_PRESSED, ui::VKEY_W, ui::DomCode::US_W, |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 153 | ui::EF_CONTROL_DOWN)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 154 | EXPECT_FALSE(browser()->command_controller()->IsReservedCommandOrKey( |
| 155 | IDC_FIND, content::NativeWebKeyboardEvent( |
dtapuska | 821d577 | 2015-10-15 02:51:30 | [diff] [blame] | 156 | ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_F, |
kpschoedel | a281bf1 | 2016-01-07 15:08:19 | [diff] [blame] | 157 | ui::DomCode::US_F, ui::EF_CONTROL_DOWN)))); |
[email protected] | 3642e2d | 2012-10-29 21:31:14 | [diff] [blame] | 158 | #endif // USE_AURA |
| 159 | } |
[email protected] | bee96452 | 2012-11-20 01:56:53 | [diff] [blame] | 160 | |
Ramin Halavati | b2af10a | 2021-07-05 05:49:42 | [diff] [blame] | 161 | TEST_F(BrowserWithTestWindowTest, IncognitoCommands) { |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 162 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
| 163 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 164 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN)); |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 165 | |
| 166 | TestingProfile* testprofile = browser()->profile()->AsTestingProfile(); |
| 167 | EXPECT_TRUE(testprofile); |
| 168 | testprofile->SetGuestSession(true); |
Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 169 | chrome::BrowserCommandController :: |
| 170 | UpdateSharedCommandsForIncognitoAvailability( |
Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 171 | browser()->command_controller(), testprofile); |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 172 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
| 173 | EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 174 | EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN)); |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 175 | |
| 176 | testprofile->SetGuestSession(false); |
| 177 | IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 178 | IncognitoModePrefs::FORCED); |
Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 179 | chrome::BrowserCommandController :: |
| 180 | UpdateSharedCommandsForIncognitoAvailability( |
Aran Gilman | d217b5b | 2019-04-11 17:45:43 | [diff] [blame] | 181 | browser()->command_controller(), testprofile); |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 182 | EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
| 183 | EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 184 | EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_SIGNIN)); |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 185 | } |
| 186 | |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 187 | TEST_F(BrowserCommandControllerTest, AppFullScreen) { |
[email protected] | bee96452 | 2012-11-20 01:56:53 | [diff] [blame] | 188 | // Enable for tabbed browser. |
| 189 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); |
| 190 | |
| 191 | // Enabled for app windows. |
Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 192 | Browser::CreateParams params = Browser::CreateParams::CreateForApp( |
| 193 | "app", |
| 194 | /*trusted_source=*/true, browser()->window()->GetBounds(), profile(), |
| 195 | /*user_gesture=*/true); |
| 196 | params.window = browser()->window(); |
Ramin Halavati | 1a201c9 | 2020-10-29 12:45:16 | [diff] [blame] | 197 | set_browser(Browser::Create(params)); |
Joel Hockey | 2687ab5 | 2019-08-14 23:59:46 | [diff] [blame] | 198 | ASSERT_TRUE(browser()->is_type_app()); |
[email protected] | bee96452 | 2012-11-20 01:56:53 | [diff] [blame] | 199 | browser()->command_controller()->FullscreenStateChanged(); |
| 200 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FULLSCREEN)); |
[email protected] | bee96452 | 2012-11-20 01:56:53 | [diff] [blame] | 201 | } |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 202 | |
anthonyvd | 66aa95d | 2015-10-02 15:40:26 | [diff] [blame] | 203 | TEST_F(BrowserCommandControllerTest, AvatarAcceleratorEnabledOnDesktop) { |
[email protected] | de71ae99 | 2013-07-18 03:30:38 | [diff] [blame] | 204 | if (!profiles::IsMultipleProfilesEnabled()) |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 205 | return; |
| 206 | |
Evan Stade | ef1543f | 2017-11-17 20:20:13 | [diff] [blame] | 207 | TestingProfileManager* testing_profile_manager = profile_manager(); |
| 208 | ProfileManager* profile_manager = testing_profile_manager->profile_manager(); |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 209 | chrome::BrowserCommandController command_controller(browser()); |
Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 210 | const CommandUpdater* command_updater = &command_controller; |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 211 | |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 212 | bool enabled = true; |
Pavol Marko | 56df027 | 2018-07-04 17:55:04 | [diff] [blame] | 213 | size_t profiles_count = 1U; |
Yuta Hijikata | 40b891d | 2020-11-27 09:05:01 | [diff] [blame] | 214 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 215 | // Chrome OS uses system tray menu to handle multi-profiles. |
| 216 | enabled = false; |
Pavol Marko | 56df027 | 2018-07-04 17:55:04 | [diff] [blame] | 217 | profiles_count = 2U; |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 218 | #endif |
| 219 | |
Pavol Marko | 56df027 | 2018-07-04 17:55:04 | [diff] [blame] | 220 | ASSERT_EQ(profiles_count, profile_manager->GetNumberOfProfiles()); |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 221 | EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 222 | |
Evan Stade | ef1543f | 2017-11-17 20:20:13 | [diff] [blame] | 223 | testing_profile_manager->CreateTestingProfile("p2"); |
Pavol Marko | 56df027 | 2018-07-04 17:55:04 | [diff] [blame] | 224 | profiles_count++; |
| 225 | ASSERT_EQ(profiles_count, profile_manager->GetNumberOfProfiles()); |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 226 | EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 227 | |
Evan Stade | ef1543f | 2017-11-17 20:20:13 | [diff] [blame] | 228 | testing_profile_manager->DeleteTestingProfile("p2"); |
Pavol Marko | 56df027 | 2018-07-04 17:55:04 | [diff] [blame] | 229 | profiles_count--; |
| 230 | ASSERT_EQ(profiles_count, profile_manager->GetNumberOfProfiles()); |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 231 | EXPECT_EQ(enabled, command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
[email protected] | 557c4e2 | 2012-12-18 18:30:55 | [diff] [blame] | 232 | } |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 233 | |
Ramin Halavati | f362b7a | 2019-04-17 05:24:50 | [diff] [blame] | 234 | TEST_F(BrowserCommandControllerTest, AvatarMenuAlwaysEnabledInIncognitoMode) { |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 235 | // Set up a profile with an off the record profile. |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 236 | TestingProfile::Builder normal_builder; |
dcheng | 9603ab9 | 2016-04-08 04:17:32 | [diff] [blame] | 237 | std::unique_ptr<TestingProfile> original_profile = normal_builder.Build(); |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 238 | |
| 239 | // Create a new browser based on the off the record profile. |
Ramin Halavati | 94e45727 | 2021-04-13 12:27:51 | [diff] [blame] | 240 | Browser::CreateParams profile_params( |
| 241 | original_profile->GetPrimaryOTRProfile(/*create_if_needed=*/true), true); |
dcheng | 9603ab9 | 2016-04-08 04:17:32 | [diff] [blame] | 242 | std::unique_ptr<Browser> otr_browser( |
Charles Zhao | fa60293 | 2020-10-21 01:38:55 | [diff] [blame] | 243 | CreateBrowserWithTestWindowForParams(profile_params)); |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 244 | |
[email protected] | 338416c0 | 2014-05-13 16:47:06 | [diff] [blame] | 245 | chrome::BrowserCommandController command_controller(otr_browser.get()); |
Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 246 | const CommandUpdater* command_updater = &command_controller; |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 247 | |
Ramin Halavati | f362b7a | 2019-04-17 05:24:50 | [diff] [blame] | 248 | // The avatar menu should be enabled. |
| 249 | EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 250 | // The command line is reset at the end of every test by the test suite. |
[email protected] | e9476cd | 2013-12-04 05:55:34 | [diff] [blame] | 251 | } |
| 252 | |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 253 | ////////////////////////////////////////////////////////////////////////////// |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 254 | class BrowserCommandControllerFullscreenTest; |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 255 | |
| 256 | // A test browser window that can toggle fullscreen state. |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 257 | class FullscreenTestBrowserWindow : public TestBrowserWindow, |
| 258 | ExclusiveAccessContext { |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 259 | public: |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 260 | FullscreenTestBrowserWindow( |
| 261 | BrowserCommandControllerFullscreenTest* test_browser) |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 262 | : fullscreen_(false), |
| 263 | toolbar_showing_(false), |
| 264 | test_browser_(test_browser) {} |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 265 | |
dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 266 | ~FullscreenTestBrowserWindow() override {} |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 267 | |
| 268 | // TestBrowserWindow overrides: |
dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 269 | bool ShouldHideUIForFullscreen() const override { return fullscreen_; } |
| 270 | bool IsFullscreen() const override { return fullscreen_; } |
| 271 | void EnterFullscreen(const GURL& url, |
Mike Wasserman | 854c948 | 2019-12-20 18:17:19 | [diff] [blame] | 272 | ExclusiveAccessBubbleType type, |
| 273 | int64_t display_id) override { |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 274 | fullscreen_ = true; |
| 275 | } |
dcheng | 5dd5ff6 | 2014-10-21 12:42:38 | [diff] [blame] | 276 | void ExitFullscreen() override { fullscreen_ = false; } |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 277 | bool IsToolbarShowing() const override { return toolbar_showing_; } |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 278 | |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 279 | ExclusiveAccessContext* GetExclusiveAccessContext() override { return this; } |
| 280 | |
| 281 | // Exclusive access interface: |
| 282 | Profile* GetProfile() override; |
| 283 | content::WebContents* GetActiveWebContents() override; |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 284 | void UpdateExclusiveAccessExitBubbleContent( |
| 285 | const GURL& url, |
Chong Zhang | 7a437eb | 2017-08-04 16:13:47 | [diff] [blame] | 286 | ExclusiveAccessBubbleType bubble_type, |
Joe Downing | 64999bc2 | 2018-05-01 04:43:00 | [diff] [blame] | 287 | ExclusiveAccessBubbleHideCallback bubble_first_hide_callback, |
| 288 | bool force_update) override {} |
mgiuca | 6fb1463 | 2015-12-08 03:59:47 | [diff] [blame] | 289 | void OnExclusiveAccessUserInput() override {} |
Ivan Sandrk | 29a551c | 2018-10-11 19:08:49 | [diff] [blame] | 290 | bool CanUserExitFullscreen() const override { return true; } |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 291 | |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 292 | void set_toolbar_showing(bool showing) { toolbar_showing_ = showing; } |
| 293 | |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 294 | private: |
| 295 | bool fullscreen_; |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 296 | bool toolbar_showing_; |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 297 | BrowserCommandControllerFullscreenTest* test_browser_; |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 298 | |
| 299 | DISALLOW_COPY_AND_ASSIGN(FullscreenTestBrowserWindow); |
| 300 | }; |
| 301 | |
| 302 | // Test that uses FullscreenTestBrowserWindow for its window. |
| 303 | class BrowserCommandControllerFullscreenTest |
Ramin Halavati | b2af10a | 2021-07-05 05:49:42 | [diff] [blame] | 304 | : public BrowserWithTestWindowTest { |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 305 | public: |
Ramin Halavati | b2af10a | 2021-07-05 05:49:42 | [diff] [blame] | 306 | BrowserCommandControllerFullscreenTest() = default; |
Ramin Halavati | 3c7580a | 2020-11-05 06:35:42 | [diff] [blame] | 307 | ~BrowserCommandControllerFullscreenTest() override = default; |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 308 | |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 309 | Browser* GetBrowser() { return BrowserWithTestWindowTest::browser(); } |
| 310 | |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 311 | // BrowserWithTestWindowTest overrides: |
Alan Screen | 189db68 | 2019-04-18 18:19:23 | [diff] [blame] | 312 | std::unique_ptr<BrowserWindow> CreateBrowserWindow() override { |
| 313 | return std::make_unique<FullscreenTestBrowserWindow>(this); |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | private: |
| 317 | DISALLOW_COPY_AND_ASSIGN(BrowserCommandControllerFullscreenTest); |
| 318 | }; |
| 319 | |
sriramsr | 39b6b787 | 2015-03-04 00:03:32 | [diff] [blame] | 320 | Profile* FullscreenTestBrowserWindow::GetProfile() { |
| 321 | return test_browser_->GetBrowser()->profile(); |
| 322 | } |
| 323 | |
| 324 | content::WebContents* FullscreenTestBrowserWindow::GetActiveWebContents() { |
| 325 | return test_browser_->GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
| 326 | } |
| 327 | |
Ramin Halavati | b2af10a | 2021-07-05 05:49:42 | [diff] [blame] | 328 | TEST_F(BrowserCommandControllerFullscreenTest, |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 329 | UpdateCommandsForFullscreenMode) { |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 330 | struct { |
| 331 | int command_id; |
| 332 | // Whether the command is enabled in tab mode. |
| 333 | bool enabled_in_tab; |
| 334 | // Whether the keyboard shortcut is reserved in tab mode. |
| 335 | bool reserved_in_tab; |
| 336 | // Whether the command is enabled in fullscreen mode. |
| 337 | bool enabled_in_fullscreen; |
| 338 | // Whether the keyboard shortcut is reserved in fullscreen mode. |
| 339 | bool reserved_in_fullscreen; |
| 340 | } commands[] = { |
| 341 | // 1. Most commands are disabled in fullscreen. |
| 342 | // 2. In fullscreen, only the exit fullscreen commands are reserved. All |
| 343 | // other shortcuts should be delivered to the web page. See |
| 344 | // http://crbug.com/680809. |
| 345 | |
| 346 | // Command ID | tab mode | fullscreen | |
| 347 | // | enabled | reserved | enabled | reserved | |
Mihai Sardarescu | 290bc88 | 2018-10-12 10:48:14 | [diff] [blame] | 348 | // clang-format off |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 349 | { IDC_OPEN_CURRENT_URL, true, false, false, false }, |
| 350 | { IDC_FOCUS_TOOLBAR, true, false, false, false }, |
| 351 | { IDC_FOCUS_LOCATION, true, false, false, false }, |
| 352 | { IDC_FOCUS_SEARCH, true, false, false, false }, |
| 353 | { IDC_FOCUS_MENU_BAR, true, false, false, false }, |
| 354 | { IDC_FOCUS_NEXT_PANE, true, false, false, false }, |
| 355 | { IDC_FOCUS_PREVIOUS_PANE, true, false, false, false }, |
| 356 | { IDC_FOCUS_BOOKMARKS, true, false, false, false }, |
| 357 | { IDC_DEVELOPER_MENU, true, false, false, false }, |
Nico Weber | 0cc7112 | 2019-07-29 17:30:40 | [diff] [blame] | 358 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 359 | { IDC_FEEDBACK, true, false, false, false }, |
[email protected] | 236ad302 | 2013-09-04 03:27:43 | [diff] [blame] | 360 | #endif |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 361 | { IDC_OPTIONS, true, false, false, false }, |
| 362 | { IDC_IMPORT_SETTINGS, true, false, false, false }, |
| 363 | { IDC_EDIT_SEARCH_ENGINES, true, false, false, false }, |
| 364 | { IDC_VIEW_PASSWORDS, true, false, false, false }, |
| 365 | { IDC_ABOUT, true, false, false, false }, |
| 366 | { IDC_SHOW_APP_MENU, true, false, false, false }, |
Tina Wang | f09681ac | 2019-03-27 20:52:10 | [diff] [blame] | 367 | { IDC_SEND_TAB_TO_SELF, true, false, false, false }, |
Tina Wang | fa01699 | 2019-05-31 00:01:15 | [diff] [blame] | 368 | { IDC_SEND_TAB_TO_SELF_SINGLE_TARGET, |
| 369 | true, false, false, false }, |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 370 | { IDC_FULLSCREEN, true, false, true, true }, |
| 371 | { IDC_CLOSE_TAB, true, true, true, false }, |
| 372 | { IDC_CLOSE_WINDOW, true, true, true, false }, |
| 373 | { IDC_NEW_INCOGNITO_WINDOW, true, true, true, false }, |
| 374 | { IDC_NEW_TAB, true, true, true, false }, |
| 375 | { IDC_NEW_WINDOW, true, true, true, false }, |
| 376 | { IDC_SELECT_NEXT_TAB, true, true, true, false }, |
| 377 | { IDC_SELECT_PREVIOUS_TAB, true, true, true, false }, |
| 378 | { IDC_EXIT, true, true, true, true }, |
| 379 | { IDC_SHOW_AS_TAB, false, false, false, false }, |
Mihai Sardarescu | 290bc88 | 2018-10-12 10:48:14 | [diff] [blame] | 380 | { IDC_SHOW_SIGNIN, true, false, true, false }, |
| 381 | // clang-format on |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 382 | }; |
| 383 | const content::NativeWebKeyboardEvent key_event( |
Dave Tapuska | b99c733 | 2020-04-22 02:14:18 | [diff] [blame] | 384 | blink::WebInputEvent::Type::kUndefined, 0, |
Daniel Cheng | 224569ee | 2018-04-25 05:45:06 | [diff] [blame] | 385 | blink::WebInputEvent::GetStaticTimeStampForTests()); |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 386 | // Defaults for a tabbed browser. |
Avi Drissman | 22f8287 | 2018-12-25 23:09:07 | [diff] [blame] | 387 | for (size_t i = 0; i < base::size(commands); i++) { |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 388 | SCOPED_TRACE(commands[i].command_id); |
| 389 | EXPECT_EQ(chrome::IsCommandEnabled(browser(), commands[i].command_id), |
| 390 | commands[i].enabled_in_tab); |
| 391 | EXPECT_EQ(browser()->command_controller()->IsReservedCommandOrKey( |
| 392 | commands[i].command_id, key_event), |
| 393 | commands[i].reserved_in_tab); |
| 394 | } |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 395 | |
| 396 | // Simulate going fullscreen. |
| 397 | chrome::ToggleFullscreenMode(browser()); |
| 398 | ASSERT_TRUE(browser()->window()->IsFullscreen()); |
| 399 | browser()->command_controller()->FullscreenStateChanged(); |
[email protected] | 0d7717fa | 2013-03-19 22:06:20 | [diff] [blame] | 400 | |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 401 | // By default, in fullscreen mode, the toolbar should be hidden; and all |
| 402 | // platforms behave similarly. |
| 403 | EXPECT_FALSE(window()->IsToolbarShowing()); |
Avi Drissman | 22f8287 | 2018-12-25 23:09:07 | [diff] [blame] | 404 | for (size_t i = 0; i < base::size(commands); i++) { |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 405 | SCOPED_TRACE(commands[i].command_id); |
| 406 | EXPECT_EQ(chrome::IsCommandEnabled(browser(), commands[i].command_id), |
| 407 | commands[i].enabled_in_fullscreen); |
| 408 | EXPECT_EQ(browser()->command_controller()->IsReservedCommandOrKey( |
| 409 | commands[i].command_id, key_event), |
| 410 | commands[i].reserved_in_fullscreen); |
| 411 | } |
zijiehe | 3c7af99 | 2017-02-12 20:59:40 | [diff] [blame] | 412 | |
Avi Drissman | 73ea864 | 2020-07-29 19:56:15 | [diff] [blame] | 413 | #if defined(OS_MAC) |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 414 | // When the toolbar is showing, commands should be reserved as if the content |
| 415 | // were in a tab; IDC_FULLSCREEN should also be reserved. |
| 416 | static_cast<FullscreenTestBrowserWindow*>(window())->set_toolbar_showing( |
| 417 | true); |
zijiehe | e84b99c | 2017-03-25 04:46:35 | [diff] [blame] | 418 | EXPECT_TRUE(browser()->command_controller()->IsReservedCommandOrKey( |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 419 | IDC_FULLSCREEN, key_event)); |
Avi Drissman | 22f8287 | 2018-12-25 23:09:07 | [diff] [blame] | 420 | for (size_t i = 0; i < base::size(commands); i++) { |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 421 | if (commands[i].command_id != IDC_FULLSCREEN) { |
| 422 | SCOPED_TRACE(commands[i].command_id); |
| 423 | EXPECT_EQ(browser()->command_controller()->IsReservedCommandOrKey( |
| 424 | commands[i].command_id, key_event), |
| 425 | commands[i].reserved_in_tab); |
| 426 | } |
| 427 | } |
| 428 | // Return to default state. |
| 429 | static_cast<FullscreenTestBrowserWindow*>(window())->set_toolbar_showing( |
| 430 | false); |
| 431 | #endif |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 432 | |
| 433 | // Exit fullscreen. |
| 434 | chrome::ToggleFullscreenMode(browser()); |
| 435 | ASSERT_FALSE(browser()->window()->IsFullscreen()); |
| 436 | browser()->command_controller()->FullscreenStateChanged(); |
[email protected] | 90efc3e | 2014-04-22 18:39:03 | [diff] [blame] | 437 | |
Avi Drissman | 22f8287 | 2018-12-25 23:09:07 | [diff] [blame] | 438 | for (size_t i = 0; i < base::size(commands); i++) { |
zijiehe | 68cd3dc2 | 2017-04-07 18:50:29 | [diff] [blame] | 439 | SCOPED_TRACE(commands[i].command_id); |
| 440 | EXPECT_EQ(chrome::IsCommandEnabled(browser(), commands[i].command_id), |
| 441 | commands[i].enabled_in_tab); |
| 442 | EXPECT_EQ(browser()->command_controller()->IsReservedCommandOrKey( |
| 443 | commands[i].command_id, key_event), |
| 444 | commands[i].reserved_in_tab); |
| 445 | } |
zijiehe | 1320780 | 2017-02-16 08:06:10 | [diff] [blame] | 446 | |
[email protected] | 90efc3e | 2014-04-22 18:39:03 | [diff] [blame] | 447 | // Guest Profiles disallow some options. |
| 448 | TestingProfile* testprofile = browser()->profile()->AsTestingProfile(); |
| 449 | EXPECT_TRUE(testprofile); |
| 450 | testprofile->SetGuestSession(true); |
| 451 | |
| 452 | browser()->command_controller()->FullscreenStateChanged(); |
[email protected] | 57b2529 | 2014-05-01 16:31:06 | [diff] [blame] | 453 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
| 454 | EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_IMPORT_SETTINGS)); |
[email protected] | 6a414ff | 2013-02-27 08:22:54 | [diff] [blame] | 455 | } |
estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 456 | |
zijiehe | db473d55 | 2017-02-24 01:13:41 | [diff] [blame] | 457 | // Ensure that the logic for enabling IDC_OPTIONS is consistent, regardless of |
| 458 | // the order of entering fullscreen and forced incognito modes. See |
| 459 | // http://crbug.com/694331. |
Ramin Halavati | b2af10a | 2021-07-05 05:49:42 | [diff] [blame] | 460 | TEST_F(BrowserWithTestWindowTest, OptionsConsistency) { |
zijiehe | db473d55 | 2017-02-24 01:13:41 | [diff] [blame] | 461 | TestingProfile* profile = browser()->profile()->AsTestingProfile(); |
| 462 | // Setup guest session. |
| 463 | profile->SetGuestSession(true); |
| 464 | // Setup forced incognito mode. |
| 465 | IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 466 | IncognitoModePrefs::FORCED); |
| 467 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
| 468 | // Enter fullscreen. |
| 469 | browser()->command_controller()->FullscreenStateChanged(); |
| 470 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
| 471 | // Exit fullscreen |
| 472 | browser()->command_controller()->FullscreenStateChanged(); |
| 473 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
| 474 | // Reenter incognito mode, this should trigger |
| 475 | // UpdateSharedCommandsForIncognitoAvailability() again. |
| 476 | IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 477 | IncognitoModePrefs::DISABLED); |
| 478 | IncognitoModePrefs::SetAvailability(browser()->profile()->GetPrefs(), |
| 479 | IncognitoModePrefs::FORCED); |
| 480 | EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPTIONS)); |
| 481 | } |
| 482 | |
Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 483 | TEST_F(BrowserCommandControllerTest, IncognitoModeOnSigninAllowedPrefChange) { |
estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 484 | // Set up a profile with an off the record profile. |
dcheng | 9603ab9 | 2016-04-08 04:17:32 | [diff] [blame] | 485 | std::unique_ptr<TestingProfile> profile1 = TestingProfile::Builder().Build(); |
Ramin Halavati | 94e45727 | 2021-04-13 12:27:51 | [diff] [blame] | 486 | Profile* profile2 = profile1->GetPrimaryOTRProfile(/*create_if_needed=*/true); |
estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 487 | |
| 488 | EXPECT_EQ(profile2->GetOriginalProfile(), profile1.get()); |
| 489 | |
| 490 | // Create a new browser based on the off the record profile. |
Ramin Halavati | 94e45727 | 2021-04-13 12:27:51 | [diff] [blame] | 491 | Browser::CreateParams profile_params( |
| 492 | profile1->GetPrimaryOTRProfile(/*create_if_needed=*/true), true); |
dcheng | 9603ab9 | 2016-04-08 04:17:32 | [diff] [blame] | 493 | std::unique_ptr<Browser> browser2( |
Charles Zhao | fa60293 | 2020-10-21 01:38:55 | [diff] [blame] | 494 | CreateBrowserWithTestWindowForParams(profile_params)); |
estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 495 | |
| 496 | chrome::BrowserCommandController command_controller(browser2.get()); |
Ivan Sandrk | 9669d0e | 2017-12-15 23:50:20 | [diff] [blame] | 497 | const CommandUpdater* command_updater = &command_controller; |
estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 498 | |
Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 499 | // Check that the SYNC_SETUP command is updated on preference change. |
Mihai Sardarescu | 290bc88 | 2018-10-12 10:48:14 | [diff] [blame] | 500 | EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SIGNIN)); |
Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 501 | profile1->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
Mihai Sardarescu | 290bc88 | 2018-10-12 10:48:14 | [diff] [blame] | 502 | EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SIGNIN)); |
Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) { |
| 506 | chrome::BrowserCommandController command_controller(browser()); |
| 507 | const CommandUpdater* command_updater = &command_controller; |
| 508 | |
| 509 | // Check that the SYNC_SETUP command is updated on preference change. |
Mihai Sardarescu | 290bc88 | 2018-10-12 10:48:14 | [diff] [blame] | 510 | EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SIGNIN)); |
Mihai Sardarescu | f87ccc1 | 2018-09-26 10:37:45 | [diff] [blame] | 511 | profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
Mihai Sardarescu | 290bc88 | 2018-10-12 10:48:14 | [diff] [blame] | 512 | EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SIGNIN)); |
estade | 8c0780f | 2015-08-21 23:36:41 | [diff] [blame] | 513 | } |
Ramin Halavati | 3c7580a | 2020-11-05 06:35:42 | [diff] [blame] | 514 | |
Rohit Agarwal | a14404f5 | 2021-06-14 11:50:44 | [diff] [blame] | 515 | class IncognitoClearBrowsingDataCommandTest |
| 516 | : public BrowserWithTestWindowTest, |
| 517 | public testing::WithParamInterface<bool> { |
| 518 | public: |
| 519 | IncognitoClearBrowsingDataCommandTest() { |
| 520 | if (GetParam()) { |
| 521 | scoped_feature_list_.InitAndEnableFeature( |
| 522 | features::kIncognitoClearBrowsingDataDialogForDesktop); |
| 523 | } else { |
| 524 | scoped_feature_list_.InitAndDisableFeature( |
| 525 | features::kIncognitoClearBrowsingDataDialogForDesktop); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | private: |
| 530 | base::test::ScopedFeatureList scoped_feature_list_; |
| 531 | }; |
| 532 | |
| 533 | INSTANTIATE_TEST_SUITE_P( |
| 534 | IncognitoClearBrowsingDataCommandTestWithFeatureFlag, |
| 535 | IncognitoClearBrowsingDataCommandTest, |
| 536 | /*should_show_cbd_option_in_incognito=*/testing::Bool()); |
| 537 | |
| 538 | TEST_P(IncognitoClearBrowsingDataCommandTest, |
| 539 | testClearBrowsingDataOptionStateInIncognito) { |
| 540 | // Set up a profile with an off the record profile. |
| 541 | std::unique_ptr<TestingProfile> profile1 = TestingProfile::Builder().Build(); |
| 542 | Profile* incognito_profile = |
| 543 | profile1->GetPrimaryOTRProfile(/*create_if_needed=*/true); |
| 544 | EXPECT_EQ(incognito_profile->GetOriginalProfile(), profile1.get()); |
| 545 | |
| 546 | // Create a new browser based on the off the record profile. |
| 547 | Browser::CreateParams profile_params(incognito_profile, true); |
| 548 | std::unique_ptr<Browser> incognito_browser = |
| 549 | CreateBrowserWithTestWindowForParams(profile_params); |
| 550 | |
| 551 | chrome::BrowserCommandController command_controller(incognito_browser.get()); |
| 552 | bool should_show_cbd_option_in_incognito = GetParam(); |
| 553 | EXPECT_EQ(should_show_cbd_option_in_incognito, |
| 554 | command_controller.IsCommandEnabled(IDC_CLEAR_BROWSING_DATA)); |
| 555 | } |