Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2797)

Unified Diff: chrome/browser/external_protocol/external_protocol_handler_unittest.cc

Issue 2623033006: [Re-landing] Migrate external protocol prefs from local state to profiles (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..62e4c31f4c3201accb7c763a9e3540e27050483f 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"
@@ -52,8 +57,8 @@ class FakeExternalProtocolHandlerDelegate
return new FakeExternalProtocolHandlerWorker(callback, protocol, os_state_);
}
- ExternalProtocolHandler::BlockState GetBlockState(
- const std::string& scheme) override {
+ ExternalProtocolHandler::BlockState GetBlockState(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,56 @@ 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);
+ 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) {
+ 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());
+}
« no previous file with comments | « chrome/browser/external_protocol/external_protocol_handler.cc ('k') | chrome/browser/prerender/prerender_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698