1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/i18n/rtl.h"
#include "base/path_service.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/api/extension_action/page_action_handler.h"
#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
#include "chrome/common/extensions/manifest_url_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#if defined(TOOLKIT_GTK)
#include <gtk/gtk.h>
#endif
namespace errors = extension_manifest_errors;
namespace keys = extension_manifest_keys;
class InitValueManifestTest : public ExtensionManifestTest {
virtual void SetUp() OVERRIDE {
ExtensionManifestTest::SetUp();
extensions::ManifestHandler::Register(
keys::kOptionsPage,
make_linked_ptr(new extensions::OptionsPageHandler));
extensions::ManifestHandler::Register(
keys::kDefaultLocale,
make_linked_ptr(new extensions::DefaultLocaleHandler));
linked_ptr<extensions::PageActionHandler> page_action_handler(
new extensions::PageActionHandler);
extensions::ManifestHandler::Register(keys::kPageAction, page_action_handler);
extensions::ManifestHandler::Register(
keys::kPageActions, page_action_handler);
}
};
TEST_F(InitValueManifestTest, InitFromValueInvalid) {
Testcase testcases[] = {
Testcase("init_invalid_version_missing.json", errors::kInvalidVersion),
Testcase("init_invalid_version_invalid.json", errors::kInvalidVersion),
Testcase("init_invalid_name_missing.json", errors::kInvalidName),
Testcase("init_invalid_name_invalid.json", errors::kInvalidName),
Testcase("init_invalid_description_invalid.json",
errors::kInvalidDescription),
Testcase("init_invalid_icons_invalid.json", errors::kInvalidIcons),
Testcase("init_invalid_icons_path_invalid.json", errors::kInvalidIconPath),
Testcase("init_invalid_script_invalid.json",
errors::kInvalidContentScriptsList),
Testcase("init_invalid_script_item_invalid.json",
errors::kInvalidContentScript),
Testcase("init_invalid_script_matches_missing.json",
errors::kInvalidMatches),
Testcase("init_invalid_script_matches_invalid.json",
errors::kInvalidMatches),
Testcase("init_invalid_script_matches_empty.json",
errors::kInvalidMatchCount),
Testcase("init_invalid_script_match_item_invalid.json",
errors::kInvalidMatch),
Testcase("init_invalid_script_match_item_invalid_2.json",
errors::kInvalidMatch),
Testcase("init_invalid_script_files_missing.json", errors::kMissingFile),
Testcase("init_invalid_files_js_invalid.json", errors::kInvalidJsList),
Testcase("init_invalid_files_empty.json", errors::kMissingFile),
Testcase("init_invalid_files_js_empty_css_missing.json",
errors::kMissingFile),
Testcase("init_invalid_files_js_item_invalid.json", errors::kInvalidJs),
Testcase("init_invalid_files_css_invalid.json", errors::kInvalidCssList),
Testcase("init_invalid_files_css_item_invalid.json", errors::kInvalidCss),
Testcase("init_invalid_permissions_invalid.json",
errors::kInvalidPermissions),
Testcase("init_invalid_permissions_item_invalid.json",
errors::kInvalidPermission),
Testcase("init_invalid_page_actions_multi.json",
errors::kInvalidPageActionsListSize),
Testcase("init_invalid_options_url_invalid.json",
errors::kInvalidOptionsPage),
Testcase("init_invalid_locale_invalid.json", errors::kInvalidDefaultLocale),
Testcase("init_invalid_locale_empty.json", errors::kInvalidDefaultLocale),
Testcase("init_invalid_min_chrome_invalid.json",
errors::kInvalidMinimumChromeVersion),
Testcase("init_invalid_chrome_version_too_low.json",
errors::kChromeVersionTooLow),
};
RunTestcases(testcases, arraysize(testcases),
EXPECT_TYPE_ERROR);
}
TEST_F(InitValueManifestTest, InitFromValueValid) {
scoped_refptr<extensions::Extension> extension(LoadAndExpectSuccess(
"init_valid_minimal.json"));
base::FilePath path;
PathService::Get(chrome::DIR_TEST_DATA, &path);
path = path.AppendASCII("extensions");
EXPECT_TRUE(extensions::Extension::IdIsValid(extension->id()));
EXPECT_EQ("1.0.0.0", extension->VersionString());
EXPECT_EQ("my extension", extension->name());
EXPECT_EQ(extension->id(), extension->url().host());
EXPECT_EQ(extension->path(), path);
EXPECT_EQ(path, extension->path());
// Test permissions scheme.
// We allow unknown API permissions, so this will be valid until we better
// distinguish between API and host permissions.
LoadAndExpectSuccess("init_valid_permissions.json");
// Test with an options page.
extension = LoadAndExpectSuccess("init_valid_options.json");
EXPECT_EQ("chrome-extension",
extensions::ManifestURL::GetOptionsPage(extension).scheme());
EXPECT_EQ("/options.html",
extensions::ManifestURL::GetOptionsPage(extension).path());
Testcase testcases[] = {
// Test that an empty list of page actions does not stop a browser action
// from being loaded.
Testcase("init_valid_empty_page_actions.json"),
// Test with a minimum_chrome_version.
Testcase("init_valid_minimum_chrome.json"),
// Test a hosted app with a minimum_chrome_version.
Testcase("init_valid_app_minimum_chrome.json"),
// Test a hosted app with a requirements section.
Testcase("init_valid_app_requirements.json"),
// Verify empty permission settings are considered valid.
Testcase("init_valid_permissions_empty.json"),
// We allow unknown API permissions, so this will be valid until we better
// distinguish between API and host permissions.
Testcase("init_valid_permissions_unknown.json")
};
RunTestcases(testcases, arraysize(testcases),
EXPECT_TYPE_SUCCESS);
}
TEST_F(InitValueManifestTest, InitFromValueValidNameInRTL) {
#if defined(TOOLKIT_GTK)
GtkTextDirection gtk_dir = gtk_widget_get_default_direction();
gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL);
#else
std::string locale = l10n_util::GetApplicationLocale("");
base::i18n::SetICUDefaultLocale("he");
#endif
// No strong RTL characters in name.
scoped_refptr<extensions::Extension> extension(LoadAndExpectSuccess(
"init_valid_name_no_rtl.json"));
string16 localized_name(ASCIIToUTF16("Dictionary (by Google)"));
base::i18n::AdjustStringForLocaleDirection(&localized_name);
EXPECT_EQ(localized_name, UTF8ToUTF16(extension->name()));
// Strong RTL characters in name.
extension = LoadAndExpectSuccess("init_valid_name_strong_rtl.json");
localized_name = base::WideToUTF16(L"Dictionary (\x05D1\x05D2"L" Google)");
base::i18n::AdjustStringForLocaleDirection(&localized_name);
EXPECT_EQ(localized_name, UTF8ToUTF16(extension->name()));
// Reset locale.
#if defined(TOOLKIT_GTK)
gtk_widget_set_default_direction(gtk_dir);
#else
base::i18n::SetICUDefaultLocale(locale);
#endif
}
|