1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright (c) 2013-2014 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 package org.xwalk.core.xwview.test;
8 import android.graphics.Bitmap;
9 import android.test.suitebuilder.annotation.SmallTest;
10 import android.util.Log;
12 import org.chromium.base.test.util.DisabledTest;
13 import org.chromium.base.test.util.Feature;
14 import org.xwalk.core.XWalkView;
15 import org.xwalk.core.internal.XWalkClient;
16 import org.xwalk.core.internal.XWalkGeolocationPermissions;
17 import org.xwalk.core.internal.XWalkWebChromeClient;
20 * Test suite for onGeolocationPermissionsShowPrompt() and
21 * onGeolocationPermissionsHidePrompt().
23 public class GeolocationPermissionTest extends XWalkViewTestBase {
25 public void setUp() throws Exception {
28 setXWalkClient(new XWalkViewTestBase.TestXWalkClient());
29 getInstrumentation().runOnMainSync(new Runnable() {
32 getXWalkView().getSettings().setJavaScriptEnabled(true);
33 getXWalkView().getSettings().setGeolocationEnabled(true);
39 @Feature({"GeolocationPermission"})
40 public void testGeolocationPermissionShowPrompt() throws Throwable {
41 class TestWebChromeClient extends XWalkWebChromeClient {
42 public TestWebChromeClient() {
43 super(getXWalkView());
46 private int mCalledCount = 0;
49 public void onGeolocationPermissionsShowPrompt(String origin,
50 XWalkGeolocationPermissions.Callback callback) {
51 // The origin is empty for data stream.
52 assertTrue(origin.isEmpty());
53 callback.invoke(origin, true, true);
57 public int getCalledCount() {
61 final TestWebChromeClient testWebChromeClient = new TestWebChromeClient();
62 setXWalkWebChromeClient(testWebChromeClient);
63 loadAssetFile("geolocation.html");
64 getInstrumentation().runOnMainSync(new Runnable() {
67 assertEquals(1, testWebChromeClient.getCalledCount());
72 // This is not used now. Need a TODO to follow up this.
73 // TODO(hengzhi): how to verify it automaticly.
75 // @Feature({"GeolocationPermission"})
77 public void testGeolocationPermissionHidePrompt() throws Throwable {
78 class TestWebChromeClient extends XWalkWebChromeClient {
79 public TestWebChromeClient() {
80 super(getXWalkView());
84 public void onGeolocationPermissionsHidePrompt() {
88 setXWalkWebChromeClient(new TestWebChromeClient());
89 loadUrlSync("http://html5demos.com/geo");