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