Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / common / extensions / manifest_tests / extension_manifests_webview_accessible_resources_unittest.cc
blobe7f456192e7469750fbd7effeeb9e5dd2bb0320d
1 // Copyright 2014 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 "base/strings/string_number_conversions.h"
6 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
7 #include "extensions/common/error_utils.h"
8 #include "extensions/common/manifest_constants.h"
9 #include "extensions/common/manifest_handlers/webview_info.h"
11 using extensions::ErrorUtils;
12 using extensions::Extension;
13 using extensions::WebviewInfo;
14 namespace errors = extensions::manifest_errors;
16 class WebviewAccessibleResourcesManifestTest : public ExtensionManifestTest {
19 TEST_F(WebviewAccessibleResourcesManifestTest, WebviewAccessibleResources) {
20 // Manifest version 2 with webview accessible resources specified.
21 scoped_refptr<Extension> extension1(
22 LoadAndExpectSuccess("webview_accessible_resources_1.json"));
24 EXPECT_FALSE(
25 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
26 "fail",
27 "a.html"));
28 EXPECT_FALSE(
29 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
30 "fail",
31 "b.html"));
32 EXPECT_FALSE(
33 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
34 "fail",
35 "c.html"));
36 EXPECT_FALSE(
37 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
38 "fail",
39 "d.html"));
41 EXPECT_TRUE(
42 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
43 "foo",
44 "a.html"));
45 EXPECT_TRUE(
46 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
47 "foo",
48 "b.html"));
49 EXPECT_FALSE(
50 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
51 "foo",
52 "c.html"));
53 EXPECT_FALSE(
54 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
55 "foo",
56 "d.html"));
58 EXPECT_TRUE(
59 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
60 "bar",
61 "a.html"));
62 EXPECT_FALSE(
63 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
64 "bar",
65 "b.html"));
66 EXPECT_TRUE(
67 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
68 "bar",
69 "c.html"));
70 EXPECT_FALSE(
71 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
72 "bar",
73 "d.html"));
75 EXPECT_TRUE(
76 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
77 "foobar",
78 "a.html"));
79 EXPECT_TRUE(
80 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
81 "foobar",
82 "b.html"));
83 EXPECT_TRUE(
84 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
85 "foobar",
86 "c.html"));
87 EXPECT_FALSE(
88 WebviewInfo::IsResourceWebviewAccessible(extension1.get(),
89 "foobar",
90 "d.html"));
93 TEST_F(WebviewAccessibleResourcesManifestTest, InvalidManifest) {
94 LoadAndExpectError("webview_accessible_resources_invalid1.json",
95 errors::kInvalidWebview);
96 LoadAndExpectError("webview_accessible_resources_invalid2.json",
97 errors::kInvalidWebviewPartitionsList);
98 LoadAndExpectError("webview_accessible_resources_invalid3.json",
99 errors::kInvalidWebviewPartitionsList);
100 LoadAndExpectError("webview_accessible_resources_invalid4.json",
101 ErrorUtils::FormatErrorMessage(
102 errors::kInvalidWebviewPartition, base::IntToString(0)));
103 LoadAndExpectError("webview_accessible_resources_invalid5.json",
104 errors::kInvalidWebviewPartitionName);
105 LoadAndExpectError("webview_accessible_resources_invalid6.json",
106 errors::kInvalidWebviewAccessibleResourcesList);
107 LoadAndExpectError("webview_accessible_resources_invalid7.json",
108 errors::kInvalidWebviewAccessibleResourcesList);
109 LoadAndExpectError("webview_accessible_resources_invalid8.json",
110 ErrorUtils::FormatErrorMessage(
111 errors::kInvalidWebviewAccessibleResource, base::IntToString(0)));