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;
21f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikovimport android.os.Build;
22f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikovimport android.support.annotation.ColorRes;
23f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikovimport android.support.test.InstrumentationRegistry;
24f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikovimport android.support.test.runner.AndroidJUnit4;
25daea069fe33cc750bcb733ebcb6206d2dcedae76Chris Banesimport android.test.suitebuilder.annotation.SmallTest;
26f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikovimport org.junit.Test;
27f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikovimport org.junit.runner.RunWith;
28f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikov
29f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikovimport static org.junit.Assert.*;
3097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
3197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize/**
3297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize * Tests for CustomTabsIntent.
3397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize */
34f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikov@RunWith(AndroidJUnit4.class)
35daea069fe33cc750bcb733ebcb6206d2dcedae76Chris Banes@SmallTest
36f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikovpublic class CustomTabsIntentTest {
37f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikov    @Test
3897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    public void testBareboneCustomTabIntent() {
3997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
4097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        Intent intent = customTabsIntent.intent;
4197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        assertNotNull(intent);
4297ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        assertNull(customTabsIntent.startAnimationBundle);
4397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
4497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        assertEquals(Intent.ACTION_VIEW, intent.getAction());
4597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        assertTrue(intent.hasExtra(CustomTabsIntent.EXTRA_SESSION));
46f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikov        if (Build.VERSION.SDK_INT >= 18) {
47f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikov            assertNull(intent.getExtras().getBinder(CustomTabsIntent.EXTRA_SESSION));
48f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikov        }
4997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        assertNull(intent.getComponent());
5097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    }
5197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
52f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikov    @Test
5397ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    public void testToolbarColor() {
5497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        int color = Color.RED;
5597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        Intent intent = new CustomTabsIntent.Builder().setToolbarColor(color).build().intent;
5697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        assertTrue(intent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR));
5797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        assertEquals(color, intent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0));
5897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    }
5997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize
60f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikov    @Test
6197ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    public void testToolbarColorIsNotAResource() {
62f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikov        @ColorRes int colorId = android.R.color.background_dark;
63f8b9ac80a1e0b4e5e816b2ca3e9fd418b419d739Kirill Grouchnikov        int color = InstrumentationRegistry.getContext().getResources().getColor(colorId);
6497ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        Intent intent = new CustomTabsIntent.Builder().setToolbarColor(colorId).build().intent;
6597ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        assertFalse("The color should not be a resource ID",
6697ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize                color == intent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0));
6797ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        intent = new CustomTabsIntent.Builder().setToolbarColor(color).build().intent;
6897ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize        assertEquals(color, intent.getIntExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR, 0));
6997ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize    }
7097ee4f3f353309991efd3ceca369548b485e9a5fBenoit Lize}
71