Roll src/third_party/WebKit 9301d6f:4619053 (svn 201058:201059)
[chromium-blink-merge.git] / extensions / common / manifest_handlers / file_handler_manifest_unittest.cc
blob5934dc094996affb63ba53c9bbb27acf7419ceeb
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 "extensions/common/manifest_constants.h"
6 #include "extensions/common/manifest_handlers/file_handler_info.h"
7 #include "extensions/common/manifest_test.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace extensions {
12 namespace errors = manifest_errors;
14 typedef ManifestTest FileHandlersManifestTest;
16 TEST_F(FileHandlersManifestTest, InvalidFileHandlers) {
17 Testcase testcases[] = {
18 Testcase("file_handlers_invalid_handlers.json",
19 errors::kInvalidFileHandlers),
20 Testcase("file_handlers_invalid_type.json",
21 errors::kInvalidFileHandlerType),
22 Testcase("file_handlers_invalid_extension.json",
23 errors::kInvalidFileHandlerExtension),
24 Testcase("file_handlers_invalid_no_type_or_extension.json",
25 errors::kInvalidFileHandlerNoTypeOrExtension),
26 Testcase("file_handlers_invalid_type_element.json",
27 errors::kInvalidFileHandlerTypeElement),
28 Testcase("file_handlers_invalid_extension_element.json",
29 errors::kInvalidFileHandlerExtensionElement),
30 Testcase("file_handlers_invalid_too_many.json",
31 errors::kInvalidFileHandlersTooManyTypesAndExtensions),
33 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR);
36 TEST_F(FileHandlersManifestTest, ValidFileHandlers) {
37 scoped_refptr<const Extension> extension =
38 LoadAndExpectSuccess("file_handlers_valid.json");
40 ASSERT_TRUE(extension.get());
41 const FileHandlersInfo* handlers =
42 FileHandlers::GetFileHandlers(extension.get());
43 ASSERT_TRUE(handlers != NULL);
44 ASSERT_EQ(2U, handlers->size());
46 FileHandlerInfo handler = handlers->at(0);
47 EXPECT_EQ("image", handler.id);
48 EXPECT_EQ(1U, handler.types.size());
49 EXPECT_EQ(1U, handler.types.count("image/*"));
50 EXPECT_EQ(2U, handler.extensions.size());
51 EXPECT_EQ(1U, handler.extensions.count(".png"));
52 EXPECT_EQ(1U, handler.extensions.count(".gif"));
54 handler = handlers->at(1);
55 EXPECT_EQ("text", handler.id);
56 EXPECT_EQ(1U, handler.types.size());
57 EXPECT_EQ(1U, handler.types.count("text/*"));
58 EXPECT_EQ(0U, handler.extensions.size());
61 TEST_F(FileHandlersManifestTest, NotPlatformApp) {
62 // This should load successfully but have the file handlers ignored.
63 scoped_refptr<const Extension> extension =
64 LoadAndExpectSuccess("file_handlers_invalid_not_app.json");
66 ASSERT_TRUE(extension.get());
67 const FileHandlersInfo* handlers =
68 FileHandlers::GetFileHandlers(extension.get());
69 ASSERT_TRUE(handlers == NULL);
72 } // namespace extensions