summaryrefslogtreecommitdiffstats
path: root/chrome/browser/status_icons/status_tray_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/status_icons/status_tray_unittest.cc')
-rw-r--r--chrome/browser/status_icons/status_tray_unittest.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/chrome/browser/status_icons/status_tray_unittest.cc b/chrome/browser/status_icons/status_tray_unittest.cc
new file mode 100644
index 0000000..01f9c30
--- /dev/null
+++ b/chrome/browser/status_icons/status_tray_unittest.cc
@@ -0,0 +1,56 @@
+// 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 "base/string_util.h"
+#include "chrome/browser/status_icons/status_icon.h"
+#include "chrome/browser/status_icons/status_tray.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::Return;
+
+class MockStatusIcon : public StatusIcon {
+ virtual void SetImage(const SkBitmap& image) {}
+ virtual void SetToolTip(const string16& tool_tip) {}
+ virtual void AddObserver(StatusIcon::StatusIconObserver* observer) {}
+ virtual void RemoveObserver(StatusIcon::StatusIconObserver* observer) {}
+};
+
+class TestStatusIconFactory : public StatusIconFactory {
+ public:
+ MOCK_METHOD0(CreateIcon, StatusIcon*());
+};
+
+TEST(StatusTrayTest, Create) {
+ // Check for creation and leaks.
+ TestStatusIconFactory* factory = new TestStatusIconFactory();
+ StatusTray tray(factory);
+ EXPECT_CALL(*factory, CreateIcon()).WillOnce(Return(new MockStatusIcon()));
+ tray.GetStatusIcon(ASCIIToUTF16("test"));
+}
+
+TEST(StatusTrayTest, GetIconTwice) {
+ TestStatusIconFactory* factory = new TestStatusIconFactory();
+ StatusTray tray(factory);
+ string16 id = ASCIIToUTF16("test");
+ // We should not try to create a new icon if we get the same ID twice.
+ EXPECT_CALL(*factory, CreateIcon()).WillOnce(Return(new MockStatusIcon()));
+ StatusIcon* icon = tray.GetStatusIcon(id);
+ EXPECT_EQ(icon, tray.GetStatusIcon(id));
+}
+
+TEST(StatusTrayTest, GetIconAfterRemove) {
+ TestStatusIconFactory* factory = new TestStatusIconFactory();
+ StatusTray tray(factory);
+ string16 id = ASCIIToUTF16("test");
+ EXPECT_CALL(*factory, CreateIcon()).Times(2)
+ .WillOnce(Return(new MockStatusIcon()))
+ .WillOnce(Return(new MockStatusIcon()));
+ StatusIcon* icon = tray.GetStatusIcon(id);
+ EXPECT_EQ(icon, tray.GetStatusIcon(id));
+
+ // If we remove the icon, then we should create a new one the next time in.
+ tray.RemoveStatusIcon(id);
+ tray.GetStatusIcon(id);
+}