EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.android_webview.test]

COVERAGE SUMMARY FOR SOURCE FILE [UserAgentTest.java]

nameclass, %method, %block, %line, %
UserAgentTest.java100% (1/1)100% (3/3)100% (48/48)100% (11/11)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class UserAgentTest100% (1/1)100% (3/3)100% (48/48)100% (11/11)
UserAgentTest (): void 100% (1/1)100% (3/3)100% (1/1)
setUp (): void 100% (1/1)100% (15/15)100% (4/4)
testNoExtraSpaceBeforeBuildName (): void 100% (1/1)100% (30/30)100% (6/6)

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
3// found in the LICENSE file.
4 
5package org.chromium.android_webview.test;
6 
7import android.test.suitebuilder.annotation.SmallTest;
8 
9import java.util.regex.Matcher;
10import java.util.regex.Pattern;
11 
12import org.chromium.android_webview.AwContents;
13import org.chromium.base.test.util.Feature;
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}

[all classes][org.chromium.android_webview.test]
EMMA 2.0.5312 (C) Vladimir Roubtsov