Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 10168017: Only enable password generation if password manager and autofill are both (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux_asan Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/autofill_manager_unittest.cc
diff --git a/chrome/browser/autofill/autofill_manager_unittest.cc b/chrome/browser/autofill/autofill_manager_unittest.cc
index bfef7ff99f916c816185e53b8d825ea4541d84bd..37fc438abab6de56cd8058f987ae5f9aabd038f1 100644
--- a/chrome/browser/autofill/autofill_manager_unittest.cc
+++ b/chrome/browser/autofill/autofill_manager_unittest.cc
@@ -488,7 +488,7 @@ class TestAutofillManager : public AutofillManager {
submitted_form_signature_ = submitted_form.FormSignature();
}
- virtual void SendPasswordSyncStateToRenderer(
+ virtual void SendPasswordGenerationStateToRenderer(
content::RenderViewHost* host, bool enabled) OVERRIDE {
sent_states_.push_back(enabled);
}
@@ -566,10 +566,12 @@ class AutofillManagerTest : public TabContentsWrapperTestHarness {
}
virtual void SetUp() OVERRIDE {
- Profile* profile = new TestingProfile();
- browser_context_.reset(profile);
- PersonalDataManagerFactory::GetInstance()->SetTestingFactory(
- profile, TestPersonalDataManager::Build);
+ if (!browser_context_.get()) {
+ Profile* profile = new TestingProfile();
+ browser_context_.reset(profile);
+ PersonalDataManagerFactory::GetInstance()->SetTestingFactory(
+ profile, TestPersonalDataManager::Build);
+ }
TabContentsWrapperTestHarness::SetUp();
autofill_manager_ = new TestAutofillManager(contents_wrapper(),
@@ -583,8 +585,18 @@ class AutofillManagerTest : public TabContentsWrapperTestHarness {
TabContentsWrapperTestHarness::TearDown();
}
- void UpdatePasswordSyncState(bool new_renderer) {
- autofill_manager_->UpdatePasswordSyncState(NULL, new_renderer);
+ void GoOffTheRecord() {
+ TearDown();
Ilya Sherman 2012/04/24 00:46:54 Hmm, I'm not sure this is safe. For example, chro
Garrett Casto 2012/04/24 18:49:56 I'm not sure how this is different from the normal
+ other_browser_context_.reset(new TestingProfile());
+ Profile* incognito =
+ Profile::FromBrowserContext(
+ other_browser_context_.get())->GetOffTheRecordProfile();
+ browser_context_.reset(incognito);
+ SetUp();
+ }
+
+ void UpdatePasswordGenerationState(bool new_renderer) {
+ autofill_manager_->UpdatePasswordGenerationState(NULL, new_renderer);
}
void GetAutofillSuggestions(int query_id,
@@ -684,6 +696,10 @@ class AutofillManagerTest : public TabContentsWrapperTestHarness {
scoped_refptr<TestAutofillManager> autofill_manager_;
TestPersonalDataManager personal_data_;
+ // Used when we want an off the record profile. This will store the original
+ // profile from which the off the record profile is derived.
+ scoped_ptr<Profile> other_browser_context_;
+
private:
DISALLOW_COPY_AND_ASSIGN(AutofillManagerTest);
};
@@ -2887,7 +2903,7 @@ TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) {
FormSubmitted(form);
}
-TEST_F(AutofillManagerTest, UpdatePasswordSyncState) {
+TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) {
// Allow this test to control what should get synced.
profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
@@ -2900,13 +2916,13 @@ TEST_F(AutofillManagerTest, UpdatePasswordSyncState) {
preferred_set.Put(syncable::PREFERENCES);
sync_service->ChangePreferredDataTypes(preferred_set);
syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes();
- UpdatePasswordSyncState(false);
+ UpdatePasswordGenerationState(false);
EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
// Now sync passwords.
preferred_set.Put(syncable::PASSWORDS);
sync_service->ChangePreferredDataTypes(preferred_set);
- UpdatePasswordSyncState(false);
+ UpdatePasswordGenerationState(false);
EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
EXPECT_TRUE(autofill_manager_->GetSentStates()[0]);
autofill_manager_->ClearSentStates();
@@ -2914,19 +2930,26 @@ TEST_F(AutofillManagerTest, UpdatePasswordSyncState) {
// Add some additional synced state. Nothing should be sent.
preferred_set.Put(syncable::THEMES);
sync_service->ChangePreferredDataTypes(preferred_set);
- UpdatePasswordSyncState(false);
+ UpdatePasswordGenerationState(false);
EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
- // Disable syncing. This should be sent.
Ilya Sherman 2012/04/24 00:46:54 Hmm, why is this case (disabling sync) removed fro
Garrett Casto 2012/04/24 18:49:56 Re-added. Just got lost in the shuffle.
- sync_service->DisableForUser();
- UpdatePasswordSyncState(false);
+ // Disable autofill. This should be sent.
+ autofill_manager_->set_autofill_enabled(false);
+ UpdatePasswordGenerationState(false);
EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
autofill_manager_->ClearSentStates();
+ // Now re-enable autofill, but disable password manager by going incognito.
+ // This should still leave the feature disabled, and shouldn't send anything.
Ilya Sherman 2012/04/24 00:46:54 nit: The "still" in this comment seems a little bi
Garrett Casto 2012/04/24 18:49:56 N/A
+ GoOffTheRecord();
+ autofill_manager_->set_autofill_enabled(true);
+ UpdatePasswordGenerationState(false);
+ EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
+
// When a new render_view is created, we send the state even if it's the
// same.
- UpdatePasswordSyncState(true);
+ UpdatePasswordGenerationState(true);
EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
autofill_manager_->ClearSentStates();

Powered by Google App Engine
This is Rietveld 408576698