Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / pepper_flash_content_settings_utils_unittest.cc
blob8ca94f370bb58a9e60fa61ecfbb115365ff9cea1
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;
14 namespace {
16 MediaExceptions ConvertAndSort(const MediaException* items, size_t count) {
17 MediaExceptions result(items, items + count);
18 PepperFlashContentSettingsUtils::SortMediaExceptions(&result);
19 return result;
22 } // namespace
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,
71 CONTENT_SETTING_ASK,
72 MediaExceptions(),
73 CONTENT_SETTING_BLOCK,
74 CONTENT_SETTING_ASK,
75 MediaExceptions(),
76 false,
77 false));
81 MediaException exceptions_1[] = {
82 MediaException(ContentSettingsPattern::FromString("www.google.com"),
83 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW),
84 MediaException(ContentSettingsPattern::FromString("www.youtube.com"),
85 CONTENT_SETTING_ASK, CONTENT_SETTING_ASK)
88 MediaException exceptions_2[] = {
89 MediaException(ContentSettingsPattern::FromString("www.google.com"),
90 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
93 // The exception of "www.youtube.com" in |exceptions_1| should not affect
94 // the result, because it has the same settings as |default_setting_2|.
95 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
96 CONTENT_SETTING_ALLOW,
97 CONTENT_SETTING_ALLOW,
98 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
99 CONTENT_SETTING_ASK,
100 CONTENT_SETTING_ASK,
101 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
102 false,
103 false));
104 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
105 CONTENT_SETTING_ASK,
106 CONTENT_SETTING_ASK,
107 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
108 CONTENT_SETTING_ALLOW,
109 CONTENT_SETTING_ALLOW,
110 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
111 false,
112 false));
113 // Changing |default_setting_2| should change the result.
114 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
115 CONTENT_SETTING_ALLOW,
116 CONTENT_SETTING_ALLOW,
117 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
118 CONTENT_SETTING_ALLOW,
119 CONTENT_SETTING_ALLOW,
120 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
121 false,
122 false));
126 // Similar to the previous block, but reoder the exceptions. The outcome
127 // should be the same.
128 MediaException exceptions_1[] = {
129 MediaException(ContentSettingsPattern::FromString("www.youtube.com"),
130 CONTENT_SETTING_ASK, CONTENT_SETTING_ASK),
131 MediaException(ContentSettingsPattern::FromString("www.google.com"),
132 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
135 MediaException exceptions_2[] = {
136 MediaException(ContentSettingsPattern::FromString("www.google.com"),
137 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
140 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
141 CONTENT_SETTING_ALLOW,
142 CONTENT_SETTING_ALLOW,
143 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
144 CONTENT_SETTING_ASK,
145 CONTENT_SETTING_ASK,
146 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
147 false,
148 false));
149 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
150 CONTENT_SETTING_ALLOW,
151 CONTENT_SETTING_ALLOW,
152 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
153 CONTENT_SETTING_ALLOW,
154 CONTENT_SETTING_ALLOW,
155 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
156 false,
157 false));
161 MediaException exceptions_1[] = {
162 MediaException(ContentSettingsPattern::FromString("www.google.com"),
163 CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK)
166 MediaException exceptions_2[] = {
167 MediaException(ContentSettingsPattern::FromString("www.google.com"),
168 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
171 // Test that |ignore_video_setting| works.
172 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
173 CONTENT_SETTING_ASK,
174 CONTENT_SETTING_ASK,
175 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
176 CONTENT_SETTING_ASK,
177 CONTENT_SETTING_BLOCK,
178 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
179 false,
180 true));
181 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
182 CONTENT_SETTING_ASK,
183 CONTENT_SETTING_ASK,
184 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
185 CONTENT_SETTING_ASK,
186 CONTENT_SETTING_ASK,
187 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
188 false,
189 false));
193 MediaException exceptions_1[] = {
194 MediaException(ContentSettingsPattern::FromString("www.google.com"),
195 CONTENT_SETTING_BLOCK, CONTENT_SETTING_ALLOW)
198 MediaException exceptions_2[] = {
199 MediaException(ContentSettingsPattern::FromString("www.google.com"),
200 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
203 // Test that |ignore_audio_setting| works.
204 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
205 CONTENT_SETTING_BLOCK,
206 CONTENT_SETTING_ASK,
207 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
208 CONTENT_SETTING_ASK,
209 CONTENT_SETTING_ASK,
210 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
211 true,
212 false));
213 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
214 CONTENT_SETTING_ASK,
215 CONTENT_SETTING_ASK,
216 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
217 CONTENT_SETTING_ASK,
218 CONTENT_SETTING_ASK,
219 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
220 false,
221 false));