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

Side by Side Diff: chrome/browser/extensions/extension_gcm_app_handler_unittest.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extensions/extension_gcm_app_handler.h" 5 #include "chrome/browser/extensions/extension_gcm_app_handler.h"
6 6
7 #include <memory>
7 #include <vector> 8 #include <vector>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
11 #include "base/command_line.h" 12 #include "base/command_line.h"
12 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 14 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 15 #include "base/files/scoped_temp_dir.h"
15 #include "base/location.h" 16 #include "base/location.h"
16 #include "base/logging.h" 17 #include "base/logging.h"
17 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/ptr_util.h"
18 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/message_loop/message_loop.h" 21 #include "base/message_loop/message_loop.h"
21 #include "base/path_service.h" 22 #include "base/path_service.h"
22 #include "base/run_loop.h" 23 #include "base/run_loop.h"
23 #include "base/values.h" 24 #include "base/values.h"
24 #include "build/build_config.h" 25 #include "build/build_config.h"
25 #include "chrome/browser/chrome_notification_types.h" 26 #include "chrome/browser/chrome_notification_types.h"
26 #include "chrome/browser/extensions/api/gcm/gcm_api.h" 27 #include "chrome/browser/extensions/api/gcm/gcm_api.h"
27 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
28 #include "chrome/browser/extensions/test_extension_service.h" 29 #include "chrome/browser/extensions/test_extension_service.h"
29 #include "chrome/browser/extensions/test_extension_system.h" 30 #include "chrome/browser/extensions/test_extension_system.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 123
123 void OnIOLoopPumpCompleted() { 124 void OnIOLoopPumpCompleted() {
124 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 125 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
125 126
126 content::BrowserThread::PostTask( 127 content::BrowserThread::PostTask(
127 content::BrowserThread::UI, 128 content::BrowserThread::UI,
128 FROM_HERE, 129 FROM_HERE,
129 base::Bind(&Waiter::PumpIOLoopCompleted, base::Unretained(this))); 130 base::Bind(&Waiter::PumpIOLoopCompleted, base::Unretained(this)));
130 } 131 }
131 132
132 scoped_ptr<base::RunLoop> run_loop_; 133 std::unique_ptr<base::RunLoop> run_loop_;
133 134
134 DISALLOW_COPY_AND_ASSIGN(Waiter); 135 DISALLOW_COPY_AND_ASSIGN(Waiter);
135 }; 136 };
136 137
137 class FakeExtensionGCMAppHandler : public ExtensionGCMAppHandler { 138 class FakeExtensionGCMAppHandler : public ExtensionGCMAppHandler {
138 public: 139 public:
139 FakeExtensionGCMAppHandler(Profile* profile, Waiter* waiter) 140 FakeExtensionGCMAppHandler(Profile* profile, Waiter* waiter)
140 : ExtensionGCMAppHandler(profile), 141 : ExtensionGCMAppHandler(profile),
141 waiter_(waiter), 142 waiter_(waiter),
142 unregistration_result_(gcm::GCMClient::UNKNOWN_ERROR), 143 unregistration_result_(gcm::GCMClient::UNKNOWN_ERROR),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 Waiter* waiter_; 189 Waiter* waiter_;
189 gcm::GCMClient::Result unregistration_result_; 190 gcm::GCMClient::Result unregistration_result_;
190 instance_id::InstanceID::Result delete_id_result_; 191 instance_id::InstanceID::Result delete_id_result_;
191 bool app_handler_count_drop_to_zero_; 192 bool app_handler_count_drop_to_zero_;
192 193
193 DISALLOW_COPY_AND_ASSIGN(FakeExtensionGCMAppHandler); 194 DISALLOW_COPY_AND_ASSIGN(FakeExtensionGCMAppHandler);
194 }; 195 };
195 196
196 class ExtensionGCMAppHandlerTest : public testing::Test { 197 class ExtensionGCMAppHandlerTest : public testing::Test {
197 public: 198 public:
198 static scoped_ptr<KeyedService> BuildGCMProfileService( 199 static std::unique_ptr<KeyedService> BuildGCMProfileService(
199 content::BrowserContext* context) { 200 content::BrowserContext* context) {
200 Profile* profile = Profile::FromBrowserContext(context); 201 Profile* profile = Profile::FromBrowserContext(context);
201 scoped_refptr<base::SequencedTaskRunner> ui_thread = 202 scoped_refptr<base::SequencedTaskRunner> ui_thread =
202 content::BrowserThread::GetMessageLoopProxyForThread( 203 content::BrowserThread::GetMessageLoopProxyForThread(
203 content::BrowserThread::UI); 204 content::BrowserThread::UI);
204 scoped_refptr<base::SequencedTaskRunner> io_thread = 205 scoped_refptr<base::SequencedTaskRunner> io_thread =
205 content::BrowserThread::GetMessageLoopProxyForThread( 206 content::BrowserThread::GetMessageLoopProxyForThread(
206 content::BrowserThread::IO); 207 content::BrowserThread::IO);
207 base::SequencedWorkerPool* worker_pool = 208 base::SequencedWorkerPool* worker_pool =
208 content::BrowserThread::GetBlockingPool(); 209 content::BrowserThread::GetBlockingPool();
209 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( 210 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
210 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( 211 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
211 worker_pool->GetSequenceToken(), 212 worker_pool->GetSequenceToken(),
212 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); 213 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
213 return make_scoped_ptr(new gcm::GCMProfileService( 214 return base::WrapUnique(new gcm::GCMProfileService(
214 profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(), 215 profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(),
215 chrome::GetChannel(), 216 chrome::GetChannel(),
216 scoped_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider( 217 std::unique_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider(
217 SigninManagerFactory::GetForProfile(profile), 218 SigninManagerFactory::GetForProfile(profile),
218 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), 219 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
219 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile( 220 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(
220 profile))), 221 profile))),
221 make_scoped_ptr(new gcm::FakeGCMClientFactory(ui_thread, io_thread)), 222 base::WrapUnique(new gcm::FakeGCMClientFactory(ui_thread, io_thread)),
222 ui_thread, io_thread, blocking_task_runner)); 223 ui_thread, io_thread, blocking_task_runner));
223 } 224 }
224 225
225 ExtensionGCMAppHandlerTest() 226 ExtensionGCMAppHandlerTest()
226 : extension_service_(NULL), 227 : extension_service_(NULL),
227 registration_result_(gcm::GCMClient::UNKNOWN_ERROR), 228 registration_result_(gcm::GCMClient::UNKNOWN_ERROR),
228 unregistration_result_(gcm::GCMClient::UNKNOWN_ERROR) { 229 unregistration_result_(gcm::GCMClient::UNKNOWN_ERROR) {
229 } 230 }
230 231
231 ~ExtensionGCMAppHandlerTest() override {} 232 ~ExtensionGCMAppHandlerTest() override {}
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 return gcm_app_handler_.get(); 390 return gcm_app_handler_.get();
390 } 391 }
391 gcm::GCMClient::Result registration_result() const { 392 gcm::GCMClient::Result registration_result() const {
392 return registration_result_; 393 return registration_result_;
393 } 394 }
394 gcm::GCMClient::Result unregistration_result() const { 395 gcm::GCMClient::Result unregistration_result() const {
395 return unregistration_result_; 396 return unregistration_result_;
396 } 397 }
397 398
398 private: 399 private:
399 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; 400 std::unique_ptr<content::TestBrowserThreadBundle> thread_bundle_;
400 scoped_ptr<content::InProcessUtilityThreadHelper> 401 std::unique_ptr<content::InProcessUtilityThreadHelper>
401 in_process_utility_thread_helper_; 402 in_process_utility_thread_helper_;
402 scoped_ptr<TestingProfile> profile_; 403 std::unique_ptr<TestingProfile> profile_;
403 ExtensionService* extension_service_; // Not owned. 404 ExtensionService* extension_service_; // Not owned.
404 base::ScopedTempDir temp_dir_; 405 base::ScopedTempDir temp_dir_;
405 406
406 // This is needed to create extension service under CrOS. 407 // This is needed to create extension service under CrOS.
407 #if defined(OS_CHROMEOS) 408 #if defined(OS_CHROMEOS)
408 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 409 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
409 chromeos::ScopedTestCrosSettings test_cros_settings_; 410 chromeos::ScopedTestCrosSettings test_cros_settings_;
410 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; 411 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_;
411 #endif 412 #endif
412 413
413 Waiter waiter_; 414 Waiter waiter_;
414 scoped_ptr<FakeExtensionGCMAppHandler> gcm_app_handler_; 415 std::unique_ptr<FakeExtensionGCMAppHandler> gcm_app_handler_;
415 gcm::GCMClient::Result registration_result_; 416 gcm::GCMClient::Result registration_result_;
416 gcm::GCMClient::Result unregistration_result_; 417 gcm::GCMClient::Result unregistration_result_;
417 418
418 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandlerTest); 419 DISALLOW_COPY_AND_ASSIGN(ExtensionGCMAppHandlerTest);
419 }; 420 };
420 421
421 TEST_F(ExtensionGCMAppHandlerTest, AddAndRemoveAppHandler) { 422 TEST_F(ExtensionGCMAppHandlerTest, AddAndRemoveAppHandler) {
422 scoped_refptr<Extension> extension(CreateExtension()); 423 scoped_refptr<Extension> extension(CreateExtension());
423 424
424 // App handler is added when extension is loaded. 425 // App handler is added when extension is loaded.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 489
489 // App handler is removed when the extension is updated to the version that 490 // App handler is removed when the extension is updated to the version that
490 // has GCM permission removed. 491 // has GCM permission removed.
491 UpdateExtension(extension.get(), "good2.crx"); 492 UpdateExtension(extension.get(), "good2.crx");
492 waiter()->PumpUILoop(); 493 waiter()->PumpUILoop();
493 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); 494 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero());
494 EXPECT_FALSE(HasAppHandlers(extension->id())); 495 EXPECT_FALSE(HasAppHandlers(extension->id()));
495 } 496 }
496 497
497 } // namespace extensions 498 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698