X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Fbrowser%2Fpassword_manager%2Fpassword_manager_browsertest.cc;h=1c3de2fa8bf49344a1fc93f312a721ab4a6dfd2e;hb=004985e17e624662a4c85c76a7654039dc83f028;hp=4e8cff4c2f57d1f34b561b7f7570e2098d40da7a;hpb=2f108dbacb161091e42a3479f4e171339b7e7623;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/browser/password_manager/password_manager_browsertest.cc b/src/chrome/browser/password_manager/password_manager_browsertest.cc index 4e8cff4..1c3de2f 100644 --- a/src/chrome/browser/password_manager/password_manager_browsertest.cc +++ b/src/chrome/browser/password_manager/password_manager_browsertest.cc @@ -9,20 +9,20 @@ #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" @@ -41,8 +41,8 @@ namespace { // 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), @@ -51,15 +51,13 @@ class NavigationObserver : public content::NotificationObserver, 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(infobar_service_)); - registrar_.Add(this, - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, - content::Source(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, @@ -68,29 +66,6 @@ class NavigationObserver : public content::NotificationObserver, 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, @@ -117,6 +92,27 @@ class NavigationObserver : public content::NotificationObserver, } 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 message_loop_runner_; bool infobar_shown_; @@ -124,7 +120,6 @@ class NavigationObserver : public content::NotificationObserver, // 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); @@ -169,6 +164,8 @@ class PasswordManagerBrowserTest : public InProcessBrowserTest { 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); @@ -595,10 +592,8 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, DeleteFrameBeforeSubmit) { // 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 @@ -656,3 +651,71 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, 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 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( + 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 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()); +}