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