1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | package org.chromium.android_webview.test.util; |
6 | |
7 | import android.webkit.ValueCallback; |
8 | |
9 | import org.chromium.android_webview.AwQuotaManagerBridge; |
10 | import org.chromium.android_webview.test.AwTestBase; |
11 | import org.chromium.content.browser.test.util.CallbackHelper; |
12 | |
13 | import java.util.concurrent.Callable; |
14 | |
15 | /** |
16 | * This class provides common methods for AwQuotaManagerBridge related tests |
17 | */ |
18 | public class AwQuotaManagerBridgeTestUtil { |
19 | |
20 | public static AwQuotaManagerBridge getQuotaManagerBridge(AwTestBase awTestBase) |
21 | throws Exception { |
22 | return awTestBase.runTestOnUiThreadAndGetResult(new Callable<AwQuotaManagerBridge>() { |
23 | @Override |
24 | public AwQuotaManagerBridge call() throws Exception { |
25 | return AwQuotaManagerBridge.getInstance(); |
26 | } |
27 | }); |
28 | } |
29 | |
30 | private static class GetOriginsCallbackHelper extends CallbackHelper { |
31 | private AwQuotaManagerBridge.Origins mOrigins; |
32 | |
33 | public void notifyCalled(AwQuotaManagerBridge.Origins origins) { |
34 | mOrigins = origins; |
35 | notifyCalled(); |
36 | } |
37 | |
38 | public AwQuotaManagerBridge.Origins getOrigins() { |
39 | assert getCallCount() > 0; |
40 | return mOrigins; |
41 | } |
42 | } |
43 | |
44 | public static AwQuotaManagerBridge.Origins getOrigins(AwTestBase awTestBase) |
45 | throws Exception { |
46 | final GetOriginsCallbackHelper callbackHelper = new GetOriginsCallbackHelper(); |
47 | final AwQuotaManagerBridge bridge = getQuotaManagerBridge(awTestBase); |
48 | |
49 | int callCount = callbackHelper.getCallCount(); |
50 | awTestBase.getInstrumentation().runOnMainSync(new Runnable() { |
51 | @Override |
52 | public void run() { |
53 | bridge.getOrigins( |
54 | new ValueCallback<AwQuotaManagerBridge.Origins>() { |
55 | @Override |
56 | public void onReceiveValue(AwQuotaManagerBridge.Origins origins) { |
57 | callbackHelper.notifyCalled(origins); |
58 | } |
59 | } |
60 | ); |
61 | } |
62 | }); |
63 | callbackHelper.waitForCallback(callCount); |
64 | |
65 | return callbackHelper.getOrigins(); |
66 | } |
67 | |
68 | } |