| 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 "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "chrome/browser/prefs/browser_prefs.h" | 9 #include "chrome/browser/prefs/browser_prefs.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/test/base/testing_browser_process.h" | 11 #include "chrome/test/base/testing_browser_process.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "components/prefs/testing_pref_service.h" | 13 #include "components/prefs/testing_pref_service.h" |
| 14 #include "content/public/test/test_browser_thread.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 using content::BrowserThread; | |
| 18 | |
| 19 class FakeExternalProtocolHandlerWorker | 17 class FakeExternalProtocolHandlerWorker |
| 20 : public shell_integration::DefaultProtocolClientWorker { | 18 : public shell_integration::DefaultProtocolClientWorker { |
| 21 public: | 19 public: |
| 22 FakeExternalProtocolHandlerWorker( | 20 FakeExternalProtocolHandlerWorker( |
| 23 const shell_integration::DefaultWebClientWorkerCallback& callback, | 21 const shell_integration::DefaultWebClientWorkerCallback& callback, |
| 24 const std::string& protocol, | 22 const std::string& protocol, |
| 25 shell_integration::DefaultWebClientState os_state) | 23 shell_integration::DefaultWebClientState os_state) |
| 26 : shell_integration::DefaultProtocolClientWorker(callback, protocol), | 24 : shell_integration::DefaultProtocolClientWorker(callback, protocol), |
| 27 os_state_(os_state) {} | 25 os_state_(os_state) {} |
| 28 | 26 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 ExternalProtocolHandler::BlockState block_state_; | 104 ExternalProtocolHandler::BlockState block_state_; |
| 107 shell_integration::DefaultWebClientState os_state_; | 105 shell_integration::DefaultWebClientState os_state_; |
| 108 bool has_launched_; | 106 bool has_launched_; |
| 109 bool has_prompted_; | 107 bool has_prompted_; |
| 110 bool has_blocked_; | 108 bool has_blocked_; |
| 111 }; | 109 }; |
| 112 | 110 |
| 113 class ExternalProtocolHandlerTest : public testing::Test { | 111 class ExternalProtocolHandlerTest : public testing::Test { |
| 114 protected: | 112 protected: |
| 115 ExternalProtocolHandlerTest() | 113 ExternalProtocolHandlerTest() |
| 116 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), | 114 : test_browser_thread_bundle_( |
| 117 file_thread_(BrowserThread::FILE) {} | 115 content::TestBrowserThreadBundle::REAL_FILE_THREAD) {} |
| 118 | 116 |
| 119 void SetUp() override { | 117 void SetUp() override { |
| 120 file_thread_.Start(); | |
| 121 local_state_.reset(new TestingPrefServiceSimple); | 118 local_state_.reset(new TestingPrefServiceSimple); |
| 122 profile_.reset(new TestingProfile()); | 119 profile_.reset(new TestingProfile()); |
| 123 chrome::RegisterLocalState(local_state_->registry()); | 120 chrome::RegisterLocalState(local_state_->registry()); |
| 124 TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.get()); | 121 TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.get()); |
| 125 } | 122 } |
| 126 | 123 |
| 127 void TearDown() override { | 124 void TearDown() override { |
| 128 // Ensure that g_accept_requests gets set back to true after test execution. | 125 // Ensure that g_accept_requests gets set back to true after test execution. |
| 129 ExternalProtocolHandler::PermitLaunchUrl(); | 126 ExternalProtocolHandler::PermitLaunchUrl(); |
| 130 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); | 127 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 146 ExternalProtocolHandler::LaunchUrlWithDelegate( | 143 ExternalProtocolHandler::LaunchUrlWithDelegate( |
| 147 url, 0, 0, ui::PAGE_TRANSITION_LINK, true, &delegate_); | 144 url, 0, 0, ui::PAGE_TRANSITION_LINK, true, &delegate_); |
| 148 if (block_state != ExternalProtocolHandler::BLOCK) | 145 if (block_state != ExternalProtocolHandler::BLOCK) |
| 149 base::RunLoop().Run(); | 146 base::RunLoop().Run(); |
| 150 | 147 |
| 151 ASSERT_EQ(should_prompt, delegate_.has_prompted()); | 148 ASSERT_EQ(should_prompt, delegate_.has_prompted()); |
| 152 ASSERT_EQ(should_launch, delegate_.has_launched()); | 149 ASSERT_EQ(should_launch, delegate_.has_launched()); |
| 153 ASSERT_EQ(should_block, delegate_.has_blocked()); | 150 ASSERT_EQ(should_block, delegate_.has_blocked()); |
| 154 } | 151 } |
| 155 | 152 |
| 156 base::MessageLoopForUI ui_message_loop_; | 153 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| 157 content::TestBrowserThread ui_thread_; | |
| 158 content::TestBrowserThread file_thread_; | |
| 159 | 154 |
| 160 FakeExternalProtocolHandlerDelegate delegate_; | 155 FakeExternalProtocolHandlerDelegate delegate_; |
| 161 | 156 |
| 162 std::unique_ptr<TestingPrefServiceSimple> local_state_; | 157 std::unique_ptr<TestingPrefServiceSimple> local_state_; |
| 163 std::unique_ptr<TestingProfile> profile_; | 158 std::unique_ptr<TestingProfile> profile_; |
| 164 }; | 159 }; |
| 165 | 160 |
| 166 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeBlockedChromeDefault) { | 161 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeBlockedChromeDefault) { |
| 167 DoTest(ExternalProtocolHandler::BLOCK, shell_integration::IS_DEFAULT, false, | 162 DoTest(ExternalProtocolHandler::BLOCK, shell_integration::IS_DEFAULT, false, |
| 168 false, true); | 163 false, true); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 TEST_F(ExternalProtocolHandlerTest, TestClearProfileState) { | 259 TEST_F(ExternalProtocolHandlerTest, TestClearProfileState) { |
| 265 base::DictionaryValue prefs; | 260 base::DictionaryValue prefs; |
| 266 prefs.SetBoolean("tel", true); | 261 prefs.SetBoolean("tel", true); |
| 267 profile_->GetPrefs()->Set(prefs::kExcludedSchemes, prefs); | 262 profile_->GetPrefs()->Set(prefs::kExcludedSchemes, prefs); |
| 268 ASSERT_FALSE( | 263 ASSERT_FALSE( |
| 269 profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty()); | 264 profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| 270 ExternalProtocolHandler::ClearData(profile_.get()); | 265 ExternalProtocolHandler::ClearData(profile_.get()); |
| 271 ASSERT_TRUE( | 266 ASSERT_TRUE( |
| 272 profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty()); | 267 profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| 273 } | 268 } |
| OLD | NEW |