| 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" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 | 245 |
| 246 // Setup and start the updater. | 246 // Setup and start the updater. |
| 247 MessageLoop message_loop; | 247 MessageLoop message_loop; |
| 248 ChromeThread io_thread(ChromeThread::IO); | 248 ChromeThread io_thread(ChromeThread::IO); |
| 249 io_thread.Start(); | 249 io_thread.Start(); |
| 250 | 250 |
| 251 TestURLFetcherFactory factory; | 251 TestURLFetcherFactory factory; |
| 252 URLFetcher::set_factory(&factory); | 252 URLFetcher::set_factory(&factory); |
| 253 ScopedTempPrefService prefs; | 253 ScopedTempPrefService prefs; |
| 254 scoped_refptr<ExtensionUpdater> updater = | 254 scoped_refptr<ExtensionUpdater> updater = |
| 255 new ExtensionUpdater(&service, prefs.get(), 60*60*24, NULL, NULL); | 255 new ExtensionUpdater(&service, prefs.get(), 60*60*24); |
| 256 updater->Start(); | 256 updater->Start(); |
| 257 | 257 |
| 258 // Tell the update that it's time to do update checks. | 258 // Tell the update that it's time to do update checks. |
| 259 SimulateTimerFired(updater.get()); | 259 SimulateTimerFired(updater.get()); |
| 260 | 260 |
| 261 // Get the url our mock fetcher was asked to fetch. | 261 // Get the url our mock fetcher was asked to fetch. |
| 262 TestURLFetcher* fetcher = | 262 TestURLFetcher* fetcher = |
| 263 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 263 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
| 264 const GURL& url = fetcher->original_url(); | 264 const GURL& url = fetcher->original_url(); |
| 265 EXPECT_FALSE(url.is_empty()); | 265 EXPECT_FALSE(url.is_empty()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 291 | 291 |
| 292 // Setup and start the updater. | 292 // Setup and start the updater. |
| 293 MessageLoop message_loop; | 293 MessageLoop message_loop; |
| 294 ChromeThread io_thread(ChromeThread::IO); | 294 ChromeThread io_thread(ChromeThread::IO); |
| 295 io_thread.Start(); | 295 io_thread.Start(); |
| 296 | 296 |
| 297 TestURLFetcherFactory factory; | 297 TestURLFetcherFactory factory; |
| 298 URLFetcher::set_factory(&factory); | 298 URLFetcher::set_factory(&factory); |
| 299 ScopedTempPrefService prefs; | 299 ScopedTempPrefService prefs; |
| 300 scoped_refptr<ExtensionUpdater> updater = | 300 scoped_refptr<ExtensionUpdater> updater = |
| 301 new ExtensionUpdater(&service, prefs.get(), 60*60*24, NULL, NULL); | 301 new ExtensionUpdater(&service, prefs.get(), 60*60*24); |
| 302 updater->Start(); | 302 updater->Start(); |
| 303 | 303 |
| 304 // Tell the updater that it's time to do update checks. | 304 // Tell the updater that it's time to do update checks. |
| 305 SimulateTimerFired(updater.get()); | 305 SimulateTimerFired(updater.get()); |
| 306 | 306 |
| 307 // Get the url our mock fetcher was asked to fetch. | 307 // Get the url our mock fetcher was asked to fetch. |
| 308 TestURLFetcher* fetcher = | 308 TestURLFetcher* fetcher = |
| 309 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 309 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
| 310 const GURL& url = fetcher->original_url(); | 310 const GURL& url = fetcher->original_url(); |
| 311 | 311 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 334 static void TestDetermineUpdates() { | 334 static void TestDetermineUpdates() { |
| 335 // Create a set of test extensions | 335 // Create a set of test extensions |
| 336 ServiceForManifestTests service; | 336 ServiceForManifestTests service; |
| 337 ExtensionList tmp; | 337 ExtensionList tmp; |
| 338 CreateTestExtensions(3, &tmp, NULL); | 338 CreateTestExtensions(3, &tmp, NULL); |
| 339 service.set_extensions(tmp); | 339 service.set_extensions(tmp); |
| 340 | 340 |
| 341 MessageLoop message_loop; | 341 MessageLoop message_loop; |
| 342 ScopedTempPrefService prefs; | 342 ScopedTempPrefService prefs; |
| 343 scoped_refptr<ExtensionUpdater> updater = | 343 scoped_refptr<ExtensionUpdater> updater = |
| 344 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, | 344 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs); |
| 345 NULL, NULL); | |
| 346 | 345 |
| 347 // Check passing an empty list of parse results to DetermineUpdates | 346 // Check passing an empty list of parse results to DetermineUpdates |
| 348 std::vector<UpdateManifest::Result> updates; | 347 std::vector<UpdateManifest::Result> updates; |
| 349 std::vector<int> updateable = updater->DetermineUpdates(updates); | 348 std::vector<int> updateable = updater->DetermineUpdates(updates); |
| 350 EXPECT_TRUE(updateable.empty()); | 349 EXPECT_TRUE(updateable.empty()); |
| 351 | 350 |
| 352 // Create two updates - expect that DetermineUpdates will return the first | 351 // Create two updates - expect that DetermineUpdates will return the first |
| 353 // one (v1.0 installed, v1.1 available) but not the second one (both | 352 // one (v1.0 installed, v1.1 available) but not the second one (both |
| 354 // installed and available at v2.0). | 353 // installed and available at v2.0). |
| 355 scoped_ptr<Version> one(Version::GetVersionFromString("1.0")); | 354 scoped_ptr<Version> one(Version::GetVersionFromString("1.0")); |
| 356 EXPECT_TRUE(tmp[0]->version()->Equals(*one)); | 355 EXPECT_TRUE(tmp[0]->version()->Equals(*one)); |
| 357 AddParseResult(tmp[0]->id(), | 356 AddParseResult(tmp[0]->id(), |
| 358 "1.1", "http://localhost/e1_1.1.crx", &updates); | 357 "1.1", "http://localhost/e1_1.1.crx", &updates); |
| 359 AddParseResult(tmp[1]->id(), | 358 AddParseResult(tmp[1]->id(), |
| 360 tmp[1]->VersionString(), "http://localhost/e2_2.0.crx", &updates); | 359 tmp[1]->VersionString(), "http://localhost/e2_2.0.crx", &updates); |
| 361 updateable = updater->DetermineUpdates(updates); | 360 updateable = updater->DetermineUpdates(updates); |
| 362 EXPECT_EQ(1u, updateable.size()); | 361 EXPECT_EQ(1u, updateable.size()); |
| 363 EXPECT_EQ(0, updateable[0]); | 362 EXPECT_EQ(0, updateable[0]); |
| 364 STLDeleteElements(&tmp); | 363 STLDeleteElements(&tmp); |
| 365 } | 364 } |
| 366 | 365 |
| 367 static void TestMultipleManifestDownloading() { | 366 static void TestMultipleManifestDownloading() { |
| 368 MessageLoop ui_loop; | 367 MessageLoop ui_loop; |
| 368 ChromeThread ui_thread(ChromeThread::UI, &ui_loop); |
| 369 ChromeThread file_thread(ChromeThread::FILE); | 369 ChromeThread file_thread(ChromeThread::FILE); |
| 370 file_thread.Start(); | 370 file_thread.Start(); |
| 371 ChromeThread io_thread(ChromeThread::IO); | 371 ChromeThread io_thread(ChromeThread::IO); |
| 372 io_thread.Start(); | 372 io_thread.Start(); |
| 373 | 373 |
| 374 TestURLFetcherFactory factory; | 374 TestURLFetcherFactory factory; |
| 375 TestURLFetcher* fetcher = NULL; | 375 TestURLFetcher* fetcher = NULL; |
| 376 URLFetcher::set_factory(&factory); | 376 URLFetcher::set_factory(&factory); |
| 377 ServiceForDownloadTests service; | 377 ServiceForDownloadTests service; |
| 378 ScopedTempPrefService prefs; | 378 ScopedTempPrefService prefs; |
| 379 scoped_refptr<ExtensionUpdater> updater = | 379 scoped_refptr<ExtensionUpdater> updater = |
| 380 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, | 380 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs); |
| 381 file_thread.message_loop(), | |
| 382 io_thread.message_loop()); | |
| 383 | 381 |
| 384 GURL url1("http://localhost/manifest1"); | 382 GURL url1("http://localhost/manifest1"); |
| 385 GURL url2("http://localhost/manifest2"); | 383 GURL url2("http://localhost/manifest2"); |
| 386 | 384 |
| 387 // Request 2 update checks - the first should begin immediately and the | 385 // Request 2 update checks - the first should begin immediately and the |
| 388 // second one should be queued up. | 386 // second one should be queued up. |
| 389 updater->StartUpdateCheck(url1); | 387 updater->StartUpdateCheck(url1); |
| 390 updater->StartUpdateCheck(url2); | 388 updater->StartUpdateCheck(url2); |
| 391 | 389 |
| 392 std::string invalid_xml = "invalid xml"; | 390 std::string invalid_xml = "invalid xml"; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 420 // kValidXml. | 418 // kValidXml. |
| 421 file_thread.Stop(); | 419 file_thread.Stop(); |
| 422 io_thread.Stop(); | 420 io_thread.Stop(); |
| 423 ui_loop.RunAllPending(); | 421 ui_loop.RunAllPending(); |
| 424 EXPECT_EQ("12345", service.last_inquired_extension_id()); | 422 EXPECT_EQ("12345", service.last_inquired_extension_id()); |
| 425 xmlCleanupGlobals(); | 423 xmlCleanupGlobals(); |
| 426 } | 424 } |
| 427 | 425 |
| 428 static void TestSingleExtensionDownloading() { | 426 static void TestSingleExtensionDownloading() { |
| 429 MessageLoop ui_loop; | 427 MessageLoop ui_loop; |
| 428 ChromeThread ui_thread(ChromeThread::UI, &ui_loop); |
| 430 ChromeThread file_thread(ChromeThread::FILE); | 429 ChromeThread file_thread(ChromeThread::FILE); |
| 431 file_thread.Start(); | 430 file_thread.Start(); |
| 432 ChromeThread io_thread(ChromeThread::IO); | 431 ChromeThread io_thread(ChromeThread::IO); |
| 433 io_thread.Start(); | 432 io_thread.Start(); |
| 434 | 433 |
| 435 TestURLFetcherFactory factory; | 434 TestURLFetcherFactory factory; |
| 436 TestURLFetcher* fetcher = NULL; | 435 TestURLFetcher* fetcher = NULL; |
| 437 URLFetcher::set_factory(&factory); | 436 URLFetcher::set_factory(&factory); |
| 438 ServiceForDownloadTests service; | 437 ServiceForDownloadTests service; |
| 439 ScopedTempPrefService prefs; | 438 ScopedTempPrefService prefs; |
| 440 scoped_refptr<ExtensionUpdater> updater = | 439 scoped_refptr<ExtensionUpdater> updater = |
| 441 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, | 440 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs); |
| 442 file_thread.message_loop(), NULL); | |
| 443 | 441 |
| 444 GURL test_url("http://localhost/extension.crx"); | 442 GURL test_url("http://localhost/extension.crx"); |
| 445 | 443 |
| 446 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 444 std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 447 std::string hash = ""; | 445 std::string hash = ""; |
| 448 std::string version = "0.0.1"; | 446 std::string version = "0.0.1"; |
| 449 | 447 |
| 450 updater->FetchUpdatedExtension(id, test_url, hash, version); | 448 updater->FetchUpdatedExtension(id, test_url, hash, version); |
| 451 | 449 |
| 452 // Call back the ExtensionUpdater with a 200 response and some test data | 450 // Call back the ExtensionUpdater with a 200 response and some test data |
| (...skipping 16 matching lines...) Expand all Loading... |
| 469 std::string file_contents; | 467 std::string file_contents; |
| 470 EXPECT_TRUE(file_util::ReadFileToString(tmpfile_path, &file_contents)); | 468 EXPECT_TRUE(file_util::ReadFileToString(tmpfile_path, &file_contents)); |
| 471 EXPECT_TRUE(extension_data == file_contents); | 469 EXPECT_TRUE(extension_data == file_contents); |
| 472 | 470 |
| 473 file_util::Delete(tmpfile_path, false); | 471 file_util::Delete(tmpfile_path, false); |
| 474 URLFetcher::set_factory(NULL); | 472 URLFetcher::set_factory(NULL); |
| 475 } | 473 } |
| 476 | 474 |
| 477 static void TestBlacklistDownloading() { | 475 static void TestBlacklistDownloading() { |
| 478 MessageLoop message_loop; | 476 MessageLoop message_loop; |
| 477 ChromeThread ui_thread(ChromeThread::UI, &message_loop); |
| 479 ChromeThread io_thread(ChromeThread::IO); | 478 ChromeThread io_thread(ChromeThread::IO); |
| 480 io_thread.Start(); | 479 io_thread.Start(); |
| 481 | 480 |
| 482 TestURLFetcherFactory factory; | 481 TestURLFetcherFactory factory; |
| 483 TestURLFetcher* fetcher = NULL; | 482 TestURLFetcher* fetcher = NULL; |
| 484 URLFetcher::set_factory(&factory); | 483 URLFetcher::set_factory(&factory); |
| 485 ServiceForBlacklistTests service; | 484 ServiceForBlacklistTests service; |
| 486 ScopedTempPrefService prefs; | 485 ScopedTempPrefService prefs; |
| 487 scoped_refptr<ExtensionUpdater> updater = | 486 scoped_refptr<ExtensionUpdater> updater = |
| 488 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, | 487 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs); |
| 489 NULL, NULL); | |
| 490 prefs.get()-> | 488 prefs.get()-> |
| 491 RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, L"0"); | 489 RegisterStringPref(prefs::kExtensionBlacklistUpdateVersion, L"0"); |
| 492 GURL test_url("http://localhost/extension.crx"); | 490 GURL test_url("http://localhost/extension.crx"); |
| 493 | 491 |
| 494 std::string id = "com.google.crx.blacklist"; | 492 std::string id = "com.google.crx.blacklist"; |
| 495 | 493 |
| 496 std::string hash = | 494 std::string hash = |
| 497 "2CE109E9D0FAF820B2434E166297934E6177B65AB9951DBC3E204CAD4689B39C"; | 495 "2CE109E9D0FAF820B2434E166297934E6177B65AB9951DBC3E204CAD4689B39C"; |
| 498 | 496 |
| 499 std::string version = "0.0.1"; | 497 std::string version = "0.0.1"; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 516 EXPECT_TRUE(service.processed_blacklist()); | 514 EXPECT_TRUE(service.processed_blacklist()); |
| 517 | 515 |
| 518 EXPECT_EQ(version, WideToASCII(prefs.get()-> | 516 EXPECT_EQ(version, WideToASCII(prefs.get()-> |
| 519 GetString(prefs::kExtensionBlacklistUpdateVersion))); | 517 GetString(prefs::kExtensionBlacklistUpdateVersion))); |
| 520 | 518 |
| 521 URLFetcher::set_factory(NULL); | 519 URLFetcher::set_factory(NULL); |
| 522 } | 520 } |
| 523 | 521 |
| 524 static void TestMultipleExtensionDownloading() { | 522 static void TestMultipleExtensionDownloading() { |
| 525 MessageLoopForUI message_loop; | 523 MessageLoopForUI message_loop; |
| 524 ChromeThread ui_thread(ChromeThread::UI, &message_loop); |
| 525 ChromeThread file_thread(ChromeThread::FILE, &message_loop); |
| 526 ChromeThread io_thread(ChromeThread::IO); | 526 ChromeThread io_thread(ChromeThread::IO); |
| 527 io_thread.Start(); | 527 io_thread.Start(); |
| 528 | 528 |
| 529 TestURLFetcherFactory factory; | 529 TestURLFetcherFactory factory; |
| 530 TestURLFetcher* fetcher = NULL; | 530 TestURLFetcher* fetcher = NULL; |
| 531 URLFetcher::set_factory(&factory); | 531 URLFetcher::set_factory(&factory); |
| 532 ServiceForDownloadTests service; | 532 ServiceForDownloadTests service; |
| 533 ScopedTempPrefService prefs; | 533 ScopedTempPrefService prefs; |
| 534 scoped_refptr<ExtensionUpdater> updater = | 534 scoped_refptr<ExtensionUpdater> updater = |
| 535 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs, | 535 new ExtensionUpdater(&service, prefs.get(), kUpdateFrequencySecs); |
| 536 &message_loop, NULL); | |
| 537 | 536 |
| 538 GURL url1("http://localhost/extension1.crx"); | 537 GURL url1("http://localhost/extension1.crx"); |
| 539 GURL url2("http://localhost/extension2.crx"); | 538 GURL url2("http://localhost/extension2.crx"); |
| 540 | 539 |
| 541 std::string id1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 540 std::string id1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 542 std::string id2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; | 541 std::string id2 = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; |
| 543 | 542 |
| 544 std::string hash1 = ""; | 543 std::string hash1 = ""; |
| 545 std::string hash2 = ""; | 544 std::string hash2 = ""; |
| 546 | 545 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 // -prodversionmin (shouldn't update if browser version too old) | 627 // -prodversionmin (shouldn't update if browser version too old) |
| 629 // -manifests & updates arriving out of order / interleaved | 628 // -manifests & updates arriving out of order / interleaved |
| 630 // -Profile::GetDefaultRequestContext() returning null | 629 // -Profile::GetDefaultRequestContext() returning null |
| 631 // (should not crash, but just do check later) | 630 // (should not crash, but just do check later) |
| 632 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 631 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 633 // -An extension gets uninstalled while updates are in progress (so it doesn't | 632 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 634 // "come back from the dead") | 633 // "come back from the dead") |
| 635 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 634 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 636 // you don't get downgraded accidentally) | 635 // you don't get downgraded accidentally) |
| 637 // -An update manifest mentions multiple updates | 636 // -An update manifest mentions multiple updates |
| OLD | NEW |