Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/status_icons/status_tray_unittest.cc

Issue 1420163003: Fixed Windows system tray icon. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@profile-icon-imagefamily
Patch Set: Remove IDR_STATUS_TRAY_ICON on Win, and update tests to account for this. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/strings/string_util.h" 6 #include "base/strings/string_util.h"
msw 2015/11/12 00:43:29 Remove; not used.
Matt Giuca 2015/11/12 04:44:39 Done.
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/status_icons/status_icon.h" 8 #include "chrome/browser/status_icons/status_icon.h"
9 #include "chrome/browser/status_icons/status_tray.h" 9 #include "chrome/browser/status_icons/status_tray.h"
10 #include "grit/chrome_unscaled_resources.h"
11 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/image/image_skia.h" 11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/gfx/image/image_unittest_util.h"
14 #include "ui/message_center/notifier_settings.h" 13 #include "ui/message_center/notifier_settings.h"
15 14
15 namespace {
16
16 class MockStatusIcon : public StatusIcon { 17 class MockStatusIcon : public StatusIcon {
17 void SetImage(const gfx::ImageSkia& image) override {} 18 void SetImage(const gfx::ImageSkia& image) override {}
18 void SetToolTip(const base::string16& tool_tip) override {} 19 void SetToolTip(const base::string16& tool_tip) override {}
19 void DisplayBalloon(const gfx::ImageSkia& icon, 20 void DisplayBalloon(const gfx::ImageSkia& icon,
20 const base::string16& title, 21 const base::string16& title,
21 const base::string16& contents, 22 const base::string16& contents,
22 const message_center::NotifierId& notifier_id) override {} 23 const message_center::NotifierId& notifier_id) override {}
23 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {} 24 void UpdatePlatformContextMenu(StatusIconMenuModel* menu) override {}
24 }; 25 };
25 26
26 class TestStatusTray : public StatusTray { 27 class TestStatusTray : public StatusTray {
27 public: 28 public:
28 StatusIcon* CreatePlatformStatusIcon( 29 StatusIcon* CreatePlatformStatusIcon(
29 StatusIconType type, 30 StatusIconType type,
30 const gfx::ImageSkia& image, 31 const gfx::ImageSkia& image,
31 const base::string16& tool_tip) override { 32 const base::string16& tool_tip) override {
32 return new MockStatusIcon(); 33 return new MockStatusIcon();
33 } 34 }
34 35
35 const StatusIcons& GetStatusIconsForTest() const { return status_icons(); } 36 const StatusIcons& GetStatusIconsForTest() const { return status_icons(); }
36 }; 37 };
37 38
39 StatusIcon* CreateStatusIcon(StatusTray* tray) {
40 // Note: IDR_STATUS_TRAY_ICON is not available on Windows, so just create a
msw 2015/11/12 00:43:29 nit: consider "Just create a dummy icon image; the
Matt Giuca 2015/11/12 04:44:39 Done.
41 // dummy icon image.
42 gfx::ImageSkia image = gfx::test::CreateImageSkia(16, 16);
msw 2015/11/12 00:43:29 nit: inline below?
Matt Giuca 2015/11/12 04:44:39 Done.
43 return tray->CreateStatusIcon(
44 StatusTray::OTHER_ICON, image, base::ASCIIToUTF16("tool tip"));
msw 2015/11/12 00:43:29 nit: use a blank string16() and remove utf_string_
Matt Giuca 2015/11/12 04:44:39 Done.
45 }
46
47 } // namespace
48
38 TEST(StatusTrayTest, Create) { 49 TEST(StatusTrayTest, Create) {
39 // Check for creation and leaks. 50 // Check for creation and leaks.
40 TestStatusTray tray; 51 TestStatusTray tray;
41 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 52 CreateStatusIcon(&tray);
42 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
43 tray.CreateStatusIcon(
44 StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip"));
45 EXPECT_EQ(1U, tray.GetStatusIconsForTest().size()); 53 EXPECT_EQ(1U, tray.GetStatusIconsForTest().size());
46 } 54 }
47 55
48 // Make sure that removing an icon removes it from the list. 56 // Make sure that removing an icon removes it from the list.
49 TEST(StatusTrayTest, CreateRemove) { 57 TEST(StatusTrayTest, CreateRemove) {
50 TestStatusTray tray; 58 TestStatusTray tray;
51 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 59 StatusIcon* icon = CreateStatusIcon(&tray);
52 gfx::ImageSkia* image = rb.GetImageSkiaNamed(IDR_STATUS_TRAY_ICON);
53 StatusIcon* icon = tray.CreateStatusIcon(
54 StatusTray::OTHER_ICON, *image, base::ASCIIToUTF16("tool tip"));
55 EXPECT_EQ(1U, tray.GetStatusIconsForTest().size()); 60 EXPECT_EQ(1U, tray.GetStatusIconsForTest().size());
56 tray.RemoveStatusIcon(icon); 61 tray.RemoveStatusIcon(icon);
57 EXPECT_EQ(0U, tray.GetStatusIconsForTest().size()); 62 EXPECT_EQ(0U, tray.GetStatusIconsForTest().size());
58 } 63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698