• 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 "iremote_object_mocker.h"
17 #include "mock_message_parcel.h"
18 #include "session_ipc_interface_code.h"
19 #include "session_proxy.h"
20 #include "ws_common.h"
21 #include <gtest/gtest.h>
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace Rosen {
28 class SessionProxyPropertyTest : public testing::Test {
29 public:
SessionProxyPropertyTest()30     SessionProxyPropertyTest() {}
~SessionProxyPropertyTest()31     ~SessionProxyPropertyTest() {}
32 };
33 
34 namespace {
35 
36 /**
37  * @tc.name: UpdateSessionPropertyByAction01
38  * @tc.desc: UpdateSessionPropertyByAction
39  * @tc.type: FUNC
40  */
41 HWTEST_F(SessionProxyPropertyTest, UpdateSessionPropertyByAction01, TestSize.Level1)
42 {
43     GTEST_LOG_(INFO) << "SessionProxyPropertyTest: UpdateSessionPropertyByAction01 start";
44     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
45     ASSERT_NE(iRemoteObjectMocker, nullptr);
46     auto sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
47     ASSERT_NE(sProxy, nullptr);
48     WMError res = sProxy->UpdateSessionPropertyByAction(nullptr, WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
49     ASSERT_EQ(res, WMError::WM_OK);
50     GTEST_LOG_(INFO) << "SessionProxyPropertyTest: UpdateSessionPropertyByAction01 end";
51 }
52 
53 /**
54  * @tc.name: UpdateSessionPropertyByAction02
55  * @tc.desc: UpdateSessionPropertyByAction
56  * @tc.type: FUNC
57  */
58 HWTEST_F(SessionProxyPropertyTest, UpdateSessionPropertyByAction02, TestSize.Level1)
59 {
60     GTEST_LOG_(INFO) << "SessionProxyPropertyTest: UpdateSessionPropertyByAction02 start";
61     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
62     ASSERT_NE(iRemoteObjectMocker, nullptr);
63     auto sProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
64     ASSERT_NE(sProxy, nullptr);
65     WMError res = sProxy->UpdateSessionPropertyByAction(nullptr, WSPropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
66     ASSERT_EQ(res, WMError::WM_OK);
67     GTEST_LOG_(INFO) << "SessionProxyPropertyTest: UpdateSessionPropertyByAction02 end";
68 }
69 
70 /**
71  * @tc.name: UpdateSessionPropertyByAction
72  * @tc.desc: normal function
73  * @tc.type: FUNC
74  */
75 HWTEST_F(SessionProxyPropertyTest, UpdateSessionPropertyByAction, TestSize.Level1)
76 {
77     MockMessageParcel::ClearAllErrorFlag();
78     sptr<IRemoteObject> iRemoteObjectMocker = sptr<IRemoteObjectMocker>::MakeSptr();
79     auto sessionProxy = sptr<SessionProxy>::MakeSptr(iRemoteObjectMocker);
80     ASSERT_NE(sessionProxy, nullptr);
81     MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true);
82     ASSERT_EQ(
83         WMError::WM_ERROR_IPC_FAILED,
84         sessionProxy->UpdateSessionPropertyByAction(nullptr, WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
85     MockMessageParcel::ClearAllErrorFlag();
86 
87     MockMessageParcel::SetWriteUint32ErrorFlag(true);
88     ASSERT_EQ(
89         WMError::WM_ERROR_IPC_FAILED,
90         sessionProxy->UpdateSessionPropertyByAction(nullptr, WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
91     MockMessageParcel::ClearAllErrorFlag();
92 
93     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
94     ASSERT_NE(property, nullptr);
95     MockMessageParcel::SetWriteBoolErrorFlag(true);
96     ASSERT_EQ(
97         WMError::WM_ERROR_IPC_FAILED,
98         sessionProxy->UpdateSessionPropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
99     MockMessageParcel::ClearAllErrorFlag();
100 
101     MockMessageParcel::SetWriteBoolErrorFlag(false);
102     ASSERT_EQ(
103         WMError::WM_OK,
104         sessionProxy->UpdateSessionPropertyByAction(property, WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
105     MockMessageParcel::ClearAllErrorFlag();
106 
107     MockMessageParcel::SetWriteBoolErrorFlag(true);
108     ASSERT_EQ(
109         WMError::WM_ERROR_IPC_FAILED,
110         sessionProxy->UpdateSessionPropertyByAction(nullptr, WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
111     MockMessageParcel::ClearAllErrorFlag();
112 
113     MockMessageParcel::SetWriteBoolErrorFlag(false);
114     ASSERT_EQ(
115         WMError::WM_OK,
116         sessionProxy->UpdateSessionPropertyByAction(nullptr, WSPropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
117     MockMessageParcel::ClearAllErrorFlag();
118 }
119 } // namespace
120 } // namespace Rosen
121 } // namespace OHOS
122