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

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

Issue 2681933002: Add Java wrapper for RenderFrameHost (Closed)
Patch Set: Make test work with PlzNavigate 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
« no previous file with comments | « content/public/android/java/src/org/chromium/content_public/browser/WebContents.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.chromium.base.ThreadUtils; 13 import org.chromium.base.ThreadUtils;
14 import org.chromium.base.test.util.UrlUtils;
15 import org.chromium.content_public.browser.RenderFrameHost;
14 import org.chromium.content_public.browser.WebContents; 16 import org.chromium.content_public.browser.WebContents;
15 import org.chromium.content_shell.Shell; 17 import org.chromium.content_shell.Shell;
16 import org.chromium.content_shell_apk.ContentShellActivity; 18 import org.chromium.content_shell_apk.ContentShellActivity;
17 import org.chromium.content_shell_apk.ContentShellTestBase; 19 import org.chromium.content_shell_apk.ContentShellTestBase;
18 20
19 import java.util.concurrent.Callable; 21 import java.util.concurrent.Callable;
20 import java.util.concurrent.ExecutionException; 22 import java.util.concurrent.ExecutionException;
21 23
22 /** 24 /**
23 * Test various Java WebContents specific features. 25 * Test various Java WebContents specific features.
24 * TODO(dtrainor): Add more testing for the WebContents methods. 26 * TODO(dtrainor): Add more testing for the WebContents methods.
25 */ 27 */
26 public class WebContentsTest extends ContentShellTestBase { 28 public class WebContentsTest extends ContentShellTestBase {
27 private static final String TEST_URL_1 = "about://blank"; 29 private static final String TEST_URL_1 = "about://blank";
30 private static final String TEST_URL_2 = UrlUtils.encodeHtmlDataUri("<html>1 </html>");
28 private static final String WEB_CONTENTS_KEY = "WEBCONTENTSKEY"; 31 private static final String WEB_CONTENTS_KEY = "WEBCONTENTSKEY";
29 private static final String PARCEL_STRING_TEST_DATA = "abcdefghijklmnopqrstu vwxyz"; 32 private static final String PARCEL_STRING_TEST_DATA = "abcdefghijklmnopqrstu vwxyz";
30 33
31 /** 34 /**
32 * Check that {@link WebContents#isDestroyed()} works as expected. 35 * Check that {@link WebContents#isDestroyed()} works as expected.
33 * TODO(dtrainor): Test this using {@link WebContents#destroy()} instead onc e it is possible to 36 * TODO(dtrainor): Test this using {@link WebContents#destroy()} instead onc e it is possible to
34 * build a {@link WebContents} directly in the content/ layer. 37 * build a {@link WebContents} directly in the content/ layer.
35 * 38 *
36 * @throws InterruptedException 39 * @throws InterruptedException
37 * @throws ExecutionException 40 * @throws ExecutionException
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 assertNull("Unexpectedly deserialized a WebContents", deserializedWe bContents); 306 assertNull("Unexpectedly deserialized a WebContents", deserializedWe bContents);
304 307
305 // Make sure we can properly deserialize the String after the WebCon tents. 308 // Make sure we can properly deserialize the String after the WebCon tents.
306 assertEquals("Failing to read the WebContents corrupted the parcel", 309 assertEquals("Failing to read the WebContents corrupted the parcel",
307 PARCEL_STRING_TEST_DATA, parcel.readString()); 310 PARCEL_STRING_TEST_DATA, parcel.readString());
308 } finally { 311 } finally {
309 parcel.recycle(); 312 parcel.recycle();
310 } 313 }
311 } 314 }
312 315
316 /**
317 * Check that the main frame associated with the WebContents is not null
318 * and corresponds with the test URL.
319 *
320 * @throws InterruptedException
321 */
322 @SmallTest
323 public void testWebContentsMainFrame() throws InterruptedException {
324 final ContentShellActivity activity = launchContentShellWithUrl(TEST_URL _2);
325 waitForActiveShellToBeDoneLoading();
326 final WebContents webContents = activity.getActiveWebContents();
327
328 ThreadUtils.postOnUiThread(new Runnable() {
329 @Override
330 public void run() {
331 RenderFrameHost frameHost = webContents.getMainFrame();
332
333 assertNotNull(frameHost);
334
335 assertEquals("RenderFrameHost has incorrect last committed URL", TEST_URL_2,
336 frameHost.getLastCommittedURL());
337
338 WebContents associatedWebContents = WebContentsImpl.fromRenderFr ameHost(frameHost);
339 assertEquals("RenderFrameHost associated with different WebConte nts", webContents,
340 associatedWebContents);
341 }
342 });
343 }
344
313 private boolean isWebContentsDestroyed(final WebContents webContents) { 345 private boolean isWebContentsDestroyed(final WebContents webContents) {
314 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean >() { 346 return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Boolean >() {
315 @Override 347 @Override
316 public Boolean call() throws Exception { 348 public Boolean call() throws Exception {
317 return webContents.isDestroyed(); 349 return webContents.isDestroyed();
318 } 350 }
319 }); 351 });
320 } 352 }
321 } 353 }
OLDNEW
« no previous file with comments | « content/public/android/java/src/org/chromium/content_public/browser/WebContents.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698