OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/status_icons/status_icon.h" | 5 #include "chrome/browser/status_icons/status_icon.h" |
6 #include "testing/gmock/include/gmock/gmock.h" | 6 #include "testing/gmock/include/gmock/gmock.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 class MockStatusIconObserver : public StatusIcon::Observer { | 9 class MockStatusIconObserver : public StatusIcon::Observer { |
10 public: | 10 public: |
11 MOCK_METHOD0(OnClicked, void()); | 11 MOCK_METHOD0(OnClicked, void()); |
12 }; | 12 }; |
13 | 13 |
14 // Define pure virtual functions so we can test base class functionality. | 14 // Define pure virtual functions so we can test base class functionality. |
15 class TestStatusIcon : public StatusIcon { | 15 class TestStatusIcon : public StatusIcon { |
16 public: | 16 public: |
17 TestStatusIcon() {} | 17 TestStatusIcon() {} |
18 virtual void SetImage(const SkBitmap& image) {} | 18 virtual void SetImage(const SkBitmap& image) {} |
19 virtual void SetPressedImage(const SkBitmap& image) {} | 19 virtual void SetPressedImage(const SkBitmap& image) {} |
20 virtual void SetToolTip(const string16& tool_tip) {} | 20 virtual void SetToolTip(const string16& tool_tip) {} |
| 21 virtual void ResetContextMenu(menus::MenuModel* menu) {} |
21 }; | 22 }; |
22 | 23 |
23 TEST(StatusIconTest, ObserverAdd) { | 24 TEST(StatusIconTest, ObserverAdd) { |
24 // Make sure that observers are invoked when we click items. | 25 // Make sure that observers are invoked when we click items. |
25 TestStatusIcon icon; | 26 TestStatusIcon icon; |
26 MockStatusIconObserver observer, observer2; | 27 MockStatusIconObserver observer, observer2; |
27 EXPECT_CALL(observer, OnClicked()).Times(2); | 28 EXPECT_CALL(observer, OnClicked()).Times(2); |
28 EXPECT_CALL(observer2, OnClicked()); | 29 EXPECT_CALL(observer2, OnClicked()); |
29 icon.AddObserver(&observer); | 30 icon.AddObserver(&observer); |
30 icon.DispatchClickEvent(); | 31 icon.DispatchClickEvent(); |
31 icon.AddObserver(&observer2); | 32 icon.AddObserver(&observer2); |
32 icon.DispatchClickEvent(); | 33 icon.DispatchClickEvent(); |
33 icon.RemoveObserver(&observer); | 34 icon.RemoveObserver(&observer); |
34 icon.RemoveObserver(&observer2); | 35 icon.RemoveObserver(&observer2); |
35 } | 36 } |
36 | 37 |
37 TEST(StatusIconTest, ObserverRemove) { | 38 TEST(StatusIconTest, ObserverRemove) { |
38 // Make sure that observers are no longer invoked after they are removed. | 39 // Make sure that observers are no longer invoked after they are removed. |
39 TestStatusIcon icon; | 40 TestStatusIcon icon; |
40 MockStatusIconObserver observer; | 41 MockStatusIconObserver observer; |
41 EXPECT_CALL(observer, OnClicked()); | 42 EXPECT_CALL(observer, OnClicked()); |
42 icon.AddObserver(&observer); | 43 icon.AddObserver(&observer); |
43 icon.DispatchClickEvent(); | 44 icon.DispatchClickEvent(); |
44 icon.RemoveObserver(&observer); | 45 icon.RemoveObserver(&observer); |
45 icon.DispatchClickEvent(); | 46 icon.DispatchClickEvent(); |
46 } | 47 } |
47 | 48 |
OLD | NEW |