| OLD | NEW |
| 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/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 206 } |
| 207 | 207 |
| 208 scoped_ptr<Profile> profile_; | 208 scoped_ptr<Profile> profile_; |
| 209 ProfileSyncServiceMock* mock_pss_; | 209 ProfileSyncServiceMock* mock_pss_; |
| 210 GoogleServiceAuthError error_; | 210 GoogleServiceAuthError error_; |
| 211 SigninManagerMock* mock_signin_; | 211 SigninManagerMock* mock_signin_; |
| 212 TestWebUI web_ui_; | 212 TestWebUI web_ui_; |
| 213 scoped_ptr<TestingSyncSetupHandler> handler_; | 213 scoped_ptr<TestingSyncSetupHandler> handler_; |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 #if !defined(OS_CHROMEOS) |
| 216 static void CheckInt(const DictionaryValue* dictionary, | 217 static void CheckInt(const DictionaryValue* dictionary, |
| 217 const std::string& key, | 218 const std::string& key, |
| 218 int expected_value) { | 219 int expected_value) { |
| 219 int actual_value; | 220 int actual_value; |
| 220 EXPECT_TRUE(dictionary->GetInteger(key, &actual_value)) << | 221 EXPECT_TRUE(dictionary->GetInteger(key, &actual_value)) << |
| 221 "Did not expect to find value for " << key;; | 222 "Did not expect to find value for " << key;; |
| 222 EXPECT_EQ(actual_value, expected_value) << | 223 EXPECT_EQ(actual_value, expected_value) << |
| 223 "Mismatch found for " << key;; | 224 "Mismatch found for " << key;; |
| 224 } | 225 } |
| 226 #endif |
| 225 | 227 |
| 226 static void CheckBool(const DictionaryValue* dictionary, | 228 static void CheckBool(const DictionaryValue* dictionary, |
| 227 const std::string& key, | 229 const std::string& key, |
| 228 bool expected_value, | 230 bool expected_value, |
| 229 bool is_optional) { | 231 bool is_optional) { |
| 230 if (is_optional && !expected_value) { | 232 if (is_optional && !expected_value) { |
| 231 EXPECT_FALSE(dictionary->HasKey(key)) << | 233 EXPECT_FALSE(dictionary->HasKey(key)) << |
| 232 "Did not expect to find value for " << key;; | 234 "Did not expect to find value for " << key;; |
| 233 } else { | 235 } else { |
| 234 bool actual_value; | 236 bool actual_value; |
| 235 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) << | 237 EXPECT_TRUE(dictionary->GetBoolean(key, &actual_value)) << |
| 236 "No value found for " << key; | 238 "No value found for " << key; |
| 237 EXPECT_EQ(actual_value, expected_value) << | 239 EXPECT_EQ(actual_value, expected_value) << |
| 238 "Mismatch found for " << key; | 240 "Mismatch found for " << key; |
| 239 } | 241 } |
| 240 } | 242 } |
| 241 | 243 |
| 242 static void CheckBool(const DictionaryValue* dictionary, | 244 static void CheckBool(const DictionaryValue* dictionary, |
| 243 const std::string& key, | 245 const std::string& key, |
| 244 bool expected_value) { | 246 bool expected_value) { |
| 245 return CheckBool(dictionary, key, expected_value, false); | 247 return CheckBool(dictionary, key, expected_value, false); |
| 246 } | 248 } |
| 247 | 249 |
| 250 #if !defined(OS_CHROMEOS) |
| 248 static void CheckString(const DictionaryValue* dictionary, | 251 static void CheckString(const DictionaryValue* dictionary, |
| 249 const std::string& key, | 252 const std::string& key, |
| 250 const std::string& expected_value, | 253 const std::string& expected_value, |
| 251 bool is_optional) { | 254 bool is_optional) { |
| 252 if (is_optional && expected_value.empty()) { | 255 if (is_optional && expected_value.empty()) { |
| 253 EXPECT_FALSE(dictionary->HasKey(key)) << | 256 EXPECT_FALSE(dictionary->HasKey(key)) << |
| 254 "Did not expect to find value for " << key; | 257 "Did not expect to find value for " << key; |
| 255 } else { | 258 } else { |
| 256 std::string actual_value; | 259 std::string actual_value; |
| 257 EXPECT_TRUE(dictionary->GetString(key, &actual_value)) << | 260 EXPECT_TRUE(dictionary->GetString(key, &actual_value)) << |
| 258 "No value found for " << key; | 261 "No value found for " << key; |
| 259 EXPECT_EQ(actual_value, expected_value) << | 262 EXPECT_EQ(actual_value, expected_value) << |
| 260 "Mismatch found for " << key; | 263 "Mismatch found for " << key; |
| 261 } | 264 } |
| 262 } | 265 } |
| 266 #endif |
| 263 | 267 |
| 268 #if !defined(OS_CHROMEOS) |
| 264 // Validates that the expected args are being passed off to javascript. | 269 // Validates that the expected args are being passed off to javascript. |
| 265 static void CheckShowSyncSetupArgs(const DictionaryValue* dictionary, | 270 static void CheckShowSyncSetupArgs(const DictionaryValue* dictionary, |
| 266 std::string error_message, | 271 std::string error_message, |
| 267 bool fatal_error, | 272 bool fatal_error, |
| 268 int error, | 273 int error, |
| 269 std::string user, | 274 std::string user, |
| 270 bool user_is_editable, | 275 bool user_is_editable, |
| 271 std::string captcha_url) { | 276 std::string captcha_url) { |
| 272 // showSyncSetupPage() expects to be passed a dictionary with the following | 277 // showSyncSetupPage() expects to be passed a dictionary with the following |
| 273 // named values set: | 278 // named values set: |
| 274 // error_message: custom error message to display. | 279 // error_message: custom error message to display. |
| 275 // fatalError: true if there was a fatal error while logging in. | 280 // fatalError: true if there was a fatal error while logging in. |
| 276 // error: GoogleServiceAuthError from previous login attempt (0 if none). | 281 // error: GoogleServiceAuthError from previous login attempt (0 if none). |
| 277 // user: The email the user most recently entered. | 282 // user: The email the user most recently entered. |
| 278 // editable_user: Whether the username field should be editable. | 283 // editable_user: Whether the username field should be editable. |
| 279 // captchaUrl: The captcha image to display to the user (empty if none). | 284 // captchaUrl: The captcha image to display to the user (empty if none). |
| 280 // | 285 // |
| 281 // The code below validates these arguments. | 286 // The code below validates these arguments. |
| 282 | 287 |
| 283 CheckString(dictionary, "error_message", error_message, true); | 288 CheckString(dictionary, "error_message", error_message, true); |
| 284 CheckString(dictionary, "user", user, false); | 289 CheckString(dictionary, "user", user, false); |
| 285 CheckString(dictionary, "captchaUrl", captcha_url, false); | 290 CheckString(dictionary, "captchaUrl", captcha_url, false); |
| 286 CheckInt(dictionary, "error", error); | 291 CheckInt(dictionary, "error", error); |
| 287 CheckBool(dictionary, "fatalError", fatal_error, true); | 292 CheckBool(dictionary, "fatalError", fatal_error, true); |
| 288 CheckBool(dictionary, "editable_user", user_is_editable); | 293 CheckBool(dictionary, "editable_user", user_is_editable); |
| 289 } | 294 } |
| 295 #endif |
| 290 | 296 |
| 291 TEST_F(SyncSetupHandlerTest, Basic) { | 297 TEST_F(SyncSetupHandlerTest, Basic) { |
| 292 } | 298 } |
| 293 | 299 |
| 300 #if !defined(OS_CHROMEOS) |
| 294 TEST_F(SyncSetupHandlerTest, DisplayBasicLogin) { | 301 TEST_F(SyncSetupHandlerTest, DisplayBasicLogin) { |
| 295 EXPECT_CALL(*mock_pss_, AreCredentialsAvailable()) | 302 EXPECT_CALL(*mock_pss_, AreCredentialsAvailable()) |
| 296 .WillRepeatedly(Return(false)); | 303 .WillRepeatedly(Return(false)); |
| 297 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 304 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 298 .WillRepeatedly(Return(false)); | 305 .WillRepeatedly(Return(false)); |
| 299 handler_->OpenSyncSetup(false); | 306 handler_->OpenSyncSetup(false); |
| 300 EXPECT_EQ(&web_ui_, | 307 EXPECT_EQ(&web_ui_, |
| 301 LoginUIServiceFactory::GetForProfile( | 308 LoginUIServiceFactory::GetForProfile( |
| 302 profile_.get())->current_login_ui()); | 309 profile_.get())->current_login_ui()); |
| 303 ASSERT_EQ(1U, web_ui_.call_data().size()); | 310 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); | 423 EXPECT_EQ("SyncSetupOverlay.showSyncSetupPage", data.function_name); |
| 417 std::string page; | 424 std::string page; |
| 418 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 425 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 419 EXPECT_EQ(page, "login"); | 426 EXPECT_EQ(page, "login"); |
| 420 // Now make sure that the appropriate params are being passed. | 427 // Now make sure that the appropriate params are being passed. |
| 421 DictionaryValue* dictionary; | 428 DictionaryValue* dictionary; |
| 422 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 429 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 423 CheckShowSyncSetupArgs( | 430 CheckShowSyncSetupArgs( |
| 424 dictionary, "", true, GoogleServiceAuthError::NONE, "", true, ""); | 431 dictionary, "", true, GoogleServiceAuthError::NONE, "", true, ""); |
| 425 } | 432 } |
| 433 #endif // !OS_CHROMEOS |
| 426 | 434 |
| 435 #if !defined(OS_CHROMEOS) |
| 436 // TODO(kochi): We need equivalent tests for ChromeOS. |
| 427 TEST_F(SyncSetupHandlerTest, UnrecoverableErrorInitializingSync) { | 437 TEST_F(SyncSetupHandlerTest, UnrecoverableErrorInitializingSync) { |
| 428 EXPECT_CALL(*mock_pss_, AreCredentialsAvailable()) | 438 EXPECT_CALL(*mock_pss_, AreCredentialsAvailable()) |
| 429 .WillRepeatedly(Return(false)); | 439 .WillRepeatedly(Return(false)); |
| 430 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) | 440 EXPECT_CALL(*mock_pss_, HasSyncSetupCompleted()) |
| 431 .WillRepeatedly(Return(false)); | 441 .WillRepeatedly(Return(false)); |
| 432 // Open the web UI. | 442 // Open the web UI. |
| 433 handler_->OpenSyncSetup(false); | 443 handler_->OpenSyncSetup(false); |
| 434 ASSERT_EQ(1U, web_ui_.call_data().size()); | 444 ASSERT_EQ(1U, web_ui_.call_data().size()); |
| 435 // Fake a successful GAIA request (gaia credentials valid, but signin not | 445 // Fake a successful GAIA request (gaia credentials valid, but signin not |
| 436 // complete yet). | 446 // complete yet). |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 std::string page; | 501 std::string page; |
| 492 ASSERT_TRUE(data.arg1->GetAsString(&page)); | 502 ASSERT_TRUE(data.arg1->GetAsString(&page)); |
| 493 EXPECT_EQ(page, "login"); | 503 EXPECT_EQ(page, "login"); |
| 494 // Now make sure that the appropriate params are being passed. | 504 // Now make sure that the appropriate params are being passed. |
| 495 DictionaryValue* dictionary; | 505 DictionaryValue* dictionary; |
| 496 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 506 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 497 CheckShowSyncSetupArgs( | 507 CheckShowSyncSetupArgs( |
| 498 dictionary, "", false, GoogleServiceAuthError::SERVICE_UNAVAILABLE, | 508 dictionary, "", false, GoogleServiceAuthError::SERVICE_UNAVAILABLE, |
| 499 kTestUser, true, ""); | 509 kTestUser, true, ""); |
| 500 } | 510 } |
| 511 #endif // !OS_CHROMEOS |
| 501 | 512 |
| 502 TEST_F(SyncSetupHandlerTest, TestSyncEverything) { | 513 TEST_F(SyncSetupHandlerTest, TestSyncEverything) { |
| 503 std::string args = | 514 std::string args = |
| 504 "{\"syncAllDataTypes\":true," | 515 "{\"syncAllDataTypes\":true," |
| 505 "\"sync_apps\":true," | 516 "\"sync_apps\":true," |
| 506 "\"sync_autofill\":true," | 517 "\"sync_autofill\":true," |
| 507 "\"sync_bookmarks\":true," | 518 "\"sync_bookmarks\":true," |
| 508 "\"sync_extensions\":true," | 519 "\"sync_extensions\":true," |
| 509 "\"sync_passwords\":true," | 520 "\"sync_passwords\":true," |
| 510 "\"sync_preferences\":true," | 521 "\"sync_preferences\":true," |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 | 968 |
| 958 // This should display the sync setup dialog (not login). | 969 // This should display the sync setup dialog (not login). |
| 959 handler_->OpenSyncSetup(false); | 970 handler_->OpenSyncSetup(false); |
| 960 | 971 |
| 961 ExpectConfig(); | 972 ExpectConfig(); |
| 962 const TestWebUI::CallData& data = web_ui_.call_data()[0]; | 973 const TestWebUI::CallData& data = web_ui_.call_data()[0]; |
| 963 DictionaryValue* dictionary; | 974 DictionaryValue* dictionary; |
| 964 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); | 975 ASSERT_TRUE(data.arg2->GetAsDictionary(&dictionary)); |
| 965 CheckBool(dictionary, "encryptAllData", true); | 976 CheckBool(dictionary, "encryptAllData", true); |
| 966 } | 977 } |
| OLD | NEW |