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

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/GetTitleTest.java

Issue 11098030: Revert 160959 - [android_webview] Use AwContents loadUrl method instead of ContentViewCore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.android_webview.test; 5 package org.chromium.android_webview.test;
6 6
7 import android.test.suitebuilder.annotation.SmallTest; 7 import android.test.suitebuilder.annotation.SmallTest;
8 import android.test.suitebuilder.annotation.Smoke; 8 import android.test.suitebuilder.annotation.Smoke;
9 9
10 import org.chromium.android_webview.AwContents;
11 import org.chromium.android_webview.test.util.TestWebServer; 10 import org.chromium.android_webview.test.util.TestWebServer;
12 import org.chromium.base.test.util.Feature; 11 import org.chromium.base.test.util.Feature;
13 import org.chromium.base.test.util.DisabledTest; 12 import org.chromium.base.test.util.DisabledTest;
13 import org.chromium.content.browser.ContentViewCore;
14 14
15 /** 15 /**
16 * A test suite for ContentView.getTitle(). 16 * A test suite for ContentView.getTitle().
17 */ 17 */
18 public class GetTitleTest extends AndroidWebViewTestBase { 18 public class GetTitleTest extends AndroidWebViewTestBase {
19 private static final String TITLE = "TITLE"; 19 private static final String TITLE = "TITLE";
20 20
21 private static final String GET_TITLE_TEST_PATH = "/get_title_test.html"; 21 private static final String GET_TITLE_TEST_PATH = "/get_title_test.html";
22 private static final String GET_TITLE_TEST_EMPTY_PATH = "/get_title_test_emp ty.html"; 22 private static final String GET_TITLE_TEST_EMPTY_PATH = "/get_title_test_emp ty.html";
23 private static final String GET_TITLE_TEST_NO_TITLE_PATH = "/get_title_test_ no_title.html"; 23 private static final String GET_TITLE_TEST_NO_TITLE_PATH = "/get_title_test_ no_title.html";
24 24
25 private TestAwContentsClient mContentsClient; 25 private TestAwContentsClient mContentsClient;
26 private AwContents mAwContents; 26 private ContentViewCore mContentViewCore;
27 27
28 private static class PageInfo { 28 private static class PageInfo {
29 public final String mTitle; 29 public final String mTitle;
30 public final String mUrl; 30 public final String mUrl;
31 31
32 public PageInfo(String title, String url) { 32 public PageInfo(String title, String url) {
33 mTitle = title; 33 mTitle = title;
34 mUrl = url; 34 mUrl = url;
35 } 35 }
36 }; 36 };
37 37
38 @Override 38 @Override
39 public void setUp() throws Exception { 39 public void setUp() throws Exception {
40 super.setUp(); 40 super.setUp();
41 mContentsClient = new TestAwContentsClient(); 41 mContentsClient = new TestAwContentsClient();
42 final AwTestContainerView testContainerView = 42 mContentViewCore =
43 createAwTestContainerViewOnMainSync(mContentsClient); 43 createAwTestContainerViewOnMainSync(mContentsClient).getContentV iewCore();
44 mAwContents = testContainerView.getAwContents();
45 } 44 }
46 45
47 private static final String getHtml(String title) { 46 private static final String getHtml(String title) {
48 StringBuilder html = new StringBuilder(); 47 StringBuilder html = new StringBuilder();
49 html.append("<html><head>"); 48 html.append("<html><head>");
50 if (title != null) { 49 if (title != null) {
51 html.append("<title>" + title + "</title>"); 50 html.append("<title>" + title + "</title>");
52 } 51 }
53 html.append("</head><body>BODY</body></html>"); 52 html.append("</head><body>BODY</body></html>");
54 return html.toString(); 53 return html.toString();
55 } 54 }
56 55
57 private String loadFromDataAndGetTitle(String html) throws Throwable { 56 private String loadFromDataAndGetTitle(String html) throws Throwable {
58 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), 57 loadDataSync(mContentViewCore, mContentsClient.getOnPageFinishedHelper() ,
59 html, "text/html", false); 58 html, "text/html", false);
60 return getTitleOnUiThread(mAwContents); 59 return getTitleOnUiThread(mContentViewCore);
61 } 60 }
62 61
63 private PageInfo loadFromUrlAndGetTitle(String html, String filename) throws Throwable { 62 private PageInfo loadFromUrlAndGetTitle(String html, String filename) throws Throwable {
64 TestWebServer webServer = null; 63 TestWebServer webServer = null;
65 try { 64 try {
66 webServer = new TestWebServer(false); 65 webServer = new TestWebServer(false);
67 66
68 final String url = webServer.setResponse(filename, html, null); 67 final String url = webServer.setResponse(filename, html, null);
69 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url); 68 loadUrlSync(mContentViewCore, mContentsClient.getOnPageFinishedHelpe r(), url);
70 return new PageInfo(getTitleOnUiThread(mAwContents), 69 return new PageInfo(getTitleOnUiThread(mContentViewCore),
71 url.replaceAll("http:\\/\\/", "")); 70 url.replaceAll("http:\\/\\/", ""));
72 71
73 } finally { 72 } finally {
74 if (webServer != null) webServer.shutdown(); 73 if (webServer != null) webServer.shutdown();
75 } 74 }
76 } 75 }
77 76
78 /** 77 /**
79 * When the data has title info, the page title is set to it. 78 * When the data has title info, the page title is set to it.
80 * @throws Throwable 79 * @throws Throwable
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 final String expectedTitle = "Expected"; 164 final String expectedTitle = "Expected";
166 final String page = 165 final String page =
167 // Note: document.title="...";document.writeln(document.title); also fails. 166 // Note: document.title="...";document.writeln(document.title); also fails.
168 "<html>" + 167 "<html>" +
169 "<body onload='document.writeln(document.title=\"" + expectedTit le + "\")'>" + 168 "<body onload='document.writeln(document.title=\"" + expectedTit le + "\")'>" +
170 "</body></html>"; 169 "</body></html>";
171 final String title = loadFromDataAndGetTitle(page); 170 final String title = loadFromDataAndGetTitle(page);
172 assertEquals("Incorrect title :: ", expectedTitle, title); 171 assertEquals("Incorrect title :: ", expectedTitle, title);
173 } 172 }
174 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698