Merge "Adding CoordinatorLayout tests for scrolling / pinning tabs." into nyc-dev

GitOrigin-RevId=ecad73bf7dfd67a3a78b9610d76719b794926010

PiperOrigin-RevId: 140559957
This commit is contained in:
Kirill Grouchnikov 2016-11-30 03:51:52 +00:00 committed by Travis Collins
parent 19311ec2d4
commit 644452d2ce
9 changed files with 598 additions and 41 deletions

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.
-->
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/include_appbar_scrollview"/>
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.
-->
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways"
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/include_appbar_scrollview"/>
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 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.
-->
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_scrollFlags="scroll|enterAlways|snap"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:tabMode="scrollable"/>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/include_appbar_scrollview"/>
</android.support.design.widget.CoordinatorLayout>

View File

@ -31,5 +31,8 @@
<string name="design_appbar_collapsing_toolbar_pin">AppBar/Collapsing Toolbar (pinned)</string>
<string name="design_appbar_collapsing_toolbar_scroll">AppBar/Collapsing Toolbar (scroll off)</string>
<string name="design_appbar_collapsing_toolbar_pin_fab">AppBar/Collapsing Toolbar (pinned with FAB)</string>
<string name="design_appbar_toolbar_scroll_tabs_scroll">AppBar/Toolbar Scroll + Tabs Scroll</string>
<string name="design_appbar_toolbar_scroll_tabs_scroll_snap">AppBar/Toolbar Scroll + Tabs Scroll + Snap</string>
<string name="design_appbar_toolbar_scroll_tabs_pin">AppBar/Toolbar Scroll + Tabs Pin</string>
</resources>

View File

