| 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/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
| 10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/password_manager/password_form_data.h" | 17 #include "chrome/browser/password_manager/password_form_data.h" |
| 18 #include "chrome/browser/password_manager/password_store_change.h" | 18 #include "chrome/browser/password_manager/password_store_change.h" |
| 19 #include "chrome/browser/password_manager/password_store_consumer.h" | 19 #include "chrome/browser/password_manager/password_store_consumer.h" |
| 20 #include "chrome/browser/password_manager/password_store_x.h" | 20 #include "chrome/browser/password_manager/password_store_x.h" |
| 21 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
| 25 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 26 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
| 27 #include "content/public/browser/notification_registrar.h" | 27 #include "content/public/browser/notification_registrar.h" |
| 28 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
| 29 #include "content/test/notification_observer_mock.h" | 29 #include "content/public/test/mock_notification_observer.h" |
| 30 #include "content/test/test_browser_thread.h" | 30 #include "content/test/test_browser_thread.h" |
| 31 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 33 |
| 34 using base::WaitableEvent; | 34 using base::WaitableEvent; |
| 35 using content::BrowserThread; | 35 using content::BrowserThread; |
| 36 using testing::_; | 36 using testing::_; |
| 37 using testing::DoAll; | 37 using testing::DoAll; |
| 38 using testing::ElementsAreArray; | 38 using testing::ElementsAreArray; |
| 39 using testing::Pointee; | 39 using testing::Pointee; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 63 void Init(PasswordStore* password_store) { | 63 void Init(PasswordStore* password_store) { |
| 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 65 BrowserThread::PostTask( | 65 BrowserThread::PostTask( |
| 66 BrowserThread::DB, | 66 BrowserThread::DB, |
| 67 FROM_HERE, | 67 FROM_HERE, |
| 68 base::Bind(&DBThreadObserverHelper::AddObserverTask, | 68 base::Bind(&DBThreadObserverHelper::AddObserverTask, |
| 69 this, make_scoped_refptr(password_store))); | 69 this, make_scoped_refptr(password_store))); |
| 70 done_event_.Wait(); | 70 done_event_.Wait(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 content::NotificationObserverMock& observer() { | 73 content::MockNotificationObserver& observer() { |
| 74 return observer_; | 74 return observer_; |
| 75 } | 75 } |
| 76 | 76 |
| 77 protected: | 77 protected: |
| 78 friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>; | 78 friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>; |
| 79 friend class base::DeleteHelper<DBThreadObserverHelper>; | 79 friend class base::DeleteHelper<DBThreadObserverHelper>; |
| 80 | 80 |
| 81 virtual ~DBThreadObserverHelper() { | 81 virtual ~DBThreadObserverHelper() { |
| 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 83 registrar_.RemoveAll(); | 83 registrar_.RemoveAll(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void AddObserverTask(PasswordStore* password_store) { | 86 void AddObserverTask(PasswordStore* password_store) { |
| 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 88 registrar_.Add(&observer_, | 88 registrar_.Add(&observer_, |
| 89 chrome::NOTIFICATION_LOGINS_CHANGED, | 89 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 90 content::Source<PasswordStore>(password_store)); | 90 content::Source<PasswordStore>(password_store)); |
| 91 done_event_.Signal(); | 91 done_event_.Signal(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 WaitableEvent done_event_; | 94 WaitableEvent done_event_; |
| 95 content::NotificationRegistrar registrar_; | 95 content::NotificationRegistrar registrar_; |
| 96 content::NotificationObserverMock observer_; | 96 content::MockNotificationObserver observer_; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 class FailingBackend : public PasswordStoreX::NativeBackend { | 99 class FailingBackend : public PasswordStoreX::NativeBackend { |
| 100 public: | 100 public: |
| 101 virtual bool Init() { return true; } | 101 virtual bool Init() { return true; } |
| 102 | 102 |
| 103 virtual bool AddLogin(const PasswordForm& form) { return false; } | 103 virtual bool AddLogin(const PasswordForm& form) { return false; } |
| 104 virtual bool UpdateLogin(const PasswordForm& form) { return false; } | 104 virtual bool UpdateLogin(const PasswordForm& form) { return false; } |
| 105 virtual bool RemoveLogin(const PasswordForm& form) { return false; } | 105 virtual bool RemoveLogin(const PasswordForm& form) { return false; } |
| 106 | 106 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 538 |
| 539 INSTANTIATE_TEST_CASE_P(NoBackend, | 539 INSTANTIATE_TEST_CASE_P(NoBackend, |
| 540 PasswordStoreXTest, | 540 PasswordStoreXTest, |
| 541 testing::Values(NO_BACKEND)); | 541 testing::Values(NO_BACKEND)); |
| 542 INSTANTIATE_TEST_CASE_P(FailingBackend, | 542 INSTANTIATE_TEST_CASE_P(FailingBackend, |
| 543 PasswordStoreXTest, | 543 PasswordStoreXTest, |
| 544 testing::Values(FAILING_BACKEND)); | 544 testing::Values(FAILING_BACKEND)); |
| 545 INSTANTIATE_TEST_CASE_P(WorkingBackend, | 545 INSTANTIATE_TEST_CASE_P(WorkingBackend, |
| 546 PasswordStoreXTest, | 546 PasswordStoreXTest, |
| 547 testing::Values(WORKING_BACKEND)); | 547 testing::Values(WORKING_BACKEND)); |
| OLD | NEW |