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

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

Issue 426713002: Revert of Fix the handling of user gestures for external protocol handler dialogs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 4 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, 54 const std::string& scheme) OVERRIDE {
55 bool initiated_by_user_gesture) OVERRIDE { return block_state_; } 55 return block_state_;
56 }
56 57
57 virtual void BlockRequest() OVERRIDE { 58 virtual void BlockRequest() OVERRIDE {
58 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK || 59 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK ||
59 os_state_ == ShellIntegration::IS_DEFAULT); 60 os_state_ == ShellIntegration::IS_DEFAULT);
60 has_blocked_ = true; 61 has_blocked_ = true;
61 } 62 }
62 63
63 virtual void RunExternalProtocolDialog(const GURL& url, 64 virtual void RunExternalProtocolDialog(const GURL& url,
64 int render_process_host_id, 65 int render_process_host_id,
65 int routing_id) OVERRIDE { 66 int routing_id) OVERRIDE {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 class ExternalProtocolHandlerTest : public testing::Test { 102 class ExternalProtocolHandlerTest : public testing::Test {
102 protected: 103 protected:
103 ExternalProtocolHandlerTest() 104 ExternalProtocolHandlerTest()
104 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), 105 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
105 file_thread_(BrowserThread::FILE) {} 106 file_thread_(BrowserThread::FILE) {}
106 107
107 virtual void SetUp() { 108 virtual void SetUp() {
108 file_thread_.Start(); 109 file_thread_.Start();
109 } 110 }
110 111
112 virtual void TearDown() {
113 // Ensure that g_accept_requests gets set back to true after test execution.
114 ExternalProtocolHandler::PermitLaunchUrl();
115 }
116
111 void DoTest(ExternalProtocolHandler::BlockState block_state, 117 void DoTest(ExternalProtocolHandler::BlockState block_state,
112 ShellIntegration::DefaultWebClientState os_state, 118 ShellIntegration::DefaultWebClientState os_state,
113 bool should_prompt, bool should_launch, bool should_block) { 119 bool should_prompt, bool should_launch, bool should_block) {
114 GURL url("mailto:test@test.com"); 120 GURL url("mailto:test@test.com");
115 ASSERT_FALSE(delegate_.has_prompted()); 121 ASSERT_FALSE(delegate_.has_prompted());
116 ASSERT_FALSE(delegate_.has_launched()); 122 ASSERT_FALSE(delegate_.has_launched());
117 ASSERT_FALSE(delegate_.has_blocked()); 123 ASSERT_FALSE(delegate_.has_blocked());
118 124
119 delegate_.set_block_state(block_state); 125 delegate_.set_block_state(block_state);
120 delegate_.set_os_state(os_state); 126 delegate_.set_os_state(os_state);
121 ExternalProtocolHandler::LaunchUrlWithDelegate(url, 0, 0, &delegate_, true); 127 ExternalProtocolHandler::LaunchUrlWithDelegate(url, 0, 0, &delegate_);
122 if (block_state != ExternalProtocolHandler::BLOCK) 128 if (block_state != ExternalProtocolHandler::BLOCK)
123 base::MessageLoop::current()->Run(); 129 base::MessageLoop::current()->Run();
124 130
125 ASSERT_EQ(should_prompt, delegate_.has_prompted()); 131 ASSERT_EQ(should_prompt, delegate_.has_prompted());
126 ASSERT_EQ(should_launch, delegate_.has_launched()); 132 ASSERT_EQ(should_launch, delegate_.has_launched());
127 ASSERT_EQ(should_block, delegate_.has_blocked()); 133 ASSERT_EQ(should_block, delegate_.has_blocked());
128 } 134 }
129 135
130 base::MessageLoopForUI ui_message_loop_; 136 base::MessageLoopForUI ui_message_loop_;
131 content::TestBrowserThread ui_thread_; 137 content::TestBrowserThread ui_thread_;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 DoTest(ExternalProtocolHandler::UNKNOWN, 186 DoTest(ExternalProtocolHandler::UNKNOWN,
181 ShellIntegration::NOT_DEFAULT, 187 ShellIntegration::NOT_DEFAULT,
182 true, false, false); 188 true, false, false);
183 } 189 }
184 190
185 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) { 191 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) {
186 DoTest(ExternalProtocolHandler::UNKNOWN, 192 DoTest(ExternalProtocolHandler::UNKNOWN,
187 ShellIntegration::UNKNOWN_DEFAULT, 193 ShellIntegration::UNKNOWN_DEFAULT,
188 true, false, false); 194 true, false, false);
189 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698