Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / common / extensions / manifest_tests / extension_manifests_initvalue_unittest.cc
blobc82a41ea4e8a5580fe277895d8763ca66b69bfc1
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
3 // found in the LICENSE file.
5 #include "base/i18n/rtl.h"
6 #include "base/path_service.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/common/chrome_paths.h"
9 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
10 #include "chrome/common/extensions/manifest_url_handler.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/manifest_constants.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/base/l10n/l10n_util.h"
16 namespace extensions {
18 namespace errors = manifest_errors;
19 namespace keys = manifest_keys;
21 class InitValueManifestTest : public ExtensionManifestTest {
24 TEST_F(InitValueManifestTest, InitFromValueInvalid) {
25 Testcase testcases[] = {
26 Testcase("init_invalid_version_missing.json", errors::kInvalidVersion),
27 Testcase("init_invalid_version_invalid.json", errors::kInvalidVersion),
28 Testcase("init_invalid_name_missing.json", errors::kInvalidName),
29 Testcase("init_invalid_name_invalid.json", errors::kInvalidName),
30 Testcase("init_invalid_description_invalid.json",
31 errors::kInvalidDescription),
32 Testcase("init_invalid_icons_invalid.json", errors::kInvalidIcons),
33 Testcase("init_invalid_icons_path_invalid.json", errors::kInvalidIconPath),
34 Testcase("init_invalid_script_invalid.json",
35 errors::kInvalidContentScriptsList),
36 Testcase("init_invalid_script_item_invalid.json",
37 errors::kInvalidContentScript),
38 Testcase("init_invalid_script_matches_missing.json",
39 errors::kInvalidMatches),
40 Testcase("init_invalid_script_matches_invalid.json",
41 errors::kInvalidMatches),
42 Testcase("init_invalid_script_matches_empty.json",
43 errors::kInvalidMatchCount),
44 Testcase("init_invalid_script_match_item_invalid.json",
45 errors::kInvalidMatch),
46 Testcase("init_invalid_script_match_item_invalid_2.json",
47 errors::kInvalidMatch),
48 Testcase("init_invalid_script_files_missing.json", errors::kMissingFile),
49 Testcase("init_invalid_files_js_invalid.json", errors::kInvalidJsList),
50 Testcase("init_invalid_files_empty.json", errors::kMissingFile),
51 Testcase("init_invalid_files_js_empty_css_missing.json",
52 errors::kMissingFile),
53 Testcase("init_invalid_files_js_item_invalid.json", errors::kInvalidJs),
54 Testcase("init_invalid_files_css_invalid.json", errors::kInvalidCssList),
55 Testcase("init_invalid_files_css_item_invalid.json", errors::kInvalidCss),
56 Testcase("init_invalid_permissions_invalid.json",
57 errors::kInvalidPermissions),
58 Testcase("init_invalid_permissions_item_invalid.json",
59 errors::kInvalidPermission),
60 Testcase("init_invalid_page_actions_multi.json",
61 errors::kInvalidPageActionsListSize),
62 Testcase("init_invalid_options_url_invalid.json",
63 errors::kInvalidOptionsPage),
64 Testcase("init_invalid_locale_invalid.json", errors::kInvalidDefaultLocale),
65 Testcase("init_invalid_locale_empty.json", errors::kInvalidDefaultLocale),
66 Testcase("init_invalid_min_chrome_invalid.json",
67 errors::kInvalidMinimumChromeVersion),
68 Testcase("init_invalid_chrome_version_too_low.json",
69 errors::kChromeVersionTooLow),
70 Testcase("init_invalid_short_name_empty.json",
71 errors::kInvalidShortName),
72 Testcase("init_invalid_short_name_type.json",
73 errors::kInvalidShortName),
76 RunTestcases(testcases, arraysize(testcases),
77 EXPECT_TYPE_ERROR);
80 TEST_F(InitValueManifestTest, InitFromValueValid) {
81 scoped_refptr<Extension> extension(LoadAndExpectSuccess(
82 "init_valid_minimal.json"));
84 base::FilePath path;
85 PathService::Get(chrome::DIR_TEST_DATA, &path);
86 path = path.AppendASCII("extensions");
88 EXPECT_TRUE(Extension::IdIsValid(extension->id()));
89 EXPECT_EQ("1.0.0.0", extension->VersionString());
90 EXPECT_EQ("my extension", extension->name());
91 EXPECT_EQ(extension->name(), extension->short_name());
92 EXPECT_EQ(extension->id(), extension->url().host());
93 EXPECT_EQ(extension->path(), path);
94 EXPECT_EQ(path, extension->path());
96 // Test permissions scheme.
97 // We allow unknown API permissions, so this will be valid until we better
98 // distinguish between API and host permissions.
99 LoadAndExpectSuccess("init_valid_permissions.json");
101 // Test with an options page.
102 extension = LoadAndExpectSuccess("init_valid_options.json");
103 EXPECT_EQ("chrome-extension",
104 ManifestURL::GetOptionsPage(extension.get()).scheme());
105 EXPECT_EQ("/options.html",
106 ManifestURL::GetOptionsPage(extension.get()).path());
108 // Test optional short_name field.
109 extension = LoadAndExpectSuccess("init_valid_short_name.json");
110 EXPECT_EQ("a very descriptive extension name", extension->name());
111 EXPECT_EQ("concise name", extension->short_name());
113 Testcase testcases[] = {
114 // Test that an empty list of page actions does not stop a browser action
115 // from being loaded.
116 Testcase("init_valid_empty_page_actions.json"),
118 // Test with a minimum_chrome_version.
119 Testcase("init_valid_minimum_chrome.json"),
121 // Test a hosted app with a minimum_chrome_version.
122 Testcase("init_valid_app_minimum_chrome.json"),
124 // Test a hosted app with a requirements section.
125 Testcase("init_valid_app_requirements.json"),
127 // Verify empty permission settings are considered valid.
128 Testcase("init_valid_permissions_empty.json"),
130 // We allow unknown API permissions, so this will be valid until we better
131 // distinguish between API and host permissions.
132 Testcase("init_valid_permissions_unknown.json")
135 RunTestcases(testcases, arraysize(testcases),
136 EXPECT_TYPE_SUCCESS);
139 TEST_F(InitValueManifestTest, InitFromValueValidNameInRTL) {
140 std::string locale = l10n_util::GetApplicationLocale("");
141 base::i18n::SetICUDefaultLocale("he");
143 // No strong RTL characters in name.
144 scoped_refptr<Extension> extension(LoadAndExpectSuccess(
145 "init_valid_name_no_rtl.json"));
147 base::string16 localized_name(base::ASCIIToUTF16("Dictionary (by Google)"));
148 base::i18n::AdjustStringForLocaleDirection(&localized_name);
149 EXPECT_EQ(localized_name, base::UTF8ToUTF16(extension->name()));
151 // Strong RTL characters in name.
152 extension = LoadAndExpectSuccess("init_valid_name_strong_rtl.json");
154 localized_name = base::WideToUTF16(L"Dictionary (\x05D1\x05D2" L" Google)");
155 base::i18n::AdjustStringForLocaleDirection(&localized_name);
156 EXPECT_EQ(localized_name, base::UTF8ToUTF16(extension->name()));
158 // Reset locale.
159 base::i18n::SetICUDefaultLocale(locale);
162 } // namespace extensions