• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "adapter/ohos/entrance/high_contrast_observer.h"
18 #include "test/mock/core/common/mock_container.h"
19 #include "test/mock/core/pipeline/mock_pipeline_context.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 using namespace OHOS::Ace::Platform;
24 
25 namespace OHOS::Ace::NG {
26 class HighContrastObserverTest : public testing::Test {
27 public:
SetUp()28     void SetUp() override {};
TearDown()29     void TearDown() override {};
30 };
31 
32 /**
33  * @tc.name: OnConfigChanged001
34  * @tc.desc: Test OnConfigChanged with first_ is true
35  * @tc.type: FUNC
36  * @tc.require: issueICK0X0
37  */
38 HWTEST_F(HighContrastObserverTest, OnConfigChanged001, TestSize.Level1)
39 {
40     auto highContrastObserver = std::make_shared<HighContrastObserver>(nullptr);
41     highContrastObserver->first_ = true;
42     AccessibilityConfig::ConfigValue value;
43     highContrastObserver->OnConfigChanged(AccessibilityConfig::CONFIG_ID::CONFIG_HIGH_CONTRAST_TEXT, value);
44     EXPECT_FALSE(highContrastObserver->first_);
45 }
46 
47 /**
48  * @tc.name: OnConfigChanged002
49  * @tc.desc: Test OnConfigChanged with AceContainer is nullptr
50  * @tc.type: FUNC
51  * @tc.require: issueICK0X0
52  */
53 HWTEST_F(HighContrastObserverTest, OnConfigChanged002, TestSize.Level1)
54 {
55     auto highContrastObserver = std::make_shared<HighContrastObserver>(nullptr);
56     highContrastObserver->first_ = false;
57     AccessibilityConfig::ConfigValue value;
58     highContrastObserver->OnConfigChanged(AccessibilityConfig::CONFIG_ID::CONFIG_HIGH_CONTRAST_TEXT, value);
59     EXPECT_FALSE(highContrastObserver->first_);
60 }
61 
62 /**
63  * @tc.name: OnConfigChanged003
64  * @tc.desc: Test OnConfigChanged with pipelineContext is nullptr
65  * @tc.type: FUNC
66  * @tc.require: issueICK0X0
67  */
68 HWTEST_F(HighContrastObserverTest, OnConfigChanged003, TestSize.Level1)
69 {
70     int32_t instanceId = 1;
71     auto container = AceContainer::GetContainer(instanceId);
72     EXPECT_NE(container, nullptr);
73     auto highContrastObserver = std::make_shared<HighContrastObserver>(AceType::WeakClaim(container.GetRawPtr()));
74     highContrastObserver->first_ = false;
75     AccessibilityConfig::ConfigValue value;
76     highContrastObserver->OnConfigChanged(AccessibilityConfig::CONFIG_ID::CONFIG_HIGH_CONTRAST_TEXT, value);
77     EXPECT_FALSE(highContrastObserver->first_);
78 }
79 } // namespace OHOS::Ace::NG