| 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); | 205 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogView); |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 // Bring over command-ids from AccountChooserModel. | 208 // Bring over command-ids from AccountChooserModel. |
| 209 class TestAccountChooserModel : public AccountChooserModel { | 209 class TestAccountChooserModel : public AccountChooserModel { |
| 210 public: | 210 public: |
| 211 TestAccountChooserModel(AccountChooserModelDelegate* delegate, | 211 TestAccountChooserModel(AccountChooserModelDelegate* delegate, |
| 212 PrefService* prefs, | 212 PrefService* prefs, |
| 213 const AutofillMetrics& metric_logger) | 213 const AutofillMetrics& metric_logger) |
| 214 : AccountChooserModel(delegate, prefs, metric_logger, | 214 : AccountChooserModel(delegate, prefs, metric_logger) {} |
| 215 DIALOG_TYPE_REQUEST_AUTOCOMPLETE) {} | |
| 216 virtual ~TestAccountChooserModel() {} | 215 virtual ~TestAccountChooserModel() {} |
| 217 | 216 |
| 218 using AccountChooserModel::kActiveWalletItemId; | 217 using AccountChooserModel::kActiveWalletItemId; |
| 219 using AccountChooserModel::kAutofillItemId; | 218 using AccountChooserModel::kAutofillItemId; |
| 220 | 219 |
| 221 private: | 220 private: |
| 222 DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel); | 221 DISALLOW_COPY_AND_ASSIGN(TestAccountChooserModel); |
| 223 }; | 222 }; |
| 224 | 223 |
| 225 class TestAutofillDialogController | 224 class TestAutofillDialogController |
| 226 : public AutofillDialogControllerImpl, | 225 : public AutofillDialogControllerImpl, |
| 227 public base::SupportsWeakPtr<TestAutofillDialogController> { | 226 public base::SupportsWeakPtr<TestAutofillDialogController> { |
| 228 public: | 227 public: |
| 229 TestAutofillDialogController( | 228 TestAutofillDialogController( |
| 230 content::WebContents* contents, | 229 content::WebContents* contents, |
| 231 const FormData& form_structure, | 230 const FormData& form_structure, |
| 232 const GURL& source_url, | 231 const GURL& source_url, |
| 233 const AutofillMetrics& metric_logger, | 232 const AutofillMetrics& metric_logger, |
| 234 const DialogType dialog_type, | |
| 235 const base::Callback<void(const FormStructure*, | 233 const base::Callback<void(const FormStructure*, |
| 236 const std::string&)>& callback, | 234 const std::string&)>& callback, |
| 237 MockNewCreditCardBubbleController* mock_new_card_bubble_controller) | 235 MockNewCreditCardBubbleController* mock_new_card_bubble_controller) |
| 238 : AutofillDialogControllerImpl(contents, | 236 : AutofillDialogControllerImpl(contents, |
| 239 form_structure, | 237 form_structure, |
| 240 source_url, | 238 source_url, |
| 241 dialog_type, | |
| 242 callback), | 239 callback), |
| 243 metric_logger_(metric_logger), | 240 metric_logger_(metric_logger), |
| 244 mock_wallet_client_( | 241 mock_wallet_client_( |
| 245 Profile::FromBrowserContext(contents->GetBrowserContext())-> | 242 Profile::FromBrowserContext(contents->GetBrowserContext())-> |
| 246 GetRequestContext(), this), | 243 GetRequestContext(), this), |
| 247 dialog_type_(dialog_type), | |
| 248 mock_new_card_bubble_controller_(mock_new_card_bubble_controller) {} | 244 mock_new_card_bubble_controller_(mock_new_card_bubble_controller) {} |
| 249 | 245 |
| 250 virtual ~TestAutofillDialogController() {} | 246 virtual ~TestAutofillDialogController() {} |
| 251 | 247 |
| 252 virtual AutofillDialogView* CreateView() OVERRIDE { | 248 virtual AutofillDialogView* CreateView() OVERRIDE { |
| 253 return new testing::NiceMock<TestAutofillDialogView>(); | 249 return new testing::NiceMock<TestAutofillDialogView>(); |
| 254 } | 250 } |
| 255 | 251 |
| 256 void Init(content::BrowserContext* browser_context) { | 252 void Init(content::BrowserContext* browser_context) { |
| 257 test_manager_.Init(browser_context); | 253 test_manager_.Init(browser_context); |
| 258 } | 254 } |
| 259 | 255 |
| 260 TestAutofillDialogView* GetView() { | 256 TestAutofillDialogView* GetView() { |
| 261 return static_cast<TestAutofillDialogView*>(view()); | 257 return static_cast<TestAutofillDialogView*>(view()); |
| 262 } | 258 } |
| 263 | 259 |
| 264 TestPersonalDataManager* GetTestingManager() { | 260 TestPersonalDataManager* GetTestingManager() { |
| 265 return &test_manager_; | 261 return &test_manager_; |
| 266 } | 262 } |
| 267 | 263 |
| 268 wallet::MockWalletClient* GetTestingWalletClient() { | 264 wallet::MockWalletClient* GetTestingWalletClient() { |
| 269 return &mock_wallet_client_; | 265 return &mock_wallet_client_; |
| 270 } | 266 } |
| 271 | 267 |
| 272 const GURL& open_tab_url() { return open_tab_url_; } | 268 const GURL& open_tab_url() { return open_tab_url_; } |
| 273 | 269 |
| 274 virtual DialogType GetDialogType() const OVERRIDE { | |
| 275 return dialog_type_; | |
| 276 } | |
| 277 | |
| 278 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } | |
| 279 | |
| 280 void SimulateSigninError() { | 270 void SimulateSigninError() { |
| 281 OnWalletSigninError(); | 271 OnWalletSigninError(); |
| 282 } | 272 } |
| 283 | 273 |
| 284 // Skips past the 2 second wait between FinishSubmit and DoFinishSubmit. | 274 // Skips past the 2 second wait between FinishSubmit and DoFinishSubmit. |
| 285 void ForceFinishSubmit() { | 275 void ForceFinishSubmit() { |
| 286 #if defined(TOOLKIT_VIEWS) | 276 #if defined(TOOLKIT_VIEWS) |
| 287 DoFinishSubmit(); | 277 DoFinishSubmit(); |
| 288 #endif | 278 #endif |
| 289 } | 279 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 private: | 311 private: |
| 322 // To specify our own metric logger. | 312 // To specify our own metric logger. |
| 323 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { | 313 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { |
| 324 return metric_logger_; | 314 return metric_logger_; |
| 325 } | 315 } |
| 326 | 316 |
| 327 const AutofillMetrics& metric_logger_; | 317 const AutofillMetrics& metric_logger_; |
| 328 TestPersonalDataManager test_manager_; | 318 TestPersonalDataManager test_manager_; |
| 329 testing::NiceMock<wallet::MockWalletClient> mock_wallet_client_; | 319 testing::NiceMock<wallet::MockWalletClient> mock_wallet_client_; |
| 330 GURL open_tab_url_; | 320 GURL open_tab_url_; |
| 331 DialogType dialog_type_; | |
| 332 MockNewCreditCardBubbleController* mock_new_card_bubble_controller_; | 321 MockNewCreditCardBubbleController* mock_new_card_bubble_controller_; |
| 333 | 322 |
| 334 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); | 323 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
| 335 }; | 324 }; |
| 336 | 325 |
| 337 class TestGeneratedCreditCardBubbleController : | 326 class TestGeneratedCreditCardBubbleController : |
| 338 public GeneratedCreditCardBubbleController { | 327 public GeneratedCreditCardBubbleController { |
| 339 public: | 328 public: |
| 340 explicit TestGeneratedCreditCardBubbleController( | 329 explicit TestGeneratedCreditCardBubbleController( |
| 341 content::WebContents* contents) | 330 content::WebContents* contents) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 controller_->ViewClosed(); | 400 controller_->ViewClosed(); |
| 412 | 401 |
| 413 base::Callback<void(const FormStructure*, const std::string&)> callback = | 402 base::Callback<void(const FormStructure*, const std::string&)> callback = |
| 414 base::Bind(&AutofillDialogControllerTest::FinishedCallback, | 403 base::Bind(&AutofillDialogControllerTest::FinishedCallback, |
| 415 base::Unretained(this)); | 404 base::Unretained(this)); |
| 416 controller_ = (new testing::NiceMock<TestAutofillDialogController>( | 405 controller_ = (new testing::NiceMock<TestAutofillDialogController>( |
| 417 web_contents(), | 406 web_contents(), |
| 418 form_data, | 407 form_data, |
| 419 GURL(), | 408 GURL(), |
| 420 metric_logger_, | 409 metric_logger_, |
| 421 DIALOG_TYPE_REQUEST_AUTOCOMPLETE, | |
| 422 callback, | 410 callback, |
| 423 mock_new_card_bubble_controller_.get()))->AsWeakPtr(); | 411 mock_new_card_bubble_controller_.get()))->AsWeakPtr(); |
| 424 controller_->Init(profile()); | 412 controller_->Init(profile()); |
| 425 controller_->Show(); | 413 controller_->Show(); |
| 426 controller_->OnUserNameFetchSuccess(kFakeEmail); | 414 controller_->OnUserNameFetchSuccess(kFakeEmail); |
| 427 } | 415 } |
| 428 | 416 |
| 429 void FillCreditCardInputs() { | 417 void FillCreditCardInputs() { |
| 430 DetailOutputMap cc_outputs; | 418 DetailOutputMap cc_outputs; |
| 431 const DetailInputs& cc_inputs = | 419 const DetailInputs& cc_inputs = |
| (...skipping 1953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2385 SaveInChromePreferenceRememberedOnSuccess) { | 2373 SaveInChromePreferenceRememberedOnSuccess) { |
| 2386 EXPECT_TRUE(controller()->ShouldSaveInChrome()); | 2374 EXPECT_TRUE(controller()->ShouldSaveInChrome()); |
| 2387 SwitchToAutofill(); | 2375 SwitchToAutofill(); |
| 2388 FillCreditCardInputs(); | 2376 FillCreditCardInputs(); |
| 2389 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(false); | 2377 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(false); |
| 2390 controller()->OnAccept(); | 2378 controller()->OnAccept(); |
| 2391 EXPECT_FALSE(controller()->ShouldSaveInChrome()); | 2379 EXPECT_FALSE(controller()->ShouldSaveInChrome()); |
| 2392 } | 2380 } |
| 2393 | 2381 |
| 2394 } // namespace autofill | 2382 } // namespace autofill |
| OLD | NEW |