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

COVERAGE SUMMARY FOR SOURCE FILE [AwShellActivity.java]

nameclass, %method, %block, %line, %
AwShellActivity.java0%   (0/6)0%   (0/22)0%   (0/341)0%   (0/61)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AwShellActivity0%   (0/1)0%   (0/12)0%   (0/201)0%   (0/39)
AwShellActivity (): void 0%   (0/1)0%   (0/3)0%   (0/1)
access$000 (AwShellActivity): EditText 0%   (0/1)0%   (0/3)0%   (0/1)
access$100 (AwShellActivity): AwTestContainerView 0%   (0/1)0%   (0/3)0%   (0/1)
access$200 (AwShellActivity, boolean): void 0%   (0/1)0%   (0/4)0%   (0/1)
access$300 (AwShellActivity): ImageButton 0%   (0/1)0%   (0/3)0%   (0/1)
access$400 (AwShellActivity): ImageButton 0%   (0/1)0%   (0/3)0%   (0/1)
createAwTestContainerView (): AwTestContainerView 0%   (0/1)0%   (0/47)0%   (0/8)
getUrlFromIntent (Intent): String 0%   (0/1)0%   (0/7)0%   (0/1)
initializeNavigationButtons (): void 0%   (0/1)0%   (0/27)0%   (0/5)
initializeUrlField (): void 0%   (0/1)0%   (0/21)0%   (0/4)
onCreate (Bundle): void 0%   (0/1)0%   (0/58)0%   (0/15)
setKeyboardVisibilityForUrl (boolean): void 0%   (0/1)0%   (0/22)0%   (0/5)
     
class AwShellActivity$10%   (0/1)0%   (0/2)0%   (0/16)0%   (0/4)
AwShellActivity$1 (AwShellActivity): void 0%   (0/1)0%   (0/6)0%   (0/1)
onPageStarted (String): void 0%   (0/1)0%   (0/10)0%   (0/3)
     
class AwShellActivity$20%   (0/1)0%   (0/2)0%   (0/48)0%   (0/8)
AwShellActivity$2 (AwShellActivity): void 0%   (0/1)0%   (0/6)0%   (0/1)
onEditorAction (TextView, int, KeyEvent): boolean 0%   (0/1)0%   (0/42)0%   (0/7)
     
class AwShellActivity$30%   (0/1)0%   (0/2)0%   (0/40)0%   (0/7)
AwShellActivity$3 (AwShellActivity): void 0%   (0/1)0%   (0/6)0%   (0/1)
onFocusChange (View, boolean): void 0%   (0/1)0%   (0/34)0%   (0/6)
     
class AwShellActivity$40%   (0/1)0%   (0/2)0%   (0/18)0%   (0/4)
AwShellActivity$4 (AwShellActivity): void 0%   (0/1)0%   (0/6)0%   (0/1)
onClick (View): void 0%   (0/1)0%   (0/12)0%   (0/3)
     
class AwShellActivity$50%   (0/1)0%   (0/2)0%   (0/18)0%   (0/4)
AwShellActivity$5 (AwShellActivity): void 0%   (0/1)0%   (0/6)0%   (0/1)
onClick (View): void 0%   (0/1)0%   (0/12)0%   (0/3)

