Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: components/password_manager/core/browser/password_store_default_unittest.cc

Issue 866983003: GetLoginsRequest: Use ScopedVector to express ownership of forms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@324291_scopedvector
Patch Set: Rebased Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 13 matching lines...) Expand all
24 using testing::_; 24 using testing::_;
25 using testing::ElementsAreArray; 25 using testing::ElementsAreArray;
26 using testing::WithArg; 26 using testing::WithArg;
27 27
28 namespace password_manager { 28 namespace password_manager {
29 29
30 namespace { 30 namespace {
31 31
32 class MockPasswordStoreConsumer : public PasswordStoreConsumer { 32 class MockPasswordStoreConsumer : public PasswordStoreConsumer {
33 public: 33 public:
34 MOCK_METHOD1(OnGetPasswordStoreResults, 34 MOCK_METHOD0(OnGetPasswordStoreResults, void());
35 void(const std::vector<PasswordForm*>&));
36 }; 35 };
37 36
38 class MockPasswordStoreObserver : public PasswordStore::Observer { 37 class MockPasswordStoreObserver : public PasswordStore::Observer {
39 public: 38 public:
40 MOCK_METHOD1(OnLoginsChanged, void(const PasswordStoreChangeList& changes)); 39 MOCK_METHOD1(OnLoginsChanged, void(const PasswordStoreChangeList& changes));
41 }; 40 };
42 41
43 // A mock LoginDatabase that simulates a failing Init() method. 42 // A mock LoginDatabase that simulates a failing Init() method.
44 class BadLoginDatabase : public LoginDatabase { 43 class BadLoginDatabase : public LoginDatabase {
45 public: 44 public:
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 "http://foo.example.com/action", 106 "http://foo.example.com/action",
108 L"มีสีสัน", 107 L"มีสีสัน",
109 L"お元気ですか?", 108 L"お元気ですか?",
110 L"盆栽", 109 L"盆栽",
111 L"أحب كرة", 110 L"أحب كرة",
112 L"£éä국수çà", 111 L"£éä국수çà",
113 true, false, 1 }, 112 true, false, 1 },
114 }; 113 };
115 114
116 // Build the expected forms vector and add the forms to the store. 115 // Build the expected forms vector and add the forms to the store.
117 std::vector<PasswordForm*> expected_forms; 116 ScopedVector<PasswordForm> expected_forms;
118 for (unsigned int i = 0; i < arraysize(form_data); ++i) { 117 for (unsigned int i = 0; i < arraysize(form_data); ++i) {
119 PasswordForm* form = CreatePasswordFormFromData(form_data[i]); 118 expected_forms.push_back(CreatePasswordFormFromData(form_data[i]));
120 expected_forms.push_back(form); 119 store->AddLogin(*expected_forms.back());
121 store->AddLogin(*form);
122 } 120 }
123 121
124 base::MessageLoop::current()->RunUntilIdle(); 122 base::MessageLoop::current()->RunUntilIdle();
125 123
126 MockPasswordStoreConsumer consumer; 124 MockPasswordStoreConsumer consumer;
127 125
128 // We expect to get the same data back, even though it's not all ASCII. 126 // We expect to get the same data back, even though it's not all ASCII.
129 EXPECT_CALL(consumer, 127 EXPECT_CALL(consumer, OnGetPasswordStoreResults());
130 OnGetPasswordStoreResults(ContainsAllPasswordForms(expected_forms)))
131 .WillOnce(WithArg<0>(STLDeleteElements0()));
132 store->GetAutofillableLogins(&consumer); 128 store->GetAutofillableLogins(&consumer);
133 129
134 base::MessageLoop::current()->RunUntilIdle(); 130 base::MessageLoop::current()->RunUntilIdle();
131 EXPECT_TRUE(ContainsSamePasswordFormsPtr(expected_forms.get(),
132 consumer.results()->get()));
135 133
136 STLDeleteElements(&expected_forms);
137 store->Shutdown(); 134 store->Shutdown();
138 base::MessageLoop::current()->RunUntilIdle(); 135 base::MessageLoop::current()->RunUntilIdle();
139 } 136 }
140 137
141 TEST_F(PasswordStoreDefaultTest, Notifications) { 138 TEST_F(PasswordStoreDefaultTest, Notifications) {
142 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( 139 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault(
143 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(), 140 base::MessageLoopProxy::current(), base::MessageLoopProxy::current(),
144 make_scoped_ptr(new LoginDatabase(test_login_db_file_path())))); 141 make_scoped_ptr(new LoginDatabase(test_login_db_file_path()))));
145 store->Init(syncer::SyncableService::StartSyncFlare()); 142 store->Init(syncer::SyncableService::StartSyncFlare());
146 143
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 blacklisted_form->signon_realm = "http://foo.example.com"; 210 blacklisted_form->signon_realm = "http://foo.example.com";
214 blacklisted_form->origin = GURL("http://foo.example.com/origin"); 211 blacklisted_form->origin = GURL("http://foo.example.com/origin");
215 blacklisted_form->action = GURL("http://foo.example.com/action"); 212 blacklisted_form->action = GURL("http://foo.example.com/action");
216 blacklisted_form->blacklisted_by_user = true; 213 blacklisted_form->blacklisted_by_user = true;
217 bad_store->AddLogin(*form); 214 bad_store->AddLogin(*form);
218 bad_store->AddLogin(*blacklisted_form); 215 bad_store->AddLogin(*blacklisted_form);
219 base::MessageLoop::current()->RunUntilIdle(); 216 base::MessageLoop::current()->RunUntilIdle();
220 217
221 // Get all logins; autofillable logins; blacklisted logins. 218 // Get all logins; autofillable logins; blacklisted logins.
222 testing::StrictMock<MockPasswordStoreConsumer> mock_consumer; 219 testing::StrictMock<MockPasswordStoreConsumer> mock_consumer;
223 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults(testing::ElementsAre())); 220 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults());
224 bad_store->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &mock_consumer); 221 bad_store->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &mock_consumer);
225 base::MessageLoop::current()->RunUntilIdle(); 222 base::MessageLoop::current()->RunUntilIdle();
223 EXPECT_EQ(0u, mock_consumer.results()->size());
226 testing::Mock::VerifyAndClearExpectations(&mock_consumer); 224 testing::Mock::VerifyAndClearExpectations(&mock_consumer);
227 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults(testing::ElementsAre())); 225 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults());
228 bad_store->GetAutofillableLogins(&mock_consumer); 226 bad_store->GetAutofillableLogins(&mock_consumer);
229 base::MessageLoop::current()->RunUntilIdle(); 227 base::MessageLoop::current()->RunUntilIdle();
228 EXPECT_EQ(0u, mock_consumer.results()->size());
230 testing::Mock::VerifyAndClearExpectations(&mock_consumer); 229 testing::Mock::VerifyAndClearExpectations(&mock_consumer);
231 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults(testing::ElementsAre())); 230 EXPECT_CALL(mock_consumer, OnGetPasswordStoreResults());
232 bad_store->GetBlacklistLogins(&mock_consumer); 231 bad_store->GetBlacklistLogins(&mock_consumer);
233 base::MessageLoop::current()->RunUntilIdle(); 232 base::MessageLoop::current()->RunUntilIdle();
233 EXPECT_EQ(0u, mock_consumer.results()->size());
234 234
235 // Report metrics. 235 // Report metrics.
236 bad_store->ReportMetrics("Test Username", true); 236 bad_store->ReportMetrics("Test Username", true);
237 base::MessageLoop::current()->RunUntilIdle(); 237 base::MessageLoop::current()->RunUntilIdle();
238 238
239 // Change the login. 239 // Change the login.
240 form->password_value = base::ASCIIToUTF16("a different password"); 240 form->password_value = base::ASCIIToUTF16("a different password");
241 bad_store->UpdateLogin(*form); 241 bad_store->UpdateLogin(*form);
242 base::MessageLoop::current()->RunUntilIdle(); 242 base::MessageLoop::current()->RunUntilIdle();
243 243
244 // Delete one login; a range of logins. 244 // Delete one login; a range of logins.
245 bad_store->RemoveLogin(*form); 245 bad_store->RemoveLogin(*form);
246 base::MessageLoop::current()->RunUntilIdle(); 246 base::MessageLoop::current()->RunUntilIdle();
247 bad_store->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max()); 247 bad_store->RemoveLoginsCreatedBetween(base::Time(), base::Time::Max());
248 base::MessageLoop::current()->RunUntilIdle(); 248 base::MessageLoop::current()->RunUntilIdle();
249 bad_store->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max()); 249 bad_store->RemoveLoginsSyncedBetween(base::Time(), base::Time::Max());
250 base::MessageLoop::current()->RunUntilIdle(); 250 base::MessageLoop::current()->RunUntilIdle();
251 251
252 // Ensure no notifications and no explosions during shutdown either. 252 // Ensure no notifications and no explosions during shutdown either.
253 bad_store->RemoveObserver(&mock_observer); 253 bad_store->RemoveObserver(&mock_observer);
254 bad_store->Shutdown(); 254 bad_store->Shutdown();
255 base::MessageLoop::current()->RunUntilIdle(); 255 base::MessageLoop::current()->RunUntilIdle();
256 } 256 }
257 257
258 } // namespace password_manager 258 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698