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

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 comments 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
msw 2017/01/05 15:57:53 Implement |cancel| or remove its mention.
dominickn 2017/01/05 23:11:55 Done.
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* dont_block)
48 : ExternalProtocolDialogDelegate(url, render_process_host_id, routing_id),
49 called_(called),
50 accept_(accept),
51 dont_block_(dont_block) {}
52
53 // ExternalProtocolDialogDelegate:
54 void DoAccept(const GURL& url, bool dont_block) const override {
55 // Don't call the base impl because it will actually launch |url|.
56 *called_ = true;
57 *accept_ = true;
58 *dont_block_ = dont_block;
59 }
60
61 void DoCancel(const GURL& url, bool dont_block) const override {
62 // Don't call the base impl because it will actually launch |url|.
63 *called_ = true;
64 *accept_ = false;
65 *dont_block_ = dont_block;
66 }
67
68 private:
69 bool* called_;
70 bool* accept_;
71 bool* dont_block_;
72
73 DISALLOW_COPY_AND_ASSIGN(TestExternalProtocolDialogDelegate);
74 };
75
76 class ExternalProtocolDialogBrowserTest : public InProcessBrowserTest {
77 public:
78 ExternalProtocolDialogBrowserTest() {}
79
80 void ShowDialog() {
81 content::WebContents* web_contents =
82 browser()->tab_strip_model()->GetActiveWebContents();
83 int render_process_host_id = web_contents->GetRenderProcessHost()->GetID();
84 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID();
85 dialog_ = new ExternalProtocolDialog(
86 base::MakeUnique<TestExternalProtocolDialogDelegate>(
87 GURL("telnet://29128"), render_process_host_id, routing_id,
msw 2017/01/05 15:57:53 I'm curious what this points to, hopefully somethi
dominickn 2017/01/05 23:11:55 This URL is completely arbitrary. telnet URLs are
msw 2017/01/06 00:54:00 gotcha, maybe do 12345 or something that's more ob
dominickn 2017/01/06 02:43:16 Done.
88 &called_, &accept_, &dont_block_),
89 render_process_host_id, routing_id);
90 }
91
92 void SetChecked(bool checked) {
93 test::ExternalProtocolDialogTestApi(dialog_).SetCheckBoxSelected(checked);
94 }
95
96 protected:
97 ExternalProtocolDialog* dialog_ = nullptr;
98 bool called_ = false;
99 bool accept_ = false;
100 bool dont_block_ = false;
101
102 private:
103 DISALLOW_COPY_AND_ASSIGN(ExternalProtocolDialogBrowserTest);
104 };
105
106 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestAccept) {
107 ShowDialog();
108 EXPECT_TRUE(dialog_->Accept());
109 EXPECT_TRUE(called_);
110 EXPECT_TRUE(accept_);
111 EXPECT_FALSE(dont_block_);
112 }
113
114 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
115 TestAcceptWithChecked) {
116 ShowDialog();
117 SetChecked(true);
118 EXPECT_TRUE(dialog_->Accept());
119 EXPECT_TRUE(called_);
120 EXPECT_TRUE(accept_);
121 EXPECT_TRUE(dont_block_);
122 }
123
124 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestCancel) {
125 ShowDialog();
126 EXPECT_TRUE(dialog_->Cancel());
127 EXPECT_TRUE(called_);
128 EXPECT_FALSE(accept_);
129 EXPECT_FALSE(dont_block_);
130 }
131
132 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
133 TestCancelWithChecked) {
134 ShowDialog();
135 SetChecked(true);
136 EXPECT_TRUE(dialog_->Cancel());
137 EXPECT_TRUE(called_);
138 EXPECT_FALSE(accept_);
139 EXPECT_TRUE(dont_block_);
140 }
141
142 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestClose) {
143 // Closing the dialog should always call DoCancel() with |dont_block| = false.
144 ShowDialog();
145 EXPECT_TRUE(dialog_->Close());
146 EXPECT_TRUE(called_);
147 EXPECT_FALSE(accept_);
148 EXPECT_FALSE(dont_block_);
149 }
150
151 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
152 TestCloseWithChecked) {
153 // Closing the dialog should always call DoCancel() with |dont_block| = false.
154 ShowDialog();
155 SetChecked(true);
156 EXPECT_TRUE(dialog_->Close());
157 EXPECT_TRUE(called_);
158 EXPECT_FALSE(accept_);
159 EXPECT_FALSE(dont_block_);
160 }
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