| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "chrome/browser/status_icons/status_icon_observer.h" | 8 #include "chrome/browser/status_icons/status_icon_observer.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/message_center/notifier_settings.h" |
| 11 | 12 |
| 12 class MockStatusIconObserver : public StatusIconObserver { | 13 class MockStatusIconObserver : public StatusIconObserver { |
| 13 public: | 14 public: |
| 14 MOCK_METHOD0(OnStatusIconClicked, void()); | 15 MOCK_METHOD0(OnStatusIconClicked, void()); |
| 15 }; | 16 }; |
| 16 | 17 |
| 17 // Define pure virtual functions so we can test base class functionality. | 18 // Define pure virtual functions so we can test base class functionality. |
| 18 class TestStatusIcon : public StatusIcon { | 19 class TestStatusIcon : public StatusIcon { |
| 19 public: | 20 public: |
| 20 TestStatusIcon() {} | 21 TestStatusIcon() {} |
| 21 void SetImage(const gfx::ImageSkia& image) override {} | 22 void SetImage(const gfx::ImageSkia& image) override {} |
| 22 void SetToolTip(const base::string16& tool_tip) override {} | 23 void SetToolTip(const base::string16& tool_tip) override {} |
| 23 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {} | 24 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {} |
| 24 void DisplayBalloon(const gfx::ImageSkia& icon, | 25 void DisplayBalloon(const gfx::ImageSkia& icon, |
| 25 const base::string16& title, | 26 const base::string16& title, |
| 26 const base::string16& contents) override {} | 27 const base::string16& contents, |
| 28 const message_center::NotifierId& notifier_id) override {} |
| 27 }; | 29 }; |
| 28 | 30 |
| 29 TEST(StatusIconTest, ObserverAdd) { | 31 TEST(StatusIconTest, ObserverAdd) { |
| 30 // Make sure that observers are invoked when we click items. | 32 // Make sure that observers are invoked when we click items. |
| 31 TestStatusIcon icon; | 33 TestStatusIcon icon; |
| 32 MockStatusIconObserver observer, observer2; | 34 MockStatusIconObserver observer, observer2; |
| 33 EXPECT_CALL(observer, OnStatusIconClicked()).Times(2); | 35 EXPECT_CALL(observer, OnStatusIconClicked()).Times(2); |
| 34 EXPECT_CALL(observer2, OnStatusIconClicked()); | 36 EXPECT_CALL(observer2, OnStatusIconClicked()); |
| 35 icon.AddObserver(&observer); | 37 icon.AddObserver(&observer); |
| 36 icon.DispatchClickEvent(); | 38 icon.DispatchClickEvent(); |
| 37 icon.AddObserver(&observer2); | 39 icon.AddObserver(&observer2); |
| 38 icon.DispatchClickEvent(); | 40 icon.DispatchClickEvent(); |
| 39 icon.RemoveObserver(&observer); | 41 icon.RemoveObserver(&observer); |
| 40 icon.RemoveObserver(&observer2); | 42 icon.RemoveObserver(&observer2); |
| 41 } | 43 } |
| 42 | 44 |
| 43 TEST(StatusIconTest, ObserverRemove) { | 45 TEST(StatusIconTest, ObserverRemove) { |
| 44 // Make sure that observers are no longer invoked after they are removed. | 46 // Make sure that observers are no longer invoked after they are removed. |
| 45 TestStatusIcon icon; | 47 TestStatusIcon icon; |
| 46 MockStatusIconObserver observer; | 48 MockStatusIconObserver observer; |
| 47 EXPECT_CALL(observer, OnStatusIconClicked()); | 49 EXPECT_CALL(observer, OnStatusIconClicked()); |
| 48 icon.AddObserver(&observer); | 50 icon.AddObserver(&observer); |
| 49 icon.DispatchClickEvent(); | 51 icon.DispatchClickEvent(); |
| 50 icon.RemoveObserver(&observer); | 52 icon.RemoveObserver(&observer); |
| 51 icon.DispatchClickEvent(); | 53 icon.DispatchClickEvent(); |
| 52 } | 54 } |
| OLD | NEW |