Add reference url to XML reports

bug: 25452494
Change-Id: I9e927da45183c2518594b8aa7432416c644abec0
diff --git a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
index 51b457d..3efc7fc 100644
--- a/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
+++ b/tools/tradefed-host/src/com/android/cts/tradefed/result/CtsXmlResultReporter.java
@@ -432,6 +432,9 @@
         serializer.attribute(ns, "endtime", endTime);
         serializer.attribute(ns, "version", CTS_RESULT_FILE_VERSION);
         serializer.attribute(ns, "suite", mSuiteName);
+        if (mReferenceUrl != null) {
+            serializer.attribute(ns, "referenceUrl", mReferenceUrl);
+        }
         mResults.serialize(serializer, mBuildInfo.getBuildId());
         // TODO: not sure why, but the serializer doesn't like this statement
         //serializer.endTag(ns, RESULT_TAG);
diff --git a/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java b/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java
index 51a6153..958dbe4 100644
--- a/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java
+++ b/tools/tradefed-host/tests/src/com/android/cts/tradefed/result/CtsXmlResultReporterTest.java
@@ -48,8 +48,9 @@
  */
 public class CtsXmlResultReporterTest extends TestCase {
 
+    private static final String TEST_SUMMARY_URL = "http://www.google.com?q=android";
     private static final List<TestSummary> SUMMARY_LIST =
-            new ArrayList<>(Arrays.asList(new TestSummary("TEST_SUMMARY_URL")));
+            new ArrayList<>(Arrays.asList(new TestSummary(TEST_SUMMARY_URL)));
     private CtsXmlResultReporter mResultReporter;
     private ByteArrayOutputStream mOutputStream;
     private File mBuildDir;
@@ -116,7 +117,7 @@
             "<?xml-stylesheet type=\"text/xsl\" href=\"cts_result.xsl\"?>";
         final String expectedTestOutput = String.format(
             "<TestResult testPlan=\"NA\" starttime=\"ignore\" endtime=\"ignore\" " +
-                    "version=\"%s\" suite=\"%s\"> ", CTS_RESULT_FILE_VERSION, "CTS" );
+                    "version=\"%s\" suite=\"%s\"> ", CTS_RESULT_FILE_VERSION, "CTS");
         final String expectedSummaryOutput =
             "<Summary failed=\"0\" notExecuted=\"0\" timeout=\"0\" pass=\"0\" />";
         final String expectedEndTag = "</TestResult>";
@@ -128,7 +129,7 @@
         assertTrue(String.format("test output did not contain expected test result [%s]. Got %s",
                 expectedTestOutput, actualOutput), actualOutput.contains(expectedTestOutput));
         assertTrue(String.format("test output did not contain expected test summary [%s]. Got %s",
-                expectedTestOutput, actualOutput), actualOutput.contains(expectedSummaryOutput));
+                expectedSummaryOutput, actualOutput), actualOutput.contains(expectedSummaryOutput));
         assertTrue(String.format("test output did not contain expected TestResult end tag. Got %s",
                 actualOutput), actualOutput.endsWith(expectedEndTag));
         EasyMock.verify(mMockBuild);
@@ -146,10 +147,15 @@
         mResultReporter.testStarted(testId);
         mResultReporter.testEnded(testId, emptyMap);
         mResultReporter.testRunEnded(3000, emptyMap);
-        mResultReporter.invocationEnded(1);
         mResultReporter.putSummary(SUMMARY_LIST);
+        mResultReporter.invocationEnded(1);
         String output =  getOutput();
         // TODO: consider doing xml based compare
+        final String expectedTestOutput = String.format(
+            "<TestResult testPlan=\"NA\" starttime=\"ignore\" endtime=\"ignore\" " +
+                    "version=\"%s\" suite=\"%s\" referenceUrl=\"%s\"> ",
+                            CTS_RESULT_FILE_VERSION, "CTS", TEST_SUMMARY_URL);
+        assertTrue("Found output: " + output, output.contains(expectedTestOutput));
         assertTrue(output.contains(
               "<Summary failed=\"0\" notExecuted=\"0\" timeout=\"0\" pass=\"1\" />"));
         assertTrue(output.contains("<TestPackage name=\"\" appPackageName=\"run\" abi=\"" +