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 "content/browser/site_per_process_browsertest.h" | 5 #include "content/browser/site_per_process_browsertest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 1826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1837 cross_site_rfh_type.c_str()); | 1837 cross_site_rfh_type.c_str()); |
1838 EXPECT_EQ(tree, DepictFrameTree(root)); | 1838 EXPECT_EQ(tree, DepictFrameTree(root)); |
1839 | 1839 |
1840 navigation_observer.Wait(); | 1840 navigation_observer.Wait(); |
1841 EXPECT_TRUE(observer.last_navigation_succeeded()); | 1841 EXPECT_TRUE(observer.last_navigation_succeeded()); |
1842 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); | 1842 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
1843 EXPECT_EQ(0U, child->child_count()); | 1843 EXPECT_EQ(0U, child->child_count()); |
1844 } | 1844 } |
1845 } | 1845 } |
1846 | 1846 |
| 1847 // Verify that "scrolling" property on frame elements propagates to child frames |
| 1848 // correctly. |
| 1849 // Does not work on android since android has scrollbars overlayed. |
| 1850 #if defined(OS_ANDROID) |
| 1851 #define MAYBE_FrameOwnerPropertiesPropagationScrolling \ |
| 1852 DISABLED_FrameOwnerPropertiesPropagationScrolling |
| 1853 #else |
| 1854 #define MAYBE_FrameOwnerPropertiesPropagationScrolling \ |
| 1855 FrameOwnerPropertiesPropagationScrolling |
| 1856 #endif |
| 1857 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 1858 MAYBE_FrameOwnerPropertiesPropagationScrolling) { |
| 1859 GURL main_url(embedded_test_server()->GetURL( |
| 1860 "a.com", "/frame_owner_properties_scrolling.html")); |
| 1861 NavigateToURL(shell(), main_url); |
| 1862 |
| 1863 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1864 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1865 ->GetFrameTree() |
| 1866 ->root(); |
| 1867 ASSERT_EQ(1u, root->child_count()); |
| 1868 |
| 1869 EXPECT_EQ( |
| 1870 " Site A ------------ proxies for B\n" |
| 1871 " +--Site B ------- proxies for A\n" |
| 1872 "Where A = http://a.com/\n" |
| 1873 " B = http://b.com/", |
| 1874 DepictFrameTree(root)); |
| 1875 |
| 1876 FrameTreeNode* child = root->child_at(0); |
| 1877 |
| 1878 // If the available client width within the iframe is smaller than the |
| 1879 // frame element's width, we assume there's a scrollbar. |
| 1880 // Also note that just comparing clientHeight and scrollHeight of the frame's |
| 1881 // document will not work. |
| 1882 auto has_scrollbar = [](RenderFrameHostImpl* rfh) { |
| 1883 int client_width; |
| 1884 EXPECT_TRUE(ExecuteScriptAndExtractInt(rfh, |
| 1885 "window.domAutomationController.send(document.body.clientWidth);", |
| 1886 &client_width)); |
| 1887 const int kFrameElementWidth = 200; |
| 1888 return client_width < kFrameElementWidth; |
| 1889 }; |
| 1890 |
| 1891 auto set_scrolling_property = [](RenderFrameHostImpl* parent_rfh, |
| 1892 const std::string& value) { |
| 1893 EXPECT_TRUE(ExecuteScript( |
| 1894 parent_rfh, |
| 1895 base::StringPrintf( |
| 1896 "document.getElementById('child-1').setAttribute(" |
| 1897 " 'scrolling', '%s');", value.c_str()))); |
| 1898 }; |
| 1899 |
| 1900 // Run the test over variety of parent/child cases. |
| 1901 GURL urls[] = { |
| 1902 // Remote to remote. |
| 1903 embedded_test_server()->GetURL("c.com", "/tall_page.html"), |
| 1904 // Remote to local. |
| 1905 embedded_test_server()->GetURL("a.com", "/tall_page.html"), |
| 1906 // Local to remote. |
| 1907 embedded_test_server()->GetURL("b.com", "/tall_page.html") |
| 1908 }; |
| 1909 const std::string scrolling_values[] = { |
| 1910 "yes", "auto", "no" |
| 1911 }; |
| 1912 |
| 1913 for (size_t i = 0; i < arraysize(scrolling_values); ++i) { |
| 1914 bool expect_scrollbar = scrolling_values[i] != "no"; |
| 1915 set_scrolling_property(root->current_frame_host(), scrolling_values[i]); |
| 1916 for (size_t j = 0; j < arraysize(urls); ++j) { |
| 1917 NavigateFrameToURL(child, urls[j]); |
| 1918 |
| 1919 // TODO(alexmos): This can be removed once TestFrameNavigationObserver is |
| 1920 // fixed to use DidFinishLoad. |
| 1921 EXPECT_TRUE(WaitForRenderFrameReady(child->current_frame_host())); |
| 1922 |
| 1923 EXPECT_EQ(expect_scrollbar, has_scrollbar(child->current_frame_host())); |
| 1924 } |
| 1925 } |
| 1926 } |
| 1927 |
| 1928 // Verify that "marginwidth" and "marginheight" properties on frame elements |
| 1929 // propagate to child frames correctly. |
| 1930 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 1931 FrameOwnerPropertiesPropagationMargin) { |
| 1932 GURL main_url(embedded_test_server()->GetURL( |
| 1933 "a.com", "/frame_owner_properties_margin.html")); |
| 1934 NavigateToURL(shell(), main_url); |
| 1935 |
| 1936 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1937 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1938 ->GetFrameTree() |
| 1939 ->root(); |
| 1940 ASSERT_EQ(1u, root->child_count()); |
| 1941 |
| 1942 EXPECT_EQ( |
| 1943 " Site A ------------ proxies for B\n" |
| 1944 " +--Site B ------- proxies for A\n" |
| 1945 "Where A = http://a.com/\n" |
| 1946 " B = http://b.com/", |
| 1947 DepictFrameTree(root)); |
| 1948 |
| 1949 FrameTreeNode* child = root->child_at(0); |
| 1950 |
| 1951 std::string margin_width; |
| 1952 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1953 child->current_frame_host(), |
| 1954 "window.domAutomationController.send(" |
| 1955 "document.body.getAttribute('marginwidth'));", |
| 1956 &margin_width)); |
| 1957 EXPECT_EQ("10", margin_width); |
| 1958 |
| 1959 std::string margin_height; |
| 1960 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1961 child->current_frame_host(), |
| 1962 "window.domAutomationController.send(" |
| 1963 "document.body.getAttribute('marginheight'));", |
| 1964 &margin_height)); |
| 1965 EXPECT_EQ("50", margin_height); |
| 1966 |
| 1967 // Run the test over variety of parent/child cases. |
| 1968 GURL urls[] = { |
| 1969 // Remote to remote. |
| 1970 embedded_test_server()->GetURL("c.com", "/title2.html"), |
| 1971 // Remote to local. |
| 1972 embedded_test_server()->GetURL("a.com", "/title1.html"), |
| 1973 // Local to remote. |
| 1974 embedded_test_server()->GetURL("b.com", "/title2.html") |
| 1975 }; |
| 1976 |
| 1977 int current_margin_width = 15; |
| 1978 int current_margin_height = 25; |
| 1979 |
| 1980 // Before each navigation, we change the marginwidth and marginheight |
| 1981 // properties of the frame. We then check whether those properties are applied |
| 1982 // correctly after the navigation has completed. |
| 1983 for (size_t i = 0; i < arraysize(urls); ++i) { |
| 1984 // Change marginwidth and marginheight before navigating. |
| 1985 EXPECT_TRUE(ExecuteScript( |
| 1986 root->current_frame_host(), |
| 1987 base::StringPrintf( |
| 1988 "document.getElementById('child-1').setAttribute(" |
| 1989 " 'marginwidth', '%d');", current_margin_width))); |
| 1990 EXPECT_TRUE(ExecuteScript( |
| 1991 root->current_frame_host(), |
| 1992 base::StringPrintf( |
| 1993 "document.getElementById('child-1').setAttribute(" |
| 1994 " 'marginheight', '%d');", current_margin_height))); |
| 1995 |
| 1996 NavigateFrameToURL(child, urls[i]); |
| 1997 // TODO(alexmos): This can be removed once TestFrameNavigationObserver is |
| 1998 // fixed to use DidFinishLoad. |
| 1999 EXPECT_TRUE(WaitForRenderFrameReady(child->current_frame_host())); |
| 2000 |
| 2001 std::string actual_margin_width; |
| 2002 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2003 child->current_frame_host(), |
| 2004 "window.domAutomationController.send(" |
| 2005 "document.body.getAttribute('marginwidth'));", |
| 2006 &actual_margin_width)); |
| 2007 EXPECT_EQ(base::IntToString(current_margin_width), actual_margin_width); |
| 2008 |
| 2009 std::string actual_margin_height; |
| 2010 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 2011 child->current_frame_host(), |
| 2012 "window.domAutomationController.send(" |
| 2013 "document.body.getAttribute('marginheight'));", |
| 2014 &actual_margin_height)); |
| 2015 EXPECT_EQ(base::IntToString(current_margin_height), actual_margin_height); |
| 2016 |
| 2017 current_margin_width += 5; |
| 2018 current_margin_height += 10; |
| 2019 } |
| 2020 } |
| 2021 |
1847 // Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy. | 2022 // Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy. |
1848 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { | 2023 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { |
1849 GURL main_url(embedded_test_server()->GetURL( | 2024 GURL main_url(embedded_test_server()->GetURL( |
1850 "a.com", "/cross_site_iframe_factory.html?a(b(c(a),b), a)")); | 2025 "a.com", "/cross_site_iframe_factory.html?a(b(c(a),b), a)")); |
1851 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 2026 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
1852 | 2027 |
1853 // It is safe to obtain the root frame tree node here, as it doesn't change. | 2028 // It is safe to obtain the root frame tree node here, as it doesn't change. |
1854 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 2029 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
1855 ->GetFrameTree() | 2030 ->GetFrameTree() |
1856 ->root(); | 2031 ->root(); |
(...skipping 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3620 | 3795 |
3621 // Use new window to navigate main window. | 3796 // Use new window to navigate main window. |
3622 std::string script = | 3797 std::string script = |
3623 "window.opener.location.href = '" + cross_url.spec() + "'"; | 3798 "window.opener.location.href = '" + cross_url.spec() + "'"; |
3624 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); | 3799 EXPECT_TRUE(ExecuteScript(popup->web_contents(), script)); |
3625 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 3800 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
3626 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); | 3801 EXPECT_EQ(shell()->web_contents()->GetLastCommittedURL(), cross_url); |
3627 } | 3802 } |
3628 | 3803 |
3629 } // namespace content | 3804 } // namespace content |
OLD | NEW |