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

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

Issue 838453003: Open the LoginDatabase on the DB thread, not the UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 27 matching lines...) Expand all
38 38
39 MOCK_METHOD1(StartSyncFlare, void(syncer::ModelType)); 39 MOCK_METHOD1(StartSyncFlare, void(syncer::ModelType));
40 }; 40 };
41 41
42 } // namespace 42 } // namespace
43 43
44 class PasswordStoreTest : public testing::Test { 44 class PasswordStoreTest : public testing::Test {
45 protected: 45 protected:
46 void SetUp() override { 46 void SetUp() override {
47 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 47 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
48 login_db_.reset(new LoginDatabase());
49 ASSERT_TRUE(login_db_->Init(temp_dir_.path().Append(
50 FILE_PATH_LITERAL("login_test"))));
51 } 48 }
52 49
53 void TearDown() override { ASSERT_TRUE(temp_dir_.Delete()); } 50 void TearDown() override { ASSERT_TRUE(temp_dir_.Delete()); }
54 51
52 base::FilePath test_login_db_file_path() const {
53 return temp_dir_.path().Append(FILE_PATH_LITERAL("login_test"));
54 }
55
55 base::MessageLoopForUI message_loop_; 56 base::MessageLoopForUI message_loop_;
56 scoped_ptr<LoginDatabase> login_db_;
57 base::ScopedTempDir temp_dir_; 57 base::ScopedTempDir temp_dir_;
58 }; 58 };
59 59
60 ACTION(STLDeleteElements0) { 60 ACTION(STLDeleteElements0) {
61 STLDeleteContainerPointers(arg0.begin(), arg0.end()); 61 STLDeleteContainerPointers(arg0.begin(), arg0.end());
62 } 62 }
63 63
64 TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) { 64 TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) {
65 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( 65 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault(
66 base::MessageLoopProxy::current(), 66 base::MessageLoopProxy::current(),
67 base::MessageLoopProxy::current(), 67 base::MessageLoopProxy::current(),
68 login_db_.release())); 68 test_login_db_file_path()));
69 store->Init(syncer::SyncableService::StartSyncFlare()); 69 store->Init(syncer::SyncableService::StartSyncFlare());
70 70
71 const time_t cutoff = 1325376000; // 00:00 Jan 1 2012 UTC 71 const time_t cutoff = 1325376000; // 00:00 Jan 1 2012 UTC
72 // The passwords are all empty because PasswordStoreDefault doesn't store the 72 // The passwords are all empty because PasswordStoreDefault doesn't store the
73 // actual passwords on OS X (they're stored in the Keychain instead). We could 73 // actual passwords on OS X (they're stored in the Keychain instead). We could
74 // special-case it, but it's easier to just have empty passwords. 74 // special-case it, but it's easier to just have empty passwords.
75 static const PasswordFormData form_data[] = { 75 static const PasswordFormData form_data[] = {
76 // A form on https://www.google.com/ older than the cutoff. Will be ignored. 76 // A form on https://www.google.com/ older than the cutoff. Will be ignored.
77 { PasswordForm::SCHEME_HTML, 77 { PasswordForm::SCHEME_HTML,
78 "https://www.google.com", 78 "https://www.google.com",
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 STLDeleteElements(&all_forms); 189 STLDeleteElements(&all_forms);
190 store->Shutdown(); 190 store->Shutdown();
191 base::MessageLoop::current()->RunUntilIdle(); 191 base::MessageLoop::current()->RunUntilIdle();
192 } 192 }
193 193
194 TEST_F(PasswordStoreTest, StartSyncFlare) { 194 TEST_F(PasswordStoreTest, StartSyncFlare) {
195 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault( 195 scoped_refptr<PasswordStoreDefault> store(new PasswordStoreDefault(
196 base::MessageLoopProxy::current(), 196 base::MessageLoopProxy::current(),
197 base::MessageLoopProxy::current(), 197 base::MessageLoopProxy::current(),
198 login_db_.release())); 198 test_login_db_file_path()));
199 StartSyncFlareMock mock; 199 StartSyncFlareMock mock;
200 store->Init( 200 store->Init(
201 base::Bind(&StartSyncFlareMock::StartSyncFlare, base::Unretained(&mock))); 201 base::Bind(&StartSyncFlareMock::StartSyncFlare, base::Unretained(&mock)));
202 { 202 {
203 PasswordForm form; 203 PasswordForm form;
204 EXPECT_CALL(mock, StartSyncFlare(syncer::PASSWORDS)); 204 EXPECT_CALL(mock, StartSyncFlare(syncer::PASSWORDS));
205 store->AddLogin(form); 205 store->AddLogin(form);
206 base::MessageLoop::current()->RunUntilIdle(); 206 base::MessageLoop::current()->RunUntilIdle();
207 } 207 }
208 store->Shutdown(); 208 store->Shutdown();
209 base::MessageLoop::current()->RunUntilIdle(); 209 base::MessageLoop::current()->RunUntilIdle();
210 } 210 }
211 211
212 } // namespace password_manager 212 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698