Chromium Code Reviews| 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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "chrome/browser/infobars/infobar_service.h" | |
| 13 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 12 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 14 #include "chrome/browser/password_manager/password_store_factory.h" | 13 #include "chrome/browser/password_manager/password_store_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 16 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 20 #include "components/autofill/core/browser/autofill_test_utils.h" | 19 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 21 #include "components/infobars/core/confirm_infobar_delegate.h" | |
| 22 #include "components/infobars/core/infobar.h" | |
| 23 #include "components/infobars/core/infobar_manager.h" | |
| 24 #include "components/password_manager/core/browser/password_manager_test_utils.h " | 20 #include "components/password_manager/core/browser/password_manager_test_utils.h " |
| 25 #include "components/password_manager/core/browser/test_password_store.h" | 21 #include "components/password_manager/core/browser/test_password_store.h" |
| 26 #include "components/password_manager/core/common/password_manager_features.h" | 22 #include "components/password_manager/core/common/password_manager_features.h" |
| 27 #include "content/public/browser/navigation_details.h" | 23 #include "content/public/browser/navigation_details.h" |
| 28 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
| 29 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
| 30 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 31 #include "net/test/embedded_test_server/embedded_test_server.h" | 27 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 32 | 28 |
| 33 NavigationObserver::NavigationObserver(content::WebContents* web_contents) | 29 NavigationObserver::NavigationObserver(content::WebContents* web_contents) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 ASSERT_TRUE(IsShowingPrompt()); | 71 ASSERT_TRUE(IsShowingPrompt()); |
| 76 AcceptImpl(); | 72 AcceptImpl(); |
| 77 } | 73 } |
| 78 | 74 |
| 79 void PromptObserver::AcceptUpdatePrompt( | 75 void PromptObserver::AcceptUpdatePrompt( |
| 80 const autofill::PasswordForm& form) const { | 76 const autofill::PasswordForm& form) const { |
| 81 EXPECT_TRUE(IsShowingUpdatePrompt()); | 77 EXPECT_TRUE(IsShowingUpdatePrompt()); |
| 82 AcceptUpdatePromptImpl(form); | 78 AcceptUpdatePromptImpl(form); |
| 83 } | 79 } |
| 84 | 80 |
| 85 class InfoBarObserver : public PromptObserver, | |
| 86 public infobars::InfoBarManager::Observer { | |
| 87 public: | |
| 88 explicit InfoBarObserver(content::WebContents* web_contents) | |
| 89 : infobar_is_being_shown_(false), | |
| 90 infobar_service_(InfoBarService::FromWebContents(web_contents)) { | |
| 91 infobar_service_->AddObserver(this); | |
| 92 } | |
| 93 | |
| 94 ~InfoBarObserver() override { | |
| 95 if (infobar_service_) | |
| 96 infobar_service_->RemoveObserver(this); | |
| 97 } | |
| 98 | |
| 99 void Dismiss() const override { | |
| 100 NOTIMPLEMENTED(); | |
| 101 } | |
| 102 | |
| 103 private: | |
| 104 // PromptObserver: | |
| 105 bool IsShowingPrompt() const override { return infobar_is_being_shown_; } | |
| 106 | |
| 107 void AcceptImpl() const override { | |
| 108 EXPECT_EQ(1u, infobar_service_->infobar_count()); | |
| 109 if (!infobar_service_->infobar_count()) | |
| 110 return; // Let the test finish to gather possibly more diagnostics. | |
| 111 | |
| 112 // ConfirmInfoBarDelegate::Accept returning true means the infobar is | |
| 113 // immediately closed. Checking the return value is preferred to testing | |
| 114 // IsShowingPrompt() here, for it avoids the delay until the closing | |
| 115 // notification is received. | |
| 116 EXPECT_TRUE(infobar_service_->infobar_at(0) | |
| 117 ->delegate() | |
| 118 ->AsConfirmInfoBarDelegate() | |
| 119 ->Accept()); | |
| 120 } | |
| 121 | |
| 122 // infobars::InfoBarManager::Observer: | |
| 123 void OnInfoBarAdded(infobars::InfoBar* infobar) override { | |
| 124 infobar_is_being_shown_ = true; | |
| 125 } | |
| 126 | |
| 127 void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override { | |
| 128 infobar_is_being_shown_ = false; | |
| 129 } | |
| 130 | |
| 131 void OnManagerShuttingDown(infobars::InfoBarManager* manager) override { | |
| 132 ASSERT_EQ(infobar_service_, manager); | |
| 133 infobar_service_->RemoveObserver(this); | |
| 134 infobar_service_ = nullptr; | |
| 135 } | |
| 136 | |
| 137 bool infobar_is_being_shown_; | |
| 138 InfoBarService* infobar_service_; | |
| 139 | |
| 140 DISALLOW_COPY_AND_ASSIGN(InfoBarObserver); | |
| 141 }; | |
| 142 | |
| 143 class BubbleObserver : public PromptObserver { | 81 class BubbleObserver : public PromptObserver { |
|
vabr (Chromium)
2016/05/12 16:19:29
We should merge PromptObserver into BubbleObserver
vasilii
2016/05/12 16:23:30
Yes, but I refrain from renaming in this CL.
| |
| 144 public: | 82 public: |
| 145 explicit BubbleObserver(content::WebContents* web_contents) | 83 explicit BubbleObserver(content::WebContents* web_contents) |
| 146 : passwords_model_delegate_( | 84 : passwords_model_delegate_( |
| 147 PasswordsModelDelegateFromWebContents(web_contents)) {} | 85 PasswordsModelDelegateFromWebContents(web_contents)) {} |
| 148 | 86 |
| 149 ~BubbleObserver() override {} | 87 ~BubbleObserver() override {} |
| 150 | 88 |
| 151 void Dismiss() const override { | 89 void Dismiss() const override { |
| 152 passwords_model_delegate_->OnBubbleHidden(); | 90 passwords_model_delegate_->OnBubbleHidden(); |
| 153 // Navigate away to reset the state to inactive. | 91 // Navigate away to reset the state to inactive. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 181 passwords_model_delegate_->UpdatePassword(form); | 119 passwords_model_delegate_->UpdatePassword(form); |
| 182 EXPECT_FALSE(IsShowingUpdatePrompt()); | 120 EXPECT_FALSE(IsShowingUpdatePrompt()); |
| 183 } | 121 } |
| 184 PasswordsModelDelegate* const passwords_model_delegate_; | 122 PasswordsModelDelegate* const passwords_model_delegate_; |
| 185 | 123 |
| 186 DISALLOW_COPY_AND_ASSIGN(BubbleObserver); | 124 DISALLOW_COPY_AND_ASSIGN(BubbleObserver); |
| 187 }; | 125 }; |
| 188 | 126 |
| 189 std::unique_ptr<PromptObserver> PromptObserver::Create( | 127 std::unique_ptr<PromptObserver> PromptObserver::Create( |
| 190 content::WebContents* web_contents) { | 128 content::WebContents* web_contents) { |
| 191 if (ChromePasswordManagerClient::IsTheHotNewBubbleUIEnabled()) { | 129 return base::WrapUnique(new BubbleObserver(web_contents)); |
| 192 return std::unique_ptr<PromptObserver>(new BubbleObserver(web_contents)); | |
| 193 } else { | |
| 194 return std::unique_ptr<PromptObserver>(new InfoBarObserver(web_contents)); | |
| 195 } | |
| 196 } | 130 } |
| 197 | 131 |
| 198 PasswordManagerBrowserTestBase::PasswordManagerBrowserTestBase() { | 132 PasswordManagerBrowserTestBase::PasswordManagerBrowserTestBase() { |
| 199 } | 133 } |
| 200 PasswordManagerBrowserTestBase::~PasswordManagerBrowserTestBase() { | 134 PasswordManagerBrowserTestBase::~PasswordManagerBrowserTestBase() { |
| 201 } | 135 } |
| 202 | 136 |
| 203 void PasswordManagerBrowserTestBase::SetUpOnMainThread() { | 137 void PasswordManagerBrowserTestBase::SetUpOnMainThread() { |
| 204 // Use TestPasswordStore to remove a possible race. Normally the | 138 // Use TestPasswordStore to remove a possible race. Normally the |
| 205 // PasswordStore does its database manipulation on the DB thread, which | 139 // PasswordStore does its database manipulation on the DB thread, which |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 " var element = document.getElementById('%s');" | 285 " var element = document.getElementById('%s');" |
| 352 "window.domAutomationController.send(element && element.value == '%s');", | 286 "window.domAutomationController.send(element && element.value == '%s');", |
| 353 iframe_id.c_str(), iframe_id.c_str(), element_id.c_str(), | 287 iframe_id.c_str(), iframe_id.c_str(), element_id.c_str(), |
| 354 element_id.c_str(), expected_value.c_str()); | 288 element_id.c_str(), expected_value.c_str()); |
| 355 bool return_value = false; | 289 bool return_value = false; |
| 356 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 290 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 357 RenderViewHost(), value_check_script, &return_value)); | 291 RenderViewHost(), value_check_script, &return_value)); |
| 358 EXPECT_TRUE(return_value) << "element_id = " << element_id | 292 EXPECT_TRUE(return_value) << "element_id = " << element_id |
| 359 << ", expected_value = " << expected_value; | 293 << ", expected_value = " << expected_value; |
| 360 } | 294 } |
| OLD | NEW |