• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include "frameworks/bridge/common/media_query/media_queryer.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS::Ace::Framework {
24 
25 class MediaQueryTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp();
30     void TearDown();
31 };
32 
SetUpTestCase()33 void MediaQueryTest::SetUpTestCase() {}
TearDownTestCase()34 void MediaQueryTest::TearDownTestCase() {}
SetUp()35 void MediaQueryTest::SetUp() {}
TearDown()36 void MediaQueryTest::TearDown() {}
37 
38 /**
39  * @tc.name: MediaQueryTest001
40  * @tc.desc: Verify that media query condition can match right result.
41  * @tc.type: FUNC
42  * @tc.require: AR000FL26S, AR000FLCEI
43  * @tc.author: kouxinxin
44  */
45 HWTEST_F(MediaQueryTest, MediaQueryTest001, TestSize.Level1)
46 {
47     OHOS::Ace::Framework::MediaFeature mediaFeature = JsonUtil::Create(true);
48     mediaFeature->Put("width", 1500);
49     mediaFeature->Put("device-type", "tv");
50     mediaFeature->Put("round-screen", true);
51 
52     struct ConditionTestCase {
53         std::string condition;
54         bool result;
55     };
56     std::vector<ConditionTestCase> conditions = {
57         { "(max-width: )", false },
58         { "(min-width: 1000)", true },
59         { "(width < 2000)", true },
60         { "(width << 2000)", false },
61         { "(1000 < width)", true },
62         { "(1000 < width < 2000)", true },
63         { "(round-screen: true) (device-type:tv)", false },
64         { "screen and (round-screen: true) and (device-type:tv)", true },
65         { "not screen and (round-screen: true) and (device-type:tv)", false },
66         { "not screen and (round-screen: false) and (device-type:tv)", true },
67         { "not screen and (round-screen: true) and (device-type:phone)", true },
68         { "screen and (round-screen: false), (device-type:tv)", true },
69         { "only screen and (1000 < width < 2000), (device-type:phone)", true },
70         { "(device-height < 2000) and (device-width < 2000) and (round-screen: true) and (device-type:phone)", false },
71         { "(device-height > 2000) or (device-width > 2000) or (round-screen: false) or (device-type:tv)", true },
72         { "(round-screen: true) or (device-type:phone)", true },
73         { "(round-screen: true), screen and (1000 < width < 2000), (device-type:phone)", false },
74     };
75 
76     MediaQueryer mediaQueryer;
77     for (const auto& item : conditions) {
78         bool result = mediaQueryer.MatchCondition(item.condition, mediaFeature);
79         ASSERT_EQ(result, item.result) << "condition = " << item.condition;
80     }
81 }
82 
83 } // namespace OHOS::Ace::Framework
84