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