@ -0,0 +1,154 @@
/*
* Copyright (C) 2016 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.design.testutils;
public class Cheeses {
public static final String[] sCheeseStrings = {
"Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale",
"Aisy Cendre", "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese",
"Ami du Chambertin", "Anejo Enchilado", "Anneau du Vic-Bilh", "Anthoriro", "Appenzell",
"Aragon", "Ardi Gasna", "Ardrahan", "Armenian String", "Aromes au Gene de Marc",
"Asadero", "Asiago", "Aubisque Pyrenees", "Autun", "Avaxtskyr", "Baby Swiss",
"Babybel", "Baguette Laonnaise", "Bakers", "Baladi", "Balaton", "Bandal", "Banon",
"Barry's Bay Cheddar", "Basing", "Basket Cheese", "Bath Cheese", "Bavarian Bergkase",
"Baylough", "Beaufort", "Beauvoorde", "Beenleigh Blue", "Beer Cheese", "Bel Paese",
"Bergader", "Bergere Bleue", "Berkswell", "Beyaz Peynir", "Bierkase", "Bishop Kennedy",
"Blarney", "Bleu d'Auvergne", "Bleu de Gex", "Bleu de Laqueuille",
"Bleu de Septmoncel", "Bleu Des Causses", "Blue", "Blue Castello", "Blue Rathgore",
"Blue Vein (Australian)", "Blue Vein Cheeses", "Bocconcini", "Bocconcini (Australian)",
"Boeren Leidenkaas", "Bonchester", "Bosworth", "Bougon", "Boule Du Roves",
"Boulette d'Avesnes", "Boursault", "Boursin", "Bouyssou", "Bra", "Braudostur",
"Breakfast Cheese", "Brebis du Lavort", "Brebis du Lochois", "Brebis du Puyfaucon",
"Bresse Bleu", "Brick", "Brie", "Brie de Meaux", "Brie de Melun", "Brillat-Savarin",
"Brin", "Brin d' Amour", "Brin d'Amour", "Brinza (Burduf Brinza)",
"Briquette de Brebis", "Briquette du Forez", "Broccio", "Broccio Demi-Affine",
"Brousse du Rove", "Bruder Basil", "Brusselae Kaas (Fromage de Bruxelles)", "Bryndza",
"Buchette d'Anjou", "Buffalo", "Burgos", "Butte", "Butterkase", "Button (Innes)",
"Buxton Blue", "Cabecou", "Caboc", "Cabrales", "Cachaille", "Caciocavallo", "Caciotta",
"Caerphilly", "Cairnsmore", "Calenzana", "Cambazola", "Camembert de Normandie",
"Canadian Cheddar", "Canestrato", "Cantal", "Caprice des Dieux", "Capricorn Goat",
"Capriole Banon", "Carre de l'Est", "Casciotta di Urbino", "Cashel Blue", "Castellano",
"Castelleno", "Castelmagno", "Castelo Branco", "Castigliano", "Cathelain",
"Celtic Promise", "Cendre d'Olivet", "Cerney", "Chabichou", "Chabichou du Poitou",
"Chabis de Gatine", "Chaource", "Charolais", "Chaumes", "Cheddar",
"Cheddar Clothbound", "Cheshire", "Chevres", "Chevrotin des Aravis", "Chontaleno",
"Civray", "Coeur de Camembert au Calvados", "Coeur de Chevre", "Colby", "Cold Pack",
"Comte", "Coolea", "Cooleney", "Coquetdale", "Corleggy", "Cornish Pepper",
"Cotherstone", "Cotija", "Cottage Cheese", "Cottage Cheese (Australian)",
"Cougar Gold", "Coulommiers", "Coverdale", "Crayeux de Roncq", "Cream Cheese",
"Cream Havarti", "Crema Agria", "Crema Mexicana", "Creme Fraiche", "Crescenza",
"Croghan", "Crottin de Chavignol", "Crottin du Chavignol", "Crowdie", "Crowley",
"Cuajada", "Curd", "Cure Nantais", "Curworthy", "Cwmtawe Pecorino",
"Cypress Grove Chevre", "Danablu (Danish Blue)", "Danbo", "Danish Fontina",
"Daralagjazsky", "Dauphin", "Delice des Fiouves", "Denhany Dorset Drum", "Derby",
"Dessertnyj Belyj", "Devon Blue", "Devon Garland", "Dolcelatte", "Doolin",
"Doppelrhamstufel", "Dorset Blue Vinney", "Double Gloucester", "Double Worcester",
"Dreux a la Feuille", "Dry Jack", "Duddleswell", "Dunbarra", "Dunlop", "Dunsyre Blue",
"Duroblando", "Durrus", "Dutch Mimolette (Commissiekaas)", "Edam", "Edelpilz",
"Emental Grand Cru", "Emlett", "Emmental", "Epoisses de Bourgogne", "Esbareich",
"Esrom", "Etorki", "Evansdale Farmhouse Brie", "Evora De L'Alentejo", "Exmoor Blue",
"Explorateur", "Feta", "Feta (Australian)", "Figue", "Filetta", "Fin-de-Siecle",
"Finlandia Swiss", "Finn", "Fiore Sardo", "Fleur du Maquis", "Flor de Guia",
"Flower Marie", "Folded", "Folded cheese with mint", "Fondant de Brebis",
"Fontainebleau", "Fontal", "Fontina Val d'Aosta", "Formaggio di capra", "Fougerus",
"Four Herb Gouda", "Fourme d' Ambert", "Fourme de Haute Loire", "Fourme de Montbrison",
"Fresh Jack", "Fresh Mozzarella", "Fresh Ricotta", "Fresh Truffles", "Fribourgeois",
"Friesekaas", "Friesian", "Friesla", "Frinault", "Fromage a Raclette", "Fromage Corse",
"Fromage de Montagne de Savoie", "Fromage Frais", "Fruit Cream Cheese",
"Frying Cheese", "Fynbo", "Gabriel", "Galette du Paludier", "Galette Lyonnaise",
"Galloway Goat's Milk Gems", "Gammelost", "Gaperon a l'Ail", "Garrotxa", "Gastanberra",
"Geitost", "Gippsland Blue", "Gjetost", "Gloucester", "Golden Cross", "Gorgonzola",
"Gornyaltajski", "Gospel Green", "Gouda", "Goutu", "Gowrie", "Grabetto", "Graddost",
"Grafton Village Cheddar", "Grana", "Grana Padano", "Grand Vatel",
"Grataron d' Areches", "Gratte-Paille", "Graviera", "Greuilh", "Greve",
"Gris de Lille", "Gruyere", "Gubbeen", "Guerbigny", "Halloumi",
"Halloumy (Australian)", "Haloumi-Style Cheese", "Harbourne Blue", "Havarti",
"Heidi Gruyere", "Hereford Hop", "Herrgardsost", "Herriot Farmhouse", "Herve",
"Hipi Iti", "Hubbardston Blue Cow", "Hushallsost", "Iberico", "Idaho Goatster",
"Idiazabal", "Il Boschetto al Tartufo", "Ile d'Yeu", "Isle of Mull", "Jarlsberg",
"Jermi Tortes", "Jibneh Arabieh", "Jindi Brie", "Jubilee Blue", "Juustoleipa",
"Kadchgall", "Kaseri", "Kashta", "Kefalotyri", "Kenafa", "Kernhem", "Kervella Affine",
"Kikorangi", "King Island Cape Wickham Brie", "King River Gold", "Klosterkaese",
"Knockalara", "Kugelkase", "L'Aveyronnais", "L'Ecir de l'Aubrac", "La Taupiniere",
"La Vache Qui Rit", "Laguiole", "Lairobell", "Lajta", "Lanark Blue", "Lancashire",
"Langres", "Lappi", "Laruns", "Lavistown", "Le Brin", "Le Fium Orbo", "Le Lacandou",
"Le Roule", "Leafield", "Lebbene", "Leerdammer", "Leicester", "Leyden", "Limburger",
"Lincolnshire Poacher", "Lingot Saint Bousquet d'Orb", "Liptauer", "Little Rydings",
"Livarot", "Llanboidy", "Llanglofan Farmhouse", "Loch Arthur Farmhouse",
"Loddiswell Avondale", "Longhorn", "Lou Palou", "Lou Pevre", "Lyonnais", "Maasdam",
"Macconais", "Mahoe Aged Gouda", "Mahon", "Malvern", "Mamirolle", "Manchego",
"Manouri", "Manur", "Marble Cheddar", "Marbled Cheeses", "Maredsous", "Margotin",
"Maribo", "Maroilles", "Mascares", "Mascarpone", "Mascarpone (Australian)",
"Mascarpone Torta", "Matocq", "Maytag Blue", "Meira", "Menallack Farmhouse",
"Menonita", "Meredith Blue", "Mesost", "Metton (Cancoillotte)", "Meyer Vintage Gouda",
"Mihalic Peynir", "Milleens", "Mimolette", "Mine-Gabhar", "Mini Baby Bells", "Mixte",
"Molbo", "Monastery Cheeses", "Mondseer", "Mont D'or Lyonnais", "Montasio",
"Monterey Jack", "Monterey Jack Dry", "Morbier", "Morbier Cru de Montagne",
"Mothais a la Feuille", "Mozzarella", "Mozzarella (Australian)",
"Mozzarella di Bufala", "Mozzarella Fresh, in water", "Mozzarella Rolls", "Munster",
"Murol", "Mycella", "Myzithra", "Naboulsi", "Nantais", "Neufchatel",
"Neufchatel (Australian)", "Niolo", "Nokkelost", "Northumberland", "Oaxaca",
"Olde York", "Olivet au Foin", "Olivet Bleu", "Olivet Cendre",
"Orkney Extra Mature Cheddar", "Orla", "Oschtjepka", "Ossau Fermier", "Ossau-Iraty",
"Oszczypek", "Oxford Blue", "P'tit Berrichon", "Palet de Babligny", "Paneer", "Panela",
"Pannerone", "Pant ys Gawn", "Parmesan (Parmigiano)", "Parmigiano Reggiano",
"Pas de l'Escalette", "Passendale", "Pasteurized Processed", "Pate de Fromage",
"Patefine Fort", "Pave d'Affinois", "Pave d'Auge", "Pave de Chirac", "Pave du Berry",
"Pecorino", "Pecorino in Walnut Leaves", "Pecorino Romano", "Peekskill Pyramid",
"Pelardon des Cevennes", "Pelardon des Corbieres", "Penamellera", "Penbryn",
"Pencarreg", "Perail de Brebis", "Petit Morin", "Petit Pardou", "Petit-Suisse",
"Picodon de Chevre", "Picos de Europa", "Piora", "Pithtviers au Foin",
"Plateau de Herve", "Plymouth Cheese", "Podhalanski", "Poivre d'Ane", "Polkolbin",
"Pont l'Eveque", "Port Nicholson", "Port-Salut", "Postel", "Pouligny-Saint-Pierre",
"Pourly", "Prastost", "Pressato", "Prince-Jean", "Processed Cheddar", "Provolone",
"Provolone (Australian)", "Pyengana Cheddar", "Pyramide", "Quark",
"Quark (Australian)", "Quartirolo Lombardo", "Quatre-Vents", "Quercy Petit",
"Queso Blanco", "Queso Blanco con Frutas --Pina y Mango", "Queso de Murcia",
"Queso del Montsec", "Queso del Tietar", "Queso Fresco", "Queso Fresco (Adobera)",
"Queso Iberico", "Queso Jalapeno", "Queso Majorero", "Queso Media Luna",
"Queso Para Frier", "Queso Quesadilla", "Rabacal", "Raclette", "Ragusano", "Raschera",
"Reblochon", "Red Leicester", "Regal de la Dombes", "Reggianito", "Remedou",
"Requeson", "Richelieu", "Ricotta", "Ricotta (Australian)", "Ricotta Salata", "Ridder",
"Rigotte", "Rocamadour", "Rollot", "Romano", "Romans Part Dieu", "Roncal", "Roquefort",
"Roule", "Rouleau De Beaulieu", "Royalp Tilsit", "Rubens", "Rustinu", "Saaland Pfarr",
"Saanenkaese", "Saga", "Sage Derby", "Sainte Maure", "Saint-Marcellin",
"Saint-Nectaire", "Saint-Paulin", "Salers", "Samso", "San Simon", "Sancerre",
"Sap Sago", "Sardo", "Sardo Egyptian", "Sbrinz", "Scamorza", "Schabzieger", "Schloss",
"Selles sur Cher", "Selva", "Serat", "Seriously Strong Cheddar", "Serra da Estrela",
"Sharpam", "Shelburne Cheddar", "Shropshire Blue", "Siraz", "Sirene", "Smoked Gouda",
"Somerset Brie", "Sonoma Jack", "Sottocenare al Tartufo", "Soumaintrain",
"Sourire Lozerien", "Spenwood", "Sraffordshire Organic", "St. Agur Blue Cheese",
"Stilton", "Stinking Bishop", "String", "Sussex Slipcote", "Sveciaost", "Swaledale",
"Sweet Style Swiss", "Swiss", "Syrian (Armenian String)", "Tala", "Taleggio", "Tamie",
"Tasmania Highland Chevre Log", "Taupiniere", "Teifi", "Telemea", "Testouri",
"Tete de Moine", "Tetilla", "Texas Goat Cheese", "Tibet", "Tillamook Cheddar",
"Tilsit", "Timboon Brie", "Toma", "Tomme Brulee", "Tomme d'Abondance",
"Tomme de Chevre", "Tomme de Romans", "Tomme de Savoie", "Tomme des Chouans", "Tommes",
"Torta del Casar", "Toscanello", "Touree de L'Aubier", "Tourmalet",
"Trappe (Veritable)", "Trois Cornes De Vendee", "Tronchon", "Trou du Cru", "Truffe",
"Tupi", "Turunmaa", "Tymsboro", "Tyn Grug", "Tyning", "Ubriaco", "Ulloa",
"Vacherin-Fribourgeois", "Valencay", "Vasterbottenost", "Venaco", "Vendomois",
"Vieux Corse", "Vignotte", "Vulscombe", "Waimata Farmhouse Blue",
"Washed Rind Cheese (Australian)", "Waterloo", "Weichkaese", "Wellington",
"Wensleydale", "White Stilton", "Whitestone Farmhouse", "Wigmore", "Woodside Cabecou",
"Xanadu", "Xynotyro", "Yarg Cornish", "Yarra Valley Pyramid", "Yorkshire Blue",
"Zamorano", "Zanetti Grana Padano", "Zanetti Parmigiano Reggiano"
};
}

View File

@ -38,7 +38,7 @@ import static android.support.test.espresso.matcher.ViewMatchers.isDisplayingAtL
public class TestUtilsActions {
/**
* Replaces an existing <code>TabLayout</code> with a new one inflated from the specified
* Replaces an existing {@link TabLayout} with a new one inflated from the specified
* layout resource.
*/
public static ViewAction replaceTabLayout(final @LayoutRes int tabLayoutResId) {
@ -136,7 +136,7 @@ public class TestUtilsActions {
}
/**
* Sets text content on <code>TextView</code>.
* Sets text content on {@link TextView}
*/
public static ViewAction setText(final @Nullable CharSequence text) {
return new ViewAction() {
@ -161,4 +161,33 @@ public class TestUtilsActions {
}
};
}
/**
* Adds tabs to {@link TabLayout}
*/
public static ViewAction addTabs(final String... tabs) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isAssignableFrom(TabLayout.class);
}
@Override
public String getDescription() {
return "TabLayout add tabs";
}
@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadUntilIdle();
TabLayout tabLayout = (TabLayout) view;
for (int i = 0; i < tabs.length; i++) {
tabLayout.addTab(tabLayout.newTab().setText(tabs[i]));
}
uiController.loopMainThreadUntilIdle();
}
};
}
}

