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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 21668003: Implement newly saved card bubble for realz and update generated card bubble to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 4 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 <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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 DialogType dialog_type_; 278 DialogType dialog_type_;
279 279
280 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); 280 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
281 }; 281 };
282 282
283 class TestAutofillCreditCardBubbleController : 283 class TestAutofillCreditCardBubbleController :
284 public AutofillCreditCardBubbleController { 284 public AutofillCreditCardBubbleController {
285 public: 285 public:
286 explicit TestAutofillCreditCardBubbleController( 286 explicit TestAutofillCreditCardBubbleController(
287 content::WebContents* contents) 287 content::WebContents* contents)
288 : AutofillCreditCardBubbleController(contents) { 288 : AutofillCreditCardBubbleController(contents),
289 new_card_bubbles_shown_(0) {
289 contents->SetUserData(UserDataKey(), this); 290 contents->SetUserData(UserDataKey(), this);
290 CHECK_EQ(contents->GetUserData(UserDataKey()), this); 291 CHECK_EQ(contents->GetUserData(UserDataKey()), this);
291 } 292 }
292 293
293 virtual ~TestAutofillCreditCardBubbleController() {} 294 virtual ~TestAutofillCreditCardBubbleController() {}
294 295
295 MOCK_METHOD2(ShowAsGeneratedCardBubble, 296 MOCK_METHOD2(ShowAsGeneratedCardBubble,
296 void(const base::string16& backing_card_name, 297 void(const base::string16& backing_card_name,
297 const base::string16& fronting_card_name)); 298 const base::string16& fronting_card_name));
298 MOCK_METHOD1(ShowAsNewCardSavedBubble, 299
299 void(const base::string16& newly_saved_card_name)); 300 int new_card_bubbles_shown() const { return new_card_bubbles_shown_; }
301 const CreditCard* new_card() const { return new_card_.get(); }
300 302
301 protected: 303 protected:
304 virtual void ShowAsNewCardSavedBubble(
305 scoped_ptr<CreditCard> new_card,
306 scoped_ptr<AutofillProfile> billing_profile) OVERRIDE {
307 ++new_card_bubbles_shown_;
308 new_card_ = new_card.Pass();
309 // At the moment there's no keep |billing_profile|.
310 }
311
302 virtual base::WeakPtr<AutofillCreditCardBubble> CreateBubble() OVERRIDE { 312 virtual base::WeakPtr<AutofillCreditCardBubble> CreateBubble() OVERRIDE {
303 return TestAutofillCreditCardBubble::Create(GetWeakPtr()); 313 return TestAutofillCreditCardBubble::Create(GetWeakPtr());
304 } 314 }
305 315
306 virtual bool CanShow() const OVERRIDE { 316 virtual bool CanShow() const OVERRIDE {
307 return true; 317 return true;
308 } 318 }
309 319
310 private: 320 private:
321 // The number of new card saved bubble shown through this class.
322 int new_card_bubbles_shown_;
323
324 // The last credit card and billing info shown in a new card bubble.
325 scoped_ptr<CreditCard> new_card_;
326
311 DISALLOW_COPY_AND_ASSIGN(TestAutofillCreditCardBubbleController); 327 DISALLOW_COPY_AND_ASSIGN(TestAutofillCreditCardBubbleController);
312 }; 328 };
313 329
314 class AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness { 330 class AutofillDialogControllerTest : public ChromeRenderViewHostTestHarness {
315 protected: 331 protected:
316 AutofillDialogControllerTest(): form_structure_(NULL) {} 332 AutofillDialogControllerTest(): form_structure_(NULL) {}
317 333
318 // testing::Test implementation: 334 // testing::Test implementation:
319 virtual void SetUp() OVERRIDE { 335 virtual void SetUp() OVERRIDE {
320 ChromeRenderViewHostTestHarness::SetUp(); 336 ChromeRenderViewHostTestHarness::SetUp();
(...skipping 1962 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, 2299 EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED,
2284 controller()->CurrentAutocheckoutSteps()[2].status()); 2300 controller()->CurrentAutocheckoutSteps()[2].status());
2285 2301
2286 controller()->ViewClosed(); 2302 controller()->ViewClosed();
2287 EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc()); 2303 EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc());
2288 } 2304 }
2289 2305
2290 2306
2291 TEST_F(AutofillDialogControllerTest, NewCardBubbleShown) { 2307 TEST_F(AutofillDialogControllerTest, NewCardBubbleShown) {
2292 EXPECT_CALL(*test_bubble_controller(), 2308 EXPECT_CALL(*test_bubble_controller(),
2293 ShowAsNewCardSavedBubble(ASCIIToUTF16("Visa - 1111"))).Times(1);
2294 EXPECT_CALL(*test_bubble_controller(),
2295 ShowAsGeneratedCardBubble(_, _)).Times(0); 2309 ShowAsGeneratedCardBubble(_, _)).Times(0);
2296 2310
2297 SwitchToAutofill(); 2311 SwitchToAutofill();
2298 FillCreditCardInputs(); 2312 FillCreditCardInputs();
2299 controller()->OnAccept(); 2313 controller()->OnAccept();
2300 controller()->ViewClosed(); 2314 controller()->ViewClosed();
2315
2316 EXPECT_EQ(1, test_bubble_controller()->new_card_bubbles_shown());
2317 EXPECT_EQ(ASCIIToUTF16("Visa - 4111"),
2318 test_bubble_controller()->new_card()->TypeAndLastFourDigits());
2301 } 2319 }
2302 2320
2303 TEST_F(AutofillDialogControllerTest, GeneratedCardBubbleShown) { 2321 TEST_F(AutofillDialogControllerTest, GeneratedCardBubbleShown) {
2304 EXPECT_CALL(*test_bubble_controller(), 2322 EXPECT_CALL(*test_bubble_controller(),
2305 ShowAsGeneratedCardBubble(_, _)).Times(1); 2323 ShowAsGeneratedCardBubble(_, _)).Times(1);
2306 EXPECT_CALL(*test_bubble_controller(), ShowAsNewCardSavedBubble(_)).Times(0);
2307 2324
2308 SubmitWithWalletItems(CompleteAndValidWalletItems()); 2325 SubmitWithWalletItems(CompleteAndValidWalletItems());
2309 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 2326 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2310 controller()->ViewClosed(); 2327 controller()->ViewClosed();
2328
2329 EXPECT_EQ(0, test_bubble_controller()->new_card_bubbles_shown());
2311 } 2330 }
2312 2331
2313 TEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) { 2332 TEST_F(AutofillDialogControllerTest, ReloadWalletItemsOnActivation) {
2314 // Switch into Wallet mode and initialize some Wallet data. 2333 // Switch into Wallet mode and initialize some Wallet data.
2315 SwitchToWallet(); 2334 SwitchToWallet();
2316 2335
2317 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); 2336 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems();
2318 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); 2337 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument());
2319 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument()); 2338 wallet_items->AddInstrument(wallet::GetTestNonDefaultMaskedInstrument());
2320 wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress()); 2339 wallet_items->AddAddress(wallet::GetTestNonDefaultShippingAddress());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); 2397 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems());
2379 2398
2380 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); 2399 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING));
2381 EXPECT_EQ( 2400 EXPECT_EQ(
2382 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); 2401 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount());
2383 } 2402 }
2384 2403
2385 TEST_F(AutofillDialogControllerTest, GeneratedCardBubbleNotShown) { 2404 TEST_F(AutofillDialogControllerTest, GeneratedCardBubbleNotShown) {
2386 EXPECT_CALL(*test_bubble_controller(), 2405 EXPECT_CALL(*test_bubble_controller(),
2387 ShowAsGeneratedCardBubble(_, _)).Times(0); 2406 ShowAsGeneratedCardBubble(_, _)).Times(0);
2388 EXPECT_CALL(*test_bubble_controller(), ShowAsNewCardSavedBubble(_)).Times(0);
2389 2407
2390 SubmitWithWalletItems(CompleteAndValidWalletItems()); 2408 SubmitWithWalletItems(CompleteAndValidWalletItems());
2391 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); 2409 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT);
2392 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); 2410 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet());
2393 controller()->OnAutocheckoutError(); 2411 controller()->OnAutocheckoutError();
2394 controller()->ViewClosed(); 2412 controller()->ViewClosed();
2413
2414 EXPECT_EQ(0, test_bubble_controller()->new_card_bubbles_shown());
2395 } 2415 }
2396 2416
2397 } // namespace autofill 2417 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698