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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 } | 146 } |
147 | 147 |
148 virtual void UpdateButtonStrip() OVERRIDE { | 148 virtual void UpdateButtonStrip() OVERRIDE { |
149 EXPECT_GE(updates_started_, 1); | 149 EXPECT_GE(updates_started_, 1); |
150 } | 150 } |
151 | 151 |
152 virtual void UpdateDetailArea() OVERRIDE { | 152 virtual void UpdateDetailArea() OVERRIDE { |
153 EXPECT_GE(updates_started_, 1); | 153 EXPECT_GE(updates_started_, 1); |
154 } | 154 } |
155 | 155 |
156 virtual void UpdateAutocheckoutStepsArea() OVERRIDE { | |
157 EXPECT_GE(updates_started_, 1); | |
158 } | |
159 | |
160 virtual void UpdateSection(DialogSection section) OVERRIDE { | 156 virtual void UpdateSection(DialogSection section) OVERRIDE { |
161 EXPECT_GE(updates_started_, 1); | 157 EXPECT_GE(updates_started_, 1); |
162 } | 158 } |
163 | 159 |
164 virtual void FillSection(DialogSection section, | 160 virtual void FillSection(DialogSection section, |
165 const DetailInput& originating_input) OVERRIDE {}; | 161 const DetailInput& originating_input) OVERRIDE {}; |
166 virtual void GetUserInput(DialogSection section, DetailOutputMap* output) | 162 virtual void GetUserInput(DialogSection section, DetailOutputMap* output) |
167 OVERRIDE { | 163 OVERRIDE { |
168 *output = outputs_[section]; | 164 *output = outputs_[section]; |
169 } | 165 } |
170 virtual TestableAutofillDialogView* GetTestableView() OVERRIDE { | 166 virtual TestableAutofillDialogView* GetTestableView() OVERRIDE { |
171 return NULL; | 167 return NULL; |
172 } | 168 } |
173 | 169 |
174 virtual string16 GetCvc() OVERRIDE { return string16(); } | 170 virtual string16 GetCvc() OVERRIDE { return string16(); } |
175 virtual bool SaveDetailsLocally() OVERRIDE { return true; } | 171 virtual bool SaveDetailsLocally() OVERRIDE { return true; } |
176 virtual const content::NavigationController* ShowSignIn() OVERRIDE { | 172 virtual const content::NavigationController* ShowSignIn() OVERRIDE { |
177 return NULL; | 173 return NULL; |
178 } | 174 } |
179 virtual void HideSignIn() OVERRIDE {} | 175 virtual void HideSignIn() OVERRIDE {} |
180 virtual void UpdateProgressBar(double value) OVERRIDE {} | |
181 | 176 |
182 MOCK_METHOD0(ModelChanged, void()); | 177 MOCK_METHOD0(ModelChanged, void()); |
183 MOCK_METHOD0(UpdateForErrors, void()); | 178 MOCK_METHOD0(UpdateForErrors, void()); |
184 | 179 |
185 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {} | 180 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE {} |
186 | 181 |
187 void SetUserInput(DialogSection section, const DetailOutputMap& map) { | 182 void SetUserInput(DialogSection section, const DetailOutputMap& map) { |
188 outputs_[section] = map; | 183 outputs_[section] = map; |
189 } | 184 } |
190 | 185 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 virtual DialogType GetDialogType() const OVERRIDE { | 260 virtual DialogType GetDialogType() const OVERRIDE { |
266 return dialog_type_; | 261 return dialog_type_; |
267 } | 262 } |
268 | 263 |
269 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } | 264 void set_dialog_type(DialogType dialog_type) { dialog_type_ = dialog_type; } |
270 | 265 |
271 void SimulateSigninError() { | 266 void SimulateSigninError() { |
272 OnWalletSigninError(); | 267 OnWalletSigninError(); |
273 } | 268 } |
274 | 269 |
275 bool AutocheckoutIsRunning() const { | |
276 return AUTOCHECKOUT_IN_PROGRESS == autocheckout_state(); | |
277 } | |
278 | |
279 MOCK_METHOD0(LoadRiskFingerprintData, void()); | 270 MOCK_METHOD0(LoadRiskFingerprintData, void()); |
280 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; | 271 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
281 using AutofillDialogControllerImpl::IsEditingExistingData; | 272 using AutofillDialogControllerImpl::IsEditingExistingData; |
282 | 273 |
283 protected: | 274 protected: |
284 virtual PersonalDataManager* GetManager() OVERRIDE { | 275 virtual PersonalDataManager* GetManager() OVERRIDE { |
285 return &test_manager_; | 276 return &test_manager_; |
286 } | 277 } |
287 | 278 |
288 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { | 279 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 } | 490 } |
500 | 491 |
501 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { | 492 const MockNewCreditCardBubbleController* mock_new_card_bubble_controller() { |
502 return mock_new_card_bubble_controller_.get(); | 493 return mock_new_card_bubble_controller_.get(); |
503 } | 494 } |
504 | 495 |
505 private: | 496 private: |
506 void FinishedCallback(const FormStructure* form_structure, | 497 void FinishedCallback(const FormStructure* form_structure, |
507 const std::string& google_transaction_id) { | 498 const std::string& google_transaction_id) { |
508 form_structure_ = form_structure; | 499 form_structure_ = form_structure; |
509 if (controller()->GetDialogType() == DIALOG_TYPE_AUTOCHECKOUT) | |
510 EXPECT_TRUE(controller()->AutocheckoutIsRunning()); | |
511 } | 500 } |
512 | 501 |
513 #if defined(OS_WIN) | 502 #if defined(OS_WIN) |
514 // http://crbug.com/227221 | 503 // http://crbug.com/227221 |
515 ui::ScopedOleInitializer ole_initializer_; | 504 ui::ScopedOleInitializer ole_initializer_; |
516 #endif | 505 #endif |
517 | 506 |
518 // The controller owns itself. | 507 // The controller owns itself. |
519 base::WeakPtr<TestAutofillDialogController> controller_; | 508 base::WeakPtr<TestAutofillDialogController> controller_; |
520 | 509 |
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1875 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | 1864 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); |
1876 controller()->OnDidGetWalletItems(wallet_items.Pass()); | 1865 controller()->OnDidGetWalletItems(wallet_items.Pass()); |
1877 | 1866 |
1878 SwitchToAutofill(); | 1867 SwitchToAutofill(); |
1879 EXPECT_EQ(0U, NotificationsOfType( | 1868 EXPECT_EQ(0U, NotificationsOfType( |
1880 DialogNotification::EXPLANATORY_MESSAGE).size()); | 1869 DialogNotification::EXPLANATORY_MESSAGE).size()); |
1881 EXPECT_EQ(0U, NotificationsOfType( | 1870 EXPECT_EQ(0U, NotificationsOfType( |
1882 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); | 1871 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); |
1883 } | 1872 } |
1884 | 1873 |
1885 TEST_F(AutofillDialogControllerTest, OnAutocheckoutError) { | |
1886 SwitchToAutofill(); | |
1887 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); | |
1888 | |
1889 // We also have to simulate CC inputs to keep the controller happy. | |
1890 FillCreditCardInputs(); | |
1891 | |
1892 controller()->OnAccept(); | |
1893 EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc()); | |
1894 controller()->OnAutocheckoutError(); | |
1895 | |
1896 EXPECT_FALSE(controller()->GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL); | |
1897 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | |
1898 EXPECT_EQ(0U, NotificationsOfType( | |
1899 DialogNotification::AUTOCHECKOUT_SUCCESS).size()); | |
1900 EXPECT_EQ(1U, NotificationsOfType( | |
1901 DialogNotification::AUTOCHECKOUT_ERROR).size()); | |
1902 | |
1903 controller()->ViewClosed(); | |
1904 EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc()); | |
1905 } | |
1906 | |
1907 TEST_F(AutofillDialogControllerTest, OnAutocheckoutSuccess) { | |
1908 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
1909 command_line->AppendSwitch(switches::kWalletServiceUseProd); | |
1910 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); | |
1911 | |
1912 // Simulate first run. | |
1913 profile()->GetPrefs()->SetBoolean(::prefs::kAutofillDialogHasPaidWithWallet, | |
1914 false); | |
1915 SetUpControllerWithFormData(DefaultFormData()); | |
1916 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); | |
1917 | |
1918 // Sign in a user with a completed account. | |
1919 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | |
1920 | |
1921 // Full account; should show "Details from Wallet" message. | |
1922 EXPECT_EQ(1U, NotificationsOfType( | |
1923 DialogNotification::EXPLANATORY_MESSAGE).size()); | |
1924 EXPECT_EQ(0U, NotificationsOfType( | |
1925 DialogNotification::WALLET_USAGE_CONFIRMATION).size()); | |
1926 | |
1927 AcceptAndLoadFakeFingerprint(); | |
1928 EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc()); | |
1929 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); | |
1930 EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty()); | |
1931 | |
1932 EXPECT_EQ(0U, NotificationsOfType( | |
1933 DialogNotification::EXPLANATORY_MESSAGE).size()); | |
1934 | |
1935 controller()->OnAutocheckoutSuccess(); | |
1936 EXPECT_TRUE(controller()->GetDialogOverlay().image.IsEmpty()); | |
1937 | |
1938 EXPECT_FALSE(controller()->GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL); | |
1939 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); | |
1940 EXPECT_EQ(1U, NotificationsOfType( | |
1941 DialogNotification::AUTOCHECKOUT_SUCCESS).size()); | |
1942 EXPECT_EQ(0U, NotificationsOfType( | |
1943 DialogNotification::AUTOCHECKOUT_ERROR).size()); | |
1944 EXPECT_EQ(0U, NotificationsOfType( | |
1945 DialogNotification::EXPLANATORY_MESSAGE).size()); | |
1946 EXPECT_TRUE(profile()->GetPrefs()->GetBoolean( | |
1947 ::prefs::kAutofillDialogHasPaidWithWallet)); | |
1948 | |
1949 controller()->ViewClosed(); | |
1950 EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc()); | |
1951 } | |
1952 | |
1953 TEST_F(AutofillDialogControllerTest, ViewCancelDoesntSetPref) { | 1874 TEST_F(AutofillDialogControllerTest, ViewCancelDoesntSetPref) { |
1954 ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( | 1875 ASSERT_FALSE(profile()->GetPrefs()->HasPrefPath( |
1955 ::prefs::kAutofillDialogPayWithoutWallet)); | 1876 ::prefs::kAutofillDialogPayWithoutWallet)); |
1956 | 1877 |
1957 SwitchToAutofill(); | 1878 SwitchToAutofill(); |
1958 | 1879 |
1959 controller()->OnCancel(); | 1880 controller()->OnCancel(); |
1960 controller()->ViewClosed(); | 1881 controller()->ViewClosed(); |
1961 | 1882 |
1962 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( | 1883 EXPECT_FALSE(profile()->GetPrefs()->HasPrefPath( |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2332 CreateFullWallet("choose_another_instrument_or_address")); | 2253 CreateFullWallet("choose_another_instrument_or_address")); |
2333 EXPECT_EQ(1U, NotificationsOfType( | 2254 EXPECT_EQ(1U, NotificationsOfType( |
2334 DialogNotification::REQUIRED_ACTION).size()); | 2255 DialogNotification::REQUIRED_ACTION).size()); |
2335 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); | 2256 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
2336 | 2257 |
2337 controller()->OnAccept(); | 2258 controller()->OnAccept(); |
2338 EXPECT_EQ(0U, NotificationsOfType( | 2259 EXPECT_EQ(0U, NotificationsOfType( |
2339 DialogNotification::REQUIRED_ACTION).size()); | 2260 DialogNotification::REQUIRED_ACTION).size()); |
2340 } | 2261 } |
2341 | 2262 |
2342 // Make sure detailed steps for Autocheckout are added | |
2343 // and updated correctly. | |
2344 TEST_F(AutofillDialogControllerTest, DetailedSteps) { | |
2345 EXPECT_CALL(*controller()->GetTestingWalletClient(), | |
2346 GetFullWallet(_)).Times(1); | |
2347 | |
2348 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); | |
2349 | |
2350 // Add steps as would normally be done by the AutocheckoutManager. | |
2351 controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING); | |
2352 controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_DELIVERY); | |
2353 controller()->AddAutocheckoutStep(AUTOCHECKOUT_STEP_BILLING); | |
2354 | |
2355 scoped_ptr<wallet::WalletItems> wallet_items = wallet::GetTestWalletItems(); | |
2356 wallet_items->AddInstrument(wallet::GetTestMaskedInstrument()); | |
2357 wallet_items->AddAddress(wallet::GetTestShippingAddress()); | |
2358 controller()->OnDidGetWalletItems(wallet_items.Pass()); | |
2359 // Initiate flow - should add proxy card step since the user is using wallet | |
2360 // data. | |
2361 controller()->OnAccept(); | |
2362 EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc()); | |
2363 controller()->OnDidLoadRiskFingerprintData(GetFakeFingerprint().Pass()); | |
2364 | |
2365 SuggestionState suggestion_state = | |
2366 controller()->SuggestionStateForSection(SECTION_CC_BILLING); | |
2367 EXPECT_TRUE(suggestion_state.extra_text.empty()); | |
2368 | |
2369 // There should be four steps total, with the first being the card generation | |
2370 // step added by the dialog controller. | |
2371 EXPECT_EQ(4U, controller()->CurrentAutocheckoutSteps().size()); | |
2372 EXPECT_EQ(AUTOCHECKOUT_STEP_PROXY_CARD, | |
2373 controller()->CurrentAutocheckoutSteps()[0].type()); | |
2374 EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED, | |
2375 controller()->CurrentAutocheckoutSteps()[0].status()); | |
2376 | |
2377 // Simulate a wallet error. This should remove the card generation step from | |
2378 // the flow, as we will have to proceed with local data. | |
2379 controller()->OnWalletError(wallet::WalletClient::UNKNOWN_ERROR); | |
2380 | |
2381 AutofillProfile shipping_profile(test::GetVerifiedProfile()); | |
2382 AutofillProfile billing_profile(test::GetVerifiedProfile2()); | |
2383 CreditCard credit_card(test::GetVerifiedCreditCard()); | |
2384 controller()->GetTestingManager()->AddTestingProfile(&shipping_profile); | |
2385 controller()->GetTestingManager()->AddTestingProfile(&billing_profile); | |
2386 controller()->GetTestingManager()->AddTestingCreditCard(&credit_card); | |
2387 ui::MenuModel* billing_model = | |
2388 controller()->MenuModelForSection(SECTION_BILLING); | |
2389 billing_model->ActivatedAt(1); | |
2390 | |
2391 // Re-initiate flow. | |
2392 controller()->OnAccept(); | |
2393 EXPECT_TRUE(ReadSetVisuallyDeemphasizedIpc()); | |
2394 | |
2395 // All steps should be initially unstarted. | |
2396 EXPECT_EQ(3U, controller()->CurrentAutocheckoutSteps().size()); | |
2397 EXPECT_EQ(AUTOCHECKOUT_STEP_SHIPPING, | |
2398 controller()->CurrentAutocheckoutSteps()[0].type()); | |
2399 EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, | |
2400 controller()->CurrentAutocheckoutSteps()[0].status()); | |
2401 EXPECT_EQ(AUTOCHECKOUT_STEP_DELIVERY, | |
2402 controller()->CurrentAutocheckoutSteps()[1].type()); | |
2403 EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, | |
2404 controller()->CurrentAutocheckoutSteps()[1].status()); | |
2405 EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING, | |
2406 controller()->CurrentAutocheckoutSteps()[2].type()); | |
2407 EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, | |
2408 controller()->CurrentAutocheckoutSteps()[2].status()); | |
2409 | |
2410 // Update steps in the same manner that we would expect to see from the | |
2411 // AutocheckoutManager while progressing through a flow. | |
2412 controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING, | |
2413 AUTOCHECKOUT_STEP_STARTED); | |
2414 controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_SHIPPING, | |
2415 AUTOCHECKOUT_STEP_COMPLETED); | |
2416 controller()->UpdateAutocheckoutStep(AUTOCHECKOUT_STEP_DELIVERY, | |
2417 AUTOCHECKOUT_STEP_STARTED); | |
2418 | |
2419 // Verify that the steps were appropriately updated. | |
2420 EXPECT_EQ(3U, controller()->CurrentAutocheckoutSteps().size()); | |
2421 EXPECT_EQ(AUTOCHECKOUT_STEP_SHIPPING, | |
2422 controller()->CurrentAutocheckoutSteps()[0].type()); | |
2423 EXPECT_EQ(AUTOCHECKOUT_STEP_COMPLETED, | |
2424 controller()->CurrentAutocheckoutSteps()[0].status()); | |
2425 EXPECT_EQ(AUTOCHECKOUT_STEP_DELIVERY, | |
2426 controller()->CurrentAutocheckoutSteps()[1].type()); | |
2427 EXPECT_EQ(AUTOCHECKOUT_STEP_STARTED, | |
2428 controller()->CurrentAutocheckoutSteps()[1].status()); | |
2429 EXPECT_EQ(AUTOCHECKOUT_STEP_BILLING, | |
2430 controller()->CurrentAutocheckoutSteps()[2].type()); | |
2431 EXPECT_EQ(AUTOCHECKOUT_STEP_UNSTARTED, | |
2432 controller()->CurrentAutocheckoutSteps()[2].status()); | |
2433 | |
2434 controller()->ViewClosed(); | |
2435 EXPECT_FALSE(ReadSetVisuallyDeemphasizedIpc()); | |
2436 } | |
2437 | |
2438 TEST_F(AutofillDialogControllerTest, NewCardBubbleShown) { | 2263 TEST_F(AutofillDialogControllerTest, NewCardBubbleShown) { |
2439 EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(0); | 2264 EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(0); |
2440 | 2265 |
2441 SwitchToAutofill(); | 2266 SwitchToAutofill(); |
2442 FillCreditCardInputs(); | 2267 FillCreditCardInputs(); |
2443 controller()->OnAccept(); | 2268 controller()->OnAccept(); |
2444 controller()->ViewClosed(); | 2269 controller()->ViewClosed(); |
2445 | 2270 |
2446 EXPECT_EQ(1, mock_new_card_bubble_controller()->bubbles_shown()); | 2271 EXPECT_EQ(1, mock_new_card_bubble_controller()->bubbles_shown()); |
2447 } | 2272 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2521 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); | 2346 EXPECT_CALL(*controller()->GetTestingWalletClient(), GetWalletItems(_)); |
2522 controller()->TabActivated(); | 2347 controller()->TabActivated(); |
2523 | 2348 |
2524 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); | 2349 controller()->OnDidGetWalletItems(wallet::GetTestWalletItems()); |
2525 | 2350 |
2526 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); | 2351 EXPECT_FALSE(controller()->MenuModelForSection(SECTION_CC_BILLING)); |
2527 EXPECT_EQ( | 2352 EXPECT_EQ( |
2528 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); | 2353 3, controller()->MenuModelForSection(SECTION_SHIPPING)->GetItemCount()); |
2529 } | 2354 } |
2530 | 2355 |
2531 TEST_F(AutofillDialogControllerTest, GeneratedCardBubbleNotShown) { | |
2532 EXPECT_CALL(*test_generated_bubble_controller(), SetupAndShow(_, _)).Times(0); | |
2533 | |
2534 SubmitWithWalletItems(CompleteAndValidWalletItems()); | |
2535 controller()->set_dialog_type(DIALOG_TYPE_AUTOCHECKOUT); | |
2536 controller()->OnDidGetFullWallet(wallet::GetTestFullWallet()); | |
2537 controller()->OnAutocheckoutError(); | |
2538 controller()->ViewClosed(); | |
2539 | |
2540 EXPECT_EQ(0, mock_new_card_bubble_controller()->bubbles_shown()); | |
2541 } | |
2542 | |
2543 } // namespace autofill | 2356 } // namespace autofill |
OLD | NEW |