OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 5 #include <algorithm> |
6 #include <map> | 6 #include <map> |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "dbus/mock_bus.h" | 22 #include "dbus/mock_bus.h" |
23 #include "dbus/mock_object_proxy.h" | 23 #include "dbus/mock_object_proxy.h" |
24 #include "dbus/object_path.h" | 24 #include "dbus/object_path.h" |
25 #include "dbus/object_proxy.h" | 25 #include "dbus/object_proxy.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
28 | 28 |
29 using autofill::PasswordForm; | 29 using autofill::PasswordForm; |
30 using base::UTF8ToUTF16; | 30 using base::UTF8ToUTF16; |
31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using password_manager::PasswordStoreChange; |
| 33 using password_manager::PasswordStoreChangeList; |
32 using testing::_; | 34 using testing::_; |
33 using testing::Invoke; | 35 using testing::Invoke; |
34 using testing::Return; | 36 using testing::Return; |
35 | 37 |
36 namespace { | 38 namespace { |
37 | 39 |
38 // This class implements a very simple version of KWallet in memory. | 40 // This class implements a very simple version of KWallet in memory. |
39 // We only provide the parts we actually use; the real version has more. | 41 // We only provide the parts we actually use; the real version has more. |
40 class TestKWallet { | 42 class TestKWallet { |
41 public: | 43 public: |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 form_isc_.origin = GURL("http://www.isc.org/"); | 158 form_isc_.origin = GURL("http://www.isc.org/"); |
157 form_isc_.action = GURL("http://www.isc.org/auth"); | 159 form_isc_.action = GURL("http://www.isc.org/auth"); |
158 form_isc_.username_element = UTF8ToUTF16("id"); | 160 form_isc_.username_element = UTF8ToUTF16("id"); |
159 form_isc_.username_value = UTF8ToUTF16("janedoe"); | 161 form_isc_.username_value = UTF8ToUTF16("janedoe"); |
160 form_isc_.password_element = UTF8ToUTF16("passwd"); | 162 form_isc_.password_element = UTF8ToUTF16("passwd"); |
161 form_isc_.password_value = UTF8ToUTF16("ihazabukkit"); | 163 form_isc_.password_value = UTF8ToUTF16("ihazabukkit"); |
162 form_isc_.submit_element = UTF8ToUTF16("login"); | 164 form_isc_.submit_element = UTF8ToUTF16("login"); |
163 form_isc_.signon_realm = "ISC"; | 165 form_isc_.signon_realm = "ISC"; |
164 } | 166 } |
165 | 167 |
166 void CheckPasswordForm(const PasswordForm& expected, | 168 static void CheckPasswordForm(const PasswordForm& expected, |
167 const PasswordForm& actual); | 169 const PasswordForm& actual); |
| 170 static void CheckPasswordChanges(const PasswordStoreChangeList& expected, |
| 171 const PasswordStoreChangeList& actual); |
168 | 172 |
169 PasswordForm old_form_google_; | 173 PasswordForm old_form_google_; |
170 PasswordForm form_google_; | 174 PasswordForm form_google_; |
171 PasswordForm form_isc_; | 175 PasswordForm form_isc_; |
172 }; | 176 }; |
173 | 177 |
174 void NativeBackendKWalletTestBase::CheckPasswordForm( | 178 void NativeBackendKWalletTestBase::CheckPasswordForm( |
175 const PasswordForm& expected, const PasswordForm& actual) { | 179 const PasswordForm& expected, const PasswordForm& actual) { |
176 EXPECT_EQ(expected.origin, actual.origin); | 180 EXPECT_EQ(expected.origin, actual.origin); |
177 EXPECT_EQ(expected.password_value, actual.password_value); | 181 EXPECT_EQ(expected.password_value, actual.password_value); |
178 EXPECT_EQ(expected.action, actual.action); | 182 EXPECT_EQ(expected.action, actual.action); |
179 EXPECT_EQ(expected.username_element, actual.username_element); | 183 EXPECT_EQ(expected.username_element, actual.username_element); |
180 EXPECT_EQ(expected.username_value, actual.username_value); | 184 EXPECT_EQ(expected.username_value, actual.username_value); |
181 EXPECT_EQ(expected.password_element, actual.password_element); | 185 EXPECT_EQ(expected.password_element, actual.password_element); |
182 EXPECT_EQ(expected.submit_element, actual.submit_element); | 186 EXPECT_EQ(expected.submit_element, actual.submit_element); |
183 EXPECT_EQ(expected.signon_realm, actual.signon_realm); | 187 EXPECT_EQ(expected.signon_realm, actual.signon_realm); |
184 EXPECT_EQ(expected.ssl_valid, actual.ssl_valid); | 188 EXPECT_EQ(expected.ssl_valid, actual.ssl_valid); |
185 EXPECT_EQ(expected.preferred, actual.preferred); | 189 EXPECT_EQ(expected.preferred, actual.preferred); |
186 // We don't check the date created. It varies. | 190 // We don't check the date created. It varies. |
187 EXPECT_EQ(expected.blacklisted_by_user, actual.blacklisted_by_user); | 191 EXPECT_EQ(expected.blacklisted_by_user, actual.blacklisted_by_user); |
188 EXPECT_EQ(expected.type, actual.type); | 192 EXPECT_EQ(expected.type, actual.type); |
189 EXPECT_EQ(expected.times_used, actual.times_used); | 193 EXPECT_EQ(expected.times_used, actual.times_used); |
190 EXPECT_EQ(expected.scheme, actual.scheme); | 194 EXPECT_EQ(expected.scheme, actual.scheme); |
191 } | 195 } |
192 | 196 |
| 197 void NativeBackendKWalletTestBase::CheckPasswordChanges( |
| 198 const PasswordStoreChangeList& expected, |
| 199 const PasswordStoreChangeList& actual) { |
| 200 ASSERT_EQ(expected.size(), actual.size()); |
| 201 for (size_t i = 0; i < expected.size(); ++i) { |
| 202 EXPECT_EQ(expected[i].type(), actual[i].type()); |
| 203 CheckPasswordForm(expected[i].form(), actual[i].form()); |
| 204 } |
| 205 } |
| 206 |
193 class NativeBackendKWalletTest : public NativeBackendKWalletTestBase { | 207 class NativeBackendKWalletTest : public NativeBackendKWalletTestBase { |
194 protected: | 208 protected: |
195 NativeBackendKWalletTest() | 209 NativeBackendKWalletTest() |
196 : ui_thread_(BrowserThread::UI, &message_loop_), | 210 : ui_thread_(BrowserThread::UI, &message_loop_), |
197 db_thread_(BrowserThread::DB), klauncher_ret_(0), | 211 db_thread_(BrowserThread::DB), klauncher_ret_(0), |
198 klauncher_contacted_(false), kwallet_runnable_(true), | 212 klauncher_contacted_(false), kwallet_runnable_(true), |
199 kwallet_running_(true), kwallet_enabled_(true) { | 213 kwallet_running_(true), kwallet_enabled_(true) { |
200 } | 214 } |
201 | 215 |
202 virtual void SetUp(); | 216 virtual void SetUp(); |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 EXPECT_EQ(1u, form_list.size()); | 641 EXPECT_EQ(1u, form_list.size()); |
628 STLDeleteElements(&form_list); | 642 STLDeleteElements(&form_list); |
629 | 643 |
630 CheckPasswordForms("Chrome Form Data (42)", expected); | 644 CheckPasswordForms("Chrome Form Data (42)", expected); |
631 } | 645 } |
632 | 646 |
633 TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) { | 647 TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) { |
634 NativeBackendKWalletStub backend(42); | 648 NativeBackendKWalletStub backend(42); |
635 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); | 649 EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); |
636 | 650 |
637 BrowserThread::PostTask( | 651 PasswordStoreChangeList changes; |
| 652 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, |
| 653 form_google_)); |
| 654 BrowserThread::PostTaskAndReplyWithResult( |
638 BrowserThread::DB, FROM_HERE, | 655 BrowserThread::DB, FROM_HERE, |
639 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | 656 base::Bind(&NativeBackendKWalletStub::AddLogin, |
640 base::Unretained(&backend), form_google_)); | 657 base::Unretained(&backend), form_google_), |
641 BrowserThread::PostTask( | 658 base::Bind(&NativeBackendKWalletTest::CheckPasswordChanges, |
| 659 changes)); |
| 660 |
| 661 changes.clear(); |
| 662 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, |
| 663 form_google_)); |
| 664 form_google_.times_used++; |
| 665 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, |
| 666 form_google_)); |
| 667 |
| 668 BrowserThread::PostTaskAndReplyWithResult( |
642 BrowserThread::DB, FROM_HERE, | 669 BrowserThread::DB, FROM_HERE, |
643 base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin), | 670 base::Bind(&NativeBackendKWalletStub::AddLogin, |
644 base::Unretained(&backend), form_google_)); | 671 base::Unretained(&backend), form_google_), |
| 672 base::Bind(&NativeBackendKWalletTest::CheckPasswordChanges, |
| 673 changes)); |
645 | 674 |
646 RunDBThread(); | 675 RunDBThread(); |
647 | 676 |
648 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); | 677 EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data")); |
649 | 678 |
650 std::vector<const PasswordForm*> forms; | 679 std::vector<const PasswordForm*> forms; |
651 forms.push_back(&form_google_); | 680 forms.push_back(&form_google_); |
652 ExpectationArray expected; | 681 ExpectationArray expected; |
653 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); | 682 expected.push_back(make_pair(std::string(form_google_.signon_realm), forms)); |
654 CheckPasswordForms("Chrome Form Data (42)", expected); | 683 CheckPasswordForms("Chrome Form Data (42)", expected); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 CheckVersion0Pickle(false, PasswordForm::SCHEME_HTML); | 821 CheckVersion0Pickle(false, PasswordForm::SCHEME_HTML); |
793 } | 822 } |
794 | 823 |
795 TEST_F(NativeBackendKWalletPickleTest, ReadsOld64BitHTTPPickles) { | 824 TEST_F(NativeBackendKWalletPickleTest, ReadsOld64BitHTTPPickles) { |
796 CheckVersion0Pickle(false, PasswordForm::SCHEME_BASIC); | 825 CheckVersion0Pickle(false, PasswordForm::SCHEME_BASIC); |
797 } | 826 } |
798 | 827 |
799 TEST_F(NativeBackendKWalletPickleTest, CheckVersion1Pickle) { | 828 TEST_F(NativeBackendKWalletPickleTest, CheckVersion1Pickle) { |
800 CheckVersion1Pickle(); | 829 CheckVersion1Pickle(); |
801 } | 830 } |
OLD | NEW |