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

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

Issue 1011503004: Autofill card unmasking - never store locally in incognito (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.h" 5 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 }; 57 };
58 58
59 class TestCardUnmaskPromptController : public CardUnmaskPromptControllerImpl { 59 class TestCardUnmaskPromptController : public CardUnmaskPromptControllerImpl {
60 public: 60 public:
61 TestCardUnmaskPromptController( 61 TestCardUnmaskPromptController(
62 content::WebContents* contents, 62 content::WebContents* contents,
63 TestCardUnmaskPromptView* test_unmask_prompt_view, 63 TestCardUnmaskPromptView* test_unmask_prompt_view,
64 scoped_refptr<content::MessageLoopRunner> runner) 64 scoped_refptr<content::MessageLoopRunner> runner)
65 : CardUnmaskPromptControllerImpl(contents), 65 : CardUnmaskPromptControllerImpl(contents),
66 test_unmask_prompt_view_(test_unmask_prompt_view), 66 test_unmask_prompt_view_(test_unmask_prompt_view),
67 can_store_locally_(true),
67 runner_(runner), 68 runner_(runner),
68 weak_factory_(this) {} 69 weak_factory_(this) {}
69 70
70 CardUnmaskPromptView* CreateAndShowView() override { 71 CardUnmaskPromptView* CreateAndShowView() override {
71 return test_unmask_prompt_view_; 72 return test_unmask_prompt_view_;
72 } 73 }
73 void LoadRiskFingerprint() override {} 74 void LoadRiskFingerprint() override {}
75 bool CanStoreLocally() const override { return can_store_locally_; }
76
77 void set_can_store_locally(bool can) { can_store_locally_ = can; }
74 78
75 base::WeakPtr<TestCardUnmaskPromptController> GetWeakPtr() { 79 base::WeakPtr<TestCardUnmaskPromptController> GetWeakPtr() {
76 return weak_factory_.GetWeakPtr(); 80 return weak_factory_.GetWeakPtr();
77 } 81 }
78 82
79 private: 83 private:
80 TestCardUnmaskPromptView* test_unmask_prompt_view_; 84 TestCardUnmaskPromptView* test_unmask_prompt_view_;
85 bool can_store_locally_;
81 scoped_refptr<content::MessageLoopRunner> runner_; 86 scoped_refptr<content::MessageLoopRunner> runner_;
82 base::WeakPtrFactory<TestCardUnmaskPromptController> weak_factory_; 87 base::WeakPtrFactory<TestCardUnmaskPromptController> weak_factory_;
83 88
84 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController); 89 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController);
85 }; 90 };
86 91
87 class CardUnmaskPromptControllerImplTest 92 class CardUnmaskPromptControllerImplTest
88 : public ChromeRenderViewHostTestHarness { 93 : public ChromeRenderViewHostTestHarness {
89 public: 94 public:
90 CardUnmaskPromptControllerImplTest() {} 95 CardUnmaskPromptControllerImplTest() {}
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 base::ASCIIToUTF16("01"), 294 base::ASCIIToUTF16("01"),
290 base::ASCIIToUTF16("2015"), 295 base::ASCIIToUTF16("2015"),
291 true /* should_store_pan */); 296 true /* should_store_pan */);
292 controller()->OnUnmaskDialogClosed(); 297 controller()->OnUnmaskDialogClosed();
293 298
294 histogram_tester.ExpectBucketCount( 299 histogram_tester.ExpectBucketCount(
295 "Autofill.UnmaskPrompt.Events", 300 "Autofill.UnmaskPrompt.Events",
296 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_OUT, 1); 301 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_OUT, 1);
297 } 302 }
298 303
304 TEST_F(CardUnmaskPromptControllerImplTest, DontLogForHiddenCheckbox) {
305 controller()->set_can_store_locally(false);
306 controller()->ShowPrompt(CreateCard(), delegate()->GetWeakPtr());
307 base::HistogramTester histogram_tester;
308
309 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"),
310 base::ASCIIToUTF16("01"),
311 base::ASCIIToUTF16("2015"),
312 false /* should_store_pan */);
313 controller()->OnUnmaskDialogClosed();
314
315 histogram_tester.ExpectBucketCount(
316 "Autofill.UnmaskPrompt.Events",
317 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_IN, 0);
318 histogram_tester.ExpectBucketCount(
319 "Autofill.UnmaskPrompt.Events",
320 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_IN, 0);
321 histogram_tester.ExpectBucketCount(
322 "Autofill.UnmaskPrompt.Events",
323 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_OPT_OUT, 0);
324 histogram_tester.ExpectBucketCount(
325 "Autofill.UnmaskPrompt.Events",
326 AutofillMetrics::UNMASK_PROMPT_LOCAL_SAVE_DID_NOT_OPT_OUT, 0);
327 }
328
299 TEST_F(CardUnmaskPromptControllerImplTest, LogRealPanResultSuccess) { 329 TEST_F(CardUnmaskPromptControllerImplTest, LogRealPanResultSuccess) {
300 controller()->ShowPrompt(CreateCard(), delegate()->GetWeakPtr()); 330 controller()->ShowPrompt(CreateCard(), delegate()->GetWeakPtr());
301 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), 331 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"),
302 base::ASCIIToUTF16("01"), 332 base::ASCIIToUTF16("01"),
303 base::ASCIIToUTF16("2015"), 333 base::ASCIIToUTF16("2015"),
304 false /* should_store_pan */); 334 false /* should_store_pan */);
305 base::HistogramTester histogram_tester; 335 base::HistogramTester histogram_tester;
306 336
307 controller()->OnVerificationResult(AutofillClient::SUCCESS); 337 controller()->OnVerificationResult(AutofillClient::SUCCESS);
308 338
(...skipping 11 matching lines...) Expand all
320 base::HistogramTester histogram_tester; 350 base::HistogramTester histogram_tester;
321 351
322 controller()->OnVerificationResult(AutofillClient::TRY_AGAIN_FAILURE); 352 controller()->OnVerificationResult(AutofillClient::TRY_AGAIN_FAILURE);
323 353
324 histogram_tester.ExpectBucketCount( 354 histogram_tester.ExpectBucketCount(
325 "Autofill.UnmaskPrompt.GetRealPanResult", 355 "Autofill.UnmaskPrompt.GetRealPanResult",
326 AutofillMetrics::GET_REAL_PAN_RESULT_TRY_AGAIN_FAILURE, 1); 356 AutofillMetrics::GET_REAL_PAN_RESULT_TRY_AGAIN_FAILURE, 1);
327 } 357 }
328 358
329 } // namespace autofill 359 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698