Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: chrome/browser/password_manager/password_form_manager_unittest.cc

Issue 12546016: Remove the Extensions URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: android webview init fix merged in. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/password_manager/password_form_manager.h" 10 #include "chrome/browser/password_manager/password_form_manager.h"
12 #include "chrome/browser/password_manager/password_manager.h" 11 #include "chrome/browser/password_manager/password_manager.h"
13 #include "chrome/browser/password_manager/password_manager_delegate.h" 12 #include "chrome/browser/password_manager/password_manager_delegate.h"
14 #include "chrome/browser/password_manager/password_store.h" 13 #include "chrome/browser/password_manager/password_store.h"
15 #include "chrome/browser/password_manager/password_store_factory.h" 14 #include "chrome/browser/password_manager/password_store_factory.h"
16 #include "chrome/browser/password_manager/test_password_store.h" 15 #include "chrome/browser/password_manager/test_password_store.h"
17 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
19 #include "content/public/common/password_form.h" 18 #include "content/public/common/password_form.h"
19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "content/public/test/test_utils.h" 20 #include "content/public/test/test_utils.h"
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 22
23 using content::PasswordForm; 23 using content::PasswordForm;
24 24
25 using ::testing::Eq; 25 using ::testing::Eq;
26 26
27 namespace { 27 namespace {
28 28
29 class TestPasswordManagerDelegate : public PasswordManagerDelegate { 29 class TestPasswordManagerDelegate : public PasswordManagerDelegate {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 size_t num_sent_messages() { 71 size_t num_sent_messages() {
72 return num_sent_messages_; 72 return num_sent_messages_;
73 } 73 }
74 74
75 private: 75 private:
76 size_t num_sent_messages_; 76 size_t num_sent_messages_;
77 }; 77 };
78 78
79 class PasswordFormManagerTest : public testing::Test { 79 class PasswordFormManagerTest : public testing::Test {
80 public: 80 public:
81 PasswordFormManagerTest() {
82 }
83 virtual void SetUp() { 81 virtual void SetUp() {
84 observed_form_.origin = GURL("http://accounts.google.com/a/LoginAuth"); 82 observed_form_.origin = GURL("http://accounts.google.com/a/LoginAuth");
85 observed_form_.action = GURL("http://accounts.google.com/a/Login"); 83 observed_form_.action = GURL("http://accounts.google.com/a/Login");
86 observed_form_.username_element = ASCIIToUTF16("Email"); 84 observed_form_.username_element = ASCIIToUTF16("Email");
87 observed_form_.password_element = ASCIIToUTF16("Passwd"); 85 observed_form_.password_element = ASCIIToUTF16("Passwd");
88 observed_form_.submit_element = ASCIIToUTF16("signIn"); 86 observed_form_.submit_element = ASCIIToUTF16("signIn");
89 observed_form_.signon_realm = "http://accounts.google.com"; 87 observed_form_.signon_realm = "http://accounts.google.com";
90 88
91 saved_match_ = observed_form_; 89 saved_match_ = observed_form_;
92 saved_match_.origin = GURL("http://accounts.google.com/a/ServiceLoginAuth"); 90 saved_match_.origin = GURL("http://accounts.google.com/a/ServiceLoginAuth");
93 saved_match_.action = GURL("http://accounts.google.com/a/ServiceLogin"); 91 saved_match_.action = GURL("http://accounts.google.com/a/ServiceLogin");
94 saved_match_.preferred = true; 92 saved_match_.preferred = true;
95 saved_match_.username_value = ASCIIToUTF16("test@gmail.com"); 93 saved_match_.username_value = ASCIIToUTF16("test@gmail.com");
96 saved_match_.password_value = ASCIIToUTF16("test1"); 94 saved_match_.password_value = ASCIIToUTF16("test1");
97 saved_match_.other_possible_usernames.push_back( 95 saved_match_.other_possible_usernames.push_back(
98 ASCIIToUTF16("test2@gmail.com")); 96 ASCIIToUTF16("test2@gmail.com"));
99 profile_ = new TestingProfile();
100 }
101
102 virtual void TearDown() {
103 delete profile_;
104 } 97 }
105 98
106 PasswordForm* GetPendingCredentials(PasswordFormManager* p) { 99 PasswordForm* GetPendingCredentials(PasswordFormManager* p) {
107 return &p->pending_credentials_; 100 return &p->pending_credentials_;
108 } 101 }
109 102
110 void SimulateMatchingPhase(PasswordFormManager* p, bool find_match) { 103 void SimulateMatchingPhase(PasswordFormManager* p, bool find_match) {
111 // Roll up the state to mock out the matching phase. 104 // Roll up the state to mock out the matching phase.
112 p->state_ = PasswordFormManager::POST_MATCHING_PHASE; 105 p->state_ = PasswordFormManager::POST_MATCHING_PHASE;
113 if (!find_match) 106 if (!find_match)
(...skipping 20 matching lines...) Expand all
134 } 127 }
135 128
136 void SanitizePossibleUsernames(PasswordFormManager* p, PasswordForm* form) { 129 void SanitizePossibleUsernames(PasswordFormManager* p, PasswordForm* form) {
137 p->SanitizePossibleUsernames(form); 130 p->SanitizePossibleUsernames(form);
138 } 131 }
139 132
140 bool IgnoredResult(PasswordFormManager* p, PasswordForm* form) { 133 bool IgnoredResult(PasswordFormManager* p, PasswordForm* form) {
141 return p->IgnoreResult(*form); 134 return p->IgnoreResult(*form);
142 } 135 }
143 136
144 Profile* profile() { return profile_; } 137 Profile* profile() { return &profile_; }
145 138
146 PasswordForm* observed_form() { return &observed_form_; } 139 PasswordForm* observed_form() { return &observed_form_; }
147 PasswordForm* saved_match() { return &saved_match_; } 140 PasswordForm* saved_match() { return &saved_match_; }
148 PasswordForm* CreateSavedMatch(bool blacklisted) { 141 PasswordForm* CreateSavedMatch(bool blacklisted) {
149 // Owned by the caller of this method. 142 // Owned by the caller of this method.
150 PasswordForm* match = new PasswordForm(saved_match_); 143 PasswordForm* match = new PasswordForm(saved_match_);
151 match->blacklisted_by_user = blacklisted; 144 match->blacklisted_by_user = blacklisted;
152 return match; 145 return match;
153 } 146 }
154 147
155 private: 148 private:
149 content::TestBrowserThreadBundle thread_bundle_;
150 TestingProfile profile_;
156 PasswordForm observed_form_; 151 PasswordForm observed_form_;
157 PasswordForm saved_match_; 152 PasswordForm saved_match_;
158 Profile* profile_;
159 }; 153 };
160 154
161 TEST_F(PasswordFormManagerTest, TestNewLogin) { 155 TEST_F(PasswordFormManagerTest, TestNewLogin) {
162 PasswordFormManager* manager = new PasswordFormManager( 156 PasswordFormManager* manager = new PasswordFormManager(
163 profile(), NULL, NULL, *observed_form(), false); 157 profile(), NULL, NULL, *observed_form(), false);
164 SimulateMatchingPhase(manager, false); 158 SimulateMatchingPhase(manager, false);
165 // User submits credentials for the observed form. 159 // User submits credentials for the observed form.
166 PasswordForm credentials = *observed_form(); 160 PasswordForm credentials = *observed_form();
167 credentials.username_value = saved_match()->username_value; 161 credentials.username_value = saved_match()->username_value;
168 credentials.password_value = saved_match()->password_value; 162 credentials.password_value = saved_match()->password_value;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 login, 324 login,
331 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES); 325 PasswordFormManager::IGNORE_OTHER_POSSIBLE_USERNAMES);
332 EXPECT_TRUE(manager->IsNewLogin()); 326 EXPECT_TRUE(manager->IsNewLogin());
333 // Check that the provisionally saved action URL is the same as the submitted 327 // Check that the provisionally saved action URL is the same as the submitted
334 // action URL, not the one observed on page load. 328 // action URL, not the one observed on page load.
335 EXPECT_EQ(new_action, 329 EXPECT_EQ(new_action,
336 GetPendingCredentials(manager.get())->action); 330 GetPendingCredentials(manager.get())->action);
337 } 331 }
338 332
339 TEST_F(PasswordFormManagerTest, TestAlternateUsername) { 333 TEST_F(PasswordFormManagerTest, TestAlternateUsername) {
340 // Need a MessageLoop for callbacks.
341 base::MessageLoop message_loop;
342 PasswordStoreFactory::GetInstance()->SetTestingFactory( 334 PasswordStoreFactory::GetInstance()->SetTestingFactory(
343 profile(), &TestPasswordStore::Create); 335 profile(), &TestPasswordStore::Create);
344 scoped_refptr<TestPasswordStore> password_store = 336 scoped_refptr<TestPasswordStore> password_store =
345 static_cast<TestPasswordStore*>( 337 static_cast<TestPasswordStore*>(
346 PasswordStoreFactory::GetForProfile(profile(), 338 PasswordStoreFactory::GetForProfile(profile(),
347 Profile::IMPLICIT_ACCESS).get()); 339 Profile::IMPLICIT_ACCESS).get());
348 TestPasswordManagerDelegate delegate(profile()); 340 TestPasswordManagerDelegate delegate(profile());
349 TestPasswordManager password_manager(&delegate); 341 TestPasswordManager password_manager(&delegate);
350 scoped_ptr<TestPasswordFormManager> manager(new TestPasswordFormManager( 342 scoped_ptr<TestPasswordFormManager> manager(new TestPasswordFormManager(
351 profile(), &password_manager, *observed_form(), false)); 343 profile(), &password_manager, *observed_form(), false));
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 533
542 SanitizePossibleUsernames(manager.get(), &credentials); 534 SanitizePossibleUsernames(manager.get(), &credentials);
543 535
544 // SSN, duplicate in |other_possible_usernames| and duplicate of 536 // SSN, duplicate in |other_possible_usernames| and duplicate of
545 // |username_value| all removed. 537 // |username_value| all removed.
546 expected.clear(); 538 expected.clear();
547 expected.push_back(ASCIIToUTF16("duplicate")); 539 expected.push_back(ASCIIToUTF16("duplicate"));
548 expected.push_back(ASCIIToUTF16("random")); 540 expected.push_back(ASCIIToUTF16("random"));
549 EXPECT_THAT(credentials.other_possible_usernames, Eq(expected)); 541 EXPECT_THAT(credentials.other_possible_usernames, Eq(expected));
550 } 542 }
OLDNEW
« no previous file with comments | « chrome/browser/net/cookie_store_util.cc ('k') | chrome/browser/predictors/autocomplete_action_predictor_table_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698