| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/values.h" | 5 #include "base/values.h" |
| 6 #include "content/browser/renderer_host/render_view_host_impl.h" | 6 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 7 #include "content/browser/web_contents/web_contents_impl.h" | 7 #include "content/browser/web_contents/web_contents_impl.h" |
| 8 #include "content/public/browser/load_notification_details.h" | 8 #include "content/public/browser/load_notification_details.h" |
| 9 #include "content/public/browser/navigation_controller.h" | 9 #include "content/public/browser/navigation_controller.h" |
| 10 #include "content/public/browser/notification_details.h" | 10 #include "content/public/browser/notification_details.h" |
| 11 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
| 12 #include "content/public/browser/notification_types.h" | 12 #include "content/public/browser/notification_types.h" |
| 13 #include "content/public/common/content_paths.h" |
| 13 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
| 14 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| 15 #include "content/shell/shell.h" | 16 #include "content/shell/shell.h" |
| 16 #include "content/test/content_browser_test.h" | 17 #include "content/test/content_browser_test.h" |
| 17 #include "content/test/content_browser_test_utils.h" | 18 #include "content/test/content_browser_test_utils.h" |
| 19 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 18 #include "net/test/spawned_test_server/spawned_test_server.h" | 20 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 class WebContentsImplBrowserTest : public ContentBrowserTest { | 24 class WebContentsImplBrowserTest : public ContentBrowserTest { |
| 23 public: | 25 public: |
| 24 WebContentsImplBrowserTest() {} | 26 WebContentsImplBrowserTest() {} |
| 25 | 27 |
| 26 private: | 28 private: |
| 27 DISALLOW_COPY_AND_ASSIGN(WebContentsImplBrowserTest); | 29 DISALLOW_COPY_AND_ASSIGN(WebContentsImplBrowserTest); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 WindowedNotificationObserver::Observe(type, source, details); | 80 WindowedNotificationObserver::Observe(type, source, details); |
| 79 } | 81 } |
| 80 | 82 |
| 81 Shell* shell_; | 83 Shell* shell_; |
| 82 GURL url_; | 84 GURL url_; |
| 83 bool done_; | 85 bool done_; |
| 84 }; | 86 }; |
| 85 | 87 |
| 86 // Test that DidStopLoading includes the correct URL in the details. | 88 // Test that DidStopLoading includes the correct URL in the details. |
| 87 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DidStopLoadingDetails) { | 89 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DidStopLoadingDetails) { |
| 88 ASSERT_TRUE(test_server()->Start()); | 90 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 89 | 91 |
| 90 LoadStopNotificationObserver load_observer( | 92 LoadStopNotificationObserver load_observer( |
| 91 &shell()->web_contents()->GetController()); | 93 &shell()->web_contents()->GetController()); |
| 92 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | 94 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); |
| 93 load_observer.Wait(); | 95 load_observer.Wait(); |
| 94 | 96 |
| 95 EXPECT_EQ("/files/title1.html", load_observer.url_.path()); | 97 EXPECT_EQ("/title1.html", load_observer.url_.path()); |
| 96 EXPECT_EQ(0, load_observer.session_index_); | 98 EXPECT_EQ(0, load_observer.session_index_); |
| 97 EXPECT_EQ(&shell()->web_contents()->GetController(), | 99 EXPECT_EQ(&shell()->web_contents()->GetController(), |
| 98 load_observer.controller_); | 100 load_observer.controller_); |
| 99 } | 101 } |
| 100 | 102 |
| 101 // Test that DidStopLoading includes the correct URL in the details when a | 103 // Test that DidStopLoading includes the correct URL in the details when a |
| 102 // pending entry is present. | 104 // pending entry is present. |
| 103 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | 105 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
| 104 DidStopLoadingDetailsWithPending) { | 106 DidStopLoadingDetailsWithPending) { |
| 105 ASSERT_TRUE(test_server()->Start()); | 107 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 106 | 108 |
| 107 // Listen for the first load to stop. | 109 // Listen for the first load to stop. |
| 108 LoadStopNotificationObserver load_observer( | 110 LoadStopNotificationObserver load_observer( |
| 109 &shell()->web_contents()->GetController()); | 111 &shell()->web_contents()->GetController()); |
| 110 // Start a new pending navigation as soon as the first load commits. | 112 // Start a new pending navigation as soon as the first load commits. |
| 111 // We will hear a DidStopLoading from the first load as the new load | 113 // We will hear a DidStopLoading from the first load as the new load |
| 112 // is started. | 114 // is started. |
| 113 NavigateOnCommitObserver commit_observer( | 115 NavigateOnCommitObserver commit_observer( |
| 114 shell(), test_server()->GetURL("files/title2.html")); | 116 shell(), embedded_test_server()->GetURL("/title2.html")); |
| 115 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | 117 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); |
| 116 commit_observer.Wait(); | 118 commit_observer.Wait(); |
| 117 load_observer.Wait(); | 119 load_observer.Wait(); |
| 118 | 120 |
| 119 EXPECT_EQ("/files/title1.html", load_observer.url_.path()); | 121 EXPECT_EQ("/title1.html", load_observer.url_.path()); |
| 120 EXPECT_EQ(0, load_observer.session_index_); | 122 EXPECT_EQ(0, load_observer.session_index_); |
| 121 EXPECT_EQ(&shell()->web_contents()->GetController(), | 123 EXPECT_EQ(&shell()->web_contents()->GetController(), |
| 122 load_observer.controller_); | 124 load_observer.controller_); |
| 123 } | 125 } |
| 124 | 126 |
| 125 // Test that the browser receives the proper frame attach/detach messages from | 127 // Test that the browser receives the proper frame attach/detach messages from |
| 126 // the renderer and builds proper frame tree. | 128 // the renderer and builds proper frame tree. |
| 127 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, FrameTree) { | 129 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, FrameTree) { |
| 128 ASSERT_TRUE(test_server()->Start()); | 130 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 129 | 131 |
| 130 NavigateToURL(shell(), test_server()->GetURL("files/frame_tree/top.html")); | 132 NavigateToURL(shell(), |
| 133 embedded_test_server()->GetURL("/frame_tree/top.html")); |
| 131 | 134 |
| 132 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); | 135 WebContentsImpl* wc = static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 133 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 136 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 134 wc->GetRenderViewHost()); | 137 wc->GetRenderViewHost()); |
| 135 FrameTreeNode* root = wc->GetFrameTreeRootForTesting(); | 138 FrameTreeNode* root = wc->GetFrameTreeRootForTesting(); |
| 136 | 139 |
| 137 // Check that the root node is properly created with the frame id of the | 140 // Check that the root node is properly created with the frame id of the |
| 138 // initial navigation. | 141 // initial navigation. |
| 139 EXPECT_EQ(3UL, root->child_count()); | 142 EXPECT_EQ(3UL, root->child_count()); |
| 140 EXPECT_EQ(std::string(), root->frame_name()); | 143 EXPECT_EQ(std::string(), root->frame_name()); |
| 141 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | 144 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); |
| 142 | 145 |
| 143 EXPECT_EQ(2UL, root->child_at(0)->child_count()); | 146 EXPECT_EQ(2UL, root->child_at(0)->child_count()); |
| 144 EXPECT_STREQ("1-1-name", root->child_at(0)->frame_name().c_str()); | 147 EXPECT_STREQ("1-1-name", root->child_at(0)->frame_name().c_str()); |
| 145 | 148 |
| 146 // Verify the deepest node exists and has the right name. | 149 // Verify the deepest node exists and has the right name. |
| 147 EXPECT_EQ(2UL, root->child_at(2)->child_count()); | 150 EXPECT_EQ(2UL, root->child_at(2)->child_count()); |
| 148 EXPECT_EQ(1UL, root->child_at(2)->child_at(1)->child_count()); | 151 EXPECT_EQ(1UL, root->child_at(2)->child_at(1)->child_count()); |
| 149 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_at(0)->child_count()); | 152 EXPECT_EQ(0UL, root->child_at(2)->child_at(1)->child_at(0)->child_count()); |
| 150 EXPECT_STREQ("3-1-id", | 153 EXPECT_STREQ("3-1-id", |
| 151 root->child_at(2)->child_at(1)->child_at(0)->frame_name().c_str()); | 154 root->child_at(2)->child_at(1)->child_at(0)->frame_name().c_str()); |
| 152 | 155 |
| 153 // Navigate to about:blank, which should leave only the root node of the frame | 156 // Navigate to about:blank, which should leave only the root node of the frame |
| 154 // tree in the browser process. | 157 // tree in the browser process. |
| 155 NavigateToURL(shell(), test_server()->GetURL("files/title1.html")); | 158 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); |
| 156 | 159 |
| 157 root = wc->GetFrameTreeRootForTesting(); | 160 root = wc->GetFrameTreeRootForTesting(); |
| 158 EXPECT_EQ(0UL, root->child_count()); | 161 EXPECT_EQ(0UL, root->child_count()); |
| 159 EXPECT_EQ(std::string(), root->frame_name()); | 162 EXPECT_EQ(std::string(), root->frame_name()); |
| 160 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); | 163 EXPECT_EQ(rvh->main_frame_id(), root->frame_id()); |
| 161 } | 164 } |
| 162 | 165 |
| 163 } // namespace content | 166 } // namespace content |
| OLD | NEW |