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/browser/ui/exclusive_access/exclusive_access_context.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
19 #include "chrome/test/base/browser_with_test_window_test.h" | 21 #include "chrome/test/base/browser_with_test_window_test.h" |
20 #include "chrome/test/base/test_browser_window.h" | 22 #include "chrome/test/base/test_browser_window.h" |
21 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
22 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
23 #include "chrome/test/base/testing_profile_manager.h" | 25 #include "chrome/test/base/testing_profile_manager.h" |
24 #include "components/signin/core/common/profile_management_switches.h" | 26 #include "components/signin/core/common/profile_management_switches.h" |
25 #include "content/public/browser/native_web_keyboard_event.h" | 27 #include "content/public/browser/native_web_keyboard_event.h" |
26 #include "ui/events/keycodes/keyboard_codes.h" | 28 #include "ui/events/keycodes/keyboard_codes.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 base::CommandLine::ForCurrentProcess()); | 262 base::CommandLine::ForCurrentProcess()); |
261 } else { | 263 } else { |
262 switches::EnableNewAvatarMenuForTesting( | 264 switches::EnableNewAvatarMenuForTesting( |
263 base::CommandLine::ForCurrentProcess()); | 265 base::CommandLine::ForCurrentProcess()); |
264 } | 266 } |
265 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | 267 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); |
266 // The command line is reset at the end of every test by the test suite. | 268 // The command line is reset at the end of every test by the test suite. |
267 } | 269 } |
268 | 270 |
269 ////////////////////////////////////////////////////////////////////////////// | 271 ////////////////////////////////////////////////////////////////////////////// |
| 272 class BrowserCommandControllerFullscreenTest; |
270 | 273 |
271 // A test browser window that can toggle fullscreen state. | 274 // A test browser window that can toggle fullscreen state. |
272 class FullscreenTestBrowserWindow : public TestBrowserWindow { | 275 class FullscreenTestBrowserWindow : public TestBrowserWindow, |
| 276 ExclusiveAccessContext { |
273 public: | 277 public: |
274 FullscreenTestBrowserWindow() : fullscreen_(false) {} | 278 FullscreenTestBrowserWindow( |
| 279 BrowserCommandControllerFullscreenTest* test_browser) |
| 280 : fullscreen_(false), test_browser_(test_browser) {} |
| 281 |
275 ~FullscreenTestBrowserWindow() override {} | 282 ~FullscreenTestBrowserWindow() override {} |
276 | 283 |
277 // TestBrowserWindow overrides: | 284 // TestBrowserWindow overrides: |
278 bool ShouldHideUIForFullscreen() const override { return fullscreen_; } | 285 bool ShouldHideUIForFullscreen() const override { return fullscreen_; } |
279 bool IsFullscreen() const override { return fullscreen_; } | 286 bool IsFullscreen() const override { return fullscreen_; } |
280 void EnterFullscreen(const GURL& url, | 287 void EnterFullscreen(const GURL& url, |
281 ExclusiveAccessBubbleType type, | 288 ExclusiveAccessBubbleType type, |
282 bool with_toolbar) override { | 289 bool with_toolbar) override { |
283 fullscreen_ = true; | 290 fullscreen_ = true; |
284 } | 291 } |
285 void ExitFullscreen() override { fullscreen_ = false; } | 292 void ExitFullscreen() override { fullscreen_ = false; } |
286 | 293 |
| 294 ExclusiveAccessContext* GetExclusiveAccessContext() override { return this; } |
| 295 |
| 296 // Exclusive access interface: |
| 297 Profile* GetProfile() override; |
| 298 content::WebContents* GetActiveWebContents() override; |
| 299 void HideDownloadShelf() override {} |
| 300 void UnhideDownloadShelf() override {} |
| 301 void UpdateExclusiveAccessExitBubbleContent( |
| 302 const GURL& url, |
| 303 ExclusiveAccessBubbleType bubble_type) override {} |
| 304 bool IsFullscreenWithToolbar() const override { return IsFullscreen(); } |
| 305 |
287 private: | 306 private: |
288 bool fullscreen_; | 307 bool fullscreen_; |
| 308 BrowserCommandControllerFullscreenTest* test_browser_; |
289 | 309 |
290 DISALLOW_COPY_AND_ASSIGN(FullscreenTestBrowserWindow); | 310 DISALLOW_COPY_AND_ASSIGN(FullscreenTestBrowserWindow); |
291 }; | 311 }; |
292 | 312 |
293 // Test that uses FullscreenTestBrowserWindow for its window. | 313 // Test that uses FullscreenTestBrowserWindow for its window. |
294 class BrowserCommandControllerFullscreenTest | 314 class BrowserCommandControllerFullscreenTest |
295 : public BrowserWithTestWindowTest { | 315 : public BrowserWithTestWindowTest { |
296 public: | 316 public: |
297 BrowserCommandControllerFullscreenTest() {} | 317 BrowserCommandControllerFullscreenTest() {} |
298 ~BrowserCommandControllerFullscreenTest() override {} | 318 ~BrowserCommandControllerFullscreenTest() override {} |
299 | 319 |
| 320 Browser* GetBrowser() { return BrowserWithTestWindowTest::browser(); } |
| 321 |
300 // BrowserWithTestWindowTest overrides: | 322 // BrowserWithTestWindowTest overrides: |
301 BrowserWindow* CreateBrowserWindow() override { | 323 BrowserWindow* CreateBrowserWindow() override { |
302 return new FullscreenTestBrowserWindow; | 324 return new FullscreenTestBrowserWindow(this); |
303 } | 325 } |
304 | 326 |
305 private: | 327 private: |
306 DISALLOW_COPY_AND_ASSIGN(BrowserCommandControllerFullscreenTest); | 328 DISALLOW_COPY_AND_ASSIGN(BrowserCommandControllerFullscreenTest); |
307 }; | 329 }; |
308 | 330 |
| 331 Profile* FullscreenTestBrowserWindow::GetProfile() { |
| 332 return test_browser_->GetBrowser()->profile(); |
| 333 } |
| 334 |
| 335 content::WebContents* FullscreenTestBrowserWindow::GetActiveWebContents() { |
| 336 return test_browser_->GetBrowser()->tab_strip_model()->GetActiveWebContents(); |
| 337 } |
| 338 |
309 TEST_F(BrowserCommandControllerFullscreenTest, | 339 TEST_F(BrowserCommandControllerFullscreenTest, |
310 UpdateCommandsForFullscreenMode) { | 340 UpdateCommandsForFullscreenMode) { |
311 // Defaults for a tabbed browser. | 341 // Defaults for a tabbed browser. |
312 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL)); | 342 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_OPEN_CURRENT_URL)); |
313 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB)); | 343 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_SHOW_AS_TAB)); |
314 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR)); | 344 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_TOOLBAR)); |
315 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION)); | 345 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_LOCATION)); |
316 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH)); | 346 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_SEARCH)); |
317 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR)); | 347 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_MENU_BAR)); |
318 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE)); | 348 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FOCUS_NEXT_PANE)); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 | 446 |
417 TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) { | 447 TEST_F(BrowserCommandControllerTest, OnSigninAllowedPrefChange) { |
418 chrome::BrowserCommandController command_controller(browser()); | 448 chrome::BrowserCommandController command_controller(browser()); |
419 const CommandUpdater* command_updater = command_controller.command_updater(); | 449 const CommandUpdater* command_updater = command_controller.command_updater(); |
420 | 450 |
421 // Check that the SYNC_SETUP command is updated on preference change. | 451 // Check that the SYNC_SETUP command is updated on preference change. |
422 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 452 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
423 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); | 453 profile()->GetPrefs()->SetBoolean(prefs::kSigninAllowed, false); |
424 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); | 454 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_SYNC_SETUP)); |
425 } | 455 } |
OLD | NEW |