OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h" | 5 #include <memory> |
6 | |
7 #include <utility> | 6 #include <utility> |
8 | 7 |
9 #include "base/macros.h" | 8 #include "base/macros.h" |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/win/scoped_com_initializer.h" | 9 #include "base/win/scoped_com_initializer.h" |
12 #include "base/win/windows_version.h" | 10 #include "base/win/windows_version.h" |
13 #include "chrome/browser/status_icons/status_icon.h" | 11 #include "chrome/browser/status_icons/status_icon.h" |
14 #include "chrome/browser/ui/views/status_icons/status_icon_win.h" | 12 #include "chrome/browser/ui/views/status_icons/status_icon_win.h" |
| 13 #include "chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h" |
15 #include "chrome/browser/ui/views/status_icons/status_tray_win.h" | 14 #include "chrome/browser/ui/views/status_icons/status_tray_win.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/skia/include/core/SkBitmap.h" | 16 #include "third_party/skia/include/core/SkBitmap.h" |
18 #include "ui/gfx/image/image_skia.h" | 17 #include "ui/gfx/image/image_skia.h" |
19 | 18 |
20 class StatusTrayStateChangerWinTest : public testing::Test { | 19 class StatusTrayStateChangerWinTest : public testing::Test { |
21 public: | 20 public: |
22 StatusTrayStateChangerWinTest() {} | 21 StatusTrayStateChangerWinTest() {} |
23 | 22 |
24 void SetUp() override { | 23 void SetUp() override { |
(...skipping 17 matching lines...) Expand all Loading... |
42 tray_watcher_ = NULL; | 41 tray_watcher_ = NULL; |
43 status_tray_.reset(); | 42 status_tray_.reset(); |
44 com_.reset(); | 43 com_.reset(); |
45 testing::Test::TearDown(); | 44 testing::Test::TearDown(); |
46 } | 45 } |
47 | 46 |
48 protected: | 47 protected: |
49 HWND icon_window() { return status_icon_win_->window(); } | 48 HWND icon_window() { return status_icon_win_->window(); } |
50 UINT icon_id() { return status_icon_win_->icon_id(); } | 49 UINT icon_id() { return status_icon_win_->icon_id(); } |
51 | 50 |
52 scoped_ptr<NOTIFYITEM> SetupAndGetCurrentNotifyItem() { | 51 std::unique_ptr<NOTIFYITEM> SetupAndGetCurrentNotifyItem() { |
53 EXPECT_TRUE(CallCreateTrayNotify()); | 52 EXPECT_TRUE(CallCreateTrayNotify()); |
54 | 53 |
55 EXPECT_TRUE(IsInterfaceKnown()); | 54 EXPECT_TRUE(IsInterfaceKnown()); |
56 | 55 |
57 scoped_ptr<NOTIFYITEM> notify_item = GetNotifyItem(); | 56 std::unique_ptr<NOTIFYITEM> notify_item = GetNotifyItem(); |
58 EXPECT_TRUE(notify_item.get() != NULL); | 57 EXPECT_TRUE(notify_item.get() != NULL); |
59 DCHECK_EQ(notify_item->hwnd, icon_window()); | 58 DCHECK_EQ(notify_item->hwnd, icon_window()); |
60 DCHECK_EQ(notify_item->id, icon_id()); | 59 DCHECK_EQ(notify_item->id, icon_id()); |
61 | 60 |
62 return notify_item; | 61 return notify_item; |
63 } | 62 } |
64 | 63 |
65 bool CallCreateTrayNotify() { return tray_watcher_->CreateTrayNotify(); } | 64 bool CallCreateTrayNotify() { return tray_watcher_->CreateTrayNotify(); } |
66 | 65 |
67 bool IsInterfaceKnown() { | 66 bool IsInterfaceKnown() { |
68 return StatusTrayStateChangerWin::INTERFACE_VERSION_UNKNOWN != | 67 return StatusTrayStateChangerWin::INTERFACE_VERSION_UNKNOWN != |
69 tray_watcher_->interface_version_; | 68 tray_watcher_->interface_version_; |
70 } | 69 } |
71 | 70 |
72 void SendNotifyItemUpdate(scoped_ptr<NOTIFYITEM> notify_item) { | 71 void SendNotifyItemUpdate(std::unique_ptr<NOTIFYITEM> notify_item) { |
73 tray_watcher_->SendNotifyItemUpdate(std::move(notify_item)); | 72 tray_watcher_->SendNotifyItemUpdate(std::move(notify_item)); |
74 } | 73 } |
75 | 74 |
76 scoped_ptr<NOTIFYITEM> GetNotifyItem() { | 75 std::unique_ptr<NOTIFYITEM> GetNotifyItem() { |
77 return tray_watcher_->RegisterCallback(); | 76 return tray_watcher_->RegisterCallback(); |
78 } | 77 } |
79 | 78 |
80 scoped_ptr<base::win::ScopedCOMInitializer> com_; | 79 std::unique_ptr<base::win::ScopedCOMInitializer> com_; |
81 scoped_ptr<StatusTrayWin> status_tray_; | 80 std::unique_ptr<StatusTrayWin> status_tray_; |
82 scoped_refptr<StatusTrayStateChangerWin> tray_watcher_; | 81 scoped_refptr<StatusTrayStateChangerWin> tray_watcher_; |
83 | 82 |
84 StatusIconWin* status_icon_win_; | 83 StatusIconWin* status_icon_win_; |
85 | 84 |
86 DISALLOW_COPY_AND_ASSIGN(StatusTrayStateChangerWinTest); | 85 DISALLOW_COPY_AND_ASSIGN(StatusTrayStateChangerWinTest); |
87 }; | 86 }; |
88 | 87 |
89 // Test is disabled due to multiple COM initialization errors. See | 88 // Test is disabled due to multiple COM initialization errors. See |
90 // http//crbug.com/367199 for details. | 89 // http//crbug.com/367199 for details. |
91 TEST_F(StatusTrayStateChangerWinTest, DISABLED_Setup) { | 90 TEST_F(StatusTrayStateChangerWinTest, DISABLED_Setup) { |
92 // This tests the code path that will read the NOTIFYITEM data structure for | 91 // This tests the code path that will read the NOTIFYITEM data structure for |
93 // use in future tests. | 92 // use in future tests. |
94 scoped_ptr<NOTIFYITEM> notify_item = SetupAndGetCurrentNotifyItem(); | 93 std::unique_ptr<NOTIFYITEM> notify_item = SetupAndGetCurrentNotifyItem(); |
95 EXPECT_FALSE(notify_item.get() == NULL); | 94 EXPECT_FALSE(notify_item.get() == NULL); |
96 } | 95 } |
97 | 96 |
98 // Test is disabled due to multiple COM initialization errors. See | 97 // Test is disabled due to multiple COM initialization errors. See |
99 // http//crbug.com/367199 for details. | 98 // http//crbug.com/367199 for details. |
100 TEST_F(StatusTrayStateChangerWinTest, DISABLED_ComApiTest) { | 99 TEST_F(StatusTrayStateChangerWinTest, DISABLED_ComApiTest) { |
101 | 100 |
102 // Setup code to read the current preference. | 101 // Setup code to read the current preference. |
103 scoped_ptr<NOTIFYITEM> notify_item = SetupAndGetCurrentNotifyItem(); | 102 std::unique_ptr<NOTIFYITEM> notify_item = SetupAndGetCurrentNotifyItem(); |
104 ASSERT_TRUE(notify_item.get() != NULL); | 103 ASSERT_TRUE(notify_item.get() != NULL); |
105 | 104 |
106 // Store the current pref. | 105 // Store the current pref. |
107 DWORD current_preference = notify_item->preference; | 106 DWORD current_preference = notify_item->preference; |
108 | 107 |
109 // Ensure that running our code will do something. | 108 // Ensure that running our code will do something. |
110 if (notify_item->preference != PREFERENCE_SHOW_WHEN_ACTIVE) { | 109 if (notify_item->preference != PREFERENCE_SHOW_WHEN_ACTIVE) { |
111 scoped_ptr<NOTIFYITEM> notify_item_copy(new NOTIFYITEM(*notify_item)); | 110 std::unique_ptr<NOTIFYITEM> notify_item_copy(new NOTIFYITEM(*notify_item)); |
112 notify_item_copy->preference = PREFERENCE_SHOW_WHEN_ACTIVE; | 111 notify_item_copy->preference = PREFERENCE_SHOW_WHEN_ACTIVE; |
113 SendNotifyItemUpdate(std::move(notify_item_copy)); | 112 SendNotifyItemUpdate(std::move(notify_item_copy)); |
114 } | 113 } |
115 | 114 |
116 // Run the interesting code. | 115 // Run the interesting code. |
117 tray_watcher_->EnsureTrayIconVisible(); | 116 tray_watcher_->EnsureTrayIconVisible(); |
118 | 117 |
119 EXPECT_EQ(PREFERENCE_SHOW_ALWAYS, GetNotifyItem()->preference); | 118 EXPECT_EQ(PREFERENCE_SHOW_ALWAYS, GetNotifyItem()->preference); |
120 SendNotifyItemUpdate(std::move(notify_item)); | 119 SendNotifyItemUpdate(std::move(notify_item)); |
121 notify_item = GetNotifyItem(); | 120 notify_item = GetNotifyItem(); |
122 | 121 |
123 EXPECT_EQ(notify_item->preference, current_preference); | 122 EXPECT_EQ(notify_item->preference, current_preference); |
124 } | 123 } |
125 | 124 |
126 // Test is disabled due to multiple COM initialization errors. See | 125 // Test is disabled due to multiple COM initialization errors. See |
127 // http//crbug.com/367199 for details. | 126 // http//crbug.com/367199 for details. |
128 TEST_F(StatusTrayStateChangerWinTest, DISABLED_TraySizeApiTest) { | 127 TEST_F(StatusTrayStateChangerWinTest, DISABLED_TraySizeApiTest) { |
129 | 128 |
130 // The tray does not auto-hide icons immediately on Vista so this test does | 129 // The tray does not auto-hide icons immediately on Vista so this test does |
131 // not detect a size change. | 130 // not detect a size change. |
132 if (base::win::GetVersion() <= base::win::VERSION_VISTA) | 131 if (base::win::GetVersion() <= base::win::VERSION_VISTA) |
133 return; | 132 return; |
134 | 133 |
135 // Used to reset operating system state afterwards. | 134 // Used to reset operating system state afterwards. |
136 scoped_ptr<NOTIFYITEM> notify_item = SetupAndGetCurrentNotifyItem(); | 135 std::unique_ptr<NOTIFYITEM> notify_item = SetupAndGetCurrentNotifyItem(); |
137 // We can't actually run this test if we're already showing the icon. | 136 // We can't actually run this test if we're already showing the icon. |
138 if (notify_item->preference == PREFERENCE_SHOW_ALWAYS) | 137 if (notify_item->preference == PREFERENCE_SHOW_ALWAYS) |
139 return; | 138 return; |
140 | 139 |
141 // This test can only run if the tray window structure conforms to what I've | 140 // This test can only run if the tray window structure conforms to what I've |
142 // seen in Win7 and Win8. | 141 // seen in Win7 and Win8. |
143 HWND shell_tray_hwnd = ::FindWindow(L"Shell_TrayWnd", NULL); | 142 HWND shell_tray_hwnd = ::FindWindow(L"Shell_TrayWnd", NULL); |
144 if (shell_tray_hwnd == NULL) | 143 if (shell_tray_hwnd == NULL) |
145 return; | 144 return; |
146 | 145 |
(...skipping 14 matching lines...) Expand all Loading... |
161 | 160 |
162 LONG new_width = new_tray_notify_rect.right - new_tray_notify_rect.left; | 161 LONG new_width = new_tray_notify_rect.right - new_tray_notify_rect.left; |
163 | 162 |
164 EXPECT_GT(new_width, width); | 163 EXPECT_GT(new_width, width); |
165 | 164 |
166 SendNotifyItemUpdate(std::move(notify_item)); | 165 SendNotifyItemUpdate(std::move(notify_item)); |
167 ::GetWindowRect(tray_notify_hwnd, &new_tray_notify_rect); | 166 ::GetWindowRect(tray_notify_hwnd, &new_tray_notify_rect); |
168 new_width = new_tray_notify_rect.right - new_tray_notify_rect.left; | 167 new_width = new_tray_notify_rect.right - new_tray_notify_rect.left; |
169 EXPECT_EQ(width, new_width); | 168 EXPECT_EQ(width, new_width); |
170 } | 169 } |
OLD | NEW |