blob: 01f9c3090d568de2c7ff09e08e3f206893a821f1 (
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
56
|
// 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 "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 SetToolTip(const string16& tool_tip) {}
virtual void AddObserver(StatusIcon::StatusIconObserver* observer) {}
virtual void RemoveObserver(StatusIcon::StatusIconObserver* observer) {}
};
class TestStatusIconFactory : public StatusIconFactory {
public:
MOCK_METHOD0(CreateIcon, StatusIcon*());
};
TEST(StatusTrayTest, Create) {
// Check for creation and leaks.
TestStatusIconFactory* factory = new TestStatusIconFactory();
StatusTray tray(factory);
EXPECT_CALL(*factory, CreateIcon()).WillOnce(Return(new MockStatusIcon()));
tray.GetStatusIcon(ASCIIToUTF16("test"));
}
TEST(StatusTrayTest, GetIconTwice) {
TestStatusIconFactory* factory = new TestStatusIconFactory();
StatusTray tray(factory);
string16 id = ASCIIToUTF16("test");
// We should not try to create a new icon if we get the same ID twice.
EXPECT_CALL(*factory, CreateIcon()).WillOnce(Return(new MockStatusIcon()));
StatusIcon* icon = tray.GetStatusIcon(id);
EXPECT_EQ(icon, tray.GetStatusIcon(id));
}
TEST(StatusTrayTest, GetIconAfterRemove) {
TestStatusIconFactory* factory = new TestStatusIconFactory();
StatusTray tray(factory);
string16 id = ASCIIToUTF16("test");
EXPECT_CALL(*factory, CreateIcon()).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);
}
|