• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #include <gtest/gtest.h>
17 #define private public
18 #include "extension_control_interceptor.h"
19 #undef private
20 
21 #include "ability_record.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS::AppExecFwk;
25 
26 namespace OHOS {
27 namespace AAFwk {
28 class ExtensionControlInterceptorTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31     static void TearDownTestCase(void);
32     void SetUp();
33     void TearDown();
34     sptr<Token> GetAbilityToken();
35 };
36 
SetUpTestCase(void)37 void ExtensionControlInterceptorTest::SetUpTestCase(void)
38 {}
TearDownTestCase(void)39 void ExtensionControlInterceptorTest::TearDownTestCase(void)
40 {}
SetUp(void)41 void ExtensionControlInterceptorTest::SetUp(void)
42 {}
TearDown(void)43 void ExtensionControlInterceptorTest::TearDown(void)
44 {}
45 
GetAbilityToken()46 sptr<Token> ExtensionControlInterceptorTest::GetAbilityToken()
47 {
48     sptr<Token> token = nullptr;
49     AbilityRequest abilityRequest;
50     abilityRequest.appInfo.bundleName = "com.example.fuzzTest";
51     abilityRequest.abilityInfo.name = "MainAbility";
52     abilityRequest.abilityInfo.type = AbilityType::DATA;
53     std::shared_ptr<AbilityRecord> abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest);
54     if (abilityRecord) {
55         token = abilityRecord->GetToken();
56     }
57     return token;
58 }
59 
60 /*
61  * Feature: ExtensionControlInterceptorTest
62  * Function: DoProcess
63  */
64 HWTEST_F(ExtensionControlInterceptorTest, DoProcess_001, TestSize.Level1)
65 {
66     std::shared_ptr<ExtensionControlInterceptor> extensionControlInterceptor =
67         std::make_shared<ExtensionControlInterceptor>();
68     Want want;
69     int requestCode = 1;
70     int32_t userId = 100;
71     bool isWithUI = false;
72     sptr<IRemoteObject> token = GetAbilityToken();
__anonfc86c9de0102() 73     auto shouldBlockFunc = []() { return false; };
74     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, isWithUI, token,
75         shouldBlockFunc);
76     extensionControlInterceptor->DoProcess(param);
77     AbilityInterceptorParam param2 = AbilityInterceptorParam(want, requestCode, userId, isWithUI, nullptr,
78         shouldBlockFunc);
79     EXPECT_EQ(extensionControlInterceptor->DoProcess(param2), ERR_OK);
80 }
81 
82 }
83 }