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

Side by Side Diff: chrome/browser/ui/webui/sync_setup_handler_unittest.cc

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights Created 8 years, 5 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 "chrome/browser/ui/webui/sync_setup_handler.h" 5 #include "chrome/browser/ui/webui/sync_setup_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "chrome/browser/signin/signin_manager_fake.h"
17 #include "chrome/browser/sync/profile_sync_service_factory.h"
15 #include "chrome/browser/sync/profile_sync_service_mock.h" 18 #include "chrome/browser/sync/profile_sync_service_mock.h"
16 #include "chrome/browser/signin/signin_manager_fake.h"
17 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 19 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
20 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" 20 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
21 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" 21 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h"
22 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
25 #include "content/public/browser/web_ui.h" 25 #include "content/public/browser/web_ui.h"
26 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
(...skipping 10 matching lines...) Expand all
39 39
40 MATCHER_P(ModelTypeSetMatches, value, "") { return arg.Equals(value); } 40 MATCHER_P(ModelTypeSetMatches, value, "") { return arg.Equals(value); }
41 41
42 const char kTestUser[] = "chrome.p13n.test@gmail.com"; 42 const char kTestUser[] = "chrome.p13n.test@gmail.com";
43 const char kTestPassword[] = "passwd"; 43 const char kTestPassword[] = "passwd";
44 const char kTestCaptcha[] = "pizzamyheart"; 44 const char kTestCaptcha[] = "pizzamyheart";
45 const char kTestCaptchaImageUrl[] = "http://pizzamyheart/image"; 45 const char kTestCaptchaImageUrl[] = "http://pizzamyheart/image";
46 const char kTestCaptchaUnlockUrl[] = "http://pizzamyheart/unlock"; 46 const char kTestCaptchaUnlockUrl[] = "http://pizzamyheart/unlock";
47 47
48 // List of all the types a user can select in the sync config dialog. 48 // List of all the types a user can select in the sync config dialog.
49 const syncable::ModelType kUserSelectableTypes[] = { 49 const syncer::ModelType kUserSelectableTypes[] = {
50 syncable::APPS, 50 syncer::APPS,
51 syncable::AUTOFILL, 51 syncer::AUTOFILL,
52 syncable::BOOKMARKS, 52 syncer::BOOKMARKS,
53 syncable::EXTENSIONS, 53 syncer::EXTENSIONS,
54 syncable::PASSWORDS, 54 syncer::PASSWORDS,
55 syncable::PREFERENCES, 55 syncer::PREFERENCES,
56 syncable::SESSIONS, 56 syncer::SESSIONS,
57 syncable::THEMES, 57 syncer::THEMES,
58 syncable::TYPED_URLS 58 syncer::TYPED_URLS
59 }; 59 };
60 60
61 // Returns a ModelTypeSet with all user selectable types set. 61 // Returns a ModelTypeSet with all user selectable types set.
62 syncable::ModelTypeSet GetAllTypes() { 62 syncer::ModelTypeSet GetAllTypes() {
63 syncable::ModelTypeSet types; 63 syncer::ModelTypeSet types;
64 for (size_t i = 0; i < arraysize(kUserSelectableTypes); ++i) 64 for (size_t i = 0; i < arraysize(kUserSelectableTypes); ++i)
65 types.Put(kUserSelectableTypes[i]); 65 types.Put(kUserSelectableTypes[i]);
66 return types; 66 return types;
67 } 67 }
68 68
69 enum SyncAllDataConfig { 69 enum SyncAllDataConfig {
70 SYNC_ALL_DATA, 70 SYNC_ALL_DATA,
71 CHOOSE_WHAT_TO_SYNC 71 CHOOSE_WHAT_TO_SYNC
72 }; 72 };
73 73
74 enum EncryptAllConfig { 74 enum EncryptAllConfig {
75 ENCRYPT_ALL_DATA, 75 ENCRYPT_ALL_DATA,
76 ENCRYPT_PASSWORDS 76 ENCRYPT_PASSWORDS
77 }; 77 };
78 78
79 // Create a json-format string with the key/value pairs appropriate for a call 79 // Create a json-format string with the key/value pairs appropriate for a call
80 // to HandleConfigure(). If |extra_values| is non-null, then the values from 80 // to HandleConfigure(). If |extra_values| is non-null, then the values from
81 // the passed dictionary are added to the json. 81 // the passed dictionary are added to the json.
82 std::string GetConfiguration(const DictionaryValue* extra_values, 82 std::string GetConfiguration(const DictionaryValue* extra_values,
83 SyncAllDataConfig sync_all, 83 SyncAllDataConfig sync_all,
84 syncable::ModelTypeSet types, 84 syncer::ModelTypeSet types,
85 const std::string& passphrase, 85 const std::string& passphrase,
86 EncryptAllConfig encrypt_all) { 86 EncryptAllConfig encrypt_all) {
87 DictionaryValue result; 87 DictionaryValue result;
88 if (extra_values) 88 if (extra_values)
89 result.MergeDictionary(extra_values); 89 result.MergeDictionary(extra_values);
90 result.SetBoolean("syncAllDataTypes", sync_all == SYNC_ALL_DATA); 90 result.SetBoolean("syncAllDataTypes", sync_all == SYNC_ALL_DATA);
91 result.SetBoolean("encryptAllData", encrypt_all == ENCRYPT_ALL_DATA); 91 result.SetBoolean("encryptAllData", encrypt_all == ENCRYPT_ALL_DATA);
92 result.SetBoolean("usePassphrase", !passphrase.empty()); 92 result.SetBoolean("usePassphrase", !passphrase.empty());
93 if (!passphrase.empty()) 93 if (!passphrase.empty())
94 result.SetString("passphrase", passphrase); 94 result.SetString("passphrase", passphrase);
95 // Add all of our data types. 95 // Add all of our data types.
96 result.SetBoolean("appsSynced", types.Has(syncable::APPS)); 96 result.SetBoolean("appsSynced", types.Has(syncer::APPS));
97 result.SetBoolean("autofillSynced", types.Has(syncable::AUTOFILL)); 97 result.SetBoolean("autofillSynced", types.Has(syncer::AUTOFILL));
98 result.SetBoolean("bookmarksSynced", types.Has(syncable::BOOKMARKS)); 98 result.SetBoolean("bookmarksSynced", types.Has(syncer::BOOKMARKS));
99 result.SetBoolean("extensionsSynced", types.Has(syncable::EXTENSIONS)); 99 result.SetBoolean("extensionsSynced", types.Has(syncer::EXTENSIONS));
100 result.SetBoolean("passwordsSynced", types.Has(syncable::PASSWORDS)); 100 result.SetBoolean("passwordsSynced", types.Has(syncer::PASSWORDS));
101 result.SetBoolean("preferencesSynced", types.Has(syncable::PREFERENCES)); 101 result.SetBoolean("preferencesSynced", types.Has(syncer::PREFERENCES));
102 result.SetBoolean("sessionsSynced", types.Has(syncable::SESSIONS)); 102 result.SetBoolean("sessionsSynced", types.Has(syncer::SESSIONS));
103 result.SetBoolean("themesSynced", types.Has(syncable::THEMES)); 103 result.SetBoolean("themesSynced", types.Has(syncer::THEMES));
104 result.SetBoolean("typedUrlsSynced", types.Has(syncable::TYPED_URLS)); 104 result.SetBoolean("typedUrlsSynced", types.Has(syncer::TYPED_URLS));
105 std::string args; 105 std::string args;
106 base::JSONWriter::Write(&result, &args); 106 base::JSONWriter::Write(&result, &args);
107 return args; 107 return args;
108 } 108 }
109 109
110 void CheckInt(const DictionaryValue* dictionary, 110 void CheckInt(const DictionaryValue* dictionary,
111 const std::string& key, 111 const std::string& key,
112 int expected_value) { 112 int expected_value) {
113 int actual_value; 113 int actual_value;
114 EXPECT_TRUE(dictionary->GetInteger(key, &actual_value)) << 114 EXPECT_TRUE(dictionary->GetInteger(key, &actual_value)) <<
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 CheckInt(dictionary, "error", error); 183 CheckInt(dictionary, "error", error);
184 CheckBool(dictionary, "fatalError", fatal_error, true); 184 CheckBool(dictionary, "fatalError", fatal_error, true);
185 CheckBool(dictionary, "editableUser", user_is_editable); 185 CheckBool(dictionary, "editableUser", user_is_editable);
186 } 186 }
187 187
188 // Checks to make sure that the values stored in |dictionary| match the values 188 // Checks to make sure that the values stored in |dictionary| match the values
189 // expected by the showSyncSetupPage() JS function for a given set of data 189 // expected by the showSyncSetupPage() JS function for a given set of data
190 // types. 190 // types.
191 void CheckConfigDataTypeArguments(DictionaryValue* dictionary, 191 void CheckConfigDataTypeArguments(DictionaryValue* dictionary,
192 SyncAllDataConfig config, 192 SyncAllDataConfig config,
193 syncable::ModelTypeSet types) { 193 syncer::ModelTypeSet types) {
194 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA); 194 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA);
195 CheckBool(dictionary, "appsSynced", types.Has(syncable::APPS)); 195 CheckBool(dictionary, "appsSynced", types.Has(syncer::APPS));
196 CheckBool(dictionary, "autofillSynced", types.Has(syncable::AUTOFILL)); 196 CheckBool(dictionary, "autofillSynced", types.Has(syncer::AUTOFILL));
197 CheckBool(dictionary, "bookmarksSynced", types.Has(syncable::BOOKMARKS)); 197 CheckBool(dictionary, "bookmarksSynced", types.Has(syncer::BOOKMARKS));
198 CheckBool(dictionary, "extensionsSynced", types.Has(syncable::EXTENSIONS)); 198 CheckBool(dictionary, "extensionsSynced", types.Has(syncer::EXTENSIONS));
199 CheckBool(dictionary, "passwordsSynced", types.Has(syncable::PASSWORDS)); 199 CheckBool(dictionary, "passwordsSynced", types.Has(syncer::PASSWORDS));
200 CheckBool(dictionary, "preferencesSynced", types.Has(syncable::PREFERENCES)); 200 CheckBool(dictionary, "preferencesSynced", types.Has(syncer::PREFERENCES));
201 CheckBool(dictionary, "sessionsSynced", types.Has(syncable::SESSIONS)); 201 CheckBool(dictionary, "sessionsSynced", types.Has(syncer::SESSIONS));
202 CheckBool(dictionary, "themesSynced", types.Has(syncable::THEMES)); 202 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES));
203 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncable::TYPED_URLS)); 203 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS));
204 } 204 }
205 205
206 206
207 } // namespace 207 } // namespace
208 208
209 // Test instance of WebUI that tracks the data passed to 209 // Test instance of WebUI that tracks the data passed to
210 // CallJavascriptFunction(). 210 // CallJavascriptFunction().
211 class TestWebUI : public content::WebUI { 211 class TestWebUI : public content::WebUI {
212 public: 212 public:
213 virtual ~TestWebUI() { 213 virtual ~TestWebUI() {
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 const TestWebUI::CallData& data = web_ui_.call_data()[0]; 874 const TestWebUI::CallData& data = web_ui_.call_data()[0];
875 DictionaryValue* dictionary; 875 DictionaryValue* dictionary;
876 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); 876 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
877 CheckBool(dictionary, "passphraseFailed", true); 877 CheckBool(dictionary, "passphraseFailed", true);
878 } 878 }
879 879
880 // Walks through each user selectable type, and tries to sync just that single 880 // Walks through each user selectable type, and tries to sync just that single
881 // data type. 881 // data type.
882 TEST_P(SyncSetupHandlerTest, TestSyncIndividualTypes) { 882 TEST_P(SyncSetupHandlerTest, TestSyncIndividualTypes) {
883 for (size_t i = 0; i < arraysize(kUserSelectableTypes); ++i) { 883 for (size_t i = 0; i < arraysize(kUserSelectableTypes); ++i) {
884 syncable::ModelTypeSet type_to_set; 884 syncer::ModelTypeSet type_to_set;
885 type_to_set.Put(kUserSelectableTypes[i]); 885 type_to_set.Put(kUserSelectableTypes[i]);
886 std::string args = GetConfiguration( 886 std::string args = GetConfiguration(
887 NULL, CHOOSE_WHAT_TO_SYNC, type_to_set, "", ENCRYPT_PASSWORDS); 887 NULL, CHOOSE_WHAT_TO_SYNC, type_to_set, "", ENCRYPT_PASSWORDS);
888 ListValue list_args; 888 ListValue list_args;
889 list_args.Append(new StringValue(args)); 889 list_args.Append(new StringValue(args));
890 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 890 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
891 .WillRepeatedly(Return(false)); 891 .WillRepeatedly(Return(false));
892 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 892 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
893 .WillRepeatedly(Return(false)); 893 .WillRepeatedly(Return(false));
894 SetupInitializedProfileSyncService(); 894 SetupInitializedProfileSyncService();
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 TEST_P(SyncSetupHandlerTest, ShowSetupSyncForAllTypesIndividually) { 1024 TEST_P(SyncSetupHandlerTest, ShowSetupSyncForAllTypesIndividually) {
1025 for (size_t i = 0; i < arraysize(kUserSelectableTypes); ++i) { 1025 for (size_t i = 0; i < arraysize(kUserSelectableTypes); ++i) {
1026 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 1026 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
1027 .WillRepeatedly(Return(false)); 1027 .WillRepeatedly(Return(false));
1028 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase()) 1028 EXPECT_CALL(*mock_pss_, IsUsingSecondaryPassphrase())
1029 .WillRepeatedly(Return(false)); 1029 .WillRepeatedly(Return(false));
1030 SetupInitializedProfileSyncService(); 1030 SetupInitializedProfileSyncService();
1031 browser_sync::SyncPrefs sync_prefs(profile_->GetPrefs()); 1031 browser_sync::SyncPrefs sync_prefs(profile_->GetPrefs());
1032 sync_prefs.SetKeepEverythingSynced(false); 1032 sync_prefs.SetKeepEverythingSynced(false);
1033 SetDefaultExpectationsForConfigPage(); 1033 SetDefaultExpectationsForConfigPage();
1034 syncable::ModelTypeSet types; 1034 syncer::ModelTypeSet types;
1035 types.Put(kUserSelectableTypes[i]); 1035 types.Put(kUserSelectableTypes[i]);
1036 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()). 1036 EXPECT_CALL(*mock_pss_, GetPreferredDataTypes()).
1037 WillRepeatedly(Return(types)); 1037 WillRepeatedly(Return(types));
1038 1038
1039 // This should display the sync setup dialog (not login). 1039 // This should display the sync setup dialog (not login).
1040 handler_->OpenSyncSetup(false); 1040 handler_->OpenSyncSetup(false);
1041 1041
1042 ExpectConfig(); 1042 ExpectConfig();
1043 // Close the config overlay. 1043 // Close the config overlay.
1044 LoginUIServiceFactory::GetForProfile(profile_.get())->LoginUIClosed( 1044 LoginUIServiceFactory::GetForProfile(profile_.get())->LoginUIClosed(
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 CheckShowSyncSetupArgs( 1150 CheckShowSyncSetupArgs(
1151 dictionary, err, false, GoogleServiceAuthError::NONE, "", true, ""); 1151 dictionary, err, false, GoogleServiceAuthError::NONE, "", true, "");
1152 handler_->CloseSyncSetup(); 1152 handler_->CloseSyncSetup();
1153 EXPECT_EQ(NULL, 1153 EXPECT_EQ(NULL,
1154 LoginUIServiceFactory::GetForProfile( 1154 LoginUIServiceFactory::GetForProfile(
1155 profile_.get())->current_login_ui()); 1155 profile_.get())->current_login_ui());
1156 } 1156 }
1157 1157
1158 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTest, SyncSetupHandlerTest, 1158 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTest, SyncSetupHandlerTest,
1159 Values(true, false)); 1159 Values(true, false));
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/sync_setup_handler.cc ('k') | chrome/browser/webdata/autocomplete_syncable_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698