Chromium Code Reviews| 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/strings/utf_string_conversions.h" | |
| 5 #include "base/values.h" | 6 #include "base/values.h" |
| 6 #include "content/browser/frame_host/navigation_entry_impl.h" | 7 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 7 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
| 8 #include "content/public/browser/load_notification_details.h" | 9 #include "content/public/browser/load_notification_details.h" |
| 9 #include "content/public/browser/navigation_controller.h" | 10 #include "content/public/browser/navigation_controller.h" |
| 10 #include "content/public/browser/notification_details.h" | 11 #include "content/public/browser/notification_details.h" |
| 11 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
| 12 #include "content/public/browser/notification_types.h" | 13 #include "content/public/browser/notification_types.h" |
| 13 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 14 #include "content/public/browser/render_widget_host_view.h" | 15 #include "content/public/browser/render_widget_host_view.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 } | 144 } |
| 144 | 145 |
| 145 gfx::Size rwhv_create_size() const { return rwhv_create_size_; } | 146 gfx::Size rwhv_create_size() const { return rwhv_create_size_; } |
| 146 | 147 |
| 147 private: | 148 private: |
| 148 Shell* shell_; // Weak ptr. | 149 Shell* shell_; // Weak ptr. |
| 149 gfx::Size wcv_new_size_; | 150 gfx::Size wcv_new_size_; |
| 150 gfx::Size rwhv_create_size_; | 151 gfx::Size rwhv_create_size_; |
| 151 }; | 152 }; |
| 152 | 153 |
| 154 class LoadingStateChangedDelegate : public WebContentsDelegate { | |
| 155 public: | |
| 156 LoadingStateChangedDelegate() | |
| 157 : loadingStateChangedCount_(0) | |
| 158 , loadingStateToDifferentDocumentCount_(0) { | |
| 159 } | |
| 160 | |
| 161 // WebContentsDelgate: | |
| 162 virtual void LoadingStateChanged(WebContents* contents, | |
| 163 bool to_different_document) OVERRIDE { | |
| 164 loadingStateChangedCount_++; | |
| 165 if (to_different_document) | |
| 166 loadingStateToDifferentDocumentCount_++; | |
|
Charlie Reis
2014/03/10 20:07:46
nit: 2 space indent
| |
| 167 } | |
| 168 | |
| 169 int loadingStateChangedCount() const { return loadingStateChangedCount_; } | |
| 170 int loadingStateToDifferentDocumentCount() const { | |
| 171 return loadingStateToDifferentDocumentCount_; | |
|
Charlie Reis
2014/03/10 20:07:46
nit: 2 space indent
| |
| 172 } | |
| 173 | |
| 174 private: | |
| 175 int loadingStateChangedCount_; | |
| 176 int loadingStateToDifferentDocumentCount_; | |
| 177 }; | |
| 178 | |
| 153 // See: http://crbug.com/298193 | 179 // See: http://crbug.com/298193 |
| 154 #if defined(OS_WIN) | 180 #if defined(OS_WIN) |
| 155 #define MAYBE_DidStopLoadingDetails DISABLED_DidStopLoadingDetails | 181 #define MAYBE_DidStopLoadingDetails DISABLED_DidStopLoadingDetails |
| 156 #else | 182 #else |
| 157 #define MAYBE_DidStopLoadingDetails DidStopLoadingDetails | 183 #define MAYBE_DidStopLoadingDetails DidStopLoadingDetails |
| 158 #endif | 184 #endif |
| 159 | 185 |
| 160 // Test that DidStopLoading includes the correct URL in the details. | 186 // Test that DidStopLoading includes the correct URL in the details. |
| 161 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | 187 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
| 162 MAYBE_DidStopLoadingDetails) { | 188 MAYBE_DidStopLoadingDetails) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 // Install the observer and navigate cross-site. | 393 // Install the observer and navigate cross-site. |
| 368 RenderFrameCreatedObserver observer(shell()); | 394 RenderFrameCreatedObserver observer(shell()); |
| 369 NavigateToURL(shell(), cross_site_url); | 395 NavigateToURL(shell(), cross_site_url); |
| 370 | 396 |
| 371 // The observer should've seen a RenderFrameCreated call for the new frame | 397 // The observer should've seen a RenderFrameCreated call for the new frame |
| 372 // and not the old one. | 398 // and not the old one. |
| 373 EXPECT_NE(observer.last_rfh(), orig_rfh); | 399 EXPECT_NE(observer.last_rfh(), orig_rfh); |
| 374 EXPECT_EQ(observer.last_rfh(), shell()->web_contents()->GetMainFrame()); | 400 EXPECT_EQ(observer.last_rfh(), shell()->web_contents()->GetMainFrame()); |
| 375 } | 401 } |
| 376 | 402 |
| 403 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | |
| 404 LoadingStateChangedForSameDocumentNavigation) { | |
| 405 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
| 406 scoped_ptr<LoadingStateChangedDelegate> delegate( | |
| 407 new LoadingStateChangedDelegate()); | |
| 408 shell()->web_contents()->SetDelegate(delegate.get()); | |
| 409 | |
| 410 LoadStopNotificationObserver load_observer( | |
| 411 &shell()->web_contents()->GetController()); | |
| 412 TitleWatcher title_watcher(shell()->web_contents(), | |
| 413 base::ASCIIToUTF16("pushState")); | |
|
Charlie Reis
2014/03/10 20:07:46
nit: Align with first argument.
| |
| 414 NavigateToURL(shell(), embedded_test_server()->GetURL("/push_state.html")); | |
| 415 load_observer.Wait(); | |
| 416 base::string16 title = title_watcher.WaitAndGetTitle(); | |
| 417 ASSERT_EQ(title, base::ASCIIToUTF16("pushState")); | |
| 418 | |
| 419 // LoadingStateChanged should be called 4 times, start and stop for the | |
|
Charlie Reis
2014/03/10 20:07:46
Colon rather than comma.
| |
| 420 // initial load of push_state.html, and start and stop for the "navigation" | |
| 421 // triggered by history.pushState(). However, the start notification for the | |
| 422 // history.pushState() navigation should set to_different_document to false. | |
| 423 EXPECT_EQ("pushState", shell()->web_contents()->GetURL().ref()); | |
| 424 EXPECT_EQ(4, delegate->loadingStateChangedCount()); | |
| 425 EXPECT_EQ(3, delegate->loadingStateToDifferentDocumentCount()); | |
| 426 } | |
| 427 | |
| 377 } // namespace content | 428 } // namespace content |
| OLD | NEW |