blob: 90f13299867181915606d1fca80d42d0b0667e09 [file] [log] [blame]
[email protected]baf5a3442012-04-21 22:48:321// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ccb55cf52010-03-06 22:02:042// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]a25fd452011-10-26 10:45:085#include "base/compiler_specific.h"
[email protected]24a555b62013-06-10 22:01:176#include "base/strings/string_util.h"
[email protected]e309f312013-06-07 21:50:087#include "base/strings/utf_string_conversions.h"
[email protected]ccb55cf52010-03-06 22:02:048#include "chrome/browser/status_icons/status_icon.h"
9#include "chrome/browser/status_icons/status_tray.h"
thestig8416a6b92014-09-03 02:48:4710#include "grit/chrome_unscaled_resources.h"
[email protected]ccb55cf52010-03-06 22:02:0411#include "testing/gtest/include/gtest/gtest.h"
[email protected]b6c510aa2013-07-31 23:36:1412#include "ui/base/resource/resource_bundle.h"
13#include "ui/gfx/image/image_skia.h"
johnme92956172015-10-15 16:54:1214#include "ui/message_center/notifier_settings.h"
[email protected]ccb55cf52010-03-06 22:02:0415
16class MockStatusIcon : public StatusIcon {
Daniel Chenga542fca2014-10-21 09:51:2917 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,
johnme92956172015-10-15 16:54:1221 const base::string16& contents,
22 const message_center::NotifierId& notifier_id) override {}
Daniel Chenga542fca2014-10-21 09:51:2923 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {}
[email protected]ccb55cf52010-03-06 22:02:0424};
25
[email protected]a24642a2010-03-24 21:29:0526class TestStatusTray : public StatusTray {
[email protected]ccb55cf52010-03-06 22:02:0427 public:
Daniel Chenga542fca2014-10-21 09:51:2928 StatusIcon* CreatePlatformStatusIcon(
[email protected]b6c510aa2013-07-31 23:36:1429 StatusIconType type,
30 const gfx::ImageSkia& image,
mostynbfb66cb4f2014-10-07 09:15:4231 const base::string16& tool_tip) override {
[email protected]b6c510aa2013-07-31 23:36:1432 return new MockStatusIcon();
33 }
[email protected]4b49fb0c2013-07-18 09:51:2534
35 const StatusIcons& GetStatusIconsForTest() const { return status_icons(); }
[email protected]ccb55cf52010-03-06 22:02:0436};
37
38TEST(StatusTrayTest, Create) {
39 // Check for creation and leaks.
[email protected]a24642a2010-03-24 21:29:0540 TestStatusTray tray;
[email protected]b6c510aa2013-07-31 23:36:1441 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
42 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
43 tray.CreateStatusIcon(
[email protected]f911df52013-12-24 23:24:2344 StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip"));
[email protected]b6c510aa2013-07-31 23:36:1445 EXPECT_EQ(1U, tray.GetStatusIconsForTest().size());
[email protected]ccb55cf52010-03-06 22:02:0446}
47
[email protected]4c793f02010-08-18 20:55:4548// Make sure that removing an icon removes it from the list.
49TEST(StatusTrayTest, CreateRemove) {
[email protected]a24642a2010-03-24 21:29:0550 TestStatusTray tray;
[email protected]b6c510aa2013-07-31 23:36:1451 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
52 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
53 StatusIcon* icon = tray.CreateStatusIcon(
[email protected]f911df52013-12-24 23:24:2354 StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip"));
[email protected]4b49fb0c2013-07-18 09:51:2555 EXPECT_EQ(1U, tray.GetStatusIconsForTest().size());
[email protected]4c793f02010-08-18 20:55:4556 tray.RemoveStatusIcon(icon);
[email protected]4b49fb0c2013-07-18 09:51:2557 EXPECT_EQ(0U, tray.GetStatusIconsForTest().size());
[email protected]ccb55cf52010-03-06 22:02:0458}