Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: chrome/browser/ui/exclusive_access/fullscreen_controller_state_unittest.cc

Issue 877413004: Refactor away the Browser* dependency in exclusive_access (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix broken mac change Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "build/build_config.h" 6 #include "build/build_config.h"
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_tabstrip.h" 8 #include "chrome/browser/ui/browser_tabstrip.h"
9 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
9 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" 10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_state_test.h" 11 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_state_test.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/browser_with_test_window_test.h" 13 #include "chrome/test/base/browser_with_test_window_test.h"
13 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/url_constants.h" 15 #include "content/public/common/url_constants.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 // The FullscreenControllerStateUnitTest unit test suite exhastively tests 18 // The FullscreenControllerStateUnitTest unit test suite exhastively tests
18 // the FullscreenController through all permutations of events. The behavior 19 // the FullscreenController through all permutations of events. The behavior
19 // of the BrowserWindow is mocked via FullscreenControllerTestWindow. 20 // of the BrowserWindow is mocked via FullscreenControllerTestWindow.
20 21
21 22
22 // FullscreenControllerTestWindow ---------------------------------------------- 23 // FullscreenControllerTestWindow ----------------------------------------------
23 24
24 // A BrowserWindow used for testing FullscreenController. The behavior of this 25 // A BrowserWindow used for testing FullscreenController. The behavior of this
25 // mock is verfied manually by running FullscreenControllerStateInteractiveTest. 26 // mock is verfied manually by running FullscreenControllerStateInteractiveTest.
26 class FullscreenControllerTestWindow : public TestBrowserWindow { 27 class FullscreenControllerTestWindow : public TestBrowserWindow,
28 ExclusiveAccessContext {
27 public: 29 public:
28 // Simulate the window state with an enumeration. 30 // Simulate the window state with an enumeration.
29 enum WindowState { 31 enum WindowState {
30 NORMAL, 32 NORMAL,
31 FULLSCREEN, 33 FULLSCREEN,
32 // No TO_ state for METRO_SNAP, the windows implementation is synchronous. 34 // No TO_ state for METRO_SNAP, the windows implementation is synchronous.
33 METRO_SNAP, 35 METRO_SNAP,
34 TO_NORMAL, 36 TO_NORMAL,
35 TO_FULLSCREEN, 37 TO_FULLSCREEN,
36 }; 38 };
(...skipping 11 matching lines...) Expand all
48 bool SupportsFullscreenWithToolbar() const override; 50 bool SupportsFullscreenWithToolbar() const override;
49 void UpdateFullscreenWithToolbar(bool with_toolbar) override; 51 void UpdateFullscreenWithToolbar(bool with_toolbar) override;
50 bool IsFullscreenWithToolbar() const override; 52 bool IsFullscreenWithToolbar() const override;
51 #if defined(OS_WIN) 53 #if defined(OS_WIN)
52 virtual void SetMetroSnapMode(bool enable) override; 54 virtual void SetMetroSnapMode(bool enable) override;
53 virtual bool IsInMetroSnapMode() const override; 55 virtual bool IsInMetroSnapMode() const override;
54 #endif 56 #endif
55 static const char* GetWindowStateString(WindowState state); 57 static const char* GetWindowStateString(WindowState state);
56 WindowState state() const { return state_; } 58 WindowState state() const { return state_; }
57 void set_browser(Browser* browser) { browser_ = browser; } 59 void set_browser(Browser* browser) { browser_ = browser; }
60 ExclusiveAccessContext* GetExclusiveAccessContext() override;
61
62 // ExclusiveAccessContext Interface:
63 Profile* GetProfile() override;
64 content::WebContents* GetActiveWebContents() override;
65 void HideDownloadShelf() override;
66 void UnhideDownloadShelf() override;
67 void UpdateExclusiveAccessExitBubbleContent(
68 const GURL& url,
69 ExclusiveAccessBubbleType bubble_type) override;
58 70
59 // Simulates the window changing state. 71 // Simulates the window changing state.
60 void ChangeWindowFullscreenState(); 72 void ChangeWindowFullscreenState();
61 73
62 private: 74 private:
63 // Enters fullscreen with |new_mac_with_toolbar_mode|. 75 // Enters fullscreen with |new_mac_with_toolbar_mode|.
64 void EnterFullscreen(bool new_mac_with_toolbar_mode); 76 void EnterFullscreen(bool new_mac_with_toolbar_mode);
65 77
66 // Returns true if ChangeWindowFullscreenState() should be called as a result 78 // Returns true if ChangeWindowFullscreenState() should be called as a result
67 // of updating the current fullscreen state to the passed in state. 79 // of updating the current fullscreen state to the passed in state.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 return true; 210 return true;
199 211
200 // BrowserWindowCocoa::EnterFullscreen() and 212 // BrowserWindowCocoa::EnterFullscreen() and
201 // BrowserWindowCocoa::EnterFullscreenWithToolbar() are reentrant when 213 // BrowserWindowCocoa::EnterFullscreenWithToolbar() are reentrant when
202 // switching between fullscreen with chrome and fullscreen without chrome. 214 // switching between fullscreen with chrome and fullscreen without chrome.
203 return state_ == FULLSCREEN && 215 return state_ == FULLSCREEN &&
204 !fullscreen_changed && 216 !fullscreen_changed &&
205 mac_with_toolbar_mode_changed; 217 mac_with_toolbar_mode_changed;
206 } 218 }
207 219
220 ExclusiveAccessContext*
221 FullscreenControllerTestWindow::GetExclusiveAccessContext() {
222 return this;
223 }
224
225 Profile* FullscreenControllerTestWindow::GetProfile() {
226 return browser_->profile();
227 }
228
229 content::WebContents* FullscreenControllerTestWindow::GetActiveWebContents() {
230 return browser_->tab_strip_model()->GetActiveWebContents();
231 }
232
233 void FullscreenControllerTestWindow::UnhideDownloadShelf() {
234 GetDownloadShelf()->Unhide();
235 }
236
237 void FullscreenControllerTestWindow::HideDownloadShelf() {
238 GetDownloadShelf()->Hide();
239 }
240
241 void FullscreenControllerTestWindow::UpdateExclusiveAccessExitBubbleContent(
242 const GURL& url,
243 ExclusiveAccessBubbleType bubble_type) {
244 TestBrowserWindow::UpdateExclusiveAccessExitBubbleContent(url, bubble_type);
245 }
208 246
209 // FullscreenControllerStateUnitTest ------------------------------------------- 247 // FullscreenControllerStateUnitTest -------------------------------------------
210 248
211 // Unit test fixture testing Fullscreen Controller through its states. Most of 249 // Unit test fixture testing Fullscreen Controller through its states. Most of
212 // the test logic comes from FullscreenControllerStateTest. 250 // the test logic comes from FullscreenControllerStateTest.
213 class FullscreenControllerStateUnitTest : public BrowserWithTestWindowTest, 251 class FullscreenControllerStateUnitTest : public BrowserWithTestWindowTest,
214 public FullscreenControllerStateTest { 252 public FullscreenControllerStateTest {
215 public: 253 public:
216 FullscreenControllerStateUnitTest(); 254 FullscreenControllerStateUnitTest();
217 255
218 // FullscreenControllerStateTest: 256 // FullscreenControllerStateTest:
219 void SetUp() override; 257 void SetUp() override;
220 BrowserWindow* CreateBrowserWindow() override; 258 BrowserWindow* CreateBrowserWindow() override;
221 void ChangeWindowFullscreenState() override; 259 void ChangeWindowFullscreenState() override;
222 const char* GetWindowStateString() override; 260 const char* GetWindowStateString() override;
223 void VerifyWindowState() override; 261 void VerifyWindowState() override;
224 262
225 protected: 263 protected:
226 // FullscreenControllerStateTest: 264 // FullscreenControllerStateTest:
227 bool ShouldSkipStateAndEventPair(State state, Event event) override; 265 bool ShouldSkipStateAndEventPair(State state, Event event) override;
228 Browser* GetBrowser() override; 266 Browser* GetBrowser() override;
229 FullscreenControllerTestWindow* window_; 267 FullscreenControllerTestWindow* window_;
230 }; 268 };
231 269
232 FullscreenControllerStateUnitTest::FullscreenControllerStateUnitTest () 270 FullscreenControllerStateUnitTest::FullscreenControllerStateUnitTest()
233 : window_(NULL) { 271 : window_(NULL) {
234 } 272 }
235 273
236 void FullscreenControllerStateUnitTest::SetUp() { 274 void FullscreenControllerStateUnitTest::SetUp() {
237 BrowserWithTestWindowTest::SetUp(); 275 BrowserWithTestWindowTest::SetUp();
238 window_->set_browser(browser()); 276 window_->set_browser(browser());
239 } 277 }
240 278
241 BrowserWindow* FullscreenControllerStateUnitTest::CreateBrowserWindow() { 279 BrowserWindow* FullscreenControllerStateUnitTest::CreateBrowserWindow() {
242 window_ = new FullscreenControllerTestWindow(); 280 window_ = new FullscreenControllerTestWindow();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 #endif 347 #endif
310 348
311 return FullscreenControllerStateTest::ShouldSkipStateAndEventPair(state, 349 return FullscreenControllerStateTest::ShouldSkipStateAndEventPair(state,
312 event); 350 event);
313 } 351 }
314 352
315 Browser* FullscreenControllerStateUnitTest::GetBrowser() { 353 Browser* FullscreenControllerStateUnitTest::GetBrowser() {
316 return BrowserWithTestWindowTest::browser(); 354 return BrowserWithTestWindowTest::browser();
317 } 355 }
318 356
319
320 // Soak tests ------------------------------------------------------------------ 357 // Soak tests ------------------------------------------------------------------
321 358
322 // Tests all states with all permutations of multiple events to detect lingering 359 // Tests all states with all permutations of multiple events to detect lingering
323 // state issues that would bleed over to other states. 360 // state issues that would bleed over to other states.
324 // I.E. for each state test all combinations of events E1, E2, E3. 361 // I.E. for each state test all combinations of events E1, E2, E3.
325 // 362 //
326 // This produces coverage for event sequences that may happen normally but 363 // This produces coverage for event sequences that may happen normally but
327 // would not be exposed by traversing to each state via TransitionToState(). 364 // would not be exposed by traversing to each state via TransitionToState().
328 // TransitionToState() always takes the same path even when multiple paths 365 // TransitionToState() always takes the same path even when multiple paths
329 // exist. 366 // exist.
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(tab)); 827 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(tab));
791 EXPECT_FALSE(second_wc_delegate->IsFullscreenForTabOrPending(tab)); 828 EXPECT_FALSE(second_wc_delegate->IsFullscreenForTabOrPending(tab));
792 EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending()); 829 EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
793 EXPECT_FALSE(second_browser->exclusive_access_manager() 830 EXPECT_FALSE(second_browser->exclusive_access_manager()
794 ->fullscreen_controller() 831 ->fullscreen_controller()
795 ->IsWindowFullscreenForTabOrPending()); 832 ->IsWindowFullscreenForTabOrPending());
796 833
797 // Required tear-down specific to this test. 834 // Required tear-down specific to this test.
798 second_browser->tab_strip_model()->CloseAllTabs(); 835 second_browser->tab_strip_model()->CloseAllTabs();
799 } 836 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698