1 /* 2 * Copyright (C) 2015 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 package com.android.messaging.ui; 17 18 import android.support.v4.view.ViewPager; 19 import android.view.View; 20 import android.view.ViewGroup; 21 import android.widget.SimpleCursorAdapter; 22 23 import com.android.messaging.FakeFactory; 24 import com.android.messaging.R; 25 26 public class CustomHeaderViewPagerTest extends ViewTest<CustomHeaderViewPager> { 27 28 @Override setUp()29 protected void setUp() throws Exception { 30 super.setUp(); 31 FakeFactory.register(getInstrumentation().getTargetContext()); 32 } 33 testBindFirstLevel()34 public void testBindFirstLevel() { 35 final CustomHeaderViewPager view = new CustomHeaderViewPager(getActivity(), null); 36 final SimpleCursorAdapter adapter = 37 new SimpleCursorAdapter(getActivity(), 0, null, null, null, 0); 38 final CustomHeaderPagerViewHolder[] viewHolders = { 39 new FakeListViewHolder(getActivity(), adapter), 40 new FakeListViewHolder(getActivity(), adapter) 41 }; 42 43 view.setViewHolders(viewHolders); 44 final ViewPager pager = (ViewPager) view.findViewById(R.id.pager); 45 final ViewGroup tabStrip = (ViewGroup) view.findViewById(R.id.tab_strip); 46 final ViewPagerTabStrip realTab = (ViewPagerTabStrip) tabStrip.getChildAt(0); 47 48 assertEquals(2, realTab.getChildCount()); 49 View headerTitleButton = realTab.getChildAt(1); 50 // Click on the first page. Now the view pager should switch to that page accordingly. 51 clickButton(headerTitleButton); 52 assertEquals(1, pager.getCurrentItem()); 53 } 54 55 @Override getLayoutIdForView()56 protected int getLayoutIdForView() { 57 // All set up should be done by creating a CustomHeaderViewPager which handles inflating 58 // the layout 59 return 0; 60 } 61 } 62