diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-11 20:44:42 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-11 20:44:42 +0000 |
commit | 5322a7f16a374a15fe69b3bb2621678aede48bca (patch) | |
tree | 56c8ee955ed32cd69f8b3395cb609dcdd504e58c | |
parent | 192a05f2e4d8f66d095227439d4dce7bb14b16b5 (diff) | |
download | chromium_src-5322a7f16a374a15fe69b3bb2621678aede48bca.zip chromium_src-5322a7f16a374a15fe69b3bb2621678aede48bca.tar.gz chromium_src-5322a7f16a374a15fe69b3bb2621678aede48bca.tar.bz2 |
Continuing with the out-of-lining of test code.
BUG=none
TEST=compiles
Review URL: http://codereview.chromium.org/6485015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74660 0039d316-1c4b-4281-b951-d872f2087c98
28 files changed, 682 insertions, 476 deletions
diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc index 8ff88e8..744c142 100644 --- a/chrome/browser/extensions/extension_apitest.cc +++ b/chrome/browser/extensions/extension_apitest.cc @@ -19,6 +19,10 @@ const char kTestServerPort[] = "testServer.port"; }; // namespace +ExtensionApiTest::ExtensionApiTest() {} + +ExtensionApiTest::~ExtensionApiTest() {} + ExtensionApiTest::ResultCatcher::ResultCatcher() : profile_restriction_(NULL), waiting_(false) { diff --git a/chrome/browser/extensions/extension_apitest.h b/chrome/browser/extensions/extension_apitest.h index f3176b5..e7d2af6 100644 --- a/chrome/browser/extensions/extension_apitest.h +++ b/chrome/browser/extensions/extension_apitest.h @@ -25,6 +25,10 @@ class Extension; // TODO(erikkay): There should also be a way to drive events in these tests. class ExtensionApiTest : public ExtensionBrowserTest { + public: + ExtensionApiTest(); + virtual ~ExtensionApiTest(); + protected: // Helper class that observes tests failing or passing. Observation starts // when the class is constructed. Get the next result by calling diff --git a/chrome/browser/net/gaia/token_service_unittest.cc b/chrome/browser/net/gaia/token_service_unittest.cc index d06956f..8650442 100644 --- a/chrome/browser/net/gaia/token_service_unittest.cc +++ b/chrome/browser/net/gaia/token_service_unittest.cc @@ -7,11 +7,68 @@ #include "chrome/browser/net/gaia/token_service_unittest.h" #include "base/command_line.h" +#include "chrome/browser/password_manager/encryptor.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h" #include "chrome/common/net/gaia/gaia_constants.h" #include "chrome/common/net/test_url_fetcher_factory.h" +TokenServiceTestHarness::TokenServiceTestHarness() + : ui_thread_(BrowserThread::UI, &message_loop_), + db_thread_(BrowserThread::DB) { +} + +TokenServiceTestHarness::~TokenServiceTestHarness() {} + +void TokenServiceTestHarness::SetUp() { +#if defined(OS_MACOSX) + Encryptor::UseMockKeychain(true); +#endif + credentials_.sid = "sid"; + credentials_.lsid = "lsid"; + credentials_.token = "token"; + credentials_.data = "data"; + + ASSERT_TRUE(db_thread_.Start()); + + profile_.reset(new TestingProfile()); + profile_->CreateWebDataService(false); + WaitForDBLoadCompletion(); + + success_tracker_.ListenFor(NotificationType::TOKEN_AVAILABLE, + Source<TokenService>(&service_)); + failure_tracker_.ListenFor(NotificationType::TOKEN_REQUEST_FAILED, + Source<TokenService>(&service_)); + + service_.Initialize("test", profile_.get()); + + URLFetcher::set_factory(NULL); +} + +void TokenServiceTestHarness::TearDown() { + // You have to destroy the profile before the db_thread_ stops. + if (profile_.get()) { + profile_.reset(NULL); + } + + db_thread_.Stop(); + MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); + MessageLoop::current()->Run(); +} + +void TokenServiceTestHarness::WaitForDBLoadCompletion() { + // The WebDB does all work on the DB thread. This will add an event + // to the end of the DB thread, so when we reach this task, all DB + // operations should be complete. + WaitableEvent done(false, false); + BrowserThread::PostTask( + BrowserThread::DB, FROM_HERE, new SignalingTask(&done)); + done.Wait(); + + // Notifications should be returned from the DB thread onto the UI thread. + message_loop_.RunAllPending(); +} + class TokenServiceTest : public TokenServiceTestHarness { public: virtual void SetUp() { diff --git a/chrome/browser/net/gaia/token_service_unittest.h b/chrome/browser/net/gaia/token_service_unittest.h index 46cffb0c..9481d22 100644 --- a/chrome/browser/net/gaia/token_service_unittest.h +++ b/chrome/browser/net/gaia/token_service_unittest.h @@ -9,7 +9,6 @@ #pragma once #include "chrome/browser/net/gaia/token_service.h" -#include "chrome/browser/password_manager/encryptor.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/common/net/gaia/gaia_auth_consumer.h" #include "chrome/common/notification_details.h" @@ -64,59 +63,14 @@ class TokenFailedTracker : public TestNotificationTracker { class TokenServiceTestHarness : public testing::Test { public: - TokenServiceTestHarness() - : ui_thread_(BrowserThread::UI, &message_loop_), - db_thread_(BrowserThread::DB) { - } - - virtual void SetUp() { -#if defined(OS_MACOSX) - Encryptor::UseMockKeychain(true); -#endif - credentials_.sid = "sid"; - credentials_.lsid = "lsid"; - credentials_.token = "token"; - credentials_.data = "data"; - - ASSERT_TRUE(db_thread_.Start()); - - profile_.reset(new TestingProfile()); - profile_->CreateWebDataService(false); - WaitForDBLoadCompletion(); - - success_tracker_.ListenFor(NotificationType::TOKEN_AVAILABLE, - Source<TokenService>(&service_)); - failure_tracker_.ListenFor(NotificationType::TOKEN_REQUEST_FAILED, - Source<TokenService>(&service_)); - - service_.Initialize("test", profile_.get()); + TokenServiceTestHarness(); + virtual ~TokenServiceTestHarness(); - URLFetcher::set_factory(NULL); - } - - virtual void TearDown() { - // You have to destroy the profile before the db_thread_ stops. - if (profile_.get()) { - profile_.reset(NULL); - } + virtual void SetUp(); - db_thread_.Stop(); - MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); - MessageLoop::current()->Run(); - } - - void WaitForDBLoadCompletion() { - // The WebDB does all work on the DB thread. This will add an event - // to the end of the DB thread, so when we reach this task, all DB - // operations should be complete. - WaitableEvent done(false, false); - BrowserThread::PostTask( - BrowserThread::DB, FROM_HERE, new SignalingTask(&done)); - done.Wait(); + virtual void TearDown(); - // Notifications should be returned from the DB thread onto the UI thread. - message_loop_.RunAllPending(); - } + void WaitForDBLoadCompletion(); MessageLoopForUI message_loop_; BrowserThread ui_thread_; // Mostly so DCHECKS pass. diff --git a/chrome/browser/notifications/desktop_notifications_unittest.cc b/chrome/browser/notifications/desktop_notifications_unittest.cc index 457b135..6effdf1 100644 --- a/chrome/browser/notifications/desktop_notifications_unittest.cc +++ b/chrome/browser/notifications/desktop_notifications_unittest.cc @@ -17,6 +17,10 @@ const int MockBalloonCollection::kMockBalloonSpace = 5; // static std::string DesktopNotificationsTest::log_output_; +MockBalloonCollection::MockBalloonCollection() {} + +MockBalloonCollection::~MockBalloonCollection() {} + void MockBalloonCollection::Add(const Notification& notification, Profile* profile) { // Swap in a logging proxy for the purpose of logging calls that diff --git a/chrome/browser/notifications/desktop_notifications_unittest.h b/chrome/browser/notifications/desktop_notifications_unittest.h index 4ddee80..25e5270 100644 --- a/chrome/browser/notifications/desktop_notifications_unittest.h +++ b/chrome/browser/notifications/desktop_notifications_unittest.h @@ -28,7 +28,8 @@ typedef LoggingNotificationDelegate<DesktopNotificationsTest> // of notifications that are added to it. class MockBalloonCollection : public BalloonCollectionImpl { public: - MockBalloonCollection() {} + MockBalloonCollection(); + virtual ~MockBalloonCollection(); // Our mock collection has an area large enough for a fixed number // of balloons. @@ -70,7 +71,7 @@ class MockBalloonCollection : public BalloonCollectionImpl { class DesktopNotificationsTest : public testing::Test { public: DesktopNotificationsTest(); - ~DesktopNotificationsTest(); + virtual ~DesktopNotificationsTest(); static void log(const std::string& message) { log_output_.append(message); diff --git a/chrome/browser/renderer_host/pepper_message_filter.cc b/chrome/browser/renderer_host/pepper_message_filter.cc index edafa05..de0793d 100644 --- a/chrome/browser/renderer_host/pepper_message_filter.cc +++ b/chrome/browser/renderer_host/pepper_message_filter.cc @@ -38,6 +38,8 @@ PepperMessageFilter::PepperMessageFilter(Profile* profile) request_context_(profile_->GetRequestContext()) { } +PepperMessageFilter::~PepperMessageFilter() {} + bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, bool* message_was_ok) { #if defined(ENABLE_FLAPPER_HACKS) diff --git a/chrome/browser/renderer_host/pepper_message_filter.h b/chrome/browser/renderer_host/pepper_message_filter.h index 0e2284d..17ccf11 100644 --- a/chrome/browser/renderer_host/pepper_message_filter.h +++ b/chrome/browser/renderer_host/pepper_message_filter.h @@ -24,6 +24,7 @@ class AddressList; class PepperMessageFilter : public BrowserMessageFilter { public: explicit PepperMessageFilter(Profile* profile); + virtual ~PepperMessageFilter(); private: // BrowserMessageFilter methods. diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 0a58aa9..b66ad08 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -161,6 +161,7 @@ 'test/testing_profile.cc', 'test/testing_profile.h', 'test/thread_observer_helper.h', + 'test/thread_test_helper.cc', 'test/thread_test_helper.h', 'test/ui_test_utils.cc', 'test/ui_test_utils.h', @@ -2985,6 +2986,7 @@ 'test/out_of_proc_test_runner.cc', 'test/live_sync/bookmark_model_verifier.cc', 'test/live_sync/bookmark_model_verifier.h', + 'test/live_sync/live_autofill_sync_test.cc', 'test/live_sync/live_autofill_sync_test.h', 'test/live_sync/live_bookmarks_sync_test.cc', 'test/live_sync/live_bookmarks_sync_test.h', diff --git a/chrome/test/live_sync/live_autofill_sync_test.cc b/chrome/test/live_sync/live_autofill_sync_test.cc new file mode 100644 index 0000000..3050a28 --- /dev/null +++ b/chrome/test/live_sync/live_autofill_sync_test.cc @@ -0,0 +1,275 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/live_sync/live_autofill_sync_test.h" + +#include "chrome/browser/autofill/autofill_common_test.h" +#include "chrome/browser/autofill/autofill_type.h" +#include "chrome/browser/autofill/autofill_profile.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/browser/sync/profile_sync_test_util.h" +#include "chrome/browser/webdata/autofill_entry.h" +#include "chrome/browser/webdata/web_database.h" +#include "chrome/test/thread_observer_helper.h" + +using base::WaitableEvent; +using testing::_; + +namespace { +class GetAllAutofillEntries + : public base::RefCountedThreadSafe<GetAllAutofillEntries> { + public: + explicit GetAllAutofillEntries(WebDataService* web_data_service) + : web_data_service_(web_data_service), + done_event_(false, false) {} + + void Init() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + BrowserThread::PostTask( + BrowserThread::DB, + FROM_HERE, + NewRunnableMethod(this, &GetAllAutofillEntries::Run)); + done_event_.Wait(); + } + + const std::vector<AutofillEntry>& entries() const { + return entries_; + } + + private: + friend class base::RefCountedThreadSafe<GetAllAutofillEntries>; + + void Run() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); + web_data_service_->GetDatabase()->GetAllAutofillEntries(&entries_); + done_event_.Signal(); + } + + WebDataService* web_data_service_; + base::WaitableEvent done_event_; + std::vector<AutofillEntry> entries_; +}; + +ACTION_P(SignalEvent, event) { + event->Signal(); +} + +class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { + protected: + virtual void RegisterObservers() { + registrar_.Add(&observer_, + NotificationType::AUTOFILL_ENTRIES_CHANGED, + NotificationService::AllSources()); + registrar_.Add(&observer_, + NotificationType::AUTOFILL_PROFILE_CHANGED, + NotificationService::AllSources()); + } +}; + +class MockPersonalDataManagerObserver : public PersonalDataManager::Observer { + public: + MOCK_METHOD0(OnPersonalDataLoaded, void()); +}; + +} // namespace + +AutoFillProfile CreateAutofillProfile(LiveAutofillSyncTest::ProfileType type) { + AutoFillProfile profile; + switch (type) { + case LiveAutofillSyncTest::PROFILE_MARION: + autofill_test::SetProfileInfoWithGuid(&profile, + "C837507A-6C3B-4872-AC14-5113F157D668", + "Marion", "Mitchell", "Morrison", + "johnwayne@me.xyz", "Fox", + "123 Zoo St.", "unit 5", "Hollywood", "CA", + "91601", "US", "12345678910", "01987654321"); + break; + case LiveAutofillSyncTest::PROFILE_HOMER: + autofill_test::SetProfileInfoWithGuid(&profile, + "137DE1C3-6A30-4571-AC86-109B1ECFBE7F", + "Homer", "J.", "Simpson", + "homer@abc.com", "SNPP", + "1 Main St", "PO Box 1", "Springfield", "MA", + "94101", "US", "14155551212", "14155551313"); + break; + case LiveAutofillSyncTest::PROFILE_FRASIER: + autofill_test::SetProfileInfoWithGuid(&profile, + "9A5E6872-6198-4688-BF75-0016E781BB0A", + "Frasier", "Winslow", "Crane", + "", "randomness", "", "Apt. 4", "Seattle", "WA", + "99121", "US", "0000000000", "ABCDEFGHIJK"); + break; + case LiveAutofillSyncTest::PROFILE_NULL: + autofill_test::SetProfileInfoWithGuid(&profile, + "FE461507-7E13-4198-8E66-74C7DB6D8322", + "", "", "", "", "", "", "", "", "", "", "", "", ""); + break; + } + return profile; +} + +LiveAutofillSyncTest::LiveAutofillSyncTest(TestType test_type) + : LiveSyncTest(test_type) {} + +LiveAutofillSyncTest::~LiveAutofillSyncTest() {} + +WebDataService* LiveAutofillSyncTest::GetWebDataService(int index) { + return GetProfile(index)->GetWebDataService(Profile::EXPLICIT_ACCESS); +} + +PersonalDataManager* LiveAutofillSyncTest::GetPersonalDataManager(int index) { + return GetProfile(index)->GetPersonalDataManager(); +} + +void LiveAutofillSyncTest::AddKeys(int profile, + const std::set<AutofillKey>& keys) { + std::vector<webkit_glue::FormField> form_fields; + for (std::set<AutofillKey>::const_iterator i = keys.begin(); + i != keys.end(); + ++i) { + form_fields.push_back(webkit_glue::FormField(string16(), + (*i).name(), + (*i).value(), + string16(), + 0, + false)); + } + + WaitableEvent done_event(false, false); + scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( + new AutofillDBThreadObserverHelper()); + observer_helper->Init(); + + EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). + WillOnce(SignalEvent(&done_event)); + WebDataService* wds = GetWebDataService(profile); + wds->AddFormFields(form_fields); + done_event.Wait(); +} + +void LiveAutofillSyncTest::RemoveKey(int profile, const AutofillKey& key) { + WaitableEvent done_event(false, false); + scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( + new AutofillDBThreadObserverHelper()); + observer_helper->Init(); + + EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). + WillOnce(SignalEvent(&done_event)); + WebDataService* wds = GetWebDataService(profile); + wds->RemoveFormValueForElementName(key.name(), key.value()); + done_event.Wait(); +} + +std::set<AutofillEntry> LiveAutofillSyncTest::GetAllKeys(int profile) { + WebDataService* wds = GetWebDataService(profile); + scoped_refptr<GetAllAutofillEntries> get_all_entries = + new GetAllAutofillEntries(wds); + get_all_entries->Init(); + const std::vector<AutofillEntry>& all_entries = get_all_entries->entries(); + std::set<AutofillEntry> all_keys; + for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); + it != all_entries.end(); ++it) { + all_keys.insert(*it); + } + return all_keys; +} + +bool LiveAutofillSyncTest::KeysMatch(int profile_a, int profile_b) { + return GetAllKeys(profile_a) == GetAllKeys(profile_b); +} + +void LiveAutofillSyncTest::SetProfiles( + int profile, std::vector<AutoFillProfile>* autofill_profiles) { + MockPersonalDataManagerObserver observer; + EXPECT_CALL(observer, OnPersonalDataLoaded()). + WillOnce(QuitUIMessageLoop()); + PersonalDataManager* pdm = GetPersonalDataManager(profile); + pdm->SetObserver(&observer); + pdm->SetProfiles(autofill_profiles); + MessageLoop::current()->Run(); + pdm->RemoveObserver(&observer); +} + +void LiveAutofillSyncTest::AddProfile(int profile, + const AutoFillProfile& autofill_profile) { + const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); + std::vector<AutoFillProfile> autofill_profiles; + for (size_t i = 0; i < all_profiles.size(); ++i) + autofill_profiles.push_back(*all_profiles[i]); + autofill_profiles.push_back(autofill_profile); + SetProfiles(profile, &autofill_profiles); +} + +void LiveAutofillSyncTest::RemoveProfile(int profile, const std::string& guid) { + const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); + std::vector<AutoFillProfile> autofill_profiles; + for (size_t i = 0; i < all_profiles.size(); ++i) { + if (all_profiles[i]->guid() != guid) + autofill_profiles.push_back(*all_profiles[i]); + } + SetProfiles(profile, &autofill_profiles); +} + +void LiveAutofillSyncTest::UpdateProfile(int profile, + const std::string& guid, + const AutoFillType& type, + const string16& value) { + const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); + std::vector<AutoFillProfile> profiles; + for (size_t i = 0; i < all_profiles.size(); ++i) { + profiles.push_back(*all_profiles[i]); + if (all_profiles[i]->guid() == guid) + profiles.back().SetInfo(type, value); + } + SetProfiles(profile, &profiles); +} + +const std::vector<AutoFillProfile*>& LiveAutofillSyncTest::GetAllProfiles( + int profile) { + MockPersonalDataManagerObserver observer; + EXPECT_CALL(observer, OnPersonalDataLoaded()). + WillOnce(QuitUIMessageLoop()); + PersonalDataManager* pdm = GetPersonalDataManager(profile); + pdm->SetObserver(&observer); + pdm->Refresh(); + MessageLoop::current()->Run(); + pdm->RemoveObserver(&observer); + return pdm->web_profiles(); +} + +bool LiveAutofillSyncTest::ProfilesMatch(int profile_a, int profile_b) { + const std::vector<AutoFillProfile*>& autofill_profiles_a = + GetAllProfiles(profile_a); + std::map<std::string, AutoFillProfile> autofill_profiles_a_map; + for (size_t i = 0; i < autofill_profiles_a.size(); ++i) { + const AutoFillProfile* p = autofill_profiles_a[i]; + autofill_profiles_a_map[p->guid()] = *p; + } + + const std::vector<AutoFillProfile*>& autofill_profiles_b = + GetAllProfiles(profile_b); + for (size_t i = 0; i < autofill_profiles_b.size(); ++i) { + const AutoFillProfile* p = autofill_profiles_b[i]; + if (!autofill_profiles_a_map.count(p->guid())) { + VLOG(1) << "GUID " << p->guid() << " not found in profile " + << profile_b << "."; + return false; + } + AutoFillProfile* expected_profile = &autofill_profiles_a_map[p->guid()]; + expected_profile->set_guid(p->guid()); + if (*expected_profile != *p) { + VLOG(1) << "Mismatch in profile with GUID " << p->guid() << "."; + return false; + } + autofill_profiles_a_map.erase(p->guid()); + } + + if (autofill_profiles_a_map.size()) { + VLOG(1) << "Entries present in Profile " << profile_a + << " but not in " << profile_b << "."; + return false; + } + return true; +} diff --git a/chrome/test/live_sync/live_autofill_sync_test.h b/chrome/test/live_sync/live_autofill_sync_test.h index f00be3a..0492429 100644 --- a/chrome/test/live_sync/live_autofill_sync_test.h +++ b/chrome/test/live_sync/live_autofill_sync_test.h @@ -6,312 +6,84 @@ #define CHROME_TEST_LIVE_SYNC_LIVE_AUTOFILL_SYNC_TEST_H_ #pragma once -#include <map> #include <set> #include <vector> #include "base/compiler_specific.h" -#include "chrome/browser/autofill/autofill_common_test.h" -#include "chrome/browser/autofill/autofill_profile.h" -#include "chrome/browser/autofill/autofill_type.h" #include "chrome/browser/autofill/personal_data_manager.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/browser/sync/profile_sync_test_util.h" -#include "chrome/browser/webdata/autofill_entry.h" -#include "chrome/browser/webdata/web_database.h" #include "chrome/test/live_sync/live_sync_test.h" -#include "chrome/test/thread_observer_helper.h" -using base::WaitableEvent; -using testing::_; - -namespace { -class GetAllAutofillEntries - : public base::RefCountedThreadSafe<GetAllAutofillEntries> { - public: - explicit GetAllAutofillEntries(WebDataService* web_data_service) - : web_data_service_(web_data_service), - done_event_(false, false) {} - - void Init() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - BrowserThread::PostTask( - BrowserThread::DB, - FROM_HERE, - NewRunnableMethod(this, &GetAllAutofillEntries::Run)); - done_event_.Wait(); - } - - const std::vector<AutofillEntry>& entries() const { - return entries_; - } - - private: - friend class base::RefCountedThreadSafe<GetAllAutofillEntries>; - - void Run() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); - web_data_service_->GetDatabase()->GetAllAutofillEntries(&entries_); - done_event_.Signal(); - } - - WebDataService* web_data_service_; - base::WaitableEvent done_event_; - std::vector<AutofillEntry> entries_; -}; - -ACTION_P(SignalEvent, event) { - event->Signal(); -} - -class AutofillDBThreadObserverHelper : public DBThreadObserverHelper { - protected: - virtual void RegisterObservers() { - registrar_.Add(&observer_, - NotificationType::AUTOFILL_ENTRIES_CHANGED, - NotificationService::AllSources()); - registrar_.Add(&observer_, - NotificationType::AUTOFILL_PROFILE_CHANGED, - NotificationService::AllSources()); - } -}; - -enum ProfileType { - PROFILE_MARION, - PROFILE_HOMER, - PROFILE_FRASIER, - PROFILE_NULL -}; - -AutoFillProfile CreateAutofillProfile(ProfileType type) { - AutoFillProfile profile; - switch (type) { - case PROFILE_MARION: - autofill_test::SetProfileInfoWithGuid(&profile, - "C837507A-6C3B-4872-AC14-5113F157D668", - "Marion", "Mitchell", "Morrison", - "johnwayne@me.xyz", "Fox", - "123 Zoo St.", "unit 5", "Hollywood", "CA", - "91601", "US", "12345678910", "01987654321"); - break; - case PROFILE_HOMER: - autofill_test::SetProfileInfoWithGuid(&profile, - "137DE1C3-6A30-4571-AC86-109B1ECFBE7F", - "Homer", "J.", "Simpson", - "homer@abc.com", "SNPP", - "1 Main St", "PO Box 1", "Springfield", "MA", - "94101", "US", "14155551212", "14155551313"); - break; - case PROFILE_FRASIER: - autofill_test::SetProfileInfoWithGuid(&profile, - "9A5E6872-6198-4688-BF75-0016E781BB0A", - "Frasier", "Winslow", "Crane", - "", "randomness", "", "Apt. 4", "Seattle", "WA", - "99121", "US", "0000000000", "ABCDEFGHIJK"); - break; - case PROFILE_NULL: - autofill_test::SetProfileInfoWithGuid(&profile, - "FE461507-7E13-4198-8E66-74C7DB6D8322", - "", "", "", "", "", "", "", "", "", "", "", "", ""); - break; - } - return profile; -} - -class MockPersonalDataManagerObserver : public PersonalDataManager::Observer { - public: - MOCK_METHOD0(OnPersonalDataLoaded, void()); -}; - -} // namespace +class AutofillEntry; +class AutofillKey; +class AutoFillProfile; +class WebDataService; class LiveAutofillSyncTest : public LiveSyncTest { public: - explicit LiveAutofillSyncTest(TestType test_type) : LiveSyncTest(test_type) {} - virtual ~LiveAutofillSyncTest() {} + enum ProfileType { + PROFILE_MARION, + PROFILE_HOMER, + PROFILE_FRASIER, + PROFILE_NULL + }; + + explicit LiveAutofillSyncTest(TestType test_type); + virtual ~LiveAutofillSyncTest(); // Used to access the web data service within a particular sync profile. - WebDataService* GetWebDataService(int index) WARN_UNUSED_RESULT { - return GetProfile(index)->GetWebDataService(Profile::EXPLICIT_ACCESS); - } + WebDataService* GetWebDataService(int index) WARN_UNUSED_RESULT; // Used to access the personal data manager within a particular sync profile. - PersonalDataManager* GetPersonalDataManager(int index) WARN_UNUSED_RESULT { - return GetProfile(index)->GetPersonalDataManager(); - } + PersonalDataManager* GetPersonalDataManager(int index) WARN_UNUSED_RESULT; // Adds the form fields in |keys| to the WebDataService of sync profile // |profile|. - void AddKeys(int profile, const std::set<AutofillKey>& keys) { - std::vector<webkit_glue::FormField> form_fields; - for (std::set<AutofillKey>::const_iterator i = keys.begin(); - i != keys.end(); - ++i) { - form_fields.push_back(webkit_glue::FormField(string16(), - (*i).name(), - (*i).value(), - string16(), - 0, - false)); - } - - WaitableEvent done_event(false, false); - scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( - new AutofillDBThreadObserverHelper()); - observer_helper->Init(); - - EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). - WillOnce(SignalEvent(&done_event)); - WebDataService* wds = GetWebDataService(profile); - wds->AddFormFields(form_fields); - done_event.Wait(); - } - + void AddKeys(int profile, const std::set<AutofillKey>& keys); // Removes the form field in |key| from the WebDataService of sync profile // |profile|. - void RemoveKey(int profile, const AutofillKey& key) { - WaitableEvent done_event(false, false); - scoped_refptr<AutofillDBThreadObserverHelper> observer_helper( - new AutofillDBThreadObserverHelper()); - observer_helper->Init(); - - EXPECT_CALL(*observer_helper->observer(), Observe(_, _, _)). - WillOnce(SignalEvent(&done_event)); - WebDataService* wds = GetWebDataService(profile); - wds->RemoveFormValueForElementName(key.name(), key.value()); - done_event.Wait(); - } + void RemoveKey(int profile, const AutofillKey& key); // Gets all the form fields in the WebDataService of sync profile |profile|. - std::set<AutofillEntry> GetAllKeys(int profile) WARN_UNUSED_RESULT { - WebDataService* wds = GetWebDataService(profile); - scoped_refptr<GetAllAutofillEntries> get_all_entries = - new GetAllAutofillEntries(wds); - get_all_entries->Init(); - const std::vector<AutofillEntry>& all_entries = get_all_entries->entries(); - std::set<AutofillEntry> all_keys; - for (std::vector<AutofillEntry>::const_iterator it = all_entries.begin(); - it != all_entries.end(); ++it) { - all_keys.insert(*it); - } - return all_keys; - } + std::set<AutofillEntry> GetAllKeys(int profile) WARN_UNUSED_RESULT; // Compares the form fields in the WebDataServices of sync profiles // |profile_a| and |profile_b|. Returns true if they match. - bool KeysMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT { - return GetAllKeys(profile_a) == GetAllKeys(profile_b); - } + bool KeysMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT; // Replaces the Autofill profiles in sync profile |profile| with // |autofill_profiles|. void SetProfiles( - int profile, std::vector<AutoFillProfile>* autofill_profiles) { - MockPersonalDataManagerObserver observer; - EXPECT_CALL(observer, OnPersonalDataLoaded()). - WillOnce(QuitUIMessageLoop()); - PersonalDataManager* pdm = GetPersonalDataManager(profile); - pdm->SetObserver(&observer); - pdm->SetProfiles(autofill_profiles); - MessageLoop::current()->Run(); - pdm->RemoveObserver(&observer); - } + int profile, std::vector<AutoFillProfile>* autofill_profiles); // Adds the autofill profile |autofill_profile| to sync profile |profile|. - void AddProfile(int profile, const AutoFillProfile& autofill_profile) { - const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); - std::vector<AutoFillProfile> autofill_profiles; - for (size_t i = 0; i < all_profiles.size(); ++i) - autofill_profiles.push_back(*all_profiles[i]); - autofill_profiles.push_back(autofill_profile); - SetProfiles(profile, &autofill_profiles); - } + void AddProfile(int profile, const AutoFillProfile& autofill_profile); // Removes the autofill profile with guid |guid| from sync profile // |profile|. - void RemoveProfile(int profile, const std::string& guid) { - const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); - std::vector<AutoFillProfile> autofill_profiles; - for (size_t i = 0; i < all_profiles.size(); ++i) { - if (all_profiles[i]->guid() != guid) - autofill_profiles.push_back(*all_profiles[i]); - } - SetProfiles(profile, &autofill_profiles); - } + void RemoveProfile(int profile, const std::string& guid); // Updates the autofill profile with guid |guid| in sync profile |profile| // to |type| and |value|. void UpdateProfile(int profile, const std::string& guid, const AutoFillType& type, - const string16& value) { - const std::vector<AutoFillProfile*>& all_profiles = GetAllProfiles(profile); - std::vector<AutoFillProfile> profiles; - for (size_t i = 0; i < all_profiles.size(); ++i) { - profiles.push_back(*all_profiles[i]); - if (all_profiles[i]->guid() == guid) - profiles.back().SetInfo(type, value); - } - SetProfiles(profile, &profiles); - } + const string16& value); // Gets all the Autofill profiles in the PersonalDataManager of sync profile // |profile|. const std::vector<AutoFillProfile*>& GetAllProfiles(int profile) - WARN_UNUSED_RESULT { - MockPersonalDataManagerObserver observer; - EXPECT_CALL(observer, OnPersonalDataLoaded()). - WillOnce(QuitUIMessageLoop()); - PersonalDataManager* pdm = GetPersonalDataManager(profile); - pdm->SetObserver(&observer); - pdm->Refresh(); - MessageLoop::current()->Run(); - pdm->RemoveObserver(&observer); - return pdm->web_profiles(); - } + WARN_UNUSED_RESULT; // Compares the Autofill profiles in the PersonalDataManagers of sync profiles // |profile_a| and |profile_b|. Returns true if they match. - bool ProfilesMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT { - const std::vector<AutoFillProfile*>& autofill_profiles_a = - GetAllProfiles(profile_a); - std::map<std::string, AutoFillProfile> autofill_profiles_a_map; - for (size_t i = 0; i < autofill_profiles_a.size(); ++i) { - const AutoFillProfile* p = autofill_profiles_a[i]; - autofill_profiles_a_map[p->guid()] = *p; - } - - const std::vector<AutoFillProfile*>& autofill_profiles_b = - GetAllProfiles(profile_b); - for (size_t i = 0; i < autofill_profiles_b.size(); ++i) { - const AutoFillProfile* p = autofill_profiles_b[i]; - if (!autofill_profiles_a_map.count(p->guid())) { - VLOG(1) << "GUID " << p->guid() << " not found in profile " - << profile_b << "."; - return false; - } - AutoFillProfile* expected_profile = &autofill_profiles_a_map[p->guid()]; - expected_profile->set_guid(p->guid()); - if (*expected_profile != *p) { - VLOG(1) << "Mismatch in profile with GUID " << p->guid() << "."; - return false; - } - autofill_profiles_a_map.erase(p->guid()); - } - - if (autofill_profiles_a_map.size()) { - VLOG(1) << "Entries present in Profile " << profile_a - << " but not in " << profile_b << "."; - return false; - } - return true; - } + bool ProfilesMatch(int profile_a, int profile_b) WARN_UNUSED_RESULT; private: DISALLOW_COPY_AND_ASSIGN(LiveAutofillSyncTest); }; +AutoFillProfile CreateAutofillProfile(LiveAutofillSyncTest::ProfileType type); + class TwoClientLiveAutofillSyncTest : public LiveAutofillSyncTest { public: TwoClientLiveAutofillSyncTest() : LiveAutofillSyncTest(TWO_CLIENT) {} diff --git a/chrome/test/live_sync/two_client_live_autofill_sync_test.cc b/chrome/test/live_sync/two_client_live_autofill_sync_test.cc index 263eaef..0f1f998 100644 --- a/chrome/test/live_sync/two_client_live_autofill_sync_test.cc +++ b/chrome/test/live_sync/two_client_live_autofill_sync_test.cc @@ -4,6 +4,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/sync/profile_sync_service_harness.h" +#include "chrome/browser/webdata/autofill_entry.h" #include "chrome/test/live_sync/live_autofill_sync_test.h" IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, WebDataServiceSanity) { @@ -101,19 +102,19 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; // Client0 adds a profile. - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(1U, GetAllProfiles(0).size()); // Client1 adds a profile. - AddProfile(1, CreateAutofillProfile(PROFILE_MARION)); + AddProfile(1, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_MARION)); ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(2U, GetAllProfiles(0).size()); // Client0 adds the same profile. - AddProfile(0, CreateAutofillProfile(PROFILE_MARION)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_MARION)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(2U, GetAllProfiles(0).size()); @@ -141,8 +142,8 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddDuplicateProfiles) { ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(ProfilesMatch(0,1)); @@ -153,8 +154,10 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddDuplicateProfiles) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, SameProfileWithConflict) { ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - AutoFillProfile profile0 = CreateAutofillProfile(PROFILE_HOMER); - AutoFillProfile profile1 = CreateAutofillProfile(PROFILE_HOMER); + AutoFillProfile profile0 = + CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER); + AutoFillProfile profile1 = + CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER); profile1.SetInfo(AutoFillType(PHONE_FAX_WHOLE_NUMBER), ASCIIToUTF16("1234567890")); @@ -170,7 +173,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, SameProfileWithConflict) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddEmptyProfile) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_NULL)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_NULL)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(0U, GetAllProfiles(0).size()); @@ -180,7 +183,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddEmptyProfile) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddProfile) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(1U, GetAllProfiles(0).size()); @@ -190,9 +193,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddProfile) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddMultipleProfiles) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); - AddProfile(0, CreateAutofillProfile(PROFILE_MARION)); - AddProfile(0, CreateAutofillProfile(PROFILE_FRASIER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_MARION)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_FRASIER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(3U, GetAllProfiles(0).size()); @@ -202,7 +205,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, AddMultipleProfiles) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, DeleteProfile) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(1U, GetAllProfiles(0).size()); @@ -217,9 +220,9 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, DeleteProfile) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, MergeProfiles) { ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); - AddProfile(1, CreateAutofillProfile(PROFILE_MARION)); - AddProfile(1, CreateAutofillProfile(PROFILE_FRASIER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); + AddProfile(1, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_MARION)); + AddProfile(1, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_FRASIER)); ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(AwaitQuiescence()); ASSERT_TRUE(ProfilesMatch(0,1)); @@ -230,7 +233,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, MergeProfiles) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, UpdateFields) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(1U, GetAllProfiles(0).size()); @@ -248,7 +251,7 @@ IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, UpdateFields) { IN_PROC_BROWSER_TEST_F(TwoClientLiveAutofillSyncTest, ConflictingFields) { ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; - AddProfile(0, CreateAutofillProfile(PROFILE_HOMER)); + AddProfile(0, CreateAutofillProfile(LiveAutofillSyncTest::PROFILE_HOMER)); ASSERT_TRUE(GetClient(0)->AwaitMutualSyncCycleCompletion(GetClient(1))); ASSERT_TRUE(ProfilesMatch(0,1)); ASSERT_EQ(1U, GetAllProfiles(0).size()); diff --git a/chrome/test/sync/engine/mock_gaia_authenticator.cc b/chrome/test/sync/engine/mock_gaia_authenticator.cc index ebcf566..75d4f97 100644 --- a/chrome/test/sync/engine/mock_gaia_authenticator.cc +++ b/chrome/test/sync/engine/mock_gaia_authenticator.cc @@ -21,6 +21,8 @@ MockGaiaAuthenticator::MockGaiaAuthenticator(const char* user_agent, // doesn't care about them. } +MockGaiaAuthenticator::~MockGaiaAuthenticator() {} + // Add a mock user to internal list of users. void MockGaiaAuthenticator::AddMockUser(MockUser mock_user) { mock_credentials_[mock_user.email] = mock_user; @@ -107,4 +109,44 @@ void MockGaiaAuthenticator::ResetCredentials() { current_user_ = ""; } +std::string MockGaiaAuthenticator::email() { + return (current_user_.empty() || !should_save_credentials_) ? "" : + mock_credentials_[current_user_].email; +} + +std::string MockGaiaAuthenticator::auth_token() { + return (current_user_.empty()) ? "" : + mock_credentials_[current_user_].auth_token; +} + +std::string MockGaiaAuthenticator::sid() { + return (current_user_.empty()) ? "" : + mock_credentials_[current_user_].sid; +} + +std::string MockGaiaAuthenticator::lsid() { + return (current_user_.empty()) ? "" : + mock_credentials_[current_user_].lsid; +} + +gaia::AuthenticationError MockGaiaAuthenticator::auth_error() { + return (current_user_.empty()) ? gaia::CredentialsNotSet : + mock_credentials_[current_user_].auth_error; +} + +std::string MockGaiaAuthenticator::auth_error_url() { + return (current_user_.empty()) ? "" : + mock_credentials_[current_user_].error_url; +} + +std::string MockGaiaAuthenticator::captcha_token() { + return (current_user_.empty()) ? "" : + mock_credentials_[current_user_].captcha_token; +} + +std::string MockGaiaAuthenticator::captcha_url() { + return (current_user_.empty()) ? "" : + mock_credentials_[current_user_].captcha_url; +} + } // namespace browser_sync diff --git a/chrome/test/sync/engine/mock_gaia_authenticator.h b/chrome/test/sync/engine/mock_gaia_authenticator.h index e882e9b..07291bf 100644 --- a/chrome/test/sync/engine/mock_gaia_authenticator.h +++ b/chrome/test/sync/engine/mock_gaia_authenticator.h @@ -57,6 +57,7 @@ class MockGaiaAuthenticator { public: MockGaiaAuthenticator(const char* user_agent, const char* service_id, const char* gaia_url); + ~MockGaiaAuthenticator(); // Add a mock user; takes a struct. You can populate any or all fields when // adding a user. The email field is required, all others optional. @@ -96,45 +97,14 @@ class MockGaiaAuthenticator { void ResetCredentials(); // Accessors follow. - std::string email() { - return (current_user_.length() == 0 || !should_save_credentials_) ? "" : - mock_credentials_[current_user_].email; - } - - std::string auth_token() { - return (current_user_.length() == 0) ? "" : - mock_credentials_[current_user_].auth_token; - } - - std::string sid() { - return (current_user_.length() == 0) ? "" : - mock_credentials_[current_user_].sid; - } - - std::string lsid() { - return (current_user_.length() == 0) ? "" : - mock_credentials_[current_user_].lsid; - } - - gaia::AuthenticationError auth_error() { - return (current_user_.length() == 0) ? gaia::CredentialsNotSet : - mock_credentials_[current_user_].auth_error; - } - - std::string auth_error_url() { - return (current_user_.length() == 0) ? "" : - mock_credentials_[current_user_].error_url; - } - - std::string captcha_token() { - return (current_user_.length() == 0) ? "" : - mock_credentials_[current_user_].captcha_token; - } - - std::string captcha_url() { - return (current_user_.length() == 0) ? "" : - mock_credentials_[current_user_].captcha_url; - } + std::string email(); + std::string auth_token(); + std::string sid(); + std::string lsid(); + gaia::AuthenticationError auth_error(); + std::string auth_error_url(); + std::string captcha_token(); + std::string captcha_url(); private: bool should_save_credentials_; diff --git a/chrome/test/thread_test_helper.cc b/chrome/test/thread_test_helper.cc new file mode 100644 index 0000000..6714310 --- /dev/null +++ b/chrome/test/thread_test_helper.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/thread_test_helper.h" + +ThreadTestHelper::ThreadTestHelper(BrowserThread::ID thread_id) + : test_result_(false), + thread_id_(thread_id), + done_event_(false, false) { +} + +bool ThreadTestHelper::Run() { + if (!BrowserThread::PostTask(thread_id_, FROM_HERE, NewRunnableMethod( + this, &ThreadTestHelper::RunInThread))) { + return false; + } + done_event_.Wait(); + return test_result_; +} + +void ThreadTestHelper::RunTest() { set_test_result(true); } + +ThreadTestHelper::~ThreadTestHelper() {} + +void ThreadTestHelper::RunInThread() { + RunTest(); + done_event_.Signal(); +} diff --git a/chrome/test/thread_test_helper.h b/chrome/test/thread_test_helper.h index 93960e1..a0dd78a 100644 --- a/chrome/test/thread_test_helper.h +++ b/chrome/test/thread_test_helper.h @@ -6,6 +6,7 @@ #define CHROME_TEST_THREAD_TEST_HELPER_H_ #pragma once +#include "base/compiler_specific.h" #include "base/ref_counted.h" #include "base/synchronization/waitable_event.h" #include "chrome/browser/browser_thread.h" @@ -17,37 +18,23 @@ // executed. class ThreadTestHelper : public base::RefCountedThreadSafe<ThreadTestHelper> { public: - explicit ThreadTestHelper(BrowserThread::ID thread_id) - : test_result_(false), - thread_id_(thread_id), - done_event_(false, false) { - } + explicit ThreadTestHelper(BrowserThread::ID thread_id); // True if RunTest() was successfully executed on the target thread. - bool Run() WARN_UNUSED_RESULT { - if (!BrowserThread::PostTask(thread_id_, FROM_HERE, NewRunnableMethod( - this, &ThreadTestHelper::RunInThread))) { - return false; - } - done_event_.Wait(); - return test_result_; - } + bool Run() WARN_UNUSED_RESULT; - virtual void RunTest() { set_test_result(true); } + virtual void RunTest(); protected: friend class base::RefCountedThreadSafe<ThreadTestHelper>; - virtual ~ThreadTestHelper() {} + virtual ~ThreadTestHelper(); // Use this method to store the result of RunTest(). void set_test_result(bool test_result) { test_result_ = test_result; } private: - void RunInThread() { - RunTest(); - done_event_.Signal(); - } + void RunInThread(); bool test_result_; BrowserThread::ID thread_id_; diff --git a/chrome/test/v8_unit_test.cc b/chrome/test/v8_unit_test.cc index 79dc887..aee85c2 100644 --- a/chrome/test/v8_unit_test.cc +++ b/chrome/test/v8_unit_test.cc @@ -5,6 +5,10 @@ #include "base/string_util.h" #include "chrome/test/v8_unit_test.h" +V8UnitTest::V8UnitTest() {} + +V8UnitTest::~V8UnitTest() {} + void V8UnitTest::SetUp() { v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(); global->Set(v8::String::New("log"), diff --git a/chrome/test/v8_unit_test.h b/chrome/test/v8_unit_test.h index 31ec1d4..e09eb2f 100644 --- a/chrome/test/v8_unit_test.h +++ b/chrome/test/v8_unit_test.h @@ -20,7 +20,9 @@ class StringPiece; // this context as well as call functions in the context. class V8UnitTest : public testing::Test { public: - V8UnitTest() {} + V8UnitTest(); + virtual ~V8UnitTest(); + virtual void SetUp(); protected: diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h index 1a1cb51..79e2a9b 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h @@ -285,7 +285,7 @@ class GLES2DecoderTestBase : public testing::Test { virtual ~MockCommandBufferEngine() { } - Buffer GetSharedMemoryBuffer(int32 shm_id) { + virtual Buffer GetSharedMemoryBuffer(int32 shm_id) { return shm_id == kSharedMemoryId ? valid_buffer_ : invalid_buffer_; } @@ -293,7 +293,7 @@ class GLES2DecoderTestBase : public testing::Test { memset(data_.get(), kInitialMemoryValue, kSharedBufferSize); } - void set_token(int32 token) { + virtual void set_token(int32 token) { DCHECK(false); } diff --git a/media/tools/omx_test/file_sink.cc b/media/tools/omx_test/file_sink.cc index 98766ab..5e92b02 100644 --- a/media/tools/omx_test/file_sink.cc +++ b/media/tools/omx_test/file_sink.cc @@ -10,6 +10,19 @@ namespace media { +FileSink::FileSink(const FilePath& output_path, + bool simulate_copy, + bool enable_csc) + : output_path_(output_path), + simulate_copy_(simulate_copy), + enable_csc_(enable_csc), + width_(0), + height_(0), + copy_buf_size_(0), + csc_buf_size_(0) { +} + +FileSink::~FileSink() {} void FileSink::BufferReady(int size, uint8* buffer) { if (size > copy_buf_size_) { diff --git a/media/tools/omx_test/file_sink.h b/media/tools/omx_test/file_sink.h index 69907031..5703600 100644 --- a/media/tools/omx_test/file_sink.h +++ b/media/tools/omx_test/file_sink.h @@ -21,17 +21,9 @@ class FileSink { public: FileSink(const FilePath& output_path, bool simulate_copy, - bool enable_csc) - : output_path_(output_path), - simulate_copy_(simulate_copy), - enable_csc_(enable_csc), - width_(0), - height_(0), - copy_buf_size_(0), - csc_buf_size_(0) { - } - - virtual ~FileSink() {} + bool enable_csc); + + virtual ~FileSink(); virtual void BufferReady(int size, uint8* buffer); diff --git a/net/http/http_auth_gssapi_posix_unittest.cc b/net/http/http_auth_gssapi_posix_unittest.cc index f83acb4..43a3285 100644 --- a/net/http/http_auth_gssapi_posix_unittest.cc +++ b/net/http/http_auth_gssapi_posix_unittest.cc @@ -109,23 +109,20 @@ TEST(HttpAuthGSSAPIPOSIXTest, GSSAPICycle) { 1, // Locally initiated 1); // Open test::MockGSSAPILibrary::SecurityContextQuery queries[] = { - { "Negotiate", // Package name - GSS_S_CONTINUE_NEEDED, // Major response code - 0, // Minor response code - context1, // Context - { 0, NULL }, // Expected input token - { arraysize(kAuthResponse), - const_cast<char*>(kAuthResponse) } // Output token - }, - { "Negotiate", // Package name - GSS_S_COMPLETE, // Major response code - 0, // Minor response code - context2, // Context - { arraysize(kAuthResponse), - const_cast<char*>(kAuthResponse) }, // Expected input token - { arraysize(kAuthResponse), - const_cast<char*>(kAuthResponse) } // Output token - }, + test::MockGSSAPILibrary::SecurityContextQuery( + "Negotiate", // Package name + GSS_S_CONTINUE_NEEDED, // Major response code + 0, // Minor response code + context1, // Context + NULL, // Expected input token + kAuthResponse), // Output token + test::MockGSSAPILibrary::SecurityContextQuery( + "Negotiate", // Package name + GSS_S_COMPLETE, // Major response code + 0, // Minor response code + context2, // Context + kAuthResponse, // Expected input token + kAuthResponse) // Output token }; for (size_t i = 0; i < arraysize(queries); ++i) { diff --git a/net/http/http_auth_handler_negotiate_unittest.cc b/net/http/http_auth_handler_negotiate_unittest.cc index bb57151..cdaa5f3 100644 --- a/net/http/http_auth_handler_negotiate_unittest.cc +++ b/net/http/http_auth_handler_negotiate_unittest.cc @@ -116,23 +116,20 @@ class HttpAuthHandlerNegotiateTest : public PlatformTest { 1, // Locally initiated 1); // Open test::MockGSSAPILibrary::SecurityContextQuery queries[] = { - { "Negotiate", // Package name + test::MockGSSAPILibrary::SecurityContextQuery( + "Negotiate", // Package name GSS_S_CONTINUE_NEEDED, // Major response code 0, // Minor response code context1, // Context - { 0, NULL }, // Expected input token - { arraysize(kAuthResponse), - const_cast<char*>(kAuthResponse) } // Output token - }, - { "Negotiate", // Package name + NULL, // Expected input token + kAuthResponse), // Output token + test::MockGSSAPILibrary::SecurityContextQuery( + "Negotiate", // Package name GSS_S_COMPLETE, // Major response code 0, // Minor response code context2, // Context - { arraysize(kAuthResponse), - const_cast<char*>(kAuthResponse) }, // Expected input token - { arraysize(kAuthResponse), - const_cast<char*>(kAuthResponse) } // Output token - }, + kAuthResponse, // Expected input token + kAuthResponse) // Output token }; for (size_t i = 0; i < arraysize(queries); ++i) { @@ -159,14 +156,13 @@ class HttpAuthHandlerNegotiateTest : public PlatformTest { 0, // Context flags 1, // Locally initiated 0); // Open - test::MockGSSAPILibrary::SecurityContextQuery query = { - "Negotiate", // Package name - major_status, // Major response code - minor_status, // Minor response code - context, // Context - { 0, NULL }, // Expected input token - { 0, NULL } // Output token - }; + test::MockGSSAPILibrary::SecurityContextQuery query( + "Negotiate", // Package name + major_status, // Major response code + minor_status, // Minor response code + context, // Context + NULL, // Expected input token + NULL); // Output token mock_library->ExpectSecurityContext(query.expected_package, query.response_code, diff --git a/net/http/http_network_session_peer.cc b/net/http/http_network_session_peer.cc new file mode 100644 index 0000000..7bb342c --- /dev/null +++ b/net/http/http_network_session_peer.cc @@ -0,0 +1,69 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/http/http_network_session_peer.h" + +#include "net/http/http_network_session.h" +#include "net/http/http_proxy_client_socket_pool.h" +#include "net/socket/socks_client_socket_pool.h" +#include "net/socket/ssl_client_socket_pool.h" +#include "net/socket/tcp_client_socket_pool.h" + +namespace net { + +HttpNetworkSessionPeer::HttpNetworkSessionPeer( + const scoped_refptr<HttpNetworkSession>& session) + : session_(session) {} + +HttpNetworkSessionPeer::~HttpNetworkSessionPeer() {} + +void HttpNetworkSessionPeer::SetTCPSocketPool(TCPClientSocketPool* pool) { + session_->socket_pool_manager_.tcp_socket_pool_.reset(pool); +} + +void HttpNetworkSessionPeer::SetSocketPoolForSOCKSProxy( + const HostPortPair& socks_proxy, + SOCKSClientSocketPool* pool) { + ClientSocketPoolManager* socket_pool_manager = + &session_->socket_pool_manager_; + + // Call through the public interface to force initialization of the + // wrapped socket pools. + delete socket_pool_manager->GetSocketPoolForSOCKSProxy(socks_proxy); + socket_pool_manager->socks_socket_pools_[socks_proxy] = pool; +} + +void HttpNetworkSessionPeer::SetSocketPoolForHTTPProxy( + const HostPortPair& http_proxy, + HttpProxyClientSocketPool* pool) { + ClientSocketPoolManager* socket_pool_manager = + &session_->socket_pool_manager_; + + // Call through the public interface to force initialization of the + // wrapped socket pools. + delete socket_pool_manager->GetSocketPoolForHTTPProxy(http_proxy); + socket_pool_manager->http_proxy_socket_pools_[http_proxy] = pool; +} + +void HttpNetworkSessionPeer::SetSSLSocketPool(SSLClientSocketPool* pool) { + session_->socket_pool_manager_.ssl_socket_pool_.reset(pool); +} + +void HttpNetworkSessionPeer::SetSocketPoolForSSLWithProxy( + const HostPortPair& proxy_host, + SSLClientSocketPool* pool) { + ClientSocketPoolManager* socket_pool_manager = + &session_->socket_pool_manager_; + + // Call through the public interface to force initialization of the + // wrapped socket pools. + delete socket_pool_manager->GetSocketPoolForSSLWithProxy(proxy_host); + socket_pool_manager->ssl_socket_pools_for_proxies_[proxy_host] = pool; +} + +void HttpNetworkSessionPeer::SetProxyService(ProxyService* proxy_service) { + session_->proxy_service_ = proxy_service; +} + +} // namespace net diff --git a/net/http/http_network_session_peer.h b/net/http/http_network_session_peer.h index 13f3fa7..398488b 100644 --- a/net/http/http_network_session_peer.h +++ b/net/http/http_network_session_peer.h @@ -6,66 +6,41 @@ #define NET_HTTP_HTTP_NETWORK_SESSION_PEER_H_ #pragma once -#include "net/http/http_network_session.h" -#include "net/http/http_proxy_client_socket_pool.h" -#include "net/socket/socks_client_socket_pool.h" -#include "net/socket/ssl_client_socket_pool.h" +#include "base/ref_counted.h" namespace net { +class HostPortPair; +class HttpNetworkSession; +class HttpProxyClientSocketPool; +class ProxyService; +class SOCKSClientSocketPool; +class SSLClientSocketPool; +class TCPClientSocketPool; + class HttpNetworkSessionPeer { public: explicit HttpNetworkSessionPeer( - const scoped_refptr<HttpNetworkSession>& session) - : session_(session) {} + const scoped_refptr<HttpNetworkSession>& session); + ~HttpNetworkSessionPeer(); - void SetTCPSocketPool(TCPClientSocketPool* pool) { - session_->socket_pool_manager_.tcp_socket_pool_.reset(pool); - } + void SetTCPSocketPool(TCPClientSocketPool* pool); void SetSocketPoolForSOCKSProxy( const HostPortPair& socks_proxy, - SOCKSClientSocketPool* pool) { - ClientSocketPoolManager* socket_pool_manager = - &session_->socket_pool_manager_; - - // Call through the public interface to force initialization of the - // wrapped socket pools. - delete socket_pool_manager->GetSocketPoolForSOCKSProxy(socks_proxy); - socket_pool_manager->socks_socket_pools_[socks_proxy] = pool; - } + SOCKSClientSocketPool* pool); void SetSocketPoolForHTTPProxy( const HostPortPair& http_proxy, - HttpProxyClientSocketPool* pool) { - ClientSocketPoolManager* socket_pool_manager = - &session_->socket_pool_manager_; + HttpProxyClientSocketPool* pool); - // Call through the public interface to force initialization of the - // wrapped socket pools. - delete socket_pool_manager->GetSocketPoolForHTTPProxy(http_proxy); - socket_pool_manager->http_proxy_socket_pools_[http_proxy] = pool; - } - - void SetSSLSocketPool(SSLClientSocketPool* pool) { - session_->socket_pool_manager_.ssl_socket_pool_.reset(pool); - } + void SetSSLSocketPool(SSLClientSocketPool* pool); void SetSocketPoolForSSLWithProxy( const HostPortPair& proxy_host, - SSLClientSocketPool* pool) { - ClientSocketPoolManager* socket_pool_manager = - &session_->socket_pool_manager_; - - // Call through the public interface to force initialization of the - // wrapped socket pools. - delete socket_pool_manager->GetSocketPoolForSSLWithProxy(proxy_host); - socket_pool_manager->ssl_socket_pools_for_proxies_[proxy_host] = pool; - } + SSLClientSocketPool* pool); - void SetProxyService(ProxyService* proxy_service) { - session_->proxy_service_ = proxy_service; - } + void SetProxyService(ProxyService* proxy_service); private: const scoped_refptr<HttpNetworkSession> session_; diff --git a/net/http/mock_gssapi_library_posix.cc b/net/http/mock_gssapi_library_posix.cc index 1ca5040..5ae4721 100644 --- a/net/http/mock_gssapi_library_posix.cc +++ b/net/http/mock_gssapi_library_posix.cc @@ -188,6 +188,47 @@ void GssContextMockImpl::Assign( open = other.open; } +MockGSSAPILibrary::SecurityContextQuery::SecurityContextQuery() + : expected_package(), + response_code(0), + minor_response_code(0), + context_info() { + expected_input_token.length = 0; + expected_input_token.value = NULL; + output_token.length = 0; + output_token.value = NULL; +} + +MockGSSAPILibrary::SecurityContextQuery::SecurityContextQuery( + const std::string& in_expected_package, + OM_uint32 in_response_code, + OM_uint32 in_minor_response_code, + const test::GssContextMockImpl& in_context_info, + const char* in_expected_input_token, + const char* in_output_token) + : expected_package(in_expected_package), + response_code(in_response_code), + minor_response_code(in_minor_response_code), + context_info(in_context_info) { + if (in_expected_input_token) { + expected_input_token.length = strlen(in_expected_input_token); + expected_input_token.value = const_cast<char*>(in_expected_input_token); + } else { + expected_input_token.length = 0; + expected_input_token.value = NULL; + } + + if (in_output_token) { + output_token.length = strlen(in_output_token); + output_token.value = const_cast<char*>(in_output_token); + } else { + output_token.length = 0; + output_token.value = NULL; + } +} + +MockGSSAPILibrary::SecurityContextQuery::~SecurityContextQuery() {} + MockGSSAPILibrary::MockGSSAPILibrary() { } diff --git a/net/http/mock_gssapi_library_posix.h b/net/http/mock_gssapi_library_posix.h index f0652d3..aad5de8 100644 --- a/net/http/mock_gssapi_library_posix.h +++ b/net/http/mock_gssapi_library_posix.h @@ -47,6 +47,15 @@ class MockGSSAPILibrary : public GSSAPILibrary { public: // Unit tests need access to this. "Friend"ing didn't help. struct SecurityContextQuery { + SecurityContextQuery(); + SecurityContextQuery(const std::string& expected_package, + OM_uint32 response_code, + OM_uint32 minor_response_code, + const test::GssContextMockImpl& context_info, + const char* expected_input_token, + const char* output_token); + ~SecurityContextQuery(); + std::string expected_package; OM_uint32 response_code; OM_uint32 minor_response_code; diff --git a/net/net.gyp b/net/net.gyp index 768aacc..7d5236f 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -488,6 +488,7 @@ 'http/http_network_layer.h', 'http/http_network_session.cc', 'http/http_network_session.h', + 'http/http_network_session_peer.cc', 'http/http_network_session_peer.h', 'http/http_network_transaction.cc', 'http/http_network_transaction.h', |