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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/background/background_mode_manager.h" | 8 #include "chrome/browser/background/background_mode_manager.h" |
9 #include "chrome/browser/lifetime/application_lifetime.h" | 9 #include "chrome/browser/lifetime/application_lifetime.h" |
10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 EXPECT_TRUE(manager.IsLaunchOnStartup()); | 77 EXPECT_TRUE(manager.IsLaunchOnStartup()); |
78 } | 78 } |
79 | 79 |
80 static void AssertBackgroundModeInactive( | 80 static void AssertBackgroundModeInactive( |
81 const TestBackgroundModeManager& manager) { | 81 const TestBackgroundModeManager& manager) { |
82 EXPECT_FALSE(chrome::WillKeepAlive()); | 82 EXPECT_FALSE(chrome::WillKeepAlive()); |
83 EXPECT_FALSE(manager.HaveStatusTray()); | 83 EXPECT_FALSE(manager.HaveStatusTray()); |
84 EXPECT_FALSE(manager.IsLaunchOnStartup()); | 84 EXPECT_FALSE(manager.IsLaunchOnStartup()); |
85 } | 85 } |
86 | 86 |
| 87 static void AssertBackgroundModeSuspended( |
| 88 const TestBackgroundModeManager& manager) { |
| 89 EXPECT_FALSE(chrome::WillKeepAlive()); |
| 90 EXPECT_FALSE(manager.HaveStatusTray()); |
| 91 EXPECT_TRUE(manager.IsLaunchOnStartup()); |
| 92 } |
| 93 |
87 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { | 94 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { |
88 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); | 95 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); |
89 TestBackgroundModeManager manager( | 96 TestBackgroundModeManager manager( |
90 command_line_.get(), profile_manager_.profile_info_cache(), true); | 97 command_line_.get(), profile_manager_.profile_info_cache(), true); |
91 manager.RegisterProfile(profile); | 98 manager.RegisterProfile(profile); |
92 EXPECT_FALSE(chrome::WillKeepAlive()); | 99 EXPECT_FALSE(chrome::WillKeepAlive()); |
93 | 100 |
94 // Mimic app load. | 101 // Mimic app load. |
95 manager.OnBackgroundAppInstalled(NULL); | 102 manager.OnBackgroundAppInstalled(NULL); |
96 manager.SetBackgroundAppCount(1); | 103 manager.SetBackgroundAppCount(1); |
97 manager.OnApplicationListChanged(profile); | 104 manager.OnApplicationListChanged(profile); |
98 AssertBackgroundModeActive(manager); | 105 AssertBackgroundModeActive(manager); |
99 | 106 |
| 107 manager.SuspendBackgroundMode(); |
| 108 AssertBackgroundModeSuspended(manager); |
| 109 manager.ResumeBackgroundMode(); |
| 110 |
100 // Mimic app unload. | 111 // Mimic app unload. |
101 manager.SetBackgroundAppCount(0); | 112 manager.SetBackgroundAppCount(0); |
102 manager.OnApplicationListChanged(profile); | 113 manager.OnApplicationListChanged(profile); |
103 AssertBackgroundModeInactive(manager); | 114 AssertBackgroundModeInactive(manager); |
| 115 |
| 116 manager.SuspendBackgroundMode(); |
| 117 AssertBackgroundModeInactive(manager); |
| 118 |
| 119 // Mimic app load while suspended. |
| 120 manager.OnBackgroundAppInstalled(NULL); |
| 121 manager.SetBackgroundAppCount(1); |
| 122 manager.OnApplicationListChanged(profile); |
| 123 AssertBackgroundModeSuspended(manager); |
| 124 |
104 } | 125 } |
105 | 126 |
106 // App installs while background mode is disabled should do nothing. | 127 // App installs while background mode is disabled should do nothing. |
107 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) { | 128 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) { |
108 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); | 129 TestingProfile* profile = profile_manager_.CreateTestingProfile("p1"); |
109 TestBackgroundModeManager manager( | 130 TestBackgroundModeManager manager( |
110 command_line_.get(), profile_manager_.profile_info_cache(), true); | 131 command_line_.get(), profile_manager_.profile_info_cache(), true); |
111 manager.RegisterProfile(profile); | 132 manager.RegisterProfile(profile); |
112 // Turn off background mode. | 133 // Turn off background mode. |
113 manager.SetEnabled(false); | 134 manager.SetEnabled(false); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 324 |
304 TEST_F(BackgroundModeManagerTest, | 325 TEST_F(BackgroundModeManagerTest, |
305 BackgroundModeDisabledPreventsKeepAliveOnStartup) { | 326 BackgroundModeDisabledPreventsKeepAliveOnStartup) { |
306 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); | 327 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); |
307 command_line_->AppendSwitch(switches::kKeepAliveForTest); | 328 command_line_->AppendSwitch(switches::kKeepAliveForTest); |
308 TestBackgroundModeManager manager( | 329 TestBackgroundModeManager manager( |
309 command_line_.get(), profile_manager_.profile_info_cache(), false); | 330 command_line_.get(), profile_manager_.profile_info_cache(), false); |
310 manager.RegisterProfile(profile1); | 331 manager.RegisterProfile(profile1); |
311 EXPECT_FALSE(manager.ShouldBeInBackgroundMode()); | 332 EXPECT_FALSE(manager.ShouldBeInBackgroundMode()); |
312 } | 333 } |
OLD | NEW |