OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "app/menus/simple_menu_model.h" |
5 #include "app/resource_bundle.h" | 6 #include "app/resource_bundle.h" |
6 #include "base/string_util.h" | 7 #include "base/string_util.h" |
7 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/views/status_icons/status_icon_win.h" | 9 #include "chrome/browser/views/status_icons/status_icon_win.h" |
9 #include "chrome/browser/views/status_icons/status_tray_win.h" | 10 #include "chrome/browser/views/status_icons/status_tray_win.h" |
10 #include "grit/browser_resources.h" | 11 #include "grit/browser_resources.h" |
11 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 class SkBitmap; | 16 class SkBitmap; |
16 | 17 |
17 class MockStatusIconObserver : public StatusIcon::Observer { | 18 class MockStatusIconObserver : public StatusIcon::Observer { |
18 public: | 19 public: |
19 MOCK_METHOD0(OnClicked, void()); | 20 MOCK_METHOD0(OnClicked, void()); |
20 }; | 21 }; |
21 | 22 |
22 TEST(StatusTrayWinTest, CreateTray) { | 23 TEST(StatusTrayWinTest, CreateTray) { |
23 // Just tests creation/destruction. | 24 // Just tests creation/destruction. |
24 StatusTrayWin tray; | 25 StatusTrayWin tray; |
25 } | 26 } |
26 | 27 |
27 TEST(StatusTrayWinTest, CreateIcon) { | 28 TEST(StatusTrayWinTest, CreateIconAndMenu) { |
28 // Create an icon, set the images and tooltip, then shut it down. | 29 // Create an icon, set the images, tooltip, and context menu, then shut it |
| 30 // down. |
29 StatusTrayWin tray; | 31 StatusTrayWin tray; |
30 StatusIcon* icon = tray.CreateStatusIcon(); | 32 StatusIcon* icon = tray.CreateStatusIcon(); |
31 SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 33 SkBitmap* bitmap = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
32 IDR_STATUS_TRAY_ICON); | 34 IDR_STATUS_TRAY_ICON); |
33 icon->SetImage(*bitmap); | 35 icon->SetImage(*bitmap); |
34 icon->SetPressedImage(*bitmap); | 36 icon->SetPressedImage(*bitmap); |
35 icon->SetToolTip(ASCIIToUTF16("tool tip")); | 37 icon->SetToolTip(ASCIIToUTF16("tool tip")); |
| 38 menus::SimpleMenuModel* menu = new menus::SimpleMenuModel(NULL); |
| 39 menu->AddItem(0, L"foo"); |
| 40 icon->SetContextMenu(menu); |
36 } | 41 } |
37 | 42 |
38 TEST(StatusTrayWinTest, ClickOnIcon) { | 43 TEST(StatusTrayWinTest, ClickOnIcon) { |
39 // Create an icon, send a fake click event, make sure observer is called. | 44 // Create an icon, send a fake click event, make sure observer is called. |
40 StatusTrayWin tray; | 45 StatusTrayWin tray; |
41 StatusIconWin* icon = static_cast<StatusIconWin*>(tray.CreateStatusIcon()); | 46 StatusIconWin* icon = static_cast<StatusIconWin*>(tray.CreateStatusIcon()); |
42 MockStatusIconObserver observer; | 47 MockStatusIconObserver observer; |
43 icon->AddObserver(&observer); | 48 icon->AddObserver(&observer); |
44 EXPECT_CALL(observer, OnClicked()); | 49 EXPECT_CALL(observer, OnClicked()); |
45 // Mimic a click. | 50 // Mimic a click. |
46 tray.WndProc(NULL, icon->message_id(), icon->icon_id(), WM_LBUTTONDOWN); | 51 tray.WndProc(NULL, icon->message_id(), icon->icon_id(), WM_LBUTTONDOWN); |
| 52 // Mimic a right-click - observer should not be called. |
| 53 tray.WndProc(NULL, icon->message_id(), icon->icon_id(), WM_RBUTTONDOWN); |
47 icon->RemoveObserver(&observer); | 54 icon->RemoveObserver(&observer); |
48 } | 55 } |
OLD | NEW |