3a31d413e46bea42626225ab4892cbd8063fb53e
[platform/framework/web/crosswalk.git] / src / xwalk / test / android / core / javatests / src / org / xwalk / core / xwview / test / GeolocationPermissionTest.java
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.
5
6 package org.xwalk.core.xwview.test;
7
8 import android.graphics.Bitmap;
9 import android.test.suitebuilder.annotation.SmallTest;
10 import android.util.Log;
11
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;
18
19 /**
20  * Test suite for onGeolocationPermissionsShowPrompt() and
21  *                onGeolocationPermissionsHidePrompt().
22  */
23 public class GeolocationPermissionTest extends XWalkViewTestBase {
24     @Override
25     public void setUp() throws Exception {
26         super.setUp();
27
28         setXWalkClient(new XWalkViewTestBase.TestXWalkClient());
29         getInstrumentation().runOnMainSync(new Runnable() {
30             @Override
31             public void run() {
32                 getXWalkView().getSettings().setJavaScriptEnabled(true);
33                 getXWalkView().getSettings().setGeolocationEnabled(true);
34             }
35         });
36     }
37
38     @SmallTest
39     @Feature({"GeolocationPermission"})
40     public void testGeolocationPermissionShowPrompt() throws Throwable {
41         class TestWebChromeClient extends XWalkWebChromeClient {
42             public TestWebChromeClient() {
43                 super(getXWalkView().getContext(), getXWalkView());
44             }
45
46             private int mCalledCount = 0;
47             @Override
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);
53                 mCalledCount++;
54             }
55
56             public int getCalledCount() {
57                 return mCalledCount;
58             }
59         }
60         final TestWebChromeClient testWebChromeClient = new TestWebChromeClient();
61         setXWalkWebChromeClient(testWebChromeClient);
62         loadAssetFile("geolocation.html");
63         getInstrumentation().runOnMainSync(new Runnable() {
64             @Override
65             public void run() {
66                 assertEquals(1, testWebChromeClient.getCalledCount());
67             }
68         });
69     }
70
71     // This is not used now. Need a TODO to follow up this.
72     // TODO(hengzhi): how to verify it automaticly.
73     // @SmallTest
74     // @Feature({"GeolocationPermission"})
75     @DisabledTest
76     public void testGeolocationPermissionHidePrompt() throws Throwable {
77         class TestWebChromeClient extends XWalkWebChromeClient {
78             public TestWebChromeClient() {
79                 super(getXWalkView().getContext(), getXWalkView());
80             }
81
82             @Override
83             public void onGeolocationPermissionsHidePrompt() {
84                 // Do something.
85             }
86         }
87         setXWalkWebChromeClient(new TestWebChromeClient());
88         loadUrlSync("http://html5demos.com/geo");
89     }
90 }