| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/background/background_mode_manager.h" | 9 #include "chrome/browser/background/background_mode_manager.h" |
| 10 #include "chrome/browser/browser_shutdown.h" | 10 #include "chrome/browser/browser_shutdown.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "chrome/browser/chromeos/settings/cros_settings.h" | 31 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 32 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 32 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // Helper class that tracks state transitions in BackgroundModeManager and | 37 // Helper class that tracks state transitions in BackgroundModeManager and |
| 38 // exposes them via getters. | 38 // exposes them via getters. |
| 39 class SimpleTestBackgroundModeManager : public BackgroundModeManager { | 39 class SimpleTestBackgroundModeManager : public BackgroundModeManager { |
| 40 public: | 40 public: |
| 41 SimpleTestBackgroundModeManager( | 41 SimpleTestBackgroundModeManager(base::CommandLine* command_line, |
| 42 CommandLine* command_line, ProfileInfoCache* cache) | 42 ProfileInfoCache* cache) |
| 43 : BackgroundModeManager(command_line, cache), | 43 : BackgroundModeManager(command_line, cache), |
| 44 have_status_tray_(false), | 44 have_status_tray_(false), |
| 45 launch_on_startup_(false), | 45 launch_on_startup_(false), |
| 46 has_shown_balloon_(false) { | 46 has_shown_balloon_(false) { |
| 47 ResumeBackgroundMode(); | 47 ResumeBackgroundMode(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void EnableLaunchOnStartup(bool launch) override { | 50 void EnableLaunchOnStartup(bool launch) override { |
| 51 launch_on_startup_ = launch; | 51 launch_on_startup_ = launch; |
| 52 } | 52 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 DISALLOW_COPY_AND_ASSIGN(TestStatusIcon); | 86 DISALLOW_COPY_AND_ASSIGN(TestStatusIcon); |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 // More complex test helper that exposes APIs for fine grained control of | 91 // More complex test helper that exposes APIs for fine grained control of |
| 92 // things like the number of background applications. This allows writing | 92 // things like the number of background applications. This allows writing |
| 93 // smaller tests that don't have to install/uninstall extensions. | 93 // smaller tests that don't have to install/uninstall extensions. |
| 94 class TestBackgroundModeManager : public SimpleTestBackgroundModeManager { | 94 class TestBackgroundModeManager : public SimpleTestBackgroundModeManager { |
| 95 public: | 95 public: |
| 96 TestBackgroundModeManager( | 96 TestBackgroundModeManager(base::CommandLine* command_line, |
| 97 CommandLine* command_line, ProfileInfoCache* cache, bool enabled) | 97 ProfileInfoCache* cache, |
| 98 bool enabled) |
| 98 : SimpleTestBackgroundModeManager(command_line, cache), | 99 : SimpleTestBackgroundModeManager(command_line, cache), |
| 99 enabled_(enabled), | 100 enabled_(enabled), |
| 100 app_count_(0), | 101 app_count_(0), |
| 101 profile_app_count_(0) { | 102 profile_app_count_(0) { |
| 102 ResumeBackgroundMode(); | 103 ResumeBackgroundMode(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 int GetBackgroundAppCount() const override { return app_count_; } | 106 int GetBackgroundAppCount() const override { return app_count_; } |
| 106 int GetBackgroundAppCountForProfile(Profile* const profile) const override { | 107 int GetBackgroundAppCountForProfile(Profile* const profile) const override { |
| 107 return profile_app_count_; | 108 return profile_app_count_; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 EXPECT_TRUE(manager.IsLaunchOnStartup()); | 148 EXPECT_TRUE(manager.IsLaunchOnStartup()); |
| 148 } | 149 } |
| 149 | 150 |
| 150 } // namespace | 151 } // namespace |
| 151 | 152 |
| 152 class BackgroundModeManagerTest : public testing::Test { | 153 class BackgroundModeManagerTest : public testing::Test { |
| 153 public: | 154 public: |
| 154 BackgroundModeManagerTest() {} | 155 BackgroundModeManagerTest() {} |
| 155 ~BackgroundModeManagerTest() override {} | 156 ~BackgroundModeManagerTest() override {} |
| 156 void SetUp() override { | 157 void SetUp() override { |
| 157 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 158 command_line_.reset(new base::CommandLine(base::CommandLine::NO_PROGRAM)); |
| 158 profile_manager_ = CreateTestingProfileManager(); | 159 profile_manager_ = CreateTestingProfileManager(); |
| 159 profile_ = profile_manager_->CreateTestingProfile("p1"); | 160 profile_ = profile_manager_->CreateTestingProfile("p1"); |
| 160 } | 161 } |
| 161 scoped_ptr<CommandLine> command_line_; | 162 scoped_ptr<base::CommandLine> command_line_; |
| 162 | 163 |
| 163 protected: | 164 protected: |
| 164 scoped_refptr<extensions::Extension> CreateExtension( | 165 scoped_refptr<extensions::Extension> CreateExtension( |
| 165 extensions::Manifest::Location location, | 166 extensions::Manifest::Location location, |
| 166 const std::string& data, | 167 const std::string& data, |
| 167 const std::string& id) { | 168 const std::string& id) { |
| 168 scoped_ptr<base::DictionaryValue> parsed_manifest( | 169 scoped_ptr<base::DictionaryValue> parsed_manifest( |
| 169 extension_function_test_utils::ParseDictionary(data)); | 170 extension_function_test_utils::ParseDictionary(data)); |
| 170 return extension_function_test_utils::CreateExtension( | 171 return extension_function_test_utils::CreateExtension( |
| 171 location, | 172 location, |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 CreateExtension( | 590 CreateExtension( |
| 590 extensions::Manifest::COMMAND_LINE, | 591 extensions::Manifest::COMMAND_LINE, |
| 591 "{\"name\": \"Regular Extension with Options\"," | 592 "{\"name\": \"Regular Extension with Options\"," |
| 592 "\"version\": \"1.0\"," | 593 "\"version\": \"1.0\"," |
| 593 "\"manifest_version\": 2," | 594 "\"manifest_version\": 2," |
| 594 "\"permissions\": [\"background\"]," | 595 "\"permissions\": [\"background\"]," |
| 595 "\"options_page\": \"test.html\"}", | 596 "\"options_page\": \"test.html\"}", |
| 596 "ID-4")); | 597 "ID-4")); |
| 597 | 598 |
| 598 static_cast<extensions::TestExtensionSystem*>( | 599 static_cast<extensions::TestExtensionSystem*>( |
| 599 extensions::ExtensionSystem::Get(profile_))->CreateExtensionService( | 600 extensions::ExtensionSystem::Get(profile_)) |
| 600 CommandLine::ForCurrentProcess(), | 601 ->CreateExtensionService(base::CommandLine::ForCurrentProcess(), |
| 601 base::FilePath(), | 602 base::FilePath(), false); |
| 602 false); | |
| 603 ExtensionService* service = | 603 ExtensionService* service = |
| 604 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 604 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 605 service->Init(); | 605 service->Init(); |
| 606 | 606 |
| 607 service->AddComponentExtension(component_extension.get()); | 607 service->AddComponentExtension(component_extension.get()); |
| 608 service->AddComponentExtension(component_extension_with_options.get()); | 608 service->AddComponentExtension(component_extension_with_options.get()); |
| 609 service->AddExtension(regular_extension.get()); | 609 service->AddExtension(regular_extension.get()); |
| 610 service->AddExtension(regular_extension_with_options.get()); | 610 service->AddExtension(regular_extension_with_options.get()); |
| 611 | 611 |
| 612 scoped_ptr<StatusIconMenuModel> menu(new StatusIconMenuModel(NULL)); | 612 scoped_ptr<StatusIconMenuModel> menu(new StatusIconMenuModel(NULL)); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 CreateExtension( | 667 CreateExtension( |
| 668 extensions::Manifest::COMMAND_LINE, | 668 extensions::Manifest::COMMAND_LINE, |
| 669 "{\"name\": \"Regular Extension with Options\"," | 669 "{\"name\": \"Regular Extension with Options\"," |
| 670 "\"version\": \"1.0\"," | 670 "\"version\": \"1.0\"," |
| 671 "\"manifest_version\": 2," | 671 "\"manifest_version\": 2," |
| 672 "\"permissions\": [\"background\"]," | 672 "\"permissions\": [\"background\"]," |
| 673 "\"options_page\": \"test.html\"}", | 673 "\"options_page\": \"test.html\"}", |
| 674 "ID-4")); | 674 "ID-4")); |
| 675 | 675 |
| 676 static_cast<extensions::TestExtensionSystem*>( | 676 static_cast<extensions::TestExtensionSystem*>( |
| 677 extensions::ExtensionSystem::Get(profile_))->CreateExtensionService( | 677 extensions::ExtensionSystem::Get(profile_)) |
| 678 CommandLine::ForCurrentProcess(), | 678 ->CreateExtensionService(base::CommandLine::ForCurrentProcess(), |
| 679 base::FilePath(), | 679 base::FilePath(), false); |
| 680 false); | |
| 681 ExtensionService* service1 = | 680 ExtensionService* service1 = |
| 682 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 681 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 683 service1->Init(); | 682 service1->Init(); |
| 684 | 683 |
| 685 service1->AddComponentExtension(component_extension.get()); | 684 service1->AddComponentExtension(component_extension.get()); |
| 686 service1->AddComponentExtension(component_extension_with_options.get()); | 685 service1->AddComponentExtension(component_extension_with_options.get()); |
| 687 service1->AddExtension(regular_extension.get()); | 686 service1->AddExtension(regular_extension.get()); |
| 688 service1->AddExtension(regular_extension_with_options.get()); | 687 service1->AddExtension(regular_extension_with_options.get()); |
| 689 | 688 |
| 690 static_cast<extensions::TestExtensionSystem*>( | 689 static_cast<extensions::TestExtensionSystem*>( |
| 691 extensions::ExtensionSystem::Get(profile2))->CreateExtensionService( | 690 extensions::ExtensionSystem::Get(profile2)) |
| 692 CommandLine::ForCurrentProcess(), | 691 ->CreateExtensionService(base::CommandLine::ForCurrentProcess(), |
| 693 base::FilePath(), | 692 base::FilePath(), false); |
| 694 false); | |
| 695 ExtensionService* service2 = | 693 ExtensionService* service2 = |
| 696 extensions::ExtensionSystem::Get(profile2)->extension_service(); | 694 extensions::ExtensionSystem::Get(profile2)->extension_service(); |
| 697 service2->Init(); | 695 service2->Init(); |
| 698 | 696 |
| 699 service2->AddComponentExtension(component_extension.get()); | 697 service2->AddComponentExtension(component_extension.get()); |
| 700 service2->AddExtension(regular_extension.get()); | 698 service2->AddExtension(regular_extension.get()); |
| 701 service2->AddExtension(regular_extension_with_options.get()); | 699 service2->AddExtension(regular_extension_with_options.get()); |
| 702 | 700 |
| 703 manager_->RegisterProfile(profile2); | 701 manager_->RegisterProfile(profile2); |
| 704 | 702 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 scoped_refptr<extensions::Extension> ephemeral_app( | 831 scoped_refptr<extensions::Extension> ephemeral_app( |
| 834 CreateExtension( | 832 CreateExtension( |
| 835 extensions::Manifest::COMMAND_LINE, | 833 extensions::Manifest::COMMAND_LINE, |
| 836 "{\"name\": \"Ephemeral App\", " | 834 "{\"name\": \"Ephemeral App\", " |
| 837 "\"version\": \"1.0\"," | 835 "\"version\": \"1.0\"," |
| 838 "\"manifest_version\": 2," | 836 "\"manifest_version\": 2," |
| 839 "\"permissions\": [\"pushMessaging\"]}", | 837 "\"permissions\": [\"pushMessaging\"]}", |
| 840 "ID-3")); | 838 "ID-3")); |
| 841 | 839 |
| 842 static_cast<extensions::TestExtensionSystem*>( | 840 static_cast<extensions::TestExtensionSystem*>( |
| 843 extensions::ExtensionSystem::Get(profile_))->CreateExtensionService( | 841 extensions::ExtensionSystem::Get(profile_)) |
| 844 CommandLine::ForCurrentProcess(), | 842 ->CreateExtensionService(base::CommandLine::ForCurrentProcess(), |
| 845 base::FilePath(), | 843 base::FilePath(), false); |
| 846 false); | |
| 847 | 844 |
| 848 ExtensionService* service = | 845 ExtensionService* service = |
| 849 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 846 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 850 DCHECK(!service->is_ready()); | 847 DCHECK(!service->is_ready()); |
| 851 service->Init(); | 848 service->Init(); |
| 852 DCHECK(service->is_ready()); | 849 DCHECK(service->is_ready()); |
| 853 manager_->status_icon_ = new TestStatusIcon(); | 850 manager_->status_icon_ = new TestStatusIcon(); |
| 854 manager_->UpdateStatusTrayIconContextMenu(); | 851 manager_->UpdateStatusTrayIconContextMenu(); |
| 855 | 852 |
| 856 // Adding a background extension should show the balloon. | 853 // Adding a background extension should show the balloon. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 875 // Installing an ephemeral app should not show the balloon. | 872 // Installing an ephemeral app should not show the balloon. |
| 876 manager_->SetHasShownBalloon(false); | 873 manager_->SetHasShownBalloon(false); |
| 877 AddEphemeralApp(ephemeral_app.get(), service); | 874 AddEphemeralApp(ephemeral_app.get(), service); |
| 878 EXPECT_FALSE(manager_->HasShownBalloon()); | 875 EXPECT_FALSE(manager_->HasShownBalloon()); |
| 879 | 876 |
| 880 // Promoting the ephemeral app to a regular installed app should now show | 877 // Promoting the ephemeral app to a regular installed app should now show |
| 881 // the balloon. | 878 // the balloon. |
| 882 service->PromoteEphemeralApp(ephemeral_app.get(), false /*from sync*/); | 879 service->PromoteEphemeralApp(ephemeral_app.get(), false /*from sync*/); |
| 883 EXPECT_TRUE(manager_->HasShownBalloon()); | 880 EXPECT_TRUE(manager_->HasShownBalloon()); |
| 884 } | 881 } |
| OLD | NEW |