Index: chrome/browser/password_manager/native_backend_gnome_x_unittest.cc |
diff --git a/chrome/browser/password_manager/native_backend_gnome_x_unittest.cc b/chrome/browser/password_manager/native_backend_gnome_x_unittest.cc |
index 92e5bc9f4eb9c7003741572c12218fcca7134c93..eb0e44d45e6b043e4a31059697acc347c3979898 100644 |
--- a/chrome/browser/password_manager/native_backend_gnome_x_unittest.cc |
+++ b/chrome/browser/password_manager/native_backend_gnome_x_unittest.cc |
@@ -257,7 +257,23 @@ const gchar* mock_gnome_keyring_result_to_message(GnomeKeyringResult res) { |
return "mock keyring simulating failure"; |
} |
-} // namespace |
+// Inherit to get access to protected fields. |
+class MockGnomeKeyringLoader : public GnomeKeyringLoader { |
+ public: |
+ static bool LoadMockGnomeKeyring() { |
+#define GNOME_KEYRING_ASSIGN_POINTER(name) \ |
+ gnome_keyring_##name = &mock_gnome_keyring_##name; |
+ GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_ASSIGN_POINTER) |
+#undef GNOME_KEYRING_ASSIGN_POINTER |
+ keyring_loaded = true; |
+ // Reset the state of the mock library. |
+ mock_keyring_items.clear(); |
+ mock_keyring_reject_local_ids = false; |
+ return true; |
+ } |
+}; |
+ |
+} // anonymous namespace |
class NativeBackendGnomeTest : public testing::Test { |
protected: |
@@ -269,6 +285,8 @@ class NativeBackendGnomeTest : public testing::Test { |
virtual void SetUp() { |
ASSERT_TRUE(db_thread_.Start()); |
+ MockGnomeKeyringLoader::LoadMockGnomeKeyring(); |
+ |
form_google_.origin = GURL("http://www.google.com/"); |
form_google_.action = GURL("http://www.google.com/login"); |
form_google_.username_element = UTF8ToUTF16("user"); |
@@ -294,20 +312,6 @@ class NativeBackendGnomeTest : public testing::Test { |
db_thread_.Stop(); |
} |
- static void SetUpMockKeyring(NativeBackendGnome* backend) { |
- LibGnomeKeyringLoader* loader = backend->libgnome_keyring_loader(); |
- loader->gnome_keyring_is_available = &mock_gnome_keyring_is_available; |
- loader->gnome_keyring_store_password = &mock_gnome_keyring_store_password; |
- loader->gnome_keyring_delete_password = &mock_gnome_keyring_delete_password; |
- loader->gnome_keyring_find_itemsv = &mock_gnome_keyring_find_itemsv; |
- loader->gnome_keyring_result_to_message = |
- &mock_gnome_keyring_result_to_message; |
- |
- // Reset the state of the mock library. |
- mock_keyring_items.clear(); |
- mock_keyring_reject_local_ids = false; |
- } |
- |
void RunBothThreads() { |
// First we post a message to the DB thread that will run after all other |
// messages that have been posted to the DB thread (we don't expect more |
@@ -391,7 +395,6 @@ TEST_F(NativeBackendGnomeTest, BasicAddLogin) { |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
BrowserThread::PostTask( |
BrowserThread::DB, FROM_HERE, |
@@ -411,7 +414,6 @@ TEST_F(NativeBackendGnomeTest, BasicListLogins) { |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
BrowserThread::PostTask( |
BrowserThread::DB, FROM_HERE, |
@@ -442,7 +444,6 @@ TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
BrowserThread::PostTask( |
BrowserThread::DB, FROM_HERE, |
@@ -471,7 +472,6 @@ TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
// First add an unrelated login. |
BrowserThread::PostTask( |
@@ -516,7 +516,6 @@ TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
BrowserThread::PostTask( |
BrowserThread::DB, FROM_HERE, |
@@ -540,7 +539,6 @@ TEST_F(NativeBackendGnomeTest, ListLoginsAppends) { |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
BrowserThread::PostTask( |
BrowserThread::DB, FROM_HERE, |
@@ -580,7 +578,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_MigrateOneLogin) { |
{ |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
@@ -611,7 +608,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_MigrateOneLogin) { |
{ |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
// This should not trigger migration because there will be no results. |
std::vector<PasswordForm*> form_list; |
@@ -639,7 +635,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_MigrateOneLogin) { |
{ |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
// Trigger the migration by looking something up. |
std::vector<PasswordForm*> form_list; |
@@ -674,7 +669,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_MigrateToMultipleProfiles) { |
{ |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
BrowserThread::PostTask( |
BrowserThread::DB, FROM_HERE, |
@@ -694,7 +688,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_MigrateToMultipleProfiles) { |
{ |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
// Trigger the migration by looking something up. |
std::vector<PasswordForm*> form_list; |
@@ -728,7 +721,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_MigrateToMultipleProfiles) { |
{ |
NativeBackendGnome backend(24, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
// Trigger the migration by looking something up. |
std::vector<PasswordForm*> form_list; |
@@ -761,7 +753,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_NoMigrationWithPrefSet) { |
{ |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
BrowserThread::PostTask( |
BrowserThread::DB, FROM_HERE, |
@@ -782,7 +773,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_NoMigrationWithPrefSet) { |
{ |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
// Trigger the migration by adding a new login. |
BrowserThread::PostTask( |
@@ -821,7 +811,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_DeleteMigratedPasswordIsIsolated) { |
{ |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
BrowserThread::PostTask( |
BrowserThread::DB, FROM_HERE, |
@@ -841,7 +830,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_DeleteMigratedPasswordIsIsolated) { |
{ |
NativeBackendGnome backend(42, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
// Trigger the migration by looking something up. |
std::vector<PasswordForm*> form_list; |
@@ -875,7 +863,6 @@ TEST_F(NativeBackendGnomeTest, DISABLED_DeleteMigratedPasswordIsIsolated) { |
{ |
NativeBackendGnome backend(24, profile_.GetPrefs()); |
backend.Init(); |
- SetUpMockKeyring(&backend); |
// Trigger the migration by looking something up. |
std::vector<PasswordForm*> form_list; |