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