diff options
8 files changed, 376 insertions, 167 deletions
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillPopupTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillPopupTest.java new file mode 100644 index 0000000..f39c70c --- /dev/null +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillPopupTest.java @@ -0,0 +1,177 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.chrome.browser.autofill; + +import org.chromium.base.test.util.Feature; +import org.chromium.base.test.util.UrlUtils; +import org.chromium.chrome.R; +import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; +import org.chromium.chrome.testshell.ChromiumTestShellTestBase; +import org.chromium.content.browser.ContentView; +import org.chromium.content.browser.test.util.Criteria; +import org.chromium.content.browser.test.util.CriteriaHelper; +import org.chromium.content.browser.test.util.DOMUtils; +import org.chromium.content.browser.test.util.TestCallbackHelperContainer; +import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; +import org.chromium.content.browser.test.util.TouchCommon; +import org.chromium.ui.autofill.AutofillPopup; + +import android.test.suitebuilder.annotation.MediumTest; +import android.text.TextUtils; +import android.view.View; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +/** + * Integration tests for the AutofillPopup. + */ +public class AutofillPopupTest extends ChromiumTestShellTestBase { + + private static final String FIRST_NAME = "John"; + private static final String LAST_NAME = "Smith"; + private static final String COMPANY_NAME = "Acme Inc."; + private static final String ADDRESS_LINE1 = "1 Main"; + private static final String ADDRESS_LINE2 = "Apt A"; + private static final String CITY = "San Francisco"; + private static final String STATE = "CA"; + private static final String ZIP_CODE = "94102"; + private static final String COUNTRY = "US"; + private static final String PHONE_NUMBER = "4158889999"; + private static final String EMAIL = "john@acme.inc"; + private static final String ORIGIN = "https://www.example.com"; + + private static final String PAGE_DATA = UrlUtils.encodeHtmlDataUri( + "<html><head><meta name=\"viewport\"" + + "content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0\" /></head>" + + "<body><form method=\"POST\">" + + "<input type=\"text\" id=\"fn\" autocomplete=\"given-name\"><br>" + + "<input type=\"text\" id=\"ln\" autocomplete=\"family-name\"><br>" + + "<input type=\"text\" id=\"a1\" autocomplete=\"address-line1\"><br>" + + "<input type=\"text\" id=\"a2\" autocomplete=\"address-line2\"><br>" + + "<input type=\"text\" id=\"ct\" autocomplete=\"locality\"><br>" + + "<input type=\"text\" id=\"zc\" autocomplete=\"postal-code\"><br>" + + "<input type=\"text\" id=\"em\" autocomplete=\"email\"><br>" + + "<input type=\"text\" id=\"ph\" autocomplete=\"tel\"><br>" + + "<input type=\"submit\" />" + + "</form></body></html>"); + + private AutofillTestHelper mHelper; + + @Override + public void setUp() throws Exception { + super.setUp(); + clearAppData(); + launchChromiumTestShellWithUrl(PAGE_DATA); + assertTrue(waitForActiveShellToBeDoneLoading()); + mHelper = new AutofillTestHelper(); + } + + @MediumTest + @Feature({"autofill"}) + public void testClickAutofillPopupSuggestion() + throws InterruptedException, ExecutionException, TimeoutException { + // The TestInputMethodManagerWrapper intercepts showSoftInput so that a keyboard is never + // brought up. + final ContentView view = getActivity().getActiveContentView(); + final TestInputMethodManagerWrapper immw = + new TestInputMethodManagerWrapper(view.getContentViewCore()); + view.getContentViewCore().getImeAdapterForTest().setInputMethodManagerWrapper(immw); + + // Add an Autofill profile. + AutofillProfile profile = new AutofillProfile( + "" /* guid */, ORIGIN, FIRST_NAME + " " + LAST_NAME, COMPANY_NAME, ADDRESS_LINE1, + ADDRESS_LINE2, CITY, STATE, ZIP_CODE, COUNTRY, PHONE_NUMBER, EMAIL); + String profileOneGUID = mHelper.setProfile(profile); + assertEquals(1, mHelper.getNumberOfProfiles()); + + // Click the input field for the first name. + final TestCallbackHelperContainer viewClient = new TestCallbackHelperContainer(view); + DOMUtils.clickNode(this, view, viewClient, "fn"); + + waitForKeyboardShowRequest(immw, 1); + + view.getContentViewCore().getInputConnectionForTest().setComposingText("J", 1); + + waitForAnchorViewAdd(view); + View anchorView = view.findViewById(R.id.autofill_popup_window); + + assertTrue(anchorView.getTag(R.id.autofill_popup_window) instanceof AutofillPopup); + final AutofillPopup popup = (AutofillPopup) anchorView.getTag(R.id.autofill_popup_window); + + waitForAutofillPopopShow(popup); + + TouchCommon touchCommon = new TouchCommon(this); + touchCommon.singleClickViewRelative(popup.getListView(), 10, 10); + + waitForInputFieldFill(view, viewClient); + + assertEquals("First name did not match", + FIRST_NAME, DOMUtils.getNodeValue(view, viewClient, "fn")); + assertEquals("Last name did not match", + LAST_NAME, DOMUtils.getNodeValue(view, viewClient, "ln")); + assertEquals("Address line 1 did not match", + ADDRESS_LINE1, DOMUtils.getNodeValue(view, viewClient, "a1")); + assertEquals("Address line 2 did not match", + ADDRESS_LINE2, DOMUtils.getNodeValue(view, viewClient, "a2")); + assertEquals("City did not match", + CITY, DOMUtils.getNodeValue(view, viewClient, "ct")); + assertEquals("Zip code des not match", + ZIP_CODE, DOMUtils.getNodeValue(view, viewClient, "zc")); + assertEquals("Email does not match", + EMAIL, DOMUtils.getNodeValue(view, viewClient, "em")); + assertEquals("Phone number does not match", + PHONE_NUMBER, DOMUtils.getNodeValue(view, viewClient, "ph")); + } + + // Wait and assert helper methods ------------------------------------------------------------- + + private void waitForKeyboardShowRequest(final TestInputMethodManagerWrapper immw, + final int count) throws InterruptedException { + assertTrue("Keyboard was never requested to be shown.", + CriteriaHelper.pollForCriteria(new Criteria() { + @Override + public boolean isSatisfied() { + return immw.getShowSoftInputCounter() == count; + } + })); + } + + private void waitForAnchorViewAdd(final ContentView view) throws InterruptedException { + assertTrue("Autofill Popup anchor view was never added.", + CriteriaHelper.pollForCriteria(new Criteria() { + @Override + public boolean isSatisfied() { + return view.findViewById(R.id.autofill_popup_window) != null; + } + })); + } + + private void waitForAutofillPopopShow(final AutofillPopup popup) throws InterruptedException { + assertTrue("Autofill Popup anchor view was never added.", + CriteriaHelper.pollForCriteria(new Criteria() { + @Override + public boolean isSatisfied() { + return popup.isShowing(); + } + })); + } + + private void waitForInputFieldFill(final ContentView view, + final TestCallbackHelperContainer viewClient) throws InterruptedException { + assertTrue("First name field was never filled.", + CriteriaHelper.pollForCriteria(new Criteria() { + @Override + public boolean isSatisfied() { + try { + return TextUtils.equals(FIRST_NAME, + DOMUtils.getNodeValue(view, viewClient, "fn")); + } catch (Exception e) { + return false; + } + } + })); + } +} diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillTestHelper.java b/chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillTestHelper.java new file mode 100644 index 0000000..c9d2f18 --- /dev/null +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillTestHelper.java @@ -0,0 +1,129 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.chrome.browser.autofill; + +import org.chromium.base.ThreadUtils; +import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; +import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; +import org.chromium.chrome.browser.autofill.PersonalDataManager.PersonalDataManagerObserver; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; + +/** + * Helper class for testing AutofillProfiles. + */ +public class AutofillTestHelper { + + private Object mObserverNotified; + + public AutofillTestHelper() { + registerDataObserver(); + } + + AutofillProfile getProfile(final String guid) throws ExecutionException { + return ThreadUtils.runOnUiThreadBlocking(new Callable<AutofillProfile>() { + @Override + public AutofillProfile call() { + return PersonalDataManager.getInstance().getProfile(guid); + } + }); + } + + int getNumberOfProfiles() throws ExecutionException { + return ThreadUtils.runOnUiThreadBlocking(new Callable<Integer>() { + @Override + public Integer call() { + return PersonalDataManager.getInstance().getProfiles().size(); + } + }).intValue(); + } + + String setProfile(final AutofillProfile profile) throws InterruptedException, + ExecutionException { + String guid = ThreadUtils.runOnUiThreadBlocking(new Callable<String>() { + @Override + public String call() { + return PersonalDataManager.getInstance().setProfile(profile); + } + }); + waitForDataChanged(); + return guid; + } + + void deleteProfile(final String guid) throws InterruptedException { + ThreadUtils.runOnUiThreadBlocking(new Runnable() { + @Override + public void run() { + PersonalDataManager.getInstance().deleteProfile(guid); + } + }); + waitForDataChanged(); + } + + CreditCard getCreditCard(final String guid) throws ExecutionException { + return ThreadUtils.runOnUiThreadBlocking(new Callable<CreditCard>() { + @Override + public CreditCard call() { + return PersonalDataManager.getInstance().getCreditCard(guid); + } + }); + } + + int getNumberOfCreditCards() throws ExecutionException { + return ThreadUtils.runOnUiThreadBlocking(new Callable<Integer>() { + @Override + public Integer call() { + return PersonalDataManager.getInstance().getCreditCards().size(); + } + }).intValue(); + } + + String setCreditCard(final CreditCard card) throws InterruptedException, ExecutionException { + String guid = ThreadUtils.runOnUiThreadBlocking(new Callable<String>() { + @Override + public String call() { + return PersonalDataManager.getInstance().setCreditCard(card); + } + }); + waitForDataChanged(); + return guid; + } + + void deleteCreditCard(final String guid) throws InterruptedException { + ThreadUtils.runOnUiThreadBlocking(new Runnable() { + @Override + public void run() { + PersonalDataManager.getInstance().deleteCreditCard(guid); + } + }); + waitForDataChanged(); + } + + private void registerDataObserver() { + mObserverNotified = new Object(); + ThreadUtils.runOnUiThreadBlocking(new Runnable() { + @Override + public void run() { + PersonalDataManager.getInstance().registerDataObserver( + new PersonalDataManagerObserver() { + @Override + public void onPersonalDataChanged() { + synchronized (mObserverNotified) { + mObserverNotified.notifyAll(); + } + } + } + ); + } + }); + } + + public void waitForDataChanged() throws InterruptedException { + synchronized (mObserverNotified) { + mObserverNotified.wait(3000); + } + } +} diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/autofill/PersonalDataManagerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/autofill/PersonalDataManagerTest.java index 5953c7a..374be84 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/autofill/PersonalDataManagerTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/autofill/PersonalDataManagerTest.java @@ -6,25 +6,19 @@ package org.chromium.chrome.browser.autofill; import android.test.suitebuilder.annotation.SmallTest; -import org.chromium.base.ThreadUtils; import org.chromium.base.test.util.Feature; import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; -import org.chromium.chrome.browser.autofill.PersonalDataManager.PersonalDataManagerObserver; import org.chromium.chrome.testshell.ChromiumTestShellTestBase; -import org.chromium.content.browser.test.util.Criteria; -import org.chromium.content.browser.test.util.CriteriaHelper; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.ExecutionException; /** * Tests for Chrome on Android's usage of the PersonalDataManager API. */ public class PersonalDataManagerTest extends ChromiumTestShellTestBase { - private AtomicBoolean mObserverNotified; + private AutofillTestHelper mHelper; @Override public void setUp() throws Exception { @@ -32,218 +26,95 @@ public class PersonalDataManagerTest extends ChromiumTestShellTestBase { clearAppData(); launchChromiumTestShellWithBlankPage(); assertTrue(waitForActiveShellToBeDoneLoading()); - mObserverNotified = registerDataObserver(); + + mHelper = new AutofillTestHelper(); } @SmallTest @Feature({"Autofill"}) - public void testAddAndEditProfiles() throws InterruptedException { + public void testAddAndEditProfiles() throws InterruptedException, ExecutionException { AutofillProfile profile = new AutofillProfile( "" /* guid */, "https://www.example.com" /* origin */, "John Smith", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", "94102", "US", "4158889999", "john@acme.inc"); - String profileOneGUID = setProfile(profile); - assertEquals(1, getNumberOfProfiles()); + String profileOneGUID = mHelper.setProfile(profile); + assertEquals(1, mHelper.getNumberOfProfiles()); AutofillProfile profile2 = new AutofillProfile( "" /* guid */, "http://www.example.com" /* origin */, "John Hackock", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", "94102", "US", "4158889999", "john@acme.inc"); - String profileTwoGUID = setProfile(profile2); - assertEquals(2, getNumberOfProfiles()); + String profileTwoGUID = mHelper.setProfile(profile2); + assertEquals(2, mHelper.getNumberOfProfiles()); profile.setGUID(profileOneGUID); profile.setCountry("Canada"); - setProfile(profile); - assertEquals("Should still have only two profile", 2, getNumberOfProfiles()); + mHelper.setProfile(profile); + assertEquals("Should still have only two profile", 2, mHelper.getNumberOfProfiles()); - AutofillProfile storedProfile = getProfile(profileOneGUID); + AutofillProfile storedProfile = mHelper.getProfile(profileOneGUID); assertEquals(profileOneGUID, storedProfile.getGUID()); assertEquals("https://www.example.com", storedProfile.getOrigin()); assertEquals("Canada", storedProfile.getCountry()); assertEquals("San Francisco", storedProfile.getCity()); - assertNotNull(getProfile(profileTwoGUID)); + assertNotNull(mHelper.getProfile(profileTwoGUID)); } @SmallTest @Feature({"Autofill"}) - public void testAddAndDeleteProfile() throws InterruptedException { + public void testAddAndDeleteProfile() throws InterruptedException, ExecutionException { AutofillProfile profile = new AutofillProfile( "" /* guid */, "Chrome settings" /* origin */, "John Smith", "Acme Inc.", "1 Main", "Apt A", "San Francisco", "CA", "94102", "US", "4158889999", "john@acme.inc"); - String profileOneGUID = setProfile(profile); - assertEquals(1, getNumberOfProfiles()); + String profileOneGUID = mHelper.setProfile(profile); + assertEquals(1, mHelper.getNumberOfProfiles()); - deleteProfile(profileOneGUID); - assertEquals(0, getNumberOfProfiles()); + mHelper.deleteProfile(profileOneGUID); + assertEquals(0, mHelper.getNumberOfProfiles()); } @SmallTest @Feature({"Autofill"}) - public void testAddAndEditCreditCards() throws InterruptedException { + public void testAddAndEditCreditCards() throws InterruptedException, ExecutionException { CreditCard card = new CreditCard( "" /* guid */, "https://www.example.com" /* origin */, "Visa", "1234123412341234", "", "5", "2020"); - String cardOneGUID = setCreditCard(card); - assertEquals(1, getNumberOfCreditCards()); + String cardOneGUID = mHelper.setCreditCard(card); + assertEquals(1, mHelper.getNumberOfCreditCards()); CreditCard card2 = new CreditCard( "" /* guid */, "http://www.example.com" /* origin */, "American Express", "1234123412341234", "", "8", "2020"); - String cardTwoGUID = setCreditCard(card2); - assertEquals(2, getNumberOfCreditCards()); + String cardTwoGUID = mHelper.setCreditCard(card2); + assertEquals(2, mHelper.getNumberOfCreditCards()); card.setGUID(cardOneGUID); card.setMonth("10"); card.setNumber("5678567856785678"); - setCreditCard(card); - assertEquals("Should still have only two cards", 2, getNumberOfCreditCards()); + mHelper.setCreditCard(card); + assertEquals("Should still have only two cards", 2, mHelper.getNumberOfCreditCards()); - CreditCard storedCard = getCreditCard(cardOneGUID); + CreditCard storedCard = mHelper.getCreditCard(cardOneGUID); assertEquals(cardOneGUID, storedCard.getGUID()); assertEquals("https://www.example.com", storedCard.getOrigin()); assertEquals("Visa", storedCard.getName()); assertEquals("10", storedCard.getMonth()); assertEquals("5678567856785678", storedCard.getNumber()); assertEquals("************5678", storedCard.getObfuscatedNumber()); - assertNotNull(getCreditCard(cardTwoGUID)); + assertNotNull(mHelper.getCreditCard(cardTwoGUID)); } @SmallTest @Feature({"Autofill"}) - public void testAddAndDeleteCreditCard() throws InterruptedException { + public void testAddAndDeleteCreditCard() throws InterruptedException, ExecutionException { CreditCard card = new CreditCard( "" /* guid */, "Chrome settings" /* origin */, "Visa", "1234123412341234", "", "5", "2020"); - String cardOneGUID = setCreditCard(card); - assertEquals(1, getNumberOfCreditCards()); - - deleteCreditCard(cardOneGUID); - assertEquals(0, getNumberOfCreditCards()); - } - - // General helper functions - // ------------------------ - private AtomicBoolean registerDataObserver() { - final AtomicBoolean observerNotified = new AtomicBoolean(false); - ThreadUtils.runOnUiThreadBlocking(new Runnable() { - @Override - public void run() { - PersonalDataManager.getInstance().registerDataObserver( - new PersonalDataManagerObserver() { - @Override - public void onPersonalDataChanged() { - observerNotified.set(true); - } - } - ); - } - }); - return observerNotified; - } - - private void waitForDataChanged() throws InterruptedException { - assertTrue("Observer wasn't notified of PersonalDataManager change.", - CriteriaHelper.pollForCriteria(new Criteria() { - @Override - public boolean isSatisfied() { - return mObserverNotified.get(); - } - })); - // Reset member for next iteration. - mObserverNotified.set(false); - } - - // Profile helper functions - // ------------------------ - private AutofillProfile getProfile(final String guid) { - final AtomicReference<AutofillProfile> profile = new AtomicReference<AutofillProfile>(); - ThreadUtils.runOnUiThreadBlocking(new Runnable() { - @Override - public void run() { - profile.set(PersonalDataManager.getInstance().getProfile(guid)); - } - }); - return profile.get(); - } - - private int getNumberOfProfiles() { - final AtomicInteger numProfiles = new AtomicInteger(); - ThreadUtils.runOnUiThreadBlocking(new Runnable() { - @Override - public void run() { - numProfiles.set(PersonalDataManager.getInstance().getProfiles().size()); - } - }); - return numProfiles.intValue(); - } - - private String setProfile(final AutofillProfile profile) throws InterruptedException { - final AtomicReference<String> guid = new AtomicReference<String>(); - ThreadUtils.runOnUiThreadBlocking(new Runnable() { - @Override - public void run() { - guid.set(PersonalDataManager.getInstance().setProfile(profile)); - } - }); - waitForDataChanged(); - return guid.get(); - } - - private void deleteProfile(final String guid) throws InterruptedException { - ThreadUtils.runOnUiThreadBlocking(new Runnable() { - @Override - public void run() { - PersonalDataManager.getInstance().deleteProfile(guid); - } - }); - waitForDataChanged(); - } - - // Credit Card helper functions - // ------------------------ - private CreditCard getCreditCard(final String guid) { - final AtomicReference<CreditCard> profile = new AtomicReference<CreditCard>(); - ThreadUtils.runOnUiThreadBlocking(new Runnable() { - @Override - public void run() { - profile.set(PersonalDataManager.getInstance().getCreditCard(guid)); - } - }); - return profile.get(); - } - - private int getNumberOfCreditCards() { - final AtomicInteger numCreditCards = new AtomicInteger(); - ThreadUtils.runOnUiThreadBlocking(new Runnable() { - @Override - public void run() { - numCreditCards.set(PersonalDataManager.getInstance().getCreditCards().size()); - } - }); - return numCreditCards.intValue(); - } - - private String setCreditCard(final CreditCard card) throws InterruptedException { - final AtomicReference<String> guid = new AtomicReference<String>(); - ThreadUtils.runOnUiThreadBlocking(new Runnable() { - @Override - public void run() { - guid.set(PersonalDataManager.getInstance().setCreditCard(card)); - } - }); - waitForDataChanged(); - return guid.get(); - } + String cardOneGUID = mHelper.setCreditCard(card); + assertEquals(1, mHelper.getNumberOfCreditCards()); - private void deleteCreditCard(final String guid) throws InterruptedException { - ThreadUtils.runOnUiThreadBlocking(new Runnable() { - @Override - public void run() { - PersonalDataManager.getInstance().deleteCreditCard(guid); - } - }); - waitForDataChanged(); + mHelper.deleteCreditCard(cardOneGUID); + assertEquals(0, mHelper.getNumberOfCreditCards()); } } diff --git a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java index b4e2311..3866404 100644 --- a/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java +++ b/content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java @@ -129,7 +129,7 @@ public class ImeAdapter { } @VisibleForTesting - protected void setInputMethodManagerWrapper(InputMethodManagerWrapper immw) { + public void setInputMethodManagerWrapper(InputMethodManagerWrapper immw) { mInputMethodManagerWrapper = immw; } diff --git a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java index db61486..997d93d 100644 --- a/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java +++ b/content/public/test/android/javatests/src/org/chromium/content/browser/test/util/DOMUtils.java @@ -120,11 +120,27 @@ public class DOMUtils { public static String getNodeContents(final ContentView view, TestCallbackHelperContainer viewClient, String nodeId) throws InterruptedException, TimeoutException { + return getNodeField("textContent", view, viewClient, nodeId); + } + + /** + * Returns the value of the node by its id. + */ + public static String getNodeValue(final ContentView view, + TestCallbackHelperContainer viewClient, String nodeId) + throws InterruptedException, TimeoutException { + return getNodeField("value", view, viewClient, nodeId); + } + + private static String getNodeField(String fieldName, final ContentView view, + TestCallbackHelperContainer viewClient, String nodeId) + throws InterruptedException, TimeoutException { StringBuilder sb = new StringBuilder(); sb.append("(function() {"); sb.append(" var node = document.getElementById('" + nodeId + "');"); sb.append(" if (!node) return null;"); - sb.append(" return [ node.textContent ];"); + sb.append(" if (!node." + fieldName +") return null;"); + sb.append(" return [ node." + fieldName + " ];"); sb.append("})();"); String jsonText = JavaScriptUtils.executeJavaScriptAndWaitForResult( @@ -133,18 +149,18 @@ public class DOMUtils { jsonText.trim().equalsIgnoreCase("null")); JsonReader jsonReader = new JsonReader(new StringReader(jsonText)); - String contents = null; + String value = null; try { jsonReader.beginArray(); - if (jsonReader.hasNext()) contents = jsonReader.nextString(); + if (jsonReader.hasNext()) value = jsonReader.nextString(); jsonReader.endArray(); - Assert.assertNotNull("Invalid contents returned.", contents); + Assert.assertNotNull("Invalid contents returned.", value); jsonReader.close(); } catch (IOException exception) { Assert.fail("Failed to evaluate JavaScript: " + jsonText + "\n" + exception); } - return contents; + return value; } /** diff --git a/ui/android/java/res/values/values.xml b/ui/android/java/res/values/values.xml new file mode 100644 index 0000000..046cf8b --- /dev/null +++ b/ui/android/java/res/values/values.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright 2013 The Chromium Authors. All rights reserved. + + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> + +<resources xmlns:android="http://schemas.android.com/apk/res/android"> + <!-- AutofillPopup constants --> + <item type="id" name="autofill_popup_window" /> +</resources>
\ No newline at end of file diff --git a/ui/android/java/resource_map/org/chromium/ui/R.java b/ui/android/java/resource_map/org/chromium/ui/R.java index 0c61b4b..d170420 100644 --- a/ui/android/java/resource_map/org/chromium/ui/R.java +++ b/ui/android/java/resource_map/org/chromium/ui/R.java @@ -28,6 +28,7 @@ public final class R { } public static final class id { public static int autofill_label; + public static int autofill_popup_window; public static int autofill_sublabel; public static int selected_color_view; public static int title; diff --git a/ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java b/ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java index 7cec3c1..46dca4d 100644 --- a/ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java +++ b/ui/android/java/src/org/chromium/ui/autofill/AutofillPopup.java @@ -82,6 +82,9 @@ public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem setOnItemClickListener(this); mAnchorView = mViewAndroidDelegate.acquireAnchorView(); + mAnchorView.setId(R.id.autofill_popup_window); + mAnchorView.setTag(R.id.autofill_popup_window, this); + mViewAndroidDelegate.setAnchorViewPosition(mAnchorView, mAnchorX, mAnchorY, mAnchorWidth, mAnchorHeight); @@ -158,6 +161,7 @@ public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem public void hide() { super.dismiss(); mAnchorView.removeOnLayoutChangeListener(mLayoutChangeListener); + mAnchorView.setTag(R.id.autofill_popup_window, null); mViewAndroidDelegate.releaseAnchorView(mAnchorView); } |