blob: 5d48882a0a5ab89c5680c3cbb8723ab9d1131157 [file] [log] [blame]
Matt Reynolds1914ff6b2022-02-04 08:48:261// Copyright 2022 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.
4
5#include "chrome/browser/policy/webhid_device_policy_handler.h"
6
7#include <memory>
8#include <utility>
9
10#include "base/json/json_reader.h"
11#include "base/strings/string_util.h"
12#include "chrome/common/pref_names.h"
13#include "components/policy/core/browser/configuration_policy_pref_store.h"
14#include "components/policy/core/browser/configuration_policy_pref_store_test.h"
15#include "components/policy/core/browser/policy_error_map.h"
16#include "components/policy/core/common/policy_map.h"
17#include "components/policy/core/common/policy_types.h"
18#include "components/policy/core/common/schema.h"
19#include "components/policy/policy_constants.h"
20
21namespace policy {
22
23namespace {
24
25using ::testing::WithParamInterface;
26
27constexpr char kDevicesKey[] = "devices";
28constexpr char kUsagesKey[] = "usages";
29constexpr char kUrlsKey[] = "urls";
30constexpr char kVendorIdKey[] = "vendor_id";
31constexpr char kProductIdKey[] = "product_id";
32constexpr char kUsagePageKey[] = "usage_page";
33constexpr char kUsageKey[] = "usage";
34
35absl::optional<base::Value> ReadJson(base::StringPiece json) {
36 auto result = base::JSONReader::ReadAndReturnValueWithError(json);
37 EXPECT_TRUE(result.value) << result.error_message;
38 return std::move(result.value);
39}
40
41} // namespace
42
43class WebHidDevicePolicyHandlerTest : public ConfigurationPolicyPrefStoreTest {
44 public:
45 WebHidDevicePolicyHandlerTest() = default;
46 WebHidDevicePolicyHandlerTest(const WebHidDevicePolicyHandlerTest&) = delete;
47 WebHidDevicePolicyHandlerTest& operator=(
48 const WebHidDevicePolicyHandlerTest&) = delete;
49 ~WebHidDevicePolicyHandlerTest() override = default;
50
51 protected:
52 SchemaValidatingPolicyHandler* AddHandler(const char* policy_name) {
53 auto handler = CreateHandler(policy_name);
54 EXPECT_TRUE(handler) << "no policy handler for " << policy_name;
55 if (!handler)
56 return nullptr;
57
58 auto* handler_ptr = handler.get();
59 handler_list_.AddHandler(std::move(handler));
60 return handler_ptr;
61 }
62
63 private:
64 // Returns the appropriate handler for `policy_name`, which must be a
65 // `policy::key::` constant.
66 std::unique_ptr<SchemaValidatingPolicyHandler> CreateHandler(
67 const char* policy_name) {
68 Schema chrome_schema = Schema::Wrap(GetChromeSchemaData());
69 if (policy_name == key::kWebHidAllowDevicesForUrls) {
70 return std::make_unique<WebHidDevicePolicyHandler>(
71 key::kWebHidAllowDevicesForUrls,
72 prefs::kManagedWebHidAllowDevicesForUrls, chrome_schema);
73 }
74 if (policy_name == key::kWebHidAllowDevicesWithHidUsagesForUrls) {
75 return std::make_unique<WebHidDevicePolicyHandler>(
76 key::kWebHidAllowDevicesWithHidUsagesForUrls,
77 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls, chrome_schema);
78 }
79 return nullptr;
80 }
81};
82
83namespace {
84
85constexpr uint16_t kTestVendorId1 = 1234;
86constexpr uint16_t kTestVendorId2 = 4321;
87constexpr uint16_t kTestVendorId3 = 2000;
88
89constexpr uint16_t kTestProductId = 5678;
90
91constexpr uint16_t kTestUsagePage1 = 1;
92constexpr uint16_t kTestUsagePage2 = 2;
93constexpr uint16_t kTestUsagePage3 = 3;
94
95constexpr uint16_t kTestUsage = 4;
96
97constexpr char kAllowDevicesForUrls[] = R"(
98 [
99 {
100 "devices": [
101 {
102 "vendor_id": 1234,
103 "product_id": 5678
104 },
105 {
106 "vendor_id": 4321
107 }
108 ],
109 "urls": [
110 "https://origin1",
111 "https://origin2"
112 ]
113 }, {
114 "devices": [
115 {
116 "vendor_id": 2000
117 }
118 ],
119 "urls": [
120 "https://origin3"
121 ]
122 }
123 ])";
124
125constexpr char kAllowDevicesWithHidUsagesForUrls[] = R"(
126 [
127 {
128 "usages": [
129 {
130 "usage_page": 1,
131 "usage": 4
132 },
133 {
134 "usage_page": 2
135 }
136 ],
137 "urls": [
138 "https://origin1",
139 "https://origin2"
140 ]
141 }, {
142 "usages": [
143 {
144 "usage_page": 3
145 }
146 ],
147 "urls": [
148 "https://origin3"
149 ]
150 }
151 ])";
152
153} // namespace
154
155TEST_F(WebHidDevicePolicyHandlerTest, CheckPolicySettingsWithDevicePolicy) {
156 auto* handler = AddHandler(key::kWebHidAllowDevicesForUrls);
157
158 PolicyMap policy;
159 PolicyErrorMap errors;
160 policy.Set(
161 key::kWebHidAllowDevicesForUrls, PolicyLevel::POLICY_LEVEL_MANDATORY,
162 PolicyScope::POLICY_SCOPE_MACHINE, PolicySource::POLICY_SOURCE_CLOUD,
163 ReadJson(kAllowDevicesForUrls), /*external_data_fetcher=*/nullptr);
164 ASSERT_TRUE(errors.empty());
165 EXPECT_TRUE(handler->CheckPolicySettings(policy, &errors));
166 EXPECT_TRUE(errors.empty());
167}
168
169TEST_F(WebHidDevicePolicyHandlerTest, CheckPolicySettingsWithUsagePolicy) {
170 auto* handler = AddHandler(key::kWebHidAllowDevicesWithHidUsagesForUrls);
171
172 PolicyMap policy;
173 PolicyErrorMap errors;
174 policy.Set(key::kWebHidAllowDevicesWithHidUsagesForUrls,
175 PolicyLevel::POLICY_LEVEL_MANDATORY,
176 PolicyScope::POLICY_SCOPE_MACHINE,
177 PolicySource::POLICY_SOURCE_CLOUD,
178 ReadJson(kAllowDevicesWithHidUsagesForUrls),
179 /*external_data_fetcher=*/nullptr);
180 ASSERT_TRUE(errors.empty());
181 EXPECT_TRUE(handler->CheckPolicySettings(policy, &errors));
182 EXPECT_TRUE(errors.empty());
183}
184
185TEST_F(WebHidDevicePolicyHandlerTest, ApplyPolicySettingsWithDevicePolicy) {
186 AddHandler(key::kWebHidAllowDevicesForUrls);
187 EXPECT_FALSE(store_->GetValue(prefs::kManagedWebHidAllowDevicesForUrls,
188 /*result=*/nullptr));
189
190 PolicyMap policy;
191 policy.Set(
192 key::kWebHidAllowDevicesForUrls, PolicyLevel::POLICY_LEVEL_MANDATORY,
193 PolicyScope::POLICY_SCOPE_MACHINE, PolicySource::POLICY_SOURCE_CLOUD,
194 ReadJson(kAllowDevicesForUrls), nullptr);
195 UpdateProviderPolicy(policy);
196
197 const base::Value* pref_value = nullptr;
198 EXPECT_TRUE(
199 store_->GetValue(prefs::kManagedWebHidAllowDevicesForUrls, &pref_value));
200 ASSERT_TRUE(pref_value);
201 ASSERT_TRUE(pref_value->is_list());
202
203 // Ensure that the kManagedWebHidAllowDevicesForUrls pref is set correctly.
204 const auto& list = pref_value->GetList();
205 ASSERT_EQ(2ul, list.size());
206
207 // Check the first item's devices list.
208 const base::Value* devices = list[0].FindKey(kDevicesKey);
209 ASSERT_TRUE(devices);
210
211 const auto& first_devices_list = devices->GetList();
212 ASSERT_EQ(2ul, first_devices_list.size());
213
214 const base::Value* vendor_id = first_devices_list[0].FindKey(kVendorIdKey);
215 ASSERT_TRUE(vendor_id);
216 EXPECT_EQ(base::Value(kTestVendorId1), *vendor_id);
217
218 const base::Value* product_id = first_devices_list[0].FindKey(kProductIdKey);
219 ASSERT_TRUE(product_id);
220 EXPECT_EQ(base::Value(kTestProductId), *product_id);
221
222 vendor_id = first_devices_list[1].FindKey(kVendorIdKey);
223 ASSERT_TRUE(vendor_id);
224 EXPECT_EQ(base::Value(kTestVendorId2), *vendor_id);
225
226 product_id = first_devices_list[1].FindKey(kProductIdKey);
227 EXPECT_FALSE(product_id);
228
229 // Check the first item's urls list.
230 const base::Value* urls = list[0].FindKey(kUrlsKey);
231 ASSERT_TRUE(urls);
232 ASSERT_EQ(2ul, urls->GetList().size());
233 EXPECT_EQ(base::Value("https://origin1"), urls->GetList()[0]);
234 EXPECT_EQ(base::Value("https://origin2"), urls->GetList()[1]);
235
236 // Check the second item's devices list.
237 devices = list[1].FindKey(kDevicesKey);
238 ASSERT_TRUE(devices);
239
240 const auto& second_devices_list = devices->GetList();
241 ASSERT_EQ(1ul, second_devices_list.size());
242
243 vendor_id = second_devices_list[0].FindKey(kVendorIdKey);
244 ASSERT_TRUE(vendor_id);
245 EXPECT_EQ(base::Value(kTestVendorId3), *vendor_id);
246
247 product_id = second_devices_list[0].FindKey(kProductIdKey);
248 EXPECT_FALSE(product_id);
249
250 // Check the second item's urls list.
251 urls = list[1].FindKey(kUrlsKey);
252 ASSERT_TRUE(urls);
253 ASSERT_EQ(1ul, urls->GetList().size());
254 EXPECT_EQ(base::Value("https://origin3"), urls->GetList()[0]);
255}
256
257TEST_F(WebHidDevicePolicyHandlerTest, ApplyPolicySettingsWithUsagePolicy) {
258 AddHandler(key::kWebHidAllowDevicesWithHidUsagesForUrls);
259 EXPECT_FALSE(
260 store_->GetValue(prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls,
261 /*result=*/nullptr));
262
263 PolicyMap policy;
264 policy.Set(key::kWebHidAllowDevicesWithHidUsagesForUrls,
265 PolicyLevel::POLICY_LEVEL_MANDATORY,
266 PolicyScope::POLICY_SCOPE_MACHINE,
267 PolicySource::POLICY_SOURCE_CLOUD,
268 ReadJson(kAllowDevicesWithHidUsagesForUrls), nullptr);
269 UpdateProviderPolicy(policy);
270
271 const base::Value* pref_value = nullptr;
272 EXPECT_TRUE(store_->GetValue(
273 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls, &pref_value));
274 ASSERT_TRUE(pref_value);
275 ASSERT_TRUE(pref_value->is_list());
276
277 // Ensure that the kManagedWebHidAllowDevicesWithHidUsagesForUrls pref is set
278 // correctly.
279 const auto& list = pref_value->GetList();
280 ASSERT_EQ(2ul, list.size());
281
282 // Check the first item's usages list.
283 const base::Value* usages = list[0].FindKey(kUsagesKey);
284 ASSERT_TRUE(usages);
285
286 const auto& first_usages_list = usages->GetList();
287 ASSERT_EQ(2ul, first_usages_list.size());
288
289 const base::Value* usage_page = first_usages_list[0].FindKey(kUsagePageKey);
290 ASSERT_TRUE(usage_page);
291 EXPECT_EQ(base::Value(kTestUsagePage1), *usage_page);
292
293 const base::Value* usage = first_usages_list[0].FindKey(kUsageKey);
294 ASSERT_TRUE(usage);
295 EXPECT_EQ(base::Value(kTestUsage), *usage);
296
297 usage_page = first_usages_list[1].FindKey(kUsagePageKey);
298 ASSERT_TRUE(usage_page);
299 EXPECT_EQ(base::Value(kTestUsagePage2), *usage_page);
300
301 usage = first_usages_list[1].FindKey(kUsageKey);
302 EXPECT_FALSE(usage);
303
304 // Check the first item's urls list.
305 const base::Value* urls = list[0].FindKey(kUrlsKey);
306 ASSERT_TRUE(urls);
307 ASSERT_EQ(2ul, urls->GetList().size());
308 EXPECT_EQ(base::Value("https://origin1"), urls->GetList()[0]);
309 EXPECT_EQ(base::Value("https://origin2"), urls->GetList()[1]);
310
311 // Check the second item's usages list.
312 usages = list[1].FindKey(kUsagesKey);
313 ASSERT_TRUE(usages);
314
315 const auto& second_usages_list = usages->GetList();
316 ASSERT_EQ(1ul, second_usages_list.size());
317
318 usage_page = second_usages_list[0].FindKey(kUsagePageKey);
319 ASSERT_TRUE(usage_page);
320 EXPECT_EQ(base::Value(kTestUsagePage3), *usage_page);
321
322 usage = second_usages_list[0].FindKey(kUsageKey);
323 EXPECT_FALSE(usage);
324
325 // Check the second item's urls list.
326 urls = list[1].FindKey(kUrlsKey);
327 ASSERT_TRUE(urls);
328 ASSERT_EQ(1ul, urls->GetList().size());
329 EXPECT_EQ(base::Value("https://origin3"), urls->GetList()[0]);
330}
331
332struct WebHidInvalidPolicyTestData {
333 const char* policy_name;
334 const char* pref_name;
335 const char* policy;
336 const char16_t* expected_errors;
337 const char* expected_pref;
338};
339
340class WebHidInvalidPolicyTest
341 : public WebHidDevicePolicyHandlerTest,
342 public WithParamInterface<WebHidInvalidPolicyTestData> {};
343
344TEST_P(WebHidInvalidPolicyTest, CheckPolicySettingsWithInvalidPolicy) {
345 const auto& test_data = GetParam();
346 auto* handler = AddHandler(test_data.policy_name);
347
348 PolicyMap policy;
349 policy.Set(test_data.policy_name, PolicyLevel::POLICY_LEVEL_MANDATORY,
350 PolicyScope::POLICY_SCOPE_MACHINE,
351 PolicySource::POLICY_SOURCE_CLOUD, ReadJson(test_data.policy),
352 /*external_data_fetcher=*/nullptr);
353
354 // Try CheckPolicySettings with the invalid policy. It returns success if the
355 // policy can be successfully applied, even if there are errors.
356 PolicyErrorMap errors;
357 bool success = handler->CheckPolicySettings(policy, &errors);
358 EXPECT_EQ(success, test_data.expected_pref != nullptr);
359 EXPECT_EQ(test_data.expected_errors, errors.GetErrors(test_data.policy_name));
360
361 EXPECT_FALSE(store_->GetValue(test_data.pref_name, /*result=*/nullptr));
362
363 // Try updating the policy.
364 UpdateProviderPolicy(policy);
365
366 // Check that the preference has the expected value.
367 if (test_data.expected_pref) {
368 const base::Value* pref_value = nullptr;
369 EXPECT_TRUE(store_->GetValue(test_data.pref_name, &pref_value));
370 ASSERT_TRUE(pref_value);
371 absl::optional<base::Value> expected_pref_value =
372 ReadJson(test_data.expected_pref);
373 ASSERT_TRUE(expected_pref_value);
374 EXPECT_EQ(*expected_pref_value, *pref_value);
375 } else {
376 EXPECT_FALSE(store_->GetValue(test_data.pref_name, /*result=*/nullptr));
377 }
378}
379
380WebHidInvalidPolicyTestData kTestData[]{
381 {
382 key::kWebHidAllowDevicesForUrls,
383 prefs::kManagedWebHidAllowDevicesForUrls,
384 R"(
385 [
386 {
387 "urls": [
388 "https://google.com"
389 ]
390 }
391 ])",
392 u"Schema validation error at \"items[0]\": Missing or invalid required "
393 u"property: devices",
394 "[]",
395 },
396 {
397 key::kWebHidAllowDevicesForUrls,
398 prefs::kManagedWebHidAllowDevicesForUrls,
399 R"(
400 [
401 {
402 "devices": [
403 {
404 "vendor_id": 1234
405 }
406 ]
407 }
408 ])",
409 u"Schema validation error at \"items[0]\": Missing or invalid required "
410 u"property: urls",
411 "[]",
412 },
413 {
414 key::kWebHidAllowDevicesForUrls,
415 prefs::kManagedWebHidAllowDevicesForUrls,
416 R"(
417 [
418 {
419 "devices": [
420 {
421 "vendor_id": 1234,
422 "serial_number": "1234ABCD"
423 }
424 ],
425 "urls": [
426 "https://google.com"
427 ]
428 }
429 ])",
430 u"Schema validation error at \"items[0].devices.items[0]\": Unknown "
431 u"property: serial_number",
432 R"(
433 [
434 {
435 "devices": [
436 {
437 "vendor_id": 1234
438 }
439 ],
440 "urls": [
441 "https://google.com"
442 ]
443 }
444 ])",
445 },
446 {
447 key::kWebHidAllowDevicesForUrls,
448 prefs::kManagedWebHidAllowDevicesForUrls,
449 R"(
450 [
451 {
452 "devices": [
453 {
454 "vendor_id": 65536
455 }
456 ],
457 "urls": [
458 "https://google.com"
459 ]
460 }
461 ])",
462 u"Schema validation error at \"items[0].devices.items[0].vendor_id\": "
463 u"Invalid value for integer",
464 R"(
465 [
466 {
467 "devices": [],
468 "urls": [
469 "https://google.com"
470 ]
471 }
472 ])",
473 },
474 {
475 key::kWebHidAllowDevicesForUrls,
476 prefs::kManagedWebHidAllowDevicesForUrls,
477 R"(
478 [
479 {
480 "devices": [
481 {
482 "vendor_id": 1234,
483 "product_id": 65536
484 }
485 ],
486 "urls": [
487 "https://google.com"
488 ]
489 }
490 ])",
491 u"Schema validation error at \"items[0].devices.items[0].product_id\": "
492 u"Invalid value for integer",
493 R"(
494 [
495 {
496 "devices": [],
497 "urls": [
498 "https://google.com"
499 ]
500 }
501 ])",
502 },
503 {
504 key::kWebHidAllowDevicesForUrls,
505 prefs::kManagedWebHidAllowDevicesForUrls,
506 R"(
507 [
508 {
509 "devices": [
510 {
511 "product_id": 1234
512 }
513 ],
514 "urls": [
515 "https://google.com"
516 ]
517 }
518 ])",
519 u"Schema validation error at \"items[0].devices.items[0]\": Missing or "
520 u"invalid required property: vendor_id",
521 R"(
522 [
523 {
524 "devices": [],
525 "urls": [
526 "https://google.com"
527 ]
528 }
529 ])",
530 },
531 {
532 key::kWebHidAllowDevicesForUrls,
533 prefs::kManagedWebHidAllowDevicesForUrls,
534 R"(
535 [
536 {
537 "devices": [
538 {
539 "vendor_id": 1234
540 }
541 ],
542 "urls": [
543 "not-a-valid-url"
544 ]
545 }
546 ])",
547 u"Schema validation error at \"items[0].urls.items[0]\": Invalid URL: "
548 u"not-a-valid-url",
549 R"(
550 [
551 {
552 "devices": [
553 {
554 "vendor_id": 1234
555 }
556 ],
557 "urls": [
558 "not-a-valid-url"
559 ]
560 }
561 ])",
562 },
563 {
564 key::kWebHidAllowDevicesForUrls,
565 prefs::kManagedWebHidAllowDevicesForUrls,
566 R"(
567 [
568 {
569 "devices": [
570 {
571 "vendor_id": 1234
572 }
573 ],
574 "urls": [
575 ""
576 ]
577 }
578 ])",
579 u"Schema validation error at \"items[0].urls.items[0]\": Invalid URL: ",
580 R"(
581 [
582 {
583 "devices": [
584 {
585 "vendor_id": 1234
586 }
587 ],
588 "urls": [
589 ""
590 ]
591 }
592 ])",
593 },
594 {
595 key::kWebHidAllowDevicesForUrls,
596 prefs::kManagedWebHidAllowDevicesForUrls,
597 R"(
598 [
599 {
600 "devices": [
601 {
602 "vendor_id": 1234
603 }
604 ],
605 "urls": [
606 "invalid-url-1",
607 "invalid-url-2"
608 ]
609 }
610 ])",
611 u"Schema validation error at \"items[0].urls.items[0]\": Invalid URL: "
612 u"invalid-url-1\nSchema validation error at "
613 u"\"items[0].urls.items[1]\": Invalid URL: invalid-url-2",
614 R"(
615 [
616 {
617 "devices": [
618 {
619 "vendor_id": 1234
620 }
621 ],
622 "urls": [
623 "invalid-url-1",
624 "invalid-url-2"
625 ]
626 }
627 ])",
628 },
629 {
630 key::kWebHidAllowDevicesWithHidUsagesForUrls,
631 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls,
632 R"(
633 [
634 {
635 "urls": [
636 "https://google.com"
637 ]
638 }
639 ])",
640 u"Schema validation error at \"items[0]\": Missing or invalid required "
641 u"property: usages",
642 "[]",
643 },
644 {
645 key::kWebHidAllowDevicesWithHidUsagesForUrls,
646 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls,
647 R"(
648 [
649 {
650 "usages": [
651 {
652 "usage_page": 1234
653 }
654 ]
655 }
656 ])",
657 u"Schema validation error at \"items[0]\": Missing or invalid required "
658 u"property: urls",
659 "[]",
660 },
661 {
662 key::kWebHidAllowDevicesWithHidUsagesForUrls,
663 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls,
664 R"(
665 [
666 {
667 "usages": [
668 {
669 "usage_page": 1234,
670 "serial_number": "1234ABCD"
671 }
672 ],
673 "urls": [
674 "https://google.com"
675 ]
676 }
677 ])",
678 u"Schema validation error at \"items[0].usages.items[0]\": Unknown "
679 u"property: serial_number",
680 R"(
681 [
682 {
683 "usages": [
684 {
685 "usage_page": 1234
686 }
687 ],
688 "urls": [
689 "https://google.com"
690 ]
691 }
692 ])",
693 },
694 {
695 key::kWebHidAllowDevicesWithHidUsagesForUrls,
696 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls,
697 R"(
698 [
699 {
700 "usages": [
701 {
702 "usage_page": 65536
703 }
704 ],
705 "urls": [
706 "https://google.com"
707 ]
708 }
709 ])",
710 u"Schema validation error at \"items[0].usages.items[0].usage_page\": "
711 u"Invalid value for integer",
712 R"(
713 [
714 {
715 "usages": [],
716 "urls": [
717 "https://google.com"
718 ]
719 }
720 ])",
721 },
722 {
723 key::kWebHidAllowDevicesWithHidUsagesForUrls,
724 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls,
725 R"(
726 [
727 {
728 "usages": [
729 {
730 "usage_page": 1234,
731 "usage": 65536
732 }
733 ],
734 "urls": [
735 "https://google.com"
736 ]
737 }
738 ])",
739 u"Schema validation error at \"items[0].usages.items[0].usage\": "
740 u"Invalid value for integer",
741 R"(
742 [
743 {
744 "usages": [],
745 "urls": [
746 "https://google.com"
747 ]
748 }
749 ])",
750 },
751 {
752 key::kWebHidAllowDevicesWithHidUsagesForUrls,
753 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls,
754 R"(
755 [
756 {
757 "usages": [
758 {
759 "usage": 1234
760 }
761 ],
762 "urls": [
763 "https://google.com"
764 ]
765 }
766 ])",
767 u"Schema validation error at \"items[0].usages.items[0]\": Missing or "
768 u"invalid required property: usage_page",
769 R"(
770 [
771 {
772 "usages": [],
773 "urls": [
774 "https://google.com"
775 ]
776 }
777 ])",
778 },
779 {
780 key::kWebHidAllowDevicesWithHidUsagesForUrls,
781 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls,
782 R"(
783 [
784 {
785 "usages": [
786 {
787 "usage_page": 1234
788 }
789 ],
790 "urls": [
791 "not-a-valid-url"
792 ]
793 }
794 ])",
795 u"Schema validation error at \"items[0].urls.items[0]\": Invalid URL: "
796 u"not-a-valid-url",
797 R"(
798 [
799 {
800 "usages": [
801 {
802 "usage_page": 1234
803 }
804 ],
805 "urls": [
806 "not-a-valid-url"
807 ]
808 }
809 ])",
810 },
811 {
812 key::kWebHidAllowDevicesWithHidUsagesForUrls,
813 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls,
814 R"(
815 [
816 {
817 "usages": [
818 {
819 "usage_page": 1234
820 }
821 ],
822 "urls": [
823 ""
824 ]
825 }
826 ])",
827 u"Schema validation error at \"items[0].urls.items[0]\": Invalid URL: ",
828 R"(
829 [
830 {
831 "usages": [
832 {
833 "usage_page": 1234
834 }
835 ],
836 "urls": [
837 ""
838 ]
839 }
840 ])",
841 },
842 {
843 key::kWebHidAllowDevicesWithHidUsagesForUrls,
844 prefs::kManagedWebHidAllowDevicesWithHidUsagesForUrls,
845 R"(
846 [
847 {
848 "usages": [
849 {
850 "usage_page": 1234
851 }
852 ],
853 "urls": [
854 "invalid-url-1",
855 "invalid-url-2"
856 ]
857 }
858 ])",
859 u"Schema validation error at \"items[0].urls.items[0]\": Invalid URL: "
860 u"invalid-url-1\nSchema validation error at "
861 u"\"items[0].urls.items[1]\": Invalid URL: invalid-url-2",
862 R"(
863 [
864 {
865 "usages": [
866 {
867 "usage_page": 1234
868 }
869 ],
870 "urls": [
871 "invalid-url-1",
872 "invalid-url-2"
873 ]
874 }
875 ])",
876 },
877};
878
879INSTANTIATE_TEST_SUITE_P(WebHidInvalidPolicyTests,
880 WebHidInvalidPolicyTest,
881 testing::ValuesIn(kTestData));
882
883} // namespace policy