| Flutter Windows Embedder |

windows_lifecycle_manager_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter 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.
4
5 #include "flutter/shell/platform/windows/windows_lifecycle_manager.h"
6
7 #include "flutter/shell/platform/windows/testing/windows_test.h"
8 #include "gtest/gtest.h"
9
10 namespace flutter {
11 namespace testing {
12
13 class WindowsLifecycleManagerTest : public WindowsTest {};
14
15 TEST_F(WindowsLifecycleManagerTest, StateTransitions) {
16 WindowsLifecycleManager manager(nullptr);
17 HWND win1 = reinterpret_cast<HWND>(1);
18 HWND win2 = reinterpret_cast<HWND>(2);
19
20 // Hidden to inactive upon window shown.
21 manager.SetLifecycleState(AppLifecycleState::kHidden);
22 manager.OnWindowStateEvent(win1, WindowStateEvent::kShow);
23 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
24
25 // Showing a second window does not change state.
26 manager.OnWindowStateEvent(win2, WindowStateEvent::kShow);
27 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
28
29 // Inactive to resumed upon window focus.
30 manager.OnWindowStateEvent(win2, WindowStateEvent::kFocus);
31 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kResumed);
32
33 // Showing a second window does not change state.
34 manager.OnWindowStateEvent(win1, WindowStateEvent::kFocus);
35 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kResumed);
36
37 // Unfocusing one window does not change state while another is focused.
38 manager.OnWindowStateEvent(win1, WindowStateEvent::kUnfocus);
39 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kResumed);
40
41 // Unfocusing final remaining focused window transitions to inactive.
42 manager.OnWindowStateEvent(win2, WindowStateEvent::kUnfocus);
43 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
44
45 // Hiding one of two visible windows does not change state.
46 manager.OnWindowStateEvent(win2, WindowStateEvent::kHide);
47 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kInactive);
48
49 // Hiding only visible window transitions to hidden.
50 manager.OnWindowStateEvent(win1, WindowStateEvent::kHide);
51 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kHidden);
52
53 // Transition directly from resumed to hidden when the window is hidden.
54 manager.OnWindowStateEvent(win1, WindowStateEvent::kShow);
55 manager.OnWindowStateEvent(win1, WindowStateEvent::kFocus);
56 manager.OnWindowStateEvent(win1, WindowStateEvent::kHide);
57 EXPECT_EQ(manager.GetLifecycleState(), AppLifecycleState::kHidden);
58 }
59
60 } // namespace testing
61 } // namespace flutter
flutter::WindowsLifecycleManager::GetLifecycleState
AppLifecycleState GetLifecycleState()
Definition: windows_lifecycle_manager.h:75
flutter::AppLifecycleState::kHidden
@ kHidden
flutter::WindowStateEvent::kHide
@ kHide
windows_lifecycle_manager.h
flutter::testing::WindowsLifecycleManagerTest
Definition: windows_lifecycle_manager_unittests.cc:13
flutter::WindowsLifecycleManager::SetLifecycleState
virtual void SetLifecycleState(AppLifecycleState state)
Definition: windows_lifecycle_manager.cc:195
flutter::WindowStateEvent::kFocus
@ kFocus
flutter::AppLifecycleState::kInactive
@ kInactive
flutter::WindowStateEvent::kShow
@ kShow
flutter
Definition: accessibility_bridge_windows.cc:11
flutter::WindowsLifecycleManager::OnWindowStateEvent
virtual void OnWindowStateEvent(HWND hwnd, WindowStateEvent event)
Definition: windows_lifecycle_manager.cc:208
flutter::AppLifecycleState::kResumed
@ kResumed
flutter::WindowStateEvent::kUnfocus
@ kUnfocus
flutter::testing::TEST_F
TEST_F(CompositorOpenGLTest, CreateBackingStore)
Definition: compositor_opengl_unittests.cc:125
flutter::WindowsLifecycleManager
Definition: windows_lifecycle_manager.h:37