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

Side by Side Diff: chrome/browser/autofill/autofill_manager_unittest.cc

Issue 10222017: Make password generation switched by a preference in chrome settings rather than a command line fla… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make password generation checkbox hidden by the command flag. Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 2873 matching lines...) Expand 10 before | Expand all | Expand 10 after
2884 autofill_test::CreateTestFormField("", "20", "901", "text", &field); 2884 autofill_test::CreateTestFormField("", "20", "901", "text", &field);
2885 types.clear(); 2885 types.clear();
2886 types.insert(UNKNOWN_TYPE); 2886 types.insert(UNKNOWN_TYPE);
2887 form.fields.push_back(field); 2887 form.fields.push_back(field);
2888 expected_types.push_back(types); 2888 expected_types.push_back(types);
2889 2889
2890 autofill_manager_->set_expected_submitted_field_types(expected_types); 2890 autofill_manager_->set_expected_submitted_field_types(expected_types);
2891 FormSubmitted(form); 2891 FormSubmitted(form);
2892 } 2892 }
2893 2893
2894 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) { 2894 TEST_F(AutofillManagerTest, UpdatePasswordSyncState) {
2895 // Allow this test to control what should get synced. 2895 // Allow this test to control what should get synced.
2896 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false); 2896 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
2897 // Always set password generation enabled check box so we can test the
2898 // behavior of password sync.
2899 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true);
2897 2900
2898 // Sync some things, but not passwords. Shouldn't send anything since 2901 // Sync some things, but not passwords. Shouldn't send anything since
2899 // password generation is disabled by default. 2902 // password generation is disabled by default.
2900 ProfileSyncService* sync_service = GetProfileSyncService(); 2903 ProfileSyncService* sync_service = GetProfileSyncService();
2901 sync_service->SetSyncSetupCompleted(); 2904 sync_service->SetSyncSetupCompleted();
2902 syncable::ModelTypeSet preferred_set; 2905 syncable::ModelTypeSet preferred_set;
2903 preferred_set.Put(syncable::EXTENSIONS); 2906 preferred_set.Put(syncable::EXTENSIONS);
2904 preferred_set.Put(syncable::PREFERENCES); 2907 preferred_set.Put(syncable::PREFERENCES);
2905 sync_service->ChangePreferredDataTypes(preferred_set); 2908 sync_service->ChangePreferredDataTypes(preferred_set);
2906 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); 2909 syncable::ModelTypeSet new_set = sync_service->GetPreferredDataTypes();
(...skipping 29 matching lines...) Expand all
2936 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size()); 2939 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
2937 2940
2938 // When a new render_view is created, we send the state even if it's the 2941 // When a new render_view is created, we send the state even if it's the
2939 // same. 2942 // same.
2940 UpdatePasswordGenerationState(true); 2943 UpdatePasswordGenerationState(true);
2941 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size()); 2944 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
2942 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]); 2945 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
2943 autofill_manager_->ClearSentStates(); 2946 autofill_manager_->ClearSentStates();
2944 } 2947 }
2945 2948
2949 TEST_F(AutofillManagerTest, UpdatePasswordGenerationState) {
2950 // Always set password sync enabled so we can test the behavior of password
2951 // generation.
2952 profile()->GetPrefs()->SetBoolean(prefs::kSyncKeepEverythingSynced, false);
2953 ProfileSyncService* sync_service = GetProfileSyncService();
2954 sync_service->SetSyncSetupCompleted();
2955 syncable::ModelTypeSet preferred_set;
2956 preferred_set.Put(syncable::PASSWORDS);
2957 sync_service->ChangePreferredDataTypes(preferred_set);
2958
2959 // Enabled state remains false, should not sent.
2960 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false);
2961 UpdatePasswordGenerationState(false);
2962 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
2963
2964 // Enabled state from false to true, should sent true.
2965 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true);
2966 UpdatePasswordGenerationState(false);
2967 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
2968 EXPECT_TRUE(autofill_manager_->GetSentStates()[0]);
2969 autofill_manager_->ClearSentStates();
2970
2971 // Enabled states remains true, should not sent.
2972 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, true);
2973 UpdatePasswordGenerationState(false);
2974 EXPECT_EQ(0u, autofill_manager_->GetSentStates().size());
2975
2976 // Enabled states from true to false, should sent false.
2977 profile()->GetPrefs()->SetBoolean(prefs::kPasswordGenerationEnabled, false);
2978 UpdatePasswordGenerationState(false);
2979 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
2980 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
2981 autofill_manager_->ClearSentStates();
2982
2983 // When a new render_view is created, we send the state even if it's the
2984 // same.
2985 UpdatePasswordGenerationState(true);
2986 EXPECT_EQ(1u, autofill_manager_->GetSentStates().size());
2987 EXPECT_FALSE(autofill_manager_->GetSentStates()[0]);
2988 autofill_manager_->ClearSentStates();
2989 }
Ilya Sherman 2012/05/01 22:27:48 nit: Please leave a blank line after this closing
zysxqn 2012/05/03 00:57:24 Done.
2946 namespace { 2990 namespace {
2947 2991
2948 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate { 2992 class MockAutofillExternalDelegate : public TestAutofillExternalDelegate {
2949 public: 2993 public:
2950 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper, 2994 explicit MockAutofillExternalDelegate(TabContentsWrapper* wrapper,
2951 AutofillManager* autofill_manager) 2995 AutofillManager* autofill_manager)
2952 : TestAutofillExternalDelegate(wrapper, autofill_manager) {} 2996 : TestAutofillExternalDelegate(wrapper, autofill_manager) {}
2953 virtual ~MockAutofillExternalDelegate() {} 2997 virtual ~MockAutofillExternalDelegate() {}
2954 2998
2955 MOCK_METHOD5(OnQuery, void(int query_id, 2999 MOCK_METHOD5(OnQuery, void(int query_id,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3003 3047
3004 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager(); 3048 AutofillManager* autofill_manager = contents_wrapper()->autofill_manager();
3005 EXPECT_TRUE(autofill_manager->external_delegate()); 3049 EXPECT_TRUE(autofill_manager->external_delegate());
3006 3050
3007 AutocompleteHistoryManager* autocomplete_history_manager = 3051 AutocompleteHistoryManager* autocomplete_history_manager =
3008 contents_wrapper()->autocomplete_history_manager(); 3052 contents_wrapper()->autocomplete_history_manager();
3009 EXPECT_TRUE(autocomplete_history_manager->external_delegate()); 3053 EXPECT_TRUE(autocomplete_history_manager->external_delegate());
3010 } 3054 }
3011 3055
3012 #endif // OS_ANDROID 3056 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698