| 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/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 done_event_.Signal(); | 93 done_event_.Signal(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 WaitableEvent done_event_; | 96 WaitableEvent done_event_; |
| 97 content::NotificationRegistrar registrar_; | 97 content::NotificationRegistrar registrar_; |
| 98 content::MockNotificationObserver observer_; | 98 content::MockNotificationObserver observer_; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 class FailingBackend : public PasswordStoreX::NativeBackend { | 101 class FailingBackend : public PasswordStoreX::NativeBackend { |
| 102 public: | 102 public: |
| 103 virtual bool Init() { return true; } | 103 virtual bool Init() OVERRIDE { return true; } |
| 104 | 104 |
| 105 virtual bool AddLogin(const PasswordForm& form) { return false; } | 105 virtual bool AddLogin(const PasswordForm& form) OVERRIDE { return false; } |
| 106 virtual bool UpdateLogin(const PasswordForm& form) { return false; } | 106 virtual bool UpdateLogin(const PasswordForm& form) OVERRIDE { return false; } |
| 107 virtual bool RemoveLogin(const PasswordForm& form) { return false; } | 107 virtual bool RemoveLogin(const PasswordForm& form) OVERRIDE { return false; } |
| 108 | 108 |
| 109 virtual bool RemoveLoginsCreatedBetween(const base::Time& delete_begin, | 109 virtual bool RemoveLoginsCreatedBetween( |
| 110 const base::Time& delete_end) { | 110 const base::Time& delete_begin, |
| 111 const base::Time& delete_end) OVERRIDE { |
| 111 return false; | 112 return false; |
| 112 } | 113 } |
| 113 | 114 |
| 114 virtual bool GetLogins(const PasswordForm& form, PasswordFormList* forms) { | 115 virtual bool GetLogins(const PasswordForm& form, |
| 116 PasswordFormList* forms) OVERRIDE { |
| 115 return false; | 117 return false; |
| 116 } | 118 } |
| 117 | 119 |
| 118 virtual bool GetLoginsCreatedBetween(const base::Time& get_begin, | 120 virtual bool GetLoginsCreatedBetween(const base::Time& get_begin, |
| 119 const base::Time& get_end, | 121 const base::Time& get_end, |
| 120 PasswordFormList* forms) { | 122 PasswordFormList* forms) OVERRIDE { |
| 121 return false; | 123 return false; |
| 122 } | 124 } |
| 123 | 125 |
| 124 virtual bool GetAutofillableLogins(PasswordFormList* forms) { return false; } | 126 virtual bool GetAutofillableLogins(PasswordFormList* forms) OVERRIDE { |
| 125 virtual bool GetBlacklistLogins(PasswordFormList* forms) { return false; } | 127 return false; |
| 128 } |
| 129 virtual bool GetBlacklistLogins(PasswordFormList* forms) OVERRIDE { |
| 130 return false; |
| 131 } |
| 126 }; | 132 }; |
| 127 | 133 |
| 128 class MockBackend : public PasswordStoreX::NativeBackend { | 134 class MockBackend : public PasswordStoreX::NativeBackend { |
| 129 public: | 135 public: |
| 130 virtual bool Init() { return true; } | 136 virtual bool Init() OVERRIDE { return true; } |
| 131 | 137 |
| 132 virtual bool AddLogin(const PasswordForm& form) { | 138 virtual bool AddLogin(const PasswordForm& form) OVERRIDE { |
| 133 all_forms_.push_back(form); | 139 all_forms_.push_back(form); |
| 134 return true; | 140 return true; |
| 135 } | 141 } |
| 136 | 142 |
| 137 virtual bool UpdateLogin(const PasswordForm& form) { | 143 virtual bool UpdateLogin(const PasswordForm& form) OVERRIDE { |
| 138 for (size_t i = 0; i < all_forms_.size(); ++i) | 144 for (size_t i = 0; i < all_forms_.size(); ++i) |
| 139 if (CompareForms(all_forms_[i], form, true)) | 145 if (CompareForms(all_forms_[i], form, true)) |
| 140 all_forms_[i] = form; | 146 all_forms_[i] = form; |
| 141 return true; | 147 return true; |
| 142 } | 148 } |
| 143 | 149 |
| 144 virtual bool RemoveLogin(const PasswordForm& form) { | 150 virtual bool RemoveLogin(const PasswordForm& form) OVERRIDE { |
| 145 for (size_t i = 0; i < all_forms_.size(); ++i) | 151 for (size_t i = 0; i < all_forms_.size(); ++i) |
| 146 if (CompareForms(all_forms_[i], form, false)) | 152 if (CompareForms(all_forms_[i], form, false)) |
| 147 erase(i--); | 153 erase(i--); |
| 148 return true; | 154 return true; |
| 149 } | 155 } |
| 150 | 156 |
| 151 virtual bool RemoveLoginsCreatedBetween(const base::Time& delete_begin, | 157 virtual bool RemoveLoginsCreatedBetween( |
| 152 const base::Time& delete_end) { | 158 const base::Time& delete_begin, |
| 159 const base::Time& delete_end) OVERRIDE { |
| 153 for (size_t i = 0; i < all_forms_.size(); ++i) { | 160 for (size_t i = 0; i < all_forms_.size(); ++i) { |
| 154 if (delete_begin <= all_forms_[i].date_created && | 161 if (delete_begin <= all_forms_[i].date_created && |
| 155 (delete_end.is_null() || all_forms_[i].date_created < delete_end)) | 162 (delete_end.is_null() || all_forms_[i].date_created < delete_end)) |
| 156 erase(i--); | 163 erase(i--); |
| 157 } | 164 } |
| 158 return true; | 165 return true; |
| 159 } | 166 } |
| 160 | 167 |
| 161 virtual bool GetLogins(const PasswordForm& form, PasswordFormList* forms) { | 168 virtual bool GetLogins(const PasswordForm& form, |
| 169 PasswordFormList* forms) OVERRIDE { |
| 162 for (size_t i = 0; i < all_forms_.size(); ++i) | 170 for (size_t i = 0; i < all_forms_.size(); ++i) |
| 163 if (all_forms_[i].signon_realm == form.signon_realm) | 171 if (all_forms_[i].signon_realm == form.signon_realm) |
| 164 forms->push_back(new PasswordForm(all_forms_[i])); | 172 forms->push_back(new PasswordForm(all_forms_[i])); |
| 165 return true; | 173 return true; |
| 166 } | 174 } |
| 167 | 175 |
| 168 virtual bool GetLoginsCreatedBetween(const base::Time& get_begin, | 176 virtual bool GetLoginsCreatedBetween(const base::Time& get_begin, |
| 169 const base::Time& get_end, | 177 const base::Time& get_end, |
| 170 PasswordFormList* forms) { | 178 PasswordFormList* forms) OVERRIDE { |
| 171 for (size_t i = 0; i < all_forms_.size(); ++i) | 179 for (size_t i = 0; i < all_forms_.size(); ++i) |
| 172 if (get_begin <= all_forms_[i].date_created && | 180 if (get_begin <= all_forms_[i].date_created && |
| 173 (get_end.is_null() || all_forms_[i].date_created < get_end)) | 181 (get_end.is_null() || all_forms_[i].date_created < get_end)) |
| 174 forms->push_back(new PasswordForm(all_forms_[i])); | 182 forms->push_back(new PasswordForm(all_forms_[i])); |
| 175 return true; | 183 return true; |
| 176 } | 184 } |
| 177 | 185 |
| 178 virtual bool GetAutofillableLogins(PasswordFormList* forms) { | 186 virtual bool GetAutofillableLogins(PasswordFormList* forms) OVERRIDE { |
| 179 for (size_t i = 0; i < all_forms_.size(); ++i) | 187 for (size_t i = 0; i < all_forms_.size(); ++i) |
| 180 if (!all_forms_[i].blacklisted_by_user) | 188 if (!all_forms_[i].blacklisted_by_user) |
| 181 forms->push_back(new PasswordForm(all_forms_[i])); | 189 forms->push_back(new PasswordForm(all_forms_[i])); |
| 182 return true; | 190 return true; |
| 183 } | 191 } |
| 184 | 192 |
| 185 virtual bool GetBlacklistLogins(PasswordFormList* forms) { | 193 virtual bool GetBlacklistLogins(PasswordFormList* forms) OVERRIDE { |
| 186 for (size_t i = 0; i < all_forms_.size(); ++i) | 194 for (size_t i = 0; i < all_forms_.size(); ++i) |
| 187 if (all_forms_[i].blacklisted_by_user) | 195 if (all_forms_[i].blacklisted_by_user) |
| 188 forms->push_back(new PasswordForm(all_forms_[i])); | 196 forms->push_back(new PasswordForm(all_forms_[i])); |
| 189 return true; | 197 return true; |
| 190 } | 198 } |
| 191 | 199 |
| 192 private: | 200 private: |
| 193 void erase(size_t index) { | 201 void erase(size_t index) { |
| 194 if (index < all_forms_.size() - 1) | 202 if (index < all_forms_.size() - 1) |
| 195 all_forms_[index] = all_forms_[all_forms_.size() - 1]; | 203 all_forms_[index] = all_forms_[all_forms_.size() - 1]; |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 | 548 |
| 541 INSTANTIATE_TEST_CASE_P(NoBackend, | 549 INSTANTIATE_TEST_CASE_P(NoBackend, |
| 542 PasswordStoreXTest, | 550 PasswordStoreXTest, |
| 543 testing::Values(NO_BACKEND)); | 551 testing::Values(NO_BACKEND)); |
| 544 INSTANTIATE_TEST_CASE_P(FailingBackend, | 552 INSTANTIATE_TEST_CASE_P(FailingBackend, |
| 545 PasswordStoreXTest, | 553 PasswordStoreXTest, |
| 546 testing::Values(FAILING_BACKEND)); | 554 testing::Values(FAILING_BACKEND)); |
| 547 INSTANTIATE_TEST_CASE_P(WorkingBackend, | 555 INSTANTIATE_TEST_CASE_P(WorkingBackend, |
| 548 PasswordStoreXTest, | 556 PasswordStoreXTest, |
| 549 testing::Values(WORKING_BACKEND)); | 557 testing::Values(WORKING_BACKEND)); |
| OLD | NEW |