1// Copyright (c) 2013 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.shell;
6 
7import android.app.Activity;
8import android.content.Intent;
9import android.content.Context;
10import android.content.SharedPreferences;
11import android.os.Bundle;
12import android.text.TextUtils;
13import android.util.Log;
14import android.view.KeyEvent;
15import android.view.View;
16import android.view.View.OnClickListener;
17import android.view.View.OnFocusChangeListener;
18import android.view.ViewGroup.LayoutParams;
19import android.view.WindowManager;
20import android.view.inputmethod.EditorInfo;
21import android.view.inputmethod.InputMethodManager;
22import android.widget.EditText;
23import android.widget.ImageButton;
24import android.widget.LinearLayout;
25import android.widget.TextView;
26import android.widget.TextView.OnEditorActionListener;
27 
28import org.chromium.android_webview.AwBrowserProcess;
29import org.chromium.android_webview.AwBrowserContext;
30import org.chromium.android_webview.AwContents;
31import org.chromium.android_webview.AwContentsClient;
32import org.chromium.android_webview.AwLayoutSizer;
33import org.chromium.android_webview.test.AwTestContainerView;
34import org.chromium.android_webview.test.NullContentsClient;
35import org.chromium.content.browser.LoadUrlParams;
36 
37/*
38 * This is a lightweight activity for tests that only require WebView functionality.
39 */
40public class AwShellActivity extends Activity {
41    private final static String PREFERENCES_NAME = "AwShellPrefs";
42    private final static String INITIAL_URL = "about:blank";
43    private AwBrowserContext mBrowserContext;
44    private AwTestContainerView mAwTestContainerView;
45    private EditText mUrlTextView;
46    private ImageButton mPrevButton;
47    private ImageButton mNextButton;
48 
49    @Override
50    public void onCreate(Bundle savedInstanceState) {
51        super.onCreate(savedInstanceState);
52 
53        setContentView(R.layout.testshell_activity);
54 
55        mAwTestContainerView = createAwTestContainerView();
56 
57        LinearLayout contentContainer = (LinearLayout) findViewById(R.id.content_container);
58        mAwTestContainerView.setLayoutParams(new LinearLayout.LayoutParams(
59                LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f));
60        contentContainer.addView(mAwTestContainerView);
61        mAwTestContainerView.requestFocus();
62 
63        initializeUrlField();
64        initializeNavigationButtons();
65 
66        String startupUrl = getUrlFromIntent(getIntent());
67        if (TextUtils.isEmpty(startupUrl)) {
68            startupUrl = INITIAL_URL;
69        }
70 
71        mAwTestContainerView.getAwContents().loadUrl(new LoadUrlParams(startupUrl));
72        mUrlTextView.setText(startupUrl);
73    }
74 
75    private AwTestContainerView createAwTestContainerView() {
76        AwTestContainerView testContainerView = new AwTestContainerView(this);
77        AwContentsClient awContentsClient = new NullContentsClient() {
78            @Override
79            public void onPageStarted(String url) {
80                if (mUrlTextView != null) {
81                    mUrlTextView.setText(url);
82                }
83            }
84        };
85 
86        SharedPreferences sharedPreferences =
87            getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE);
88        if (mBrowserContext == null) {
89            mBrowserContext = new AwBrowserContext(sharedPreferences);
90        }
91        testContainerView.initialize(new AwContents(mBrowserContext, testContainerView,
92                testContainerView.getInternalAccessDelegate(),
93                awContentsClient, false, new AwLayoutSizer(), true));
94        testContainerView.getAwContents().getSettings().setJavaScriptEnabled(true);
95        return testContainerView;
96    }
97 
98    private static String getUrlFromIntent(Intent intent) {
99        return intent != null ? intent.getDataString() : null;
100    }
101 
102    private void setKeyboardVisibilityForUrl(boolean visible) {
103        InputMethodManager imm = (InputMethodManager) getSystemService(
104                Context.INPUT_METHOD_SERVICE);
105        if (visible) {
106            imm.showSoftInput(mUrlTextView, InputMethodManager.SHOW_IMPLICIT);
107        } else {
108            imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0);
109        }
110    }
111 
112    private void initializeUrlField() {
113        mUrlTextView = (EditText) findViewById(R.id.url);
114        mUrlTextView.setOnEditorActionListener(new OnEditorActionListener() {
115            @Override
116            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
117                if ((actionId != EditorInfo.IME_ACTION_GO) && (event == null ||
118                        event.getKeyCode() != KeyEvent.KEYCODE_ENTER ||
119                        event.getKeyCode() != KeyEvent.ACTION_DOWN)) {
120                    return false;
121                }
122 
123                mAwTestContainerView.getAwContents().loadUrl(
124                        new LoadUrlParams(mUrlTextView.getText().toString()));
125                mUrlTextView.clearFocus();
126                setKeyboardVisibilityForUrl(false);
127                mAwTestContainerView.requestFocus();
128                return true;
129            }
130        });
131        mUrlTextView.setOnFocusChangeListener(new OnFocusChangeListener() {
132            @Override
133            public void onFocusChange(View v, boolean hasFocus) {
134                setKeyboardVisibilityForUrl(hasFocus);
135                mNextButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
136                mPrevButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
137                if (!hasFocus) {
138                    mUrlTextView.setText(mAwTestContainerView.getContentViewCore().getUrl());
139                }
140            }
141        });
142    }
143 
144    private void initializeNavigationButtons() {
145        mPrevButton = (ImageButton) findViewById(R.id.prev);
146        mPrevButton.setOnClickListener(new OnClickListener() {
147            @Override
148            public void onClick(View v) {
149                if (mAwTestContainerView.getContentViewCore().canGoBack()) {
150                    mAwTestContainerView.getContentViewCore().goBack();
151                }
152            }
153        });
154 
155        mNextButton = (ImageButton) findViewById(R.id.next);
156        mNextButton.setOnClickListener(new OnClickListener() {
157            @Override
158            public void onClick(View v) {
159                if (mAwTestContainerView.getContentViewCore().canGoForward()) {
160                        mAwTestContainerView.getContentViewCore().goForward();
161                }
162            }
163        });
164    }
165}

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