Chromium Code Reviews| Index: chrome/browser/component_updater/test/component_updater_service_unittest.cc |
| =================================================================== |
| --- chrome/browser/component_updater/test/component_updater_service_unittest.cc (revision 231370) |
| +++ chrome/browser/component_updater/test/component_updater_service_unittest.cc (working copy) |
| @@ -12,10 +12,14 @@ |
| #include "chrome/browser/component_updater/test/test_installer.h" |
| #include "chrome/common/chrome_paths.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/resource_controller.h" |
| +#include "content/public/browser/resource_request_info.h" |
| +#include "content/public/browser/resource_throttle.h" |
| #include "content/test/net/url_request_prepackaged_interceptor.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_test_util.h" |
| #include "url/gurl.h" |
| using content::BrowserThread; |
| @@ -31,7 +35,8 @@ |
| } |
| TestConfigurator::TestConfigurator() |
| - : times_(1), |
| + : initial_time_(0), |
| + times_(1), |
| recheck_time_(0), |
| ondemand_time_(0), |
| cus_(NULL), |
| @@ -42,7 +47,7 @@ |
| TestConfigurator::~TestConfigurator() { |
| } |
| -int TestConfigurator::InitialDelay() { return 0; } |
| +int TestConfigurator::InitialDelay() { return initial_time_; } |
| int TestConfigurator::NextCheckDelay() { |
| // This is called when a new full cycle of checking for updates is going |
| @@ -118,6 +123,10 @@ |
| quit_closure_ = quit_closure; |
| } |
| +void TestConfigurator::SetInitialDelay(int seconds) { |
| + initial_time_ = seconds; |
| +} |
| + |
| ComponentUpdaterTest::ComponentUpdaterTest() |
| : test_config_(NULL), |
| thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| @@ -1115,3 +1124,87 @@ |
| EXPECT_EQ(1, ping_checker.NumMisses()) << ping_checker.GetPings(); |
| EXPECT_EQ(5, interceptor.GetHitCount()); |
| } |
| + |
| +void RequestAndDeleteResourceThrottle( |
| + ComponentUpdateService* cus, const char* crx_id) { |
| + // By requesting a throttle and deleting it immediately we insure that we |
|
waffles
2013/11/12 00:22:58
nitpicky: ensure.
Also on line 1185.
|
| + // excersize the case where the component updater tries to use the weak |
|
Sorin Jianu
2013/10/31 21:33:04
exercise
|
| + // pointer to a dead Resource throttle. |
| + class NoCallResourceController : public content::ResourceController { |
| + public: |
| + virtual ~NoCallResourceController() {} |
| + virtual void Cancel() OVERRIDE { CHECK(false); } |
| + virtual void CancelAndIgnore() OVERRIDE { CHECK(false); } |
| + virtual void CancelWithError(int error_code) OVERRIDE { CHECK(false); } |
| + virtual void Resume() OVERRIDE { CHECK(false); } |
| + }; |
| + |
| + net::TestURLRequestContext context; |
| + net::TestURLRequest url_request( |
| + GURL("http://foo.example.com/thing.bin"), NULL, &context, NULL); |
| + |
| + content::ResourceThrottle* rt = |
| + cus->GetOnDemandResourceThrottle(&url_request, crx_id); |
| + NoCallResourceController controller; |
| + rt->set_controller_for_testing(&controller); |
| + delete rt; |
| +} |
| + |
| +TEST_F(ComponentUpdaterTest, ResourceThrottleNoUpdate) { |
| + content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| + |
| + MockComponentObserver observer; |
| + EXPECT_CALL(observer, |
| + OnEvent(ComponentObserver::COMPONENT_UPDATER_STARTED, 0)) |
| + .Times(1); |
| + EXPECT_CALL(observer, |
| + OnEvent(ComponentObserver::COMPONENT_UPDATER_SLEEPING, 0)) |
| + .Times(1); |
| + |
| + EXPECT_CALL(observer, |
| + OnEvent(ComponentObserver::COMPONENT_NOT_UPDATED, 0)) |
| + .Times(1); |
| + |
| + TestInstaller installer; |
| + CrxComponent com; |
| + com.observer = &observer; |
| + EXPECT_EQ(ComponentUpdateService::kOk, |
| + RegisterComponent(&com, |
| + kTestComponent_abag, |
| + Version("1.1"), |
| + &installer)); |
| + |
| + const GURL expected_update_url( |
| + "http://localhost/upd?extra=foo" |
| + "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc" |
| + "%26installsource%3Dondemand"); |
| + |
| + interceptor.SetResponse(expected_update_url, |
| + test_file("updatecheck_reply_1.xml")); |
| + |
| + // The following two calls insure that we don't do an update check via the |
| + // timer, so the only update check should be the on-demand one. |
| + test_configurator()->SetInitialDelay(1000000); |
| + test_configurator()->SetRecheckTime(1000000); |
| + test_configurator()->SetLoopCount(1); |
| + component_updater()->Start(); |
| + |
| + RunThreadsUntilIdle(); |
| + |
| + EXPECT_EQ(0, interceptor.GetHitCount()); |
| + |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&RequestAndDeleteResourceThrottle, |
| + component_updater(), |
| + "abagagagagagagagagagagagagagagag")); |
| + |
| + RunThreads(); |
| + |
| + EXPECT_EQ(1, interceptor.GetHitCount()); |
| + EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| + EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| + |
| + component_updater()->Stop(); |
| +} |