OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/command_line.h" | 5 #include "base/command_line.h" |
6 | 6 |
7 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 7 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
8 | 8 |
9 #include "chrome/common/chrome_version_info.h" | 9 #include "chrome/common/chrome_version_info.h" |
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 const char kTestText[] = "abcd1234"; | 28 const char kTestText[] = "abcd1234"; |
29 | 29 |
30 class MockLogReceiver : public password_manager::LogReceiver { | 30 class MockLogReceiver : public password_manager::LogReceiver { |
31 public: | 31 public: |
32 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); | 32 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
33 }; | 33 }; |
34 | 34 |
35 class TestChromePasswordManagerClient : public ChromePasswordManagerClient { | |
36 public: | |
37 explicit TestChromePasswordManagerClient(content::WebContents* web_contents) | |
38 : ChromePasswordManagerClient(web_contents, NULL), | |
39 is_sync_account_credential_(false) {} | |
40 virtual ~TestChromePasswordManagerClient() {} | |
41 | |
42 virtual bool IsSyncAccountCredential( | |
43 const std::string& username, | |
44 const std::string& origin) const OVERRIDE { | |
45 return is_sync_account_credential_; | |
46 } | |
47 | |
48 void set_is_sync_account_credential(bool is_sync_account_credential) { | |
49 is_sync_account_credential_ = is_sync_account_credential; | |
50 } | |
51 | |
52 private: | |
53 bool is_sync_account_credential_; | |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(TestChromePasswordManagerClient); | |
56 }; | |
57 | |
35 } // namespace | 58 } // namespace |
36 | 59 |
37 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { | 60 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { |
38 public: | 61 public: |
39 ChromePasswordManagerClientTest(); | 62 ChromePasswordManagerClientTest(); |
40 | 63 |
41 virtual void SetUp() OVERRIDE; | 64 virtual void SetUp() OVERRIDE; |
42 | 65 |
43 protected: | 66 protected: |
44 ChromePasswordManagerClient* GetClient(); | 67 ChromePasswordManagerClient* GetClient(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 ChromePasswordManagerClient* client = GetClient(); | 208 ChromePasswordManagerClient* client = GetClient(); |
186 service_->RegisterReceiver(&receiver_); | 209 service_->RegisterReceiver(&receiver_); |
187 EXPECT_TRUE(client->IsLoggingActive()); | 210 EXPECT_TRUE(client->IsLoggingActive()); |
188 | 211 |
189 EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(1); | 212 EXPECT_CALL(receiver_, LogSavePasswordProgress(kTestText)).Times(1); |
190 client->LogSavePasswordProgress(kTestText); | 213 client->LogSavePasswordProgress(kTestText); |
191 | 214 |
192 service_->UnregisterReceiver(&receiver_); | 215 service_->UnregisterReceiver(&receiver_); |
193 EXPECT_FALSE(client->IsLoggingActive()); | 216 EXPECT_FALSE(client->IsLoggingActive()); |
194 } | 217 } |
218 | |
219 TEST_F(ChromePasswordManagerClientTest, ShouldFilterAutofillResult_Reauth) { | |
220 // Make client disallow only reauth requests. | |
221 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
222 command_line->AppendSwitch( | |
223 password_manager::switches::kDisallowAutofillSyncCredentialForReauth); | |
224 scoped_ptr<TestChromePasswordManagerClient> client( | |
225 new TestChromePasswordManagerClient(web_contents())); | |
226 autofill::PasswordForm form; | |
227 | |
228 client->set_is_sync_account_credential(false); | |
229 NavigateAndCommit( | |
230 GURL("https://accounts.google.com/login?rart=123&continue=blah")); | |
231 EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); | |
232 | |
233 client->set_is_sync_account_credential(true); | |
234 NavigateAndCommit( | |
235 GURL("https://accounts.google.com/login?rart=123&continue=blah")); | |
236 EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); | |
237 | |
238 // This counts as a reauth url, though a valid URL should have a value for | |
239 // "rart" | |
240 NavigateAndCommit(GURL("https://accounts.google.com/addlogin?rart")); | |
241 EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); | |
242 | |
243 NavigateAndCommit(GURL("https://accounts.google.com/login?param=123")); | |
244 EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); | |
245 | |
246 NavigateAndCommit(GURL("https://site.com/login?rart=678")); | |
247 EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); | |
248 } | |
249 | |
250 TEST_F(ChromePasswordManagerClientTest, ShouldFilterAutofillResult) { | |
251 // Normally the client should allow any credentials through, even if they | |
252 // are the sync credential. | |
253 scoped_ptr<TestChromePasswordManagerClient> client( | |
254 new TestChromePasswordManagerClient(web_contents())); | |
255 autofill::PasswordForm form; | |
256 client->set_is_sync_account_credential(true); | |
257 NavigateAndCommit(GURL("https://accounts.google.com/Login")); | |
258 EXPECT_FALSE(client->ShouldFilterAutofillResult(form)); | |
259 | |
260 // | |
Ilya Sherman
2014/08/14 07:38:14
nit: ^^^
Garrett Casto
2014/08/14 19:48:43
Filled out the comment I meant to leave.
| |
261 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
262 command_line->AppendSwitch( | |
263 password_manager::switches::kDisallowAutofillSyncCredential); | |
264 client.reset(new TestChromePasswordManagerClient(web_contents())); | |
265 client->set_is_sync_account_credential(true); | |
266 NavigateAndCommit(GURL("https://accounts.google.com/Login")); | |
267 EXPECT_TRUE(client->ShouldFilterAutofillResult(form)); | |
268 } | |
OLD | NEW |