OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
8 | 8 |
9 import android.net.Uri; | 9 import android.net.Uri; |
10 import android.support.test.InstrumentationRegistry; | 10 import android.support.test.InstrumentationRegistry; |
11 | 11 |
12 import org.junit.Assert; | |
13 | |
14 import org.chromium.base.Log; | |
12 import org.chromium.base.test.util.CallbackHelper; | 15 import org.chromium.base.test.util.CallbackHelper; |
13 import org.chromium.base.test.util.UrlUtils; | 16 import org.chromium.base.test.util.UrlUtils; |
14 import org.chromium.content.browser.test.util.DOMUtils; | 17 import org.chromium.content.browser.test.util.DOMUtils; |
15 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; | 18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; |
16 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage FinishedHelper; | 19 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage FinishedHelper; |
17 import org.chromium.content_shell.ShellViewAndroidDelegate.ContentIntentHandler; | 20 import org.chromium.content_shell.ShellViewAndroidDelegate.ContentIntentHandler; |
18 import org.chromium.content_shell_apk.ContentShellActivityTestRule; | 21 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
19 | 22 |
20 import java.util.concurrent.TimeUnit; | 23 import java.util.concurrent.TimeUnit; |
21 | 24 |
22 /** | 25 /** |
23 * ActivityTestRule for content detection test suites. | 26 * ActivityTestRule for content detection test suites. |
24 */ | 27 */ |
25 public class ContentDetectionActivityTestRule extends ContentShellActivityTestRu le { | 28 public class ContentDetectionActivityTestRule extends ContentShellActivityTestRu le { |
26 private static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(10); | 29 private static final long WAIT_TIMEOUT_SECONDS = 60; |
27 | 30 |
28 private TestCallbackHelperContainer mCallbackHelper; | 31 private TestCallbackHelperContainer mCallbackHelper; |
29 private TestContentIntentHandler mContentIntentHandler; | 32 private TestContentIntentHandler mContentIntentHandler; |
30 | 33 |
31 /** | 34 /** |
32 * CallbackHelper for OnStartContentIntent. | 35 * CallbackHelper for OnStartContentIntent. |
33 */ | 36 */ |
34 private static class OnStartContentIntentHelper extends CallbackHelper { | 37 private static class OnStartContentIntentHelper extends CallbackHelper { |
35 private String mIntentUrl; | 38 private String mIntentUrl; |
36 public void notifyCalled(String intentUrl) { | 39 public void notifyCalled(String intentUrl) { |
(...skipping 14 matching lines...) Expand all Loading... | |
51 | 54 |
52 public OnStartContentIntentHelper getOnStartContentIntentHelper() { | 55 public OnStartContentIntentHelper getOnStartContentIntentHelper() { |
53 if (mOnStartContentIntentHelper == null) { | 56 if (mOnStartContentIntentHelper == null) { |
54 mOnStartContentIntentHelper = new OnStartContentIntentHelper(); | 57 mOnStartContentIntentHelper = new OnStartContentIntentHelper(); |
55 } | 58 } |
56 return mOnStartContentIntentHelper; | 59 return mOnStartContentIntentHelper; |
57 } | 60 } |
58 | 61 |
59 @Override | 62 @Override |
60 public void onIntentUrlReceived(String intentUrl) { | 63 public void onIntentUrlReceived(String intentUrl) { |
64 Log.d("#YOLAND", "called onIntentUrlReceived"); | |
jbudorick
2017/03/01 23:10:19
:)
I'm assuming that your intention was to remove
the real yoland
2017/03/08 23:35:31
lol, just did
Done
| |
61 mOnStartContentIntentHelper.notifyCalled(intentUrl); | 65 mOnStartContentIntentHelper.notifyCalled(intentUrl); |
62 } | 66 } |
63 } | 67 } |
64 | 68 |
65 /** | 69 /** |
66 * Returns the TestCallbackHelperContainer associated with this ContentView, | 70 * Returns the TestCallbackHelperContainer associated with this ContentView, |
67 * or creates it lazily. | 71 * or creates it lazily. |
68 */ | 72 */ |
69 public TestCallbackHelperContainer getTestCallbackHelperContainer() { | 73 public TestCallbackHelperContainer getTestCallbackHelperContainer() { |
70 if (mCallbackHelper == null) { | 74 if (mCallbackHelper == null) { |
71 mCallbackHelper = new TestCallbackHelperContainer(getContentViewCore ()); | 75 mCallbackHelper = new TestCallbackHelperContainer(getContentViewCore ()); |
72 } | 76 } |
73 return mCallbackHelper; | 77 return mCallbackHelper; |
74 } | 78 } |
75 | 79 |
76 @Override | 80 @Override |
77 protected void beforeActivityLaunched() { | 81 protected void beforeActivityLaunched() { |
82 Log.d("#YOLAND", "beforeActivityLaunched called"); | |
78 super.beforeActivityLaunched(); | 83 super.beforeActivityLaunched(); |
79 mContentIntentHandler = new TestContentIntentHandler(); | 84 mContentIntentHandler = new TestContentIntentHandler(); |
85 Log.d("#YOLAND", "instantiating handler"); | |
80 } | 86 } |
81 | 87 |
82 @Override | 88 @Override |
83 protected void afterActivityLaunched() { | 89 protected void afterActivityLaunched() { |
90 Log.d("#YOLAND", "afterActivityLaunched called"); | |
84 getActivity() | 91 getActivity() |
85 .getShellManager() | 92 .getShellManager() |
86 .getActiveShell() | 93 .getActiveShell() |
87 .getViewAndroidDelegate() | 94 .getViewAndroidDelegate() |
88 .setContentIntentHandler(mContentIntentHandler); | 95 .setContentIntentHandler(mContentIntentHandler); |
89 } | 96 } |
90 | 97 |
91 /** | 98 /** |
92 * Encodes the provided content string into an escaped url as intents do. | 99 * Encodes the provided content string into an escaped url as intents do. |
93 * @param content Content to escape into a url. | 100 * @param content Content to escape into a url. |
(...skipping 12 matching lines...) Expand all Loading... | |
106 return UrlUtils.getIsolatedTestFileUrl(testUrl).equals( | 113 return UrlUtils.getIsolatedTestFileUrl(testUrl).equals( |
107 getContentViewCore().getWebContents().getUrl()); | 114 getContentViewCore().getWebContents().getUrl()); |
108 } | 115 } |
109 | 116 |
110 /** | 117 /** |
111 * Scrolls to the node with the provided id, taps on it and waits for an int ent to come. | 118 * Scrolls to the node with the provided id, taps on it and waits for an int ent to come. |
112 * @param id Id of the node to scroll and tap. | 119 * @param id Id of the node to scroll and tap. |
113 * @return The content url of the received intent or null if none. | 120 * @return The content url of the received intent or null if none. |
114 */ | 121 */ |
115 public String scrollAndTapExpectingIntent(String id) throws Throwable { | 122 public String scrollAndTapExpectingIntent(String id) throws Throwable { |
116 OnStartContentIntentHelper onStartContentIntentHelper = | 123 ContentIntentHandler handler = getActivity() |
124 .getShellManager() | |
125 .getActiveShell() | |
126 .getViewAndroidDelegate() | |
127 .getContentIntentHandler(); | |
128 Log.d("#YOLAND", "hander one is " + handler.toString() + " handler two i s " + mContentIntentHandler.toString()); | |
129 Assert.assertEquals(handler, mContentIntentHandler); | |
130 OnStartContentIntentHelper onStartContentIntentHelper = | |
117 mContentIntentHandler.getOnStartContentIntentHelper(); | 131 mContentIntentHandler.getOnStartContentIntentHelper(); |
118 int currentCallCount = onStartContentIntentHelper.getCallCount(); | 132 int currentCallCount = onStartContentIntentHelper.getCallCount(); |
119 | 133 |
120 DOMUtils.clickNode(getContentViewCore(), id); | 134 Log.d("#YOLAND", "about to click, current count: " + Integer.toString(cu rrentCallCount)); |
135 // DOMUtils.clickNode(getContentViewCore(), id); | |
121 | 136 |
122 onStartContentIntentHelper.waitForCallback( | 137 onStartContentIntentHelper.waitForCallback( |
123 currentCallCount, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); | 138 currentCallCount, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); |
124 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); | 139 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
125 return onStartContentIntentHelper.getIntentUrl(); | 140 return onStartContentIntentHelper.getIntentUrl(); |
126 } | 141 } |
127 | 142 |
128 /** | 143 /** |
129 * Scrolls to the node with the provided id, taps on it and waits for a new page load to finish. | 144 * Scrolls to the node with the provided id, taps on it and waits for a new page load to finish. |
130 * Useful when tapping on links that take to other pages. | 145 * Useful when tapping on links that take to other pages. |
131 * @param id Id of the node to scroll and tap. | 146 * @param id Id of the node to scroll and tap. |
132 * @return The content url of the received intent or null if none. | 147 * @return The content url of the received intent or null if none. |
133 */ | 148 */ |
134 public void scrollAndTapNavigatingOut(String id) throws Throwable { | 149 public void scrollAndTapNavigatingOut(String id) throws Throwable { |
135 TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHel perContainer(); | 150 TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHel perContainer(); |
136 OnPageFinishedHelper onPageFinishedHelper = | 151 OnPageFinishedHelper onPageFinishedHelper = |
137 callbackHelperContainer.getOnPageFinishedHelper(); | 152 callbackHelperContainer.getOnPageFinishedHelper(); |
138 int currentCallCount = onPageFinishedHelper.getCallCount(); | 153 int currentCallCount = onPageFinishedHelper.getCallCount(); |
139 | 154 |
140 DOMUtils.clickNode(getContentViewCore(), id); | 155 DOMUtils.clickNode(getContentViewCore(), id); |
141 | 156 |
142 onPageFinishedHelper.waitForCallback( | 157 onPageFinishedHelper.waitForCallback( |
143 currentCallCount, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); | 158 currentCallCount, 1, WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS); |
144 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); | 159 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
145 } | 160 } |
146 } | 161 } |
OLD | NEW |