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 29 matching lines...) Expand all Loading... |
40 public: | 40 public: |
41 SimpleTestBackgroundModeManager( | 41 SimpleTestBackgroundModeManager( |
42 CommandLine* command_line, ProfileInfoCache* cache) | 42 CommandLine* command_line, 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 virtual void EnableLaunchOnStartup(bool launch) OVERRIDE { | 50 virtual void EnableLaunchOnStartup(bool launch) override { |
51 launch_on_startup_ = launch; | 51 launch_on_startup_ = launch; |
52 } | 52 } |
53 | 53 |
54 virtual void DisplayAppInstalledNotification( | 54 virtual void DisplayAppInstalledNotification( |
55 const extensions::Extension* extension) OVERRIDE { | 55 const extensions::Extension* extension) override { |
56 has_shown_balloon_ = true; | 56 has_shown_balloon_ = true; |
57 } | 57 } |
58 virtual void CreateStatusTrayIcon() OVERRIDE { have_status_tray_ = true; } | 58 virtual void CreateStatusTrayIcon() override { have_status_tray_ = true; } |
59 virtual void RemoveStatusTrayIcon() OVERRIDE { have_status_tray_ = false; } | 59 virtual void RemoveStatusTrayIcon() override { have_status_tray_ = false; } |
60 | 60 |
61 bool HaveStatusTray() const { return have_status_tray_; } | 61 bool HaveStatusTray() const { return have_status_tray_; } |
62 bool IsLaunchOnStartup() const { return launch_on_startup_; } | 62 bool IsLaunchOnStartup() const { return launch_on_startup_; } |
63 bool HasShownBalloon() const { return has_shown_balloon_; } | 63 bool HasShownBalloon() const { return has_shown_balloon_; } |
64 void SetHasShownBalloon(bool value) { has_shown_balloon_ = value; } | 64 void SetHasShownBalloon(bool value) { has_shown_balloon_ = value; } |
65 | 65 |
66 private: | 66 private: |
67 // Flags to track whether we are launching on startup/have a status tray. | 67 // Flags to track whether we are launching on startup/have a status tray. |
68 bool have_status_tray_; | 68 bool have_status_tray_; |
69 bool launch_on_startup_; | 69 bool launch_on_startup_; |
70 bool has_shown_balloon_; | 70 bool has_shown_balloon_; |
71 | 71 |
72 DISALLOW_COPY_AND_ASSIGN(SimpleTestBackgroundModeManager); | 72 DISALLOW_COPY_AND_ASSIGN(SimpleTestBackgroundModeManager); |
73 }; | 73 }; |
74 | 74 |
75 class TestStatusIcon : public StatusIcon { | 75 class TestStatusIcon : public StatusIcon { |
76 public: | 76 public: |
77 TestStatusIcon() {} | 77 TestStatusIcon() {} |
78 virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE {} | 78 virtual void SetImage(const gfx::ImageSkia& image) override {} |
79 virtual void SetToolTip(const base::string16& tool_tip) OVERRIDE {} | 79 virtual void SetToolTip(const base::string16& tool_tip) override {} |
80 virtual void DisplayBalloon(const gfx::ImageSkia& icon, | 80 virtual void DisplayBalloon(const gfx::ImageSkia& icon, |
81 const base::string16& title, | 81 const base::string16& title, |
82 const base::string16& contents) OVERRIDE {} | 82 const base::string16& contents) override {} |
83 virtual void UpdatePlatformContextMenu( | 83 virtual void UpdatePlatformContextMenu( |
84 StatusIconMenuModel* menu) OVERRIDE {} | 84 StatusIconMenuModel* menu) override {} |
85 | 85 |
86 private: | 86 private: |
87 DISALLOW_COPY_AND_ASSIGN(TestStatusIcon); | 87 DISALLOW_COPY_AND_ASSIGN(TestStatusIcon); |
88 }; | 88 }; |
89 | 89 |
90 } // namespace | 90 } // namespace |
91 | 91 |
92 // More complex test helper that exposes APIs for fine grained control of | 92 // More complex test helper that exposes APIs for fine grained control of |
93 // things like the number of background applications. This allows writing | 93 // things like the number of background applications. This allows writing |
94 // smaller tests that don't have to install/uninstall extensions. | 94 // smaller tests that don't have to install/uninstall extensions. |
95 class TestBackgroundModeManager : public SimpleTestBackgroundModeManager { | 95 class TestBackgroundModeManager : public SimpleTestBackgroundModeManager { |
96 public: | 96 public: |
97 TestBackgroundModeManager( | 97 TestBackgroundModeManager( |
98 CommandLine* command_line, ProfileInfoCache* cache, bool enabled) | 98 CommandLine* command_line, ProfileInfoCache* cache, bool enabled) |
99 : SimpleTestBackgroundModeManager(command_line, cache), | 99 : SimpleTestBackgroundModeManager(command_line, cache), |
100 enabled_(enabled), | 100 enabled_(enabled), |
101 app_count_(0), | 101 app_count_(0), |
102 profile_app_count_(0) { | 102 profile_app_count_(0) { |
103 ResumeBackgroundMode(); | 103 ResumeBackgroundMode(); |
104 } | 104 } |
105 | 105 |
106 virtual int GetBackgroundAppCount() const OVERRIDE { return app_count_; } | 106 virtual int GetBackgroundAppCount() const override { return app_count_; } |
107 virtual int GetBackgroundAppCountForProfile( | 107 virtual int GetBackgroundAppCountForProfile( |
108 Profile* const profile) const OVERRIDE { | 108 Profile* const profile) const override { |
109 return profile_app_count_; | 109 return profile_app_count_; |
110 } | 110 } |
111 void SetBackgroundAppCount(int count) { app_count_ = count; } | 111 void SetBackgroundAppCount(int count) { app_count_ = count; } |
112 void SetBackgroundAppCountForProfile(int count) { | 112 void SetBackgroundAppCountForProfile(int count) { |
113 profile_app_count_ = count; | 113 profile_app_count_ = count; |
114 } | 114 } |
115 void SetEnabled(bool enabled) { | 115 void SetEnabled(bool enabled) { |
116 enabled_ = enabled; | 116 enabled_ = enabled; |
117 OnBackgroundModeEnabledPrefChanged(); | 117 OnBackgroundModeEnabledPrefChanged(); |
118 } | 118 } |
119 virtual bool IsBackgroundModePrefEnabled() const OVERRIDE { return enabled_; } | 119 virtual bool IsBackgroundModePrefEnabled() const override { return enabled_; } |
120 | 120 |
121 private: | 121 private: |
122 bool enabled_; | 122 bool enabled_; |
123 int app_count_; | 123 int app_count_; |
124 int profile_app_count_; | 124 int profile_app_count_; |
125 | 125 |
126 DISALLOW_COPY_AND_ASSIGN(TestBackgroundModeManager); | 126 DISALLOW_COPY_AND_ASSIGN(TestBackgroundModeManager); |
127 }; | 127 }; |
128 | 128 |
129 namespace { | 129 namespace { |
(...skipping 18 matching lines...) Expand all Loading... |
148 EXPECT_FALSE(manager.HaveStatusTray()); | 148 EXPECT_FALSE(manager.HaveStatusTray()); |
149 EXPECT_TRUE(manager.IsLaunchOnStartup()); | 149 EXPECT_TRUE(manager.IsLaunchOnStartup()); |
150 } | 150 } |
151 | 151 |
152 } // namespace | 152 } // namespace |
153 | 153 |
154 class BackgroundModeManagerTest : public testing::Test { | 154 class BackgroundModeManagerTest : public testing::Test { |
155 public: | 155 public: |
156 BackgroundModeManagerTest() {} | 156 BackgroundModeManagerTest() {} |
157 virtual ~BackgroundModeManagerTest() {} | 157 virtual ~BackgroundModeManagerTest() {} |
158 virtual void SetUp() OVERRIDE { | 158 virtual void SetUp() override { |
159 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 159 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
160 profile_manager_ = CreateTestingProfileManager(); | 160 profile_manager_ = CreateTestingProfileManager(); |
161 profile_ = profile_manager_->CreateTestingProfile("p1"); | 161 profile_ = profile_manager_->CreateTestingProfile("p1"); |
162 } | 162 } |
163 scoped_ptr<CommandLine> command_line_; | 163 scoped_ptr<CommandLine> command_line_; |
164 | 164 |
165 protected: | 165 protected: |
166 scoped_refptr<extensions::Extension> CreateExtension( | 166 scoped_refptr<extensions::Extension> CreateExtension( |
167 extensions::Manifest::Location location, | 167 extensions::Manifest::Location location, |
168 const std::string& data, | 168 const std::string& data, |
(...skipping 28 matching lines...) Expand all Loading... |
197 } | 197 } |
198 | 198 |
199 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerTest); | 199 DISALLOW_COPY_AND_ASSIGN(BackgroundModeManagerTest); |
200 }; | 200 }; |
201 | 201 |
202 class BackgroundModeManagerWithExtensionsTest | 202 class BackgroundModeManagerWithExtensionsTest |
203 : public BackgroundModeManagerTest { | 203 : public BackgroundModeManagerTest { |
204 public: | 204 public: |
205 BackgroundModeManagerWithExtensionsTest() {} | 205 BackgroundModeManagerWithExtensionsTest() {} |
206 virtual ~BackgroundModeManagerWithExtensionsTest() {} | 206 virtual ~BackgroundModeManagerWithExtensionsTest() {} |
207 virtual void SetUp() OVERRIDE { | 207 virtual void SetUp() override { |
208 BackgroundModeManagerTest::SetUp(); | 208 BackgroundModeManagerTest::SetUp(); |
209 // Aura clears notifications from the message center at shutdown. | 209 // Aura clears notifications from the message center at shutdown. |
210 message_center::MessageCenter::Initialize(); | 210 message_center::MessageCenter::Initialize(); |
211 | 211 |
212 // BackgroundModeManager actually affects Chrome start/stop state, | 212 // BackgroundModeManager actually affects Chrome start/stop state, |
213 // tearing down our thread bundle before we've had chance to clean | 213 // tearing down our thread bundle before we've had chance to clean |
214 // everything up. Keeping Chrome alive prevents this. | 214 // everything up. Keeping Chrome alive prevents this. |
215 // We aren't interested in if the keep alive works correctly in this test. | 215 // We aren't interested in if the keep alive works correctly in this test. |
216 chrome::IncrementKeepAliveCount(); | 216 chrome::IncrementKeepAliveCount(); |
217 | 217 |
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 // Installing an ephemeral app should not show the balloon. | 877 // Installing an ephemeral app should not show the balloon. |
878 manager_->SetHasShownBalloon(false); | 878 manager_->SetHasShownBalloon(false); |
879 AddEphemeralApp(ephemeral_app.get(), service); | 879 AddEphemeralApp(ephemeral_app.get(), service); |
880 EXPECT_FALSE(manager_->HasShownBalloon()); | 880 EXPECT_FALSE(manager_->HasShownBalloon()); |
881 | 881 |
882 // Promoting the ephemeral app to a regular installed app should now show | 882 // Promoting the ephemeral app to a regular installed app should now show |
883 // the balloon. | 883 // the balloon. |
884 service->PromoteEphemeralApp(ephemeral_app.get(), false /*from sync*/); | 884 service->PromoteEphemeralApp(ephemeral_app.get(), false /*from sync*/); |
885 EXPECT_TRUE(manager_->HasShownBalloon()); | 885 EXPECT_TRUE(manager_->HasShownBalloon()); |
886 } | 886 } |
OLD | NEW |