Chromium Code Reviews| Index: ash/wm/screen_pinning_controller_unittest.cc |
| diff --git a/ash/wm/screen_pinning_controller_unittest.cc b/ash/wm/screen_pinning_controller_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d65d86d09cf5911e8b1239939417b720da675aec |
| --- /dev/null |
| +++ b/ash/wm/screen_pinning_controller_unittest.cc |
| @@ -0,0 +1,161 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
oshima
2016/06/18 04:47:44
nit: 2016
hidehiko
2016/06/18 05:32:45
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/wm/screen_pinning_controller.h" |
| + |
| +#include <vector> |
| + |
| +#include "ash/aura/wm_window_aura.h" |
| +#include "ash/common/wm/window_state.h" |
| +#include "ash/common/wm/wm_event.h" |
| +#include "ash/common/wm_shell.h" |
| +#include "ash/common/wm_window.h" |
| +#include "ash/test/ash_test_base.h" |
| +#include "ash/wm/window_util.h" |
| +#include "base/stl_util.h" |
| +#include "ui/aura/window.h" |
| + |
| +namespace ash { |
| +namespace test { |
|
oshima
2016/06/18 04:47:45
we keep ash::test for test utility (at least in as
hidehiko
2016/06/18 05:32:45
Done.
|
| +namespace { |
| + |
| +int FindIndex(const std::vector<aura::Window*>& windows, |
| + const aura::Window* target) { |
| + auto iter = std::find(windows.begin(), windows.end(), target); |
| + return iter != windows.end() ? iter - windows.begin() : -1; |
| +} |
| + |
| +} // namespace |
| + |
| +class ScreenPinningControllerTest : public test::AshTestBase { |
| + public: |
| + ScreenPinningControllerTest() = default; |
| + ~ScreenPinningControllerTest() override = default; |
| +}; |
|
oshima
2016/06/18 04:47:44
using ScreenPinningControllerTest = test::AshTestB
hidehiko
2016/06/18 05:32:45
Done.
|
| + |
| +TEST_F(ScreenPinningControllerTest, IsPinned) { |
| + aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| + wm::ActivateWindow(w1); |
| + |
| + wm::PinWindow(w1); |
| + EXPECT_TRUE(WmShell::Get()->IsPinned()); |
| +} |
| + |
| +TEST_F(ScreenPinningControllerTest, OnlyOnePinnedWindow) { |
| + aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| + aura::Window* w2 = CreateTestWindowInShellWithId(1); |
| + wm::ActivateWindow(w1); |
| + |
| + wm::PinWindow(w1); |
| + EXPECT_TRUE(WmWindowAura::Get(w1)->GetWindowState()->IsPinned()); |
| + EXPECT_FALSE(WmWindowAura::Get(w2)->GetWindowState()->IsPinned()); |
| + |
| + // Prohibit to pin two (or more) windows. |
| + wm::PinWindow(w2); |
| + EXPECT_TRUE(WmWindowAura::Get(w1)->GetWindowState()->IsPinned()); |
| + EXPECT_FALSE(WmWindowAura::Get(w2)->GetWindowState()->IsPinned()); |
| +} |
| + |
| +TEST_F(ScreenPinningControllerTest, FullscreenInPinnedMode) { |
| + aura::Window* w1 = CreateTestWindowInShellWithId(0); |
| + aura::Window* w2 = CreateTestWindowInShellWithId(1); |
| + wm::ActivateWindow(w1); |
| + |
| + wm::PinWindow(w1); |
| + { |
| + // Window w1 should be in front of w2. |
| + std::vector<aura::Window*> siblings = w1->parent()->children(); |
| + int index1 = FindIndex(siblings, w1); |
| + int index2 = FindIndex(siblings, w2); |
| + EXPECT_NE(index1, -1); |
|
oshima
2016/06/18 04:47:44
It should be:
EXPECTE_NE(expected_value, actual_v
hidehiko
2016/06/18 05:32:45
Done.
|
| + EXPECT_NE(index2, -1); |
| + EXPECT_GT(index1, index2); |
| + } |
| + |
| + // Set w2 to fullscreen. |
| + { |
| + wm::ActivateWindow(w2); |
| + const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| + WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); |
| + } |
| + { |
| + // Verify that w1 is still in front of w2. |
| + std::vector<aura::Window*> siblings = w1->parent()->children(); |
| + int index1 = FindIndex(siblings, w1); |
| + int index2 = FindIndex(siblings, w2); |
| + EXPECT_NE(index1, -1); |
| + EXPECT_NE(index2, -1); |
| + EXPECT_GT(index1, index2); |
| + } |
| + |
| + // Unset w2's fullscreen. |
| + { |
| + wm::ActivateWindow(w2); |
| + const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| + WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); |
| + } |
| + { |
| + // Verify that w1 is still in front of w2. |
| + std::vector<aura::Window*> siblings = w1->parent()->children(); |
| + int index1 = FindIndex(siblings, w1); |
| + int index2 = FindIndex(siblings, w2); |
| + EXPECT_NE(index1, -1); |
| + EXPECT_NE(index2, -1); |
| + EXPECT_GT(index1, index2); |
| + } |
| + |
| + // Maximize w2. |
| + { |
| + wm::ActivateWindow(w2); |
| + const wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); |
| + WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); |
| + } |
| + { |
| + // Verify that w1 is still in front of w2. |
| + std::vector<aura::Window*> siblings = w1->parent()->children(); |
| + int index1 = FindIndex(siblings, w1); |
| + int index2 = FindIndex(siblings, w2); |
| + EXPECT_NE(index1, -1); |
| + EXPECT_NE(index2, -1); |
| + EXPECT_GT(index1, index2); |
| + } |
| + |
| + // Unset w2's maximize. |
| + { |
| + wm::ActivateWindow(w2); |
| + const wm::WMEvent event(wm::WM_EVENT_TOGGLE_MAXIMIZE); |
| + WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); |
| + } |
| + { |
| + // Verify that w1 is still in front of w2. |
| + std::vector<aura::Window*> siblings = w1->parent()->children(); |
| + int index1 = FindIndex(siblings, w1); |
| + int index2 = FindIndex(siblings, w2); |
| + EXPECT_NE(index1, -1); |
| + EXPECT_NE(index2, -1); |
| + EXPECT_GT(index1, index2); |
| + } |
| + |
| + // Restore w1. |
| + WmWindowAura::Get(w1)->GetWindowState()->Restore(); |
| + |
| + // Now, fullscreen-ize w2 should put it in front of w1. |
| + { |
| + wm::ActivateWindow(w2); |
| + const wm::WMEvent event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| + WmWindowAura::Get(w2)->GetWindowState()->OnWMEvent(&event); |
| + } |
| + { |
| + // Verify that w1 is still in front of w2. |
| + std::vector<aura::Window*> siblings = w1->parent()->children(); |
| + int index1 = FindIndex(siblings, w1); |
| + int index2 = FindIndex(siblings, w2); |
| + EXPECT_NE(index1, -1); |
| + EXPECT_NE(index2, -1); |
| + EXPECT_GT(index2, index1); |
| + } |
| +} |
| + |
| +} // namespace test |
| +} // namespace ash |