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 |
11 using content::BrowserThread; | 11 using content::BrowserThread; |
12 | 12 |
13 class FakeExternalProtocolHandlerWorker | 13 class FakeExternalProtocolHandlerWorker |
14 : public ShellIntegration::DefaultProtocolClientWorker { | 14 : public ShellIntegration::DefaultProtocolClientWorker { |
15 public: | 15 public: |
16 FakeExternalProtocolHandlerWorker( | 16 FakeExternalProtocolHandlerWorker( |
17 ShellIntegration::DefaultWebClientObserver* observer, | 17 ShellIntegration::DefaultWebClientObserver* observer, |
18 const std::string& protocol, | 18 const std::string& protocol, |
19 ShellIntegration::DefaultWebClientState os_state) | 19 ShellIntegration::DefaultWebClientState os_state) |
20 : ShellIntegration::DefaultProtocolClientWorker(observer, protocol), | 20 : ShellIntegration::DefaultProtocolClientWorker(observer, protocol), |
21 os_state_(os_state) {} | 21 os_state_(os_state) {} |
22 | 22 |
23 private: | 23 private: |
24 virtual ~FakeExternalProtocolHandlerWorker() {} | 24 virtual ~FakeExternalProtocolHandlerWorker() {} |
25 | 25 |
26 virtual ShellIntegration::DefaultWebClientState CheckIsDefault() OVERRIDE { | 26 virtual ShellIntegration::DefaultWebClientState CheckIsDefault() override { |
27 return os_state_; | 27 return os_state_; |
28 } | 28 } |
29 | 29 |
30 virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE { | 30 virtual bool SetAsDefault(bool interactive_permitted) override { |
31 return true; | 31 return true; |
32 } | 32 } |
33 | 33 |
34 ShellIntegration::DefaultWebClientState os_state_; | 34 ShellIntegration::DefaultWebClientState os_state_; |
35 }; | 35 }; |
36 | 36 |
37 class FakeExternalProtocolHandlerDelegate | 37 class FakeExternalProtocolHandlerDelegate |
38 : public ExternalProtocolHandler::Delegate { | 38 : public ExternalProtocolHandler::Delegate { |
39 public: | 39 public: |
40 FakeExternalProtocolHandlerDelegate() | 40 FakeExternalProtocolHandlerDelegate() |
41 : block_state_(ExternalProtocolHandler::BLOCK), | 41 : block_state_(ExternalProtocolHandler::BLOCK), |
42 os_state_(ShellIntegration::UNKNOWN_DEFAULT), | 42 os_state_(ShellIntegration::UNKNOWN_DEFAULT), |
43 has_launched_(false), | 43 has_launched_(false), |
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 { | 54 const std::string& scheme) override { |
55 return block_state_; | 55 return block_state_; |
56 } | 56 } |
57 | 57 |
58 virtual void BlockRequest() OVERRIDE { | 58 virtual void BlockRequest() override { |
59 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK || | 59 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK || |
60 os_state_ == ShellIntegration::IS_DEFAULT); | 60 os_state_ == ShellIntegration::IS_DEFAULT); |
61 has_blocked_ = true; | 61 has_blocked_ = true; |
62 } | 62 } |
63 | 63 |
64 virtual void RunExternalProtocolDialog(const GURL& url, | 64 virtual void RunExternalProtocolDialog(const GURL& url, |
65 int render_process_host_id, | 65 int render_process_host_id, |
66 int routing_id) OVERRIDE { | 66 int routing_id) override { |
67 ASSERT_EQ(block_state_, ExternalProtocolHandler::UNKNOWN); | 67 ASSERT_EQ(block_state_, ExternalProtocolHandler::UNKNOWN); |
68 ASSERT_NE(os_state_, ShellIntegration::IS_DEFAULT); | 68 ASSERT_NE(os_state_, ShellIntegration::IS_DEFAULT); |
69 has_prompted_ = true; | 69 has_prompted_ = true; |
70 } | 70 } |
71 | 71 |
72 virtual void LaunchUrlWithoutSecurityCheck(const GURL& url) OVERRIDE { | 72 virtual void LaunchUrlWithoutSecurityCheck(const GURL& url) override { |
73 ASSERT_EQ(block_state_, ExternalProtocolHandler::DONT_BLOCK); | 73 ASSERT_EQ(block_state_, ExternalProtocolHandler::DONT_BLOCK); |
74 ASSERT_NE(os_state_, ShellIntegration::IS_DEFAULT); | 74 ASSERT_NE(os_state_, ShellIntegration::IS_DEFAULT); |
75 has_launched_ = true; | 75 has_launched_ = true; |
76 } | 76 } |
77 | 77 |
78 virtual void FinishedProcessingCheck() OVERRIDE { | 78 virtual void FinishedProcessingCheck() override { |
79 base::MessageLoop::current()->Quit(); | 79 base::MessageLoop::current()->Quit(); |
80 } | 80 } |
81 | 81 |
82 void set_os_state(ShellIntegration::DefaultWebClientState value) { | 82 void set_os_state(ShellIntegration::DefaultWebClientState value) { |
83 os_state_ = value; | 83 os_state_ = value; |
84 } | 84 } |
85 | 85 |
86 void set_block_state(ExternalProtocolHandler::BlockState value) { | 86 void set_block_state(ExternalProtocolHandler::BlockState value) { |
87 block_state_ = value; | 87 block_state_ = value; |
88 } | 88 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 DoTest(ExternalProtocolHandler::UNKNOWN, | 186 DoTest(ExternalProtocolHandler::UNKNOWN, |
187 ShellIntegration::NOT_DEFAULT, | 187 ShellIntegration::NOT_DEFAULT, |
188 true, false, false); | 188 true, false, false); |
189 } | 189 } |
190 | 190 |
191 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) { | 191 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) { |
192 DoTest(ExternalProtocolHandler::UNKNOWN, | 192 DoTest(ExternalProtocolHandler::UNKNOWN, |
193 ShellIntegration::UNKNOWN_DEFAULT, | 193 ShellIntegration::UNKNOWN_DEFAULT, |
194 true, false, false); | 194 true, false, false); |
195 } | 195 } |
OLD | NEW |