OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/thread.h" | 11 #include "base/thread.h" |
| 12 #include "chrome/browser/chrome_thread.h" |
12 #include "chrome/browser/extensions/extension_updater.h" | 13 #include "chrome/browser/extensions/extension_updater.h" |
13 #include "chrome/browser/extensions/extensions_service.h" | 14 #include "chrome/browser/extensions/extensions_service.h" |
14 #include "chrome/browser/net/test_url_fetcher_factory.h" | 15 #include "chrome/browser/net/test_url_fetcher_factory.h" |
15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/extensions/extension_constants.h" | 17 #include "chrome/common/extensions/extension_constants.h" |
17 #include "chrome/common/extensions/extension_error_reporter.h" | 18 #include "chrome/common/extensions/extension_error_reporter.h" |
18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
19 #include "chrome/common/pref_service.h" | 20 #include "chrome/common/pref_service.h" |
20 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
21 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 | 228 |
228 static void TestExtensionUpdateCheckRequests() { | 229 static void TestExtensionUpdateCheckRequests() { |
229 // Create an extension with an update_url. | 230 // Create an extension with an update_url. |
230 ServiceForManifestTests service; | 231 ServiceForManifestTests service; |
231 ExtensionList tmp; | 232 ExtensionList tmp; |
232 std::string update_url("http://foo.com/bar"); | 233 std::string update_url("http://foo.com/bar"); |
233 CreateTestExtensions(1, &tmp, &update_url); | 234 CreateTestExtensions(1, &tmp, &update_url); |
234 service.set_extensions(tmp); | 235 service.set_extensions(tmp); |
235 | 236 |
236 // Setup and start the updater. | 237 // Setup and start the updater. |
| 238 MessageLoop message_loop; |
| 239 ChromeThread io_thread(ChromeThread::IO); |
| 240 io_thread.Start(); |
| 241 |
237 TestURLFetcherFactory factory; | 242 TestURLFetcherFactory factory; |
238 URLFetcher::set_factory(&factory); | 243 URLFetcher::set_factory(&factory); |
239 MessageLoop message_loop; | |
240 ScopedTempPrefService prefs; | 244 ScopedTempPrefService prefs; |
241 scoped_refptr<ExtensionUpdater> updater = | 245 scoped_refptr<ExtensionUpdater> updater = |
242 new ExtensionUpdater(&service, prefs.get(), 60*60*24, NULL, NULL); | 246 new ExtensionUpdater(&service, prefs.get(), 60*60*24, NULL, NULL); |
243 updater->Start(); | 247 updater->Start(); |
244 | 248 |
245 // Tell the update that it's time to do update checks. | 249 // Tell the update that it's time to do update checks. |
246 SimulateTimerFired(updater.get()); | 250 SimulateTimerFired(updater.get()); |
247 | 251 |
248 // Get the url our mock fetcher was asked to fetch. | 252 // Get the url our mock fetcher was asked to fetch. |
249 TestURLFetcher* fetcher = | 253 TestURLFetcher* fetcher = |
(...skipping 20 matching lines...) Expand all Loading... |
270 EXPECT_EQ(tmp[0]->VersionString(), params["v"]); | 274 EXPECT_EQ(tmp[0]->VersionString(), params["v"]); |
271 EXPECT_EQ("", params["uc"]); | 275 EXPECT_EQ("", params["uc"]); |
272 | 276 |
273 STLDeleteElements(&tmp); | 277 STLDeleteElements(&tmp); |
274 } | 278 } |
275 | 279 |
276 static void TestBlacklistUpdateCheckRequests() { | 280 static void TestBlacklistUpdateCheckRequests() { |
277 ServiceForManifestTests service; | 281 ServiceForManifestTests service; |
278 | 282 |
279 // Setup and start the updater. | 283 // Setup and start the updater. |
| 284 MessageLoop message_loop; |
| 285 ChromeThread io_thread(ChromeThread::IO); |
| 286 io_thread.Start(); |
| 287 |
280 TestURLFetcherFactory factory; | 288 TestURLFetcherFactory factory; |
281 URLFetcher::set_factory(&factory); | 289 URLFetcher::set_factory(&factory); |
282 MessageLoop message_loop; | |
283 ScopedTempPrefService prefs; | 290 ScopedTempPrefService prefs; |
284 scoped_refptr<ExtensionUpdater> updater = | 291 scoped_refptr<ExtensionUpdater> updater = |
285 new ExtensionUpdater(&service, prefs.get(), 60*60*24, NULL, NULL); | 292 new ExtensionUpdater(&service, prefs.get(), 60*60*24, NULL, NULL); |
286 updater->Start(); | 293 updater->Start(); |
287 | 294 |
288 // Tell the updater that it's time to do update checks. | 295 // Tell the updater that it's time to do update checks. |
289 SimulateTimerFired(updater.get()); | 296 SimulateTimerFired(updater.get()); |
290 | 297 |
291 // Get the url our mock fetcher was asked to fetch. | 298 // Get the url our mock fetcher was asked to fetch. |
292 TestURLFetcher* fetcher = | 299 TestURLFetcher* fetcher = |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 "1.1", "http://localhost/e1_1.1.crx", &updates); | 349 "1.1", "http://localhost/e1_1.1.crx", &updates); |
343 AddParseResult(tmp[1]->id(), | 350 AddParseResult(tmp[1]->id(), |
344 tmp[1]->VersionString(), "http://localhost/e2_2.0.crx", &updates); | 351 tmp[1]->VersionString(), "http://localhost/e2_2.0.crx", &updates); |
345 updateable = updater->DetermineUpdates(updates); | 352 updateable = updater->DetermineUpdates(updates); |
346 EXPECT_EQ(1u, updateable.size()); | 353 EXPECT_EQ(1u, updateable.size()); |
347 EXPECT_EQ(0, updateable[0]); | 354 EXPECT_EQ(0, updateable[0]); |
348 STLDeleteElements(&tmp); | 355 STLDeleteElements(&tmp); |
349 } | 356 } |
350 | 357 |
351 static void TestMultipleManifestDownloading() { | 358 static void TestMultipleManifestDownloading() { |
| 359 MessageLoop ui_loop; |
| 360 ChromeThread file_thread(ChromeThread::FILE); |
| 361 file_thread.Start(); |
| 362 ChromeThread io_thread(ChromeThread::IO); |
| 363 io_thread.Start(); |
| 364 |
352 TestURLFetcherFactory factory; | 365 TestURLFetcherFactory factory; |
353 TestURLFetcher* fetcher = NULL; | 366 TestURLFetcher* fetcher = NULL; |
354 URLFetcher::set_factory(&factory); | 367 URLFetcher::set_factory(&factory); |
355 ServiceForDownloadTests service; | 368 ServiceForDownloadTests service; |
356 MessageLoop ui_loop; | |
357 base::Thread file_thread("File Thread"); | |
358 ASSERT_TRUE(file_thread.Start()); | |
359 base::Thread io_thread("IO Thread"); | |
360 ASSERT_TRUE(io_thread.Start()); | |
361 ScopedTempPrefService prefs; | 369 ScopedTempPrefService prefs; |
362 scoped_refptr<ExtensionUpdater> updater = | 370 scoped_refptr<ExtensionUpdater> updater = |
363 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, | 371 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, |
364 file_thread.message_loop(), | 372 file_thread.message_loop(), |
365 io_thread.message_loop()); | 373 io_thread.message_loop()); |
366 | 374 |
367 GURL url1("http://localhost/manifest1"); | 375 GURL url1("http://localhost/manifest1"); |
368 GURL url2("http://localhost/manifest2"); | 376 GURL url2("http://localhost/manifest2"); |
369 | 377 |
370 // Request 2 update checks - the first should begin immediately and the | 378 // Request 2 update checks - the first should begin immediately and the |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 // kValidXml. | 411 // kValidXml. |
404 file_thread.Stop(); | 412 file_thread.Stop(); |
405 io_thread.Stop(); | 413 io_thread.Stop(); |
406 ui_loop.RunAllPending(); | 414 ui_loop.RunAllPending(); |
407 EXPECT_EQ("12345", service.last_inquired_extension_id()); | 415 EXPECT_EQ("12345", service.last_inquired_extension_id()); |
408 xmlCleanupGlobals(); | 416 xmlCleanupGlobals(); |
409 } | 417 } |
410 | 418 |
411 static void TestSingleExtensionDownloading() { | 419 static void TestSingleExtensionDownloading() { |
412 MessageLoop ui_loop; | 420 MessageLoop ui_loop; |
413 base::Thread file_thread("File Thread"); | 421 ChromeThread file_thread(ChromeThread::FILE); |
414 ASSERT_TRUE(file_thread.Start()); | 422 file_thread.Start(); |
| 423 ChromeThread io_thread(ChromeThread::IO); |
| 424 io_thread.Start(); |
415 | 425 |
416 TestURLFetcherFactory factory; | 426 TestURLFetcherFactory factory; |
417 TestURLFetcher* fetcher = NULL; | 427 TestURLFetcher* fetcher = NULL; |
418 URLFetcher::set_factory(&factory); | 428 URLFetcher::set_factory(&factory); |
419 ServiceForDownloadTests service; | 429 ServiceForDownloadTests service; |
420 ScopedTempPrefService prefs; | 430 ScopedTempPrefService prefs; |
421 scoped_refptr<ExtensionUpdater> updater = | 431 scoped_refptr<ExtensionUpdater> updater = |
422 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, | 432 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, |
423 file_thread.message_loop(), NULL); | 433 file_thread.message_loop(), NULL); |
424 | 434 |
(...skipping 25 matching lines...) Expand all Loading... |
450 std::string file_contents; | 460 std::string file_contents; |
451 EXPECT_TRUE(file_util::ReadFileToString(tmpfile_path, &file_contents)); | 461 EXPECT_TRUE(file_util::ReadFileToString(tmpfile_path, &file_contents)); |
452 EXPECT_TRUE(extension_data == file_contents); | 462 EXPECT_TRUE(extension_data == file_contents); |
453 | 463 |
454 file_util::Delete(tmpfile_path, false); | 464 file_util::Delete(tmpfile_path, false); |
455 URLFetcher::set_factory(NULL); | 465 URLFetcher::set_factory(NULL); |
456 } | 466 } |
457 | 467 |
458 static void TestBlacklistDownloading() { | 468 static void TestBlacklistDownloading() { |
459 MessageLoop message_loop; | 469 MessageLoop message_loop; |
| 470 ChromeThread io_thread(ChromeThread::IO); |
| 471 io_thread.Start(); |
| 472 |
460 TestURLFetcherFactory factory; | 473 TestURLFetcherFactory factory; |
461 TestURLFetcher* fetcher = NULL; | 474 TestURLFetcher* fetcher = NULL; |
462 URLFetcher::set_factory(&factory); | 475 URLFetcher::set_factory(&factory); |
463 ServiceForBlacklistTests service; | 476 ServiceForBlacklistTests service; |
464 ScopedTempPrefService prefs; | 477 ScopedTempPrefService prefs; |
465 scoped_refptr<ExtensionUpdater> updater = | 478 scoped_refptr<ExtensionUpdater> updater = |
466 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, | 479 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, |
467 NULL, NULL); | 480 NULL, NULL); |
468 prefs.get()-> | 481 prefs.get()-> |
469 RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, L"0"); | 482 RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, L"0"); |
(...skipping 24 matching lines...) Expand all Loading... |
494 EXPECT_TRUE(service.processed_blacklist()); | 507 EXPECT_TRUE(service.processed_blacklist()); |
495 | 508 |
496 EXPECT_EQ(version, WideToASCII(prefs.get()-> | 509 EXPECT_EQ(version, WideToASCII(prefs.get()-> |
497 GetString(prefs::kExtensionBlacklistUpdateVersion))); | 510 GetString(prefs::kExtensionBlacklistUpdateVersion))); |
498 | 511 |
499 URLFetcher::set_factory(NULL); | 512 URLFetcher::set_factory(NULL); |
500 } | 513 } |
501 | 514 |
502 static void TestMultipleExtensionDownloading() { | 515 static void TestMultipleExtensionDownloading() { |
503 MessageLoopForUI message_loop; | 516 MessageLoopForUI message_loop; |
| 517 ChromeThread io_thread(ChromeThread::IO); |
| 518 io_thread.Start(); |
| 519 |
504 TestURLFetcherFactory factory; | 520 TestURLFetcherFactory factory; |
505 TestURLFetcher* fetcher = NULL; | 521 TestURLFetcher* fetcher = NULL; |
506 URLFetcher::set_factory(&factory); | 522 URLFetcher::set_factory(&factory); |
507 ServiceForDownloadTests service; | 523 ServiceForDownloadTests service; |
508 ScopedTempPrefService prefs; | 524 ScopedTempPrefService prefs; |
509 scoped_refptr<ExtensionUpdater> updater = | 525 scoped_refptr<ExtensionUpdater> updater = |
510 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, | 526 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, |
511 &message_loop, NULL); | 527 &message_loop, NULL); |
512 | 528 |
513 GURL url1("http://localhost/extension1.crx"); | 529 GURL url1("http://localhost/extension1.crx"); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 // -prodversionmin (shouldn't update if browser version too old) | 617 // -prodversionmin (shouldn't update if browser version too old) |
602 // -manifests & updates arriving out of order / interleaved | 618 // -manifests & updates arriving out of order / interleaved |
603 // -Profile::GetDefaultRequestContext() returning null | 619 // -Profile::GetDefaultRequestContext() returning null |
604 // (should not crash, but just do check later) | 620 // (should not crash, but just do check later) |
605 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 621 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
606 // -An extension gets uninstalled while updates are in progress (so it doesn't | 622 // -An extension gets uninstalled while updates are in progress (so it doesn't |
607 // "come back from the dead") | 623 // "come back from the dead") |
608 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 624 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
609 // you don't get downgraded accidentally) | 625 // you don't get downgraded accidentally) |
610 // -An update manifest mentions multiple updates | 626 // -An update manifest mentions multiple updates |
OLD | NEW |