diff options
-rw-r--r-- | android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java index e5a5479..3275597 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwSettingsTest.java @@ -8,6 +8,8 @@ import android.content.Context; import android.os.Build; import android.test.suitebuilder.annotation.SmallTest; +import org.apache.http.Header; +import org.apache.http.HttpRequest; import org.chromium.android_webview.AndroidProtocolHandler; import org.chromium.android_webview.AwContents; import org.chromium.android_webview.AwSettings; @@ -1262,6 +1264,41 @@ public class AwSettingsTest extends AndroidWebViewTestBase { @SmallTest @Feature({"Android-WebView", "Preferences"}) + public void testUserAgentWithTestServer() throws Throwable { + final TestAwContentsClient contentClient = new TestAwContentsClient(); + final AwTestContainerView testContainerView = + createAwTestContainerViewOnMainSync(contentClient); + AwContents awContents = testContainerView.getAwContents(); + ContentSettings settings = getContentSettingsOnUiThread(awContents); + final String customUserAgentString = + "testUserAgentWithTestServerUserAgent"; + + TestWebServer webServer = null; + String fileName = null; + try { + webServer = new TestWebServer(false); + final String httpPath = "/testUserAgentWithTestServer.html"; + final String url = webServer.setResponse(httpPath, "foo", null); + + settings.setUserAgentString(customUserAgentString); + loadUrlSync(awContents, + contentClient.getOnPageFinishedHelper(), + url); + + assertEquals(1, webServer.getRequestCount(httpPath)); + HttpRequest request = webServer.getLastRequest(httpPath); + Header[] matchingHeaders = request.getHeaders("User-Agent"); + assertEquals(1, matchingHeaders.length); + + Header header = matchingHeaders[0]; + assertEquals(customUserAgentString, header.getValue()); + } finally { + if (webServer != null) webServer.shutdown(); + } + } + + @SmallTest + @Feature({"Android-WebView", "Preferences"}) public void testDomStorageEnabledNormal() throws Throwable { ViewPair views = createViews(NORMAL_VIEW, NORMAL_VIEW); runPerViewSettingsTest( |