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

Side by Side Diff: chrome/browser/ui/views/message_center/tray_watcher_win_browsertest.cc

Issue 110693004: Moves the notification icon out of the status area overflow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address sky+cpu first comments. Created 6 years, 9 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 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 "chrome/browser/ui/views/message_center/tray_watcher_win.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/win/scoped_com_initializer.h"
9 #include "chrome/browser/status_icons/status_icon.h"
10 #include "chrome/browser/ui/views/status_icons/status_icon_win.h"
11 #include "chrome/browser/ui/views/status_icons/status_tray_win.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/gfx/image/image_skia.h"
15
16 namespace message_center {
17
18 class TrayWatcherWinTest : public InProcessBrowserTest {
19 public:
20 TrayWatcherWinTest() {}
21
22 void SetUpOnMainThread() OVERRIDE {
23 com_.reset(new base::win::ScopedCOMInitializer());
24 status_tray_.reset(new StatusTrayWin());
25 SkBitmap bitmap;
26
27 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
28 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
29 bitmap.allocPixels();
30 bitmap.eraseColor(SK_ColorGREEN);
31 StatusIcon* status_icon = status_tray_->CreateStatusIcon(
32 StatusTray::OTHER_ICON,
33 gfx::ImageSkia::CreateFrom1xBitmap(bitmap),
34 base::string16());
35 status_icon_win_ = status_icon->AsStatusIconWin();
36 tray_watcher_ = new TrayWatcherWin(status_icon_win_->icon_id(),
37 status_icon_win_->window());
38 }
39
40 void CleanUpOnMainThread() OVERRIDE {
41 tray_watcher_ = NULL;
42 status_tray_.reset();
43 com_.reset();
44 }
45
46 protected:
47 HWND icon_window() { return status_icon_win_->window(); }
48 UINT icon_id() { return status_icon_win_->icon_id(); }
49
50 scoped_ptr<NOTIFYITEM> SetupAndGetCurrentNotifyItem() {
51 EXPECT_TRUE(CallCreateTrayNotify());
52 EXPECT_TRUE(IsInterfaceKnown());
53 scoped_ptr<NOTIFYITEM> notify_item = GetNotifyItem();
54 EXPECT_TRUE(notify_item.get() != NULL);
55 DCHECK_EQ(notify_item->hWnd, icon_window());
56 DCHECK_EQ(notify_item->uID, icon_id());
57 EXPECT_TRUE(notify_item->dwPreference == PREFERENCE_SHOW_WHEN_ACTIVE);
58
59 return notify_item.Pass();
60 }
61
62 bool CallCreateTrayNotify() { return tray_watcher_->CreateTrayNotify(); }
63
64 bool IsInterfaceKnown() {
65 return TrayWatcherWin::INTERFACE_VERSION_UNKNOWN !=
66 tray_watcher_->interface_version_;
67 }
68
69 void SendNotifyItemUpdate(scoped_ptr<NOTIFYITEM> notify_item) {
70 tray_watcher_->SendNotifyItemUpdate(notify_item.Pass());
71 }
72
73 scoped_ptr<NOTIFYITEM> GetNotifyItem() {
74 return tray_watcher_->RegisterCallback();
75 }
76
77 scoped_ptr<base::win::ScopedCOMInitializer> com_;
78 scoped_ptr<StatusTrayWin> status_tray_;
79 scoped_refptr<TrayWatcherWin> tray_watcher_;
80
81 StatusIconWin* status_icon_win_;
82
83 DISALLOW_COPY_AND_ASSIGN(TrayWatcherWinTest);
84 };
85
86 IN_PROC_BROWSER_TEST_F(TrayWatcherWinTest, Setup) {
87 // This tests the code path that will read the NOTIFYITEM data structure for
88 // use in future tests.
89 scoped_ptr<NOTIFYITEM> notify_item = SetupAndGetCurrentNotifyItem();
90 EXPECT_FALSE(notify_item.get() == NULL);
91 }
92
93 IN_PROC_BROWSER_TEST_F(TrayWatcherWinTest, ComApiTest) {
94
95 // Setup code to read the current preference.
96 scoped_ptr<NOTIFYITEM> notify_item = SetupAndGetCurrentNotifyItem();
97 ASSERT_TRUE(notify_item.get() != NULL);
98
99 // Store the current pref.
100 DWORD current_preference = notify_item->dwPreference;
101
102 // Ensure that running our code will do something.
103 if (notify_item->dwPreference != PREFERENCE_SHOW_WHEN_ACTIVE) {
104 scoped_ptr<NOTIFYITEM> notify_item_copy(new NOTIFYITEM(*notify_item));
105 notify_item_copy->dwPreference = PREFERENCE_SHOW_WHEN_ACTIVE;
106 SendNotifyItemUpdate(notify_item_copy.Pass());
107 }
108
109 // Run the interesting code.
110 tray_watcher_->EnsureTrayIconVisible();
111
112 EXPECT_EQ(GetNotifyItem()->dwPreference, PREFERENCE_SHOW_ALWAYS);
113 SendNotifyItemUpdate(notify_item.Pass());
114 notify_item = GetNotifyItem();
115
116 EXPECT_EQ(notify_item->dwPreference, current_preference);
117 };
118
119 IN_PROC_BROWSER_TEST_F(TrayWatcherWinTest, TraySizeApiTest) {
120 // Used to reset operating system state afterwards.
121 scoped_ptr<NOTIFYITEM> notify_item = SetupAndGetCurrentNotifyItem();
122 // We can't actually run this test if we're already showing the icon.
123 if (notify_item->dwPreference = PREFERENCE_SHOW_ALWAYS)
124 return;
125
126 // This test can only run if the tray window structure conforms to what I've
127 // seen in Win7 and Win8.
128 HWND shell_tray_hwnd = ::FindWindow(L"Shell_TrayWnd", NULL);
129 if (shell_tray_hwnd == NULL)
130 return;
131
132 HWND tray_notify_hwnd =
133 ::FindWindowEx(shell_tray_hwnd, NULL, L"TrayNotifyWnd", NULL);
134 ASSERT_TRUE(tray_notify_hwnd != NULL);
135
136 RECT original_tray_notify_rect;
137 ::GetWindowRect(tray_notify_hwnd, &original_tray_notify_rect);
138
139 LONG width = original_tray_notify_rect.right - original_tray_notify_rect.left;
140 ASSERT_GT(width, 0);
141
142 tray_watcher_->EnsureTrayIconVisible();
143
144 RECT new_tray_notify_rect;
145 ::GetWindowRect(tray_notify_hwnd, &new_tray_notify_rect);
146
147 LONG new_width = new_tray_notify_rect.right - new_tray_notify_rect.left;
148
149 EXPECT_GT(new_width, width);
150
151 SendNotifyItemUpdate(notify_item.Pass());
152 ::GetWindowRect(tray_notify_hwnd, &new_tray_notify_rect);
153 new_width = new_tray_notify_rect.right - new_tray_notify_rect.left;
154 EXPECT_EQ(width, new_width);
155 }
156
157 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698