diff options
| author | xingx <xingx@chromium.org> | 2015-12-06 15:53:00 -0800 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2015-12-06 23:53:51 +0000 |
| commit | bf2a7d01ad2e91dcbb6bfca4d7e48897c400cd3b (patch) | |
| tree | 4a2c41d18c7734a9c0602a63d36fe5f9ca9348af | |
| parent | 44929cdb67189f2715c90b1a17bc29ccc2276991 (diff) | |
| download | chromium_src-bf2a7d01ad2e91dcbb6bfca4d7e48897c400cd3b.zip chromium_src-bf2a7d01ad2e91dcbb6bfca4d7e48897c400cd3b.tar.gz chromium_src-bf2a7d01ad2e91dcbb6bfca4d7e48897c400cd3b.tar.bz2 | |
Tamper Detection - Adding Tamper Detection Results for Video Objects
Report responses of video MIME type separately. This includes two new reports: 1) report number of video responses whose ContentLength header has been tampered with, also report the corresponding compression ratio; 2) report the total number of video responses that has been checked for tamper detection.
Also added unittest for compression ratio report.
BUG=381907
Review URL: https://codereview.chromium.org/1492753002
Cr-Commit-Position: refs/heads/master@{#363387}
4 files changed, 124 insertions, 35 deletions
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.cc index eaaf44e..572cce5 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.cc @@ -250,6 +250,10 @@ void DataReductionProxyTamperDetection::ReportUMAForTamperDetectionCount( "DataReductionProxy.HeaderTamperDetectionHTTP_Image_500KB", carrier_id_); } + } else if (net::MatchesMimeType("video/*", mime_type)) { + REPORT_TAMPER_DETECTION_UMA( + scheme_is_https_, "DataReductionProxy.HeaderTamperDetectionHTTPS_Video", + "DataReductionProxy.HeaderTamperDetectionHTTP_Video", carrier_id_); } } @@ -490,6 +494,12 @@ void DataReductionProxyTamperDetection::ReportUMAForContentLength( REPORT_TAMPER_DETECTION_UMA_COMPRESSION_RATIO( scheme_is_https_, "_Image_500KB", compression_ratio); } + } else if (net::MatchesMimeType("video/*", mime_type)) { + REPORT_TAMPER_DETECTION_UMA_AND_COMPRESSION_RATIO( + scheme_is_https_, + "DataReductionProxy.HeaderTamperedHTTPS_ContentLength_Video", + "DataReductionProxy.HeaderTamperedHTTP_ContentLength_Video", + carrier_id_, "_Video", compression_ratio); } else { REPORT_TAMPER_DETECTION_UMA( scheme_is_https_, diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.h b/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.h index 03611d6..b497712 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.h +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.h @@ -105,6 +105,8 @@ class DataReductionProxyTamperDetection { HistogramCount); FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, DetectAndReport); + FRIEND_TEST_ALL_PREFIXES(DataReductionProxyTamperDetectionTest, + CompressionRatio); // Reports UMA for the numbers of responses with valid fingerprints, separated // by MIME type. diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection_unittest.cc index cdda92c..fff0914 100644 --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection_unittest.cc +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection_unittest.cc @@ -4,9 +4,9 @@ #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection.h" -#include <string.h> #include <algorithm> #include <map> +#include <string> #include <vector> #include "base/base64.h" @@ -14,6 +14,7 @@ #include "base/memory/scoped_ptr.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" +#include "base/strings/stringprintf.h" #include "base/test/histogram_tester.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers.h" #include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h" @@ -606,45 +607,35 @@ TEST_F(DataReductionProxyTamperDetectionTest, HistogramCount) { // Checks the correctness of histogram for Javascript {"HTTP/1.1 200 OK\n" "Content-Type: text/javascript\n", - "_JS", - -1, - ""}, + "_JS", -1, ""}, // Checks the correctness of histogram for CSS {"HTTP/1.1 200 OK\n" "Content-Type: text/css\n", - "_CSS", - -1, - ""}, + "_CSS", -1, ""}, // Checks the correctness of histogram for image {"HTTP/1.1 200 OK\n" "Content-Type: image/test\n", - "_Image", - 1, - "_Image_0_10KB"}, + "_Image", 1, "_Image_0_10KB"}, // Checks the correctness of histogram for GIF {"HTTP/1.1 200 OK\n" "Content-Type: image/gif\n", - "_Image_GIF", - 20 * 1024, - "_Image_10_100KB"}, + "_Image_GIF", 20 * 1024, "_Image_10_100KB"}, // Checks the correctness of histogram for JPG {"HTTP/1.1 200 OK\n" "Content-Type: image/jpeg\n", - "_Image_JPG", - 200 * 1024, - "_Image_100_500KB"}, + "_Image_JPG", 200 * 1024, "_Image_100_500KB"}, // Checks the correctness of histogram for PNG {"HTTP/1.1 200 OK\n" "Content-Type: image/png\n", - "_Image_PNG", - 600 * 1024, - "_Image_500KB"}, + "_Image_PNG", 600 * 1024, "_Image_500KB"}, // Checks the correctness of histogram for WebP {"HTTP/1.1 200 OK\n" "Content-Type: image/webp\n", - "_Image_WEBP", - -1, - ""}, + "_Image_WEBP", -1, ""}, + // Checks the correctness of histogram for Video + {"HTTP/1.1 200 OK\n" + "Content-Type: video/webm\n", + "_Video", -1, ""}, }; const int carrier_id = 100; @@ -665,37 +656,113 @@ TEST_F(DataReductionProxyTamperDetectionTest, HistogramCount) { tamper_detection.ReportUMAForTamperDetectionCount( test.original_content_length); histogram_tester.ExpectTotalCount( - std::string("DataReductionProxy.HeaderTamperDetectionHTTP") + - (https ? "S" : "") + test.histogram_name_suffix + "_Total", + base::StringPrintf("DataReductionProxy.HeaderTamperDetectionHTTP%s" + "%s_Total", + (https ? "S" : ""), + test.histogram_name_suffix.c_str()), 1); histogram_tester.ExpectUniqueSample( - std::string("DataReductionProxy.HeaderTamperDetectionHTTP") + - (https ? "S" : "") + test.histogram_name_suffix, + base::StringPrintf("DataReductionProxy.HeaderTamperDetectionHTTP%s" + "%s", + (https ? "S" : ""), + test.histogram_name_suffix.c_str()), carrier_id, 1); histogram_tester.ExpectTotalCount( - std::string("DataReductionProxy.HeaderTamperDetectionHTTP") + - (https ? "S" : "") + "_Total", + base::StringPrintf("DataReductionProxy.HeaderTamperDetectionHTTP%s" + "_Total", + (https ? "S" : "")), 1); histogram_tester.ExpectUniqueSample( - std::string("DataReductionProxy.HeaderTamperDetectionHTTP") + - (https ? "S" : ""), + base::StringPrintf("DataReductionProxy.HeaderTamperDetectionHTTP%s", + (https ? "S" : "")), carrier_id, 1); if (test.original_content_length != -1) { histogram_tester.ExpectTotalCount( - std::string("DataReductionProxy.HeaderTamperDetectionHTTP") + - (https ? "S" : "") + test.image_histogram_name_suffix + - "_Total", + base::StringPrintf("DataReductionProxy.HeaderTamperDetectionHTTP%s" + "%s_Total", + (https ? "S" : ""), + test.image_histogram_name_suffix.c_str()), 1); histogram_tester.ExpectUniqueSample( - std::string("DataReductionProxy.HeaderTamperDetectionHTTP") + - (https ? "S" : "") + test.image_histogram_name_suffix, + base::StringPrintf("DataReductionProxy.HeaderTamperDetectionHTTP%s" + "%s", + (https ? "S" : ""), + test.image_histogram_name_suffix.c_str()), carrier_id, 1); } } } } +// Tests function ReportUMAForContentLength, with the focus on compression +// ratio. +TEST_F(DataReductionProxyTamperDetectionTest, CompressionRatio) { + struct { + std::string raw_header; + std::string histogram_name_suffix; + int original_content_length; + int content_length; + int compression_ratio; + ; + } tests[] = { + // Checks the correctness of histogram for Video + {"HTTP/1.1 200 OK\n" + "Content-Type: video/webm\n", + "_Video", 1000, 800, 80}, + // Checks the correctness of histogram for JPEG + {"HTTP/1.1 200 OK\n" + "Content-Type: image/jpg\n", + "_Image_JPG", 1000, 1, 0}, + // Checks the correctness of histogram for PNG + {"HTTP/1.1 200 OK\n" + "Content-Type: image/png\n", + "_Image_PNG", 1000, 0, 0}, + // Checks the correctness of histogram for WebP + {"HTTP/1.1 200 OK\n" + "Content-Type: image/webp\n", + "_Image_WEBP", 1000, 5000, 500}, + }; + + const int carrier_id = 100; + + for (auto& test : tests) { + std::string raw_headers(test.raw_header); + HeadersToRaw(&raw_headers); + scoped_refptr<net::HttpResponseHeaders> headers( + new net::HttpResponseHeaders(raw_headers)); + + // Test HTTPS and HTTP separately. + int https_values[] = {true, false}; + for (auto https : https_values) { + base::HistogramTester histogram_tester; + + DataReductionProxyTamperDetection tamper_detection(headers.get(), https, + carrier_id); + tamper_detection.ReportUMAForContentLength(test.content_length, + test.original_content_length); + histogram_tester.ExpectTotalCount( + base::StringPrintf("DataReductionProxy.HeaderTamperedHTTP%s" + "_ContentLength%s_Total", + (https ? "S" : ""), + test.histogram_name_suffix.c_str()), + 1); + histogram_tester.ExpectUniqueSample( + base::StringPrintf("DataReductionProxy.HeaderTamperedHTTP%s" + "_ContentLength%s", + (https ? "S" : ""), + test.histogram_name_suffix.c_str()), + carrier_id, 1); + histogram_tester.ExpectUniqueSample( + base::StringPrintf("DataReductionProxy.HeaderTamperedHTTP%s" + "_CompressionRatio%s", + (https ? "S" : ""), + test.histogram_name_suffix.c_str()), + test.compression_ratio, 1); + } + } +} + // Tests main function DetectAndReport. TEST_F(DataReductionProxyTamperDetectionTest, DetectAndReport) { struct { diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 5ea6df9..dacd572 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -79775,6 +79775,9 @@ To add a new entry, add it with any value and run test to compute valid value. <suffix name="ContentLength_Image_WEBP" label="for each carrier, number of WebP image responses whose Content-Length header has been tampered with"/> + <suffix name="ContentLength_Video" + label="for each carrier, number of video responses whose Content-Length + header has been tampered with"/> <suffix name="CompressionRatio_Image" label="the histogram of compression ratio of images"/> <suffix name="CompressionRatio_Image_GIF" @@ -79785,6 +79788,8 @@ To add a new entry, add it with any value and run test to compute valid value. label="the histogram of compression ratio of PNG images"/> <suffix name="CompressionRatio_Image_WEBP" label="the histogram of compression ratio of WEBP images"/> + <suffix name="CompressionRatio_Video" + label="the histogram of compression ratio of videos"/> <suffix name="CompressionRatio_Image_0_10KB" label="the histogram of compression ratio of images whose sizes are in the range of 0-10KB"/> @@ -79838,6 +79843,8 @@ To add a new entry, add it with any value and run test to compute valid value. <affected-histogram name="DataReductionProxy.HeaderTamperDetectionHTTP_Image_WEBP"/> <affected-histogram name="DataReductionProxy.HeaderTamperDetectionHTTP_JS"/> + <affected-histogram + name="DataReductionProxy.HeaderTamperDetectionHTTP_Video"/> <affected-histogram name="DataReductionProxy.HeaderTamperDetectionHTTPS"/> <affected-histogram name="DataReductionProxy.HeaderTamperDetectionHTTPS_CSS"/> <affected-histogram @@ -79859,6 +79866,8 @@ To add a new entry, add it with any value and run test to compute valid value. <affected-histogram name="DataReductionProxy.HeaderTamperDetectionHTTPS_Image_WEBP"/> <affected-histogram name="DataReductionProxy.HeaderTamperDetectionHTTPS_JS"/> + <affected-histogram + name="DataReductionProxy.HeaderTamperDetectionHTTPS_Video"/> <affected-histogram name="DataReductionProxy.HeaderTamperDetectionPassHTTP"/> <affected-histogram name="DataReductionProxy.HeaderTamperDetectionPassHTTPS"/> <affected-histogram name="DataReductionProxy.HeaderTamperedHTTP_ChromeProxy"/> @@ -79903,6 +79912,7 @@ To add a new entry, add it with any value and run test to compute valid value. <suffix name="Image_JPG" label="JPG image count"/> <suffix name="Image_PNG" label="PNG image count"/> <suffix name="Image_WEBP" label="WEBP image count"/> + <suffix name="Video" label="Video count"/> <suffix name="Image_0_10KB" label="image counts of 0-10KB"/> <suffix name="Image_10_100KB" label="image counts of 10-100KB"/> <suffix name="Image_100_500KB" label="image counts of 100-500KB"/> |
