• 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 
18 #define private public
19 #define protected public
20 #include "auto_fill_extension_context.h"
21 #undef private
22 #undef protected
23 
24 #include "hilog_tag_wrapper.h"
25 #include "mock_window.h"
26 
27 using namespace testing::ext;
28 using namespace OHOS::Rosen;
29 
30 namespace OHOS {
31 namespace AbilityRuntime {
32 class AutoFillExtensionContextTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp() override;
37     void TearDown() override;
38 };
39 
SetUpTestCase(void)40 void AutoFillExtensionContextTest::SetUpTestCase(void)
41 {}
42 
TearDownTestCase(void)43 void AutoFillExtensionContextTest::TearDownTestCase(void)
44 {}
45 
SetUp()46 void AutoFillExtensionContextTest::SetUp()
47 {}
48 
TearDown()49 void AutoFillExtensionContextTest::TearDown()
50 {}
51 
52 class AutoFillMockWindow : public MockWindow {
53 public:
54     AutoFillMockWindow() = default;
55     ~AutoFillMockWindow() = default;
56 
GetUIContent() const57     virtual Ace::UIContent* GetUIContent() const override
58     {
59         return (Ace::UIContent*)0x12345678;
60     }
61 };
62 
63 /**
64  * @tc.number: GetWidow_0100
65  * @tc.name: GetWidow
66  * @tc.desc: GetWidow.
67  */
68 HWTEST_F(AutoFillExtensionContextTest, GetWidow_0100, TestSize.Level1)
69 {
70     TAG_LOGI(AAFwkTag::TEST, "GetWidow_0100 start");
71 
72     auto context = std::make_shared<AutoFillExtensionContext>();
73     sptr<AutoFillMockWindow> window(new (std::nothrow) AutoFillMockWindow());
74     context->SetWindow(window);
75     EXPECT_TRUE(context->GetWindow() != nullptr);
76     TAG_LOGI(AAFwkTag::TEST, "GetWidow_0100 end");
77 }
78 
79 /**
80  * @tc.number: GetUIContent_0100
81  * @tc.name: GetUIContent
82  * @tc.desc: GetUIContent.
83  */
84 HWTEST_F(AutoFillExtensionContextTest, GetUIContent_0100, TestSize.Level1)
85 {
86     TAG_LOGI(AAFwkTag::TEST, "GetUIContent_0100 start");
87 
88     auto context = std::make_shared<AutoFillExtensionContext>();
89     sptr<AutoFillMockWindow> window(new (std::nothrow) AutoFillMockWindow());
90     context->SetWindow(window);
91     Ace::UIContent* content = context->GetUIContent();
92     EXPECT_TRUE(content == (Ace::UIContent*)0x12345678);
93     TAG_LOGI(AAFwkTag::TEST, "GetUIContent_0100 end");
94 }
95 
96 /**
97  * @tc.number: IsContext_0100
98  * @tc.name: IsContext
99  * @tc.desc: IsContext.
100  */
101 HWTEST_F(AutoFillExtensionContextTest, IsContext_0100, TestSize.Level1)
102 {
103     TAG_LOGI(AAFwkTag::TEST, "IsContext_0100 start");
104     auto context = std::make_shared<AutoFillExtensionContext>();
105     auto ret = context->IsContext(AutoFillExtensionContext::CONTEXT_TYPE_ID);
106     EXPECT_TRUE(ret);
107     ret = context->IsContext(UIExtensionContext::CONTEXT_TYPE_ID);
108     EXPECT_TRUE(ret);
109     TAG_LOGI(AAFwkTag::TEST, "IsContext_0100 end");
110 }
111 
112 /**
113  * @tc.number: ConvertTo_0100
114  * @tc.name: ConvertTo
115  * @tc.desc: ConvertTo.
116  */
117 HWTEST_F(AutoFillExtensionContextTest, ConvertTo_0100, TestSize.Level1)
118 {
119     TAG_LOGI(AAFwkTag::TEST, "ConvertTo_0100 start");
120     std::shared_ptr<Context> context = std::make_shared<AutoFillExtensionContext>();
121     auto uiHolderExtensionContext = Context::ConvertTo<UIHolderExtensionContext>(context);
122     EXPECT_NE(uiHolderExtensionContext, nullptr);
123     auto uiExtensionContext = Context::ConvertTo<UIExtensionContext>(context);
124     EXPECT_NE(uiExtensionContext, nullptr);
125     auto autoFillExtensionContext = Context::ConvertTo<AutoFillExtensionContext>(context);
126     EXPECT_NE(autoFillExtensionContext, nullptr);
127     TAG_LOGI(AAFwkTag::TEST, "ConvertTo_0100 end");
128 }
129 
130 /**
131  * @tc.number: ConvertTo_0200
132  * @tc.name: ConvertTo
133  * @tc.desc: ConvertTo.
134  */
135 HWTEST_F(AutoFillExtensionContextTest, ConvertTo_0200, TestSize.Level1)
136 {
137     TAG_LOGI(AAFwkTag::TEST, "ConvertTo_0200 start");
138     std::shared_ptr<Context> context = std::make_shared<UIExtensionContext>();
139     auto autoFillExtensionContext = Context::ConvertTo<AutoFillExtensionContext>(context);
140     EXPECT_EQ(autoFillExtensionContext, nullptr);
141     TAG_LOGI(AAFwkTag::TEST, "ConvertTo_0200 end");
142 }
143 } // namespace AbilityRuntime
144 } // namespace OHOS
145