| OLD | NEW |
| 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" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 EXPECT_FALSE(IsShowingSavePrompt()); | 85 EXPECT_FALSE(IsShowingSavePrompt()); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void BubbleObserver::AcceptUpdatePrompt( | 88 void BubbleObserver::AcceptUpdatePrompt( |
| 89 const autofill::PasswordForm& form) const { | 89 const autofill::PasswordForm& form) const { |
| 90 ASSERT_TRUE(IsShowingUpdatePrompt()); | 90 ASSERT_TRUE(IsShowingUpdatePrompt()); |
| 91 passwords_ui_controller_->UpdatePassword(form); | 91 passwords_ui_controller_->UpdatePassword(form); |
| 92 EXPECT_FALSE(IsShowingUpdatePrompt()); | 92 EXPECT_FALSE(IsShowingUpdatePrompt()); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void PasswordStoreResultsObserver::OnGetPasswordStoreResults( |
| 96 std::vector<std::unique_ptr<autofill::PasswordForm>> results) { |
| 97 run_loop_.Quit(); |
| 98 } |
| 99 |
| 100 void PasswordStoreResultsObserver::Wait() { |
| 101 run_loop_.Run(); |
| 102 } |
| 103 |
| 95 PasswordManagerBrowserTestBase::PasswordManagerBrowserTestBase() { | 104 PasswordManagerBrowserTestBase::PasswordManagerBrowserTestBase() { |
| 96 } | 105 } |
| 97 PasswordManagerBrowserTestBase::~PasswordManagerBrowserTestBase() { | 106 PasswordManagerBrowserTestBase::~PasswordManagerBrowserTestBase() { |
| 98 } | 107 } |
| 99 | 108 |
| 100 void PasswordManagerBrowserTestBase::SetUpOnMainThread() { | 109 void PasswordManagerBrowserTestBase::SetUpOnMainThread() { |
| 101 // Use TestPasswordStore to remove a possible race. Normally the | 110 // Use TestPasswordStore to remove a possible race. Normally the |
| 102 // PasswordStore does its database manipulation on the DB thread, which | 111 // PasswordStore does its database manipulation on the DB thread, which |
| 103 // creates a possible race during navigation. Specifically the | 112 // creates a possible race during navigation. Specifically the |
| 104 // PasswordManager will ignore any forms in a page if the load from the | 113 // PasswordManager will ignore any forms in a page if the load from the |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 element_id.c_str(), element_id.c_str(), RETURN_CODE_NO_ELEMENT, | 232 element_id.c_str(), element_id.c_str(), RETURN_CODE_NO_ELEMENT, |
| 224 RETURN_CODE_OK, RETURN_CODE_WRONG_VALUE); | 233 RETURN_CODE_OK, RETURN_CODE_WRONG_VALUE); |
| 225 int return_value = RETURN_CODE_INVALID; | 234 int return_value = RETURN_CODE_INVALID; |
| 226 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(RenderViewHost(), script, | 235 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(RenderViewHost(), script, |
| 227 &return_value)); | 236 &return_value)); |
| 228 EXPECT_EQ(RETURN_CODE_OK, return_value) | 237 EXPECT_EQ(RETURN_CODE_OK, return_value) |
| 229 << "element_id = " << element_id | 238 << "element_id = " << element_id |
| 230 << ", expected_value = " << expected_value; | 239 << ", expected_value = " << expected_value; |
| 231 } | 240 } |
| 232 | 241 |
| 242 void PasswordManagerBrowserTestBase::WaitForPasswordStore() { |
| 243 scoped_refptr<password_manager::PasswordStore> password_store = |
| 244 PasswordStoreFactory::GetForProfile(browser()->profile(), |
| 245 ServiceAccessType::IMPLICIT_ACCESS); |
| 246 PasswordStoreResultsObserver syncer; |
| 247 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer); |
| 248 syncer.Wait(); |
| 249 } |
| 250 |
| 233 void PasswordManagerBrowserTestBase::CheckElementValue( | 251 void PasswordManagerBrowserTestBase::CheckElementValue( |
| 234 const std::string& element_id, | 252 const std::string& element_id, |
| 235 const std::string& expected_value) { | 253 const std::string& expected_value) { |
| 236 CheckElementValue("null", element_id, expected_value); | 254 CheckElementValue("null", element_id, expected_value); |
| 237 } | 255 } |
| 238 | 256 |
| 239 void PasswordManagerBrowserTestBase::CheckElementValue( | 257 void PasswordManagerBrowserTestBase::CheckElementValue( |
| 240 const std::string& iframe_id, | 258 const std::string& iframe_id, |
| 241 const std::string& element_id, | 259 const std::string& element_id, |
| 242 const std::string& expected_value) { | 260 const std::string& expected_value) { |
| 243 const std::string value_check_script = base::StringPrintf( | 261 const std::string value_check_script = base::StringPrintf( |
| 244 "if (%s)" | 262 "if (%s)" |
| 245 " var element = document.getElementById(" | 263 " var element = document.getElementById(" |
| 246 " '%s').contentDocument.getElementById('%s');" | 264 " '%s').contentDocument.getElementById('%s');" |
| 247 "else " | 265 "else " |
| 248 " var element = document.getElementById('%s');" | 266 " var element = document.getElementById('%s');" |
| 249 "window.domAutomationController.send(element && element.value == '%s');", | 267 "window.domAutomationController.send(element && element.value == '%s');", |
| 250 iframe_id.c_str(), iframe_id.c_str(), element_id.c_str(), | 268 iframe_id.c_str(), iframe_id.c_str(), element_id.c_str(), |
| 251 element_id.c_str(), expected_value.c_str()); | 269 element_id.c_str(), expected_value.c_str()); |
| 252 bool return_value = false; | 270 bool return_value = false; |
| 253 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 271 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 254 RenderViewHost(), value_check_script, &return_value)); | 272 RenderViewHost(), value_check_script, &return_value)); |
| 255 EXPECT_TRUE(return_value) << "element_id = " << element_id | 273 EXPECT_TRUE(return_value) << "element_id = " << element_id |
| 256 << ", expected_value = " << expected_value; | 274 << ", expected_value = " << expected_value; |
| 257 } | 275 } |
| OLD | NEW |