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

Side by Side Diff: chrome/browser/background_mode_manager_unittest.cc

Issue 6914021: Modifying the BackgroundModeManager to handle multiple profiles. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/background_mode_manager.h" 7 #include "chrome/browser/background_mode_manager.h"
8 #include "chrome/browser/ui/browser_list.h" 8 #include "chrome/browser/ui/browser_list.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/test/testing_browser_process.h" 10 #include "chrome/test/testing_browser_process.h"
(...skipping 11 matching lines...) Expand all
22 BackgroundModeManagerTest() {} 22 BackgroundModeManagerTest() {}
23 ~BackgroundModeManagerTest() {} 23 ~BackgroundModeManagerTest() {}
24 void SetUp() { 24 void SetUp() {
25 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); 25 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM));
26 } 26 }
27 scoped_ptr<CommandLine> command_line_; 27 scoped_ptr<CommandLine> command_line_;
28 }; 28 };
29 29
30 class TestBackgroundModeManager : public BackgroundModeManager { 30 class TestBackgroundModeManager : public BackgroundModeManager {
31 public: 31 public:
32 TestBackgroundModeManager(Profile* profile, CommandLine* cl) 32 explicit TestBackgroundModeManager(CommandLine* command_line)
33 : BackgroundModeManager(profile, cl), 33 : BackgroundModeManager(command_line),
34 enabled_(true) {} 34 enabled_(true) {}
35 MOCK_METHOD1(EnableLaunchOnStartup, void(bool)); 35 MOCK_METHOD1(EnableLaunchOnStartup, void(bool));
36 MOCK_METHOD0(CreateStatusTrayIcon, void()); 36 MOCK_METHOD1(CreateStatusTrayIcon, void(Profile*)); // NOLINT
37 MOCK_METHOD0(RemoveStatusTrayIcon, void()); 37 MOCK_METHOD1(RemoveStatusTrayIcon, void(Profile*)); // NOLINT
38 virtual bool IsBackgroundModePrefEnabled() { return enabled_; } 38 virtual bool IsBackgroundModePrefEnabled() { return enabled_; }
39 void SetEnabled(bool enabled) { enabled_ = enabled; } 39 void SetEnabled(bool enabled) { enabled_ = enabled; }
40 private: 40 private:
41 bool enabled_; 41 bool enabled_;
42 }; 42 };
43 43
44 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { 44 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) {
45 InSequence s; 45 InSequence s;
46 TestingProfile profile; 46 TestingProfile profile;
47 TestBackgroundModeManager manager(&profile, command_line_.get()); 47 TestBackgroundModeManager manager(command_line_.get());
48 EXPECT_CALL(manager, CreateStatusTrayIcon()); 48 manager.RegisterProfile(&profile);
49 EXPECT_CALL(manager, RemoveStatusTrayIcon()); 49 EXPECT_CALL(manager, CreateStatusTrayIcon(&profile));
50 EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile));
50 EXPECT_FALSE(BrowserList::WillKeepAlive()); 51 EXPECT_FALSE(BrowserList::WillKeepAlive());
51 // Call to AppLoaded() will cause the status tray to be created, then call to 52 // Call to AppLoaded() will cause the status tray to be created, then call to
52 // unloaded will result in call to remove the icon. 53 // unloaded will result in call to remove the icon.
53 manager.OnBackgroundAppLoaded(); 54 manager.OnBackgroundAppLoaded();
54 EXPECT_TRUE(BrowserList::WillKeepAlive()); 55 EXPECT_TRUE(BrowserList::WillKeepAlive());
55 manager.OnBackgroundAppUnloaded(); 56 manager.OnBackgroundAppUnloaded();
56 EXPECT_FALSE(BrowserList::WillKeepAlive()); 57 EXPECT_FALSE(BrowserList::WillKeepAlive());
57 } 58 }
58 59
59 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstall) { 60 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstall) {
60 InSequence s; 61 InSequence s;
61 TestingProfile profile; 62 TestingProfile profile;
62 TestBackgroundModeManager manager(&profile, command_line_.get()); 63 TestBackgroundModeManager manager(command_line_.get());
64 manager.RegisterProfile(&profile);
63 // Call to AppInstalled() will cause chrome to be set to launch on startup, 65 // Call to AppInstalled() will cause chrome to be set to launch on startup,
64 // and call to AppUninstalled() set chrome to not launch on startup. 66 // and call to AppUninstalled() set chrome to not launch on startup.
65 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); 67 EXPECT_CALL(manager, EnableLaunchOnStartup(true));
66 EXPECT_CALL(manager, CreateStatusTrayIcon()); 68 EXPECT_CALL(manager, CreateStatusTrayIcon(&profile));
67 EXPECT_CALL(manager, RemoveStatusTrayIcon()); 69 EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile));
68 EXPECT_CALL(manager, EnableLaunchOnStartup(false)); 70 EXPECT_CALL(manager, EnableLaunchOnStartup(false));
69 manager.OnBackgroundAppInstalled(NULL); 71 manager.OnBackgroundAppInstalled(NULL, &profile);
70 manager.OnBackgroundAppLoaded(); 72 manager.OnBackgroundAppLoaded();
71 manager.OnBackgroundAppUnloaded(); 73 manager.OnBackgroundAppUnloaded();
72 manager.OnBackgroundAppUninstalled(); 74 manager.OnBackgroundAppUninstalled();
73 } 75 }
74 76
75 // App installs while disabled should do nothing. 77 // App installs while disabled should do nothing.
76 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) { 78 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) {
77 InSequence s; 79 InSequence s;
78 TestingProfile profile; 80 TestingProfile profile;
79 TestBackgroundModeManager manager(&profile, command_line_.get()); 81 TestBackgroundModeManager manager(command_line_.get());
82 manager.RegisterProfile(&profile);
80 // Turn off background mode. 83 // Turn off background mode.
81 manager.SetEnabled(false); 84 manager.SetEnabled(false);
82 manager.DisableBackgroundMode(); 85 manager.DisableBackgroundMode();
83 86
84 // Status tray icons will not be created, launch on startup status will be set 87 // Status tray icons will not be created, launch on startup status will be set
85 // to "do not launch on startup". 88 // to "do not launch on startup".
86 EXPECT_CALL(manager, EnableLaunchOnStartup(false)); 89 EXPECT_CALL(manager, EnableLaunchOnStartup(false));
87 manager.OnBackgroundAppInstalled(NULL); 90 manager.OnBackgroundAppInstalled(NULL, &profile);
88 manager.OnBackgroundAppLoaded(); 91 manager.OnBackgroundAppLoaded();
89 manager.OnBackgroundAppUnloaded(); 92 manager.OnBackgroundAppUnloaded();
90 manager.OnBackgroundAppUninstalled(); 93 manager.OnBackgroundAppUninstalled();
91 94
92 // Re-enable background mode. 95 // Re-enable background mode.
93 manager.SetEnabled(true); 96 manager.SetEnabled(true);
94 manager.EnableBackgroundMode(); 97 manager.EnableBackgroundMode();
95 } 98 }
96 99
97 100
98 // App installs while disabled should do nothing. 101 // App installs while disabled should do nothing.
99 TEST_F(BackgroundModeManagerTest, EnableAfterBackgroundAppInstall) { 102 TEST_F(BackgroundModeManagerTest, EnableAfterBackgroundAppInstall) {
100 InSequence s; 103 InSequence s;
101 TestingProfile profile; 104 TestingProfile profile;
102 TestBackgroundModeManager manager(&profile, command_line_.get()); 105 TestBackgroundModeManager manager(command_line_.get());
106 manager.RegisterProfile(&profile);
103 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); 107 EXPECT_CALL(manager, EnableLaunchOnStartup(true));
104 EXPECT_CALL(manager, CreateStatusTrayIcon()); 108 EXPECT_CALL(manager, CreateStatusTrayIcon(&profile));
105 EXPECT_CALL(manager, RemoveStatusTrayIcon()); 109 EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile));
106 EXPECT_CALL(manager, EnableLaunchOnStartup(false)); 110 EXPECT_CALL(manager, EnableLaunchOnStartup(false));
107 EXPECT_CALL(manager, CreateStatusTrayIcon()); 111 EXPECT_CALL(manager, CreateStatusTrayIcon(&profile));
108 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); 112 EXPECT_CALL(manager, EnableLaunchOnStartup(true));
109 EXPECT_CALL(manager, RemoveStatusTrayIcon()); 113 EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile));
110 EXPECT_CALL(manager, EnableLaunchOnStartup(false)); 114 EXPECT_CALL(manager, EnableLaunchOnStartup(false));
111 115
112 // Install app, should show status tray icon. 116 // Install app, should show status tray icon.
113 manager.OnBackgroundAppInstalled(NULL); 117 manager.OnBackgroundAppInstalled(NULL, &profile);
114 manager.OnBackgroundAppLoaded(); 118 manager.OnBackgroundAppLoaded();
115 119
116 // Turn off background mode - should hide status tray icon. 120 // Turn off background mode - should hide status tray icon.
117 manager.SetEnabled(false); 121 manager.SetEnabled(false);
118 manager.DisableBackgroundMode(); 122 manager.DisableBackgroundMode();
119 123
120 // Turn back on background mode - should show status tray icon. 124 // Turn back on background mode - should show status tray icon.
121 manager.SetEnabled(true); 125 manager.SetEnabled(true);
122 manager.EnableBackgroundMode(); 126 manager.EnableBackgroundMode();
123 127
124 // Uninstall app, should hide status tray icon again. 128 // Uninstall app, should hide status tray icon again.
125 manager.OnBackgroundAppUnloaded(); 129 manager.OnBackgroundAppUnloaded();
126 manager.OnBackgroundAppUninstalled(); 130 manager.OnBackgroundAppUninstalled();
127 } 131 }
132
133 TEST_F(BackgroundModeManagerTest, MultiProfile) {
134 InSequence s;
135 TestingProfile profile1;
136 TestingProfile profile2;
137 TestBackgroundModeManager manager(command_line_.get());
138 manager.RegisterProfile(&profile1);
139 manager.RegisterProfile(&profile2);
140 EXPECT_CALL(manager, EnableLaunchOnStartup(true));
141 EXPECT_CALL(manager, CreateStatusTrayIcon(&profile1));
142 EXPECT_CALL(manager, CreateStatusTrayIcon(&profile2));
143 EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile1));
144 EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile2));
145 EXPECT_CALL(manager, EnableLaunchOnStartup(false));
146 EXPECT_CALL(manager, CreateStatusTrayIcon(&profile1));
147 EXPECT_CALL(manager, CreateStatusTrayIcon(&profile2));
148 EXPECT_CALL(manager, EnableLaunchOnStartup(true));
149 EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile1));
150 EXPECT_CALL(manager, RemoveStatusTrayIcon(&profile2));
151 EXPECT_CALL(manager, EnableLaunchOnStartup(false));
152 EXPECT_FALSE(BrowserList::WillKeepAlive());
153
154 // Install app, should show status tray icon.
155 manager.OnBackgroundAppInstalled(NULL, &profile1);
rpetterson 2011/05/20 05:53:17 What needs to be done to be able to call these pri
Miranda Callahan 2011/05/20 15:16:53 Have you tried adding this line to background_mode
Andrew T Wilson (Slow) 2011/05/20 16:52:46 Yeah, Miranda is correct. I really hate this patte
rpetterson 2011/05/23 03:23:19 Thanks!
156 manager.OnBackgroundAppLoaded();
157
158 // Install app for other profile, hsould show other status tray icon.
159 manager.OnBackgroundAppInstalled(NULL, &profile2);
160 manager.OnBackgroundAppLoaded();
161
162 // Should hide both status tray icons.
163 manager.SetEnabled(false);
164 manager.DisableBackgroundMode();
165
166 // Turn back on background mode - should show both status tray icons.
167 manager.SetEnabled(true);
168 manager.EnableBackgroundMode();
169
170 manager.OnBackgroundAppUnloaded();
171 manager.OnBackgroundAppUninstalled();
172 // There is still one background app alive
173 EXPECT_TRUE(BrowserList::WillKeepAlive());
174 manager.OnBackgroundAppUnloaded();
175 manager.OnBackgroundAppUninstalled();
176 EXPECT_FALSE(BrowserList::WillKeepAlive());
177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698