View File

@ -16,14 +16,21 @@
package android.support.design.widget;
import android.support.annotation.CallSuper;
import android.support.annotation.IdRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes;
import android.support.design.test.R;
import android.support.design.testutils.Shakespeare;
import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.action.CoordinatesProvider;
import android.support.test.espresso.action.GeneralSwipeAction;
import android.support.test.espresso.action.Press;
import android.support.test.espresso.action.Swipe;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import static android.support.design.testutils.TestUtilsActions.setText;
@ -41,6 +48,43 @@ public abstract class AppBarLayoutBaseTest extends BaseDynamicCoordinatorLayoutT
protected TextView mTextView;
protected static void performVerticalUpGesture(@IdRes int containerId, final int swipeX,
final int swipeStartY, final int swipeAmountY) {
onView(withId(containerId)).perform(new GeneralSwipeAction(
Swipe.SLOW,
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { swipeX, swipeStartY };
}
},
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { swipeX, swipeStartY - swipeAmountY };
}
}, Press.FINGER));
}
protected static void performVerticalSwipeDownGesture(@IdRes int containerId, final int swipeX,
final int swipeStartY, final int swipeAmountY) {
onView(withId(containerId)).perform(new GeneralSwipeAction(
Swipe.SLOW,
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { swipeX, swipeStartY };
}
},
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { swipeX, swipeStartY + swipeAmountY };
}
}, Press.FINGER));
}
@CallSuper
protected void configureContent(final @LayoutRes int layoutResId,
final @StringRes int titleResId) {
onView(withId(R.id.coordinator_stub)).perform(inflateViewStub(layoutResId));
@ -48,7 +92,7 @@ public abstract class AppBarLayoutBaseTest extends BaseDynamicCoordinatorLayoutT
mAppBar = (AppBarLayout) mCoordinatorLayout.findViewById(R.id.app_bar);
mCollapsingToolbar =
(CollapsingToolbarLayout) mAppBar.findViewById(R.id.collapsing_app_bar);
mToolbar = (Toolbar) mCollapsingToolbar.findViewById(R.id.toolbar);
mToolbar = (Toolbar) mAppBar.findViewById(R.id.toolbar);
final AppCompatActivity activity = mActivityTestRule.getActivity();
InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
@ -58,9 +102,10 @@ public abstract class AppBarLayoutBaseTest extends BaseDynamicCoordinatorLayoutT
}
});
final CharSequence activityTitle = activity.getString(titleResId);
activity.setTitle(activityTitle);
if (mCollapsingToolbar != null) {
onView(withId(R.id.collapsing_app_bar)).perform(
setTitle(activity.getString(titleResId)));
onView(withId(R.id.collapsing_app_bar)).perform(setTitle(activityTitle));
}
TextView dialog = (TextView) mCoordinatorLayout.findViewById(R.id.textview_dialogue);

