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
3 // found in the LICENSE file.
5 #include "base/strings/string_util.h"
6 #include "base/strings/sys_string_conversions.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/status_icons/status_icon_menu_model.h"
9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
10 #include "chrome/browser/ui/cocoa/status_icons/status_icon_mac.h"
11 #include "grit/chrome_unscaled_resources.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/base/resource/resource_bundle.h"
18 class StatusIconMacTest : public CocoaTest {
21 TEST_F(StatusIconMacTest, Create) {
22 // Create an icon, set the tool tip, then shut it down (checks for leaks).
23 scoped_ptr<StatusIcon> icon(new StatusIconMac());
24 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
25 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
26 icon->SetImage(*image);
27 gfx::ImageSkia* pressed = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON_PRESSED);
28 icon->SetPressedImage(*pressed);
29 icon->SetToolTip(base::ASCIIToUTF16("tool tip"));
32 TEST_F(StatusIconMacTest, CreateMenu) {
33 // Create a menu and verify by getting the title of the first menu item.
34 const char* menu_title = "Menu Title";
35 scoped_ptr<StatusIconMenuModel> model(new StatusIconMenuModel(NULL));
36 model->AddItem(0, base::ASCIIToUTF16(menu_title));
38 scoped_ptr<StatusIconMac> icon(new StatusIconMac());
39 icon->UpdatePlatformContextMenu(model.get());
40 EXPECT_EQ(1, [[icon->item() menu] numberOfItems]);
42 NSMenuItem* menuItem = [[icon->item() menu] itemAtIndex:0];
43 EXPECT_STREQ(menu_title, [[menuItem title] UTF8String]);
46 TEST_F(StatusIconMacTest, MenuToolTip) {
47 // Create a menu and set a tool tip. Verify the tool tip is inserted as the
49 const char* menu_title = "Menu Title";
50 const char* tool_tip = "Tool tip";
51 scoped_ptr<StatusIconMenuModel> model(new StatusIconMenuModel(NULL));
52 model->AddItem(0, base::ASCIIToUTF16(menu_title));
54 scoped_ptr<StatusIconMac> icon(new StatusIconMac());
55 icon->UpdatePlatformContextMenu(model.get());
56 icon->SetToolTip(base::ASCIIToUTF16(tool_tip));
57 EXPECT_EQ(2, [[icon->item() menu] numberOfItems]);
59 NSMenuItem* toolTipItem = [[icon->item() menu] itemAtIndex:0];
60 EXPECT_STREQ(tool_tip, [[toolTipItem title] UTF8String]);
61 NSMenuItem* menuItem = [[icon->item() menu] itemAtIndex:1];
62 EXPECT_STREQ(menu_title, [[menuItem title] UTF8String]);