OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ash/metrics/desktop_task_switch_metric_recorder.h" | 5 #include "ash/metrics/desktop_task_switch_metric_recorder.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "ash/shell.h" | 9 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "base/test/user_action_tester.h" | 11 #include "base/test/user_action_tester.h" |
11 #include "ui/aura/test/test_window_delegate.h" | 12 #include "ui/aura/test/test_window_delegate.h" |
12 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
13 #include "ui/compositor/layer_type.h" | 14 #include "ui/compositor/layer_type.h" |
14 #include "ui/events/test/event_generator.h" | 15 #include "ui/events/test/event_generator.h" |
15 #include "ui/wm/public/activation_client.h" | 16 #include "ui/wm/public/activation_client.h" |
16 #include "ui/wm/public/window_types.h" | 17 #include "ui/wm/public/window_types.h" |
17 | 18 |
18 using aura::client::ActivationChangeObserver; | 19 using aura::client::ActivationChangeObserver; |
19 | 20 |
(...skipping 18 matching lines...) Expand all Loading... |
38 | 39 |
39 // Resets the recorded user action counts. | 40 // Resets the recorded user action counts. |
40 void ResetActionCounts(); | 41 void ResetActionCounts(); |
41 | 42 |
42 // Returns the number of times the "Desktop_SwitchTask" user action was | 43 // Returns the number of times the "Desktop_SwitchTask" user action was |
43 // recorded. | 44 // recorded. |
44 int GetActionCount() const; | 45 int GetActionCount() const; |
45 | 46 |
46 // Creates a positionable window such that wm::IsWindowUserPositionable(...) | 47 // Creates a positionable window such that wm::IsWindowUserPositionable(...) |
47 // would retun true. | 48 // would retun true. |
48 scoped_ptr<aura::Window> CreatePositionableWindow() const; | 49 std::unique_ptr<aura::Window> CreatePositionableWindow() const; |
49 | 50 |
50 // Creates a non-positionable window such that | 51 // Creates a non-positionable window such that |
51 // wm::IsWindowUserPositionable(...) would retun false. | 52 // wm::IsWindowUserPositionable(...) would retun false. |
52 scoped_ptr<aura::Window> CreateNonPositionableWindow() const; | 53 std::unique_ptr<aura::Window> CreateNonPositionableWindow() const; |
53 | 54 |
54 // Wrapper to notify the test target's OnWindowActivated(...) method that | 55 // Wrapper to notify the test target's OnWindowActivated(...) method that |
55 // |window| was activated due to an INPUT_EVENT. | 56 // |window| was activated due to an INPUT_EVENT. |
56 void ActiveTaskWindowWithUserInput(aura::Window* window); | 57 void ActiveTaskWindowWithUserInput(aura::Window* window); |
57 | 58 |
58 protected: | 59 protected: |
59 // Records UMA user action counts. | 60 // Records UMA user action counts. |
60 scoped_ptr<base::UserActionTester> user_action_tester_; | 61 std::unique_ptr<base::UserActionTester> user_action_tester_; |
61 | 62 |
62 // The test target. | 63 // The test target. |
63 scoped_ptr<DesktopTaskSwitchMetricRecorder> metrics_recorder_; | 64 std::unique_ptr<DesktopTaskSwitchMetricRecorder> metrics_recorder_; |
64 | 65 |
65 private: | 66 private: |
66 DISALLOW_COPY_AND_ASSIGN(DesktopTaskSwitchMetricRecorderTest); | 67 DISALLOW_COPY_AND_ASSIGN(DesktopTaskSwitchMetricRecorderTest); |
67 }; | 68 }; |
68 | 69 |
69 DesktopTaskSwitchMetricRecorderTest::DesktopTaskSwitchMetricRecorderTest() { | 70 DesktopTaskSwitchMetricRecorderTest::DesktopTaskSwitchMetricRecorderTest() { |
70 } | 71 } |
71 | 72 |
72 DesktopTaskSwitchMetricRecorderTest::~DesktopTaskSwitchMetricRecorderTest() { | 73 DesktopTaskSwitchMetricRecorderTest::~DesktopTaskSwitchMetricRecorderTest() { |
73 } | 74 } |
(...skipping 17 matching lines...) Expand all Loading... |
91 } | 92 } |
92 | 93 |
93 void DesktopTaskSwitchMetricRecorderTest::ResetActionCounts() { | 94 void DesktopTaskSwitchMetricRecorderTest::ResetActionCounts() { |
94 user_action_tester_->ResetCounts(); | 95 user_action_tester_->ResetCounts(); |
95 } | 96 } |
96 | 97 |
97 int DesktopTaskSwitchMetricRecorderTest::GetActionCount() const { | 98 int DesktopTaskSwitchMetricRecorderTest::GetActionCount() const { |
98 return user_action_tester_->GetActionCount(kDesktopTaskSwitchUserAction); | 99 return user_action_tester_->GetActionCount(kDesktopTaskSwitchUserAction); |
99 } | 100 } |
100 | 101 |
101 scoped_ptr<aura::Window> | 102 std::unique_ptr<aura::Window> |
102 DesktopTaskSwitchMetricRecorderTest::CreatePositionableWindow() const { | 103 DesktopTaskSwitchMetricRecorderTest::CreatePositionableWindow() const { |
103 scoped_ptr<aura::Window> window(new aura::Window( | 104 std::unique_ptr<aura::Window> window(new aura::Window( |
104 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate())); | 105 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate())); |
105 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 106 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
106 window->Init(ui::LAYER_NOT_DRAWN); | 107 window->Init(ui::LAYER_NOT_DRAWN); |
107 return window; | 108 return window; |
108 } | 109 } |
109 | 110 |
110 scoped_ptr<aura::Window> | 111 std::unique_ptr<aura::Window> |
111 DesktopTaskSwitchMetricRecorderTest::CreateNonPositionableWindow() const { | 112 DesktopTaskSwitchMetricRecorderTest::CreateNonPositionableWindow() const { |
112 scoped_ptr<aura::Window> window(new aura::Window( | 113 std::unique_ptr<aura::Window> window(new aura::Window( |
113 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate())); | 114 aura::test::TestWindowDelegate::CreateSelfDestroyingDelegate())); |
114 window->SetType(ui::wm::WINDOW_TYPE_UNKNOWN); | 115 window->SetType(ui::wm::WINDOW_TYPE_UNKNOWN); |
115 window->Init(ui::LAYER_NOT_DRAWN); | 116 window->Init(ui::LAYER_NOT_DRAWN); |
116 return window; | 117 return window; |
117 } | 118 } |
118 | 119 |
119 // Verify user action is recorded when a positionable window is activated given | 120 // Verify user action is recorded when a positionable window is activated given |
120 // that a null window was activated last. | 121 // that a null window was activated last. |
121 TEST_F(DesktopTaskSwitchMetricRecorderTest, | 122 TEST_F(DesktopTaskSwitchMetricRecorderTest, |
122 ActivatePositionableWindowWhenNullWindowWasActivatedLast) { | 123 ActivatePositionableWindowWhenNullWindowWasActivatedLast) { |
123 scoped_ptr<aura::Window> null_window; | 124 std::unique_ptr<aura::Window> null_window; |
124 scoped_ptr<aura::Window> positionable_window = CreatePositionableWindow(); | 125 std::unique_ptr<aura::Window> positionable_window = |
| 126 CreatePositionableWindow(); |
125 | 127 |
126 ActiveTaskWindowWithUserInput(null_window.get()); | 128 ActiveTaskWindowWithUserInput(null_window.get()); |
127 ResetActionCounts(); | 129 ResetActionCounts(); |
128 | 130 |
129 ActiveTaskWindowWithUserInput(positionable_window.get()); | 131 ActiveTaskWindowWithUserInput(positionable_window.get()); |
130 EXPECT_EQ(1, GetActionCount()); | 132 EXPECT_EQ(1, GetActionCount()); |
131 } | 133 } |
132 | 134 |
133 // Verify user action is recorded whena positionable window is activated given | 135 // Verify user action is recorded whena positionable window is activated given |
134 // a different positionable window was activated last. | 136 // a different positionable window was activated last. |
135 TEST_F( | 137 TEST_F( |
136 DesktopTaskSwitchMetricRecorderTest, | 138 DesktopTaskSwitchMetricRecorderTest, |
137 ActivatePositionableWindowWhenADifferentPositionableWindowWasActivatedLast)
{ | 139 ActivatePositionableWindowWhenADifferentPositionableWindowWasActivatedLast)
{ |
138 scoped_ptr<aura::Window> positionable_window_1 = CreatePositionableWindow(); | 140 std::unique_ptr<aura::Window> positionable_window_1 = |
139 scoped_ptr<aura::Window> positionable_window_2 = CreatePositionableWindow(); | 141 CreatePositionableWindow(); |
| 142 std::unique_ptr<aura::Window> positionable_window_2 = |
| 143 CreatePositionableWindow(); |
140 | 144 |
141 ActiveTaskWindowWithUserInput(positionable_window_1.get()); | 145 ActiveTaskWindowWithUserInput(positionable_window_1.get()); |
142 ResetActionCounts(); | 146 ResetActionCounts(); |
143 | 147 |
144 ActiveTaskWindowWithUserInput(positionable_window_2.get()); | 148 ActiveTaskWindowWithUserInput(positionable_window_2.get()); |
145 EXPECT_EQ(1, GetActionCount()); | 149 EXPECT_EQ(1, GetActionCount()); |
146 } | 150 } |
147 | 151 |
148 // Verify user action is not recorded when a positionable window is activated | 152 // Verify user action is not recorded when a positionable window is activated |
149 // given the same positionable window was activated last. | 153 // given the same positionable window was activated last. |
150 TEST_F( | 154 TEST_F( |
151 DesktopTaskSwitchMetricRecorderTest, | 155 DesktopTaskSwitchMetricRecorderTest, |
152 ActivatePositionableWindowWhenTheSamePositionableWindowWasActivatedLast) { | 156 ActivatePositionableWindowWhenTheSamePositionableWindowWasActivatedLast) { |
153 scoped_ptr<aura::Window> positionable_window = CreatePositionableWindow(); | 157 std::unique_ptr<aura::Window> positionable_window = |
| 158 CreatePositionableWindow(); |
154 | 159 |
155 ActiveTaskWindowWithUserInput(positionable_window.get()); | 160 ActiveTaskWindowWithUserInput(positionable_window.get()); |
156 ResetActionCounts(); | 161 ResetActionCounts(); |
157 | 162 |
158 ActiveTaskWindowWithUserInput(positionable_window.get()); | 163 ActiveTaskWindowWithUserInput(positionable_window.get()); |
159 EXPECT_EQ(0, GetActionCount()); | 164 EXPECT_EQ(0, GetActionCount()); |
160 } | 165 } |
161 | 166 |
162 // Verify user action is recorded when a positionable window is activated given | 167 // Verify user action is recorded when a positionable window is activated given |
163 // a non-positionable window was activated last. | 168 // a non-positionable window was activated last. |
164 TEST_F(DesktopTaskSwitchMetricRecorderTest, | 169 TEST_F(DesktopTaskSwitchMetricRecorderTest, |
165 ActivatePositionableWindowWhenANonPositionableWindowWasActivatedLast) { | 170 ActivatePositionableWindowWhenANonPositionableWindowWasActivatedLast) { |
166 scoped_ptr<aura::Window> non_positionable_window = | 171 std::unique_ptr<aura::Window> non_positionable_window = |
167 CreateNonPositionableWindow(); | 172 CreateNonPositionableWindow(); |
168 scoped_ptr<aura::Window> positionable_window = CreatePositionableWindow(); | 173 std::unique_ptr<aura::Window> positionable_window = |
| 174 CreatePositionableWindow(); |
169 | 175 |
170 ActiveTaskWindowWithUserInput(non_positionable_window.get()); | 176 ActiveTaskWindowWithUserInput(non_positionable_window.get()); |
171 ResetActionCounts(); | 177 ResetActionCounts(); |
172 | 178 |
173 ActiveTaskWindowWithUserInput(positionable_window.get()); | 179 ActiveTaskWindowWithUserInput(positionable_window.get()); |
174 EXPECT_EQ(1, GetActionCount()); | 180 EXPECT_EQ(1, GetActionCount()); |
175 } | 181 } |
176 | 182 |
177 // Verify user action is not recorded when a non-positionable window is | 183 // Verify user action is not recorded when a non-positionable window is |
178 // activated between two activations of the same positionable window. | 184 // activated between two activations of the same positionable window. |
179 TEST_F(DesktopTaskSwitchMetricRecorderTest, | 185 TEST_F(DesktopTaskSwitchMetricRecorderTest, |
180 ActivateNonPositionableWindowBetweenTwoPositionableWindowActivations) { | 186 ActivateNonPositionableWindowBetweenTwoPositionableWindowActivations) { |
181 scoped_ptr<aura::Window> positionable_window = CreatePositionableWindow(); | 187 std::unique_ptr<aura::Window> positionable_window = |
182 scoped_ptr<aura::Window> non_positionable_window = | 188 CreatePositionableWindow(); |
| 189 std::unique_ptr<aura::Window> non_positionable_window = |
183 CreateNonPositionableWindow(); | 190 CreateNonPositionableWindow(); |
184 | 191 |
185 ActiveTaskWindowWithUserInput(positionable_window.get()); | 192 ActiveTaskWindowWithUserInput(positionable_window.get()); |
186 ResetActionCounts(); | 193 ResetActionCounts(); |
187 | 194 |
188 ActiveTaskWindowWithUserInput(non_positionable_window.get()); | 195 ActiveTaskWindowWithUserInput(non_positionable_window.get()); |
189 EXPECT_EQ(0, GetActionCount()); | 196 EXPECT_EQ(0, GetActionCount()); |
190 | 197 |
191 ActiveTaskWindowWithUserInput(positionable_window.get()); | 198 ActiveTaskWindowWithUserInput(positionable_window.get()); |
192 EXPECT_EQ(0, GetActionCount()); | 199 EXPECT_EQ(0, GetActionCount()); |
193 } | 200 } |
194 | 201 |
195 // Verify user action is not recorded when a null window is activated. | 202 // Verify user action is not recorded when a null window is activated. |
196 TEST_F(DesktopTaskSwitchMetricRecorderTest, ActivateNullWindow) { | 203 TEST_F(DesktopTaskSwitchMetricRecorderTest, ActivateNullWindow) { |
197 scoped_ptr<aura::Window> positionable_window = CreatePositionableWindow(); | 204 std::unique_ptr<aura::Window> positionable_window = |
198 scoped_ptr<aura::Window> null_window = nullptr; | 205 CreatePositionableWindow(); |
| 206 std::unique_ptr<aura::Window> null_window = nullptr; |
199 | 207 |
200 ActiveTaskWindowWithUserInput(positionable_window.get()); | 208 ActiveTaskWindowWithUserInput(positionable_window.get()); |
201 ResetActionCounts(); | 209 ResetActionCounts(); |
202 | 210 |
203 ActiveTaskWindowWithUserInput(null_window.get()); | 211 ActiveTaskWindowWithUserInput(null_window.get()); |
204 EXPECT_EQ(0, GetActionCount()); | 212 EXPECT_EQ(0, GetActionCount()); |
205 } | 213 } |
206 | 214 |
207 // Verify user action is not recorded when a non-positionable window is | 215 // Verify user action is not recorded when a non-positionable window is |
208 // activated. | 216 // activated. |
209 TEST_F(DesktopTaskSwitchMetricRecorderTest, ActivateNonPositionableWindow) { | 217 TEST_F(DesktopTaskSwitchMetricRecorderTest, ActivateNonPositionableWindow) { |
210 scoped_ptr<aura::Window> positionable_window = CreatePositionableWindow(); | 218 std::unique_ptr<aura::Window> positionable_window = |
211 scoped_ptr<aura::Window> non_positionable_window = | 219 CreatePositionableWindow(); |
| 220 std::unique_ptr<aura::Window> non_positionable_window = |
212 CreateNonPositionableWindow(); | 221 CreateNonPositionableWindow(); |
213 | 222 |
214 ActiveTaskWindowWithUserInput(positionable_window.get()); | 223 ActiveTaskWindowWithUserInput(positionable_window.get()); |
215 ResetActionCounts(); | 224 ResetActionCounts(); |
216 | 225 |
217 ActiveTaskWindowWithUserInput(non_positionable_window.get()); | 226 ActiveTaskWindowWithUserInput(non_positionable_window.get()); |
218 EXPECT_EQ(0, GetActionCount()); | 227 EXPECT_EQ(0, GetActionCount()); |
219 } | 228 } |
220 | 229 |
221 // Verify user action is not recorded when the ActivationReason is not an | 230 // Verify user action is not recorded when the ActivationReason is not an |
222 // INPUT_EVENT. | 231 // INPUT_EVENT. |
223 TEST_F(DesktopTaskSwitchMetricRecorderTest, | 232 TEST_F(DesktopTaskSwitchMetricRecorderTest, |
224 ActivatePositionableWindowWithNonInputEventReason) { | 233 ActivatePositionableWindowWithNonInputEventReason) { |
225 scoped_ptr<aura::Window> positionable_window_1 = CreatePositionableWindow(); | 234 std::unique_ptr<aura::Window> positionable_window_1 = |
226 scoped_ptr<aura::Window> positionable_window_2 = CreatePositionableWindow(); | 235 CreatePositionableWindow(); |
| 236 std::unique_ptr<aura::Window> positionable_window_2 = |
| 237 CreatePositionableWindow(); |
227 | 238 |
228 ActiveTaskWindowWithUserInput(positionable_window_1.get()); | 239 ActiveTaskWindowWithUserInput(positionable_window_1.get()); |
229 ResetActionCounts(); | 240 ResetActionCounts(); |
230 | 241 |
231 metrics_recorder_->OnWindowActivated( | 242 metrics_recorder_->OnWindowActivated( |
232 ActivationChangeObserver::ActivationReason::ACTIVATION_CLIENT, | 243 ActivationChangeObserver::ActivationReason::ACTIVATION_CLIENT, |
233 positionable_window_2.get(), nullptr); | 244 positionable_window_2.get(), nullptr); |
234 EXPECT_EQ(0, GetActionCount()); | 245 EXPECT_EQ(0, GetActionCount()); |
235 } | 246 } |
236 | 247 |
(...skipping 13 matching lines...) Expand all Loading... |
250 // recorded. | 261 // recorded. |
251 int GetActionCount() const; | 262 int GetActionCount() const; |
252 | 263 |
253 // Creates a positionable window with the given |bounds| such that | 264 // Creates a positionable window with the given |bounds| such that |
254 // wm::IsWindowUserPositionable(...) would retun true. | 265 // wm::IsWindowUserPositionable(...) would retun true. |
255 aura::Window* CreatePositionableWindowInShellWithBounds( | 266 aura::Window* CreatePositionableWindowInShellWithBounds( |
256 const gfx::Rect& bounds); | 267 const gfx::Rect& bounds); |
257 | 268 |
258 protected: | 269 protected: |
259 // Records UMA user action counts. | 270 // Records UMA user action counts. |
260 scoped_ptr<base::UserActionTester> user_action_tester_; | 271 std::unique_ptr<base::UserActionTester> user_action_tester_; |
261 | 272 |
262 // Delegate used when creating new windows using the | 273 // Delegate used when creating new windows using the |
263 // CreatePositionableWindowInShellWithBounds(...) method. | 274 // CreatePositionableWindowInShellWithBounds(...) method. |
264 aura::test::TestWindowDelegate test_window_delegate_; | 275 aura::test::TestWindowDelegate test_window_delegate_; |
265 | 276 |
266 private: | 277 private: |
267 DISALLOW_COPY_AND_ASSIGN( | 278 DISALLOW_COPY_AND_ASSIGN( |
268 DesktopTaskSwitchMetricRecorderWithShellIntegrationTest); | 279 DesktopTaskSwitchMetricRecorderWithShellIntegrationTest); |
269 }; | 280 }; |
270 | 281 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 CreatePositionableWindowInShellWithBounds(gfx::Rect(0, 0, 10, 10)); | 330 CreatePositionableWindowInShellWithBounds(gfx::Rect(0, 0, 10, 10)); |
320 | 331 |
321 Shell::GetInstance()->activation_client()->ActivateWindow( | 332 Shell::GetInstance()->activation_client()->ActivateWindow( |
322 positionable_window); | 333 positionable_window); |
323 | 334 |
324 EXPECT_EQ(0, GetActionCount()); | 335 EXPECT_EQ(0, GetActionCount()); |
325 } | 336 } |
326 | 337 |
327 } // namespace | 338 } // namespace |
328 } // namespace ash | 339 } // namespace ash |
OLD | NEW |