123b3eb3cSopenharmony_ci/*
223b3eb3cSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License.
523b3eb3cSopenharmony_ci * You may obtain a copy of the License at
623b3eb3cSopenharmony_ci *
723b3eb3cSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
823b3eb3cSopenharmony_ci *
923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and
1323b3eb3cSopenharmony_ci * limitations under the License.
1423b3eb3cSopenharmony_ci */
1523b3eb3cSopenharmony_ci
1623b3eb3cSopenharmony_ci#include "gtest/gtest.h"
1723b3eb3cSopenharmony_ci#define private public
1823b3eb3cSopenharmony_ci#define protected public
1923b3eb3cSopenharmony_ci#include "ace_forward_compatibility.h"
2023b3eb3cSopenharmony_ci#include "interfaces/inner_api/ace/ui_event.h"
2123b3eb3cSopenharmony_ci#include "interfaces/inner_api/ace/ui_event_func.h"
2223b3eb3cSopenharmony_ci#include "interfaces/inner_api/ace/ui_event_observer.h"
2323b3eb3cSopenharmony_ci#include "test/mock/core/common/mock_container.h"
2423b3eb3cSopenharmony_ci#include "test/mock/core/common/mock_theme_manager.h"
2523b3eb3cSopenharmony_ci#include "test/mock/core/pipeline/mock_pipeline_context.h"
2623b3eb3cSopenharmony_ci
2723b3eb3cSopenharmony_ci#include "core/components/popup/popup_theme.h"
2823b3eb3cSopenharmony_ci
2923b3eb3cSopenharmony_ciusing namespace testing;
3023b3eb3cSopenharmony_ciusing namespace testing::ext;
3123b3eb3cSopenharmony_ci
3223b3eb3cSopenharmony_cinamespace OHOS::Ace {
3323b3eb3cSopenharmony_ciclass UiEventTest : public testing::Test {
3423b3eb3cSopenharmony_cipublic:
3523b3eb3cSopenharmony_ci    static void SetUpTestSuite()
3623b3eb3cSopenharmony_ci    {
3723b3eb3cSopenharmony_ci        NG::MockPipelineContext::SetUp();
3823b3eb3cSopenharmony_ci        MockContainer::SetUp();
3923b3eb3cSopenharmony_ci        MockContainer::Current()->pipelineContext_ = PipelineBase::GetCurrentContext();
4023b3eb3cSopenharmony_ci        auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
4123b3eb3cSopenharmony_ci        PipelineBase::GetCurrentContext()->SetThemeManager(themeManager);
4223b3eb3cSopenharmony_ci        PipelineBase::GetCurrentContext()->SetEventManager(AceType::MakeRefPtr<EventManager>());
4323b3eb3cSopenharmony_ci        EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<PopupTheme>()));
4423b3eb3cSopenharmony_ci    }
4523b3eb3cSopenharmony_ci    static void TearDownTestSuite()
4623b3eb3cSopenharmony_ci    {
4723b3eb3cSopenharmony_ci        MockContainer::Current()->pipelineContext_ = nullptr;
4823b3eb3cSopenharmony_ci        NG::MockPipelineContext::TearDown();
4923b3eb3cSopenharmony_ci    }
5023b3eb3cSopenharmony_ci    void SetUp() {}
5123b3eb3cSopenharmony_ci    void TearDown() {}
5223b3eb3cSopenharmony_ci};
5323b3eb3cSopenharmony_ci
5423b3eb3cSopenharmony_ci/**
5523b3eb3cSopenharmony_ci * @tc.name: UiEventTest001
5623b3eb3cSopenharmony_ci * @tc.desc: test UIEvent GetNodeProperty
5723b3eb3cSopenharmony_ci * @tc.type: FUNC
5823b3eb3cSopenharmony_ci */
5923b3eb3cSopenharmony_ciHWTEST_F(UiEventTest, UiEventTest001, TestSize.Level1)
6023b3eb3cSopenharmony_ci{
6123b3eb3cSopenharmony_ci    /**
6223b3eb3cSopenharmony_ci     * @tc.steps1: initialize parameters.
6323b3eb3cSopenharmony_ci     */
6423b3eb3cSopenharmony_ci    std::string pageUrl = "Pages/Index";
6523b3eb3cSopenharmony_ci    auto nodeProperties = std::unordered_map<std::string, std::string>();
6623b3eb3cSopenharmony_ci
6723b3eb3cSopenharmony_ci    /**
6823b3eb3cSopenharmony_ci     * @tc.steps2: Call the function GetNodeProperty.
6923b3eb3cSopenharmony_ci     * @tc.expected: The function is run ok and IsAvailable() is true.
7023b3eb3cSopenharmony_ci     */
7123b3eb3cSopenharmony_ci    UIEvent::GetNodeProperty(pageUrl, nodeProperties);
7223b3eb3cSopenharmony_ci
7323b3eb3cSopenharmony_ci    bool result = UIEventFunc::Get().IsAvailable();
7423b3eb3cSopenharmony_ci    EXPECT_FALSE(result);
7523b3eb3cSopenharmony_ci}
7623b3eb3cSopenharmony_ci
7723b3eb3cSopenharmony_ci/**
7823b3eb3cSopenharmony_ci * @tc.name: UiEventTest002
7923b3eb3cSopenharmony_ci * @tc.desc: test UIEvent GetSimplifiedInspectorTree
8023b3eb3cSopenharmony_ci * @tc.type: FUNC
8123b3eb3cSopenharmony_ci */
8223b3eb3cSopenharmony_ciHWTEST_F(UiEventTest, UiEventTest002, TestSize.Level1)
8323b3eb3cSopenharmony_ci{
8423b3eb3cSopenharmony_ci    /**
8523b3eb3cSopenharmony_ci     * @tc.steps1: initialize parameters.
8623b3eb3cSopenharmony_ci     */
8723b3eb3cSopenharmony_ci    std::string tree = "treeTest";
8823b3eb3cSopenharmony_ci
8923b3eb3cSopenharmony_ci    /**
9023b3eb3cSopenharmony_ci     * @tc.steps2: Call the function GetSimplifiedInspectorTree.
9123b3eb3cSopenharmony_ci     * @tc.expected: The function is run ok and IsAvailable() is true.
9223b3eb3cSopenharmony_ci     */
9323b3eb3cSopenharmony_ci    UIEvent::GetSimplifiedInspectorTree(tree);
9423b3eb3cSopenharmony_ci    bool result = UIEventFunc::Get().IsAvailable();
9523b3eb3cSopenharmony_ci    EXPECT_FALSE(result);
9623b3eb3cSopenharmony_ci}
9723b3eb3cSopenharmony_ci
9823b3eb3cSopenharmony_ci/**
9923b3eb3cSopenharmony_ci * @tc.name: UiEventTest003
10023b3eb3cSopenharmony_ci * @tc.desc: test UIEventFunc RegisterUIEventObserver/UnregisterUIEventObserver
10123b3eb3cSopenharmony_ci * @tc.type: FUNC
10223b3eb3cSopenharmony_ci */
10323b3eb3cSopenharmony_ciHWTEST_F(UiEventTest, UiEventTest003, TestSize.Level1)
10423b3eb3cSopenharmony_ci{
10523b3eb3cSopenharmony_ci    /**
10623b3eb3cSopenharmony_ci     * @tc.steps1: initialize parameters Call the function RegisterUIEventObserver.
10723b3eb3cSopenharmony_ci     */
10823b3eb3cSopenharmony_ci    std::string config = "configTest";
10923b3eb3cSopenharmony_ci    const std::shared_ptr<UIEventObserver> observer = nullptr;
11023b3eb3cSopenharmony_ci    UIEventFunc::RegisterUIEventObserver(config, observer);
11123b3eb3cSopenharmony_ci    bool result = UIEventFunc::Get().IsAvailable();
11223b3eb3cSopenharmony_ci    EXPECT_FALSE(result);
11323b3eb3cSopenharmony_ci
11423b3eb3cSopenharmony_ci    /**
11523b3eb3cSopenharmony_ci     * @tc.steps2: Call the function UnregisterUIEventObserver.
11623b3eb3cSopenharmony_ci     * @tc.expected: The function is run ok and IsAvailable() is true.
11723b3eb3cSopenharmony_ci     */
11823b3eb3cSopenharmony_ci    UIEventFunc::UnregisterUIEventObserver(observer);
11923b3eb3cSopenharmony_ci    bool result2 = UIEventFunc::Get().IsAvailable();
12023b3eb3cSopenharmony_ci    EXPECT_FALSE(result2);
12123b3eb3cSopenharmony_ci}
12223b3eb3cSopenharmony_ci} // namespace OHOS::Ace