-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
supervised_user_error_page_unittest.cc
267 lines (250 loc) · 12.2 KB
/
supervised_user_error_page_unittest.cc
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/supervised_user/core/browser/supervised_user_error_page.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "components/grit/components_resources.h"
#include "components/strings/grit/components_strings.h"
#include "components/supervised_user/core/common/features.h"
#include "components/supervised_user/core/common/supervised_user_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest-param-test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
namespace supervised_user {
struct BlockMessageIDTestParameter {
FilteringBehaviorReason reason;
bool single_parent;
int expected_result;
};
class SupervisedUserErrorPageTest_GetBlockMessageID
: public ::testing::TestWithParam<BlockMessageIDTestParameter> {};
TEST_P(SupervisedUserErrorPageTest_GetBlockMessageID, GetBlockMessageID) {
BlockMessageIDTestParameter param = GetParam();
EXPECT_EQ(param.expected_result,
GetBlockMessageID(param.reason, param.single_parent))
<< "reason = " << FilteringBehaviorReasonToString(param.reason)
<< " single parent = " << param.single_parent;
}
BlockMessageIDTestParameter block_message_id_test_params[] = {
{FilteringBehaviorReason::DEFAULT, true,
IDS_CHILD_BLOCK_MESSAGE_DEFAULT_SINGLE_PARENT},
{FilteringBehaviorReason::DEFAULT, false,
IDS_CHILD_BLOCK_MESSAGE_DEFAULT_MULTI_PARENT},
// SafeSites is not enabled for supervised users.
{FilteringBehaviorReason::ASYNC_CHECKER, true,
IDS_SUPERVISED_USER_BLOCK_MESSAGE_SAFE_SITES},
{FilteringBehaviorReason::ASYNC_CHECKER, false,
IDS_SUPERVISED_USER_BLOCK_MESSAGE_SAFE_SITES},
{FilteringBehaviorReason::MANUAL, true,
IDS_CHILD_BLOCK_MESSAGE_MANUAL_SINGLE_PARENT},
{FilteringBehaviorReason::MANUAL, false,
IDS_CHILD_BLOCK_MESSAGE_MANUAL_MULTI_PARENT},
};
INSTANTIATE_TEST_SUITE_P(GetBlockMessageIDParameterized,
SupervisedUserErrorPageTest_GetBlockMessageID,
::testing::ValuesIn(block_message_id_test_params));
struct BuildHtmlTestParameter {
bool allow_access_requests;
const std::string& profile_image_url;
const std::string& profile_image_url2;
const std::string& custodian;
const std::string& custodian_email;
const std::string& second_custodian;
const std::string& second_custodian_email;
FilteringBehaviorReason reason;
bool has_two_parents;
bool is_web_filter_interstitial_refresh_enabled;
};
class SupervisedUserErrorPageTest_BuildHtml
: public ::testing::TestWithParam<BuildHtmlTestParameter> {};
TEST_P(SupervisedUserErrorPageTest_BuildHtml, BuildHtml) {
BuildHtmlTestParameter param = GetParam();
base::test::ScopedFeatureList scoped_feature_list_;
if (param.is_web_filter_interstitial_refresh_enabled) {
scoped_feature_list_.InitWithFeatures(
/* enabled_features */ {supervised_user::kWebFilterInterstitialRefresh,
supervised_user::kLocalWebApprovals},
/* disabled_features */ {});
} else {
scoped_feature_list_.InitWithFeatures(
/* enabled_features */ {},
/* disabled_features */ {supervised_user::kWebFilterInterstitialRefresh,
supervised_user::kLocalWebApprovals});
}
std::string result = BuildErrorPageHtml(
param.allow_access_requests, param.profile_image_url,
param.profile_image_url2, param.custodian, param.custodian_email,
param.second_custodian, param.second_custodian_email, param.reason,
/*app_locale=*/"",
/*already_sent_request=*/false, /*is_main_frame=*/true,
/*show_banner=*/true);
// The result should contain the original HTML (with $i18n{} replacements)
// plus scripts that plug values into it. The test can't easily check that the
// scripts are correct, but can check that the output contains the expected
// values.
EXPECT_THAT(result, testing::HasSubstr(param.profile_image_url));
EXPECT_THAT(result, testing::HasSubstr(param.profile_image_url2));
EXPECT_THAT(result, testing::HasSubstr(param.custodian));
EXPECT_THAT(result, testing::HasSubstr(param.custodian_email));
if (param.has_two_parents) {
EXPECT_THAT(result, testing::HasSubstr(param.second_custodian));
EXPECT_THAT(result, testing::HasSubstr(param.second_custodian_email));
}
if (param.reason == FilteringBehaviorReason::ASYNC_CHECKER) {
EXPECT_THAT(result, testing::HasSubstr("\"showFeedbackLink\":true"));
} else {
EXPECT_THAT(result, testing::HasSubstr("\"showFeedbackLink\":false"));
}
// Messages containing parameters aren't tested since they get modified before
// they are added to the result.
if (param.allow_access_requests) {
EXPECT_THAT(result, testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_HEADER)));
if (param.is_web_filter_interstitial_refresh_enabled) {
EXPECT_THAT(result, testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE_V2)));
// Ensure that HTML contains a block message that is specific to the
// number of parents who can approve and the reason that the site is
// blocked. DEFAULT indicates that the parent(s) required the child
// request permission for all sites, and MANUAL indicates that the
// parent(s) specifically blocked this site.
if (param.reason == FilteringBehaviorReason::DEFAULT) {
if (param.has_two_parents) {
EXPECT_THAT(result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_MESSAGE_DEFAULT_MULTI_PARENT)));
} else {
EXPECT_THAT(result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_MESSAGE_DEFAULT_SINGLE_PARENT)));
}
}
if (param.reason == FilteringBehaviorReason::MANUAL) {
if (param.has_two_parents) {
EXPECT_THAT(result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_MESSAGE_MANUAL_MULTI_PARENT)));
} else {
EXPECT_THAT(result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_MESSAGE_MANUAL_SINGLE_PARENT)));
}
}
} else {
EXPECT_THAT(result, testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE)));
}
EXPECT_THAT(result,
testing::Not(testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_BLOCK_INTERSTITIAL_HEADER_ACCESS_REQUESTS_DISABLED))));
// This string is used for a button that is always present in the DOM, but
// only visible when local web approvals is enabled.
EXPECT_THAT(result, testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_BLOCK_INTERSTITIAL_ASK_IN_PERSON_BUTTON)));
if (param.is_web_filter_interstitial_refresh_enabled) {
EXPECT_THAT(result, testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_BLOCK_INTERSTITIAL_ASK_IN_A_MESSAGE_BUTTON)));
EXPECT_THAT(result, testing::HasSubstr(
l10n_util::GetStringUTF8(IDS_REQUEST_SENT_OK)));
} else {
EXPECT_THAT(result, testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_BLOCK_INTERSTITIAL_REQUEST_ACCESS_BUTTON)));
EXPECT_THAT(result, testing::HasSubstr(
l10n_util::GetStringUTF8(IDS_BACK_BUTTON)));
}
} else {
EXPECT_THAT(result,
testing::Not(testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_HEADER))));
EXPECT_THAT(result,
testing::Not(testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_MESSAGE))));
EXPECT_THAT(result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_BLOCK_INTERSTITIAL_HEADER_ACCESS_REQUESTS_DISABLED)));
}
if (param.is_web_filter_interstitial_refresh_enabled) {
EXPECT_THAT(result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_WAITING_APPROVAL_MESSAGE)));
if (param.has_two_parents) {
EXPECT_THAT(
result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_WAITING_APPROVAL_DESCRIPTION_MULTI_PARENT)));
} else {
EXPECT_THAT(
result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_WAITING_APPROVAL_DESCRIPTION_SINGLE_PARENT)));
}
} else if (param.has_two_parents) {
EXPECT_THAT(
result,
testing::Not(testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT))));
EXPECT_THAT(
result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT)));
EXPECT_THAT(
result,
testing::Not(testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT))));
EXPECT_THAT(
result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT)));
} else {
EXPECT_THAT(
result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_SINGLE_PARENT)));
EXPECT_THAT(
result,
testing::Not(testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_SENT_MESSAGE_MULTI_PARENT))));
EXPECT_THAT(
result,
testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_SINGLE_PARENT)));
EXPECT_THAT(
result,
testing::Not(testing::HasSubstr(l10n_util::GetStringUTF8(
IDS_CHILD_BLOCK_INTERSTITIAL_REQUEST_FAILED_MESSAGE_MULTI_PARENT))));
}
}
BuildHtmlTestParameter build_html_test_parameter[] = {
{true, "url1", "url2", "custodian", "custodian_email", "", "",
FilteringBehaviorReason::DEFAULT, false, false},
{true, "url1", "url2", "custodian", "custodian_email", "custodian2",
"custodian2_email", FilteringBehaviorReason::DEFAULT, true, false},
{false, "url1", "url2", "custodian", "custodian_email", "custodian2",
"custodian2_email", FilteringBehaviorReason::DEFAULT, true, false},
{false, "url1", "url2", "custodian", "custodian_email", "custodian2",
"custodian2_email", FilteringBehaviorReason::DEFAULT, true, false},
{true, "url1", "url2", "custodian", "custodian_email", "custodian2",
"custodian2_email", FilteringBehaviorReason::DEFAULT, true, false},
{true, "url1", "url2", "custodian", "custodian_email", "custodian2",
"custodian2_email", FilteringBehaviorReason::ASYNC_CHECKER, true, false},
// Test cases with local web approvals feature enabled
{true, "url1", "url2", "custodian", "custodian_email", "", "",
FilteringBehaviorReason::DEFAULT, false, true},
{true, "url1", "url2", "custodian", "custodian_email", "custodian2",
"custodian2_email", FilteringBehaviorReason::DEFAULT, true, true},
{false, "url1", "url2", "custodian", "custodian_email", "custodian2",
"custodian2_email", FilteringBehaviorReason::DEFAULT, true, true},
{false, "url1", "url2", "custodian", "custodian_email", "custodian2",
"custodian2_email", FilteringBehaviorReason::DEFAULT, true, true},
{true, "url1", "url2", "custodian", "custodian_email", "custodian2",
"custodian2_email", FilteringBehaviorReason::DEFAULT, true, true},
{true, "url1", "url2", "custodian", "custodian_email", "custodian2",
"custodian2_email", FilteringBehaviorReason::ASYNC_CHECKER, true, true},
};
INSTANTIATE_TEST_SUITE_P(GetBlockMessageIDParameterized,
SupervisedUserErrorPageTest_BuildHtml,
::testing::ValuesIn(build_html_test_parameter));
} // namespace supervised_user