OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/manifest_tests/extension_manifest_test.h" | 5 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
10 #include "chrome/common/extensions/extension_error_utils.h" | |
11 #include "chrome/common/extensions/extension_manifest_constants.h" | 10 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 11 #include "extensions/common/error_utils.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace errors = extension_manifest_errors; | 14 namespace errors = extension_manifest_errors; |
15 | 15 |
| 16 using extensions::ErrorUtils; |
| 17 |
16 TEST_F(ExtensionManifestTest, AppLaunchContainer) { | 18 TEST_F(ExtensionManifestTest, AppLaunchContainer) { |
17 scoped_refptr<extensions::Extension> extension; | 19 scoped_refptr<extensions::Extension> extension; |
18 | 20 |
19 extension = LoadAndExpectSuccess("launch_tab.json"); | 21 extension = LoadAndExpectSuccess("launch_tab.json"); |
20 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); | 22 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); |
21 | 23 |
22 extension = LoadAndExpectSuccess("launch_panel.json"); | 24 extension = LoadAndExpectSuccess("launch_panel.json"); |
23 EXPECT_EQ(extension_misc::LAUNCH_PANEL, extension->launch_container()); | 25 EXPECT_EQ(extension_misc::LAUNCH_PANEL, extension->launch_container()); |
24 | 26 |
25 extension = LoadAndExpectSuccess("launch_default.json"); | 27 extension = LoadAndExpectSuccess("launch_default.json"); |
26 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); | 28 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); |
27 | 29 |
28 extension = LoadAndExpectSuccess("launch_width.json"); | 30 extension = LoadAndExpectSuccess("launch_width.json"); |
29 EXPECT_EQ(640, extension->launch_width()); | 31 EXPECT_EQ(640, extension->launch_width()); |
30 | 32 |
31 extension = LoadAndExpectSuccess("launch_height.json"); | 33 extension = LoadAndExpectSuccess("launch_height.json"); |
32 EXPECT_EQ(480, extension->launch_height()); | 34 EXPECT_EQ(480, extension->launch_height()); |
33 | 35 |
34 Testcase testcases[] = { | 36 Testcase testcases[] = { |
35 Testcase("launch_window.json", errors::kInvalidLaunchContainer), | 37 Testcase("launch_window.json", errors::kInvalidLaunchContainer), |
36 Testcase("launch_container_invalid_type.json", | 38 Testcase("launch_container_invalid_type.json", |
37 errors::kInvalidLaunchContainer), | 39 errors::kInvalidLaunchContainer), |
38 Testcase("launch_container_invalid_value.json", | 40 Testcase("launch_container_invalid_value.json", |
39 errors::kInvalidLaunchContainer), | 41 errors::kInvalidLaunchContainer), |
40 Testcase("launch_container_without_launch_url.json", | 42 Testcase("launch_container_without_launch_url.json", |
41 errors::kLaunchURLRequired), | 43 errors::kLaunchURLRequired), |
42 Testcase("launch_width_invalid.json", | 44 Testcase("launch_width_invalid.json", |
43 ExtensionErrorUtils::FormatErrorMessage( | 45 ErrorUtils::FormatErrorMessage( |
44 errors::kInvalidLaunchValueContainer, | 46 errors::kInvalidLaunchValueContainer, |
45 keys::kLaunchWidth)), | 47 keys::kLaunchWidth)), |
46 Testcase("launch_width_negative.json", | 48 Testcase("launch_width_negative.json", |
47 ExtensionErrorUtils::FormatErrorMessage( | 49 ErrorUtils::FormatErrorMessage( |
48 errors::kInvalidLaunchValue, | 50 errors::kInvalidLaunchValue, |
49 keys::kLaunchWidth)), | 51 keys::kLaunchWidth)), |
50 Testcase("launch_height_invalid.json", | 52 Testcase("launch_height_invalid.json", |
51 ExtensionErrorUtils::FormatErrorMessage( | 53 ErrorUtils::FormatErrorMessage( |
52 errors::kInvalidLaunchValueContainer, | 54 errors::kInvalidLaunchValueContainer, |
53 keys::kLaunchHeight)), | 55 keys::kLaunchHeight)), |
54 Testcase("launch_height_negative.json", | 56 Testcase("launch_height_negative.json", |
55 ExtensionErrorUtils::FormatErrorMessage( | 57 ErrorUtils::FormatErrorMessage( |
56 errors::kInvalidLaunchValue, | 58 errors::kInvalidLaunchValue, |
57 keys::kLaunchHeight)) | 59 keys::kLaunchHeight)) |
58 }; | 60 }; |
59 RunTestcases(testcases, arraysize(testcases), | 61 RunTestcases(testcases, arraysize(testcases), |
60 EXPECT_TYPE_ERROR); | 62 EXPECT_TYPE_ERROR); |
61 } | 63 } |
62 | 64 |
63 TEST_F(ExtensionManifestTest, AppLaunchURL) { | 65 TEST_F(ExtensionManifestTest, AppLaunchURL) { |
64 Testcase testcases[] = { | 66 Testcase testcases[] = { |
65 Testcase("launch_path_and_url.json", | 67 Testcase("launch_path_and_url.json", |
66 errors::kLaunchPathAndURLAreExclusive), | 68 errors::kLaunchPathAndURLAreExclusive), |
67 Testcase("launch_path_and_extent.json", | 69 Testcase("launch_path_and_extent.json", |
68 errors::kLaunchPathAndExtentAreExclusive), | 70 errors::kLaunchPathAndExtentAreExclusive), |
69 Testcase("launch_path_invalid_type.json", | 71 Testcase("launch_path_invalid_type.json", |
70 ExtensionErrorUtils::FormatErrorMessage( | 72 ErrorUtils::FormatErrorMessage( |
71 errors::kInvalidLaunchValue, | 73 errors::kInvalidLaunchValue, |
72 keys::kLaunchLocalPath)), | 74 keys::kLaunchLocalPath)), |
73 Testcase("launch_path_invalid_value.json", | 75 Testcase("launch_path_invalid_value.json", |
74 ExtensionErrorUtils::FormatErrorMessage( | 76 ErrorUtils::FormatErrorMessage( |
75 errors::kInvalidLaunchValue, | 77 errors::kInvalidLaunchValue, |
76 keys::kLaunchLocalPath)), | 78 keys::kLaunchLocalPath)), |
77 Testcase("launch_path_invalid_localized.json", | 79 Testcase("launch_path_invalid_localized.json", |
78 ExtensionErrorUtils::FormatErrorMessage( | 80 ErrorUtils::FormatErrorMessage( |
79 errors::kInvalidLaunchValue, | 81 errors::kInvalidLaunchValue, |
80 keys::kLaunchLocalPath)), | 82 keys::kLaunchLocalPath)), |
81 Testcase("launch_url_invalid_type_1.json", | 83 Testcase("launch_url_invalid_type_1.json", |
82 ExtensionErrorUtils::FormatErrorMessage( | 84 ErrorUtils::FormatErrorMessage( |
83 errors::kInvalidLaunchValue, | 85 errors::kInvalidLaunchValue, |
84 keys::kLaunchWebURL)), | 86 keys::kLaunchWebURL)), |
85 Testcase("launch_url_invalid_type_2.json", | 87 Testcase("launch_url_invalid_type_2.json", |
86 ExtensionErrorUtils::FormatErrorMessage( | 88 ErrorUtils::FormatErrorMessage( |
87 errors::kInvalidLaunchValue, | 89 errors::kInvalidLaunchValue, |
88 keys::kLaunchWebURL)), | 90 keys::kLaunchWebURL)), |
89 Testcase("launch_url_invalid_type_3.json", | 91 Testcase("launch_url_invalid_type_3.json", |
90 ExtensionErrorUtils::FormatErrorMessage( | 92 ErrorUtils::FormatErrorMessage( |
91 errors::kInvalidLaunchValue, | 93 errors::kInvalidLaunchValue, |
92 keys::kLaunchWebURL)), | 94 keys::kLaunchWebURL)), |
93 Testcase("launch_url_invalid_localized.json", | 95 Testcase("launch_url_invalid_localized.json", |
94 ExtensionErrorUtils::FormatErrorMessage( | 96 ErrorUtils::FormatErrorMessage( |
95 errors::kInvalidLaunchValue, | 97 errors::kInvalidLaunchValue, |
96 keys::kLaunchWebURL)) | 98 keys::kLaunchWebURL)) |
97 }; | 99 }; |
98 RunTestcases(testcases, arraysize(testcases), | 100 RunTestcases(testcases, arraysize(testcases), |
99 EXPECT_TYPE_ERROR); | 101 EXPECT_TYPE_ERROR); |
100 | 102 |
101 scoped_refptr<extensions::Extension> extension; | 103 scoped_refptr<extensions::Extension> extension; |
102 extension = LoadAndExpectSuccess("launch_local_path.json"); | 104 extension = LoadAndExpectSuccess("launch_local_path.json"); |
103 EXPECT_EQ(extension->url().spec() + "launch.html", | 105 EXPECT_EQ(extension->url().spec() + "launch.html", |
104 extension->GetFullLaunchURL().spec()); | 106 extension->GetFullLaunchURL().spec()); |
105 | 107 |
106 extension = LoadAndExpectSuccess("launch_local_path_localized.json"); | 108 extension = LoadAndExpectSuccess("launch_local_path_localized.json"); |
107 EXPECT_EQ(extension->url().spec() + "launch.html", | 109 EXPECT_EQ(extension->url().spec() + "launch.html", |
108 extension->GetFullLaunchURL().spec()); | 110 extension->GetFullLaunchURL().spec()); |
109 | 111 |
110 LoadAndExpectError("launch_web_url_relative.json", | 112 LoadAndExpectError("launch_web_url_relative.json", |
111 ExtensionErrorUtils::FormatErrorMessage( | 113 ErrorUtils::FormatErrorMessage( |
112 errors::kInvalidLaunchValue, | 114 errors::kInvalidLaunchValue, |
113 keys::kLaunchWebURL)); | 115 keys::kLaunchWebURL)); |
114 | 116 |
115 extension = LoadAndExpectSuccess("launch_web_url_absolute.json"); | 117 extension = LoadAndExpectSuccess("launch_web_url_absolute.json"); |
116 EXPECT_EQ(GURL("http://www.google.com/launch.html"), | 118 EXPECT_EQ(GURL("http://www.google.com/launch.html"), |
117 extension->GetFullLaunchURL()); | 119 extension->GetFullLaunchURL()); |
118 extension = LoadAndExpectSuccess("launch_web_url_localized.json"); | 120 extension = LoadAndExpectSuccess("launch_web_url_localized.json"); |
119 EXPECT_EQ(GURL("http://www.google.com/launch.html"), | 121 EXPECT_EQ(GURL("http://www.google.com/launch.html"), |
120 extension->GetFullLaunchURL()); | 122 extension->GetFullLaunchURL()); |
121 } | 123 } |
OLD | NEW |