Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / status_icons / status_tray_unittest.cc
blob12adee34b4f74f7860bfe70c7046e4446e1beee0
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/compiler_specific.h"
6 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/status_icons/status_icon.h"
9 #include "chrome/browser/status_icons/status_tray.h"
10 #include "grit/chrome_unscaled_resources.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/image/image_skia.h"
15 class MockStatusIcon : public StatusIcon {
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,
20 const base::string16& contents) override {}
21 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {}
24 class TestStatusTray : public StatusTray {
25 public:
26 StatusIcon* CreatePlatformStatusIcon(
27 StatusIconType type,
28 const gfx::ImageSkia& image,
29 const base::string16& tool_tip) override {
30 return new MockStatusIcon();
33 const StatusIcons& GetStatusIconsForTest() const { return status_icons(); }
36 TEST(StatusTrayTest, Create) {
37 // Check for creation and leaks.
38 TestStatusTray tray;
39 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
40 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
41 tray.CreateStatusIcon(
42 StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip"));
43 EXPECT_EQ(1U, tray.GetStatusIconsForTest().size());
46 // Make sure that removing an icon removes it from the list.
47 TEST(StatusTrayTest, CreateRemove) {
48 TestStatusTray tray;
49 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
50 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
51 StatusIcon* icon = tray.CreateStatusIcon(
52 StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip"));
53 EXPECT_EQ(1U, tray.GetStatusIconsForTest().size());
54 tray.RemoveStatusIcon(icon);
55 EXPECT_EQ(0U, tray.GetStatusIconsForTest().size());