blob: f9a1d47d38a97d71248e767ed28cf6de55ff27ec [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]ccb55cf52010-03-06 22:02:045#include "chrome/browser/status_icons/status_tray.h"
leon.han4ea301f2017-03-28 03:36:316
7#include "base/compiler_specific.h"
leon.han4ea301f2017-03-28 03:36:318#include "chrome/browser/status_icons/status_icon.h"
[email protected]ccb55cf52010-03-06 22:02:049#include "testing/gtest/include/gtest/gtest.h"
[email protected]b6c510aa2013-07-31 23:36:1410#include "ui/gfx/image/image_skia.h"
mgiuca8367e722015-11-25 06:53:4811#include "ui/gfx/image/image_unittest_util.h"
Evan Stade889ce4712018-01-28 15:26:2612#include "ui/message_center/public/cpp/notifier_id.h"
[email protected]ccb55cf52010-03-06 22:02:0413
mgiuca8367e722015-11-25 06:53:4814namespace {
15
[email protected]ccb55cf52010-03-06 22:02:0416class 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:
leon.han4ea301f2017-03-28 03:36:3128 std::unique_ptr<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 {
Jeremy Romanec48d7a2018-03-01 17:35:0932 return std::make_unique<MockStatusIcon>();
[email protected]b6c510aa2013-07-31 23:36:1433 }
[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
mgiuca8367e722015-11-25 06:53:4838StatusIcon* 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]ccb55cf52010-03-06 22:02:0447TEST(StatusTrayTest, Create) {
48 // Check for creation and leaks.
[email protected]a24642a2010-03-24 21:29:0549 TestStatusTray tray;
mgiuca8367e722015-11-25 06:53:4850 CreateStatusIcon(&tray);
[email protected]b6c510aa2013-07-31 23:36:1451 EXPECT_EQ(1U, tray.GetStatusIconsForTest().size());
[email protected]ccb55cf52010-03-06 22:02:0452}
53
[email protected]4c793f02010-08-18 20:55:4554// Make sure that removing an icon removes it from the list.
55TEST(StatusTrayTest, CreateRemove) {
[email protected]a24642a2010-03-24 21:29:0556 TestStatusTray tray;
mgiuca8367e722015-11-25 06:53:4857 StatusIcon* icon = CreateStatusIcon(&tray);
[email protected]4b49fb0c2013-07-18 09:51:2558 EXPECT_EQ(1U, tray.GetStatusIconsForTest().size());
[email protected]4c793f02010-08-18 20:55:4559 tray.RemoveStatusIcon(icon);
[email protected]4b49fb0c2013-07-18 09:51:2560 EXPECT_EQ(0U, tray.GetStatusIconsForTest().size());
[email protected]ccb55cf52010-03-06 22:02:0461}