Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/frame_host/frame_navigation_entry.h" | 8 #include "content/browser/frame_host/frame_navigation_entry.h" |
| 9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
| 10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
| (...skipping 1886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1897 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 1897 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 1898 // The entry should have a new FrameNavigationEntries for the subframe. | 1898 // The entry should have a new FrameNavigationEntries for the subframe. |
| 1899 ASSERT_EQ(1U, entry3->root_node()->children.size()); | 1899 ASSERT_EQ(1U, entry3->root_node()->children.size()); |
| 1900 EXPECT_EQ(frame_url3, entry3->root_node()->children[0]->frame_entry->url()); | 1900 EXPECT_EQ(frame_url3, entry3->root_node()->children[0]->frame_entry->url()); |
| 1901 } else { | 1901 } else { |
| 1902 // There are no subframe FrameNavigationEntries by default. | 1902 // There are no subframe FrameNavigationEntries by default. |
| 1903 EXPECT_EQ(0U, entry3->root_node()->children.size()); | 1903 EXPECT_EQ(0U, entry3->root_node()->children.size()); |
| 1904 } | 1904 } |
| 1905 } | 1905 } |
| 1906 | 1906 |
| 1907 // Verifies that the target is correctly set to the unique name of the frame. | |
| 1908 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | |
| 1909 FrameNavigationEntry_Target) { | |
| 1910 const NavigationControllerImpl& controller = | |
| 1911 static_cast<const NavigationControllerImpl&>( | |
| 1912 shell()->web_contents()->GetController()); | |
| 1913 | |
| 1914 // 1. Navigate the main frame. | |
| 1915 GURL url(embedded_test_server()->GetURL( | |
| 1916 "/navigation_controller/page_with_links.html")); | |
| 1917 NavigateToURL(shell(), url); | |
| 1918 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | |
| 1919 ->GetFrameTree() | |
| 1920 ->root(); | |
| 1921 SiteInstance* main_site_instance = | |
| 1922 root->current_frame_host()->GetSiteInstance(); | |
| 1923 | |
| 1924 // The main frame defaults to an empty target. | |
| 1925 FrameNavigationEntry* frame_entry = | |
| 1926 controller.GetLastCommittedEntry()->GetFrameEntry(root); | |
| 1927 EXPECT_EQ("", frame_entry->target()); | |
| 1928 | |
| 1929 // Test subframe targets only if enabled, e.g. in --site-per-process. | |
| 1930 if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) | |
| 1931 return; | |
| 1932 | |
| 1933 // 2. Add an unnamed subframe, which does an AUTO_SUBFRAME navigation. | |
| 1934 { | |
| 1935 LoadCommittedCapturer capturer(shell()->web_contents()); | |
| 1936 std::string script = "var iframe = document.createElement('iframe');" | |
| 1937 "iframe.src = '" + url.spec() + "';" | |
| 1938 "document.body.appendChild(iframe);"; | |
| 1939 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 1940 capturer.Wait(); | |
| 1941 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
| 1942 } | |
| 1943 | |
| 1944 // The root FrameNavigationEntry hasn't changed. | |
| 1945 EXPECT_EQ(frame_entry, | |
| 1946 controller.GetLastCommittedEntry()->GetFrameEntry(root)); | |
| 1947 | |
| 1948 // The subframe should have a generated name for the target. | |
| 1949 FrameTreeNode* subframe = root->child_at(0); | |
| 1950 EXPECT_EQ(main_site_instance, | |
| 1951 subframe->current_frame_host()->GetSiteInstance()); | |
| 1952 FrameNavigationEntry* subframe_entry = | |
| 1953 controller.GetLastCommittedEntry()->GetFrameEntry(subframe); | |
| 1954 std::string unnamed_subframe_target = "<!--framePath //<!--frame0-->-->"; | |
| 1955 EXPECT_EQ(unnamed_subframe_target, subframe_entry->target()); | |
| 1956 | |
| 1957 // 3. Add a named subframe. | |
| 1958 { | |
| 1959 LoadCommittedCapturer capturer(shell()->web_contents()); | |
| 1960 std::string script = "var iframe = document.createElement('iframe');" | |
| 1961 "iframe.src = '" + url.spec() + "';" | |
| 1962 "iframe.name = 'foo';" | |
| 1963 "document.body.appendChild(iframe);"; | |
| 1964 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | |
| 1965 capturer.Wait(); | |
| 1966 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | |
| 1967 } | |
| 1968 | |
| 1969 // The new subframe should have the specified name for the target. | |
| 1970 EXPECT_EQ(frame_entry, | |
| 1971 controller.GetLastCommittedEntry()->GetFrameEntry(root)); | |
| 1972 FrameTreeNode* foo_subframe = root->child_at(1); | |
| 1973 EXPECT_EQ(main_site_instance, | |
| 1974 foo_subframe->current_frame_host()->GetSiteInstance()); | |
| 1975 FrameNavigationEntry* foo_subframe_entry = | |
| 1976 controller.GetLastCommittedEntry()->GetFrameEntry(foo_subframe); | |
| 1977 std::string named_subframe_target = "foo"; | |
| 1978 EXPECT_EQ(named_subframe_target, foo_subframe_entry->target()); | |
| 1979 | |
| 1980 // 4. Navigating in the subframes cross-process shouldn't change their names. | |
| 1981 // TODO(creis): Fix the unnamed case in https://crbug.com/502317. | |
|
Charlie Reis
2015/11/09 18:17:05
I'm working on the fix here:
https://codereview.ch
| |
| 1982 GURL bar_url(embedded_test_server()->GetURL( | |
| 1983 "bar.com", "/navigation_controller/simple_page_1.html")); | |
| 1984 NavigateFrameToURL(foo_subframe, bar_url); | |
| 1985 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | |
| 1986 EXPECT_NE(main_site_instance, | |
| 1987 foo_subframe->current_frame_host()->GetSiteInstance()); | |
| 1988 foo_subframe_entry = | |
| 1989 controller.GetLastCommittedEntry()->GetFrameEntry(foo_subframe); | |
| 1990 EXPECT_EQ(named_subframe_target, foo_subframe_entry->target()); | |
| 1991 } | |
| 1992 | |
| 1907 // Verifies that item sequence numbers and document sequence numbers update | 1993 // Verifies that item sequence numbers and document sequence numbers update |
| 1908 // properly for main frames and subframes. | 1994 // properly for main frames and subframes. |
| 1909 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1995 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1910 FrameNavigationEntry_SequenceNumbers) { | 1996 FrameNavigationEntry_SequenceNumbers) { |
| 1911 const NavigationControllerImpl& controller = | 1997 const NavigationControllerImpl& controller = |
| 1912 static_cast<const NavigationControllerImpl&>( | 1998 static_cast<const NavigationControllerImpl&>( |
| 1913 shell()->web_contents()->GetController()); | 1999 shell()->web_contents()->GetController()); |
| 1914 | 2000 |
| 1915 // 1. Navigate the main frame. | 2001 // 1. Navigate the main frame. |
| 1916 GURL url(embedded_test_server()->GetURL( | 2002 GURL url(embedded_test_server()->GetURL( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1939 EXPECT_NE(isn_1, isn_2); | 2025 EXPECT_NE(isn_1, isn_2); |
| 1940 EXPECT_EQ(dsn_1, dsn_2); | 2026 EXPECT_EQ(dsn_1, dsn_2); |
| 1941 | 2027 |
| 1942 // Test subframe sequence numbers only if enabled, e.g. in --site-per-process. | 2028 // Test subframe sequence numbers only if enabled, e.g. in --site-per-process. |
| 1943 if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) | 2029 if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) |
| 1944 return; | 2030 return; |
| 1945 | 2031 |
| 1946 // 3. Add a subframe, which does an AUTO_SUBFRAME navigation. | 2032 // 3. Add a subframe, which does an AUTO_SUBFRAME navigation. |
| 1947 { | 2033 { |
| 1948 LoadCommittedCapturer capturer(shell()->web_contents()); | 2034 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1949 std::string script = "var iframe = document.createElement('iframe');" | 2035 std::string add_script = "var iframe = document.createElement('iframe');" |
| 1950 "iframe.src = '" + url.spec() + "';" | 2036 "iframe.src = '" + url.spec() + "';" |
| 1951 "document.body.appendChild(iframe);"; | 2037 "document.body.appendChild(iframe);"; |
| 1952 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 2038 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), add_script)); |
| 1953 capturer.Wait(); | 2039 capturer.Wait(); |
| 1954 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 2040 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1955 } | 2041 } |
| 1956 | 2042 |
| 1957 // The root FrameNavigationEntry hasn't changed. | 2043 // The root FrameNavigationEntry hasn't changed. |
| 1958 EXPECT_EQ(frame_entry, | 2044 EXPECT_EQ(frame_entry, |
| 1959 controller.GetLastCommittedEntry()->GetFrameEntry(root)); | 2045 controller.GetLastCommittedEntry()->GetFrameEntry(root)); |
| 1960 | 2046 |
| 1961 // We should have a unique ISN and DSN for the subframe entry. | 2047 // We should have a unique ISN and DSN for the subframe entry. |
| 1962 FrameTreeNode* subframe = root->child_at(0); | 2048 FrameTreeNode* subframe = root->child_at(0); |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2381 EXPECT_EQ(original_url, capturer.all_params()[1].url); | 2467 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
| 2382 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 2468 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
| 2383 } | 2469 } |
| 2384 | 2470 |
| 2385 // Make sure the renderer is still alive. | 2471 // Make sure the renderer is still alive. |
| 2386 EXPECT_TRUE( | 2472 EXPECT_TRUE( |
| 2387 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | 2473 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
| 2388 } | 2474 } |
| 2389 | 2475 |
| 2390 } // namespace content | 2476 } // namespace content |
| OLD | NEW |