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.XWalkClient;
15 import org.xwalk.core.XWalkGeolocationPermissions;
16 import org.xwalk.core.XWalkView;
17 import org.xwalk.core.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().getContext(), getXWalkView());
46 private int mCalledCount = 0;
48 public void onGeolocationPermissionsShowPrompt(String origin,
49 XWalkGeolocationPermissions.Callback callback) {
50 // The origin is empty for data stream.
51 assertTrue(origin.isEmpty());
52 callback.invoke(origin, true, true);
56 public int getCalledCount() {
60 final TestWebChromeClient testWebChromeClient = new TestWebChromeClient();
61 setXWalkWebChromeClient(testWebChromeClient);
62 loadAssetFile("geolocation.html");
63 getInstrumentation().runOnMainSync(new Runnable() {
66 assertEquals(1, testWebChromeClient.getCalledCount());
71 // This is not used now. Need a TODO to follow up this.
72 // TODO(hengzhi): how to verify it automaticly.
74 // @Feature({"GeolocationPermission"})
76 public void testGeolocationPermissionHidePrompt() throws Throwable {
77 class TestWebChromeClient extends XWalkWebChromeClient {
78 public TestWebChromeClient() {
79 super(getXWalkView().getContext(), getXWalkView());
83 public void onGeolocationPermissionsHidePrompt() {
87 setXWalkWebChromeClient(new TestWebChromeClient());
88 loadUrlSync("http://html5demos.com/geo");