1 /*
2 * Copyright (c) 2023 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 <cstring>
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19
20 #define private public
21 #include "background_task_adapter.h"
22 #include "background_task_mgr_helper.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace OHOS::BackgroundTaskMgr;
27
28 namespace OHOS::BackgroundTaskMgr {
29 namespace {
30 ErrCode g_errCode = 0;
31 } // namespace
RequestBackgroundRunningForInner(const ContinuousTaskParamForInner & taskParam)32 ErrCode BackgroundTaskMgrHelper::RequestBackgroundRunningForInner(const ContinuousTaskParamForInner &taskParam)
33 {
34 return g_errCode;
35 }
36 }
37
38 namespace OHOS::NWeb {
39 class BackgroundTaskImplTest : public testing::Test {
40 public:
41 static void SetUpTestCase(void);
42 static void TearDownTestCase(void);
43 void SetUp();
44 void TearDown();
45 };
46
SetUpTestCase(void)47 void BackgroundTaskImplTest::SetUpTestCase(void)
48 {}
49
TearDownTestCase(void)50 void BackgroundTaskImplTest::TearDownTestCase(void)
51 {}
52
SetUp(void)53 void BackgroundTaskImplTest::SetUp(void)
54 {}
55
TearDown(void)56 void BackgroundTaskImplTest::TearDown(void)
57 {}
58
59 /**
60 * @tc.name: BackgroundTaskImplTest_BackgroundTaskAdapter_001
61 * @tc.desc: BackgroundTaskAdapter.
62 * @tc.type: FUNC
63 * @tc.require:
64 */
65 HWTEST_F(BackgroundTaskImplTest, BackgroundTaskImplTest_BackgroundTaskAdapter_001, TestSize.Level1)
66 {
67 auto taskAdapter = std::make_shared<BackgroundTaskAdapter>();
68 EXPECT_NE(taskAdapter, nullptr);
69 bool result = taskAdapter->RequestBackgroundRunning(true, BackgroundModeAdapter::DATA_TRANSFER);
70 EXPECT_TRUE(result);
71 g_errCode = -1;
72 result = taskAdapter->RequestBackgroundRunning(true, BackgroundModeAdapter::AUDIO_PLAYBACK);
73 EXPECT_FALSE(result);
74 result = taskAdapter->RequestBackgroundRunning(true, BackgroundModeAdapter::AUDIO_RECORDING);
75 EXPECT_FALSE(result);
76 result = taskAdapter->RequestBackgroundRunning(true, BackgroundModeAdapter::LOCATION);
77 EXPECT_FALSE(result);
78 result = taskAdapter->RequestBackgroundRunning(true, BackgroundModeAdapter::BLUETOOTH_INTERACTION);
79 EXPECT_FALSE(result);
80 result = taskAdapter->RequestBackgroundRunning(true, BackgroundModeAdapter::MULTI_DEVICE_CONNECTION);
81 EXPECT_FALSE(result);
82 result = taskAdapter->RequestBackgroundRunning(true, BackgroundModeAdapter::WIFI_INTERACTION);
83 EXPECT_FALSE(result);
84 result = taskAdapter->RequestBackgroundRunning(true, BackgroundModeAdapter::VOIP);
85 EXPECT_FALSE(result);
86 result = taskAdapter->RequestBackgroundRunning(true, BackgroundModeAdapter::TASK_KEEPING);
87 EXPECT_FALSE(result);
88 }
89 } // namespace OHOS