OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #include "base/version.h" |
| 6 #include "chrome/common/extensions/extension.h" |
| 7 #include "chrome/common/extensions/extension_unittest.h" |
| 8 #include "chrome/common/extensions/manifest_handlers/shared_module_info.h" |
| 9 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace { |
| 13 |
| 14 const char* kValidImportPath = |
| 15 "_modules/abcdefghijklmnopabcdefghijklmnop/foo/bar.html"; |
| 16 const char* kValidImportPathID = "abcdefghijklmnopabcdefghijklmnop"; |
| 17 const char* kValidImportPathRelative = "foo/bar.html"; |
| 18 const char* kInvalidImportPath = "_modules/abc/foo.html"; |
| 19 const char* kImportId1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 20 const char* kImportId2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; |
| 21 const char* kNoImport = "cccccccccccccccccccccccccccccccc"; |
| 22 |
| 23 } |
| 24 |
| 25 namespace extensions { |
| 26 |
| 27 class SharedModuleManifestTest : public ExtensionManifestTest { |
| 28 protected: |
| 29 virtual void SetUp() OVERRIDE { |
| 30 ExtensionManifestTest::SetUp(); |
| 31 (new SharedModuleHandler)->Register(); |
| 32 } |
| 33 }; |
| 34 |
| 35 TEST_F(SharedModuleManifestTest, ExportsAll) { |
| 36 Manifest manifest("shared_module_export.json"); |
| 37 |
| 38 scoped_refptr<Extension> extension = LoadAndExpectSuccess(manifest); |
| 39 |
| 40 EXPECT_TRUE(SharedModuleInfo::IsSharedModule(extension)) << manifest.name(); |
| 41 EXPECT_FALSE(SharedModuleInfo::ImportsModules(extension)) << manifest.name(); |
| 42 EXPECT_TRUE(SharedModuleInfo::IsExportAllowed(extension, "foo")) |
| 43 << manifest.name(); |
| 44 EXPECT_TRUE(SharedModuleInfo::IsExportAllowed(extension, "foo/bar")) |
| 45 << manifest.name(); |
| 46 } |
| 47 |
| 48 TEST_F(SharedModuleManifestTest, ExportFoo) { |
| 49 Manifest manifest("shared_module_export_foo.json"); |
| 50 |
| 51 scoped_refptr<Extension> extension = LoadAndExpectSuccess(manifest); |
| 52 |
| 53 EXPECT_TRUE(SharedModuleInfo::IsSharedModule(extension)) << manifest.name(); |
| 54 EXPECT_FALSE(SharedModuleInfo::ImportsModules(extension)) << manifest.name(); |
| 55 EXPECT_TRUE(SharedModuleInfo::IsExportAllowed(extension, "foo")) |
| 56 << manifest.name(); |
| 57 EXPECT_FALSE(SharedModuleInfo::IsExportAllowed(extension, "foo/bar")) |
| 58 << manifest.name(); |
| 59 } |
| 60 |
| 61 TEST_F(SharedModuleManifestTest, ExportParseErrors) { |
| 62 Testcase testcases[] = { |
| 63 Testcase("shared_module_export_and_import.json", |
| 64 "Simultaneous 'import' and 'export' are not allowed."), |
| 65 Testcase("shared_module_export_not_dict.json", |
| 66 "Invalid value for 'export'."), |
| 67 Testcase("shared_module_export_resources_not_list.json", |
| 68 "Invalid value for 'export.resources'."), |
| 69 Testcase("shared_module_export_resource_not_string.json", |
| 70 "Invalid value for 'export.resources[1]'."), |
| 71 }; |
| 72 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR); |
| 73 } |
| 74 |
| 75 TEST_F(SharedModuleManifestTest, SharedModuleStaticFunctions) { |
| 76 EXPECT_TRUE(SharedModuleInfo::IsImportedPath(kValidImportPath)); |
| 77 EXPECT_FALSE(SharedModuleInfo::IsImportedPath(kInvalidImportPath)); |
| 78 |
| 79 std::string id; |
| 80 std::string relative; |
| 81 SharedModuleInfo::ParseImportedPath(kValidImportPath, &id, &relative); |
| 82 EXPECT_EQ(id, kValidImportPathID); |
| 83 EXPECT_EQ(relative, kValidImportPathRelative); |
| 84 } |
| 85 |
| 86 TEST_F(SharedModuleManifestTest, Import) { |
| 87 Manifest manifest("shared_module_import.json"); |
| 88 |
| 89 scoped_refptr<Extension> extension = LoadAndExpectSuccess(manifest); |
| 90 |
| 91 EXPECT_FALSE(SharedModuleInfo::IsSharedModule(extension)) << manifest.name(); |
| 92 EXPECT_TRUE(SharedModuleInfo::ImportsModules(extension)) << manifest.name(); |
| 93 const std::vector<SharedModuleInfo::ImportInfo>& imports = |
| 94 SharedModuleInfo::GetImports(extension); |
| 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(SharedModuleInfo::ImportsExtensionById(extension, kImportId1)); |
| 101 EXPECT_TRUE(SharedModuleInfo::ImportsExtensionById(extension, kImportId2)); |
| 102 EXPECT_FALSE(SharedModuleInfo::ImportsExtensionById(extension, kNoImport)); |
| 103 } |
| 104 |
| 105 TEST_F(SharedModuleManifestTest, ImportParseErrors) { |
| 106 Testcase testcases[] = { |
| 107 Testcase("shared_module_import_not_list.json", |
| 108 "Invalid value for 'import'."), |
| 109 Testcase("shared_module_import_invalid_id.json", |
| 110 "Invalid value for 'import[0].id'."), |
| 111 Testcase("shared_module_import_invalid_version.json", |
| 112 "Invalid value for 'import[0].minimum_version'."), |
| 113 }; |
| 114 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR); |
| 115 } |
| 116 |
| 117 } // namespace extensions |
OLD | NEW |