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 2267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2278 TEST_F(AutofillDialogControllerTest, GeneratedCardBubbleShown) { | 2278 TEST_F(AutofillDialogControllerTest, GeneratedCardBubbleShown) { |
2279 EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(1); | 2279 EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(1); |
2280 | 2280 |
2281 SubmitWithWalletItems(CompleteAndValidWalletItems()); | 2281 SubmitWithWalletItems(CompleteAndValidWalletItems()); |
2282 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); | 2282 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); |
2283 controller()->ViewClosed(); | 2283 controller()->ViewClosed(); |
2284 | 2284 |
2285 EXPECT_EQ(0, mock_new_card_bubble_controller()->bubbles_shown()); | 2285 EXPECT_EQ(0, mock_new_card_bubble_controller()->bubbles_shown()); |
2286 } | 2286 } |
2287 | 2287 |
| 2288 // Verify that new Wallet data is fetched when the user switches away from the |
| 2289 // tab hosting the Autofill dialog and back. Also verify that the user's |
| 2290 // selection is preserved across this re-fetch. |
2288 TEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) { | 2291 TEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) { |
2289 // Switch into Wallet mode and initialize some Wallet data. | 2292 // Switch into Wallet mode and initialize some Wallet data. |
2290 SwitchToWallet(); | 2293 SwitchToWallet(); |
2291 | 2294 |
2292 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | 2295 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
2293 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 2296 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
2294 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); | 2297 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
2295 wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); | 2298 wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); |
2296 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | 2299 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
2297 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 2300 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
2298 | 2301 |
2299 // Initially, the default entries should be selected. | 2302 // Initially, the default entries should be selected. |
2300 ui::MenuModel* cc_billing_model = | 2303 ui::MenuModel* cc_billing_model = |
2301 controller()->MenuModelForSection(SECTION_CC_BILLING); | 2304 controller()->MenuModelForSection(SECTION_CC_BILLING); |
2302 ui::MenuModel* shipping_model = | 2305 ui::MenuModel* shipping_model = |
2303 controller()->MenuModelForSection(SECTION_SHIPPING); | 2306 controller()->MenuModelForSection(SECTION_SHIPPING); |
2304 // "add", "manage", and 2 suggestions. | 2307 // "add", "manage", and 2 suggestions. |
2305 ASSERT_EQ(4, cc_billing_model->GetItemCount()); | 2308 ASSERT_EQ(4, cc_billing_model->GetItemCount()); |
2306 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(0)); | 2309 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(0)); |
2307 // "use billing", "add", "manage", and 2 suggestions. | 2310 // "use billing", "add", "manage", and 2 suggestions. |
2308 ASSERT_EQ(5, shipping_model->GetItemCount()); | 2311 ASSERT_EQ(5, shipping_model->GetItemCount()); |
2309 EXPECT_TRUE(shipping_model->IsItemCheckedAt(2)); | 2312 EXPECT_TRUE(shipping_model->IsItemCheckedAt(2)); |
2310 | 2313 |
2311 // Select entries other than the defaults. | 2314 // Select entries other than the defaults. |
2312 cc_billing_model->ActivatedAt(1); | 2315 cc_billing_model->ActivatedAt(1); |
2313 shipping_model->ActivatedAt(1); | 2316 shipping_model->ActivatedAt(1); |
2314 // "add", "manage", and 2 suggestions. | 2317 // 2 suggestions, "add", and "manage". |
2315 ASSERT_EQ(4, cc_billing_model->GetItemCount()); | 2318 ASSERT_EQ(4, cc_billing_model->GetItemCount()); |
2316 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(1)); | 2319 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(1)); |
2317 // "use billing", "add", "manage", and 2 suggestions. | 2320 // "use billing", 2 suggestions, "add", "manage". |
2318 ASSERT_EQ(5, shipping_model->GetItemCount()); | 2321 ASSERT_EQ(5, shipping_model->GetItemCount()); |
2319 EXPECT_TRUE(shipping_model-> IsItemCheckedAt(1)); | 2322 EXPECT_TRUE(shipping_model-> IsItemCheckedAt(1)); |
2320 | 2323 |
2321 // Simulate switching away from the tab and back. This should issue a request | 2324 // Simulate switching away from the tab and back. This should issue a request |
2322 // for wallet items. | 2325 // for wallet items. |
2323 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); | 2326 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); |
2324 controller()->TabActivated(); | 2327 controller()->TabActivated(); |
2325 | 2328 |
2326 // Simulate a response that includes different items. | 2329 // Simulate a response that includes different items. |
2327 wallet_items = wallet::GetTestWalletItems(); | 2330 wallet_items = wallet::GetTestWalletItems(); |
2328 wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); | 2331 wallet_items->AddInstrument(wallet::GetTestMaskedInstrumentExpired()); |
2329 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 2332 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
2330 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); | 2333 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
2331 wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); | 2334 wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); |
2332 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 2335 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
2333 | 2336 |
2334 // The previously selected entries should still be selected. | 2337 // The previously selected entries should still be selected. |
2335 // "add", "manage", and 3 suggestions. | 2338 // 3 suggestions, "add", and "manage". |
2336 ASSERT_EQ(5, cc_billing_model->GetItemCount()); | 2339 ASSERT_EQ(5, cc_billing_model->GetItemCount()); |
2337 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(2)); | 2340 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(2)); |
2338 // "use billing", "add", "manage", and 1 suggestion. | 2341 // "use billing", 1 suggestion, "add", and "manage". |
2339 ASSERT_EQ(4, shipping_model->GetItemCount()); | 2342 ASSERT_EQ(4, shipping_model->GetItemCount()); |
2340 EXPECT_TRUE(shipping_model->IsItemCheckedAt(1)); | 2343 EXPECT_TRUE(shipping_model->IsItemCheckedAt(1)); |
2341 } | 2344 } |
2342 | 2345 |
| 2346 // Verify that if the default values change when re-fetching Wallet data, these |
| 2347 // new default values are selected in the dialog. |
| 2348 TEST_F(AutofillDialogControllerTest, |
| 2349 ReloadWalletItemsOnActivationWithNewDefaults) { |
| 2350 // Switch into Wallet mode and initialize some Wallet data. |
| 2351 SwitchToWallet(); |
| 2352 |
| 2353 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); |
| 2354 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
| 2355 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); |
| 2356 wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); |
| 2357 wallet_items->AddAddress(wallet::GetTestShippingAddress()); |
| 2358 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 2359 |
| 2360 // Initially, the default entries should be selected. |
| 2361 ui::MenuModel* cc_billing_model = |
| 2362 controller()->MenuModelForSection(SECTION_CC_BILLING); |
| 2363 ui::MenuModel* shipping_model = |
| 2364 controller()->MenuModelForSection(SECTION_SHIPPING); |
| 2365 // 2 suggestions, "add", and "manage". |
| 2366 ASSERT_EQ(4, cc_billing_model->GetItemCount()); |
| 2367 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(0)); |
| 2368 // "use billing", 2 suggestions, "add", and "manage". |
| 2369 ASSERT_EQ(5, shipping_model->GetItemCount()); |
| 2370 EXPECT_TRUE(shipping_model->IsItemCheckedAt(2)); |
| 2371 |
| 2372 // Simulate switching away from the tab and back. This should issue a request |
| 2373 // for wallet items. |
| 2374 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); |
| 2375 controller()->TabActivated(); |
| 2376 |
| 2377 // Simulate a response that includes different default values. |
| 2378 wallet_items = |
| 2379 wallet::GetTestWalletItemsWithDefaultIds("new_default_instrument_id", |
| 2380 "new_default_address_id"); |
| 2381 scoped_ptr<wallet::Address> other_address = wallet::GetTestShippingAddress(); |
| 2382 other_address->set_object_id("other_address_id"); |
| 2383 scoped_ptr<wallet::Address> new_default_address = |
| 2384 wallet::GetTestNonDefaultShippingAddress(); |
| 2385 new_default_address->set_object_id("new_default_address_id"); |
| 2386 |
| 2387 wallet_items->AddInstrument( |
| 2388 wallet::GetTestMaskedInstrumentWithId("other_instrument_id")); |
| 2389 wallet_items->AddInstrument( |
| 2390 wallet::GetTestMaskedInstrumentWithId("new_default_instrument_id")); |
| 2391 wallet_items->AddAddress(new_default_address.Pass()); |
| 2392 wallet_items->AddAddress(other_address.Pass()); |
| 2393 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
| 2394 |
| 2395 // The new default entries should be selected. |
| 2396 // 2 suggestions, "add", and "manage". |
| 2397 ASSERT_EQ(4, cc_billing_model->GetItemCount()); |
| 2398 EXPECT_TRUE(cc_billing_model->IsItemCheckedAt(1)); |
| 2399 // "use billing", 2 suggestions, "add", and "manage". |
| 2400 ASSERT_EQ(5, shipping_model->GetItemCount()); |
| 2401 EXPECT_TRUE(shipping_model->IsItemCheckedAt(1)); |
| 2402 } |
| 2403 |
2343 TEST_F(AutofillDialogControllerTest, ReloadWithEmptyWalletItems) { | 2404 TEST_F(AutofillDialogControllerTest, ReloadWithEmptyWalletItems) { |
2344 SwitchToWallet(); | 2405 SwitchToWallet(); |
2345 | 2406 |
2346 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | 2407 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
2347 controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(1); | 2408 controller()->MenuModelForSection(SECTION_CC_BILLING)->ActivatedAt(1); |
2348 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1); | 2409 controller()->MenuModelForSection(SECTION_SHIPPING)->ActivatedAt(1); |
2349 | 2410 |
2350 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); | 2411 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); |
2351 controller()->TabActivated(); | 2412 controller()->TabActivated(); |
2352 | 2413 |
2353 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); | 2414 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); |
2354 | 2415 |
2355 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); | 2416 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); |
2356 EXPECT_EQ( | 2417 EXPECT_EQ( |
2357 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); | 2418 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); |
2358 } | 2419 } |
2359 | 2420 |
2360 } // namespace autofill | 2421 } // namespace autofill |
OLD | NEW |