Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / pepper_flash_content_settings_utils_unittest.cc
blob4bfcd215f9c362303ed934e9ba4602ba5a6d8485
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.
5 #include "chrome/browser/ui/webui/options/pepper_flash_content_settings_utils.h"
7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 using options::MediaException;
11 using options::MediaExceptions;
12 using options::PepperFlashContentSettingsUtils;
14 namespace {
16 MediaExceptions ConvertAndSort(const MediaException* items, size_t count) {
17 MediaExceptions result(items, items + count);
18 PepperFlashContentSettingsUtils::SortMediaExceptions(&result);
19 return result;
22 } // namespace
24 TEST(PepperFlashContentSettingsUtilsTest, SortMediaExceptions) {
25 MediaException entry_1(ContentSettingsPattern::FromString("www.google.com"),
26 CONTENT_SETTING_ALLOW);
27 MediaException entry_2(ContentSettingsPattern::FromString("www.youtube.com"),
28 CONTENT_SETTING_BLOCK);
29 MediaException entry_3(ContentSettingsPattern::Wildcard(),
30 CONTENT_SETTING_ASK);
31 MediaException entry_4(ContentSettingsPattern(),
32 CONTENT_SETTING_SESSION_ONLY);
34 MediaExceptions list_1;
35 list_1.push_back(entry_1);
36 list_1.push_back(entry_2);
37 list_1.push_back(entry_3);
38 list_1.push_back(entry_4);
40 MediaExceptions list_2;
41 list_2.push_back(entry_1);
42 list_2.push_back(entry_3);
43 list_2.push_back(entry_2);
44 list_2.push_back(entry_4);
46 MediaExceptions list_3;
47 list_3.push_back(entry_4);
48 list_3.push_back(entry_1);
49 list_3.push_back(entry_2);
50 list_3.push_back(entry_3);
52 EXPECT_NE(list_1, list_2);
53 EXPECT_NE(list_2, list_3);
54 EXPECT_NE(list_3, list_1);
56 PepperFlashContentSettingsUtils::SortMediaExceptions(&list_1);
57 PepperFlashContentSettingsUtils::SortMediaExceptions(&list_2);
58 PepperFlashContentSettingsUtils::SortMediaExceptions(&list_3);
60 EXPECT_EQ(list_1, list_2);
61 EXPECT_EQ(list_2, list_3);
64 TEST(PepperFlashContentSettingsUtilsTest, AreMediaExceptionsEqual) {
66 // Empty lists are equal.
67 // Default settings are not compared directly, so it is possible to return
68 // true when they are different.
69 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
70 CONTENT_SETTING_BLOCK,
71 MediaExceptions(),
72 CONTENT_SETTING_ASK,
73 MediaExceptions()));
77 MediaException exceptions_1[] = {
78 MediaException(ContentSettingsPattern::FromString("www.google.com"),
79 CONTENT_SETTING_ALLOW),
80 MediaException(ContentSettingsPattern::FromString("www.youtube.com"),
81 CONTENT_SETTING_ASK)
84 MediaException exceptions_2[] = {
85 MediaException(ContentSettingsPattern::FromString("www.google.com"),
86 CONTENT_SETTING_ALLOW)
89 // The exception of "www.youtube.com" in |exceptions_1| should not affect
90 // the result, because it has the same settings as |default_setting_2|.
91 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
92 CONTENT_SETTING_ALLOW,
93 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
94 CONTENT_SETTING_ASK,
95 ConvertAndSort(exceptions_2, arraysize(exceptions_2))));
96 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
97 CONTENT_SETTING_ASK,
98 ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
99 CONTENT_SETTING_ALLOW,
100 ConvertAndSort(exceptions_1, arraysize(exceptions_1))));
101 // Changing |default_setting_2| should change the result.
102 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
103 CONTENT_SETTING_ALLOW,
104 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
105 CONTENT_SETTING_ALLOW,
106 ConvertAndSort(exceptions_2, arraysize(exceptions_2))));
110 // Similar to the previous block, but reoder the exceptions. The outcome
111 // should be the same.
112 MediaException exceptions_1[] = {
113 MediaException(ContentSettingsPattern::FromString("www.youtube.com"),
114 CONTENT_SETTING_ASK),
115 MediaException(ContentSettingsPattern::FromString("www.google.com"),
116 CONTENT_SETTING_ALLOW)
119 MediaException exceptions_2[] = {
120 MediaException(ContentSettingsPattern::FromString("www.google.com"),
121 CONTENT_SETTING_ALLOW)
124 EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
125 CONTENT_SETTING_ALLOW,
126 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
127 CONTENT_SETTING_ASK,
128 ConvertAndSort(exceptions_2, arraysize(exceptions_2))));
129 EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
130 CONTENT_SETTING_ALLOW,
131 ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
132 CONTENT_SETTING_ALLOW,
133 ConvertAndSort(exceptions_2, arraysize(exceptions_2))));