| 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 "chrome/browser/component_updater/component_updater_service.h" | |
| 6 | |
| 7 #include <list> | 5 #include <list> |
| 8 #include <utility> | 6 #include <utility> |
| 9 | 7 |
| 10 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 11 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 13 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 14 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 15 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/stringprintf.h" |
| 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/component_updater/component_updater_service.h" |
| 18 #include "chrome/browser/component_updater/test/component_patcher_mock.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 19 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
| 22 #include "content/public/test/test_notification_tracker.h" | 24 #include "content/public/test/test_notification_tracker.h" |
| 23 #include "content/test/net/url_request_prepackaged_interceptor.h" | 25 #include "content/test/net/url_request_prepackaged_interceptor.h" |
| 24 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 25 #include "libxml/globals.h" | 27 #include "libxml/globals.h" |
| 28 #include "net/base/upload_bytes_element_reader.h" |
| 26 #include "net/url_request/url_fetcher.h" | 29 #include "net/url_request/url_fetcher.h" |
| 30 #include "net/url_request/url_request.h" |
| 31 #include "net/url_request/url_request_filter.h" |
| 32 #include "net/url_request/url_request_simple_job.h" |
| 27 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 35 |
| 30 using content::BrowserThread; | 36 using content::BrowserThread; |
| 31 using content::TestNotificationTracker; | 37 using content::TestNotificationTracker; |
| 32 | 38 |
| 33 namespace { | 39 namespace { |
| 34 // Overrides some of the component updater behaviors so it is easier to test | 40 |
| 35 // and loops faster. In actual usage it takes hours do to a full cycle. | 41 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and |
| 42 // the RSA public key the following hash: |
| 43 const uint8 jebg_hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec, |
| 44 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5, |
| 45 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4, |
| 46 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}; |
| 47 // component 2 has extension id "abagagagagagagagagagagagagagagag", and |
| 48 // the RSA public key the following hash: |
| 49 const uint8 abag_hash[] = {0x01, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, |
| 50 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, |
| 51 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, |
| 52 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x01}; |
| 53 // component 3 has extension id "ihfokbkgjpifnbbojhneepfflplebdkc", and |
| 54 // the RSA public key the following hash: |
| 55 const uint8 ihfo_hash[] = {0x87, 0x5e, 0xa1, 0xa6, 0x9f, 0x85, 0xd1, 0x1e, |
| 56 0x97, 0xd4, 0x4f, 0x55, 0xbf, 0xb4, 0x13, 0xa2, |
| 57 0xe7, 0xc5, 0xc8, 0xf5, 0x60, 0x19, 0x78, 0x1b, |
| 58 0x6d, 0xe9, 0x4c, 0xeb, 0x96, 0x05, 0x42, 0x17}; |
| 59 |
| 36 class TestConfigurator : public ComponentUpdateService::Configurator { | 60 class TestConfigurator : public ComponentUpdateService::Configurator { |
| 37 public: | 61 public: |
| 38 TestConfigurator() | 62 TestConfigurator(); |
| 39 : times_(1), recheck_time_(0), ondemand_time_(0), cus_(NULL) { | |
| 40 } | |
| 41 | 63 |
| 42 virtual int InitialDelay() OVERRIDE { return 0; } | 64 virtual int InitialDelay() OVERRIDE; |
| 43 | 65 |
| 44 typedef std::pair<CrxComponent*, int> CheckAtLoopCount; | 66 typedef std::pair<CrxComponent*, int> CheckAtLoopCount; |
| 45 | 67 |
| 46 virtual int NextCheckDelay() OVERRIDE { | 68 virtual int NextCheckDelay() OVERRIDE; |
| 47 // This is called when a new full cycle of checking for updates is going | |
| 48 // to happen. In test we normally only test one cycle so it is a good | |
| 49 // time to break from the test messageloop Run() method so the test can | |
| 50 // finish. | |
| 51 if (--times_ <= 0) { | |
| 52 MessageLoop::current()->Quit(); | |
| 53 return 0; | |
| 54 | 69 |
| 55 } | 70 virtual int StepDelay() OVERRIDE; |
| 56 | 71 |
| 57 // Look for checks to issue in the middle of the loop. | 72 virtual int MinimumReCheckWait() OVERRIDE; |
| 58 for (std::list<CheckAtLoopCount>::iterator | |
| 59 i = components_to_check_.begin(); | |
| 60 i != components_to_check_.end(); ) { | |
| 61 if (i->second == times_) { | |
| 62 cus_->CheckForUpdateSoon(*i->first); | |
| 63 i = components_to_check_.erase(i); | |
| 64 } else { | |
| 65 ++i; | |
| 66 } | |
| 67 } | |
| 68 return 1; | |
| 69 } | |
| 70 | 73 |
| 71 virtual int StepDelay() OVERRIDE { | 74 virtual int OnDemandDelay() OVERRIDE; |
| 72 return 0; | |
| 73 } | |
| 74 | 75 |
| 75 virtual int MinimumReCheckWait() OVERRIDE { | 76 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE; |
| 76 return recheck_time_; | |
| 77 } | |
| 78 | 77 |
| 79 virtual int OnDemandDelay() OVERRIDE { | 78 virtual GURL PingUrl() OVERRIDE; |
| 80 return ondemand_time_; | |
| 81 } | |
| 82 | 79 |
| 83 virtual GURL UpdateUrl(CrxComponent::UrlSource source) OVERRIDE { | 80 virtual const char* ExtraRequestParams() OVERRIDE; |
| 84 switch (source) { | |
| 85 case CrxComponent::BANDAID: | |
| 86 return GURL("http://localhost/upd"); | |
| 87 case CrxComponent::CWS_PUBLIC: | |
| 88 return GURL("http://localhost/cws"); | |
| 89 default: | |
| 90 return GURL("http://wronghost/bad"); | |
| 91 }; | |
| 92 } | |
| 93 | 81 |
| 94 virtual const char* ExtraRequestParams() OVERRIDE { return "extra=foo"; } | 82 virtual size_t UrlSizeLimit() OVERRIDE; |
| 95 | 83 |
| 96 virtual size_t UrlSizeLimit() OVERRIDE { return 256; } | 84 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE; |
| 97 | |
| 98 virtual net::URLRequestContextGetter* RequestContext() OVERRIDE { | |
| 99 return new net::TestURLRequestContextGetter( | |
| 100 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | |
| 101 } | |
| 102 | 85 |
| 103 // Don't use the utility process to decode files. | 86 // Don't use the utility process to decode files. |
| 104 virtual bool InProcess() OVERRIDE { return true; } | 87 virtual bool InProcess() OVERRIDE; |
| 105 | 88 |
| 106 virtual void OnEvent(Events event, int extra) OVERRIDE { } | 89 virtual void OnEvent(Events event, int extra) OVERRIDE; |
| 107 | 90 |
| 108 // Set how many update checks are called, the default value is just once. | 91 virtual ComponentPatcher* CreateComponentPatcher() OVERRIDE; |
| 109 void SetLoopCount(int times) { times_ = times; } | |
| 110 | 92 |
| 111 void SetRecheckTime(int seconds) { | 93 virtual bool PingsEnabled() const OVERRIDE; |
| 112 recheck_time_ = seconds; | |
| 113 } | |
| 114 | 94 |
| 115 void SetOnDemandTime(int seconds) { | 95 virtual bool DeltasEnabled() const OVERRIDE; |
| 116 ondemand_time_ = seconds; | |
| 117 } | |
| 118 | 96 |
| 119 void AddComponentToCheck(CrxComponent* com, int at_loop_iter) { | 97 void SetLoopCount(int times); |
| 120 components_to_check_.push_back(std::make_pair(com, at_loop_iter)); | |
| 121 } | |
| 122 | 98 |
| 123 void SetComponentUpdateService(ComponentUpdateService* cus) { | 99 void SetRecheckTime(int seconds); |
| 124 cus_ = cus; | 100 |
| 125 } | 101 void SetOnDemandTime(int seconds); |
| 102 |
| 103 void AddComponentToCheck(CrxComponent* com, int at_loop_iter); |
| 104 |
| 105 void SetComponentUpdateService(ComponentUpdateService* cus); |
| 126 | 106 |
| 127 private: | 107 private: |
| 128 int times_; | 108 int times_; |
| 129 int recheck_time_; | 109 int recheck_time_; |
| 130 int ondemand_time_; | 110 int ondemand_time_; |
| 131 | 111 |
| 132 std::list<CheckAtLoopCount> components_to_check_; | 112 std::list<CheckAtLoopCount> components_to_check_; |
| 133 ComponentUpdateService* cus_; | 113 ComponentUpdateService* cus_; |
| 134 }; | 114 }; |
| 135 | 115 |
| 136 class TestInstaller : public ComponentInstaller { | 116 class TestInstaller : public ComponentInstaller { |
| 137 public : | 117 public : |
| 138 explicit TestInstaller() | 118 explicit TestInstaller(); |
| 139 : error_(0), install_count_(0) { | 119 |
| 140 } | 120 virtual void OnUpdateError(int error) OVERRIDE; |
| 141 | |
| 142 virtual void OnUpdateError(int error) OVERRIDE { | |
| 143 EXPECT_NE(0, error); | |
| 144 error_ = error; | |
| 145 } | |
| 146 | 121 |
| 147 virtual bool Install(const base::DictionaryValue& manifest, | 122 virtual bool Install(const base::DictionaryValue& manifest, |
| 148 const base::FilePath& unpack_path) OVERRIDE { | 123 const base::FilePath& unpack_path) OVERRIDE; |
| 149 ++install_count_; | 124 |
| 150 return file_util::Delete(unpack_path, true); | 125 virtual bool GetInstalledFile(const std::string& file, |
| 151 } | 126 base::FilePath* installed_file) OVERRIDE; |
| 152 | 127 |
| 153 int error() const { return error_; } | 128 int error() const; |
| 154 | 129 |
| 155 int install_count() const { return install_count_; } | 130 int install_count() const; |
| 156 | 131 |
| 157 private: | 132 protected: |
| 158 int error_; | 133 int error_; |
| 159 int install_count_; | 134 int install_count_; |
| 160 }; | 135 }; |
| 161 | 136 |
| 162 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and | 137 class PersistentTestInstaller : public TestInstaller { |
| 163 // the RSA public key the following hash: | 138 public : |
| 164 const uint8 jebg_hash[] = {0x94,0x16,0x0b,0x6d,0x41,0x75,0xe9,0xec,0x8e,0xd5, | 139 explicit PersistentTestInstaller(); |
| 165 0xfa,0x54,0xb0,0xd2,0xdd,0xa5,0x6e,0x05,0x6b,0xe8, | 140 |
| 166 0x73,0x47,0xf6,0xc4,0x11,0x9f,0xbc,0xb3,0x09,0xb3, | 141 virtual ~PersistentTestInstaller(); |
| 167 0x5b,0x40}; | 142 |
| 168 // component 2 has extension id "abagagagagagagagagagagagagagagag", and | 143 virtual bool Install(const base::DictionaryValue& manifest, |
| 169 // the RSA public key the following hash: | 144 const base::FilePath& unpack_path) OVERRIDE; |
| 170 const uint8 abag_hash[] = {0x01,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06, | 145 |
| 171 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06, | 146 virtual bool GetInstalledFile(const std::string& file, |
| 172 0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06, | 147 base::FilePath* installed_file) OVERRIDE; |
| 173 0x06,0x01}; | 148 |
| 174 | 149 private: |
| 175 const char expected_crx_url[] = | 150 base::FilePath install_directory_; |
| 176 "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"; | 151 Version current_version_; |
| 177 | 152 }; |
| 178 } // namespace | 153 |
| 179 | |
| 180 // Common fixture for all the component updater tests. | |
| 181 class ComponentUpdaterTest : public testing::Test { | 154 class ComponentUpdaterTest : public testing::Test { |
| 182 public: | 155 public: |
| 183 enum TestComponents { | 156 enum TestComponents { |
| 184 kTestComponent_abag, | 157 kTestComponent_abag, |
| 185 kTestComponent_jebg | 158 kTestComponent_jebg, |
| 159 kTestComponent_ihfo, |
| 186 }; | 160 }; |
| 187 | 161 |
| 188 ComponentUpdaterTest() : component_updater_(NULL), test_config_(NULL) { | 162 ComponentUpdaterTest(); |
| 189 // The component updater instance under test. | 163 |
| 190 test_config_ = new TestConfigurator; | 164 virtual ~ComponentUpdaterTest(); |
| 191 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); | 165 |
| 192 test_config_->SetComponentUpdateService(component_updater_.get()); | 166 virtual void TearDown(); |
| 193 // The test directory is chrome/test/data/components. | 167 |
| 194 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 168 ComponentUpdateService* component_updater(); |
| 195 test_data_dir_ = test_data_dir_.AppendASCII("components"); | |
| 196 | |
| 197 // Subscribe to all component updater notifications. | |
| 198 const int notifications[] = { | |
| 199 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, | |
| 200 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, | |
| 201 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, | |
| 202 chrome::NOTIFICATION_COMPONENT_UPDATE_READY | |
| 203 }; | |
| 204 | |
| 205 for (int ix = 0; ix != arraysize(notifications); ++ix) { | |
| 206 notification_tracker_.ListenFor( | |
| 207 notifications[ix], content::NotificationService::AllSources()); | |
| 208 } | |
| 209 net::URLFetcher::SetEnableInterceptionForTests(true); | |
| 210 } | |
| 211 | |
| 212 virtual ~ComponentUpdaterTest() { | |
| 213 net::URLFetcher::SetEnableInterceptionForTests(false); | |
| 214 } | |
| 215 | |
| 216 virtual void TearDown() { | |
| 217 xmlCleanupGlobals(); | |
| 218 } | |
| 219 | |
| 220 ComponentUpdateService* component_updater() { | |
| 221 return component_updater_.get(); | |
| 222 } | |
| 223 | 169 |
| 224 // Makes the full path to a component updater test file. | 170 // Makes the full path to a component updater test file. |
| 225 const base::FilePath test_file(const char* file) { | 171 const base::FilePath test_file(const char* file); |
| 226 return test_data_dir_.AppendASCII(file); | 172 |
| 227 } | 173 TestNotificationTracker& notification_tracker(); |
| 228 | 174 |
| 229 TestNotificationTracker& notification_tracker() { | 175 TestConfigurator* test_configurator(); |
| 230 return notification_tracker_; | |
| 231 } | |
| 232 | |
| 233 TestConfigurator* test_configurator() { | |
| 234 return test_config_; | |
| 235 } | |
| 236 | 176 |
| 237 ComponentUpdateService::Status RegisterComponent(CrxComponent* com, | 177 ComponentUpdateService::Status RegisterComponent(CrxComponent* com, |
| 238 TestComponents component, | 178 TestComponents component, |
| 239 const Version& version) { | 179 const Version& version, |
| 240 if (component == kTestComponent_abag) { | 180 TestInstaller* installer); |
| 241 com->name = "test_abag"; | |
| 242 com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash)); | |
| 243 } else { | |
| 244 com->name = "test_jebg"; | |
| 245 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | |
| 246 } | |
| 247 com->version = version; | |
| 248 TestInstaller* installer = new TestInstaller; | |
| 249 com->installer = installer; | |
| 250 test_installers_.push_back(installer); | |
| 251 return component_updater_->RegisterComponent(*com); | |
| 252 } | |
| 253 | 181 |
| 254 private: | 182 private: |
| 255 scoped_ptr<ComponentUpdateService> component_updater_; | 183 scoped_ptr<ComponentUpdateService> component_updater_; |
| 256 base::FilePath test_data_dir_; | 184 base::FilePath test_data_dir_; |
| 257 TestNotificationTracker notification_tracker_; | 185 TestNotificationTracker notification_tracker_; |
| 258 TestConfigurator* test_config_; | 186 TestConfigurator* test_config_; |
| 259 // ComponentInstaller objects to delete after each test. | 187 }; |
| 260 ScopedVector<TestInstaller> test_installers_; | 188 |
| 261 }; | 189 const char expected_crx_url[] = |
| 190 "http://localhost/download/jebgalgnebhfojomionfpkfelancnnkf.crx"; |
| 191 |
| 192 class PingChecker { |
| 193 public: |
| 194 explicit PingChecker(const std::map<std::string, std::string>& attributes); |
| 195 |
| 196 virtual ~PingChecker(); |
| 197 |
| 198 void Trial(net::URLRequest* request); |
| 199 |
| 200 int NumHits() const { |
| 201 return num_hits_; |
| 202 } |
| 203 int NumMisses() const { |
| 204 return num_misses_; |
| 205 } |
| 206 |
| 207 private: |
| 208 int num_hits_; |
| 209 int num_misses_; |
| 210 const std::map<std::string, std::string> attributes_; |
| 211 virtual bool Test(net::URLRequest* request); |
| 212 }; |
| 213 |
| 214 PingChecker::PingChecker(const std::map<std::string, std::string>& attributes) |
| 215 : num_hits_(0), num_misses_(0), attributes_(attributes) { |
| 216 } |
| 217 |
| 218 PingChecker::~PingChecker() {} |
| 219 |
| 220 void PingChecker::Trial(net::URLRequest* request) { |
| 221 if (Test(request)) { |
| 222 ++num_hits_; |
| 223 } else { |
| 224 ++num_misses_; |
| 225 } |
| 226 } |
| 227 |
| 228 bool PingChecker::Test(net::URLRequest* request) { |
| 229 if (request->has_upload()) { |
| 230 const net::UploadDataStream* stream = request->get_upload(); |
| 231 const net::UploadBytesElementReader* reader = |
| 232 stream->element_readers()[0]->AsBytesReader(); |
| 233 int size = reader->length(); |
| 234 scoped_refptr <net::IOBuffer> buffer = new net::IOBuffer(size); |
| 235 std::string data(reader->bytes()); |
| 236 // For now, we assume that there is only one ping per POST. |
| 237 std::string::size_type start = data.find("<o:event"); |
| 238 if (start != std::string::npos) { |
| 239 std::string::size_type end = data.find(">", start); |
| 240 if (end != std::string::npos) { |
| 241 std::string ping = data.substr(start, end - start); |
| 242 std::map<std::string, std::string>::const_iterator iter; |
| 243 for (iter = attributes_.begin(); iter != attributes_.end(); ++iter) { |
| 244 // does the ping contain the specified attribute/value? |
| 245 if (ping.find(std::string(" ") + (iter->first) + |
| 246 std::string("=") + (iter->second)) == string::npos) { |
| 247 return false; |
| 248 } |
| 249 } |
| 250 return true; |
| 251 } |
| 252 } |
| 253 } |
| 254 return false; |
| 255 } |
| 256 |
| 257 class URLRequestPostInterceptor { |
| 258 public: |
| 259 explicit URLRequestPostInterceptor(PingChecker* counter); |
| 260 virtual ~URLRequestPostInterceptor(); |
| 261 |
| 262 private: |
| 263 class Delegate; |
| 264 |
| 265 // After creation, |delegate_| lives on the IO thread, and a task to delete it |
| 266 // is posted from ~URLRequestPostInterceptor(). |
| 267 Delegate* delegate_; |
| 268 |
| 269 DISALLOW_COPY_AND_ASSIGN(URLRequestPostInterceptor); |
| 270 }; |
| 271 |
| 272 class URLRequestPostInterceptor::Delegate |
| 273 : public net::URLRequestJobFactory::ProtocolHandler { |
| 274 public: |
| 275 explicit Delegate(PingChecker* counter); |
| 276 virtual ~Delegate() {} |
| 277 |
| 278 void Register(); |
| 279 |
| 280 void Unregister(); |
| 281 |
| 282 private: |
| 283 PingChecker* counter_; |
| 284 |
| 285 virtual net::URLRequestJob* MaybeCreateJob( |
| 286 net::URLRequest* request, |
| 287 net::NetworkDelegate* network_delegate) const OVERRIDE; |
| 288 }; |
| 289 |
| 290 class URLRequestPingMockJob : public net::URLRequestSimpleJob { |
| 291 public: |
| 292 URLRequestPingMockJob(net::URLRequest* request, |
| 293 net::NetworkDelegate* network_delegate); |
| 294 |
| 295 protected: |
| 296 virtual int GetData(std::string* mime_type, |
| 297 std::string* charset, |
| 298 std::string* data, |
| 299 const net::CompletionCallback& callback) const OVERRIDE; |
| 300 |
| 301 private: |
| 302 virtual ~URLRequestPingMockJob() {} |
| 303 |
| 304 DISALLOW_COPY_AND_ASSIGN(URLRequestPingMockJob); |
| 305 }; |
| 306 |
| 307 URLRequestPostInterceptor::URLRequestPostInterceptor( |
| 308 PingChecker* counter) : delegate_(new Delegate(counter)) { |
| 309 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 310 base::Bind(&Delegate::Register, |
| 311 base::Unretained(delegate_))); |
| 312 } |
| 313 |
| 314 URLRequestPostInterceptor::~URLRequestPostInterceptor() { |
| 315 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 316 base::Bind(&Delegate::Unregister, |
| 317 base::Unretained(delegate_))); |
| 318 } |
| 319 |
| 320 URLRequestPostInterceptor::Delegate::Delegate( |
| 321 PingChecker* counter) : counter_(counter) { |
| 322 } |
| 323 |
| 324 void URLRequestPostInterceptor::Delegate::Register() { |
| 325 net::URLRequestFilter::GetInstance()->AddHostnameProtocolHandler( |
| 326 "http", "localhost2", |
| 327 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(this)); |
| 328 } |
| 329 |
| 330 void URLRequestPostInterceptor::Delegate::Unregister() { |
| 331 net::URLRequestFilter::GetInstance()-> |
| 332 RemoveHostnameHandler("http", "localhost2"); |
| 333 } |
| 334 |
| 335 net::URLRequestJob* URLRequestPostInterceptor::Delegate::MaybeCreateJob( |
| 336 net::URLRequest* request, |
| 337 net::NetworkDelegate* network_delegate) const { |
| 338 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 339 if (request->has_upload()) { |
| 340 counter_->Trial(request); |
| 341 return new URLRequestPingMockJob(request, network_delegate); |
| 342 } |
| 343 return NULL; |
| 344 } |
| 345 |
| 346 URLRequestPingMockJob::URLRequestPingMockJob( |
| 347 net::URLRequest* request, |
| 348 net::NetworkDelegate* network_delegate) |
| 349 : net::URLRequestSimpleJob(request, network_delegate) { |
| 350 } |
| 351 |
| 352 int URLRequestPingMockJob::GetData( |
| 353 std::string* mime_type, |
| 354 std::string* charset, |
| 355 std::string* data, |
| 356 const net::CompletionCallback& callback) const { |
| 357 mime_type->assign("text/plain"); |
| 358 charset->assign("US-ASCII"); |
| 359 data->assign(""); // There is no reason to have a response body in this test. |
| 360 return net::OK; |
| 361 } |
| 362 |
| 363 } // namespace |
| 364 |
| 365 TestInstaller::TestInstaller() |
| 366 : error_(0), install_count_(0) { |
| 367 } |
| 368 |
| 369 void TestInstaller::OnUpdateError(int error) { |
| 370 EXPECT_NE(0, error); |
| 371 error_ = error; |
| 372 } |
| 373 |
| 374 bool TestInstaller::Install(const base::DictionaryValue& manifest, |
| 375 const base::FilePath& unpack_path) { |
| 376 ++install_count_; |
| 377 return file_util::Delete(unpack_path, true); |
| 378 } |
| 379 |
| 380 bool TestInstaller::GetInstalledFile(const std::string& file, |
| 381 base::FilePath* installed_file) { |
| 382 return false; |
| 383 } |
| 384 |
| 385 int TestInstaller::error() const { return error_; } |
| 386 |
| 387 int TestInstaller::install_count() const { return install_count_; } |
| 388 |
| 389 PersistentTestInstaller::PersistentTestInstaller() { |
| 390 file_util::CreateNewTempDirectory(FILE_PATH_LITERAL("TEST_"), |
| 391 &install_directory_); |
| 392 } |
| 393 |
| 394 PersistentTestInstaller::~PersistentTestInstaller() { |
| 395 file_util::Delete(install_directory_, true); |
| 396 } |
| 397 |
| 398 bool PersistentTestInstaller::Install(const base::DictionaryValue& manifest, |
| 399 const base::FilePath& unpack_path) { |
| 400 std::string version_string; |
| 401 manifest.GetStringASCII("version", &version_string); |
| 402 Version version(version_string.c_str()); |
| 403 |
| 404 base::FilePath path; |
| 405 path = install_directory_.AppendASCII(version.GetString()); |
| 406 file_util::CreateDirectory(path.DirName()); |
| 407 if (!file_util::Move(unpack_path, path)) |
| 408 return false; |
| 409 current_version_ = version; |
| 410 ++install_count_; |
| 411 return true; |
| 412 } |
| 413 |
| 414 bool PersistentTestInstaller::GetInstalledFile(const std::string& file, |
| 415 base::FilePath* installed_file) { |
| 416 base::FilePath path; |
| 417 path = install_directory_.AppendASCII(current_version_.GetString()); |
| 418 *installed_file = path.Append(base::FilePath::FromUTF8Unsafe(file)); |
| 419 return true; |
| 420 } |
| 421 |
| 422 TestConfigurator::TestConfigurator() |
| 423 : times_(1), recheck_time_(0), ondemand_time_(0), cus_(NULL) { |
| 424 } |
| 425 |
| 426 int TestConfigurator::InitialDelay() { return 0; } |
| 427 |
| 428 int TestConfigurator::NextCheckDelay() { |
| 429 // This is called when a new full cycle of checking for updates is going |
| 430 // to happen. In test we normally only test one cycle so it is a good |
| 431 // time to break from the test messageloop Run() method so the test can |
| 432 // finish. |
| 433 if (--times_ <= 0) { |
| 434 MessageLoop::current()->Quit(); |
| 435 return 0; |
| 436 } |
| 437 |
| 438 // Look for checks to issue in the middle of the loop. |
| 439 for (std::list<CheckAtLoopCount>::iterator |
| 440 i = components_to_check_.begin(); |
| 441 i != components_to_check_.end(); ) { |
| 442 if (i->second == times_) { |
| 443 cus_->CheckForUpdateSoon(*i->first); |
| 444 i = components_to_check_.erase(i); |
| 445 } else { |
| 446 ++i; |
| 447 } |
| 448 } |
| 449 return 1; |
| 450 } |
| 451 |
| 452 int TestConfigurator::StepDelay() { |
| 453 return 0; |
| 454 } |
| 455 |
| 456 int TestConfigurator::MinimumReCheckWait() { |
| 457 return recheck_time_; |
| 458 } |
| 459 |
| 460 int TestConfigurator::OnDemandDelay() { |
| 461 return ondemand_time_; |
| 462 } |
| 463 |
| 464 GURL TestConfigurator::UpdateUrl(CrxComponent::UrlSource source) { |
| 465 switch (source) { |
| 466 case CrxComponent::BANDAID: |
| 467 return GURL("http://localhost/upd"); |
| 468 case CrxComponent::CWS_PUBLIC: |
| 469 return GURL("http://localhost/cws"); |
| 470 default: |
| 471 return GURL("http://wronghost/bad"); |
| 472 }; |
| 473 } |
| 474 |
| 475 GURL TestConfigurator::PingUrl() { |
| 476 return GURL("http://localhost2/ping"); |
| 477 } |
| 478 |
| 479 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } |
| 480 |
| 481 size_t TestConfigurator::UrlSizeLimit() { return 256; } |
| 482 |
| 483 net::URLRequestContextGetter* TestConfigurator::RequestContext() { |
| 484 return new net::TestURLRequestContextGetter( |
| 485 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); |
| 486 } |
| 487 |
| 488 // Don't use the utility process to decode files. |
| 489 bool TestConfigurator::InProcess() { return true; } |
| 490 |
| 491 void TestConfigurator::OnEvent(Events event, int extra) { } |
| 492 |
| 493 ComponentPatcher* TestConfigurator::CreateComponentPatcher() { |
| 494 return new MockComponentPatcher(); |
| 495 } |
| 496 |
| 497 bool TestConfigurator::PingsEnabled() const { |
| 498 return true; |
| 499 } |
| 500 |
| 501 bool TestConfigurator::DeltasEnabled() const { |
| 502 return true; |
| 503 } |
| 504 |
| 505 // Set how many update checks are called, the default value is just once. |
| 506 void TestConfigurator::SetLoopCount(int times) { times_ = times; } |
| 507 |
| 508 void TestConfigurator::SetRecheckTime(int seconds) { |
| 509 recheck_time_ = seconds; |
| 510 } |
| 511 |
| 512 void TestConfigurator::SetOnDemandTime(int seconds) { |
| 513 ondemand_time_ = seconds; |
| 514 } |
| 515 |
| 516 void TestConfigurator::AddComponentToCheck(CrxComponent* com, |
| 517 int at_loop_iter) { |
| 518 components_to_check_.push_back(std::make_pair(com, at_loop_iter)); |
| 519 } |
| 520 |
| 521 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { |
| 522 cus_ = cus; |
| 523 } |
| 524 |
| 525 ComponentUpdaterTest::ComponentUpdaterTest() |
| 526 : component_updater_(NULL), test_config_(NULL) { |
| 527 // The component updater instance under test. |
| 528 test_config_ = new TestConfigurator; |
| 529 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); |
| 530 test_config_->SetComponentUpdateService(component_updater_.get()); |
| 531 // The test directory is chrome/test/data/components. |
| 532 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| 533 test_data_dir_ = test_data_dir_.AppendASCII("components"); |
| 534 |
| 535 // Subscribe to all component updater notifications. |
| 536 const int notifications[] = { |
| 537 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, |
| 538 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, |
| 539 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, |
| 540 chrome::NOTIFICATION_COMPONENT_UPDATE_READY |
| 541 }; |
| 542 |
| 543 for (int ix = 0; ix != arraysize(notifications); ++ix) { |
| 544 notification_tracker_.ListenFor( |
| 545 notifications[ix], content::NotificationService::AllSources()); |
| 546 } |
| 547 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 548 } |
| 549 |
| 550 ComponentUpdaterTest::~ComponentUpdaterTest() { |
| 551 net::URLFetcher::SetEnableInterceptionForTests(false); |
| 552 } |
| 553 |
| 554 void ComponentUpdaterTest::TearDown() { |
| 555 xmlCleanupGlobals(); |
| 556 } |
| 557 |
| 558 ComponentUpdateService* ComponentUpdaterTest::component_updater() { |
| 559 return component_updater_.get(); |
| 560 } |
| 561 |
| 562 // Makes the full path to a component updater test file. |
| 563 const base::FilePath ComponentUpdaterTest::test_file(const char* file) { |
| 564 return test_data_dir_.AppendASCII(file); |
| 565 } |
| 566 |
| 567 TestNotificationTracker& ComponentUpdaterTest::notification_tracker() { |
| 568 return notification_tracker_; |
| 569 } |
| 570 |
| 571 TestConfigurator* ComponentUpdaterTest::test_configurator() { |
| 572 return test_config_; |
| 573 } |
| 574 |
| 575 ComponentUpdateService::Status ComponentUpdaterTest::RegisterComponent( |
| 576 CrxComponent* com, |
| 577 TestComponents component, |
| 578 const Version& version, |
| 579 TestInstaller* installer) { |
| 580 if (component == kTestComponent_abag) { |
| 581 com->name = "test_abag"; |
| 582 com->pk_hash.assign(abag_hash, abag_hash + arraysize(abag_hash)); |
| 583 } else if (component == kTestComponent_jebg) { |
| 584 com->name = "test_jebg"; |
| 585 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 586 } else { |
| 587 com->name = "test_ihfo"; |
| 588 com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
| 589 } |
| 590 com->version = version; |
| 591 com->installer = installer; |
| 592 return component_updater_->RegisterComponent(*com); |
| 593 } |
| 262 | 594 |
| 263 // Verify that our test fixture work and the component updater can | 595 // Verify that our test fixture work and the component updater can |
| 264 // be created and destroyed with no side effects. | 596 // be created and destroyed with no side effects. |
| 265 TEST_F(ComponentUpdaterTest, VerifyFixture) { | 597 TEST_F(ComponentUpdaterTest, VerifyFixture) { |
| 266 EXPECT_TRUE(component_updater() != NULL); | 598 EXPECT_TRUE(component_updater() != NULL); |
| 267 EXPECT_EQ(0ul, notification_tracker().size()); | 599 EXPECT_EQ(0ul, notification_tracker().size()); |
| 268 } | 600 } |
| 269 | 601 |
| 270 // Verify that the component updater can be caught in a quick | 602 // Verify that the component updater can be caught in a quick |
| 271 // start-shutdown situation. Failure of this test will be a crash. Also | 603 // start-shutdown situation. Failure of this test will be a crash. Also |
| (...skipping 16 matching lines...) Expand all Loading... |
| 288 MessageLoop message_loop; | 620 MessageLoop message_loop; |
| 289 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 621 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 290 content::TestBrowserThread file_thread(BrowserThread::FILE); | 622 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 291 content::TestBrowserThread io_thread(BrowserThread::IO); | 623 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 292 | 624 |
| 293 io_thread.StartIOThread(); | 625 io_thread.StartIOThread(); |
| 294 file_thread.Start(); | 626 file_thread.Start(); |
| 295 | 627 |
| 296 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 628 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 297 | 629 |
| 630 TestInstaller installer; |
| 298 CrxComponent com; | 631 CrxComponent com; |
| 299 EXPECT_EQ(ComponentUpdateService::kOk, | 632 EXPECT_EQ(ComponentUpdateService::kOk, |
| 300 RegisterComponent(&com, kTestComponent_abag, Version("1.1"))); | 633 RegisterComponent(&com, |
| 634 kTestComponent_abag, |
| 635 Version("1.1"), |
| 636 &installer)); |
| 301 | 637 |
| 302 const GURL expected_update_url( | 638 const GURL expected_update_url( |
| 303 "http://localhost/upd?extra=foo&x=id%3D" | 639 "http://localhost/upd?extra=foo" |
| 304 "abagagagagagagagagagagagagagagag%26v%3D1.1%26uc"); | 640 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc"); |
| 305 | 641 |
| 306 interceptor.SetResponse(expected_update_url, | 642 interceptor.SetResponse(expected_update_url, |
| 307 test_file("updatecheck_reply_1.xml")); | 643 test_file("updatecheck_reply_1.xml")); |
| 308 | 644 |
| 309 // We loop twice, but there are no updates so we expect two sleep messages. | 645 // We loop twice, but there are no updates so we expect two sleep messages. |
| 310 test_configurator()->SetLoopCount(2); | 646 test_configurator()->SetLoopCount(2); |
| 311 component_updater()->Start(); | 647 component_updater()->Start(); |
| 312 | 648 |
| 313 ASSERT_EQ(1ul, notification_tracker().size()); | 649 ASSERT_EQ(1ul, notification_tracker().size()); |
| 314 TestNotificationTracker::Event ev1 = notification_tracker().at(0); | 650 TestNotificationTracker::Event ev1 = notification_tracker().at(0); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 688 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 353 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 689 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 354 | 690 |
| 355 component_updater()->Stop(); | 691 component_updater()->Stop(); |
| 356 } | 692 } |
| 357 | 693 |
| 358 // Verify that we can check for updates and install one component. Besides | 694 // Verify that we can check for updates and install one component. Besides |
| 359 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and | 695 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and |
| 360 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops | 696 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops |
| 361 // so the second time around there should be nothing left to do. | 697 // so the second time around there should be nothing left to do. |
| 362 // We also check that only 3 network requests are issued: | 698 // We also check that only 3 non-ping network requests are issued: |
| 363 // 1- manifest check | 699 // 1- manifest check |
| 364 // 2- download crx | 700 // 2- download crx |
| 365 // 3- second manifest check. | 701 // 3- second manifest check. |
| 366 TEST_F(ComponentUpdaterTest, InstallCrx) { | 702 TEST_F(ComponentUpdaterTest, InstallCrx) { |
| 367 MessageLoop message_loop; | 703 MessageLoop message_loop; |
| 368 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 704 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 369 content::TestBrowserThread file_thread(BrowserThread::FILE); | 705 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 370 content::TestBrowserThread io_thread(BrowserThread::IO); | 706 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 371 | 707 |
| 372 io_thread.StartIOThread(); | 708 io_thread.StartIOThread(); |
| 373 file_thread.Start(); | 709 file_thread.Start(); |
| 374 | 710 |
| 711 std::map<std::string, std::string> map; |
| 712 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 713 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 714 map.insert(std::pair<std::string, std::string>("previousversion", |
| 715 "\"0.9\"")); |
| 716 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 717 PingChecker ping_checker(map); |
| 718 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 375 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 719 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 376 | 720 |
| 721 TestInstaller installer1; |
| 377 CrxComponent com1; | 722 CrxComponent com1; |
| 378 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9")); | 723 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
| 724 TestInstaller installer2; |
| 379 CrxComponent com2; | 725 CrxComponent com2; |
| 380 RegisterComponent(&com2, kTestComponent_abag, Version("2.2")); | 726 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
| 381 | 727 |
| 382 const GURL expected_update_url_1( | 728 const GURL expected_update_url_1( |
| 383 "http://localhost/upd?extra=foo&x=id%3D" | 729 "http://localhost/upd?extra=foo" |
| 384 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D" | 730 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" |
| 385 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); | 731 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| 386 | 732 |
| 387 const GURL expected_update_url_2( | 733 const GURL expected_update_url_2( |
| 388 "http://localhost/upd?extra=foo&x=id%3D" | 734 "http://localhost/upd?extra=foo" |
| 389 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D" | 735 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" |
| 390 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc"); | 736 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"); |
| 391 | 737 |
| 392 interceptor.SetResponse(expected_update_url_1, | 738 interceptor.SetResponse(expected_update_url_1, |
| 393 test_file("updatecheck_reply_1.xml")); | 739 test_file("updatecheck_reply_1.xml")); |
| 394 interceptor.SetResponse(expected_update_url_2, | 740 interceptor.SetResponse(expected_update_url_2, |
| 395 test_file("updatecheck_reply_1.xml")); | 741 test_file("updatecheck_reply_1.xml")); |
| 396 interceptor.SetResponse(GURL(expected_crx_url), | 742 interceptor.SetResponse(GURL(expected_crx_url), |
| 397 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 743 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 398 | 744 |
| 399 test_configurator()->SetLoopCount(2); | 745 test_configurator()->SetLoopCount(2); |
| 400 | 746 |
| 401 component_updater()->Start(); | 747 component_updater()->Start(); |
| 402 message_loop.Run(); | 748 message_loop.Run(); |
| 403 | 749 |
| 404 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 750 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 405 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 751 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 406 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 752 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 407 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 753 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 408 | 754 |
| 409 EXPECT_EQ(3, interceptor.GetHitCount()); | 755 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 756 EXPECT_EQ(1, ping_checker.NumHits()); |
| 757 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 410 | 758 |
| 411 ASSERT_EQ(5ul, notification_tracker().size()); | 759 ASSERT_EQ(5ul, notification_tracker().size()); |
| 412 | 760 |
| 413 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 761 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 414 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 762 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
| 415 | 763 |
| 416 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 764 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
| 417 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 765 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
| 418 | 766 |
| 419 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 767 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 430 // checks to different urls, each only containing one component. | 778 // checks to different urls, each only containing one component. |
| 431 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) { | 779 TEST_F(ComponentUpdaterTest, InstallCrxTwoSources) { |
| 432 MessageLoop message_loop; | 780 MessageLoop message_loop; |
| 433 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 781 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 434 content::TestBrowserThread file_thread(BrowserThread::FILE); | 782 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 435 content::TestBrowserThread io_thread(BrowserThread::IO); | 783 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 436 | 784 |
| 437 io_thread.StartIOThread(); | 785 io_thread.StartIOThread(); |
| 438 file_thread.Start(); | 786 file_thread.Start(); |
| 439 | 787 |
| 788 std::map<std::string, std::string> map; |
| 789 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 790 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 791 map.insert(std::pair<std::string, std::string>("previousversion", |
| 792 "\"0.9\"")); |
| 793 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 794 PingChecker ping_checker(map); |
| 795 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 440 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 796 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 441 | 797 |
| 798 TestInstaller installer1; |
| 442 CrxComponent com1; | 799 CrxComponent com1; |
| 443 RegisterComponent(&com1, kTestComponent_abag, Version("2.2")); | 800 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); |
| 801 TestInstaller installer2; |
| 444 CrxComponent com2; | 802 CrxComponent com2; |
| 445 com2.source = CrxComponent::CWS_PUBLIC; | 803 com2.source = CrxComponent::CWS_PUBLIC; |
| 446 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9")); | 804 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); |
| 447 | 805 |
| 448 const GURL expected_update_url_1( | 806 const GURL expected_update_url_1( |
| 449 "http://localhost/upd?extra=foo&x=id%3D" | 807 "http://localhost/upd?extra=foo&x=id%3D" |
| 450 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); | 808 "abagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| 451 | 809 |
| 452 const GURL expected_update_url_2( | 810 const GURL expected_update_url_2( |
| 453 "http://localhost/cws?extra=foo&x=id%3D" | 811 "http://localhost/cws?extra=foo&x=id%3D" |
| 454 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc"); | 812 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
| 455 | 813 |
| 456 interceptor.SetResponse(expected_update_url_1, | 814 interceptor.SetResponse(expected_update_url_1, |
| 457 test_file("updatecheck_reply_3.xml")); | 815 test_file("updatecheck_reply_3.xml")); |
| 458 interceptor.SetResponse(expected_update_url_2, | 816 interceptor.SetResponse(expected_update_url_2, |
| 459 test_file("updatecheck_reply_1.xml")); | 817 test_file("updatecheck_reply_1.xml")); |
| 460 interceptor.SetResponse(GURL(expected_crx_url), | 818 interceptor.SetResponse(GURL(expected_crx_url), |
| 461 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 819 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 462 | 820 |
| 463 test_configurator()->SetLoopCount(3); | 821 test_configurator()->SetLoopCount(3); |
| 464 | 822 |
| 465 // We have to set SetRecheckTime to something bigger than 0 or else the | 823 // We have to set SetRecheckTime to something bigger than 0 or else the |
| 466 // component updater will keep re-checking the 'abag' component because | 824 // component updater will keep re-checking the 'abag' component because |
| 467 // the default source pre-empts the other sources. | 825 // the default source pre-empts the other sources. |
| 468 test_configurator()->SetRecheckTime(60*60); | 826 test_configurator()->SetRecheckTime(60*60); |
| 469 | 827 |
| 470 component_updater()->Start(); | 828 component_updater()->Start(); |
| 471 message_loop.Run(); | 829 message_loop.Run(); |
| 472 | 830 |
| 473 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 831 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 474 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); | 832 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 475 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 833 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 476 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count()); | 834 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 477 | 835 |
| 836 EXPECT_EQ(1, ping_checker.NumHits()); |
| 837 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 478 EXPECT_EQ(3, interceptor.GetHitCount()); | 838 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 479 | 839 |
| 480 ASSERT_EQ(6ul, notification_tracker().size()); | 840 ASSERT_EQ(6ul, notification_tracker().size()); |
| 481 | 841 |
| 482 TestNotificationTracker::Event ev0 = notification_tracker().at(1); | 842 TestNotificationTracker::Event ev0 = notification_tracker().at(1); |
| 483 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev0.type); | 843 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev0.type); |
| 484 | 844 |
| 485 TestNotificationTracker::Event ev1 = notification_tracker().at(2); | 845 TestNotificationTracker::Event ev1 = notification_tracker().at(2); |
| 486 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 846 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
| 487 | 847 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 502 // version is much higher than of chrome. | 862 // version is much higher than of chrome. |
| 503 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { | 863 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
| 504 MessageLoop message_loop; | 864 MessageLoop message_loop; |
| 505 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 865 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 506 content::TestBrowserThread file_thread(BrowserThread::FILE); | 866 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 507 content::TestBrowserThread io_thread(BrowserThread::IO); | 867 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 508 | 868 |
| 509 io_thread.StartIOThread(); | 869 io_thread.StartIOThread(); |
| 510 file_thread.Start(); | 870 file_thread.Start(); |
| 511 | 871 |
| 872 std::map<std::string, std::string> map; |
| 873 PingChecker ping_checker(map); |
| 874 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 512 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 875 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 513 | 876 |
| 877 TestInstaller installer; |
| 514 CrxComponent com; | 878 CrxComponent com; |
| 515 RegisterComponent(&com, kTestComponent_jebg, Version("0.9")); | 879 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); |
| 516 | 880 |
| 517 const GURL expected_update_url( | 881 const GURL expected_update_url( |
| 518 "http://localhost/upd?extra=foo&x=id%3D" | 882 "http://localhost/upd?extra=foo&x=id%3D" |
| 519 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc"); | 883 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
| 520 | 884 |
| 521 interceptor.SetResponse(expected_update_url, | 885 interceptor.SetResponse(expected_update_url, |
| 522 test_file("updatecheck_reply_2.xml")); | 886 test_file("updatecheck_reply_2.xml")); |
| 523 interceptor.SetResponse(GURL(expected_crx_url), | 887 interceptor.SetResponse(GURL(expected_crx_url), |
| 524 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 888 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 525 | 889 |
| 526 test_configurator()->SetLoopCount(1); | 890 test_configurator()->SetLoopCount(1); |
| 527 component_updater()->Start(); | 891 component_updater()->Start(); |
| 528 message_loop.Run(); | 892 message_loop.Run(); |
| 529 | 893 |
| 894 EXPECT_EQ(0, ping_checker.NumHits()); |
| 895 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 530 EXPECT_EQ(1, interceptor.GetHitCount()); | 896 EXPECT_EQ(1, interceptor.GetHitCount()); |
| 531 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 897 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 532 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 898 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 533 | 899 |
| 534 component_updater()->Stop(); | 900 component_updater()->Stop(); |
| 535 } | 901 } |
| 536 | 902 |
| 537 // Test that a ping for an update check can cause installs. | 903 // Test that a ping for an update check can cause installs. |
| 538 // Here is the timeline: | 904 // Here is the timeline: |
| 539 // - First loop: we return a reply that indicates no update, so | 905 // - First loop: we return a reply that indicates no update, so |
| 540 // nothing happens. | 906 // nothing happens. |
| 541 // - We ping. | 907 // - We ping. |
| 542 // - This triggers a second loop, which has a reply that triggers an install. | 908 // - This triggers a second loop, which has a reply that triggers an install. |
| 543 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { | 909 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { |
| 544 MessageLoop message_loop; | 910 MessageLoop message_loop; |
| 545 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 911 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 546 content::TestBrowserThread file_thread(BrowserThread::FILE); | 912 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 547 content::TestBrowserThread io_thread(BrowserThread::IO); | 913 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 548 | 914 |
| 549 io_thread.StartIOThread(); | 915 io_thread.StartIOThread(); |
| 550 file_thread.Start(); | 916 file_thread.Start(); |
| 551 | 917 |
| 918 std::map<std::string, std::string> map; |
| 919 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 920 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 921 map.insert(std::pair<std::string, std::string>("previousversion", |
| 922 "\"0.9\"")); |
| 923 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 924 PingChecker ping_checker(map); |
| 925 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 552 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 926 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 553 | 927 |
| 928 TestInstaller installer1; |
| 554 CrxComponent com1; | 929 CrxComponent com1; |
| 555 RegisterComponent(&com1, kTestComponent_abag, Version("2.2")); | 930 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); |
| 931 TestInstaller installer2; |
| 556 CrxComponent com2; | 932 CrxComponent com2; |
| 557 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9")); | 933 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); |
| 558 | 934 |
| 559 const GURL expected_update_url_1( | 935 const GURL expected_update_url_1( |
| 560 "http://localhost/upd?extra=foo&x=id%3D" | 936 "http://localhost/upd?extra=foo" |
| 561 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D" | 937 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" |
| 562 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc"); | 938 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
| 563 | 939 |
| 564 const GURL expected_update_url_2( | 940 const GURL expected_update_url_2( |
| 565 "http://localhost/upd?extra=foo&x=id%3D" | 941 "http://localhost/upd?extra=foo" |
| 566 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D" | 942 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" |
| 567 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); | 943 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| 568 | 944 |
| 569 interceptor.SetResponse(expected_update_url_1, | 945 interceptor.SetResponse(expected_update_url_1, |
| 570 test_file("updatecheck_reply_empty")); | 946 test_file("updatecheck_reply_empty")); |
| 571 interceptor.SetResponse(expected_update_url_2, | 947 interceptor.SetResponse(expected_update_url_2, |
| 572 test_file("updatecheck_reply_1.xml")); | 948 test_file("updatecheck_reply_1.xml")); |
| 573 interceptor.SetResponse(GURL(expected_crx_url), | 949 interceptor.SetResponse(GURL(expected_crx_url), |
| 574 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 950 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 575 // Test success. | 951 // Test success. |
| 576 test_configurator()->SetLoopCount(2); | 952 test_configurator()->SetLoopCount(2); |
| 577 test_configurator()->AddComponentToCheck(&com2, 1); | 953 test_configurator()->AddComponentToCheck(&com2, 1); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 606 test_configurator()->SetOnDemandTime(60 * 60); | 982 test_configurator()->SetOnDemandTime(60 * 60); |
| 607 EXPECT_EQ(ComponentUpdateService::kError, | 983 EXPECT_EQ(ComponentUpdateService::kError, |
| 608 component_updater()->CheckForUpdateSoon(com2)); | 984 component_updater()->CheckForUpdateSoon(com2)); |
| 609 // Okay, now reset to 0 for the other tests. | 985 // Okay, now reset to 0 for the other tests. |
| 610 test_configurator()->SetOnDemandTime(0); | 986 test_configurator()->SetOnDemandTime(0); |
| 611 component_updater()->Stop(); | 987 component_updater()->Stop(); |
| 612 | 988 |
| 613 // Test a few error cases. NOTE: We don't have callbacks for | 989 // Test a few error cases. NOTE: We don't have callbacks for |
| 614 // when the updates failed yet. | 990 // when the updates failed yet. |
| 615 const GURL expected_update_url_3( | 991 const GURL expected_update_url_3( |
| 616 "http://localhost/upd?extra=foo&x=id%3D" | 992 "http://localhost/upd?extra=foo" |
| 617 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc&x=id%3D" | 993 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc" |
| 618 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); | 994 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| 619 | 995 |
| 620 // No update: error from no server response | 996 // No update: error from no server response |
| 621 interceptor.SetResponse(expected_update_url_3, | 997 interceptor.SetResponse(expected_update_url_3, |
| 622 test_file("updatecheck_reply_empty")); | 998 test_file("updatecheck_reply_empty")); |
| 623 notification_tracker().Reset(); | 999 notification_tracker().Reset(); |
| 624 test_configurator()->SetLoopCount(1); | 1000 test_configurator()->SetLoopCount(1); |
| 625 component_updater()->Start(); | 1001 component_updater()->Start(); |
| 626 EXPECT_EQ(ComponentUpdateService::kOk, | 1002 EXPECT_EQ(ComponentUpdateService::kOk, |
| 627 component_updater()->CheckForUpdateSoon(com2)); | 1003 component_updater()->CheckForUpdateSoon(com2)); |
| 628 | 1004 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 639 interceptor.SetResponse(expected_update_url_3, | 1015 interceptor.SetResponse(expected_update_url_3, |
| 640 test_file("updatecheck_reply_1.xml")); | 1016 test_file("updatecheck_reply_1.xml")); |
| 641 notification_tracker().Reset(); | 1017 notification_tracker().Reset(); |
| 642 test_configurator()->SetLoopCount(1); | 1018 test_configurator()->SetLoopCount(1); |
| 643 component_updater()->Start(); | 1019 component_updater()->Start(); |
| 644 EXPECT_EQ(ComponentUpdateService::kOk, | 1020 EXPECT_EQ(ComponentUpdateService::kOk, |
| 645 component_updater()->CheckForUpdateSoon(com2)); | 1021 component_updater()->CheckForUpdateSoon(com2)); |
| 646 | 1022 |
| 647 message_loop.Run(); | 1023 message_loop.Run(); |
| 648 | 1024 |
| 1025 EXPECT_EQ(1, ping_checker.NumHits()); |
| 1026 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 649 ASSERT_EQ(2ul, notification_tracker().size()); | 1027 ASSERT_EQ(2ul, notification_tracker().size()); |
| 650 ev0 = notification_tracker().at(0); | 1028 ev0 = notification_tracker().at(0); |
| 651 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 1029 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 652 ev1 = notification_tracker().at(1); | 1030 ev1 = notification_tracker().at(1); |
| 653 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); | 1031 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); |
| 654 component_updater()->Stop(); | 1032 component_updater()->Stop(); |
| 655 } | 1033 } |
| 656 | 1034 |
| 657 // Verify that a previously registered component can get re-registered | 1035 // Verify that a previously registered component can get re-registered |
| 658 // with a different version. | 1036 // with a different version. |
| 659 TEST_F(ComponentUpdaterTest, CheckReRegistration) { | 1037 TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| 660 MessageLoop message_loop; | 1038 MessageLoop message_loop; |
| 661 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 1039 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 662 content::TestBrowserThread file_thread(BrowserThread::FILE); | 1040 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 663 content::TestBrowserThread io_thread(BrowserThread::IO); | 1041 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 664 | 1042 |
| 665 io_thread.StartIOThread(); | 1043 io_thread.StartIOThread(); |
| 666 file_thread.Start(); | 1044 file_thread.Start(); |
| 667 | 1045 |
| 1046 std::map<std::string, std::string> map; |
| 1047 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 1048 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 1049 map.insert(std::pair<std::string, std::string>("previousversion", |
| 1050 "\"0.9\"")); |
| 1051 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 1052 PingChecker ping_checker(map); |
| 1053 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 668 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 1054 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 669 | 1055 |
| 1056 TestInstaller installer1; |
| 670 CrxComponent com1; | 1057 CrxComponent com1; |
| 671 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9")); | 1058 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
| 1059 TestInstaller installer2; |
| 672 CrxComponent com2; | 1060 CrxComponent com2; |
| 673 RegisterComponent(&com2, kTestComponent_abag, Version("2.2")); | 1061 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
| 674 | 1062 |
| 675 // Start with 0.9, and update to 1.0 | 1063 // Start with 0.9, and update to 1.0 |
| 676 const GURL expected_update_url_1( | 1064 const GURL expected_update_url_1( |
| 677 "http://localhost/upd?extra=foo&x=id%3D" | 1065 "http://localhost/upd?extra=foo" |
| 678 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26uc&x=id%3D" | 1066 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" |
| 679 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); | 1067 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| 680 | 1068 |
| 681 const GURL expected_update_url_2( | 1069 const GURL expected_update_url_2( |
| 682 "http://localhost/upd?extra=foo&x=id%3D" | 1070 "http://localhost/upd?extra=foo" |
| 683 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc&x=id%3D" | 1071 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" |
| 684 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26uc"); | 1072 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"); |
| 685 | 1073 |
| 686 interceptor.SetResponse(expected_update_url_1, | 1074 interceptor.SetResponse(expected_update_url_1, |
| 687 test_file("updatecheck_reply_1.xml")); | 1075 test_file("updatecheck_reply_1.xml")); |
| 688 interceptor.SetResponse(expected_update_url_2, | 1076 interceptor.SetResponse(expected_update_url_2, |
| 689 test_file("updatecheck_reply_1.xml")); | 1077 test_file("updatecheck_reply_1.xml")); |
| 690 interceptor.SetResponse(GURL(expected_crx_url), | 1078 interceptor.SetResponse(GURL(expected_crx_url), |
| 691 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 1079 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 692 | 1080 |
| 693 // Loop twice to issue two checks: (1) with original 0.9 version | 1081 // Loop twice to issue two checks: (1) with original 0.9 version |
| 694 // and (2) with the updated 1.0 version. | 1082 // and (2) with the updated 1.0 version. |
| 695 test_configurator()->SetLoopCount(2); | 1083 test_configurator()->SetLoopCount(2); |
| 696 | 1084 |
| 697 component_updater()->Start(); | 1085 component_updater()->Start(); |
| 698 message_loop.Run(); | 1086 message_loop.Run(); |
| 699 | 1087 |
| 700 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 1088 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 701 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 1089 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 702 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 1090 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 703 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 1091 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 704 | 1092 |
| 1093 EXPECT_EQ(1, ping_checker.NumHits()); |
| 1094 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 705 EXPECT_EQ(3, interceptor.GetHitCount()); | 1095 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 706 | 1096 |
| 707 ASSERT_EQ(5ul, notification_tracker().size()); | 1097 ASSERT_EQ(5ul, notification_tracker().size()); |
| 708 | 1098 |
| 709 TestNotificationTracker::Event ev0 = notification_tracker().at(0); | 1099 TestNotificationTracker::Event ev0 = notification_tracker().at(0); |
| 710 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 1100 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 711 | 1101 |
| 712 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 1102 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 713 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 1103 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
| 714 | 1104 |
| 715 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 1105 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
| 716 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 1106 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
| 717 | 1107 |
| 718 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 1108 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
| 719 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 1109 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
| 720 | 1110 |
| 721 TestNotificationTracker::Event ev4 = notification_tracker().at(4); | 1111 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
| 722 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); | 1112 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
| 723 | 1113 |
| 724 // Now re-register, pretending to be an even newer version (2.2) | 1114 // Now re-register, pretending to be an even newer version (2.2) |
| 1115 TestInstaller installer3; |
| 725 component_updater()->Stop(); | 1116 component_updater()->Stop(); |
| 726 EXPECT_EQ(ComponentUpdateService::kReplaced, | 1117 EXPECT_EQ(ComponentUpdateService::kReplaced, |
| 727 RegisterComponent(&com1, kTestComponent_jebg, Version("2.2"))); | 1118 RegisterComponent(&com1, |
| 1119 kTestComponent_jebg, |
| 1120 Version("2.2"), |
| 1121 &installer3)); |
| 728 | 1122 |
| 729 // Check that we send out 2.2 as our version. | 1123 // Check that we send out 2.2 as our version. |
| 730 // Interceptor's hit count should go up by 1. | 1124 // Interceptor's hit count should go up by 1. |
| 731 const GURL expected_update_url_3( | 1125 const GURL expected_update_url_3( |
| 732 "http://localhost/upd?extra=foo&x=id%3D" | 1126 "http://localhost/upd?extra=foo" |
| 733 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26uc&x=id%3D" | 1127 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D2.2%26fp%3D%26uc" |
| 734 "abagagagagagagagagagagagagagagag%26v%3D2.2%26uc"); | 1128 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| 735 | 1129 |
| 736 interceptor.SetResponse(expected_update_url_3, | 1130 interceptor.SetResponse(expected_update_url_3, |
| 737 test_file("updatecheck_reply_1.xml")); | 1131 test_file("updatecheck_reply_1.xml")); |
| 738 | 1132 |
| 739 notification_tracker().Reset(); | 1133 notification_tracker().Reset(); |
| 740 | 1134 |
| 741 // Loop once just to notice the check happening with the re-register version. | 1135 // Loop once just to notice the check happening with the re-register version. |
| 742 test_configurator()->SetLoopCount(1); | 1136 test_configurator()->SetLoopCount(1); |
| 743 component_updater()->Start(); | 1137 component_updater()->Start(); |
| 744 message_loop.Run(); | 1138 message_loop.Run(); |
| 745 | 1139 |
| 746 ASSERT_EQ(2ul, notification_tracker().size()); | 1140 ASSERT_EQ(2ul, notification_tracker().size()); |
| 747 | 1141 |
| 748 ev0 = notification_tracker().at(0); | 1142 ev0 = notification_tracker().at(0); |
| 749 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 1143 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 750 | 1144 |
| 751 ev1 = notification_tracker().at(1); | 1145 ev1 = notification_tracker().at(1); |
| 752 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); | 1146 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); |
| 753 | 1147 |
| 754 EXPECT_EQ(4, interceptor.GetHitCount()); | 1148 EXPECT_EQ(4, interceptor.GetHitCount()); |
| 755 | 1149 |
| 756 // The test harness's Register() function creates a new installer, | 1150 // We created a new installer, so the counts go back to 0. |
| 757 // so the counts go back to 0. | |
| 758 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 1151 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 759 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); | 1152 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 760 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 1153 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 761 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 1154 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 762 | 1155 |
| 763 component_updater()->Stop(); | 1156 component_updater()->Stop(); |
| 764 } | 1157 } |
| 1158 |
| 1159 // Verify that we can download and install a component and a differential |
| 1160 // update to that component. We do three loops; the final loop should do |
| 1161 // nothing. |
| 1162 // We also check that exactly 5 non-ping network requests are issued: |
| 1163 // 1- update check (response: v1 available) |
| 1164 // 2- download crx (v1) |
| 1165 // 3- update check (response: v2 available) |
| 1166 // 4- download differential crx (v1 to v2) |
| 1167 // 5- update check (response: no further update available) |
| 1168 // There should be two pings, one for each update. The second will bear a |
| 1169 // diffresult=1, while the first will not. |
| 1170 TEST_F(ComponentUpdaterTest, DifferentialUpdate) { |
| 1171 MessageLoop message_loop; |
| 1172 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 1173 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 1174 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 1175 |
| 1176 io_thread.StartIOThread(); |
| 1177 file_thread.Start(); |
| 1178 |
| 1179 std::map<std::string, std::string> map; |
| 1180 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 1181 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 1182 map.insert(std::pair<std::string, std::string>("diffresult", "\"1\"")); |
| 1183 PingChecker ping_checker(map); |
| 1184 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 1185 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 1186 |
| 1187 PersistentTestInstaller installer; |
| 1188 CrxComponent com; |
| 1189 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
| 1190 |
| 1191 const GURL expected_update_url_0( |
| 1192 "http://localhost/upd?extra=foo" |
| 1193 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); |
| 1194 const GURL expected_update_url_1( |
| 1195 "http://localhost/upd?extra=foo" |
| 1196 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc"); |
| 1197 const GURL expected_update_url_2( |
| 1198 "http://localhost/upd?extra=foo" |
| 1199 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc"); |
| 1200 const GURL expected_crx_url_1( |
| 1201 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"); |
| 1202 const GURL expected_crx_url_1_diff_2( |
| 1203 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"); |
| 1204 |
| 1205 interceptor.SetResponse(expected_update_url_0, |
| 1206 test_file("updatecheck_diff_reply_1.xml")); |
| 1207 interceptor.SetResponse(expected_update_url_1, |
| 1208 test_file("updatecheck_diff_reply_2.xml")); |
| 1209 interceptor.SetResponse(expected_update_url_2, |
| 1210 test_file("updatecheck_diff_reply_3.xml")); |
| 1211 interceptor.SetResponse(expected_crx_url_1, |
| 1212 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| 1213 interceptor.SetResponse( |
| 1214 expected_crx_url_1_diff_2, |
| 1215 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
| 1216 |
| 1217 test_configurator()->SetLoopCount(3); |
| 1218 |
| 1219 component_updater()->Start(); |
| 1220 message_loop.Run(); |
| 1221 |
| 1222 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 1223 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 1224 |
| 1225 EXPECT_EQ(1, ping_checker.NumHits()); |
| 1226 EXPECT_EQ(1, ping_checker.NumMisses()); |
| 1227 EXPECT_EQ(5, interceptor.GetHitCount()); |
| 1228 |
| 1229 component_updater()->Stop(); |
| 1230 } |
| 1231 |
| 1232 // Verify that component installation falls back to downloading and installing |
| 1233 // a full update if the differential update fails (in this case, because the |
| 1234 // installer does not know about the existing files). We do two loops; the final |
| 1235 // loop should do nothing. |
| 1236 // We also check that exactly 4 non-ping network requests are issued: |
| 1237 // 1- update check (loop 1) |
| 1238 // 2- download differential crx |
| 1239 // 3- download full crx |
| 1240 // 4- update check (loop 2 - no update available) |
| 1241 // There should be one ping for the first attempted update. |
| 1242 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { |
| 1243 MessageLoop message_loop; |
| 1244 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 1245 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 1246 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 1247 |
| 1248 io_thread.StartIOThread(); |
| 1249 file_thread.Start(); |
| 1250 |
| 1251 std::map<std::string, std::string> map; |
| 1252 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 1253 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 1254 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\"")); |
| 1255 map.insert(std::pair<std::string, std::string>("differrorcode", "\"12\"")); |
| 1256 PingChecker ping_checker(map); |
| 1257 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 1258 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 1259 |
| 1260 TestInstaller installer; |
| 1261 CrxComponent com; |
| 1262 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); |
| 1263 |
| 1264 const GURL expected_update_url_1( |
| 1265 "http://localhost/upd?extra=foo" |
| 1266 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); |
| 1267 const GURL expected_update_url_2( |
| 1268 "http://localhost/upd?extra=foo" |
| 1269 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc"); |
| 1270 const GURL expected_crx_url_1( |
| 1271 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"); |
| 1272 const GURL expected_crx_url_1_diff_2( |
| 1273 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"); |
| 1274 const GURL expected_crx_url_2( |
| 1275 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"); |
| 1276 |
| 1277 interceptor.SetResponse(expected_update_url_1, |
| 1278 test_file("updatecheck_diff_reply_2.xml")); |
| 1279 interceptor.SetResponse(expected_update_url_2, |
| 1280 test_file("updatecheck_diff_reply_3.xml")); |
| 1281 interceptor.SetResponse(expected_crx_url_1, |
| 1282 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| 1283 interceptor.SetResponse( |
| 1284 expected_crx_url_1_diff_2, |
| 1285 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
| 1286 interceptor.SetResponse(expected_crx_url_2, |
| 1287 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
| 1288 |
| 1289 test_configurator()->SetLoopCount(2); |
| 1290 |
| 1291 component_updater()->Start(); |
| 1292 message_loop.Run(); |
| 1293 |
| 1294 // A failed differential update does not count as a failed install. |
| 1295 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 1296 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 1297 |
| 1298 EXPECT_EQ(1, ping_checker.NumHits()); |
| 1299 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 1300 EXPECT_EQ(4, interceptor.GetHitCount()); |
| 1301 |
| 1302 component_updater()->Stop(); |
| 1303 } |
| 1304 |
| 1305 // Verify that a failed installation causes an install failure ping. |
| 1306 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { |
| 1307 MessageLoop message_loop; |
| 1308 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 1309 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 1310 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 1311 |
| 1312 io_thread.StartIOThread(); |
| 1313 file_thread.Start(); |
| 1314 |
| 1315 std::map<std::string, std::string> map; |
| 1316 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 1317 map.insert(std::pair<std::string, std::string>("eventresult", "\"0\"")); |
| 1318 map.insert(std::pair<std::string, std::string>("errorcode", "\"9\"")); |
| 1319 map.insert(std::pair<std::string, std::string>("previousversion", |
| 1320 "\"0.9\"")); |
| 1321 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 1322 PingChecker ping_checker(map); |
| 1323 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 1324 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 1325 |
| 1326 // This test installer reports installation failure. |
| 1327 class : public TestInstaller { |
| 1328 virtual bool Install(const base::DictionaryValue& manifest, |
| 1329 const base::FilePath& unpack_path) OVERRIDE { |
| 1330 ++install_count_; |
| 1331 file_util::Delete(unpack_path, true); |
| 1332 return false; |
| 1333 } |
| 1334 } installer; |
| 1335 |
| 1336 CrxComponent com; |
| 1337 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); |
| 1338 |
| 1339 // Start with 0.9, and attempt update to 1.0 |
| 1340 const GURL expected_update_url_1( |
| 1341 "http://localhost/upd?extra=foo" |
| 1342 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
| 1343 |
| 1344 interceptor.SetResponse(expected_update_url_1, |
| 1345 test_file("updatecheck_reply_1.xml")); |
| 1346 interceptor.SetResponse(GURL(expected_crx_url), |
| 1347 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 1348 |
| 1349 // Loop twice to issue two checks: (1) with original 0.9 version |
| 1350 // and (2), which should retry with 0.9. |
| 1351 test_configurator()->SetLoopCount(2); |
| 1352 component_updater()->Start(); |
| 1353 message_loop.Run(); |
| 1354 |
| 1355 // Loop once more, but expect no ping because a noupdate response is issued. |
| 1356 // This is necessary to clear out the fire-and-forget ping from the previous |
| 1357 // iteration. |
| 1358 interceptor.SetResponse(expected_update_url_1, |
| 1359 test_file("updatecheck_reply_noupdate.xml")); |
| 1360 test_configurator()->SetLoopCount(1); |
| 1361 component_updater()->Start(); |
| 1362 message_loop.Run(); |
| 1363 |
| 1364 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 1365 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 1366 |
| 1367 EXPECT_EQ(2, ping_checker.NumHits()); |
| 1368 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 1369 EXPECT_EQ(5, interceptor.GetHitCount()); |
| 1370 |
| 1371 component_updater()->Stop(); |
| 1372 } |
| 1373 |
| 1374 // Verify that we successfully propagate a patcher error. |
| 1375 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect |
| 1376 // patching instruction that should fail. |
| 1377 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { |
| 1378 MessageLoop message_loop; |
| 1379 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); |
| 1380 content::TestBrowserThread file_thread(BrowserThread::FILE); |
| 1381 content::TestBrowserThread io_thread(BrowserThread::IO); |
| 1382 |
| 1383 io_thread.StartIOThread(); |
| 1384 file_thread.Start(); |
| 1385 |
| 1386 std::map<std::string, std::string> map; |
| 1387 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 1388 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 1389 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\"")); |
| 1390 map.insert(std::pair<std::string, std::string>("differrorcode", "\"14\"")); |
| 1391 map.insert(std::pair<std::string, std::string>("diffextracode1", "\"305\"")); |
| 1392 PingChecker ping_checker(map); |
| 1393 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 1394 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 1395 |
| 1396 PersistentTestInstaller installer; |
| 1397 CrxComponent com; |
| 1398 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
| 1399 |
| 1400 const GURL expected_update_url_0( |
| 1401 "http://localhost/upd?extra=foo" |
| 1402 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); |
| 1403 const GURL expected_update_url_1( |
| 1404 "http://localhost/upd?extra=foo" |
| 1405 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D1%26uc"); |
| 1406 const GURL expected_update_url_2( |
| 1407 "http://localhost/upd?extra=foo" |
| 1408 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D2.0%26fp%3Df22%26uc"); |
| 1409 const GURL expected_crx_url_1( |
| 1410 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1.crx"); |
| 1411 const GURL expected_crx_url_1_diff_2( |
| 1412 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx"); |
| 1413 const GURL expected_crx_url_2( |
| 1414 "http://localhost/download/ihfokbkgjpifnbbojhneepfflplebdkc_2.crx"); |
| 1415 |
| 1416 interceptor.SetResponse(expected_update_url_0, |
| 1417 test_file("updatecheck_diff_reply_1.xml")); |
| 1418 interceptor.SetResponse(expected_update_url_1, |
| 1419 test_file("updatecheck_diff_reply_2.xml")); |
| 1420 interceptor.SetResponse(expected_update_url_2, |
| 1421 test_file("updatecheck_diff_reply_3.xml")); |
| 1422 interceptor.SetResponse(expected_crx_url_1, |
| 1423 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| 1424 interceptor.SetResponse( |
| 1425 expected_crx_url_1_diff_2, |
| 1426 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); |
| 1427 interceptor.SetResponse(expected_crx_url_2, |
| 1428 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
| 1429 |
| 1430 test_configurator()->SetLoopCount(3); |
| 1431 |
| 1432 component_updater()->Start(); |
| 1433 message_loop.Run(); |
| 1434 |
| 1435 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 1436 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 1437 |
| 1438 EXPECT_EQ(1, ping_checker.NumHits()); |
| 1439 EXPECT_EQ(1, ping_checker.NumMisses()); |
| 1440 EXPECT_EQ(6, interceptor.GetHitCount()); |
| 1441 |
| 1442 component_updater()->Stop(); |
| 1443 } |
| OLD | NEW |