1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "media/base/android/media_codec_util.h"
6 #include "base/android/build_info.h"
7 #include "base/macros.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace media {
11
12 // These will come from mockable BuildInfo, once it exists.
13 using base::android::SDK_VERSION_KITKAT;
14 using base::android::SDK_VERSION_LOLLIPOP;
15 using base::android::SDK_VERSION_LOLLIPOP_MR1;
16 using base::android::SDK_VERSION_MARSHMALLOW;
17 using base::android::SDK_VERSION_NOUGAT;
18 using base::android::SDK_VERSION_NOUGAT_MR1;
19
20 class MediaCodecUtilTest : public testing::Test {
21 public:
MediaCodecUtilTest()22 MediaCodecUtilTest() {}
~MediaCodecUtilTest()23 ~MediaCodecUtilTest() override {}
24
25 public:
26 DISALLOW_COPY_AND_ASSIGN(MediaCodecUtilTest);
27 };
28
TEST_F(MediaCodecUtilTest,TestCodecAvailableIfNewerVersion)29 TEST_F(MediaCodecUtilTest, TestCodecAvailableIfNewerVersion) {
30 // Test models that should be available above some sdk level. We probably
31 // don't need to test them all; we're more concerned that the blocklist code
32 // is doing the right thing with the entries it has rather than the map
33 // contents are right.
34 struct {
35 const char* model;
36 int last_bad_sdk;
37 } devices[] = {{"LGMS330", SDK_VERSION_LOLLIPOP_MR1},
38
39 {"GT-I9100", SDK_VERSION_KITKAT},
40 {"GT-I9300", SDK_VERSION_KITKAT},
41 {"GT-N7000", SDK_VERSION_KITKAT},
42 {"GT-N7100", SDK_VERSION_KITKAT},
43 {"A6600", SDK_VERSION_KITKAT},
44 {"A6800", SDK_VERSION_KITKAT},
45 {"GT-S7262", SDK_VERSION_KITKAT},
46 {"GT-S5282", SDK_VERSION_KITKAT},
47 {"GT-I8552", SDK_VERSION_KITKAT},
48
49 {"always_works", 0}, // Some codec that works everywhere.
50 {nullptr, 0}};
51
52 for (int sdk = SDK_VERSION_KITKAT; sdk <= SDK_VERSION_NOUGAT; sdk++) {
53 for (int i = 0; devices[i].model; i++) {
54 bool supported =
55 MediaCodecUtil::IsMediaCodecAvailableFor(sdk, devices[i].model);
56
57 // Make sure that this model is supported if and only if |sdk| is
58 // newer than |last_bad_sdk|.
59 ASSERT_TRUE(supported == (sdk > devices[i].last_bad_sdk))
60 << " model: " << devices[i].model << " sdk: " << sdk;
61 }
62 }
63 }
64
TEST_F(MediaCodecUtilTest,TestCbcsAvailableIfNewerVersion)65 TEST_F(MediaCodecUtilTest, TestCbcsAvailableIfNewerVersion) {
66 EXPECT_FALSE(
67 MediaCodecUtil::PlatformSupportsCbcsEncryption(SDK_VERSION_MARSHMALLOW));
68 EXPECT_FALSE(
69 MediaCodecUtil::PlatformSupportsCbcsEncryption(SDK_VERSION_NOUGAT));
70 EXPECT_TRUE(
71 MediaCodecUtil::PlatformSupportsCbcsEncryption(SDK_VERSION_NOUGAT_MR1));
72 }
73
74 } // namespace media
75