| 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 291 } |
| 292 | 292 |
| 293 void SimulateSubmitButtonDelayBegin() { | 293 void SimulateSubmitButtonDelayBegin() { |
| 294 AutofillDialogControllerImpl::SubmitButtonDelayBegin(); | 294 AutofillDialogControllerImpl::SubmitButtonDelayBegin(); |
| 295 } | 295 } |
| 296 | 296 |
| 297 void SimulateSubmitButtonDelayEnd() { | 297 void SimulateSubmitButtonDelayEnd() { |
| 298 AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting(); | 298 AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting(); |
| 299 } | 299 } |
| 300 | 300 |
| 301 using AutofillDialogControllerImpl:: |
| 302 ClearLastWalletItemsFetchTimestampForTesting; |
| 303 |
| 301 // Returns the number of times that the submit button was delayed. | 304 // Returns the number of times that the submit button was delayed. |
| 302 int get_submit_button_delay_count() const { | 305 int get_submit_button_delay_count() const { |
| 303 return submit_button_delay_count_; | 306 return submit_button_delay_count_; |
| 304 } | 307 } |
| 305 | 308 |
| 306 MOCK_METHOD0(LoadRiskFingerprintData, void()); | 309 MOCK_METHOD0(LoadRiskFingerprintData, void()); |
| 307 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; | 310 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
| 308 using AutofillDialogControllerImpl::IsEditingExistingData; | 311 using AutofillDialogControllerImpl::IsEditingExistingData; |
| 309 | 312 |
| 310 protected: | 313 protected: |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 controller_ = (new testing::NiceMock<TestAutofillDialogController>( | 443 controller_ = (new testing::NiceMock<TestAutofillDialogController>( |
| 441 web_contents(), | 444 web_contents(), |
| 442 form_data, | 445 form_data, |
| 443 GURL(), | 446 GURL(), |
| 444 metric_logger_, | 447 metric_logger_, |
| 445 callback, | 448 callback, |
| 446 mock_new_card_bubble_controller_.get()))->AsWeakPtr(); | 449 mock_new_card_bubble_controller_.get()))->AsWeakPtr(); |
| 447 controller_->Init(profile()); | 450 controller_->Init(profile()); |
| 448 controller_->Show(); | 451 controller_->Show(); |
| 449 controller_->OnUserNameFetchSuccess(kFakeEmail); | 452 controller_->OnUserNameFetchSuccess(kFakeEmail); |
| 453 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); |
| 454 controller_->OnDidFetchWalletCookieValue(std::string()); |
| 450 } | 455 } |
| 451 | 456 |
| 452 void FillCreditCardInputs() { | 457 void FillCreditCardInputs() { |
| 453 DetailOutputMap cc_outputs; | 458 DetailOutputMap cc_outputs; |
| 454 const DetailInputs& cc_inputs = | 459 const DetailInputs& cc_inputs = |
| 455 controller()->RequestedFieldsForSection(SECTION_CC); | 460 controller()->RequestedFieldsForSection(SECTION_CC); |
| 456 for (size_t i = 0; i < cc_inputs.size(); ++i) { | 461 for (size_t i = 0; i < cc_inputs.size(); ++i) { |
| 457 cc_outputs[&cc_inputs[i]] = cc_inputs[i].type == CREDIT_CARD_NUMBER ? | 462 cc_outputs[&cc_inputs[i]] = cc_inputs[i].type == CREDIT_CARD_NUMBER ? |
| 458 ASCIIToUTF16(kTestCCNumberVisa) : ASCIIToUTF16("11"); | 463 ASCIIToUTF16(kTestCCNumberVisa) : ASCIIToUTF16("11"); |
| 459 } | 464 } |
| (...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 | 1709 |
| 1705 // Test Wallet banners are show in the right situations. These banners promote | 1710 // Test Wallet banners are show in the right situations. These banners promote |
| 1706 // saving details into Wallet (i.e. "[x] Save details to Wallet"). | 1711 // saving details into Wallet (i.e. "[x] Save details to Wallet"). |
| 1707 TEST_F(AutofillDialogControllerTest, WalletBanners) { | 1712 TEST_F(AutofillDialogControllerTest, WalletBanners) { |
| 1708 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 1713 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 1709 command_line->AppendSwitch(switches::kWalletServiceUseProd); | 1714 command_line->AppendSwitch(switches::kWalletServiceUseProd); |
| 1710 | 1715 |
| 1711 // Simulate non-signed-in case. | 1716 // Simulate non-signed-in case. |
| 1712 SetUpControllerWithFormData(DefaultFormData()); | 1717 SetUpControllerWithFormData(DefaultFormData()); |
| 1713 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); | 1718 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); |
| 1714 controller()->OnUserNameFetchFailure(error); | 1719 controller()->OnPassiveSigninFailure(error); |
| 1715 EXPECT_EQ(0U, NotificationsOfType( | 1720 EXPECT_EQ(0U, NotificationsOfType( |
| 1716 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); | 1721 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); |
| 1717 | 1722 |
| 1718 // Sign in a user with a completed account. | 1723 // Sign in a user with a completed account. |
| 1719 SetUpControllerWithFormData(DefaultFormData()); | 1724 SetUpControllerWithFormData(DefaultFormData()); |
| 1720 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | 1725 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
| 1721 | 1726 |
| 1722 // Full account; should show "Details from Wallet" message. | 1727 // Full account; should show "Details from Wallet" message. |
| 1723 EXPECT_EQ(1U, NotificationsOfType( | 1728 EXPECT_EQ(1U, NotificationsOfType( |
| 1724 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); | 1729 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2183 shipping_model->ActivatedAt(1); | 2188 shipping_model->ActivatedAt(1); |
| 2184 // 2 suggestions, "add", and "manage". | 2189 // 2 suggestions, "add", and "manage". |
| 2185 ASSERT_EQ(4, cc_billing_model->GetItemCount()); | 2190 ASSERT_EQ(4, cc_billing_model->GetItemCount()); |
| 2186 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(1)); | 2191 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(1)); |
| 2187 // "use billing", 2 suggestions, "add", "manage". | 2192 // "use billing", 2 suggestions, "add", "manage". |
| 2188 ASSERT_EQ(5, shipping_model->GetItemCount()); | 2193 ASSERT_EQ(5, shipping_model->GetItemCount()); |
| 2189 EXPECT_TRUE(shipping_model-> IsItemCheckedAt(1)); | 2194 EXPECT_TRUE(shipping_model-> IsItemCheckedAt(1)); |
| 2190 | 2195 |
| 2191 // Simulate switching away from the tab and back. This should issue a request | 2196 // Simulate switching away from the tab and back. This should issue a request |
| 2192 // for wallet items. | 2197 // for wallet items. |
| 2198 controller()->ClearLastWalletItemsFetchTimestampForTesting(); |
| 2193 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); | 2199 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); |
| 2194 controller()->TabActivated(); | 2200 controller()->TabActivated(); |
| 2195 | 2201 |
| 2196 // Simulate a response that includes different items. | 2202 // Simulate a response that includes different items. |
| 2197 wallet_items = wallet::GetTestWalletItems(); | 2203 wallet_items = wallet::GetTestWalletItems(); |
| 2198 wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); | 2204 wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); |
| 2199 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 2205 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 2200 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); | 2206 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
| 2201 wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); | 2207 wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); |
| 2202 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 2208 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2231 controller()->MenuModelForSection(SECTION_SHIPPING); | 2237 controller()->MenuModelForSection(SECTION_SHIPPING); |
| 2232 // 2 suggestions, "add", and "manage". | 2238 // 2 suggestions, "add", and "manage". |
| 2233 ASSERT_EQ(4, cc_billing_model->GetItemCount()); | 2239 ASSERT_EQ(4, cc_billing_model->GetItemCount()); |
| 2234 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(0)); | 2240 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(0)); |
| 2235 // "use billing", 2 suggestions, "add", and "manage". | 2241 // "use billing", 2 suggestions, "add", and "manage". |
| 2236 ASSERT_EQ(5, shipping_model->GetItemCount()); | 2242 ASSERT_EQ(5, shipping_model->GetItemCount()); |
| 2237 EXPECT_TRUE(shipping_model->IsItemCheckedAt(2)); | 2243 EXPECT_TRUE(shipping_model->IsItemCheckedAt(2)); |
| 2238 | 2244 |
| 2239 // Simulate switching away from the tab and back. This should issue a request | 2245 // Simulate switching away from the tab and back. This should issue a request |
| 2240 // for wallet items. | 2246 // for wallet items. |
| 2247 controller()->ClearLastWalletItemsFetchTimestampForTesting(); |
| 2241 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); | 2248 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); |
| 2242 controller()->TabActivated(); | 2249 controller()->TabActivated(); |
| 2243 | 2250 |
| 2244 // Simulate a response that includes different default values. | 2251 // Simulate a response that includes different default values. |
| 2245 wallet_items = | 2252 wallet_items = |
| 2246 wallet::GetTestWalletItemsWithDefaultIds("new_default_instrument_id", | 2253 wallet::GetTestWalletItemsWithDefaultIds("new_default_instrument_id", |
| 2247 "new_default_address_id"); | 2254 "new_default_address_id"); |
| 2248 scoped_ptr<wallet::Address> other_address = wallet::GetTestShippingAddress(); | 2255 scoped_ptr<wallet::Address> other_address = wallet::GetTestShippingAddress(); |
| 2249 other_address->set_object_id("other_address_id"); | 2256 other_address->set_object_id("other_address_id"); |
| 2250 scoped_ptr<wallet::Address> new_default_address = | 2257 scoped_ptr<wallet::Address> new_default_address = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2268 EXPECT_TRUE(shipping_model->IsItemCheckedAt(1)); | 2275 EXPECT_TRUE(shipping_model->IsItemCheckedAt(1)); |
| 2269 } | 2276 } |
| 2270 | 2277 |
| 2271 TEST_F(AutofillDialogControllerTest, ReloadWithEmptyWalletItems) { | 2278 TEST_F(AutofillDialogControllerTest, ReloadWithEmptyWalletItems) { |
| 2272 SwitchToWallet(); | 2279 SwitchToWallet(); |
| 2273 | 2280 |
| 2274 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | 2281 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
| 2275 controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(1); | 2282 controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(1); |
| 2276 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1); | 2283 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1); |
| 2277 | 2284 |
| 2285 controller()->ClearLastWalletItemsFetchTimestampForTesting(); |
| 2278 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); | 2286 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); |
| 2279 controller()->TabActivated(); | 2287 controller()->TabActivated(); |
| 2280 | 2288 |
| 2281 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); | 2289 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); |
| 2282 | 2290 |
| 2283 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); | 2291 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); |
| 2284 EXPECT_EQ( | 2292 EXPECT_EQ( |
| 2285 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); | 2293 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); |
| 2286 } | 2294 } |
| 2287 | 2295 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2416 EXPECT_EQ(1UL, icons.count(CREDIT_CARD_NUMBER)); | 2424 EXPECT_EQ(1UL, icons.count(CREDIT_CARD_NUMBER)); |
| 2417 } | 2425 } |
| 2418 | 2426 |
| 2419 TEST_F(AutofillDialogControllerTest, FieldControlsIcons) { | 2427 TEST_F(AutofillDialogControllerTest, FieldControlsIcons) { |
| 2420 EXPECT_TRUE(controller()->FieldControlsIcons(CREDIT_CARD_NUMBER)); | 2428 EXPECT_TRUE(controller()->FieldControlsIcons(CREDIT_CARD_NUMBER)); |
| 2421 EXPECT_FALSE(controller()->FieldControlsIcons(CREDIT_CARD_VERIFICATION_CODE)); | 2429 EXPECT_FALSE(controller()->FieldControlsIcons(CREDIT_CARD_VERIFICATION_CODE)); |
| 2422 EXPECT_FALSE(controller()->FieldControlsIcons(EMAIL_ADDRESS)); | 2430 EXPECT_FALSE(controller()->FieldControlsIcons(EMAIL_ADDRESS)); |
| 2423 } | 2431 } |
| 2424 | 2432 |
| 2425 } // namespace autofill | 2433 } // namespace autofill |
| OLD | NEW |