| /* |
| * Copyright (C) 2017 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.widget.cts; |
| |
| import static org.junit.Assert.assertEquals; |
| |
| import android.widget.Toolbar; |
| |
| import androidx.test.annotation.UiThreadTest; |
| import androidx.test.filters.MediumTest; |
| import androidx.test.rule.ActivityTestRule; |
| import androidx.test.runner.AndroidJUnit4; |
| |
| import org.junit.Before; |
| import org.junit.Rule; |
| import org.junit.Test; |
| import org.junit.runner.RunWith; |
| |
| @MediumTest |
| @RunWith(AndroidJUnit4.class) |
| public class ToolbarWithMarginsTest { |
| private ToolbarWithMarginsCtsActivity mActivity; |
| private Toolbar mMainToolbar; |
| |
| @Rule |
| public ActivityTestRule<ToolbarWithMarginsCtsActivity> mActivityRule = |
| new ActivityTestRule<>(ToolbarWithMarginsCtsActivity.class); |
| |
| @Before |
| public void setup() { |
| mActivity = mActivityRule.getActivity(); |
| mMainToolbar = mActivity.getMainToolbar(); |
| } |
| |
| @UiThreadTest |
| @Test |
| public void testGetTitleMargins() { |
| assertEquals(5, mMainToolbar.getTitleMarginStart()); |
| assertEquals(10, mMainToolbar.getTitleMarginTop()); |
| assertEquals(15, mMainToolbar.getTitleMarginEnd()); |
| assertEquals(20, mMainToolbar.getTitleMarginBottom()); |
| } |
| |
| @UiThreadTest |
| @Test |
| public void testSetTitleMargins() { |
| Toolbar toolbar = (Toolbar) mActivity.findViewById(R.id.toolbar2); |
| |
| toolbar.setTitleMargin(5, 10, 15, 20); |
| assertEquals(5, toolbar.getTitleMarginStart()); |
| assertEquals(10, toolbar.getTitleMarginTop()); |
| assertEquals(15, toolbar.getTitleMarginEnd()); |
| assertEquals(20, toolbar.getTitleMarginBottom()); |
| |
| toolbar.setTitleMarginStart(25); |
| toolbar.setTitleMarginTop(30); |
| toolbar.setTitleMarginEnd(35); |
| toolbar.setTitleMarginBottom(40); |
| assertEquals(25, toolbar.getTitleMarginStart()); |
| assertEquals(30, toolbar.getTitleMarginTop()); |
| assertEquals(35, toolbar.getTitleMarginEnd()); |
| assertEquals(40, toolbar.getTitleMarginBottom()); |
| } |
| } |