Chromium Code Reviews| Index: chrome/browser/external_protocol/external_protocol_handler_unittest.cc |
| diff --git a/chrome/browser/external_protocol/external_protocol_handler_unittest.cc b/chrome/browser/external_protocol/external_protocol_handler_unittest.cc |
| index e0c29f4d714b3dbbe6c3d7de2c6551cd9a6bd33d..2e5a048a14933d9f8a56f0570db5ffd407278a63 100644 |
| --- a/chrome/browser/external_protocol/external_protocol_handler_unittest.cc |
| +++ b/chrome/browser/external_protocol/external_protocol_handler_unittest.cc |
| @@ -6,6 +6,11 @@ |
| #include "base/message_loop/message_loop.h" |
| #include "base/run_loop.h" |
| +#include "chrome/browser/prefs/browser_prefs.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "chrome/test/base/testing_browser_process.h" |
| +#include "chrome/test/base/testing_profile.h" |
| +#include "components/prefs/testing_pref_service.h" |
| #include "content/public/test/test_browser_thread.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| @@ -53,7 +58,7 @@ class FakeExternalProtocolHandlerDelegate |
| } |
| ExternalProtocolHandler::BlockState GetBlockState( |
| - const std::string& scheme) override { |
| + const std::string& scheme, Profile* profile) override { |
| return block_state_; |
| } |
| @@ -111,11 +116,19 @@ class ExternalProtocolHandlerTest : public testing::Test { |
| : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), |
| file_thread_(BrowserThread::FILE) {} |
| - void SetUp() override { file_thread_.Start(); } |
| + void SetUp() override { |
| + file_thread_.Start(); |
| + local_state_.reset(new TestingPrefServiceSimple); |
| + profile_.reset(new TestingProfile()); |
| + chrome::RegisterLocalState(local_state_->registry()); |
| + TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.get()); |
| + } |
| void TearDown() override { |
| // Ensure that g_accept_requests gets set back to true after test execution. |
| ExternalProtocolHandler::PermitLaunchUrl(); |
| + TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); |
| + local_state_.reset(); |
| } |
| void DoTest(ExternalProtocolHandler::BlockState block_state, |
| @@ -145,6 +158,9 @@ class ExternalProtocolHandlerTest : public testing::Test { |
| content::TestBrowserThread file_thread_; |
| FakeExternalProtocolHandlerDelegate delegate_; |
| + |
| + std::unique_ptr<TestingPrefServiceSimple> local_state_; |
| + std::unique_ptr<TestingProfile> profile_; |
| }; |
| TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeBlockedChromeDefault) { |
| @@ -191,3 +207,57 @@ TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) { |
| DoTest(ExternalProtocolHandler::UNKNOWN, shell_integration::UNKNOWN_DEFAULT, |
| true, false, false); |
| } |
| + |
| +TEST_F(ExternalProtocolHandlerTest, TestGetBlockStateUnknown) { |
| + ExternalProtocolHandler::BlockState block_state = |
| + ExternalProtocolHandler::GetBlockState("tel", profile_.get()); |
|
meacer
2017/01/25 22:15:07
nit: Indentation seems off here (2 more spaces) an
ramyasharma
2017/01/30 00:16:45
Thanks Done.
|
| + ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state); |
| + ASSERT_TRUE(local_state_->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| + ASSERT_FALSE( |
| + profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| +} |
| + |
| +TEST_F(ExternalProtocolHandlerTest, TestGetBlockStateDefaultBlock) { |
| + ExternalProtocolHandler::BlockState block_state = |
| + ExternalProtocolHandler::GetBlockState("afp", profile_.get()); |
| + ASSERT_EQ(ExternalProtocolHandler::BLOCK, block_state); |
| + ASSERT_TRUE(local_state_->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| + ASSERT_FALSE( |
| + profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| +} |
| + |
| +TEST_F(ExternalProtocolHandlerTest, TestGetBlockStateDefaultDontBlock) { |
| + ExternalProtocolHandler::BlockState block_state = |
| + ExternalProtocolHandler::GetBlockState("mailto", profile_.get()); |
| + ASSERT_EQ(ExternalProtocolHandler::DONT_BLOCK, block_state); |
| + ASSERT_TRUE(local_state_->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| + ASSERT_FALSE( |
| + profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| +} |
| + |
| +TEST_F(ExternalProtocolHandlerTest, |
| + TestGetBlockStateLocalBlockStateCopiedAndResetOnProfilePref) { |
|
meacer
2017/01/25 22:15:07
nit: Indentation, here and below.
ramyasharma
2017/01/30 00:16:45
Done.
|
| + base::DictionaryValue prefs_local; |
| + prefs_local.SetBoolean("tel", true); |
| + local_state_->Set(prefs::kExcludedSchemes, prefs_local); |
| + ExternalProtocolHandler::BlockState block_state = |
| + ExternalProtocolHandler::GetBlockState("tel", profile_.get()); |
| + ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state); |
| + ASSERT_TRUE(local_state_->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| + ASSERT_FALSE( |
| + profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| +} |
| + |
| +TEST_F(ExternalProtocolHandlerTest, |
| + TestGetBlockStateLocalDontBlockCopiedAsIsToProfilePref) { |
| + base::DictionaryValue prefs_local; |
| + prefs_local.SetBoolean("tel", false); |
| + local_state_->Set(prefs::kExcludedSchemes, prefs_local); |
| + ExternalProtocolHandler::BlockState block_state = |
| + ExternalProtocolHandler::GetBlockState("tel", profile_.get()); |
| + ASSERT_EQ(ExternalProtocolHandler::DONT_BLOCK, block_state); |
| + ASSERT_TRUE(local_state_->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| + ASSERT_FALSE( |
| + profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty()); |
| +} |
| + |