Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <list> | 5 #include <list> |
| 6 #include <map> | 6 #include <map> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 #include "chrome/browser/extensions/updater/extension_updater.h" | 38 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 39 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" | 39 #include "chrome/browser/extensions/updater/manifest_fetch_data.h" |
| 40 #include "chrome/browser/extensions/updater/request_queue_impl.h" | 40 #include "chrome/browser/extensions/updater/request_queue_impl.h" |
| 41 #include "chrome/browser/google/google_util.h" | 41 #include "chrome/browser/google/google_util.h" |
| 42 #include "chrome/browser/prefs/pref_service_syncable.h" | 42 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 43 #include "chrome/common/chrome_notification_types.h" | 43 #include "chrome/common/chrome_notification_types.h" |
| 44 #include "chrome/common/extensions/extension.h" | 44 #include "chrome/common/extensions/extension.h" |
| 45 #include "chrome/common/extensions/extension_manifest_constants.h" | 45 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 46 #include "chrome/common/extensions/manifest_handler.h" | 46 #include "chrome/common/extensions/manifest_handler.h" |
| 47 #include "chrome/common/extensions/manifest_url_handler.h" | 47 #include "chrome/common/extensions/manifest_url_handler.h" |
| 48 #include "chrome/common/omaha_query_params.h" | |
| 48 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
| 49 #include "chrome/test/base/testing_profile.h" | 50 #include "chrome/test/base/testing_profile.h" |
| 50 #include "content/public/browser/notification_details.h" | 51 #include "content/public/browser/notification_details.h" |
| 51 #include "content/public/browser/notification_observer.h" | 52 #include "content/public/browser/notification_observer.h" |
| 52 #include "content/public/browser/notification_registrar.h" | 53 #include "content/public/browser/notification_registrar.h" |
| 53 #include "content/public/browser/notification_service.h" | 54 #include "content/public/browser/notification_service.h" |
| 54 #include "content/public/browser/notification_source.h" | 55 #include "content/public/browser/notification_source.h" |
| 55 #include "content/public/test/test_browser_thread.h" | 56 #include "content/public/test/test_browser_thread.h" |
| 56 #include "libxml/globals.h" | 57 #include "libxml/globals.h" |
| 57 #include "net/base/backoff_entry.h" | 58 #include "net/base/backoff_entry.h" |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 if (!key_val.empty()) { | 437 if (!key_val.empty()) { |
| 437 std::string key = key_val[0]; | 438 std::string key = key_val[0]; |
| 438 EXPECT_TRUE(result->find(key) == result->end()); | 439 EXPECT_TRUE(result->find(key) == result->end()); |
| 439 (*result)[key] = (key_val.size() == 2) ? key_val[1] : ""; | 440 (*result)[key] = (key_val.size() == 2) ? key_val[1] : ""; |
| 440 } else { | 441 } else { |
| 441 NOTREACHED(); | 442 NOTREACHED(); |
| 442 } | 443 } |
| 443 } | 444 } |
| 444 } | 445 } |
| 445 | 446 |
| 447 static void VerifyQueryAndExtractParameters( | |
| 448 const std::string& query, | |
| 449 std::map<std::string, std::string>* result) { | |
| 450 std::map<std::string, std::string> params; | |
| 451 ExtractParameters(query, ¶ms); | |
| 452 | |
| 453 #if defined(GOOGLE_CHROME_BUILD) | |
| 454 std::string prod = "chromecrx"; | |
| 455 #else | |
| 456 std::string prod = "chromiumcrx"; | |
| 457 #endif | |
| 458 std::string omaha_params = chrome::GetOmahaQueryParams(prod); | |
| 459 std::map<std::string, std::string> expected; | |
| 460 ExtractParameters(omaha_params, &expected); | |
| 461 | |
| 462 for (std::map<std::string, std::string>::iterator it = expected.begin(); | |
| 463 it != expected.end(); ++it) { | |
| 464 EXPECT_EQ(it->second, params[it->first]); | |
| 465 } | |
| 466 | |
| 467 EXPECT_NE(params.find("x"), params.end()); | |
| 468 std::string decoded = net::UnescapeURLComponent( | |
| 469 params["x"], net::UnescapeRule::URL_SPECIAL_CHARS); | |
| 470 ExtractParameters(decoded, result); | |
| 471 } | |
| 472 | |
| 446 // All of our tests that need to use private APIs of ExtensionUpdater live | 473 // All of our tests that need to use private APIs of ExtensionUpdater live |
| 447 // inside this class (which is a friend to ExtensionUpdater). | 474 // inside this class (which is a friend to ExtensionUpdater). |
| 448 class ExtensionUpdaterTest : public testing::Test { | 475 class ExtensionUpdaterTest : public testing::Test { |
| 449 public: | 476 public: |
| 450 ExtensionUpdaterTest() | 477 ExtensionUpdaterTest() |
| 451 : ui_thread_(BrowserThread::UI, &loop_), | 478 : ui_thread_(BrowserThread::UI, &loop_), |
| 452 file_thread_(BrowserThread::FILE, &loop_), | 479 file_thread_(BrowserThread::FILE, &loop_), |
| 453 io_thread_(BrowserThread::IO, &loop_) { | 480 io_thread_(BrowserThread::IO, &loop_) { |
| 454 } | 481 } |
| 455 | 482 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 net::TestURLFetcher* fetcher = | 574 net::TestURLFetcher* fetcher = |
| 548 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); | 575 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); |
| 549 const GURL& url = fetcher->GetOriginalURL(); | 576 const GURL& url = fetcher->GetOriginalURL(); |
| 550 EXPECT_FALSE(url.is_empty()); | 577 EXPECT_FALSE(url.is_empty()); |
| 551 EXPECT_TRUE(url.is_valid()); | 578 EXPECT_TRUE(url.is_valid()); |
| 552 EXPECT_TRUE(url.SchemeIs("http")); | 579 EXPECT_TRUE(url.SchemeIs("http")); |
| 553 EXPECT_EQ("foo.com", url.host()); | 580 EXPECT_EQ("foo.com", url.host()); |
| 554 EXPECT_EQ("/bar", url.path()); | 581 EXPECT_EQ("/bar", url.path()); |
| 555 | 582 |
| 556 // Validate the extension request parameters in the query. It should | 583 // Validate the extension request parameters in the query. It should |
| 557 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". | 584 // look something like "x=id%3D<id>%26v%3D<version>%26uc". |
| 558 EXPECT_TRUE(url.has_query()); | 585 EXPECT_TRUE(url.has_query()); |
| 559 std::vector<std::string> parts; | |
| 560 base::SplitString(url.query(), '=', &parts); | |
| 561 EXPECT_EQ(2u, parts.size()); | |
| 562 EXPECT_EQ("x", parts[0]); | |
| 563 std::string decoded = net::UnescapeURLComponent( | |
| 564 parts[1], net::UnescapeRule::URL_SPECIAL_CHARS); | |
| 565 std::map<std::string, std::string> params; | 586 std::map<std::string, std::string> params; |
| 566 ExtractParameters(decoded, ¶ms); | 587 VerifyQueryAndExtractParameters(url.query(), ¶ms); |
| 567 if (pending) { | 588 if (pending) { |
| 568 EXPECT_TRUE(pending_extension_manager->IsIdPending(params["id"])); | 589 EXPECT_TRUE(pending_extension_manager->IsIdPending(params["id"])); |
| 569 EXPECT_EQ("0.0.0.0", params["v"]); | 590 EXPECT_EQ("0.0.0.0", params["v"]); |
| 570 } else { | 591 } else { |
| 571 EXPECT_EQ(extensions[0]->id(), params["id"]); | 592 EXPECT_EQ(extensions[0]->id(), params["id"]); |
| 572 EXPECT_EQ(extensions[0]->VersionString(), params["v"]); | 593 EXPECT_EQ(extensions[0]->VersionString(), params["v"]); |
| 573 } | 594 } |
| 574 EXPECT_EQ("", params["uc"]); | 595 EXPECT_EQ("", params["uc"]); |
| 575 } | 596 } |
| 576 | 597 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 596 ASSERT_FALSE(fetcher == NULL); | 617 ASSERT_FALSE(fetcher == NULL); |
| 597 const GURL& url = fetcher->GetOriginalURL(); | 618 const GURL& url = fetcher->GetOriginalURL(); |
| 598 | 619 |
| 599 EXPECT_FALSE(url.is_empty()); | 620 EXPECT_FALSE(url.is_empty()); |
| 600 EXPECT_TRUE(url.is_valid()); | 621 EXPECT_TRUE(url.is_valid()); |
| 601 EXPECT_TRUE(url.SchemeIs("https")); | 622 EXPECT_TRUE(url.SchemeIs("https")); |
| 602 EXPECT_EQ("clients2.google.com", url.host()); | 623 EXPECT_EQ("clients2.google.com", url.host()); |
| 603 EXPECT_EQ("/service/update2/crx", url.path()); | 624 EXPECT_EQ("/service/update2/crx", url.path()); |
| 604 | 625 |
| 605 // Validate the extension request parameters in the query. It should | 626 // Validate the extension request parameters in the query. It should |
| 606 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". | 627 // look something like "x=id%3D<id>%26v%3D<version>%26uc". |
| 607 EXPECT_TRUE(url.has_query()); | 628 EXPECT_TRUE(url.has_query()); |
| 608 std::vector<std::string> parts; | |
| 609 base::SplitString(url.query(), '=', &parts); | |
| 610 EXPECT_EQ(2u, parts.size()); | |
| 611 EXPECT_EQ("x", parts[0]); | |
| 612 std::string decoded = net::UnescapeURLComponent( | |
| 613 parts[1], net::UnescapeRule::URL_SPECIAL_CHARS); | |
| 614 std::map<std::string, std::string> params; | 629 std::map<std::string, std::string> params; |
| 615 ExtractParameters(decoded, ¶ms); | 630 VerifyQueryAndExtractParameters(url.query(), ¶ms); |
| 616 EXPECT_EQ("com.google.crx.blacklist", params["id"]); | 631 EXPECT_EQ("com.google.crx.blacklist", params["id"]); |
| 617 EXPECT_EQ("0", params["v"]); | 632 EXPECT_EQ("0", params["v"]); |
| 618 EXPECT_EQ("", params["uc"]); | 633 EXPECT_EQ("", params["uc"]); |
| 619 EXPECT_TRUE(ContainsKey(params, "ping")); | 634 EXPECT_TRUE(ContainsKey(params, "ping")); |
| 620 } | 635 } |
| 621 | 636 |
| 622 void TestUpdateUrlDataEmpty() { | 637 void TestUpdateUrlDataEmpty() { |
| 623 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 638 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 624 const std::string version = "1.0"; | 639 const std::string version = "1.0"; |
| 625 | 640 |
| 626 // Make sure that an empty update URL data string does not cause a ap= | 641 // Make sure that an empty update URL data string does not cause a ap= |
| 627 // option to appear in the x= parameter. | 642 // option to appear in the x= parameter. |
| 628 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 643 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
| 629 fetch_data.AddExtension(id, version, &kNeverPingedData, "", ""); | 644 fetch_data.AddExtension(id, version, &kNeverPingedData, "", ""); |
| 630 EXPECT_EQ("http://localhost/foo\?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | 645 |
| 631 "%26v%3D1.0%26uc", | 646 std::map<std::string, std::string> params; |
| 632 fetch_data.full_url().spec()); | 647 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); |
| 648 EXPECT_EQ(id, params["id"]); | |
| 649 EXPECT_EQ(version, params["v"]); | |
| 650 EXPECT_EQ(params.end(), params.find("ap")); | |
|
asargent_no_longer_on_chrome
2013/03/06 00:45:06
nice cleanup - this is much more readable!
| |
| 633 } | 651 } |
| 634 | 652 |
| 635 void TestUpdateUrlDataSimple() { | 653 void TestUpdateUrlDataSimple() { |
| 636 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 654 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 637 const std::string version = "1.0"; | 655 const std::string version = "1.0"; |
| 638 | 656 |
| 639 // Make sure that an update URL data string causes an appropriate ap= | 657 // Make sure that an update URL data string causes an appropriate ap= |
| 640 // option to appear in the x= parameter. | 658 // option to appear in the x= parameter. |
| 641 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 659 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
| 642 fetch_data.AddExtension(id, version, &kNeverPingedData, "bar", ""); | 660 fetch_data.AddExtension(id, version, &kNeverPingedData, "bar", ""); |
| 643 EXPECT_EQ("http://localhost/foo\?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | 661 std::map<std::string, std::string> params; |
| 644 "%26v%3D1.0%26uc%26ap%3Dbar", | 662 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); |
| 645 fetch_data.full_url().spec()); | 663 EXPECT_EQ(id, params["id"]); |
| 664 EXPECT_EQ(version, params["v"]); | |
| 665 EXPECT_EQ("bar", params["ap"]); | |
| 646 } | 666 } |
| 647 | 667 |
| 648 void TestUpdateUrlDataCompound() { | 668 void TestUpdateUrlDataCompound() { |
| 649 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 669 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 650 const std::string version = "1.0"; | 670 const std::string version = "1.0"; |
| 651 | 671 |
| 652 // Make sure that an update URL data string causes an appropriate ap= | 672 // Make sure that an update URL data string causes an appropriate ap= |
| 653 // option to appear in the x= parameter. | 673 // option to appear in the x= parameter. |
| 654 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 674 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
| 655 fetch_data.AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", ""); | 675 fetch_data.AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", ""); |
| 656 EXPECT_EQ("http://localhost/foo\?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | 676 std::map<std::string, std::string> params; |
| 657 "%26v%3D1.0%26uc%26ap%3Da%253D1%2526b%253D2%2526c", | 677 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); |
| 658 fetch_data.full_url().spec()); | 678 EXPECT_EQ(id, params["id"]); |
| 679 EXPECT_EQ(version, params["v"]); | |
| 680 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]); | |
| 659 } | 681 } |
| 660 | 682 |
| 661 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { | 683 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { |
| 662 net::TestURLFetcherFactory factory; | 684 net::TestURLFetcherFactory factory; |
| 663 | 685 |
| 664 MockService service(prefs_.get()); | 686 MockService service(prefs_.get()); |
| 665 MockExtensionDownloaderDelegate delegate; | 687 MockExtensionDownloaderDelegate delegate; |
| 666 ExtensionDownloader downloader(&delegate, service.request_context()); | 688 ExtensionDownloader downloader(&delegate, service.request_context()); |
| 667 ExtensionList extensions; | 689 ExtensionList extensions; |
| 668 std::string url(gallery_url); | 690 std::string url(gallery_url); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 688 | 710 |
| 689 void TestInstallSource() { | 711 void TestInstallSource() { |
| 690 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 712 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 691 const std::string version = "1.0"; | 713 const std::string version = "1.0"; |
| 692 const std::string install_source = "instally"; | 714 const std::string install_source = "instally"; |
| 693 | 715 |
| 694 // Make sure that an installsource= appears in the x= parameter. | 716 // Make sure that an installsource= appears in the x= parameter. |
| 695 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 717 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
| 696 fetch_data.AddExtension(id, version, &kNeverPingedData, | 718 fetch_data.AddExtension(id, version, &kNeverPingedData, |
| 697 kEmptyUpdateUrlData, install_source); | 719 kEmptyUpdateUrlData, install_source); |
| 698 EXPECT_EQ("http://localhost/foo\?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" | 720 std::map<std::string, std::string> params; |
| 699 "%26v%3D1.0%26installsource%3Dinstally%26uc", | 721 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), ¶ms); |
| 700 fetch_data.full_url().spec()); | 722 EXPECT_EQ(id, params["id"]); |
| 723 EXPECT_EQ(version, params["v"]); | |
| 724 EXPECT_EQ(install_source, params["installsource"]); | |
| 701 } | 725 } |
| 702 | 726 |
| 703 void TestDetermineUpdates() { | 727 void TestDetermineUpdates() { |
| 704 TestingProfile profile; | 728 TestingProfile profile; |
| 705 profile.CreateRequestContext(); | 729 profile.CreateRequestContext(); |
| 706 MockExtensionDownloaderDelegate delegate; | 730 MockExtensionDownloaderDelegate delegate; |
| 707 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); | 731 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); |
| 708 | 732 |
| 709 // Check passing an empty list of parse results to DetermineUpdates | 733 // Check passing an empty list of parse results to DetermineUpdates |
| 710 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); | 734 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); |
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1693 // -prodversionmin (shouldn't update if browser version too old) | 1717 // -prodversionmin (shouldn't update if browser version too old) |
| 1694 // -manifests & updates arriving out of order / interleaved | 1718 // -manifests & updates arriving out of order / interleaved |
| 1695 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 1719 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 1696 // -An extension gets uninstalled while updates are in progress (so it doesn't | 1720 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 1697 // "come back from the dead") | 1721 // "come back from the dead") |
| 1698 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 1722 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 1699 // you don't get downgraded accidentally) | 1723 // you don't get downgraded accidentally) |
| 1700 // -An update manifest mentions multiple updates | 1724 // -An update manifest mentions multiple updates |
| 1701 | 1725 |
| 1702 } // namespace extensions | 1726 } // namespace extensions |
| OLD | NEW |