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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 14904002: Load and send Wallet Risk params after user has agreed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 "base/guid.h" 5 #include "base/guid.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" 10 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
11 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" 11 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
12 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/testing_profile.h" 13 #include "chrome/test/base/testing_profile.h"
14 #include "components/autofill/browser/autofill_common_test.h" 14 #include "components/autofill/browser/autofill_common_test.h"
15 #include "components/autofill/browser/autofill_metrics.h" 15 #include "components/autofill/browser/autofill_metrics.h"
16 #include "components/autofill/browser/risk/proto/fingerprint.pb.h"
16 #include "components/autofill/browser/test_personal_data_manager.h" 17 #include "components/autofill/browser/test_personal_data_manager.h"
17 #include "components/autofill/browser/wallet/full_wallet.h" 18 #include "components/autofill/browser/wallet/full_wallet.h"
18 #include "components/autofill/browser/wallet/instrument.h" 19 #include "components/autofill/browser/wallet/instrument.h"
19 #include "components/autofill/browser/wallet/wallet_address.h" 20 #include "components/autofill/browser/wallet/wallet_address.h"
20 #include "components/autofill/browser/wallet/wallet_client.h" 21 #include "components/autofill/browser/wallet/wallet_client.h"
21 #include "components/autofill/browser/wallet/wallet_test_util.h" 22 #include "components/autofill/browser/wallet/wallet_test_util.h"
22 #include "components/autofill/common/form_data.h" 23 #include "components/autofill/common/form_data.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "content/public/test/test_browser_thread.h" 25 #include "content/public/test/test_browser_thread.h"
25 #include "content/public/test/web_contents_tester.h" 26 #include "content/public/test/web_contents_tester.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 } 173 }
173 174
174 TestPersonalDataManager* GetTestingManager() { 175 TestPersonalDataManager* GetTestingManager() {
175 return &test_manager_; 176 return &test_manager_;
176 } 177 }
177 178
178 TestWalletClient* GetTestingWalletClient() { 179 TestWalletClient* GetTestingWalletClient() {
179 return &test_wallet_client_; 180 return &test_wallet_client_;
180 } 181 }
181 182
183 MOCK_METHOD0(LoadRiskFingerprintData, void());
184
182 void set_is_first_run(bool is_first_run) { is_first_run_ = is_first_run; } 185 void set_is_first_run(bool is_first_run) { is_first_run_ = is_first_run; }
186 void set_fingerprint_data(std::string fingerprint_data) {
Ilya Sherman 2013/05/03 07:38:31 nit: Pass by const-reference.
Dan Beam 2013/05/03 23:02:40 Done.
187 fingerprint_data_ = fingerprint_data;
188 }
183 189
184 protected: 190 protected:
185 virtual PersonalDataManager* GetManager() OVERRIDE { 191 virtual PersonalDataManager* GetManager() OVERRIDE {
186 return &test_manager_; 192 return &test_manager_;
187 } 193 }
188 194
189 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { 195 virtual wallet::WalletClient* GetWalletClient() OVERRIDE {
190 return &test_wallet_client_; 196 return &test_wallet_client_;
191 } 197 }
192 198
193 virtual bool IsFirstRun() const OVERRIDE { 199 virtual bool IsFirstRun() const OVERRIDE {
194 return is_first_run_; 200 return is_first_run_;
195 } 201 }
196 202
203 virtual void SerializeFingerprint(risk::Fingerprint* fingerprint,
204 std::string* data) {
205 // Ignore |fingerprint|, it's NULL.
Ilya Sherman 2013/05/03 07:38:31 Why? It seems much better not to override this me
Dan Beam 2013/05/03 09:24:47 If it's obvious what the base64 encoded expected t
Ilya Sherman 2013/05/07 00:59:30 It's pretty easy to encode the data and DLOG what
Dan Beam 2013/05/07 05:02:38 Done.
206 data->assign(fingerprint_data_);
207 }
208
197 private: 209 private:
198 // To specify our own metric logger. 210 // To specify our own metric logger.
199 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { 211 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
200 return metric_logger_; 212 return metric_logger_;
201 } 213 }
202 214
203 const AutofillMetrics& metric_logger_; 215 const AutofillMetrics& metric_logger_;
204 TestPersonalDataManager test_manager_; 216 TestPersonalDataManager test_manager_;
205 testing::NiceMock<TestWalletClient> test_wallet_client_; 217 testing::NiceMock<TestWalletClient> test_wallet_client_;
206 bool is_first_run_; 218 bool is_first_run_;
219 std::string fingerprint_data_;
207 220
208 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); 221 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
209 }; 222 };
210 223
211 class AutofillDialogControllerTest : public testing::Test { 224 class AutofillDialogControllerTest : public testing::Test {
212 public: 225 public:
213 AutofillDialogControllerTest() 226 AutofillDialogControllerTest()
214 : ui_thread_(BrowserThread::UI, &loop_), 227 : ui_thread_(BrowserThread::UI, &loop_),
215 file_thread_(BrowserThread::FILE), 228 file_thread_(BrowserThread::FILE),
216 file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING), 229 file_blocking_thread_(BrowserThread::FILE_USER_BLOCKING),
(...skipping 14 matching lines...) Expand all
231 form_data.fields.push_back(field); 244 form_data.fields.push_back(field);
232 } 245 }
233 246
234 profile()->CreateRequestContext(); 247 profile()->CreateRequestContext();
235 test_web_contents_.reset( 248 test_web_contents_.reset(
236 content::WebContentsTester::CreateTestWebContents(profile(), NULL)); 249 content::WebContentsTester::CreateTestWebContents(profile(), NULL));
237 250
238 base::Callback<void(const FormStructure*, const std::string&)> callback = 251 base::Callback<void(const FormStructure*, const std::string&)> callback =
239 base::Bind(&AutofillDialogControllerTest::FinishedCallback, 252 base::Bind(&AutofillDialogControllerTest::FinishedCallback,
240 base::Unretained(this)); 253 base::Unretained(this));
241 controller_ = (new TestAutofillDialogController( 254 controller_ = (new testing::NiceMock<TestAutofillDialogController>(
242 test_web_contents_.get(), 255 test_web_contents_.get(),
243 form_data, 256 form_data,
244 GURL(), 257 GURL(),
245 metric_logger_, 258 metric_logger_,
246 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, 259 DIALOG_TYPE_REQUEST_AUTOCOMPLETE,
247 callback))->AsWeakPtr(); 260 callback))->AsWeakPtr();
248 controller_->Init(profile()); 261 controller_->Init(profile());
249 controller_->Show(); 262 controller_->Show();
250 controller_->OnUserNameFetchSuccess(kFakeEmail); 263 controller_->OnUserNameFetchSuccess(kFakeEmail);
251 } 264 }
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 controller()->EditCancelledForSection(SECTION_EMAIL); 948 controller()->EditCancelledForSection(SECTION_EMAIL);
936 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 949 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
937 950
938 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1); 951 controller()->MenuModelForSection(SECTION_EMAIL)->ActivatedAt(1);
939 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome()); 952 EXPECT_TRUE(controller()->ShouldOfferToSaveInChrome());
940 953
941 profile()->set_incognito(true); 954 profile()->set_incognito(true);
942 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome()); 955 EXPECT_FALSE(controller()->ShouldOfferToSaveInChrome());
943 } 956 }
944 957
958 TEST_F(AutofillDialogControllerTest, RiskRespectsLegalDocs) {
959 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(0);
960
961 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
962 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
963 controller()->OnDidGetWalletItems(wallet_items.Pass());
964
965 EXPECT_EQ("risky business", controller()->GetRiskData());
966 }
967
968 TEST_F(AutofillDialogControllerTest, LoadRiskWhenNoLegalDocs) {
969 EXPECT_CALL(*controller(), LoadRiskFingerprintData()).Times(1);
970
971 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
972 wallet_items->AddLegalDocument(wallet::GetTestLegalDocument());
973 controller()->OnDidGetWalletItems(wallet_items.Pass());
974 controller()->OnDidAcceptLegalDocuments();
975
976 // No OnRiskFingerprintDataLoaded() has happened yet.
977 EXPECT_EQ("risky business", controller()->GetRiskData());
978
979 scoped_ptr<risk::Fingerprint> fake_fingerprint;
980
981 controller()->set_fingerprint_data("hello");
982 controller()->OnDidLoadRiskFingerprintData(fake_fingerprint.Pass());
983 EXPECT_EQ("aGVsbG8=", controller()->GetRiskData());
984 }
985
945 } // namespace autofill 986 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698