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
|
// 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 <stddef.h>
#include "base/macros.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);
MediaException entry_2(ContentSettingsPattern::FromString("www.youtube.com"),
CONTENT_SETTING_BLOCK);
MediaException entry_3(ContentSettingsPattern::Wildcard(),
CONTENT_SETTING_ASK);
MediaException entry_4(ContentSettingsPattern(),
CONTENT_SETTING_SESSION_ONLY);
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()));
}
{
MediaException exceptions_1[] = {
MediaException(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_ALLOW),
MediaException(ContentSettingsPattern::FromString("www.youtube.com"),
CONTENT_SETTING_ASK)
};
MediaException exceptions_2[] = {
MediaException(ContentSettingsPattern::FromString("www.google.com"),
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))));
EXPECT_TRUE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ASK,
ConvertAndSort(exceptions_2, arraysize(exceptions_2)),
CONTENT_SETTING_ALLOW,
ConvertAndSort(exceptions_1, arraysize(exceptions_1))));
// 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))));
}
{
// 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),
MediaException(ContentSettingsPattern::FromString("www.google.com"),
CONTENT_SETTING_ALLOW)
};
MediaException exceptions_2[] = {
MediaException(ContentSettingsPattern::FromString("www.google.com"),
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))));
EXPECT_FALSE(PepperFlashContentSettingsUtils::AreMediaExceptionsEqual(
CONTENT_SETTING_ALLOW,
ConvertAndSort(exceptions_1, arraysize(exceptions_1)),
CONTENT_SETTING_ALLOW,
ConvertAndSort(exceptions_2, arraysize(exceptions_2))));
}
}
|