1 // Copyright (c) 2012 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.
6 #include "ash/test/ash_test_base.h"
7 #include "ash/test/test_shell_delegate.h"
8 #include "ash/wm/window_state.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h"
11 #include "ui/aura/root_window.h"
12 #include "ui/aura/test/test_windows.h"
13 #include "ui/aura/window.h"
17 class WallpaperPrivateApiUnittest : public ash::test::AshTestBase {
20 class TestMinimizeFunction
21 : public WallpaperPrivateMinimizeInactiveWindowsFunction {
23 TestMinimizeFunction() {}
25 virtual bool RunImpl() OVERRIDE {
26 return WallpaperPrivateMinimizeInactiveWindowsFunction::RunImpl();
30 virtual ~TestMinimizeFunction() {}
33 class TestRestoreFunction
34 : public WallpaperPrivateRestoreMinimizedWindowsFunction {
36 TestRestoreFunction() {}
38 virtual bool RunImpl() OVERRIDE {
39 return WallpaperPrivateRestoreMinimizedWindowsFunction::RunImpl();
42 virtual ~TestRestoreFunction() {}
47 TEST_F(WallpaperPrivateApiUnittest, HideAndRestoreWindows) {
48 scoped_ptr<aura::Window> window3(CreateTestWindowInShellWithId(3));
49 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(2));
50 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1));
51 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0));
53 ash::wm::WindowState* window0_state = ash::wm::GetWindowState(window0.get());
54 ash::wm::WindowState* window1_state = ash::wm::GetWindowState(window1.get());
55 ash::wm::WindowState* window2_state = ash::wm::GetWindowState(window2.get());
56 ash::wm::WindowState* window3_state = ash::wm::GetWindowState(window3.get());
58 window3_state->Minimize();
59 window1_state->Maximize();
61 // Window 3 starts minimized, window 1 starts maximized.
62 EXPECT_FALSE(window0_state->IsMinimized());
63 EXPECT_FALSE(window1_state->IsMinimized());
64 EXPECT_FALSE(window2_state->IsMinimized());
65 EXPECT_TRUE(window3_state->IsMinimized());
67 // We then activate window 0 (i.e. wallpaper picker) and call the minimize
69 window0_state->Activate();
70 EXPECT_TRUE(window0_state->IsActive());
71 scoped_refptr<TestMinimizeFunction> minimize_function(
72 new TestMinimizeFunction());
73 EXPECT_TRUE(minimize_function->RunImpl());
75 // All windows except window 0 should be minimized.
76 EXPECT_FALSE(window0_state->IsMinimized());
77 EXPECT_TRUE(window1_state->IsMinimized());
78 EXPECT_TRUE(window2_state->IsMinimized());
79 EXPECT_TRUE(window3_state->IsMinimized());
81 // Then we destroy window 0 and call the restore function.
83 scoped_refptr<TestRestoreFunction> restore_function(
84 new TestRestoreFunction());
85 EXPECT_TRUE(restore_function->RunImpl());
87 // Windows 1 and 2 should no longer be minimized. Window 1 should again
88 // be maximized. Window 3 should still be minimized.
89 EXPECT_FALSE(window1_state->IsMinimized());
90 EXPECT_TRUE(window1_state->IsMaximized());
91 EXPECT_FALSE(window2_state->IsMinimized());
92 EXPECT_TRUE(window3_state->IsMinimized());