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

Side by Side Diff: chrome/browser/external_protocol/external_protocol_handler_unittest.cc

Issue 2660333004: Revert of Migrate external protocol prefs from local state to profiles (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
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"
10 #include "chrome/common/pref_names.h"
11 #include "chrome/test/base/testing_browser_process.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "components/prefs/testing_pref_service.h"
14 #include "content/public/test/test_browser_thread.h" 9 #include "content/public/test/test_browser_thread.h"
15 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
16 11
17 using content::BrowserThread; 12 using content::BrowserThread;
18 13
19 class FakeExternalProtocolHandlerWorker 14 class FakeExternalProtocolHandlerWorker
20 : public shell_integration::DefaultProtocolClientWorker { 15 : public shell_integration::DefaultProtocolClientWorker {
21 public: 16 public:
22 FakeExternalProtocolHandlerWorker( 17 FakeExternalProtocolHandlerWorker(
23 const shell_integration::DefaultWebClientWorkerCallback& callback, 18 const shell_integration::DefaultWebClientWorkerCallback& callback,
(...skipping 26 matching lines...) Expand all
50 has_prompted_(false), 45 has_prompted_(false),
51 has_blocked_(false) {} 46 has_blocked_(false) {}
52 47
53 scoped_refptr<shell_integration::DefaultProtocolClientWorker> 48 scoped_refptr<shell_integration::DefaultProtocolClientWorker>
54 CreateShellWorker( 49 CreateShellWorker(
55 const shell_integration::DefaultWebClientWorkerCallback& callback, 50 const shell_integration::DefaultWebClientWorkerCallback& callback,
56 const std::string& protocol) override { 51 const std::string& protocol) override {
57 return new FakeExternalProtocolHandlerWorker(callback, protocol, os_state_); 52 return new FakeExternalProtocolHandlerWorker(callback, protocol, os_state_);
58 } 53 }
59 54
60 ExternalProtocolHandler::BlockState GetBlockState(const std::string& scheme, 55 ExternalProtocolHandler::BlockState GetBlockState(
61 Profile* profile) override { 56 const std::string& scheme) override {
62 return block_state_; 57 return block_state_;
63 } 58 }
64 59
65 void BlockRequest() override { 60 void BlockRequest() override {
66 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK || 61 ASSERT_TRUE(block_state_ == ExternalProtocolHandler::BLOCK ||
67 os_state_ == shell_integration::IS_DEFAULT); 62 os_state_ == shell_integration::IS_DEFAULT);
68 has_blocked_ = true; 63 has_blocked_ = true;
69 } 64 }
70 65
71 void RunExternalProtocolDialog(const GURL& url, 66 void RunExternalProtocolDialog(const GURL& url,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 bool has_prompted_; 104 bool has_prompted_;
110 bool has_blocked_; 105 bool has_blocked_;
111 }; 106 };
112 107
113 class ExternalProtocolHandlerTest : public testing::Test { 108 class ExternalProtocolHandlerTest : public testing::Test {
114 protected: 109 protected:
115 ExternalProtocolHandlerTest() 110 ExternalProtocolHandlerTest()
116 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), 111 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
117 file_thread_(BrowserThread::FILE) {} 112 file_thread_(BrowserThread::FILE) {}
118 113
119 void SetUp() override { 114 void SetUp() override { file_thread_.Start(); }
120 file_thread_.Start();
121 local_state_.reset(new TestingPrefServiceSimple);
122 profile_.reset(new TestingProfile());
123 chrome::RegisterLocalState(local_state_->registry());
124 TestingBrowserProcess::GetGlobal()->SetLocalState(local_state_.get());
125 }
126 115
127 void TearDown() override { 116 void TearDown() override {
128 // Ensure that g_accept_requests gets set back to true after test execution. 117 // Ensure that g_accept_requests gets set back to true after test execution.
129 ExternalProtocolHandler::PermitLaunchUrl(); 118 ExternalProtocolHandler::PermitLaunchUrl();
130 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
131 local_state_.reset();
132 } 119 }
133 120
134 void DoTest(ExternalProtocolHandler::BlockState block_state, 121 void DoTest(ExternalProtocolHandler::BlockState block_state,
135 shell_integration::DefaultWebClientState os_state, 122 shell_integration::DefaultWebClientState os_state,
136 bool should_prompt, 123 bool should_prompt,
137 bool should_launch, 124 bool should_launch,
138 bool should_block) { 125 bool should_block) {
139 GURL url("mailto:test@test.com"); 126 GURL url("mailto:test@test.com");
140 ASSERT_FALSE(delegate_.has_prompted()); 127 ASSERT_FALSE(delegate_.has_prompted());
141 ASSERT_FALSE(delegate_.has_launched()); 128 ASSERT_FALSE(delegate_.has_launched());
142 ASSERT_FALSE(delegate_.has_blocked()); 129 ASSERT_FALSE(delegate_.has_blocked());
143 130
144 delegate_.set_block_state(block_state); 131 delegate_.set_block_state(block_state);
145 delegate_.set_os_state(os_state); 132 delegate_.set_os_state(os_state);
146 ExternalProtocolHandler::LaunchUrlWithDelegate( 133 ExternalProtocolHandler::LaunchUrlWithDelegate(
147 url, 0, 0, ui::PAGE_TRANSITION_LINK, true, &delegate_); 134 url, 0, 0, ui::PAGE_TRANSITION_LINK, true, &delegate_);
148 if (block_state != ExternalProtocolHandler::BLOCK) 135 if (block_state != ExternalProtocolHandler::BLOCK)
149 base::RunLoop().Run(); 136 base::RunLoop().Run();
150 137
151 ASSERT_EQ(should_prompt, delegate_.has_prompted()); 138 ASSERT_EQ(should_prompt, delegate_.has_prompted());
152 ASSERT_EQ(should_launch, delegate_.has_launched()); 139 ASSERT_EQ(should_launch, delegate_.has_launched());
153 ASSERT_EQ(should_block, delegate_.has_blocked()); 140 ASSERT_EQ(should_block, delegate_.has_blocked());
154 } 141 }
155 142
156 base::MessageLoopForUI ui_message_loop_; 143 base::MessageLoopForUI ui_message_loop_;
157 content::TestBrowserThread ui_thread_; 144 content::TestBrowserThread ui_thread_;
158 content::TestBrowserThread file_thread_; 145 content::TestBrowserThread file_thread_;
159 146
160 FakeExternalProtocolHandlerDelegate delegate_; 147 FakeExternalProtocolHandlerDelegate delegate_;
161
162 std::unique_ptr<TestingPrefServiceSimple> local_state_;
163 std::unique_ptr<TestingProfile> profile_;
164 }; 148 };
165 149
166 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeBlockedChromeDefault) { 150 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeBlockedChromeDefault) {
167 DoTest(ExternalProtocolHandler::BLOCK, shell_integration::IS_DEFAULT, false, 151 DoTest(ExternalProtocolHandler::BLOCK, shell_integration::IS_DEFAULT, false,
168 false, true); 152 false, true);
169 } 153 }
170 154
171 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeBlockedChromeNotDefault) { 155 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeBlockedChromeNotDefault) {
172 DoTest(ExternalProtocolHandler::BLOCK, shell_integration::NOT_DEFAULT, false, 156 DoTest(ExternalProtocolHandler::BLOCK, shell_integration::NOT_DEFAULT, false,
173 false, true); 157 false, true);
(...skipping 26 matching lines...) Expand all
200 184
201 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeNotDefault) { 185 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeNotDefault) {
202 DoTest(ExternalProtocolHandler::UNKNOWN, shell_integration::NOT_DEFAULT, true, 186 DoTest(ExternalProtocolHandler::UNKNOWN, shell_integration::NOT_DEFAULT, true,
203 false, false); 187 false, false);
204 } 188 }
205 189
206 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) { 190 TEST_F(ExternalProtocolHandlerTest, TestLaunchSchemeUnknownChromeUnknown) {
207 DoTest(ExternalProtocolHandler::UNKNOWN, shell_integration::UNKNOWN_DEFAULT, 191 DoTest(ExternalProtocolHandler::UNKNOWN, shell_integration::UNKNOWN_DEFAULT,
208 true, false, false); 192 true, false, false);
209 } 193 }
210
211 TEST_F(ExternalProtocolHandlerTest, TestGetBlockStateUnknown) {
212 ExternalProtocolHandler::BlockState block_state =
213 ExternalProtocolHandler::GetBlockState("tel", profile_.get());
214 ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state);
215 ASSERT_TRUE(local_state_->GetDictionary(prefs::kExcludedSchemes)->empty());
216 ASSERT_FALSE(
217 profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty());
218 }
219
220 TEST_F(ExternalProtocolHandlerTest, TestGetBlockStateDefaultBlock) {
221 ExternalProtocolHandler::BlockState block_state =
222 ExternalProtocolHandler::GetBlockState("afp", profile_.get());
223 ASSERT_EQ(ExternalProtocolHandler::BLOCK, block_state);
224 ASSERT_TRUE(local_state_->GetDictionary(prefs::kExcludedSchemes)->empty());
225 ASSERT_FALSE(
226 profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty());
227 }
228
229 TEST_F(ExternalProtocolHandlerTest, TestGetBlockStateDefaultDontBlock) {
230 ExternalProtocolHandler::BlockState block_state =
231 ExternalProtocolHandler::GetBlockState("mailto", profile_.get());
232 ASSERT_EQ(ExternalProtocolHandler::DONT_BLOCK, block_state);
233 ASSERT_TRUE(local_state_->GetDictionary(prefs::kExcludedSchemes)->empty());
234 ASSERT_FALSE(
235 profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty());
236 }
237
238 TEST_F(ExternalProtocolHandlerTest,
239 TestGetBlockStateLocalBlockStateCopiedAndResetOnProfilePref) {
240 base::DictionaryValue prefs_local;
241 prefs_local.SetBoolean("tel", true);
242 local_state_->Set(prefs::kExcludedSchemes, prefs_local);
243 ExternalProtocolHandler::BlockState block_state =
244 ExternalProtocolHandler::GetBlockState("tel", profile_.get());
245 ASSERT_EQ(ExternalProtocolHandler::UNKNOWN, block_state);
246 ASSERT_TRUE(local_state_->GetDictionary(prefs::kExcludedSchemes)->empty());
247 ASSERT_FALSE(
248 profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty());
249 }
250
251 TEST_F(ExternalProtocolHandlerTest,
252 TestGetBlockStateLocalDontBlockCopiedAsIsToProfilePref) {
253 base::DictionaryValue prefs_local;
254 prefs_local.SetBoolean("tel", false);
255 local_state_->Set(prefs::kExcludedSchemes, prefs_local);
256 ExternalProtocolHandler::BlockState block_state =
257 ExternalProtocolHandler::GetBlockState("tel", profile_.get());
258 ASSERT_EQ(ExternalProtocolHandler::DONT_BLOCK, block_state);
259 ASSERT_TRUE(local_state_->GetDictionary(prefs::kExcludedSchemes)->empty());
260 ASSERT_FALSE(
261 profile_->GetPrefs()->GetDictionary(prefs::kExcludedSchemes)->empty());
262 }
OLDNEW
« 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