• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.support.customtabs;
18 
19 import android.net.Uri;
20 import android.os.Bundle;
21 
22 import java.util.List;
23 
24 /**
25  * A test class that simulates how a {@link CustomTabsService} would behave.
26  */
27 
28 public class TestCustomTabsService extends CustomTabsService {
29     public static final String CALLBACK_BIND_TO_POST_MESSAGE = "BindToPostMessageService";
30     private boolean mPostMessageRequested;
31     private CustomTabsSessionToken mSession;
32 
33     @Override
warmup(long flags)34     protected boolean warmup(long flags) {
35         return false;
36     }
37 
38     @Override
newSession(CustomTabsSessionToken sessionToken)39     protected boolean newSession(CustomTabsSessionToken sessionToken) {
40         mSession = sessionToken;
41         return true;
42     }
43 
44     @Override
mayLaunchUrl(CustomTabsSessionToken sessionToken, Uri url, Bundle extras, List<Bundle> otherLikelyBundles)45     protected boolean mayLaunchUrl(CustomTabsSessionToken sessionToken,
46                                    Uri url, Bundle extras, List<Bundle> otherLikelyBundles) {
47         return false;
48     }
49 
50     @Override
extraCommand(String commandName, Bundle args)51     protected Bundle extraCommand(String commandName, Bundle args) {
52         return null;
53     }
54 
55     @Override
updateVisuals(CustomTabsSessionToken sessionToken, Bundle bundle)56     protected boolean updateVisuals(CustomTabsSessionToken sessionToken, Bundle bundle) {
57         return false;
58     }
59 
60     @Override
requestPostMessageChannel( CustomTabsSessionToken sessionToken, Uri postMessageOrigin)61     protected boolean requestPostMessageChannel(
62             CustomTabsSessionToken sessionToken, Uri postMessageOrigin) {
63         if (mSession == null) return false;
64         mPostMessageRequested = true;
65         mSession.getCallback().extraCallback(CALLBACK_BIND_TO_POST_MESSAGE, null);
66         return true;
67     }
68 
69     @Override
postMessage(CustomTabsSessionToken sessionToken, String message, Bundle extras)70     protected int postMessage(CustomTabsSessionToken sessionToken, String message, Bundle extras) {
71         if (!mPostMessageRequested) return CustomTabsService.RESULT_FAILURE_DISALLOWED;
72         return CustomTabsService.RESULT_SUCCESS;
73     }
74 }
75