Allow only one bookmark to be added for multiple fast starring
[chromium-blink-merge.git] / extensions / common / manifest_handlers / shared_module_manifest_unittest.cc
blobecbabbd0e8e40f79fb83b33069f50e6bbe1a58e9
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 "extensions/common/extension.h"
7 #include "extensions/common/manifest_handlers/shared_module_info.h"
8 #include "extensions/common/manifest_test.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 ManifestTest {
29 TEST_F(SharedModuleManifestTest, ExportsAll) {
30 ManifestData 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();
39 EXPECT_TRUE(SharedModuleInfo::IsExportAllowedByWhitelist(extension.get(),
40 kImportId1)) << manifest.name();
41 EXPECT_TRUE(SharedModuleInfo::IsExportAllowedByWhitelist(extension.get(),
42 kImportId2)) << manifest.name();
43 EXPECT_FALSE(SharedModuleInfo::IsExportAllowedByWhitelist(extension.get(),
44 kNoImport)) << manifest.name();
47 TEST_F(SharedModuleManifestTest, ExportWhitelistAll) {
48 ManifestData manifest("shared_module_export_no_whitelist.json");
50 scoped_refptr<Extension> extension = LoadAndExpectSuccess(manifest);
52 EXPECT_TRUE(SharedModuleInfo::IsExportAllowedByWhitelist(extension.get(),
53 kImportId1)) << manifest.name();
54 EXPECT_TRUE(SharedModuleInfo::IsExportAllowedByWhitelist(extension.get(),
55 kImportId2)) << manifest.name();
56 EXPECT_TRUE(SharedModuleInfo::IsExportAllowedByWhitelist(extension.get(),
57 kNoImport)) << manifest.name();
60 TEST_F(SharedModuleManifestTest, ExportParseErrors) {
61 Testcase testcases[] = {
62 Testcase("shared_module_export_and_import.json",
63 "Simultaneous 'import' and 'export' are not allowed."),
64 Testcase("shared_module_export_not_dict.json",
65 "Invalid value for 'export'."),
66 Testcase("shared_module_export_whitelist_item_not_id.json",
67 "Invalid value for 'export.whitelist[0]'."),
68 Testcase("shared_module_export_whitelist_item_not_string.json",
69 "Invalid value for 'export.whitelist[0]'."),
70 Testcase("shared_module_export_whitelist_not_list.json",
71 "Invalid value for 'export.whitelist'."),
73 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR);
76 TEST_F(SharedModuleManifestTest, SharedModuleStaticFunctions) {
77 EXPECT_TRUE(SharedModuleInfo::IsImportedPath(kValidImportPath));
78 EXPECT_FALSE(SharedModuleInfo::IsImportedPath(kInvalidImportPath));
80 std::string id;
81 std::string relative;
82 SharedModuleInfo::ParseImportedPath(kValidImportPath, &id, &relative);
83 EXPECT_EQ(id, kValidImportPathID);
84 EXPECT_EQ(relative, kValidImportPathRelative);
87 TEST_F(SharedModuleManifestTest, Import) {
88 ManifestData manifest("shared_module_import.json");
90 scoped_refptr<Extension> extension = LoadAndExpectSuccess(manifest);
92 EXPECT_FALSE(SharedModuleInfo::IsSharedModule(extension.get()))
93 << manifest.name();
94 EXPECT_TRUE(SharedModuleInfo::ImportsModules(extension.get()))
95 << manifest.name();
96 const std::vector<SharedModuleInfo::ImportInfo>& imports =
97 SharedModuleInfo::GetImports(extension.get());
98 ASSERT_EQ(2U, imports.size());
99 EXPECT_EQ(imports[0].extension_id, kImportId1);
100 EXPECT_EQ(imports[0].minimum_version, "");
101 EXPECT_EQ(imports[1].extension_id, kImportId2);
102 EXPECT_TRUE(base::Version(imports[1].minimum_version).IsValid());
103 EXPECT_TRUE(
104 SharedModuleInfo::ImportsExtensionById(extension.get(), kImportId1));
105 EXPECT_TRUE(
106 SharedModuleInfo::ImportsExtensionById(extension.get(), kImportId2));
107 EXPECT_FALSE(
108 SharedModuleInfo::ImportsExtensionById(extension.get(), kNoImport));
111 TEST_F(SharedModuleManifestTest, ImportParseErrors) {
112 Testcase testcases[] = {
113 Testcase("shared_module_import_not_list.json",
114 "Invalid value for 'import'."),
115 Testcase("shared_module_import_invalid_id.json",
116 "Invalid value for 'import[0].id'."),
117 Testcase("shared_module_import_invalid_version.json",
118 "Invalid value for 'import[0].minimum_version'."),
120 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR);
123 } // namespace extensions