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 "chrome/common/extensions/api/file_handlers/file_handlers_parser.h"
6 #include "chrome/common/extensions/extension_constants.h"
7 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
8 //#include "extensions/common/error_utils.h"
9 #include "extensions/common/manifest_constants.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace errors
= extensions::manifest_errors
;
14 using extensions::Extension
;
15 using extensions::FileHandlers
;
16 using extensions::FileHandlerInfo
;
18 class FileHandlersManifestTest
: public ExtensionManifestTest
{
21 TEST_F(FileHandlersManifestTest
, InvalidFileHandlers
) {
22 Testcase testcases
[] = {
23 Testcase("file_handlers_invalid_handlers.json",
24 errors::kInvalidFileHandlers
),
25 Testcase("file_handlers_invalid_type.json",
26 errors::kInvalidFileHandlerType
),
27 Testcase("file_handlers_invalid_extension.json",
28 errors::kInvalidFileHandlerExtension
),
29 Testcase("file_handlers_invalid_no_type_or_extension.json",
30 errors::kInvalidFileHandlerNoTypeOrExtension
),
31 Testcase("file_handlers_invalid_title.json",
32 errors::kInvalidFileHandlerTitle
),
33 Testcase("file_handlers_invalid_type_element.json",
34 errors::kInvalidFileHandlerTypeElement
),
35 Testcase("file_handlers_invalid_extension_element.json",
36 errors::kInvalidFileHandlerExtensionElement
),
37 Testcase("file_handlers_invalid_too_many.json",
38 errors::kInvalidFileHandlersTooManyTypesAndExtensions
),
40 RunTestcases(testcases
, arraysize(testcases
), EXPECT_TYPE_ERROR
);
43 TEST_F(FileHandlersManifestTest
, ValidFileHandlers
) {
44 scoped_refptr
<const Extension
> extension
=
45 LoadAndExpectSuccess("file_handlers_valid.json");
47 ASSERT_TRUE(extension
.get());
48 const std::vector
<FileHandlerInfo
>* handlers
=
49 FileHandlers::GetFileHandlers(extension
.get());
50 ASSERT_TRUE(handlers
!= NULL
);
51 ASSERT_EQ(2U, handlers
->size());
53 FileHandlerInfo handler
= handlers
->at(0);
54 EXPECT_EQ("image", handler
.id
);
55 EXPECT_EQ("Image editor", handler
.title
);
56 EXPECT_EQ(1U, handler
.types
.size());
57 EXPECT_EQ(1U, handler
.types
.count("image/*"));
58 EXPECT_EQ(2U, handler
.extensions
.size());
59 EXPECT_EQ(1U, handler
.extensions
.count(".png"));
60 EXPECT_EQ(1U, handler
.extensions
.count(".gif"));
62 handler
= handlers
->at(1);
63 EXPECT_EQ("text", handler
.id
);
64 EXPECT_EQ("Text editor", handler
.title
);
65 EXPECT_EQ(1U, handler
.types
.size());
66 EXPECT_EQ(1U, handler
.types
.count("text/*"));
67 EXPECT_EQ(0U, handler
.extensions
.size());
70 TEST_F(FileHandlersManifestTest
, NotPlatformApp
) {
71 // This should load successfully but have the file handlers ignored.
72 scoped_refptr
<const Extension
> extension
=
73 LoadAndExpectSuccess("file_handlers_invalid_not_app.json");
75 ASSERT_TRUE(extension
.get());
76 const std::vector
<FileHandlerInfo
>* handlers
=
77 FileHandlers::GetFileHandlers(extension
.get());
78 ASSERT_TRUE(handlers
== NULL
);