Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / common / extensions / manifest_tests / extension_manifests_initvalue_unittest.cc
blob28f06880471248875d103411b8e11c4d0206e72f
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/command_line.h"
6 #include "base/i18n/rtl.h"
7 #include "base/path_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/common/chrome_paths.h"
10 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
11 #include "components/crx_file/id_util.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/features/simple_feature.h"
14 #include "extensions/common/manifest_constants.h"
15 #include "extensions/common/manifest_handlers/options_page_info.h"
16 #include "extensions/common/switches.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/base/l10n/l10n_util.h"
20 namespace extensions {
22 namespace {
24 // The ID of test manifests requiring whitelisting.
25 const char kWhitelistID[] = "lmadimbbgapmngbiclpjjngmdickadpl";
27 } // namespace
29 namespace errors = manifest_errors;
30 namespace keys = manifest_keys;
32 class InitValueManifestTest : public ChromeManifestTest {
35 TEST_F(InitValueManifestTest, InitFromValueInvalid) {
36 extensions::SimpleFeature::ScopedWhitelistForTest whitelist(kWhitelistID);
37 Testcase testcases[] = {
38 Testcase("init_invalid_version_missing.json", errors::kInvalidVersion),
39 Testcase("init_invalid_version_invalid.json", errors::kInvalidVersion),
40 Testcase("init_invalid_version_name_invalid.json",
41 errors::kInvalidVersionName),
42 Testcase("init_invalid_name_missing.json", errors::kInvalidName),
43 Testcase("init_invalid_name_invalid.json", errors::kInvalidName),
44 Testcase("init_invalid_description_invalid.json",
45 errors::kInvalidDescription),
46 Testcase("init_invalid_icons_invalid.json", errors::kInvalidIcons),
47 Testcase("init_invalid_icons_path_invalid.json",
48 errors::kInvalidIconPath),
49 Testcase("init_invalid_launcher_page_invalid.json",
50 errors::kInvalidLauncherPage),
51 Testcase("init_invalid_launcher_page_page_missing.json",
52 errors::kLauncherPagePageRequired),
53 Testcase("init_invalid_launcher_page_page_invalid.json",
54 errors::kInvalidLauncherPagePage),
55 Testcase("init_invalid_script_invalid.json",
56 errors::kInvalidContentScriptsList),
57 Testcase("init_invalid_script_item_invalid.json",
58 errors::kInvalidContentScript),
59 Testcase("init_invalid_script_matches_missing.json",
60 errors::kInvalidMatches),
61 Testcase("init_invalid_script_matches_invalid.json",
62 errors::kInvalidMatches),
63 Testcase("init_invalid_script_matches_empty.json",
64 errors::kInvalidMatchCount),
65 Testcase("init_invalid_script_match_item_invalid.json",
66 errors::kInvalidMatch),
67 Testcase("init_invalid_script_match_item_invalid_2.json",
68 errors::kInvalidMatch),
69 Testcase("init_invalid_script_files_missing.json", errors::kMissingFile),
70 Testcase("init_invalid_files_js_invalid.json", errors::kInvalidJsList),
71 Testcase("init_invalid_files_empty.json", errors::kMissingFile),
72 Testcase("init_invalid_files_js_empty_css_missing.json",
73 errors::kMissingFile),
74 Testcase("init_invalid_files_js_item_invalid.json", errors::kInvalidJs),
75 Testcase("init_invalid_files_css_invalid.json", errors::kInvalidCssList),
76 Testcase("init_invalid_files_css_item_invalid.json", errors::kInvalidCss),
77 Testcase("init_invalid_permissions_invalid.json",
78 errors::kInvalidPermissions),
79 Testcase("init_invalid_permissions_item_invalid.json",
80 errors::kInvalidPermission),
81 Testcase("init_invalid_options_url_invalid.json",
82 errors::kInvalidOptionsPage),
83 Testcase("init_invalid_locale_invalid.json",
84 errors::kInvalidDefaultLocale),
85 Testcase("init_invalid_locale_empty.json", errors::kInvalidDefaultLocale),
86 Testcase("init_invalid_min_chrome_invalid.json",
87 errors::kInvalidMinimumChromeVersion),
88 Testcase("init_invalid_chrome_version_too_low.json",
89 errors::kChromeVersionTooLow),
90 Testcase("init_invalid_short_name_empty.json", errors::kInvalidShortName),
91 Testcase("init_invalid_short_name_type.json", errors::kInvalidShortName),
94 RunTestcases(testcases, arraysize(testcases),
95 EXPECT_TYPE_ERROR);
98 TEST_F(InitValueManifestTest, InitFromValueValid) {
99 scoped_refptr<Extension> extension(LoadAndExpectSuccess(
100 "init_valid_minimal.json"));
102 base::FilePath path;
103 PathService::Get(chrome::DIR_TEST_DATA, &path);
104 path = path.AppendASCII("extensions");
106 EXPECT_TRUE(crx_file::id_util::IdIsValid(extension->id()));
107 EXPECT_EQ("1.0.0.0", extension->VersionString());
108 EXPECT_EQ("my extension", extension->name());
109 EXPECT_EQ(extension->name(), extension->short_name());
110 EXPECT_EQ(extension->id(), extension->url().host());
111 EXPECT_EQ(extension->path(), path);
112 EXPECT_EQ(path, extension->path());
114 // Test permissions scheme.
115 // We allow unknown API permissions, so this will be valid until we better
116 // distinguish between API and host permissions.
117 LoadAndExpectSuccess("init_valid_permissions.json");
119 // Test with an options page.
120 extension = LoadAndExpectSuccess("init_valid_options.json");
121 EXPECT_EQ("chrome-extension",
122 OptionsPageInfo::GetOptionsPage(extension.get()).scheme());
123 EXPECT_EQ("/options.html",
124 OptionsPageInfo::GetOptionsPage(extension.get()).path());
126 // Test optional short_name field.
127 extension = LoadAndExpectSuccess("init_valid_short_name.json");
128 EXPECT_EQ("a very descriptive extension name", extension->name());
129 EXPECT_EQ("concise name", extension->short_name());
131 // Test optional version_name field.
132 extension = LoadAndExpectSuccess("init_valid_version_name.json");
133 EXPECT_EQ("1.0.0.0", extension->VersionString());
134 EXPECT_EQ("1.0 alpha", extension->GetVersionForDisplay());
136 Testcase testcases[] = {
137 // Test with a minimum_chrome_version.
138 Testcase("init_valid_minimum_chrome.json"),
140 // Test a hosted app with a minimum_chrome_version.
141 Testcase("init_valid_app_minimum_chrome.json"),
143 // Test a hosted app with a requirements section.
144 Testcase("init_valid_app_requirements.json"),
146 // Verify empty permission settings are considered valid.
147 Testcase("init_valid_permissions_empty.json"),
149 // We allow unknown API permissions, so this will be valid until we better
150 // distinguish between API and host permissions.
151 Testcase("init_valid_permissions_unknown.json")
154 RunTestcases(testcases, arraysize(testcases),
155 EXPECT_TYPE_SUCCESS);
158 TEST_F(InitValueManifestTest, InitFromValueValidNameInRTL) {
159 std::string locale = l10n_util::GetApplicationLocale("");
160 base::i18n::SetICUDefaultLocale("he");
162 // No strong RTL characters in name.
163 scoped_refptr<Extension> extension(LoadAndExpectSuccess(
164 "init_valid_name_no_rtl.json"));
166 base::string16 localized_name(base::ASCIIToUTF16("Dictionary (by Google)"));
167 base::i18n::AdjustStringForLocaleDirection(&localized_name);
168 EXPECT_EQ(localized_name, base::UTF8ToUTF16(extension->name()));
170 // Strong RTL characters in name.
171 extension = LoadAndExpectSuccess("init_valid_name_strong_rtl.json");
173 localized_name = base::WideToUTF16(L"Dictionary (\x05D1\x05D2" L" Google)");
174 base::i18n::AdjustStringForLocaleDirection(&localized_name);
175 EXPECT_EQ(localized_name, base::UTF8ToUTF16(extension->name()));
177 // Reset locale.
178 base::i18n::SetICUDefaultLocale(locale);
181 } // namespace extensions