Added documentation to web_view.js/web_view_experimental.js regarding the webview...
[chromium-blink-merge.git] / extensions / common / manifest_handlers / shared_module_manifest_unittest.cc
blobfa1e387e11b4a2f4a72874c848fb8fa5c77042d3
1 // Copyright 2013 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/version.h"
6 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
7 #include "extensions/common/extension.h"
8 #include "extensions/common/manifest_handlers/shared_module_info.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace {
13 const char* kValidImportPath =
14 "_modules/abcdefghijklmnopabcdefghijklmnop/foo/bar.html";
15 const char* kValidImportPathID = "abcdefghijklmnopabcdefghijklmnop";
16 const char* kValidImportPathRelative = "foo/bar.html";
17 const char* kInvalidImportPath = "_modules/abc/foo.html";
18 const char* kImportId1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
19 const char* kImportId2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
20 const char* kNoImport = "cccccccccccccccccccccccccccccccc";
22 } // namespace
24 namespace extensions {
26 class SharedModuleManifestTest : public ExtensionManifestTest {
29 TEST_F(SharedModuleManifestTest, ExportsAll) {
30 Manifest manifest("shared_module_export.json");
32 scoped_refptr<Extension> extension = LoadAndExpectSuccess(manifest);
34 EXPECT_TRUE(SharedModuleInfo::IsSharedModule(extension.get()))
35 << manifest.name();
36 EXPECT_FALSE(SharedModuleInfo::ImportsModules(extension.get()))
37 << manifest.name();
38 EXPECT_TRUE(SharedModuleInfo::IsExportAllowed(extension.get(), "foo"))
39 << manifest.name();
40 EXPECT_TRUE(SharedModuleInfo::IsExportAllowed(extension.get(), "foo/bar"))
41 << manifest.name();
44 TEST_F(SharedModuleManifestTest, ExportFoo) {
45 Manifest manifest("shared_module_export_foo.json");
47 scoped_refptr<Extension> extension = LoadAndExpectSuccess(manifest);
49 EXPECT_TRUE(SharedModuleInfo::IsSharedModule(extension.get()))
50 << manifest.name();
51 EXPECT_FALSE(SharedModuleInfo::ImportsModules(extension.get()))
52 << manifest.name();
53 EXPECT_TRUE(SharedModuleInfo::IsExportAllowed(extension.get(), "foo"))
54 << manifest.name();
55 EXPECT_FALSE(SharedModuleInfo::IsExportAllowed(extension.get(), "foo/bar"))
56 << manifest.name();
59 TEST_F(SharedModuleManifestTest, ExportParseErrors) {
60 Testcase testcases[] = {
61 Testcase("shared_module_export_and_import.json",
62 "Simultaneous 'import' and 'export' are not allowed."),
63 Testcase("shared_module_export_not_dict.json",
64 "Invalid value for 'export'."),
65 Testcase("shared_module_export_resources_not_list.json",
66 "Invalid value for 'export.resources'."),
67 Testcase("shared_module_export_resource_not_string.json",
68 "Invalid value for 'export.resources[1]'."),
70 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR);
73 TEST_F(SharedModuleManifestTest, SharedModuleStaticFunctions) {
74 EXPECT_TRUE(SharedModuleInfo::IsImportedPath(kValidImportPath));
75 EXPECT_FALSE(SharedModuleInfo::IsImportedPath(kInvalidImportPath));
77 std::string id;
78 std::string relative;
79 SharedModuleInfo::ParseImportedPath(kValidImportPath, &id, &relative);
80 EXPECT_EQ(id, kValidImportPathID);
81 EXPECT_EQ(relative, kValidImportPathRelative);
84 TEST_F(SharedModuleManifestTest, Import) {
85 Manifest manifest("shared_module_import.json");
87 scoped_refptr<Extension> extension = LoadAndExpectSuccess(manifest);
89 EXPECT_FALSE(SharedModuleInfo::IsSharedModule(extension.get()))
90 << manifest.name();
91 EXPECT_TRUE(SharedModuleInfo::ImportsModules(extension.get()))
92 << manifest.name();
93 const std::vector<SharedModuleInfo::ImportInfo>& imports =
94 SharedModuleInfo::GetImports(extension.get());
95 ASSERT_EQ(2U, imports.size());
96 EXPECT_EQ(imports[0].extension_id, kImportId1);
97 EXPECT_EQ(imports[0].minimum_version, "");
98 EXPECT_EQ(imports[1].extension_id, kImportId2);
99 EXPECT_TRUE(base::Version(imports[1].minimum_version).IsValid());
100 EXPECT_TRUE(
101 SharedModuleInfo::ImportsExtensionById(extension.get(), kImportId1));
102 EXPECT_TRUE(
103 SharedModuleInfo::ImportsExtensionById(extension.get(), kImportId2));
104 EXPECT_FALSE(
105 SharedModuleInfo::ImportsExtensionById(extension.get(), kNoImport));
108 TEST_F(SharedModuleManifestTest, ImportParseErrors) {
109 Testcase testcases[] = {
110 Testcase("shared_module_import_not_list.json",
111 "Invalid value for 'import'."),
112 Testcase("shared_module_import_invalid_id.json",
113 "Invalid value for 'import[0].id'."),
114 Testcase("shared_module_import_invalid_version.json",
115 "Invalid value for 'import[0].minimum_version'."),
117 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR);
120 } // namespace extensions