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

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

Issue 14691004: [sync] Separate sign in from sync on Desktop Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 "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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 const char kTestCaptchaImageUrl[] = "http://pizzamyheart/image"; 51 const char kTestCaptchaImageUrl[] = "http://pizzamyheart/image";
52 const char kTestCaptchaUnlockUrl[] = "http://pizzamyheart/unlock"; 52 const char kTestCaptchaUnlockUrl[] = "http://pizzamyheart/unlock";
53 53
54 // Returns a ModelTypeSet with all user selectable types set. 54 // Returns a ModelTypeSet with all user selectable types set.
55 syncer::ModelTypeSet GetAllTypes() { 55 syncer::ModelTypeSet GetAllTypes() {
56 return syncer::UserSelectableTypes(); 56 return syncer::UserSelectableTypes();
57 } 57 }
58 58
59 enum SyncAllDataConfig { 59 enum SyncAllDataConfig {
60 SYNC_ALL_DATA, 60 SYNC_ALL_DATA,
61 CHOOSE_WHAT_TO_SYNC 61 CHOOSE_WHAT_TO_SYNC,
62 SYNC_NOTHING
62 }; 63 };
63 64
64 enum EncryptAllConfig { 65 enum EncryptAllConfig {
65 ENCRYPT_ALL_DATA, 66 ENCRYPT_ALL_DATA,
66 ENCRYPT_PASSWORDS 67 ENCRYPT_PASSWORDS
67 }; 68 };
68 69
69 // Create a json-format string with the key/value pairs appropriate for a call 70 // Create a json-format string with the key/value pairs appropriate for a call
70 // to HandleConfigure(). If |extra_values| is non-null, then the values from 71 // to HandleConfigure(). If |extra_values| is non-null, then the values from
71 // the passed dictionary are added to the json. 72 // the passed dictionary are added to the json.
72 std::string GetConfiguration(const DictionaryValue* extra_values, 73 std::string GetConfiguration(const DictionaryValue* extra_values,
73 SyncAllDataConfig sync_all, 74 SyncAllDataConfig sync_all,
74 syncer::ModelTypeSet types, 75 syncer::ModelTypeSet types,
75 const std::string& passphrase, 76 const std::string& passphrase,
76 EncryptAllConfig encrypt_all) { 77 EncryptAllConfig encrypt_all) {
77 DictionaryValue result; 78 DictionaryValue result;
78 if (extra_values) 79 if (extra_values)
79 result.MergeDictionary(extra_values); 80 result.MergeDictionary(extra_values);
80 result.SetBoolean("syncAllDataTypes", sync_all == SYNC_ALL_DATA); 81 result.SetBoolean("syncAllDataTypes", sync_all == SYNC_ALL_DATA);
82 result.SetBoolean("syncNothing", sync_all == SYNC_NOTHING);
81 result.SetBoolean("encryptAllData", encrypt_all == ENCRYPT_ALL_DATA); 83 result.SetBoolean("encryptAllData", encrypt_all == ENCRYPT_ALL_DATA);
82 result.SetBoolean("usePassphrase", !passphrase.empty()); 84 result.SetBoolean("usePassphrase", !passphrase.empty());
83 if (!passphrase.empty()) 85 if (!passphrase.empty())
84 result.SetString("passphrase", passphrase); 86 result.SetString("passphrase", passphrase);
85 // Add all of our data types. 87 // Add all of our data types.
86 result.SetBoolean("appsSynced", types.Has(syncer::APPS)); 88 result.SetBoolean("appsSynced", types.Has(syncer::APPS));
87 result.SetBoolean("autofillSynced", types.Has(syncer::AUTOFILL)); 89 result.SetBoolean("autofillSynced", types.Has(syncer::AUTOFILL));
88 result.SetBoolean("bookmarksSynced", types.Has(syncer::BOOKMARKS)); 90 result.SetBoolean("bookmarksSynced", types.Has(syncer::BOOKMARKS));
89 result.SetBoolean("extensionsSynced", types.Has(syncer::EXTENSIONS)); 91 result.SetBoolean("extensionsSynced", types.Has(syncer::EXTENSIONS));
90 result.SetBoolean("passwordsSynced", types.Has(syncer::PASSWORDS)); 92 result.SetBoolean("passwordsSynced", types.Has(syncer::PASSWORDS));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 CheckBool(dictionary, "editableUser", user_is_editable); 177 CheckBool(dictionary, "editableUser", user_is_editable);
176 } 178 }
177 179
178 // Checks to make sure that the values stored in |dictionary| match the values 180 // Checks to make sure that the values stored in |dictionary| match the values
179 // expected by the showSyncSetupPage() JS function for a given set of data 181 // expected by the showSyncSetupPage() JS function for a given set of data
180 // types. 182 // types.
181 void CheckConfigDataTypeArguments(DictionaryValue* dictionary, 183 void CheckConfigDataTypeArguments(DictionaryValue* dictionary,
182 SyncAllDataConfig config, 184 SyncAllDataConfig config,
183 syncer::ModelTypeSet types) { 185 syncer::ModelTypeSet types) {
184 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA); 186 CheckBool(dictionary, "syncAllDataTypes", config == SYNC_ALL_DATA);
187 CheckBool(dictionary, "syncNothing", config == SYNC_NOTHING);
185 CheckBool(dictionary, "appsSynced", types.Has(syncer::APPS)); 188 CheckBool(dictionary, "appsSynced", types.Has(syncer::APPS));
186 CheckBool(dictionary, "autofillSynced", types.Has(syncer::AUTOFILL)); 189 CheckBool(dictionary, "autofillSynced", types.Has(syncer::AUTOFILL));
187 CheckBool(dictionary, "bookmarksSynced", types.Has(syncer::BOOKMARKS)); 190 CheckBool(dictionary, "bookmarksSynced", types.Has(syncer::BOOKMARKS));
188 CheckBool(dictionary, "extensionsSynced", types.Has(syncer::EXTENSIONS)); 191 CheckBool(dictionary, "extensionsSynced", types.Has(syncer::EXTENSIONS));
189 CheckBool(dictionary, "passwordsSynced", types.Has(syncer::PASSWORDS)); 192 CheckBool(dictionary, "passwordsSynced", types.Has(syncer::PASSWORDS));
190 CheckBool(dictionary, "preferencesSynced", types.Has(syncer::PREFERENCES)); 193 CheckBool(dictionary, "preferencesSynced", types.Has(syncer::PREFERENCES));
191 CheckBool(dictionary, "tabsSynced", types.Has(syncer::PROXY_TABS)); 194 CheckBool(dictionary, "tabsSynced", types.Has(syncer::PROXY_TABS));
192 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES)); 195 CheckBool(dictionary, "themesSynced", types.Has(syncer::THEMES));
193 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS)); 196 CheckBool(dictionary, "typedUrlsSynced", types.Has(syncer::TYPED_URLS));
194 } 197 }
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 644
642 handler_->OpenSyncSetup(); 645 handler_->OpenSyncSetup();
643 const TestWebUI::CallData& data = web_ui_.call_data()[0]; 646 const TestWebUI::CallData& data = web_ui_.call_data()[0];
644 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); 647 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name);
645 std::string page; 648 std::string page;
646 ASSERT_TRUE(data.arg1->GetAsString(&page)); 649 ASSERT_TRUE(data.arg1->GetAsString(&page));
647 EXPECT_EQ(page, "spinner"); 650 EXPECT_EQ(page, "spinner");
648 GoogleServiceAuthError error( 651 GoogleServiceAuthError error(
649 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 652 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
650 handler_->SigninFailed(error); 653 handler_->SigninFailed(error);
651 // On failure, the dialog will be closed. 654 // On failure, a re-auth dialog will be displayed.
652 EXPECT_EQ(NULL, 655 EXPECT_EQ(handler_.get(),
653 LoginUIServiceFactory::GetForProfile( 656 LoginUIServiceFactory::GetForProfile(
654 profile_.get())->current_login_ui()); 657 profile_.get())->current_login_ui());
655 } 658 }
656 659
657 #if !defined(OS_CHROMEOS) 660 #if !defined(OS_CHROMEOS)
658 661
659 class SyncSetupHandlerNonCrosTest : public SyncSetupHandlerTest { 662 class SyncSetupHandlerNonCrosTest : public SyncSetupHandlerTest {
660 public: 663 public:
661 SyncSetupHandlerNonCrosTest() {} 664 SyncSetupHandlerNonCrosTest() {}
662 virtual void SetUp() OVERRIDE { 665 virtual void SetUp() OVERRIDE {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 .WillRepeatedly(Return(false)); 920 .WillRepeatedly(Return(false));
918 SetupInitializedProfileSyncService(); 921 SetupInitializedProfileSyncService();
919 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _)); 922 EXPECT_CALL(*mock_pss_, OnUserChoseDatatypes(true, _));
920 handler_->HandleConfigure(&list_args); 923 handler_->HandleConfigure(&list_args);
921 924
922 // Ensure that we navigated to the "done" state since we don't need a 925 // Ensure that we navigated to the "done" state since we don't need a
923 // passphrase. 926 // passphrase.
924 ExpectDone(); 927 ExpectDone();
925 } 928 }
926 929
930 TEST_P(SyncSetupHandlerTest, TestSyncNothing) {
931 std::string args = GetConfiguration(
932 NULL, SYNC_NOTHING, GetAllTypes(), std::string(), ENCRYPT_PASSWORDS);
933 ListValue list_args;
934 list_args.Append(new StringValue(args));
935 EXPECT_CALL(*mock_pss_, DisableForUser());
936 SetupInitializedProfileSyncService();
937 handler_->HandleConfigure(&list_args);
938
939 // Ensure that the sync setup dialog was closed.
940 const TestWebUI::CallData& data = web_ui_.call_data()[0];
941 EXPECT_EQ("OptionsPage.closeOverlay", data.function_name);
942 }
943
927 TEST_P(SyncSetupHandlerTest, TurnOnEncryptAll) { 944 TEST_P(SyncSetupHandlerTest, TurnOnEncryptAll) {
928 std::string args = GetConfiguration( 945 std::string args = GetConfiguration(
929 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA); 946 NULL, SYNC_ALL_DATA, GetAllTypes(), std::string(), ENCRYPT_ALL_DATA);
930 ListValue list_args; 947 ListValue list_args;
931 list_args.Append(new StringValue(args)); 948 list_args.Append(new StringValue(args));
932 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption()) 949 EXPECT_CALL(*mock_pss_, IsPassphraseRequiredForDecryption())
933 .WillRepeatedly(Return(false)); 950 .WillRepeatedly(Return(false));
934 EXPECT_CALL(*mock_pss_, IsPassphraseRequired()) 951 EXPECT_CALL(*mock_pss_, IsPassphraseRequired())
935 .WillRepeatedly(Return(false)); 952 .WillRepeatedly(Return(false));
936 SetupInitializedProfileSyncService(); 953 SetupInitializedProfileSyncService();
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 ExpectConfig(); 1323 ExpectConfig();
1307 const TestWebUI::CallData& data = web_ui_.call_data()[0]; 1324 const TestWebUI::CallData& data = web_ui_.call_data()[0];
1308 DictionaryValue* dictionary; 1325 DictionaryValue* dictionary;
1309 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); 1326 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary));
1310 CheckBool(dictionary, "encryptAllData", true); 1327 CheckBool(dictionary, "encryptAllData", true);
1311 } 1328 }
1312 1329
1313 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam, 1330 INSTANTIATE_TEST_CASE_P(SyncSetupHandlerTestWithParam,
1314 SyncSetupHandlerTest, 1331 SyncSetupHandlerTest,
1315 Values(true, false)); 1332 Values(true, false));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698