1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 // gtest
17 #include <gtest/gtest.h>
18 #include "window_test_utils.h"
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 using Utils = WindowTestUtils;
26 class WindowMultiAbilityTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 virtual void SetUp() override;
31 virtual void TearDown() override;
32 };
33
SetUpTestCase()34 void WindowMultiAbilityTest::SetUpTestCase()
35 {
36 }
37
TearDownTestCase()38 void WindowMultiAbilityTest::TearDownTestCase()
39 {
40 }
41
SetUp()42 void WindowMultiAbilityTest::SetUp()
43 {
44 }
45
TearDown()46 void WindowMultiAbilityTest::TearDown()
47 {
48 }
49
50 /**
51 * @tc.name: MultiAbilityWindow01
52 * @tc.desc: Five scene process in one thread
53 * @tc.type: FUNC
54 */
55 HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow01, Function | MediumTest | Level2)
56 {
57 sptr<WindowScene> scene1 = Utils::CreateWindowScene();
58 sptr<WindowScene> scene2 = Utils::CreateWindowScene();
59 sptr<WindowScene> scene3 = Utils::CreateWindowScene();
60 sptr<WindowScene> scene4 = Utils::CreateWindowScene();
61 sptr<WindowScene> scene5 = Utils::CreateWindowScene();
62
63 ASSERT_EQ(WMError::WM_OK, scene1->GoForeground());
64 ASSERT_EQ(WMError::WM_OK, scene2->GoForeground());
65 ASSERT_EQ(WMError::WM_OK, scene3->GoForeground());
66 ASSERT_EQ(WMError::WM_OK, scene4->GoForeground());
67 ASSERT_EQ(WMError::WM_OK, scene5->GoForeground());
68 ASSERT_EQ(WMError::WM_OK, scene5->GoBackground());
69 ASSERT_EQ(WMError::WM_OK, scene4->GoBackground());
70 ASSERT_EQ(WMError::WM_OK, scene3->GoBackground());
71 ASSERT_EQ(WMError::WM_OK, scene2->GoBackground());
72 ASSERT_EQ(WMError::WM_OK, scene1->GoBackground());
73 ASSERT_EQ(WMError::WM_OK, scene1->GoDestroy());
74 ASSERT_EQ(WMError::WM_OK, scene2->GoDestroy());
75 ASSERT_EQ(WMError::WM_OK, scene3->GoDestroy());
76 ASSERT_EQ(WMError::WM_OK, scene4->GoDestroy());
77 ASSERT_EQ(WMError::WM_OK, scene5->GoDestroy());
78 }
79
80 /**
81 * @tc.name: MultiAbilityWindow04
82 * @tc.desc: Five scene process in one thread, create/show/hide/destroy in order
83 * @tc.type: FUNC
84 */
85 HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow02, Function | MediumTest | Level3)
86 {
87 sptr<WindowScene> scene1 = Utils::CreateWindowScene();
88 ASSERT_EQ(WMError::WM_OK, scene1->GoForeground());
89 ASSERT_EQ(WMError::WM_OK, scene1->GoBackground());
90 ASSERT_EQ(WMError::WM_OK, scene1->GoDestroy());
91
92 sptr<WindowScene> scene2 = Utils::CreateWindowScene();
93 ASSERT_EQ(WMError::WM_OK, scene2->GoForeground());
94 ASSERT_EQ(WMError::WM_OK, scene2->GoBackground());
95 ASSERT_EQ(WMError::WM_OK, scene2->GoDestroy());
96
97 sptr<WindowScene> scene3 = Utils::CreateWindowScene();
98 ASSERT_EQ(WMError::WM_OK, scene3->GoForeground());
99 ASSERT_EQ(WMError::WM_OK, scene3->GoBackground());
100 ASSERT_EQ(WMError::WM_OK, scene3->GoDestroy());
101
102 sptr<WindowScene> scene4 = Utils::CreateWindowScene();
103 ASSERT_EQ(WMError::WM_OK, scene4->GoForeground());
104 ASSERT_EQ(WMError::WM_OK, scene4->GoBackground());
105 ASSERT_EQ(WMError::WM_OK, scene4->GoDestroy());
106
107 sptr<WindowScene> scene5 = Utils::CreateWindowScene();
108 ASSERT_EQ(WMError::WM_OK, scene5->GoForeground());
109 ASSERT_EQ(WMError::WM_OK, scene5->GoBackground());
110 ASSERT_EQ(WMError::WM_OK, scene5->GoDestroy());
111 }
112
113 /**
114 * @tc.name: MultiAbilityWindow05
115 * @tc.desc: Five scene process in one thread, create/show/hide/destroy out of order
116 * @tc.type: FUNC
117 */
118 HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow03, Function | MediumTest | Level3)
119 {
120 sptr<WindowScene> scene1 = Utils::CreateWindowScene();
121 ASSERT_EQ(WMError::WM_OK, scene1->GoForeground());
122 sptr<WindowScene> scene2 = Utils::CreateWindowScene();
123 sptr<WindowScene> scene3 = Utils::CreateWindowScene();
124 ASSERT_EQ(WMError::WM_OK, scene3->GoForeground());
125 ASSERT_EQ(WMError::WM_OK, scene1->GoBackground());
126 ASSERT_EQ(WMError::WM_OK, scene1->GoDestroy());
127 sptr<WindowScene> scene4 = Utils::CreateWindowScene();
128 ASSERT_EQ(WMError::WM_OK, scene3->GoBackground());
129 ASSERT_EQ(WMError::WM_OK, scene2->GoForeground());
130 ASSERT_EQ(WMError::WM_OK, scene4->GoForeground());
131 ASSERT_EQ(WMError::WM_OK, scene2->GoBackground());
132 sptr<WindowScene> scene5 = Utils::CreateWindowScene();
133 ASSERT_EQ(WMError::WM_OK, scene3->GoDestroy());
134 ASSERT_EQ(WMError::WM_OK, scene5->GoForeground());
135 ASSERT_EQ(WMError::WM_OK, scene5->GoBackground());
136 ASSERT_EQ(WMError::WM_OK, scene4->GoBackground());
137 ASSERT_EQ(WMError::WM_OK, scene4->GoDestroy());
138 ASSERT_EQ(WMError::WM_OK, scene5->GoDestroy());
139 ASSERT_EQ(WMError::WM_OK, scene2->GoDestroy());
140 }
141 } // namespace Rosen
142 } // namespace OHOS
143