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

Side by Side Diff: content/public/test/test_navigation_observer.cc

Issue 2650033008: Convert TestNavigationObserver to use the new navigation callbacks. (Closed)
Patch Set: fix test Created 3 years, 10 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
« no previous file with comments | « content/public/test/test_navigation_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/public/test/test_navigation_observer.h" 5 #include "content/public/test/test_navigation_observer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h"
12 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/navigation_handle.h"
13 #include "content/public/browser/web_contents_observer.h" 11 #include "content/public/browser/web_contents_observer.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 12
16 namespace content { 13 namespace content {
17 14
18 class TestNavigationObserver::TestWebContentsObserver 15 class TestNavigationObserver::TestWebContentsObserver
19 : public WebContentsObserver { 16 : public WebContentsObserver {
20 public: 17 public:
21 TestWebContentsObserver(TestNavigationObserver* parent, 18 TestWebContentsObserver(TestNavigationObserver* parent,
22 WebContents* web_contents) 19 WebContents* web_contents)
23 : WebContentsObserver(web_contents), 20 : WebContentsObserver(web_contents),
24 parent_(parent) { 21 parent_(parent) {
(...skipping 15 matching lines...) Expand all
40 } 37 }
41 38
42 void DidStartLoading() override { 39 void DidStartLoading() override {
43 parent_->OnDidStartLoading(web_contents()); 40 parent_->OnDidStartLoading(web_contents());
44 } 41 }
45 42
46 void DidStopLoading() override { 43 void DidStopLoading() override {
47 parent_->OnDidStopLoading(web_contents()); 44 parent_->OnDidStopLoading(web_contents());
48 } 45 }
49 46
50 void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host, 47 void DidStartNavigation(NavigationHandle* navigation_handle) override {
51 const GURL& validated_url, 48 if (navigation_handle->IsSamePage())
52 bool is_error_page) override { 49 return;
53 parent_->OnDidStartProvisionalLoad(render_frame_host, validated_url, 50
54 is_error_page); 51 parent_->OnDidStartNavigation();
55 } 52 }
56 53
57 void DidFailProvisionalLoad( 54 void DidFinishNavigation(NavigationHandle* navigation_handle) override {
58 RenderFrameHost* render_frame_host, 55 if (!navigation_handle->HasCommitted())
59 const GURL& validated_url, 56 return;
60 int error_code,
61 const base::string16& error_description,
62 bool was_ignored_by_handler) override {
63 parent_->OnDidFailProvisionalLoad(render_frame_host, validated_url,
64 error_code, error_description);
65 }
66 57
67 void DidCommitProvisionalLoadForFrame( 58 parent_->OnDidFinishNavigation(navigation_handle->IsErrorPage(),
68 RenderFrameHost* render_frame_host, 59 navigation_handle->GetURL());
69 const GURL& url,
70 ui::PageTransition transition_type) override {
71 parent_->OnDidCommitProvisionalLoadForFrame(
72 render_frame_host, url, transition_type);
73 } 60 }
74 61
75 TestNavigationObserver* parent_; 62 TestNavigationObserver* parent_;
76 63
77 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver); 64 DISALLOW_COPY_AND_ASSIGN(TestWebContentsObserver);
78 }; 65 };
79 66
80 TestNavigationObserver::TestNavigationObserver( 67 TestNavigationObserver::TestNavigationObserver(
81 WebContents* web_contents, 68 WebContents* web_contents,
82 int number_of_navigations) 69 int number_of_navigations)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 if (!navigation_started_) 152 if (!navigation_started_)
166 return; 153 return;
167 154
168 ++navigations_completed_; 155 ++navigations_completed_;
169 if (navigations_completed_ == number_of_navigations_) { 156 if (navigations_completed_ == number_of_navigations_) {
170 navigation_started_ = false; 157 navigation_started_ = false;
171 message_loop_runner_->Quit(); 158 message_loop_runner_->Quit();
172 } 159 }
173 } 160 }
174 161
175 void TestNavigationObserver::OnDidStartProvisionalLoad( 162 void TestNavigationObserver::OnDidStartNavigation() {
176 RenderFrameHost* render_frame_host,
177 const GURL& validated_url,
178 bool is_error_page) {
179 last_navigation_succeeded_ = false; 163 last_navigation_succeeded_ = false;
180 } 164 }
181 165
182 void TestNavigationObserver::OnDidFailProvisionalLoad( 166 void TestNavigationObserver::OnDidFinishNavigation(bool is_error_page,
183 RenderFrameHost* render_frame_host, 167 const GURL& url) {
184 const GURL& validated_url,
185 int error_code,
186 const base::string16& error_description) {
187 last_navigation_url_ = validated_url;
188 last_navigation_succeeded_ = false;
189 }
190
191 void TestNavigationObserver::OnDidCommitProvisionalLoadForFrame(
192 RenderFrameHost* render_frame_host,
193 const GURL& url,
194 ui::PageTransition transition_type) {
195 last_navigation_url_ = url; 168 last_navigation_url_ = url;
196 last_navigation_succeeded_ = true; 169 last_navigation_succeeded_ = !is_error_page;
197 } 170 }
198 171
199 } // namespace content 172 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/test_navigation_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698