| 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/extensions/updater/extension_updater.h" | 5 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 } | 295 } |
| 296 | 296 |
| 297 } // namespace | 297 } // namespace |
| 298 | 298 |
| 299 // Base class for further specialized test classes. | 299 // Base class for further specialized test classes. |
| 300 class MockService : public TestExtensionService { | 300 class MockService : public TestExtensionService { |
| 301 public: | 301 public: |
| 302 explicit MockService(TestExtensionPrefs* prefs) | 302 explicit MockService(TestExtensionPrefs* prefs) |
| 303 : prefs_(prefs), | 303 : prefs_(prefs), |
| 304 pending_extension_manager_(&profile_), | 304 pending_extension_manager_(&profile_), |
| 305 downloader_delegate_override_(NULL), | 305 downloader_delegate_override_(NULL) {} |
| 306 enable_metrics_(false) {} | |
| 307 | 306 |
| 308 ~MockService() override {} | 307 ~MockService() override {} |
| 309 | 308 |
| 310 PendingExtensionManager* pending_extension_manager() override { | 309 PendingExtensionManager* pending_extension_manager() override { |
| 311 ADD_FAILURE() << "Subclass should override this if it will " | 310 ADD_FAILURE() << "Subclass should override this if it will " |
| 312 << "be accessed by a test."; | 311 << "be accessed by a test."; |
| 313 return &pending_extension_manager_; | 312 return &pending_extension_manager_; |
| 314 } | 313 } |
| 315 | 314 |
| 316 Profile* profile() { return &profile_; } | 315 Profile* profile() { return &profile_; } |
| 317 | 316 |
| 318 net::URLRequestContextGetter* request_context() { | 317 net::URLRequestContextGetter* request_context() { |
| 319 return profile_.GetRequestContext(); | 318 return profile_.GetRequestContext(); |
| 320 } | 319 } |
| 321 | 320 |
| 322 ExtensionPrefs* extension_prefs() { return prefs_->prefs(); } | 321 ExtensionPrefs* extension_prefs() { return prefs_->prefs(); } |
| 323 | 322 |
| 324 PrefService* pref_service() { return prefs_->pref_service(); } | 323 PrefService* pref_service() { return prefs_->pref_service(); } |
| 325 | 324 |
| 326 FakeOAuth2TokenService* fake_token_service() { | 325 FakeOAuth2TokenService* fake_token_service() { |
| 327 return fake_token_service_.get(); | 326 return fake_token_service_.get(); |
| 328 } | 327 } |
| 329 | 328 |
| 330 // Controls whether metrics (enable/disabled state, etc.) are sent in the | |
| 331 // autoupdate ping requests. | |
| 332 void set_enable_metrics(bool enable) { enable_metrics_ = enable; } | |
| 333 | |
| 334 // Creates test extensions and inserts them into list. The name and | 329 // Creates test extensions and inserts them into list. The name and |
| 335 // version are all based on their index. If |update_url| is non-null, it | 330 // version are all based on their index. If |update_url| is non-null, it |
| 336 // will be used as the update_url for each extension. | 331 // will be used as the update_url for each extension. |
| 337 // The |id| is used to distinguish extension names and make sure that | 332 // The |id| is used to distinguish extension names and make sure that |
| 338 // no two extensions share the same name. | 333 // no two extensions share the same name. |
| 339 void CreateTestExtensions(int id, int count, ExtensionList *list, | 334 void CreateTestExtensions(int id, int count, ExtensionList *list, |
| 340 const std::string* update_url, | 335 const std::string* update_url, |
| 341 Manifest::Location location) { | 336 Manifest::Location location) { |
| 342 for (int i = 1; i <= count; i++) { | 337 for (int i = 1; i <= count; i++) { |
| 343 base::DictionaryValue manifest; | 338 base::DictionaryValue manifest; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 374 PendingExtensionManager pending_extension_manager_; | 369 PendingExtensionManager pending_extension_manager_; |
| 375 | 370 |
| 376 private: | 371 private: |
| 377 std::unique_ptr<ExtensionDownloader> CreateExtensionDownloader( | 372 std::unique_ptr<ExtensionDownloader> CreateExtensionDownloader( |
| 378 ExtensionDownloaderDelegate* delegate) { | 373 ExtensionDownloaderDelegate* delegate) { |
| 379 std::unique_ptr<ExtensionDownloader> downloader = | 374 std::unique_ptr<ExtensionDownloader> downloader = |
| 380 ChromeExtensionDownloaderFactory::CreateForRequestContext( | 375 ChromeExtensionDownloaderFactory::CreateForRequestContext( |
| 381 request_context(), downloader_delegate_override_ | 376 request_context(), downloader_delegate_override_ |
| 382 ? downloader_delegate_override_ | 377 ? downloader_delegate_override_ |
| 383 : delegate); | 378 : delegate); |
| 384 if (enable_metrics_) | |
| 385 downloader->set_enable_extra_update_metrics(true); | |
| 386 return downloader; | 379 return downloader; |
| 387 } | 380 } |
| 388 | 381 |
| 389 std::unique_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity( | 382 std::unique_ptr<ExtensionDownloader> CreateExtensionDownloaderWithIdentity( |
| 390 ExtensionDownloaderDelegate* delegate) { | 383 ExtensionDownloaderDelegate* delegate) { |
| 391 std::unique_ptr<FakeIdentityProvider> fake_identity_provider; | 384 std::unique_ptr<FakeIdentityProvider> fake_identity_provider; |
| 392 fake_token_service_.reset(new FakeOAuth2TokenService()); | 385 fake_token_service_.reset(new FakeOAuth2TokenService()); |
| 393 fake_identity_provider.reset(new FakeIdentityProvider( | 386 fake_identity_provider.reset(new FakeIdentityProvider( |
| 394 fake_token_service_.get())); | 387 fake_token_service_.get())); |
| 395 fake_identity_provider->LogIn(kFakeAccountId); | 388 fake_identity_provider->LogIn(kFakeAccountId); |
| 396 fake_token_service_->AddAccount(kFakeAccountId); | 389 fake_token_service_->AddAccount(kFakeAccountId); |
| 397 | 390 |
| 398 std::unique_ptr<ExtensionDownloader> downloader( | 391 std::unique_ptr<ExtensionDownloader> downloader( |
| 399 CreateExtensionDownloader(delegate)); | 392 CreateExtensionDownloader(delegate)); |
| 400 downloader->SetWebstoreIdentityProvider(std::move(fake_identity_provider)); | 393 downloader->SetWebstoreIdentityProvider(std::move(fake_identity_provider)); |
| 401 return downloader; | 394 return downloader; |
| 402 } | 395 } |
| 403 | 396 |
| 404 std::unique_ptr<FakeOAuth2TokenService> fake_token_service_; | 397 std::unique_ptr<FakeOAuth2TokenService> fake_token_service_; |
| 405 | 398 |
| 406 ExtensionDownloaderDelegate* downloader_delegate_override_; | 399 ExtensionDownloaderDelegate* downloader_delegate_override_; |
| 407 | 400 |
| 408 bool enable_metrics_; | |
| 409 | |
| 410 DISALLOW_COPY_AND_ASSIGN(MockService); | 401 DISALLOW_COPY_AND_ASSIGN(MockService); |
| 411 }; | 402 }; |
| 412 | 403 |
| 413 | 404 |
| 414 bool ShouldInstallExtensionsOnly(const Extension* extension) { | 405 bool ShouldInstallExtensionsOnly(const Extension* extension) { |
| 415 return extension->GetType() == Manifest::TYPE_EXTENSION; | 406 return extension->GetType() == Manifest::TYPE_EXTENSION; |
| 416 } | 407 } |
| 417 | 408 |
| 418 bool ShouldInstallThemesOnly(const Extension* extension) { | 409 bool ShouldInstallThemesOnly(const Extension* extension) { |
| 419 return extension->is_theme(); | 410 return extension->is_theme(); |
| (...skipping 1851 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2271 // -prodversionmin (shouldn't update if browser version too old) | 2262 // -prodversionmin (shouldn't update if browser version too old) |
| 2272 // -manifests & updates arriving out of order / interleaved | 2263 // -manifests & updates arriving out of order / interleaved |
| 2273 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 2264 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 2274 // -An extension gets uninstalled while updates are in progress (so it doesn't | 2265 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 2275 // "come back from the dead") | 2266 // "come back from the dead") |
| 2276 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 2267 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 2277 // you don't get downgraded accidentally) | 2268 // you don't get downgraded accidentally) |
| 2278 // -An update manifest mentions multiple updates | 2269 // -An update manifest mentions multiple updates |
| 2279 | 2270 |
| 2280 } // namespace extensions | 2271 } // namespace extensions |
| OLD | NEW |