Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2039)

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_tamper_detection_unittest.cc

Issue 1546143002: Switch to standard integer types in components/, part 1 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_tamp er_detection.h" 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_tamp er_detection.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include <algorithm> 10 #include <algorithm>
8 #include <map> 11 #include <map>
9 #include <string> 12 #include <string>
10 #include <vector> 13 #include <vector>
11 14
12 #include "base/base64.h" 15 #include "base/base64.h"
16 #include "base/macros.h"
13 #include "base/md5.h" 17 #include "base/md5.h"
14 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
17 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
18 #include "base/test/histogram_tester.h" 22 #include "base/test/histogram_tester.h"
23 #include "build/build_config.h"
19 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
20 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h" 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h"
21 #include "net/http/http_response_headers.h" 26 #include "net/http/http_response_headers.h"
22 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
23 28
24 #if defined(OS_ANDROID) 29 #if defined(OS_ANDROID)
25 #include "base/android/jni_android.h" 30 #include "base/android/jni_android.h"
26 #include "net/android/network_library.h" 31 #include "net/android/network_library.h"
27 #endif 32 #endif
28 33
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 466
462 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label; 467 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label;
463 } 468 }
464 } 469 }
465 470
466 // Tests function ValidateContentLength. 471 // Tests function ValidateContentLength.
467 TEST_F(DataReductionProxyTamperDetectionTest, ContentLength) { 472 TEST_F(DataReductionProxyTamperDetectionTest, ContentLength) {
468 struct { 473 struct {
469 std::string label; 474 std::string label;
470 std::string received_fingerprint; 475 std::string received_fingerprint;
471 int64 actual_content_length; 476 int64_t actual_content_length;
472 int64 expected_original_content_length; 477 int64_t expected_original_content_length;
473 bool expected_tampered_with; 478 bool expected_tampered_with;
474 } test[] = { 479 } test[] = {
475 { 480 {
476 "Checks the case fingerprint matches actual content length.", 481 "Checks the case fingerprint matches actual content length.",
477 "12345", 482 "12345",
478 12345, 483 12345,
479 12345, 484 12345,
480 false, 485 false,
481 }, 486 },
482 { 487 {
483 "Checks case that response got modified.", 488 "Checks case that response got modified.",
484 "12345", 489 "12345",
485 12346, 490 12346,
486 12345, 491 12345,
487 true, 492 true,
488 }, 493 },
489 }; 494 };
490 495
491 for (size_t i = 0; i < arraysize(test); ++i) { 496 for (size_t i = 0; i < arraysize(test); ++i) {
492 std::string raw_headers("HTTP/1.1 200 OK\n"); 497 std::string raw_headers("HTTP/1.1 200 OK\n");
493 HeadersToRaw(&raw_headers); 498 HeadersToRaw(&raw_headers);
494 scoped_refptr<net::HttpResponseHeaders> headers( 499 scoped_refptr<net::HttpResponseHeaders> headers(
495 new net::HttpResponseHeaders(raw_headers)); 500 new net::HttpResponseHeaders(raw_headers));
496 501
497 DataReductionProxyTamperDetection tamper_detection(headers.get(), true, 0); 502 DataReductionProxyTamperDetection tamper_detection(headers.get(), true, 0);
498 503
499 int64 original_content_length; 504 int64_t original_content_length;
500 bool tampered = tamper_detection.ValidateContentLength( 505 bool tampered = tamper_detection.ValidateContentLength(
501 test[i].received_fingerprint, 506 test[i].received_fingerprint,
502 test[i].actual_content_length, 507 test[i].actual_content_length,
503 &original_content_length); 508 &original_content_length);
504 509
505 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label; 510 EXPECT_EQ(test[i].expected_tampered_with, tampered) << test[i].label;
506 EXPECT_EQ(test[i].expected_original_content_length, 511 EXPECT_EQ(test[i].expected_original_content_length,
507 original_content_length) << test[i].label; 512 original_content_length) << test[i].label;
508 } 513 }
509 } 514 }
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 test.compression_ratio, 1); 766 test.compression_ratio, 1);
762 } 767 }
763 } 768 }
764 } 769 }
765 770
766 // Tests main function DetectAndReport. 771 // Tests main function DetectAndReport.
767 TEST_F(DataReductionProxyTamperDetectionTest, DetectAndReport) { 772 TEST_F(DataReductionProxyTamperDetectionTest, DetectAndReport) {
768 struct { 773 struct {
769 std::string label; 774 std::string label;
770 std::string raw_header; 775 std::string raw_header;
771 int64 content_length; 776 int64_t content_length;
772 bool expected_tampered_with; 777 bool expected_tampered_with;
773 } test[] = { 778 } test[] = {
774 { 779 {
775 "Check no fingerprint added case.", 780 "Check no fingerprint added case.",
776 "HTTP/1.1 200 OK\n" 781 "HTTP/1.1 200 OK\n"
777 "Via: a1, b2, 1.1 Chrome-Compression-Proxy\n" 782 "Via: a1, b2, 1.1 Chrome-Compression-Proxy\n"
778 "Content-Length: 12345\n" 783 "Content-Length: 12345\n"
779 "Chrome-Proxy: bypass=0\n", 784 "Chrome-Proxy: bypass=0\n",
780 12345, 785 12345,
781 false, 786 false,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 new net::HttpResponseHeaders(raw_headers)); 841 new net::HttpResponseHeaders(raw_headers));
837 842
838 EXPECT_EQ( 843 EXPECT_EQ(
839 test[i].expected_tampered_with, 844 test[i].expected_tampered_with,
840 DataReductionProxyTamperDetection::DetectAndReport( 845 DataReductionProxyTamperDetection::DetectAndReport(
841 headers.get(), true, test[i].content_length)) << test[i].label; 846 headers.get(), true, test[i].content_length)) << test[i].label;
842 } 847 }
843 } 848 }
844 849
845 } // namespace 850 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698