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/strings/utf_string_conversions.h" |
6 #include "base/values.h" | 6 #include "base/values.h" |
7 #include "content/browser/frame_host/navigation_entry_impl.h" | 7 #include "content/browser/frame_host/navigation_entry_impl.h" |
8 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
9 #include "content/browser/web_contents/web_contents_view.h" | 9 #include "content/browser/web_contents/web_contents_view.h" |
10 #include "content/public/browser/load_notification_details.h" | 10 #include "content/public/browser/load_notification_details.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 gfx::Size rwhv_create_size_; | 151 gfx::Size rwhv_create_size_; |
152 }; | 152 }; |
153 | 153 |
154 class LoadingStateChangedDelegate : public WebContentsDelegate { | 154 class LoadingStateChangedDelegate : public WebContentsDelegate { |
155 public: | 155 public: |
156 LoadingStateChangedDelegate() | 156 LoadingStateChangedDelegate() |
157 : loadingStateChangedCount_(0) | 157 : loadingStateChangedCount_(0) |
158 , loadingStateToDifferentDocumentCount_(0) { | 158 , loadingStateToDifferentDocumentCount_(0) { |
159 } | 159 } |
160 | 160 |
161 // WebContentsDelgate: | 161 // WebContentsDelegate: |
162 virtual void LoadingStateChanged(WebContents* contents, | 162 virtual void LoadingStateChanged(WebContents* contents, |
163 bool to_different_document) OVERRIDE { | 163 bool to_different_document) OVERRIDE { |
164 loadingStateChangedCount_++; | 164 loadingStateChangedCount_++; |
165 if (to_different_document) | 165 if (to_different_document) |
166 loadingStateToDifferentDocumentCount_++; | 166 loadingStateToDifferentDocumentCount_++; |
167 } | 167 } |
168 | 168 |
169 int loadingStateChangedCount() const { return loadingStateChangedCount_; } | 169 int loadingStateChangedCount() const { return loadingStateChangedCount_; } |
170 int loadingStateToDifferentDocumentCount() const { | 170 int loadingStateToDifferentDocumentCount() const { |
171 return loadingStateToDifferentDocumentCount_; | 171 return loadingStateToDifferentDocumentCount_; |
172 } | 172 } |
173 | 173 |
174 private: | 174 private: |
175 int loadingStateChangedCount_; | 175 int loadingStateChangedCount_; |
176 int loadingStateToDifferentDocumentCount_; | 176 int loadingStateToDifferentDocumentCount_; |
177 }; | 177 }; |
178 | 178 |
179 struct LoadProgressDelegate : public WebContentsDelegate { | |
180 // WebContentsDelegate: | |
181 virtual void LoadProgressChanged(WebContents* source, | |
182 double progress) OVERRIDE { | |
183 progresses.push_back(progress); | |
184 } | |
185 | |
186 std::vector<double> progresses; | |
187 }; | |
188 | |
179 // See: http://crbug.com/298193 | 189 // See: http://crbug.com/298193 |
180 #if defined(OS_WIN) | 190 #if defined(OS_WIN) |
181 #define MAYBE_DidStopLoadingDetails DISABLED_DidStopLoadingDetails | 191 #define MAYBE_DidStopLoadingDetails DISABLED_DidStopLoadingDetails |
182 #else | 192 #else |
183 #define MAYBE_DidStopLoadingDetails DidStopLoadingDetails | 193 #define MAYBE_DidStopLoadingDetails DidStopLoadingDetails |
184 #endif | 194 #endif |
185 | 195 |
186 // Test that DidStopLoading includes the correct URL in the details. | 196 // Test that DidStopLoading includes the correct URL in the details. |
187 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, | 197 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, |
188 MAYBE_DidStopLoadingDetails) { | 198 MAYBE_DidStopLoadingDetails) { |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 | 440 |
431 // LoadingStateChanged should be called 4 times: start and stop for the | 441 // LoadingStateChanged should be called 4 times: start and stop for the |
432 // initial load of push_state.html, and start and stop for the "navigation" | 442 // initial load of push_state.html, and start and stop for the "navigation" |
433 // triggered by history.pushState(). However, the start notification for the | 443 // triggered by history.pushState(). However, the start notification for the |
434 // history.pushState() navigation should set to_different_document to false. | 444 // history.pushState() navigation should set to_different_document to false. |
435 EXPECT_EQ("pushState", shell()->web_contents()->GetURL().ref()); | 445 EXPECT_EQ("pushState", shell()->web_contents()->GetURL().ref()); |
436 EXPECT_EQ(4, delegate->loadingStateChangedCount()); | 446 EXPECT_EQ(4, delegate->loadingStateChangedCount()); |
437 EXPECT_EQ(3, delegate->loadingStateToDifferentDocumentCount()); | 447 EXPECT_EQ(3, delegate->loadingStateToDifferentDocumentCount()); |
438 } | 448 } |
439 | 449 |
450 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, LoadProgress) { | |
Charlie Reis
2014/05/07 23:51:00
This doesn't seem to test that DidStartLoading and
Avi (use Gerrit)
2014/05/13 21:08:08
Done.
| |
451 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
452 scoped_ptr<LoadProgressDelegate> delegate(new LoadProgressDelegate()); | |
453 shell()->web_contents()->SetDelegate(delegate.get()); | |
454 | |
455 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); | |
456 | |
457 const std::vector<double>& progresses = delegate->progresses; | |
458 // All updates should be in order ... | |
459 if (std::adjacent_find(progresses.begin(), | |
460 progresses.end(), | |
461 std::greater<double>()) != progresses.end()) { | |
462 ADD_FAILURE() << "Progress values should be in order: " | |
463 << ::testing::PrintToString(progresses); | |
464 } | |
465 | |
466 // ... and the last one should be 1.0, meaning complete. | |
467 ASSERT_GE(progresses.size(), 1U) | |
468 << "There should be at least one progress update"; | |
469 EXPECT_EQ(1.0, *progresses.rbegin()); | |
470 } | |
471 | |
440 } // namespace content | 472 } // namespace content |
441 | 473 |
OLD | NEW |