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

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

Issue 11028094: [android_webview] Use AwContents loadUrl method instead of ContentViewCore. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase yet again 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
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;
10 import org.chromium.android_webview.test.util.TestWebServer; 11 import org.chromium.android_webview.test.util.TestWebServer;
11 import org.chromium.base.test.util.Feature; 12 import org.chromium.base.test.util.Feature;
12 import org.chromium.base.test.util.DisabledTest; 13 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 ContentViewCore mContentViewCore; 26 private AwContents mAwContents;
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 mContentViewCore = 42 final AwTestContainerView testContainerView =
43 createAwTestContainerViewOnMainSync(mContentsClient).getContentV iewCore(); 43 createAwTestContainerViewOnMainSync(mContentsClient);
44 mAwContents = testContainerView.getAwContents();
44 } 45 }
45 46
46 private static final String getHtml(String title) { 47 private static final String getHtml(String title) {
47 StringBuilder html = new StringBuilder(); 48 StringBuilder html = new StringBuilder();
48 html.append("<html><head>"); 49 html.append("<html><head>");
49 if (title != null) { 50 if (title != null) {
50 html.append("<title>" + title + "</title>"); 51 html.append("<title>" + title + "</title>");
51 } 52 }
52 html.append("</head><body>BODY</body></html>"); 53 html.append("</head><body>BODY</body></html>");
53 return html.toString(); 54 return html.toString();
54 } 55 }
55 56
56 private String loadFromDataAndGetTitle(String html) throws Throwable { 57 private String loadFromDataAndGetTitle(String html) throws Throwable {
57 loadDataSync(mContentViewCore, mContentsClient.getOnPageFinishedHelper() , 58 loadDataSync(mAwContents, mContentsClient.getOnPageFinishedHelper(),
58 html, "text/html", false); 59 html, "text/html", false);
59 return getTitleOnUiThread(mContentViewCore); 60 return getTitleOnUiThread(mAwContents);
60 } 61 }
61 62
62 private PageInfo loadFromUrlAndGetTitle(String html, String filename) throws Throwable { 63 private PageInfo loadFromUrlAndGetTitle(String html, String filename) throws Throwable {
63 TestWebServer webServer = null; 64 TestWebServer webServer = null;
64 try { 65 try {
65 webServer = new TestWebServer(false); 66 webServer = new TestWebServer(false);
66 67
67 final String url = webServer.setResponse(filename, html, null); 68 final String url = webServer.setResponse(filename, html, null);
68 loadUrlSync(mContentViewCore, mContentsClient.getOnPageFinishedHelpe r(), url); 69 loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
69 return new PageInfo(getTitleOnUiThread(mContentViewCore), 70 return new PageInfo(getTitleOnUiThread(mAwContents),
70 url.replaceAll("http:\\/\\/", "")); 71 url.replaceAll("http:\\/\\/", ""));
71 72
72 } finally { 73 } finally {
73 if (webServer != null) webServer.shutdown(); 74 if (webServer != null) webServer.shutdown();
74 } 75 }
75 } 76 }
76 77
77 /** 78 /**
78 * When the data has title info, the page title is set to it. 79 * When the data has title info, the page title is set to it.
79 * @throws Throwable 80 * @throws Throwable
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 final String expectedTitle = "Expected"; 165 final String expectedTitle = "Expected";
165 final String page = 166 final String page =
166 // Note: document.title="...";document.writeln(document.title); also fails. 167 // Note: document.title="...";document.writeln(document.title); also fails.
167 "<html>" + 168 "<html>" +
168 "<body onload='document.writeln(document.title=\"" + expectedTit le + "\")'>" + 169 "<body onload='document.writeln(document.title=\"" + expectedTit le + "\")'>" +
169 "</body></html>"; 170 "</body></html>";
170 final String title = loadFromDataAndGetTitle(page); 171 final String title = loadFromDataAndGetTitle(page);
171 assertEquals("Incorrect title :: ", expectedTitle, title); 172 assertEquals("Incorrect title :: ", expectedTitle, title);
172 } 173 }
173 } 174 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698