#include "base/metrics/statistics_recorder.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/infobars/confirm_infobar_delegate.h"
-#include "chrome/browser/infobars/infobar.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/password_manager/test_password_store_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/chrome_version_info.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
+#include "components/infobars/core/infobar.h"
+#include "components/infobars/core/infobar_manager.h"
#include "components/password_manager/core/browser/test_password_store.h"
-#include "content/public/browser/notification_observer.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_service.h"
+#include "components/password_manager/core/common/password_manager_switches.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
// Observer that waits for navigation to complete and for the password infobar
// to be shown.
-class NavigationObserver : public content::NotificationObserver,
- public content::WebContentsObserver {
+class NavigationObserver : public content::WebContentsObserver,
+ public infobars::InfoBarManager::Observer {
public:
explicit NavigationObserver(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents),
infobar_removed_(false),
should_automatically_accept_infobar_(true),
infobar_service_(InfoBarService::FromWebContents(web_contents)) {
- registrar_.Add(this,
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
- content::Source<InfoBarService>(infobar_service_));
- registrar_.Add(this,
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
- content::Source<InfoBarService>(infobar_service_));
+ infobar_service_->AddObserver(this);
}
- virtual ~NavigationObserver() {}
+ virtual ~NavigationObserver() {
+ if (infobar_service_)
+ infobar_service_->RemoveObserver(this);
+ }
// Normally Wait() will not return until a main frame navigation occurs.
// If a path is set, Wait() will return after this path has been seen,
wait_for_path_ = path;
}
- // content::NotificationObserver:
- virtual void Observe(int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE {
- switch (type) {
- case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED:
- if (should_automatically_accept_infobar_) {
- infobar_service_->infobar_at(0)
- ->delegate()
- ->AsConfirmInfoBarDelegate()
- ->Accept();
- }
- infobar_shown_ = true;
- return;
- case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED:
- infobar_removed_ = true;
- return;
- default:
- NOTREACHED();
- return;
- }
- }
-
// content::WebContentsObserver:
virtual void DidFinishLoad(
int64 frame_id,
}
private:
+ // infobars::InfoBarManager::Observer:
+ virtual void OnInfoBarAdded(infobars::InfoBar* infobar) OVERRIDE {
+ if (should_automatically_accept_infobar_) {
+ infobar_service_->infobar_at(0)->delegate()->
+ AsConfirmInfoBarDelegate()->Accept();
+ }
+ infobar_shown_ = true;
+ }
+
+ virtual void OnInfoBarRemoved(infobars::InfoBar* infobar,
+ bool animate) OVERRIDE {
+ infobar_removed_ = true;
+ }
+
+ virtual void OnManagerShuttingDown(
+ infobars::InfoBarManager* manager) OVERRIDE {
+ ASSERT_EQ(infobar_service_, manager);
+ infobar_service_->RemoveObserver(this);
+ infobar_service_ = NULL;
+ }
+
std::string wait_for_path_;
scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
bool infobar_shown_;
// If |should_automatically_accept_infobar_| is true, then whenever the test
// sees an infobar added, it will click its accepting button. Default = true.
bool should_automatically_accept_infobar_;
- content::NotificationRegistrar registrar_;
InfoBarService* infobar_service_;
DISALLOW_COPY_AND_ASSIGN(NavigationObserver);
if (!embedded_test_server()->Started())
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
+ ASSERT_FALSE(CommandLine::ForCurrentProcess()->HasSwitch(
+ password_manager::switches::kEnableAutomaticPasswordSaving));
NavigationObserver observer(WebContents());
GURL url = embedded_test_server()->GetURL(path);
ui_test_utils::NavigateToURL(browser(), url);
// The only thing we check here is that there is no use-after-free reported.
}
-// Disabled on Windows due to flakiness: http://crbug.com/163072
-// TODO(vabr): Also disabled on Android, because the tested feature is currently
-// disabled there. http://crbug.com/345510#c13
-#if defined(OS_WIN) || defined(OS_ANDROID)
+// Disabled on Windows due to flakiness: http://crbug.com/346297
+#if defined(OS_WIN)
#define MAYBE_PasswordValueAccessible DISABLED_PasswordValueAccessible
#else
#define MAYBE_PasswordValueAccessible PasswordValueAccessible
observer.Wait();
EXPECT_FALSE(observer.infobar_shown());
}
+
+IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
+ PromptWhenEnableAutomaticPasswordSavingSwitchIsNotSet) {
+ NavigateToFile("/password/password_form.html");
+
+ // Fill a form and submit through a <input type="submit"> button.
+ NavigationObserver observer(WebContents());
+ std::string fill_and_submit =
+ "document.getElementById('username_field').value = 'temp';"
+ "document.getElementById('password_field').value = 'random';"
+ "document.getElementById('input_submit_button').click()";
+ ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
+ observer.Wait();
+ EXPECT_TRUE(observer.infobar_shown());
+}
+
+IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
+ DontPromptWhenEnableAutomaticPasswordSavingSwitchIsSet) {
+ password_manager::TestPasswordStore* password_store =
+ static_cast<password_manager::TestPasswordStore*>(
+ PasswordStoreFactory::GetForProfile(browser()->profile(),
+ Profile::IMPLICIT_ACCESS).get());
+
+ EXPECT_TRUE(password_store->IsEmpty());
+
+ NavigateToFile("/password/password_form.html");
+
+ // Add the enable-automatic-password-saving switch.
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ password_manager::switches::kEnableAutomaticPasswordSaving);
+
+ // Fill a form and submit through a <input type="submit"> button.
+ NavigationObserver observer(WebContents());
+ // Make sure that the only passwords saved are the auto-saved ones.
+ observer.disable_should_automatically_accept_infobar();
+ std::string fill_and_submit =
+ "document.getElementById('username_field').value = 'temp';"
+ "document.getElementById('password_field').value = 'random';"
+ "document.getElementById('input_submit_button').click()";
+ ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
+ observer.Wait();
+ if (chrome::VersionInfo::GetChannel() ==
+ chrome::VersionInfo::CHANNEL_UNKNOWN) {
+ EXPECT_FALSE(observer.infobar_shown());
+ EXPECT_FALSE(password_store->IsEmpty());
+ } else {
+ EXPECT_TRUE(observer.infobar_shown());
+ EXPECT_TRUE(password_store->IsEmpty());
+ }
+}
+
+// Test fix for crbug.com/368690.
+IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptWhenReloading) {
+ NavigateToFile("/password/password_form.html");
+
+ std::string fill =
+ "document.getElementById('username_redirect').value = 'temp';"
+ "document.getElementById('password_redirect').value = 'random';";
+ ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill));
+
+ NavigationObserver observer(WebContents());
+ GURL url = embedded_test_server()->GetURL("/password/password_form.html");
+ chrome::NavigateParams params(browser(), url,
+ content::PAGE_TRANSITION_RELOAD);
+ ui_test_utils::NavigateToURL(¶ms);
+ observer.Wait();
+ EXPECT_FALSE(observer.infobar_shown());
+}