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

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

Issue 2146753002: Android: Remove unneeded RegisterNatives() calls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Android: Don't require RegisterNatives if there are none Created 4 years, 4 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> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 #include <map> 11 #include <map>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/base64.h" 15 #include "base/base64.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/md5.h" 17 #include "base/md5.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
20 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
21 #include "base/test/histogram_tester.h" 21 #include "base/test/histogram_tester.h"
22 #include "build/build_config.h" 22 #include "build/build_config.h"
23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 23 #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_test_utils.h" 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h"
25 #include "net/http/http_response_headers.h" 25 #include "net/http/http_response_headers.h"
26 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
27 27
28 #if defined(OS_ANDROID)
29 #include "base/android/jni_android.h"
30 #include "net/android/network_library.h"
31 #endif
32
33 namespace { 28 namespace {
34 29
35 // Calcuates MD5 hash value for a string and then base64 encode it. Testcases 30 // Calcuates MD5 hash value for a string and then base64 encode it. Testcases
36 // contain expected fingerprint in plain text, which needs to be encoded before 31 // contain expected fingerprint in plain text, which needs to be encoded before
37 // comparison. 32 // comparison.
38 std::string GetEncoded(const std::string& input) { 33 std::string GetEncoded(const std::string& input) {
39 base::MD5Digest digest; 34 base::MD5Digest digest;
40 base::MD5Sum(input.c_str(), input.size(), &digest); 35 base::MD5Sum(input.c_str(), input.size(), &digest);
41 std::string base64encoded; 36 std::string base64encoded;
42 base::Base64Encode( 37 base::Base64Encode(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 return ret; 71 return ret;
77 size_t now = 0; 72 size_t now = 0;
78 size_t next; 73 size_t next;
79 while ((next = values.find(",", now)) != std::string::npos) { 74 while ((next = values.find(",", now)) != std::string::npos) {
80 ret.push_back(values.substr(now, next - now)); 75 ret.push_back(values.substr(now, next - now));
81 now = next + 1; 76 now = next + 1;
82 } 77 }
83 return ret; 78 return ret;
84 } 79 }
85 80
86 void InitEnv() {
87 #if defined(OS_ANDROID)
88 JNIEnv* env = base::android::AttachCurrentThread();
89 static bool inited = false;
90 if (!inited) {
91 net::android::RegisterNetworkLibrary(env);
92 inited = true;
93 }
94 #endif
95 }
96
97 } // namespace 81 } // namespace
98 82
99 namespace data_reduction_proxy { 83 namespace data_reduction_proxy {
100 84
101 using DataReductionProxyTamperDetectionTest = testing::Test; 85 using DataReductionProxyTamperDetectionTest = testing::Test;
102 86
103 // Tests function ValidateChromeProxyHeader. 87 // Tests function ValidateChromeProxyHeader.
104 TEST_F(DataReductionProxyTamperDetectionTest, ChromeProxy) { 88 TEST_F(DataReductionProxyTamperDetectionTest, ChromeProxy) {
105 // |received_fingerprint| is not the actual fingerprint from Data Reduction 89 // |received_fingerprint| is not the actual fingerprint from Data Reduction
106 // Proxy, instead, the base64 encoded field is in plain text (within "[]") 90 // Proxy, instead, the base64 encoded field is in plain text (within "[]")
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 "header3: header_3\n" 805 "header3: header_3\n"
822 "Chrome-Proxy: fcl=12345, " 806 "Chrome-Proxy: fcl=12345, "
823 "foh=[header_1,;header_2,;header_3,;]|header1|header2|header3, fvia=0, " 807 "foh=[header_1,;header_2,;header_3,;]|header1|header2|header3, fvia=0, "
824 "fcp=[fcl=12345,foh=[header_1,;header_2,;header_3,;]|" 808 "fcp=[fcl=12345,foh=[header_1,;header_2,;header_3,;]|"
825 "header1|header2|header3,fvia=0,]\n", 809 "header1|header2|header3,fvia=0,]\n",
826 123, 810 123,
827 true, 811 true,
828 }, 812 },
829 }; 813 };
830 814
831 InitEnv();
832
833 for (size_t i = 0; i < arraysize(test); ++i) { 815 for (size_t i = 0; i < arraysize(test); ++i) {
834 std::string raw_headers(test[i].raw_header); 816 std::string raw_headers(test[i].raw_header);
835 ReplaceWithEncodedString(&raw_headers); 817 ReplaceWithEncodedString(&raw_headers);
836 HeadersToRaw(&raw_headers); 818 HeadersToRaw(&raw_headers);
837 scoped_refptr<net::HttpResponseHeaders> headers( 819 scoped_refptr<net::HttpResponseHeaders> headers(
838 new net::HttpResponseHeaders(raw_headers)); 820 new net::HttpResponseHeaders(raw_headers));
839 821
840 EXPECT_EQ( 822 EXPECT_EQ(
841 test[i].expected_tampered_with, 823 test[i].expected_tampered_with,
842 DataReductionProxyTamperDetection::DetectAndReport( 824 DataReductionProxyTamperDetection::DetectAndReport(
843 headers.get(), true, test[i].content_length)) << test[i].label; 825 headers.get(), true, test[i].content_length)) << test[i].label;
844 } 826 }
845 } 827 }
846 828
847 } // namespace data_reduction_proxy 829 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698