summaryrefslogtreecommitdiffstats
path: root/chrome/browser/status_icons/status_tray_unittest.cc
blob: a10c5aa1bfe3ae6329969dbd7d17352fe0b6797f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/compiler_specific.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/status_icons/status_icon.h"
#include "chrome/browser/status_icons/status_tray.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

using testing::Return;

class MockStatusIcon : public StatusIcon {
  virtual void SetImage(const SkBitmap& image) OVERRIDE {}
  virtual void SetPressedImage(const SkBitmap& image) OVERRIDE {}
  virtual void SetToolTip(const string16& tool_tip) OVERRIDE {}
  virtual void DisplayBalloon(const SkBitmap& icon,
                              const string16& title,
                              const string16& contents) OVERRIDE {}
  virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) OVERRIDE {}
};

class TestStatusTray : public StatusTray {
 public:
  MOCK_METHOD0(CreatePlatformStatusIcon, StatusIcon*());
  MOCK_METHOD1(UpdatePlatformContextMenu, void(ui::MenuModel*));
};

TEST(StatusTrayTest, Create) {
  // Check for creation and leaks.
  TestStatusTray tray;
  EXPECT_CALL(tray,
      CreatePlatformStatusIcon()).WillOnce(Return(new MockStatusIcon()));
  tray.CreateStatusIcon();
}

// Make sure that removing an icon removes it from the list.
TEST(StatusTrayTest, CreateRemove) {
  TestStatusTray tray;
  EXPECT_CALL(tray,
      CreatePlatformStatusIcon()).WillOnce(Return(new MockStatusIcon()));
  StatusIcon* icon = tray.CreateStatusIcon();
  EXPECT_EQ(1U, tray.status_icons_.size());
  tray.RemoveStatusIcon(icon);
  EXPECT_EQ(0U, tray.status_icons_.size());
  // Calling again should do nothing.
  tray.RemoveStatusIcon(icon);
}