Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <sstream> | 7 #include <sstream> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 std::stringstream ss; | 37 std::stringstream ss; |
| 38 ss << "http://test" << num << ".com"; | 38 ss << "http://test" << num << ".com"; |
| 39 entry.login_pair.origin_url = ss.str(); | 39 entry.login_pair.origin_url = ss.str(); |
| 40 ss.clear(); | 40 ss.clear(); |
| 41 ss << "testName" << num; | 41 ss << "testName" << num; |
| 42 entry.login_pair.username = ss.str(); | 42 entry.login_pair.username = ss.str(); |
| 43 entry.num_characters_in_password = kNumCharactersInPassword; | 43 entry.num_characters_in_password = kNumCharactersInPassword; |
| 44 return entry; | 44 return entry; |
| 45 } | 45 } |
| 46 | 46 |
| 47 std::string CreateException(size_t num) { | 47 api::passwords_private::ExceptionPair CreateException(size_t num) { |
| 48 api::passwords_private::ExceptionPair exception; | |
| 48 std::stringstream ss; | 49 std::stringstream ss; |
| 49 ss << "http://exception" << num << ".com"; | 50 ss << "http://exception" << num << ".com"; |
| 50 return ss.str(); | 51 exception.exception_url = ss.str(); |
| 52 exception.link_url = ss.str(); | |
|
stevenjb
2016/04/22 16:11:20
nit: we should probably test with a different link
hcarmona
2016/04/23 01:46:08
Done.
| |
| 53 return exception; | |
| 51 } | 54 } |
| 52 | 55 |
| 53 // A test PasswordsPrivateDelegate implementation which uses mock data. | 56 // A test PasswordsPrivateDelegate implementation which uses mock data. |
| 54 // TestDelegate starts out with kNumMocks mocks of each type (saved password | 57 // TestDelegate starts out with kNumMocks mocks of each type (saved password |
| 55 // and password exception) and removes one mock each time RemoveSavedPassword() | 58 // and password exception) and removes one mock each time RemoveSavedPassword() |
| 56 // or RemovePasswordException() is called. | 59 // or RemovePasswordException() is called. |
| 57 class TestDelegate : public PasswordsPrivateDelegate { | 60 class TestDelegate : public PasswordsPrivateDelegate { |
| 58 public: | 61 public: |
| 59 TestDelegate() : profile_(nullptr) { | 62 TestDelegate() : profile_(nullptr) { |
| 60 // Create mock data. | 63 // Create mock data. |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 77 return ¤t_entries_; | 80 return ¤t_entries_; |
| 78 } | 81 } |
| 79 | 82 |
| 80 void SendPasswordExceptionsList() override { | 83 void SendPasswordExceptionsList() override { |
| 81 PasswordsPrivateEventRouter* router = | 84 PasswordsPrivateEventRouter* router = |
| 82 PasswordsPrivateEventRouterFactory::GetForProfile(profile_); | 85 PasswordsPrivateEventRouterFactory::GetForProfile(profile_); |
| 83 if (router) | 86 if (router) |
| 84 router->OnPasswordExceptionsListChanged(current_exceptions_); | 87 router->OnPasswordExceptionsListChanged(current_exceptions_); |
| 85 } | 88 } |
| 86 | 89 |
| 87 const std::vector<std::string>* GetPasswordExceptionsList() const override { | 90 const std::vector<api::passwords_private::ExceptionPair>* |
| 91 GetPasswordExceptionsList() const override { | |
| 88 return ¤t_exceptions_; | 92 return ¤t_exceptions_; |
| 89 } | 93 } |
| 90 | 94 |
| 91 void RemoveSavedPassword( | 95 void RemoveSavedPassword( |
| 92 const std::string& origin_url, const std::string& username) override { | 96 const std::string& origin_url, const std::string& username) override { |
| 93 if (!current_entries_.size()) | 97 if (!current_entries_.size()) |
| 94 return; | 98 return; |
| 95 | 99 |
| 96 // Since this is just mock data, remove the first entry regardless of | 100 // Since this is just mock data, remove the first entry regardless of |
| 97 // the data contained. | 101 // the data contained. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 122 } | 126 } |
| 123 } | 127 } |
| 124 | 128 |
| 125 void SetProfile(Profile* profile) { profile_ = profile; } | 129 void SetProfile(Profile* profile) { profile_ = profile; } |
| 126 | 130 |
| 127 private: | 131 private: |
| 128 // The current list of entries/exceptions. Cached here so that when new | 132 // The current list of entries/exceptions. Cached here so that when new |
| 129 // observers are added, this delegate can send the current lists without | 133 // observers are added, this delegate can send the current lists without |
| 130 // having to request them from |password_manager_presenter_| again. | 134 // having to request them from |password_manager_presenter_| again. |
| 131 std::vector<api::passwords_private::PasswordUiEntry> current_entries_; | 135 std::vector<api::passwords_private::PasswordUiEntry> current_entries_; |
| 132 std::vector<std::string> current_exceptions_; | 136 std::vector<api::passwords_private::ExceptionPair> current_exceptions_; |
| 133 Profile* profile_; | 137 Profile* profile_; |
| 134 }; | 138 }; |
| 135 | 139 |
| 136 class PasswordsPrivateApiTest : public ExtensionApiTest { | 140 class PasswordsPrivateApiTest : public ExtensionApiTest { |
| 137 public: | 141 public: |
| 138 PasswordsPrivateApiTest() { | 142 PasswordsPrivateApiTest() { |
| 139 if (!s_test_delegate_) { | 143 if (!s_test_delegate_) { |
| 140 s_test_delegate_ = new TestDelegate(); | 144 s_test_delegate_ = new TestDelegate(); |
| 141 } | 145 } |
| 142 } | 146 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 | 200 |
| 197 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetSavedPasswordList) { | 201 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetSavedPasswordList) { |
| 198 EXPECT_TRUE(RunPasswordsSubtest("getSavedPasswordList")) << message_; | 202 EXPECT_TRUE(RunPasswordsSubtest("getSavedPasswordList")) << message_; |
| 199 } | 203 } |
| 200 | 204 |
| 201 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetPasswordExceptionList) { | 205 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetPasswordExceptionList) { |
| 202 EXPECT_TRUE(RunPasswordsSubtest("getPasswordExceptionList")) << message_; | 206 EXPECT_TRUE(RunPasswordsSubtest("getPasswordExceptionList")) << message_; |
| 203 } | 207 } |
| 204 | 208 |
| 205 } // namespace extensions | 209 } // namespace extensions |
| OLD | NEW |