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
3 // found in the LICENSE file.
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/command_line.h"
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/run_loop.h"
18 #include "base/sequenced_task_runner.h"
19 #include "base/stl_util.h"
20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_split.h"
22 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h"
24 #include "base/threading/thread.h"
25 #include "base/version.h"
26 #include "chrome/browser/chrome_notification_types.h"
27 #include "chrome/browser/extensions/crx_installer.h"
28 #include "chrome/browser/extensions/extension_error_reporter.h"
29 #include "chrome/browser/extensions/extension_sync_data.h"
30 #include "chrome/browser/extensions/test_extension_prefs.h"
31 #include "chrome/browser/extensions/test_extension_service.h"
32 #include "chrome/browser/extensions/test_extension_system.h"
33 #include "chrome/browser/extensions/updater/extension_downloader.h"
34 #include "chrome/browser/extensions/updater/extension_downloader_delegate.h"
35 #include "chrome/browser/extensions/updater/extension_updater.h"
36 #include "chrome/browser/extensions/updater/manifest_fetch_data.h"
37 #include "chrome/browser/extensions/updater/request_queue_impl.h"
38 #include "chrome/browser/google/google_util.h"
39 #include "chrome/browser/omaha_query_params/omaha_query_params.h"
40 #include "chrome/browser/prefs/pref_service_syncable.h"
41 #include "chrome/common/pref_names.h"
42 #include "chrome/test/base/testing_profile.h"
43 #include "content/public/browser/notification_details.h"
44 #include "content/public/browser/notification_observer.h"
45 #include "content/public/browser/notification_registrar.h"
46 #include "content/public/browser/notification_service.h"
47 #include "content/public/browser/notification_source.h"
48 #include "content/public/test/test_browser_thread_bundle.h"
49 #include "content/public/test/test_utils.h"
50 #include "extensions/browser/extension_registry.h"
51 #include "extensions/browser/extension_system.h"
52 #include "extensions/common/extension.h"
53 #include "extensions/common/id_util.h"
54 #include "extensions/common/manifest_constants.h"
55 #include "libxml/globals.h"
56 #include "net/base/backoff_entry.h"
57 #include "net/base/escape.h"
58 #include "net/base/load_flags.h"
59 #include "net/url_request/test_url_fetcher_factory.h"
60 #include "net/url_request/url_request_status.h"
61 #include "testing/gmock/include/gmock/gmock.h"
62 #include "testing/gtest/include/gtest/gtest.h"
64 #if defined(OS_CHROMEOS)
65 #include "chrome/browser/chromeos/login/user_manager.h"
66 #include "chrome/browser/chromeos/settings/cros_settings.h"
67 #include "chrome/browser/chromeos/settings/device_settings_service.h"
71 using base::TimeDelta
;
72 using content::BrowserThread
;
74 using testing::Invoke
;
75 using testing::InvokeWithoutArgs
;
77 using testing::Return
;
78 using testing::SetArgPointee
;
81 namespace extensions
{
83 typedef ExtensionDownloaderDelegate::Error Error
;
84 typedef ExtensionDownloaderDelegate::PingResult PingResult
;
88 const net::BackoffEntry::Policy kNoBackoffPolicy
= {
89 // Number of initial errors (in sequence) to ignore before applying
90 // exponential back-off rules.
93 // Initial delay for exponential back-off in ms.
96 // Factor by which the waiting time will be multiplied.
99 // Fuzzing percentage. ex: 10% will spread requests randomly
100 // between 90%-100% of the calculated time.
103 // Maximum amount of time we are willing to delay our request in ms.
106 // Time to keep an entry from being discarded even when it
107 // has no significant state, -1 to never discard.
110 // Don't use initial delay unless the last request was an error.
114 const char kEmptyUpdateUrlData
[] = "";
116 int kExpectedLoadFlags
=
117 net::LOAD_DO_NOT_SEND_COOKIES
|
118 net::LOAD_DO_NOT_SAVE_COOKIES
|
119 net::LOAD_DISABLE_CACHE
;
121 int kExpectedLoadFlagsForProtectedDownload
= net::LOAD_DISABLE_CACHE
;
123 const ManifestFetchData::PingData
kNeverPingedData(
124 ManifestFetchData::kNeverPinged
, ManifestFetchData::kNeverPinged
, true);
126 class MockExtensionDownloaderDelegate
: public ExtensionDownloaderDelegate
{
128 MOCK_METHOD4(OnExtensionDownloadFailed
, void(const std::string
&,
131 const std::set
<int>&));
132 MOCK_METHOD7(OnExtensionDownloadFinished
, void(const std::string
&,
133 const base::FilePath
&,
138 const std::set
<int>&));
139 MOCK_METHOD2(GetPingDataForExtension
,
140 bool(const std::string
&, ManifestFetchData::PingData
*));
141 MOCK_METHOD1(GetUpdateUrlData
, std::string(const std::string
&));
142 MOCK_METHOD1(IsExtensionPending
, bool(const std::string
&));
143 MOCK_METHOD2(GetExtensionExistingVersion
,
144 bool(const std::string
&, std::string
*));
147 scoped_refptr
<content::MessageLoopRunner
> runner
=
148 new content::MessageLoopRunner
;
149 quit_closure_
= runner
->QuitClosure();
151 quit_closure_
.Reset();
158 void DelegateTo(ExtensionDownloaderDelegate
* delegate
) {
159 ON_CALL(*this, OnExtensionDownloadFailed(_
, _
, _
, _
))
160 .WillByDefault(Invoke(delegate
,
161 &ExtensionDownloaderDelegate::OnExtensionDownloadFailed
));
162 ON_CALL(*this, OnExtensionDownloadFinished(_
, _
, _
, _
, _
, _
, _
))
163 .WillByDefault(Invoke(delegate
,
164 &ExtensionDownloaderDelegate::OnExtensionDownloadFinished
));
165 ON_CALL(*this, GetPingDataForExtension(_
, _
))
166 .WillByDefault(Invoke(delegate
,
167 &ExtensionDownloaderDelegate::GetPingDataForExtension
));
168 ON_CALL(*this, GetUpdateUrlData(_
))
169 .WillByDefault(Invoke(delegate
,
170 &ExtensionDownloaderDelegate::GetUpdateUrlData
));
171 ON_CALL(*this, IsExtensionPending(_
))
172 .WillByDefault(Invoke(delegate
,
173 &ExtensionDownloaderDelegate::IsExtensionPending
));
174 ON_CALL(*this, GetExtensionExistingVersion(_
, _
))
175 .WillByDefault(Invoke(delegate
,
176 &ExtensionDownloaderDelegate::GetExtensionExistingVersion
));
180 base::Closure quit_closure_
;
183 const int kNotificationsObserved
[] = {
184 chrome::NOTIFICATION_EXTENSION_UPDATING_STARTED
,
185 chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND
,
188 // A class that observes the notifications sent by the ExtensionUpdater and
189 // the ExtensionDownloader.
190 class NotificationsObserver
: public content::NotificationObserver
{
192 NotificationsObserver() {
193 for (size_t i
= 0; i
< arraysize(kNotificationsObserved
); ++i
) {
196 kNotificationsObserved
[i
],
197 content::NotificationService::AllSources());
201 virtual ~NotificationsObserver() {
202 for (size_t i
= 0; i
< arraysize(kNotificationsObserved
); ++i
) {
203 registrar_
.Remove(this,
204 kNotificationsObserved
[i
],
205 content::NotificationService::AllSources());
209 size_t StartedCount() { return count_
[0]; }
210 size_t UpdatedCount() { return count_
[1]; }
212 bool Updated(const std::string
& id
) {
213 return updated_
.find(id
) != updated_
.end();
217 scoped_refptr
<content::MessageLoopRunner
> runner
=
218 new content::MessageLoopRunner
;
219 quit_closure_
= runner
->QuitClosure();
221 quit_closure_
.Reset();
225 virtual void Observe(int type
,
226 const content::NotificationSource
& source
,
227 const content::NotificationDetails
& details
) OVERRIDE
{
228 if (!quit_closure_
.is_null())
230 for (size_t i
= 0; i
< arraysize(kNotificationsObserved
); ++i
) {
231 if (kNotificationsObserved
[i
] == type
) {
233 if (type
== chrome::NOTIFICATION_EXTENSION_UPDATE_FOUND
) {
235 content::Details
<UpdateDetails
>(details
)->id
);
243 content::NotificationRegistrar registrar_
;
244 size_t count_
[arraysize(kNotificationsObserved
)];
245 std::set
<std::string
> updated_
;
246 base::Closure quit_closure_
;
248 DISALLOW_COPY_AND_ASSIGN(NotificationsObserver
);
253 // Base class for further specialized test classes.
254 class MockService
: public TestExtensionService
{
256 explicit MockService(TestExtensionPrefs
* prefs
)
257 : prefs_(prefs
), pending_extension_manager_(*this, &profile_
) {}
259 virtual ~MockService() {}
261 virtual PendingExtensionManager
* pending_extension_manager() OVERRIDE
{
262 ADD_FAILURE() << "Subclass should override this if it will "
263 << "be accessed by a test.";
264 return &pending_extension_manager_
;
267 Profile
* profile() { return &profile_
; }
269 net::URLRequestContextGetter
* request_context() {
270 return profile_
.GetRequestContext();
273 ExtensionPrefs
* extension_prefs() { return prefs_
->prefs(); }
275 PrefService
* pref_service() { return prefs_
->pref_service(); }
277 // Creates test extensions and inserts them into list. The name and
278 // version are all based on their index. If |update_url| is non-null, it
279 // will be used as the update_url for each extension.
280 // The |id| is used to distinguish extension names and make sure that
281 // no two extensions share the same name.
282 void CreateTestExtensions(int id
, int count
, ExtensionList
*list
,
283 const std::string
* update_url
,
284 Manifest::Location location
) {
285 for (int i
= 1; i
<= count
; i
++) {
286 base::DictionaryValue manifest
;
287 manifest
.SetString(manifest_keys::kVersion
,
288 base::StringPrintf("%d.0.0.0", i
));
289 manifest
.SetString(manifest_keys::kName
,
290 base::StringPrintf("Extension %d.%d", id
, i
));
292 manifest
.SetString(manifest_keys::kUpdateURL
, *update_url
);
293 scoped_refptr
<Extension
> e
=
294 prefs_
->AddExtensionWithManifest(manifest
, location
);
295 ASSERT_TRUE(e
.get() != NULL
);
301 TestExtensionPrefs
* const prefs_
;
302 TestingProfile profile_
;
303 PendingExtensionManager pending_extension_manager_
;
306 DISALLOW_COPY_AND_ASSIGN(MockService
);
310 bool ShouldInstallExtensionsOnly(const Extension
* extension
) {
311 return extension
->GetType() == Manifest::TYPE_EXTENSION
;
314 bool ShouldInstallThemesOnly(const Extension
* extension
) {
315 return extension
->is_theme();
318 bool ShouldAlwaysInstall(const Extension
* extension
) {
322 // Loads some pending extension records into a pending extension manager.
323 void SetupPendingExtensionManagerForTest(
325 const GURL
& update_url
,
326 PendingExtensionManager
* pending_extension_manager
) {
327 for (int i
= 1; i
<= count
; ++i
) {
328 PendingExtensionInfo::ShouldAllowInstallPredicate should_allow_install
=
329 (i
% 2 == 0) ? &ShouldInstallThemesOnly
: &ShouldInstallExtensionsOnly
;
330 const bool kIsFromSync
= true;
331 const bool kInstallSilently
= true;
332 const bool kMarkAcknowledged
= false;
333 std::string id
= id_util::GenerateId(base::StringPrintf("extension%i", i
));
335 pending_extension_manager
->AddForTesting(
336 PendingExtensionInfo(id
,
340 should_allow_install
,
349 class ServiceForManifestTests
: public MockService
{
351 explicit ServiceForManifestTests(TestExtensionPrefs
* prefs
)
352 : MockService(prefs
), registry_(ExtensionRegistry::Get(profile())) {}
354 virtual ~ServiceForManifestTests() {}
356 virtual const Extension
* GetExtensionById(
357 const std::string
& id
, bool include_disabled
) const OVERRIDE
{
358 const Extension
* result
= registry_
->enabled_extensions().GetByID(id
);
359 if (result
|| !include_disabled
)
361 return registry_
->disabled_extensions().GetByID(id
);
364 virtual const ExtensionSet
* extensions() const OVERRIDE
{
365 return ®istry_
->enabled_extensions();
368 virtual PendingExtensionManager
* pending_extension_manager() OVERRIDE
{
369 return &pending_extension_manager_
;
372 virtual const Extension
* GetPendingExtensionUpdate(
373 const std::string
& id
) const OVERRIDE
{
377 virtual bool IsExtensionEnabled(const std::string
& id
) const OVERRIDE
{
378 return !registry_
->disabled_extensions().Contains(id
);
381 void set_extensions(ExtensionList extensions
,
382 ExtensionList disabled_extensions
) {
383 registry_
->ClearAll();
384 for (ExtensionList::const_iterator it
= extensions
.begin();
385 it
!= extensions
.end(); ++it
) {
386 registry_
->AddEnabled(*it
);
388 for (ExtensionList::const_iterator it
= disabled_extensions
.begin();
389 it
!= disabled_extensions
.end(); ++it
) {
390 registry_
->AddDisabled(*it
);
395 ExtensionRegistry
* registry_
;
398 class ServiceForDownloadTests
: public MockService
{
400 explicit ServiceForDownloadTests(TestExtensionPrefs
* prefs
)
401 : MockService(prefs
) {
404 // Add a fake crx installer to be returned by a call to UpdateExtension()
405 // with a specific ID. Caller keeps ownership of |crx_installer|.
406 void AddFakeCrxInstaller(const std::string
& id
, CrxInstaller
* crx_installer
) {
407 fake_crx_installers_
[id
] = crx_installer
;
410 virtual bool UpdateExtension(
411 const std::string
& id
,
412 const base::FilePath
& extension_path
,
413 bool file_ownership_passed
,
414 CrxInstaller
** out_crx_installer
) OVERRIDE
{
416 install_path_
= extension_path
;
418 if (ContainsKey(fake_crx_installers_
, id
)) {
419 *out_crx_installer
= fake_crx_installers_
[id
];
426 virtual PendingExtensionManager
* pending_extension_manager() OVERRIDE
{
427 return &pending_extension_manager_
;
430 virtual const Extension
* GetExtensionById(
431 const std::string
& id
, bool) const OVERRIDE
{
432 last_inquired_extension_id_
= id
;
436 const std::string
& extension_id() const { return extension_id_
; }
437 const base::FilePath
& install_path() const { return install_path_
; }
440 // Hold the set of ids that UpdateExtension() should fake success on.
441 // UpdateExtension(id, ...) will return true iff fake_crx_installers_
442 // contains key |id|. |out_install_notification_source| will be set
443 // to Source<CrxInstaller(fake_crx_installers_[i]).
444 std::map
<std::string
, CrxInstaller
*> fake_crx_installers_
;
446 std::string extension_id_
;
447 base::FilePath install_path_
;
450 // The last extension ID that GetExtensionById was called with.
451 // Mutable because the method that sets it (GetExtensionById) is const
452 // in the actual extension service, but must record the last extension
453 // ID in this test class.
454 mutable std::string last_inquired_extension_id_
;
457 static const int kUpdateFrequencySecs
= 15;
459 // Takes a string with KEY=VALUE parameters separated by '&' in |params| and
460 // puts the key/value pairs into |result|. For keys with no value, the empty
461 // string is used. So for "a=1&b=foo&c", result would map "a" to "1", "b" to
462 // "foo", and "c" to "".
463 static void ExtractParameters(const std::string
& params
,
464 std::map
<std::string
, std::string
>* result
) {
465 std::vector
<std::string
> pairs
;
466 base::SplitString(params
, '&', &pairs
);
467 for (size_t i
= 0; i
< pairs
.size(); i
++) {
468 std::vector
<std::string
> key_val
;
469 base::SplitString(pairs
[i
], '=', &key_val
);
470 if (!key_val
.empty()) {
471 std::string key
= key_val
[0];
472 EXPECT_TRUE(result
->find(key
) == result
->end());
473 (*result
)[key
] = (key_val
.size() == 2) ? key_val
[1] : std::string();
480 static void VerifyQueryAndExtractParameters(
481 const std::string
& query
,
482 std::map
<std::string
, std::string
>* result
) {
483 std::map
<std::string
, std::string
> params
;
484 ExtractParameters(query
, ¶ms
);
486 std::string omaha_params
=
487 chrome::OmahaQueryParams::Get(chrome::OmahaQueryParams::CRX
);
488 std::map
<std::string
, std::string
> expected
;
489 ExtractParameters(omaha_params
, &expected
);
491 for (std::map
<std::string
, std::string
>::iterator it
= expected
.begin();
492 it
!= expected
.end(); ++it
) {
493 EXPECT_EQ(it
->second
, params
[it
->first
]);
496 EXPECT_EQ(1U, params
.count("x"));
497 std::string decoded
= net::UnescapeURLComponent(
498 params
["x"], net::UnescapeRule::URL_SPECIAL_CHARS
);
499 ExtractParameters(decoded
, result
);
502 // All of our tests that need to use private APIs of ExtensionUpdater live
503 // inside this class (which is a friend to ExtensionUpdater).
504 class ExtensionUpdaterTest
: public testing::Test
{
506 ExtensionUpdaterTest()
508 content::TestBrowserThreadBundle::IO_MAINLOOP
) {
511 virtual void SetUp() OVERRIDE
{
512 prefs_
.reset(new TestExtensionPrefs(base::MessageLoopProxy::current()));
515 virtual void TearDown() OVERRIDE
{
516 // Some tests create URLRequestContextGetters, whose destruction must run
517 // on the IO thread. Make sure the IO loop spins before shutdown so that
518 // those objects are released.
523 void RunUntilIdle() {
524 prefs_
->pref_service()->CommitPendingWrite();
525 base::RunLoop().RunUntilIdle();
528 void SimulateTimerFired(ExtensionUpdater
* updater
) {
529 EXPECT_TRUE(updater
->timer_
.IsRunning());
530 updater
->timer_
.Stop();
531 updater
->TimerFired();
534 // Adds a Result with the given data to results.
535 void AddParseResult(const std::string
& id
,
536 const std::string
& version
,
537 const std::string
& url
,
538 UpdateManifest::Results
* results
) {
539 UpdateManifest::Result result
;
540 result
.extension_id
= id
;
541 result
.version
= version
;
542 result
.crx_url
= GURL(url
);
543 results
->list
.push_back(result
);
546 void ResetDownloader(ExtensionUpdater
* updater
,
547 ExtensionDownloader
* downloader
) {
548 EXPECT_FALSE(updater
->downloader_
.get());
549 updater
->downloader_
.reset(downloader
);
552 void StartUpdateCheck(ExtensionDownloader
* downloader
,
553 ManifestFetchData
* fetch_data
) {
554 downloader
->StartUpdateCheck(scoped_ptr
<ManifestFetchData
>(fetch_data
));
557 size_t ManifestFetchersCount(ExtensionDownloader
* downloader
) {
558 return downloader
->manifests_queue_
.size() +
559 (downloader
->manifest_fetcher_
.get() ? 1 : 0);
562 void TestExtensionUpdateCheckRequests(bool pending
) {
563 // Create an extension with an update_url.
564 ServiceForManifestTests
service(prefs_
.get());
565 std::string
update_url("http://foo.com/bar");
566 ExtensionList extensions
;
567 NotificationsObserver observer
;
568 PendingExtensionManager
* pending_extension_manager
=
569 service
.pending_extension_manager();
571 SetupPendingExtensionManagerForTest(1, GURL(update_url
),
572 pending_extension_manager
);
574 service
.CreateTestExtensions(1, 1, &extensions
, &update_url
,
576 service
.set_extensions(extensions
, ExtensionList());
579 // Set up and start the updater.
580 net::TestURLFetcherFactory factory
;
581 ExtensionUpdater
updater(
582 &service
, service
.extension_prefs(), service
.pref_service(),
583 service
.profile(), 60*60*24, NULL
);
586 // Tell the update that it's time to do update checks.
587 EXPECT_EQ(0u, observer
.StartedCount());
588 SimulateTimerFired(&updater
);
589 EXPECT_EQ(1u, observer
.StartedCount());
591 // Get the url our mock fetcher was asked to fetch.
592 net::TestURLFetcher
* fetcher
=
593 factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
594 const GURL
& url
= fetcher
->GetOriginalURL();
595 EXPECT_FALSE(url
.is_empty());
596 EXPECT_TRUE(url
.is_valid());
597 EXPECT_TRUE(url
.SchemeIs("http"));
598 EXPECT_EQ("foo.com", url
.host());
599 EXPECT_EQ("/bar", url
.path());
601 // Validate the extension request parameters in the query. It should
602 // look something like "x=id%3D<id>%26v%3D<version>%26uc".
603 EXPECT_TRUE(url
.has_query());
604 std::map
<std::string
, std::string
> params
;
605 VerifyQueryAndExtractParameters(url
.query(), ¶ms
);
607 EXPECT_TRUE(pending_extension_manager
->IsIdPending(params
["id"]));
608 EXPECT_EQ("0.0.0.0", params
["v"]);
610 EXPECT_EQ(extensions
[0]->id(), params
["id"]);
611 EXPECT_EQ(extensions
[0]->VersionString(), params
["v"]);
613 EXPECT_EQ("", params
["uc"]);
616 void TestUpdateUrlDataEmpty() {
617 const std::string id
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
618 const std::string version
= "1.0";
620 // Make sure that an empty update URL data string does not cause a ap=
621 // option to appear in the x= parameter.
622 ManifestFetchData
fetch_data(GURL("http://localhost/foo"), 0);
623 fetch_data
.AddExtension(
624 id
, version
, &kNeverPingedData
, std::string(), std::string());
626 std::map
<std::string
, std::string
> params
;
627 VerifyQueryAndExtractParameters(fetch_data
.full_url().query(), ¶ms
);
628 EXPECT_EQ(id
, params
["id"]);
629 EXPECT_EQ(version
, params
["v"]);
630 EXPECT_EQ(0U, params
.count("ap"));
633 void TestUpdateUrlDataSimple() {
634 const std::string id
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
635 const std::string version
= "1.0";
637 // Make sure that an update URL data string causes an appropriate ap=
638 // option to appear in the x= parameter.
639 ManifestFetchData
fetch_data(GURL("http://localhost/foo"), 0);
640 fetch_data
.AddExtension(
641 id
, version
, &kNeverPingedData
, "bar", std::string());
642 std::map
<std::string
, std::string
> params
;
643 VerifyQueryAndExtractParameters(fetch_data
.full_url().query(), ¶ms
);
644 EXPECT_EQ(id
, params
["id"]);
645 EXPECT_EQ(version
, params
["v"]);
646 EXPECT_EQ("bar", params
["ap"]);
649 void TestUpdateUrlDataCompound() {
650 const std::string id
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
651 const std::string version
= "1.0";
653 // Make sure that an update URL data string causes an appropriate ap=
654 // option to appear in the x= parameter.
655 ManifestFetchData
fetch_data(GURL("http://localhost/foo"), 0);
656 fetch_data
.AddExtension(
657 id
, version
, &kNeverPingedData
, "a=1&b=2&c", std::string());
658 std::map
<std::string
, std::string
> params
;
659 VerifyQueryAndExtractParameters(fetch_data
.full_url().query(), ¶ms
);
660 EXPECT_EQ(id
, params
["id"]);
661 EXPECT_EQ(version
, params
["v"]);
662 EXPECT_EQ("a%3D1%26b%3D2%26c", params
["ap"]);
665 void TestUpdateUrlDataFromGallery(const std::string
& gallery_url
) {
666 net::TestURLFetcherFactory factory
;
668 MockService
service(prefs_
.get());
669 MockExtensionDownloaderDelegate delegate
;
670 ExtensionDownloader
downloader(&delegate
, service
.request_context());
671 ExtensionList extensions
;
672 std::string
url(gallery_url
);
674 service
.CreateTestExtensions(1, 1, &extensions
, &url
, Manifest::INTERNAL
);
676 const std::string
& id
= extensions
[0]->id();
677 EXPECT_CALL(delegate
, GetPingDataForExtension(id
, _
));
679 downloader
.AddExtension(*extensions
[0].get(), 0);
680 downloader
.StartAllPending(NULL
);
681 net::TestURLFetcher
* fetcher
=
682 factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
683 ASSERT_TRUE(fetcher
);
684 // Make sure that extensions that update from the gallery ignore any
686 const std::string
& update_url
= fetcher
->GetOriginalURL().spec();
687 std::string::size_type x
= update_url
.find("x=");
688 EXPECT_NE(std::string::npos
, x
);
689 std::string::size_type ap
= update_url
.find("ap%3D", x
);
690 EXPECT_EQ(std::string::npos
, ap
);
693 void TestInstallSource() {
694 const std::string id
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
695 const std::string version
= "1.0";
696 const std::string install_source
= "instally";
698 // Make sure that an installsource= appears in the x= parameter.
699 ManifestFetchData
fetch_data(GURL("http://localhost/foo"), 0);
700 fetch_data
.AddExtension(id
, version
, &kNeverPingedData
,
701 kEmptyUpdateUrlData
, install_source
);
702 std::map
<std::string
, std::string
> params
;
703 VerifyQueryAndExtractParameters(fetch_data
.full_url().query(), ¶ms
);
704 EXPECT_EQ(id
, params
["id"]);
705 EXPECT_EQ(version
, params
["v"]);
706 EXPECT_EQ(install_source
, params
["installsource"]);
709 void TestDetermineUpdates() {
710 TestingProfile profile
;
711 MockExtensionDownloaderDelegate delegate
;
712 ExtensionDownloader
downloader(&delegate
, profile
.GetRequestContext());
714 // Check passing an empty list of parse results to DetermineUpdates
715 ManifestFetchData
fetch_data(GURL("http://localhost/foo"), 0);
716 UpdateManifest::Results updates
;
717 std::vector
<int> updateable
;
718 downloader
.DetermineUpdates(fetch_data
, updates
, &updateable
);
719 EXPECT_TRUE(updateable
.empty());
721 // Create two updates - expect that DetermineUpdates will return the first
722 // one (v1.0 installed, v1.1 available) but not the second one (both
723 // installed and available at v2.0).
724 const std::string id1
= id_util::GenerateId("1");
725 const std::string id2
= id_util::GenerateId("2");
726 fetch_data
.AddExtension(
727 id1
, "1.0.0.0", &kNeverPingedData
, kEmptyUpdateUrlData
, std::string());
728 AddParseResult(id1
, "1.1", "http://localhost/e1_1.1.crx", &updates
);
729 fetch_data
.AddExtension(
730 id2
, "2.0.0.0", &kNeverPingedData
, kEmptyUpdateUrlData
, std::string());
731 AddParseResult(id2
, "2.0.0.0", "http://localhost/e2_2.0.crx", &updates
);
733 EXPECT_CALL(delegate
, IsExtensionPending(_
)).WillRepeatedly(Return(false));
734 EXPECT_CALL(delegate
, GetExtensionExistingVersion(id1
, _
))
735 .WillOnce(DoAll(SetArgPointee
<1>("1.0.0.0"),
737 EXPECT_CALL(delegate
, GetExtensionExistingVersion(id2
, _
))
738 .WillOnce(DoAll(SetArgPointee
<1>("2.0.0.0"),
741 downloader
.DetermineUpdates(fetch_data
, updates
, &updateable
);
742 EXPECT_EQ(1u, updateable
.size());
743 EXPECT_EQ(0, updateable
[0]);
746 void TestDetermineUpdatesPending() {
747 // Create a set of test extensions
748 ServiceForManifestTests
service(prefs_
.get());
749 PendingExtensionManager
* pending_extension_manager
=
750 service
.pending_extension_manager();
751 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager
);
753 TestingProfile profile
;
754 MockExtensionDownloaderDelegate delegate
;
755 ExtensionDownloader
downloader(&delegate
, profile
.GetRequestContext());
757 ManifestFetchData
fetch_data(GURL("http://localhost/foo"), 0);
758 UpdateManifest::Results updates
;
760 std::list
<std::string
> ids_for_update_check
;
761 pending_extension_manager
->GetPendingIdsForUpdateCheck(
762 &ids_for_update_check
);
764 std::list
<std::string
>::const_iterator it
;
765 for (it
= ids_for_update_check
.begin();
766 it
!= ids_for_update_check
.end(); ++it
) {
767 fetch_data
.AddExtension(*it
,
772 AddParseResult(*it
, "1.1", "http://localhost/e1_1.1.crx", &updates
);
775 // The delegate will tell the downloader that all the extensions are
777 EXPECT_CALL(delegate
, IsExtensionPending(_
)).WillRepeatedly(Return(true));
779 std::vector
<int> updateable
;
780 downloader
.DetermineUpdates(fetch_data
, updates
, &updateable
);
781 // All the apps should be updateable.
782 EXPECT_EQ(3u, updateable
.size());
783 for (std::vector
<int>::size_type i
= 0; i
< updateable
.size(); ++i
) {
784 EXPECT_EQ(static_cast<int>(i
), updateable
[i
]);
788 void TestMultipleManifestDownloading() {
789 net::TestURLFetcherFactory factory
;
790 net::TestURLFetcher
* fetcher
= NULL
;
791 NotificationsObserver observer
;
792 MockService
service(prefs_
.get());
793 MockExtensionDownloaderDelegate delegate
;
794 ExtensionDownloader
downloader(&delegate
, service
.request_context());
795 downloader
.manifests_queue_
.set_backoff_policy(&kNoBackoffPolicy
);
797 GURL
kUpdateUrl("http://localhost/manifest1");
799 scoped_ptr
<ManifestFetchData
> fetch1(new ManifestFetchData(kUpdateUrl
, 0));
800 scoped_ptr
<ManifestFetchData
> fetch2(new ManifestFetchData(kUpdateUrl
, 0));
801 scoped_ptr
<ManifestFetchData
> fetch3(new ManifestFetchData(kUpdateUrl
, 0));
802 scoped_ptr
<ManifestFetchData
> fetch4(new ManifestFetchData(kUpdateUrl
, 0));
803 ManifestFetchData::PingData
zeroDays(0, 0, true);
804 fetch1
->AddExtension(
805 "1111", "1.0", &zeroDays
, kEmptyUpdateUrlData
, std::string());
806 fetch2
->AddExtension(
807 "2222", "2.0", &zeroDays
, kEmptyUpdateUrlData
, std::string());
808 fetch3
->AddExtension(
809 "3333", "3.0", &zeroDays
, kEmptyUpdateUrlData
, std::string());
810 fetch4
->AddExtension(
811 "4444", "4.0", &zeroDays
, kEmptyUpdateUrlData
, std::string());
813 // This will start the first fetcher and queue the others. The next in queue
814 // is started as each fetcher receives its response.
815 downloader
.StartUpdateCheck(fetch1
.Pass());
816 downloader
.StartUpdateCheck(fetch2
.Pass());
817 downloader
.StartUpdateCheck(fetch3
.Pass());
818 downloader
.StartUpdateCheck(fetch4
.Pass());
821 // The first fetch will fail.
822 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
823 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
824 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
825 EXPECT_CALL(delegate
, OnExtensionDownloadFailed(
826 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED
, _
, _
));
827 fetcher
->set_url(kUpdateUrl
);
828 fetcher
->set_status(net::URLRequestStatus());
829 fetcher
->set_response_code(400);
830 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
832 Mock::VerifyAndClearExpectations(&delegate
);
834 // The second fetch gets invalid data.
835 const std::string kInvalidXml
= "invalid xml";
836 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
837 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
838 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
839 EXPECT_CALL(delegate
, OnExtensionDownloadFailed(
840 "2222", ExtensionDownloaderDelegate::MANIFEST_INVALID
, _
, _
))
841 .WillOnce(InvokeWithoutArgs(&delegate
,
842 &MockExtensionDownloaderDelegate::Quit
));
843 fetcher
->set_url(kUpdateUrl
);
844 fetcher
->set_status(net::URLRequestStatus());
845 fetcher
->set_response_code(200);
846 fetcher
->SetResponseString(kInvalidXml
);
847 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
849 Mock::VerifyAndClearExpectations(&delegate
);
851 // The third fetcher doesn't have an update available.
852 const std::string kNoUpdate
=
853 "<?xml version='1.0' encoding='UTF-8'?>"
854 "<gupdate xmlns='http://www.google.com/update2/response'"
856 " <app appid='3333'>"
857 " <updatecheck codebase='http://example.com/extension_3.0.0.0.crx'"
858 " version='3.0.0.0' prodversionmin='3.0.0.0' />"
861 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
862 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
863 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
864 EXPECT_CALL(delegate
, IsExtensionPending("3333")).WillOnce(Return(false));
865 EXPECT_CALL(delegate
, GetExtensionExistingVersion("3333", _
))
866 .WillOnce(DoAll(SetArgPointee
<1>("3.0.0.0"),
868 EXPECT_CALL(delegate
, OnExtensionDownloadFailed(
869 "3333", ExtensionDownloaderDelegate::NO_UPDATE_AVAILABLE
, _
, _
))
870 .WillOnce(InvokeWithoutArgs(&delegate
,
871 &MockExtensionDownloaderDelegate::Quit
));
872 fetcher
->set_url(kUpdateUrl
);
873 fetcher
->set_status(net::URLRequestStatus());
874 fetcher
->set_response_code(200);
875 fetcher
->SetResponseString(kNoUpdate
);
876 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
878 Mock::VerifyAndClearExpectations(&delegate
);
880 // The last fetcher has an update.
881 const std::string kUpdateAvailable
=
882 "<?xml version='1.0' encoding='UTF-8'?>"
883 "<gupdate xmlns='http://www.google.com/update2/response'"
885 " <app appid='4444'>"
886 " <updatecheck codebase='http://example.com/extension_1.2.3.4.crx'"
887 " version='4.0.42.0' prodversionmin='4.0.42.0' />"
890 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
891 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
892 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
893 EXPECT_CALL(delegate
, IsExtensionPending("4444")).WillOnce(Return(false));
894 EXPECT_CALL(delegate
, GetExtensionExistingVersion("4444", _
))
895 .WillOnce(DoAll(SetArgPointee
<1>("4.0.0.0"),
897 fetcher
->set_url(kUpdateUrl
);
898 fetcher
->set_status(net::URLRequestStatus());
899 fetcher
->set_response_code(200);
900 fetcher
->SetResponseString(kUpdateAvailable
);
901 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
903 Mock::VerifyAndClearExpectations(&delegate
);
905 // Verify that the downloader decided to update this extension.
906 EXPECT_EQ(1u, observer
.UpdatedCount());
907 EXPECT_TRUE(observer
.Updated("4444"));
910 void TestManifestRetryDownloading() {
911 net::TestURLFetcherFactory factory
;
912 net::TestURLFetcher
* fetcher
= NULL
;
913 NotificationsObserver observer
;
914 MockService
service(prefs_
.get());
915 MockExtensionDownloaderDelegate delegate
;
916 ExtensionDownloader
downloader(&delegate
, service
.request_context());
917 downloader
.manifests_queue_
.set_backoff_policy(&kNoBackoffPolicy
);
919 GURL
kUpdateUrl("http://localhost/manifest1");
921 scoped_ptr
<ManifestFetchData
> fetch(new ManifestFetchData(kUpdateUrl
, 0));
922 ManifestFetchData::PingData
zeroDays(0, 0, true);
924 "1111", "1.0", &zeroDays
, kEmptyUpdateUrlData
, std::string());
926 // This will start the first fetcher.
927 downloader
.StartUpdateCheck(fetch
.Pass());
930 // ExtensionDownloader should retry kMaxRetries times and then fail.
931 EXPECT_CALL(delegate
, OnExtensionDownloadFailed(
932 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED
, _
, _
));
933 for (int i
= 0; i
<= ExtensionDownloader::kMaxRetries
; ++i
) {
934 // All fetches will fail.
935 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
936 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
937 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
938 fetcher
->set_url(kUpdateUrl
);
939 fetcher
->set_status(net::URLRequestStatus());
940 // Code 5xx causes ExtensionDownloader to retry.
941 fetcher
->set_response_code(500);
942 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
945 Mock::VerifyAndClearExpectations(&delegate
);
948 // For response codes that are not in the 5xx range ExtensionDownloader
950 fetch
.reset(new ManifestFetchData(kUpdateUrl
, 0));
952 "1111", "1.0", &zeroDays
, kEmptyUpdateUrlData
, std::string());
954 // This will start the first fetcher.
955 downloader
.StartUpdateCheck(fetch
.Pass());
958 EXPECT_CALL(delegate
, OnExtensionDownloadFailed(
959 "1111", ExtensionDownloaderDelegate::MANIFEST_FETCH_FAILED
, _
, _
));
960 // The first fetch will fail, and require retrying.
961 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
962 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
963 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
964 fetcher
->set_url(kUpdateUrl
);
965 fetcher
->set_status(net::URLRequestStatus());
966 fetcher
->set_response_code(500);
967 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
970 // The second fetch will fail with response 400 and should not cause
971 // ExtensionDownloader to retry.
972 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
973 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
974 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
975 fetcher
->set_url(kUpdateUrl
);
976 fetcher
->set_status(net::URLRequestStatus());
977 fetcher
->set_response_code(400);
978 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
981 Mock::VerifyAndClearExpectations(&delegate
);
984 void TestSingleExtensionDownloading(bool pending
, bool retry
, bool fail
) {
985 net::TestURLFetcherFactory factory
;
986 net::TestURLFetcher
* fetcher
= NULL
;
987 scoped_ptr
<ServiceForDownloadTests
> service(
988 new ServiceForDownloadTests(prefs_
.get()));
989 ExtensionUpdater
updater(service
.get(), service
->extension_prefs(),
990 service
->pref_service(),
992 kUpdateFrequencySecs
,
995 MockExtensionDownloaderDelegate delegate
;
996 delegate
.DelegateTo(&updater
);
999 new ExtensionDownloader(&delegate
, service
->request_context()));
1000 updater
.downloader_
->extensions_queue_
.set_backoff_policy(
1003 GURL
test_url("http://localhost/extension.crx");
1005 std::string id
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1007 Version
version("0.0.1");
1008 std::set
<int> requests
;
1010 scoped_ptr
<ExtensionDownloader::ExtensionFetch
> fetch(
1011 new ExtensionDownloader::ExtensionFetch(
1012 id
, test_url
, hash
, version
.GetString(), requests
));
1013 updater
.downloader_
->FetchUpdatedExtension(fetch
.Pass());
1016 const bool kIsFromSync
= true;
1017 const bool kInstallSilently
= true;
1018 const bool kMarkAcknowledged
= false;
1019 PendingExtensionManager
* pending_extension_manager
=
1020 service
->pending_extension_manager();
1021 pending_extension_manager
->AddForTesting(
1022 PendingExtensionInfo(id
,
1026 &ShouldAlwaysInstall
,
1030 Extension::NO_FLAGS
,
1031 kMarkAcknowledged
));
1034 // Call back the ExtensionUpdater with a 200 response and some test data
1035 base::FilePath
extension_file_path(FILE_PATH_LITERAL("/whatever"));
1036 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId
);
1037 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
1038 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
1041 // Reply with response code 500 to cause ExtensionDownloader to retry
1042 fetcher
->set_url(test_url
);
1043 fetcher
->set_status(net::URLRequestStatus());
1044 fetcher
->set_response_code(500);
1045 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
1048 fetcher
= factory
.GetFetcherByID(
1049 ExtensionDownloader::kExtensionFetcherId
);
1050 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
1051 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
1054 fetcher
->set_url(test_url
);
1055 fetcher
->set_status(net::URLRequestStatus());
1057 fetcher
->set_response_code(404);
1058 EXPECT_CALL(delegate
, OnExtensionDownloadFailed(id
, _
, _
, requests
));
1060 fetcher
->set_response_code(200);
1061 fetcher
->SetResponseFilePath(extension_file_path
);
1062 EXPECT_CALL(delegate
, OnExtensionDownloadFinished(
1063 id
, _
, _
, _
, version
.GetString(), _
, requests
));
1065 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
1070 // Don't expect any extension to have been installed.
1071 EXPECT_TRUE(service
->extension_id().empty());
1073 // Expect that ExtensionUpdater asked the mock extensions service to
1074 // install a file with the test data for the right id.
1075 EXPECT_EQ(id
, service
->extension_id());
1076 base::FilePath tmpfile_path
= service
->install_path();
1077 EXPECT_FALSE(tmpfile_path
.empty());
1078 EXPECT_EQ(extension_file_path
, tmpfile_path
);
1082 // Update a single extension in an environment where the download request
1083 // initially responds with a 403 status. Expect the fetcher to automatically
1084 // retry with cookies enabled.
1085 void TestSingleProtectedExtensionDownloading(bool use_https
, bool fail
) {
1086 net::TestURLFetcherFactory factory
;
1087 net::TestURLFetcher
* fetcher
= NULL
;
1088 scoped_ptr
<ServiceForDownloadTests
> service(
1089 new ServiceForDownloadTests(prefs_
.get()));
1090 ExtensionUpdater
updater(service
.get(), service
->extension_prefs(),
1091 service
->pref_service(),
1093 kUpdateFrequencySecs
,
1098 new ExtensionDownloader(&updater
, service
->request_context()));
1099 updater
.downloader_
->extensions_queue_
.set_backoff_policy(
1102 GURL
test_url(use_https
? "https://localhost/extension.crx" :
1103 "http://localhost/extension.crx");
1105 std::string id
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1107 Version
version("0.0.1");
1108 std::set
<int> requests
;
1110 scoped_ptr
<ExtensionDownloader::ExtensionFetch
> fetch(
1111 new ExtensionDownloader::ExtensionFetch(
1112 id
, test_url
, hash
, version
.GetString(), requests
));
1113 updater
.downloader_
->FetchUpdatedExtension(fetch
.Pass());
1115 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId
);
1116 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
1117 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
1119 // Fake a 403 response.
1120 fetcher
->set_url(test_url
);
1121 fetcher
->set_status(net::URLRequestStatus());
1122 fetcher
->set_response_code(403);
1123 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
1126 // Verify that the fetcher has been switched to protected download mode
1127 // so that cookies would be sent with the next request (https only).
1128 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId
);
1129 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
1132 fetcher
->GetLoadFlags() == kExpectedLoadFlagsForProtectedDownload
);
1134 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
1137 // Attempt to fetch again after the auth failure.
1139 // Fail and verify that the fetch queue is cleared.
1140 fetcher
->set_url(test_url
);
1141 fetcher
->set_status(net::URLRequestStatus());
1142 fetcher
->set_response_code(403);
1143 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
1145 EXPECT_EQ(0U, updater
.downloader_
->extensions_queue_
.active_request());
1148 base::FilePath
extension_file_path(FILE_PATH_LITERAL("/whatever"));
1149 fetcher
->set_url(test_url
);
1150 fetcher
->set_status(net::URLRequestStatus());
1151 fetcher
->set_response_code(200);
1152 fetcher
->SetResponseFilePath(extension_file_path
);
1153 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
1156 // Verify installation would proceed as normal.
1157 EXPECT_EQ(id
, service
->extension_id());
1158 base::FilePath tmpfile_path
= service
->install_path();
1159 EXPECT_FALSE(tmpfile_path
.empty());
1160 EXPECT_EQ(extension_file_path
, tmpfile_path
);
1164 // Two extensions are updated. If |updates_start_running| is true, the
1165 // mock extensions service has UpdateExtension(...) return true, and
1166 // the test is responsible for creating fake CrxInstallers. Otherwise,
1167 // UpdateExtension() returns false, signaling install failures.
1168 void TestMultipleExtensionDownloading(bool updates_start_running
) {
1169 net::TestURLFetcherFactory factory
;
1170 net::TestURLFetcher
* fetcher
= NULL
;
1171 ServiceForDownloadTests
service(prefs_
.get());
1172 ExtensionUpdater
updater(
1173 &service
, service
.extension_prefs(), service
.pref_service(),
1174 service
.profile(), kUpdateFrequencySecs
, NULL
);
1178 new ExtensionDownloader(&updater
, service
.request_context()));
1179 updater
.downloader_
->extensions_queue_
.set_backoff_policy(
1182 EXPECT_FALSE(updater
.crx_install_is_running_
);
1184 GURL
url1("http://localhost/extension1.crx");
1185 GURL
url2("http://localhost/extension2.crx");
1187 std::string id1
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
1188 std::string id2
= "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
1193 std::string version1
= "0.1";
1194 std::string version2
= "0.1";
1195 std::set
<int> requests
;
1197 // Start two fetches
1198 scoped_ptr
<ExtensionDownloader::ExtensionFetch
> fetch1(
1199 new ExtensionDownloader::ExtensionFetch(
1200 id1
, url1
, hash1
, version1
, requests
));
1201 scoped_ptr
<ExtensionDownloader::ExtensionFetch
> fetch2(
1202 new ExtensionDownloader::ExtensionFetch(
1203 id2
, url2
, hash2
, version2
, requests
));
1204 updater
.downloader_
->FetchUpdatedExtension(fetch1
.Pass());
1205 updater
.downloader_
->FetchUpdatedExtension(fetch2
.Pass());
1207 // Make the first fetch complete.
1208 base::FilePath
extension_file_path(FILE_PATH_LITERAL("/whatever"));
1210 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId
);
1211 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
1212 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
1214 // We need some CrxInstallers, and CrxInstallers require a real
1215 // ExtensionService. Create one on the testing profile. Any action
1216 // the CrxInstallers take is on the testing profile's extension
1217 // service, not on our mock |service|. This allows us to fake
1218 // the CrxInstaller actions we want.
1219 TestingProfile profile
;
1220 static_cast<TestExtensionSystem
*>(
1221 ExtensionSystem::Get(&profile
))->
1222 CreateExtensionService(
1223 CommandLine::ForCurrentProcess(),
1226 ExtensionService
* extension_service
=
1227 ExtensionSystem::Get(&profile
)->extension_service();
1228 extension_service
->set_extensions_enabled(true);
1229 extension_service
->set_show_extensions_prompts(false);
1231 scoped_refptr
<CrxInstaller
> fake_crx1(
1232 CrxInstaller::CreateSilent(extension_service
));
1233 scoped_refptr
<CrxInstaller
> fake_crx2(
1234 CrxInstaller::CreateSilent(extension_service
));
1236 if (updates_start_running
) {
1237 // Add fake CrxInstaller to be returned by service.UpdateExtension().
1238 service
.AddFakeCrxInstaller(id1
, fake_crx1
.get());
1239 service
.AddFakeCrxInstaller(id2
, fake_crx2
.get());
1241 // If we don't add fake CRX installers, the mock service fakes a failure
1242 // starting the install.
1245 fetcher
->set_url(url1
);
1246 fetcher
->set_status(net::URLRequestStatus());
1247 fetcher
->set_response_code(200);
1248 fetcher
->SetResponseFilePath(extension_file_path
);
1249 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
1253 // Expect that the service was asked to do an install with the right data.
1254 base::FilePath tmpfile_path
= service
.install_path();
1255 EXPECT_FALSE(tmpfile_path
.empty());
1256 EXPECT_EQ(id1
, service
.extension_id());
1259 // Make sure the second fetch finished and asked the service to do an
1261 base::FilePath
extension_file_path2(FILE_PATH_LITERAL("/whatever2"));
1262 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kExtensionFetcherId
);
1263 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
1264 EXPECT_TRUE(fetcher
->GetLoadFlags() == kExpectedLoadFlags
);
1266 fetcher
->set_url(url2
);
1267 fetcher
->set_status(net::URLRequestStatus());
1268 fetcher
->set_response_code(200);
1269 fetcher
->SetResponseFilePath(extension_file_path2
);
1270 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
1273 if (updates_start_running
) {
1274 EXPECT_TRUE(updater
.crx_install_is_running_
);
1276 // The second install should not have run, because the first has not
1277 // sent a notification that it finished.
1278 EXPECT_EQ(id1
, service
.extension_id());
1280 // Fake install notice. This should start the second installation,
1281 // which will be checked below.
1282 fake_crx1
->NotifyCrxInstallComplete(false);
1284 EXPECT_TRUE(updater
.crx_install_is_running_
);
1287 EXPECT_EQ(id2
, service
.extension_id());
1288 EXPECT_FALSE(service
.install_path().empty());
1290 // Make sure the correct crx contents were passed for the update call.
1291 EXPECT_EQ(extension_file_path2
, service
.install_path());
1293 if (updates_start_running
) {
1294 EXPECT_TRUE(updater
.crx_install_is_running_
);
1295 fake_crx2
->NotifyCrxInstallComplete(false);
1297 EXPECT_FALSE(updater
.crx_install_is_running_
);
1300 void TestGalleryRequestsWithBrand(bool use_organic_brand_code
) {
1301 google_util::BrandForTesting
brand_for_testing(
1302 use_organic_brand_code
? "GGLS" : "TEST");
1304 // We want to test a variety of combinations of expected ping conditions for
1305 // rollcall and active pings.
1306 int ping_cases
[] = { ManifestFetchData::kNeverPinged
, 0, 1, 5 };
1308 for (size_t i
= 0; i
< arraysize(ping_cases
); i
++) {
1309 for (size_t j
= 0; j
< arraysize(ping_cases
); j
++) {
1310 for (size_t k
= 0; k
< 2; k
++) {
1311 int rollcall_ping_days
= ping_cases
[i
];
1312 int active_ping_days
= ping_cases
[j
];
1313 // Skip cases where rollcall_ping_days == -1, but
1314 // active_ping_days > 0, because rollcall_ping_days == -1 means the
1315 // app was just installed and this is the first update check after
1317 if (rollcall_ping_days
== ManifestFetchData::kNeverPinged
&&
1318 active_ping_days
> 0)
1321 bool active_bit
= k
> 0;
1322 TestGalleryRequests(rollcall_ping_days
, active_ping_days
, active_bit
,
1323 !use_organic_brand_code
);
1324 ASSERT_FALSE(HasFailure()) <<
1325 " rollcall_ping_days=" << ping_cases
[i
] <<
1326 " active_ping_days=" << ping_cases
[j
] <<
1327 " active_bit=" << active_bit
;
1333 // Test requests to both a Google server and a non-google server. This allows
1334 // us to test various combinations of installed (ie roll call) and active
1335 // (ie app launch) ping scenarios. The invariant is that each type of ping
1336 // value should be present at most once per day, and can be calculated based
1337 // on the delta between now and the last ping time (or in the case of active
1338 // pings, that delta plus whether the app has been active).
1339 void TestGalleryRequests(int rollcall_ping_days
,
1340 int active_ping_days
,
1342 bool expect_brand_code
) {
1343 net::TestURLFetcherFactory factory
;
1345 // Set up 2 mock extensions, one with a google.com update url and one
1347 prefs_
.reset(new TestExtensionPrefs(base::MessageLoopProxy::current()));
1348 ServiceForManifestTests
service(prefs_
.get());
1350 GURL
url1("http://clients2.google.com/service/update2/crx");
1351 GURL
url2("http://www.somewebsite.com");
1352 service
.CreateTestExtensions(1, 1, &tmp
, &url1
.possibly_invalid_spec(),
1353 Manifest::INTERNAL
);
1354 service
.CreateTestExtensions(2, 1, &tmp
, &url2
.possibly_invalid_spec(),
1355 Manifest::INTERNAL
);
1356 EXPECT_EQ(2u, tmp
.size());
1357 service
.set_extensions(tmp
, ExtensionList());
1359 ExtensionPrefs
* prefs
= service
.extension_prefs();
1360 const std::string
& id
= tmp
[0]->id();
1361 Time now
= Time::Now();
1362 if (rollcall_ping_days
== 0) {
1363 prefs
->SetLastPingDay(id
, now
- TimeDelta::FromSeconds(15));
1364 } else if (rollcall_ping_days
> 0) {
1365 Time last_ping_day
= now
-
1366 TimeDelta::FromDays(rollcall_ping_days
) -
1367 TimeDelta::FromSeconds(15);
1368 prefs
->SetLastPingDay(id
, last_ping_day
);
1371 // Store a value for the last day we sent an active ping.
1372 if (active_ping_days
== 0) {
1373 prefs
->SetLastActivePingDay(id
, now
- TimeDelta::FromSeconds(15));
1374 } else if (active_ping_days
> 0) {
1375 Time last_active_ping_day
= now
-
1376 TimeDelta::FromDays(active_ping_days
) -
1377 TimeDelta::FromSeconds(15);
1378 prefs
->SetLastActivePingDay(id
, last_active_ping_day
);
1381 prefs
->SetActiveBit(id
, true);
1383 ExtensionUpdater
updater(
1384 &service
, service
.extension_prefs(), service
.pref_service(),
1385 service
.profile(), kUpdateFrequencySecs
, NULL
);
1386 ExtensionUpdater::CheckParams params
;
1388 updater
.CheckNow(params
);
1390 // Make the updater do manifest fetching, and note the urls it tries to
1392 std::vector
<GURL
> fetched_urls
;
1393 net::TestURLFetcher
* fetcher
=
1394 factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
1395 EXPECT_TRUE(fetcher
!= NULL
&& fetcher
->delegate() != NULL
);
1396 fetched_urls
.push_back(fetcher
->GetOriginalURL());
1398 fetcher
->set_url(fetched_urls
[0]);
1399 fetcher
->set_status(net::URLRequestStatus());
1400 fetcher
->set_response_code(500);
1401 fetcher
->SetResponseString(std::string());
1402 fetcher
->delegate()->OnURLFetchComplete(fetcher
);
1404 fetcher
= factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
1405 fetched_urls
.push_back(fetcher
->GetOriginalURL());
1407 // The urls could have been fetched in either order, so use the host to
1408 // tell them apart and note the query each used.
1409 std::string url1_query
;
1410 std::string url2_query
;
1411 if (fetched_urls
[0].host() == url1
.host()) {
1412 url1_query
= fetched_urls
[0].query();
1413 url2_query
= fetched_urls
[1].query();
1414 } else if (fetched_urls
[0].host() == url2
.host()) {
1415 url1_query
= fetched_urls
[1].query();
1416 url2_query
= fetched_urls
[0].query();
1421 // First make sure the non-google query had no ping parameter.
1422 std::string search_string
= "ping%3D";
1423 EXPECT_TRUE(url2_query
.find(search_string
) == std::string::npos
);
1425 // Now make sure the google query had the correct ping parameter.
1426 bool ping_expected
= false;
1427 bool did_rollcall
= false;
1428 if (rollcall_ping_days
!= 0) {
1429 search_string
+= "r%253D" + base::IntToString(rollcall_ping_days
);
1430 did_rollcall
= true;
1431 ping_expected
= true;
1433 if (active_bit
&& active_ping_days
!= 0) {
1435 search_string
+= "%2526";
1436 search_string
+= "a%253D" + base::IntToString(active_ping_days
);
1437 ping_expected
= true;
1439 bool ping_found
= url1_query
.find(search_string
) != std::string::npos
;
1440 EXPECT_EQ(ping_expected
, ping_found
) << "query was: " << url1_query
1441 << " was looking for " << search_string
;
1443 // Make sure the non-google query has no brand parameter.
1444 const std::string brand_string
= "brand%3D";
1445 EXPECT_TRUE(url2_query
.find(brand_string
) == std::string::npos
);
1447 #if defined(GOOGLE_CHROME_BUILD)
1448 // Make sure the google query has a brand parameter, but only if the
1449 // brand is non-organic.
1450 if (expect_brand_code
) {
1451 EXPECT_TRUE(url1_query
.find(brand_string
) != std::string::npos
);
1453 EXPECT_TRUE(url1_query
.find(brand_string
) == std::string::npos
);
1456 // Chromium builds never add the brand to the parameter, even for google
1458 EXPECT_TRUE(url1_query
.find(brand_string
) == std::string::npos
);
1464 // This makes sure that the extension updater properly stores the results
1465 // of a <daystart> tag from a manifest fetch in one of two cases: 1) This is
1466 // the first time we fetched the extension, or 2) We sent a ping value of
1467 // >= 1 day for the extension.
1468 void TestHandleManifestResults() {
1469 ServiceForManifestTests
service(prefs_
.get());
1470 GURL
update_url("http://www.google.com/manifest");
1472 service
.CreateTestExtensions(1, 1, &tmp
, &update_url
.spec(),
1473 Manifest::INTERNAL
);
1474 service
.set_extensions(tmp
, ExtensionList());
1476 ExtensionUpdater
updater(
1477 &service
, service
.extension_prefs(), service
.pref_service(),
1478 service
.profile(), kUpdateFrequencySecs
, NULL
);
1482 new ExtensionDownloader(&updater
, service
.request_context()));
1484 ManifestFetchData
fetch_data(update_url
, 0);
1485 const Extension
* extension
= tmp
[0].get();
1486 fetch_data
.AddExtension(extension
->id(),
1487 extension
->VersionString(),
1489 kEmptyUpdateUrlData
,
1491 UpdateManifest::Results results
;
1492 results
.daystart_elapsed_seconds
= 750;
1494 updater
.downloader_
->HandleManifestResults(fetch_data
, &results
);
1495 Time last_ping_day
=
1496 service
.extension_prefs()->LastPingDay(extension
->id());
1497 EXPECT_FALSE(last_ping_day
.is_null());
1498 int64 seconds_diff
= (Time::Now() - last_ping_day
).InSeconds();
1499 EXPECT_LT(seconds_diff
- results
.daystart_elapsed_seconds
, 5);
1503 scoped_ptr
<TestExtensionPrefs
> prefs_
;
1506 content::TestBrowserThreadBundle thread_bundle_
;
1507 content::InProcessUtilityThreadHelper in_process_utility_thread_helper_
;
1509 #if defined OS_CHROMEOS
1510 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_
;
1511 chromeos::ScopedTestCrosSettings test_cros_settings_
;
1512 chromeos::ScopedTestUserManager test_user_manager_
;
1516 // Because we test some private methods of ExtensionUpdater, it's easier for the
1517 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F
1518 // subclasses where friendship with ExtenionUpdater is not inherited.
1520 TEST_F(ExtensionUpdaterTest
, TestExtensionUpdateCheckRequests
) {
1521 TestExtensionUpdateCheckRequests(false);
1524 TEST_F(ExtensionUpdaterTest
, TestExtensionUpdateCheckRequestsPending
) {
1525 TestExtensionUpdateCheckRequests(true);
1528 TEST_F(ExtensionUpdaterTest
, TestUpdateUrlData
) {
1529 TestUpdateUrlDataEmpty();
1530 TestUpdateUrlDataSimple();
1531 TestUpdateUrlDataCompound();
1532 TestUpdateUrlDataFromGallery(
1533 extension_urls::GetWebstoreUpdateUrl().spec());
1536 TEST_F(ExtensionUpdaterTest
, TestInstallSource
) {
1537 TestInstallSource();
1540 TEST_F(ExtensionUpdaterTest
, TestDetermineUpdates
) {
1541 TestDetermineUpdates();
1544 TEST_F(ExtensionUpdaterTest
, TestDetermineUpdatesPending
) {
1545 TestDetermineUpdatesPending();
1548 #if defined(THREAD_SANITIZER) || defined(MEMORY_SANITIZER)
1549 // This test fails under ThreadSanitizer and MemorySanitizer, which build with
1550 // libc++ instead of libstdc++.
1551 #define MAYBE_TestMultipleManifestDownloading \
1552 DISABLED_TestMultipleManifestDownloading
1554 #define MAYBE_TestMultipleManifestDownloading TestMultipleManifestDownloading
1556 TEST_F(ExtensionUpdaterTest
, MAYBE_TestMultipleManifestDownloading
) {
1557 TestMultipleManifestDownloading();
1560 TEST_F(ExtensionUpdaterTest
, TestSingleExtensionDownloading
) {
1561 TestSingleExtensionDownloading(false, false, false);
1564 TEST_F(ExtensionUpdaterTest
, TestSingleExtensionDownloadingPending
) {
1565 TestSingleExtensionDownloading(true, false, false);
1568 TEST_F(ExtensionUpdaterTest
, TestSingleExtensionDownloadingWithRetry
) {
1569 TestSingleExtensionDownloading(false, true, false);
1572 TEST_F(ExtensionUpdaterTest
, TestSingleExtensionDownloadingPendingWithRetry
) {
1573 TestSingleExtensionDownloading(true, true, false);
1576 TEST_F(ExtensionUpdaterTest
, TestSingleExtensionDownloadingFailure
) {
1577 TestSingleExtensionDownloading(false, false, true);
1580 TEST_F(ExtensionUpdaterTest
, TestSingleExtensionDownloadingFailureWithRetry
) {
1581 TestSingleExtensionDownloading(false, true, true);
1584 TEST_F(ExtensionUpdaterTest
, TestSingleExtensionDownloadingFailurePending
) {
1585 TestSingleExtensionDownloading(true, false, true);
1588 TEST_F(ExtensionUpdaterTest
, TestSingleProtectedExtensionDownloading
) {
1589 TestSingleProtectedExtensionDownloading(true, false);
1592 TEST_F(ExtensionUpdaterTest
, TestSingleProtectedExtensionDownloadingFailure
) {
1593 TestSingleProtectedExtensionDownloading(true, true);
1596 TEST_F(ExtensionUpdaterTest
, TestSingleProtectedExtensionDownloadingNoHTTPS
) {
1597 TestSingleProtectedExtensionDownloading(false, false);
1600 TEST_F(ExtensionUpdaterTest
, TestMultipleExtensionDownloadingUpdatesFail
) {
1601 TestMultipleExtensionDownloading(false);
1603 TEST_F(ExtensionUpdaterTest
, TestMultipleExtensionDownloadingUpdatesSucceed
) {
1604 TestMultipleExtensionDownloading(true);
1607 TEST_F(ExtensionUpdaterTest
, TestManifestRetryDownloading
) {
1608 TestManifestRetryDownloading();
1611 TEST_F(ExtensionUpdaterTest
, TestGalleryRequestsWithOrganicBrand
) {
1612 TestGalleryRequestsWithBrand(true);
1615 TEST_F(ExtensionUpdaterTest
, TestGalleryRequestsWithNonOrganicBrand
) {
1616 TestGalleryRequestsWithBrand(false);
1619 TEST_F(ExtensionUpdaterTest
, TestHandleManifestResults
) {
1620 TestHandleManifestResults();
1623 TEST_F(ExtensionUpdaterTest
, TestNonAutoUpdateableLocations
) {
1624 net::TestURLFetcherFactory factory
;
1625 ServiceForManifestTests
service(prefs_
.get());
1626 ExtensionUpdater
updater(&service
, service
.extension_prefs(),
1627 service
.pref_service(), service
.profile(),
1628 kUpdateFrequencySecs
, NULL
);
1629 MockExtensionDownloaderDelegate delegate
;
1630 // Set the downloader directly, so that all its events end up in the mock
1632 ExtensionDownloader
* downloader
=
1633 new ExtensionDownloader(&delegate
, service
.request_context());
1634 ResetDownloader(&updater
, downloader
);
1636 // Non-internal non-external extensions should be rejected.
1637 ExtensionList extensions
;
1638 service
.CreateTestExtensions(1, 1, &extensions
, NULL
,
1639 Manifest::INVALID_LOCATION
);
1640 service
.CreateTestExtensions(2, 1, &extensions
, NULL
, Manifest::INTERNAL
);
1641 ASSERT_EQ(2u, extensions
.size());
1642 const std::string
& updateable_id
= extensions
[1]->id();
1644 // These expectations fail if the delegate's methods are invoked for the
1645 // first extension, which has a non-matching id.
1646 EXPECT_CALL(delegate
, GetUpdateUrlData(updateable_id
)).WillOnce(Return(""));
1647 EXPECT_CALL(delegate
, GetPingDataForExtension(updateable_id
, _
));
1649 service
.set_extensions(extensions
, ExtensionList());
1650 ExtensionUpdater::CheckParams params
;
1652 updater
.CheckNow(params
);
1655 TEST_F(ExtensionUpdaterTest
, TestUpdatingDisabledExtensions
) {
1656 net::TestURLFetcherFactory factory
;
1657 ServiceForManifestTests
service(prefs_
.get());
1658 ExtensionUpdater
updater(&service
, service
.extension_prefs(),
1659 service
.pref_service(), service
.profile(),
1660 kUpdateFrequencySecs
, NULL
);
1661 MockExtensionDownloaderDelegate delegate
;
1662 // Set the downloader directly, so that all its events end up in the mock
1664 ExtensionDownloader
* downloader
=
1665 new ExtensionDownloader(&delegate
, service
.request_context());
1666 ResetDownloader(&updater
, downloader
);
1668 // Non-internal non-external extensions should be rejected.
1669 ExtensionList enabled_extensions
;
1670 ExtensionList disabled_extensions
;
1671 service
.CreateTestExtensions(1, 1, &enabled_extensions
, NULL
,
1672 Manifest::INTERNAL
);
1673 service
.CreateTestExtensions(2, 1, &disabled_extensions
, NULL
,
1674 Manifest::INTERNAL
);
1675 ASSERT_EQ(1u, enabled_extensions
.size());
1676 ASSERT_EQ(1u, disabled_extensions
.size());
1677 const std::string
& enabled_id
= enabled_extensions
[0]->id();
1678 const std::string
& disabled_id
= disabled_extensions
[0]->id();
1680 // We expect that both enabled and disabled extensions are auto-updated.
1681 EXPECT_CALL(delegate
, GetUpdateUrlData(enabled_id
)).WillOnce(Return(""));
1682 EXPECT_CALL(delegate
, GetPingDataForExtension(enabled_id
, _
));
1683 EXPECT_CALL(delegate
, GetUpdateUrlData(disabled_id
)).WillOnce(Return(""));
1684 EXPECT_CALL(delegate
, GetPingDataForExtension(disabled_id
, _
));
1686 service
.set_extensions(enabled_extensions
, disabled_extensions
);
1687 ExtensionUpdater::CheckParams params
;
1689 updater
.CheckNow(params
);
1692 TEST_F(ExtensionUpdaterTest
, TestManifestFetchesBuilderAddExtension
) {
1693 net::TestURLFetcherFactory factory
;
1694 MockService
service(prefs_
.get());
1695 MockExtensionDownloaderDelegate delegate
;
1696 scoped_ptr
<ExtensionDownloader
> downloader(
1697 new ExtensionDownloader(&delegate
, service
.request_context()));
1698 EXPECT_EQ(0u, ManifestFetchersCount(downloader
.get()));
1700 // First, verify that adding valid extensions does invoke the callbacks on
1702 std::string id
= id_util::GenerateId("foo");
1703 EXPECT_CALL(delegate
, GetPingDataForExtension(id
, _
)).WillOnce(Return(false));
1705 downloader
->AddPendingExtension(id
, GURL("http://example.com/update"),
1707 downloader
->StartAllPending(NULL
);
1708 Mock::VerifyAndClearExpectations(&delegate
);
1709 EXPECT_EQ(1u, ManifestFetchersCount(downloader
.get()));
1711 // Extensions with invalid update URLs should be rejected.
1712 id
= id_util::GenerateId("foo2");
1714 downloader
->AddPendingExtension(id
, GURL("http:google.com:foo"), 0));
1715 downloader
->StartAllPending(NULL
);
1716 EXPECT_EQ(1u, ManifestFetchersCount(downloader
.get()));
1718 // Extensions with empty IDs should be rejected.
1719 EXPECT_FALSE(downloader
->AddPendingExtension(std::string(), GURL(), 0));
1720 downloader
->StartAllPending(NULL
);
1721 EXPECT_EQ(1u, ManifestFetchersCount(downloader
.get()));
1723 // TODO(akalin): Test that extensions with empty update URLs
1724 // converted from user scripts are rejected.
1726 // Reset the ExtensionDownloader so that it drops the current fetcher.
1728 new ExtensionDownloader(&delegate
, service
.request_context()));
1729 EXPECT_EQ(0u, ManifestFetchersCount(downloader
.get()));
1731 // Extensions with empty update URLs should have a default one
1733 id
= id_util::GenerateId("foo3");
1734 EXPECT_CALL(delegate
, GetPingDataForExtension(id
, _
)).WillOnce(Return(false));
1735 EXPECT_TRUE(downloader
->AddPendingExtension(id
, GURL(), 0));
1736 downloader
->StartAllPending(NULL
);
1737 EXPECT_EQ(1u, ManifestFetchersCount(downloader
.get()));
1739 net::TestURLFetcher
* fetcher
=
1740 factory
.GetFetcherByID(ExtensionDownloader::kManifestFetcherId
);
1741 ASSERT_TRUE(fetcher
);
1742 EXPECT_FALSE(fetcher
->GetOriginalURL().is_empty());
1745 TEST_F(ExtensionUpdaterTest
, TestStartUpdateCheckMemory
) {
1746 net::TestURLFetcherFactory factory
;
1747 MockService
service(prefs_
.get());
1748 MockExtensionDownloaderDelegate delegate
;
1749 ExtensionDownloader
downloader(&delegate
, service
.request_context());
1751 StartUpdateCheck(&downloader
, new ManifestFetchData(GURL(), 0));
1752 // This should delete the newly-created ManifestFetchData.
1753 StartUpdateCheck(&downloader
, new ManifestFetchData(GURL(), 0));
1754 // This should add into |manifests_pending_|.
1755 StartUpdateCheck(&downloader
, new ManifestFetchData(GURL(
1756 GURL("http://www.google.com")), 0));
1757 // The dtor of |downloader| should delete the pending fetchers.
1760 TEST_F(ExtensionUpdaterTest
, TestCheckSoon
) {
1761 ServiceForManifestTests
service(prefs_
.get());
1762 net::TestURLFetcherFactory factory
;
1763 ExtensionUpdater
updater(
1764 &service
, service
.extension_prefs(), service
.pref_service(),
1765 service
.profile(), kUpdateFrequencySecs
, NULL
);
1766 EXPECT_FALSE(updater
.WillCheckSoon());
1768 EXPECT_FALSE(updater
.WillCheckSoon());
1769 updater
.CheckSoon();
1770 EXPECT_TRUE(updater
.WillCheckSoon());
1771 updater
.CheckSoon();
1772 EXPECT_TRUE(updater
.WillCheckSoon());
1774 EXPECT_FALSE(updater
.WillCheckSoon());
1775 updater
.CheckSoon();
1776 EXPECT_TRUE(updater
.WillCheckSoon());
1778 EXPECT_FALSE(updater
.WillCheckSoon());
1781 // TODO(asargent) - (http://crbug.com/12780) add tests for:
1782 // -prodversionmin (shouldn't update if browser version too old)
1783 // -manifests & updates arriving out of order / interleaved
1784 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1785 // -An extension gets uninstalled while updates are in progress (so it doesn't
1786 // "come back from the dead")
1787 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1788 // you don't get downgraded accidentally)
1789 // -An update manifest mentions multiple updates
1791 } // namespace extensions