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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/autofill/CardUnmaskPrompt.java

Issue 1964323002: Reland: Test dismissing CVC prompt for PaymentRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 package org.chromium.chrome.browser.autofill; 5 package org.chromium.chrome.browser.autofill;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.DialogInterface; 8 import android.content.DialogInterface;
9 import android.content.res.Resources; 9 import android.content.res.Resources;
10 import android.graphics.Color; 10 import android.graphics.Color;
11 import android.graphics.ColorFilter; 11 import android.graphics.ColorFilter;
12 import android.graphics.PorterDuff; 12 import android.graphics.PorterDuff;
13 import android.graphics.PorterDuffColorFilter; 13 import android.graphics.PorterDuffColorFilter;
14 import android.os.AsyncTask;
14 import android.os.Build; 15 import android.os.Build;
15 import android.os.Handler; 16 import android.os.Handler;
16 import android.support.v4.view.MarginLayoutParamsCompat; 17 import android.support.v4.view.MarginLayoutParamsCompat;
17 import android.support.v4.view.ViewCompat; 18 import android.support.v4.view.ViewCompat;
18 import android.support.v7.app.AlertDialog; 19 import android.support.v7.app.AlertDialog;
19 import android.text.Editable; 20 import android.text.Editable;
20 import android.text.TextWatcher; 21 import android.text.TextWatcher;
21 import android.view.LayoutInflater; 22 import android.view.LayoutInflater;
22 import android.view.View; 23 import android.view.View;
23 import android.view.View.OnClickListener; 24 import android.view.View.OnClickListener;
(...skipping 19 matching lines...) Expand all
43 * A prompt that bugs users to enter their CVC when unmasking a Wallet instrumen t (credit card). 44 * A prompt that bugs users to enter their CVC when unmasking a Wallet instrumen t (credit card).
44 */ 45 */
45 public class CardUnmaskPrompt 46 public class CardUnmaskPrompt
46 implements DialogInterface.OnDismissListener, TextWatcher, OnClickListen er { 47 implements DialogInterface.OnDismissListener, TextWatcher, OnClickListen er {
47 private static CardUnmaskObserverForTest sObserverForTest; 48 private static CardUnmaskObserverForTest sObserverForTest;
48 49
49 private final CardUnmaskPromptDelegate mDelegate; 50 private final CardUnmaskPromptDelegate mDelegate;
50 private final CardUnmaskObserverForTest mObserverForTest; 51 private final CardUnmaskObserverForTest mObserverForTest;
51 private final AlertDialog mDialog; 52 private final AlertDialog mDialog;
52 private boolean mShouldRequestExpirationDate; 53 private boolean mShouldRequestExpirationDate;
53 private final int mThisYear;
54 private final int mThisMonth;
55 54
56 private final View mMainView; 55 private final View mMainView;
57 private final TextView mInstructions; 56 private final TextView mInstructions;
58 private final TextView mNoRetryErrorMessage; 57 private final TextView mNoRetryErrorMessage;
59 private final EditText mCardUnmaskInput; 58 private final EditText mCardUnmaskInput;
60 private final EditText mMonthInput; 59 private final EditText mMonthInput;
61 private final EditText mYearInput; 60 private final EditText mYearInput;
62 private final View mExpirationContainer; 61 private final View mExpirationContainer;
63 private final TextView mNewCardLink; 62 private final TextView mNewCardLink;
64 private final TextView mErrorMessage; 63 private final TextView mErrorMessage;
65 private final CheckBox mStoreLocallyCheckbox; 64 private final CheckBox mStoreLocallyCheckbox;
66 private final ImageView mStoreLocallyTooltipIcon; 65 private final ImageView mStoreLocallyTooltipIcon;
67 private PopupWindow mStoreLocallyTooltipPopup; 66 private PopupWindow mStoreLocallyTooltipPopup;
68 private final ViewGroup mControlsContainer; 67 private final ViewGroup mControlsContainer;
69 private final View mVerificationOverlay; 68 private final View mVerificationOverlay;
70 private final ProgressBar mVerificationProgressBar; 69 private final ProgressBar mVerificationProgressBar;
71 private final TextView mVerificationView; 70 private final TextView mVerificationView;
72 71
72 private int mThisYear;
73 private int mThisMonth;
74 private boolean mValidationWaitsForCalendarTask;
75
73 /** 76 /**
74 * An interface to handle the interaction with an CardUnmaskPrompt object. 77 * An interface to handle the interaction with an CardUnmaskPrompt object.
75 */ 78 */
76 public interface CardUnmaskPromptDelegate { 79 public interface CardUnmaskPromptDelegate {
77 /** 80 /**
78 * Called when the dialog has been dismissed. 81 * Called when the dialog has been dismissed.
79 */ 82 */
80 void dismissed(); 83 void dismissed();
81 84
82 /** 85 /**
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 160
158 mDialog = new AlertDialog.Builder(context, R.style.AlertDialogTheme) 161 mDialog = new AlertDialog.Builder(context, R.style.AlertDialogTheme)
159 .setTitle(title) 162 .setTitle(title)
160 .setView(v) 163 .setView(v)
161 .setNegativeButton(R.string.cancel, null) 164 .setNegativeButton(R.string.cancel, null)
162 .setPositiveButton(confirmButtonLabel, null) 165 .setPositiveButton(confirmButtonLabel, null)
163 .create(); 166 .create();
164 mDialog.setOnDismissListener(this); 167 mDialog.setOnDismissListener(this);
165 168
166 mShouldRequestExpirationDate = shouldRequestExpirationDate; 169 mShouldRequestExpirationDate = shouldRequestExpirationDate;
167 mThisYear = Calendar.getInstance().get(Calendar.YEAR); 170 mThisYear = -1;
168 mThisMonth = Calendar.getInstance().get(Calendar.MONTH) + 1; 171 mThisMonth = -1;
172 if (mShouldRequestExpirationDate) new CalendarTask().execute();
gone 2016/05/11 17:47:46 Do you need to disable the button until the date h
please use gerrit instead 2016/05/11 17:58:56 It's disabled on lines 199-200: Button verifyBu
173 }
174
175 /**
176 * Avoids disk reads for timezone when getting the default instance of Calen dar.
177 */
178 private class CalendarTask extends AsyncTask<Void, Void, Calendar> {
179 @Override
180 protected Calendar doInBackground(Void... unused) {
181 return Calendar.getInstance();
182 }
183
184 @Override
185 protected void onPostExecute(Calendar result) {
186 mThisYear = result.get(Calendar.YEAR);
187 mThisMonth = result.get(Calendar.MONTH) + 1;
188 if (mValidationWaitsForCalendarTask) validate();
189 }
169 } 190 }
170 191
171 public void show() { 192 public void show() {
172 mDialog.show(); 193 mDialog.show();
173 194
174 showExpirationDateInputsInputs(); 195 showExpirationDateInputsInputs();
175 196
176 // Override the View.OnClickListener so that pressing the positive butto n doesn't dismiss 197 // Override the View.OnClickListener so that pressing the positive butto n doesn't dismiss
177 // the dialog. 198 // the dialog.
178 Button verifyButton = mDialog.getButton(AlertDialog.BUTTON_POSITIVE); 199 Button verifyButton = mDialog.getButton(AlertDialog.BUTTON_POSITIVE);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 266 }
246 } 267 }
247 268
248 @Override 269 @Override
249 public void onDismiss(DialogInterface dialog) { 270 public void onDismiss(DialogInterface dialog) {
250 mDelegate.dismissed(); 271 mDelegate.dismissed();
251 } 272 }
252 273
253 @Override 274 @Override
254 public void afterTextChanged(Editable s) { 275 public void afterTextChanged(Editable s) {
276 validate();
277 }
278
279 private void validate() {
255 mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(areInputsValid ()); 280 mDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(areInputsValid ());
256 } 281 }
257 282
258 @Override 283 @Override
259 public void beforeTextChanged(CharSequence s, int start, int count, int afte r) {} 284 public void beforeTextChanged(CharSequence s, int start, int count, int afte r) {}
260 285
261 @Override 286 @Override
262 public void onTextChanged(CharSequence s, int start, int before, int count) {} 287 public void onTextChanged(CharSequence s, int start, int before, int count) {}
263 288
264 @Override 289 @Override
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 View view = mShouldRequestExpirationDate ? mMonthInput : mCardUnmaskInpu t; 370 View view = mShouldRequestExpirationDate ? mMonthInput : mCardUnmaskInpu t;
346 imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); 371 imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
347 view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED); 372 view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
348 if (mObserverForTest != null) { 373 if (mObserverForTest != null) {
349 mObserverForTest.onCardUnmaskReadyForInput(CardUnmaskPrompt.this); 374 mObserverForTest.onCardUnmaskReadyForInput(CardUnmaskPrompt.this);
350 } 375 }
351 } 376 }
352 377
353 private boolean areInputsValid() { 378 private boolean areInputsValid() {
354 if (mShouldRequestExpirationDate) { 379 if (mShouldRequestExpirationDate) {
380 if (mThisYear == -1 || mThisMonth == -1) {
381 mValidationWaitsForCalendarTask = true;
382 return false;
383 }
384
355 int month = -1; 385 int month = -1;
356 try { 386 try {
357 month = Integer.parseInt(mMonthInput.getText().toString()); 387 month = Integer.parseInt(mMonthInput.getText().toString());
358 if (month < 1 || month > 12) return false; 388 if (month < 1 || month > 12) return false;
359 } catch (NumberFormatException e) { 389 } catch (NumberFormatException e) {
360 return false; 390 return false;
361 } 391 }
362 392
363 int year = getFourDigitYear(); 393 int year = getFourDigitYear();
364 if (year < mThisYear || year > mThisYear + 10) return false; 394 if (year < mThisYear || year > mThisYear + 10) return false;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 @VisibleForTesting 502 @VisibleForTesting
473 public static void setObserverForTest(CardUnmaskObserverForTest observerForT est) { 503 public static void setObserverForTest(CardUnmaskObserverForTest observerForT est) {
474 sObserverForTest = observerForTest; 504 sObserverForTest = observerForTest;
475 } 505 }
476 506
477 @VisibleForTesting 507 @VisibleForTesting
478 public AlertDialog getDialogForTest() { 508 public AlertDialog getDialogForTest() {
479 return mDialog; 509 return mDialog;
480 } 510 }
481 } 511 }
OLDNEW
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentRequestImpl.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698