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

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

Issue 1488653002: Fix scroll restoration when exiting fullscreen mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from scheib@ Created 4 years, 11 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/exclusive_access_context.h"
10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" 10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
11 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_state_test.h" 11 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_state_test.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/test/base/browser_with_test_window_test.h" 13 #include "chrome/test/base/browser_with_test_window_test.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/url_constants.h" 15 #include "content/public/common/url_constants.h"
16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 // The FullscreenControllerStateUnitTest unit test suite exhastively tests 19 // The FullscreenControllerStateUnitTest unit test suite exhastively tests
19 // the FullscreenController through all permutations of events. The behavior 20 // the FullscreenController through all permutations of events. The behavior
20 // of the BrowserWindow is mocked via FullscreenControllerTestWindow. 21 // of the BrowserWindow is mocked via FullscreenControllerTestWindow.
21 22
22 23
23 // FullscreenControllerTestWindow ---------------------------------------------- 24 // FullscreenControllerTestWindow ----------------------------------------------
24 25
25 // A BrowserWindow used for testing FullscreenController. The behavior of this 26 // A BrowserWindow used for testing FullscreenController. The behavior of this
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 // tab fullscreen mode. The browser window should stay fullscreened, while 743 // tab fullscreen mode. The browser window should stay fullscreened, while
743 // the tab exits fullscreen mode. 744 // the tab exits fullscreen mode.
744 ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN)); 745 ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN));
745 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE)); 746 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
746 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE)); 747 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
747 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(tab)); 748 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(tab));
748 EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending()); 749 EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
749 EXPECT_TRUE(GetFullscreenController()->IsFullscreenForBrowser()); 750 EXPECT_TRUE(GetFullscreenController()->IsFullscreenForBrowser());
750 } 751 }
751 752
753 class FullscreenChangeObserver : public content::WebContentsObserver {
754 public:
755 explicit FullscreenChangeObserver(content::WebContents* web_contents)
756 : WebContentsObserver(web_contents) {
757 }
758
759 MOCK_METHOD2(DidToggleFullscreenModeForTab, void(bool, bool));
760
761 private:
762
Avi (use Gerrit) 2016/01/05 16:17:57 nit: no need for a newline here
bokan 2016/01/05 17:15:47 Done.
763 DISALLOW_COPY_AND_ASSIGN(FullscreenChangeObserver);
764 };
765
766 // Tests that going from tab fullscreen -> browser fullscreen causes an explicit
767 // WasResized to be called on ExitFullscreen while going from tab fullscreen ->
768 // Normal does not. This ensures that the Resize message we get in the renderer
769 // will have both the fullscreen change and size change in the same message.
770 // crbug.com/142427.
771 TEST_F(FullscreenControllerStateUnitTest, TabToBrowserFullscreenCausesResize) {
772 AddTab(browser(), GURL(url::kAboutBlankURL));
773 content::WebContents* const tab =
774 browser()->tab_strip_model()->GetWebContentsAt(0);
775
776 FullscreenChangeObserver fullscreenObserver(tab);
777
778 // Go into browser fullscreen, then tab fullscreen. Exiting tab fullscreen
779 // should call WasResized since the fullscreen change wont cause a size change
Avi (use Gerrit) 2016/01/05 16:17:57 s/wont/won't/
bokan 2016/01/05 17:15:47 Done.
780 // itself.
781 ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN));
782 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
783 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
784 ASSERT_TRUE(browser()->window()->IsFullscreen());
785
786 // The second parameter in DidToggleFullscreenModeForTab should be false,
787 // indicating that the fullscreen change will *not* cause a resize.
788 EXPECT_CALL(fullscreenObserver,
789 DidToggleFullscreenModeForTab(false, false));
790 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
791 testing::Mock::VerifyAndClearExpectations(&fullscreenObserver);
792
793 ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN));
794 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
795 ASSERT_FALSE(browser()->window()->IsFullscreen());
796
797 // Go into tab fullscreen only. Exiting tab fullscreen should *not* cause
798 // a call to WasResized since the window will change size and we want the
799 // fullscreen change and size change to be in one Resize message.
800 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
801 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
802 ASSERT_TRUE(browser()->window()->IsFullscreen());
803
804 // The second parameter in DidToggleFullscreenModeForTab should now be true,
805 // indicating that the fullscreen change *will* cause a resize.
806 EXPECT_CALL(fullscreenObserver,
807 DidToggleFullscreenModeForTab(false, true));
808 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
809 ASSERT_FALSE(browser()->window()->IsFullscreen());
810 testing::Mock::VerifyAndClearExpectations(&fullscreenObserver);
811 }
812
752 // Tests that the state of a fullscreened, screen-captured tab is preserved if 813 // Tests that the state of a fullscreened, screen-captured tab is preserved if
753 // the tab is detached from one Browser window and attached to another. 814 // the tab is detached from one Browser window and attached to another.
754 // 815 //
755 // See 'FullscreenWithinTab Note' in fullscreen_controller.h. 816 // See 'FullscreenWithinTab Note' in fullscreen_controller.h.
756 TEST_F(FullscreenControllerStateUnitTest, 817 TEST_F(FullscreenControllerStateUnitTest,
757 CapturedFullscreenedTabTransferredBetweenBrowserWindows) { 818 CapturedFullscreenedTabTransferredBetweenBrowserWindows) {
758 content::WebContentsDelegate* const wc_delegate = 819 content::WebContentsDelegate* const wc_delegate =
759 static_cast<content::WebContentsDelegate*>(browser()); 820 static_cast<content::WebContentsDelegate*>(browser());
760 ASSERT_TRUE(wc_delegate->EmbedsFullscreenWidget()); 821 ASSERT_TRUE(wc_delegate->EmbedsFullscreenWidget());
761 822
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(tab)); 889 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(tab));
829 EXPECT_FALSE(second_wc_delegate->IsFullscreenForTabOrPending(tab)); 890 EXPECT_FALSE(second_wc_delegate->IsFullscreenForTabOrPending(tab));
830 EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending()); 891 EXPECT_FALSE(GetFullscreenController()->IsWindowFullscreenForTabOrPending());
831 EXPECT_FALSE(second_browser->exclusive_access_manager() 892 EXPECT_FALSE(second_browser->exclusive_access_manager()
832 ->fullscreen_controller() 893 ->fullscreen_controller()
833 ->IsWindowFullscreenForTabOrPending()); 894 ->IsWindowFullscreenForTabOrPending());
834 895
835 // Required tear-down specific to this test. 896 // Required tear-down specific to this test.
836 second_browser->tab_strip_model()->CloseAllTabs(); 897 second_browser->tab_strip_model()->CloseAllTabs();
837 } 898 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698