| OLD | NEW |
| 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.content.Context; | 7 import android.content.Context; |
| 8 import android.graphics.Point; | 8 import android.graphics.Point; |
| 9 import android.os.Build; | 9 import android.os.Build; |
| 10 import android.os.SystemClock; | 10 import android.os.SystemClock; |
| 11 import android.test.suitebuilder.annotation.LargeTest; | 11 import android.test.suitebuilder.annotation.LargeTest; |
| 12 import android.test.suitebuilder.annotation.MediumTest; | 12 import android.test.suitebuilder.annotation.MediumTest; |
| 13 import android.test.suitebuilder.annotation.SmallTest; | 13 import android.test.suitebuilder.annotation.SmallTest; |
| 14 import android.util.Pair; | 14 import android.util.Pair; |
| 15 import android.view.MotionEvent; | 15 import android.view.MotionEvent; |
| 16 import android.view.WindowManager; | 16 import android.view.WindowManager; |
| 17 import android.webkit.JavascriptInterface; |
| 17 import android.webkit.WebSettings; | 18 import android.webkit.WebSettings; |
| 18 | 19 |
| 19 import org.apache.http.Header; | 20 import org.apache.http.Header; |
| 20 import org.apache.http.HttpRequest; | 21 import org.apache.http.HttpRequest; |
| 21 import org.chromium.android_webview.AndroidProtocolHandler; | 22 import org.chromium.android_webview.AndroidProtocolHandler; |
| 22 import org.chromium.android_webview.AwContents; | 23 import org.chromium.android_webview.AwContents; |
| 23 import org.chromium.android_webview.AwSettings.LayoutAlgorithm; | 24 import org.chromium.android_webview.AwSettings.LayoutAlgorithm; |
| 24 import org.chromium.android_webview.AwSettings; | 25 import org.chromium.android_webview.AwSettings; |
| 25 import org.chromium.android_webview.InterceptedRequestData; | 26 import org.chromium.android_webview.InterceptedRequestData; |
| 26 import org.chromium.android_webview.test.util.CommonResources; | 27 import org.chromium.android_webview.test.util.CommonResources; |
| (...skipping 1891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 contentClient.getOnPageFinishedHelper(), | 1919 contentClient.getOnPageFinishedHelper(), |
| 1919 "file:///" + fileName); | 1920 "file:///" + fileName); |
| 1920 assertEquals(1, webServer.getRequestCount(httpPath)); | 1921 assertEquals(1, webServer.getRequestCount(httpPath)); |
| 1921 assertEquals("img_onload_fired", getTitleOnUiThread(awContents)); | 1922 assertEquals("img_onload_fired", getTitleOnUiThread(awContents)); |
| 1922 } finally { | 1923 } finally { |
| 1923 if (fileName != null) TestFileUtil.deleteFile(fileName); | 1924 if (fileName != null) TestFileUtil.deleteFile(fileName); |
| 1924 if (webServer != null) webServer.shutdown(); | 1925 if (webServer != null) webServer.shutdown(); |
| 1925 } | 1926 } |
| 1926 } | 1927 } |
| 1927 | 1928 |
| 1929 public static class AudioEvent { |
| 1930 private CallbackHelper mCallback; |
| 1931 public AudioEvent(CallbackHelper callback) { |
| 1932 mCallback = callback; |
| 1933 } |
| 1934 |
| 1935 @JavascriptInterface |
| 1936 public void onCanPlay() { |
| 1937 mCallback.notifyCalled(); |
| 1938 } |
| 1939 |
| 1940 @JavascriptInterface |
| 1941 public void onError() { |
| 1942 mCallback.notifyCalled(); |
| 1943 } |
| 1944 } |
| 1945 |
| 1946 @SmallTest |
| 1947 @Feature({"AndroidWebView", "Preferences"}) |
| 1948 public void testBlockNetworkLoadsWithAudio() throws Throwable { |
| 1949 final TestAwContentsClient contentClient = new TestAwContentsClient(); |
| 1950 final AwTestContainerView testContainer = |
| 1951 createAwTestContainerViewOnMainSync(contentClient); |
| 1952 final AwContents awContents = testContainer.getAwContents(); |
| 1953 final AwSettings awSettings = getAwSettingsOnUiThread(awContents); |
| 1954 CallbackHelper callback = new CallbackHelper(); |
| 1955 awSettings.setJavaScriptEnabled(true); |
| 1956 |
| 1957 TestWebServer webServer = null; |
| 1958 try { |
| 1959 webServer = new TestWebServer(false); |
| 1960 final String httpPath = "/audio.mp3"; |
| 1961 // Don't care about the response is correct or not, just want |
| 1962 // to know whether Url is accessed. |
| 1963 final String audioUrl = webServer.setResponse(httpPath, "1", null); |
| 1964 |
| 1965 String pageHtml ="<html><body><audio controls src='" + audioUrl + "'
" + |
| 1966 "oncanplay=\"AudioEvent.onCanPlay();\" " + |
| 1967 "onerror=\"AudioEvent.onError();\" /> </body></html>"; |
| 1968 // Actual test. Blocking should trigger onerror handler. |
| 1969 awSettings.setBlockNetworkLoads(true); |
| 1970 awContents.addPossiblyUnsafeJavascriptInterface( |
| 1971 new AudioEvent(callback), "AudioEvent", null); |
| 1972 int count = callback.getCallCount(); |
| 1973 loadDataSync(awContents, contentClient.getOnPageFinishedHelper(), pa
geHtml, |
| 1974 "text/html", false); |
| 1975 callback.waitForCallback(count, 1); |
| 1976 assertEquals(0, webServer.getRequestCount(httpPath)); |
| 1977 |
| 1978 // Unblock should load normally. |
| 1979 awSettings.setBlockNetworkLoads(false); |
| 1980 count = callback.getCallCount(); |
| 1981 loadDataSync(awContents, contentClient.getOnPageFinishedHelper(), pa
geHtml, |
| 1982 "text/html", false); |
| 1983 callback.waitForCallback(count, 1); |
| 1984 assertTrue(0 != webServer.getRequestCount(httpPath)); |
| 1985 } finally { |
| 1986 if (webServer != null) webServer.shutdown(); |
| 1987 } |
| 1988 } |
| 1989 |
| 1928 // Test an assert URL (file:///android_asset/) | 1990 // Test an assert URL (file:///android_asset/) |
| 1929 @SmallTest | 1991 @SmallTest |
| 1930 @Feature({"AndroidWebView", "Navigation"}) | 1992 @Feature({"AndroidWebView", "Navigation"}) |
| 1931 public void testAssetUrl() throws Throwable { | 1993 public void testAssetUrl() throws Throwable { |
| 1932 // Note: this text needs to be kept in sync with the contents of the htm
l file referenced | 1994 // Note: this text needs to be kept in sync with the contents of the htm
l file referenced |
| 1933 // below. | 1995 // below. |
| 1934 final String expectedTitle = "Asset File"; | 1996 final String expectedTitle = "Asset File"; |
| 1935 final TestAwContentsClient contentClient = new TestAwContentsClient(); | 1997 final TestAwContentsClient contentClient = new TestAwContentsClient(); |
| 1936 final AwTestContainerView testContainerView = | 1998 final AwTestContainerView testContainerView = |
| 1937 createAwTestContainerViewOnMainSync(contentClient); | 1999 createAwTestContainerViewOnMainSync(contentClient); |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2777 awContents.onTouchEvent(MotionEvent.obtain( | 2839 awContents.onTouchEvent(MotionEvent.obtain( |
| 2778 secondTapTime, secondTapTime, MotionEvent.ACTION_DOWN, | 2840 secondTapTime, secondTapTime, MotionEvent.ACTION_DOWN, |
| 2779 x, y, 0)); | 2841 x, y, 0)); |
| 2780 awContents.onTouchEvent(MotionEvent.obtain( | 2842 awContents.onTouchEvent(MotionEvent.obtain( |
| 2781 secondTapTime, secondTapTime, MotionEvent.ACTION_UP, | 2843 secondTapTime, secondTapTime, MotionEvent.ACTION_UP, |
| 2782 x, y, 0)); | 2844 x, y, 0)); |
| 2783 } | 2845 } |
| 2784 }); | 2846 }); |
| 2785 } | 2847 } |
| 2786 } | 2848 } |
| OLD | NEW |