[email protected] | baf5a344 | 2012-04-21 22:48:32 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | a25fd45 | 2011-10-26 10:45:08 | [diff] [blame] | 5 | #include "base/compiler_specific.h" |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 6 | #include "chrome/browser/status_icons/status_icon.h" |
| 7 | #include "chrome/browser/status_icons/status_tray.h" |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 8 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 9 | #include "ui/gfx/image/image_skia.h" |
mgiuca | 8367e72 | 2015-11-25 06:53:48 | [diff] [blame^] | 10 | #include "ui/gfx/image/image_unittest_util.h" |
johnme | 9295617 | 2015-10-15 16:54:12 | [diff] [blame] | 11 | #include "ui/message_center/notifier_settings.h" |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 12 | |
mgiuca | 8367e72 | 2015-11-25 06:53:48 | [diff] [blame^] | 13 | namespace { |
| 14 | |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 15 | class MockStatusIcon : public StatusIcon { |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 16 | void SetImage(const gfx::ImageSkia& image) override {} |
| 17 | void SetToolTip(const base::string16& tool_tip) override {} |
| 18 | void DisplayBalloon(const gfx::ImageSkia& icon, |
| 19 | const base::string16& title, |
johnme | 9295617 | 2015-10-15 16:54:12 | [diff] [blame] | 20 | const base::string16& contents, |
| 21 | const message_center::NotifierId& notifier_id) override {} |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 22 | void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {} |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 23 | }; |
| 24 | |
[email protected] | a24642a | 2010-03-24 21:29:05 | [diff] [blame] | 25 | class TestStatusTray : public StatusTray { |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 26 | public: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 27 | StatusIcon* CreatePlatformStatusIcon( |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 28 | StatusIconType type, |
| 29 | const gfx::ImageSkia& image, |
mostynb | fb66cb4f | 2014-10-07 09:15:42 | [diff] [blame] | 30 | const base::string16& tool_tip) override { |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 31 | return new MockStatusIcon(); |
| 32 | } |
[email protected] | 4b49fb0c | 2013-07-18 09:51:25 | [diff] [blame] | 33 | |
| 34 | const StatusIcons& GetStatusIconsForTest() const { return status_icons(); } |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 35 | }; |
| 36 | |
mgiuca | 8367e72 | 2015-11-25 06:53:48 | [diff] [blame^] | 37 | StatusIcon* CreateStatusIcon(StatusTray* tray) { |
| 38 | // Just create a dummy icon image; the actual image is irrelevant. |
| 39 | return tray->CreateStatusIcon(StatusTray::OTHER_ICON, |
| 40 | gfx::test::CreateImageSkia(16, 16), |
| 41 | base::string16()); |
| 42 | } |
| 43 | |
| 44 | } // namespace |
| 45 | |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 46 | TEST(StatusTrayTest, Create) { |
| 47 | // Check for creation and leaks. |
[email protected] | a24642a | 2010-03-24 21:29:05 | [diff] [blame] | 48 | TestStatusTray tray; |
mgiuca | 8367e72 | 2015-11-25 06:53:48 | [diff] [blame^] | 49 | CreateStatusIcon(&tray); |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 50 | EXPECT_EQ(1U, tray.GetStatusIconsForTest().size()); |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 51 | } |
| 52 | |
[email protected] | 4c793f0 | 2010-08-18 20:55:45 | [diff] [blame] | 53 | // Make sure that removing an icon removes it from the list. |
| 54 | TEST(StatusTrayTest, CreateRemove) { |
[email protected] | a24642a | 2010-03-24 21:29:05 | [diff] [blame] | 55 | TestStatusTray tray; |
mgiuca | 8367e72 | 2015-11-25 06:53:48 | [diff] [blame^] | 56 | StatusIcon* icon = CreateStatusIcon(&tray); |
[email protected] | 4b49fb0c | 2013-07-18 09:51:25 | [diff] [blame] | 57 | EXPECT_EQ(1U, tray.GetStatusIconsForTest().size()); |
[email protected] | 4c793f0 | 2010-08-18 20:55:45 | [diff] [blame] | 58 | tray.RemoveStatusIcon(icon); |
[email protected] | 4b49fb0c | 2013-07-18 09:51:25 | [diff] [blame] | 59 | EXPECT_EQ(0U, tray.GetStatusIconsForTest().size()); |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 60 | } |