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 #import "chrome/browser/ui/cocoa/autofill/card_unmask_prompt_bridge.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "components/autofill/core/browser/card_unmask_delegate.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/test/test_utils.h" |
| 15 |
| 16 namespace autofill { |
| 17 |
| 18 namespace { |
| 19 |
| 20 class TestCardUnmaskPromptController : public CardUnmaskPromptControllerImpl, |
| 21 public CardUnmaskDelegate { |
| 22 public: |
| 23 TestCardUnmaskPromptController( |
| 24 content::WebContents* contents, |
| 25 scoped_refptr<content::MessageLoopRunner> runner) |
| 26 : CardUnmaskPromptControllerImpl(contents), |
| 27 runner_(runner), |
| 28 weak_factory_(this) {} |
| 29 |
| 30 ~TestCardUnmaskPromptController() {} |
| 31 |
| 32 // CardUnmaskPromptController implementation. |
| 33 void OnUnmaskDialogClosed() override { |
| 34 CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed(); |
| 35 runner_->Quit(); |
| 36 } |
| 37 |
| 38 // CardUnmaskDelegate implementation. |
| 39 void OnUnmaskResponse(const base::string16& cvc, |
| 40 const base::string16& exp_month, |
| 41 const base::string16& exp_year) override {} |
| 42 void OnUnmaskPromptClosed() override {} |
| 43 |
| 44 void RunMessageLoop() { |
| 45 runner_->Run(); |
| 46 } |
| 47 |
| 48 base::WeakPtr<TestCardUnmaskPromptController> GetWeakPtr() { |
| 49 return weak_factory_.GetWeakPtr(); |
| 50 } |
| 51 |
| 52 // Increase visibility for testing. |
| 53 CardUnmaskPromptView* view() { |
| 54 return CardUnmaskPromptControllerImpl::view(); |
| 55 } |
| 56 |
| 57 private: |
| 58 scoped_refptr<content::MessageLoopRunner> runner_; |
| 59 base::WeakPtrFactory<TestCardUnmaskPromptController> weak_factory_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController); |
| 62 }; |
| 63 |
| 64 class CardUnmaskPromptCocoaBrowserTest : public InProcessBrowserTest { |
| 65 public: |
| 66 CardUnmaskPromptCocoaBrowserTest() : InProcessBrowserTest() {} |
| 67 |
| 68 ~CardUnmaskPromptCocoaBrowserTest() override {} |
| 69 |
| 70 void SetUpOnMainThread() override { |
| 71 runner_ = new content::MessageLoopRunner; |
| 72 controller_ = new TestCardUnmaskPromptController( |
| 73 browser()->tab_strip_model()->GetActiveWebContents(), runner_); |
| 74 } |
| 75 |
| 76 TestCardUnmaskPromptController* controller() { return controller_; } |
| 77 |
| 78 private: |
| 79 // This member must outlive the controller. |
| 80 scoped_refptr<content::MessageLoopRunner> runner_; |
| 81 |
| 82 // The controller owns itself. |
| 83 TestCardUnmaskPromptController* controller_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptCocoaBrowserTest); |
| 86 }; |
| 87 |
| 88 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptCocoaBrowserTest, DisplayUI) { |
| 89 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); |
| 90 |
| 91 controller()->ShowPrompt(credit_card, controller()->GetWeakPtr()); |
| 92 controller()->view()->CancelForTesting(); |
| 93 |
| 94 controller()->RunMessageLoop(); |
| 95 } |
| 96 |
| 97 } // namespace |
| 98 |
| 99 } // namespace autofill |
OLD | NEW |