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/macros.h" | 5 #include "base/macros.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 #include "content/browser/frame_host/navigation_entry_impl.h" | 9 #include "content/browser/frame_host/navigation_entry_impl.h" |
10 #include "content/browser/renderer_host/render_widget_host_impl.h" | 10 #include "content/browser/renderer_host/render_widget_host_impl.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 shell_(shell), | 101 shell_(shell), |
102 url_(url), | 102 url_(url), |
103 done_(false) { | 103 done_(false) { |
104 } | 104 } |
105 | 105 |
106 // WebContentsObserver: | 106 // WebContentsObserver: |
107 void NavigationEntryCommitted( | 107 void NavigationEntryCommitted( |
108 const LoadCommittedDetails& load_details) override { | 108 const LoadCommittedDetails& load_details) override { |
109 if (!done_) { | 109 if (!done_) { |
110 done_ = true; | 110 done_ = true; |
| 111 shell_->Stop(); |
111 shell_->LoadURL(url_); | 112 shell_->LoadURL(url_); |
112 | |
113 // There should be a pending entry. | |
114 CHECK(shell_->web_contents()->GetController().GetPendingEntry()); | |
115 | |
116 // Now that there is a pending entry, stop the load. | |
117 shell_->Stop(); | |
118 } | 113 } |
119 } | 114 } |
120 | 115 |
121 Shell* shell_; | 116 Shell* shell_; |
122 GURL url_; | 117 GURL url_; |
123 bool done_; | 118 bool done_; |
124 }; | 119 }; |
125 | 120 |
126 class RenderViewSizeDelegate : public WebContentsDelegate { | 121 class RenderViewSizeDelegate : public WebContentsDelegate { |
127 public: | 122 public: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 int loadingStateChangedCount() const { return loadingStateChangedCount_; } | 182 int loadingStateChangedCount() const { return loadingStateChangedCount_; } |
188 int loadingStateToDifferentDocumentCount() const { | 183 int loadingStateToDifferentDocumentCount() const { |
189 return loadingStateToDifferentDocumentCount_; | 184 return loadingStateToDifferentDocumentCount_; |
190 } | 185 } |
191 | 186 |
192 private: | 187 private: |
193 int loadingStateChangedCount_; | 188 int loadingStateChangedCount_; |
194 int loadingStateToDifferentDocumentCount_; | 189 int loadingStateToDifferentDocumentCount_; |
195 }; | 190 }; |
196 | 191 |
| 192 // See: http://crbug.com/298193 |
| 193 #if defined(OS_WIN) || defined(OS_LINUX) |
| 194 #define MAYBE_DidStopLoadingDetails DISABLED_DidStopLoadingDetails |
| 195 #else |
| 196 #define MAYBE_DidStopLoadingDetails DidStopLoadingDetails |
| 197 #endif |
| 198 |
197 // Test that DidStopLoading includes the correct URL in the details. | 199 // Test that DidStopLoading includes the correct URL in the details. |
198 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, DidStopLoadingDetails) { | 200 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
| 201 MAYBE_DidStopLoadingDetails) { |
199 ASSERT_TRUE(embedded_test_server()->Start()); | 202 ASSERT_TRUE(embedded_test_server()->Start()); |
200 | 203 |
201 LoadStopNotificationObserver load_observer( | 204 LoadStopNotificationObserver load_observer( |
202 &shell()->web_contents()->GetController()); | 205 &shell()->web_contents()->GetController()); |
203 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); | 206 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); |
204 load_observer.Wait(); | 207 load_observer.Wait(); |
205 | 208 |
206 EXPECT_EQ("/title1.html", load_observer.url_.path()); | 209 EXPECT_EQ("/title1.html", load_observer.url_.path()); |
207 EXPECT_EQ(0, load_observer.session_index_); | 210 EXPECT_EQ(0, load_observer.session_index_); |
208 EXPECT_EQ(&shell()->web_contents()->GetController(), | 211 EXPECT_EQ(&shell()->web_contents()->GetController(), |
209 load_observer.controller_); | 212 load_observer.controller_); |
210 } | 213 } |
211 | 214 |
| 215 // See: http://crbug.com/298193 |
| 216 #if defined(OS_WIN) || defined(OS_LINUX) |
| 217 #define MAYBE_DidStopLoadingDetailsWithPending \ |
| 218 DISABLED_DidStopLoadingDetailsWithPending |
| 219 #else |
| 220 #define MAYBE_DidStopLoadingDetailsWithPending DidStopLoadingDetailsWithPending |
| 221 #endif |
| 222 |
212 // Test that DidStopLoading includes the correct URL in the details when a | 223 // Test that DidStopLoading includes the correct URL in the details when a |
213 // pending entry is present. | 224 // pending entry is present. |
214 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | 225 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
215 DidStopLoadingDetailsWithPending) { | 226 MAYBE_DidStopLoadingDetailsWithPending) { |
216 ASSERT_TRUE(embedded_test_server()->Start()); | 227 ASSERT_TRUE(embedded_test_server()->Start()); |
217 // TODO(clamy): Add a cross-process navigation case as well once | 228 GURL url("data:text/html,<div>test</div>"); |
218 // crbug.com/581024 is fixed. | |
219 GURL url1 = embedded_test_server()->GetURL("/title1.html"); | |
220 GURL url2 = embedded_test_server()->GetURL("/title2.html"); | |
221 | 229 |
222 // Listen for the first load to stop. | 230 // Listen for the first load to stop. |
223 LoadStopNotificationObserver load_observer( | 231 LoadStopNotificationObserver load_observer( |
224 &shell()->web_contents()->GetController()); | 232 &shell()->web_contents()->GetController()); |
225 // Start a new pending navigation as soon as the first load commits. | 233 // Start a new pending navigation as soon as the first load commits. |
226 // We will hear a DidStopLoading from the first load as the new load | 234 // We will hear a DidStopLoading from the first load as the new load |
227 // is started. | 235 // is started. |
228 NavigateOnCommitObserver commit_observer( | 236 NavigateOnCommitObserver commit_observer( |
229 shell(), url2); | 237 shell(), embedded_test_server()->GetURL("/title2.html")); |
230 NavigateToURL(shell(), url1); | 238 NavigateToURL(shell(), url); |
231 load_observer.Wait(); | 239 load_observer.Wait(); |
232 | 240 |
233 EXPECT_EQ(url1, load_observer.url_); | 241 EXPECT_EQ(url, load_observer.url_); |
234 EXPECT_EQ(0, load_observer.session_index_); | 242 EXPECT_EQ(0, load_observer.session_index_); |
235 EXPECT_EQ(&shell()->web_contents()->GetController(), | 243 EXPECT_EQ(&shell()->web_contents()->GetController(), |
236 load_observer.controller_); | 244 load_observer.controller_); |
237 } | 245 } |
238 // Test that a renderer-initiated navigation to an invalid URL does not leave | 246 // Test that a renderer-initiated navigation to an invalid URL does not leave |
239 // around a pending entry that could be used in a URL spoof. We test this in | 247 // around a pending entry that could be used in a URL spoof. We test this in |
240 // a browser test because our unit test framework incorrectly calls | 248 // a browser test because our unit test framework incorrectly calls |
241 // DidStartProvisionalLoadForFrame for in-page navigations. | 249 // DidStartProvisionalLoadForFrame for in-page navigations. |
242 // See http://crbug.com/280512. | 250 // See http://crbug.com/280512. |
243 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | 251 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 Shell* new_shell = new_shell_observer.GetShell(); | 812 Shell* new_shell = new_shell_observer.GetShell(); |
805 WaitForLoadStop(new_shell->web_contents()); | 813 WaitForLoadStop(new_shell->web_contents()); |
806 | 814 |
807 EXPECT_EQ("foo", | 815 EXPECT_EQ("foo", |
808 static_cast<WebContentsImpl*>(new_shell->web_contents()) | 816 static_cast<WebContentsImpl*>(new_shell->web_contents()) |
809 ->GetFrameTree()->root()->frame_name()); | 817 ->GetFrameTree()->root()->frame_name()); |
810 } | 818 } |
811 } | 819 } |
812 | 820 |
813 } // namespace content | 821 } // namespace content |
OLD | NEW |