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

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java

Issue 2708243004: Auto convert content shell tests to JUnit4 (Closed)
Patch Set: New test added from WebContentsTest Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 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.webcontents; 5 package org.chromium.content.browser.webcontents;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.content.Intent; 8 import android.content.Intent;
9 import android.os.Bundle; 9 import android.os.Bundle;
10 import android.os.Parcel; 10 import android.os.Parcel;
11 import android.support.test.filters.SmallTest; 11 import android.support.test.filters.SmallTest;
12 12
13 import org.junit.Assert;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17
13 import org.chromium.base.ThreadUtils; 18 import org.chromium.base.ThreadUtils;
19 import org.chromium.base.test.BaseJUnit4ClassRunner;
14 import org.chromium.content_public.browser.RenderFrameHost; 20 import org.chromium.content_public.browser.RenderFrameHost;
15 import org.chromium.content_public.browser.WebContents; 21 import org.chromium.content_public.browser.WebContents;
16 import org.chromium.content_shell.Shell; 22 import org.chromium.content_shell.Shell;
17 import org.chromium.content_shell_apk.ContentShellActivity; 23 import org.chromium.content_shell_apk.ContentShellActivity;
18 import org.chromium.content_shell_apk.ContentShellTestBase; 24 import org.chromium.content_shell_apk.ContentShellActivityTestRule;
19 25
20 import java.util.concurrent.Callable; 26 import java.util.concurrent.Callable;
21 import java.util.concurrent.ExecutionException; 27 import java.util.concurrent.ExecutionException;
22 28
23 /** 29 /**
24 * Test various Java WebContents specific features. 30 * Test various Java WebContents specific features.
25 * TODO(dtrainor): Add more testing for the WebContents methods. 31 * TODO(dtrainor): Add more testing for the WebContents methods.
26 */ 32 */
27 public class WebContentsTest extends ContentShellTestBase { 33 @RunWith(BaseJUnit4ClassRunner.class)
34 public class WebContentsTest {
35 @Rule
36 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi vityTestRule();
37
28 private static final String TEST_URL_1 = "about://blank"; 38 private static final String TEST_URL_1 = "about://blank";
29 private static final String WEB_CONTENTS_KEY = "WEBCONTENTSKEY"; 39 private static final String WEB_CONTENTS_KEY = "WEBCONTENTSKEY";
30 private static final String PARCEL_STRING_TEST_DATA = "abcdefghijklmnopqrstu vwxyz"; 40 private static final String PARCEL_STRING_TEST_DATA = "abcdefghijklmnopqrstu vwxyz";
31 41
32 /** 42 /**
33 * Check that {@link WebContents#isDestroyed()} works as expected. 43 * Check that {@link WebContents#isDestroyed()} works as expected.
34 * TODO(dtrainor): Test this using {@link WebContents#destroy()} instead onc e it is possible to 44 * TODO(dtrainor): Test this using {@link WebContents#destroy()} instead onc e it is possible to
35 * build a {@link WebContents} directly in the content/ layer. 45 * build a {@link WebContents} directly in the content/ layer.
36 * 46 *
37 * @throws InterruptedException 47 * @throws InterruptedException
38 * @throws ExecutionException 48 * @throws ExecutionException
39 */ 49 */
50 @Test
40 @SmallTest 51 @SmallTest
41 public void testWebContentsIsDestroyedMethod() throws InterruptedException, ExecutionException { 52 public void testWebContentsIsDestroyedMethod() throws InterruptedException, ExecutionException {
42 final ContentShellActivity activity = launchContentShellWithUrl(TEST_URL _1); 53 final ContentShellActivity activity =
43 waitForActiveShellToBeDoneLoading(); 54 mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
55 mActivityTestRule.waitForActiveShellToBeDoneLoading();
44 WebContents webContents = activity.getActiveWebContents(); 56 WebContents webContents = activity.getActiveWebContents();
45 57
46 assertFalse("WebContents incorrectly marked as destroyed", 58 Assert.assertFalse(
47 isWebContentsDestroyed(webContents)); 59 "WebContents incorrectly marked as destroyed", isWebContentsDest royed(webContents));
48 60
49 // Launch a new shell. 61 // Launch a new shell.
50 Shell originalShell = activity.getActiveShell(); 62 Shell originalShell = activity.getActiveShell();
51 loadNewShell(TEST_URL_1); 63 mActivityTestRule.loadNewShell(TEST_URL_1);
52 assertNotSame("New shell not created", activity.getActiveShell(), origin alShell); 64 Assert.assertNotSame("New shell not created", activity.getActiveShell(), originalShell);
53 65
54 assertTrue("WebContents incorrectly marked as not destroyed", 66 Assert.assertTrue("WebContents incorrectly marked as not destroyed",
55 isWebContentsDestroyed(webContents)); 67 isWebContentsDestroyed(webContents));
56 } 68 }
57 69
58 /** 70 /**
59 * Check that it is possible to serialize and deserialize a WebContents obje ct through Parcels. 71 * Check that it is possible to serialize and deserialize a WebContents obje ct through Parcels.
60 * 72 *
61 * @throws InterruptedException 73 * @throws InterruptedException
62 */ 74 */
75 @Test
63 @SmallTest 76 @SmallTest
64 public void testWebContentsSerializeDeserializeInParcel() throws Interrupted Exception { 77 public void testWebContentsSerializeDeserializeInParcel() throws Interrupted Exception {
65 launchContentShellWithUrl(TEST_URL_1); 78 mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
66 waitForActiveShellToBeDoneLoading(); 79 mActivityTestRule.waitForActiveShellToBeDoneLoading();
67 WebContents webContents = getWebContents(); 80 WebContents webContents = mActivityTestRule.getWebContents();
68 81
69 Parcel parcel = Parcel.obtain(); 82 Parcel parcel = Parcel.obtain();
70 83
71 try { 84 try {
72 // Serialize the WebContents. 85 // Serialize the WebContents.
73 parcel.writeParcelable(webContents, 0); 86 parcel.writeParcelable(webContents, 0);
74 87
75 // Read back the WebContents. 88 // Read back the WebContents.
76 parcel.setDataPosition(0); 89 parcel.setDataPosition(0);
77 WebContents deserializedWebContents = parcel.readParcelable( 90 WebContents deserializedWebContents = parcel.readParcelable(
78 WebContents.class.getClassLoader()); 91 WebContents.class.getClassLoader());
79 92
80 // Make sure they're equal. 93 // Make sure they're equal.
81 assertEquals("Deserialized object does not match", 94 Assert.assertEquals(
82 webContents, deserializedWebContents); 95 "Deserialized object does not match", webContents, deseriali zedWebContents);
83 } finally { 96 } finally {
84 parcel.recycle(); 97 parcel.recycle();
85 } 98 }
86 } 99 }
87 100
88 /** 101 /**
89 * Check that it is possible to serialize and deserialize a WebContents obje ct through Bundles. 102 * Check that it is possible to serialize and deserialize a WebContents obje ct through Bundles.
90 * @throws InterruptedException 103 * @throws InterruptedException
91 */ 104 */
105 @Test
92 @SmallTest 106 @SmallTest
93 // TODO(crbug.com/635567): Fix this properly. 107 // TODO(crbug.com/635567): Fix this properly.
94 @SuppressLint("ParcelClassLoader") 108 @SuppressLint("ParcelClassLoader")
95 public void testWebContentsSerializeDeserializeInBundle() throws Interrupted Exception { 109 public void testWebContentsSerializeDeserializeInBundle() throws Interrupted Exception {
96 launchContentShellWithUrl(TEST_URL_1); 110 mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
97 waitForActiveShellToBeDoneLoading(); 111 mActivityTestRule.waitForActiveShellToBeDoneLoading();
98 WebContents webContents = getWebContents(); 112 WebContents webContents = mActivityTestRule.getWebContents();
99 113
100 // Use a parcel to force the Bundle to actually serialize and deserializ e, otherwise it can 114 // Use a parcel to force the Bundle to actually serialize and deserializ e, otherwise it can
101 // cache the WebContents object. 115 // cache the WebContents object.
102 Parcel parcel = Parcel.obtain(); 116 Parcel parcel = Parcel.obtain();
103 117
104 try { 118 try {
105 // Create a bundle and put the WebContents in it. 119 // Create a bundle and put the WebContents in it.
106 Bundle bundle = new Bundle(); 120 Bundle bundle = new Bundle();
107 bundle.putParcelable(WEB_CONTENTS_KEY, webContents); 121 bundle.putParcelable(WEB_CONTENTS_KEY, webContents);
108 122
109 // Serialize the Bundle. 123 // Serialize the Bundle.
110 parcel.writeBundle(bundle); 124 parcel.writeBundle(bundle);
111 125
112 // Read back the Bundle. 126 // Read back the Bundle.
113 parcel.setDataPosition(0); 127 parcel.setDataPosition(0);
114 Bundle deserializedBundle = parcel.readBundle(); 128 Bundle deserializedBundle = parcel.readBundle();
115 129
116 // Read back the WebContents. 130 // Read back the WebContents.
117 deserializedBundle.setClassLoader(WebContents.class.getClassLoader() ); 131 deserializedBundle.setClassLoader(WebContents.class.getClassLoader() );
118 WebContents deserializedWebContents = 132 WebContents deserializedWebContents =
119 deserializedBundle.getParcelable(WEB_CONTENTS_KEY); 133 deserializedBundle.getParcelable(WEB_CONTENTS_KEY);
120 134
121 // Make sure they're equal. 135 // Make sure they're equal.
122 assertEquals("Deserialized object does not match", 136 Assert.assertEquals(
123 webContents, deserializedWebContents); 137 "Deserialized object does not match", webContents, deseriali zedWebContents);
124 } finally { 138 } finally {
125 parcel.recycle(); 139 parcel.recycle();
126 } 140 }
127 } 141 }
128 142
129 /** 143 /**
130 * Check that it is possible to serialize and deserialize a WebContents obje ct through Intents. 144 * Check that it is possible to serialize and deserialize a WebContents obje ct through Intents.
131 * @throws InterruptedException 145 * @throws InterruptedException
132 */ 146 */
147 @Test
133 @SmallTest 148 @SmallTest
134 // TODO(crbug.com/635567): Fix this properly. 149 // TODO(crbug.com/635567): Fix this properly.
135 @SuppressLint("ParcelClassLoader") 150 @SuppressLint("ParcelClassLoader")
136 public void testWebContentsSerializeDeserializeInIntent() throws Interrupted Exception { 151 public void testWebContentsSerializeDeserializeInIntent() throws Interrupted Exception {
137 launchContentShellWithUrl(TEST_URL_1); 152 mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
138 waitForActiveShellToBeDoneLoading(); 153 mActivityTestRule.waitForActiveShellToBeDoneLoading();
139 WebContents webContents = getWebContents(); 154 WebContents webContents = mActivityTestRule.getWebContents();
140 155
141 // Use a parcel to force the Intent to actually serialize and deserializ e, otherwise it can 156 // Use a parcel to force the Intent to actually serialize and deserializ e, otherwise it can
142 // cache the WebContents object. 157 // cache the WebContents object.
143 Parcel parcel = Parcel.obtain(); 158 Parcel parcel = Parcel.obtain();
144 159
145 try { 160 try {
146 // Create an Intent and put the WebContents in it. 161 // Create an Intent and put the WebContents in it.
147 Intent intent = new Intent(); 162 Intent intent = new Intent();
148 intent.putExtra(WEB_CONTENTS_KEY, webContents); 163 intent.putExtra(WEB_CONTENTS_KEY, webContents);
149 164
150 // Serialize the Intent 165 // Serialize the Intent
151 parcel.writeParcelable(intent, 0); 166 parcel.writeParcelable(intent, 0);
152 167
153 // Read back the Intent. 168 // Read back the Intent.
154 parcel.setDataPosition(0); 169 parcel.setDataPosition(0);
155 Intent deserializedIntent = parcel.readParcelable(null); 170 Intent deserializedIntent = parcel.readParcelable(null);
156 171
157 // Read back the WebContents. 172 // Read back the WebContents.
158 deserializedIntent.setExtrasClassLoader(WebContents.class.getClassLo ader()); 173 deserializedIntent.setExtrasClassLoader(WebContents.class.getClassLo ader());
159 WebContents deserializedWebContents = 174 WebContents deserializedWebContents =
160 (WebContents) deserializedIntent.getParcelableExtra(WEB_CONT ENTS_KEY); 175 (WebContents) deserializedIntent.getParcelableExtra(WEB_CONT ENTS_KEY);
161 176
162 // Make sure they're equal. 177 // Make sure they're equal.
163 assertEquals("Deserialized object does not match", 178 Assert.assertEquals(
164 webContents, deserializedWebContents); 179 "Deserialized object does not match", webContents, deseriali zedWebContents);
165 } finally { 180 } finally {
166 parcel.recycle(); 181 parcel.recycle();
167 } 182 }
168 } 183 }
169 184
170 /** 185 /**
171 * Check that attempting to deserialize a WebContents object from a Parcel f rom another process 186 * Check that attempting to deserialize a WebContents object from a Parcel f rom another process
172 * instance fails. 187 * instance fails.
173 * @throws InterruptedException 188 * @throws InterruptedException
174 */ 189 */
190 @Test
175 @SmallTest 191 @SmallTest
176 public void testWebContentsFailDeserializationAcrossProcessBoundary() 192 public void testWebContentsFailDeserializationAcrossProcessBoundary()
177 throws InterruptedException { 193 throws InterruptedException {
178 launchContentShellWithUrl(TEST_URL_1); 194 mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
179 waitForActiveShellToBeDoneLoading(); 195 mActivityTestRule.waitForActiveShellToBeDoneLoading();
180 WebContents webContents = getWebContents(); 196 WebContents webContents = mActivityTestRule.getWebContents();
181 197
182 Parcel parcel = Parcel.obtain(); 198 Parcel parcel = Parcel.obtain();
183 199
184 try { 200 try {
185 // Serialize the WebContents. 201 // Serialize the WebContents.
186 parcel.writeParcelable(webContents, 0); 202 parcel.writeParcelable(webContents, 0);
187 203
188 // Invalidate all serialized WebContents. 204 // Invalidate all serialized WebContents.
189 WebContentsImpl.invalidateSerializedWebContentsForTesting(); 205 WebContentsImpl.invalidateSerializedWebContentsForTesting();
190 206
191 // Try to read back the WebContents. 207 // Try to read back the WebContents.
192 parcel.setDataPosition(0); 208 parcel.setDataPosition(0);
193 WebContents deserializedWebContents = parcel.readParcelable( 209 WebContents deserializedWebContents = parcel.readParcelable(
194 WebContents.class.getClassLoader()); 210 WebContents.class.getClassLoader());
195 211
196 // Make sure we weren't able to deserialize the WebContents. 212 // Make sure we weren't able to deserialize the WebContents.
197 assertNull("Unexpectedly deserialized a WebContents", deserializedWe bContents); 213 Assert.assertNull("Unexpectedly deserialized a WebContents", deseria lizedWebContents);
198 } finally { 214 } finally {
199 parcel.recycle(); 215 parcel.recycle();
200 } 216 }
201 } 217 }
202 218
203 /** 219 /**
204 * Check that serializing a destroyed WebContents always results in a null d eserialized 220 * Check that serializing a destroyed WebContents always results in a null d eserialized
205 * WebContents. 221 * WebContents.
206 * @throws InterruptedException 222 * @throws InterruptedException
207 * @throws ExecutionException 223 * @throws ExecutionException
208 */ 224 */
225 @Test
209 @SmallTest 226 @SmallTest
210 public void testSerializingADestroyedWebContentsDoesNotDeserialize() 227 public void testSerializingADestroyedWebContentsDoesNotDeserialize()
211 throws InterruptedException, ExecutionException { 228 throws InterruptedException, ExecutionException {
212 ContentShellActivity activity = launchContentShellWithUrl(TEST_URL_1); 229 ContentShellActivity activity = mActivityTestRule.launchContentShellWith Url(TEST_URL_1);
213 waitForActiveShellToBeDoneLoading(); 230 mActivityTestRule.waitForActiveShellToBeDoneLoading();
214 WebContents webContents = activity.getActiveWebContents(); 231 WebContents webContents = activity.getActiveWebContents();
215 loadNewShell(TEST_URL_1); 232 mActivityTestRule.loadNewShell(TEST_URL_1);
216 233
217 assertTrue("WebContents not destroyed", isWebContentsDestroyed(webConten ts)); 234 Assert.assertTrue("WebContents not destroyed", isWebContentsDestroyed(we bContents));
218 235
219 Parcel parcel = Parcel.obtain(); 236 Parcel parcel = Parcel.obtain();
220 237
221 try { 238 try {
222 // Serialize the WebContents. 239 // Serialize the WebContents.
223 parcel.writeParcelable(webContents, 0); 240 parcel.writeParcelable(webContents, 0);
224 241
225 // Try to read back the WebContents. 242 // Try to read back the WebContents.
226 parcel.setDataPosition(0); 243 parcel.setDataPosition(0);
227 WebContents deserializedWebContents = parcel.readParcelable( 244 WebContents deserializedWebContents = parcel.readParcelable(
228 WebContents.class.getClassLoader()); 245 WebContents.class.getClassLoader());
229 246
230 // Make sure we weren't able to deserialize the WebContents. 247 // Make sure we weren't able to deserialize the WebContents.
231 assertNull("Unexpectedly deserialized a destroyed WebContents", 248 Assert.assertNull(
232 deserializedWebContents); 249 "Unexpectedly deserialized a destroyed WebContents", deseria lizedWebContents);
233 } finally { 250 } finally {
234 parcel.recycle(); 251 parcel.recycle();
235 } 252 }
236 } 253 }
237 254
238 /** 255 /**
239 * Check that destroying a WebContents after serializing it always results i n a null 256 * Check that destroying a WebContents after serializing it always results i n a null
240 * deserialized WebContents. 257 * deserialized WebContents.
241 * @throws InterruptedException 258 * @throws InterruptedException
242 * @throws ExecutionException 259 * @throws ExecutionException
243 */ 260 */
261 @Test
244 @SmallTest 262 @SmallTest
245 public void testDestroyingAWebContentsAfterSerializingDoesNotDeserialize() 263 public void testDestroyingAWebContentsAfterSerializingDoesNotDeserialize()
246 throws InterruptedException, ExecutionException { 264 throws InterruptedException, ExecutionException {
247 ContentShellActivity activity = launchContentShellWithUrl(TEST_URL_1); 265 ContentShellActivity activity = mActivityTestRule.launchContentShellWith Url(TEST_URL_1);
248 waitForActiveShellToBeDoneLoading(); 266 mActivityTestRule.waitForActiveShellToBeDoneLoading();
249 WebContents webContents = activity.getActiveWebContents(); 267 WebContents webContents = activity.getActiveWebContents();
250 268
251 Parcel parcel = Parcel.obtain(); 269 Parcel parcel = Parcel.obtain();
252 270
253 try { 271 try {
254 // Serialize the WebContents. 272 // Serialize the WebContents.
255 parcel.writeParcelable(webContents, 0); 273 parcel.writeParcelable(webContents, 0);
256 274
257 // Destroy the WebContents. 275 // Destroy the WebContents.
258 loadNewShell(TEST_URL_1); 276 mActivityTestRule.loadNewShell(TEST_URL_1);
259 assertTrue("WebContents not destroyed", isWebContentsDestroyed(webCo ntents)); 277 Assert.assertTrue("WebContents not destroyed", isWebContentsDestroye d(webContents));
260 278
261 // Try to read back the WebContents. 279 // Try to read back the WebContents.
262 parcel.setDataPosition(0); 280 parcel.setDataPosition(0);
263 WebContents deserializedWebContents = parcel.readParcelable( 281 WebContents deserializedWebContents = parcel.readParcelable(
264 WebContents.class.getClassLoader()); 282 WebContents.class.getClassLoader());
265 283
266 // Make sure we weren't able to deserialize the WebContents. 284 // Make sure we weren't able to deserialize the WebContents.
267 assertNull("Unexpectedly deserialized a destroyed WebContents", 285 Assert.assertNull(
268 deserializedWebContents); 286 "Unexpectedly deserialized a destroyed WebContents", deseria lizedWebContents);
269 } finally { 287 } finally {
270 parcel.recycle(); 288 parcel.recycle();
271 } 289 }
272 } 290 }
273 291
274 /** 292 /**
275 * Check that failing a WebContents deserialization doesn't corrupt subseque nt data in the 293 * Check that failing a WebContents deserialization doesn't corrupt subseque nt data in the
276 * Parcel. 294 * Parcel.
277 * @throws InterruptedException 295 * @throws InterruptedException
278 */ 296 */
297 @Test
279 @SmallTest 298 @SmallTest
280 public void testFailedDeserializationDoesntCorruptParcel() 299 public void testFailedDeserializationDoesntCorruptParcel() throws Interrupte dException {
281 throws InterruptedException { 300 mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
282 launchContentShellWithUrl(TEST_URL_1); 301 mActivityTestRule.waitForActiveShellToBeDoneLoading();
283 waitForActiveShellToBeDoneLoading(); 302 WebContents webContents = mActivityTestRule.getWebContents();
284 WebContents webContents = getWebContents();
285 303
286 Parcel parcel = Parcel.obtain(); 304 Parcel parcel = Parcel.obtain();
287 305
288 try { 306 try {
289 // Serialize the WebContents. 307 // Serialize the WebContents.
290 parcel.writeParcelable(webContents, 0); 308 parcel.writeParcelable(webContents, 0);
291 309
292 // Serialize a String after the WebContents. 310 // Serialize a String after the WebContents.
293 parcel.writeString(PARCEL_STRING_TEST_DATA); 311 parcel.writeString(PARCEL_STRING_TEST_DATA);
294 312
295 // Invalidate all serialized WebContents. 313 // Invalidate all serialized WebContents.
296 WebContentsImpl.invalidateSerializedWebContentsForTesting(); 314 WebContentsImpl.invalidateSerializedWebContentsForTesting();
297 315
298 // Try to read back the WebContents. 316 // Try to read back the WebContents.
299 parcel.setDataPosition(0); 317 parcel.setDataPosition(0);
300 WebContents deserializedWebContents = parcel.readParcelable( 318 WebContents deserializedWebContents = parcel.readParcelable(
301 WebContents.class.getClassLoader()); 319 WebContents.class.getClassLoader());
302 320
303 // Make sure we weren't able to deserialize the WebContents. 321 // Make sure we weren't able to deserialize the WebContents.
304 assertNull("Unexpectedly deserialized a WebContents", deserializedWe bContents); 322 Assert.assertNull("Unexpectedly deserialized a WebContents", deseria lizedWebContents);
305 323
306 // Make sure we can properly deserialize the String after the WebCon tents. 324 // Make sure we can properly deserialize the String after the WebCon tents.
307 assertEquals("Failing to read the WebContents corrupted the parcel", 325 Assert.assertEquals("Failing to read the WebContents corrupted the p arcel",
308 PARCEL_STRING_TEST_DATA, parcel.readString()); 326 PARCEL_STRING_TEST_DATA, parcel.readString());
309 } finally { 327 } finally {
310 parcel.recycle(); 328 parcel.recycle();
311 } 329 }
312 } 330 }
313 331
314 /** 332 /**
315 * Check that the main frame associated with the WebContents is not null 333 * Check that the main frame associated with the WebContents is not null
316 * and corresponds with the test URL. 334 * and corresponds with the test URL.
317 * 335 *
318 * @throws InterruptedException 336 * @throws InterruptedException
319 */ 337 */
338 @Test
320 @SmallTest 339 @SmallTest
321 public void testWebContentsMainFrame() throws InterruptedException { 340 public void testWebContentsMainFrame() throws InterruptedException {
boliu 2017/03/10 18:32:32 this needs a rebase.. depending on timing of when
the real yoland 2017/03/10 19:31:58 Will do
boliu 2017/03/10 19:36:10 That CL just got cq-ed again, so guess you have to
322 final ContentShellActivity activity = launchContentShellWithUrl(TEST_URL _1); 341 final ContentShellActivity activity =
323 waitForActiveShellToBeDoneLoading(); 342 mActivityTestRule.launchContentShellWithUrl(TEST_URL_1);
343 mActivityTestRule.waitForActiveShellToBeDoneLoading();
324 final WebContents webContents = activity.getActiveWebContents(); 344 final WebContents webContents = activity.getActiveWebContents();
325 345
326 ThreadUtils.postOnUiThread(new Runnable() { 346 ThreadUtils.postOnUiThread(new Runnable() {
327 @Override 347 @Override
328 public void run() { 348 public void run() {
329 RenderFrameHost frameHost = webContents.getMainFrame(); 349 RenderFrameHost frameHost = webContents.getMainFrame();
330 350
331 assertNotNull(frameHost); 351 Assert.assertNotNull(frameHost);
332 352
333 assertEquals("RenderFrameHost has incorrect last committed URL", "about:blank", 353 Assert.assertEquals("RenderFrameHost has incorrect last committe d URL",
334 frameHost.getLastCommittedURL()); 354 "about:blank", frameHost.getLastCommittedURL());
335 355
336 WebContents associatedWebContents = WebContentsImpl.fromRenderFr ameHost(frameHost); 356 WebContents associatedWebContents = WebContentsImpl.fromRenderFr ameHost(frameHost);
337 assertEquals("RenderFrameHost associated with different WebConte nts", webContents, 357 Assert.assertEquals("RenderFrameHost associated with different W ebContents",
338 associatedWebContents); 358 webContents, associatedWebContents);
339 } 359 }
340 }); 360 });
341 } 361 }
342 362
343 private boolean isWebContentsDestroyed(final WebContents webContents) { 363 private boolean isWebContentsDestroyed(final WebContents webContents) {
344 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean >() { 364 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean >() {
345 @Override 365 @Override
346 public Boolean call() throws Exception { 366 public Boolean call() throws Exception {
347 return webContents.isDestroyed(); 367 return webContents.isDestroyed();
348 } 368 }
349 }); 369 });
350 } 370 }
351 } 371 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698