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/autofill/card_unmask_prompt_view_tester.h" | |
9 #include "chrome/browser/ui/browser.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 MockCardUnmaskDelegate : public CardUnmaskDelegate { | |
bondd
2015/02/19 00:17:20
With updated code there were compile errors on OSX
Evan Stade
2015/02/19 00:52:13
yes, agreed. But you shouldn't call this MockCardU
bondd
2015/02/19 01:02:50
Done.
| |
21 public: | |
22 MockCardUnmaskDelegate() : weak_factory_(this) {} | |
23 | |
24 // CardUnmaskDelegate implementation. | |
25 void OnUnmaskResponse(const UnmaskResponse& response) override {} | |
26 void OnUnmaskPromptClosed() override {} | |
27 | |
28 base::WeakPtr<MockCardUnmaskDelegate> GetWeakPtr() { | |
29 return weak_factory_.GetWeakPtr(); | |
30 } | |
31 | |
32 private: | |
33 base::WeakPtrFactory<MockCardUnmaskDelegate> weak_factory_; | |
34 | |
35 DISALLOW_COPY_AND_ASSIGN(MockCardUnmaskDelegate); | |
36 }; | |
37 | |
38 class TestCardUnmaskPromptController : public CardUnmaskPromptControllerImpl { | |
39 public: | |
40 TestCardUnmaskPromptController( | |
41 content::WebContents* contents, | |
42 scoped_refptr<content::MessageLoopRunner> runner) | |
43 : CardUnmaskPromptControllerImpl(contents), runner_(runner) {} | |
44 | |
45 ~TestCardUnmaskPromptController() {} | |
46 | |
47 // CardUnmaskPromptController implementation. | |
48 void OnUnmaskDialogClosed() override { | |
49 CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed(); | |
50 runner_->Quit(); | |
51 } | |
52 | |
53 void RunMessageLoop() { runner_->Run(); } | |
54 | |
55 scoped_ptr<CardUnmaskPromptViewTester> GetViewTester() { | |
56 return CardUnmaskPromptViewTester::For(view()).Pass(); | |
57 } | |
58 | |
59 private: | |
60 scoped_refptr<content::MessageLoopRunner> runner_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController); | |
63 }; | |
64 | |
65 class CardUnmaskPromptViewBrowserTest : public InProcessBrowserTest { | |
66 public: | |
67 CardUnmaskPromptViewBrowserTest() : InProcessBrowserTest() {} | |
68 | |
69 ~CardUnmaskPromptViewBrowserTest() override {} | |
70 | |
71 void SetUpOnMainThread() override { | |
72 runner_ = new content::MessageLoopRunner; | |
73 controller_ = new TestCardUnmaskPromptController( | |
74 browser()->tab_strip_model()->GetActiveWebContents(), runner_); | |
75 } | |
76 | |
77 TestCardUnmaskPromptController* controller() { return controller_; } | |
78 | |
79 private: | |
80 // This member must outlive the controller. | |
81 scoped_refptr<content::MessageLoopRunner> runner_; | |
82 | |
83 // The controller owns itself. | |
84 TestCardUnmaskPromptController* controller_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); | |
87 }; | |
88 | |
89 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { | |
90 CreditCard credit_card(base::GenerateGUID(), "https://www.example.com/"); | |
91 MockCardUnmaskDelegate delegate; | |
92 | |
93 controller()->ShowPrompt(credit_card, delegate.GetWeakPtr()); | |
94 controller()->GetViewTester()->CancelForTesting(); | |
95 | |
96 controller()->RunMessageLoop(); | |
97 } | |
98 | |
99 } // namespace | |
100 | |
101 } // namespace autofill | |
OLD | NEW |