summaryrefslogtreecommitdiffstats
path: root/chrome/browser/status_icons/status_tray_unittest.cc
blob: 957faa7c45fb562b6654ad02ce9327b2f9d24198 (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
51
52
53
54
55
// Copyright (c) 2010 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/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) {}
  virtual void SetPressedImage(const SkBitmap& image) {}
  virtual void SetToolTip(const string16& tool_tip) {}
  virtual void AddObserver(StatusIcon::Observer* observer) {}
  virtual void RemoveObserver(StatusIcon::Observer* observer) {}
};

class TestStatusTray : public StatusTray {
 public:
  MOCK_METHOD0(CreateStatusIcon, StatusIcon*());
};

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

TEST(StatusTrayTest, GetIconTwice) {
  TestStatusTray tray;
  string16 id = ASCIIToUTF16("test");
  // We should not try to create a new icon if we get the same ID twice.
  EXPECT_CALL(tray, CreateStatusIcon()).WillOnce(Return(new MockStatusIcon()));
  StatusIcon* icon =  tray.GetStatusIcon(id);
  EXPECT_EQ(icon, tray.GetStatusIcon(id));
}

TEST(StatusTrayTest, GetIconAfterRemove) {
  TestStatusTray tray;
  string16 id = ASCIIToUTF16("test");
  EXPECT_CALL(tray, CreateStatusIcon()).Times(2)
      .WillOnce(Return(new MockStatusIcon()))
      .WillOnce(Return(new MockStatusIcon()));
  StatusIcon* icon =  tray.GetStatusIcon(id);
  EXPECT_EQ(icon, tray.GetStatusIcon(id));

  // If we remove the icon, then we should create a new one the next time in.
  tray.RemoveStatusIcon(id);
  tray.GetStatusIcon(id);
}