blob: 807866525592bbf8dd9b2bb7aa0a030b1467065b (
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
|
// Copyright (c) 2012 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 "chrome/browser/status_icons/status_icon.h"
#include "base/compiler_specific.h"
#include "chrome/browser/status_icons/status_icon_observer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
class MockStatusIconObserver : public StatusIconObserver {
public:
MOCK_METHOD0(OnStatusIconClicked, void());
};
// Define pure virtual functions so we can test base class functionality.
class TestStatusIcon : public StatusIcon {
public:
TestStatusIcon() {}
virtual void SetImage(const gfx::ImageSkia& image) OVERRIDE {}
virtual void SetPressedImage(const gfx::ImageSkia& image) OVERRIDE {}
virtual void SetToolTip(const string16& tool_tip) OVERRIDE {}
virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) OVERRIDE {}
virtual void DisplayBalloon(const gfx::ImageSkia& icon,
const string16& title,
const string16& contents) OVERRIDE {}
};
TEST(StatusIconTest, ObserverAdd) {
// Make sure that observers are invoked when we click items.
TestStatusIcon icon;
MockStatusIconObserver observer, observer2;
EXPECT_CALL(observer, OnStatusIconClicked()).Times(2);
EXPECT_CALL(observer2, OnStatusIconClicked());
icon.AddObserver(&observer);
icon.DispatchClickEvent();
icon.AddObserver(&observer2);
icon.DispatchClickEvent();
icon.RemoveObserver(&observer);
icon.RemoveObserver(&observer2);
}
TEST(StatusIconTest, ObserverRemove) {
// Make sure that observers are no longer invoked after they are removed.
TestStatusIcon icon;
MockStatusIconObserver observer;
EXPECT_CALL(observer, OnStatusIconClicked());
icon.AddObserver(&observer);
icon.DispatchClickEvent();
icon.RemoveObserver(&observer);
icon.DispatchClickEvent();
}
|