• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include <gtest/gtest.h>
17 #include <parameters.h>
18 #include "ability_context_impl.h"
19 #include "display_info.h"
20 #include "common_test_utils.h"
21 #include "mock_session.h"
22 #include "mock_uicontent.h"
23 #include "mock_window_adapter.h"
24 #include "singleton_mocker.h"
25 #include "window_scene_session_impl.h"
26 #include "window_session_impl.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 
31 namespace OHOS {
32 namespace Rosen {
33 class WindowSceneSessionImplTest5 : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     void SetUp() override;
38     void TearDown() override;
39 };
40 
SetUpTestCase()41 void WindowSceneSessionImplTest5::SetUpTestCase()
42 {
43 }
44 
TearDownTestCase()45 void WindowSceneSessionImplTest5::TearDownTestCase()
46 {
47 }
48 
SetUp()49 void WindowSceneSessionImplTest5::SetUp()
50 {
51 }
52 
TearDown()53 void WindowSceneSessionImplTest5::TearDown()
54 {
55 }
56 
57 namespace {
58 /**
59  * @tc.name: ShowKeyboard01
60  * @tc.desc: SwitchFreeMultiWindow
61  * @tc.type: FUNC
62  */
63 HWTEST_F(WindowSceneSessionImplTest5, ShowKeyboard01, Function | SmallTest | Level2)
64 {
65     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
66     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
67     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
68 
69     sptr<WindowSceneSessionImpl> keyboardWindow = sptr<WindowSceneSessionImpl>::MakeSptr(option);
70     keyboardWindow->property_->SetPersistentId(1000);
71     keyboardWindow->hostSession_ = session;
72     keyboardWindow->property_->SetWindowName("SwitchFreeMultiWindow02_mainWindow");
73     keyboardWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
74     keyboardWindow->state_ = WindowState::STATE_DESTROYED;
75 
76     // normal value
77     ASSERT_EQ(keyboardWindow->ShowKeyboard(KeyboardViewMode::DARK_IMMERSIVE_MODE), WMError::WM_ERROR_INVALID_WINDOW);
78 
79     // exception value
80     ASSERT_EQ(keyboardWindow->ShowKeyboard(KeyboardViewMode::VIEW_MODE_END), WMError::WM_ERROR_INVALID_WINDOW);
81     ASSERT_EQ(keyboardWindow->property_->GetKeyboardViewMode(), KeyboardViewMode::NON_IMMERSIVE_MODE);
82 }
83 
84 /**
85  * @tc.name: ChangeKeyboardViewMode01
86  * @tc.desc: SwitchFreeMultiWindow
87  * @tc.type: FUNC
88  */
89 HWTEST_F(WindowSceneSessionImplTest5, ChangeKeyboardViewMode01, Function | SmallTest | Level2)
90 {
91     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
92     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
93     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
94 
95     sptr<WindowSceneSessionImpl> keyboardWindow = sptr<WindowSceneSessionImpl>::MakeSptr(option);
96     keyboardWindow->property_->SetPersistentId(1000);
97     keyboardWindow->hostSession_ = session;
98     keyboardWindow->property_->SetWindowName("SwitchFreeMultiWindow02_mainWindow");
99     keyboardWindow->property_->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
100     keyboardWindow->property_->SetKeyboardViewMode(KeyboardViewMode::NON_IMMERSIVE_MODE);
101 
102     auto result = WMError::WM_OK;
103     // exception mode value
104     result = keyboardWindow->ChangeKeyboardViewMode(KeyboardViewMode::VIEW_MODE_END);
105     ASSERT_EQ(result, WMError::WM_ERROR_INVALID_PARAM);
106 
107     // same mode
108     result = keyboardWindow->ChangeKeyboardViewMode(KeyboardViewMode::NON_IMMERSIVE_MODE);
109     ASSERT_EQ(result, WMError::WM_DO_NOTHING);
110 
111     // invalid window state
112     keyboardWindow->state_ = WindowState::STATE_DESTROYED;
113     result = keyboardWindow->ChangeKeyboardViewMode(KeyboardViewMode::LIGHT_IMMERSIVE_MODE);
114     ASSERT_EQ(result, WMError::WM_ERROR_INVALID_WINDOW);
115 
116     // window state not shown
117     keyboardWindow->state_ = WindowState::STATE_HIDDEN;
118     result = keyboardWindow->ChangeKeyboardViewMode(KeyboardViewMode::LIGHT_IMMERSIVE_MODE);
119     ASSERT_EQ(result, WMError::WM_ERROR_INVALID_WINDOW);
120 
121     keyboardWindow->state_ = WindowState::STATE_SHOWN;
122     result = keyboardWindow->ChangeKeyboardViewMode(KeyboardViewMode::DARK_IMMERSIVE_MODE);
123     ASSERT_EQ(result, WMError::WM_OK);
124     auto currentMode = keyboardWindow->property_->GetKeyboardViewMode();
125     ASSERT_EQ(currentMode, KeyboardViewMode::DARK_IMMERSIVE_MODE);
126 }
127 
128 /**
129  * @tc.name: StartMoveWindowWithCoordinate_01
130  * @tc.desc: StartMoveWindowWithCoordinate
131  * @tc.type: FUNC
132  */
133 HWTEST_F(WindowSceneSessionImplTest5, StartMoveWindowWithCoordinate_01, Function | SmallTest | Level2)
134 {
135     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
136     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
137     window->property_->SetPersistentId(1);
138     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
139     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
140     window->hostSession_ = session;
141 
142     window->windowSystemConfig_.uiType_ = UI_TYPE_PHONE;
143     ASSERT_EQ(window->StartMoveWindowWithCoordinate(100, 50), WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT);
144 
145     window->windowSystemConfig_.uiType_ = UI_TYPE_PC;
146     ASSERT_NE(window->StartMoveWindowWithCoordinate(100, 50), WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT);
147 
148     window->windowSystemConfig_.uiType_ = UI_TYPE_PAD;
149     window->windowSystemConfig_.freeMultiWindowEnable_ = true;
150     window->windowSystemConfig_.freeMultiWindowSupport_ = true;
151     ASSERT_NE(window->StartMoveWindowWithCoordinate(100, 50), WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT);
152 }
153 
154 /**
155  * @tc.name: StartMoveWindowWithCoordinate_02
156  * @tc.desc: StartMoveWindowWithCoordinate
157  * @tc.type: FUNC
158  */
159 HWTEST_F(WindowSceneSessionImplTest5, StartMoveWindowWithCoordinate_02, Function | SmallTest | Level2)
160 {
161     sptr<WindowOption> option = sptr<WindowOption>::MakeSptr();
162     sptr<WindowSceneSessionImpl> window = sptr<WindowSceneSessionImpl>::MakeSptr(option);
163     window->property_->SetPersistentId(1);
164     Rect windowRect = { 200, 200, 1000, 1000 };
165     window->property_->SetWindowRect(windowRect);
166     SessionInfo sessionInfo = { "CreateTestBundle", "CreateTestModule", "CreateTestAbility" };
167     sptr<SessionMocker> session = sptr<SessionMocker>::MakeSptr(sessionInfo);
168     window->hostSession_ = session;
169     window->windowSystemConfig_.uiType_ = UI_TYPE_PC;
170 
171     ASSERT_EQ(window->StartMoveWindowWithCoordinate(-1, 50), WmErrorCode::WM_ERROR_INVALID_PARAM);
172     ASSERT_EQ(window->StartMoveWindowWithCoordinate(100, -1), WmErrorCode::WM_ERROR_INVALID_PARAM);
173     ASSERT_EQ(window->StartMoveWindowWithCoordinate(1500, 50), WmErrorCode::WM_ERROR_INVALID_PARAM);
174     ASSERT_EQ(window->StartMoveWindowWithCoordinate(100, 1500), WmErrorCode::WM_ERROR_INVALID_PARAM);
175 }
176 }  // namespace
177 }
178 }