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

Side by Side Diff: components/cronet/android/test/native_test_server.cc

Issue 1376593007: SSL in EmbeddedTestServer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Typo fix. Created 5 years, 1 month 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 "native_test_server.h" 5 #include "native_test_server.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // supports Sdch encoding. E.g. /sdch/index?q=LeQxM80O will make the server 49 // supports Sdch encoding. E.g. /sdch/index?q=LeQxM80O will make the server
50 // responds with "Get-Dictionary: /sdch/dict/LeQxM80O". 50 // responds with "Get-Dictionary: /sdch/dict/LeQxM80O".
51 const char kSdchPath[] = "/sdch/index"; 51 const char kSdchPath[] = "/sdch/index";
52 // Path that returns encoded response if client has the right dictionary. 52 // Path that returns encoded response if client has the right dictionary.
53 const char kSdchTestPath[] = "/sdch/test"; 53 const char kSdchTestPath[] = "/sdch/test";
54 // Path where dictionaries are stored. 54 // Path where dictionaries are stored.
55 const char kSdchDictPath[] = "/sdch/dict/"; 55 const char kSdchDictPath[] = "/sdch/dict/";
56 56
57 net::test_server::EmbeddedTestServer* g_test_server = nullptr; 57 net::test_server::EmbeddedTestServer* g_test_server = nullptr;
58 58
59 class CustomHttpResponse : public net::test_server::HttpResponse { 59 scoped_ptr<net::test_server::RawHttpResponse> ConstructResponseBasedOnFile(
60 public:
61 CustomHttpResponse(const std::string& headers, const std::string& contents)
62 : headers_(headers), contents_(contents) {}
63
64 std::string ToResponseString() const override {
65 return headers_ + "\r\n" + contents_;
66 }
67
68 void AddHeader(const std::string& key_value_pair) {
69 headers_.append(base::StringPrintf("%s\r\n", key_value_pair.c_str()));
70 }
71
72 private:
73 std::string headers_;
74 std::string contents_;
75
76 DISALLOW_COPY_AND_ASSIGN(CustomHttpResponse);
77 };
78
79 scoped_ptr<CustomHttpResponse> ConstructResponseBasedOnFile(
80 const base::FilePath& file_path) { 60 const base::FilePath& file_path) {
81 std::string file_contents; 61 std::string file_contents;
82 bool read_file = base::ReadFileToString(file_path, &file_contents); 62 bool read_file = base::ReadFileToString(file_path, &file_contents);
83 DCHECK(read_file); 63 DCHECK(read_file);
84 base::FilePath headers_path( 64 base::FilePath headers_path(
85 file_path.AddExtension(FILE_PATH_LITERAL("mock-http-headers"))); 65 file_path.AddExtension(FILE_PATH_LITERAL("mock-http-headers")));
86 std::string headers_contents; 66 std::string headers_contents;
87 bool read_headers = base::ReadFileToString(headers_path, &headers_contents); 67 bool read_headers = base::ReadFileToString(headers_path, &headers_contents);
88 DCHECK(read_headers); 68 DCHECK(read_headers);
89 scoped_ptr<CustomHttpResponse> http_response( 69 scoped_ptr<net::test_server::RawHttpResponse> http_response(
90 new CustomHttpResponse(headers_contents, file_contents)); 70 new net::test_server::RawHttpResponse(headers_contents, file_contents));
91 return http_response.Pass(); 71 return http_response.Pass();
92 } 72 }
93 73
94 scoped_ptr<net::test_server::HttpResponse> NativeTestServerRequestHandler( 74 scoped_ptr<net::test_server::HttpResponse> NativeTestServerRequestHandler(
95 const net::test_server::HttpRequest& request) { 75 const net::test_server::HttpRequest& request) {
96 DCHECK(g_test_server); 76 DCHECK(g_test_server);
97 scoped_ptr<net::test_server::BasicHttpResponse> response( 77 scoped_ptr<net::test_server::BasicHttpResponse> response(
98 new net::test_server::BasicHttpResponse()); 78 new net::test_server::BasicHttpResponse());
99 response->set_content_type("text/plain"); 79 response->set_content_type("text/plain");
100 80
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 const net::test_server::HttpRequest& request) { 123 const net::test_server::HttpRequest& request) {
144 DCHECK(g_test_server); 124 DCHECK(g_test_server);
145 base::FilePath dir_path; 125 base::FilePath dir_path;
146 bool get_data_dir = base::android::GetDataDirectory(&dir_path); 126 bool get_data_dir = base::android::GetDataDirectory(&dir_path);
147 DCHECK(get_data_dir); 127 DCHECK(get_data_dir);
148 dir_path = dir_path.Append(FILE_PATH_LITERAL("test")); 128 dir_path = dir_path.Append(FILE_PATH_LITERAL("test"));
149 129
150 if (base::StartsWith(request.relative_url, kSdchPath, 130 if (base::StartsWith(request.relative_url, kSdchPath,
151 base::CompareCase::SENSITIVE)) { 131 base::CompareCase::SENSITIVE)) {
152 base::FilePath file_path = dir_path.Append("sdch/index"); 132 base::FilePath file_path = dir_path.Append("sdch/index");
153 scoped_ptr<CustomHttpResponse> response = 133 scoped_ptr<net::test_server::RawHttpResponse> response =
154 ConstructResponseBasedOnFile(file_path).Pass(); 134 ConstructResponseBasedOnFile(file_path).Pass();
155 // Check for query params to see which dictionary to advertise. 135 // Check for query params to see which dictionary to advertise.
156 // For instance, ?q=dictionaryA will make the server advertise dictionaryA. 136 // For instance, ?q=dictionaryA will make the server advertise dictionaryA.
157 GURL url = g_test_server->GetURL(request.relative_url); 137 GURL url = g_test_server->GetURL(request.relative_url);
158 std::string dictionary; 138 std::string dictionary;
159 if (!net::GetValueForKeyInQuery(url, "q", &dictionary)) { 139 if (!net::GetValueForKeyInQuery(url, "q", &dictionary)) {
160 CHECK(false) << "dictionary is not found in query params of " 140 CHECK(false) << "dictionary is not found in query params of "
161 << request.relative_url; 141 << request.relative_url;
162 } 142 }
163 auto accept_encoding_header = request.headers.find("Accept-Encoding"); 143 auto accept_encoding_header = request.headers.find("Accept-Encoding");
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 #else 319 #else
340 return JNI_FALSE; 320 return JNI_FALSE;
341 #endif 321 #endif
342 } 322 }
343 323
344 bool RegisterNativeTestServer(JNIEnv* env) { 324 bool RegisterNativeTestServer(JNIEnv* env) {
345 return RegisterNativesImpl(env); 325 return RegisterNativesImpl(env);
346 } 326 }
347 327
348 } // namespace cronet 328 } // namespace cronet
OLDNEW
« no previous file with comments | « chrome/browser/apps/guest_view/web_view_browsertest.cc ('k') | content/public/test/browser_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698