1// Copyright 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package org.chromium.android_webview.test; 6 7import android.test.suitebuilder.annotation.SmallTest; 8 9import org.chromium.android_webview.AwContents; 10import org.chromium.base.test.util.Feature; 11 12import java.util.regex.Matcher; 13import java.util.regex.Pattern; 14 15public class UserAgentTest extends AwTestBase { 16 17 private TestAwContentsClient mContentsClient; 18 private AwContents mAwContents; 19 20 @Override 21 public void setUp() throws Exception { 22 super.setUp(); 23 mContentsClient = new TestAwContentsClient(); 24 mAwContents = createAwTestContainerViewOnMainSync(mContentsClient).getAwContents(); 25 } 26 27 /** 28 * Test for b/6404375. Verify that the UA string doesn't contain 29 * two spaces before the Android build name. 30 */ 31 @SmallTest 32 @Feature({"AndroidWebView"}) 33 public void testNoExtraSpaceBeforeBuildName() throws Throwable { 34 getAwSettingsOnUiThread(mAwContents).setJavaScriptEnabled(true); 35 loadDataSync( 36 mAwContents, 37 mContentsClient.getOnPageFinishedHelper(), 38 // Spaces are replaced with underscores to avoid consecutive spaces compression. 39 "<html>" + 40 "<body onload='document.title=navigator.userAgent.replace(/ /g, \"_\")'></body>" + 41 "</html>", 42 "text/html", false); 43 final String ua = getTitleOnUiThread(mAwContents); 44 Matcher matcher = Pattern.compile("Android_[^;]+;_[^_]").matcher(ua); 45 assertTrue(matcher.find()); 46 } 47} 48