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 void EnableLaunchOnStartup(bool launch) override { |
51 launch_on_startup_ = launch; | 51 launch_on_startup_ = launch; |
52 } | 52 } |
53 | 53 |
54 virtual void DisplayAppInstalledNotification( | 54 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 void CreateStatusTrayIcon() override { have_status_tray_ = true; } |
59 virtual void RemoveStatusTrayIcon() override { have_status_tray_ = false; } | 59 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 void SetImage(const gfx::ImageSkia& image) override {} |
79 virtual void SetToolTip(const base::string16& tool_tip) override {} | 79 void SetToolTip(const base::string16& tool_tip) override {} |
80 virtual void DisplayBalloon(const gfx::ImageSkia& icon, | 80 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 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {} |
84 StatusIconMenuModel* menu) override {} | |
85 | 84 |
86 private: | 85 private: |
87 DISALLOW_COPY_AND_ASSIGN(TestStatusIcon); | 86 DISALLOW_COPY_AND_ASSIGN(TestStatusIcon); |
88 }; | 87 }; |
89 | 88 |
90 } // namespace | 89 } // namespace |
91 | 90 |
92 // 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 |
93 // things like the number of background applications. This allows writing | 92 // things like the number of background applications. This allows writing |
94 // smaller tests that don't have to install/uninstall extensions. | 93 // smaller tests that don't have to install/uninstall extensions. |
95 class TestBackgroundModeManager : public SimpleTestBackgroundModeManager { | 94 class TestBackgroundModeManager : public SimpleTestBackgroundModeManager { |
96 public: | 95 public: |
97 TestBackgroundModeManager( | 96 TestBackgroundModeManager( |
98 CommandLine* command_line, ProfileInfoCache* cache, bool enabled) | 97 CommandLine* command_line, ProfileInfoCache* cache, bool enabled) |
99 : SimpleTestBackgroundModeManager(command_line, cache), | 98 : SimpleTestBackgroundModeManager(command_line, cache), |
100 enabled_(enabled), | 99 enabled_(enabled), |
101 app_count_(0), | 100 app_count_(0), |
102 profile_app_count_(0) { | 101 profile_app_count_(0) { |
103 ResumeBackgroundMode(); | 102 ResumeBackgroundMode(); |
104 } | 103 } |
105 | 104 |
106 virtual int GetBackgroundAppCount() const override { return app_count_; } | 105 int GetBackgroundAppCount() const override { return app_count_; } |
107 virtual int GetBackgroundAppCountForProfile( | 106 int GetBackgroundAppCountForProfile(Profile* const profile) const override { |
108 Profile* const profile) const override { | |
109 return profile_app_count_; | 107 return profile_app_count_; |
110 } | 108 } |
111 void SetBackgroundAppCount(int count) { app_count_ = count; } | 109 void SetBackgroundAppCount(int count) { app_count_ = count; } |
112 void SetBackgroundAppCountForProfile(int count) { | 110 void SetBackgroundAppCountForProfile(int count) { |
113 profile_app_count_ = count; | 111 profile_app_count_ = count; |
114 } | 112 } |
115 void SetEnabled(bool enabled) { | 113 void SetEnabled(bool enabled) { |
116 enabled_ = enabled; | 114 enabled_ = enabled; |
117 OnBackgroundModeEnabledPrefChanged(); | 115 OnBackgroundModeEnabledPrefChanged(); |
118 } | 116 } |
119 virtual bool IsBackgroundModePrefEnabled() const override { return enabled_; } | 117 bool IsBackgroundModePrefEnabled() const override { return enabled_; } |
120 | 118 |
121 private: | 119 private: |
122 bool enabled_; | 120 bool enabled_; |
123 int app_count_; | 121 int app_count_; |
124 int profile_app_count_; | 122 int profile_app_count_; |
125 | 123 |
126 DISALLOW_COPY_AND_ASSIGN(TestBackgroundModeManager); | 124 DISALLOW_COPY_AND_ASSIGN(TestBackgroundModeManager); |
127 }; | 125 }; |
128 | 126 |
129 namespace { | 127 namespace { |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 // Installing an ephemeral app should not show the balloon. | 875 // Installing an ephemeral app should not show the balloon. |
878 manager_->SetHasShownBalloon(false); | 876 manager_->SetHasShownBalloon(false); |
879 AddEphemeralApp(ephemeral_app.get(), service); | 877 AddEphemeralApp(ephemeral_app.get(), service); |
880 EXPECT_FALSE(manager_->HasShownBalloon()); | 878 EXPECT_FALSE(manager_->HasShownBalloon()); |
881 | 879 |
882 // Promoting the ephemeral app to a regular installed app should now show | 880 // Promoting the ephemeral app to a regular installed app should now show |
883 // the balloon. | 881 // the balloon. |
884 service->PromoteEphemeralApp(ephemeral_app.get(), false /*from sync*/); | 882 service->PromoteEphemeralApp(ephemeral_app.get(), false /*from sync*/); |
885 EXPECT_TRUE(manager_->HasShownBalloon()); | 883 EXPECT_TRUE(manager_->HasShownBalloon()); |
886 } | 884 } |
OLD | NEW |