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 |frame_unique_name| is set to the correct frame, so that we |
| 1908 // can match subframe FrameNavigationEntries to newly created frames after |
| 1909 // back/forward and restore. |
| 1910 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1911 FrameNavigationEntry_FrameUniqueName) { |
| 1912 const NavigationControllerImpl& controller = |
| 1913 static_cast<const NavigationControllerImpl&>( |
| 1914 shell()->web_contents()->GetController()); |
| 1915 |
| 1916 // 1. Navigate the main frame. |
| 1917 GURL url(embedded_test_server()->GetURL( |
| 1918 "/navigation_controller/page_with_links.html")); |
| 1919 NavigateToURL(shell(), url); |
| 1920 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| 1921 ->GetFrameTree() |
| 1922 ->root(); |
| 1923 SiteInstance* main_site_instance = |
| 1924 root->current_frame_host()->GetSiteInstance(); |
| 1925 |
| 1926 // The main frame defaults to an empty name. |
| 1927 FrameNavigationEntry* frame_entry = |
| 1928 controller.GetLastCommittedEntry()->GetFrameEntry(root); |
| 1929 EXPECT_EQ("", frame_entry->frame_unique_name()); |
| 1930 |
| 1931 // Test subframe unique names only if enabled, e.g. in --site-per-process. |
| 1932 if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) |
| 1933 return; |
| 1934 |
| 1935 // 2. Add an unnamed subframe, which does an AUTO_SUBFRAME navigation. |
| 1936 { |
| 1937 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1938 std::string script = "var iframe = document.createElement('iframe');" |
| 1939 "iframe.src = '" + url.spec() + "';" |
| 1940 "document.body.appendChild(iframe);"; |
| 1941 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 1942 capturer.Wait(); |
| 1943 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1944 } |
| 1945 |
| 1946 // The root FrameNavigationEntry hasn't changed. |
| 1947 EXPECT_EQ(frame_entry, |
| 1948 controller.GetLastCommittedEntry()->GetFrameEntry(root)); |
| 1949 |
| 1950 // The subframe should have a generated name. |
| 1951 FrameTreeNode* subframe = root->child_at(0); |
| 1952 EXPECT_EQ(main_site_instance, |
| 1953 subframe->current_frame_host()->GetSiteInstance()); |
| 1954 FrameNavigationEntry* subframe_entry = |
| 1955 controller.GetLastCommittedEntry()->GetFrameEntry(subframe); |
| 1956 std::string unnamed_subframe_name = "<!--framePath //<!--frame0-->-->"; |
| 1957 EXPECT_EQ(unnamed_subframe_name, subframe_entry->frame_unique_name()); |
| 1958 |
| 1959 // 3. Add a named subframe. |
| 1960 { |
| 1961 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1962 std::string script = "var iframe = document.createElement('iframe');" |
| 1963 "iframe.src = '" + url.spec() + "';" |
| 1964 "iframe.name = 'foo';" |
| 1965 "document.body.appendChild(iframe);"; |
| 1966 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| 1967 capturer.Wait(); |
| 1968 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1969 } |
| 1970 |
| 1971 // The new subframe should have the specified name. |
| 1972 EXPECT_EQ(frame_entry, |
| 1973 controller.GetLastCommittedEntry()->GetFrameEntry(root)); |
| 1974 FrameTreeNode* foo_subframe = root->child_at(1); |
| 1975 EXPECT_EQ(main_site_instance, |
| 1976 foo_subframe->current_frame_host()->GetSiteInstance()); |
| 1977 FrameNavigationEntry* foo_subframe_entry = |
| 1978 controller.GetLastCommittedEntry()->GetFrameEntry(foo_subframe); |
| 1979 std::string named_subframe_name = "foo"; |
| 1980 EXPECT_EQ(named_subframe_name, foo_subframe_entry->frame_unique_name()); |
| 1981 |
| 1982 // 4. Navigating in the subframes cross-process shouldn't change their names. |
| 1983 // TODO(creis): Fix the unnamed case in https://crbug.com/502317. |
| 1984 GURL bar_url(embedded_test_server()->GetURL( |
| 1985 "bar.com", "/navigation_controller/simple_page_1.html")); |
| 1986 NavigateFrameToURL(foo_subframe, bar_url); |
| 1987 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 1988 EXPECT_NE(main_site_instance, |
| 1989 foo_subframe->current_frame_host()->GetSiteInstance()); |
| 1990 foo_subframe_entry = |
| 1991 controller.GetLastCommittedEntry()->GetFrameEntry(foo_subframe); |
| 1992 EXPECT_EQ(named_subframe_name, foo_subframe_entry->frame_unique_name()); |
| 1993 } |
| 1994 |
1907 // Verifies that item sequence numbers and document sequence numbers update | 1995 // Verifies that item sequence numbers and document sequence numbers update |
1908 // properly for main frames and subframes. | 1996 // properly for main frames and subframes. |
1909 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1997 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
1910 FrameNavigationEntry_SequenceNumbers) { | 1998 FrameNavigationEntry_SequenceNumbers) { |
1911 const NavigationControllerImpl& controller = | 1999 const NavigationControllerImpl& controller = |
1912 static_cast<const NavigationControllerImpl&>( | 2000 static_cast<const NavigationControllerImpl&>( |
1913 shell()->web_contents()->GetController()); | 2001 shell()->web_contents()->GetController()); |
1914 | 2002 |
1915 // 1. Navigate the main frame. | 2003 // 1. Navigate the main frame. |
1916 GURL url(embedded_test_server()->GetURL( | 2004 GURL url(embedded_test_server()->GetURL( |
(...skipping 22 matching lines...) Expand all Loading... |
1939 EXPECT_NE(isn_1, isn_2); | 2027 EXPECT_NE(isn_1, isn_2); |
1940 EXPECT_EQ(dsn_1, dsn_2); | 2028 EXPECT_EQ(dsn_1, dsn_2); |
1941 | 2029 |
1942 // Test subframe sequence numbers only if enabled, e.g. in --site-per-process. | 2030 // Test subframe sequence numbers only if enabled, e.g. in --site-per-process. |
1943 if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) | 2031 if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) |
1944 return; | 2032 return; |
1945 | 2033 |
1946 // 3. Add a subframe, which does an AUTO_SUBFRAME navigation. | 2034 // 3. Add a subframe, which does an AUTO_SUBFRAME navigation. |
1947 { | 2035 { |
1948 LoadCommittedCapturer capturer(shell()->web_contents()); | 2036 LoadCommittedCapturer capturer(shell()->web_contents()); |
1949 std::string script = "var iframe = document.createElement('iframe');" | 2037 std::string add_script = "var iframe = document.createElement('iframe');" |
1950 "iframe.src = '" + url.spec() + "';" | 2038 "iframe.src = '" + url.spec() + "';" |
1951 "document.body.appendChild(iframe);"; | 2039 "document.body.appendChild(iframe);"; |
1952 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); | 2040 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), add_script)); |
1953 capturer.Wait(); | 2041 capturer.Wait(); |
1954 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); | 2042 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
1955 } | 2043 } |
1956 | 2044 |
1957 // The root FrameNavigationEntry hasn't changed. | 2045 // The root FrameNavigationEntry hasn't changed. |
1958 EXPECT_EQ(frame_entry, | 2046 EXPECT_EQ(frame_entry, |
1959 controller.GetLastCommittedEntry()->GetFrameEntry(root)); | 2047 controller.GetLastCommittedEntry()->GetFrameEntry(root)); |
1960 | 2048 |
1961 // We should have a unique ISN and DSN for the subframe entry. | 2049 // We should have a unique ISN and DSN for the subframe entry. |
1962 FrameTreeNode* subframe = root->child_at(0); | 2050 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); | 2469 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
2382 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 2470 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
2383 } | 2471 } |
2384 | 2472 |
2385 // Make sure the renderer is still alive. | 2473 // Make sure the renderer is still alive. |
2386 EXPECT_TRUE( | 2474 EXPECT_TRUE( |
2387 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | 2475 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
2388 } | 2476 } |
2389 | 2477 |
2390 } // namespace content | 2478 } // namespace content |
OLD | NEW |