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..65751953f1ca3fe9d9f6ef67a18d5ea0dc7f821f 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(NULL); |
|
dominickn
2017/01/19 07:01:22
Nit: use nullptr instead of NULL
ramyasharma
2017/01/20 04:04:45
Done.
|
| + 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,42 @@ 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()); |
| + ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state); |
| +} |
| + |
| +TEST_F(ExternalProtocolHandlerTest, TestGetBlockStateDefaultBlock) { |
| + ExternalProtocolHandler::BlockState block_state = |
| + ExternalProtocolHandler::GetBlockState("afp", profile_.get()); |
| + ASSERT_EQ(ExternalProtocolHandler::BLOCK, block_state); |
| +} |
| + |
| +TEST_F(ExternalProtocolHandlerTest, TestGetBlockStateDefaultDontBlock) { |
| + ExternalProtocolHandler::BlockState block_state = |
| + ExternalProtocolHandler::GetBlockState("mailto", profile_.get()); |
| + ASSERT_EQ(ExternalProtocolHandler::DONT_BLOCK, block_state); |
| +} |
| + |
| +TEST_F(ExternalProtocolHandlerTest, |
| + TestGetBlockStateLocalBlockResetOnProfilePref) { |
| + 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); |
|
dominickn
2017/01/19 07:01:22
Can you assert that the local_state_ pref is empty
ramyasharma
2017/01/20 04:04:45
Added a check to local state, to ensure it has not
|
| +} |
| + |
| +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); |
|
dominickn
2017/01/19 07:01:22
Ditto
ramyasharma
2017/01/20 04:04:45
Done.
|
| +} |
| + |