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

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

Issue 2607413003: Add security feature to ProvisionalSavePassword (Closed)
Patch Set: Addressed nit. 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/password_manager/password_manager_test_base.h" 5 #include "chrome/browser/password_manager/password_manager_test_base.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
12 #include "chrome/browser/password_manager/password_store_factory.h" 12 #include "chrome/browser/password_manager/password_store_factory.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 15 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
18 #include "components/autofill/core/browser/autofill_test_utils.h" 18 #include "components/autofill/core/browser/autofill_test_utils.h"
19 #include "components/password_manager/core/browser/password_manager_test_utils.h " 19 #include "components/password_manager/core/browser/password_manager_test_utils.h "
20 #include "components/password_manager/core/browser/test_password_store.h" 20 #include "components/password_manager/core/browser/test_password_store.h"
21 #include "components/password_manager/core/common/password_manager_features.h" 21 #include "components/password_manager/core/common/password_manager_features.h"
22 #include "content/public/browser/navigation_details.h" 22 #include "content/public/browser/navigation_details.h"
23 #include "content/public/browser/render_frame_host.h" 23 #include "content/public/browser/render_frame_host.h"
24 #include "content/public/test/browser_test_utils.h" 24 #include "content/public/test/browser_test_utils.h"
25 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
26 #include "net/test/embedded_test_server/embedded_test_server.h" 26 #include "net/test/embedded_test_server/embedded_test_server.h"
27 27
28 namespace {
29
30 // A helper class that synchronously waits until the password store handles a
31 // GetLogins() request.
32 class PasswordStoreResultsObserver
33 : public password_manager::PasswordStoreConsumer {
34 public:
35 PasswordStoreResultsObserver() = default;
36
37 void OnGetPasswordStoreResults(
38 std::vector<std::unique_ptr<autofill::PasswordForm>> results) override {
39 run_loop_.Quit();
40 }
41
42 void Wait() { run_loop_.Run(); }
43
44 private:
45 base::RunLoop run_loop_;
46
47 DISALLOW_COPY_AND_ASSIGN(PasswordStoreResultsObserver);
48 };
49
50 } // namespace
51
28 NavigationObserver::NavigationObserver(content::WebContents* web_contents) 52 NavigationObserver::NavigationObserver(content::WebContents* web_contents)
29 : content::WebContentsObserver(web_contents), 53 : content::WebContentsObserver(web_contents),
30 quit_on_entry_committed_(false), 54 quit_on_entry_committed_(false),
31 message_loop_runner_(new content::MessageLoopRunner) { 55 message_loop_runner_(new content::MessageLoopRunner) {
32 } 56 }
33 NavigationObserver::~NavigationObserver() { 57 NavigationObserver::~NavigationObserver() {
34 } 58 }
35 59
36 void NavigationObserver::DidFinishNavigation( 60 void NavigationObserver::DidFinishNavigation(
37 content::NavigationHandle* navigation_handle) { 61 content::NavigationHandle* navigation_handle) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 element_id.c_str(), element_id.c_str(), RETURN_CODE_NO_ELEMENT, 247 element_id.c_str(), element_id.c_str(), RETURN_CODE_NO_ELEMENT,
224 RETURN_CODE_OK, RETURN_CODE_WRONG_VALUE); 248 RETURN_CODE_OK, RETURN_CODE_WRONG_VALUE);
225 int return_value = RETURN_CODE_INVALID; 249 int return_value = RETURN_CODE_INVALID;
226 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(RenderViewHost(), script, 250 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(RenderViewHost(), script,
227 &return_value)); 251 &return_value));
228 EXPECT_EQ(RETURN_CODE_OK, return_value) 252 EXPECT_EQ(RETURN_CODE_OK, return_value)
229 << "element_id = " << element_id 253 << "element_id = " << element_id
230 << ", expected_value = " << expected_value; 254 << ", expected_value = " << expected_value;
231 } 255 }
232 256
257 void PasswordManagerBrowserTestBase::WaitForPasswordStore() {
258 scoped_refptr<password_manager::PasswordStore> password_store =
259 PasswordStoreFactory::GetForProfile(browser()->profile(),
260 ServiceAccessType::IMPLICIT_ACCESS);
261 PasswordStoreResultsObserver syncer;
262 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer);
263 syncer.Wait();
264 }
265
233 void PasswordManagerBrowserTestBase::CheckElementValue( 266 void PasswordManagerBrowserTestBase::CheckElementValue(
234 const std::string& element_id, 267 const std::string& element_id,
235 const std::string& expected_value) { 268 const std::string& expected_value) {
236 CheckElementValue("null", element_id, expected_value); 269 CheckElementValue("null", element_id, expected_value);
237 } 270 }
238 271
239 void PasswordManagerBrowserTestBase::CheckElementValue( 272 void PasswordManagerBrowserTestBase::CheckElementValue(
240 const std::string& iframe_id, 273 const std::string& iframe_id,
241 const std::string& element_id, 274 const std::string& element_id,
242 const std::string& expected_value) { 275 const std::string& expected_value) {
243 const std::string value_check_script = base::StringPrintf( 276 const std::string value_check_script = base::StringPrintf(
244 "if (%s)" 277 "if (%s)"
245 " var element = document.getElementById(" 278 " var element = document.getElementById("
246 " '%s').contentDocument.getElementById('%s');" 279 " '%s').contentDocument.getElementById('%s');"
247 "else " 280 "else "
248 " var element = document.getElementById('%s');" 281 " var element = document.getElementById('%s');"
249 "window.domAutomationController.send(element && element.value == '%s');", 282 "window.domAutomationController.send(element && element.value == '%s');",
250 iframe_id.c_str(), iframe_id.c_str(), element_id.c_str(), 283 iframe_id.c_str(), iframe_id.c_str(), element_id.c_str(),
251 element_id.c_str(), expected_value.c_str()); 284 element_id.c_str(), expected_value.c_str());
252 bool return_value = false; 285 bool return_value = false;
253 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 286 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
254 RenderViewHost(), value_check_script, &return_value)); 287 RenderViewHost(), value_check_script, &return_value));
255 EXPECT_TRUE(return_value) << "element_id = " << element_id 288 EXPECT_TRUE(return_value) << "element_id = " << element_id
256 << ", expected_value = " << expected_value; 289 << ", expected_value = " << expected_value;
257 } 290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698