| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 #include "chrome/browser/ui/browser.h" | 6 #include "chrome/browser/ui/browser.h" |
| 7 #include "chrome/browser/ui/browser_tabstrip.h" | 7 #include "chrome/browser/ui/browser_tabstrip.h" |
| 8 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 8 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
| 9 #include "chrome/browser/ui/fullscreen/fullscreen_controller_state_test.h" | 9 #include "chrome/browser/ui/fullscreen/fullscreen_controller_state_test.h" |
| 10 #include "chrome/test/base/browser_with_test_window_test.h" | 10 #include "chrome/test/base/browser_with_test_window_test.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 virtual void EnterFullscreen(const GURL& url, | 44 virtual void EnterFullscreen(const GURL& url, |
| 45 FullscreenExitBubbleType type) OVERRIDE; | 45 FullscreenExitBubbleType type) OVERRIDE; |
| 46 virtual void EnterFullscreen(); | 46 virtual void EnterFullscreen(); |
| 47 virtual void ExitFullscreen() OVERRIDE; | 47 virtual void ExitFullscreen() OVERRIDE; |
| 48 virtual bool IsFullscreen() const OVERRIDE; | 48 virtual bool IsFullscreen() const OVERRIDE; |
| 49 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
| 50 virtual void SetMetroSnapMode(bool enable) OVERRIDE; | 50 virtual void SetMetroSnapMode(bool enable) OVERRIDE; |
| 51 virtual bool IsInMetroSnapMode() const OVERRIDE; | 51 virtual bool IsInMetroSnapMode() const OVERRIDE; |
| 52 #endif | 52 #endif |
| 53 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
| 54 virtual void EnterPresentationMode( | 54 virtual void EnterFullscreenWithChrome( |
| 55 const GURL& url, | 55 const GURL& url, |
| 56 FullscreenExitBubbleType bubble_type) OVERRIDE; | 56 FullscreenExitBubbleType bubble_type) OVERRIDE; |
| 57 virtual void ExitPresentationMode() OVERRIDE; | 57 virtual bool IsFullscreenWithChrome() OVERRIDE; |
| 58 virtual bool InPresentationMode() OVERRIDE; | 58 virtual bool IsFullscreenWithoutChrome() OVERRIDE; |
| 59 #endif | 59 #endif |
| 60 | 60 |
| 61 static const char* GetWindowStateString(WindowState state); | 61 static const char* GetWindowStateString(WindowState state); |
| 62 WindowState state() const { return state_; } | 62 WindowState state() const { return state_; } |
| 63 void set_browser(Browser* browser) { browser_ = browser; } | 63 void set_browser(Browser* browser) { browser_ = browser; } |
| 64 void set_reentrant(bool value) { reentrant_ = value; } | 64 void set_reentrant(bool value) { reentrant_ = value; } |
| 65 bool reentrant() const { return reentrant_; } | 65 bool reentrant() const { return reentrant_; } |
| 66 | 66 |
| 67 // Simulates the window changing state. | 67 // Simulates the window changing state. |
| 68 void ChangeWindowFullscreenState(); | 68 void ChangeWindowFullscreenState(); |
| 69 // Calls ChangeWindowFullscreenState() if |reentrant_| is true. | 69 // Calls ChangeWindowFullscreenState() if |reentrant_| is true. |
| 70 void ChangeWindowFullscreenStateIfReentrant(); | 70 void ChangeWindowFullscreenStateIfReentrant(); |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 WindowState state_; | 73 WindowState state_; |
| 74 bool mac_presentation_mode_; | 74 bool mac_with_chrome_mode_; |
| 75 Browser* browser_; | 75 Browser* browser_; |
| 76 | 76 |
| 77 // Causes reentrant calls to be made by calling | 77 // Causes reentrant calls to be made by calling |
| 78 // browser_->WindowFullscreenStateChanged() from the BrowserWindow | 78 // browser_->WindowFullscreenStateChanged() from the BrowserWindow |
| 79 // interface methods. | 79 // interface methods. |
| 80 bool reentrant_; | 80 bool reentrant_; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 FullscreenControllerTestWindow::FullscreenControllerTestWindow() | 83 FullscreenControllerTestWindow::FullscreenControllerTestWindow() |
| 84 : state_(NORMAL), | 84 : state_(NORMAL), |
| 85 mac_presentation_mode_(false), | 85 mac_with_chrome_mode_(false), |
| 86 browser_(NULL), | 86 browser_(NULL), |
| 87 reentrant_(false) { | 87 reentrant_(false) { |
| 88 } | 88 } |
| 89 | 89 |
| 90 void FullscreenControllerTestWindow::EnterFullscreen( | 90 void FullscreenControllerTestWindow::EnterFullscreen( |
| 91 const GURL& url, FullscreenExitBubbleType type) { | 91 const GURL& url, FullscreenExitBubbleType type) { |
| 92 EnterFullscreen(); | 92 EnterFullscreen(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void FullscreenControllerTestWindow::EnterFullscreen() { | 95 void FullscreenControllerTestWindow::EnterFullscreen() { |
| 96 mac_with_chrome_mode_ = false; |
| 96 if (!IsFullscreen()) { | 97 if (!IsFullscreen()) { |
| 97 state_ = TO_FULLSCREEN; | 98 state_ = TO_FULLSCREEN; |
| 98 ChangeWindowFullscreenStateIfReentrant(); | 99 ChangeWindowFullscreenStateIfReentrant(); |
| 99 } | 100 } |
| 100 } | 101 } |
| 101 | 102 |
| 102 void FullscreenControllerTestWindow::ExitFullscreen() { | 103 void FullscreenControllerTestWindow::ExitFullscreen() { |
| 103 if (IsFullscreen()) { | 104 if (IsFullscreen()) { |
| 104 state_ = TO_NORMAL; | 105 state_ = TO_NORMAL; |
| 105 mac_presentation_mode_ = false; | 106 mac_with_chrome_mode_ = false; |
| 106 ChangeWindowFullscreenStateIfReentrant(); | 107 ChangeWindowFullscreenStateIfReentrant(); |
| 107 } | 108 } |
| 108 } | 109 } |
| 109 | 110 |
| 110 bool FullscreenControllerTestWindow::IsFullscreen() const { | 111 bool FullscreenControllerTestWindow::IsFullscreen() const { |
| 111 #if defined(OS_MACOSX) | 112 #if defined(OS_MACOSX) |
| 112 return state_ == FULLSCREEN || state_ == TO_FULLSCREEN; | 113 return state_ == FULLSCREEN || state_ == TO_FULLSCREEN; |
| 113 #else | 114 #else |
| 114 return state_ == FULLSCREEN || state_ == TO_NORMAL; | 115 return state_ == FULLSCREEN || state_ == TO_NORMAL; |
| 115 #endif | 116 #endif |
| 116 } | 117 } |
| 117 | 118 |
| 118 #if defined(OS_WIN) | 119 #if defined(OS_WIN) |
| 119 void FullscreenControllerTestWindow::SetMetroSnapMode(bool enable) { | 120 void FullscreenControllerTestWindow::SetMetroSnapMode(bool enable) { |
| 120 if (enable != IsInMetroSnapMode()) { | 121 if (enable != IsInMetroSnapMode()) { |
| 121 if (enable) | 122 if (enable) |
| 122 state_ = METRO_SNAP; | 123 state_ = METRO_SNAP; |
| 123 else | 124 else |
| 124 state_ = NORMAL; | 125 state_ = NORMAL; |
| 125 } | 126 } |
| 126 ChangeWindowFullscreenStateIfReentrant(); | 127 ChangeWindowFullscreenStateIfReentrant(); |
| 127 } | 128 } |
| 128 | 129 |
| 129 bool FullscreenControllerTestWindow::IsInMetroSnapMode() const { | 130 bool FullscreenControllerTestWindow::IsInMetroSnapMode() const { |
| 130 return state_ == METRO_SNAP; | 131 return state_ == METRO_SNAP; |
| 131 } | 132 } |
| 132 #endif | 133 #endif |
| 133 | 134 |
| 134 #if defined(OS_MACOSX) | 135 #if defined(OS_MACOSX) |
| 135 void FullscreenControllerTestWindow::EnterPresentationMode( | 136 void FullscreenControllerTestWindow::EnterFullscreenWithChrome( |
| 136 const GURL& url, | 137 const GURL& url, |
| 137 FullscreenExitBubbleType bubble_type) { | 138 FullscreenExitBubbleType bubble_type) { |
| 138 mac_presentation_mode_ = true; | |
| 139 EnterFullscreen(); | 139 EnterFullscreen(); |
| 140 mac_with_chrome_mode_ = true; |
| 140 } | 141 } |
| 141 | 142 |
| 142 void FullscreenControllerTestWindow::ExitPresentationMode() { | 143 bool FullscreenControllerTestWindow::IsFullscreenWithChrome() { |
| 143 if (InPresentationMode()) { | 144 return IsFullscreen() && mac_with_chrome_mode_; |
| 144 mac_presentation_mode_ = false; | |
| 145 ExitFullscreen(); | |
| 146 } | |
| 147 } | 145 } |
| 148 | 146 |
| 149 bool FullscreenControllerTestWindow::InPresentationMode() { | 147 bool FullscreenControllerTestWindow::IsFullscreenWithoutChrome() { |
| 150 return mac_presentation_mode_; | 148 return IsFullscreen() && !mac_with_chrome_mode_; |
| 151 } | 149 } |
| 152 #endif | 150 #endif |
| 153 | 151 |
| 154 // static | 152 // static |
| 155 const char* FullscreenControllerTestWindow::GetWindowStateString( | 153 const char* FullscreenControllerTestWindow::GetWindowStateString( |
| 156 WindowState state) { | 154 WindowState state) { |
| 157 switch (state) { | 155 switch (state) { |
| 158 case NORMAL: | 156 case NORMAL: |
| 159 return "NORMAL"; | 157 return "NORMAL"; |
| 160 case FULLSCREEN: | 158 case FULLSCREEN: |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 ASSERT_NO_FATAL_FAILURE(TestStateAndEvent(state, event, reentrant)) \ | 322 ASSERT_NO_FATAL_FAILURE(TestStateAndEvent(state, event, reentrant)) \ |
| 325 << GetAndClearDebugLog(); \ | 323 << GetAndClearDebugLog(); \ |
| 326 } | 324 } |
| 327 // Progress of tests can be examined by inserting the following line: | 325 // Progress of tests can be examined by inserting the following line: |
| 328 // LOG(INFO) << GetAndClearDebugLog(); } | 326 // LOG(INFO) << GetAndClearDebugLog(); } |
| 329 | 327 |
| 330 #define TEST_EVENT(state, event) \ | 328 #define TEST_EVENT(state, event) \ |
| 331 TEST_EVENT_INNER(state, event, false, ); \ | 329 TEST_EVENT_INNER(state, event, false, ); \ |
| 332 TEST_EVENT_INNER(state, event, true, _Reentrant); | 330 TEST_EVENT_INNER(state, event, true, _Reentrant); |
| 333 | 331 |
| 332 // Soak tests: |
| 333 |
| 334 // Tests all states with all permutations of multiple events to detect lingering |
| 335 // state issues that would bleed over to other states. |
| 336 // I.E. for each state test all combinations of events E1, E2, E3. |
| 337 // |
| 338 // This produces coverage for event sequences that may happen normally but |
| 339 // would not be exposed by traversing to each state via TransitionToState(). |
| 340 // TransitionToState() always takes the same path even when multiple paths |
| 341 // exist. |
| 342 TEST_F(FullscreenControllerStateUnitTest, TransitionsForEachState) { |
| 343 // A tab is needed for tab fullscreen. |
| 344 AddTab(browser(), GURL(chrome::kAboutBlankURL)); |
| 345 TestTransitionsForEachState(); |
| 346 // Progress of test can be examined via LOG(INFO) << GetAndClearDebugLog(); |
| 347 } |
| 348 |
| 349 |
| 334 // Individual tests for each pair of state and event: | 350 // Individual tests for each pair of state and event: |
| 335 | 351 |
| 336 TEST_EVENT(STATE_NORMAL, TOGGLE_FULLSCREEN); | 352 TEST_EVENT(STATE_NORMAL, TOGGLE_FULLSCREEN); |
| 337 TEST_EVENT(STATE_NORMAL, TAB_FULLSCREEN_TRUE); | 353 TEST_EVENT(STATE_NORMAL, TAB_FULLSCREEN_TRUE); |
| 338 TEST_EVENT(STATE_NORMAL, TAB_FULLSCREEN_FALSE); | 354 TEST_EVENT(STATE_NORMAL, TAB_FULLSCREEN_FALSE); |
| 339 #if defined(OS_WIN) | 355 #if defined(OS_WIN) |
| 340 TEST_EVENT(STATE_NORMAL, METRO_SNAP_TRUE); | 356 TEST_EVENT(STATE_NORMAL, METRO_SNAP_TRUE); |
| 341 TEST_EVENT(STATE_NORMAL, METRO_SNAP_FALSE); | 357 TEST_EVENT(STATE_NORMAL, METRO_SNAP_FALSE); |
| 342 #endif | 358 #endif |
| 343 TEST_EVENT(STATE_NORMAL, BUBBLE_EXIT_LINK); | 359 TEST_EVENT(STATE_NORMAL, BUBBLE_EXIT_LINK); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 ASSERT_NO_FATAL_FAILURE( | 471 ASSERT_NO_FATAL_FAILURE( |
| 456 TransitionToState(STATE_TO_TAB_FULLSCREEN)) | 472 TransitionToState(STATE_TO_TAB_FULLSCREEN)) |
| 457 << GetAndClearDebugLog(); | 473 << GetAndClearDebugLog(); |
| 458 | 474 |
| 459 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE)) << GetAndClearDebugLog(); | 475 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE)) << GetAndClearDebugLog(); |
| 460 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE)) << GetAndClearDebugLog(); | 476 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE)) << GetAndClearDebugLog(); |
| 461 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE)) << GetAndClearDebugLog(); | 477 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE)) << GetAndClearDebugLog(); |
| 462 #endif | 478 #endif |
| 463 } | 479 } |
| 464 | 480 |
| 465 // Soak tests: | |
| 466 | |
| 467 // Tests all states with all permutations of multiple events to detect lingering | |
| 468 // state issues that would bleed over to other states. | |
| 469 // I.E. for each state test all combinations of events E1, E2, E3. | |
| 470 // | |
| 471 // This produces coverage for event sequences that may happen normally but | |
| 472 // would not be exposed by traversing to each state via TransitionToState(). | |
| 473 // TransitionToState() always takes the same path even when multiple paths | |
| 474 // exist. | |
| 475 TEST_F(FullscreenControllerStateUnitTest, TransitionsForEachState) { | |
| 476 // A tab is needed for tab fullscreen. | |
| 477 AddTab(browser(), GURL(chrome::kAboutBlankURL)); | |
| 478 TestTransitionsForEachState(); | |
| 479 // Progress of test can be examined via LOG(INFO) << GetAndClearDebugLog(); | |
| 480 } | |
| 481 | |
| OLD | NEW |