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 1818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1829 cross_site_rfh_type.c_str()); | 1829 cross_site_rfh_type.c_str()); |
1830 EXPECT_EQ(tree, DepictFrameTree(root)); | 1830 EXPECT_EQ(tree, DepictFrameTree(root)); |
1831 | 1831 |
1832 navigation_observer.Wait(); | 1832 navigation_observer.Wait(); |
1833 EXPECT_TRUE(observer.last_navigation_succeeded()); | 1833 EXPECT_TRUE(observer.last_navigation_succeeded()); |
1834 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); | 1834 EXPECT_EQ(cross_site_url, observer.last_navigation_url()); |
1835 EXPECT_EQ(0U, child->child_count()); | 1835 EXPECT_EQ(0U, child->child_count()); |
1836 } | 1836 } |
1837 } | 1837 } |
1838 | 1838 |
| 1839 // Verify that "scrolling" property on frame elements propagates to child frames |
| 1840 // correctly. |
| 1841 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 1842 FrameOwnerPropertiesPropagationScrolling) { |
| 1843 GURL main_url(embedded_test_server()->GetURL( |
| 1844 "a.com", "/frame_owner_properties_scrolling.html")); |
| 1845 NavigateToURL(shell(), main_url); |
| 1846 |
| 1847 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1848 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1849 ->GetFrameTree() |
| 1850 ->root(); |
| 1851 ASSERT_EQ(1u, root->child_count()); |
| 1852 |
| 1853 EXPECT_EQ( |
| 1854 " Site A ------------ proxies for B\n" |
| 1855 " +--Site B ------- proxies for A\n" |
| 1856 "Where A = http://a.com/\n" |
| 1857 " B = http://b.com/", |
| 1858 DepictFrameTree(root)); |
| 1859 |
| 1860 FrameTreeNode* child = root->child_at(0); |
| 1861 |
| 1862 // If the available client width within the iframe is smaller than the |
| 1863 // frame element's width, we assume there's a scrollbar. |
| 1864 // Also note that just comparing clientHeight and scrollHeight of the frame's |
| 1865 // document will not work. |
| 1866 auto has_scrollbar = [](RenderFrameHostImpl* rfh) { |
| 1867 int client_width; |
| 1868 EXPECT_TRUE(ExecuteScriptAndExtractInt(rfh, |
| 1869 "window.domAutomationController.send(document.body.clientWidth);", |
| 1870 &client_width)); |
| 1871 const int kFrameElementWidth = 200; |
| 1872 return client_width < kFrameElementWidth; |
| 1873 }; |
| 1874 |
| 1875 auto set_scrolling_property = [](RenderFrameHostImpl* parent_rfh, |
| 1876 const std::string& value) { |
| 1877 EXPECT_TRUE(ExecuteScript( |
| 1878 parent_rfh, |
| 1879 base::StringPrintf( |
| 1880 "document.getElementById('child-1').setAttribute(" |
| 1881 " 'scrolling', '%s');", value.c_str()))); |
| 1882 }; |
| 1883 |
| 1884 // Run the test over variety of parent/child cases. |
| 1885 GURL urls[] = { |
| 1886 // Remote to remote. |
| 1887 embedded_test_server()->GetURL("c.com", "/tall_page.html"), |
| 1888 // Remote to local. |
| 1889 embedded_test_server()->GetURL("a.com", "/tall_page.html"), |
| 1890 // Local to remote. |
| 1891 embedded_test_server()->GetURL("b.com", "/tall_page.html") |
| 1892 }; |
| 1893 const std::string scrolling_values[] = { |
| 1894 "yes", "auto", "no" |
| 1895 }; |
| 1896 |
| 1897 for (size_t i = 0; i < arraysize(scrolling_values); ++i) { |
| 1898 bool expect_scrollbar = scrolling_values[i] != "no"; |
| 1899 set_scrolling_property(root->current_frame_host(), scrolling_values[i]); |
| 1900 for (size_t j = 0; j < arraysize(urls); ++j) { |
| 1901 NavigateFrameToURL(child, urls[j]); |
| 1902 |
| 1903 // TODO(alexmos): This can be removed once TestFrameNavigationObserver is |
| 1904 // fixed to use DidFinishLoad. |
| 1905 EXPECT_TRUE(WaitForRenderFrameReady(child->current_frame_host())); |
| 1906 |
| 1907 EXPECT_EQ(expect_scrollbar, has_scrollbar(child->current_frame_host())); |
| 1908 } |
| 1909 } |
| 1910 } |
| 1911 |
| 1912 // Verify that "marginwidth" and "marginheight" properties on frame elements |
| 1913 // propagate to child frames correctly. |
| 1914 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, |
| 1915 FrameOwnerPropertiesPropagationMargin) { |
| 1916 GURL main_url(embedded_test_server()->GetURL( |
| 1917 "a.com", "/frame_owner_properties_margin.html")); |
| 1918 NavigateToURL(shell(), main_url); |
| 1919 |
| 1920 // It is safe to obtain the root frame tree node here, as it doesn't change. |
| 1921 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1922 ->GetFrameTree() |
| 1923 ->root(); |
| 1924 ASSERT_EQ(1u, root->child_count()); |
| 1925 |
| 1926 EXPECT_EQ( |
| 1927 " Site A ------------ proxies for B\n" |
| 1928 " +--Site B ------- proxies for A\n" |
| 1929 "Where A = http://a.com/\n" |
| 1930 " B = http://b.com/", |
| 1931 DepictFrameTree(root)); |
| 1932 |
| 1933 FrameTreeNode* child = root->child_at(0); |
| 1934 |
| 1935 std::string margin_width; |
| 1936 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1937 child->current_frame_host(), |
| 1938 "window.domAutomationController.send(" |
| 1939 "document.body.getAttribute('marginwidth'));", |
| 1940 &margin_width)); |
| 1941 EXPECT_EQ("10", margin_width); |
| 1942 |
| 1943 std::string margin_height; |
| 1944 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1945 child->current_frame_host(), |
| 1946 "window.domAutomationController.send(" |
| 1947 "document.body.getAttribute('marginheight'));", |
| 1948 &margin_height)); |
| 1949 EXPECT_EQ("50", margin_height); |
| 1950 |
| 1951 // Run the test over variety of parent/child cases. |
| 1952 GURL urls[] = { |
| 1953 // Remote to remote. |
| 1954 embedded_test_server()->GetURL("c.com", "/title2.html"), |
| 1955 // Remote to local. |
| 1956 embedded_test_server()->GetURL("a.com", "/title1.html"), |
| 1957 // Local to remote. |
| 1958 embedded_test_server()->GetURL("b.com", "/title2.html") |
| 1959 }; |
| 1960 |
| 1961 int current_margin_width = 15; |
| 1962 int current_margin_height = 25; |
| 1963 |
| 1964 // Before each navigation, we change the marginwidth and marginheight |
| 1965 // properties of the frame. We then check whether those properties are applied |
| 1966 // correctly after the navigation has completed. |
| 1967 for (size_t i = 0; i < arraysize(urls); ++i) { |
| 1968 // Change marginwidth and marginheight before navigating. |
| 1969 EXPECT_TRUE(ExecuteScript( |
| 1970 root->current_frame_host(), |
| 1971 base::StringPrintf( |
| 1972 "document.getElementById('child-1').setAttribute(" |
| 1973 " 'marginwidth', '%d');", current_margin_width))); |
| 1974 EXPECT_TRUE(ExecuteScript( |
| 1975 root->current_frame_host(), |
| 1976 base::StringPrintf( |
| 1977 "document.getElementById('child-1').setAttribute(" |
| 1978 " 'marginheight', '%d');", current_margin_height))); |
| 1979 |
| 1980 NavigateFrameToURL(child, urls[i]); |
| 1981 // TODO(alexmos): This can be removed once TestFrameNavigationObserver is |
| 1982 // fixed to use DidFinishLoad. |
| 1983 EXPECT_TRUE(WaitForRenderFrameReady(child->current_frame_host())); |
| 1984 |
| 1985 std::string actual_margin_width; |
| 1986 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1987 child->current_frame_host(), |
| 1988 "window.domAutomationController.send(" |
| 1989 "document.body.getAttribute('marginwidth'));", |
| 1990 &actual_margin_width)); |
| 1991 EXPECT_EQ(base::IntToString(current_margin_width), actual_margin_width); |
| 1992 |
| 1993 std::string actual_margin_height; |
| 1994 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 1995 child->current_frame_host(), |
| 1996 "window.domAutomationController.send(" |
| 1997 "document.body.getAttribute('marginheight'));", |
| 1998 &actual_margin_height)); |
| 1999 EXPECT_EQ(base::IntToString(current_margin_height), actual_margin_height); |
| 2000 |
| 2001 current_margin_width += 5; |
| 2002 current_margin_height += 10; |
| 2003 } |
| 2004 } |
| 2005 |
1839 // Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy. | 2006 // Verify origin replication with an A-embed-B-embed-C-embed-A hierarchy. |
1840 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { | 2007 IN_PROC_BROWSER_TEST_F(SitePerProcessBrowserTest, OriginReplication) { |
1841 GURL main_url(embedded_test_server()->GetURL( | 2008 GURL main_url(embedded_test_server()->GetURL( |
1842 "a.com", "/cross_site_iframe_factory.html?a(b(c(a),b), a)")); | 2009 "a.com", "/cross_site_iframe_factory.html?a(b(c(a),b), a)")); |
1843 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | 2010 EXPECT_TRUE(NavigateToURL(shell(), main_url)); |
1844 | 2011 |
1845 // It is safe to obtain the root frame tree node here, as it doesn't change. | 2012 // It is safe to obtain the root frame tree node here, as it doesn't change. |
1846 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 2013 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
1847 ->GetFrameTree() | 2014 ->GetFrameTree() |
1848 ->root(); | 2015 ->root(); |
(...skipping 1659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3508 while (msg_queue.WaitForMessage(&status)) { | 3675 while (msg_queue.WaitForMessage(&status)) { |
3509 if (status == "\"document-blur\"") | 3676 if (status == "\"document-blur\"") |
3510 break; | 3677 break; |
3511 } | 3678 } |
3512 | 3679 |
3513 // The root frame should be focused again. | 3680 // The root frame should be focused again. |
3514 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); | 3681 EXPECT_EQ(root, root->frame_tree()->GetFocusedFrame()); |
3515 } | 3682 } |
3516 | 3683 |
3517 } // namespace content | 3684 } // namespace content |
OLD | NEW |