View File

@ -34,42 +34,6 @@ import static org.junit.Assert.assertEquals;
@MediumTest
public class AppBarWithCollapsingToolbarTest extends AppBarLayoutBaseTest {
private static void performVerticalUpGesture(@IdRes int containerId, final int swipeX,
final int swipeStartY, final int swipeAmountY) {
onView(withId(containerId)).perform(new GeneralSwipeAction(
Swipe.SLOW,
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { swipeX, swipeStartY };
}
},
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { swipeX, swipeStartY - swipeAmountY };
}
}, Press.FINGER));
}
private static void performVerticalSwipeDownGesture(@IdRes int containerId, final int swipeX,
final int swipeStartY, final int swipeAmountY) {
onView(withId(containerId)).perform(new GeneralSwipeAction(
Swipe.SLOW,
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { swipeX, swipeStartY };
}
},
new CoordinatesProvider() {
@Override
public float[] calculateCoordinates(View view) {
return new float[] { swipeX, swipeStartY + swipeAmountY };
}
}, Press.FINGER));
}
@Test
public void testPinnedToolbar() {
configureContent(R.layout.design_appbar_toolbar_collapse_pin,

View File

@ -0,0 +1,219 @@
/*
* Copyright (C) 2016 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.design.widget;
import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes;
import android.support.design.test.R;
import android.support.design.testutils.Cheeses;
import android.test.suitebuilder.annotation.MediumTest;
import org.junit.Test;
import java.util.Arrays;
import static android.support.design.testutils.TestUtilsActions.addTabs;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static org.junit.Assert.assertEquals;
@MediumTest
public class AppBarWithToolbarAndTabsTest extends AppBarLayoutBaseTest {
private TabLayout mTabLayout;
@Override
protected void configureContent(@LayoutRes int layoutResId, @StringRes int titleResId) {
super.configureContent(layoutResId, titleResId);
mTabLayout = (TabLayout) mAppBar.findViewById(R.id.tabs);
onView(withId(R.id.tabs)).perform(addTabs(Arrays.copyOf(Cheeses.sCheeseStrings, 5)));
}
@Test
public void testScrollingToolbarAndScrollingTabs() {
configureContent(R.layout.design_appbar_toolbar_scroll_tabs_scroll,
R.string.design_appbar_toolbar_scroll_tabs_scroll);
final int[] appbarOnScreenXY = new int[2];
final int[] coordinatorLayoutOnScreenXY = new int[2];
mAppBar.getLocationOnScreen(appbarOnScreenXY);
mCoordinatorLayout.getLocationOnScreen(coordinatorLayoutOnScreenXY);
final int originalAppbarTop = appbarOnScreenXY[1];
final int originalAppbarBottom = appbarOnScreenXY[1] + mAppBar.getHeight();
final int centerX = appbarOnScreenXY[0] + mAppBar.getWidth() / 2;
final int toolbarHeight = mToolbar.getHeight();
final int tabsHeight = mTabLayout.getHeight();
final int appbarHeight = mAppBar.getHeight();
final int longSwipeAmount = 3 * appbarHeight / 2;
final int shortSwipeAmount = toolbarHeight;
// Perform a swipe-up gesture across the horizontal center of the screen.
performVerticalUpGesture(
R.id.coordinator_layout,
centerX,
originalAppbarBottom + 3 * longSwipeAmount / 2,
longSwipeAmount);
mAppBar.getLocationOnScreen(appbarOnScreenXY);
// At this point the app bar should not be visually "present" on the screen, with its bottom
// edge aligned with the system status bar. Allow for off-by-a-pixel margin of error.
assertEquals(originalAppbarTop, appbarOnScreenXY[1] + appbarHeight, 1);
// Perform another swipe-up gesture
performVerticalUpGesture(
R.id.coordinator_layout,
centerX,
originalAppbarBottom,
shortSwipeAmount);
mAppBar.getLocationOnScreen(appbarOnScreenXY);
// At this point the app bar should still be off the screen. Allow for off-by-a-pixel
// margin of error.
assertEquals(originalAppbarTop, appbarOnScreenXY[1] + appbarHeight, 1);
// Perform a long swipe-down gesture across the horizontal center of the screen.
// Note that the swipe down is a bit longer than the swipe up to fully bring down
// the scrolled-away toolbar and tab layout
performVerticalSwipeDownGesture(
R.id.coordinator_layout,
centerX,
originalAppbarBottom,
longSwipeAmount * 3 / 2);
mAppBar.getLocationOnScreen(appbarOnScreenXY);
// At this point the app bar should be visually snapped below the system status bar as it
// in scrolling mode and we've swiped down. Allow for off-by-a-pixel
// margin of error.
assertEquals(originalAppbarTop, appbarOnScreenXY[1], 1);
assertEquals(originalAppbarBottom, appbarOnScreenXY[1] + appbarHeight, 1);
// Perform another swipe-down gesture across the horizontal center of the screen.
performVerticalSwipeDownGesture(
R.id.coordinator_layout,
centerX,
originalAppbarBottom,
longSwipeAmount);
mAppBar.getLocationOnScreen(appbarOnScreenXY);
// At this point the app bar should be in its original position.
// Allow for off-by-a-pixel margin of error.
assertEquals(originalAppbarTop, appbarOnScreenXY[1], 1);
assertEquals(originalAppbarBottom, appbarOnScreenXY[1] + appbarHeight, 1);
// Perform yet another swipe-down gesture across the horizontal center of the screen.
performVerticalSwipeDownGesture(
R.id.coordinator_layout,
centerX,
originalAppbarBottom,
longSwipeAmount);
mAppBar.getLocationOnScreen(appbarOnScreenXY);
// At this point the app bar should still be in its original position.
// Allow for off-by-a-pixel margin of error.
assertEquals(originalAppbarTop, appbarOnScreenXY[1], 1);
assertEquals(originalAppbarBottom, appbarOnScreenXY[1] + appbarHeight, 1);
}
@Test
public void testPinnedToolbar() {
configureContent(R.layout.design_appbar_toolbar_scroll_tabs_pinned,
R.string.design_appbar_toolbar_scroll_tabs_pin);
final int[] appbarOnScreenXY = new int[2];
final int[] coordinatorLayoutOnScreenXY = new int[2];
mAppBar.getLocationOnScreen(appbarOnScreenXY);
mCoordinatorLayout.getLocationOnScreen(coordinatorLayoutOnScreenXY);
final int originalAppbarTop = appbarOnScreenXY[1];
final int originalAppbarBottom = appbarOnScreenXY[1] + mAppBar.getHeight();
final int centerX = appbarOnScreenXY[0] + mAppBar.getWidth() / 2;
final int toolbarHeight = mToolbar.getHeight();
final int tabsHeight = mTabLayout.getHeight();
final int appbarHeight = mAppBar.getHeight();
final int longSwipeAmount = 3 * appbarHeight / 2;
final int shortSwipeAmount = toolbarHeight;
// Perform a swipe-up gesture across the horizontal center of the screen.
performVerticalUpGesture(
R.id.coordinator_layout,
centerX,
originalAppbarBottom + 3 * longSwipeAmount / 2,
longSwipeAmount);
mAppBar.getLocationOnScreen(appbarOnScreenXY);
// At this point the tab bar should be visually snapped below the system status bar.
// Allow for off-by-a-pixel margin of error.
assertEquals(originalAppbarTop + tabsHeight, appbarOnScreenXY[1] + appbarHeight, 1);
// Perform another swipe-up gesture
performVerticalUpGesture(
R.id.coordinator_layout,
centerX,
originalAppbarBottom,
shortSwipeAmount);
mAppBar.getLocationOnScreen(appbarOnScreenXY);
// At this point the tab bar should still be visually snapped below the system status bar
// as it is in the pinned mode. Allow for off-by-a-pixel margin of error.
assertEquals(originalAppbarTop + tabsHeight, appbarOnScreenXY[1] + appbarHeight, 1);
// Perform a short swipe-down gesture across the horizontal center of the screen.
// Note that the swipe down is a bit longer than the swipe up to fully bring down
// the scrolled-away toolbar and tab layout
performVerticalSwipeDownGesture(
R.id.coordinator_layout,
centerX,
originalAppbarBottom - shortSwipeAmount,
3 * shortSwipeAmount / 2);
mAppBar.getLocationOnScreen(appbarOnScreenXY);
// At this point the app bar should be in its original position as it
// in scrolling mode and we've swiped down. Allow for off-by-a-pixel
// margin of error.
assertEquals(originalAppbarTop, appbarOnScreenXY[1], 1);
assertEquals(originalAppbarBottom, appbarOnScreenXY[1] + appbarHeight, 1);
// Perform another swipe-down gesture across the horizontal center of the screen.
performVerticalSwipeDownGesture(
R.id.coordinator_layout,
centerX,
originalAppbarBottom,
longSwipeAmount);
mAppBar.getLocationOnScreen(appbarOnScreenXY);
// At this point the app bar should be in its original position.
// Allow for off-by-a-pixel margin of error.
assertEquals(originalAppbarTop, appbarOnScreenXY[1], 1);
assertEquals(originalAppbarBottom, appbarOnScreenXY[1] + appbarHeight, 1);
// Perform yet another swipe-down gesture across the horizontal center of the screen.
performVerticalSwipeDownGesture(
R.id.coordinator_layout,
centerX,
originalAppbarBottom,
longSwipeAmount);
mAppBar.getLocationOnScreen(appbarOnScreenXY);
// At this point the app bar should still be in its original position.
// Allow for off-by-a-pixel margin of error.
assertEquals(originalAppbarTop, appbarOnScreenXY[1], 1);
assertEquals(originalAppbarBottom, appbarOnScreenXY[1] + appbarHeight, 1);
}
}