[Omnibox] show alternate answers images

This CL shows answer images that are delivered through the alternate json property

Bug: 843370
Change-Id: Ic0a2088b16b5f2d00944719c46c5ff1724d7cc90
Reviewed-on: https://chromium-review.googlesource.com/1066973
Commit-Queue: Dave Schuyler <[email protected]>
Reviewed-by: Justin Donnelly <[email protected]>
Cr-Commit-Position: refs/heads/master@{#560796}
diff --git a/components/omnibox/browser/suggestion_answer_unittest.cc b/components/omnibox/browser/suggestion_answer_unittest.cc
index 7552c23..151dc12 100644
--- a/components/omnibox/browser/suggestion_answer_unittest.cc
+++ b/components/omnibox/browser/suggestion_answer_unittest.cc
@@ -9,7 +9,9 @@
 
 #include "base/json/json_reader.h"
 #include "base/strings/utf_string_conversions.h"
+#include "base/test/scoped_feature_list.h"
 #include "base/values.h"
+#include "components/omnibox/browser/omnibox_field_trial.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
@@ -261,6 +263,23 @@
   answer->AddImageURLsTo(&urls);
   ASSERT_EQ(0U, urls.size());
 
+  {
+    base::test::ScopedFeatureList feature_list;
+    feature_list.InitAndEnableFeature(omnibox::kOmniboxNewAnswerLayout);
+    json =
+        "{ \"i\": { \"d\": \"https://gstatic.com/foo.png\", \"t\": 3 },"
+        "  \"l\" : ["
+        "    { \"il\": { \"t\": [{ \"t\": \"some text\", \"tt\": 5 }] } },"
+        "    { \"il\": { \"t\": [{ \"t\": \"other text\", \"tt\": 8 }] } }"
+        "  ]}";
+    answer = ParseAnswer(json);
+    ASSERT_TRUE(answer);
+    answer->AddImageURLsTo(&urls);
+    ASSERT_EQ(1U, urls.size());
+    EXPECT_EQ(GURL("https://gstatic.com/foo.png"), urls[0]);
+    urls.clear();
+  }
+
   json =
       "{ \"l\" : ["
       "  { \"il\": { \"t\": [{ \"t\": \"some text\", \"tt\": 5 }] } },"
@@ -271,6 +290,21 @@
   answer->AddImageURLsTo(&urls);
   ASSERT_EQ(1U, urls.size());
   EXPECT_EQ(GURL("https://gstatic.com/foo.png"), urls[0]);
+  urls.clear();
+
+  json =
+      "{ \"i\": { \"d\": \"https://gstatic.com/foo.png\", \"t\": 3 },"
+      "  \"l\" : ["
+      "    { \"il\": { \"t\": [{ \"t\": \"some text\", \"tt\": 5 }] } },"
+      "    { \"il\": { \"t\": [{ \"t\": \"other text\", \"tt\": 8 }],"
+      "              \"i\": { \"d\": \"//gstatic.com/bar.png\", \"t\": 3 }}}"
+      "  ]}";
+  answer = ParseAnswer(json);
+  ASSERT_TRUE(answer);
+  answer->AddImageURLsTo(&urls);
+  ASSERT_EQ(1U, urls.size());
+  EXPECT_EQ(GURL("https://gstatic.com/bar.png"), urls[0]);
+  urls.clear();
 
   json =
       "{ \"l\" : ["
@@ -281,7 +315,7 @@
   answer = ParseAnswer(json);
   ASSERT_TRUE(answer);
   answer->AddImageURLsTo(&urls);
-  ASSERT_EQ(3U, urls.size());
-  EXPECT_EQ(GURL("https://gstatic.com/foo.png"), urls[1]);
-  EXPECT_EQ(GURL("https://gstatic.com/bar.jpg"), urls[2]);
+  ASSERT_EQ(1U, urls.size());
+  // Note: first_line_.image_url() is not used in practice (so it's ignored).
+  EXPECT_EQ(GURL("https://gstatic.com/bar.jpg"), urls[0]);
 }