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

Side by Side Diff: chrome/browser/password_manager/password_manager_browsertest.cc

Issue 659563005: Standardize usage of virtual/override/final in chrome/browser/password_manager (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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram_samples.h" 8 #include "base/metrics/histogram_samples.h"
9 #include "base/metrics/statistics_recorder.h" 9 #include "base/metrics/statistics_recorder.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 namespace { 60 namespace {
61 61
62 // Observer that waits for navigation to complete and for the password infobar 62 // Observer that waits for navigation to complete and for the password infobar
63 // to be shown. 63 // to be shown.
64 class NavigationObserver : public content::WebContentsObserver { 64 class NavigationObserver : public content::WebContentsObserver {
65 public: 65 public:
66 explicit NavigationObserver(content::WebContents* web_contents) 66 explicit NavigationObserver(content::WebContents* web_contents)
67 : content::WebContentsObserver(web_contents), 67 : content::WebContentsObserver(web_contents),
68 message_loop_runner_(new content::MessageLoopRunner) {} 68 message_loop_runner_(new content::MessageLoopRunner) {}
69 69
70 virtual ~NavigationObserver() {} 70 ~NavigationObserver() override {}
71 71
72 // Normally Wait() will not return until a main frame navigation occurs. 72 // Normally Wait() will not return until a main frame navigation occurs.
73 // If a path is set, Wait() will return after this path has been seen, 73 // If a path is set, Wait() will return after this path has been seen,
74 // regardless of the frame that navigated. Useful for multi-frame pages. 74 // regardless of the frame that navigated. Useful for multi-frame pages.
75 void SetPathToWaitFor(const std::string& path) { 75 void SetPathToWaitFor(const std::string& path) {
76 wait_for_path_ = path; 76 wait_for_path_ = path;
77 } 77 }
78 78
79 // content::WebContentsObserver: 79 // content::WebContentsObserver:
80 virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, 80 void DidFinishLoad(content::RenderFrameHost* render_frame_host,
81 const GURL& validated_url) override { 81 const GURL& validated_url) override {
82 if (!wait_for_path_.empty()) { 82 if (!wait_for_path_.empty()) {
83 if (validated_url.path() == wait_for_path_) 83 if (validated_url.path() == wait_for_path_)
84 message_loop_runner_->Quit(); 84 message_loop_runner_->Quit();
85 } else if (!render_frame_host->GetParent()) { 85 } else if (!render_frame_host->GetParent()) {
86 message_loop_runner_->Quit(); 86 message_loop_runner_->Quit();
87 } 87 }
88 } 88 }
89 89
90 void Wait() { message_loop_runner_->Run(); } 90 void Wait() { message_loop_runner_->Run(); }
91 91
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 class InfoBarObserver : public PromptObserver, 132 class InfoBarObserver : public PromptObserver,
133 public infobars::InfoBarManager::Observer { 133 public infobars::InfoBarManager::Observer {
134 public: 134 public:
135 explicit InfoBarObserver(content::WebContents* web_contents) 135 explicit InfoBarObserver(content::WebContents* web_contents)
136 : infobar_is_being_shown_(false), 136 : infobar_is_being_shown_(false),
137 infobar_service_(InfoBarService::FromWebContents(web_contents)) { 137 infobar_service_(InfoBarService::FromWebContents(web_contents)) {
138 infobar_service_->AddObserver(this); 138 infobar_service_->AddObserver(this);
139 } 139 }
140 140
141 virtual ~InfoBarObserver() { 141 ~InfoBarObserver() override {
142 if (infobar_service_) 142 if (infobar_service_)
143 infobar_service_->RemoveObserver(this); 143 infobar_service_->RemoveObserver(this);
144 } 144 }
145 145
146 private: 146 private:
147 // PromptObserver: 147 // PromptObserver:
148 virtual bool IsShowingPrompt() const override { 148 bool IsShowingPrompt() const override { return infobar_is_being_shown_; }
149 return infobar_is_being_shown_;
150 }
151 149
152 virtual void AcceptImpl() const override { 150 void AcceptImpl() const override {
153 EXPECT_EQ(1u, infobar_service_->infobar_count()); 151 EXPECT_EQ(1u, infobar_service_->infobar_count());
154 if (!infobar_service_->infobar_count()) 152 if (!infobar_service_->infobar_count())
155 return; // Let the test finish to gather possibly more diagnostics. 153 return; // Let the test finish to gather possibly more diagnostics.
156 154
157 // ConfirmInfoBarDelegate::Accept returning true means the infobar is 155 // ConfirmInfoBarDelegate::Accept returning true means the infobar is
158 // immediately closed. Checking the return value is preferred to testing 156 // immediately closed. Checking the return value is preferred to testing
159 // IsShowingPrompt() here, for it avoids the delay until the closing 157 // IsShowingPrompt() here, for it avoids the delay until the closing
160 // notification is received. 158 // notification is received.
161 EXPECT_TRUE(infobar_service_->infobar_at(0) 159 EXPECT_TRUE(infobar_service_->infobar_at(0)
162 ->delegate() 160 ->delegate()
163 ->AsConfirmInfoBarDelegate() 161 ->AsConfirmInfoBarDelegate()
164 ->Accept()); 162 ->Accept());
165 } 163 }
166 164
167 // infobars::InfoBarManager::Observer: 165 // infobars::InfoBarManager::Observer:
168 virtual void OnInfoBarAdded(infobars::InfoBar* infobar) override { 166 void OnInfoBarAdded(infobars::InfoBar* infobar) override {
169 infobar_is_being_shown_ = true; 167 infobar_is_being_shown_ = true;
170 } 168 }
171 169
172 virtual void OnInfoBarRemoved(infobars::InfoBar* infobar, 170 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override {
173 bool animate) override {
174 infobar_is_being_shown_ = false; 171 infobar_is_being_shown_ = false;
175 } 172 }
176 173
177 virtual void OnManagerShuttingDown( 174 void OnManagerShuttingDown(infobars::InfoBarManager* manager) override {
178 infobars::InfoBarManager* manager) override {
179 ASSERT_EQ(infobar_service_, manager); 175 ASSERT_EQ(infobar_service_, manager);
180 infobar_service_->RemoveObserver(this); 176 infobar_service_->RemoveObserver(this);
181 infobar_service_ = NULL; 177 infobar_service_ = NULL;
182 } 178 }
183 179
184 bool infobar_is_being_shown_; 180 bool infobar_is_being_shown_;
185 InfoBarService* infobar_service_; 181 InfoBarService* infobar_service_;
186 182
187 DISALLOW_COPY_AND_ASSIGN(InfoBarObserver); 183 DISALLOW_COPY_AND_ASSIGN(InfoBarObserver);
188 }; 184 };
189 185
190 class BubbleObserver : public PromptObserver { 186 class BubbleObserver : public PromptObserver {
191 public: 187 public:
192 explicit BubbleObserver(content::WebContents* web_contents) 188 explicit BubbleObserver(content::WebContents* web_contents)
193 : ui_controller_( 189 : ui_controller_(
194 ManagePasswordsUIController::FromWebContents(web_contents)) {} 190 ManagePasswordsUIController::FromWebContents(web_contents)) {}
195 191
196 virtual ~BubbleObserver() {} 192 ~BubbleObserver() override {}
197 193
198 private: 194 private:
199 // PromptObserver: 195 // PromptObserver:
200 virtual bool IsShowingPrompt() const override { 196 bool IsShowingPrompt() const override {
201 return ui_controller_->PasswordPendingUserDecision(); 197 return ui_controller_->PasswordPendingUserDecision();
202 } 198 }
203 199
204 virtual void AcceptImpl() const override { 200 void AcceptImpl() const override {
205 ui_controller_->SavePassword(); 201 ui_controller_->SavePassword();
206 EXPECT_FALSE(IsShowingPrompt()); 202 EXPECT_FALSE(IsShowingPrompt());
207 } 203 }
208 204
209 ManagePasswordsUIController* const ui_controller_; 205 ManagePasswordsUIController* const ui_controller_;
210 206
211 DISALLOW_COPY_AND_ASSIGN(BubbleObserver); 207 DISALLOW_COPY_AND_ASSIGN(BubbleObserver);
212 }; 208 };
213 209
214 GURL GetFileURL(const char* filename) { 210 GURL GetFileURL(const char* filename) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 253
258 254
259 // PasswordManagerBrowserTest ------------------------------------------------- 255 // PasswordManagerBrowserTest -------------------------------------------------
260 256
261 class PasswordManagerBrowserTest : public InProcessBrowserTest { 257 class PasswordManagerBrowserTest : public InProcessBrowserTest {
262 public: 258 public:
263 PasswordManagerBrowserTest() {} 259 PasswordManagerBrowserTest() {}
264 virtual ~PasswordManagerBrowserTest() {} 260 virtual ~PasswordManagerBrowserTest() {}
265 261
266 // InProcessBrowserTest: 262 // InProcessBrowserTest:
267 virtual void SetUpOnMainThread() override { 263 void SetUpOnMainThread() override {
268 // Use TestPasswordStore to remove a possible race. Normally the 264 // Use TestPasswordStore to remove a possible race. Normally the
269 // PasswordStore does its database manipulation on the DB thread, which 265 // PasswordStore does its database manipulation on the DB thread, which
270 // creates a possible race during navigation. Specifically the 266 // creates a possible race during navigation. Specifically the
271 // PasswordManager will ignore any forms in a page if the load from the 267 // PasswordManager will ignore any forms in a page if the load from the
272 // PasswordStore has not completed. 268 // PasswordStore has not completed.
273 PasswordStoreFactory::GetInstance()->SetTestingFactory( 269 PasswordStoreFactory::GetInstance()->SetTestingFactory(
274 browser()->profile(), TestPasswordStoreService::Build); 270 browser()->profile(), TestPasswordStoreService::Build);
275 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 271 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
276 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch( 272 ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch(
277 password_manager::switches::kEnableAutomaticPasswordSaving)); 273 password_manager::switches::kEnableAutomaticPasswordSaving));
278 } 274 }
279 275
280 virtual void TearDownOnMainThread() override { 276 void TearDownOnMainThread() override {
281 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); 277 ASSERT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete());
282 } 278 }
283 279
284 protected: 280 protected:
285 content::WebContents* WebContents() { 281 content::WebContents* WebContents() {
286 return browser()->tab_strip_model()->GetActiveWebContents(); 282 return browser()->tab_strip_model()->GetActiveWebContents();
287 } 283 }
288 284
289 content::RenderViewHost* RenderViewHost() { 285 content::RenderViewHost* RenderViewHost() {
290 return WebContents()->GetRenderViewHost(); 286 return WebContents()->GetRenderViewHost();
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 NavigateToFile("/password/form_with_only_password_field.html"); 1269 NavigateToFile("/password/form_with_only_password_field.html");
1274 1270
1275 // Let the user interact with the page, so that DOM gets modification events, 1271 // Let the user interact with the page, so that DOM gets modification events,
1276 // needed for autofilling fields. 1272 // needed for autofilling fields.
1277 content::SimulateMouseClickAt( 1273 content::SimulateMouseClickAt(
1278 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1)); 1274 WebContents(), 0, blink::WebMouseEvent::ButtonLeft, gfx::Point(1, 1));
1279 1275
1280 // Wait until that interaction causes the password value to be revealed. 1276 // Wait until that interaction causes the password value to be revealed.
1281 WaitForElementValue("password", "mypassword"); 1277 WaitForElementValue("password", "mypassword");
1282 } 1278 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698