Chromium Code Reviews| 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..7bb9422648bad81d26c58d8018ba8c108ef613ce |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/external_protocol_dialog_browsertest.cc |
| @@ -0,0 +1,132 @@ |
| +// 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.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#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 "url/gurl.h" |
| + |
|
tapted
2017/01/04 23:32:49
namespace test {
class ExternalProtocolDialogTest
dominickn
2017/01/04 23:51:36
Done.
|
| +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) {} |
| + |
| + 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.
|
| + *called_ = true; |
| + *accept_ = true; |
| + *dont_block_ = dont_block; |
| + } |
| + |
| + void DoCancel(const GURL& url, bool dont_block) const override { |
| + *called_ = true; |
| + *accept_ = false; |
| + *dont_block_ = dont_block; |
| + } |
| + |
| + private: |
| + bool* called_; |
| + bool* accept_; |
| + bool* dont_block_; |
| +}; |
|
tapted
2017/01/04 23:32:49
nit: DISALLOW_COPY_AND_ASSIGN(..)
dominickn
2017/01/04 23:51:36
Done.
|
| + |
| +class ExternalProtocolDialogBrowserTest : public InProcessBrowserTest { |
| + public: |
| + ExternalProtocolDialogBrowserTest() |
| + : InProcessBrowserTest(), |
|
tapted
2017/01/04 23:32:49
this superclass constructor call isn't needed - th
dominickn
2017/01/04 23:51:36
Done.
|
| + dialog_(nullptr), |
| + called_(false), |
| + accept_(false), |
| + dont_block_(false) {} |
| + |
| + void ShowDialog(const GURL& url) { |
| + 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>( |
| + url, render_process_host_id, routing_id, &called_, &accept_, |
| + &dont_block_), |
| + render_process_host_id, routing_id); |
| + } |
| + |
| + void SetChecked(bool checked) { |
| + dialog_->SetCheckBoxSelectedForTesting(checked); |
|
tapted
2017/01/04 23:32:49
ExternalProtocolDialogTestApi(dialog_).SetCheckBox
dominickn
2017/01/04 23:51:36
Done.
|
| + } |
| + |
| + protected: |
| + ExternalProtocolDialog* dialog_; |
|
tapted
2017/01/04 23:32:49
i.e. = nullptr, etc.
dominickn
2017/01/04 23:51:35
Done.
|
| + bool called_; |
| + bool accept_; |
| + bool dont_block_; |
| +}; |
|
tapted
2017/01/04 23:32:49
private:
DISALLOW_COPY_AND_ASSIGN(..)
dominickn
2017/01/04 23:51:36
Done.
|
| + |
| +IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestAccept) { |
| + 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,
|
| + EXPECT_TRUE(dialog_->Accept()); |
| + EXPECT_TRUE(called_); |
| + EXPECT_TRUE(accept_); |
| + EXPECT_FALSE(dont_block_); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, |
| + TestAcceptWithChecked) { |
| + ShowDialog(GURL("https://www.google.com")); |
| + SetChecked(true); |
| + EXPECT_TRUE(dialog_->Accept()); |
| + EXPECT_TRUE(called_); |
| + EXPECT_TRUE(accept_); |
| + EXPECT_TRUE(dont_block_); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestCancel) { |
| + ShowDialog(GURL("https://www.google.com")); |
| + EXPECT_TRUE(dialog_->Cancel()); |
| + EXPECT_TRUE(called_); |
| + EXPECT_FALSE(accept_); |
| + EXPECT_FALSE(dont_block_); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, |
| + TestCancelWithChecked) { |
| + ShowDialog(GURL("https://www.google.com")); |
| + SetChecked(true); |
| + EXPECT_TRUE(dialog_->Cancel()); |
| + EXPECT_TRUE(called_); |
| + EXPECT_FALSE(accept_); |
| + EXPECT_TRUE(dont_block_); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, TestClose) { |
| + ShowDialog(GURL("https://www.google.com")); |
| + EXPECT_TRUE(dialog_->Close()); |
| + EXPECT_TRUE(called_); |
| + EXPECT_FALSE(accept_); |
| + EXPECT_FALSE(dont_block_); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ExternalProtocolDialogBrowserTest, |
| + TestCloseWithChecked) { |
| + ShowDialog(GURL("https://www.google.com")); |
| + SetChecked(true); |
| + EXPECT_TRUE(dialog_->Close()); |
| + EXPECT_TRUE(called_); |
| + EXPECT_FALSE(accept_); |
| + EXPECT_FALSE(dont_block_); |
| +} |