| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 using testing::WithArg; | 29 using testing::WithArg; |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 class MockPasswordStoreConsumer : public PasswordStoreConsumer { | 33 class MockPasswordStoreConsumer : public PasswordStoreConsumer { |
| 34 public: | 34 public: |
| 35 MOCK_METHOD1(OnGetPasswordStoreResults, | 35 MOCK_METHOD1(OnGetPasswordStoreResults, |
| 36 void(const std::vector<PasswordForm*>&)); | 36 void(const std::vector<PasswordForm*>&)); |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // This class will add and remove a mock notification observer from | |
| 40 // the DB thread. | |
| 41 class DBThreadObserverHelper | |
| 42 : public base::RefCountedThreadSafe<DBThreadObserverHelper, | |
| 43 BrowserThread::DeleteOnDBThread> { | |
| 44 public: | |
| 45 DBThreadObserverHelper() : done_event_(true, false) {} | |
| 46 | |
| 47 void Init(PasswordStore* password_store) { | |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 49 BrowserThread::PostTask( | |
| 50 BrowserThread::DB, | |
| 51 FROM_HERE, | |
| 52 base::Bind(&DBThreadObserverHelper::AddObserverTask, | |
| 53 this, | |
| 54 make_scoped_refptr(password_store))); | |
| 55 done_event_.Wait(); | |
| 56 } | |
| 57 | |
| 58 content::MockNotificationObserver& observer() { | |
| 59 return observer_; | |
| 60 } | |
| 61 | |
| 62 protected: | |
| 63 virtual ~DBThreadObserverHelper() { | |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 65 registrar_.RemoveAll(); | |
| 66 } | |
| 67 | |
| 68 void AddObserverTask(PasswordStore* password_store) { | |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 70 registrar_.Add(&observer_, | |
| 71 chrome::NOTIFICATION_LOGINS_CHANGED, | |
| 72 content::Source<PasswordStore>(password_store)); | |
| 73 done_event_.Signal(); | |
| 74 } | |
| 75 | |
| 76 WaitableEvent done_event_; | |
| 77 content::NotificationRegistrar registrar_; | |
| 78 content::MockNotificationObserver observer_; | |
| 79 | |
| 80 private: | |
| 81 friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>; | |
| 82 friend class base::DeleteHelper<DBThreadObserverHelper>; | |
| 83 }; | |
| 84 | |
| 85 } // anonymous namespace | 39 } // anonymous namespace |
| 86 | 40 |
| 87 class PasswordStoreTest : public testing::Test { | 41 class PasswordStoreTest : public testing::Test { |
| 88 protected: | 42 protected: |
| 89 PasswordStoreTest() | 43 PasswordStoreTest() |
| 90 : ui_thread_(BrowserThread::UI, &message_loop_), | 44 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 91 db_thread_(BrowserThread::DB) { | 45 db_thread_(BrowserThread::DB) { |
| 92 } | 46 } |
| 93 | 47 |
| 94 virtual void SetUp() { | 48 virtual void SetUp() { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 121 STLDeleteContainerPointers(arg0.begin(), arg0.end()); | 75 STLDeleteContainerPointers(arg0.begin(), arg0.end()); |
| 122 } | 76 } |
| 123 | 77 |
| 124 ACTION(QuitUIMessageLoop) { | 78 ACTION(QuitUIMessageLoop) { |
| 125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 126 base::MessageLoop::current()->Quit(); | 80 base::MessageLoop::current()->Quit(); |
| 127 } | 81 } |
| 128 | 82 |
| 129 TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) { | 83 TEST_F(PasswordStoreTest, IgnoreOldWwwGoogleLogins) { |
| 130 scoped_refptr<PasswordStoreDefault> store( | 84 scoped_refptr<PasswordStoreDefault> store( |
| 131 new PasswordStoreDefault(login_db_.release(), profile_.get())); | 85 new PasswordStoreDefault( |
| 86 base::MessageLoopProxy::current(), |
| 87 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), |
| 88 login_db_.release(), |
| 89 profile_.get())); |
| 132 store->Init(); | 90 store->Init(); |
| 133 | 91 |
| 134 const time_t cutoff = 1325376000; // 00:00 Jan 1 2012 UTC | 92 const time_t cutoff = 1325376000; // 00:00 Jan 1 2012 UTC |
| 135 // The passwords are all empty because PasswordStoreDefault doesn't store the | 93 // The passwords are all empty because PasswordStoreDefault doesn't store the |
| 136 // actual passwords on OS X (they're stored in the Keychain instead). We could | 94 // actual passwords on OS X (they're stored in the Keychain instead). We could |
| 137 // special-case it, but it's easier to just have empty passwords. | 95 // special-case it, but it's easier to just have empty passwords. |
| 138 static const PasswordFormData form_data[] = { | 96 static const PasswordFormData form_data[] = { |
| 139 // A form on https://www.google.com/ older than the cutoff. Will be ignored. | 97 // A form on https://www.google.com/ older than the cutoff. Will be ignored. |
| 140 { PasswordForm::SCHEME_HTML, | 98 { PasswordForm::SCHEME_HTML, |
| 141 "https://www.google.com", | 99 "https://www.google.com", |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 .WillOnce(WithArg<0>(STLDeleteElements0())).RetiresOnSaturation(); | 215 .WillOnce(WithArg<0>(STLDeleteElements0())).RetiresOnSaturation(); |
| 258 | 216 |
| 259 store->GetLogins(www_google, PasswordStore::ALLOW_PROMPT, &consumer); | 217 store->GetLogins(www_google, PasswordStore::ALLOW_PROMPT, &consumer); |
| 260 store->GetLogins(accounts_google, PasswordStore::ALLOW_PROMPT, &consumer); | 218 store->GetLogins(accounts_google, PasswordStore::ALLOW_PROMPT, &consumer); |
| 261 store->GetLogins(bar_example, PasswordStore::ALLOW_PROMPT, &consumer); | 219 store->GetLogins(bar_example, PasswordStore::ALLOW_PROMPT, &consumer); |
| 262 | 220 |
| 263 base::MessageLoop::current()->Run(); | 221 base::MessageLoop::current()->Run(); |
| 264 | 222 |
| 265 STLDeleteElements(&all_forms); | 223 STLDeleteElements(&all_forms); |
| 266 } | 224 } |
| OLD | NEW |