blob: 48fbc2062d816b364e6183c8e5d167d0c705f73c (
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
|
// 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 "chrome/browser/status_icons/status_icon.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
class MockStatusIconObserver : public StatusIcon::Observer {
public:
MOCK_METHOD0(OnClicked, void());
};
// Define pure virtual functions so we can test base class functionality.
class TestStatusIcon : public StatusIcon {
public:
TestStatusIcon() {}
virtual void SetImage(const SkBitmap& image) {}
virtual void SetPressedImage(const SkBitmap& image) {}
virtual void SetToolTip(const string16& tool_tip) {}
virtual void UpdatePlatformContextMenu(menus::MenuModel* menu) {}
};
TEST(StatusIconTest, ObserverAdd) {
// Make sure that observers are invoked when we click items.
TestStatusIcon icon;
MockStatusIconObserver observer, observer2;
EXPECT_CALL(observer, OnClicked()).Times(2);
EXPECT_CALL(observer2, OnClicked());
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, OnClicked());
icon.AddObserver(&observer);
icon.DispatchClickEvent();
icon.RemoveObserver(&observer);
icon.DispatchClickEvent();
}
|