Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / status_icons / status_tray_win_unittest.cc
blob5502430a26824b4eaf4b3ce86bf009bb8bf98bf0
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 "chrome/browser/ui/views/status_icons/status_tray_win.h"
7 #include <commctrl.h>
9 #include "base/strings/string_util.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/status_icons/status_icon_menu_model.h"
12 #include "chrome/browser/status_icons/status_icon_observer.h"
13 #include "chrome/browser/ui/views/status_icons/status_icon_win.h"
14 #include "grit/chrome_unscaled_resources.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/image/image_skia.h"
19 class FakeStatusIconObserver : public StatusIconObserver {
20 public:
21 FakeStatusIconObserver()
22 : balloon_clicked_(false),
23 status_icon_click_count_(0) {}
24 virtual void OnStatusIconClicked() {
25 ++status_icon_click_count_;
27 virtual void OnBalloonClicked() { balloon_clicked_ = true; }
28 bool balloon_clicked() const { return balloon_clicked_; }
29 size_t status_icon_click_count() const {
30 return status_icon_click_count_;
33 private:
34 size_t status_icon_click_count_;
35 bool balloon_clicked_;
38 TEST(StatusTrayWinTest, CreateTray) {
39 // Just tests creation/destruction.
40 StatusTrayWin tray;
43 TEST(StatusTrayWinTest, CreateIconAndMenu) {
44 // Create an icon, set the images, tooltip, and context menu, then shut it
45 // down.
46 StatusTrayWin tray;
47 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
48 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
49 StatusIcon* icon = tray.CreateStatusIcon(
50 StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip"));
51 icon->SetPressedImage(*image);
52 scoped_ptr<StatusIconMenuModel> menu(new StatusIconMenuModel(NULL));
53 menu->AddItem(0, L"foo");
54 icon->SetContextMenu(menu.Pass());
57 #if !defined(USE_AURA) // http://crbug.com/156370
58 TEST(StatusTrayWinTest, ClickOnIcon) {
59 // Create an icon, send a fake click event, make sure observer is called.
60 StatusTrayWin tray;
61 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
62 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
64 StatusIconWin* icon = static_cast<StatusIconWin*>(tray.CreateStatusIcon(
65 StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip")));
66 FakeStatusIconObserver observer;
67 icon->AddObserver(&observer);
68 // Mimic a click.
69 tray.WndProc(NULL, icon->message_id(), icon->icon_id(), WM_LBUTTONDOWN);
70 // Mimic a right-click - observer should not be called.
71 tray.WndProc(NULL, icon->message_id(), icon->icon_id(), WM_RBUTTONDOWN);
72 EXPECT_EQ(1, observer.status_icon_click_count());
73 icon->RemoveObserver(&observer);
76 TEST(StatusTrayWinTest, ClickOnBalloon) {
77 // Create an icon, send a fake click event, make sure observer is called.
78 StatusTrayWin tray;
79 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
80 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
82 StatusIconWin* icon = static_cast<StatusIconWin*>(tray.CreateStatusIcon(
83 StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip")));
84 FakeStatusIconObserver observer;
85 icon->AddObserver(&observer);
86 // Mimic a click.
87 tray.WndProc(
88 NULL, icon->message_id(), icon->icon_id(), TB_INDETERMINATE);
89 EXPECT_TRUE(observer.balloon_clicked());
90 icon->RemoveObserver(&observer);
93 TEST(StatusTrayWinTest, HandleOldIconId) {
94 StatusTrayWin tray;
95 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
96 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
98 StatusIconWin* icon = static_cast<StatusIconWin*>(tray.CreateStatusIcon(
99 StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip")));
100 UINT message_id = icon->message_id();
101 UINT icon_id = icon->icon_id();
103 tray.RemoveStatusIcon(icon);
104 tray.WndProc(NULL, message_id, icon_id, WM_LBUTTONDOWN);
106 #endif // !defined(USE_AURA)