Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: chrome/browser/ui/webui/options/pepper_flash_content_settings_utils_unittest.cc

Issue 440423003: Clean content_settings_pattern_parser.* from unnecessary dependencies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/pepper_flash_content_settings_utils.h" 5 #include "chrome/browser/ui/webui/options/pepper_flash_content_settings_utils.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "chrome/common/chrome_content_settings_client.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 using options::MediaException; 11 using options::MediaException;
11 using options::MediaExceptions; 12 using options::MediaExceptions;
12 using options::PepperFlashContentSettingsUtils; 13 using options::PepperFlashContentSettingsUtils;
13 14
14 namespace { 15 namespace {
15 16
16 MediaExceptions ConvertAndSort(const MediaException* items, size_t count) { 17 MediaExceptions ConvertAndSort(const MediaException* items, size_t count) {
17 MediaExceptions result(items, items + count); 18 MediaExceptions result(items, items + count);
18 PepperFlashContentSettingsUtils::SortMediaExceptions(&result); 19 PepperFlashContentSettingsUtils::SortMediaExceptions(&result);
19 return result; 20 return result;
20 } 21 }
21 22
22 } // namespace 23 } // namespace
23 24
24 TEST(PepperFlashContentSettingsUtilsTest, SortMediaExceptions) { 25 TEST(PepperFlashContentSettingsUtilsTest, SortMediaExceptions) {
25 MediaException entry_1(ContentSettingsPattern::FromString("www.google.com"), 26 content_settings::ChromeContentSettingsClient client;
27 MediaException entry_1(ContentSettingsPattern::FromString(&client,
28 "www.google.com"),
26 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ASK); 29 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ASK);
27 MediaException entry_2(ContentSettingsPattern::FromString("www.youtube.com"), 30 MediaException entry_2(ContentSettingsPattern::FromString(&client,
31 "www.youtube.com"),
28 CONTENT_SETTING_BLOCK, CONTENT_SETTING_DEFAULT); 32 CONTENT_SETTING_BLOCK, CONTENT_SETTING_DEFAULT);
29 MediaException entry_3(ContentSettingsPattern::Wildcard(), 33 MediaException entry_3(ContentSettingsPattern::Wildcard(),
30 CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK); 34 CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK);
31 MediaException entry_4(ContentSettingsPattern(), 35 MediaException entry_4(ContentSettingsPattern(),
32 CONTENT_SETTING_SESSION_ONLY, CONTENT_SETTING_ALLOW); 36 CONTENT_SETTING_SESSION_ONLY, CONTENT_SETTING_ALLOW);
33 37
34 MediaExceptions list_1; 38 MediaExceptions list_1;
35 list_1.push_back(entry_1); 39 list_1.push_back(entry_1);
36 list_1.push_back(entry_2); 40 list_1.push_back(entry_2);
37 list_1.push_back(entry_3); 41 list_1.push_back(entry_3);
(...skipping 30 matching lines...) Expand all
68 // true when they are different. 72 // true when they are different.
69 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( 73 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
70 CONTENT_SETTING_BLOCK, 74 CONTENT_SETTING_BLOCK,
71 MediaExceptions(), 75 MediaExceptions(),
72 CONTENT_SETTING_ASK, 76 CONTENT_SETTING_ASK,
73 MediaExceptions(), 77 MediaExceptions(),
74 false, 78 false,
75 false)); 79 false));
76 } 80 }
77 81
82 content_settings::ChromeContentSettingsClient client;
78 { 83 {
79 MediaException exceptions_1[] = { 84 MediaException exceptions_1[] = {
80 MediaException(ContentSettingsPattern::FromString("www.google.com"), 85 MediaException(ContentSettingsPattern::FromString(&client,
86 "www.google.com"),
81 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW), 87 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW),
82 MediaException(ContentSettingsPattern::FromString("www.youtube.com"), 88 MediaException(ContentSettingsPattern::FromString(&client,
89 "www.youtube.com"),
83 CONTENT_SETTING_ASK, CONTENT_SETTING_ASK) 90 CONTENT_SETTING_ASK, CONTENT_SETTING_ASK)
84 }; 91 };
85 92
86 MediaException exceptions_2[] = { 93 MediaException exceptions_2[] = {
87 MediaException(ContentSettingsPattern::FromString("www.google.com"), 94 MediaException(ContentSettingsPattern::FromString(&client,
95 "www.google.com"),
88 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW) 96 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
89 }; 97 };
90 98
91 // The exception of "www.youtube.com" in |exceptions_1| should not affect 99 // 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|. 100 // the result, because it has the same settings as |default_setting_2|.
93 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( 101 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
94 CONTENT_SETTING_ALLOW, 102 CONTENT_SETTING_ALLOW,
95 ConvertAndSort(exceptions_1, arraysize(exceptions_1)), 103 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
96 CONTENT_SETTING_ASK, 104 CONTENT_SETTING_ASK,
97 ConvertAndSort(exceptions_2, arraysize(exceptions_2)), 105 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
(...skipping 13 matching lines...) Expand all
111 CONTENT_SETTING_ALLOW, 119 CONTENT_SETTING_ALLOW,
112 ConvertAndSort(exceptions_2, arraysize(exceptions_2)), 120 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
113 false, 121 false,
114 false)); 122 false));
115 } 123 }
116 124
117 { 125 {
118 // Similar to the previous block, but reoder the exceptions. The outcome 126 // Similar to the previous block, but reoder the exceptions. The outcome
119 // should be the same. 127 // should be the same.
120 MediaException exceptions_1[] = { 128 MediaException exceptions_1[] = {
121 MediaException(ContentSettingsPattern::FromString("www.youtube.com"), 129 MediaException(ContentSettingsPattern::FromString(&client,
130 "www.youtube.com"),
122 CONTENT_SETTING_ASK, CONTENT_SETTING_ASK), 131 CONTENT_SETTING_ASK, CONTENT_SETTING_ASK),
123 MediaException(ContentSettingsPattern::FromString("www.google.com"), 132 MediaException(ContentSettingsPattern::FromString(&client,
133 "www.google.com"),
124 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW) 134 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
125 }; 135 };
126 136
127 MediaException exceptions_2[] = { 137 MediaException exceptions_2[] = {
128 MediaException(ContentSettingsPattern::FromString("www.google.com"), 138 MediaException(ContentSettingsPattern::FromString(&client,
139 "www.google.com"),
129 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW) 140 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
130 }; 141 };
131 142
132 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( 143 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
133 CONTENT_SETTING_ALLOW, 144 CONTENT_SETTING_ALLOW,
134 ConvertAndSort(exceptions_1, arraysize(exceptions_1)), 145 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
135 CONTENT_SETTING_ASK, 146 CONTENT_SETTING_ASK,
136 ConvertAndSort(exceptions_2, arraysize(exceptions_2)), 147 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
137 false, 148 false,
138 false)); 149 false));
139 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( 150 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
140 CONTENT_SETTING_ALLOW, 151 CONTENT_SETTING_ALLOW,
141 ConvertAndSort(exceptions_1, arraysize(exceptions_1)), 152 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
142 CONTENT_SETTING_ALLOW, 153 CONTENT_SETTING_ALLOW,
143 ConvertAndSort(exceptions_2, arraysize(exceptions_2)), 154 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
144 false, 155 false,
145 false)); 156 false));
146 } 157 }
147 158
148 { 159 {
149 MediaException exceptions_1[] = { 160 MediaException exceptions_1[] = {
150 MediaException(ContentSettingsPattern::FromString("www.google.com"), 161 MediaException(ContentSettingsPattern::FromString(&client,
162 "www.google.com"),
151 CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK) 163 CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK)
152 }; 164 };
153 165
154 MediaException exceptions_2[] = { 166 MediaException exceptions_2[] = {
155 MediaException(ContentSettingsPattern::FromString("www.google.com"), 167 MediaException(ContentSettingsPattern::FromString(&client,
168 "www.google.com"),
156 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW) 169 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
157 }; 170 };
158 171
159 // Test that |ignore_video_setting| works. 172 // Test that |ignore_video_setting| works.
160 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( 173 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
161 CONTENT_SETTING_ASK, 174 CONTENT_SETTING_ASK,
162 ConvertAndSort(exceptions_1, arraysize(exceptions_1)), 175 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
163 CONTENT_SETTING_ASK, 176 CONTENT_SETTING_ASK,
164 ConvertAndSort(exceptions_2, arraysize(exceptions_2)), 177 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
165 false, 178 false,
166 true)); 179 true));
167 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( 180 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
168 CONTENT_SETTING_ASK, 181 CONTENT_SETTING_ASK,
169 ConvertAndSort(exceptions_1, arraysize(exceptions_1)), 182 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
170 CONTENT_SETTING_ASK, 183 CONTENT_SETTING_ASK,
171 ConvertAndSort(exceptions_2, arraysize(exceptions_2)), 184 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
172 false, 185 false,
173 false)); 186 false));
174 } 187 }
175 188
176 { 189 {
177 MediaException exceptions_1[] = { 190 MediaException exceptions_1[] = {
178 MediaException(ContentSettingsPattern::FromString("www.google.com"), 191 MediaException(ContentSettingsPattern::FromString(&client,
192 "www.google.com"),
179 CONTENT_SETTING_BLOCK, CONTENT_SETTING_ALLOW) 193 CONTENT_SETTING_BLOCK, CONTENT_SETTING_ALLOW)
180 }; 194 };
181 195
182 MediaException exceptions_2[] = { 196 MediaException exceptions_2[] = {
183 MediaException(ContentSettingsPattern::FromString("www.google.com"), 197 MediaException(ContentSettingsPattern::FromString(&client,
198 "www.google.com"),
184 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW) 199 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
185 }; 200 };
186 201
187 // Test that |ignore_audio_setting| works. 202 // Test that |ignore_audio_setting| works.
188 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( 203 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
189 CONTENT_SETTING_ASK, 204 CONTENT_SETTING_ASK,
190 ConvertAndSort(exceptions_1, arraysize(exceptions_1)), 205 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
191 CONTENT_SETTING_ASK, 206 CONTENT_SETTING_ASK,
192 ConvertAndSort(exceptions_2, arraysize(exceptions_2)), 207 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
193 true, 208 true,
194 false)); 209 false));
195 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( 210 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
196 CONTENT_SETTING_ASK, 211 CONTENT_SETTING_ASK,
197 ConvertAndSort(exceptions_1, arraysize(exceptions_1)), 212 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
198 CONTENT_SETTING_ASK, 213 CONTENT_SETTING_ASK,
199 ConvertAndSort(exceptions_2, arraysize(exceptions_2)), 214 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
200 false, 215 false,
201 false)); 216 false));
202 } 217 }
203 } 218 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698