• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
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"
14 
15 class MockStatusIcon : public StatusIcon {
SetImage(const gfx::ImageSkia & image)16   virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE {}
SetToolTip(const base::string16 & tool_tip)17   virtual void SetToolTip(const base::string16& tool_tip) OVERRIDE {}
DisplayBalloon(const gfx::ImageSkia & icon,const base::string16 & title,const base::string16 & contents)18   virtual void DisplayBalloon(const gfx::ImageSkia& icon,
19                               const base::string16& title,
20                               const base::string16& contents) OVERRIDE {}
UpdatePlatformContextMenu(StatusIconMenuModel * menu)21   virtual void UpdatePlatformContextMenu(
22       StatusIconMenuModel* menu) OVERRIDE {}
23 };
24 
25 class TestStatusTray : public StatusTray {
26  public:
CreatePlatformStatusIcon(StatusIconType type,const gfx::ImageSkia & image,const base::string16 & tool_tip)27   virtual StatusIcon* CreatePlatformStatusIcon(
28       StatusIconType type,
29       const gfx::ImageSkia& image,
30       const base::string16& tool_tip) OVERRIDE {
31     return new MockStatusIcon();
32   }
33 
GetStatusIconsForTest() const34   const StatusIcons& GetStatusIconsForTest() const { return status_icons(); }
35 };
36 
TEST(StatusTrayTest,Create)37 TEST(StatusTrayTest, Create) {
38   // Check for creation and leaks.
39   TestStatusTray tray;
40   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
41   gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
42   tray.CreateStatusIcon(
43       StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip"));
44   EXPECT_EQ(1U, tray.GetStatusIconsForTest().size());
45 }
46 
47 // Make sure that removing an icon removes it from the list.
TEST(StatusTrayTest,CreateRemove)48 TEST(StatusTrayTest, CreateRemove) {
49   TestStatusTray tray;
50   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
51   gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
52   StatusIcon* icon = tray.CreateStatusIcon(
53       StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip"));
54   EXPECT_EQ(1U, tray.GetStatusIconsForTest().size());
55   tray.RemoveStatusIcon(icon);
56   EXPECT_EQ(0U, tray.GetStatusIconsForTest().size());
57 }
58