OLD | NEW |
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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/prefs/pref_service.h" | |
21 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
22 #include "base/values.h" | 21 #include "base/values.h" |
23 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
24 #include "chrome/browser/extensions/api/gcm/gcm_api.h" | 23 #include "chrome/browser/extensions/api/gcm/gcm_api.h" |
25 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
26 #include "chrome/browser/extensions/test_extension_service.h" | 25 #include "chrome/browser/extensions/test_extension_service.h" |
27 #include "chrome/browser/extensions/test_extension_system.h" | 26 #include "chrome/browser/extensions/test_extension_system.h" |
28 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
29 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 28 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
30 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 29 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
31 #include "chrome/common/chrome_paths.h" | 30 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/pref_names.h" | |
33 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
34 #include "components/gcm_driver/fake_gcm_app_handler.h" | 32 #include "components/gcm_driver/fake_gcm_app_handler.h" |
35 #include "components/gcm_driver/fake_gcm_client.h" | 33 #include "components/gcm_driver/fake_gcm_client.h" |
36 #include "components/gcm_driver/fake_gcm_client_factory.h" | 34 #include "components/gcm_driver/fake_gcm_client_factory.h" |
37 #include "components/gcm_driver/gcm_client_factory.h" | 35 #include "components/gcm_driver/gcm_client_factory.h" |
38 #include "components/gcm_driver/gcm_driver.h" | 36 #include "components/gcm_driver/gcm_driver.h" |
39 #include "components/keyed_service/core/keyed_service.h" | 37 #include "components/keyed_service/core/keyed_service.h" |
40 #include "content/public/browser/browser_context.h" | 38 #include "content/public/browser/browser_context.h" |
41 #include "content/public/browser/browser_thread.h" | 39 #include "content/public/browser/browser_thread.h" |
42 #include "content/public/test/test_browser_thread_bundle.h" | 40 #include "content/public/test/test_browser_thread_bundle.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))); | 224 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))); |
227 base::FilePath extensions_install_dir = | 225 base::FilePath extensions_install_dir = |
228 temp_dir_.path().Append(FILE_PATH_LITERAL("Extensions")); | 226 temp_dir_.path().Append(FILE_PATH_LITERAL("Extensions")); |
229 extension_system->CreateExtensionService( | 227 extension_system->CreateExtensionService( |
230 base::CommandLine::ForCurrentProcess(), extensions_install_dir, false); | 228 base::CommandLine::ForCurrentProcess(), extensions_install_dir, false); |
231 extension_service_ = extension_system->Get(profile())->extension_service(); | 229 extension_service_ = extension_system->Get(profile())->extension_service(); |
232 extension_service_->set_extensions_enabled(true); | 230 extension_service_->set_extensions_enabled(true); |
233 extension_service_->set_show_extensions_prompts(false); | 231 extension_service_->set_show_extensions_prompts(false); |
234 extension_service_->set_install_updates_when_idle_for_test(false); | 232 extension_service_->set_install_updates_when_idle_for_test(false); |
235 | 233 |
236 // Enable GCM such that tests could be run on all channels. | |
237 profile()->GetPrefs()->SetBoolean(prefs::kGCMChannelEnabled, true); | |
238 | |
239 // Create GCMProfileService that talks with fake GCMClient. | 234 // Create GCMProfileService that talks with fake GCMClient. |
240 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 235 gcm::GCMProfileServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
241 profile(), &ExtensionGCMAppHandlerTest::BuildGCMProfileService); | 236 profile(), &ExtensionGCMAppHandlerTest::BuildGCMProfileService); |
242 | 237 |
243 // Create a fake version of ExtensionGCMAppHandler. | 238 // Create a fake version of ExtensionGCMAppHandler. |
244 gcm_app_handler_.reset(new FakeExtensionGCMAppHandler(profile(), &waiter_)); | 239 gcm_app_handler_.reset(new FakeExtensionGCMAppHandler(profile(), &waiter_)); |
245 } | 240 } |
246 | 241 |
247 void TearDown() override { | 242 void TearDown() override { |
248 #if defined(OS_CHROMEOS) | 243 #if defined(OS_CHROMEOS) |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 457 |
463 // App handler is removed when the extension is updated to the version that | 458 // App handler is removed when the extension is updated to the version that |
464 // has GCM permission removed. | 459 // has GCM permission removed. |
465 UpdateExtension(extension.get(), "good2.crx"); | 460 UpdateExtension(extension.get(), "good2.crx"); |
466 waiter()->PumpUILoop(); | 461 waiter()->PumpUILoop(); |
467 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); | 462 EXPECT_TRUE(gcm_app_handler()->app_handler_count_drop_to_zero()); |
468 EXPECT_FALSE(HasAppHandlers(extension->id())); | 463 EXPECT_FALSE(HasAppHandlers(extension->id())); |
469 } | 464 } |
470 | 465 |
471 } // namespace extensions | 466 } // namespace extensions |
OLD | NEW |