OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/guid.h" |
| 6 #include "base/message_loop/message_loop.h" |
| 7 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.h" |
| 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "components/autofill/core/browser/card_unmask_delegate.h" |
| 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/test/test_utils.h" |
| 14 |
| 15 namespace autofill { |
| 16 |
| 17 namespace { |
| 18 |
| 19 class TestCardUnmaskDelegate : public CardUnmaskDelegate { |
| 20 public: |
| 21 TestCardUnmaskDelegate() : weak_factory_(this) {} |
| 22 |
| 23 virtual ~TestCardUnmaskDelegate() {} |
| 24 |
| 25 // CardUnmaskDelegate implementation. |
| 26 void OnUnmaskResponse(const UnmaskResponse& response) override {} |
| 27 void OnUnmaskPromptClosed() override {} |
| 28 |
| 29 base::WeakPtr<TestCardUnmaskDelegate> GetWeakPtr() { |
| 30 return weak_factory_.GetWeakPtr(); |
| 31 } |
| 32 |
| 33 private: |
| 34 base::WeakPtrFactory<TestCardUnmaskDelegate> weak_factory_; |
| 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskDelegate); |
| 37 }; |
| 38 |
| 39 class TestCardUnmaskPromptController : public CardUnmaskPromptControllerImpl { |
| 40 public: |
| 41 TestCardUnmaskPromptController( |
| 42 content::WebContents* contents, |
| 43 scoped_refptr<content::MessageLoopRunner> runner) |
| 44 : CardUnmaskPromptControllerImpl(contents), |
| 45 runner_(runner), |
| 46 weak_factory_(this) {} |
| 47 |
| 48 // CardUnmaskPromptControllerImpl implementation. |
| 49 void OnDidLoadRiskFingerprint(const std::string& risk_data) override { |
| 50 CardUnmaskPromptControllerImpl::OnDidLoadRiskFingerprint(risk_data); |
| 51 |
| 52 // Call Quit() from here rather than from OnUnmaskDialogClosed(). |
| 53 // FingerprintDataLoader starts several async tasks that take a while to |
| 54 // complete. If Quit() is called before FingerprintDataLoader is all done |
| 55 // then LeakTracker will detect that some resources have not been freed |
| 56 // and cause the browser test to fail. This is not a real leak though - |
| 57 // normally the async tasks would complete and encounter weak callbacks. |
| 58 runner_->Quit(); |
| 59 } |
| 60 |
| 61 void RunMessageLoop() { runner_->Run(); } |
| 62 |
| 63 base::WeakPtr<TestCardUnmaskPromptController> GetWeakPtr() { |
| 64 return weak_factory_.GetWeakPtr(); |
| 65 } |
| 66 |
| 67 private: |
| 68 scoped_refptr<content::MessageLoopRunner> runner_; |
| 69 base::WeakPtrFactory<TestCardUnmaskPromptController> weak_factory_; |
| 70 |
| 71 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController); |
| 72 }; |
| 73 |
| 74 class CardUnmaskPromptViewBrowserTest : public InProcessBrowserTest { |
| 75 public: |
| 76 CardUnmaskPromptViewBrowserTest() : InProcessBrowserTest() {} |
| 77 |
| 78 ~CardUnmaskPromptViewBrowserTest() override {} |
| 79 |
| 80 void SetUpOnMainThread() override { |
| 81 runner_ = new content::MessageLoopRunner; |
| 82 controller_.reset(new TestCardUnmaskPromptController( |
| 83 browser()->tab_strip_model()->GetActiveWebContents(), runner_)); |
| 84 delegate_.reset(new TestCardUnmaskDelegate()); |
| 85 } |
| 86 |
| 87 TestCardUnmaskPromptController* controller() { return controller_.get(); } |
| 88 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } |
| 89 |
| 90 private: |
| 91 // This member must outlive the controller. |
| 92 scoped_refptr<content::MessageLoopRunner> runner_; |
| 93 |
| 94 scoped_ptr<TestCardUnmaskPromptController> controller_; |
| 95 scoped_ptr<TestCardUnmaskDelegate> delegate_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); |
| 98 }; |
| 99 |
| 100 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { |
| 101 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); |
| 102 |
| 103 controller()->ShowPrompt(credit_card, delegate()->GetWeakPtr()); |
| 104 controller()->RunMessageLoop(); |
| 105 } |
| 106 |
| 107 } // namespace |
| 108 |
| 109 } // namespace autofill |
OLD | NEW |