| 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 = "test" + std::to_string(num) + ".com"; |
| 37 ss << "http://test" << num << ".com"; | 37 entry.login_pair.urls.origin = |
| 38 entry.login_pair.origin_url = ss.str(); | 38 "http://" + entry.login_pair.urls.shown + "/login"; |
| 39 ss << "/login"; | 39 entry.login_pair.urls.link = entry.login_pair.urls.origin; |
| 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 = "exception" + std::to_string(num) + ".com"; |
| 51 ss << "http://exception" << num << ".com"; | 48 exception.urls.origin = "http://" + exception.urls.shown + "/login"; |
| 52 exception.exception_url = ss.str(); | 49 exception.urls.link = exception.urls.origin; |
| 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(const std::string& origin, |
| 97 const std::string& origin_url, const std::string& username) override { | 92 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. |
| 103 current_entries_.erase(current_entries_.begin()); | 98 current_entries_.erase(current_entries_.begin()); |
| 104 SendSavedPasswordsList(); | 99 SendSavedPasswordsList(); |
| 105 } | 100 } |
| 106 | 101 |
| 107 void RemovePasswordException(const std::string& exception_url) override { | 102 void RemovePasswordException(const std::string& exception_url) override { |
| 108 if (current_exceptions_.empty()) | 103 if (current_exceptions_.empty()) |
| 109 return; | 104 return; |
| 110 | 105 |
| 111 // Since this is just mock data, remove the first entry regardless of | 106 // Since this is just mock data, remove the first entry regardless of |
| 112 // the data contained. | 107 // the data contained. |
| 113 current_exceptions_.erase(current_exceptions_.begin()); | 108 current_exceptions_.erase(current_exceptions_.begin()); |
| 114 SendPasswordExceptionsList(); | 109 SendPasswordExceptionsList(); |
| 115 } | 110 } |
| 116 | 111 |
| 117 void RequestShowPassword(const std::string& origin_url, | 112 void RequestShowPassword(const std::string& origin, |
| 118 const std::string& username, | 113 const std::string& username, |
| 119 content::WebContents* web_contents) override { | 114 content::WebContents* web_contents) override { |
| 120 // Return a mocked password value. | 115 // Return a mocked password value. |
| 121 std::string plaintext_password(kPlaintextPassword); | 116 std::string plaintext_password(kPlaintextPassword); |
| 122 PasswordsPrivateEventRouter* router = | 117 PasswordsPrivateEventRouter* router = |
| 123 PasswordsPrivateEventRouterFactory::GetForProfile(profile_); | 118 PasswordsPrivateEventRouterFactory::GetForProfile(profile_); |
| 124 if (router) { | 119 if (router) { |
| 125 router->OnPlaintextPasswordFetched(origin_url, username, | 120 router->OnPlaintextPasswordFetched(origin, username, plaintext_password); |
| 126 plaintext_password); | |
| 127 } | 121 } |
| 128 } | 122 } |
| 129 | 123 |
| 130 void SetProfile(Profile* profile) { profile_ = profile; } | 124 void SetProfile(Profile* profile) { profile_ = profile; } |
| 131 | 125 |
| 132 private: | 126 private: |
| 133 // The current list of entries/exceptions. Cached here so that when new | 127 // The current list of entries/exceptions. Cached here so that when new |
| 134 // observers are added, this delegate can send the current lists without | 128 // observers are added, this delegate can send the current lists without |
| 135 // having to request them from |password_manager_presenter_| again. | 129 // having to request them from |password_manager_presenter_| again. |
| 136 std::vector<api::passwords_private::PasswordUiEntry> current_entries_; | 130 std::vector<api::passwords_private::PasswordUiEntry> current_entries_; |
| 137 std::vector<api::passwords_private::ExceptionPair> current_exceptions_; | 131 std::vector<api::passwords_private::ExceptionEntry> current_exceptions_; |
| 138 Profile* profile_; | 132 Profile* profile_; |
| 139 }; | 133 }; |
| 140 | 134 |
| 141 class PasswordsPrivateApiTest : public ExtensionApiTest { | 135 class PasswordsPrivateApiTest : public ExtensionApiTest { |
| 142 public: | 136 public: |
| 143 PasswordsPrivateApiTest() { | 137 PasswordsPrivateApiTest() { |
| 144 if (!s_test_delegate_) { | 138 if (!s_test_delegate_) { |
| 145 s_test_delegate_ = new TestDelegate(); | 139 s_test_delegate_ = new TestDelegate(); |
| 146 } | 140 } |
| 147 } | 141 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 195 |
| 202 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetSavedPasswordList) { | 196 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetSavedPasswordList) { |
| 203 EXPECT_TRUE(RunPasswordsSubtest("getSavedPasswordList")) << message_; | 197 EXPECT_TRUE(RunPasswordsSubtest("getSavedPasswordList")) << message_; |
| 204 } | 198 } |
| 205 | 199 |
| 206 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetPasswordExceptionList) { | 200 IN_PROC_BROWSER_TEST_F(PasswordsPrivateApiTest, GetPasswordExceptionList) { |
| 207 EXPECT_TRUE(RunPasswordsSubtest("getPasswordExceptionList")) << message_; | 201 EXPECT_TRUE(RunPasswordsSubtest("getPasswordExceptionList")) << message_; |
| 208 } | 202 } |
| 209 | 203 |
| 210 } // namespace extensions | 204 } // namespace extensions |
| OLD | NEW |