[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] | 24a555b6 | 2013-06-10 22:01:17 | [diff] [blame] | 6 | #include "base/strings/string_util.h" |
[email protected] | e309f31 | 2013-06-07 21:50:08 | [diff] [blame] | 7 | #include "base/strings/utf_string_conversions.h" |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 8 | #include "chrome/browser/status_icons/status_icon.h" |
| 9 | #include "chrome/browser/status_icons/status_tray.h" |
thestig | 8416a6b9 | 2014-09-03 02:48:47 | [diff] [blame] | 10 | #include "grit/chrome_unscaled_resources.h" |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 11 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 12 | #include "ui/base/resource/resource_bundle.h" |
| 13 | #include "ui/gfx/image/image_skia.h" |
johnme | 9295617 | 2015-10-15 16:54:12 | [diff] [blame^] | 14 | #include "ui/message_center/notifier_settings.h" |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 15 | |
| 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: |
Daniel Cheng | a542fca | 2014-10-21 09:51:29 | [diff] [blame] | 28 | 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 { |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 32 | return new MockStatusIcon(); |
| 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 | |
| 38 | TEST(StatusTrayTest, Create) { |
| 39 | // Check for creation and leaks. |
[email protected] | a24642a | 2010-03-24 21:29:05 | [diff] [blame] | 40 | TestStatusTray tray; |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 41 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 42 | gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON); |
| 43 | tray.CreateStatusIcon( |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 44 | StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip")); |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 45 | EXPECT_EQ(1U, tray.GetStatusIconsForTest().size()); |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 46 | } |
| 47 | |
[email protected] | 4c793f0 | 2010-08-18 20:55:45 | [diff] [blame] | 48 | // Make sure that removing an icon removes it from the list. |
| 49 | TEST(StatusTrayTest, CreateRemove) { |
[email protected] | a24642a | 2010-03-24 21:29:05 | [diff] [blame] | 50 | TestStatusTray tray; |
[email protected] | b6c510aa | 2013-07-31 23:36:14 | [diff] [blame] | 51 | ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 52 | gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON); |
| 53 | StatusIcon* icon = tray.CreateStatusIcon( |
[email protected] | f911df5 | 2013-12-24 23:24:23 | [diff] [blame] | 54 | StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip")); |
[email protected] | 4b49fb0c | 2013-07-18 09:51:25 | [diff] [blame] | 55 | EXPECT_EQ(1U, tray.GetStatusIconsForTest().size()); |
[email protected] | 4c793f0 | 2010-08-18 20:55:45 | [diff] [blame] | 56 | tray.RemoveStatusIcon(icon); |
[email protected] | 4b49fb0c | 2013-07-18 09:51:25 | [diff] [blame] | 57 | EXPECT_EQ(0U, tray.GetStatusIconsForTest().size()); |
[email protected] | ccb55cf5 | 2010-03-06 22:02:04 | [diff] [blame] | 58 | } |