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, | |
groby-ooo-7-16
2015/02/12 00:51:55
Can this be shared with Views tests?
bondd
2015/02/12 19:07:22
Yes I think it can. I was planning to do that as a
| |
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 DCHECK(runner_); | |
35 CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed(); | |
36 runner_->Quit(); | |
37 } | |
38 | |
39 // CardUnmaskDelegate implementation. | |
40 void OnUnmaskResponse(const base::string16& cvc, | |
41 const base::string16& exp_month, | |
42 const base::string16& exp_year) override {} | |
43 void OnUnmaskPromptClosed() override {} | |
44 | |
45 void RunMessageLoop() { | |
46 DCHECK(runner_); | |
47 runner_->Run(); | |
48 } | |
49 | |
50 base::WeakPtr<TestCardUnmaskPromptController> GetWeakPtr() { | |
51 return weak_factory_.GetWeakPtr(); | |
52 } | |
53 | |
54 // Increase visibility for testing. | |
55 CardUnmaskPromptView* view() { | |
56 return CardUnmaskPromptControllerImpl::view(); | |
57 } | |
58 | |
59 private: | |
60 scoped_refptr<content::MessageLoopRunner> runner_; | |
61 base::WeakPtrFactory<TestCardUnmaskPromptController> weak_factory_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController); | |
64 }; | |
65 | |
66 class CardUnmaskPromptCocoaBrowserTest : public InProcessBrowserTest { | |
67 public: | |
68 CardUnmaskPromptCocoaBrowserTest() : InProcessBrowserTest() {} | |
69 | |
70 ~CardUnmaskPromptCocoaBrowserTest() override {} | |
71 | |
72 void SetUpOnMainThread() override { | |
73 runner_ = new content::MessageLoopRunner; | |
74 controller_ = new TestCardUnmaskPromptController( | |
75 browser()->tab_strip_model()->GetActiveWebContents(), runner_); | |
76 } | |
77 | |
78 TestCardUnmaskPromptController* controller() { return controller_; } | |
79 | |
80 private: | |
81 // The controller owns itself. | |
82 TestCardUnmaskPromptController* controller_; | |
83 | |
84 // This member must outlive the controller. | |
85 scoped_refptr<content::MessageLoopRunner> runner_; | |
groby-ooo-7-16
2015/02/12 00:51:56
If it must outlive the controller, it might be bet
bondd
2015/02/12 19:07:22
Done. Thanks!
| |
86 | |
87 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptCocoaBrowserTest); | |
88 }; | |
89 | |
90 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptCocoaBrowserTest, DisplayUI) { | |
91 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); | |
92 | |
93 controller()->ShowPrompt(credit_card, controller()->GetWeakPtr()); | |
94 controller()->view()->CancelForTesting(); | |
95 | |
96 controller()->RunMessageLoop(); | |
97 } | |
98 | |
99 } // namespace | |
100 | |
101 } // namespace autofill | |
OLD | NEW |