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

Side by Side Diff: chrome/browser/extensions/updater/extension_updater_unittest.cc

Issue 12396002: Add chrome version information to extension update checks (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Use count() instead of find() Created 7 years, 9 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
OLDNEW
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
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
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, &params);
452
453 chrome::OmahaQueryParams::ProdId prod =
454 #if defined(GOOGLE_CHROME_BUILD)
455 chrome::OmahaQueryParams::CHROMECRX;
456 #else
457 chrome::OmahaQueryParams::CHROMIUMCRX;
458 #endif
459 std::string omaha_params = chrome::OmahaQueryParams::Get(prod);
460 std::map<std::string, std::string> expected;
461 ExtractParameters(omaha_params, &expected);
462
463 for (std::map<std::string, std::string>::iterator it = expected.begin();
464 it != expected.end(); ++it) {
465 EXPECT_EQ(it->second, params[it->first]);
466 }
467
468 EXPECT_EQ(1U, params.count("x"));
469 std::string decoded = net::UnescapeURLComponent(
470 params["x"], net::UnescapeRule::URL_SPECIAL_CHARS);
471 ExtractParameters(decoded, result);
472 }
473
446 // All of our tests that need to use private APIs of ExtensionUpdater live 474 // All of our tests that need to use private APIs of ExtensionUpdater live
447 // inside this class (which is a friend to ExtensionUpdater). 475 // inside this class (which is a friend to ExtensionUpdater).
448 class ExtensionUpdaterTest : public testing::Test { 476 class ExtensionUpdaterTest : public testing::Test {
449 public: 477 public:
450 ExtensionUpdaterTest() 478 ExtensionUpdaterTest()
451 : ui_thread_(BrowserThread::UI, &loop_), 479 : ui_thread_(BrowserThread::UI, &loop_),
452 file_thread_(BrowserThread::FILE, &loop_), 480 file_thread_(BrowserThread::FILE, &loop_),
453 io_thread_(BrowserThread::IO, &loop_) { 481 io_thread_(BrowserThread::IO, &loop_) {
454 } 482 }
455 483
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 net::TestURLFetcher* fetcher = 575 net::TestURLFetcher* fetcher =
548 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId); 576 factory.GetFetcherByID(ExtensionDownloader::kManifestFetcherId);
549 const GURL& url = fetcher->GetOriginalURL(); 577 const GURL& url = fetcher->GetOriginalURL();
550 EXPECT_FALSE(url.is_empty()); 578 EXPECT_FALSE(url.is_empty());
551 EXPECT_TRUE(url.is_valid()); 579 EXPECT_TRUE(url.is_valid());
552 EXPECT_TRUE(url.SchemeIs("http")); 580 EXPECT_TRUE(url.SchemeIs("http"));
553 EXPECT_EQ("foo.com", url.host()); 581 EXPECT_EQ("foo.com", url.host());
554 EXPECT_EQ("/bar", url.path()); 582 EXPECT_EQ("/bar", url.path());
555 583
556 // Validate the extension request parameters in the query. It should 584 // Validate the extension request parameters in the query. It should
557 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". 585 // look something like "x=id%3D<id>%26v%3D<version>%26uc".
558 EXPECT_TRUE(url.has_query()); 586 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; 587 std::map<std::string, std::string> params;
566 ExtractParameters(decoded, &params); 588 VerifyQueryAndExtractParameters(url.query(), &params);
567 if (pending) { 589 if (pending) {
568 EXPECT_TRUE(pending_extension_manager->IsIdPending(params["id"])); 590 EXPECT_TRUE(pending_extension_manager->IsIdPending(params["id"]));
569 EXPECT_EQ("0.0.0.0", params["v"]); 591 EXPECT_EQ("0.0.0.0", params["v"]);
570 } else { 592 } else {
571 EXPECT_EQ(extensions[0]->id(), params["id"]); 593 EXPECT_EQ(extensions[0]->id(), params["id"]);
572 EXPECT_EQ(extensions[0]->VersionString(), params["v"]); 594 EXPECT_EQ(extensions[0]->VersionString(), params["v"]);
573 } 595 }
574 EXPECT_EQ("", params["uc"]); 596 EXPECT_EQ("", params["uc"]);
575 } 597 }
576 598
(...skipping 19 matching lines...) Expand all
596 ASSERT_FALSE(fetcher == NULL); 618 ASSERT_FALSE(fetcher == NULL);
597 const GURL& url = fetcher->GetOriginalURL(); 619 const GURL& url = fetcher->GetOriginalURL();
598 620
599 EXPECT_FALSE(url.is_empty()); 621 EXPECT_FALSE(url.is_empty());
600 EXPECT_TRUE(url.is_valid()); 622 EXPECT_TRUE(url.is_valid());
601 EXPECT_TRUE(url.SchemeIs("https")); 623 EXPECT_TRUE(url.SchemeIs("https"));
602 EXPECT_EQ("clients2.google.com", url.host()); 624 EXPECT_EQ("clients2.google.com", url.host());
603 EXPECT_EQ("/service/update2/crx", url.path()); 625 EXPECT_EQ("/service/update2/crx", url.path());
604 626
605 // Validate the extension request parameters in the query. It should 627 // Validate the extension request parameters in the query. It should
606 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". 628 // look something like "x=id%3D<id>%26v%3D<version>%26uc".
607 EXPECT_TRUE(url.has_query()); 629 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; 630 std::map<std::string, std::string> params;
615 ExtractParameters(decoded, &params); 631 VerifyQueryAndExtractParameters(url.query(), &params);
616 EXPECT_EQ("com.google.crx.blacklist", params["id"]); 632 EXPECT_EQ("com.google.crx.blacklist", params["id"]);
617 EXPECT_EQ("0", params["v"]); 633 EXPECT_EQ("0", params["v"]);
618 EXPECT_EQ("", params["uc"]); 634 EXPECT_EQ("", params["uc"]);
619 EXPECT_TRUE(ContainsKey(params, "ping")); 635 EXPECT_TRUE(ContainsKey(params, "ping"));
620 } 636 }
621 637
622 void TestUpdateUrlDataEmpty() { 638 void TestUpdateUrlDataEmpty() {
623 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 639 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
624 const std::string version = "1.0"; 640 const std::string version = "1.0";
625 641
626 // Make sure that an empty update URL data string does not cause a ap= 642 // Make sure that an empty update URL data string does not cause a ap=
627 // option to appear in the x= parameter. 643 // option to appear in the x= parameter.
628 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 644 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
629 fetch_data.AddExtension(id, version, &kNeverPingedData, "", ""); 645 fetch_data.AddExtension(id, version, &kNeverPingedData, "", "");
630 EXPECT_EQ("http://localhost/foo\?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 646
631 "%26v%3D1.0%26uc", 647 std::map<std::string, std::string> params;
632 fetch_data.full_url().spec()); 648 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params);
649 EXPECT_EQ(id, params["id"]);
650 EXPECT_EQ(version, params["v"]);
651 EXPECT_EQ(0U, params.count("ap"));
633 } 652 }
634 653
635 void TestUpdateUrlDataSimple() { 654 void TestUpdateUrlDataSimple() {
636 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 655 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
637 const std::string version = "1.0"; 656 const std::string version = "1.0";
638 657
639 // Make sure that an update URL data string causes an appropriate ap= 658 // Make sure that an update URL data string causes an appropriate ap=
640 // option to appear in the x= parameter. 659 // option to appear in the x= parameter.
641 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 660 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
642 fetch_data.AddExtension(id, version, &kNeverPingedData, "bar", ""); 661 fetch_data.AddExtension(id, version, &kNeverPingedData, "bar", "");
643 EXPECT_EQ("http://localhost/foo\?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 662 std::map<std::string, std::string> params;
644 "%26v%3D1.0%26uc%26ap%3Dbar", 663 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params);
645 fetch_data.full_url().spec()); 664 EXPECT_EQ(id, params["id"]);
665 EXPECT_EQ(version, params["v"]);
666 EXPECT_EQ("bar", params["ap"]);
646 } 667 }
647 668
648 void TestUpdateUrlDataCompound() { 669 void TestUpdateUrlDataCompound() {
649 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 670 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
650 const std::string version = "1.0"; 671 const std::string version = "1.0";
651 672
652 // Make sure that an update URL data string causes an appropriate ap= 673 // Make sure that an update URL data string causes an appropriate ap=
653 // option to appear in the x= parameter. 674 // option to appear in the x= parameter.
654 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 675 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
655 fetch_data.AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", ""); 676 fetch_data.AddExtension(id, version, &kNeverPingedData, "a=1&b=2&c", "");
656 EXPECT_EQ("http://localhost/foo\?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 677 std::map<std::string, std::string> params;
657 "%26v%3D1.0%26uc%26ap%3Da%253D1%2526b%253D2%2526c", 678 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params);
658 fetch_data.full_url().spec()); 679 EXPECT_EQ(id, params["id"]);
680 EXPECT_EQ(version, params["v"]);
681 EXPECT_EQ("a%3D1%26b%3D2%26c", params["ap"]);
659 } 682 }
660 683
661 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) { 684 void TestUpdateUrlDataFromGallery(const std::string& gallery_url) {
662 net::TestURLFetcherFactory factory; 685 net::TestURLFetcherFactory factory;
663 686
664 MockService service(prefs_.get()); 687 MockService service(prefs_.get());
665 MockExtensionDownloaderDelegate delegate; 688 MockExtensionDownloaderDelegate delegate;
666 ExtensionDownloader downloader(&delegate, service.request_context()); 689 ExtensionDownloader downloader(&delegate, service.request_context());
667 ExtensionList extensions; 690 ExtensionList extensions;
668 std::string url(gallery_url); 691 std::string url(gallery_url);
(...skipping 19 matching lines...) Expand all
688 711
689 void TestInstallSource() { 712 void TestInstallSource() {
690 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 713 const std::string id = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
691 const std::string version = "1.0"; 714 const std::string version = "1.0";
692 const std::string install_source = "instally"; 715 const std::string install_source = "instally";
693 716
694 // Make sure that an installsource= appears in the x= parameter. 717 // Make sure that an installsource= appears in the x= parameter.
695 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 718 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
696 fetch_data.AddExtension(id, version, &kNeverPingedData, 719 fetch_data.AddExtension(id, version, &kNeverPingedData,
697 kEmptyUpdateUrlData, install_source); 720 kEmptyUpdateUrlData, install_source);
698 EXPECT_EQ("http://localhost/foo\?x=id%3Daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" 721 std::map<std::string, std::string> params;
699 "%26v%3D1.0%26installsource%3Dinstally%26uc", 722 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params);
700 fetch_data.full_url().spec()); 723 EXPECT_EQ(id, params["id"]);
724 EXPECT_EQ(version, params["v"]);
725 EXPECT_EQ(install_source, params["installsource"]);
701 } 726 }
702 727
703 void TestDetermineUpdates() { 728 void TestDetermineUpdates() {
704 TestingProfile profile; 729 TestingProfile profile;
705 profile.CreateRequestContext(); 730 profile.CreateRequestContext();
706 MockExtensionDownloaderDelegate delegate; 731 MockExtensionDownloaderDelegate delegate;
707 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 732 ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
708 733
709 // Check passing an empty list of parse results to DetermineUpdates 734 // Check passing an empty list of parse results to DetermineUpdates
710 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 735 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
1693 // -prodversionmin (shouldn't update if browser version too old) 1718 // -prodversionmin (shouldn't update if browser version too old)
1694 // -manifests & updates arriving out of order / interleaved 1719 // -manifests & updates arriving out of order / interleaved
1695 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1720 // -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 1721 // -An extension gets uninstalled while updates are in progress (so it doesn't
1697 // "come back from the dead") 1722 // "come back from the dead")
1698 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1723 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1699 // you don't get downgraded accidentally) 1724 // you don't get downgraded accidentally)
1700 // -An update manifest mentions multiple updates 1725 // -An update manifest mentions multiple updates
1701 1726
1702 } // namespace extensions 1727 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698