| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 static const size_t kNumMocks = 3; | 31 static const size_t kNumMocks = 3; |
| 32 static const int kNumCharactersInPassword = 10; | 32 static const int kNumCharactersInPassword = 10; |
| 33 static const char kPlaintextPassword[] = "plaintext"; | 33 static const char kPlaintextPassword[] = "plaintext"; |
| 34 | 34 |
| 35 api::passwords_private::PasswordUiEntry CreateEntry(size_t num) { | 35 api::passwords_private::PasswordUiEntry CreateEntry(size_t num) { |
| 36 api::passwords_private::PasswordUiEntry entry; | 36 api::passwords_private::PasswordUiEntry entry; |
| 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 << "/login"; |
| 41 entry.link_url = ss.str(); |
| 40 ss.clear(); | 42 ss.clear(); |
| 41 ss << "testName" << num; | 43 ss << "testName" << num; |
| 42 entry.login_pair.username = ss.str(); | 44 entry.login_pair.username = ss.str(); |
| 43 entry.num_characters_in_password = kNumCharactersInPassword; | 45 entry.num_characters_in_password = kNumCharactersInPassword; |
| 44 return entry; | 46 return entry; |
| 45 } | 47 } |
| 46 | 48 |
| 47 std::string CreateException(size_t num) { | 49 api::passwords_private::ExceptionPair CreateException(size_t num) { |
| 50 api::passwords_private::ExceptionPair exception; |
| 48 std::stringstream ss; | 51 std::stringstream ss; |
| 49 ss << "http://exception" << num << ".com"; | 52 ss << "http://exception" << num << ".com"; |
| 50 return ss.str(); | 53 exception.exception_url = ss.str(); |
| 54 ss << "/login"; |
| 55 exception.link_url = ss.str(); |
| 56 return exception; |
| 51 } | 57 } |
| 52 | 58 |
| 53 // A test PasswordsPrivateDelegate implementation which uses mock data. | 59 // A test PasswordsPrivateDelegate implementation which uses mock data. |
| 54 // TestDelegate starts out with kNumMocks mocks of each type (saved password | 60 // TestDelegate starts out with kNumMocks mocks of each type (saved password |
| 55 // and password exception) and removes one mock each time RemoveSavedPassword() | 61 // and password exception) and removes one mock each time RemoveSavedPassword() |
| 56 // or RemovePasswordException() is called. | 62 // or RemovePasswordException() is called. |
| 57 class TestDelegate : public PasswordsPrivateDelegate { | 63 class TestDelegate : public PasswordsPrivateDelegate { |
| 58 public: | 64 public: |
| 59 TestDelegate() : profile_(nullptr) { | 65 TestDelegate() : profile_(nullptr) { |
| 60 // Create mock data. | 66 // Create mock data. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 77 return ¤t_entries_; | 83 return ¤t_entries_; |
| 78 } | 84 } |
| 79 | 85 |
| 80 void SendPasswordExceptionsList() override { | 86 void SendPasswordExceptionsList() override { |
| 81 PasswordsPrivateEventRouter* router = | 87 PasswordsPrivateEventRouter* router = |
| 82 PasswordsPrivateEventRouterFactory::GetForProfile(profile_); | 88 PasswordsPrivateEventRouterFactory::GetForProfile(profile_); |
| 83 if (router) | 89 if (router) |
| 84 router->OnPasswordExceptionsListChanged(current_exceptions_); | 90 router->OnPasswordExceptionsListChanged(current_exceptions_); |
| 85 } | 91 } |
| 86 | 92 |
| 87 const std::vector<std::string>* GetPasswordExceptionsList() const override { | 93 const std::vector<api::passwords_private::ExceptionPair>* |
| 94 GetPasswordExceptionsList() const override { |
| 88 return ¤t_exceptions_; | 95 return ¤t_exceptions_; |
| 89 } | 96 } |
| 90 | 97 |
| 91 void RemoveSavedPassword( | 98 void RemoveSavedPassword( |
| 92 const std::string& origin_url, const std::string& username) override { | 99 const std::string& origin_url, const std::string& username) override { |
| 93 if (!current_entries_.size()) | 100 if (!current_entries_.size()) |
| 94 return; | 101 return; |
| 95 | 102 |
| 96 // Since this is just mock data, remove the first entry regardless of | 103 // Since this is just mock data, remove the first entry regardless of |
| 97 // the data contained. | 104 // the data contained. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 122 } | 129 } |
| 123 } | 130 } |
| 124 | 131 |
| 125 void SetProfile(Profile* profile) { profile_ = profile; } | 132 void SetProfile(Profile* profile) { profile_ = profile; } |
| 126 | 133 |
| 127 private: | 134 private: |
| 128 // The current list of entries/exceptions. Cached here so that when new | 135 // The current list of entries/exceptions. Cached here so that when new |
| 129 // observers are added, this delegate can send the current lists without | 136 // observers are added, this delegate can send the current lists without |
| 130 // having to request them from |password_manager_presenter_| again. | 137 // having to request them from |password_manager_presenter_| again. |
| 131 std::vector<api::passwords_private::PasswordUiEntry> current_entries_; | 138 std::vector<api::passwords_private::PasswordUiEntry> current_entries_; |
| 132 std::vector<std::string> current_exceptions_; | 139 std::vector<api::passwords_private::ExceptionPair> current_exceptions_; |
| 133 Profile* profile_; | 140 Profile* profile_; |
| 134 }; | 141 }; |
| 135 | 142 |
| 136 class PasswordsPrivateApiTest : public ExtensionApiTest { | 143 class PasswordsPrivateApiTest : public ExtensionApiTest { |
| 137 public: | 144 public: |
| 138 PasswordsPrivateApiTest() { | 145 PasswordsPrivateApiTest() { |
| 139 if (!s_test_delegate_) { | 146 if (!s_test_delegate_) { |
| 140 s_test_delegate_ = new TestDelegate(); | 147 s_test_delegate_ = new TestDelegate(); |
| 141 } | 148 } |
| 142 } | 149 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 203 |
| 197 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetSavedPasswordList) { | 204 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetSavedPasswordList) { |
| 198 EXPECT_TRUE(RunPasswordsSubtest("getSavedPasswordList")) << message_; | 205 EXPECT_TRUE(RunPasswordsSubtest("getSavedPasswordList")) << message_; |
| 199 } | 206 } |
| 200 | 207 |
| 201 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetPasswordExceptionList) { | 208 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetPasswordExceptionList) { |
| 202 EXPECT_TRUE(RunPasswordsSubtest("getPasswordExceptionList")) << message_; | 209 EXPECT_TRUE(RunPasswordsSubtest("getPasswordExceptionList")) << message_; |
| 203 } | 210 } |
| 204 | 211 |
| 205 } // namespace extensions | 212 } // namespace extensions |
| OLD | NEW |