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

Side by Side Diff: chrome/browser/extensions/extensions_service_unittest.cc

Issue 27236: Enforce new id format (hex str of sha-1) (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/json_reader.h" 10 #include "base/json_reader.h"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 103 }
104 104
105 void TestInstallExtension(const FilePath& path, 105 void TestInstallExtension(const FilePath& path,
106 ExtensionsServiceBackend* backend, 106 ExtensionsServiceBackend* backend,
107 bool should_succeed) { 107 bool should_succeed) {
108 ASSERT_TRUE(file_util::PathExists(path)); 108 ASSERT_TRUE(file_util::PathExists(path));
109 backend->InstallExtension(path, install_dir_, false, 109 backend->InstallExtension(path, install_dir_, false,
110 scoped_refptr<ExtensionsServiceFrontendInterface>(this)); 110 scoped_refptr<ExtensionsServiceFrontendInterface>(this));
111 message_loop_.RunAllPending(); 111 message_loop_.RunAllPending();
112 if (should_succeed) { 112 if (should_succeed) {
113 EXPECT_EQ(1u, installed_.size()); 113 EXPECT_EQ(1u, installed_.size()) << path.value();
114 EXPECT_EQ(0u, errors_.size()) << path.value(); 114 EXPECT_EQ(0u, errors_.size()) << path.value();
115 for (std::vector<std::string>::iterator err = errors_.begin();
116 err != errors_.end(); ++err) {
117 LOG(ERROR) << *err;
118 }
115 } else { 119 } else {
116 EXPECT_EQ(0u, installed_.size()); 120 EXPECT_EQ(0u, installed_.size()) << path.value();
117 EXPECT_EQ(1u, errors_.size()); 121 EXPECT_EQ(1u, errors_.size()) << path.value();
118 } 122 }
119 installed_.clear(); 123 installed_.clear();
120 errors_.clear(); 124 errors_.clear();
121 } 125 }
122 126
123 127
124 private: 128 private:
125 MessageLoop message_loop_; 129 MessageLoop message_loop_;
126 ExtensionList extensions_; 130 ExtensionList extensions_;
127 std::vector<std::string> errors_; 131 std::vector<std::string> errors_;
(...skipping 13 matching lines...) Expand all
141 145
142 scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend); 146 scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend);
143 scoped_refptr<ExtensionsServiceTestFrontend> frontend( 147 scoped_refptr<ExtensionsServiceTestFrontend> frontend(
144 new ExtensionsServiceTestFrontend); 148 new ExtensionsServiceTestFrontend);
145 149
146 std::vector<Extension*> extensions; 150 std::vector<Extension*> extensions;
147 backend->LoadExtensionsFromDirectory(extensions_path, 151 backend->LoadExtensionsFromDirectory(extensions_path,
148 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get())); 152 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()));
149 frontend->GetMessageLoop()->RunAllPending(); 153 frontend->GetMessageLoop()->RunAllPending();
150 154
155 std::vector<std::string>* errors = frontend->errors();
156 for (std::vector<std::string>::iterator err = errors->begin();
157 err != errors->end(); ++err) {
158 LOG(ERROR) << *err;
159 }
151 ASSERT_EQ(3u, frontend->extensions()->size()); 160 ASSERT_EQ(3u, frontend->extensions()->size());
152 161
153 EXPECT_EQ(std::string("com.google.myextension1"), 162 EXPECT_EQ(std::string("00123456789ABCDEF0123456789ABCDEF0123456"),
154 frontend->extensions()->at(0)->id()); 163 frontend->extensions()->at(0)->id());
155 EXPECT_EQ(std::string("My extension 1"), 164 EXPECT_EQ(std::string("My extension 1"),
156 frontend->extensions()->at(0)->name()); 165 frontend->extensions()->at(0)->name());
157 EXPECT_EQ(std::string("The first extension that I made."), 166 EXPECT_EQ(std::string("The first extension that I made."),
158 frontend->extensions()->at(0)->description()); 167 frontend->extensions()->at(0)->description());
159 168
160 Extension* extension = frontend->extensions()->at(0); 169 Extension* extension = frontend->extensions()->at(0);
161 const UserScriptList& scripts = extension->content_scripts(); 170 const UserScriptList& scripts = extension->content_scripts();
162 ASSERT_EQ(2u, scripts.size()); 171 ASSERT_EQ(2u, scripts.size());
163 EXPECT_EQ(2u, scripts[0].url_patterns().size()); 172 EXPECT_EQ(2u, scripts[0].url_patterns().size());
164 EXPECT_EQ("http://*.google.com/*", 173 EXPECT_EQ("http://*.google.com/*",
165 scripts[0].url_patterns()[0].GetAsString()); 174 scripts[0].url_patterns()[0].GetAsString());
166 EXPECT_EQ("https://*.google.com/*", 175 EXPECT_EQ("https://*.google.com/*",
167 scripts[0].url_patterns()[1].GetAsString()); 176 scripts[0].url_patterns()[1].GetAsString());
168 EXPECT_EQ(extension->path().AppendASCII("script1.js").value(), 177 EXPECT_EQ(extension->path().AppendASCII("script1.js").value(),
169 scripts[0].path().value()); 178 scripts[0].path().value());
170 EXPECT_EQ(1u, scripts[1].url_patterns().size()); 179 EXPECT_EQ(1u, scripts[1].url_patterns().size());
171 EXPECT_EQ("http://*.yahoo.com/*", scripts[1].url_patterns()[0].GetAsString()); 180 EXPECT_EQ("http://*.yahoo.com/*", scripts[1].url_patterns()[0].GetAsString());
172 EXPECT_EQ(extension->path().AppendASCII("script2.js").value(), 181 EXPECT_EQ(extension->path().AppendASCII("script2.js").value(),
173 scripts[1].path().value()); 182 scripts[1].path().value());
174 183
175 EXPECT_EQ(std::string("com.google.myextension2"), 184 EXPECT_EQ(std::string("10123456789ABCDEF0123456789ABCDEF0123456"),
176 frontend->extensions()->at(1)->id()); 185 frontend->extensions()->at(1)->id());
177 EXPECT_EQ(std::string("My extension 2"), 186 EXPECT_EQ(std::string("My extension 2"),
178 frontend->extensions()->at(1)->name()); 187 frontend->extensions()->at(1)->name());
179 EXPECT_EQ(std::string(""), 188 EXPECT_EQ(std::string(""),
180 frontend->extensions()->at(1)->description()); 189 frontend->extensions()->at(1)->description());
181 EXPECT_EQ(frontend->extensions()->at(1)->path().AppendASCII("npapi").value(), 190 EXPECT_EQ(frontend->extensions()->at(1)->path().AppendASCII("npapi").value(),
182 frontend->extensions()->at(1)->plugins_dir().value()); 191 frontend->extensions()->at(1)->plugins_dir().value());
183 ASSERT_EQ(0u, frontend->extensions()->at(1)->content_scripts().size()); 192 ASSERT_EQ(0u, frontend->extensions()->at(1)->content_scripts().size());
184 193
185 EXPECT_EQ(std::string("com.google.myextension3"), 194 EXPECT_EQ(std::string("20123456789ABCDEF0123456789ABCDEF0123456"),
186 frontend->extensions()->at(2)->id()); 195 frontend->extensions()->at(2)->id());
187 EXPECT_EQ(std::string("My extension 3"), 196 EXPECT_EQ(std::string("My extension 3"),
188 frontend->extensions()->at(2)->name()); 197 frontend->extensions()->at(2)->name());
189 EXPECT_EQ(std::string(""), 198 EXPECT_EQ(std::string(""),
190 frontend->extensions()->at(2)->description()); 199 frontend->extensions()->at(2)->description());
191 ASSERT_EQ(0u, frontend->extensions()->at(2)->content_scripts().size()); 200 ASSERT_EQ(0u, frontend->extensions()->at(2)->content_scripts().size());
192 }; 201 };
193 202
194 // Test loading bad extensions from the profile directory. 203 // Test loading bad extensions from the profile directory.
195 TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectoryFail) { 204 TEST_F(ExtensionsServiceTest, LoadAllExtensionsFromDirectoryFail) {
196 FilePath extensions_path; 205 FilePath extensions_path;
197 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 206 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
198 extensions_path = extensions_path.AppendASCII("extensions"); 207 extensions_path = extensions_path.AppendASCII("extensions");
199 extensions_path = extensions_path.AppendASCII("bad"); 208 extensions_path = extensions_path.AppendASCII("bad");
200 209
201 scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend); 210 scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend);
202 scoped_refptr<ExtensionsServiceTestFrontend> frontend( 211 scoped_refptr<ExtensionsServiceTestFrontend> frontend(
203 new ExtensionsServiceTestFrontend); 212 new ExtensionsServiceTestFrontend);
204 213
205 std::vector<Extension*> extensions; 214 std::vector<Extension*> extensions;
206 backend->LoadExtensionsFromDirectory(extensions_path, 215 backend->LoadExtensionsFromDirectory(extensions_path,
207 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get())); 216 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()));
208 frontend->GetMessageLoop()->RunAllPending(); 217 frontend->GetMessageLoop()->RunAllPending();
209 218
210 EXPECT_EQ(4u, frontend->errors()->size()); 219 EXPECT_EQ(4u, frontend->errors()->size());
211 EXPECT_EQ(0u, frontend->extensions()->size()); 220 EXPECT_EQ(0u, frontend->extensions()->size());
212 221
213 EXPECT_TRUE(MatchPattern(frontend->errors()->at(0), 222 EXPECT_TRUE(MatchPattern(frontend->errors()->at(0),
214 std::string("Could not load extension from '*'. * ") + 223 std::string("Could not load extension from '*'. * ") +
215 JSONReader::kBadRootElementType)); 224 JSONReader::kBadRootElementType)) << frontend->errors()->at(0);
216 225
217 EXPECT_TRUE(MatchPattern(frontend->errors()->at(1), 226 EXPECT_TRUE(MatchPattern(frontend->errors()->at(1),
218 std::string("Could not load extension from '*'. ") + 227 std::string("Could not load extension from '*'. ") +
219 Extension::kInvalidJsListError)); 228 Extension::kInvalidJsListError)) << frontend->errors()->at(1);
220 229
221 EXPECT_TRUE(MatchPattern(frontend->errors()->at(2), 230 EXPECT_TRUE(MatchPattern(frontend->errors()->at(2),
222 std::string("Could not load extension from '*'. ") + 231 std::string("Could not load extension from '*'. ") +
223 Extension::kInvalidManifestError)); 232 Extension::kInvalidManifestError)) << frontend->errors()->at(2);
224 233
225 EXPECT_TRUE(MatchPattern(frontend->errors()->at(3), 234 EXPECT_TRUE(MatchPattern(frontend->errors()->at(3),
226 "Could not load extension from '*'. Could not read '*' file.")); 235 "Could not load extension from '*'. Could not read '*' file.")) <<
236 frontend->errors()->at(3);
227 }; 237 };
228 238
229 // Test installing extensions. 239 // Test installing extensions.
230 TEST_F(ExtensionsServiceTest, InstallExtension) { 240 TEST_F(ExtensionsServiceTest, InstallExtension) {
231 FilePath extensions_path; 241 FilePath extensions_path;
232 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path)); 242 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &extensions_path));
233 extensions_path = extensions_path.AppendASCII("extensions"); 243 extensions_path = extensions_path.AppendASCII("extensions");
234 244
235 scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend); 245 scoped_refptr<ExtensionsServiceBackend> backend(new ExtensionsServiceBackend);
236 scoped_refptr<ExtensionsServiceTestFrontend> frontend( 246 scoped_refptr<ExtensionsServiceTestFrontend> frontend(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 294
285 FilePath no_manifest = extensions_path.AppendASCII("bad") 295 FilePath no_manifest = extensions_path.AppendASCII("bad")
286 .AppendASCII("no_manifest").AppendASCII("1"); 296 .AppendASCII("no_manifest").AppendASCII("1");
287 backend->LoadSingleExtension(no_manifest, 297 backend->LoadSingleExtension(no_manifest,
288 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get())); 298 scoped_refptr<ExtensionsServiceFrontendInterface>(frontend.get()));
289 frontend->GetMessageLoop()->RunAllPending(); 299 frontend->GetMessageLoop()->RunAllPending();
290 EXPECT_EQ(1u, frontend->errors()->size()); 300 EXPECT_EQ(1u, frontend->errors()->size());
291 ASSERT_EQ(1u, frontend->extensions()->size()); 301 ASSERT_EQ(1u, frontend->extensions()->size());
292 } 302 }
293 303
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension.cc ('k') | chrome/test/data/extensions/bad/missing_content_script/1/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698