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

Side by Side Diff: chrome/browser/ui/browser_instant_controller_unittest.cc

Issue 2640473003: Convert tests to use the non-deprecated WebContentsObserver navigation methods. (Closed)
Patch Set: review comments Created 3 years, 11 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/gtest_prod_util.h" 7 #include "base/gtest_prod_util.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/search/instant_service.h" 12 #include "chrome/browser/search/instant_service.h"
13 #include "chrome/browser/search/instant_service_observer.h" 13 #include "chrome/browser/search/instant_service_observer.h"
14 #include "chrome/browser/search/instant_unittest_base.h" 14 #include "chrome/browser/search/instant_unittest_base.h"
15 #include "chrome/browser/search/search.h" 15 #include "chrome/browser/search/search.h"
16 #include "chrome/browser/ui/browser_instant_controller.h" 16 #include "chrome/browser/ui/browser_instant_controller.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/navigation_handle.h"
19 #include "content/public/browser/reload_type.h" 20 #include "content/public/browser/reload_type.h"
20 #include "content/public/browser/render_process_host.h" 21 #include "content/public/browser/render_process_host.h"
21 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
22 #include "content/public/browser/web_contents_observer.h" 23 #include "content/public/browser/web_contents_observer.h"
24 #include "content/public/common/browser_side_navigation_policy.h"
23 25
24 namespace chrome { 26 namespace chrome {
25 27
26 namespace { 28 namespace {
27 29
28 class BrowserInstantControllerTest : public InstantUnitTestBase { 30 class BrowserInstantControllerTest : public InstantUnitTestBase {
29 public: 31 public:
30 void SetUp() override { 32 void SetUp() override {
31 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( 33 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
32 "EmbeddedSearch", "Group1 use_cacheable_ntp:1")); 34 "EmbeddedSearch", "Group1 use_cacheable_ntp:1"));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 74
73 75
74 class FakeWebContentsObserver : public content::WebContentsObserver { 76 class FakeWebContentsObserver : public content::WebContentsObserver {
75 public: 77 public:
76 explicit FakeWebContentsObserver(content::WebContents* contents) 78 explicit FakeWebContentsObserver(content::WebContents* contents)
77 : WebContentsObserver(contents), 79 : WebContentsObserver(contents),
78 contents_(contents), 80 contents_(contents),
79 url_(contents->GetURL()), 81 url_(contents->GetURL()),
80 num_reloads_(0) {} 82 num_reloads_(0) {}
81 83
84 void DidStartNavigation(
85 content::NavigationHandle* navigation_handle) override {
86 if (!content::IsBrowserSideNavigationEnabled())
87 return;
88 if (url_ == navigation_handle->GetURL())
89 num_reloads_++;
90 current_url_ = navigation_handle->GetURL();
91 }
92
93 // TODO: remove this method when PlzNavigate is turned on by default.
82 void DidStartNavigationToPendingEntry( 94 void DidStartNavigationToPendingEntry(
83 const GURL& url, 95 const GURL& url,
84 content::ReloadType reload_type) override { 96 content::ReloadType reload_type) override {
97 if (content::IsBrowserSideNavigationEnabled())
98 return;
85 if (url_ == url) 99 if (url_ == url)
86 num_reloads_++; 100 num_reloads_++;
87 current_url_ = url; 101 current_url_ = url;
88 } 102 }
89 103
90 const GURL& url() const { return url_; } 104 const GURL& url() const { return url_; }
91 105
92 const GURL& current_url() const { return contents_->GetURL(); } 106 const GURL& current_url() const { return contents_->GetURL(); }
93 107
94 int num_reloads() const { 108 int num_reloads() const {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 233
220 browser.reset(NULL); 234 browser.reset(NULL);
221 window.reset(NULL); 235 window.reset(NULL);
222 EXPECT_FALSE(IsInstantServiceObserver(bic)) 236 EXPECT_FALSE(IsInstantServiceObserver(bic))
223 << "New BrowserInstantController should register as InstantServiceObserver"; 237 << "New BrowserInstantController should register as InstantServiceObserver";
224 } 238 }
225 239
226 } // namespace 240 } // namespace
227 241
228 } // namespace chrome 242 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698