| OLD | NEW |
| 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 "extensions/common/constants.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 MediaException entry_1( |
| 26 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ASK); | 27 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 27 MediaException entry_2(ContentSettingsPattern::FromString("www.youtube.com"), | 28 "www.google.com"), |
| 28 CONTENT_SETTING_BLOCK, CONTENT_SETTING_DEFAULT); | 29 CONTENT_SETTING_ALLOW, CONTENT_SETTING_ASK); |
| 30 MediaException entry_2( |
| 31 ContentSettingsPattern::FromString(extensions::kExtensionScheme, |
| 32 "www.youtube.com"), |
| 33 CONTENT_SETTING_BLOCK, CONTENT_SETTING_DEFAULT); |
| 29 MediaException entry_3(ContentSettingsPattern::Wildcard(), | 34 MediaException entry_3(ContentSettingsPattern::Wildcard(), |
| 30 CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK); | 35 CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK); |
| 31 MediaException entry_4(ContentSettingsPattern(), | 36 MediaException entry_4(ContentSettingsPattern(), |
| 32 CONTENT_SETTING_SESSION_ONLY, CONTENT_SETTING_ALLOW); | 37 CONTENT_SETTING_SESSION_ONLY, CONTENT_SETTING_ALLOW); |
| 33 | 38 |
| 34 MediaExceptions list_1; | 39 MediaExceptions list_1; |
| 35 list_1.push_back(entry_1); | 40 list_1.push_back(entry_1); |
| 36 list_1.push_back(entry_2); | 41 list_1.push_back(entry_2); |
| 37 list_1.push_back(entry_3); | 42 list_1.push_back(entry_3); |
| 38 list_1.push_back(entry_4); | 43 list_1.push_back(entry_4); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 CONTENT_SETTING_BLOCK, | 75 CONTENT_SETTING_BLOCK, |
| 71 MediaExceptions(), | 76 MediaExceptions(), |
| 72 CONTENT_SETTING_ASK, | 77 CONTENT_SETTING_ASK, |
| 73 MediaExceptions(), | 78 MediaExceptions(), |
| 74 false, | 79 false, |
| 75 false)); | 80 false)); |
| 76 } | 81 } |
| 77 | 82 |
| 78 { | 83 { |
| 79 MediaException exceptions_1[] = { | 84 MediaException exceptions_1[] = { |
| 80 MediaException(ContentSettingsPattern::FromString("www.google.com"), | 85 MediaException(ContentSettingsPattern::FromString( |
| 86 extensions::kExtensionScheme, "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( |
| 89 extensions::kExtensionScheme, "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( |
| 95 extensions::kExtensionScheme, "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 Loading... |
| 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( |
| 130 extensions::kExtensionScheme, "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( |
| 133 extensions::kExtensionScheme, "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( |
| 139 extensions::kExtensionScheme, "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( |
| 162 extensions::kExtensionScheme, "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( |
| 168 extensions::kExtensionScheme, "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( |
| 192 extensions::kExtensionScheme, "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( |
| 198 extensions::kExtensionScheme, "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 } |
| OLD | NEW |