Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: extensions/common/manifest_handlers/file_handler_manifest_unittest.cc

Issue 1872223002: Add verbs API to file handlers. Modify the Chrome OS UI so that it displayes the internationalized … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move back to "open-with" for the id of the more actions dialog, as it breaks some browsers tests, a… Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/macros.h" 5 #include "base/macros.h"
6 #include "extensions/common/manifest_constants.h" 6 #include "extensions/common/manifest_constants.h"
7 #include "extensions/common/manifest_handlers/file_handler_info.h" 7 #include "extensions/common/manifest_handlers/file_handler_info.h"
8 #include "extensions/common/manifest_test.h" 8 #include "extensions/common/manifest_test.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace extensions { 11 namespace extensions {
12 12
13 namespace errors = manifest_errors; 13 namespace errors = manifest_errors;
14 14
15 typedef ManifestTest FileHandlersManifestTest; 15 typedef ManifestTest FileHandlersManifestTest;
16 16
17 TEST_F(FileHandlersManifestTest, InvalidFileHandlers) { 17 TEST_F(FileHandlersManifestTest, InvalidFileHandlers) {
18 Testcase testcases[] = { 18 Testcase testcases[] = {
19 Testcase("file_handlers_invalid_handlers.json", 19 Testcase("file_handlers_invalid_handlers.json",
20 errors::kInvalidFileHandlers), 20 errors::kInvalidFileHandlers),
21 Testcase("file_handlers_invalid_type.json", 21 Testcase("file_handlers_invalid_type.json",
22 errors::kInvalidFileHandlerType), 22 errors::kInvalidFileHandlerType),
23 Testcase("file_handlers_invalid_extension.json", 23 Testcase("file_handlers_invalid_extension.json",
24 errors::kInvalidFileHandlerExtension), 24 errors::kInvalidFileHandlerExtension),
25 Testcase("file_handlers_invalid_no_type_or_extension.json", 25 Testcase("file_handlers_invalid_no_type_or_extension.json",
26 errors::kInvalidFileHandlerNoTypeOrExtension), 26 errors::kInvalidFileHandlerNoTypeOrExtension),
27 Testcase("file_handlers_invalid_type_element.json", 27 Testcase("file_handlers_invalid_type_element.json",
28 errors::kInvalidFileHandlerTypeElement), 28 errors::kInvalidFileHandlerTypeElement),
29 Testcase("file_handlers_invalid_extension_element.json", 29 Testcase("file_handlers_invalid_extension_element.json",
30 errors::kInvalidFileHandlerExtensionElement), 30 errors::kInvalidFileHandlerExtensionElement),
31 Testcase("file_handlers_invalid_too_many.json", 31 Testcase("file_handlers_invalid_too_many.json",
32 errors::kInvalidFileHandlersTooManyTypesAndExtensions), 32 errors::kInvalidFileHandlersTooManyTypesAndExtensions),
33 Testcase("file_handlers_invalid_verb.json",
34 errors::kInvalidFileHandlerVerb),
33 }; 35 };
34 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR); 36 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR);
35 } 37 }
36 38
37 TEST_F(FileHandlersManifestTest, ValidFileHandlers) { 39 TEST_F(FileHandlersManifestTest, ValidFileHandlers) {
38 scoped_refptr<const Extension> extension = 40 scoped_refptr<const Extension> extension =
39 LoadAndExpectSuccess("file_handlers_valid.json"); 41 LoadAndExpectSuccess("file_handlers_valid.json");
40 42
41 ASSERT_TRUE(extension.get()); 43 ASSERT_TRUE(extension.get());
42 const FileHandlersInfo* handlers = 44 const FileHandlersInfo* handlers =
43 FileHandlers::GetFileHandlers(extension.get()); 45 FileHandlers::GetFileHandlers(extension.get());
44 ASSERT_TRUE(handlers != NULL); 46 ASSERT_TRUE(handlers != NULL);
45 ASSERT_EQ(2U, handlers->size()); 47 ASSERT_EQ(2U, handlers->size());
46 48
47 FileHandlerInfo handler = handlers->at(0); 49 FileHandlerInfo handler = handlers->at(0);
48 EXPECT_EQ("image", handler.id); 50 EXPECT_EQ("image", handler.id);
49 EXPECT_EQ(1U, handler.types.size()); 51 EXPECT_EQ(1U, handler.types.size());
50 EXPECT_EQ(1U, handler.types.count("image/*")); 52 EXPECT_EQ(1U, handler.types.count("image/*"));
51 EXPECT_EQ(2U, handler.extensions.size()); 53 EXPECT_EQ(2U, handler.extensions.size());
52 EXPECT_EQ(1U, handler.extensions.count(".png")); 54 EXPECT_EQ(1U, handler.extensions.count(".png"));
53 EXPECT_EQ(1U, handler.extensions.count(".gif")); 55 EXPECT_EQ(1U, handler.extensions.count(".gif"));
56 EXPECT_EQ("add_to", handler.verb);
54 57
55 handler = handlers->at(1); 58 handler = handlers->at(1);
56 EXPECT_EQ("text", handler.id); 59 EXPECT_EQ("text", handler.id);
57 EXPECT_EQ(1U, handler.types.size()); 60 EXPECT_EQ(1U, handler.types.size());
58 EXPECT_EQ(1U, handler.types.count("text/*")); 61 EXPECT_EQ(1U, handler.types.count("text/*"));
59 EXPECT_EQ(0U, handler.extensions.size()); 62 EXPECT_EQ(0U, handler.extensions.size());
60 } 63 }
61 64
62 TEST_F(FileHandlersManifestTest, NotPlatformApp) { 65 TEST_F(FileHandlersManifestTest, NotPlatformApp) {
63 // This should load successfully but have the file handlers ignored. 66 // This should load successfully but have the file handlers ignored.
64 scoped_refptr<const Extension> extension = 67 scoped_refptr<const Extension> extension =
65 LoadAndExpectSuccess("file_handlers_invalid_not_app.json"); 68 LoadAndExpectSuccess("file_handlers_invalid_not_app.json");
66 69
67 ASSERT_TRUE(extension.get()); 70 ASSERT_TRUE(extension.get());
68 const FileHandlersInfo* handlers = 71 const FileHandlersInfo* handlers =
69 FileHandlers::GetFileHandlers(extension.get()); 72 FileHandlers::GetFileHandlers(extension.get());
70 ASSERT_TRUE(handlers == NULL); 73 ASSERT_TRUE(handlers == NULL);
71 } 74 }
72 75
73 } // namespace extensions 76 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698