Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 263973003: Move LoadProgressTracker to the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final comment Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/common/frame_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 "var a = document.createElement('a');" 449 "var a = document.createElement('a');"
450 "a.href='./title2.html';" 450 "a.href='./title2.html';"
451 "a.target = '_blank';" 451 "a.target = '_blank';"
452 "document.body.appendChild(a);" 452 "document.body.appendChild(a);"
453 "a.click();")); 453 "a.click();"));
454 WebContents* new_web_contents = new_web_contents_observer.GetWebContents(); 454 WebContents* new_web_contents = new_web_contents_observer.GetWebContents();
455 WaitForLoadStop(new_web_contents); 455 WaitForLoadStop(new_web_contents);
456 EXPECT_TRUE(new_web_contents_observer.RenderViewCreatedCalled()); 456 EXPECT_TRUE(new_web_contents_observer.RenderViewCreatedCalled());
457 } 457 }
458 458
459 struct LoadProgressDelegateAndObserver : public WebContentsDelegate,
460 public WebContentsObserver {
461 LoadProgressDelegateAndObserver(Shell* shell)
462 : WebContentsObserver(shell->web_contents()),
463 did_start_loading(false),
464 did_stop_loading(false) {
465 web_contents()->SetDelegate(this);
466 }
467
468 // WebContentsDelegate:
469 virtual void LoadProgressChanged(WebContents* source,
470 double progress) OVERRIDE {
471 EXPECT_TRUE(did_start_loading);
472 EXPECT_FALSE(did_stop_loading);
473 progresses.push_back(progress);
474 }
475
476 // WebContentsObserver:
477 virtual void DidStartLoading(RenderViewHost* render_view_host) OVERRIDE {
478 EXPECT_FALSE(did_start_loading);
479 EXPECT_EQ(0U, progresses.size());
480 EXPECT_FALSE(did_stop_loading);
481 did_start_loading = true;
482 }
483
484 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE {
485 EXPECT_TRUE(did_start_loading);
486 EXPECT_GE(progresses.size(), 1U);
487 EXPECT_FALSE(did_stop_loading);
488 did_stop_loading = true;
489 }
490
491 bool did_start_loading;
492 std::vector<double> progresses;
493 bool did_stop_loading;
494 };
495
496 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest, LoadProgress) {
497 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
498 scoped_ptr<LoadProgressDelegateAndObserver> delegate(
499 new LoadProgressDelegateAndObserver(shell()));
500
501 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
502
503 const std::vector<double>& progresses = delegate->progresses;
504 // All updates should be in order ...
505 if (std::adjacent_find(progresses.begin(),
506 progresses.end(),
507 std::greater<double>()) != progresses.end()) {
508 ADD_FAILURE() << "Progress values should be in order: "
509 << ::testing::PrintToString(progresses);
510 }
511
512 // ... and the last one should be 1.0, meaning complete.
513 ASSERT_GE(progresses.size(), 1U)
514 << "There should be at least one progress update";
515 EXPECT_EQ(1.0, *progresses.rbegin());
516 }
517
459 } // namespace content 518 } // namespace content
460 519
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/common/frame_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698