Bug 1772053 - Enable dynamic code disable mitigations only on Windows 10 1703+ r...
[gecko.git] / dom / media / gtest / TestVideoUtils.cpp
blobd322d15d644160bd74da9ae841395bb1d1971e62
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "gtest/gtest.h"
7 #include "nsMimeTypes.h"
8 #include "nsString.h"
9 #include "VideoUtils.h"
11 using namespace mozilla;
13 TEST(MediaMIMETypes, IsMediaMIMEType)
15 EXPECT_TRUE(IsMediaMIMEType(AUDIO_MP4));
16 EXPECT_TRUE(IsMediaMIMEType(VIDEO_MP4));
17 EXPECT_TRUE(IsMediaMIMEType("application/x-mp4"));
19 EXPECT_TRUE(IsMediaMIMEType("audio/m"));
20 EXPECT_FALSE(IsMediaMIMEType("audio/"));
22 EXPECT_FALSE(IsMediaMIMEType("vide/mp4"));
23 EXPECT_FALSE(IsMediaMIMEType("videos/mp4"));
25 // Expect lowercase only.
26 EXPECT_FALSE(IsMediaMIMEType("Video/mp4"));
29 TEST(StringListRange, MakeStringListRange)
31 static const struct {
32 const char* mList;
33 const char* mExpectedSkipEmpties;
34 const char* mExpectedProcessAll;
35 const char* mExpectedProcessEmpties;
36 } tests[] = {
37 // string skip all empties
38 {"", "", "|", ""},
39 {" ", "", "|", "|"},
40 {",", "", "||", "||"},
41 {" , ", "", "||", "||"},
42 {"a", "a|", "a|", "a|"},
43 {" a ", "a|", "a|", "a|"},
44 {"a,", "a|", "a||", "a||"},
45 {"a, ", "a|", "a||", "a||"},
46 {",a", "a|", "|a|", "|a|"},
47 {" ,a", "a|", "|a|", "|a|"},
48 {"aa,bb", "aa|bb|", "aa|bb|", "aa|bb|"},
49 {" a a , b b ", "a a|b b|", "a a|b b|", "a a|b b|"},
50 {" , ,a 1,, ,b 2,", "a 1|b 2|", "||a 1|||b 2||", "||a 1|||b 2||"}};
52 for (const auto& test : tests) {
53 nsCString list(test.mList);
54 nsCString out;
55 for (const auto& item : MakeStringListRange(list)) {
56 out += item;
57 out += "|";
59 EXPECT_STREQ(test.mExpectedSkipEmpties, out.Data());
60 out.SetLength(0);
62 for (const auto& item :
63 MakeStringListRange<StringListRangeEmptyItems::ProcessAll>(list)) {
64 out += item;
65 out += "|";
67 EXPECT_STREQ(test.mExpectedProcessAll, out.Data());
68 out.SetLength(0);
70 for (const auto& item :
71 MakeStringListRange<StringListRangeEmptyItems::ProcessEmptyItems>(
72 list)) {
73 out += item;
74 out += "|";
76 EXPECT_STREQ(test.mExpectedProcessEmpties, out.Data());
80 TEST(StringListRange, StringListContains)
82 static const struct {
83 const char* mList;
84 const char* mItemToSearch;
85 bool mExpectedSkipEmpties;
86 bool mExpectedProcessAll;
87 bool mExpectedProcessEmpties;
88 } tests[] = {// haystack needle skip all empties
89 {"", "", false, true, false},
90 {" ", "", false, true, true},
91 {"", "a", false, false, false},
92 {" ", "a", false, false, false},
93 {",", "a", false, false, false},
94 {" , ", "", false, true, true},
95 {" , ", "a", false, false, false},
96 {"a", "a", true, true, true},
97 {"a", "b", false, false, false},
98 {" a ", "a", true, true, true},
99 {"aa,bb", "aa", true, true, true},
100 {"aa,bb", "bb", true, true, true},
101 {"aa,bb", "cc", false, false, false},
102 {"aa,bb", " aa ", false, false, false},
103 {" a a , b b ", "a a", true, true, true},
104 {" , ,a 1,, ,b 2,", "a 1", true, true, true},
105 {" , ,a 1,, ,b 2,", "b 2", true, true, true},
106 {" , ,a 1,, ,b 2,", "", false, true, true},
107 {" , ,a 1,, ,b 2,", " ", false, false, false},
108 {" , ,a 1,, ,b 2,", "A 1", false, false, false},
109 {" , ,A 1,, ,b 2,", "a 1", false, false, false}};
111 for (const auto& test : tests) {
112 nsCString list(test.mList);
113 nsCString itemToSearch(test.mItemToSearch);
114 EXPECT_EQ(test.mExpectedSkipEmpties, StringListContains(list, itemToSearch))
115 << "trying to find \"" << itemToSearch.Data() << "\" in \""
116 << list.Data() << "\" (skipping empties)";
117 EXPECT_EQ(test.mExpectedProcessAll,
118 StringListContains<StringListRangeEmptyItems::ProcessAll>(
119 list, itemToSearch))
120 << "trying to find \"" << itemToSearch.Data() << "\" in \""
121 << list.Data() << "\" (processing everything)";
122 EXPECT_EQ(test.mExpectedProcessEmpties,
123 StringListContains<StringListRangeEmptyItems::ProcessEmptyItems>(
124 list, itemToSearch))
125 << "trying to find \"" << itemToSearch.Data() << "\" in \""
126 << list.Data() << "\" (processing empties)";