X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fcomponents%2Fpassword_manager%2Fcore%2Fbrowser%2Fpassword_form_manager_unittest.cc;h=0e76081fb979e45c83e94ee073cc01f29eeed708;hb=004985e17e624662a4c85c76a7654039dc83f028;hp=58db999ab1517ca5ab14b1d84785496aeddde116;hpb=2f108dbacb161091e42a3479f4e171339b7e7623;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/components/password_manager/core/browser/password_form_manager_unittest.cc b/src/components/password_manager/core/browser/password_form_manager_unittest.cc index 58db999..0e76081 100644 --- a/src/components/password_manager/core/browser/password_form_manager_unittest.cc +++ b/src/components/password_manager/core/browser/password_form_manager_unittest.cc @@ -11,12 +11,13 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "components/autofill/core/common/password_form.h" +#include "components/password_manager/core/browser/mock_password_manager_driver.h" #include "components/password_manager/core/browser/mock_password_store.h" #include "components/password_manager/core/browser/password_form_manager.h" #include "components/password_manager/core/browser/password_manager.h" -#include "components/password_manager/core/browser/password_manager_client.h" #include "components/password_manager/core/browser/password_manager_driver.h" #include "components/password_manager/core/browser/password_store.h" +#include "components/password_manager/core/browser/stub_password_manager_client.h" #include "components/password_manager/core/browser/test_password_store.h" #include "components/password_manager/core/common/password_manager_pref_names.h" #include "testing/gmock/include/gmock/gmock.h" @@ -33,6 +34,8 @@ namespace autofill { class AutofillManager; } +namespace password_manager { + namespace { void RunAllPendingTasks() { @@ -42,23 +45,7 @@ void RunAllPendingTasks() { run_loop.Run(); } -class MockPasswordManagerDriver : public PasswordManagerDriver { - public: - MockPasswordManagerDriver() {} - virtual ~MockPasswordManagerDriver() {} - - MOCK_METHOD1(FillPasswordForm, void(const autofill::PasswordFormFillData&)); - MOCK_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); - MOCK_METHOD0(IsOffTheRecord, bool()); - MOCK_METHOD0(GetPasswordGenerationManager, PasswordGenerationManager*()); - MOCK_METHOD0(GetPasswordManager, PasswordManager*()); - MOCK_METHOD0(GetAutofillManager, autofill::AutofillManager*()); - MOCK_METHOD1(AllowPasswordGenerationForForm, void(autofill::PasswordForm*)); - MOCK_METHOD1(AccountCreationFormsFound, - void(const std::vector&)); -}; - -class TestPasswordManagerClient : public PasswordManagerClient { +class TestPasswordManagerClient : public StubPasswordManagerClient { public: explicit TestPasswordManagerClient(PasswordStore* password_store) : password_store_(password_store) { @@ -699,3 +686,35 @@ TEST_F(PasswordFormManagerTest, TestUpdateIncompleteCredentials) { EXPECT_CALL(*mock_store(), UpdateLogin(complete_form)); form_manager.Save(); } + +TEST_F(PasswordFormManagerTest, TestScoringPublicSuffixMatch) { + base::MessageLoop message_loop; + + TestPasswordManagerClient client(NULL); + MockPasswordManagerDriver driver; + EXPECT_CALL(driver, IsOffTheRecord()).WillRepeatedly(Return(false)); + EXPECT_CALL(driver, AllowPasswordGenerationForForm(_)); + + TestPasswordManager password_manager(&client); + scoped_ptr manager(new PasswordFormManager( + &password_manager, &client, &driver, *observed_form(), false)); + + // Simulate having two matches for this form, first comes from different + // signon realm, but reports the same origin and action as matched form. + // Second candidate has the same signon realm as the form, but has a different + // origin and action. Public suffix match is the most important criterion so + // the second candidate should be selected. + std::vector results; + results.push_back(CreateSavedMatch(false)); + results.push_back(CreateSavedMatch(false)); + results[0]->original_signon_realm = "http://accounts2.google.com"; + results[1]->origin = GURL("http://accounts.google.com/a/ServiceLoginAuth2"); + results[1]->action = GURL("http://accounts.google.com/a/ServiceLogin2"); + SimulateFetchMatchingLoginsFromPasswordStore(manager.get()); + SimulateResponseFromPasswordStore(manager.get(), results); + EXPECT_EQ(1u, password_manager.GetLatestBestMatches().size()); + EXPECT_EQ("", password_manager.GetLatestBestMatches().begin() + ->second->original_signon_realm); +} + +} // namespace password_manager