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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/external_protocol_dialog_browsertest.cc
diff --git a/chrome/browser/ui/views/external_protocol_dialog_browsertest.cc b/chrome/browser/ui/views/external_protocol_dialog_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..16771a9cb7256b6a2d2315aba5a58fe49f9c61b4
--- /dev/null
+++ b/chrome/browser/ui/views/external_protocol_dialog_browsertest.cc
@@ -0,0 +1,160 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/external_protocol_dialog_delegate.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/views/external_protocol_dialog.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "ui/views/controls/message_box_view.h"
+#include "url/gurl.h"
+
+namespace test {
+
+class ExternalProtocolDialogTestApi {
+ public:
+ explicit ExternalProtocolDialogTestApi(ExternalProtocolDialog* dialog)
+ : dialog_(dialog) {}
+
+ void SetCheckBoxSelected(bool checked) {
+ dialog_->message_box_view_->SetCheckBoxSelected(checked);
+ }
+
+ private:
+ ExternalProtocolDialog* dialog_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExternalProtocolDialogTestApi);
+};
+
+} // namespace test
+
+// 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.
+// |dont_block| bools based on what is called by the ExternalProtocolDialog.
+class TestExternalProtocolDialogDelegate
+ : public ExternalProtocolDialogDelegate {
+ public:
+ TestExternalProtocolDialogDelegate(const GURL& url,
+ int render_process_host_id,
+ int routing_id,
+ bool* called,
+ bool* accept,
+ bool* dont_block)
+ : ExternalProtocolDialogDelegate(url, render_process_host_id, routing_id),
+ called_(called),
+ accept_(accept),
+ dont_block_(dont_block) {}
+
+ // ExternalProtocolDialogDelegate:
+ void DoAccept(const GURL& url, bool dont_block) const override {
+ // Don't call the base impl because it will actually launch |url|.
+ *called_ = true;
+ *accept_ = true;
+ *dont_block_ = dont_block;
+ }
+
+ void DoCancel(const GURL& url, bool dont_block) const override {
+ // Don't call the base impl because it will actually launch |url|.
+ *called_ = true;
+ *accept_ = false;
+ *dont_block_ = dont_block;
+ }
+
+ private:
+ bool* called_;
+ bool* accept_;
+ bool* dont_block_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestExternalProtocolDialogDelegate);
+};
+
+class ExternalProtocolDialogBrowserTest : public InProcessBrowserTest {
+ public:
+ ExternalProtocolDialogBrowserTest() {}
+
+ void ShowDialog() {
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ int render_process_host_id = web_contents->GetRenderProcessHost()->GetID();
+ int routing_id = web_contents->GetRenderViewHost()->GetRoutingID();
+ dialog_ = new ExternalProtocolDialog(
+ base::MakeUnique<TestExternalProtocolDialogDelegate>(
+ 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.
+ &called_, &accept_, &dont_block_),
+ render_process_host_id, routing_id);
+ }
+
+ void SetChecked(bool checked) {
+ test::ExternalProtocolDialogTestApi(dialog_).SetCheckBoxSelected(checked);
+ }
+
+ protected:
+ ExternalProtocolDialog* dialog_ = nullptr;
+ bool called_ = false;
+ bool accept_ = false;
+ bool dont_block_ = false;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ExternalProtocolDialogBrowserTest);
+};
+
+IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestAccept) {
+ ShowDialog();
+ EXPECT_TRUE(dialog_->Accept());
+ EXPECT_TRUE(called_);
+ EXPECT_TRUE(accept_);
+ EXPECT_FALSE(dont_block_);
+}
+
+IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
+ TestAcceptWithChecked) {
+ ShowDialog();
+ SetChecked(true);
+ EXPECT_TRUE(dialog_->Accept());
+ EXPECT_TRUE(called_);
+ EXPECT_TRUE(accept_);
+ EXPECT_TRUE(dont_block_);
+}
+
+IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestCancel) {
+ ShowDialog();
+ EXPECT_TRUE(dialog_->Cancel());
+ EXPECT_TRUE(called_);
+ EXPECT_FALSE(accept_);
+ EXPECT_FALSE(dont_block_);
+}
+
+IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
+ TestCancelWithChecked) {
+ ShowDialog();
+ SetChecked(true);
+ EXPECT_TRUE(dialog_->Cancel());
+ EXPECT_TRUE(called_);
+ EXPECT_FALSE(accept_);
+ EXPECT_TRUE(dont_block_);
+}
+
+IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestClose) {
+ // Closing the dialog should always call DoCancel() with |dont_block| = false.
+ ShowDialog();
+ EXPECT_TRUE(dialog_->Close());
+ EXPECT_TRUE(called_);
+ EXPECT_FALSE(accept_);
+ EXPECT_FALSE(dont_block_);
+}
+
+IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest,
+ TestCloseWithChecked) {
+ // Closing the dialog should always call DoCancel() with |dont_block| = false.
+ ShowDialog();
+ SetChecked(true);
+ EXPECT_TRUE(dialog_->Close());
+ EXPECT_TRUE(called_);
+ EXPECT_FALSE(accept_);
+ EXPECT_FALSE(dont_block_);
+}
« 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