| OLD | NEW |
| 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 "base/compiler_specific.h" |
| 5 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 6 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/status_icons/status_icon.h" | 8 #include "chrome/browser/status_icons/status_icon.h" |
| 8 #include "chrome/browser/status_icons/status_tray.h" | 9 #include "chrome/browser/status_icons/status_tray.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 using testing::Return; | 13 using testing::Return; |
| 13 | 14 |
| 14 class MockStatusIcon : public StatusIcon { | 15 class MockStatusIcon : public StatusIcon { |
| 15 virtual void SetImage(const SkBitmap& image) {} | 16 virtual void SetImage(const SkBitmap& image) OVERRIDE {} |
| 16 virtual void SetPressedImage(const SkBitmap& image) {} | 17 virtual void SetPressedImage(const SkBitmap& image) OVERRIDE {} |
| 17 virtual void SetToolTip(const string16& tool_tip) {} | 18 virtual void SetToolTip(const string16& tool_tip) OVERRIDE {} |
| 18 virtual void DisplayBalloon(const string16& title, | 19 virtual void DisplayBalloon(const SkBitmap& icon, |
| 19 const string16& contents) {} | 20 const string16& title, |
| 20 virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) {} | 21 const string16& contents) OVERRIDE {} |
| 21 virtual void AddObserver(StatusIcon::Observer* observer) {} | 22 virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) OVERRIDE {} |
| 22 virtual void RemoveObserver(StatusIcon::Observer* observer) {} | |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 class TestStatusTray : public StatusTray { | 25 class TestStatusTray : public StatusTray { |
| 26 public: | 26 public: |
| 27 MOCK_METHOD0(CreatePlatformStatusIcon, StatusIcon*()); | 27 MOCK_METHOD0(CreatePlatformStatusIcon, StatusIcon*()); |
| 28 MOCK_METHOD1(UpdatePlatformContextMenu, void(ui::MenuModel*)); | 28 MOCK_METHOD1(UpdatePlatformContextMenu, void(ui::MenuModel*)); |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 TEST(StatusTrayTest, Create) { | 31 TEST(StatusTrayTest, Create) { |
| 32 // Check for creation and leaks. | 32 // Check for creation and leaks. |
| 33 TestStatusTray tray; | 33 TestStatusTray tray; |
| 34 EXPECT_CALL(tray, | 34 EXPECT_CALL(tray, |
| 35 CreatePlatformStatusIcon()).WillOnce(Return(new MockStatusIcon())); | 35 CreatePlatformStatusIcon()).WillOnce(Return(new MockStatusIcon())); |
| 36 tray.CreateStatusIcon(); | 36 tray.CreateStatusIcon(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // Make sure that removing an icon removes it from the list. | 39 // Make sure that removing an icon removes it from the list. |
| 40 TEST(StatusTrayTest, CreateRemove) { | 40 TEST(StatusTrayTest, CreateRemove) { |
| 41 TestStatusTray tray; | 41 TestStatusTray tray; |
| 42 EXPECT_CALL(tray, | 42 EXPECT_CALL(tray, |
| 43 CreatePlatformStatusIcon()).WillOnce(Return(new MockStatusIcon())); | 43 CreatePlatformStatusIcon()).WillOnce(Return(new MockStatusIcon())); |
| 44 StatusIcon* icon = tray.CreateStatusIcon(); | 44 StatusIcon* icon = tray.CreateStatusIcon(); |
| 45 EXPECT_EQ(1U, tray.status_icons_.size()); | 45 EXPECT_EQ(1U, tray.status_icons_.size()); |
| 46 tray.RemoveStatusIcon(icon); | 46 tray.RemoveStatusIcon(icon); |
| 47 EXPECT_EQ(0U, tray.status_icons_.size()); | 47 EXPECT_EQ(0U, tray.status_icons_.size()); |
| 48 // Calling again should do nothing. | 48 // Calling again should do nothing. |
| 49 tray.RemoveStatusIcon(icon); | 49 tray.RemoveStatusIcon(icon); |
| 50 } | 50 } |
| OLD | NEW |