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

Side by Side Diff: chrome/browser/external_protocol/external_protocol_handler_unittest.cc

Issue 131783012: Fix the handling of user gestures for external protocol handler dialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unnecessary DCHECK Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/external_protocol/external_protocol_handler.h" 5 #include "chrome/browser/external_protocol/external_protocol_handler.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "content/public/test/test_browser_thread.h" 8 #include "content/public/test/test_browser_thread.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 has_prompted_(false), 44 has_prompted_(false),
45 has_blocked_ (false) {} 45 has_blocked_ (false) {}
46 46
47 virtual ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( 47 virtual ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker(
48 ShellIntegration::DefaultWebClientObserver* observer, 48 ShellIntegration::DefaultWebClientObserver* observer,
49 const std::string& protocol) OVERRIDE { 49 const std::string& protocol) OVERRIDE {
50 return new FakeExternalProtocolHandlerWorker(observer, protocol, os_state_); 50 return new FakeExternalProtocolHandlerWorker(observer, protocol, os_state_);
51 } 51 }
52 52
53 virtual ExternalProtocolHandler::BlockState GetBlockState( 53 virtual ExternalProtocolHandler::BlockState GetBlockState(
54 const std::string& scheme) OVERRIDE { return block_state_; } 54 const std::string& scheme,
55 bool initiated_by_user_gesture) OVERRIDE { return block_state_; }
55 56
56 virtual void BlockRequest() OVERRIDE { 57 virtual void BlockRequest() OVERRIDE {
57 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK || 58 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK ||
58 os_state_ == ShellIntegration::IS_DEFAULT); 59 os_state_ == ShellIntegration::IS_DEFAULT);
59 has_blocked_ = true; 60 has_blocked_ = true;
60 } 61 }
61 62
62 virtual void RunExternalProtocolDialog(const GURL& url, 63 virtual void RunExternalProtocolDialog(const GURL& url,
63 int render_process_host_id, 64 int render_process_host_id,
64 int routing_id) OVERRIDE { 65 int routing_id) OVERRIDE {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 class ExternalProtocolHandlerTest : public testing::Test { 101 class ExternalProtocolHandlerTest : public testing::Test {
101 protected: 102 protected:
102 ExternalProtocolHandlerTest() 103 ExternalProtocolHandlerTest()
103 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), 104 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
104 file_thread_(BrowserThread::FILE) {} 105 file_thread_(BrowserThread::FILE) {}
105 106
106 virtual void SetUp() { 107 virtual void SetUp() {
107 file_thread_.Start(); 108 file_thread_.Start();
108 } 109 }
109 110
110 virtual void TearDown() {
111 // Ensure that g_accept_requests gets set back to true after test execution.
112 ExternalProtocolHandler::PermitLaunchUrl();
113 }
114
115 void DoTest(ExternalProtocolHandler::BlockState block_state, 111 void DoTest(ExternalProtocolHandler::BlockState block_state,
116 ShellIntegration::DefaultWebClientState os_state, 112 ShellIntegration::DefaultWebClientState os_state,
117 bool should_prompt, bool should_launch, bool should_block) { 113 bool should_prompt, bool should_launch, bool should_block) {
118 GURL url("mailto:test@test.com"); 114 GURL url("mailto:test@test.com");
119 ASSERT_FALSE(delegate_.has_prompted()); 115 ASSERT_FALSE(delegate_.has_prompted());
120 ASSERT_FALSE(delegate_.has_launched()); 116 ASSERT_FALSE(delegate_.has_launched());
121 ASSERT_FALSE(delegate_.has_blocked()); 117 ASSERT_FALSE(delegate_.has_blocked());
122 118
123 delegate_.set_block_state(block_state); 119 delegate_.set_block_state(block_state);
124 delegate_.set_os_state(os_state); 120 delegate_.set_os_state(os_state);
125 ExternalProtocolHandler::LaunchUrlWithDelegate(url, 0, 0, &delegate_); 121 ExternalProtocolHandler::LaunchUrlWithDelegate(url, 0, 0, &delegate_, true);
126 if (block_state != ExternalProtocolHandler::BLOCK) 122 if (block_state != ExternalProtocolHandler::BLOCK)
127 base::MessageLoop::current()->Run(); 123 base::MessageLoop::current()->Run();
128 124
129 ASSERT_EQ(should_prompt, delegate_.has_prompted()); 125 ASSERT_EQ(should_prompt, delegate_.has_prompted());
130 ASSERT_EQ(should_launch, delegate_.has_launched()); 126 ASSERT_EQ(should_launch, delegate_.has_launched());
131 ASSERT_EQ(should_block, delegate_.has_blocked()); 127 ASSERT_EQ(should_block, delegate_.has_blocked());
132 } 128 }
133 129
134 base::MessageLoopForUI ui_message_loop_; 130 base::MessageLoopForUI ui_message_loop_;
135 content::TestBrowserThread ui_thread_; 131 content::TestBrowserThread ui_thread_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 DoTest(ExternalProtocolHandler::UNKNOWN, 180 DoTest(ExternalProtocolHandler::UNKNOWN,
185 ShellIntegration::NOT_DEFAULT, 181 ShellIntegration::NOT_DEFAULT,
186 true, false, false); 182 true, false, false);
187 } 183 }
188 184
189 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) { 185 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) {
190 DoTest(ExternalProtocolHandler::UNKNOWN, 186 DoTest(ExternalProtocolHandler::UNKNOWN,
191 ShellIntegration::UNKNOWN_DEFAULT, 187 ShellIntegration::UNKNOWN_DEFAULT,
192 true, false, false); 188 true, false, false);
193 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698