1170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam/* 2170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * Copyright (C) 2015 The Android Open Source Project 3170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * 4170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * Licensed under the Apache License, Version 2.0 (the "License"); 5170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * you may not use this file except in compliance with the License. 6170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * You may obtain a copy of the License at 7170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * 8170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * http://www.apache.org/licenses/LICENSE-2.0 9170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * 10170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * Unless required by applicable law or agreed to in writing, software 11170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * distributed under the License is distributed on an "AS IS" BASIS, 12170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * See the License for the specific language governing permissions and 14170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam * limitations under the License. 15170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam */ 16170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 17170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lampackage com.android.setupwizardlib.test; 18170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 192614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport static org.junit.Assert.assertEquals; 202614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport static org.junit.Assert.assertFalse; 212614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport static org.junit.Assert.assertNotNull; 222614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport static org.junit.Assert.assertNull; 232614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport static org.junit.Assert.assertSame; 242614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport static org.junit.Assert.assertTrue; 252614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam 2624ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lamimport android.content.Context; 27170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lamimport android.graphics.Color; 28170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lamimport android.graphics.drawable.ColorDrawable; 297f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lamimport android.os.Parcelable; 3063cdc5ccb7f1f61d0e752e38d7e57c690658a0acMaurice Lamimport android.support.annotation.IdRes; 312614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport android.support.test.InstrumentationRegistry; 322614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport android.support.test.filters.SmallTest; 332614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport android.support.test.runner.AndroidJUnit4; 347f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lamimport android.util.SparseArray; 357f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lamimport android.view.AbsSavedState; 3624ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lamimport android.view.ContextThemeWrapper; 37170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lamimport android.view.LayoutInflater; 38170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lamimport android.view.View; 39d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lamimport android.widget.ProgressBar; 40170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lamimport android.widget.TextView; 41170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 42170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lamimport com.android.setupwizardlib.SetupWizardLayout; 437514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lamimport com.android.setupwizardlib.template.HeaderMixin; 447514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lamimport com.android.setupwizardlib.template.NavigationBarMixin; 457514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lamimport com.android.setupwizardlib.template.ProgressBarMixin; 46170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lamimport com.android.setupwizardlib.view.NavigationBar; 47170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 482614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport org.junit.Before; 492614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport org.junit.Test; 502614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lamimport org.junit.runner.RunWith; 512614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam 522614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam@RunWith(AndroidJUnit4.class) 532614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam@SmallTest 542614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lampublic class SetupWizardLayoutTest { 55170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 5663cdc5ccb7f1f61d0e752e38d7e57c690658a0acMaurice Lam @IdRes 5763cdc5ccb7f1f61d0e752e38d7e57c690658a0acMaurice Lam private static final int ID1234 = 1234; 5863cdc5ccb7f1f61d0e752e38d7e57c690658a0acMaurice Lam 5924ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam private Context mContext; 6024ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam 612614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Before 622614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam public void setUp() throws Exception { 632614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(), 6424ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam R.style.SuwThemeMaterial_Light); 6524ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam } 6624ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam 672614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 68170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam public void testDefaultTemplate() { 6924ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam SetupWizardLayout layout = new SetupWizardLayout(mContext); 70170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertDefaultTemplateInflated(layout); 71170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam } 72170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 732614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 74170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam public void testSetHeaderText() { 7524ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam SetupWizardLayout layout = new SetupWizardLayout(mContext); 76170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam TextView title = (TextView) layout.findViewById(R.id.suw_layout_title); 77170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam layout.setHeaderText("Abracadabra"); 78170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertEquals("Header text should be \"Abracadabra\"", "Abracadabra", title.getText()); 79170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam } 80170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 812614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 82170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam public void testAddView() { 8324ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam SetupWizardLayout layout = new SetupWizardLayout(mContext); 8424ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam TextView tv = new TextView(mContext); 859f9367672191190f903955d09a4314d40869acc6Maurice Lam tv.setId(R.id.test_view_id); 86170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam layout.addView(tv); 87170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertDefaultTemplateInflated(layout); 889f9367672191190f903955d09a4314d40869acc6Maurice Lam View view = layout.findViewById(R.id.test_view_id); 89170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertSame("The view added should be the same text view", tv, view); 90170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam } 91170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 922614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 93170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam public void testInflateFromXml() { 9424ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam LayoutInflater inflater = LayoutInflater.from(mContext); 95170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam SetupWizardLayout layout = (SetupWizardLayout) inflater.inflate(R.layout.test_layout, null); 96170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertDefaultTemplateInflated(layout); 97170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam View content = layout.findViewById(R.id.test_content); 98170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertTrue("@id/test_content should be a TextView", content instanceof TextView); 99170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam } 100170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 1012614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 102170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam public void testCustomTemplate() { 10324ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam SetupWizardLayout layout = new SetupWizardLayout(mContext, R.layout.test_template); 104170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam View templateView = layout.findViewById(R.id.test_template_view); 105170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertNotNull("@id/test_template_view should exist in template", templateView); 106170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 10724ab59ef4f9726316743d94d31c93bf9420e7717Maurice Lam TextView tv = new TextView(mContext); 1089f9367672191190f903955d09a4314d40869acc6Maurice Lam tv.setId(R.id.test_view_id); 109170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam layout.addView(tv); 110170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 111170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam templateView = layout.findViewById(R.id.test_template_view); 112170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertNotNull("@id/test_template_view should exist in template", templateView); 1139f9367672191190f903955d09a4314d40869acc6Maurice Lam View contentView = layout.findViewById(R.id.test_view_id); 114170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertSame("The view added should be the same text view", tv, contentView); 115170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 116170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam // The following methods should be no-ops because the custom template doesn't contain the 117170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam // corresponding optional views. Just check that they don't throw exceptions. 118170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam layout.setHeaderText("Abracadabra"); 119170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam layout.setIllustration(new ColorDrawable(Color.MAGENTA)); 120170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam layout.setLayoutBackground(new ColorDrawable(Color.RED)); 121170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam } 122170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam 1232614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 1247e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam public void testGetNavigationBar() { 1257e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam final SetupWizardLayout layout = new SetupWizardLayout(mContext); 1267e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam final NavigationBar navigationBar = layout.getNavigationBar(); 1277e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam assertEquals("Navigation bar should have ID = @id/suw_layout_navigation_bar", 1287e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam R.id.suw_layout_navigation_bar, navigationBar.getId()); 1297e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam } 1307e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam 1312614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 1327e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam public void testGetNavigationBarNull() { 1337e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam // test_template does not have navigation bar so getNavigationBar() should return null. 1347e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam final SetupWizardLayout layout = new SetupWizardLayout(mContext, R.layout.test_template); 1357e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam final NavigationBar navigationBar = layout.getNavigationBar(); 1367e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam assertNull("getNavigationBar() in test_template should return null", navigationBar); 1377e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam } 1387e5f0f0ea3b3075258cac9d26f90fd97c1a71dcaMaurice Lam 1392614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 140d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam public void testShowProgressBar() { 141d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam final SetupWizardLayout layout = new SetupWizardLayout(mContext); 142d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam layout.showProgressBar(); 143d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam assertTrue("Progress bar should be shown", layout.isProgressBarShown()); 144d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam final View progressBar = layout.findViewById(R.id.suw_layout_progress); 145d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam assertTrue("Progress bar view should be shown", 146d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam progressBar instanceof ProgressBar && progressBar.getVisibility() == View.VISIBLE); 147d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam } 148d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam 1492614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 150d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam public void testHideProgressBar() { 151d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam final SetupWizardLayout layout = new SetupWizardLayout(mContext); 152d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam layout.showProgressBar(); 153d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam assertTrue("Progress bar should be shown", layout.isProgressBarShown()); 154d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam layout.hideProgressBar(); 155d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam assertFalse("Progress bar should be hidden", layout.isProgressBarShown()); 156d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam final View progressBar = layout.findViewById(R.id.suw_layout_progress); 157d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam assertTrue("Progress bar view should exist", 158d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam progressBar == null || progressBar.getVisibility() != View.VISIBLE); 159d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam } 160d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam 1612614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 162d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam public void testShowProgressBarNotExist() { 163d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam // test_template does not have progress bar, so showNavigationBar() should do nothing. 164d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam final SetupWizardLayout layout = new SetupWizardLayout(mContext, R.layout.test_template); 165d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam layout.showProgressBar(); 166d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam assertFalse("Progress bar should not be shown", layout.isProgressBarShown()); 167d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam } 168d61674efcfaa9f591a44fc75d59566cdd5b409ebMaurice Lam 1692614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 170e2a8d27c2a43cf0b48b80e5b05f893222c541e04Maurice Lam public void testNonMaterialTheme() { 1712614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam mContext = new ContextThemeWrapper(InstrumentationRegistry.getContext(), 17299586481628659cd2982a0248bc0d09a6ec4590eMaurice Lam android.R.style.Theme); 173e2a8d27c2a43cf0b48b80e5b05f893222c541e04Maurice Lam new SetupWizardLayout(mContext); 174e2a8d27c2a43cf0b48b80e5b05f893222c541e04Maurice Lam // Inflating with a non-Material theme should not crash 17599586481628659cd2982a0248bc0d09a6ec4590eMaurice Lam } 17699586481628659cd2982a0248bc0d09a6ec4590eMaurice Lam 1772614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 1787f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam public void testOnRestoreFromInstanceState() { 1797f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam final SetupWizardLayout layout = new SetupWizardLayout(mContext); 18063cdc5ccb7f1f61d0e752e38d7e57c690658a0acMaurice Lam layout.setId(ID1234); 1817f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 1827f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam SparseArray<Parcelable> container = new SparseArray<>(); 1837f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam layout.saveHierarchyState(container); 1847f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 1857f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam final SetupWizardLayout layout2 = new SetupWizardLayout(mContext); 18663cdc5ccb7f1f61d0e752e38d7e57c690658a0acMaurice Lam layout2.setId(ID1234); 1877f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam layout2.restoreHierarchyState(container); 1887f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 1897f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam assertFalse("Progress bar should not be shown", layout2.isProgressBarShown()); 1907f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam } 1917f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 1922614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 1937f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam public void testOnRestoreFromInstanceStateProgressBarShown() { 1947f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam final SetupWizardLayout layout = new SetupWizardLayout(mContext); 19563cdc5ccb7f1f61d0e752e38d7e57c690658a0acMaurice Lam layout.setId(ID1234); 1967f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 1977f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam layout.setProgressBarShown(true); 1987f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 1997f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam SparseArray<Parcelable> container = new SparseArray<>(); 2007f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam layout.saveHierarchyState(container); 2017f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 2027f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam final SetupWizardLayout layout2 = new SetupWizardLayout(mContext); 20363cdc5ccb7f1f61d0e752e38d7e57c690658a0acMaurice Lam layout2.setId(ID1234); 2047f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam layout2.restoreHierarchyState(container); 2057f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 2067f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam assertTrue("Progress bar should be shown", layout2.isProgressBarShown()); 2077f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam } 2087f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 2092614260933341bd4ea7bb37a3435f46f82cacef7Maurice Lam @Test 2107f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam public void testOnRestoreFromIncompatibleInstanceState() { 2117f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam final SetupWizardLayout layout = new SetupWizardLayout(mContext); 21263cdc5ccb7f1f61d0e752e38d7e57c690658a0acMaurice Lam layout.setId(ID1234); 2137f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 2147f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam SparseArray<Parcelable> container = new SparseArray<>(); 2157f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam container.put(1234, AbsSavedState.EMPTY_STATE); 2167f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam layout.restoreHierarchyState(container); 2177f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 2187f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam // SetupWizardLayout shouldn't crash with incompatible Parcelable 2197f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 2207f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam assertFalse("Progress bar should not be shown", layout.isProgressBarShown()); 2217f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam } 2227f2a6e95f20408e055bb8b965b9e2bc664eec86bMaurice Lam 2237514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam @Test 2247514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam public void testGetMixins() { 2257514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam final SetupWizardLayout layout = new SetupWizardLayout(mContext); 2267514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam assertNotNull("SetupWizardLayout should have header mixin", 2277514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam layout.getMixin(HeaderMixin.class)); 2287514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam assertNotNull("SetupWizardLayout should have progress bar mixin", 2297514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam layout.getMixin(ProgressBarMixin.class)); 2307514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam assertNotNull("SetupWizardLayout should have navigation bar mixin", 2317514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam layout.getMixin(NavigationBarMixin.class)); 2327514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam } 2337514f1cee29b3feb4822ce16945c1c312057d24fMaurice Lam 234170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam private void assertDefaultTemplateInflated(SetupWizardLayout layout) { 235170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam View decorView = layout.findViewById(R.id.suw_layout_decor); 236170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam View navbar = layout.findViewById(R.id.suw_layout_navigation_bar); 237170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam View title = layout.findViewById(R.id.suw_layout_title); 238170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertNotNull("@id/suw_layout_decor_view should not be null", decorView); 239170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertTrue("@id/suw_layout_navigation_bar should be an instance of NavigationBar", 240170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam navbar instanceof NavigationBar); 241170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam assertNotNull("@id/suw_layout_title should not be null", title); 242170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam } 243170a720fe110de6cc1a8c1cd660e591295562cfaMaurice Lam} 244