Remove some dependencies on ContentView.

Turns out that https://chromiumcodereview.appspot.com/11788005 made it
such that blocking for JavaScript doesn't require ContentViewClient,
just a ContentViewCore. Many places in tests still get the ContentView
in order to create a TestCallbackHelperContainer in order to wait for
JavaScript to execute...

Instead for clients that don't care about waiting themselves for JS to
execute, just do it inside JavaScriptUtils.

BUG=360644

Review URL: https://codereview.chromium.org/231693002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@262929 0039d316-1c4b-4281-b951-d872f2087c98
parent 6c16ef3d
...@@ -19,7 +19,6 @@ import org.chromium.content.browser.ContentViewCore; ...@@ -19,7 +19,6 @@ import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils; 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.TestInputMethodManagerWrapper;
import org.chromium.content.browser.test.util.TouchCommon; import org.chromium.content.browser.test.util.TouchCommon;
import org.chromium.ui.autofill.AutofillPopup; import org.chromium.ui.autofill.AutofillPopup;
...@@ -127,7 +126,7 @@ public class AutofillPopupTest extends ChromeShellTestBase { ...@@ -127,7 +126,7 @@ public class AutofillPopupTest extends ChromeShellTestBase {
); );
} }
private TestCallbackHelperContainer loadAndFillForm( private void loadAndFillForm(
final String formDataUrl, final String inputText) final String formDataUrl, final String inputText)
throws InterruptedException, ExecutionException, TimeoutException { throws InterruptedException, ExecutionException, TimeoutException {
launchChromeShellWithUrl(formDataUrl); launchChromeShellWithUrl(formDataUrl);
...@@ -150,9 +149,8 @@ public class AutofillPopupTest extends ChromeShellTestBase { ...@@ -150,9 +149,8 @@ public class AutofillPopupTest extends ChromeShellTestBase {
assertEquals(1, mHelper.getNumberOfProfiles()); assertEquals(1, mHelper.getNumberOfProfiles());
// Click the input field for the first name. // Click the input field for the first name.
final TestCallbackHelperContainer viewClient = new TestCallbackHelperContainer(view); assertTrue(DOMUtils.waitForNonZeroNodeBounds(viewCore, "fn"));
assertTrue(DOMUtils.waitForNonZeroNodeBounds(viewCore, viewClient, "fn")); DOMUtils.clickNode(this, view, "fn");
DOMUtils.clickNode(this, view, viewClient, "fn");
waitForKeyboardShowRequest(immw, 1); waitForKeyboardShowRequest(immw, 1);
...@@ -175,9 +173,7 @@ public class AutofillPopupTest extends ChromeShellTestBase { ...@@ -175,9 +173,7 @@ public class AutofillPopupTest extends ChromeShellTestBase {
TouchCommon touchCommon = new TouchCommon(this); TouchCommon touchCommon = new TouchCommon(this);
touchCommon.singleClickViewRelative(popup.getListView(), 10, 10); touchCommon.singleClickViewRelative(popup.getListView(), 10, 10);
waitForInputFieldFill(viewCore, viewClient); waitForInputFieldFill(viewCore);
return viewClient;
} }
/** /**
...@@ -188,27 +184,27 @@ public class AutofillPopupTest extends ChromeShellTestBase { ...@@ -188,27 +184,27 @@ public class AutofillPopupTest extends ChromeShellTestBase {
@Feature({"autofill"}) @Feature({"autofill"})
public void testClickAutofillPopupSuggestion() public void testClickAutofillPopupSuggestion()
throws InterruptedException, ExecutionException, TimeoutException { throws InterruptedException, ExecutionException, TimeoutException {
TestCallbackHelperContainer viewClient = loadAndFillForm(BASIC_PAGE_DATA, "J"); loadAndFillForm(BASIC_PAGE_DATA, "J");
final ContentViewCore viewCore = getActivity().getActiveContentView().getContentViewCore(); final ContentViewCore viewCore = getActivity().getActiveContentView().getContentViewCore();
assertEquals("First name did not match", assertEquals("First name did not match",
FIRST_NAME, DOMUtils.getNodeValue(viewCore, viewClient, "fn")); FIRST_NAME, DOMUtils.getNodeValue(viewCore, "fn"));
assertEquals("Last name did not match", assertEquals("Last name did not match",
LAST_NAME, DOMUtils.getNodeValue(viewCore, viewClient, "ln")); LAST_NAME, DOMUtils.getNodeValue(viewCore, "ln"));
assertEquals("Address line 1 did not match", assertEquals("Address line 1 did not match",
ADDRESS_LINE1, DOMUtils.getNodeValue(viewCore, viewClient, "a1")); ADDRESS_LINE1, DOMUtils.getNodeValue(viewCore, "a1"));
assertEquals("Address line 2 did not match", assertEquals("Address line 2 did not match",
ADDRESS_LINE2, DOMUtils.getNodeValue(viewCore, viewClient, "a2")); ADDRESS_LINE2, DOMUtils.getNodeValue(viewCore, "a2"));
assertEquals("City did not match", assertEquals("City did not match",
CITY, DOMUtils.getNodeValue(viewCore, viewClient, "ct")); CITY, DOMUtils.getNodeValue(viewCore, "ct"));
assertEquals("Zip code did not match", assertEquals("Zip code did not match",
ZIP_CODE, DOMUtils.getNodeValue(viewCore, viewClient, "zc")); ZIP_CODE, DOMUtils.getNodeValue(viewCore, "zc"));
assertEquals("Country did not match", assertEquals("Country did not match",
COUNTRY, DOMUtils.getNodeValue(viewCore, viewClient, "co")); COUNTRY, DOMUtils.getNodeValue(viewCore, "co"));
assertEquals("Email did not match", assertEquals("Email did not match",
EMAIL, DOMUtils.getNodeValue(viewCore, viewClient, "em")); EMAIL, DOMUtils.getNodeValue(viewCore, "em"));
assertEquals("Phone number did not match", assertEquals("Phone number did not match",
PHONE_NUMBER, DOMUtils.getNodeValue(viewCore, viewClient, "ph")); PHONE_NUMBER, DOMUtils.getNodeValue(viewCore, "ph"));
final String profileFullName = FIRST_NAME + " " + LAST_NAME; final String profileFullName = FIRST_NAME + " " + LAST_NAME;
final int loggedEntries = 9; final int loggedEntries = 9;
...@@ -314,15 +310,14 @@ public class AutofillPopupTest extends ChromeShellTestBase { ...@@ -314,15 +310,14 @@ public class AutofillPopupTest extends ChromeShellTestBase {
})); }));
} }
private void waitForInputFieldFill(final ContentViewCore viewCore, private void waitForInputFieldFill(final ContentViewCore viewCore) throws InterruptedException {
final TestCallbackHelperContainer viewClient) throws InterruptedException {
assertTrue("First name field was never filled.", assertTrue("First name field was never filled.",
CriteriaHelper.pollForCriteria(new Criteria() { CriteriaHelper.pollForCriteria(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
try { try {
return TextUtils.equals(FIRST_NAME, return TextUtils.equals(FIRST_NAME,
DOMUtils.getNodeValue(viewCore, viewClient, "fn")); DOMUtils.getNodeValue(viewCore, "fn"));
} catch (InterruptedException e) { } catch (InterruptedException e) {
return false; return false;
} catch (TimeoutException e) { } catch (TimeoutException e) {
......
...@@ -18,7 +18,6 @@ import org.chromium.content.browser.ContentView; ...@@ -18,7 +18,6 @@ import org.chromium.content.browser.ContentView;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils; import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content.browser.test.util.UiUtils; import org.chromium.content.browser.test.util.UiUtils;
import org.chromium.ui.base.ActivityWindowAndroid; import org.chromium.ui.base.ActivityWindowAndroid;
...@@ -37,7 +36,6 @@ public class SelectFileDialogTest extends ChromeShellTestBase { ...@@ -37,7 +36,6 @@ public class SelectFileDialogTest extends ChromeShellTestBase {
"</body></html>"); "</body></html>");
private ContentView mContentView; private ContentView mContentView;
private TestCallbackHelperContainer mCallbackContainer;
private ActivityWindowAndroidForTest mActivityWindowAndroidForTest; private ActivityWindowAndroidForTest mActivityWindowAndroidForTest;
private static class ActivityWindowAndroidForTest extends ActivityWindowAndroid { private static class ActivityWindowAndroidForTest extends ActivityWindowAndroid {
...@@ -80,12 +78,11 @@ public class SelectFileDialogTest extends ChromeShellTestBase { ...@@ -80,12 +78,11 @@ public class SelectFileDialogTest extends ChromeShellTestBase {
assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
mContentView = getActivity().getActiveContentView(); mContentView = getActivity().getActiveContentView();
mCallbackContainer = new TestCallbackHelperContainer(mContentView);
// TODO(aurimas) remove this wait once crbug.com/179511 is fixed. // TODO(aurimas) remove this wait once crbug.com/179511 is fixed.
assertWaitForPageScaleFactorMatch(2); assertWaitForPageScaleFactorMatch(2);
assertTrue( assertTrue(
DOMUtils.waitForNonZeroNodeBounds(mContentView.getContentViewCore(), DOMUtils.waitForNonZeroNodeBounds(mContentView.getContentViewCore(),
mCallbackContainer, "input_file")); "input_file"));
} }
/** /**
...@@ -94,20 +91,20 @@ public class SelectFileDialogTest extends ChromeShellTestBase { ...@@ -94,20 +91,20 @@ public class SelectFileDialogTest extends ChromeShellTestBase {
@MediumTest @MediumTest
@Feature({"TextInput", "Main"}) @Feature({"TextInput", "Main"})
public void testSelectFileAndCancelRequest() throws Throwable { public void testSelectFileAndCancelRequest() throws Throwable {
DOMUtils.clickNode(this, mContentView, mCallbackContainer, "input_file"); DOMUtils.clickNode(this, mContentView, "input_file");
assertTrue("SelectFileDialog never sent an intent.", assertTrue("SelectFileDialog never sent an intent.",
CriteriaHelper.pollForCriteria(new IntentSentCriteria())); CriteriaHelper.pollForCriteria(new IntentSentCriteria()));
assertEquals(Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastIntent.getAction()); assertEquals(Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastIntent.getAction());
resetActivityWindowAndroidForTest(); resetActivityWindowAndroidForTest();
DOMUtils.clickNode(this, mContentView, mCallbackContainer, "input_image"); DOMUtils.clickNode(this, mContentView, "input_image");
assertTrue("SelectFileDialog never sent an intent.", assertTrue("SelectFileDialog never sent an intent.",
CriteriaHelper.pollForCriteria(new IntentSentCriteria())); CriteriaHelper.pollForCriteria(new IntentSentCriteria()));
assertEquals(MediaStore.ACTION_IMAGE_CAPTURE, assertEquals(MediaStore.ACTION_IMAGE_CAPTURE,
mActivityWindowAndroidForTest.lastIntent.getAction()); mActivityWindowAndroidForTest.lastIntent.getAction());
resetActivityWindowAndroidForTest(); resetActivityWindowAndroidForTest();
DOMUtils.clickNode(this, mContentView, mCallbackContainer, "input_audio"); DOMUtils.clickNode(this, mContentView, "input_audio");
assertTrue("SelectFileDialog never sent an intent.", assertTrue("SelectFileDialog never sent an intent.",
CriteriaHelper.pollForCriteria(new IntentSentCriteria())); CriteriaHelper.pollForCriteria(new IntentSentCriteria()));
assertEquals(MediaStore.Audio.Media.RECORD_SOUND_ACTION, assertEquals(MediaStore.Audio.Media.RECORD_SOUND_ACTION,
......
...@@ -12,7 +12,6 @@ import org.chromium.content.browser.ContentView; ...@@ -12,7 +12,6 @@ import org.chromium.content.browser.ContentView;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils; import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content.browser.test.util.UiUtils; import org.chromium.content.browser.test.util.UiUtils;
import org.chromium.ui.base.ActivityWindowAndroid; import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
...@@ -59,11 +58,9 @@ public class SelectPopupOtherContentViewTest extends ChromeShellTestBase { ...@@ -59,11 +58,9 @@ public class SelectPopupOtherContentViewTest extends ChromeShellTestBase {
assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
final ContentView view = getActivity().getActiveContentView(); final ContentView view = getActivity().getActiveContentView();
final TestCallbackHelperContainer viewClient =
new TestCallbackHelperContainer(view);
// Once clicked, the popup should show up. // Once clicked, the popup should show up.
DOMUtils.clickNode(this, view, viewClient, "select"); DOMUtils.clickNode(this, view, "select");
assertTrue("The select popup did not show up on click.", assertTrue("The select popup did not show up on click.",
CriteriaHelper.pollForCriteria(new PopupShowingCriteria())); CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
......
...@@ -22,7 +22,6 @@ import org.chromium.content.browser.ContentViewCore; ...@@ -22,7 +22,6 @@ import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.JavaScriptUtils; import org.chromium.content.browser.test.util.JavaScriptUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.sync.notifier.SyncStatusHelper; import org.chromium.sync.notifier.SyncStatusHelper;
import org.chromium.sync.signin.AccountManagerHelper; import org.chromium.sync.signin.AccountManagerHelper;
import org.chromium.sync.signin.ChromeSigninController; import org.chromium.sync.signin.ChromeSigninController;
...@@ -115,10 +114,8 @@ public class SyncTest extends ChromeShellTestBase { ...@@ -115,10 +114,8 @@ public class SyncTest extends ChromeShellTestBase {
final ContentViewCore contentViewCore = getContentViewCore(getActivity()); final ContentViewCore contentViewCore = getContentViewCore(getActivity());
String innerHtml = ""; String innerHtml = "";
try { try {
final TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper helper =
new TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper();
innerHtml = JavaScriptUtils.executeJavaScriptAndWaitForResult( innerHtml = JavaScriptUtils.executeJavaScriptAndWaitForResult(
contentViewCore, helper, "document.documentElement.innerHTML"); contentViewCore, "document.documentElement.innerHTML");
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.w(TAG, "Interrupted while polling about:sync page for sync status.", e); Log.w(TAG, "Interrupted while polling about:sync page for sync status.", e);
} catch (TimeoutException e) { } catch (TimeoutException e) {
......
...@@ -306,9 +306,7 @@ public class ModalDialogTest extends ChromeShellTestBase { ...@@ -306,9 +306,7 @@ public class ModalDialogTest extends ChromeShellTestBase {
*/ */
private OnEvaluateJavaScriptResultHelper executeJavaScriptAndWaitForDialog(String script) private OnEvaluateJavaScriptResultHelper executeJavaScriptAndWaitForDialog(String script)
throws InterruptedException { throws InterruptedException {
final OnEvaluateJavaScriptResultHelper helper = return executeJavaScriptAndWaitForDialog(new OnEvaluateJavaScriptResultHelper(), script);
getActiveTabTestCallbackHelperContainer().getOnEvaluateJavaScriptResultHelper();
return executeJavaScriptAndWaitForDialog(helper, script);
} }
/** /**
......
...@@ -44,7 +44,7 @@ public class ContextMenuUtils { ...@@ -44,7 +44,7 @@ public class ContextMenuUtils {
client.getOnContextMenuShownHelper(); client.getOnContextMenuShownHelper();
int callCount = helper.getCallCount(); int callCount = helper.getCallCount();
DOMUtils.longPressNode(testCase, tab.getContentView(), client, openerDOMNodeId); DOMUtils.longPressNode(testCase, tab.getContentView(), openerDOMNodeId);
helper.waitForCallback(callCount); helper.waitForCallback(callCount);
return helper.getContextMenu(); return helper.getContextMenu();
......
...@@ -66,8 +66,8 @@ public class ContentDetectionTestBase extends ContentShellTestBase { ...@@ -66,8 +66,8 @@ public class ContentDetectionTestBase extends ContentShellTestBase {
callbackHelperContainer.getOnStartContentIntentHelper(); callbackHelperContainer.getOnStartContentIntentHelper();
int currentCallCount = onStartContentIntentHelper.getCallCount(); int currentCallCount = onStartContentIntentHelper.getCallCount();
DOMUtils.scrollNodeIntoView(getContentViewCore(), callbackHelperContainer, id); DOMUtils.scrollNodeIntoView(getContentViewCore(), id);
DOMUtils.clickNode(this, getContentView(), callbackHelperContainer, id); DOMUtils.clickNode(this, getContentView(), id);
onStartContentIntentHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS, onStartContentIntentHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
TimeUnit.SECONDS); TimeUnit.SECONDS);
...@@ -87,8 +87,8 @@ public class ContentDetectionTestBase extends ContentShellTestBase { ...@@ -87,8 +87,8 @@ public class ContentDetectionTestBase extends ContentShellTestBase {
callbackHelperContainer.getOnPageFinishedHelper(); callbackHelperContainer.getOnPageFinishedHelper();
int currentCallCount = onPageFinishedHelper.getCallCount(); int currentCallCount = onPageFinishedHelper.getCallCount();
DOMUtils.scrollNodeIntoView(getContentViewCore(), callbackHelperContainer, id); DOMUtils.scrollNodeIntoView(getContentViewCore(), id);
DOMUtils.clickNode(this, getContentView(), callbackHelperContainer, id); DOMUtils.clickNode(this, getContentView(), id);
onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS, onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_SECONDS,
TimeUnit.SECONDS); TimeUnit.SECONDS);
......
...@@ -11,6 +11,7 @@ import org.chromium.content.browser.test.util.Criteria; ...@@ -11,6 +11,7 @@ import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.MockLocationProvider; import org.chromium.content.browser.test.util.MockLocationProvider;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer; import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper;
import org.chromium.content_shell_apk.ContentShellTestBase; import org.chromium.content_shell_apk.ContentShellTestBase;
/** /**
...@@ -91,7 +92,7 @@ public class ContentViewLocationTest extends ContentShellTestBase { ...@@ -91,7 +92,7 @@ public class ContentViewLocationTest extends ContentShellTestBase {
} }
mTestCallbackHelperContainer = new TestCallbackHelperContainer(getContentView()); mTestCallbackHelperContainer = new TestCallbackHelperContainer(getContentView());
mJavascriptHelper = mTestCallbackHelperContainer.getOnEvaluateJavaScriptResultHelper(); mJavascriptHelper = new OnEvaluateJavaScriptResultHelper();
ensureGeolocationRunning(false); ensureGeolocationRunning(false);
} }
......
...@@ -92,7 +92,7 @@ public class ContentViewPopupZoomerTest extends ContentShellTestBase { ...@@ -92,7 +92,7 @@ public class ContentViewPopupZoomerTest extends ContentShellTestBase {
CriteriaHelper.pollForCriteria(new PopupShowingCriteria(view, false))); CriteriaHelper.pollForCriteria(new PopupShowingCriteria(view, false)));
// Once clicked, the popup should show up. // Once clicked, the popup should show up.
DOMUtils.clickNode(this, view, viewClient, "clickme"); DOMUtils.clickNode(this, view, "clickme");
assertTrue("The zoomer popup did not show up on click.", assertTrue("The zoomer popup did not show up on click.",
CriteriaHelper.pollForCriteria(new PopupShowingCriteria(view, true))); CriteriaHelper.pollForCriteria(new PopupShowingCriteria(view, true)));
......
...@@ -32,16 +32,13 @@ public class GestureDetectorResetTest extends ContentShellTestBase { ...@@ -32,16 +32,13 @@ public class GestureDetectorResetTest extends ContentShellTestBase {
private static class NodeContentsIsEqualToCriteria implements Criteria { private static class NodeContentsIsEqualToCriteria implements Criteria {
private final ContentViewCore mViewCore; private final ContentViewCore mViewCore;
private final TestCallbackHelperContainer mViewClient;
private final String mNodeId; private final String mNodeId;
private final String mExpectedContents; private final String mExpectedContents;
public NodeContentsIsEqualToCriteria( public NodeContentsIsEqualToCriteria(
ContentViewCore viewCore, ContentViewCore viewCore,
TestCallbackHelperContainer viewClient,
String nodeId, String expectedContents) { String nodeId, String expectedContents) {
mViewCore = viewCore; mViewCore = viewCore;
mViewClient = viewClient;
mNodeId = nodeId; mNodeId = nodeId;
mExpectedContents = expectedContents; mExpectedContents = expectedContents;
assert mExpectedContents != null; assert mExpectedContents != null;
...@@ -50,7 +47,7 @@ public class GestureDetectorResetTest extends ContentShellTestBase { ...@@ -50,7 +47,7 @@ public class GestureDetectorResetTest extends ContentShellTestBase {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
try { try {
String contents = DOMUtils.getNodeContents(mViewCore, mViewClient, mNodeId); String contents = DOMUtils.getNodeContents(mViewCore, mNodeId);
return mExpectedContents.equals(contents); return mExpectedContents.equals(contents);
} catch (Throwable e) { } catch (Throwable e) {
Assert.fail("Failed to retrieve node contents: " + e); Assert.fail("Failed to retrieve node contents: " + e);
...@@ -64,20 +61,20 @@ public class GestureDetectorResetTest extends ContentShellTestBase { ...@@ -64,20 +61,20 @@ public class GestureDetectorResetTest extends ContentShellTestBase {
private void verifyClicksAreRegistered( private void verifyClicksAreRegistered(
String disambiguation, String disambiguation,
ContentView view, TestCallbackHelperContainer viewClient) ContentView view)
throws InterruptedException, Exception, Throwable { throws InterruptedException, Exception, Throwable {
// Initially the text on the page should say "not clicked". // Initially the text on the page should say "not clicked".
assertTrue("The page contents is invalid " + disambiguation, assertTrue("The page contents is invalid " + disambiguation,
CriteriaHelper.pollForCriteria(new NodeContentsIsEqualToCriteria( CriteriaHelper.pollForCriteria(new NodeContentsIsEqualToCriteria(
view.getContentViewCore(), viewClient, "test", "not clicked"))); view.getContentViewCore(), "test", "not clicked")));
// Click the button. // Click the button.
DOMUtils.clickNode(this, view, viewClient, "button"); DOMUtils.clickNode(this, view, "button");
// After the click, the text on the page should say "clicked". // After the click, the text on the page should say "clicked".
assertTrue("The page contents didn't change after a click " + disambiguation, assertTrue("The page contents didn't change after a click " + disambiguation,
CriteriaHelper.pollForCriteria(new NodeContentsIsEqualToCriteria( CriteriaHelper.pollForCriteria(new NodeContentsIsEqualToCriteria(
view.getContentViewCore(), viewClient, "test", "clicked"))); view.getContentViewCore(), "test", "clicked")));
} }
/** /**
...@@ -102,7 +99,7 @@ public class GestureDetectorResetTest extends ContentShellTestBase { ...@@ -102,7 +99,7 @@ public class GestureDetectorResetTest extends ContentShellTestBase {
viewClient.getOnPageFinishedHelper(); viewClient.getOnPageFinishedHelper();
// Test that the button click works. // Test that the button click works.
verifyClicksAreRegistered("on initial load", view, viewClient); verifyClicksAreRegistered("on initial load", view);
// Reload the test page. // Reload the test page.
int currentCallCount = onPageFinishedHelper.getCallCount(); int currentCallCount = onPageFinishedHelper.getCallCount();
...@@ -116,7 +113,7 @@ public class GestureDetectorResetTest extends ContentShellTestBase { ...@@ -116,7 +113,7 @@ public class GestureDetectorResetTest extends ContentShellTestBase {
WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
// Test that the button click still works. // Test that the button click still works.
verifyClicksAreRegistered("after reload", view, viewClient); verifyClicksAreRegistered("after reload", view);
// Directly navigate to the test page. // Directly navigate to the test page.
currentCallCount = onPageFinishedHelper.getCallCount(); currentCallCount = onPageFinishedHelper.getCallCount();
...@@ -131,6 +128,6 @@ public class GestureDetectorResetTest extends ContentShellTestBase { ...@@ -131,6 +128,6 @@ public class GestureDetectorResetTest extends ContentShellTestBase {
WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
// Test that the button click still works. // Test that the button click still works.
verifyClicksAreRegistered("after direct navigation", view, viewClient); verifyClicksAreRegistered("after direct navigation", view);
} }
} }
...@@ -9,6 +9,7 @@ import android.test.suitebuilder.annotation.MediumTest; ...@@ -9,6 +9,7 @@ import android.test.suitebuilder.annotation.MediumTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer; import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper;
import org.chromium.content_shell_apk.ContentShellActivity; import org.chromium.content_shell_apk.ContentShellActivity;
import org.chromium.content_shell_apk.ContentShellTestBase; import org.chromium.content_shell_apk.ContentShellTestBase;
...@@ -112,8 +113,7 @@ public class NavigationTest extends ContentShellTestBase { ...@@ -112,8 +113,7 @@ public class NavigationTest extends ContentShellTestBase {
ContentView contentView = activity.getActiveContentView(); ContentView contentView = activity.getActiveContentView();
TestCallbackHelperContainer testCallbackHelperContainer = TestCallbackHelperContainer testCallbackHelperContainer =
new TestCallbackHelperContainer(contentView); new TestCallbackHelperContainer(contentView);
TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper javascriptHelper = OnEvaluateJavaScriptResultHelper javascriptHelper = new OnEvaluateJavaScriptResultHelper();
testCallbackHelperContainer.getOnEvaluateJavaScriptResultHelper();
// Grab the first timestamp. // Grab the first timestamp.
javascriptHelper.evaluateJavaScript(contentView.getContentViewCore(), "getLoadtime();"); javascriptHelper.evaluateJavaScript(contentView.getContentViewCore(), "getLoadtime();");
......
...@@ -9,7 +9,6 @@ import android.test.suitebuilder.annotation.SmallTest; ...@@ -9,7 +9,6 @@ import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.content.browser.test.util.JavaScriptUtils; import org.chromium.content.browser.test.util.JavaScriptUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content_shell_apk.ContentShellActivity; import org.chromium.content_shell_apk.ContentShellActivity;
import org.chromium.content_shell_apk.ContentShellTestBase; import org.chromium.content_shell_apk.ContentShellTestBase;
...@@ -35,7 +34,6 @@ public class ScreenOrientationIntegrationTest extends ContentShellTestBase { ...@@ -35,7 +34,6 @@ public class ScreenOrientationIntegrationTest extends ContentShellTestBase {
return Integer.parseInt( return Integer.parseInt(
JavaScriptUtils.executeJavaScriptAndWaitForResult( JavaScriptUtils.executeJavaScriptAndWaitForResult(
mContentView.getContentViewCore(), mContentView.getContentViewCore(),
new TestCallbackHelperContainer(mContentView),
"window.orientation")); "window.orientation"));
} }
...@@ -48,7 +46,6 @@ public class ScreenOrientationIntegrationTest extends ContentShellTestBase { ...@@ -48,7 +46,6 @@ public class ScreenOrientationIntegrationTest extends ContentShellTestBase {
return Integer.parseInt( return Integer.parseInt(
JavaScriptUtils.executeJavaScriptAndWaitForResult( JavaScriptUtils.executeJavaScriptAndWaitForResult(
mContentView.getContentViewCore(), mContentView.getContentViewCore(),
new TestCallbackHelperContainer(mContentView),
"changes")); "changes"));
} }
......
...@@ -9,7 +9,6 @@ import android.test.suitebuilder.annotation.LargeTest; ...@@ -9,7 +9,6 @@ import android.test.suitebuilder.annotation.LargeTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.content.browser.test.util.DOMUtils; import org.chromium.content.browser.test.util.DOMUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content_shell_apk.ContentShellTestBase; import org.chromium.content_shell_apk.ContentShellTestBase;
public class TestsJavaScriptEvalTest extends ContentShellTestBase { public class TestsJavaScriptEvalTest extends ContentShellTestBase {
...@@ -34,9 +33,6 @@ public class TestsJavaScriptEvalTest extends ContentShellTestBase { ...@@ -34,9 +33,6 @@ public class TestsJavaScriptEvalTest extends ContentShellTestBase {
assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
final ContentView view = getActivity().getActiveContentView(); final ContentView view = getActivity().getActiveContentView();
final TestCallbackHelperContainer viewClient =
new TestCallbackHelperContainer(view);
for (int i = 0; i < 30; ++i) { for (int i = 0; i < 30; ++i) {
for (int j = 0; j < 10; ++j) { for (int j = 0; j < 10; ++j) {
// Start evaluation of a JavaScript script -- we don't need a result. // Start evaluation of a JavaScript script -- we don't need a result.
...@@ -44,7 +40,7 @@ public class TestsJavaScriptEvalTest extends ContentShellTestBase { ...@@ -44,7 +40,7 @@ public class TestsJavaScriptEvalTest extends ContentShellTestBase {
} }
// DOMUtils does need to evaluate a JavaScript and get its result to get DOM bounds. // DOMUtils does need to evaluate a JavaScript and get its result to get DOM bounds.
assertNotNull("Failed to get bounds", assertNotNull("Failed to get bounds",
DOMUtils.getNodeBounds(view.getContentViewCore(), viewClient, "test")); DOMUtils.getNodeBounds(view.getContentViewCore(), "test"));
} }
} }
} }
...@@ -10,29 +10,15 @@ import android.view.WindowManager; ...@@ -10,29 +10,15 @@ import android.view.WindowManager;
import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.DisabledTest;
import org.chromium.content.browser.test.util.JavaScriptUtils; import org.chromium.content.browser.test.util.JavaScriptUtils;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
/** /**
* Test suite for viewport-related properties. * Test suite for viewport-related properties.
*/ */
public class ViewportTest extends ContentViewTestBase { public class ViewportTest extends ContentViewTestBase {
private TestCallbackHelperContainer mCallbackHelper;
/**
* Returns the TestCallbackHelperContainer associated with this ContentView,
* or creates it lazily.
*/
protected TestCallbackHelperContainer getTestCallbackHelperContainer() {
if (mCallbackHelper == null) {
mCallbackHelper = new TestCallbackHelperContainer(getContentView());
}
return mCallbackHelper;
}
protected String evaluateStringValue(String expression) throws Throwable { protected String evaluateStringValue(String expression) throws Throwable {
return JavaScriptUtils.executeJavaScriptAndWaitForResult(getContentViewCore(), return JavaScriptUtils.executeJavaScriptAndWaitForResult(getContentViewCore(),
getTestCallbackHelperContainer(), expression); expression);
} }
protected float evaluateFloatValue(String expression) throws Throwable { protected float evaluateFloatValue(String expression) throws Throwable {
......
...@@ -72,8 +72,8 @@ public class ImeTest extends ContentShellTestBase { ...@@ -72,8 +72,8 @@ public class ImeTest extends ContentShellTestBase {
// TODO(aurimas) remove this wait once crbug.com/179511 is fixed. // TODO(aurimas) remove this wait once crbug.com/179511 is fixed.
assertWaitForPageScaleFactorMatch(2); assertWaitForPageScaleFactorMatch(2);
assertTrue(DOMUtils.waitForNonZeroNodeBounds( assertTrue(DOMUtils.waitForNonZeroNodeBounds(
mContentViewCore, mCallbackContainer, "input_text")); mContentViewCore, "input_text"));
DOMUtils.clickNode(this, mContentView, mCallbackContainer, "input_text"); DOMUtils.clickNode(this, mContentView, "input_text");
assertWaitForKeyboardStatus(true); assertWaitForKeyboardStatus(true);
mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
...@@ -136,10 +136,10 @@ public class ImeTest extends ContentShellTestBase { ...@@ -136,10 +136,10 @@ public class ImeTest extends ContentShellTestBase {
commitText(mConnection, "hello", 1); commitText(mConnection, "hello", 1);
waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 1, "hello", 5, 5, -1, -1); waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 1, "hello", 5, 5, -1, -1);
DOMUtils.clickNode(this, mContentView, mCallbackContainer, "input_radio"); DOMUtils.clickNode(this, mContentView, "input_radio");
assertWaitForKeyboardStatus(false); assertWaitForKeyboardStatus(false);
DOMUtils.clickNode(this, mContentView, mCallbackContainer, "input_text"); DOMUtils.clickNode(this, mContentView, "input_text");
assertWaitForKeyboardStatus(true); assertWaitForKeyboardStatus(true);
assertEquals(5, mInputMethodManagerWrapper.getEditorInfo().initialSelStart); assertEquals(5, mInputMethodManagerWrapper.getEditorInfo().initialSelStart);
assertEquals(5, mInputMethodManagerWrapper.getEditorInfo().initialSelEnd); assertEquals(5, mInputMethodManagerWrapper.getEditorInfo().initialSelEnd);
...@@ -207,13 +207,13 @@ public class ImeTest extends ContentShellTestBase { ...@@ -207,13 +207,13 @@ public class ImeTest extends ContentShellTestBase {
@SmallTest @SmallTest
@Feature({"TextInput", "Main"}) @Feature({"TextInput", "Main"})
public void testShowImeIfNeeded() throws Throwable { public void testShowImeIfNeeded() throws Throwable {
DOMUtils.focusNode(this, mContentViewCore, mCallbackContainer, "input_radio"); DOMUtils.focusNode(this, mContentViewCore, "input_radio");
assertWaitForKeyboardStatus(false); assertWaitForKeyboardStatus(false);
performShowImeIfNeeded(); performShowImeIfNeeded();
assertWaitForKeyboardStatus(false); assertWaitForKeyboardStatus(false);
DOMUtils.focusNode(this, mContentViewCore, mCallbackContainer, "input_text"); DOMUtils.focusNode(this, mContentViewCore, "input_text");
assertWaitForKeyboardStatus(false); assertWaitForKeyboardStatus(false);
performShowImeIfNeeded(); performShowImeIfNeeded();
...@@ -224,9 +224,9 @@ public class ImeTest extends ContentShellTestBase { ...@@ -224,9 +224,9 @@ public class ImeTest extends ContentShellTestBase {
@Feature({"TextInput", "Main"}) @Feature({"TextInput", "Main"})
public void testFinishComposingText() throws Throwable { public void testFinishComposingText() throws Throwable {
// Focus the textarea. We need to do the following steps because we are focusing using JS. // Focus the textarea. We need to do the following steps because we are focusing using JS.
DOMUtils.focusNode(this, mContentViewCore, mCallbackContainer, "input_radio"); DOMUtils.focusNode(this, mContentViewCore, "input_radio");
assertWaitForKeyboardStatus(false); assertWaitForKeyboardStatus(false);
DOMUtils.focusNode(this, mContentViewCore, mCallbackContainer, "textarea"); DOMUtils.focusNode(this, mContentViewCore, "textarea");
assertWaitForKeyboardStatus(false); assertWaitForKeyboardStatus(false);
performShowImeIfNeeded(); performShowImeIfNeeded();
assertWaitForKeyboardStatus(true); assertWaitForKeyboardStatus(true);
...@@ -257,9 +257,9 @@ public class ImeTest extends ContentShellTestBase { ...@@ -257,9 +257,9 @@ public class ImeTest extends ContentShellTestBase {
@Feature({"TextInput", "Main"}) @Feature({"TextInput", "Main"})
public void testEnterKeyEventWhileComposingText() throws Throwable { public void testEnterKeyEventWhileComposingText() throws Throwable {
// Focus the textarea. We need to do the following steps because we are focusing using JS. // Focus the textarea. We need to do the following steps because we are focusing using JS.
DOMUtils.focusNode(this, mContentViewCore, mCallbackContainer, "input_radio"); DOMUtils.focusNode(this, mContentViewCore, "input_radio");
assertWaitForKeyboardStatus(false); assertWaitForKeyboardStatus(false);
DOMUtils.focusNode(this, mContentViewCore, mCallbackContainer, "textarea"); DOMUtils.focusNode(this, mContentViewCore, "textarea");
assertWaitForKeyboardStatus(false); assertWaitForKeyboardStatus(false);
performShowImeIfNeeded(); performShowImeIfNeeded();
assertWaitForKeyboardStatus(true); assertWaitForKeyboardStatus(true);
......
...@@ -21,7 +21,6 @@ import org.chromium.content.browser.RenderCoordinates; ...@@ -21,7 +21,6 @@ import org.chromium.content.browser.RenderCoordinates;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils; 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.TestInputMethodManagerWrapper;
import org.chromium.content.browser.test.util.TestTouchUtils; import org.chromium.content.browser.test.util.TestTouchUtils;
import org.chromium.content.browser.test.util.TouchCommon; import org.chromium.content.browser.test.util.TouchCommon;
...@@ -250,8 +249,7 @@ public class InsertionHandleTest extends ContentShellTestBase { ...@@ -250,8 +249,7 @@ public class InsertionHandleTest extends ContentShellTestBase {
// click (only if it changes the selection), the insertion handle is displayed. So that the // click (only if it changes the selection), the insertion handle is displayed. So that the
// second click changes the selection, the two clicks should be in sufficiently different // second click changes the selection, the two clicks should be in sufficiently different
// locations. // locations.
Rect nodeBounds = DOMUtils.getNodeBounds(getContentViewCore(), Rect nodeBounds = DOMUtils.getNodeBounds(getContentViewCore(), nodeId);
new TestCallbackHelperContainer(getContentView()), nodeId);
RenderCoordinates renderCoordinates = getContentViewCore().getRenderCoordinates(); RenderCoordinates renderCoordinates = getContentViewCore().getRenderCoordinates();
int offsetX = getContentViewCore().getViewportSizeOffsetWidthPix(); int offsetX = getContentViewCore().getViewportSizeOffsetWidthPix();
......
...@@ -83,7 +83,7 @@ public class SelectPopupTest extends ContentShellTestBase { ...@@ -83,7 +83,7 @@ public class SelectPopupTest extends ContentShellTestBase {
viewClient.getOnPageFinishedHelper(); viewClient.getOnPageFinishedHelper();
// Once clicked, the popup should show up. // Once clicked, the popup should show up.
DOMUtils.clickNode(this, view, viewClient, "select"); DOMUtils.clickNode(this, view, "select");
assertTrue("The select popup did not show up on click.", assertTrue("The select popup did not show up on click.",
CriteriaHelper.pollForCriteria(new PopupShowingCriteria())); CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
...@@ -104,7 +104,7 @@ public class SelectPopupTest extends ContentShellTestBase { ...@@ -104,7 +104,7 @@ public class SelectPopupTest extends ContentShellTestBase {
CriteriaHelper.pollForCriteria(new PopupHiddenCriteria())); CriteriaHelper.pollForCriteria(new PopupHiddenCriteria()));
// Click the select and wait for the popup to show. // Click the select and wait for the popup to show.
DOMUtils.clickNode(this, view, viewClient, "select"); DOMUtils.clickNode(this, view, "select");
assertTrue("The select popup did not show on click after reload.", assertTrue("The select popup did not show on click after reload.",
CriteriaHelper.pollForCriteria(new PopupShowingCriteria())); CriteriaHelper.pollForCriteria(new PopupShowingCriteria()));
} }
......
...@@ -22,7 +22,6 @@ import org.chromium.content.browser.RenderCoordinates; ...@@ -22,7 +22,6 @@ import org.chromium.content.browser.RenderCoordinates;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils; 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.TestInputMethodManagerWrapper;
import org.chromium.content.browser.test.util.TestTouchUtils; import org.chromium.content.browser.test.util.TestTouchUtils;
import org.chromium.content.browser.test.util.TouchCommon; import org.chromium.content.browser.test.util.TouchCommon;
...@@ -449,8 +448,7 @@ public class SelectionHandleTest extends ContentShellTestBase { ...@@ -449,8 +448,7 @@ public class SelectionHandleTest extends ContentShellTestBase {
} }
private Rect getNodeBoundsPix(String nodeId) throws Throwable { private Rect getNodeBoundsPix(String nodeId) throws Throwable {
Rect nodeBounds = DOMUtils.getNodeBounds(getContentViewCore(), Rect nodeBounds = DOMUtils.getNodeBounds(getContentViewCore(), nodeId);
new TestCallbackHelperContainer(getContentView()), nodeId);
RenderCoordinates renderCoordinates = getContentViewCore().getRenderCoordinates(); RenderCoordinates renderCoordinates = getContentViewCore().getRenderCoordinates();
int offsetX = getContentViewCore().getViewportSizeOffsetWidthPix(); int offsetX = getContentViewCore().getViewportSizeOffsetWidthPix();
......
...@@ -25,8 +25,7 @@ public class DOMUtils { ...@@ -25,8 +25,7 @@ public class DOMUtils {
/** /**
* Returns the rect boundaries for a node by its id. * Returns the rect boundaries for a node by its id.
*/ */
public static Rect getNodeBounds( public static Rect getNodeBounds(final ContentViewCore viewCore, String nodeId)
final ContentViewCore viewCore, TestCallbackHelperContainer viewClient, String nodeId)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("(function() {"); sb.append("(function() {");
...@@ -44,7 +43,7 @@ public class DOMUtils { ...@@ -44,7 +43,7 @@ public class DOMUtils {
sb.append("})();"); sb.append("})();");
String jsonText = JavaScriptUtils.executeJavaScriptAndWaitForResult( String jsonText = JavaScriptUtils.executeJavaScriptAndWaitForResult(
viewCore, viewClient, sb.toString()); viewCore, sb.toString());
Assert.assertFalse("Failed to retrieve bounds for " + nodeId, Assert.assertFalse("Failed to retrieve bounds for " + nodeId,
jsonText.trim().equalsIgnoreCase("null")); jsonText.trim().equalsIgnoreCase("null"));
...@@ -72,7 +71,7 @@ public class DOMUtils { ...@@ -72,7 +71,7 @@ public class DOMUtils {
* Focus a DOM node by its id. * Focus a DOM node by its id.
*/ */
public static void focusNode(ActivityInstrumentationTestCase2 activityTestCase, public static void focusNode(ActivityInstrumentationTestCase2 activityTestCase,
final ContentViewCore viewCore, TestCallbackHelperContainer viewClient, String nodeId) final ContentViewCore viewCore, String nodeId)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("(function() {"); sb.append("(function() {");
...@@ -80,16 +79,16 @@ public class DOMUtils { ...@@ -80,16 +79,16 @@ public class DOMUtils {
sb.append(" if (node) node.focus();"); sb.append(" if (node) node.focus();");
sb.append("})();"); sb.append("})();");
JavaScriptUtils.executeJavaScriptAndWaitForResult(viewCore, viewClient, sb.toString()); JavaScriptUtils.executeJavaScriptAndWaitForResult(viewCore, sb.toString());
} }
/** /**
* Click a DOM node by its id. * Click a DOM node by its id.
*/ */
public static void clickNode(ActivityInstrumentationTestCase2 activityTestCase, public static void clickNode(ActivityInstrumentationTestCase2 activityTestCase,
final ContentView view, TestCallbackHelperContainer viewClient, String nodeId) final ContentView view, String nodeId)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
int[] clickTarget = getClickTargetForNode(view.getContentViewCore(), viewClient, nodeId); int[] clickTarget = getClickTargetForNode(view.getContentViewCore(), nodeId);
TouchCommon touchCommon = new TouchCommon(activityTestCase); TouchCommon touchCommon = new TouchCommon(activityTestCase);
touchCommon.singleClickView(view, clickTarget[0], clickTarget[1]); touchCommon.singleClickView(view, clickTarget[0], clickTarget[1]);
} }
...@@ -98,9 +97,9 @@ public class DOMUtils { ...@@ -98,9 +97,9 @@ public class DOMUtils {
* Long-press a DOM node by its id. * Long-press a DOM node by its id.
*/ */
public static void longPressNode(ActivityInstrumentationTestCase2 activityTestCase, public static void longPressNode(ActivityInstrumentationTestCase2 activityTestCase,
final ContentView view, TestCallbackHelperContainer viewClient, String nodeId) final ContentView view, String nodeId)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
int[] clickTarget = getClickTargetForNode(view.getContentViewCore(), viewClient, nodeId); int[] clickTarget = getClickTargetForNode(view.getContentViewCore(), nodeId);
TouchCommon touchCommon = new TouchCommon(activityTestCase); TouchCommon touchCommon = new TouchCommon(activityTestCase);
touchCommon.longPressView(view, clickTarget[0], clickTarget[1]); touchCommon.longPressView(view, clickTarget[0], clickTarget[1]);
} }
...@@ -108,33 +107,30 @@ public class DOMUtils { ...@@ -108,33 +107,30 @@ public class DOMUtils {
/** /**
* Scrolls the view to ensure that the required DOM node is visible. * Scrolls the view to ensure that the required DOM node is visible.
*/ */
public static void scrollNodeIntoView(final ContentViewCore viewCore, public static void scrollNodeIntoView(ContentViewCore viewCore, String nodeId)
TestCallbackHelperContainer viewClient, String nodeId)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
JavaScriptUtils.executeJavaScriptAndWaitForResult(viewCore, viewClient, JavaScriptUtils.executeJavaScriptAndWaitForResult(viewCore,
"document.getElementById('" + nodeId + "').scrollIntoView()"); "document.getElementById('" + nodeId + "').scrollIntoView()");
} }
/** /**
* Returns the contents of the node by its id. * Returns the contents of the node by its id.
*/ */
public static String getNodeContents(final ContentViewCore viewCore, public static String getNodeContents(ContentViewCore viewCore, String nodeId)
TestCallbackHelperContainer viewClient, String nodeId)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
return getNodeField("textContent", viewCore, viewClient, nodeId); return getNodeField("textContent", viewCore, nodeId);
} }
/** /**
* Returns the value of the node by its id. * Returns the value of the node by its id.
*/ */
public static String getNodeValue(final ContentViewCore viewCore, public static String getNodeValue(final ContentViewCore viewCore, String nodeId)
TestCallbackHelperContainer viewClient, String nodeId)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
return getNodeField("value", viewCore, viewClient, nodeId); return getNodeField("value", viewCore, nodeId);
} }
private static String getNodeField(String fieldName, final ContentViewCore viewCore, private static String getNodeField(String fieldName, final ContentViewCore viewCore,
TestCallbackHelperContainer viewClient, String nodeId) String nodeId)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("(function() {"); sb.append("(function() {");
...@@ -145,7 +141,7 @@ public class DOMUtils { ...@@ -145,7 +141,7 @@ public class DOMUtils {
sb.append("})();"); sb.append("})();");
String jsonText = JavaScriptUtils.executeJavaScriptAndWaitForResult( String jsonText = JavaScriptUtils.executeJavaScriptAndWaitForResult(
viewCore, viewClient, sb.toString()); viewCore, sb.toString());
Assert.assertFalse("Failed to retrieve contents for " + nodeId, Assert.assertFalse("Failed to retrieve contents for " + nodeId,
jsonText.trim().equalsIgnoreCase("null")); jsonText.trim().equalsIgnoreCase("null"));
...@@ -169,13 +165,13 @@ public class DOMUtils { ...@@ -169,13 +165,13 @@ public class DOMUtils {
* @return Whether the node started having non-zero bounds. * @return Whether the node started having non-zero bounds.
*/ */
public static boolean waitForNonZeroNodeBounds(final ContentViewCore viewCore, public static boolean waitForNonZeroNodeBounds(final ContentViewCore viewCore,
final TestCallbackHelperContainer viewClient, final String nodeName) final String nodeName)
throws InterruptedException { throws InterruptedException {
return CriteriaHelper.pollForCriteria(new Criteria() { return CriteriaHelper.pollForCriteria(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
try { try {
return !DOMUtils.getNodeBounds(viewCore, viewClient, nodeName).isEmpty(); return !DOMUtils.getNodeBounds(viewCore, nodeName).isEmpty();
} catch (InterruptedException e) { } catch (InterruptedException e) {
// Intentionally do nothing // Intentionally do nothing
return false; return false;
...@@ -190,10 +186,9 @@ public class DOMUtils { ...@@ -190,10 +186,9 @@ public class DOMUtils {
/** /**
* Returns click targets for a given DOM node. * Returns click targets for a given DOM node.
*/ */
private static int[] getClickTargetForNode(final ContentViewCore viewCore, private static int[] getClickTargetForNode(ContentViewCore viewCore, String nodeName)
TestCallbackHelperContainer viewClient, String nodeName)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
Rect bounds = getNodeBounds(viewCore, viewClient, nodeName); Rect bounds = getNodeBounds(viewCore, nodeName);
Assert.assertNotNull("Failed to get DOM element bounds of '" + nodeName + "'.", bounds); Assert.assertNotNull("Failed to get DOM element bounds of '" + nodeName + "'.", bounds);
int clickX = (int) viewCore.getRenderCoordinates().fromLocalCssToPix(bounds.exactCenterX()) int clickX = (int) viewCore.getRenderCoordinates().fromLocalCssToPix(bounds.exactCenterX())
......
...@@ -10,6 +10,7 @@ import junit.framework.Assert; ...@@ -10,6 +10,7 @@ import junit.framework.Assert;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
...@@ -25,10 +26,9 @@ public class JavaScriptUtils { ...@@ -25,10 +26,9 @@ public class JavaScriptUtils {
* Returns the result of its execution in JSON format. * Returns the result of its execution in JSON format.
*/ */
public static String executeJavaScriptAndWaitForResult( public static String executeJavaScriptAndWaitForResult(
final ContentViewCore viewCore, TestCallbackHelperContainer viewClient, ContentViewCore viewCore, String code) throws InterruptedException, TimeoutException {
final String code) throws InterruptedException, TimeoutException {
return executeJavaScriptAndWaitForResult( return executeJavaScriptAndWaitForResult(
viewCore, viewClient.getOnEvaluateJavaScriptResultHelper(), code); viewCore, code, EVALUATION_TIMEOUT_SECONDS, TimeUnit.SECONDS);
} }
/** /**
...@@ -38,23 +38,11 @@ public class JavaScriptUtils { ...@@ -38,23 +38,11 @@ public class JavaScriptUtils {
*/ */
public static String executeJavaScriptAndWaitForResult( public static String executeJavaScriptAndWaitForResult(
final ContentViewCore viewCore, final ContentViewCore viewCore,
final TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper helper,
final String code) throws InterruptedException, TimeoutException {
return executeJavaScriptAndWaitForResult(
viewCore, helper, code, EVALUATION_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
/**
* Executes the given snippet of JavaScript code within the given ContentViewCore.
* Does not depend on ContentView and TestCallbackHelperContainer.
* Returns the result of its execution in JSON format.
*/
public static String executeJavaScriptAndWaitForResult(
final ContentViewCore viewCore,
final TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper helper,
final String code, final String code,
final long timeout, final TimeUnit timeoutUnits) final long timeout,
final TimeUnit timeoutUnits)
throws InterruptedException, TimeoutException { throws InterruptedException, TimeoutException {
final OnEvaluateJavaScriptResultHelper helper = new OnEvaluateJavaScriptResultHelper();
// Calling this from the UI thread causes it to time-out: the UI thread being blocked won't // Calling this from the UI thread causes it to time-out: the UI thread being blocked won't
// have a chance to process the JavaScript eval response). // have a chance to process the JavaScript eval response).
Assert.assertFalse("Executing JavaScript should be done from the test thread, " Assert.assertFalse("Executing JavaScript should be done from the test thread, "
......
...@@ -15,8 +15,8 @@ import java.util.concurrent.TimeoutException; ...@@ -15,8 +15,8 @@ import java.util.concurrent.TimeoutException;
* This class is used to provide callback hooks for tests and related classes. * This class is used to provide callback hooks for tests and related classes.
*/ */
public class TestCallbackHelperContainer { public class TestCallbackHelperContainer {
private TestContentViewClient mTestContentViewClient; private final TestContentViewClient mTestContentViewClient;
private TestWebContentsObserver mTestWebContentsObserver; private final TestWebContentsObserver mTestWebContentsObserver;
public TestCallbackHelperContainer(ContentView contentView) { public TestCallbackHelperContainer(ContentView contentView) {
mTestContentViewClient = new TestContentViewClient(); mTestContentViewClient = new TestContentViewClient();
...@@ -176,10 +176,6 @@ public class TestCallbackHelperContainer { ...@@ -176,10 +176,6 @@ public class TestCallbackHelperContainer {
return mTestWebContentsObserver.getOnReceivedErrorHelper(); return mTestWebContentsObserver.getOnReceivedErrorHelper();
} }
public OnEvaluateJavaScriptResultHelper getOnEvaluateJavaScriptResultHelper() {
return mTestContentViewClient.getOnEvaluateJavaScriptResultHelper();
}
public OnStartContentIntentHelper getOnStartContentIntentHelper() { public OnStartContentIntentHelper getOnStartContentIntentHelper() {
return mTestContentViewClient.getOnStartContentIntentHelper(); return mTestContentViewClient.getOnStartContentIntentHelper();
} }
......
...@@ -7,7 +7,6 @@ package org.chromium.content.browser.test.util; ...@@ -7,7 +7,6 @@ package org.chromium.content.browser.test.util;
import android.content.Context; import android.content.Context;
import org.chromium.content.browser.ContentViewClient; import org.chromium.content.browser.ContentViewClient;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnStartContentIntentHelper; import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnStartContentIntentHelper;
/** /**
...@@ -18,18 +17,12 @@ import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnStar ...@@ -18,18 +17,12 @@ import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnStar
*/ */
public class TestContentViewClient extends ContentViewClient { public class TestContentViewClient extends ContentViewClient {
private OnEvaluateJavaScriptResultHelper mOnEvaluateJavaScriptResultHelper; private final OnStartContentIntentHelper mOnStartContentIntentHelper;
private OnStartContentIntentHelper mOnStartContentIntentHelper;
public TestContentViewClient() { public TestContentViewClient() {
mOnEvaluateJavaScriptResultHelper = new OnEvaluateJavaScriptResultHelper();
mOnStartContentIntentHelper = new OnStartContentIntentHelper(); mOnStartContentIntentHelper = new OnStartContentIntentHelper();
} }
public OnEvaluateJavaScriptResultHelper getOnEvaluateJavaScriptResultHelper() {
return mOnEvaluateJavaScriptResultHelper;
}
public OnStartContentIntentHelper getOnStartContentIntentHelper() { public OnStartContentIntentHelper getOnStartContentIntentHelper() {
return mOnStartContentIntentHelper; return mOnStartContentIntentHelper;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment