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

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

Issue 667943003: Standardize usage of virtual/override/final in content/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // Keeps track of data from LoadNotificationDetails so we can later verify that 56 // Keeps track of data from LoadNotificationDetails so we can later verify that
57 // they are correct, after the LoadNotificationDetails object is deleted. 57 // they are correct, after the LoadNotificationDetails object is deleted.
58 class LoadStopNotificationObserver : public WindowedNotificationObserver { 58 class LoadStopNotificationObserver : public WindowedNotificationObserver {
59 public: 59 public:
60 LoadStopNotificationObserver(NavigationController* controller) 60 LoadStopNotificationObserver(NavigationController* controller)
61 : WindowedNotificationObserver(NOTIFICATION_LOAD_STOP, 61 : WindowedNotificationObserver(NOTIFICATION_LOAD_STOP,
62 Source<NavigationController>(controller)), 62 Source<NavigationController>(controller)),
63 session_index_(-1), 63 session_index_(-1),
64 controller_(NULL) { 64 controller_(NULL) {
65 } 65 }
66 virtual void Observe(int type, 66 void Observe(int type,
67 const NotificationSource& source, 67 const NotificationSource& source,
68 const NotificationDetails& details) override { 68 const NotificationDetails& details) override {
69 if (type == NOTIFICATION_LOAD_STOP) { 69 if (type == NOTIFICATION_LOAD_STOP) {
70 const Details<LoadNotificationDetails> load_details(details); 70 const Details<LoadNotificationDetails> load_details(details);
71 url_ = load_details->url; 71 url_ = load_details->url;
72 session_index_ = load_details->session_index; 72 session_index_ = load_details->session_index;
73 controller_ = load_details->controller; 73 controller_ = load_details->controller;
74 } 74 }
75 WindowedNotificationObserver::Observe(type, source, details); 75 WindowedNotificationObserver::Observe(type, source, details);
76 } 76 }
77 77
78 GURL url_; 78 GURL url_;
79 int session_index_; 79 int session_index_;
80 NavigationController* controller_; 80 NavigationController* controller_;
81 }; 81 };
82 82
83 // Starts a new navigation as soon as the current one commits, but does not 83 // Starts a new navigation as soon as the current one commits, but does not
84 // wait for it to complete. This allows us to observe DidStopLoading while 84 // wait for it to complete. This allows us to observe DidStopLoading while
85 // a pending entry is present. 85 // a pending entry is present.
86 class NavigateOnCommitObserver : public WebContentsObserver { 86 class NavigateOnCommitObserver : public WebContentsObserver {
87 public: 87 public:
88 NavigateOnCommitObserver(Shell* shell, GURL url) 88 NavigateOnCommitObserver(Shell* shell, GURL url)
89 : WebContentsObserver(shell->web_contents()), 89 : WebContentsObserver(shell->web_contents()),
90 shell_(shell), 90 shell_(shell),
91 url_(url), 91 url_(url),
92 done_(false) { 92 done_(false) {
93 } 93 }
94 94
95 // WebContentsObserver: 95 // WebContentsObserver:
96 virtual void NavigationEntryCommitted( 96 void NavigationEntryCommitted(
97 const LoadCommittedDetails& load_details) override { 97 const LoadCommittedDetails& load_details) override {
98 if (!done_) { 98 if (!done_) {
99 done_ = true; 99 done_ = true;
100 shell_->Stop(); 100 shell_->Stop();
101 shell_->LoadURL(url_); 101 shell_->LoadURL(url_);
102 } 102 }
103 } 103 }
104 104
105 Shell* shell_; 105 Shell* shell_;
106 GURL url_; 106 GURL url_;
107 bool done_; 107 bool done_;
108 }; 108 };
109 109
110 class RenderViewSizeDelegate : public WebContentsDelegate { 110 class RenderViewSizeDelegate : public WebContentsDelegate {
111 public: 111 public:
112 void set_size_insets(const gfx::Size& size_insets) { 112 void set_size_insets(const gfx::Size& size_insets) {
113 size_insets_ = size_insets; 113 size_insets_ = size_insets;
114 } 114 }
115 115
116 // WebContentsDelegate: 116 // WebContentsDelegate:
117 virtual gfx::Size GetSizeForNewRenderView( 117 gfx::Size GetSizeForNewRenderView(WebContents* web_contents) const override {
118 WebContents* web_contents) const override {
119 gfx::Size size(web_contents->GetContainerBounds().size()); 118 gfx::Size size(web_contents->GetContainerBounds().size());
120 size.Enlarge(size_insets_.width(), size_insets_.height()); 119 size.Enlarge(size_insets_.width(), size_insets_.height());
121 return size; 120 return size;
122 } 121 }
123 122
124 private: 123 private:
125 gfx::Size size_insets_; 124 gfx::Size size_insets_;
126 }; 125 };
127 126
128 class RenderViewSizeObserver : public WebContentsObserver { 127 class RenderViewSizeObserver : public WebContentsObserver {
129 public: 128 public:
130 RenderViewSizeObserver(Shell* shell, const gfx::Size& wcv_new_size) 129 RenderViewSizeObserver(Shell* shell, const gfx::Size& wcv_new_size)
131 : WebContentsObserver(shell->web_contents()), 130 : WebContentsObserver(shell->web_contents()),
132 shell_(shell), 131 shell_(shell),
133 wcv_new_size_(wcv_new_size) { 132 wcv_new_size_(wcv_new_size) {
134 } 133 }
135 134
136 // WebContentsObserver: 135 // WebContentsObserver:
137 virtual void RenderViewCreated(RenderViewHost* rvh) override { 136 void RenderViewCreated(RenderViewHost* rvh) override {
138 rwhv_create_size_ = rvh->GetView()->GetViewBounds().size(); 137 rwhv_create_size_ = rvh->GetView()->GetViewBounds().size();
139 } 138 }
140 139
141 virtual void DidStartNavigationToPendingEntry( 140 void DidStartNavigationToPendingEntry(
142 const GURL& url, 141 const GURL& url,
143 NavigationController::ReloadType reload_type) override { 142 NavigationController::ReloadType reload_type) override {
144 ResizeWebContentsView(shell_, wcv_new_size_, false); 143 ResizeWebContentsView(shell_, wcv_new_size_, false);
145 } 144 }
146 145
147 gfx::Size rwhv_create_size() const { return rwhv_create_size_; } 146 gfx::Size rwhv_create_size() const { return rwhv_create_size_; }
148 147
149 private: 148 private:
150 Shell* shell_; // Weak ptr. 149 Shell* shell_; // Weak ptr.
151 gfx::Size wcv_new_size_; 150 gfx::Size wcv_new_size_;
152 gfx::Size rwhv_create_size_; 151 gfx::Size rwhv_create_size_;
153 }; 152 };
154 153
155 class LoadingStateChangedDelegate : public WebContentsDelegate { 154 class LoadingStateChangedDelegate : public WebContentsDelegate {
156 public: 155 public:
157 LoadingStateChangedDelegate() 156 LoadingStateChangedDelegate()
158 : loadingStateChangedCount_(0) 157 : loadingStateChangedCount_(0)
159 , loadingStateToDifferentDocumentCount_(0) { 158 , loadingStateToDifferentDocumentCount_(0) {
160 } 159 }
161 160
162 // WebContentsDelegate: 161 // WebContentsDelegate:
163 virtual void LoadingStateChanged(WebContents* contents, 162 void LoadingStateChanged(WebContents* contents,
164 bool to_different_document) override { 163 bool to_different_document) override {
165 loadingStateChangedCount_++; 164 loadingStateChangedCount_++;
166 if (to_different_document) 165 if (to_different_document)
167 loadingStateToDifferentDocumentCount_++; 166 loadingStateToDifferentDocumentCount_++;
168 } 167 }
169 168
170 int loadingStateChangedCount() const { return loadingStateChangedCount_; } 169 int loadingStateChangedCount() const { return loadingStateChangedCount_; }
171 int loadingStateToDifferentDocumentCount() const { 170 int loadingStateToDifferentDocumentCount() const {
172 return loadingStateToDifferentDocumentCount_; 171 return loadingStateToDifferentDocumentCount_;
173 } 172 }
174 173
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 377
379 // Observer class to track the creation of RenderFrameHost objects. It is used 378 // Observer class to track the creation of RenderFrameHost objects. It is used
380 // in subsequent tests. 379 // in subsequent tests.
381 class RenderFrameCreatedObserver : public WebContentsObserver { 380 class RenderFrameCreatedObserver : public WebContentsObserver {
382 public: 381 public:
383 RenderFrameCreatedObserver(Shell* shell) 382 RenderFrameCreatedObserver(Shell* shell)
384 : WebContentsObserver(shell->web_contents()), 383 : WebContentsObserver(shell->web_contents()),
385 last_rfh_(NULL) { 384 last_rfh_(NULL) {
386 } 385 }
387 386
388 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) override { 387 void RenderFrameCreated(RenderFrameHost* render_frame_host) override {
389 last_rfh_ = render_frame_host; 388 last_rfh_ = render_frame_host;
390 } 389 }
391 390
392 RenderFrameHost* last_rfh() const { return last_rfh_; } 391 RenderFrameHost* last_rfh() const { return last_rfh_; }
393 392
394 private: 393 private:
395 RenderFrameHost* last_rfh_; 394 RenderFrameHost* last_rfh_;
396 395
397 DISALLOW_COPY_AND_ASSIGN(RenderFrameCreatedObserver); 396 DISALLOW_COPY_AND_ASSIGN(RenderFrameCreatedObserver);
398 }; 397 };
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 struct LoadProgressDelegateAndObserver : public WebContentsDelegate, 481 struct LoadProgressDelegateAndObserver : public WebContentsDelegate,
483 public WebContentsObserver { 482 public WebContentsObserver {
484 LoadProgressDelegateAndObserver(Shell* shell) 483 LoadProgressDelegateAndObserver(Shell* shell)
485 : WebContentsObserver(shell->web_contents()), 484 : WebContentsObserver(shell->web_contents()),
486 did_start_loading(false), 485 did_start_loading(false),
487 did_stop_loading(false) { 486 did_stop_loading(false) {
488 web_contents()->SetDelegate(this); 487 web_contents()->SetDelegate(this);
489 } 488 }
490 489
491 // WebContentsDelegate: 490 // WebContentsDelegate:
492 virtual void LoadProgressChanged(WebContents* source, 491 void LoadProgressChanged(WebContents* source, double progress) override {
493 double progress) override {
494 EXPECT_TRUE(did_start_loading); 492 EXPECT_TRUE(did_start_loading);
495 EXPECT_FALSE(did_stop_loading); 493 EXPECT_FALSE(did_stop_loading);
496 progresses.push_back(progress); 494 progresses.push_back(progress);
497 } 495 }
498 496
499 // WebContentsObserver: 497 // WebContentsObserver:
500 virtual void DidStartLoading(RenderViewHost* render_view_host) override { 498 void DidStartLoading(RenderViewHost* render_view_host) override {
501 EXPECT_FALSE(did_start_loading); 499 EXPECT_FALSE(did_start_loading);
502 EXPECT_EQ(0U, progresses.size()); 500 EXPECT_EQ(0U, progresses.size());
503 EXPECT_FALSE(did_stop_loading); 501 EXPECT_FALSE(did_stop_loading);
504 did_start_loading = true; 502 did_start_loading = true;
505 } 503 }
506 504
507 virtual void DidStopLoading(RenderViewHost* render_view_host) override { 505 void DidStopLoading(RenderViewHost* render_view_host) override {
508 EXPECT_TRUE(did_start_loading); 506 EXPECT_TRUE(did_start_loading);
509 EXPECT_GE(progresses.size(), 1U); 507 EXPECT_GE(progresses.size(), 1U);
510 EXPECT_FALSE(did_stop_loading); 508 EXPECT_FALSE(did_stop_loading);
511 did_stop_loading = true; 509 did_stop_loading = true;
512 } 510 }
513 511
514 bool did_start_loading; 512 bool did_start_loading;
515 std::vector<double> progresses; 513 std::vector<double> progresses;
516 bool did_stop_loading; 514 bool did_stop_loading;
517 }; 515 };
(...skipping 18 matching lines...) Expand all
536 ASSERT_GE(progresses.size(), 1U) 534 ASSERT_GE(progresses.size(), 1U)
537 << "There should be at least one progress update"; 535 << "There should be at least one progress update";
538 EXPECT_EQ(1.0, *progresses.rbegin()); 536 EXPECT_EQ(1.0, *progresses.rbegin());
539 } 537 }
540 538
541 struct FirstVisuallyNonEmptyPaintObserver : public WebContentsObserver { 539 struct FirstVisuallyNonEmptyPaintObserver : public WebContentsObserver {
542 FirstVisuallyNonEmptyPaintObserver(Shell* shell) 540 FirstVisuallyNonEmptyPaintObserver(Shell* shell)
543 : WebContentsObserver(shell->web_contents()), 541 : WebContentsObserver(shell->web_contents()),
544 did_fist_visually_non_empty_paint_(false) {} 542 did_fist_visually_non_empty_paint_(false) {}
545 543
546 virtual void DidFirstVisuallyNonEmptyPaint() override { 544 void DidFirstVisuallyNonEmptyPaint() override {
547 did_fist_visually_non_empty_paint_ = true; 545 did_fist_visually_non_empty_paint_ = true;
548 on_did_first_visually_non_empty_paint_.Run(); 546 on_did_first_visually_non_empty_paint_.Run();
549 } 547 }
550 548
551 void WaitForDidFirstVisuallyNonEmptyPaint() { 549 void WaitForDidFirstVisuallyNonEmptyPaint() {
552 if (did_fist_visually_non_empty_paint_) 550 if (did_fist_visually_non_empty_paint_)
553 return; 551 return;
554 base::RunLoop run_loop; 552 base::RunLoop run_loop;
555 on_did_first_visually_non_empty_paint_ = run_loop.QuitClosure(); 553 on_did_first_visually_non_empty_paint_ = run_loop.QuitClosure();
556 run_loop.Run(); 554 run_loop.Run();
(...skipping 17 matching lines...) Expand all
574 new FirstVisuallyNonEmptyPaintObserver(shell())); 572 new FirstVisuallyNonEmptyPaintObserver(shell()));
575 573
576 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html")); 574 NavigateToURL(shell(), embedded_test_server()->GetURL("/title1.html"));
577 575
578 observer->WaitForDidFirstVisuallyNonEmptyPaint(); 576 observer->WaitForDidFirstVisuallyNonEmptyPaint();
579 ASSERT_TRUE(observer->did_fist_visually_non_empty_paint_); 577 ASSERT_TRUE(observer->did_fist_visually_non_empty_paint_);
580 } 578 }
581 579
582 } // namespace content 580 } // namespace content
583 581
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/browser/web_contents/web_contents_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698