This source file includes following definitions.
- ConvertAndSort
- TEST
- TEST
#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;
}
}
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) {
{
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)
};
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));
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.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)
};
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)
};
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));
}
}