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