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 fa7bff0bb707d2e07ebbfe81ac04d3559c4d3677..e5210fe04f8f28b444ed959f6af7ab10ef412bfa 100644 |
| --- a/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| +++ b/content/browser/frame_host/navigation_controller_impl_browsertest.cc |
| @@ -217,6 +217,46 @@ struct FrameNavigateParamsCapturer : public WebContentsObserver { |
| scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| }; |
| +struct LoadCommittedCapturer : public WebContentsObserver { |
| + public: |
| + explicit LoadCommittedCapturer(FrameTreeNode* node) |
| + : WebContentsObserver( |
| + node->current_frame_host()->delegate()->GetAsWebContents()), |
| + frame_tree_node_id_(node->frame_tree_node_id()), |
| + message_loop_runner_(new MessageLoopRunner) {} |
| + |
| + void Wait() { |
| + message_loop_runner_->Run(); |
| + } |
| + |
| + ui::PageTransition transition_type() const { |
| + return transition_type_; |
| + } |
| + |
| + private: |
| + void DidCommitProvisionalLoadForFrame( |
| + RenderFrameHost* render_frame_host, |
| + const GURL& url, |
| + ui::PageTransition transition_type) override { |
| + RenderFrameHostImpl* rfh = |
| + static_cast<RenderFrameHostImpl*>(render_frame_host); |
| + if (rfh->frame_tree_node()->frame_tree_node_id() != frame_tree_node_id_) |
| + return; |
| + |
| + transition_type_ = transition_type; |
| + message_loop_runner_->Quit(); |
| + } |
| + |
| + // The id of the FrameTreeNode whose navigations to observe. |
| + int frame_tree_node_id_; |
| + |
| + // The transition_type of the last navigation. |
| + ui::PageTransition transition_type_; |
| + |
| + // The MessageLoopRunner used to spin the message loop. |
| + scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| +}; |
| + |
| } // namespace |
| // Verify that the distinction between manual and auto subframes is properly set |
| @@ -224,8 +264,8 @@ struct FrameNavigateParamsCapturer : public WebContentsObserver { |
| // in two different enums; http://crbug.com/453555. |
| IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| ManualAndAutoSubframeNavigationClassification) { |
| - GURL main_url( |
| - embedded_test_server()->GetURL("/frame_tree/page_with_one_frame.html")); |
| + GURL main_url(embedded_test_server()->GetURL( |
| + "/navigation_controller/page_with_iframe.html")); |
| NavigateToURL(shell(), main_url); |
| // It is safe to obtain the root frame tree node here, as it doesn't change. |
| @@ -239,8 +279,8 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| { |
| // Navigate the iframe to a new URL; expect a manual subframe transition. |
| FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| - GURL frame_url( |
| - embedded_test_server()->GetURL("/frame_tree/2-1.html")); |
| + GURL frame_url(embedded_test_server()->GetURL( |
| + "/navigation_controller/simple_page_1.html")); |
| NavigateFrameToURL(root->child_at(0), frame_url); |
| capturer.Wait(); |
| EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| @@ -249,7 +289,7 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| } |
| { |
| - // History navigations should result in an auto subframe transition. |
| + // Do a history navigation; expect an auto subframe transition. |
| FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| shell()->web_contents()->GetController().GoBack(); |
| capturer.Wait(); |
| @@ -258,7 +298,7 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| } |
| { |
| - // History navigations should result in an auto subframe transition. |
| + // Do a history navigation; expect an auto subframe transition. |
| FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| shell()->web_contents()->GetController().GoForward(); |
| capturer.Wait(); |
| @@ -269,14 +309,24 @@ IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| { |
| // Navigate the iframe to a new URL; expect a manual subframe transition. |
| FrameNavigateParamsCapturer capturer(root->child_at(0)); |
| - GURL frame_url( |
| - embedded_test_server()->GetURL("/frame_tree/2-3.html")); |
| + GURL frame_url(embedded_test_server()->GetURL( |
| + "/navigation_controller/simple_page_2.html")); |
| NavigateFrameToURL(root->child_at(0), frame_url); |
| capturer.Wait(); |
| EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| capturer.params().transition); |
| EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| } |
| + |
| + { |
| + // Reload the subframe; expect an auto subframe transition. (Reloads aren't |
| + // "navigation" so we only see the frame load committing.) |
| + LoadCommittedCapturer capturer(root->child_at(0)); |
| + EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
| + "location.reload()")); |
| + capturer.Wait(); |
| + EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| + } |
|
Charlie Reis
2015/02/18 17:57:37
We should add a case for location.replace in the s
Avi (use Gerrit)
2015/02/18 18:33:12
More tests are always awesome. Let me try to make
|
| } |
| } // namespace content |