Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/browser/ui/views/external_protocol_dialog_browsertest.cc

Issue 2610793002: Add a browser test for the views external protocol dialog. (Closed)
Patch Set: Address nit Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/external_protocol_dialog.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
32 DISALLOW_COPY_AND_ASSIGN(ExternalProtocolDialogTestApi);
33 };
34
35 } // namespace test
36
37 // Wrapper dialog delegate that sets |called|, |accept|, |cancel|, and
38 // |dont_block| bools based on what is called by the ExternalProtocolDialog.
39 class TestExternalProtocolDialogDelegate
40 : public ExternalProtocolDialogDelegate {
41 public:
42 TestExternalProtocolDialogDelegate(const GURL& url,
43 int render_process_host_id,
44 int routing_id,
45 bool* called,
46 bool* accept,
47 bool* cancel,
48 bool* dont_block)
49 : ExternalProtocolDialogDelegate(url, render_process_host_id, routing_id),
50 called_(called),
51 accept_(accept),
52 cancel_(cancel),
53 dont_block_(dont_block) {}
54
55 // ExternalProtocolDialogDelegate:
56 void DoAccept(const GURL& url, bool dont_block) const override {
57 // Don't call the base impl because it will actually launch |url|.
58 *called_ = true;
59 *accept_ = true;
60 *cancel_ = false;
61 *dont_block_ = dont_block;
62 }
63
64 void DoCancel(const GURL& url, bool dont_block) const override {
65 // Don't call the base impl because it will actually launch |url|.
66 *called_ = true;
67 *accept_ = false;
68 *cancel_ = true;
69 *dont_block_ = dont_block;
70 }
71
72 private:
73 bool* called_;
74 bool* accept_;
75 bool* cancel_;
76 bool* dont_block_;
77
78 DISALLOW_COPY_AND_ASSIGN(TestExternalProtocolDialogDelegate);
79 };
80
81 class ExternalProtocolDialogBrowserTest : public InProcessBrowserTest {
82 public:
83 ExternalProtocolDialogBrowserTest() {}
84
85 void ShowDialog() {
86 content::WebContents* web_contents =
87 browser()->tab_strip_model()->GetActiveWebContents();
88 int render_process_host_id = web_contents->GetRenderProcessHost()->GetID();
89 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID();
90 dialog_ = new ExternalProtocolDialog(
91 base::MakeUnique<TestExternalProtocolDialogDelegate>(
92 GURL("telnet://12345"), render_process_host_id, routing_id,
93 &called_, &accept_, &cancel_, &dont_block_),
94 render_process_host_id, routing_id);
95 }
96
97 void SetChecked(bool checked) {
98 test::ExternalProtocolDialogTestApi(dialog_).SetCheckBoxSelected(checked);
99 }
100
101 protected:
102 ExternalProtocolDialog* dialog_ = nullptr;
103 bool called_ = false;
104 bool accept_ = false;
105 bool cancel_ = false;
106 bool dont_block_ = false;
107
108 private:
109 DISALLOW_COPY_AND_ASSIGN(ExternalProtocolDialogBrowserTest);
110 };
111
112 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestAccept) {
113 ShowDialog();
114 EXPECT_TRUE(dialog_->Accept());
115 EXPECT_TRUE(called_);
116 EXPECT_TRUE(accept_);
117 EXPECT_FALSE(cancel_);
118 EXPECT_FALSE(dont_block_);
119 }
120
121 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
122 TestAcceptWithChecked) {
123 ShowDialog();
124 SetChecked(true);
125 EXPECT_TRUE(dialog_->Accept());
126 EXPECT_TRUE(called_);
127 EXPECT_TRUE(accept_);
128 EXPECT_FALSE(cancel_);
129 EXPECT_TRUE(dont_block_);
130 }
131
132 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestCancel) {
133 ShowDialog();
134 EXPECT_TRUE(dialog_->Cancel());
135 EXPECT_TRUE(called_);
136 EXPECT_FALSE(accept_);
137 EXPECT_TRUE(cancel_);
138 EXPECT_FALSE(dont_block_);
139 }
140
141 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
142 TestCancelWithChecked) {
143 ShowDialog();
144 SetChecked(true);
145 EXPECT_TRUE(dialog_->Cancel());
146 EXPECT_TRUE(called_);
147 EXPECT_FALSE(accept_);
148 EXPECT_TRUE(cancel_);
149 EXPECT_TRUE(dont_block_);
150 }
151
152 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestClose) {
153 // Closing the dialog should always call DoCancel() with |dont_block| = false.
154 ShowDialog();
155 EXPECT_TRUE(dialog_->Close());
156 EXPECT_TRUE(called_);
157 EXPECT_FALSE(accept_);
158 EXPECT_TRUE(cancel_);
159 EXPECT_FALSE(dont_block_);
160 }
161
162 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
163 TestCloseWithChecked) {
164 // Closing the dialog should always call DoCancel() with |dont_block| = false.
165 ShowDialog();
166 SetChecked(true);
167 EXPECT_TRUE(dialog_->Close());
168 EXPECT_TRUE(called_);
169 EXPECT_FALSE(accept_);
170 EXPECT_TRUE(cancel_);
171 EXPECT_FALSE(dont_block_);
172 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/external_protocol_dialog.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698