| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 virtual Extension* GetExtensionById(const std::string& id, bool) { | 55 virtual Extension* GetExtensionById(const std::string& id, bool) { |
| 56 EXPECT_TRUE(false); | 56 EXPECT_TRUE(false); |
| 57 return NULL; | 57 return NULL; |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual void UpdateExtensionBlacklist( | 60 virtual void UpdateExtensionBlacklist( |
| 61 const std::vector<std::string>& blacklist) { | 61 const std::vector<std::string>& blacklist) { |
| 62 EXPECT_TRUE(false); | 62 EXPECT_TRUE(false); |
| 63 } | 63 } |
| 64 |
| 65 virtual bool HasInstalledExtensions() { |
| 66 EXPECT_TRUE(false); |
| 67 return false; |
| 68 } |
| 64 private: | 69 private: |
| 65 DISALLOW_COPY_AND_ASSIGN(MockService); | 70 DISALLOW_COPY_AND_ASSIGN(MockService); |
| 66 }; | 71 }; |
| 67 | 72 |
| 68 // Class that contains a PrefService and handles cleanup of a temporary file | 73 // Class that contains a PrefService and handles cleanup of a temporary file |
| 69 // backing it. | 74 // backing it. |
| 70 class ScopedTempPrefService { | 75 class ScopedTempPrefService { |
| 71 public: | 76 public: |
| 72 ScopedTempPrefService() { | 77 ScopedTempPrefService() { |
| 73 // Make sure different tests won't use the same prefs file. It will cause | 78 // Make sure different tests won't use the same prefs file. It will cause |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 if (update_url) | 114 if (update_url) |
| 110 input.SetString(extension_manifest_keys::kUpdateURL, *update_url); | 115 input.SetString(extension_manifest_keys::kUpdateURL, *update_url); |
| 111 std::string error; | 116 std::string error; |
| 112 EXPECT_TRUE(e->InitFromValue(input, false, &error)); | 117 EXPECT_TRUE(e->InitFromValue(input, false, &error)); |
| 113 list->push_back(e); | 118 list->push_back(e); |
| 114 } | 119 } |
| 115 } | 120 } |
| 116 | 121 |
| 117 class ServiceForManifestTests : public MockService { | 122 class ServiceForManifestTests : public MockService { |
| 118 public: | 123 public: |
| 119 ServiceForManifestTests() {} | 124 ServiceForManifestTests() : has_installed_extensions_(false) {} |
| 120 | 125 |
| 121 virtual ~ServiceForManifestTests() {} | 126 virtual ~ServiceForManifestTests() {} |
| 122 | 127 |
| 123 virtual Extension* GetExtensionById(const std::string& id, bool) { | 128 virtual Extension* GetExtensionById(const std::string& id, bool) { |
| 124 for (ExtensionList::iterator iter = extensions_.begin(); | 129 for (ExtensionList::iterator iter = extensions_.begin(); |
| 125 iter != extensions_.end(); ++iter) { | 130 iter != extensions_.end(); ++iter) { |
| 126 if ((*iter)->id() == id) { | 131 if ((*iter)->id() == id) { |
| 127 return *iter; | 132 return *iter; |
| 128 } | 133 } |
| 129 } | 134 } |
| 130 return NULL; | 135 return NULL; |
| 131 } | 136 } |
| 132 | 137 |
| 133 virtual const ExtensionList* extensions() const { return &extensions_; } | 138 virtual const ExtensionList* extensions() const { return &extensions_; } |
| 134 | 139 |
| 135 void set_extensions(ExtensionList extensions) { | 140 void set_extensions(ExtensionList extensions) { |
| 136 extensions_ = extensions; | 141 extensions_ = extensions; |
| 137 } | 142 } |
| 138 | 143 |
| 144 virtual bool HasInstalledExtensions() { |
| 145 return has_installed_extensions_; |
| 146 } |
| 147 |
| 148 void set_has_installed_extensions(bool value) { |
| 149 has_installed_extensions_ = value; |
| 150 } |
| 151 |
| 139 private: | 152 private: |
| 140 ExtensionList extensions_; | 153 ExtensionList extensions_; |
| 154 bool has_installed_extensions_; |
| 141 }; | 155 }; |
| 142 | 156 |
| 143 class ServiceForDownloadTests : public MockService { | 157 class ServiceForDownloadTests : public MockService { |
| 144 public: | 158 public: |
| 145 virtual void UpdateExtension(const std::string& id, | 159 virtual void UpdateExtension(const std::string& id, |
| 146 const FilePath& extension_path) { | 160 const FilePath& extension_path) { |
| 147 extension_id_ = id; | 161 extension_id_ = id; |
| 148 install_path_ = extension_path; | 162 install_path_ = extension_path; |
| 149 } | 163 } |
| 150 | 164 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 TestURLFetcherFactory factory; | 323 TestURLFetcherFactory factory; |
| 310 URLFetcher::set_factory(&factory); | 324 URLFetcher::set_factory(&factory); |
| 311 ScopedTempPrefService prefs; | 325 ScopedTempPrefService prefs; |
| 312 scoped_refptr<ExtensionUpdater> updater = | 326 scoped_refptr<ExtensionUpdater> updater = |
| 313 new ExtensionUpdater(&service, prefs.get(), 60*60*24); | 327 new ExtensionUpdater(&service, prefs.get(), 60*60*24); |
| 314 updater->Start(); | 328 updater->Start(); |
| 315 | 329 |
| 316 // Tell the updater that it's time to do update checks. | 330 // Tell the updater that it's time to do update checks. |
| 317 SimulateTimerFired(updater.get()); | 331 SimulateTimerFired(updater.get()); |
| 318 | 332 |
| 319 // Get the url our mock fetcher was asked to fetch. | 333 // No extensions installed, so nothing should have been fetched. |
| 320 TestURLFetcher* fetcher = | 334 TestURLFetcher* fetcher = |
| 321 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); | 335 factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
| 336 EXPECT_TRUE(fetcher == NULL); |
| 337 |
| 338 // Try again with an extension installed. |
| 339 service.set_has_installed_extensions(true); |
| 340 SimulateTimerFired(updater.get()); |
| 341 |
| 342 // Get the url our mock fetcher was asked to fetch. |
| 343 fetcher = factory.GetFetcherByID(ExtensionUpdater::kManifestFetcherId); |
| 344 ASSERT_FALSE(fetcher == NULL); |
| 322 const GURL& url = fetcher->original_url(); | 345 const GURL& url = fetcher->original_url(); |
| 323 | 346 |
| 324 EXPECT_FALSE(url.is_empty()); | 347 EXPECT_FALSE(url.is_empty()); |
| 325 EXPECT_TRUE(url.is_valid()); | 348 EXPECT_TRUE(url.is_valid()); |
| 326 EXPECT_TRUE(url.SchemeIs("https")); | 349 EXPECT_TRUE(url.SchemeIs("https")); |
| 327 EXPECT_EQ("clients2.google.com", url.host()); | 350 EXPECT_EQ("clients2.google.com", url.host()); |
| 328 EXPECT_EQ("/service/update2/crx", url.path()); | 351 EXPECT_EQ("/service/update2/crx", url.path()); |
| 329 | 352 |
| 330 // Validate the extension request parameters in the query. It should | 353 // Validate the extension request parameters in the query. It should |
| 331 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". | 354 // look something like "?x=id%3D<id>%26v%3D<version>%26uc". |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 // -prodversionmin (shouldn't update if browser version too old) | 727 // -prodversionmin (shouldn't update if browser version too old) |
| 705 // -manifests & updates arriving out of order / interleaved | 728 // -manifests & updates arriving out of order / interleaved |
| 706 // -Profile::GetDefaultRequestContext() returning null | 729 // -Profile::GetDefaultRequestContext() returning null |
| 707 // (should not crash, but just do check later) | 730 // (should not crash, but just do check later) |
| 708 // -malformed update url (empty, file://, has query, has a # fragment, etc.) | 731 // -malformed update url (empty, file://, has query, has a # fragment, etc.) |
| 709 // -An extension gets uninstalled while updates are in progress (so it doesn't | 732 // -An extension gets uninstalled while updates are in progress (so it doesn't |
| 710 // "come back from the dead") | 733 // "come back from the dead") |
| 711 // -An extension gets manually updated to v3 while we're downloading v2 (ie | 734 // -An extension gets manually updated to v3 while we're downloading v2 (ie |
| 712 // you don't get downgraded accidentally) | 735 // you don't get downgraded accidentally) |
| 713 // -An update manifest mentions multiple updates | 736 // -An update manifest mentions multiple updates |
| OLD | NEW |