summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-19 20:29:36 +0000
committerdavemoore@chromium.org <davemoore@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-19 20:29:36 +0000
commit2024513b9c22eb479f14948169cc94dd2163a952 (patch)
tree7290a2b7f9e776a3a46605d4b997adea78c2fa83
parent6c9d9b18c4cf4112d2b6f113ab7b19b35e083743 (diff)
downloadchromium_src-2024513b9c22eb479f14948169cc94dd2163a952.zip
chromium_src-2024513b9c22eb479f14948169cc94dd2163a952.tar.gz
chromium_src-2024513b9c22eb479f14948169cc94dd2163a952.tar.bz2
Added new arg to google_authenticator_unittest so it would build.
TBR:cmasone Revert "Revert 44935 - Allow mocking of cros api without automatically deleting the mocks" This reverts commit 6113af35343e47bb584395d387aba96b7c435277. Review URL: http://codereview.chromium.org/1627028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44945 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/cros/cros_in_process_browser_test.cc30
-rw-r--r--chrome/browser/chromeos/cros/cros_in_process_browser_test.h4
-rw-r--r--chrome/browser/chromeos/cros/cros_library.cc68
-rw-r--r--chrome/browser/chromeos/cros/cros_library.h28
-rw-r--r--chrome/browser/chromeos/login/google_authenticator_unittest.cc8
-rw-r--r--chrome/browser/chromeos/login/login_manager_view_browsertest.cc8
-rw-r--r--chrome/browser/chromeos/login/network_screen_browsertest.cc4
7 files changed, 98 insertions, 52 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 6d5c99b..467e674 100644
--- a/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc
+++ b/chrome/browser/chromeos/cros/cros_in_process_browser_test.cc
@@ -51,7 +51,15 @@ void CrosInProcessBrowserTest::InitMockLibraryLoader() {
EXPECT_CALL(*loader_, Load(_))
.Times(AnyNumber())
.WillRepeatedly(Return(true));
- test_api()->SetLibraryLoader(loader_);
+ 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);
}
void CrosInProcessBrowserTest::InitMockLanguageLibrary() {
@@ -59,7 +67,7 @@ void CrosInProcessBrowserTest::InitMockLanguageLibrary() {
if (mock_language_library_)
return;
mock_language_library_ = new MockLanguageLibrary();
- test_api()->SetLanguageLibrary(mock_language_library_);
+ test_api()->SetLanguageLibrary(mock_language_library_, true);
}
void CrosInProcessBrowserTest::InitMockNetworkLibrary() {
@@ -67,7 +75,7 @@ void CrosInProcessBrowserTest::InitMockNetworkLibrary() {
if (mock_network_library_)
return;
mock_network_library_ = new MockNetworkLibrary();
- test_api()->SetNetworkLibrary(mock_network_library_);
+ test_api()->SetNetworkLibrary(mock_network_library_, true);
}
void CrosInProcessBrowserTest::InitMockPowerLibrary() {
@@ -75,7 +83,7 @@ void CrosInProcessBrowserTest::InitMockPowerLibrary() {
if (mock_power_library_)
return;
mock_power_library_ = new MockPowerLibrary();
- test_api()->SetPowerLibrary(mock_power_library_);
+ test_api()->SetPowerLibrary(mock_power_library_, true);
}
void CrosInProcessBrowserTest::InitMockSynapticsLibrary() {
@@ -83,7 +91,7 @@ void CrosInProcessBrowserTest::InitMockSynapticsLibrary() {
if (mock_synaptics_library_)
return;
mock_synaptics_library_ = new MockSynapticsLibrary();
- test_api()->SetSynapticsLibrary(mock_synaptics_library_);
+ test_api()->SetSynapticsLibrary(mock_synaptics_library_, true);
}
void CrosInProcessBrowserTest::SetStatusAreaMocksExpectations() {
@@ -190,15 +198,17 @@ void CrosInProcessBrowserTest::SetSynapticsLibraryExpectations() {
void CrosInProcessBrowserTest::TearDownInProcessBrowserTestFixture() {
// Prevent bogus gMock leak check from firing.
if (loader_)
- test_api()->SetLibraryLoader(NULL);
+ test_api()->SetLibraryLoader(NULL, false);
+ if (mock_cryptohome_library_)
+ test_api()->SetCryptohomeLibrary(NULL, false);
if (mock_language_library_)
- test_api()->SetLanguageLibrary(NULL);
+ test_api()->SetLanguageLibrary(NULL, false);
if (mock_network_library_)
- test_api()->SetNetworkLibrary(NULL);
+ test_api()->SetNetworkLibrary(NULL, false);
if (mock_power_library_)
- test_api()->SetPowerLibrary(NULL);
+ test_api()->SetPowerLibrary(NULL, false);
if (mock_synaptics_library_)
- test_api()->SetSynapticsLibrary(NULL);
+ test_api()->SetSynapticsLibrary(NULL, false);
}
} // 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 6e01bc2..524ad93 100644
--- a/chrome/browser/chromeos/cros/cros_in_process_browser_test.h
+++ b/chrome/browser/chromeos/cros/cros_in_process_browser_test.h
@@ -6,6 +6,8 @@
#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"
@@ -41,6 +43,7 @@ class CrosInProcessBrowserTest : public InProcessBrowserTest {
void InitMockLibraryLoader();
// Initialization of mocks.
+ void InitMockCryptohomeLibrary();
void InitMockLanguageLibrary();
void InitMockNetworkLibrary();
void InitMockPowerLibrary();
@@ -68,6 +71,7 @@ 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 71a7f4d..388fabc 100644
--- a/chrome/browser/chromeos/cros/cros_library.cc
+++ b/chrome/browser/chromeos/cros/cros_library.cc
@@ -23,6 +23,14 @@ 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) {
@@ -30,21 +38,21 @@ CrosLibrary::CrosLibrary() : library_loader_(NULL),
}
CrosLibrary::~CrosLibrary() {
- if (library_loader_)
+ if (own_library_loader_ && library_loader_)
delete library_loader_;
- if (crypto_lib_)
+ if (own_cryptohome_loader_ && crypto_lib_)
delete crypto_lib_;
- if (language_lib_)
+ if (own_language_loader_ && language_lib_)
delete language_lib_;
- if (login_lib_)
+ if (own_login_loader_ && login_lib_)
delete login_lib_;
- if (mount_lib_)
+ if (own_mount_loader_ && mount_lib_)
delete mount_lib_;
- if (network_lib_)
+ if (own_network_loader_ && network_lib_)
delete network_lib_;
- if (power_lib_)
+ if (own_power_loader_ && power_lib_)
delete power_lib_;
- if (synaptics_lib_)
+ if (own_synaptics_library_ && synaptics_lib_)
delete synaptics_lib_;
if (test_api_)
delete test_api_;
@@ -113,11 +121,12 @@ CrosLibrary::TestApi* CrosLibrary::GetTestApi() {
return test_api_;
}
-void CrosLibrary::TestApi::SetLibraryLoader(LibraryLoader* loader) {
+void CrosLibrary::TestApi::SetLibraryLoader(LibraryLoader* loader, bool own) {
if (library_->library_loader_ == loader)
return;
- if (library_->library_loader_)
+ if (library_->own_library_loader_ && 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.
@@ -125,45 +134,56 @@ void CrosLibrary::TestApi::SetLibraryLoader(LibraryLoader* loader) {
library_->load_error_ = false;
}
-void CrosLibrary::TestApi::SetCryptohomeLibrary(CryptohomeLibrary* library) {
- if (library_->crypto_lib_)
+void CrosLibrary::TestApi::SetCryptohomeLibrary(CryptohomeLibrary* library,
+ bool own) {
+ if (library_->own_cryptohome_loader_ && library_->crypto_lib_)
delete library_->crypto_lib_;
+ library_->own_cryptohome_loader_ = own;
library_->crypto_lib_ = library;
}
-void CrosLibrary::TestApi::SetLanguageLibrary(LanguageLibrary* library) {
- if (library_->language_lib_)
+void CrosLibrary::TestApi::SetLanguageLibrary(LanguageLibrary* library,
+ bool own) {
+ if (library_->own_language_loader_ && library_->language_lib_)
delete library_->language_lib_;
+ library_->own_language_loader_ = own;
library_->language_lib_ = library;
}
-void CrosLibrary::TestApi::SetLoginLibrary(LoginLibrary* library) {
- if (library_->login_lib_)
+void CrosLibrary::TestApi::SetLoginLibrary(LoginLibrary* library, bool own) {
+ if (library_->own_login_loader_ && library_->login_lib_)
delete library_->login_lib_;
+ library_->own_login_loader_ = own;
library_->login_lib_ = library;
}
-void CrosLibrary::TestApi::SetMountLibrary(MountLibrary* library) {
- if (library_->mount_lib_)
+void CrosLibrary::TestApi::SetMountLibrary(MountLibrary* library, bool own) {
+ if (library_->own_mount_loader_ && library_->mount_lib_)
delete library_->mount_lib_;
+ library_->own_mount_loader_ = own;
library_->mount_lib_ = library;
}
-void CrosLibrary::TestApi::SetNetworkLibrary(NetworkLibrary* library) {
- if (library_->network_lib_)
+void CrosLibrary::TestApi::SetNetworkLibrary(NetworkLibrary* library,
+ bool own) {
+ if (library_->own_network_loader_ && library_->network_lib_)
delete library_->network_lib_;
+ library_->own_network_loader_ = own;
library_->network_lib_ = library;
}
-void CrosLibrary::TestApi::SetPowerLibrary(PowerLibrary* library) {
- if (library_->power_lib_)
+void CrosLibrary::TestApi::SetPowerLibrary(PowerLibrary* library, bool own) {
+ if (library_->own_power_loader_ && library_->power_lib_)
delete library_->power_lib_;
+ library_->own_power_loader_ = own;
library_->power_lib_ = library;
}
-void CrosLibrary::TestApi::SetSynapticsLibrary(SynapticsLibrary* library) {
- if (library_->synaptics_lib_)
+void CrosLibrary::TestApi::SetSynapticsLibrary(SynapticsLibrary* library,
+ bool own) {
+ if (library_->own_synaptics_library_ && 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 3bdfa50..cfee217 100644
--- a/chrome/browser/chromeos/cros/cros_library.h
+++ b/chrome/browser/chromeos/cros/cros_library.h
@@ -31,22 +31,24 @@ 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);
+ void SetLibraryLoader(LibraryLoader* loader, bool own);
// Setter for CryptohomeLibrary.
- void SetCryptohomeLibrary(CryptohomeLibrary* library);
+ void SetCryptohomeLibrary(CryptohomeLibrary* library, bool own);
// Setter for LanguageLibrary
- void SetLanguageLibrary(LanguageLibrary* library);
+ void SetLanguageLibrary(LanguageLibrary* library, bool own);
// Setter for LoginLibrary.
- void SetLoginLibrary(LoginLibrary* library);
+ void SetLoginLibrary(LoginLibrary* library, bool own);
// Setter for MountLibrary.
- void SetMountLibrary(MountLibrary* library);
+ void SetMountLibrary(MountLibrary* library, bool own);
// Setter for NetworkLibrary.
- void SetNetworkLibrary(NetworkLibrary* library);
+ void SetNetworkLibrary(NetworkLibrary* library, bool own);
// Setter for PowerLibrary.
- void SetPowerLibrary(PowerLibrary* library);
+ void SetPowerLibrary(PowerLibrary* library, bool own);
// Setter for SynapticsLibrary.
- void SetSynapticsLibrary(SynapticsLibrary* library);
+ void SetSynapticsLibrary(SynapticsLibrary* library, bool own);
private:
friend class CrosLibrary;
@@ -105,6 +107,16 @@ 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/google_authenticator_unittest.cc b/chrome/browser/chromeos/login/google_authenticator_unittest.cc
index 4d2fad0..e11a3c2 100644
--- a/chrome/browser/chromeos/login/google_authenticator_unittest.cc
+++ b/chrome/browser/chromeos/login/google_authenticator_unittest.cc
@@ -71,10 +71,10 @@ class GoogleAuthenticatorTest : public ::testing::Test {
EXPECT_CALL(*loader_, Load(_))
.Times(AnyNumber());
- test_api->SetLibraryLoader(loader_);
+ test_api->SetLibraryLoader(loader_, true);
mock_library_ = new MockCryptohomeLibrary();
- test_api->SetCryptohomeLibrary(mock_library_);
+ test_api->SetCryptohomeLibrary(mock_library_, true);
}
// Tears down the test fixture.
@@ -82,8 +82,8 @@ class GoogleAuthenticatorTest : public ::testing::Test {
// Prevent bogus gMock leak check from firing.
chromeos::CrosLibrary::TestApi* test_api =
chromeos::CrosLibrary::Get()->GetTestApi();
- test_api->SetLibraryLoader(NULL);
- test_api->SetCryptohomeLibrary(NULL);
+ test_api->SetLibraryLoader(NULL, false);
+ test_api->SetCryptohomeLibrary(NULL, false);
}
FilePath PopulateTempFile(const char* data, int data_len) {
diff --git a/chrome/browser/chromeos/login/login_manager_view_browsertest.cc b/chrome/browser/chromeos/login/login_manager_view_browsertest.cc
index cf49a7c..7c378fc 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_);
+ test_api()->SetLoginLibrary(mock_login_library_, true);
mock_cryptohome_library_ = new MockCryptohomeLibrary();
EXPECT_CALL(*mock_cryptohome_library_, IsMounted())
.Times(AnyNumber())
.WillRepeatedly((Return(true)));
- test_api()->SetCryptohomeLibrary(mock_cryptohome_library_);
+ test_api()->SetCryptohomeLibrary(mock_cryptohome_library_, true);
LoginUtils::Set(new MockLoginUtils(kUsername, kPassword));
}
virtual void TearDownInProcessBrowserTestFixture() {
WizardInProcessBrowserTest::TearDownInProcessBrowserTestFixture();
- test_api()->SetLoginLibrary(NULL);
- test_api()->SetCryptohomeLibrary(NULL);
+ test_api()->SetLoginLibrary(NULL, false);
+ test_api()->SetCryptohomeLibrary(NULL, false);
}
private:
diff --git a/chrome/browser/chromeos/login/network_screen_browsertest.cc b/chrome/browser/chromeos/login/network_screen_browsertest.cc
index e151e83..b0cda72 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_);
+ test_api()->SetLoginLibrary(mock_login_library_, true);
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);
+ test_api()->SetLoginLibrary(NULL, false);
}
void EthernetExpectations(bool connected, bool connecting) {