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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 1713473002: Make TestRenderWidgetHostView::Show/Hide call through to RWHI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@crash
Patch Set: Fix ExtensionContextMenuModelTest.TestPageAccessSubmenu Created 3 years, 10 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 void TestRenderViewTerminated(base::TerminationStatus status, 156 void TestRenderViewTerminated(base::TerminationStatus status,
157 int error_code) { 157 int error_code) {
158 RenderViewTerminated(GetMainFrame()->GetRenderViewHost(), status, 158 RenderViewTerminated(GetMainFrame()->GetRenderViewHost(), status,
159 error_code); 159 error_code);
160 } 160 }
161 161
162 bool is_showing() const { 162 bool is_showing() const {
163 return static_cast<TestRenderWidgetHostView*>( 163 return static_cast<TestRenderWidgetHostView*>(
164 GetMainFrame()->GetRenderViewHost()->GetWidget()->GetView()) 164 GetMainFrame()->GetRenderViewHost()->GetWidget()->GetView())
165 ->is_showing(); 165 ->IsShowing();
166 } 166 }
167 167
168 void ClearStates() { 168 void ClearStates() {
169 state_ = nullptr; 169 state_ = nullptr;
170 deleted_ = nullptr; 170 deleted_ = nullptr;
171 delegate_ = nullptr; 171 delegate_ = nullptr;
172 } 172 }
173 173
174 void CommandReceived() { 174 void CommandReceived() {
175 command_received_count_++; 175 command_received_count_++;
(...skipping 1501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 TestInterstitialPage::InterstitialState state = 1677 TestInterstitialPage::InterstitialState state =
1678 TestInterstitialPage::INVALID; 1678 TestInterstitialPage::INVALID;
1679 bool deleted = false; 1679 bool deleted = false;
1680 GURL url2("http://interstitial"); 1680 GURL url2("http://interstitial");
1681 TestInterstitialPage* interstitial = 1681 TestInterstitialPage* interstitial =
1682 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1682 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1683 TestInterstitialPageStateGuard state_guard(interstitial); 1683 TestInterstitialPageStateGuard state_guard(interstitial);
1684 interstitial->Show(); 1684 interstitial->Show();
1685 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID(); 1685 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1686 // The interstitial should not show until its navigation has committed. 1686 // The interstitial should not show until its navigation has committed.
1687 EXPECT_FALSE(interstitial->is_showing());
sky 2017/02/08 23:21:36 Why are the interstitial assertions no longer inte
johnme 2017/02/09 18:59:29 They were misleading. Outside of tests, is_showing
1688 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1687 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1689 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1688 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1690 // Let's commit the interstitial navigation. 1689 // Let's commit the interstitial navigation.
1691 interstitial->TestDidNavigate(interstitial_entry_id, true, url2); 1690 interstitial->TestDidNavigate(interstitial_entry_id, true, url2);
1692 EXPECT_TRUE(interstitial->is_showing()); 1691 EXPECT_TRUE(interstitial->is_showing());
1693 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1692 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1694 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1693 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1695 entry = controller().GetVisibleEntry(); 1694 entry = controller().GetVisibleEntry();
1696 ASSERT_NE(nullptr, entry); 1695 ASSERT_NE(nullptr, entry);
1697 EXPECT_TRUE(entry->GetURL() == url2); 1696 EXPECT_TRUE(entry->GetURL() == url2);
(...skipping 27 matching lines...) Expand all
1725 TestInterstitialPage::InterstitialState state = 1724 TestInterstitialPage::InterstitialState state =
1726 TestInterstitialPage::INVALID; 1725 TestInterstitialPage::INVALID;
1727 bool deleted = false; 1726 bool deleted = false;
1728 GURL url2("http://interstitial"); 1727 GURL url2("http://interstitial");
1729 TestInterstitialPage* interstitial = 1728 TestInterstitialPage* interstitial =
1730 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1729 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1731 TestInterstitialPageStateGuard state_guard(interstitial); 1730 TestInterstitialPageStateGuard state_guard(interstitial);
1732 interstitial->Show(); 1731 interstitial->Show();
1733 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID(); 1732 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1734 // The interstitial should not show until its navigation has committed. 1733 // The interstitial should not show until its navigation has committed.
1735 EXPECT_FALSE(interstitial->is_showing());
1736 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1734 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1737 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1735 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1738 // Let's commit the interstitial navigation. 1736 // Let's commit the interstitial navigation.
1739 interstitial->TestDidNavigate(interstitial_entry_id, true, url2); 1737 interstitial->TestDidNavigate(interstitial_entry_id, true, url2);
1740 EXPECT_TRUE(interstitial->is_showing()); 1738 EXPECT_TRUE(interstitial->is_showing());
1741 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1739 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1742 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1740 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1743 NavigationEntry* entry = controller().GetVisibleEntry(); 1741 NavigationEntry* entry = controller().GetVisibleEntry();
1744 ASSERT_NE(nullptr, entry); 1742 ASSERT_NE(nullptr, entry);
1745 EXPECT_TRUE(entry->GetURL() == url2); 1743 EXPECT_TRUE(entry->GetURL() == url2);
(...skipping 24 matching lines...) Expand all
1770 // Show an interstitial. 1768 // Show an interstitial.
1771 TestInterstitialPage::InterstitialState state = 1769 TestInterstitialPage::InterstitialState state =
1772 TestInterstitialPage::INVALID; 1770 TestInterstitialPage::INVALID;
1773 bool deleted = false; 1771 bool deleted = false;
1774 GURL url2("http://interstitial"); 1772 GURL url2("http://interstitial");
1775 TestInterstitialPage* interstitial = 1773 TestInterstitialPage* interstitial =
1776 new TestInterstitialPage(contents(), false, url2, &state, &deleted); 1774 new TestInterstitialPage(contents(), false, url2, &state, &deleted);
1777 TestInterstitialPageStateGuard state_guard(interstitial); 1775 TestInterstitialPageStateGuard state_guard(interstitial);
1778 interstitial->Show(); 1776 interstitial->Show();
1779 // The interstitial should not show until its navigation has committed. 1777 // The interstitial should not show until its navigation has committed.
1780 EXPECT_FALSE(interstitial->is_showing());
1781 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1778 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1782 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1779 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1783 // Let's commit the interstitial navigation. 1780 // Let's commit the interstitial navigation.
1784 interstitial->TestDidNavigate(0, true, url2); 1781 interstitial->TestDidNavigate(0, true, url2);
1785 EXPECT_TRUE(interstitial->is_showing()); 1782 EXPECT_TRUE(interstitial->is_showing());
1786 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1783 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1787 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1784 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1788 NavigationEntry* entry = controller().GetVisibleEntry(); 1785 NavigationEntry* entry = controller().GetVisibleEntry();
1789 ASSERT_NE(nullptr, entry); 1786 ASSERT_NE(nullptr, entry);
1790 // The URL specified to the interstitial should have been ignored. 1787 // The URL specified to the interstitial should have been ignored.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1822 TestInterstitialPage::InterstitialState state = 1819 TestInterstitialPage::InterstitialState state =
1823 TestInterstitialPage::INVALID; 1820 TestInterstitialPage::INVALID;
1824 bool deleted = false; 1821 bool deleted = false;
1825 GURL url2("http://interstitial"); 1822 GURL url2("http://interstitial");
1826 TestInterstitialPage* interstitial = 1823 TestInterstitialPage* interstitial =
1827 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1824 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1828 TestInterstitialPageStateGuard state_guard(interstitial); 1825 TestInterstitialPageStateGuard state_guard(interstitial);
1829 interstitial->Show(); 1826 interstitial->Show();
1830 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID(); 1827 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1831 // The interstitial should not show until its navigation has committed. 1828 // The interstitial should not show until its navigation has committed.
1832 EXPECT_FALSE(interstitial->is_showing());
1833 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1829 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1834 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1830 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1835 // Let's commit the interstitial navigation. 1831 // Let's commit the interstitial navigation.
1836 interstitial->TestDidNavigate(interstitial_entry_id, true, url2); 1832 interstitial->TestDidNavigate(interstitial_entry_id, true, url2);
1837 EXPECT_TRUE(interstitial->is_showing()); 1833 EXPECT_TRUE(interstitial->is_showing());
1838 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1834 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1839 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1835 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1840 NavigationEntry* entry = controller().GetVisibleEntry(); 1836 NavigationEntry* entry = controller().GetVisibleEntry();
1841 ASSERT_NE(nullptr, entry); 1837 ASSERT_NE(nullptr, entry);
1842 EXPECT_TRUE(entry->GetURL() == url2); 1838 EXPECT_TRUE(entry->GetURL() == url2);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1882 TestInterstitialPage::InterstitialState state = 1878 TestInterstitialPage::InterstitialState state =
1883 TestInterstitialPage::INVALID; 1879 TestInterstitialPage::INVALID;
1884 bool deleted = false; 1880 bool deleted = false;
1885 GURL url2("http://interstitial"); 1881 GURL url2("http://interstitial");
1886 TestInterstitialPage* interstitial = 1882 TestInterstitialPage* interstitial =
1887 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1883 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1888 TestInterstitialPageStateGuard state_guard(interstitial); 1884 TestInterstitialPageStateGuard state_guard(interstitial);
1889 interstitial->Show(); 1885 interstitial->Show();
1890 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID(); 1886 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
1891 // The interstitial should not show until its navigation has committed. 1887 // The interstitial should not show until its navigation has committed.
1892 EXPECT_FALSE(interstitial->is_showing());
1893 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1888 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1894 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1889 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1895 // Let's commit the interstitial navigation. 1890 // Let's commit the interstitial navigation.
1896 interstitial->TestDidNavigate(interstitial_entry_id, true, url2); 1891 interstitial->TestDidNavigate(interstitial_entry_id, true, url2);
1897 EXPECT_TRUE(interstitial->is_showing()); 1892 EXPECT_TRUE(interstitial->is_showing());
1898 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1893 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1899 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1894 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1900 NavigationEntry* entry = controller().GetVisibleEntry(); 1895 NavigationEntry* entry = controller().GetVisibleEntry();
1901 ASSERT_NE(nullptr, entry); 1896 ASSERT_NE(nullptr, entry);
1902 EXPECT_TRUE(entry->GetURL() == url2); 1897 EXPECT_TRUE(entry->GetURL() == url2);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1939 // Show an interstitial. 1934 // Show an interstitial.
1940 TestInterstitialPage::InterstitialState state = 1935 TestInterstitialPage::InterstitialState state =
1941 TestInterstitialPage::INVALID; 1936 TestInterstitialPage::INVALID;
1942 bool deleted = false; 1937 bool deleted = false;
1943 GURL url2("http://interstitial"); 1938 GURL url2("http://interstitial");
1944 TestInterstitialPage* interstitial = 1939 TestInterstitialPage* interstitial =
1945 new TestInterstitialPage(contents(), false, url2, &state, &deleted); 1940 new TestInterstitialPage(contents(), false, url2, &state, &deleted);
1946 TestInterstitialPageStateGuard state_guard(interstitial); 1941 TestInterstitialPageStateGuard state_guard(interstitial);
1947 interstitial->Show(); 1942 interstitial->Show();
1948 // The interstitial should not show until its navigation has committed. 1943 // The interstitial should not show until its navigation has committed.
1949 EXPECT_FALSE(interstitial->is_showing());
1950 EXPECT_FALSE(contents()->ShowingInterstitialPage()); 1944 EXPECT_FALSE(contents()->ShowingInterstitialPage());
1951 EXPECT_EQ(nullptr, contents()->GetInterstitialPage()); 1945 EXPECT_EQ(nullptr, contents()->GetInterstitialPage());
1952 // Let's commit the interstitial navigation. 1946 // Let's commit the interstitial navigation.
1953 interstitial->TestDidNavigate(0, true, url2); 1947 interstitial->TestDidNavigate(0, true, url2);
1954 EXPECT_TRUE(interstitial->is_showing()); 1948 EXPECT_TRUE(interstitial->is_showing());
1955 EXPECT_TRUE(contents()->ShowingInterstitialPage()); 1949 EXPECT_TRUE(contents()->ShowingInterstitialPage());
1956 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial); 1950 EXPECT_TRUE(contents()->GetInterstitialPage() == interstitial);
1957 NavigationEntry* entry = controller().GetVisibleEntry(); 1951 NavigationEntry* entry = controller().GetVisibleEntry();
1958 ASSERT_NE(nullptr, entry); 1952 ASSERT_NE(nullptr, entry);
1959 // The URL specified to the interstitial should have been ignored. 1953 // The URL specified to the interstitial should have been ignored.
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
2324 &state, &deleted); 2318 &state, &deleted);
2325 TestInterstitialPageStateGuard state_guard(interstitial); 2319 TestInterstitialPageStateGuard state_guard(interstitial);
2326 interstitial->Show(); 2320 interstitial->Show();
2327 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID(); 2321 int interstitial_entry_id = controller().GetTransientEntry()->GetUniqueID();
2328 2322
2329 // Let's simulate a navigation initiated from the browser before the 2323 // Let's simulate a navigation initiated from the browser before the
2330 // interstitial finishes loading. 2324 // interstitial finishes loading.
2331 const GURL url("http://www.google.com"); 2325 const GURL url("http://www.google.com");
2332 controller().LoadURL( 2326 controller().LoadURL(
2333 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 2327 url, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2334 EXPECT_FALSE(interstitial->is_showing()); 2328 EXPECT_FALSE(contents()->ShowingInterstitialPage());
2335 RunAllPendingInMessageLoop(); 2329 RunAllPendingInMessageLoop();
2336 ASSERT_FALSE(deleted); 2330 ASSERT_FALSE(deleted);
2337 2331
2338 // Now let's make the interstitial navigation commit. 2332 // Now let's make the interstitial navigation commit.
2339 interstitial->TestDidNavigate(interstitial_entry_id, true, 2333 interstitial->TestDidNavigate(interstitial_entry_id, true,
2340 interstitial_url); 2334 interstitial_url);
2341 2335
2342 // After it loaded the interstitial should be gone. 2336 // After it loaded the interstitial should be gone.
2343 EXPECT_EQ(TestInterstitialPage::CANCELED, state); 2337 EXPECT_EQ(TestInterstitialPage::CANCELED, state);
2344 2338
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2696 2690
2697 TEST_F(WebContentsImplTest, CapturerPreventsHiding) { 2691 TEST_F(WebContentsImplTest, CapturerPreventsHiding) {
2698 const gfx::Size original_preferred_size(1024, 768); 2692 const gfx::Size original_preferred_size(1024, 768);
2699 contents()->UpdatePreferredSize(original_preferred_size); 2693 contents()->UpdatePreferredSize(original_preferred_size);
2700 2694
2701 TestRenderWidgetHostView* view = static_cast<TestRenderWidgetHostView*>( 2695 TestRenderWidgetHostView* view = static_cast<TestRenderWidgetHostView*>(
2702 main_test_rfh()->GetRenderViewHost()->GetWidget()->GetView()); 2696 main_test_rfh()->GetRenderViewHost()->GetWidget()->GetView());
2703 2697
2704 // With no capturers, setting and un-setting occlusion should change the 2698 // With no capturers, setting and un-setting occlusion should change the
2705 // view's occlusion state. 2699 // view's occlusion state.
2706 EXPECT_FALSE(view->is_showing()); 2700 EXPECT_TRUE(view->IsShowing());
2701 contents()->WasHidden();
2702 EXPECT_FALSE(view->IsShowing());
2707 contents()->WasShown(); 2703 contents()->WasShown();
2708 EXPECT_TRUE(view->is_showing()); 2704 EXPECT_TRUE(view->IsShowing());
2709 contents()->WasHidden();
2710 EXPECT_FALSE(view->is_showing());
2711 contents()->WasShown();
2712 EXPECT_TRUE(view->is_showing());
2713 2705
2714 // Add a capturer and try to hide the contents. The view will remain visible. 2706 // Add a capturer and try to hide the contents. The view will remain visible.
2715 contents()->IncrementCapturerCount(gfx::Size()); 2707 contents()->IncrementCapturerCount(gfx::Size());
2716 contents()->WasHidden(); 2708 contents()->WasHidden();
2717 EXPECT_TRUE(view->is_showing()); 2709 EXPECT_TRUE(view->IsShowing());
2718 2710
2719 // Remove the capturer, and the WasHidden should take effect. 2711 // Remove the capturer, and the WasHidden should take effect.
2720 contents()->DecrementCapturerCount(); 2712 contents()->DecrementCapturerCount();
2721 EXPECT_FALSE(view->is_showing()); 2713 EXPECT_FALSE(view->IsShowing());
2722 } 2714 }
2723 2715
2724 TEST_F(WebContentsImplTest, CapturerPreventsOcclusion) { 2716 TEST_F(WebContentsImplTest, CapturerPreventsOcclusion) {
2725 const gfx::Size original_preferred_size(1024, 768); 2717 const gfx::Size original_preferred_size(1024, 768);
2726 contents()->UpdatePreferredSize(original_preferred_size); 2718 contents()->UpdatePreferredSize(original_preferred_size);
2727 2719
2728 TestRenderWidgetHostView* view = static_cast<TestRenderWidgetHostView*>( 2720 TestRenderWidgetHostView* view = static_cast<TestRenderWidgetHostView*>(
2729 main_test_rfh()->GetRenderViewHost()->GetWidget()->GetView()); 2721 main_test_rfh()->GetRenderViewHost()->GetWidget()->GetView());
2730 2722
2731 // With no capturers, setting and un-setting occlusion should change the 2723 // With no capturers, setting and un-setting occlusion should change the
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
3436 // An automatic navigation. 3428 // An automatic navigation.
3437 main_test_rfh()->SendNavigateWithModificationCallback( 3429 main_test_rfh()->SendNavigateWithModificationCallback(
3438 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture)); 3430 0, true, GURL(url::kAboutBlankURL), base::Bind(SetAsNonUserGesture));
3439 3431
3440 EXPECT_EQ(1u, dialog_manager.reset_count()); 3432 EXPECT_EQ(1u, dialog_manager.reset_count());
3441 3433
3442 contents()->SetJavaScriptDialogManagerForTesting(nullptr); 3434 contents()->SetJavaScriptDialogManagerForTesting(nullptr);
3443 } 3435 }
3444 3436
3445 } // namespace content 3437 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698