OLD | NEW |
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 22 matching lines...) Expand all Loading... |
33 }; | 33 }; |
34 | 34 |
35 class FakeExternalProtocolHandlerDelegate | 35 class FakeExternalProtocolHandlerDelegate |
36 : public ExternalProtocolHandler::Delegate { | 36 : public ExternalProtocolHandler::Delegate { |
37 public: | 37 public: |
38 FakeExternalProtocolHandlerDelegate() | 38 FakeExternalProtocolHandlerDelegate() |
39 : block_state_(ExternalProtocolHandler::BLOCK), | 39 : block_state_(ExternalProtocolHandler::BLOCK), |
40 os_state_(ShellIntegration::UNKNOWN_DEFAULT), | 40 os_state_(ShellIntegration::UNKNOWN_DEFAULT), |
41 has_launched_(false), | 41 has_launched_(false), |
42 has_prompted_(false), | 42 has_prompted_(false), |
43 has_blocked_ (false) {} | 43 has_blocked_(false) {} |
44 | 44 |
45 ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( | 45 ShellIntegration::DefaultProtocolClientWorker* CreateShellWorker( |
46 ShellIntegration::DefaultWebClientObserver* observer, | 46 ShellIntegration::DefaultWebClientObserver* observer, |
47 const std::string& protocol) override { | 47 const std::string& protocol) override { |
48 return new FakeExternalProtocolHandlerWorker(observer, protocol, os_state_); | 48 return new FakeExternalProtocolHandlerWorker(observer, protocol, os_state_); |
49 } | 49 } |
50 | 50 |
51 ExternalProtocolHandler::BlockState GetBlockState( | 51 ExternalProtocolHandler::BlockState GetBlockState( |
52 const std::string& scheme) override { | 52 const std::string& scheme) override { |
53 return block_state_; | 53 return block_state_; |
54 } | 54 } |
55 | 55 |
56 void BlockRequest() override { | 56 void BlockRequest() override { |
57 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK || | 57 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK || |
58 os_state_ == ShellIntegration::IS_DEFAULT); | 58 os_state_ == ShellIntegration::IS_DEFAULT); |
59 has_blocked_ = true; | 59 has_blocked_ = true; |
60 } | 60 } |
61 | 61 |
62 void RunExternalProtocolDialog(const GURL& url, | 62 void RunExternalProtocolDialog(const GURL& url, |
63 int render_process_host_id, | 63 int render_process_host_id, |
64 int routing_id) override { | 64 int routing_id, |
| 65 ui::PageTransition page_transition, |
| 66 bool has_user_gesture) override { |
65 ASSERT_EQ(block_state_, ExternalProtocolHandler::UNKNOWN); | 67 ASSERT_EQ(block_state_, ExternalProtocolHandler::UNKNOWN); |
66 ASSERT_NE(os_state_, ShellIntegration::IS_DEFAULT); | 68 ASSERT_NE(os_state_, ShellIntegration::IS_DEFAULT); |
67 has_prompted_ = true; | 69 has_prompted_ = true; |
68 } | 70 } |
69 | 71 |
70 void LaunchUrlWithoutSecurityCheck(const GURL& url) override { | 72 void LaunchUrlWithoutSecurityCheck(const GURL& url) override { |
71 ASSERT_EQ(block_state_, ExternalProtocolHandler::DONT_BLOCK); | 73 ASSERT_EQ(block_state_, ExternalProtocolHandler::DONT_BLOCK); |
72 ASSERT_NE(os_state_, ShellIntegration::IS_DEFAULT); | 74 ASSERT_NE(os_state_, ShellIntegration::IS_DEFAULT); |
73 has_launched_ = true; | 75 has_launched_ = true; |
74 } | 76 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 void DoTest(ExternalProtocolHandler::BlockState block_state, | 115 void DoTest(ExternalProtocolHandler::BlockState block_state, |
114 ShellIntegration::DefaultWebClientState os_state, | 116 ShellIntegration::DefaultWebClientState os_state, |
115 bool should_prompt, bool should_launch, bool should_block) { | 117 bool should_prompt, bool should_launch, bool should_block) { |
116 GURL url("mailto:test@test.com"); | 118 GURL url("mailto:test@test.com"); |
117 ASSERT_FALSE(delegate_.has_prompted()); | 119 ASSERT_FALSE(delegate_.has_prompted()); |
118 ASSERT_FALSE(delegate_.has_launched()); | 120 ASSERT_FALSE(delegate_.has_launched()); |
119 ASSERT_FALSE(delegate_.has_blocked()); | 121 ASSERT_FALSE(delegate_.has_blocked()); |
120 | 122 |
121 delegate_.set_block_state(block_state); | 123 delegate_.set_block_state(block_state); |
122 delegate_.set_os_state(os_state); | 124 delegate_.set_os_state(os_state); |
123 ExternalProtocolHandler::LaunchUrlWithDelegate(url, 0, 0, &delegate_); | 125 ExternalProtocolHandler::LaunchUrlWithDelegate( |
| 126 url, 0, 0, ui::PAGE_TRANSITION_LINK, true, &delegate_); |
124 if (block_state != ExternalProtocolHandler::BLOCK) | 127 if (block_state != ExternalProtocolHandler::BLOCK) |
125 base::MessageLoop::current()->Run(); | 128 base::MessageLoop::current()->Run(); |
126 | 129 |
127 ASSERT_EQ(should_prompt, delegate_.has_prompted()); | 130 ASSERT_EQ(should_prompt, delegate_.has_prompted()); |
128 ASSERT_EQ(should_launch, delegate_.has_launched()); | 131 ASSERT_EQ(should_launch, delegate_.has_launched()); |
129 ASSERT_EQ(should_block, delegate_.has_blocked()); | 132 ASSERT_EQ(should_block, delegate_.has_blocked()); |
130 } | 133 } |
131 | 134 |
132 base::MessageLoopForUI ui_message_loop_; | 135 base::MessageLoopForUI ui_message_loop_; |
133 content::TestBrowserThread ui_thread_; | 136 content::TestBrowserThread ui_thread_; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 DoTest(ExternalProtocolHandler::UNKNOWN, | 185 DoTest(ExternalProtocolHandler::UNKNOWN, |
183 ShellIntegration::NOT_DEFAULT, | 186 ShellIntegration::NOT_DEFAULT, |
184 true, false, false); | 187 true, false, false); |
185 } | 188 } |
186 | 189 |
187 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) { | 190 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) { |
188 DoTest(ExternalProtocolHandler::UNKNOWN, | 191 DoTest(ExternalProtocolHandler::UNKNOWN, |
189 ShellIntegration::UNKNOWN_DEFAULT, | 192 ShellIntegration::UNKNOWN_DEFAULT, |
190 true, false, false); | 193 true, false, false); |
191 } | 194 } |
OLD | NEW |