Chromium Code Reviews| Index: content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| diff --git a/content/browser/frame_host/navigation_controller_impl_browsertest.cc b/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| index fe2616cac523324dbf154ebab9d6139450ece98c..d52a94ff398524bf40993ddeace8c0669571e8d4 100644 |
| --- a/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| +++ b/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| @@ -1904,6 +1904,92 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| } |
| } |
| +// Verifies that the target is correctly set to the unique name of the frame. |
| +IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| + FrameNavigationEntry_Target) { |
| + const NavigationControllerImpl& controller = |
| + static_cast<const NavigationControllerImpl&>( |
| + shell()->web_contents()->GetController()); |
| + |
| + // 1. Navigate the main frame. |
| + GURL url(embedded_test_server()->GetURL( |
| + "/navigation_controller/page_with_links.html")); |
| + NavigateToURL(shell(), url); |
| + FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
| + ->GetFrameTree() |
| + ->root(); |
| + SiteInstance* main_site_instance = |
| + root->current_frame_host()->GetSiteInstance(); |
| + |
| + // The main frame defaults to an empty target. |
| + FrameNavigationEntry* frame_entry = |
| + controller.GetLastCommittedEntry()->GetFrameEntry(root); |
| + EXPECT_EQ("", frame_entry->target()); |
| + |
| + // Test subframe targets only if enabled, e.g. in --site-per-process. |
| + if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) |
| + return; |
| + |
| + // 2. Add an unnamed subframe, which does an AUTO_SUBFRAME navigation. |
| + { |
| + LoadCommittedCapturer capturer(shell()->web_contents()); |
| + std::string script = "var iframe = document.createElement('iframe');" |
| + "iframe.src = '" + url.spec() + "';" |
| + "document.body.appendChild(iframe);"; |
| + EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| + capturer.Wait(); |
| + EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| + } |
| + |
| + // The root FrameNavigationEntry hasn't changed. |
| + EXPECT_EQ(frame_entry, |
| + controller.GetLastCommittedEntry()->GetFrameEntry(root)); |
| + |
| + // The subframe should have a generated name for the target. |
| + FrameTreeNode* subframe = root->child_at(0); |
| + EXPECT_EQ(main_site_instance, |
| + subframe->current_frame_host()->GetSiteInstance()); |
| + FrameNavigationEntry* subframe_entry = |
| + controller.GetLastCommittedEntry()->GetFrameEntry(subframe); |
| + std::string unnamed_subframe_target = "<!--framePath //<!--frame0-->-->"; |
| + EXPECT_EQ(unnamed_subframe_target, subframe_entry->target()); |
| + |
| + // 3. Add a named subframe. |
| + { |
| + LoadCommittedCapturer capturer(shell()->web_contents()); |
| + std::string script = "var iframe = document.createElement('iframe');" |
| + "iframe.src = '" + url.spec() + "';" |
| + "iframe.name = 'foo';" |
| + "document.body.appendChild(iframe);"; |
| + EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| + capturer.Wait(); |
| + EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| + } |
| + |
| + // The new subframe should have the specified name for the target. |
| + EXPECT_EQ(frame_entry, |
| + controller.GetLastCommittedEntry()->GetFrameEntry(root)); |
| + FrameTreeNode* foo_subframe = root->child_at(1); |
| + EXPECT_EQ(main_site_instance, |
| + foo_subframe->current_frame_host()->GetSiteInstance()); |
| + FrameNavigationEntry* foo_subframe_entry = |
| + controller.GetLastCommittedEntry()->GetFrameEntry(foo_subframe); |
| + std::string named_subframe_target = "foo"; |
| + EXPECT_EQ(named_subframe_target, foo_subframe_entry->target()); |
| + |
| + // 4. Navigating in the subframes cross-process shouldn't change their names. |
| + // 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
|
| + GURL bar_url(embedded_test_server()->GetURL( |
| + "bar.com", "/navigation_controller/simple_page_1.html")); |
| + NavigateFrameToURL(foo_subframe, bar_url); |
| + EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| + EXPECT_NE(main_site_instance, |
| + foo_subframe->current_frame_host()->GetSiteInstance()); |
| + foo_subframe_entry = |
| + controller.GetLastCommittedEntry()->GetFrameEntry(foo_subframe); |
| + EXPECT_EQ(named_subframe_target, foo_subframe_entry->target()); |
| +} |
| + |
| // Verifies that item sequence numbers and document sequence numbers update |
| // properly for main frames and subframes. |
| IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| @@ -1946,10 +2032,10 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| // 3. Add a subframe, which does an AUTO_SUBFRAME navigation. |
| { |
| LoadCommittedCapturer capturer(shell()->web_contents()); |
| - std::string script = "var iframe = document.createElement('iframe');" |
| - "iframe.src = '" + url.spec() + "';" |
| - "document.body.appendChild(iframe);"; |
| - EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), script)); |
| + std::string add_script = "var iframe = document.createElement('iframe');" |
| + "iframe.src = '" + url.spec() + "';" |
| + "document.body.appendChild(iframe);"; |
| + EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), add_script)); |
| capturer.Wait(); |
| EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| } |