| /* |
| * Copyright (C) 2015 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package android.support.customtabs; |
| |
| import android.content.Intent; |
| import android.graphics.Color; |
| import android.test.AndroidTestCase; |
| |
| /** |
| * Tests for CustomTabsIntent. |
| */ |
| public class CustomTabsIntentTest extends AndroidTestCase { |
| |
| public void testBareboneCustomTabIntent() { |
| CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build(); |
| Intent intent = customTabsIntent.intent; |
| assertNotNull(intent); |
| assertNull(customTabsIntent.startAnimationBundle); |
| |
| assertEquals(Intent.ACTION_VIEW, intent.getAction()); |
| assertTrue(intent.hasExtra(CustomTabsIntent.EXTRA_SESSION)); |
| assertNull(intent.getExtras().getBinder(CustomTabsIntent.EXTRA_SESSION)); |
| assertNull(intent.getComponent()); |
| } |
| |
| public void testToolbarColor() { |
| int color = Color.RED; |
| Intent intent = new CustomTabsIntent.Builder().setToolbarColor(color).build().intent; |
| assertTrue(intent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR)); |
| assertEquals(color, intent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0)); |
| } |
| |
| public void testToolbarColorIsNotAResource() { |
| int colorId = android.R.color.background_dark; |
| int color = getContext().getResources().getColor(colorId); |
| Intent intent = new CustomTabsIntent.Builder().setToolbarColor(colorId).build().intent; |
| assertFalse("The color should not be a resource ID", |
| color == intent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0)); |
| intent = new CustomTabsIntent.Builder().setToolbarColor(color).build().intent; |
| assertEquals(color, intent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0)); |
| } |
| } |