Upstream version 8.36.161.0
[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.XWalkView;
15 import org.xwalk.core.internal.XWalkClient;
16 import org.xwalk.core.internal.XWalkGeolocationPermissions;
17 import org.xwalk.core.internal.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());
44             }
45
46             private int mCalledCount = 0;
47
48             @Override
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);
54                 mCalledCount++;
55             }
56
57             public int getCalledCount() {
58                 return mCalledCount;
59             }
60         }
61         final TestWebChromeClient testWebChromeClient = new TestWebChromeClient();
62         setXWalkWebChromeClient(testWebChromeClient);
63         loadAssetFile("geolocation.html");
64         getInstrumentation().runOnMainSync(new Runnable() {
65             @Override
66             public void run() {
67                 assertEquals(1, testWebChromeClient.getCalledCount());
68             }
69         });
70     }
71
72     // This is not used now. Need a TODO to follow up this.
73     // TODO(hengzhi): how to verify it automaticly.
74     // @SmallTest
75     // @Feature({"GeolocationPermission"})
76     @DisabledTest
77     public void testGeolocationPermissionHidePrompt() throws Throwable {
78         class TestWebChromeClient extends XWalkWebChromeClient {
79             public TestWebChromeClient() {
80                 super(getXWalkView());
81             }
82
83             @Override
84             public void onGeolocationPermissionsHidePrompt() {
85                 // Do something.
86             }
87         }
88         setXWalkWebChromeClient(new TestWebChromeClient());
89         loadUrlSync("http://html5demos.com/geo");
90     }
91 }