Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: chrome/browser/status_icons/status_icon_unittest.cc

Issue 10408039: status_icons: Factor out status icon observer into its own header file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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"
6
5 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
6 #include "chrome/browser/status_icons/status_icon.h" 8 #include "chrome/browser/status_icons/status_icon_observer.h"
7 #include "testing/gmock/include/gmock/gmock.h" 9 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 11
10 class MockStatusIconObserver : public StatusIcon::Observer { 12 class MockStatusIconObserver : public StatusIconObserver {
11 public: 13 public:
12 MOCK_METHOD0(OnClicked, void()); 14 MOCK_METHOD0(OnStatusIconClicked, void());
13 }; 15 };
14 16
15 // Define pure virtual functions so we can test base class functionality. 17 // Define pure virtual functions so we can test base class functionality.
16 class TestStatusIcon : public StatusIcon { 18 class TestStatusIcon : public StatusIcon {
17 public: 19 public:
18 TestStatusIcon() {} 20 TestStatusIcon() {}
19 virtual void SetImage(const SkBitmap& image) OVERRIDE {} 21 virtual void SetImage(const SkBitmap& image) OVERRIDE {}
20 virtual void SetPressedImage(const SkBitmap& image) OVERRIDE {} 22 virtual void SetPressedImage(const SkBitmap& image) OVERRIDE {}
21 virtual void SetToolTip(const string16& tool_tip) OVERRIDE {} 23 virtual void SetToolTip(const string16& tool_tip) OVERRIDE {}
22 virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) OVERRIDE {} 24 virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) OVERRIDE {}
23 virtual void DisplayBalloon(const SkBitmap& icon, 25 virtual void DisplayBalloon(const SkBitmap& icon,
24 const string16& title, 26 const string16& title,
25 const string16& contents) OVERRIDE {} 27 const string16& contents) OVERRIDE {}
26 }; 28 };
27 29
28 TEST(StatusIconTest, ObserverAdd) { 30 TEST(StatusIconTest, ObserverAdd) {
29 // Make sure that observers are invoked when we click items. 31 // Make sure that observers are invoked when we click items.
30 TestStatusIcon icon; 32 TestStatusIcon icon;
31 MockStatusIconObserver observer, observer2; 33 MockStatusIconObserver observer, observer2;
32 EXPECT_CALL(observer, OnClicked()).Times(2); 34 EXPECT_CALL(observer, OnStatusIconClicked()).Times(2);
33 EXPECT_CALL(observer2, OnClicked()); 35 EXPECT_CALL(observer2, OnStatusIconClicked());
34 icon.AddObserver(&observer); 36 icon.AddObserver(&observer);
35 icon.DispatchClickEvent(); 37 icon.DispatchClickEvent();
36 icon.AddObserver(&observer2); 38 icon.AddObserver(&observer2);
37 icon.DispatchClickEvent(); 39 icon.DispatchClickEvent();
38 icon.RemoveObserver(&observer); 40 icon.RemoveObserver(&observer);
39 icon.RemoveObserver(&observer2); 41 icon.RemoveObserver(&observer2);
40 } 42 }
41 43
42 TEST(StatusIconTest, ObserverRemove) { 44 TEST(StatusIconTest, ObserverRemove) {
43 // Make sure that observers are no longer invoked after they are removed. 45 // Make sure that observers are no longer invoked after they are removed.
44 TestStatusIcon icon; 46 TestStatusIcon icon;
45 MockStatusIconObserver observer; 47 MockStatusIconObserver observer;
46 EXPECT_CALL(observer, OnClicked()); 48 EXPECT_CALL(observer, OnStatusIconClicked());
47 icon.AddObserver(&observer); 49 icon.AddObserver(&observer);
48 icon.DispatchClickEvent(); 50 icon.DispatchClickEvent();
49 icon.RemoveObserver(&observer); 51 icon.RemoveObserver(&observer);
50 icon.DispatchClickEvent(); 52 icon.DispatchClickEvent();
51 } 53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698