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

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

Powered by Google App Engine
This is Rietveld 408576698