1 // Copyright (c) 2012 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.
5 #include "chrome/browser/ui/webui/options/pepper_flash_content_settings_utils.h"
7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using options::MediaException
;
11 using options::MediaExceptions
;
12 using options::PepperFlashContentSettingsUtils
;
16 MediaExceptions
ConvertAndSort(const MediaException
* items
, size_t count
) {
17 MediaExceptions
result(items
, items
+ count
);
18 PepperFlashContentSettingsUtils::SortMediaExceptions(&result
);
24 TEST(PepperFlashContentSettingsUtilsTest
, SortMediaExceptions
) {
25 MediaException
entry_1(ContentSettingsPattern::FromString("www.google.com"),
26 CONTENT_SETTING_ALLOW
, CONTENT_SETTING_ASK
);
27 MediaException
entry_2(ContentSettingsPattern::FromString("www.youtube.com"),
28 CONTENT_SETTING_BLOCK
, CONTENT_SETTING_DEFAULT
);
29 MediaException
entry_3(ContentSettingsPattern::Wildcard(),
30 CONTENT_SETTING_ASK
, CONTENT_SETTING_BLOCK
);
31 MediaException
entry_4(ContentSettingsPattern(),
32 CONTENT_SETTING_SESSION_ONLY
, CONTENT_SETTING_ALLOW
);
34 MediaExceptions list_1
;
35 list_1
.push_back(entry_1
);
36 list_1
.push_back(entry_2
);
37 list_1
.push_back(entry_3
);
38 list_1
.push_back(entry_4
);
40 MediaExceptions list_2
;
41 list_2
.push_back(entry_1
);
42 list_2
.push_back(entry_3
);
43 list_2
.push_back(entry_2
);
44 list_2
.push_back(entry_4
);
46 MediaExceptions list_3
;
47 list_3
.push_back(entry_4
);
48 list_3
.push_back(entry_1
);
49 list_3
.push_back(entry_2
);
50 list_3
.push_back(entry_3
);
52 EXPECT_NE(list_1
, list_2
);
53 EXPECT_NE(list_2
, list_3
);
54 EXPECT_NE(list_3
, list_1
);
56 PepperFlashContentSettingsUtils::SortMediaExceptions(&list_1
);
57 PepperFlashContentSettingsUtils::SortMediaExceptions(&list_2
);
58 PepperFlashContentSettingsUtils::SortMediaExceptions(&list_3
);
60 EXPECT_EQ(list_1
, list_2
);
61 EXPECT_EQ(list_2
, list_3
);
64 TEST(PepperFlashContentSettingsUtilsTest
, AreMediaExceptionsEqual
) {
66 // Empty lists are equal.
67 // Default settings are not compared directly, so it is possible to return
68 // true when they are different.
69 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
70 CONTENT_SETTING_BLOCK
,
79 MediaException exceptions_1
[] = {
80 MediaException(ContentSettingsPattern::FromString("www.google.com"),
81 CONTENT_SETTING_ALLOW
, CONTENT_SETTING_ALLOW
),
82 MediaException(ContentSettingsPattern::FromString("www.youtube.com"),
83 CONTENT_SETTING_ASK
, CONTENT_SETTING_ASK
)
86 MediaException exceptions_2
[] = {
87 MediaException(ContentSettingsPattern::FromString("www.google.com"),
88 CONTENT_SETTING_ALLOW
, CONTENT_SETTING_ALLOW
)
91 // The exception of "www.youtube.com" in |exceptions_1| should not affect
92 // the result, because it has the same settings as |default_setting_2|.
93 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
94 CONTENT_SETTING_ALLOW
,
95 ConvertAndSort(exceptions_1
, arraysize(exceptions_1
)),
97 ConvertAndSort(exceptions_2
, arraysize(exceptions_2
)),
100 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
102 ConvertAndSort(exceptions_2
, arraysize(exceptions_2
)),
103 CONTENT_SETTING_ALLOW
,
104 ConvertAndSort(exceptions_1
, arraysize(exceptions_1
)),
107 // Changing |default_setting_2| should change the result.
108 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
109 CONTENT_SETTING_ALLOW
,
110 ConvertAndSort(exceptions_1
, arraysize(exceptions_1
)),
111 CONTENT_SETTING_ALLOW
,
112 ConvertAndSort(exceptions_2
, arraysize(exceptions_2
)),
118 // Similar to the previous block, but reoder the exceptions. The outcome
119 // should be the same.
120 MediaException exceptions_1
[] = {
121 MediaException(ContentSettingsPattern::FromString("www.youtube.com"),
122 CONTENT_SETTING_ASK
, CONTENT_SETTING_ASK
),
123 MediaException(ContentSettingsPattern::FromString("www.google.com"),
124 CONTENT_SETTING_ALLOW
, CONTENT_SETTING_ALLOW
)
127 MediaException exceptions_2
[] = {
128 MediaException(ContentSettingsPattern::FromString("www.google.com"),
129 CONTENT_SETTING_ALLOW
, CONTENT_SETTING_ALLOW
)
132 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
133 CONTENT_SETTING_ALLOW
,
134 ConvertAndSort(exceptions_1
, arraysize(exceptions_1
)),
136 ConvertAndSort(exceptions_2
, arraysize(exceptions_2
)),
139 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
140 CONTENT_SETTING_ALLOW
,
141 ConvertAndSort(exceptions_1
, arraysize(exceptions_1
)),
142 CONTENT_SETTING_ALLOW
,
143 ConvertAndSort(exceptions_2
, arraysize(exceptions_2
)),
149 MediaException exceptions_1
[] = {
150 MediaException(ContentSettingsPattern::FromString("www.google.com"),
151 CONTENT_SETTING_ALLOW
, CONTENT_SETTING_BLOCK
)
154 MediaException exceptions_2
[] = {
155 MediaException(ContentSettingsPattern::FromString("www.google.com"),
156 CONTENT_SETTING_ALLOW
, CONTENT_SETTING_ALLOW
)
159 // Test that |ignore_video_setting| works.
160 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
162 ConvertAndSort(exceptions_1
, arraysize(exceptions_1
)),
164 ConvertAndSort(exceptions_2
, arraysize(exceptions_2
)),
167 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
169 ConvertAndSort(exceptions_1
, arraysize(exceptions_1
)),
171 ConvertAndSort(exceptions_2
, arraysize(exceptions_2
)),
177 MediaException exceptions_1
[] = {
178 MediaException(ContentSettingsPattern::FromString("www.google.com"),
179 CONTENT_SETTING_BLOCK
, CONTENT_SETTING_ALLOW
)
182 MediaException exceptions_2
[] = {
183 MediaException(ContentSettingsPattern::FromString("www.google.com"),
184 CONTENT_SETTING_ALLOW
, CONTENT_SETTING_ALLOW
)
187 // Test that |ignore_audio_setting| works.
188 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
190 ConvertAndSort(exceptions_1
, arraysize(exceptions_1
)),
192 ConvertAndSort(exceptions_2
, arraysize(exceptions_2
)),
195 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
197 ConvertAndSort(exceptions_1
, arraysize(exceptions_1
)),
199 ConvertAndSort(exceptions_2
, arraysize(exceptions_2
)),