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

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: Fix build Created 6 years, 10 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, bool user_gesture) OVERRIDE {
55 return block_state_;
56 }
55 57
56 virtual void BlockRequest() OVERRIDE { 58 virtual void BlockRequest() OVERRIDE {
57 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK || 59 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK ||
58 os_state_ == ShellIntegration::IS_DEFAULT); 60 os_state_ == ShellIntegration::IS_DEFAULT);
59 has_blocked_ = true; 61 has_blocked_ = true;
60 } 62 }
61 63
62 virtual void RunExternalProtocolDialog(const GURL& url, 64 virtual void RunExternalProtocolDialog(const GURL& url,
63 int render_process_host_id, 65 int render_process_host_id,
64 int routing_id) OVERRIDE { 66 int routing_id) OVERRIDE {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 class ExternalProtocolHandlerTest : public testing::Test { 102 class ExternalProtocolHandlerTest : public testing::Test {
101 protected: 103 protected:
102 ExternalProtocolHandlerTest() 104 ExternalProtocolHandlerTest()
103 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), 105 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
104 file_thread_(BrowserThread::FILE) {} 106 file_thread_(BrowserThread::FILE) {}
105 107
106 virtual void SetUp() { 108 virtual void SetUp() {
107 file_thread_.Start(); 109 file_thread_.Start();
108 } 110 }
109 111
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, 112 void DoTest(ExternalProtocolHandler::BlockState block_state,
116 ShellIntegration::DefaultWebClientState os_state, 113 ShellIntegration::DefaultWebClientState os_state,
117 bool should_prompt, bool should_launch, bool should_block) { 114 bool should_prompt, bool should_launch, bool should_block) {
118 GURL url("mailto:test@test.com"); 115 GURL url("mailto:test@test.com");
119 ASSERT_FALSE(delegate_.has_prompted()); 116 ASSERT_FALSE(delegate_.has_prompted());
120 ASSERT_FALSE(delegate_.has_launched()); 117 ASSERT_FALSE(delegate_.has_launched());
121 ASSERT_FALSE(delegate_.has_blocked()); 118 ASSERT_FALSE(delegate_.has_blocked());
122 119
123 delegate_.set_block_state(block_state); 120 delegate_.set_block_state(block_state);
124 delegate_.set_os_state(os_state); 121 delegate_.set_os_state(os_state);
125 ExternalProtocolHandler::LaunchUrlWithDelegate(url, 0, 0, &delegate_); 122 ExternalProtocolHandler::LaunchUrlWithDelegate(url, 0, 0, &delegate_, true);
126 if (block_state != ExternalProtocolHandler::BLOCK) 123 if (block_state != ExternalProtocolHandler::BLOCK)
127 base::MessageLoop::current()->Run(); 124 base::MessageLoop::current()->Run();
128 125
129 ASSERT_EQ(should_prompt, delegate_.has_prompted()); 126 ASSERT_EQ(should_prompt, delegate_.has_prompted());
130 ASSERT_EQ(should_launch, delegate_.has_launched()); 127 ASSERT_EQ(should_launch, delegate_.has_launched());
131 ASSERT_EQ(should_block, delegate_.has_blocked()); 128 ASSERT_EQ(should_block, delegate_.has_blocked());
132 } 129 }
133 130
134 base::MessageLoopForUI ui_message_loop_; 131 base::MessageLoopForUI ui_message_loop_;
135 content::TestBrowserThread ui_thread_; 132 content::TestBrowserThread ui_thread_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 DoTest(ExternalProtocolHandler::UNKNOWN, 181 DoTest(ExternalProtocolHandler::UNKNOWN,
185 ShellIntegration::NOT_DEFAULT, 182 ShellIntegration::NOT_DEFAULT,
186 true, false, false); 183 true, false, false);
187 } 184 }
188 185
189 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) { 186 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) {
190 DoTest(ExternalProtocolHandler::UNKNOWN, 187 DoTest(ExternalProtocolHandler::UNKNOWN,
191 ShellIntegration::UNKNOWN_DEFAULT, 188 ShellIntegration::UNKNOWN_DEFAULT,
192 true, false, false); 189 true, false, false);
193 } 190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698