197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize/* 297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Copyright (C) 2015 The Android Open Source Project 397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Licensed under the Apache License, Version 2.0 (the "License"); 597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * you may not use this file except in compliance with the License. 697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * You may obtain a copy of the License at 797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * http://www.apache.org/licenses/LICENSE-2.0 997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * 1097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Unless required by applicable law or agreed to in writing, software 1197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * distributed under the License is distributed on an "AS IS" BASIS, 1297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * See the License for the specific language governing permissions and 1497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * limitations under the License. 1597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 1697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 1797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizepackage android.support.customtabs; 1897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 1997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport android.content.Intent; 2097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport android.graphics.Color; 2197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizeimport android.test.AndroidTestCase; 2297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 2397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize/** 2497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Tests for CustomTabsIntent. 2597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */ 2697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lizepublic class CustomTabsIntentTest extends AndroidTestCase { 2797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 2897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public void testBareboneCustomTabIntent() { 2997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build(); 3097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize Intent intent = customTabsIntent.intent; 3197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize assertNotNull(intent); 3297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize assertNull(customTabsIntent.startAnimationBundle); 3397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 3497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize assertEquals(Intent.ACTION_VIEW, intent.getAction()); 3597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize assertTrue(intent.hasExtra(CustomTabsIntent.EXTRA_SESSION)); 3697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize assertNull(intent.getExtras().getBinder(CustomTabsIntent.EXTRA_SESSION)); 3797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize assertNull(intent.getComponent()); 3897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 3997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 4097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public void testToolbarColor() { 4197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize int color = Color.RED; 4297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize Intent intent = new CustomTabsIntent.Builder().setToolbarColor(color).build().intent; 4397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize assertTrue(intent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR)); 4497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize assertEquals(color, intent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0)); 4597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 4697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize 4797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize public void testToolbarColorIsNotAResource() { 4897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize int colorId = android.R.color.background_dark; 4997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize int color = getContext().getResources().getColor(colorId); 5097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize Intent intent = new CustomTabsIntent.Builder().setToolbarColor(colorId).build().intent; 5197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize assertFalse("The color should not be a resource ID", 5297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize color == intent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0)); 5397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize intent = new CustomTabsIntent.Builder().setToolbarColor(color).build().intent; 5497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize assertEquals(color, intent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0)); 5597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize } 5697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize} 57