OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "app/resource_bundle.h" |
| 6 #include "base/string_util.h" |
| 7 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 8 #include "chrome/browser/cocoa/status_icons/status_icon_mac.h" |
| 9 #include "grit/browser_resources.h" |
| 10 #include "grit/theme_resources.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 class SkBitmap; |
| 15 |
| 16 class MockStatusIconObserver : public StatusIcon::StatusIconObserver { |
| 17 public: |
| 18 MOCK_METHOD0(OnClicked, void()); |
| 19 }; |
| 20 |
| 21 class StatusIconMacTest : public CocoaTest { |
| 22 }; |
| 23 |
| 24 TEST_F(StatusIconMacTest, Create) { |
| 25 // Create an icon, set the tool tip, then shut it down (checks for leaks). |
| 26 scoped_ptr<StatusIcon> icon(new StatusIconMac()); |
| 27 SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 28 IDR_STATUS_TRAY_ICON); |
| 29 icon->SetImage(*bitmap); |
| 30 icon->SetToolTip(ASCIIToUTF16("tool tip")); |
| 31 } |
| 32 |
| 33 TEST_F(StatusIconMacTest, ObserverAdd) { |
| 34 // Make sure that observers are invoked when we click items. |
| 35 StatusIconMac icon; |
| 36 MockStatusIconObserver observer, observer2; |
| 37 EXPECT_CALL(observer, OnClicked()).Times(2); |
| 38 EXPECT_CALL(observer2, OnClicked()); |
| 39 icon.AddObserver(&observer); |
| 40 icon.HandleClick(); |
| 41 icon.AddObserver(&observer2); |
| 42 icon.HandleClick(); |
| 43 icon.RemoveObserver(&observer); |
| 44 icon.RemoveObserver(&observer2); |
| 45 } |
| 46 |
| 47 TEST_F(StatusIconMacTest, ObserverRemove) { |
| 48 // Make sure that observers are no longer invoked after they are removed. |
| 49 StatusIconMac icon; |
| 50 MockStatusIconObserver observer; |
| 51 EXPECT_CALL(observer, OnClicked()); |
| 52 icon.AddObserver(&observer); |
| 53 icon.HandleClick(); |
| 54 icon.RemoveObserver(&observer); |
| 55 icon.HandleClick(); |
| 56 } |
| 57 |
OLD | NEW |