summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/autofill_manager_unittest.cc
diff options
context:
space:
mode:
authorgcasto@chromium.org <gcasto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-04 00:39:42 +0000
committergcasto@chromium.org <gcasto@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-04 00:39:42 +0000
commit6dcaeae807dffd3784b45625cf746bfd882f2828 (patch)
treef6d6fdcef9760c4062f0caa6f5cf1b2fbf67d675 /chrome/browser/autofill/autofill_manager_unittest.cc
parentf6cb7cafbdde72f71c8b78179542d2392350b2ae (diff)
downloadchromium_src-6dcaeae807dffd3784b45625cf746bfd882f2828.zip
chromium_src-6dcaeae807dffd3784b45625cf746bfd882f2828.tar.gz
chromium_src-6dcaeae807dffd3784b45625cf746bfd882f2828.tar.bz2
Enable password generation only if sync for passwords is enabled.
This is the second try at this change. The first failed because the ProfileSyncService apparently does not always outlive the autofill_manager. Fixed by using a WeakPtr. BUG=114092 TEST=Ran memory try bots. Review URL: https://chromiumcodereview.appspot.com/9950051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@130523 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/autofill_manager_unittest.cc')
-rw-r--r--chrome/browser/autofill/autofill_manager_unittest.cc61
1 files changed, 61 insertions, 0 deletions
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index a50cff2..8695d44 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -23,6 +23,7 @@
#include "chrome/browser/autofill/test_autofill_external_delegate.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h"
@@ -486,6 +487,19 @@ class TestAutofillManager : public AutofillManager {
submitted_form_signature_ = submitted_form.FormSignature();
}
+ virtual void SendPasswordSyncStateToRenderer(
+ content::RenderViewHost* host, bool enabled) OVERRIDE {
+ sent_states_.push_back(enabled);
+ }
+
+ const std::vector<bool>& GetSentStates() {
+ return sent_states_;
+ }
+
+ void ClearSentStates() {
+ sent_states_.clear();
+ }
+
const std::string GetSubmittedFormSignature() {
return submitted_form_signature_;
}
@@ -527,6 +541,7 @@ class TestAutofillManager : public AutofillManager {
std::string submitted_form_signature_;
std::vector<FieldTypeSet> expected_submitted_field_types_;
+ std::vector<bool> sent_states_;
DISALLOW_COPY_AND_ASSIGN(TestAutofillManager);
};
@@ -567,6 +582,10 @@ class AutofillManagerTest : public TabContentsWrapperTestHarness {
TabContentsWrapperTestHarness::TearDown();
}
+ void UpdatePasswordSyncState() {
+ autofill_manager_->UpdatePasswordSyncState(NULL);
+ }
+
void GetAutofillSuggestions(int query_id,
const webkit::forms::FormData& form,
const webkit::forms::FormField& field) {
@@ -653,6 +672,10 @@ class AutofillManagerTest : public TabContentsWrapperTestHarness {
return true;
}
+ ProfileSyncService* GetProfileSyncService() {
+ return autofill_manager_->sync_service_;
+ }
+
protected:
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
@@ -2862,6 +2885,44 @@ TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) {
FormSubmitted(form);
}
+TEST_F(AutofillManagerTest, UpdatePasswordSyncState) {
+ // Allow this test to control what should get synced.
+ profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
+
+ // Sync some things, but not passwords. Shouldn't send anything since
+ // password generation is disabled by default.
+ ProfileSyncService* sync_service = GetProfileSyncService();
+ sync_service->SetSyncSetupCompleted();
+ syncable::ModelTypeSet preferred_set;
+ preferred_set.Put(syncable::EXTENSIONS);
+ preferred_set.Put(syncable::PREFERENCES);
+ sync_service->ChangePreferredDataTypes(preferred_set);
+ syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes();
+ UpdatePasswordSyncState();
+ EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
+
+ // Now sync passwords.
+ preferred_set.Put(syncable::PASSWORDS);
+ sync_service->ChangePreferredDataTypes(preferred_set);
+ UpdatePasswordSyncState();
+ EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
+ EXPECT_EQ(true, autofill_manager_->GetSentStates()[0]);
+ autofill_manager_->ClearSentStates();
+
+ // Add some additional synced state. Nothing should be sent.
+ preferred_set.Put(syncable::THEMES);
+ sync_service->ChangePreferredDataTypes(preferred_set);
+ UpdatePasswordSyncState();
+ EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
+
+ // Disable syncing. This should be sent.
+ sync_service->DisableForUser();
+ UpdatePasswordSyncState();
+ EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
+ EXPECT_EQ(false, autofill_manager_->GetSentStates()[0]);
+ autofill_manager_->ClearSentStates();
+}
+
namespace {
class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {