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

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

Issue 1139643006: Rename chrome/android/javatests to javatests_shell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 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
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.autofill;
6
7 import org.chromium.base.ThreadUtils;
8 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
9 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard;
10 import org.chromium.chrome.browser.autofill.PersonalDataManager.PersonalDataMana gerObserver;
11
12 import java.util.List;
13 import java.util.concurrent.Callable;
14 import java.util.concurrent.ExecutionException;
15
16 /**
17 * Helper class for testing AutofillProfiles.
18 */
19 public class AutofillTestHelper {
20
21 private Object mObserverNotified;
22
23 public AutofillTestHelper() {
24 registerDataObserver();
25 }
26
27 AutofillProfile getProfile(final String guid) throws ExecutionException {
28 return ThreadUtils.runOnUiThreadBlocking(new Callable<AutofillProfile>() {
29 @Override
30 public AutofillProfile call() {
31 return PersonalDataManager.getInstance().getProfile(guid);
32 }
33 });
34 }
35
36 List<AutofillProfile> getProfiles() throws ExecutionException {
37 return ThreadUtils.runOnUiThreadBlocking(new Callable<List<AutofillProfi le>>() {
38 @Override
39 public List<AutofillProfile> call() {
40 return PersonalDataManager.getInstance().getProfiles();
41 }
42 });
43 }
44
45 int getNumberOfProfiles() throws ExecutionException {
46 return ThreadUtils.runOnUiThreadBlocking(new Callable<Integer>() {
47 @Override
48 public Integer call() {
49 return PersonalDataManager.getInstance().getProfiles().size();
50 }
51 }).intValue();
52 }
53
54 String setProfile(final AutofillProfile profile) throws InterruptedException ,
55 ExecutionException {
56 String guid = ThreadUtils.runOnUiThreadBlocking(new Callable<String>() {
57 @Override
58 public String call() {
59 return PersonalDataManager.getInstance().setProfile(profile);
60 }
61 });
62 waitForDataChanged();
63 return guid;
64 }
65
66 void deleteProfile(final String guid) throws InterruptedException {
67 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
68 @Override
69 public void run() {
70 PersonalDataManager.getInstance().deleteProfile(guid);
71 }
72 });
73 waitForDataChanged();
74 }
75
76 CreditCard getCreditCard(final String guid) throws ExecutionException {
77 return ThreadUtils.runOnUiThreadBlocking(new Callable<CreditCard>() {
78 @Override
79 public CreditCard call() {
80 return PersonalDataManager.getInstance().getCreditCard(guid);
81 }
82 });
83 }
84
85 int getNumberOfCreditCards() throws ExecutionException {
86 return ThreadUtils.runOnUiThreadBlocking(new Callable<Integer>() {
87 @Override
88 public Integer call() {
89 return PersonalDataManager.getInstance().getCreditCards().size() ;
90 }
91 }).intValue();
92 }
93
94 String setCreditCard(final CreditCard card) throws InterruptedException, Exe cutionException {
95 String guid = ThreadUtils.runOnUiThreadBlocking(new Callable<String>() {
96 @Override
97 public String call() {
98 return PersonalDataManager.getInstance().setCreditCard(card);
99 }
100 });
101 waitForDataChanged();
102 return guid;
103 }
104
105 void deleteCreditCard(final String guid) throws InterruptedException {
106 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
107 @Override
108 public void run() {
109 PersonalDataManager.getInstance().deleteCreditCard(guid);
110 }
111 });
112 waitForDataChanged();
113 }
114
115 private void registerDataObserver() {
116 mObserverNotified = new Object();
117 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
118 @Override
119 public void run() {
120 PersonalDataManager.getInstance().registerDataObserver(
121 new PersonalDataManagerObserver() {
122 @Override
123 public void onPersonalDataChanged() {
124 synchronized (mObserverNotified) {
125 mObserverNotified.notifyAll();
126 }
127 }
128 }
129 );
130 }
131 });
132 }
133
134 public void waitForDataChanged() throws InterruptedException {
135 synchronized (mObserverNotified) {
136 mObserverNotified.wait(3000);
137 }
138 }
139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698