Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: chrome/browser/extensions/updater/extension_updater_unittest.cc

Issue 17127002: Correctly integrate StoragePartition into TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments. merge to ToT. Murder a DB thread and more TestBrowserThreads. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <list> 5 #include <list>
6 #include <map> 6 #include <map>
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "chrome/common/extensions/extension.h" 43 #include "chrome/common/extensions/extension.h"
44 #include "chrome/common/extensions/extension_manifest_constants.h" 44 #include "chrome/common/extensions/extension_manifest_constants.h"
45 #include "chrome/common/omaha_query_params/omaha_query_params.h" 45 #include "chrome/common/omaha_query_params/omaha_query_params.h"
46 #include "chrome/common/pref_names.h" 46 #include "chrome/common/pref_names.h"
47 #include "chrome/test/base/testing_profile.h" 47 #include "chrome/test/base/testing_profile.h"
48 #include "content/public/browser/notification_details.h" 48 #include "content/public/browser/notification_details.h"
49 #include "content/public/browser/notification_observer.h" 49 #include "content/public/browser/notification_observer.h"
50 #include "content/public/browser/notification_registrar.h" 50 #include "content/public/browser/notification_registrar.h"
51 #include "content/public/browser/notification_service.h" 51 #include "content/public/browser/notification_service.h"
52 #include "content/public/browser/notification_source.h" 52 #include "content/public/browser/notification_source.h"
53 #include "content/public/test/test_browser_thread.h" 53 #include "content/public/test/test_browser_thread_bundle.h"
54 #include "extensions/common/id_util.h" 54 #include "extensions/common/id_util.h"
55 #include "libxml/globals.h" 55 #include "libxml/globals.h"
56 #include "net/base/backoff_entry.h" 56 #include "net/base/backoff_entry.h"
57 #include "net/base/escape.h" 57 #include "net/base/escape.h"
58 #include "net/base/load_flags.h" 58 #include "net/base/load_flags.h"
59 #include "net/url_request/test_url_fetcher_factory.h" 59 #include "net/url_request/test_url_fetcher_factory.h"
60 #include "net/url_request/url_request_status.h" 60 #include "net/url_request/url_request_status.h"
61 #include "testing/gmock/include/gmock/gmock.h" 61 #include "testing/gmock/include/gmock/gmock.h"
62 #include "testing/gtest/include/gtest/gtest.h" 62 #include "testing/gtest/include/gtest/gtest.h"
63 63
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 } // namespace 204 } // namespace
205 205
206 // Base class for further specialized test classes. 206 // Base class for further specialized test classes.
207 class MockService : public TestExtensionService { 207 class MockService : public TestExtensionService {
208 public: 208 public:
209 explicit MockService(TestExtensionPrefs* prefs) 209 explicit MockService(TestExtensionPrefs* prefs)
210 : prefs_(prefs), 210 : prefs_(prefs),
211 pending_extension_manager_(*this), 211 pending_extension_manager_(*this),
212 blacklist_(prefs_->prefs()) { 212 blacklist_(prefs_->prefs()) {
213 profile_.CreateRequestContext();
214 } 213 }
215 214
216 virtual ~MockService() {} 215 virtual ~MockService() {}
217 216
218 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE { 217 virtual PendingExtensionManager* pending_extension_manager() OVERRIDE {
219 ADD_FAILURE() << "Subclass should override this if it will " 218 ADD_FAILURE() << "Subclass should override this if it will "
220 << "be accessed by a test."; 219 << "be accessed by a test.";
221 return &pending_extension_manager_; 220 return &pending_extension_manager_;
222 } 221 }
223 222
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 EXPECT_EQ(1U, params.count("x")); 460 EXPECT_EQ(1U, params.count("x"));
462 std::string decoded = net::UnescapeURLComponent( 461 std::string decoded = net::UnescapeURLComponent(
463 params["x"], net::UnescapeRule::URL_SPECIAL_CHARS); 462 params["x"], net::UnescapeRule::URL_SPECIAL_CHARS);
464 ExtractParameters(decoded, result); 463 ExtractParameters(decoded, result);
465 } 464 }
466 465
467 // All of our tests that need to use private APIs of ExtensionUpdater live 466 // All of our tests that need to use private APIs of ExtensionUpdater live
468 // inside this class (which is a friend to ExtensionUpdater). 467 // inside this class (which is a friend to ExtensionUpdater).
469 class ExtensionUpdaterTest : public testing::Test { 468 class ExtensionUpdaterTest : public testing::Test {
470 public: 469 public:
471 ExtensionUpdaterTest()
472 : ui_thread_(BrowserThread::UI, &loop_),
473 file_thread_(BrowserThread::FILE, &loop_),
474 io_thread_(BrowserThread::IO, &loop_) {
475 }
476
477 virtual ~ExtensionUpdaterTest() {
478 }
479
480 virtual void SetUp() OVERRIDE { 470 virtual void SetUp() OVERRIDE {
481 prefs_.reset(new TestExtensionPrefs(loop_.message_loop_proxy().get())); 471 prefs_.reset(new TestExtensionPrefs(base::MessageLoopProxy::current()));
482 } 472 }
483 473
484 virtual void TearDown() OVERRIDE { 474 virtual void TearDown() OVERRIDE {
485 // Some tests create URLRequestContextGetters, whose destruction must run 475 // Some tests create URLRequestContextGetters, whose destruction must run
486 // on the IO thread. Make sure the IO loop spins before shutdown so that 476 // on the IO thread. Make sure the IO loop spins before shutdown so that
487 // those objects are released. 477 // those objects are released.
488 RunUntilIdle(); 478 RunUntilIdle();
489 prefs_.reset(); 479 prefs_.reset();
490 } 480 }
491 481
492 void RunUntilIdle() { 482 void RunUntilIdle() {
493 prefs_->pref_service()->CommitPendingWrite(); 483 prefs_->pref_service()->CommitPendingWrite();
494 loop_.RunUntilIdle(); 484 base::RunLoop().RunUntilIdle();
495 } 485 }
496 486
497 void SimulateTimerFired(ExtensionUpdater* updater) { 487 void SimulateTimerFired(ExtensionUpdater* updater) {
498 EXPECT_TRUE(updater->timer_.IsRunning()); 488 EXPECT_TRUE(updater->timer_.IsRunning());
499 updater->timer_.Stop(); 489 updater->timer_.Stop();
500 updater->TimerFired(); 490 updater->TimerFired();
501 } 491 }
502 492
503 // Adds a Result with the given data to results. 493 // Adds a Result with the given data to results.
504 void AddParseResult(const std::string& id, 494 void AddParseResult(const std::string& id,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 kEmptyUpdateUrlData, install_source); 704 kEmptyUpdateUrlData, install_source);
715 std::map<std::string, std::string> params; 705 std::map<std::string, std::string> params;
716 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params); 706 VerifyQueryAndExtractParameters(fetch_data.full_url().query(), &params);
717 EXPECT_EQ(id, params["id"]); 707 EXPECT_EQ(id, params["id"]);
718 EXPECT_EQ(version, params["v"]); 708 EXPECT_EQ(version, params["v"]);
719 EXPECT_EQ(install_source, params["installsource"]); 709 EXPECT_EQ(install_source, params["installsource"]);
720 } 710 }
721 711
722 void TestDetermineUpdates() { 712 void TestDetermineUpdates() {
723 TestingProfile profile; 713 TestingProfile profile;
724 profile.CreateRequestContext();
725 MockExtensionDownloaderDelegate delegate; 714 MockExtensionDownloaderDelegate delegate;
726 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 715 ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
727 716
728 // Check passing an empty list of parse results to DetermineUpdates 717 // Check passing an empty list of parse results to DetermineUpdates
729 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 718 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
730 UpdateManifest::Results updates; 719 UpdateManifest::Results updates;
731 std::vector<int> updateable; 720 std::vector<int> updateable;
732 downloader.DetermineUpdates(fetch_data, updates, &updateable); 721 downloader.DetermineUpdates(fetch_data, updates, &updateable);
733 EXPECT_TRUE(updateable.empty()); 722 EXPECT_TRUE(updateable.empty());
734 723
(...skipping 23 matching lines...) Expand all
758 } 747 }
759 748
760 void TestDetermineUpdatesPending() { 749 void TestDetermineUpdatesPending() {
761 // Create a set of test extensions 750 // Create a set of test extensions
762 ServiceForManifestTests service(prefs_.get()); 751 ServiceForManifestTests service(prefs_.get());
763 PendingExtensionManager* pending_extension_manager = 752 PendingExtensionManager* pending_extension_manager =
764 service.pending_extension_manager(); 753 service.pending_extension_manager();
765 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager); 754 SetupPendingExtensionManagerForTest(3, GURL(), pending_extension_manager);
766 755
767 TestingProfile profile; 756 TestingProfile profile;
768 profile.CreateRequestContext();
769 MockExtensionDownloaderDelegate delegate; 757 MockExtensionDownloaderDelegate delegate;
770 ExtensionDownloader downloader(&delegate, profile.GetRequestContext()); 758 ExtensionDownloader downloader(&delegate, profile.GetRequestContext());
771 759
772 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0); 760 ManifestFetchData fetch_data(GURL("http://localhost/foo"), 0);
773 UpdateManifest::Results updates; 761 UpdateManifest::Results updates;
774 762
775 std::list<std::string> ids_for_update_check; 763 std::list<std::string> ids_for_update_check;
776 pending_extension_manager->GetPendingIdsForUpdateCheck( 764 pending_extension_manager->GetPendingIdsForUpdateCheck(
777 &ids_for_update_check); 765 &ids_for_update_check);
778 766
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 // on the delta between now and the last ping time (or in the case of active 1289 // on the delta between now and the last ping time (or in the case of active
1302 // pings, that delta plus whether the app has been active). 1290 // pings, that delta plus whether the app has been active).
1303 void TestGalleryRequests(int rollcall_ping_days, 1291 void TestGalleryRequests(int rollcall_ping_days,
1304 int active_ping_days, 1292 int active_ping_days,
1305 bool active_bit, 1293 bool active_bit,
1306 bool expect_brand_code) { 1294 bool expect_brand_code) {
1307 net::TestURLFetcherFactory factory; 1295 net::TestURLFetcherFactory factory;
1308 1296
1309 // Set up 2 mock extensions, one with a google.com update url and one 1297 // Set up 2 mock extensions, one with a google.com update url and one
1310 // without. 1298 // without.
1311 prefs_.reset(new TestExtensionPrefs(loop_.message_loop_proxy().get())); 1299 prefs_.reset(new TestExtensionPrefs(base::MessageLoopProxy::current()));
1312 ServiceForManifestTests service(prefs_.get()); 1300 ServiceForManifestTests service(prefs_.get());
1313 ExtensionList tmp; 1301 ExtensionList tmp;
1314 GURL url1("http://clients2.google.com/service/update2/crx"); 1302 GURL url1("http://clients2.google.com/service/update2/crx");
1315 GURL url2("http://www.somewebsite.com"); 1303 GURL url2("http://www.somewebsite.com");
1316 service.CreateTestExtensions(1, 1, &tmp, &url1.possibly_invalid_spec(), 1304 service.CreateTestExtensions(1, 1, &tmp, &url1.possibly_invalid_spec(),
1317 Manifest::INTERNAL); 1305 Manifest::INTERNAL);
1318 service.CreateTestExtensions(2, 1, &tmp, &url2.possibly_invalid_spec(), 1306 service.CreateTestExtensions(2, 1, &tmp, &url2.possibly_invalid_spec(),
1319 Manifest::INTERNAL); 1307 Manifest::INTERNAL);
1320 EXPECT_EQ(2u, tmp.size()); 1308 EXPECT_EQ(2u, tmp.size());
1321 service.set_extensions(tmp); 1309 service.set_extensions(tmp);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 service.extension_prefs()->LastPingDay(extension->id()); 1449 service.extension_prefs()->LastPingDay(extension->id());
1462 EXPECT_FALSE(last_ping_day.is_null()); 1450 EXPECT_FALSE(last_ping_day.is_null());
1463 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds(); 1451 int64 seconds_diff = (Time::Now() - last_ping_day).InSeconds();
1464 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5); 1452 EXPECT_LT(seconds_diff - results.daystart_elapsed_seconds, 5);
1465 } 1453 }
1466 1454
1467 protected: 1455 protected:
1468 scoped_ptr<TestExtensionPrefs> prefs_; 1456 scoped_ptr<TestExtensionPrefs> prefs_;
1469 1457
1470 private: 1458 private:
1471 base::MessageLoop loop_; 1459 content::TestBrowserThreadBundle thread_bundle_;
1472 content::TestBrowserThread ui_thread_;
1473 content::TestBrowserThread file_thread_;
1474 content::TestBrowserThread io_thread_;
1475 1460
1476 #if defined OS_CHROMEOS 1461 #if defined OS_CHROMEOS
1477 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 1462 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
1478 chromeos::ScopedTestCrosSettings test_cros_settings_; 1463 chromeos::ScopedTestCrosSettings test_cros_settings_;
1479 chromeos::ScopedTestUserManager test_user_manager_; 1464 chromeos::ScopedTestUserManager test_user_manager_;
1480 #endif 1465 #endif
1481 }; 1466 };
1482 1467
1483 // Because we test some private methods of ExtensionUpdater, it's easier for the 1468 // Because we test some private methods of ExtensionUpdater, it's easier for the
1484 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F 1469 // actual test code to live in ExtenionUpdaterTest methods instead of TEST_F
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 // -prodversionmin (shouldn't update if browser version too old) 1713 // -prodversionmin (shouldn't update if browser version too old)
1729 // -manifests & updates arriving out of order / interleaved 1714 // -manifests & updates arriving out of order / interleaved
1730 // -malformed update url (empty, file://, has query, has a # fragment, etc.) 1715 // -malformed update url (empty, file://, has query, has a # fragment, etc.)
1731 // -An extension gets uninstalled while updates are in progress (so it doesn't 1716 // -An extension gets uninstalled while updates are in progress (so it doesn't
1732 // "come back from the dead") 1717 // "come back from the dead")
1733 // -An extension gets manually updated to v3 while we're downloading v2 (ie 1718 // -An extension gets manually updated to v3 while we're downloading v2 (ie
1734 // you don't get downgraded accidentally) 1719 // you don't get downgraded accidentally)
1735 // -An update manifest mentions multiple updates 1720 // -An update manifest mentions multiple updates
1736 1721
1737 } // namespace extensions 1722 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698