From aa987d73f5c7a29ea56cf9d5126ac1b4f4cc1d92 Mon Sep 17 00:00:00 2001 From: "mmoss@chromium.org" Date: Mon, 19 Apr 2010 19:50:45 +0000 Subject: Revert 44935 - Allow mocking of cros api without automatically deleting the mocks Review URL: http://codereview.chromium.org/1653011 TBR=davemoore@chromium.org Review URL: http://codereview.chromium.org/1637022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44938 0039d316-1c4b-4281-b951-d872f2087c98 --- .../chromeos/cros/cros_in_process_browser_test.cc | 30 ++++------ .../chromeos/cros/cros_in_process_browser_test.h | 4 -- chrome/browser/chromeos/cros/cros_library.cc | 68 ++++++++-------------- chrome/browser/chromeos/cros/cros_library.h | 28 +++------ .../login/login_manager_view_browsertest.cc | 8 +-- .../chromeos/login/network_screen_browsertest.cc | 4 +- 6 files changed, 48 insertions(+), 94 deletions(-) diff --git a/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc b/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc index 467e674..6d5c99b 100644 --- a/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc +++ b/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc @@ -51,15 +51,7 @@ void CrosInProcessBrowserTest::InitMockLibraryLoader() { EXPECT_CALL(*loader_, Load(_)) .Times(AnyNumber()) .WillRepeatedly(Return(true)); - test_api()->SetLibraryLoader(loader_, true); -} - -void CrosInProcessBrowserTest::InitMockCryptohomeLibrary() { - InitMockLibraryLoader(); - if (mock_cryptohome_library_) - return; - mock_cryptohome_library_ = new MockCryptohomeLibrary(); - test_api()->SetCryptohomeLibrary(mock_cryptohome_library_, true); + test_api()->SetLibraryLoader(loader_); } void CrosInProcessBrowserTest::InitMockLanguageLibrary() { @@ -67,7 +59,7 @@ void CrosInProcessBrowserTest::InitMockLanguageLibrary() { if (mock_language_library_) return; mock_language_library_ = new MockLanguageLibrary(); - test_api()->SetLanguageLibrary(mock_language_library_, true); + test_api()->SetLanguageLibrary(mock_language_library_); } void CrosInProcessBrowserTest::InitMockNetworkLibrary() { @@ -75,7 +67,7 @@ void CrosInProcessBrowserTest::InitMockNetworkLibrary() { if (mock_network_library_) return; mock_network_library_ = new MockNetworkLibrary(); - test_api()->SetNetworkLibrary(mock_network_library_, true); + test_api()->SetNetworkLibrary(mock_network_library_); } void CrosInProcessBrowserTest::InitMockPowerLibrary() { @@ -83,7 +75,7 @@ void CrosInProcessBrowserTest::InitMockPowerLibrary() { if (mock_power_library_) return; mock_power_library_ = new MockPowerLibrary(); - test_api()->SetPowerLibrary(mock_power_library_, true); + test_api()->SetPowerLibrary(mock_power_library_); } void CrosInProcessBrowserTest::InitMockSynapticsLibrary() { @@ -91,7 +83,7 @@ void CrosInProcessBrowserTest::InitMockSynapticsLibrary() { if (mock_synaptics_library_) return; mock_synaptics_library_ = new MockSynapticsLibrary(); - test_api()->SetSynapticsLibrary(mock_synaptics_library_, true); + test_api()->SetSynapticsLibrary(mock_synaptics_library_); } void CrosInProcessBrowserTest::SetStatusAreaMocksExpectations() { @@ -198,17 +190,15 @@ void CrosInProcessBrowserTest::SetSynapticsLibraryExpectations() { void CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture() { // Prevent bogus gMock leak check from firing. if (loader_) - test_api()->SetLibraryLoader(NULL, false); - if (mock_cryptohome_library_) - test_api()->SetCryptohomeLibrary(NULL, false); + test_api()->SetLibraryLoader(NULL); if (mock_language_library_) - test_api()->SetLanguageLibrary(NULL, false); + test_api()->SetLanguageLibrary(NULL); if (mock_network_library_) - test_api()->SetNetworkLibrary(NULL, false); + test_api()->SetNetworkLibrary(NULL); if (mock_power_library_) - test_api()->SetPowerLibrary(NULL, false); + test_api()->SetPowerLibrary(NULL); if (mock_synaptics_library_) - test_api()->SetSynapticsLibrary(NULL, false); + test_api()->SetSynapticsLibrary(NULL); } } // namespace chromeos diff --git a/chrome/browser/chromeos/cros/cros_in_process_browser_test.h b/chrome/browser/chromeos/cros/cros_in_process_browser_test.h index 524ad93..6e01bc2 100644 --- a/chrome/browser/chromeos/cros/cros_in_process_browser_test.h +++ b/chrome/browser/chromeos/cros/cros_in_process_browser_test.h @@ -6,8 +6,6 @@ #define CHROME_BROWSER_CHROMEOS_CROS_CROS_IN_PROCESS_BROWSER_TEST_H_ #include "base/scoped_ptr.h" -#include "chrome/browser/chromeos/cros/cros_library.h" -#include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" #include "chrome/browser/chromeos/cros/mock_language_library.h" #include "chrome/browser/chromeos/cros/mock_library_loader.h" #include "chrome/browser/chromeos/cros/mock_network_library.h" @@ -43,7 +41,6 @@ class CrosInProcessBrowserTest : public InProcessBrowserTest { void InitMockLibraryLoader(); // Initialization of mocks. - void InitMockCryptohomeLibrary(); void InitMockLanguageLibrary(); void InitMockNetworkLibrary(); void InitMockPowerLibrary(); @@ -71,7 +68,6 @@ class CrosInProcessBrowserTest : public InProcessBrowserTest { // Mocks, destroyed by CrosLibrary class. MockLibraryLoader* loader_; - MockCryptohomeLibrary* mock_cryptohome_library_; MockLanguageLibrary* mock_language_library_; MockNetworkLibrary* mock_network_library_; MockPowerLibrary* mock_power_library_; diff --git a/chrome/browser/chromeos/cros/cros_library.cc b/chrome/browser/chromeos/cros/cros_library.cc index 388fabc..71a7f4d 100644 --- a/chrome/browser/chromeos/cros/cros_library.cc +++ b/chrome/browser/chromeos/cros/cros_library.cc @@ -23,14 +23,6 @@ CrosLibrary::CrosLibrary() : library_loader_(NULL), network_lib_(NULL), power_lib_(NULL), synaptics_lib_(NULL), - own_library_loader_(true), - own_cryptohome_loader_(true), - own_language_loader_(true), - own_login_loader_(true), - own_mount_loader_(true), - own_network_loader_(true), - own_power_loader_(true), - own_synaptics_library_(true), loaded_(false), load_error_(false), test_api_(NULL) { @@ -38,21 +30,21 @@ CrosLibrary::CrosLibrary() : library_loader_(NULL), } CrosLibrary::~CrosLibrary() { - if (own_library_loader_ && library_loader_) + if (library_loader_) delete library_loader_; - if (own_cryptohome_loader_ && crypto_lib_) + if (crypto_lib_) delete crypto_lib_; - if (own_language_loader_ && language_lib_) + if (language_lib_) delete language_lib_; - if (own_login_loader_ && login_lib_) + if (login_lib_) delete login_lib_; - if (own_mount_loader_ && mount_lib_) + if (mount_lib_) delete mount_lib_; - if (own_network_loader_ && network_lib_) + if (network_lib_) delete network_lib_; - if (own_power_loader_ && power_lib_) + if (power_lib_) delete power_lib_; - if (own_synaptics_library_ && synaptics_lib_) + if (synaptics_lib_) delete synaptics_lib_; if (test_api_) delete test_api_; @@ -121,12 +113,11 @@ CrosLibrary::TestApi* CrosLibrary::GetTestApi() { return test_api_; } -void CrosLibrary::TestApi::SetLibraryLoader(LibraryLoader* loader, bool own) { +void CrosLibrary::TestApi::SetLibraryLoader(LibraryLoader* loader) { if (library_->library_loader_ == loader) return; - if (library_->own_library_loader_ && library_->library_loader_) + if (library_->library_loader_) delete library_->library_loader_; - library_->own_library_loader_ = own; library_->library_loader_ = loader; // Reset load flags when loader changes. Otherwise some tests are really not // going to be happy. @@ -134,56 +125,45 @@ void CrosLibrary::TestApi::SetLibraryLoader(LibraryLoader* loader, bool own) { library_->load_error_ = false; } -void CrosLibrary::TestApi::SetCryptohomeLibrary(CryptohomeLibrary* library, - bool own) { - if (library_->own_cryptohome_loader_ && library_->crypto_lib_) +void CrosLibrary::TestApi::SetCryptohomeLibrary(CryptohomeLibrary* library) { + if (library_->crypto_lib_) delete library_->crypto_lib_; - library_->own_cryptohome_loader_ = own; library_->crypto_lib_ = library; } -void CrosLibrary::TestApi::SetLanguageLibrary(LanguageLibrary* library, - bool own) { - if (library_->own_language_loader_ && library_->language_lib_) +void CrosLibrary::TestApi::SetLanguageLibrary(LanguageLibrary* library) { + if (library_->language_lib_) delete library_->language_lib_; - library_->own_language_loader_ = own; library_->language_lib_ = library; } -void CrosLibrary::TestApi::SetLoginLibrary(LoginLibrary* library, bool own) { - if (library_->own_login_loader_ && library_->login_lib_) +void CrosLibrary::TestApi::SetLoginLibrary(LoginLibrary* library) { + if (library_->login_lib_) delete library_->login_lib_; - library_->own_login_loader_ = own; library_->login_lib_ = library; } -void CrosLibrary::TestApi::SetMountLibrary(MountLibrary* library, bool own) { - if (library_->own_mount_loader_ && library_->mount_lib_) +void CrosLibrary::TestApi::SetMountLibrary(MountLibrary* library) { + if (library_->mount_lib_) delete library_->mount_lib_; - library_->own_mount_loader_ = own; library_->mount_lib_ = library; } -void CrosLibrary::TestApi::SetNetworkLibrary(NetworkLibrary* library, - bool own) { - if (library_->own_network_loader_ && library_->network_lib_) +void CrosLibrary::TestApi::SetNetworkLibrary(NetworkLibrary* library) { + if (library_->network_lib_) delete library_->network_lib_; - library_->own_network_loader_ = own; library_->network_lib_ = library; } -void CrosLibrary::TestApi::SetPowerLibrary(PowerLibrary* library, bool own) { - if (library_->own_power_loader_ && library_->power_lib_) +void CrosLibrary::TestApi::SetPowerLibrary(PowerLibrary* library) { + if (library_->power_lib_) delete library_->power_lib_; - library_->own_power_loader_ = own; library_->power_lib_ = library; } -void CrosLibrary::TestApi::SetSynapticsLibrary(SynapticsLibrary* library, - bool own) { - if (library_->own_synaptics_library_ && library_->synaptics_lib_) +void CrosLibrary::TestApi::SetSynapticsLibrary(SynapticsLibrary* library) { + if (library_->synaptics_lib_) delete library_->synaptics_lib_; - library_->own_synaptics_library_ = own; library_->synaptics_lib_ = library; } diff --git a/chrome/browser/chromeos/cros/cros_library.h b/chrome/browser/chromeos/cros/cros_library.h index cfee217..3bdfa50 100644 --- a/chrome/browser/chromeos/cros/cros_library.h +++ b/chrome/browser/chromeos/cros/cros_library.h @@ -31,24 +31,22 @@ class CrosLibrary { // mock objects). class TestApi { public: - // Passing true for own for these setters will cause them to be deleted - // when the CrosLibrary is deleted (or other mocks are set). // Setter for LibraryLoader. - void SetLibraryLoader(LibraryLoader* loader, bool own); + void SetLibraryLoader(LibraryLoader* loader); // Setter for CryptohomeLibrary. - void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own); + void SetCryptohomeLibrary(CryptohomeLibrary* library); // Setter for LanguageLibrary - void SetLanguageLibrary(LanguageLibrary* library, bool own); + void SetLanguageLibrary(LanguageLibrary* library); // Setter for LoginLibrary. - void SetLoginLibrary(LoginLibrary* library, bool own); + void SetLoginLibrary(LoginLibrary* library); // Setter for MountLibrary. - void SetMountLibrary(MountLibrary* library, bool own); + void SetMountLibrary(MountLibrary* library); // Setter for NetworkLibrary. - void SetNetworkLibrary(NetworkLibrary* library, bool own); + void SetNetworkLibrary(NetworkLibrary* library); // Setter for PowerLibrary. - void SetPowerLibrary(PowerLibrary* library, bool own); + void SetPowerLibrary(PowerLibrary* library); // Setter for SynapticsLibrary. - void SetSynapticsLibrary(SynapticsLibrary* library, bool own); + void SetSynapticsLibrary(SynapticsLibrary* library); private: friend class CrosLibrary; @@ -107,16 +105,6 @@ class CrosLibrary { NetworkLibrary* network_lib_; PowerLibrary* power_lib_; SynapticsLibrary* synaptics_lib_; - - bool own_library_loader_; - bool own_cryptohome_loader_; - bool own_language_loader_; - bool own_login_loader_; - bool own_mount_loader_; - bool own_network_loader_; - bool own_power_loader_; - bool own_synaptics_library_; - // True if libcros was successfully loaded. bool loaded_; // True if the last load attempt had an error. diff --git a/chrome/browser/chromeos/login/login_manager_view_browsertest.cc b/chrome/browser/chromeos/login/login_manager_view_browsertest.cc index 7c378fc..cf49a7c 100644 --- a/chrome/browser/chromeos/login/login_manager_view_browsertest.cc +++ b/chrome/browser/chromeos/login/login_manager_view_browsertest.cc @@ -125,21 +125,21 @@ class LoginManagerViewTest : public WizardInProcessBrowserTest { mock_login_library_ = new MockLoginLibrary(); EXPECT_CALL(*mock_login_library_, EmitLoginPromptReady()) .Times(1); - test_api()->SetLoginLibrary(mock_login_library_, true); + test_api()->SetLoginLibrary(mock_login_library_); mock_cryptohome_library_ = new MockCryptohomeLibrary(); EXPECT_CALL(*mock_cryptohome_library_, IsMounted()) .Times(AnyNumber()) .WillRepeatedly((Return(true))); - test_api()->SetCryptohomeLibrary(mock_cryptohome_library_, true); + test_api()->SetCryptohomeLibrary(mock_cryptohome_library_); LoginUtils::Set(new MockLoginUtils(kUsername, kPassword)); } virtual void TearDownInProcessBrowserTestFixture() { WizardInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); - test_api()->SetLoginLibrary(NULL, false); - test_api()->SetCryptohomeLibrary(NULL, false); + test_api()->SetLoginLibrary(NULL); + test_api()->SetCryptohomeLibrary(NULL); } private: diff --git a/chrome/browser/chromeos/login/network_screen_browsertest.cc b/chrome/browser/chromeos/login/network_screen_browsertest.cc index b0cda72..e151e83 100644 --- a/chrome/browser/chromeos/login/network_screen_browsertest.cc +++ b/chrome/browser/chromeos/login/network_screen_browsertest.cc @@ -46,7 +46,7 @@ class NetworkScreenTest : public WizardInProcessBrowserTest { InitStatusAreaMocks(); mock_login_library_ = new MockLoginLibrary(); - test_api()->SetLoginLibrary(mock_login_library_, true); + test_api()->SetLoginLibrary(mock_login_library_); EXPECT_CALL(*mock_login_library_, EmitLoginPromptReady()) .Times(1); @@ -75,7 +75,7 @@ class NetworkScreenTest : public WizardInProcessBrowserTest { virtual void TearDownInProcessBrowserTestFixture() { CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture(); - test_api()->SetLoginLibrary(NULL, false); + test_api()->SetLoginLibrary(NULL); } void EthernetExpectations(bool connected, bool connecting) { -- cgit v1.1