| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <list> | 5 #include "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" |
| 6 #include <utility> | |
| 7 #include "base/compiler_specific.h" | |
| 8 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/memory/scoped_vector.h" | |
| 11 #include "base/message_loop.h" | |
| 12 #include "base/path_service.h" | |
| 13 #include "base/strings/string_number_conversions.h" | |
| 14 #include "base/strings/stringprintf.h" | |
| 15 #include "base/values.h" | |
| 16 #include "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/component_updater/component_updater_service.h" | 8 #include "chrome/browser/component_updater/component_updater_service.h" |
| 18 #include "chrome/browser/component_updater/test/component_patcher_mock.h" | |
| 19 #include "chrome/browser/component_updater/test/component_updater_service_unitte
st.h" | |
| 20 #include "chrome/browser/component_updater/test/test_installer.h" | 9 #include "chrome/browser/component_updater/test/test_installer.h" |
| 21 #include "chrome/common/chrome_paths.h" | 10 #include "chrome/common/chrome_paths.h" |
| 22 #include "content/public/browser/notification_observer.h" | |
| 23 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/test/test_browser_thread.h" | |
| 25 #include "content/public/test/test_notification_tracker.h" | |
| 26 #include "content/test/net/url_request_prepackaged_interceptor.h" | 12 #include "content/test/net/url_request_prepackaged_interceptor.h" |
| 27 #include "libxml/globals.h" | 13 #include "libxml/globals.h" |
| 28 #include "net/base/upload_bytes_element_reader.h" | 14 #include "net/base/upload_bytes_element_reader.h" |
| 29 #include "net/url_request/url_fetcher.h" | 15 #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" | |
| 33 #include "net/url_request/url_request_test_util.h" | |
| 34 #include "testing/gtest/include/gtest/gtest.h" | |
| 35 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 36 | 17 |
| 37 using content::BrowserThread; | 18 using content::BrowserThread; |
| 38 using content::TestNotificationTracker; | 19 using content::TestNotificationTracker; |
| 39 | 20 |
| 40 TestConfigurator::TestConfigurator() | 21 TestConfigurator::TestConfigurator() |
| 41 : times_(1), recheck_time_(0), ondemand_time_(0), cus_(NULL) { | 22 : times_(1), |
| 23 recheck_time_(0), |
| 24 ondemand_time_(0), |
| 25 cus_(NULL), |
| 26 context_(new net::TestURLRequestContextGetter( |
| 27 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))) { |
| 42 } | 28 } |
| 43 | 29 |
| 44 TestConfigurator::~TestConfigurator() { | 30 TestConfigurator::~TestConfigurator() { |
| 45 } | 31 } |
| 46 | 32 |
| 47 int TestConfigurator::InitialDelay() { return 0; } | 33 int TestConfigurator::InitialDelay() { return 0; } |
| 48 | 34 |
| 49 int TestConfigurator::NextCheckDelay() { | 35 int TestConfigurator::NextCheckDelay() { |
| 50 // This is called when a new full cycle of checking for updates is going | 36 // This is called when a new full cycle of checking for updates is going |
| 51 // to happen. In test we normally only test one cycle so it is a good | 37 // to happen. In test we normally only test one cycle so it is a good |
| (...skipping 24 matching lines...) Expand all Loading... |
| 76 | 62 |
| 77 int TestConfigurator::MinimumReCheckWait() { | 63 int TestConfigurator::MinimumReCheckWait() { |
| 78 return recheck_time_; | 64 return recheck_time_; |
| 79 } | 65 } |
| 80 | 66 |
| 81 int TestConfigurator::OnDemandDelay() { | 67 int TestConfigurator::OnDemandDelay() { |
| 82 return ondemand_time_; | 68 return ondemand_time_; |
| 83 } | 69 } |
| 84 | 70 |
| 85 GURL TestConfigurator::UpdateUrl() { | 71 GURL TestConfigurator::UpdateUrl() { |
| 86 return GURL("http://localhost/upd"); | 72 return GURL("http://localhost/upd"); |
| 73 } |
| 74 |
| 75 GURL TestConfigurator::PingUrl() { |
| 76 return GURL("http://localhost2/ping"); |
| 87 } | 77 } |
| 88 | 78 |
| 89 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } | 79 const char* TestConfigurator::ExtraRequestParams() { return "extra=foo"; } |
| 90 | 80 |
| 91 size_t TestConfigurator::UrlSizeLimit() { return 256; } | 81 size_t TestConfigurator::UrlSizeLimit() { return 256; } |
| 92 | 82 |
| 93 net::URLRequestContextGetter* TestConfigurator::RequestContext() { | 83 net::URLRequestContextGetter* TestConfigurator::RequestContext() { |
| 94 return new net::TestURLRequestContextGetter( | 84 return context_.get(); |
| 95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); | |
| 96 } | 85 } |
| 97 | 86 |
| 98 // Don't use the utility process to decode files. | 87 // Don't use the utility process to decode files. |
| 99 bool TestConfigurator::InProcess() { return true; } | 88 bool TestConfigurator::InProcess() { return true; } |
| 100 | 89 |
| 101 void TestConfigurator::OnEvent(Events event, int extra) { } | |
| 102 | |
| 103 ComponentPatcher* TestConfigurator::CreateComponentPatcher() { | 90 ComponentPatcher* TestConfigurator::CreateComponentPatcher() { |
| 104 return new MockComponentPatcher(); | 91 return new MockComponentPatcher(); |
| 105 } | 92 } |
| 106 | 93 |
| 107 bool TestConfigurator::DeltasEnabled() const { | 94 bool TestConfigurator::DeltasEnabled() const { |
| 108 return true; | 95 return true; |
| 109 } | 96 } |
| 110 | 97 |
| 111 // Set how many update checks are called, the default value is just once. | 98 // Set how many update checks are called, the default value is just once. |
| 112 void TestConfigurator::SetLoopCount(int times) { times_ = times; } | 99 void TestConfigurator::SetLoopCount(int times) { times_ = times; } |
| 113 | 100 |
| 114 void TestConfigurator::SetRecheckTime(int seconds) { | 101 void TestConfigurator::SetRecheckTime(int seconds) { |
| 115 recheck_time_ = seconds; | 102 recheck_time_ = seconds; |
| 116 } | 103 } |
| 117 | 104 |
| 118 void TestConfigurator::SetOnDemandTime(int seconds) { | 105 void TestConfigurator::SetOnDemandTime(int seconds) { |
| 119 ondemand_time_ = seconds; | 106 ondemand_time_ = seconds; |
| 120 } | 107 } |
| 121 | 108 |
| 122 void TestConfigurator::AddComponentToCheck(CrxComponent* com, | 109 void TestConfigurator::AddComponentToCheck(CrxComponent* com, |
| 123 int at_loop_iter) { | 110 int at_loop_iter) { |
| 124 components_to_check_.push_back(std::make_pair(com, at_loop_iter)); | 111 components_to_check_.push_back(std::make_pair(com, at_loop_iter)); |
| 125 } | 112 } |
| 126 | 113 |
| 127 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { | 114 void TestConfigurator::SetComponentUpdateService(ComponentUpdateService* cus) { |
| 128 cus_ = cus; | 115 cus_ = cus; |
| 129 } | 116 } |
| 130 | 117 |
| 131 ComponentUpdaterTest::ComponentUpdaterTest() : test_config_(NULL) { | 118 ComponentUpdaterTest::ComponentUpdaterTest() |
| 119 : test_config_(NULL), |
| 120 ui_thread_(BrowserThread::UI, &message_loop_), |
| 121 file_thread_(BrowserThread::FILE), |
| 122 io_thread_(BrowserThread::IO) { |
| 132 // The component updater instance under test. | 123 // The component updater instance under test. |
| 133 test_config_ = new TestConfigurator; | 124 test_config_ = new TestConfigurator; |
| 134 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); | 125 component_updater_.reset(ComponentUpdateServiceFactory(test_config_)); |
| 135 test_config_->SetComponentUpdateService(component_updater_.get()); | 126 test_config_->SetComponentUpdateService(component_updater_.get()); |
| 127 |
| 136 // The test directory is chrome/test/data/components. | 128 // The test directory is chrome/test/data/components. |
| 137 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 129 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| 138 test_data_dir_ = test_data_dir_.AppendASCII("components"); | 130 test_data_dir_ = test_data_dir_.AppendASCII("components"); |
| 139 | 131 |
| 140 // Subscribe to all component updater notifications. | 132 // Subscribe to all component updater notifications. |
| 141 const int notifications[] = { | 133 const int notifications[] = { |
| 142 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, | 134 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, |
| 143 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, | 135 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, |
| 144 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, | 136 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, |
| 145 chrome::NOTIFICATION_COMPONENT_UPDATE_READY | 137 chrome::NOTIFICATION_COMPONENT_UPDATE_READY |
| 146 }; | 138 }; |
| 147 | 139 |
| 148 for (int ix = 0; ix != arraysize(notifications); ++ix) { | 140 for (int ix = 0; ix != arraysize(notifications); ++ix) { |
| 149 notification_tracker_.ListenFor( | 141 notification_tracker_.ListenFor( |
| 150 notifications[ix], content::NotificationService::AllSources()); | 142 notifications[ix], content::NotificationService::AllSources()); |
| 151 } | 143 } |
| 152 net::URLFetcher::SetEnableInterceptionForTests(true); | 144 net::URLFetcher::SetEnableInterceptionForTests(true); |
| 145 |
| 146 io_thread_.StartIOThread(); |
| 147 file_thread_.Start(); |
| 153 } | 148 } |
| 154 | 149 |
| 155 ComponentUpdaterTest::~ComponentUpdaterTest() { | 150 ComponentUpdaterTest::~ComponentUpdaterTest() { |
| 156 net::URLFetcher::SetEnableInterceptionForTests(false); | 151 net::URLFetcher::SetEnableInterceptionForTests(false); |
| 157 } | 152 } |
| 158 | 153 |
| 159 void ComponentUpdaterTest::TearDown() { | 154 void ComponentUpdaterTest::TearDown() { |
| 160 xmlCleanupGlobals(); | 155 xmlCleanupGlobals(); |
| 161 } | 156 } |
| 162 | 157 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 190 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); | 185 com->pk_hash.assign(jebg_hash, jebg_hash + arraysize(jebg_hash)); |
| 191 } else { | 186 } else { |
| 192 com->name = "test_ihfo"; | 187 com->name = "test_ihfo"; |
| 193 com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); | 188 com->pk_hash.assign(ihfo_hash, ihfo_hash + arraysize(ihfo_hash)); |
| 194 } | 189 } |
| 195 com->version = version; | 190 com->version = version; |
| 196 com->installer = installer; | 191 com->installer = installer; |
| 197 return component_updater_->RegisterComponent(*com); | 192 return component_updater_->RegisterComponent(*com); |
| 198 } | 193 } |
| 199 | 194 |
| 195 PingChecker::PingChecker(const std::map<std::string, std::string>& attributes) |
| 196 : num_hits_(0), num_misses_(0), attributes_(attributes) { |
| 197 } |
| 198 |
| 199 PingChecker::~PingChecker() {} |
| 200 |
| 201 void PingChecker::Trial(net::URLRequest* request) { |
| 202 if (Test(request)) |
| 203 ++num_hits_; |
| 204 else |
| 205 ++num_misses_; |
| 206 } |
| 207 |
| 208 bool PingChecker::Test(net::URLRequest* request) { |
| 209 if (request->has_upload()) { |
| 210 const net::UploadDataStream* stream = request->get_upload(); |
| 211 const net::UploadBytesElementReader* reader = |
| 212 stream->element_readers()[0]->AsBytesReader(); |
| 213 int size = reader->length(); |
| 214 scoped_refptr <net::IOBuffer> buffer = new net::IOBuffer(size); |
| 215 std::string data(reader->bytes()); |
| 216 // For now, we assume that there is only one ping per POST. |
| 217 std::string::size_type start = data.find("<o:event"); |
| 218 if (start != std::string::npos) { |
| 219 std::string::size_type end = data.find(">", start); |
| 220 if (end != std::string::npos) { |
| 221 std::string ping = data.substr(start, end - start); |
| 222 std::map<std::string, std::string>::const_iterator iter; |
| 223 for (iter = attributes_.begin(); iter != attributes_.end(); ++iter) { |
| 224 // does the ping contain the specified attribute/value? |
| 225 if (ping.find(std::string(" ") + (iter->first) + |
| 226 std::string("=") + (iter->second)) == string::npos) { |
| 227 return false; |
| 228 } |
| 229 } |
| 230 return true; |
| 231 } |
| 232 } |
| 233 } |
| 234 return false; |
| 235 } |
| 236 |
| 200 // Verify that our test fixture work and the component updater can | 237 // Verify that our test fixture work and the component updater can |
| 201 // be created and destroyed with no side effects. | 238 // be created and destroyed with no side effects. |
| 202 TEST_F(ComponentUpdaterTest, VerifyFixture) { | 239 TEST_F(ComponentUpdaterTest, VerifyFixture) { |
| 203 EXPECT_TRUE(component_updater() != NULL); | 240 EXPECT_TRUE(component_updater() != NULL); |
| 204 EXPECT_EQ(0ul, notification_tracker().size()); | 241 EXPECT_EQ(0ul, notification_tracker().size()); |
| 205 } | 242 } |
| 206 | 243 |
| 207 // Verify that the component updater can be caught in a quick | 244 // Verify that the component updater can be caught in a quick |
| 208 // start-shutdown situation. Failure of this test will be a crash. Also | 245 // start-shutdown situation. Failure of this test will be a crash. Also |
| 209 // if there is no work to do, there are no notifications generated. | 246 // if there is no work to do, there are no notifications generated. |
| 210 TEST_F(ComponentUpdaterTest, StartStop) { | 247 TEST_F(ComponentUpdaterTest, StartStop) { |
| 211 base::MessageLoop message_loop; | |
| 212 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | |
| 213 | |
| 214 component_updater()->Start(); | 248 component_updater()->Start(); |
| 215 message_loop.RunUntilIdle(); | 249 message_loop_.RunUntilIdle(); |
| 216 component_updater()->Stop(); | 250 component_updater()->Stop(); |
| 217 | 251 |
| 218 EXPECT_EQ(0ul, notification_tracker().size()); | 252 EXPECT_EQ(0ul, notification_tracker().size()); |
| 219 } | 253 } |
| 220 | 254 |
| 221 // Verify that when the server has no updates, we go back to sleep and | 255 // Verify that when the server has no updates, we go back to sleep and |
| 222 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications | 256 // the COMPONENT_UPDATER_STARTED and COMPONENT_UPDATER_SLEEPING notifications |
| 223 // are generated. | 257 // are generated. |
| 224 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { | 258 TEST_F(ComponentUpdaterTest, CheckCrxSleep) { |
| 225 base::MessageLoop message_loop; | |
| 226 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | |
| 227 content::TestBrowserThread file_thread(BrowserThread::FILE); | |
| 228 content::TestBrowserThread io_thread(BrowserThread::IO); | |
| 229 | |
| 230 io_thread.StartIOThread(); | |
| 231 file_thread.Start(); | |
| 232 | |
| 233 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 259 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 234 | 260 |
| 235 TestInstaller installer; | 261 TestInstaller installer; |
| 236 CrxComponent com; | 262 CrxComponent com; |
| 237 EXPECT_EQ(ComponentUpdateService::kOk, | 263 EXPECT_EQ(ComponentUpdateService::kOk, |
| 238 RegisterComponent(&com, | 264 RegisterComponent(&com, |
| 239 kTestComponent_abag, | 265 kTestComponent_abag, |
| 240 Version("1.1"), | 266 Version("1.1"), |
| 241 &installer)); | 267 &installer)); |
| 242 | 268 |
| 243 const GURL expected_update_url( | 269 const GURL expected_update_url( |
| 244 "http://localhost/upd?extra=foo" | 270 "http://localhost/upd?extra=foo" |
| 245 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc"); | 271 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D1.1%26fp%3D%26uc"); |
| 246 | 272 |
| 247 interceptor.SetResponse(expected_update_url, | 273 interceptor.SetResponse(expected_update_url, |
| 248 test_file("updatecheck_reply_1.xml")); | 274 test_file("updatecheck_reply_1.xml")); |
| 249 | 275 |
| 250 // We loop twice, but there are no updates so we expect two sleep messages. | 276 // We loop twice, but there are no updates so we expect two sleep messages. |
| 251 test_configurator()->SetLoopCount(2); | 277 test_configurator()->SetLoopCount(2); |
| 252 component_updater()->Start(); | 278 component_updater()->Start(); |
| 253 | 279 |
| 254 ASSERT_EQ(1ul, notification_tracker().size()); | 280 ASSERT_EQ(1ul, notification_tracker().size()); |
| 255 TestNotificationTracker::Event ev1 = notification_tracker().at(0); | 281 TestNotificationTracker::Event ev1 = notification_tracker().at(0); |
| 256 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); | 282 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); |
| 257 | 283 |
| 258 message_loop.Run(); | 284 message_loop_.Run(); |
| 259 | 285 |
| 260 ASSERT_EQ(3ul, notification_tracker().size()); | 286 ASSERT_EQ(3ul, notification_tracker().size()); |
| 261 TestNotificationTracker::Event ev2 = notification_tracker().at(1); | 287 TestNotificationTracker::Event ev2 = notification_tracker().at(1); |
| 262 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 288 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
| 263 TestNotificationTracker::Event ev3 = notification_tracker().at(2); | 289 TestNotificationTracker::Event ev3 = notification_tracker().at(2); |
| 264 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 290 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
| 265 EXPECT_EQ(2, interceptor.GetHitCount()); | 291 EXPECT_EQ(2, interceptor.GetHitCount()); |
| 266 | 292 |
| 267 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 293 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 268 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 294 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 269 | 295 |
| 270 component_updater()->Stop(); | 296 component_updater()->Stop(); |
| 271 | 297 |
| 272 // Loop twice again but this case we simulate a server error by returning | 298 // Loop twice again but this case we simulate a server error by returning |
| 273 // an empty file. | 299 // an empty file. |
| 274 | 300 |
| 275 interceptor.SetResponse(expected_update_url, | 301 interceptor.SetResponse(expected_update_url, |
| 276 test_file("updatecheck_reply_empty")); | 302 test_file("updatecheck_reply_empty")); |
| 277 | 303 |
| 278 notification_tracker().Reset(); | 304 notification_tracker().Reset(); |
| 279 test_configurator()->SetLoopCount(2); | 305 test_configurator()->SetLoopCount(2); |
| 280 component_updater()->Start(); | 306 component_updater()->Start(); |
| 281 | 307 |
| 282 message_loop.Run(); | 308 message_loop_.Run(); |
| 283 | 309 |
| 284 ASSERT_EQ(3ul, notification_tracker().size()); | 310 ASSERT_EQ(3ul, notification_tracker().size()); |
| 285 ev1 = notification_tracker().at(0); | 311 ev1 = notification_tracker().at(0); |
| 286 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); | 312 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev1.type); |
| 287 ev2 = notification_tracker().at(1); | 313 ev2 = notification_tracker().at(1); |
| 288 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 314 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
| 289 ev3 = notification_tracker().at(2); | 315 ev3 = notification_tracker().at(2); |
| 290 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); | 316 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev2.type); |
| 291 EXPECT_EQ(4, interceptor.GetHitCount()); | 317 EXPECT_EQ(4, interceptor.GetHitCount()); |
| 292 | 318 |
| 293 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 319 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 294 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 320 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 295 | 321 |
| 296 component_updater()->Stop(); | 322 component_updater()->Stop(); |
| 297 } | 323 } |
| 298 | 324 |
| 299 // Verify that we can check for updates and install one component. Besides | 325 // Verify that we can check for updates and install one component. Besides |
| 300 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and | 326 // the notifications above NOTIFICATION_COMPONENT_UPDATE_FOUND and |
| 301 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops | 327 // NOTIFICATION_COMPONENT_UPDATE_READY should have been fired. We do two loops |
| 302 // so the second time around there should be nothing left to do. | 328 // so the second time around there should be nothing left to do. |
| 303 // We also check that only 3 network requests are issued: | 329 // We also check that only 3 non-ping network requests are issued: |
| 304 // 1- manifest check | 330 // 1- manifest check |
| 305 // 2- download crx | 331 // 2- download crx |
| 306 // 3- second manifest check. | 332 // 3- second manifest check. |
| 307 TEST_F(ComponentUpdaterTest, InstallCrx) { | 333 TEST_F(ComponentUpdaterTest, InstallCrx) { |
| 308 base::MessageLoop message_loop; | 334 std::map<std::string, std::string> map; |
| 309 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 335 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 310 content::TestBrowserThread file_thread(BrowserThread::FILE); | 336 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 311 content::TestBrowserThread io_thread(BrowserThread::IO); | 337 map.insert(std::pair<std::string, std::string>("previousversion", |
| 312 | 338 "\"0.9\"")); |
| 313 io_thread.StartIOThread(); | 339 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 314 file_thread.Start(); | 340 PingChecker ping_checker(map); |
| 315 | 341 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 316 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 342 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 317 | 343 |
| 318 TestInstaller installer1; | 344 TestInstaller installer1; |
| 319 CrxComponent com1; | 345 CrxComponent com1; |
| 320 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); | 346 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
| 321 TestInstaller installer2; | 347 TestInstaller installer2; |
| 322 CrxComponent com2; | 348 CrxComponent com2; |
| 323 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); | 349 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
| 324 | 350 |
| 325 const GURL expected_update_url_1( | 351 const GURL expected_update_url_1( |
| 326 "http://localhost/upd?extra=foo" | 352 "http://localhost/upd?extra=foo" |
| 327 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" | 353 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc" |
| 328 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); | 354 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| 329 | 355 |
| 330 const GURL expected_update_url_2( | 356 const GURL expected_update_url_2( |
| 331 "http://localhost/upd?extra=foo" | 357 "http://localhost/upd?extra=foo" |
| 332 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" | 358 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc" |
| 333 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"); | 359 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D1.0%26fp%3D%26uc"); |
| 334 | 360 |
| 335 interceptor.SetResponse(expected_update_url_1, | 361 interceptor.SetResponse(expected_update_url_1, |
| 336 test_file("updatecheck_reply_1.xml")); | 362 test_file("updatecheck_reply_1.xml")); |
| 337 interceptor.SetResponse(expected_update_url_2, | 363 interceptor.SetResponse(expected_update_url_2, |
| 338 test_file("updatecheck_reply_1.xml")); | 364 test_file("updatecheck_reply_1.xml")); |
| 339 interceptor.SetResponse(GURL(expected_crx_url), | 365 interceptor.SetResponse(GURL(expected_crx_url), |
| 340 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 366 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 341 | 367 |
| 342 test_configurator()->SetLoopCount(2); | 368 test_configurator()->SetLoopCount(2); |
| 343 | 369 |
| 344 component_updater()->Start(); | 370 component_updater()->Start(); |
| 345 message_loop.Run(); | 371 message_loop_.Run(); |
| 346 | 372 |
| 347 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 373 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 348 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 374 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 349 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 375 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 350 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 376 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 351 | 377 |
| 352 EXPECT_EQ(3, interceptor.GetHitCount()); | 378 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 379 EXPECT_EQ(1, ping_checker.NumHits()); |
| 380 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 353 | 381 |
| 354 ASSERT_EQ(5ul, notification_tracker().size()); | 382 ASSERT_EQ(5ul, notification_tracker().size()); |
| 355 | 383 |
| 356 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 384 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 357 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 385 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
| 358 | 386 |
| 359 TestNotificationTracker::Event ev2 = notification_tracker().at(2); | 387 TestNotificationTracker::Event ev2 = notification_tracker().at(2); |
| 360 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); | 388 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_READY, ev2.type); |
| 361 | 389 |
| 362 TestNotificationTracker::Event ev3 = notification_tracker().at(3); | 390 TestNotificationTracker::Event ev3 = notification_tracker().at(3); |
| 363 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); | 391 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev3.type); |
| 364 | 392 |
| 365 TestNotificationTracker::Event ev4 = notification_tracker().at(4); | 393 TestNotificationTracker::Event ev4 = notification_tracker().at(4); |
| 366 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); | 394 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev4.type); |
| 367 | 395 |
| 368 component_updater()->Stop(); | 396 component_updater()->Stop(); |
| 369 } | 397 } |
| 370 | 398 |
| 371 // This test checks that the "prodversionmin" value is handled correctly. In | 399 // This test checks that the "prodversionmin" value is handled correctly. In |
| 372 // particular there should not be an install because the minimum product | 400 // particular there should not be an install because the minimum product |
| 373 // version is much higher than of chrome. | 401 // version is much higher than of chrome. |
| 374 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { | 402 TEST_F(ComponentUpdaterTest, ProdVersionCheck) { |
| 375 base::MessageLoop message_loop; | 403 std::map<std::string, std::string> map; |
| 376 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 404 PingChecker ping_checker(map); |
| 377 content::TestBrowserThread file_thread(BrowserThread::FILE); | 405 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 378 content::TestBrowserThread io_thread(BrowserThread::IO); | |
| 379 | |
| 380 io_thread.StartIOThread(); | |
| 381 file_thread.Start(); | |
| 382 | |
| 383 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 406 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 384 | 407 |
| 385 TestInstaller installer; | 408 TestInstaller installer; |
| 386 CrxComponent com; | 409 CrxComponent com; |
| 387 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); | 410 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); |
| 388 | 411 |
| 389 const GURL expected_update_url( | 412 const GURL expected_update_url( |
| 390 "http://localhost/upd?extra=foo&x=id%3D" | 413 "http://localhost/upd?extra=foo&x=id%3D" |
| 391 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); | 414 "jebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
| 392 | 415 |
| 393 interceptor.SetResponse(expected_update_url, | 416 interceptor.SetResponse(expected_update_url, |
| 394 test_file("updatecheck_reply_2.xml")); | 417 test_file("updatecheck_reply_2.xml")); |
| 395 interceptor.SetResponse(GURL(expected_crx_url), | 418 interceptor.SetResponse(GURL(expected_crx_url), |
| 396 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 419 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 397 | 420 |
| 398 test_configurator()->SetLoopCount(1); | 421 test_configurator()->SetLoopCount(1); |
| 399 component_updater()->Start(); | 422 component_updater()->Start(); |
| 400 message_loop.Run(); | 423 message_loop_.Run(); |
| 401 | 424 |
| 425 EXPECT_EQ(0, ping_checker.NumHits()); |
| 426 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 402 EXPECT_EQ(1, interceptor.GetHitCount()); | 427 EXPECT_EQ(1, interceptor.GetHitCount()); |
| 403 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 428 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 404 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); | 429 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 405 | 430 |
| 406 component_updater()->Stop(); | 431 component_updater()->Stop(); |
| 407 } | 432 } |
| 408 | 433 |
| 409 // Test that a ping for an update check can cause installs. | 434 // Test that a ping for an update check can cause installs. |
| 410 // Here is the timeline: | 435 // Here is the timeline: |
| 411 // - First loop: we return a reply that indicates no update, so | 436 // - First loop: we return a reply that indicates no update, so |
| 412 // nothing happens. | 437 // nothing happens. |
| 413 // - We ping. | 438 // - We ping. |
| 414 // - This triggers a second loop, which has a reply that triggers an install. | 439 // - This triggers a second loop, which has a reply that triggers an install. |
| 415 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { | 440 TEST_F(ComponentUpdaterTest, CheckForUpdateSoon) { |
| 416 base::MessageLoop message_loop; | 441 std::map<std::string, std::string> map; |
| 417 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 442 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 418 content::TestBrowserThread file_thread(BrowserThread::FILE); | 443 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 419 content::TestBrowserThread io_thread(BrowserThread::IO); | 444 map.insert(std::pair<std::string, std::string>("previousversion", |
| 420 | 445 "\"0.9\"")); |
| 421 io_thread.StartIOThread(); | 446 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 422 file_thread.Start(); | 447 PingChecker ping_checker(map); |
| 423 | 448 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 424 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 449 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 425 | 450 |
| 426 TestInstaller installer1; | 451 TestInstaller installer1; |
| 427 CrxComponent com1; | 452 CrxComponent com1; |
| 428 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); | 453 RegisterComponent(&com1, kTestComponent_abag, Version("2.2"), &installer1); |
| 429 TestInstaller installer2; | 454 TestInstaller installer2; |
| 430 CrxComponent com2; | 455 CrxComponent com2; |
| 431 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); | 456 RegisterComponent(&com2, kTestComponent_jebg, Version("0.9"), &installer2); |
| 432 | 457 |
| 433 const GURL expected_update_url_1( | 458 const GURL expected_update_url_1( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 444 interceptor.SetResponse(expected_update_url_1, | 469 interceptor.SetResponse(expected_update_url_1, |
| 445 test_file("updatecheck_reply_empty")); | 470 test_file("updatecheck_reply_empty")); |
| 446 interceptor.SetResponse(expected_update_url_2, | 471 interceptor.SetResponse(expected_update_url_2, |
| 447 test_file("updatecheck_reply_1.xml")); | 472 test_file("updatecheck_reply_1.xml")); |
| 448 interceptor.SetResponse(GURL(expected_crx_url), | 473 interceptor.SetResponse(GURL(expected_crx_url), |
| 449 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 474 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 450 // Test success. | 475 // Test success. |
| 451 test_configurator()->SetLoopCount(2); | 476 test_configurator()->SetLoopCount(2); |
| 452 test_configurator()->AddComponentToCheck(&com2, 1); | 477 test_configurator()->AddComponentToCheck(&com2, 1); |
| 453 component_updater()->Start(); | 478 component_updater()->Start(); |
| 454 message_loop.Run(); | 479 message_loop_.Run(); |
| 455 | 480 |
| 456 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 481 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 457 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); | 482 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 458 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 483 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 459 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count()); | 484 EXPECT_EQ(1, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 460 | 485 |
| 461 EXPECT_EQ(3, interceptor.GetHitCount()); | 486 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 462 | 487 |
| 463 ASSERT_EQ(5ul, notification_tracker().size()); | 488 ASSERT_EQ(5ul, notification_tracker().size()); |
| 464 | 489 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 494 | 519 |
| 495 // No update: error from no server response | 520 // No update: error from no server response |
| 496 interceptor.SetResponse(expected_update_url_3, | 521 interceptor.SetResponse(expected_update_url_3, |
| 497 test_file("updatecheck_reply_empty")); | 522 test_file("updatecheck_reply_empty")); |
| 498 notification_tracker().Reset(); | 523 notification_tracker().Reset(); |
| 499 test_configurator()->SetLoopCount(1); | 524 test_configurator()->SetLoopCount(1); |
| 500 component_updater()->Start(); | 525 component_updater()->Start(); |
| 501 EXPECT_EQ(ComponentUpdateService::kOk, | 526 EXPECT_EQ(ComponentUpdateService::kOk, |
| 502 component_updater()->CheckForUpdateSoon(com2)); | 527 component_updater()->CheckForUpdateSoon(com2)); |
| 503 | 528 |
| 504 message_loop.Run(); | 529 message_loop_.Run(); |
| 505 | 530 |
| 506 ASSERT_EQ(2ul, notification_tracker().size()); | 531 ASSERT_EQ(2ul, notification_tracker().size()); |
| 507 ev0 = notification_tracker().at(0); | 532 ev0 = notification_tracker().at(0); |
| 508 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 533 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 509 ev1 = notification_tracker().at(1); | 534 ev1 = notification_tracker().at(1); |
| 510 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); | 535 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); |
| 511 component_updater()->Stop(); | 536 component_updater()->Stop(); |
| 512 | 537 |
| 513 // No update: already updated to 1.0 so nothing new | 538 // No update: already updated to 1.0 so nothing new |
| 514 interceptor.SetResponse(expected_update_url_3, | 539 interceptor.SetResponse(expected_update_url_3, |
| 515 test_file("updatecheck_reply_1.xml")); | 540 test_file("updatecheck_reply_1.xml")); |
| 516 notification_tracker().Reset(); | 541 notification_tracker().Reset(); |
| 517 test_configurator()->SetLoopCount(1); | 542 test_configurator()->SetLoopCount(1); |
| 518 component_updater()->Start(); | 543 component_updater()->Start(); |
| 519 EXPECT_EQ(ComponentUpdateService::kOk, | 544 EXPECT_EQ(ComponentUpdateService::kOk, |
| 520 component_updater()->CheckForUpdateSoon(com2)); | 545 component_updater()->CheckForUpdateSoon(com2)); |
| 521 | 546 |
| 522 message_loop.Run(); | 547 message_loop_.Run(); |
| 523 | 548 |
| 549 EXPECT_EQ(1, ping_checker.NumHits()); |
| 550 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 524 ASSERT_EQ(2ul, notification_tracker().size()); | 551 ASSERT_EQ(2ul, notification_tracker().size()); |
| 525 ev0 = notification_tracker().at(0); | 552 ev0 = notification_tracker().at(0); |
| 526 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 553 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 527 ev1 = notification_tracker().at(1); | 554 ev1 = notification_tracker().at(1); |
| 528 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); | 555 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); |
| 529 component_updater()->Stop(); | 556 component_updater()->Stop(); |
| 530 } | 557 } |
| 531 | 558 |
| 532 // Verify that a previously registered component can get re-registered | 559 // Verify that a previously registered component can get re-registered |
| 533 // with a different version. | 560 // with a different version. |
| 534 TEST_F(ComponentUpdaterTest, CheckReRegistration) { | 561 TEST_F(ComponentUpdaterTest, CheckReRegistration) { |
| 535 base::MessageLoop message_loop; | 562 std::map<std::string, std::string> map; |
| 536 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 563 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 537 content::TestBrowserThread file_thread(BrowserThread::FILE); | 564 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 538 content::TestBrowserThread io_thread(BrowserThread::IO); | 565 map.insert(std::pair<std::string, std::string>("previousversion", |
| 539 | 566 "\"0.9\"")); |
| 540 io_thread.StartIOThread(); | 567 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 541 file_thread.Start(); | 568 PingChecker ping_checker(map); |
| 542 | 569 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 543 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 570 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 544 | 571 |
| 545 TestInstaller installer1; | 572 TestInstaller installer1; |
| 546 CrxComponent com1; | 573 CrxComponent com1; |
| 547 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); | 574 RegisterComponent(&com1, kTestComponent_jebg, Version("0.9"), &installer1); |
| 548 TestInstaller installer2; | 575 TestInstaller installer2; |
| 549 CrxComponent com2; | 576 CrxComponent com2; |
| 550 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); | 577 RegisterComponent(&com2, kTestComponent_abag, Version("2.2"), &installer2); |
| 551 | 578 |
| 552 // Start with 0.9, and update to 1.0 | 579 // Start with 0.9, and update to 1.0 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 565 interceptor.SetResponse(expected_update_url_2, | 592 interceptor.SetResponse(expected_update_url_2, |
| 566 test_file("updatecheck_reply_1.xml")); | 593 test_file("updatecheck_reply_1.xml")); |
| 567 interceptor.SetResponse(GURL(expected_crx_url), | 594 interceptor.SetResponse(GURL(expected_crx_url), |
| 568 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); | 595 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 569 | 596 |
| 570 // Loop twice to issue two checks: (1) with original 0.9 version | 597 // Loop twice to issue two checks: (1) with original 0.9 version |
| 571 // and (2) with the updated 1.0 version. | 598 // and (2) with the updated 1.0 version. |
| 572 test_configurator()->SetLoopCount(2); | 599 test_configurator()->SetLoopCount(2); |
| 573 | 600 |
| 574 component_updater()->Start(); | 601 component_updater()->Start(); |
| 575 message_loop.Run(); | 602 message_loop_.Run(); |
| 576 | 603 |
| 577 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 604 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 578 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); | 605 EXPECT_EQ(1, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 579 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 606 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 580 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 607 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 581 | 608 |
| 609 EXPECT_EQ(1, ping_checker.NumHits()); |
| 610 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 582 EXPECT_EQ(3, interceptor.GetHitCount()); | 611 EXPECT_EQ(3, interceptor.GetHitCount()); |
| 583 | 612 |
| 584 ASSERT_EQ(5ul, notification_tracker().size()); | 613 ASSERT_EQ(5ul, notification_tracker().size()); |
| 585 | 614 |
| 586 TestNotificationTracker::Event ev0 = notification_tracker().at(0); | 615 TestNotificationTracker::Event ev0 = notification_tracker().at(0); |
| 587 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 616 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 588 | 617 |
| 589 TestNotificationTracker::Event ev1 = notification_tracker().at(1); | 618 TestNotificationTracker::Event ev1 = notification_tracker().at(1); |
| 590 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); | 619 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, ev1.type); |
| 591 | 620 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 615 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); | 644 "&x=id%3Dabagagagagagagagagagagagagagagag%26v%3D2.2%26fp%3D%26uc"); |
| 616 | 645 |
| 617 interceptor.SetResponse(expected_update_url_3, | 646 interceptor.SetResponse(expected_update_url_3, |
| 618 test_file("updatecheck_reply_1.xml")); | 647 test_file("updatecheck_reply_1.xml")); |
| 619 | 648 |
| 620 notification_tracker().Reset(); | 649 notification_tracker().Reset(); |
| 621 | 650 |
| 622 // Loop once just to notice the check happening with the re-register version. | 651 // Loop once just to notice the check happening with the re-register version. |
| 623 test_configurator()->SetLoopCount(1); | 652 test_configurator()->SetLoopCount(1); |
| 624 component_updater()->Start(); | 653 component_updater()->Start(); |
| 625 message_loop.Run(); | 654 message_loop_.Run(); |
| 626 | 655 |
| 627 ASSERT_EQ(2ul, notification_tracker().size()); | 656 ASSERT_EQ(2ul, notification_tracker().size()); |
| 628 | 657 |
| 629 ev0 = notification_tracker().at(0); | 658 ev0 = notification_tracker().at(0); |
| 630 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); | 659 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, ev0.type); |
| 631 | 660 |
| 632 ev1 = notification_tracker().at(1); | 661 ev1 = notification_tracker().at(1); |
| 633 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); | 662 EXPECT_EQ(chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, ev1.type); |
| 634 | 663 |
| 635 EXPECT_EQ(4, interceptor.GetHitCount()); | 664 EXPECT_EQ(4, interceptor.GetHitCount()); |
| 636 | 665 |
| 637 // We created a new installer, so the counts go back to 0. | 666 // We created a new installer, so the counts go back to 0. |
| 638 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); | 667 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->error()); |
| 639 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); | 668 EXPECT_EQ(0, static_cast<TestInstaller*>(com1.installer)->install_count()); |
| 640 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); | 669 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->error()); |
| 641 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); | 670 EXPECT_EQ(0, static_cast<TestInstaller*>(com2.installer)->install_count()); |
| 642 | 671 |
| 643 component_updater()->Stop(); | 672 component_updater()->Stop(); |
| 644 } | 673 } |
| 645 | 674 |
| 646 // Verify that component installation falls back to downloading and installing | 675 // Verify that component installation falls back to downloading and installing |
| 647 // a full update if the differential update fails (in this case, because the | 676 // a full update if the differential update fails (in this case, because the |
| 648 // installer does not know about the existing files). We do two loops; the final | 677 // installer does not know about the existing files). We do two loops; the final |
| 649 // loop should do nothing. | 678 // loop should do nothing. |
| 650 // We also check that exactly 4 network requests are issued: | 679 // We also check that exactly 4 non-ping network requests are issued: |
| 651 // 1- update check (loop 1) | 680 // 1- update check (loop 1) |
| 652 // 2- download differential crx | 681 // 2- download differential crx |
| 653 // 3- download full crx | 682 // 3- download full crx |
| 654 // 4- update check (loop 2 - no update available) | 683 // 4- update check (loop 2 - no update available) |
| 684 // There should be one ping for the first attempted update. |
| 655 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { | 685 TEST_F(ComponentUpdaterTest, DifferentialUpdateFails) { |
| 656 base::MessageLoop message_loop; | 686 std::map<std::string, std::string> map; |
| 657 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 687 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 658 content::TestBrowserThread file_thread(BrowserThread::FILE); | 688 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 659 content::TestBrowserThread io_thread(BrowserThread::IO); | 689 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\"")); |
| 660 | 690 map.insert(std::pair<std::string, std::string>("differrorcode", "\"16\"")); |
| 661 io_thread.StartIOThread(); | 691 PingChecker ping_checker(map); |
| 662 file_thread.Start(); | 692 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 663 | |
| 664 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 693 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 665 | 694 |
| 666 TestInstaller installer; | 695 TestInstaller installer; |
| 667 CrxComponent com; | 696 CrxComponent com; |
| 668 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); | 697 RegisterComponent(&com, kTestComponent_ihfo, Version("1.0"), &installer); |
| 669 | 698 |
| 670 const GURL expected_update_url_1( | 699 const GURL expected_update_url_1( |
| 671 "http://localhost/upd?extra=foo" | 700 "http://localhost/upd?extra=foo" |
| 672 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); | 701 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D1.0%26fp%3D%26uc"); |
| 673 const GURL expected_update_url_2( | 702 const GURL expected_update_url_2( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 688 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); | 717 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| 689 interceptor.SetResponse( | 718 interceptor.SetResponse( |
| 690 expected_crx_url_1_diff_2, | 719 expected_crx_url_1_diff_2, |
| 691 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); | 720 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2.crx")); |
| 692 interceptor.SetResponse(expected_crx_url_2, | 721 interceptor.SetResponse(expected_crx_url_2, |
| 693 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); | 722 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
| 694 | 723 |
| 695 test_configurator()->SetLoopCount(2); | 724 test_configurator()->SetLoopCount(2); |
| 696 | 725 |
| 697 component_updater()->Start(); | 726 component_updater()->Start(); |
| 698 message_loop.Run(); | 727 message_loop_.Run(); |
| 699 | 728 |
| 700 // A failed differential update does not count as a failed install. | 729 // A failed differential update does not count as a failed install. |
| 701 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 730 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 702 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); | 731 EXPECT_EQ(1, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 703 | 732 |
| 733 EXPECT_EQ(1, ping_checker.NumHits()); |
| 734 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 704 EXPECT_EQ(4, interceptor.GetHitCount()); | 735 EXPECT_EQ(4, interceptor.GetHitCount()); |
| 705 | 736 |
| 706 component_updater()->Stop(); | 737 component_updater()->Stop(); |
| 707 } | 738 } |
| 708 | 739 |
| 740 // Verify that a failed installation causes an install failure ping. |
| 741 TEST_F(ComponentUpdaterTest, CheckFailedInstallPing) { |
| 742 std::map<std::string, std::string> map; |
| 743 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 744 map.insert(std::pair<std::string, std::string>("eventresult", "\"0\"")); |
| 745 map.insert(std::pair<std::string, std::string>("errorcode", "\"9\"")); |
| 746 map.insert(std::pair<std::string, std::string>("previousversion", |
| 747 "\"0.9\"")); |
| 748 map.insert(std::pair<std::string, std::string>("nextversion", "\"1.0\"")); |
| 749 PingChecker ping_checker(map); |
| 750 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 751 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 752 |
| 753 // This test installer reports installation failure. |
| 754 class : public TestInstaller { |
| 755 virtual bool Install(const base::DictionaryValue& manifest, |
| 756 const base::FilePath& unpack_path) OVERRIDE { |
| 757 ++install_count_; |
| 758 base::Delete(unpack_path, true); |
| 759 return false; |
| 760 } |
| 761 } installer; |
| 762 |
| 763 CrxComponent com; |
| 764 RegisterComponent(&com, kTestComponent_jebg, Version("0.9"), &installer); |
| 765 |
| 766 // Start with 0.9, and attempt update to 1.0 |
| 767 const GURL expected_update_url_1( |
| 768 "http://localhost/upd?extra=foo" |
| 769 "&x=id%3Djebgalgnebhfojomionfpkfelancnnkf%26v%3D0.9%26fp%3D%26uc"); |
| 770 |
| 771 interceptor.SetResponse(expected_update_url_1, |
| 772 test_file("updatecheck_reply_1.xml")); |
| 773 interceptor.SetResponse(GURL(expected_crx_url), |
| 774 test_file("jebgalgnebhfojomionfpkfelancnnkf.crx")); |
| 775 |
| 776 // Loop twice to issue two checks: (1) with original 0.9 version |
| 777 // and (2), which should retry with 0.9. |
| 778 test_configurator()->SetLoopCount(2); |
| 779 component_updater()->Start(); |
| 780 message_loop_.Run(); |
| 781 |
| 782 // Loop once more, but expect no ping because a noupdate response is issued. |
| 783 // This is necessary to clear out the fire-and-forget ping from the previous |
| 784 // iteration. |
| 785 interceptor.SetResponse(expected_update_url_1, |
| 786 test_file("updatecheck_reply_noupdate.xml")); |
| 787 test_configurator()->SetLoopCount(1); |
| 788 component_updater()->Start(); |
| 789 message_loop_.Run(); |
| 790 |
| 791 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 792 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 793 |
| 794 EXPECT_EQ(2, ping_checker.NumHits()); |
| 795 EXPECT_EQ(0, ping_checker.NumMisses()); |
| 796 EXPECT_EQ(5, interceptor.GetHitCount()); |
| 797 |
| 798 component_updater()->Stop(); |
| 799 } |
| 800 |
| 709 // Verify that we successfully propagate a patcher error. | 801 // Verify that we successfully propagate a patcher error. |
| 710 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect | 802 // ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx contains an incorrect |
| 711 // patching instruction that should fail. | 803 // patching instruction that should fail. |
| 712 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { | 804 TEST_F(ComponentUpdaterTest, DifferentialUpdateFailErrorcode) { |
| 713 base::MessageLoop message_loop; | 805 std::map<std::string, std::string> map; |
| 714 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); | 806 map.insert(std::pair<std::string, std::string>("eventtype", "\"3\"")); |
| 715 content::TestBrowserThread file_thread(BrowserThread::FILE); | 807 map.insert(std::pair<std::string, std::string>("eventresult", "\"1\"")); |
| 716 content::TestBrowserThread io_thread(BrowserThread::IO); | 808 map.insert(std::pair<std::string, std::string>("diffresult", "\"0\"")); |
| 717 | 809 map.insert(std::pair<std::string, std::string>("differrorcode", "\"14\"")); |
| 718 io_thread.StartIOThread(); | 810 map.insert(std::pair<std::string, std::string>("diffextracode1", "\"305\"")); |
| 719 file_thread.Start(); | 811 PingChecker ping_checker(map); |
| 720 | 812 URLRequestPostInterceptor post_interceptor(&ping_checker); |
| 721 content::URLLocalHostRequestPrepackagedInterceptor interceptor; | 813 content::URLLocalHostRequestPrepackagedInterceptor interceptor; |
| 722 | 814 |
| 723 VersionedTestInstaller installer; | 815 VersionedTestInstaller installer; |
| 724 CrxComponent com; | 816 CrxComponent com; |
| 725 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); | 817 RegisterComponent(&com, kTestComponent_ihfo, Version("0.0"), &installer); |
| 726 | 818 |
| 727 const GURL expected_update_url_0( | 819 const GURL expected_update_url_0( |
| 728 "http://localhost/upd?extra=foo" | 820 "http://localhost/upd?extra=foo" |
| 729 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); | 821 "&x=id%3Dihfokbkgjpifnbbojhneepfflplebdkc%26v%3D0.0%26fp%3D%26uc"); |
| 730 const GURL expected_update_url_1( | 822 const GURL expected_update_url_1( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 750 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); | 842 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1.crx")); |
| 751 interceptor.SetResponse( | 843 interceptor.SetResponse( |
| 752 expected_crx_url_1_diff_2, | 844 expected_crx_url_1_diff_2, |
| 753 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); | 845 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_1to2_bad.crx")); |
| 754 interceptor.SetResponse(expected_crx_url_2, | 846 interceptor.SetResponse(expected_crx_url_2, |
| 755 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); | 847 test_file("ihfokbkgjpifnbbojhneepfflplebdkc_2.crx")); |
| 756 | 848 |
| 757 test_configurator()->SetLoopCount(3); | 849 test_configurator()->SetLoopCount(3); |
| 758 | 850 |
| 759 component_updater()->Start(); | 851 component_updater()->Start(); |
| 760 message_loop.Run(); | 852 message_loop_.Run(); |
| 761 | 853 |
| 762 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); | 854 EXPECT_EQ(0, static_cast<TestInstaller*>(com.installer)->error()); |
| 763 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); | 855 EXPECT_EQ(2, static_cast<TestInstaller*>(com.installer)->install_count()); |
| 764 | 856 |
| 857 EXPECT_EQ(1, ping_checker.NumHits()); |
| 858 EXPECT_EQ(1, ping_checker.NumMisses()); |
| 765 EXPECT_EQ(6, interceptor.GetHitCount()); | 859 EXPECT_EQ(6, interceptor.GetHitCount()); |
| 766 | 860 |
| 767 component_updater()->Stop(); | 861 component_updater()->Stop(); |
| 768 } | 862 } |
| OLD | NEW |