OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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/macros.h" | |
6 #include "base/memory/ptr_util.h" | |
7 #include "chrome/browser/ui/browser.h" | |
8 #include "chrome/browser/ui/external_protocol_dialog_delegate.h" | |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
10 #include "chrome/browser/ui/views/external_protocol_dialog.h" | |
11 #include "chrome/test/base/in_process_browser_test.h" | |
12 #include "content/public/browser/render_process_host.h" | |
13 #include "content/public/browser/render_view_host.h" | |
14 #include "content/public/browser/web_contents.h" | |
15 #include "ui/views/controls/message_box_view.h" | |
16 #include "url/gurl.h" | |
17 | |
18 namespace test { | |
19 | |
20 class ExternalProtocolDialogTestApi { | |
21 public: | |
22 explicit ExternalProtocolDialogTestApi(ExternalProtocolDialog* dialog) | |
23 : dialog_(dialog) {} | |
24 | |
25 void SetCheckBoxSelected(bool checked) { | |
26 dialog_->message_box_view_->SetCheckBoxSelected(checked); | |
27 } | |
28 | |
29 private: | |
30 ExternalProtocolDialog* dialog_; | |
31 }; | |
msw
2017/01/05 01:32:16
nit: DISALLOW_COPY_AND_ASSIGN
dominickn
2017/01/05 02:00:50
Done.
| |
32 | |
33 } // namespace test | |
34 | |
35 class TestExternalProtocolDialogDelegate | |
msw
2017/01/05 01:32:16
nit: add a short comment?
dominickn
2017/01/05 02:00:50
Done.
| |
36 : public ExternalProtocolDialogDelegate { | |
37 public: | |
38 TestExternalProtocolDialogDelegate(const GURL& url, | |
39 int render_process_host_id, | |
40 int routing_id, | |
41 bool* called, | |
42 bool* accept, | |
43 bool* dont_block) | |
44 : ExternalProtocolDialogDelegate(url, render_process_host_id, routing_id), | |
45 called_(called), | |
46 accept_(accept), | |
47 dont_block_(dont_block) {} | |
48 | |
49 // ExternalProtocolDialogDelegate: | |
50 void DoAccept(const GURL& url, bool dont_block) const override { | |
msw
2017/01/05 01:32:16
q: Should these overrides call the base class impl
dominickn
2017/01/05 02:00:50
It's not really important because this test is des
msw
2017/01/05 15:57:53
Acknowledged.
| |
51 *called_ = true; | |
52 *accept_ = true; | |
53 *dont_block_ = dont_block; | |
54 } | |
55 | |
56 void DoCancel(const GURL& url, bool dont_block) const override { | |
57 *called_ = true; | |
58 *accept_ = false; | |
59 *dont_block_ = dont_block; | |
60 } | |
61 | |
62 private: | |
63 bool* called_; | |
64 bool* accept_; | |
65 bool* dont_block_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(TestExternalProtocolDialogDelegate); | |
68 }; | |
69 | |
70 class ExternalProtocolDialogBrowserTest : public InProcessBrowserTest { | |
71 public: | |
72 ExternalProtocolDialogBrowserTest() {} | |
73 | |
74 void ShowDialog() { | |
75 content::WebContents* web_contents = | |
76 browser()->tab_strip_model()->GetActiveWebContents(); | |
77 int render_process_host_id = web_contents->GetRenderProcessHost()->GetID(); | |
78 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID(); | |
79 dialog_ = new ExternalProtocolDialog( | |
80 base::MakeUnique<TestExternalProtocolDialogDelegate>( | |
81 GURL("https://www.google.com"), render_process_host_id, routing_id, | |
82 &called_, &accept_, &dont_block_), | |
83 render_process_host_id, routing_id); | |
84 } | |
85 | |
86 void SetChecked(bool checked) { | |
87 test::ExternalProtocolDialogTestApi(dialog_).SetCheckBoxSelected(checked); | |
88 } | |
89 | |
90 protected: | |
91 ExternalProtocolDialog* dialog_ = nullptr; | |
92 bool called_ = false; | |
93 bool accept_ = false; | |
94 bool dont_block_ = false; | |
95 | |
96 private: | |
97 DISALLOW_COPY_AND_ASSIGN(ExternalProtocolDialogBrowserTest); | |
98 }; | |
99 | |
100 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestAccept) { | |
101 ShowDialog(); | |
102 EXPECT_TRUE(dialog_->Accept()); | |
103 EXPECT_TRUE(called_); | |
104 EXPECT_TRUE(accept_); | |
105 EXPECT_FALSE(dont_block_); | |
106 } | |
107 | |
108 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, | |
109 TestAcceptWithChecked) { | |
110 ShowDialog(); | |
111 SetChecked(true); | |
112 EXPECT_TRUE(dialog_->Accept()); | |
113 EXPECT_TRUE(called_); | |
114 EXPECT_TRUE(accept_); | |
115 EXPECT_TRUE(dont_block_); | |
116 } | |
117 | |
118 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestCancel) { | |
msw
2017/01/05 01:32:15
It seems like we should have an explicit flag for
dominickn
2017/01/05 02:00:50
Close() is overridden to call DoCancel() (see crre
msw
2017/01/05 15:57:53
Ack. I still suggest testing for |cancel|
| |
119 ShowDialog(); | |
120 EXPECT_TRUE(dialog_->Cancel()); | |
121 EXPECT_TRUE(called_); | |
122 EXPECT_FALSE(accept_); | |
123 EXPECT_FALSE(dont_block_); | |
124 } | |
125 | |
126 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, | |
127 TestCancelWithChecked) { | |
128 ShowDialog(); | |
129 SetChecked(true); | |
130 EXPECT_TRUE(dialog_->Cancel()); | |
131 EXPECT_TRUE(called_); | |
132 EXPECT_FALSE(accept_); | |
133 EXPECT_TRUE(dont_block_); | |
134 } | |
135 | |
136 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestClose) { | |
137 ShowDialog(); | |
138 EXPECT_TRUE(dialog_->Close()); | |
139 EXPECT_TRUE(called_); | |
140 EXPECT_FALSE(accept_); | |
141 EXPECT_FALSE(dont_block_); | |
142 } | |
143 | |
144 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, | |
145 TestCloseWithChecked) { | |
146 ShowDialog(); | |
147 SetChecked(true); | |
148 EXPECT_TRUE(dialog_->Close()); | |
149 EXPECT_TRUE(called_); | |
150 EXPECT_FALSE(accept_); | |
151 EXPECT_FALSE(dont_block_); | |
152 } | |
OLD | NEW |