Commit 18873a37 authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

SearchProviderLogos: Add parsing tests for captured ddljson API output

This CL adds a script to download a number of test doodle configs from
the ddljson API. It also adds a captured snapshot of those configs, and
a test that they all get parsed without errors.

Bug: 690467
Change-Id: Idf8375a4199fc129b905c7f8cd32f12d071389e9
Reviewed-on: https://chromium-review.googlesource.com/597647
Commit-Queue: Marc Treib <treib@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491731}
parent fff01c72
...@@ -33,6 +33,33 @@ static_library("search_provider_logos") { ...@@ -33,6 +33,33 @@ static_library("search_provider_logos") {
] ]
} }
bundle_data("unit_tests_bundle_data") {
visibility = [ ":unit_tests" ]
testonly = true
sources = [
"//components/test/data/search_provider_logos/ddljson_android1.json",
"//components/test/data/search_provider_logos/ddljson_android1_fp.json",
"//components/test/data/search_provider_logos/ddljson_android2.json",
"//components/test/data/search_provider_logos/ddljson_android2_fp.json",
"//components/test/data/search_provider_logos/ddljson_android3.json",
"//components/test/data/search_provider_logos/ddljson_android3_fp.json",
"//components/test/data/search_provider_logos/ddljson_android4.json",
"//components/test/data/search_provider_logos/ddljson_android4_fp.json",
"//components/test/data/search_provider_logos/ddljson_ios1.json",
"//components/test/data/search_provider_logos/ddljson_ios1_fp.json",
"//components/test/data/search_provider_logos/ddljson_ios2.json",
"//components/test/data/search_provider_logos/ddljson_ios2_fp.json",
"//components/test/data/search_provider_logos/ddljson_ios3.json",
"//components/test/data/search_provider_logos/ddljson_ios3_fp.json",
"//components/test/data/search_provider_logos/ddljson_ios4.json",
"//components/test/data/search_provider_logos/ddljson_ios4_fp.json",
]
outputs = [
"{{bundle_resources_dir}}/" +
"{{source_root_relative_dir}}/{{source_file_part}}",
]
}
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
...@@ -42,6 +69,7 @@ source_set("unit_tests") { ...@@ -42,6 +69,7 @@ source_set("unit_tests") {
] ]
deps = [ deps = [
":search_provider_logos", ":search_provider_logos",
":unit_tests_bundle_data",
"//base/test:test_support", "//base/test:test_support",
"//net:test_support", "//net:test_support",
"//testing/gmock", "//testing/gmock",
......
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/path_service.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -98,4 +101,47 @@ TEST(GoogleNewLogoApiTest, ParsesAnimatedImage) { ...@@ -98,4 +101,47 @@ TEST(GoogleNewLogoApiTest, ParsesAnimatedImage) {
EXPECT_EQ("abc", logo->encoded_image->data()); EXPECT_EQ("abc", logo->encoded_image->data());
} }
TEST(GoogleNewLogoApiTest, ParsesCapturedApiResult) {
const GURL base_url("https://base.doo/");
base::FilePath test_data_dir;
ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir));
test_data_dir = test_data_dir.AppendASCII("components")
.AppendASCII("test")
.AppendASCII("data")
.AppendASCII("search_provider_logos");
// TODO(treib): Add the doodle with index 0 (here and in the
// download_test_doodles.sh script) once it has been updated on the server.
const struct TestCase {
const char* file;
bool has_image_data;
} test_cases[] = {
{"ddljson_android1.json", true}, {"ddljson_android1_fp.json", false},
{"ddljson_android2.json", true}, {"ddljson_android2_fp.json", false},
{"ddljson_android3.json", true}, {"ddljson_android3_fp.json", false},
{"ddljson_android4.json", true}, {"ddljson_android4_fp.json", false},
{"ddljson_ios1.json", true}, {"ddljson_ios1_fp.json", false},
{"ddljson_ios2.json", true}, {"ddljson_ios2_fp.json", false},
{"ddljson_ios3.json", true}, {"ddljson_ios3_fp.json", false},
{"ddljson_ios4.json", true}, {"ddljson_ios4_fp.json", false},
};
for (const TestCase& test_case : test_cases) {
std::string json;
ASSERT_TRUE(base::ReadFileToString(
test_data_dir.AppendASCII(test_case.file), &json))
<< test_case.file;
bool failed = false;
std::unique_ptr<EncodedLogo> logo = GoogleNewParseLogoResponse(
base_url, base::MakeUnique<std::string>(json), base::Time(), &failed);
EXPECT_FALSE(failed) << test_case.file;
EXPECT_TRUE(logo) << test_case.file;
bool has_image_data = logo && logo->encoded_image.get();
EXPECT_EQ(has_image_data, test_case.has_image_data) << test_case.file;
}
}
} // namespace search_provider_logos } // namespace search_provider_logos
This directory contains canned test responses from Google's Doodle API at
www.google.com/async/ddljson. There's a unit test that verifies that Chromium
parses all the files without errors. When something on the server-side changes,
simply run the download_test_doodles.sh script to update all the files. Note
that if the number of files changes (e.g. because a new test Doodle was added),
the file list in the unit test also has to be updated.
)]}'
{"ddljson":{"alt_text":"Gilbert Baker\u0027s 66th birthday","doodle_type":"ANIMATED","fingerprint":"b2d3e5e8","gallery_url":"http://www.google.com/doodles/gilbert-bakers-66th-birthday","header_layout":"LEGACY","id":37727880,"intent":"BUILTIN","large_cta_image":{"height":200,"image_id":4817033455730688,"image_name":"StaticCTA","is_animated_gif":false,"slot":26,"url":"/logos/doodles/2017/gilbert-bakers-66th-birthday-6016396013076480.2-scta.png","width":469},"large_image":{"alternate_url":"https://lh3.googleusercontent.com/zCtRFJP-Rz8iKp1XXnazo9vWr2YMBb-vEzhr1C3-QfEQpEhzMyajvLqSMDS6wPpOEImC7RdfdwxiI9ofoKahlSCu5HJ65bc0lIeHyHs0","height":200,"image_id":5661458385862656,"image_name":"LargeAnimatedWhite","is_animated_gif":true,"slot":27,"url":"/logos/doodles/2017/gilbert-bakers-66th-birthday-6016396013076480.8-law.gif","width":469},"search_url":"/search?q\u003dGilbert+Baker\u0026oi\u003dddle\u0026ct\u003dgilbert-bakers-66th-birthday-6016396013076480","share_text":"Gilbert Baker\u0027s 66th birthday\nhttps://g.co/doodle/2ythp4","short_link":"//g.co/doodle/2ythp4","show_now_header_search_affordance":false,"show_now_header_share_button":true,"target_url":"/search?q\u003dGilbert+Baker\u0026oi\u003dddle\u0026ct\u003dgilbert-bakers-66th-birthday-6016396013076480","time_to_live_ms":498337149000}}
\ No newline at end of file
)]}'
{"ddljson":{"alt_text":"Happy Halloween!","doodle_type":"INTERACTIVE","fingerprint":"4438a87d","fullpage_interactive_url":"https://www.google.com/?fpdoodle\u003d1\u0026doodle\u003d28464230\u0026hl\u003den","gallery_url":"http://www.google.com/doodles/halloween-2016?hl\u003den","header_layout":"LEGACY","id":28464230,"intent":"BUILTIN","large_cta_image":{"height":230,"image_id":5910974510923776,"image_name":"StaticCTA","is_animated_gif":false,"slot":26,"url":"/logos/doodles/2016/halloween-2016-5643419163557888.5-scta.png","width":460},"large_image":{"height":220,"image_id":5066549580791808,"image_name":"LargeAnimatedWhiteCTA","is_animated_gif":true,"slot":27,"url":"/logos/doodles/2016/halloween-2016-5643419163557888-cta.gif","width":429},"screen_orientation":"LANDSCAPE","search_url":"/search?q\u003dHalloween\u0026oi\u003dddle\u0026ct\u003dhalloween-2016-5643419163557888\u0026hl\u003den","share_text":"Happy Halloween 2016! #GoogleDoodle\nhttps://g.co/doodle/vu3nqy","short_link":"//g.co/doodle/vu3nqy","show_now_header_search_affordance":true,"show_now_header_share_button":true,"target_url":"https://www.google.com/?fpdoodle\u003d1\u0026doodle\u003d28464230\u0026hl\u003den","time_to_live_ms":498337150000}}
\ No newline at end of file
)]}'
{"ddljson":{"alt_text":"Hedy Lamarr\u0027s 101st birthday","doodle_type":"VIDEO","fingerprint":"5a5c777a","fullpage_interactive_url":"https://www.google.com/?fpdoodle\u003d1\u0026doodle\u003d24101651\u0026hl\u003den","gallery_url":"http://www.google.com/doodles/hedy-lamarrs-101st-birthday?hl\u003den","header_layout":"LEGACY","id":24101651,"intent":"BUILTIN","large_cta_image":{"height":230,"image_id":5910974510923776,"image_name":"StaticCTA","is_animated_gif":false,"slot":26,"url":"/logos/doodles/2015/hedy-lamarrs-101st-birthday-5679746450980864.2-scta.png","width":409},"large_image":{"alternate_url":"https://lh3.googleusercontent.com/N3wSsA1KchbJFobk3TmC0SOeSoGhwSyQPlISjqSUMpBN1frPmUCJJcZmPat7uZUguaNt_x5qbbdBgsHLMSQKy_oK5UbB5dn_i_6TtsiK","height":230,"image_id":5066549580791808,"image_name":"LargeAnimatedWhiteCTA","is_animated_gif":true,"slot":27,"url":"/logos/doodles/2015/hedy-lamarrs-101st-birthday-5679746450980864.2-hp.gif","width":409},"search_url":"/search?q\u003dHedy+Lamarr\u0026oi\u003dddle\u0026ct\u003dhedy-lamarrs-101st-birthday-5679746450980864\u0026hl\u003den","share_text":"Actress and Inventor Hedy Lamarr\u0027s 101st birthday #GoogleDoodle\nhttps://g.co/doodle/pzx7av","short_link":"//g.co/doodle/pzx7av","show_now_header_search_affordance":true,"show_now_header_share_button":true,"target_url":"//www.youtube.com/watch?v\u003dZ0gu2QhV1dc","time_to_live_ms":498337151000}}
\ No newline at end of file
)]}'
{"ddljson":{"alt_text":"155th Anniversary of the Pony Express (Test Interactive Doodle)","doodle_type":"INTERACTIVE","fingerprint":"de2ab303","fullpage_interactive_url":"https://www.google.com/?fpdoodle\u003d1\u0026doodle\u003d18511013\u0026hl\u003den","gallery_url":"//www.google.com/doodles/155th-anniversary-of-the-pony-express","header_layout":"LEGACY","id":18511013,"intent":"JAR","large_image":{"alternate_url":"http://lh3.googleusercontent.com/YYmuJ3RPEk93WIRxZ8EmrJVA4vHDZX2jIREH_Sc5G6KT8pnkG7kQB24NR_6HsB5wl50VpCSIYzlcIqZjjFapdQwSldLfmip27tLja1dZ","height":225,"image_id":5066549580791808,"image_name":"Large","is_animated_gif":false,"slot":27,"url":"/logos/doodles/2015/155th-anniversary-of-the-pony-express-5959391580782592.2-hp.jpg","width":400},"mobile_native":{"jar_object_name":"particles"},"screen_orientation":"LANDSCAPE","search_url":"/search?q\u003dwhen+was+the+first+mail+pouch+delivered+by+the+pony+express\u0026oi\u003dddle\u0026ct\u003d155th-anniversary-of-the-pony-express-5959391580782592\u0026hl\u003den","share_text":"Join the Pony Express to deliver 100 letters! #GoogleDoodle\nhttps://g.co/doodle/7j375g","short_link":"//g.co/doodle/7j375g","show_now_header_search_affordance":true,"show_now_header_share_button":true,"target_url":"/search?q\u003dwhen+was+the+first+mail+pouch+delivered+by+the+pony+express\u0026oi\u003dddle\u0026ct\u003d155th-anniversary-of-the-pony-express-5959391580782592\u0026hl\u003den","time_to_live_ms":498337151000}}
\ No newline at end of file
This diff is collapsed.
)]}'
{"ddljson":{"alt_text":"Gilbert Baker\u0027s 66th birthday","doodle_type":"ANIMATED","fingerprint":"b2d3e5e8","gallery_url":"http://www.google.com/doodles/gilbert-bakers-66th-birthday","header_layout":"LEGACY","id":37727880,"intent":"BUILTIN","large_cta_image":{"height":200,"image_id":4817033455730688,"image_name":"StaticCTA","is_animated_gif":false,"slot":26,"url":"/logos/doodles/2017/gilbert-bakers-66th-birthday-6016396013076480.2-scta.png","width":469},"large_image":{"alternate_url":"https://lh3.googleusercontent.com/zCtRFJP-Rz8iKp1XXnazo9vWr2YMBb-vEzhr1C3-QfEQpEhzMyajvLqSMDS6wPpOEImC7RdfdwxiI9ofoKahlSCu5HJ65bc0lIeHyHs0","height":200,"image_id":5661458385862656,"image_name":"LargeAnimatedWhite","is_animated_gif":true,"slot":27,"url":"/logos/doodles/2017/gilbert-bakers-66th-birthday-6016396013076480.8-law.gif","width":469},"search_url":"/search?q\u003dGilbert+Baker\u0026oi\u003dddle\u0026ct\u003dgilbert-bakers-66th-birthday-6016396013076480","share_text":"Gilbert Baker\u0027s 66th birthday\nhttps://g.co/doodle/2ythp4","short_link":"//g.co/doodle/2ythp4","show_now_header_search_affordance":false,"show_now_header_share_button":true,"target_url":"/search?q\u003dGilbert+Baker\u0026oi\u003dddle\u0026ct\u003dgilbert-bakers-66th-birthday-6016396013076480","time_to_live_ms":498337149000}}
\ No newline at end of file
This diff is collapsed.
)]}'
{"ddljson":{"alt_text":"Happy Halloween!","doodle_type":"INTERACTIVE","fingerprint":"4438a87d","fullpage_interactive_url":"https://www.google.com/?fpdoodle\u003d1\u0026doodle\u003d28464230\u0026hl\u003den","gallery_url":"http://www.google.com/doodles/halloween-2016?hl\u003den","header_layout":"LEGACY","id":28464230,"intent":"BUILTIN","large_cta_image":{"height":230,"image_id":5910974510923776,"image_name":"StaticCTA","is_animated_gif":false,"slot":26,"url":"/logos/doodles/2016/halloween-2016-5643419163557888.5-scta.png","width":460},"large_image":{"height":220,"image_id":5066549580791808,"image_name":"LargeAnimatedWhiteCTA","is_animated_gif":true,"slot":27,"url":"/logos/doodles/2016/halloween-2016-5643419163557888-cta.gif","width":429},"screen_orientation":"LANDSCAPE","search_url":"/search?q\u003dHalloween\u0026oi\u003dddle\u0026ct\u003dhalloween-2016-5643419163557888\u0026hl\u003den","share_text":"Happy Halloween 2016! #GoogleDoodle\nhttps://g.co/doodle/vu3nqy","short_link":"//g.co/doodle/vu3nqy","show_now_header_search_affordance":true,"show_now_header_share_button":true,"target_url":"https://www.google.com/?fpdoodle\u003d1\u0026doodle\u003d28464230\u0026hl\u003den","time_to_live_ms":498337150000}}
\ No newline at end of file
This diff is collapsed.
)]}'
{"ddljson":{"alt_text":"Hedy Lamarr\u0027s 101st birthday","doodle_type":"VIDEO","fingerprint":"5a5c777a","fullpage_interactive_url":"https://www.google.com/?fpdoodle\u003d1\u0026doodle\u003d24101651\u0026hl\u003den","gallery_url":"http://www.google.com/doodles/hedy-lamarrs-101st-birthday?hl\u003den","header_layout":"LEGACY","id":24101651,"intent":"BUILTIN","large_cta_image":{"height":230,"image_id":5910974510923776,"image_name":"StaticCTA","is_animated_gif":false,"slot":26,"url":"/logos/doodles/2015/hedy-lamarrs-101st-birthday-5679746450980864.2-scta.png","width":409},"large_image":{"alternate_url":"https://lh3.googleusercontent.com/N3wSsA1KchbJFobk3TmC0SOeSoGhwSyQPlISjqSUMpBN1frPmUCJJcZmPat7uZUguaNt_x5qbbdBgsHLMSQKy_oK5UbB5dn_i_6TtsiK","height":230,"image_id":5066549580791808,"image_name":"LargeAnimatedWhiteCTA","is_animated_gif":true,"slot":27,"url":"/logos/doodles/2015/hedy-lamarrs-101st-birthday-5679746450980864.2-hp.gif","width":409},"search_url":"/search?q\u003dHedy+Lamarr\u0026oi\u003dddle\u0026ct\u003dhedy-lamarrs-101st-birthday-5679746450980864\u0026hl\u003den","share_text":"Actress and Inventor Hedy Lamarr\u0027s 101st birthday #GoogleDoodle\nhttps://g.co/doodle/pzx7av","short_link":"//g.co/doodle/pzx7av","show_now_header_search_affordance":true,"show_now_header_share_button":true,"target_url":"//www.youtube.com/watch?v\u003dZ0gu2QhV1dc","time_to_live_ms":498337150000}}
\ No newline at end of file
This diff is collapsed.
)]}'
{"ddljson":{"alt_text":"155th Anniversary of the Pony Express (Test Interactive Doodle)","doodle_type":"INTERACTIVE","fingerprint":"de2ab303","fullpage_interactive_url":"https://www.google.com/?fpdoodle\u003d1\u0026doodle\u003d18511013\u0026hl\u003den","gallery_url":"//www.google.com/doodles/155th-anniversary-of-the-pony-express","header_layout":"LEGACY","id":18511013,"intent":"JAR","large_image":{"alternate_url":"http://lh3.googleusercontent.com/YYmuJ3RPEk93WIRxZ8EmrJVA4vHDZX2jIREH_Sc5G6KT8pnkG7kQB24NR_6HsB5wl50VpCSIYzlcIqZjjFapdQwSldLfmip27tLja1dZ","height":225,"image_id":5066549580791808,"image_name":"Large","is_animated_gif":false,"slot":27,"url":"/logos/doodles/2015/155th-anniversary-of-the-pony-express-5959391580782592.2-hp.jpg","width":400},"mobile_native":{"jar_object_name":"particles"},"screen_orientation":"LANDSCAPE","search_url":"/search?q\u003dwhen+was+the+first+mail+pouch+delivered+by+the+pony+express\u0026oi\u003dddle\u0026ct\u003d155th-anniversary-of-the-pony-express-5959391580782592\u0026hl\u003den","share_text":"Join the Pony Express to deliver 100 letters! #GoogleDoodle\nhttps://g.co/doodle/7j375g","short_link":"//g.co/doodle/7j375g","show_now_header_search_affordance":true,"show_now_header_share_button":true,"target_url":"/search?q\u003dwhen+was+the+first+mail+pouch+delivered+by+the+pony+express\u0026oi\u003dddle\u0026ct\u003d155th-anniversary-of-the-pony-express-5959391580782592\u0026hl\u003den","time_to_live_ms":498337151000}}
\ No newline at end of file
#!/bin/bash
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# This script downloads a number of test doodle API responses with different
# user agents. For each response, it also extracts the fingerprint of the
# inlined image data, and calls the API again with the fingerprint value in a
# query param, to get the response without inlined image data.
# sed command to extract the fingerprint value (abc123 from
# "fingerprint":"abc123") from a given ddljson output.
FINGERPRINT_PATTERN='s/.*"fingerprint":"\([a-z0-9]*\)".*/\1/p'
# Absolute path to this folder. Output will be written there.
OUTPATH=$( cd $(dirname $0) ; pwd )
API_URL="https://www.google.com/async/ddljson?async=ntp:1"
UA_ANDROID="Mozilla/5.0%20(Linux;%20Android%206.0.1;%20Nexus%207%20Build/M4B30Q\
)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/57.0.2987.19%20Safari\
/537.36"
UA_IOS="Mozilla/5.0%20%28iPhone%3B%20CPU%20iPhone%20OS%2011_0%20like%20Mac%20OS\
%20X%29%20AppleWebKit/603.1.30%20%28KHTML%2C%20like%20Gecko%29%20CriOS/60.0.311\
2.72%20Mobile/15A5304i%20Safari/602.1"
for i in `seq 1 4`; do
DOODLE_PARAM="data_push_epoch=200000000$i"
# Android UA.
URL="$API_URL&useragent=$UA_ANDROID&$DOODLE_PARAM"
curl $URL > $OUTPATH/ddljson\_android$i.json
# Android UA, with fingerprint.
FINGERPRINT=`sed -n $FINGERPRINT_PATTERN $OUTPATH/ddljson\_android$i.json`
URL="$API_URL,es_dfp:$FINGERPRINT&useragent=$UA_ANDROID&$DOODLE_PARAM"
curl $URL > $OUTPATH/ddljson\_android$i\_fp.json
# iOS UA.
URL="$API_URL&useragent=$UA_IOS&$DOODLE_PARAM"
curl $URL > $OUTPATH/ddljson\_ios$i.json
# iOS UA, with fingerprint.
FINGERPRINT=`sed -n $FINGERPRINT_PATTERN $OUTPATH/ddljson\_ios$i.json`
URL="$API_URL,es_dfp:$FINGERPRINT&useragent=$UA_IOS&$DOODLE_PARAM"
curl $URL > $OUTPATH/ddljson\_ios$i\_fp.json
done
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment