| Index: trunk/src/chrome/browser/component_updater/test/component_updater_service_unittest.cc
|
| ===================================================================
|
| --- trunk/src/chrome/browser/component_updater/test/component_updater_service_unittest.cc (revision 207822)
|
| +++ trunk/src/chrome/browser/component_updater/test/component_updater_service_unittest.cc (working copy)
|
| @@ -2,6 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +#include "chrome/browser/component_updater/component_updater_service.h"
|
| +
|
| #include <list>
|
| #include <utility>
|
|
|
| @@ -11,12 +13,7 @@
|
| #include "base/memory/scoped_vector.h"
|
| #include "base/message_loop.h"
|
| #include "base/path_service.h"
|
| -#include "base/stringprintf.h"
|
| -#include "base/strings/string_number_conversions.h"
|
| #include "base/values.h"
|
| -#include "chrome/browser/component_updater/component_updater_service.h"
|
| -#include "chrome/browser/component_updater/test/component_patcher_mock.h"
|
| -#include "chrome/browser/component_updater/test/test_installer.h"
|
| #include "chrome/common/chrome_notification_types.h"
|
| #include "chrome/common/chrome_paths.h"
|
| #include "content/public/browser/notification_observer.h"
|
| @@ -26,11 +23,7 @@
|
| #include "content/test/net/url_request_prepackaged_interceptor.h"
|
| #include "googleurl/src/gurl.h"
|
| #include "libxml/globals.h"
|
| -#include "net/base/upload_bytes_element_reader.h"
|
| #include "net/url_request/url_fetcher.h"
|
| -#include "net/url_request/url_request.h"
|
| -#include "net/url_request/url_request_filter.h"
|
| -#include "net/url_request/url_request_simple_job.h"
|
| #include "net/url_request/url_request_test_util.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -38,68 +31,98 @@
|
| using content::TestNotificationTracker;
|
|
|
| namespace {
|
| -
|
| -// component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and
|
| -// the RSA public key the following hash:
|
| -const uint8 jebg_hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,
|
| - 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,
|
| - 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,
|
| - 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40};
|
| -// component 2 has extension id "abagagagagagagagagagagagagagagag", and
|
| -// the RSA public key the following hash:
|
| -const uint8 abag_hash[] = {0x01, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
|
| - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
|
| - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
|
| - 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x01};
|
| -// component 3 has extension id "ihfokbkgjpifnbbojhneepfflplebdkc", and
|
| -// the RSA public key the following hash:
|
| -const uint8 ihfo_hash[] = {0x87, 0x5e, 0xa1, 0xa6, 0x9f, 0x85, 0xd1, 0x1e,
|
| - 0x97, 0xd4, 0x4f, 0x55, 0xbf, 0xb4, 0x13, 0xa2,
|
| - 0xe7, 0xc5, 0xc8, 0xf5, 0x60, 0x19, 0x78, 0x1b,
|
| - 0x6d, 0xe9, 0x4c, 0xeb, 0x96, 0x05, 0x42, 0x17};
|
| -
|
| +// Overrides some of the component updater behaviors so it is easier to test
|
| +// and loops faster. In actual usage it takes hours do to a full cycle.
|
| class TestConfigurator : public ComponentUpdateService::Configurator {
|
| public:
|
| - TestConfigurator();
|
| + TestConfigurator()
|
| + : times_(1), recheck_time_(0), ondemand_time_(0), cus_(NULL) {
|
| + }
|
|
|
| - virtual int InitialDelay() OVERRIDE;
|
| + virtual int InitialDelay() OVERRIDE { return 0; }
|
|
|
| typedef std::pair<CrxComponent*, int> CheckAtLoopCount;
|
|
|
| - virtual int NextCheckDelay() OVERRIDE;
|
| + virtual int NextCheckDelay() OVERRIDE {
|
| + // This is called when a new full cycle of checking for updates is going
|
| + // to happen. In test we normally only test one cycle so it is a good
|
| + // time to break from the test messageloop Run() method so the test can
|
| + // finish.
|
| + if (--times_ <= 0) {
|
| + base::MessageLoop::current()->Quit();
|
| + return 0;
|
|
|
| - virtual int StepDelay() OVERRIDE;
|
| + }
|
|
|
| - virtual int MinimumReCheckWait() OVERRIDE;
|
| + // Look for checks to issue in the middle of the loop.
|
| + for (std::list<CheckAtLoopCount>::iterator
|
| + i = components_to_check_.begin();
|
| + i != components_to_check_.end(); ) {
|
| + if (i->second == times_) {
|
| + cus_->CheckForUpdateSoon(*i->first);
|
| + i = components_to_check_.erase(i);
|
| + } else {
|
| + ++i;
|
| + }
|
| + }
|
| + return 1;
|
| + }
|
|
|
| - virtual int OnDemandDelay() OVERRIDE;
|
| + virtual int StepDelay() OVERRIDE {
|
| + return 0;
|
| + }
|
|
|
| - virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE;
|
| + virtual int MinimumReCheckWait() OVERRIDE {
|
| + return recheck_time_;
|
| + }
|
|
|
| - virtual const char* ExtraRequestParams() OVERRIDE;
|
| + virtual int OnDemandDelay() OVERRIDE {
|
| + return ondemand_time_;
|
| + }
|
|
|
| - virtual size_t UrlSizeLimit() OVERRIDE;
|
| + virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE {
|
| + switch (source) {
|
| + case CrxComponent::BANDAID:
|
| + return GURL("http://localhost/upd");
|
| + case CrxComponent::CWS_PUBLIC:
|
| + return GURL("http://localhost/cws");
|
| + default:
|
| + return GURL("http://wronghost/bad");
|
| + };
|
| + }
|
|
|
| - virtual net::URLRequestContextGetter* RequestContext() OVERRIDE;
|
| + virtual const char* ExtraRequestParams() OVERRIDE { return "extra=foo"; }
|
|
|
| - // Don't use the utility process to decode files.
|
| - virtual bool InProcess() OVERRIDE;
|
| + virtual size_t UrlSizeLimit() OVERRIDE { return 256; }
|
|
|
| - virtual void OnEvent(Events event, int extra) OVERRIDE;
|
| + virtual net::URLRequestContextGetter* RequestContext() OVERRIDE {
|
| + return new net::TestURLRequestContextGetter(
|
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
|
| + }
|
|
|
| - virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE;
|
| + // Don't use the utility process to decode files.
|
| + virtual bool InProcess() OVERRIDE { return true; }
|
|
|
| - virtual bool DeltasEnabled() const OVERRIDE;
|
| + virtual void OnEvent(Events event, int extra) OVERRIDE { }
|
|
|
| - void SetLoopCount(int times);
|
| + // Set how many update checks are called, the default value is just once.
|
| + void SetLoopCount(int times) { times_ = times; }
|
|
|
| - void SetRecheckTime(int seconds);
|
| + void SetRecheckTime(int seconds) {
|
| + recheck_time_ = seconds;
|
| + }
|
|
|
| - void SetOnDemandTime(int seconds);
|
| + void SetOnDemandTime(int seconds) {
|
| + ondemand_time_ = seconds;
|
| + }
|
|
|
| - void AddComponentToCheck(CrxComponent* com, int at_loop_iter);
|
| + void AddComponentToCheck(CrxComponent* com, int at_loop_iter) {
|
| + components_to_check_.push_back(std::make_pair(com, at_loop_iter));
|
| + }
|
|
|
| - void SetComponentUpdateService(ComponentUpdateService* cus);
|
| + void SetComponentUpdateService(ComponentUpdateService* cus) {
|
| + cus_ = cus;
|
| + }
|
|
|
| private:
|
| int times_;
|
| @@ -110,210 +133,133 @@
|
| ComponentUpdateService* cus_;
|
| };
|
|
|
| -class ComponentUpdaterTest : public testing::Test {
|
| - public:
|
| - enum TestComponents {
|
| - kTestComponent_abag,
|
| - kTestComponent_jebg,
|
| - kTestComponent_ihfo,
|
| - };
|
| +class TestInstaller : public ComponentInstaller {
|
| + public :
|
| + explicit TestInstaller()
|
| + : error_(0), install_count_(0) {
|
| + }
|
|
|
| - ComponentUpdaterTest();
|
| + virtual void OnUpdateError(int error) OVERRIDE {
|
| + EXPECT_NE(0, error);
|
| + error_ = error;
|
| + }
|
|
|
| - virtual ~ComponentUpdaterTest();
|
| + virtual bool Install(const base::DictionaryValue& manifest,
|
| + const base::FilePath& unpack_path) OVERRIDE {
|
| + ++install_count_;
|
| + return file_util::Delete(unpack_path, true);
|
| + }
|
|
|
| - virtual void TearDown();
|
| + int error() const { return error_; }
|
|
|
| - ComponentUpdateService* component_updater();
|
| + int install_count() const { return install_count_; }
|
|
|
| - // Makes the full path to a component updater test file.
|
| - const base::FilePath test_file(const char* file);
|
| -
|
| - TestNotificationTracker& notification_tracker();
|
| -
|
| - TestConfigurator* test_configurator();
|
| -
|
| - ComponentUpdateService::Status RegisterComponent(CrxComponent* com,
|
| - TestComponents component,
|
| - const Version& version,
|
| - TestInstaller* installer);
|
| -
|
| private:
|
| - scoped_ptr<ComponentUpdateService> component_updater_;
|
| - base::FilePath test_data_dir_;
|
| - TestNotificationTracker notification_tracker_;
|
| - TestConfigurator* test_config_;
|
| + int error_;
|
| + int install_count_;
|
| };
|
|
|
| +// component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and
|
| +// the RSA public key the following hash:
|
| +const uint8 jebg_hash[] = {0x94,0x16,0x0b,0x6d,0x41,0x75,0xe9,0xec,0x8e,0xd5,
|
| + 0xfa,0x54,0xb0,0xd2,0xdd,0xa5,0x6e,0x05,0x6b,0xe8,
|
| + 0x73,0x47,0xf6,0xc4,0x11,0x9f,0xbc,0xb3,0x09,0xb3,
|
| + 0x5b,0x40};
|
| +// component 2 has extension id "abagagagagagagagagagagagagagagag", and
|
| +// the RSA public key the following hash:
|
| +const uint8 abag_hash[] = {0x01,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
|
| + 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
|
| + 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,
|
| + 0x06,0x01};
|
| +
|
| const char expected_crx_url[] =
|
| "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx";
|
|
|
| } // namespace
|
|
|
| -TestConfigurator::TestConfigurator()
|
| - : times_(1), recheck_time_(0), ondemand_time_(0), cus_(NULL) {
|
| -}
|
| +// Common fixture for all the component updater tests.
|
| +class ComponentUpdaterTest : public testing::Test {
|
| + public:
|
| + enum TestComponents {
|
| + kTestComponent_abag,
|
| + kTestComponent_jebg
|
| + };
|
|
|
| -int TestConfigurator::InitialDelay() { return 0; }
|
| + ComponentUpdaterTest() : test_config_(NULL) {
|
| + // The component updater instance under test.
|
| + test_config_ = new TestConfigurator;
|
| + component_updater_.reset(ComponentUpdateServiceFactory(test_config_));
|
| + test_config_->SetComponentUpdateService(component_updater_.get());
|
| + // The test directory is chrome/test/data/components.
|
| + PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
|
| + test_data_dir_ = test_data_dir_.AppendASCII("components");
|
|
|
| -int TestConfigurator::NextCheckDelay() {
|
| - // This is called when a new full cycle of checking for updates is going
|
| - // to happen. In test we normally only test one cycle so it is a good
|
| - // time to break from the test messageloop Run() method so the test can
|
| - // finish.
|
| - if (--times_ <= 0) {
|
| - base::MessageLoop::current()->Quit();
|
| - return 0;
|
| - }
|
| + // Subscribe to all component updater notifications.
|
| + const int notifications[] = {
|
| + chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED,
|
| + chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING,
|
| + chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND,
|
| + chrome::NOTIFICATION_COMPONENT_UPDATE_READY
|
| + };
|
|
|
| - // Look for checks to issue in the middle of the loop.
|
| - for (std::list<CheckAtLoopCount>::iterator
|
| - i = components_to_check_.begin();
|
| - i != components_to_check_.end(); ) {
|
| - if (i->second == times_) {
|
| - cus_->CheckForUpdateSoon(*i->first);
|
| - i = components_to_check_.erase(i);
|
| - } else {
|
| - ++i;
|
| + for (int ix = 0; ix != arraysize(notifications); ++ix) {
|
| + notification_tracker_.ListenFor(
|
| + notifications[ix], content::NotificationService::AllSources());
|
| }
|
| + net::URLFetcher::SetEnableInterceptionForTests(true);
|
| }
|
| - return 1;
|
| -}
|
|
|
| -int TestConfigurator::StepDelay() {
|
| - return 0;
|
| -}
|
| + virtual ~ComponentUpdaterTest() {
|
| + net::URLFetcher::SetEnableInterceptionForTests(false);
|
| + }
|
|
|
| -int TestConfigurator::MinimumReCheckWait() {
|
| - return recheck_time_;
|
| -}
|
| + virtual void TearDown() {
|
| + xmlCleanupGlobals();
|
| + }
|
|
|
| -int TestConfigurator::OnDemandDelay() {
|
| - return ondemand_time_;
|
| -}
|
| -
|
| -GURL TestConfigurator::UpdateUrl(CrxComponent::UrlSource source) {
|
| - switch (source) {
|
| - case CrxComponent::BANDAID:
|
| - return GURL("http://localhost/upd");
|
| - case CrxComponent::CWS_PUBLIC:
|
| - return GURL("http://localhost/cws");
|
| - default:
|
| - return GURL("http://wronghost/bad");
|
| - };
|
| -}
|
| -
|
| -const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; }
|
| -
|
| -size_t TestConfigurator::UrlSizeLimit() { return 256; }
|
| -
|
| -net::URLRequestContextGetter* TestConfigurator::RequestContext() {
|
| - return new net::TestURLRequestContextGetter(
|
| - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
|
| -}
|
| -
|
| -// Don't use the utility process to decode files.
|
| -bool TestConfigurator::InProcess() { return true; }
|
| -
|
| -void TestConfigurator::OnEvent(Events event, int extra) { }
|
| -
|
| -ComponentPatcher* TestConfigurator::CreateComponentPatcher() {
|
| - return new MockComponentPatcher();
|
| -}
|
| -
|
| -bool TestConfigurator::DeltasEnabled() const {
|
| - return true;
|
| -}
|
| -
|
| -// Set how many update checks are called, the default value is just once.
|
| -void TestConfigurator::SetLoopCount(int times) { times_ = times; }
|
| -
|
| -void TestConfigurator::SetRecheckTime(int seconds) {
|
| - recheck_time_ = seconds;
|
| -}
|
| -
|
| -void TestConfigurator::SetOnDemandTime(int seconds) {
|
| - ondemand_time_ = seconds;
|
| -}
|
| -
|
| -void TestConfigurator::AddComponentToCheck(CrxComponent* com,
|
| - int at_loop_iter) {
|
| - components_to_check_.push_back(std::make_pair(com, at_loop_iter));
|
| -}
|
| -
|
| -void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) {
|
| - cus_ = cus;
|
| -}
|
| -
|
| -ComponentUpdaterTest::ComponentUpdaterTest() : test_config_(NULL) {
|
| - // The component updater instance under test.
|
| - test_config_ = new TestConfigurator;
|
| - component_updater_.reset(ComponentUpdateServiceFactory(test_config_));
|
| - test_config_->SetComponentUpdateService(component_updater_.get());
|
| - // The test directory is chrome/test/data/components.
|
| - PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
|
| - test_data_dir_ = test_data_dir_.AppendASCII("components");
|
| -
|
| - // Subscribe to all component updater notifications.
|
| - const int notifications[] = {
|
| - chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED,
|
| - chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING,
|
| - chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND,
|
| - chrome::NOTIFICATION_COMPONENT_UPDATE_READY
|
| - };
|
| -
|
| - for (int ix = 0; ix != arraysize(notifications); ++ix) {
|
| - notification_tracker_.ListenFor(
|
| - notifications[ix], content::NotificationService::AllSources());
|
| + ComponentUpdateService* component_updater() {
|
| + return component_updater_.get();
|
| }
|
| - net::URLFetcher::SetEnableInterceptionForTests(true);
|
| -}
|
|
|
| -ComponentUpdaterTest::~ComponentUpdaterTest() {
|
| - net::URLFetcher::SetEnableInterceptionForTests(false);
|
| -}
|
| -
|
| -void ComponentUpdaterTest::TearDown() {
|
| - xmlCleanupGlobals();
|
| -}
|
| -
|
| -ComponentUpdateService* ComponentUpdaterTest::component_updater() {
|
| - return component_updater_.get();
|
| -}
|
| -
|
| // Makes the full path to a component updater test file.
|
| -const base::FilePath ComponentUpdaterTest::test_file(const char* file) {
|
| - return test_data_dir_.AppendASCII(file);
|
| -}
|
| + const base::FilePath test_file(const char* file) {
|
| + return test_data_dir_.AppendASCII(file);
|
| + }
|
|
|
| -TestNotificationTracker& ComponentUpdaterTest::notification_tracker() {
|
| - return notification_tracker_;
|
| -}
|
| + TestNotificationTracker& notification_tracker() {
|
| + return notification_tracker_;
|
| + }
|
|
|
| -TestConfigurator* ComponentUpdaterTest::test_configurator() {
|
| - return test_config_;
|
| -}
|
| + TestConfigurator* test_configurator() {
|
| + return test_config_;
|
| + }
|
|
|
| -ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent(
|
| - CrxComponent* com,
|
| - TestComponents component,
|
| - const Version& version,
|
| - TestInstaller* installer) {
|
| - if (component == kTestComponent_abag) {
|
| - com->name = "test_abag";
|
| - com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash));
|
| - } else if (component == kTestComponent_jebg) {
|
| - com->name = "test_jebg";
|
| - com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
|
| - } else {
|
| - com->name = "test_ihfo";
|
| - com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash));
|
| + ComponentUpdateService::Status RegisterComponent(CrxComponent* com,
|
| + TestComponents component,
|
| + const Version& version) {
|
| + if (component == kTestComponent_abag) {
|
| + com->name = "test_abag";
|
| + com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash));
|
| + } else {
|
| + com->name = "test_jebg";
|
| + com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash));
|
| + }
|
| + com->version = version;
|
| + TestInstaller* installer = new TestInstaller;
|
| + com->installer = installer;
|
| + test_installers_.push_back(installer);
|
| + return component_updater_->RegisterComponent(*com);
|
| }
|
| - com->version = version;
|
| - com->installer = installer;
|
| - return component_updater_->RegisterComponent(*com);
|
| -}
|
|
|
| + private:
|
| + scoped_ptr<ComponentUpdateService> component_updater_;
|
| + base::FilePath test_data_dir_;
|
| + TestNotificationTracker notification_tracker_;
|
| + TestConfigurator* test_config_;
|
| + // ComponentInstaller objects to delete after each test.
|
| + ScopedVector<TestInstaller> test_installers_;
|
| +};
|
| +
|
| // Verify that our test fixture work and the component updater can
|
| // be created and destroyed with no side effects.
|
| TEST_F(ComponentUpdaterTest, VerifyFixture) {
|
| @@ -349,17 +295,13 @@
|
|
|
| content::URLLocalHostRequestPrepackagedInterceptor interceptor;
|
|
|
| - TestInstaller installer;
|
| CrxComponent com;
|
| EXPECT_EQ(ComponentUpdateService::kOk,
|
| - RegisterComponent(&com,
|
| - kTestComponent_abag,
|
| - Version("1.1"),
|
| - &installer));
|
| + RegisterComponent(&com, kTestComponent_abag, Version("1.1")));
|
|
|
| const GURL expected_update_url(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc");
|
| + "http://localhost/upd?extra=foo&x=id%3D"
|
| + "abagagagagagagagagagagagagagagag%26v%3D1.1%26uc");
|
|
|
| interceptor.SetResponse(expected_update_url,
|
| test_file("updatecheck_reply_1.xml"));
|
| @@ -432,22 +374,20 @@
|
|
|
| content::URLLocalHostRequestPrepackagedInterceptor interceptor;
|
|
|
| - TestInstaller installer1;
|
| CrxComponent com1;
|
| - RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
|
| - TestInstaller installer2;
|
| + RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"));
|
| CrxComponent com2;
|
| - RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
|
| + RegisterComponent(&com2, kTestComponent_abag, Version("2.2"));
|
|
|
| const GURL expected_update_url_1(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
|
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
|
| + "http://localhost/upd?extra=foo&x=id%3D"
|
| + "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D"
|
| + "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc");
|
|
|
| const GURL expected_update_url_2(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
|
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc");
|
| + "http://localhost/upd?extra=foo&x=id%3D"
|
| + "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D"
|
| + "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc");
|
|
|
| interceptor.SetResponse(expected_update_url_1,
|
| test_file("updatecheck_reply_1.xml"));
|
| @@ -499,21 +439,19 @@
|
|
|
| content::URLLocalHostRequestPrepackagedInterceptor interceptor;
|
|
|
| - TestInstaller installer1;
|
| CrxComponent com1;
|
| - RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
|
| - TestInstaller installer2;
|
| + RegisterComponent(&com1, kTestComponent_abag, Version("2.2"));
|
| CrxComponent com2;
|
| com2.source = CrxComponent::CWS_PUBLIC;
|
| - RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2);
|
| + RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"));
|
|
|
| const GURL expected_update_url_1(
|
| "http://localhost/upd?extra=foo&x=id%3D"
|
| - "abagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
|
| + "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc");
|
|
|
| const GURL expected_update_url_2(
|
| "http://localhost/cws?extra=foo&x=id%3D"
|
| - "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
|
| + "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc");
|
|
|
| interceptor.SetResponse(expected_update_url_1,
|
| test_file("updatecheck_reply_3.xml"));
|
| @@ -573,13 +511,12 @@
|
|
|
| content::URLLocalHostRequestPrepackagedInterceptor interceptor;
|
|
|
| - TestInstaller installer;
|
| CrxComponent com;
|
| - RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer);
|
| + RegisterComponent(&com, kTestComponent_jebg, Version("0.9"));
|
|
|
| const GURL expected_update_url(
|
| "http://localhost/upd?extra=foo&x=id%3D"
|
| - "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
|
| + "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc");
|
|
|
| interceptor.SetResponse(expected_update_url,
|
| test_file("updatecheck_reply_2.xml"));
|
| @@ -614,22 +551,20 @@
|
|
|
| content::URLLocalHostRequestPrepackagedInterceptor interceptor;
|
|
|
| - TestInstaller installer1;
|
| CrxComponent com1;
|
| - RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1);
|
| - TestInstaller installer2;
|
| + RegisterComponent(&com1, kTestComponent_abag, Version("2.2"));
|
| CrxComponent com2;
|
| - RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2);
|
| + RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"));
|
|
|
| const GURL expected_update_url_1(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
|
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc");
|
| + "http://localhost/upd?extra=foo&x=id%3D"
|
| + "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D"
|
| + "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc");
|
|
|
| const GURL expected_update_url_2(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
|
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
|
| + "http://localhost/upd?extra=foo&x=id%3D"
|
| + "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D"
|
| + "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc");
|
|
|
| interceptor.SetResponse(expected_update_url_1,
|
| test_file("updatecheck_reply_empty"));
|
| @@ -678,9 +613,9 @@
|
| // Test a few error cases. NOTE: We don't have callbacks for
|
| // when the updates failed yet.
|
| const GURL expected_update_url_3(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"
|
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
|
| + "http://localhost/upd?extra=foo&x=id%3D"
|
| + "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc&x=id%3D"
|
| + "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc");
|
|
|
| // No update: error from no server response
|
| interceptor.SetResponse(expected_update_url_3,
|
| @@ -732,23 +667,21 @@
|
|
|
| content::URLLocalHostRequestPrepackagedInterceptor interceptor;
|
|
|
| - TestInstaller installer1;
|
| CrxComponent com1;
|
| - RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1);
|
| - TestInstaller installer2;
|
| + RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"));
|
| CrxComponent com2;
|
| - RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2);
|
| + RegisterComponent(&com2, kTestComponent_abag, Version("2.2"));
|
|
|
| // Start with 0.9, and update to 1.0
|
| const GURL expected_update_url_1(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"
|
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
|
| + "http://localhost/upd?extra=foo&x=id%3D"
|
| + "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D"
|
| + "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc");
|
|
|
| const GURL expected_update_url_2(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"
|
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc");
|
| + "http://localhost/upd?extra=foo&x=id%3D"
|
| + "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D"
|
| + "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc");
|
|
|
| interceptor.SetResponse(expected_update_url_1,
|
| test_file("updatecheck_reply_1.xml"));
|
| @@ -789,20 +722,16 @@
|
| EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type);
|
|
|
| // Now re-register, pretending to be an even newer version (2.2)
|
| - TestInstaller installer3;
|
| component_updater()->Stop();
|
| EXPECT_EQ(ComponentUpdateService::kReplaced,
|
| - RegisterComponent(&com1,
|
| - kTestComponent_jebg,
|
| - Version("2.2"),
|
| - &installer3));
|
| + RegisterComponent(&com1, kTestComponent_jebg, Version("2.2")));
|
|
|
| // Check that we send out 2.2 as our version.
|
| // Interceptor's hit count should go up by 1.
|
| const GURL expected_update_url_3(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26fp%3D%26uc"
|
| - "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc");
|
| + "http://localhost/upd?extra=foo&x=id%3D"
|
| + "jebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26uc&x=id%3D"
|
| + "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc");
|
|
|
| interceptor.SetResponse(expected_update_url_3,
|
| test_file("updatecheck_reply_1.xml"));
|
| @@ -824,7 +753,8 @@
|
|
|
| EXPECT_EQ(4, interceptor.GetHitCount());
|
|
|
| - // We created a new installer, so the counts go back to 0.
|
| + // The test harness's Register() function creates a new installer,
|
| + // so the counts go back to 0.
|
| EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error());
|
| EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count());
|
| EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error());
|
| @@ -832,190 +762,3 @@
|
|
|
| component_updater()->Stop();
|
| }
|
| -
|
| -// Verify that we can download and install a component and a differential
|
| -// update to that component. We do three loops; the final loop should do
|
| -// nothing.
|
| -// We also check that exactly 5 network requests are issued:
|
| -// 1- update check (response: v1 available)
|
| -// 2- download crx (v1)
|
| -// 3- update check (response: v2 available)
|
| -// 4- download differential crx (v1 to v2)
|
| -// 5- update check (response: no further update available)
|
| -TEST_F(ComponentUpdaterTest, DifferentialUpdate) {
|
| - base::MessageLoop message_loop;
|
| - content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
|
| - content::TestBrowserThread file_thread(BrowserThread::FILE);
|
| - content::TestBrowserThread io_thread(BrowserThread::IO);
|
| -
|
| - io_thread.StartIOThread();
|
| - file_thread.Start();
|
| -
|
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor;
|
| -
|
| - VersionedTestInstaller installer;
|
| - CrxComponent com;
|
| - RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
|
| -
|
| - const GURL expected_update_url_0(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
|
| - const GURL expected_update_url_1(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc");
|
| - const GURL expected_update_url_2(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
|
| - const GURL expected_crx_url_1(
|
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
|
| - const GURL expected_crx_url_1_diff_2(
|
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
|
| -
|
| - interceptor.SetResponse(expected_update_url_0,
|
| - test_file("updatecheck_diff_reply_1.xml"));
|
| - interceptor.SetResponse(expected_update_url_1,
|
| - test_file("updatecheck_diff_reply_2.xml"));
|
| - interceptor.SetResponse(expected_update_url_2,
|
| - test_file("updatecheck_diff_reply_3.xml"));
|
| - interceptor.SetResponse(expected_crx_url_1,
|
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
|
| - interceptor.SetResponse(
|
| - expected_crx_url_1_diff_2,
|
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
|
| -
|
| - test_configurator()->SetLoopCount(3);
|
| -
|
| - component_updater()->Start();
|
| - message_loop.Run();
|
| -
|
| - EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
|
| - EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
|
| -
|
| - EXPECT_EQ(5, interceptor.GetHitCount());
|
| -
|
| - component_updater()->Stop();
|
| -}
|
| -
|
| -// Verify that component installation falls back to downloading and installing
|
| -// a full update if the differential update fails (in this case, because the
|
| -// installer does not know about the existing files). We do two loops; the final
|
| -// loop should do nothing.
|
| -// We also check that exactly 4 network requests are issued:
|
| -// 1- update check (loop 1)
|
| -// 2- download differential crx
|
| -// 3- download full crx
|
| -// 4- update check (loop 2 - no update available)
|
| -TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) {
|
| - base::MessageLoop message_loop;
|
| - content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
|
| - content::TestBrowserThread file_thread(BrowserThread::FILE);
|
| - content::TestBrowserThread io_thread(BrowserThread::IO);
|
| -
|
| - io_thread.StartIOThread();
|
| - file_thread.Start();
|
| -
|
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor;
|
| -
|
| - TestInstaller installer;
|
| - CrxComponent com;
|
| - RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer);
|
| -
|
| - const GURL expected_update_url_1(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc");
|
| - const GURL expected_update_url_2(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
|
| - const GURL expected_crx_url_1(
|
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
|
| - const GURL expected_crx_url_1_diff_2(
|
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
|
| - const GURL expected_crx_url_2(
|
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx");
|
| -
|
| - interceptor.SetResponse(expected_update_url_1,
|
| - test_file("updatecheck_diff_reply_2.xml"));
|
| - interceptor.SetResponse(expected_update_url_2,
|
| - test_file("updatecheck_diff_reply_3.xml"));
|
| - interceptor.SetResponse(expected_crx_url_1,
|
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
|
| - interceptor.SetResponse(
|
| - expected_crx_url_1_diff_2,
|
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"));
|
| - interceptor.SetResponse(expected_crx_url_2,
|
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
|
| -
|
| - test_configurator()->SetLoopCount(2);
|
| -
|
| - component_updater()->Start();
|
| - message_loop.Run();
|
| -
|
| - // A failed differential update does not count as a failed install.
|
| - EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
|
| - EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count());
|
| -
|
| - EXPECT_EQ(4, interceptor.GetHitCount());
|
| -
|
| - component_updater()->Stop();
|
| -}
|
| -
|
| -// Verify that we successfully propagate a patcher error.
|
| -// ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect
|
| -// patching instruction that should fail.
|
| -TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) {
|
| - base::MessageLoop message_loop;
|
| - content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
|
| - content::TestBrowserThread file_thread(BrowserThread::FILE);
|
| - content::TestBrowserThread io_thread(BrowserThread::IO);
|
| -
|
| - io_thread.StartIOThread();
|
| - file_thread.Start();
|
| -
|
| - content::URLLocalHostRequestPrepackagedInterceptor interceptor;
|
| -
|
| - VersionedTestInstaller installer;
|
| - CrxComponent com;
|
| - RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer);
|
| -
|
| - const GURL expected_update_url_0(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc");
|
| - const GURL expected_update_url_1(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc");
|
| - const GURL expected_update_url_2(
|
| - "http://localhost/upd?extra=foo"
|
| - "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc");
|
| - const GURL expected_crx_url_1(
|
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx");
|
| - const GURL expected_crx_url_1_diff_2(
|
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx");
|
| - const GURL expected_crx_url_2(
|
| - "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx");
|
| -
|
| - interceptor.SetResponse(expected_update_url_0,
|
| - test_file("updatecheck_diff_reply_1.xml"));
|
| - interceptor.SetResponse(expected_update_url_1,
|
| - test_file("updatecheck_diff_reply_2.xml"));
|
| - interceptor.SetResponse(expected_update_url_2,
|
| - test_file("updatecheck_diff_reply_3.xml"));
|
| - interceptor.SetResponse(expected_crx_url_1,
|
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"));
|
| - interceptor.SetResponse(
|
| - expected_crx_url_1_diff_2,
|
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx"));
|
| - interceptor.SetResponse(expected_crx_url_2,
|
| - test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"));
|
| -
|
| - test_configurator()->SetLoopCount(3);
|
| -
|
| - component_updater()->Start();
|
| - message_loop.Run();
|
| -
|
| - EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error());
|
| - EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count());
|
| -
|
| - EXPECT_EQ(6, interceptor.GetHitCount());
|
| -
|
| - component_updater()->Stop();
|
| -}
|
|
|