1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/options/pepper_flash_content_settings_utils.h"
#include "base/basictypes.h"
#include "testing/gtest/include/gtest/gtest.h"
using options::MediaException;
using options::MediaExceptions;
using options::PepperFlashContentSettingsUtils;
namespace {
MediaExceptions ConvertAndSort(const MediaException* items, size_t count) {
MediaExceptions result(items, items + count);
PepperFlashContentSettingsUtils::SortMediaExceptions(&result);
return result;
}
} // namespace
TEST(PepperFlashContentSettingsUtilsTest, SortMediaExceptions) {
MediaException entry_1(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_ALLOW, CONTENT_SETTING_ASK);
MediaException entry_2(ContentSettingsPattern::FromString("www.youtube.com"),
CONTENT_SETTING_BLOCK, CONTENT_SETTING_DEFAULT);
MediaException entry_3(ContentSettingsPattern::Wildcard(),
CONTENT_SETTING_ASK, CONTENT_SETTING_BLOCK);
MediaException entry_4(ContentSettingsPattern(),
CONTENT_SETTING_SESSION_ONLY, CONTENT_SETTING_ALLOW);
MediaExceptions list_1;
list_1.push_back(entry_1);
list_1.push_back(entry_2);
list_1.push_back(entry_3);
list_1.push_back(entry_4);
MediaExceptions list_2;
list_2.push_back(entry_1);
list_2.push_back(entry_3);
list_2.push_back(entry_2);
list_2.push_back(entry_4);
MediaExceptions list_3;
list_3.push_back(entry_4);
list_3.push_back(entry_1);
list_3.push_back(entry_2);
list_3.push_back(entry_3);
EXPECT_NE(list_1, list_2);
EXPECT_NE(list_2, list_3);
EXPECT_NE(list_3, list_1);
PepperFlashContentSettingsUtils::SortMediaExceptions(&list_1);
PepperFlashContentSettingsUtils::SortMediaExceptions(&list_2);
PepperFlashContentSettingsUtils::SortMediaExceptions(&list_3);
EXPECT_EQ(list_1, list_2);
EXPECT_EQ(list_2, list_3);
}
TEST(PepperFlashContentSettingsUtilsTest, AreMediaExceptionsEqual) {
{
// Empty lists are equal.
// Default settings are not compared directly, so it is possible to return
// true when they are different.
EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_BLOCK,
MediaExceptions(),
CONTENT_SETTING_ASK,
MediaExceptions(),
false,
false));
}
{
MediaException exceptions_1[] = {
MediaException(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW),
MediaException(ContentSettingsPattern::FromString("www.youtube.com"),
CONTENT_SETTING_ASK, CONTENT_SETTING_ASK)
};
MediaException exceptions_2[] = {
MediaException(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
};
// The exception of "www.youtube.com" in |exceptions_1| should not affect
// the result, because it has the same settings as |default_setting_2|.
EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ALLOW,
ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
false,
false));
EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
CONTENT_SETTING_ALLOW,
ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
false,
false));
// Changing |default_setting_2| should change the result.
EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ALLOW,
ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
CONTENT_SETTING_ALLOW,
ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
false,
false));
}
{
// Similar to the previous block, but reoder the exceptions. The outcome
// should be the same.
MediaException exceptions_1[] = {
MediaException(ContentSettingsPattern::FromString("www.youtube.com"),
CONTENT_SETTING_ASK, CONTENT_SETTING_ASK),
MediaException(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
};
MediaException exceptions_2[] = {
MediaException(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
};
EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ALLOW,
ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
false,
false));
EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ALLOW,
ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
CONTENT_SETTING_ALLOW,
ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
false,
false));
}
{
MediaException exceptions_1[] = {
MediaException(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK)
};
MediaException exceptions_2[] = {
MediaException(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
};
// Test that |ignore_video_setting| works.
EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
false,
true));
EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
false,
false));
}
{
MediaException exceptions_1[] = {
MediaException(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_BLOCK, CONTENT_SETTING_ALLOW)
};
MediaException exceptions_2[] = {
MediaException(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_ALLOW, CONTENT_SETTING_ALLOW)
};
// Test that |ignore_audio_setting| works.
EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
true,
false));
EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
false,
false));
}
}
|