| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/options/pepper_flash_content_settings_utils.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 | |
| 9 #include "base/macros.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 using options::MediaException; | |
| 13 using options::MediaExceptions; | |
| 14 using options::PepperFlashContentSettingsUtils; | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 MediaExceptions ConvertAndSort(const MediaException* items, size_t count) { | |
| 19 MediaExceptions result(items, items + count); | |
| 20 PepperFlashContentSettingsUtils::SortMediaExceptions(&result); | |
| 21 return result; | |
| 22 } | |
| 23 | |
| 24 } // namespace | |
| 25 | |
| 26 TEST(PepperFlashContentSettingsUtilsTest, SortMediaExceptions) { | |
| 27 MediaException entry_1(ContentSettingsPattern::FromString("www.google.com"), | |
| 28 CONTENT_SETTING_ALLOW); | |
| 29 MediaException entry_2(ContentSettingsPattern::FromString("www.youtube.com"), | |
| 30 CONTENT_SETTING_BLOCK); | |
| 31 MediaException entry_3(ContentSettingsPattern::Wildcard(), | |
| 32 CONTENT_SETTING_ASK); | |
| 33 MediaException entry_4(ContentSettingsPattern(), | |
| 34 CONTENT_SETTING_SESSION_ONLY); | |
| 35 | |
| 36 MediaExceptions list_1; | |
| 37 list_1.push_back(entry_1); | |
| 38 list_1.push_back(entry_2); | |
| 39 list_1.push_back(entry_3); | |
| 40 list_1.push_back(entry_4); | |
| 41 | |
| 42 MediaExceptions list_2; | |
| 43 list_2.push_back(entry_1); | |
| 44 list_2.push_back(entry_3); | |
| 45 list_2.push_back(entry_2); | |
| 46 list_2.push_back(entry_4); | |
| 47 | |
| 48 MediaExceptions list_3; | |
| 49 list_3.push_back(entry_4); | |
| 50 list_3.push_back(entry_1); | |
| 51 list_3.push_back(entry_2); | |
| 52 list_3.push_back(entry_3); | |
| 53 | |
| 54 EXPECT_NE(list_1, list_2); | |
| 55 EXPECT_NE(list_2, list_3); | |
| 56 EXPECT_NE(list_3, list_1); | |
| 57 | |
| 58 PepperFlashContentSettingsUtils::SortMediaExceptions(&list_1); | |
| 59 PepperFlashContentSettingsUtils::SortMediaExceptions(&list_2); | |
| 60 PepperFlashContentSettingsUtils::SortMediaExceptions(&list_3); | |
| 61 | |
| 62 EXPECT_EQ(list_1, list_2); | |
| 63 EXPECT_EQ(list_2, list_3); | |
| 64 } | |
| 65 | |
| 66 TEST(PepperFlashContentSettingsUtilsTest, AreMediaExceptionsEqual) { | |
| 67 { | |
| 68 // Empty lists are equal. | |
| 69 // Default settings are not compared directly, so it is possible to return | |
| 70 // true when they are different. | |
| 71 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( | |
| 72 CONTENT_SETTING_BLOCK, | |
| 73 MediaExceptions(), | |
| 74 CONTENT_SETTING_ASK, | |
| 75 MediaExceptions())); | |
| 76 } | |
| 77 | |
| 78 { | |
| 79 MediaException exceptions_1[] = { | |
| 80 MediaException(ContentSettingsPattern::FromString("www.google.com"), | |
| 81 CONTENT_SETTING_ALLOW), | |
| 82 MediaException(ContentSettingsPattern::FromString("www.youtube.com"), | |
| 83 CONTENT_SETTING_ASK) | |
| 84 }; | |
| 85 | |
| 86 MediaException exceptions_2[] = { | |
| 87 MediaException(ContentSettingsPattern::FromString("www.google.com"), | |
| 88 CONTENT_SETTING_ALLOW) | |
| 89 }; | |
| 90 | |
| 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)), | |
| 96 CONTENT_SETTING_ASK, | |
| 97 ConvertAndSort(exceptions_2, arraysize(exceptions_2)))); | |
| 98 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( | |
| 99 CONTENT_SETTING_ASK, | |
| 100 ConvertAndSort(exceptions_2, arraysize(exceptions_2)), | |
| 101 CONTENT_SETTING_ALLOW, | |
| 102 ConvertAndSort(exceptions_1, arraysize(exceptions_1)))); | |
| 103 // Changing |default_setting_2| should change the result. | |
| 104 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( | |
| 105 CONTENT_SETTING_ALLOW, | |
| 106 ConvertAndSort(exceptions_1, arraysize(exceptions_1)), | |
| 107 CONTENT_SETTING_ALLOW, | |
| 108 ConvertAndSort(exceptions_2, arraysize(exceptions_2)))); | |
| 109 } | |
| 110 | |
| 111 { | |
| 112 // Similar to the previous block, but reoder the exceptions. The outcome | |
| 113 // should be the same. | |
| 114 MediaException exceptions_1[] = { | |
| 115 MediaException(ContentSettingsPattern::FromString("www.youtube.com"), | |
| 116 CONTENT_SETTING_ASK), | |
| 117 MediaException(ContentSettingsPattern::FromString("www.google.com"), | |
| 118 CONTENT_SETTING_ALLOW) | |
| 119 }; | |
| 120 | |
| 121 MediaException exceptions_2[] = { | |
| 122 MediaException(ContentSettingsPattern::FromString("www.google.com"), | |
| 123 CONTENT_SETTING_ALLOW) | |
| 124 }; | |
| 125 | |
| 126 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( | |
| 127 CONTENT_SETTING_ALLOW, | |
| 128 ConvertAndSort(exceptions_1, arraysize(exceptions_1)), | |
| 129 CONTENT_SETTING_ASK, | |
| 130 ConvertAndSort(exceptions_2, arraysize(exceptions_2)))); | |
| 131 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual( | |
| 132 CONTENT_SETTING_ALLOW, | |
| 133 ConvertAndSort(exceptions_1, arraysize(exceptions_1)), | |
| 134 CONTENT_SETTING_ALLOW, | |
| 135 ConvertAndSort(exceptions_2, arraysize(exceptions_2)))); | |
| 136 } | |
| 137 } | |
| OLD | NEW |