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

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

Issue 6954001: Add "Keep chrome running in background" preference. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review feedback + added tests. 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"
11 #include "chrome/test/testing_browser_process_test.h" 11 #include "chrome/test/testing_browser_process_test.h"
12 #include "chrome/test/testing_profile.h" 12 #include "chrome/test/testing_profile.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using testing::AtLeast;
16 using testing::InSequence; 17 using testing::InSequence;
18 using testing::Return;
17 19
18 class BackgroundModeManagerTest : public TestingBrowserProcessTest { 20 class BackgroundModeManagerTest : public TestingBrowserProcessTest {
19 public: 21 public:
20 BackgroundModeManagerTest() {} 22 BackgroundModeManagerTest() {}
21 ~BackgroundModeManagerTest() {} 23 ~BackgroundModeManagerTest() {}
22 void SetUp() { 24 void SetUp() {
23 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); 25 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM));
24 } 26 }
25 scoped_ptr<CommandLine> command_line_; 27 scoped_ptr<CommandLine> command_line_;
26 }; 28 };
27 29
28 class TestBackgroundModeManager : public BackgroundModeManager { 30 class TestBackgroundModeManager : public BackgroundModeManager {
29 public: 31 public:
30 TestBackgroundModeManager(Profile* profile, CommandLine* cl) 32 TestBackgroundModeManager(Profile* profile, CommandLine* cl)
31 : BackgroundModeManager(profile, cl) { 33 : BackgroundModeManager(profile, cl),
32 } 34 enabled_(true) {}
33 MOCK_METHOD1(EnableLaunchOnStartup, void(bool)); 35 MOCK_METHOD1(EnableLaunchOnStartup, void(bool));
34 MOCK_METHOD0(CreateStatusTrayIcon, void()); 36 MOCK_METHOD0(CreateStatusTrayIcon, void());
35 MOCK_METHOD0(RemoveStatusTrayIcon, void()); 37 MOCK_METHOD0(RemoveStatusTrayIcon, void());
38 virtual bool IsBackgroundModePrefEnabled() { return enabled_; }
39 void SetEnabled(bool enabled) { enabled_ = enabled; }
40 private:
41 bool enabled_;
36 }; 42 };
37 43
38 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) { 44 TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) {
39 InSequence s; 45 InSequence s;
40 TestingProfile profile; 46 TestingProfile profile;
41 TestBackgroundModeManager manager(&profile, command_line_.get()); 47 TestBackgroundModeManager manager(&profile, command_line_.get());
42 EXPECT_CALL(manager, CreateStatusTrayIcon()); 48 EXPECT_CALL(manager, CreateStatusTrayIcon());
43 EXPECT_CALL(manager, RemoveStatusTrayIcon()); 49 EXPECT_CALL(manager, RemoveStatusTrayIcon());
44 EXPECT_FALSE(BrowserList::WillKeepAlive()); 50 EXPECT_FALSE(BrowserList::WillKeepAlive());
45 // Call to AppLoaded() will cause the status tray to be created, then call to 51 // Call to AppLoaded() will cause the status tray to be created, then call to
(...skipping 12 matching lines...) Expand all
58 // and call to AppUninstalled() set chrome to not launch on startup. 64 // and call to AppUninstalled() set chrome to not launch on startup.
59 EXPECT_CALL(manager, EnableLaunchOnStartup(true)); 65 EXPECT_CALL(manager, EnableLaunchOnStartup(true));
60 EXPECT_CALL(manager, CreateStatusTrayIcon()); 66 EXPECT_CALL(manager, CreateStatusTrayIcon());
61 EXPECT_CALL(manager, RemoveStatusTrayIcon()); 67 EXPECT_CALL(manager, RemoveStatusTrayIcon());
62 EXPECT_CALL(manager, EnableLaunchOnStartup(false)); 68 EXPECT_CALL(manager, EnableLaunchOnStartup(false));
63 manager.OnBackgroundAppInstalled(NULL); 69 manager.OnBackgroundAppInstalled(NULL);
64 manager.OnBackgroundAppLoaded(); 70 manager.OnBackgroundAppLoaded();
65 manager.OnBackgroundAppUnloaded(); 71 manager.OnBackgroundAppUnloaded();
66 manager.OnBackgroundAppUninstalled(); 72 manager.OnBackgroundAppUninstalled();
67 } 73 }
74
75 // App installs while disabled should do nothing.
76 TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstallWhileDisabled) {
77 InSequence s;
78 TestingProfile profile;
79 TestBackgroundModeManager manager(&profile, command_line_.get());
80 // Turn off background mode.
81 manager.SetEnabled(false);
82 manager.DisableBackgroundMode();
83
84 // Status tray icons will not be created, launch on startup status will be set
85 // to "do not launch on startup".
86 EXPECT_CALL(manager, EnableLaunchOnStartup(false));
87 manager.OnBackgroundAppInstalled(NULL);
88 manager.OnBackgroundAppLoaded();
89 manager.OnBackgroundAppUnloaded();
90 manager.OnBackgroundAppUninstalled();
91
92 // Re-enable background mode.
Rick Campbell 2011/05/12 05:42:42 Reverse the sense of this comment to match the cod
Andrew T Wilson (Slow) 2011/05/12 23:34:31 Actually, I needed to reverse the sense of the cod
93 manager.SetEnabled(false);
94 manager.DisableBackgroundMode();
95 }
96
97
98 // App installs while disabled should do nothing.
99 TEST_F(BackgroundModeManagerTest, EnableAfterBackgroundAppInstall) {
100 InSequence s;
101 TestingProfile profile;
102 TestBackgroundModeManager manager(&profile, command_line_.get());
103 EXPECT_CALL(manager, EnableLaunchOnStartup(true));
104 EXPECT_CALL(manager, CreateStatusTrayIcon());
105 EXPECT_CALL(manager, RemoveStatusTrayIcon());
106 EXPECT_CALL(manager, EnableLaunchOnStartup(false));
107 EXPECT_CALL(manager, CreateStatusTrayIcon());
108 EXPECT_CALL(manager, EnableLaunchOnStartup(true));
109 EXPECT_CALL(manager, RemoveStatusTrayIcon());
110 EXPECT_CALL(manager, EnableLaunchOnStartup(false));
111
112 // Install app, should show status tray icon.
113 manager.OnBackgroundAppInstalled(NULL);
114 manager.OnBackgroundAppLoaded();
115
116 // Turn off background mode - should hide status tray icon.
117 manager.SetEnabled(false);
118 manager.DisableBackgroundMode();
119
120 // Turn back on background mode - should show status tray icon.
121 manager.SetEnabled(true);
122 manager.EnableBackgroundMode();
123
124 // Uninstall app, should hide status tray icon again.
125 manager.OnBackgroundAppUnloaded();
126 manager.OnBackgroundAppUninstalled();
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698