| 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> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/public/cpp/config.h" |
| 9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 10 #include "ash/shell_port.h" | |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "base/test/user_action_tester.h" | 12 #include "base/test/user_action_tester.h" |
| 13 #include "ui/aura/test/test_window_delegate.h" | 13 #include "ui/aura/test/test_window_delegate.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/compositor/layer_type.h" | 15 #include "ui/compositor/layer_type.h" |
| 16 #include "ui/events/test/event_generator.h" | 16 #include "ui/events/test/event_generator.h" |
| 17 #include "ui/wm/public/activation_client.h" | 17 #include "ui/wm/public/activation_client.h" |
| 18 #include "ui/wm/public/window_types.h" | 18 #include "ui/wm/public/window_types.h" |
| 19 | 19 |
| 20 using aura::client::ActivationChangeObserver; | 20 using aura::client::ActivationChangeObserver; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 window->SetType(ui::wm::WINDOW_TYPE_UNKNOWN); | 114 window->SetType(ui::wm::WINDOW_TYPE_UNKNOWN); |
| 115 window->Init(ui::LAYER_NOT_DRAWN); | 115 window->Init(ui::LAYER_NOT_DRAWN); |
| 116 return window; | 116 return window; |
| 117 } | 117 } |
| 118 | 118 |
| 119 // Verify user action is recorded when a positionable window is activated given | 119 // Verify user action is recorded when a positionable window is activated given |
| 120 // that a null window was activated last. | 120 // that a null window was activated last. |
| 121 TEST_F(DesktopTaskSwitchMetricRecorderTest, | 121 TEST_F(DesktopTaskSwitchMetricRecorderTest, |
| 122 ActivatePositionableWindowWhenNullWindowWasActivatedLast) { | 122 ActivatePositionableWindowWhenNullWindowWasActivatedLast) { |
| 123 // TODO: investigate failure in mash, http://crbug.com/695628. | 123 // TODO: investigate failure in mash, http://crbug.com/695628. |
| 124 if (ShellPort::Get()->IsRunningInMash()) | 124 if (Shell::GetAshConfig() == Config::MASH) |
| 125 return; | 125 return; |
| 126 | 126 |
| 127 std::unique_ptr<aura::Window> null_window; | 127 std::unique_ptr<aura::Window> null_window; |
| 128 std::unique_ptr<aura::Window> positionable_window = | 128 std::unique_ptr<aura::Window> positionable_window = |
| 129 CreatePositionableWindow(); | 129 CreatePositionableWindow(); |
| 130 | 130 |
| 131 ActiveTaskWindowWithUserInput(null_window.get()); | 131 ActiveTaskWindowWithUserInput(null_window.get()); |
| 132 ResetActionCounts(); | 132 ResetActionCounts(); |
| 133 | 133 |
| 134 ActiveTaskWindowWithUserInput(positionable_window.get()); | 134 ActiveTaskWindowWithUserInput(positionable_window.get()); |
| 135 EXPECT_EQ(1, GetActionCount()); | 135 EXPECT_EQ(1, GetActionCount()); |
| 136 } | 136 } |
| 137 | 137 |
| 138 // Verify user action is recorded whena positionable window is activated given | 138 // Verify user action is recorded whena positionable window is activated given |
| 139 // a different positionable window was activated last. | 139 // a different positionable window was activated last. |
| 140 TEST_F( | 140 TEST_F( |
| 141 DesktopTaskSwitchMetricRecorderTest, | 141 DesktopTaskSwitchMetricRecorderTest, |
| 142 ActivatePositionableWindowWhenADifferentPositionableWindowWasActivatedLast)
{ | 142 ActivatePositionableWindowWhenADifferentPositionableWindowWasActivatedLast)
{ |
| 143 // TODO: investigate failure in mash, http://crbug.com/695628. | 143 // TODO: investigate failure in mash, http://crbug.com/695628. |
| 144 if (ShellPort::Get()->IsRunningInMash()) | 144 if (Shell::GetAshConfig() == Config::MASH) |
| 145 return; | 145 return; |
| 146 | 146 |
| 147 std::unique_ptr<aura::Window> positionable_window_1 = | 147 std::unique_ptr<aura::Window> positionable_window_1 = |
| 148 CreatePositionableWindow(); | 148 CreatePositionableWindow(); |
| 149 std::unique_ptr<aura::Window> positionable_window_2 = | 149 std::unique_ptr<aura::Window> positionable_window_2 = |
| 150 CreatePositionableWindow(); | 150 CreatePositionableWindow(); |
| 151 | 151 |
| 152 ActiveTaskWindowWithUserInput(positionable_window_1.get()); | 152 ActiveTaskWindowWithUserInput(positionable_window_1.get()); |
| 153 ResetActionCounts(); | 153 ResetActionCounts(); |
| 154 | 154 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 169 | 169 |
| 170 ActiveTaskWindowWithUserInput(positionable_window.get()); | 170 ActiveTaskWindowWithUserInput(positionable_window.get()); |
| 171 EXPECT_EQ(0, GetActionCount()); | 171 EXPECT_EQ(0, GetActionCount()); |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Verify user action is recorded when a positionable window is activated given | 174 // Verify user action is recorded when a positionable window is activated given |
| 175 // a non-positionable window was activated last. | 175 // a non-positionable window was activated last. |
| 176 TEST_F(DesktopTaskSwitchMetricRecorderTest, | 176 TEST_F(DesktopTaskSwitchMetricRecorderTest, |
| 177 ActivatePositionableWindowWhenANonPositionableWindowWasActivatedLast) { | 177 ActivatePositionableWindowWhenANonPositionableWindowWasActivatedLast) { |
| 178 // TODO: investigate failure in mash, http://crbug.com/695628. | 178 // TODO: investigate failure in mash, http://crbug.com/695628. |
| 179 if (ShellPort::Get()->IsRunningInMash()) | 179 if (Shell::GetAshConfig() == Config::MASH) |
| 180 return; | 180 return; |
| 181 | 181 |
| 182 std::unique_ptr<aura::Window> non_positionable_window = | 182 std::unique_ptr<aura::Window> non_positionable_window = |
| 183 CreateNonPositionableWindow(); | 183 CreateNonPositionableWindow(); |
| 184 std::unique_ptr<aura::Window> positionable_window = | 184 std::unique_ptr<aura::Window> positionable_window = |
| 185 CreatePositionableWindow(); | 185 CreatePositionableWindow(); |
| 186 | 186 |
| 187 ActiveTaskWindowWithUserInput(non_positionable_window.get()); | 187 ActiveTaskWindowWithUserInput(non_positionable_window.get()); |
| 188 ResetActionCounts(); | 188 ResetActionCounts(); |
| 189 | 189 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 aura::Window* DesktopTaskSwitchMetricRecorderWithShellIntegrationTest:: | 314 aura::Window* DesktopTaskSwitchMetricRecorderWithShellIntegrationTest:: |
| 315 CreatePositionableWindowInShellWithBounds(const gfx::Rect& bounds) { | 315 CreatePositionableWindowInShellWithBounds(const gfx::Rect& bounds) { |
| 316 return CreateTestWindowInShellWithDelegate(&test_window_delegate_, 0, bounds); | 316 return CreateTestWindowInShellWithDelegate(&test_window_delegate_, 0, bounds); |
| 317 } | 317 } |
| 318 | 318 |
| 319 // Verify a user action is recorded when a positionable window is activated by | 319 // Verify a user action is recorded when a positionable window is activated by |
| 320 // a INPUT_EVENT. | 320 // a INPUT_EVENT. |
| 321 TEST_F(DesktopTaskSwitchMetricRecorderWithShellIntegrationTest, | 321 TEST_F(DesktopTaskSwitchMetricRecorderWithShellIntegrationTest, |
| 322 ActivatePositionableWindowWithInputEvent) { | 322 ActivatePositionableWindowWithInputEvent) { |
| 323 // TODO: investigate failure in mash, http://crbug.com/695628. | 323 // TODO: investigate failure in mash, http://crbug.com/695628. |
| 324 if (ShellPort::Get()->IsRunningInMash()) | 324 if (Shell::GetAshConfig() == Config::MASH) |
| 325 return; | 325 return; |
| 326 aura::Window* positionable_window = | 326 aura::Window* positionable_window = |
| 327 CreatePositionableWindowInShellWithBounds(gfx::Rect(0, 0, 10, 10)); | 327 CreatePositionableWindowInShellWithBounds(gfx::Rect(0, 0, 10, 10)); |
| 328 | 328 |
| 329 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow()); | 329 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow()); |
| 330 | 330 |
| 331 event_generator.MoveMouseToCenterOf(positionable_window); | 331 event_generator.MoveMouseToCenterOf(positionable_window); |
| 332 event_generator.ClickLeftButton(); | 332 event_generator.ClickLeftButton(); |
| 333 | 333 |
| 334 EXPECT_EQ(1, GetActionCount()); | 334 EXPECT_EQ(1, GetActionCount()); |
| 335 } | 335 } |
| 336 | 336 |
| 337 // Verify a user action is not recorded when a positionable window is activated | 337 // Verify a user action is not recorded when a positionable window is activated |
| 338 // by a non INPUT_EVENT. | 338 // by a non INPUT_EVENT. |
| 339 TEST_F(DesktopTaskSwitchMetricRecorderWithShellIntegrationTest, | 339 TEST_F(DesktopTaskSwitchMetricRecorderWithShellIntegrationTest, |
| 340 ActivatePositionableWindowWithNonInputEvent) { | 340 ActivatePositionableWindowWithNonInputEvent) { |
| 341 aura::Window* positionable_window = | 341 aura::Window* positionable_window = |
| 342 CreatePositionableWindowInShellWithBounds(gfx::Rect(0, 0, 10, 10)); | 342 CreatePositionableWindowInShellWithBounds(gfx::Rect(0, 0, 10, 10)); |
| 343 | 343 |
| 344 Shell::Get()->activation_client()->ActivateWindow(positionable_window); | 344 Shell::Get()->activation_client()->ActivateWindow(positionable_window); |
| 345 | 345 |
| 346 EXPECT_EQ(0, GetActionCount()); | 346 EXPECT_EQ(0, GetActionCount()); |
| 347 } | 347 } |
| 348 | 348 |
| 349 } // namespace | 349 } // namespace |
| 350 } // namespace ash | 350 } // namespace ash |
| OLD | NEW |