[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] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 5 | #include "chrome/browser/status_icons/status_tray.h" |
leon.han | 4ea301f | 2017-03-28 03:36:31 | [diff] [blame] | 6 | |
| 7 | #include "base/compiler_specific.h" |
leon.han | 4ea301f | 2017-03-28 03:36:31 | [diff] [blame] | 8 | #include "chrome/browser/status_icons/status_icon.h" |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 9 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 10 | #include "ui/gfx/image/image_skia.h" |
mgiuca | 8367e72 | 2015-11-25 06:53:48 | [diff] [blame] | 11 | #include "ui/gfx/image/image_unittest_util.h" |
Evan Stade | 889ce471 | 2018-01-28 15:26:26 | [diff] [blame] | 12 | #include "ui/message_center/public/cpp/notifier_id.h" |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 13 | |
mgiuca | 8367e72 | 2015-11-25 06:53:48 | [diff] [blame] | 14 | namespace { |
| 15 | |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 16 | class MockStatusIcon : public StatusIcon { |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 17 | void SetImage(const gfx::ImageSkia& image) override {} |
| 18 | void SetToolTip(const base::string16& tool_tip) override {} |
| 19 | void DisplayBalloon(const gfx::ImageSkia& icon, |
| 20 | const base::string16& title, |
johnme | 9295617 | 2015-10-15 16:54:12 | [diff] [blame] | 21 | const base::string16& contents, |
| 22 | const message_center::NotifierId& notifier_id) override {} |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 23 | void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {} |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 24 | }; |
| 25 | |
[email protected] | a24642a | 2010-03-24 21:29:05 | [diff] [blame] | 26 | class TestStatusTray : public StatusTray { |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 27 | public: |
leon.han | 4ea301f | 2017-03-28 03:36:31 | [diff] [blame] | 28 | std::unique_ptr<StatusIcon> CreatePlatformStatusIcon( |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 29 | StatusIconType type, |
| 30 | const gfx::ImageSkia& image, |
mostynb | fb66cb4f | 2014-10-07 09:15:42 | [diff] [blame] | 31 | const base::string16& tool_tip) override { |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 32 | return std::make_unique<MockStatusIcon>(); |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 33 | } |
[email protected] | 4b49fb0c | 2013-07-18 09:51:25 | [diff] [blame] | 34 | |
| 35 | const StatusIcons& GetStatusIconsForTest() const { return status_icons(); } |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 36 | }; |
| 37 | |
mgiuca | 8367e72 | 2015-11-25 06:53:48 | [diff] [blame] | 38 | StatusIcon* CreateStatusIcon(StatusTray* tray) { |
| 39 | // Just create a dummy icon image; the actual image is irrelevant. |
| 40 | return tray->CreateStatusIcon(StatusTray::OTHER_ICON, |
| 41 | gfx::test::CreateImageSkia(16, 16), |
| 42 | base::string16()); |
| 43 | } |
| 44 | |
| 45 | } // namespace |
| 46 | |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 47 | TEST(StatusTrayTest, Create) { |
| 48 | // Check for creation and leaks. |
[email protected] | a24642a | 2010-03-24 21:29:05 | [diff] [blame] | 49 | TestStatusTray tray; |
mgiuca | 8367e72 | 2015-11-25 06:53:48 | [diff] [blame] | 50 | CreateStatusIcon(&tray); |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 51 | EXPECT_EQ(1U, tray.GetStatusIconsForTest().size()); |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 52 | } |
| 53 | |
[email protected] | 4c793f0 | 2010-08-18 20:55:45 | [diff] [blame] | 54 | // Make sure that removing an icon removes it from the list. |
| 55 | TEST(StatusTrayTest, CreateRemove) { |
[email protected] | a24642a | 2010-03-24 21:29:05 | [diff] [blame] | 56 | TestStatusTray tray; |
mgiuca | 8367e72 | 2015-11-25 06:53:48 | [diff] [blame] | 57 | StatusIcon* icon = CreateStatusIcon(&tray); |
[email protected] | 4b49fb0c | 2013-07-18 09:51:25 | [diff] [blame] | 58 | EXPECT_EQ(1U, tray.GetStatusIconsForTest().size()); |
[email protected] | 4c793f0 | 2010-08-18 20:55:45 | [diff] [blame] | 59 | tray.RemoveStatusIcon(icon); |
[email protected] | 4b49fb0c | 2013-07-18 09:51:25 | [diff] [blame] | 60 | EXPECT_EQ(0U, tray.GetStatusIconsForTest().size()); |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 61 | } |