Add CTS tests for Toolbar title margins

Bug: 23719889
Change-Id: I9d21bcfc98fb7b983020ee82f48c36dba8d0a5ee
diff --git a/tests/tests/widget/res/layout/toolbar_layout.xml b/tests/tests/widget/res/layout/toolbar_layout.xml
new file mode 100644
index 0000000..af8a596
--- /dev/null
+++ b/tests/tests/widget/res/layout/toolbar_layout.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2015 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.
+-->
+
+<Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
+         android:layout_width="match_parent"
+         android:layout_height="wrap_content"
+         android:id="@+id/toolbar"
+         android:titleMargins="5px"
+         android:titleMarginTop="10px"
+         android:titleMarginEnd="15px"
+         android:titleMarginBottom="20px" />
diff --git a/tests/tests/widget/src/android/widget/cts/ToolbarTest.java b/tests/tests/widget/src/android/widget/cts/ToolbarTest.java
new file mode 100644
index 0000000..f4953c0
--- /dev/null
+++ b/tests/tests/widget/src/android/widget/cts/ToolbarTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2015 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 android.content.Context;
+import android.test.AndroidTestCase;
+import android.test.UiThreadTest;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Toolbar;
+
+import com.android.cts.widget.R;
+
+public class ToolbarTest extends AndroidTestCase {
+    private Context mContext;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        mContext = getContext();
+    }
+
+    @UiThreadTest
+    public void testGetTitleMargins() {
+        LayoutInflater inflater = LayoutInflater.from(mContext);
+        View layout = inflater.inflate(R.layout.toolbar);
+        Toolbar toolbar = (Toolbar) layout.findViewById(R.id.toolbar);
+
+        assertEquals(5, toolbar.getTitleMarginStart());
+        assertEquals(10, toolbar.getTitleMarginTop());
+        assertEquals(15, toolbar.getTitleMarginEnd());
+        assertEquals(20, toolbar.getTitleMarginBottom());
+    }
+
+    @UiThreadTest
+    public void testSetTitleMargins() {
+        Toolbar toolbar = new Toolbar(mContext);
+        assertEquals(0, toolbar.getTitleMarginStart());
+        assertEquals(0, toolbar.getTitleMarginTop());
+        assertEquals(0, toolbar.getTitleMarginEnd());
+        assertEquals(0, toolbar.getTitleMarginBottom());
+
+        toolbar.setTitleMargins(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());
+    }
+}