Update TypedArrayTest to test source layout resource ids.

Test: atest CtsContentTestCases:android.content.res.cts.TypedArrayTest
Change-Id: Iaf7fe85cae7c8bf01849fc92197fa57914d31bd2
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index 47f12b8..9042e16 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -13,6 +13,7 @@
                       tests/autofillservice/
                       tests/contentcaptureservice/
                       tests/tests/animation/
+                      tests/tests/content/
                       tests/tests/graphics/
                       tests/tests/hardware/
                       tests/tests/print/
diff --git a/tests/tests/content/res/layout/source_style_layout.xml b/tests/tests/content/res/layout/source_style_layout.xml
new file mode 100644
index 0000000..f861155
--- /dev/null
+++ b/tests/tests/content/res/layout/source_style_layout.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2019 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
+  -->
+
+<View 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"
+              style="@style/StyleA"
+              app:type1="true"/>
\ No newline at end of file
diff --git a/tests/tests/content/res/values/styles.xml b/tests/tests/content/res/values/styles.xml
index 7da5c5e..bc583f1 100644
--- a/tests/tests/content/res/values/styles.xml
+++ b/tests/tests/content/res/values/styles.xml
@@ -41,6 +41,7 @@
 
     <style name="StyleA" parent="StyleB">
         <item name="type1">true</item>
+        <item name="type17">@color/testcolor_orientation</item>
     </style>
     <style name="StyleB" parent="StyleC">
         <item name="type1">false</item>
diff --git a/tests/tests/content/src/android/content/res/cts/TypedArrayTest.java b/tests/tests/content/src/android/content/res/cts/TypedArrayTest.java
index 38a6a5b..d98bda8 100644
--- a/tests/tests/content/src/android/content/res/cts/TypedArrayTest.java
+++ b/tests/tests/content/src/android/content/res/cts/TypedArrayTest.java
@@ -28,8 +28,10 @@
 import android.test.AndroidTestCase;
 import android.util.AttributeSet;
 import android.util.TypedValue;
+import android.util.Xml;
 import android.view.ContextThemeWrapper;
 
+import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.IOException;
@@ -72,19 +74,41 @@
         mTypedArray.recycle();
     }
 
-    public void testSourceStyleResourceId() {
+    public void testSourceResourceIdFromStyle() {
         final TypedArray t = getContext().getTheme().obtainStyledAttributes(
                 R.style.StyleA, R.styleable.style1);
 
-        assertEquals(R.style.StyleA, t.getSourceStyleResourceId(R.styleable.style1_type1, 0));
-        assertEquals(R.style.StyleB, t.getSourceStyleResourceId(R.styleable.style1_type2, 0));
-        assertEquals(R.style.StyleC, t.getSourceStyleResourceId(R.styleable.style1_type3, 0));
-        assertEquals(R.style.StyleB, t.getSourceStyleResourceId(R.styleable.style1_type4, 0));
-        assertEquals(0, t.getSourceStyleResourceId(R.styleable.style1_type5, 0));
+        assertEquals(R.style.StyleA, t.getSourceResourceId(R.styleable.style1_type1, 0));
+        assertEquals(R.style.StyleB, t.getSourceResourceId(R.styleable.style1_type2, 0));
+        assertEquals(R.style.StyleC, t.getSourceResourceId(R.styleable.style1_type3, 0));
+        assertEquals(R.style.StyleB, t.getSourceResourceId(R.styleable.style1_type4, 0));
+        assertEquals(0, t.getSourceResourceId(R.styleable.style1_type5, 0));
+        assertEquals(R.style.StyleA, t.getSourceResourceId(R.styleable.style1_type17, 0));
 
         t.recycle();
     }
 
+    public void testSourceResourceIdFromLayout() throws Exception {
+        XmlResourceParser parser =
+                getContext().getResources().getLayout(R.layout.source_style_layout);
+
+        final AttributeSet attrs = Xml.asAttributeSet(parser);
+
+        // Look for the root node.
+        assertEquals(XmlPullParser.START_DOCUMENT, parser.next());
+        assertEquals(XmlPullParser.START_TAG, parser.next());
+
+        final TypedArray t = getContext().getTheme().obtainStyledAttributes(
+                attrs, R.styleable.style1, 0, 0);
+        assertEquals(R.layout.source_style_layout,
+                t.getSourceResourceId(R.styleable.style1_type1, 0));
+        assertEquals(R.style.StyleB, t.getSourceResourceId(R.styleable.style1_type2, 0));
+        assertEquals(R.style.StyleC, t.getSourceResourceId(R.styleable.style1_type3, 0));
+        assertEquals(R.style.StyleB, t.getSourceResourceId(R.styleable.style1_type4, 0));
+        assertEquals(0, t.getSourceResourceId(R.styleable.style1_type5, 0));
+        assertEquals(R.style.StyleA, t.getSourceResourceId(R.styleable.style1_type17, 0));
+    }
+
     public void testGetType() {
         final TypedArray t = getContext().getTheme().obtainStyledAttributes(
                 R.style.Whatever, R.styleable.style1);