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

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: CreateDialog is a macro on Windows -_- 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
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
tapted 2017/01/04 23:32:49 nit: no (c). Also, 2017 :)
dominickn 2017/01/04 23:51:35 Done.
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/memory/ptr_util.h"
6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/external_protocol_dialog_delegate.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/browser/ui/views/external_protocol_dialog.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/web_contents.h"
14 #include "url/gurl.h"
15
tapted 2017/01/04 23:32:49 namespace test { class ExternalProtocolDialogTest
dominickn 2017/01/04 23:51:36 Done.
16 class TestExternalProtocolDialogDelegate
17 : public ExternalProtocolDialogDelegate {
18 public:
19 TestExternalProtocolDialogDelegate(const GURL& url,
20 int render_process_host_id,
21 int routing_id,
22 bool* called,
23 bool* accept,
24 bool* dont_block)
25 : ExternalProtocolDialogDelegate(url, render_process_host_id, routing_id),
26 called_(called),
27 accept_(accept),
28 dont_block_(dont_block) {}
29
30 void DoAccept(const GURL& url, bool dont_block) const override {
tapted 2017/01/04 23:32:49 nit: // ExternalProtocolDialogDelegate:
dominickn 2017/01/04 23:51:36 Done.
31 *called_ = true;
32 *accept_ = true;
33 *dont_block_ = dont_block;
34 }
35
36 void DoCancel(const GURL& url, bool dont_block) const override {
37 *called_ = true;
38 *accept_ = false;
39 *dont_block_ = dont_block;
40 }
41
42 private:
43 bool* called_;
44 bool* accept_;
45 bool* dont_block_;
46 };
tapted 2017/01/04 23:32:49 nit: DISALLOW_COPY_AND_ASSIGN(..)
dominickn 2017/01/04 23:51:36 Done.
47
48 class ExternalProtocolDialogBrowserTest : public InProcessBrowserTest {
49 public:
50 ExternalProtocolDialogBrowserTest()
51 : InProcessBrowserTest(),
tapted 2017/01/04 23:32:49 this superclass constructor call isn't needed - th
dominickn 2017/01/04 23:51:36 Done.
52 dialog_(nullptr),
53 called_(false),
54 accept_(false),
55 dont_block_(false) {}
56
57 void ShowDialog(const GURL& url) {
58 content::WebContents* web_contents =
59 browser()->tab_strip_model()->GetActiveWebContents();
60 int render_process_host_id = web_contents->GetRenderProcessHost()->GetID();
61 int routing_id = web_contents->GetRenderViewHost()->GetRoutingID();
62 dialog_ = new ExternalProtocolDialog(
63 base::MakeUnique<TestExternalProtocolDialogDelegate>(
64 url, render_process_host_id, routing_id, &called_, &accept_,
65 &dont_block_),
66 render_process_host_id, routing_id);
67 }
68
69 void SetChecked(bool checked) {
70 dialog_->SetCheckBoxSelectedForTesting(checked);
tapted 2017/01/04 23:32:49 ExternalProtocolDialogTestApi(dialog_).SetCheckBox
dominickn 2017/01/04 23:51:36 Done.
71 }
72
73 protected:
74 ExternalProtocolDialog* dialog_;
tapted 2017/01/04 23:32:49 i.e. = nullptr, etc.
dominickn 2017/01/04 23:51:35 Done.
75 bool called_;
76 bool accept_;
77 bool dont_block_;
78 };
tapted 2017/01/04 23:32:49 private: DISALLOW_COPY_AND_ASSIGN(..)
dominickn 2017/01/04 23:51:36 Done.
79
80 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestAccept) {
81 ShowDialog(GURL("https://www.google.com"));
tapted 2017/01/04 23:32:49 since it's always google.com, can we just call Sho
dominickn 2017/01/04 23:51:36 I made it a URL argument for future extensibility,
82 EXPECT_TRUE(dialog_->Accept());
83 EXPECT_TRUE(called_);
84 EXPECT_TRUE(accept_);
85 EXPECT_FALSE(dont_block_);
86 }
87
88 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
89 TestAcceptWithChecked) {
90 ShowDialog(GURL("https://www.google.com"));
91 SetChecked(true);
92 EXPECT_TRUE(dialog_->Accept());
93 EXPECT_TRUE(called_);
94 EXPECT_TRUE(accept_);
95 EXPECT_TRUE(dont_block_);
96 }
97
98 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestCancel) {
99 ShowDialog(GURL("https://www.google.com"));
100 EXPECT_TRUE(dialog_->Cancel());
101 EXPECT_TRUE(called_);
102 EXPECT_FALSE(accept_);
103 EXPECT_FALSE(dont_block_);
104 }
105
106 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
107 TestCancelWithChecked) {
108 ShowDialog(GURL("https://www.google.com"));
109 SetChecked(true);
110 EXPECT_TRUE(dialog_->Cancel());
111 EXPECT_TRUE(called_);
112 EXPECT_FALSE(accept_);
113 EXPECT_TRUE(dont_block_);
114 }
115
116 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestClose) {
117 ShowDialog(GURL("https://www.google.com"));
118 EXPECT_TRUE(dialog_->Close());
119 EXPECT_TRUE(called_);
120 EXPECT_FALSE(accept_);
121 EXPECT_FALSE(dont_block_);
122 }
123
124 IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
125 TestCloseWithChecked) {
126 ShowDialog(GURL("https://www.google.com"));
127 SetChecked(true);
128 EXPECT_TRUE(dialog_->Close());
129 EXPECT_TRUE(called_);
130 EXPECT_FALSE(accept_);
131 EXPECT_FALSE(dont_block_);
132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698