1 // Copyright 2016 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_CRONET_TESTING_TEST_SERVER_TEST_SERVER_H_ 6 #define COMPONENTS_CRONET_TESTING_TEST_SERVER_TEST_SERVER_H_ 7 8 #include <string> 9 10 namespace base { 11 class FilePath; 12 } // namespace base 13 14 namespace cronet { 15 16 class TestServer { 17 public: 18 // Starts the server serving files from default test data directory. 19 // Returns true if started, false if server is already running. 20 static bool Start(); 21 // Starts the server serving files from |test_files_root| directory. 22 // Returns true if started, false if server is already running. 23 static bool StartServeFilesFromDirectory( 24 const base::FilePath& test_files_root); 25 // Shuts down the server. 26 static void Shutdown(); 27 28 // Returns port number of the server. 29 static int GetPort(); 30 // Returns host:port string of the server. 31 static std::string GetHostPort(); 32 33 // Returns URL which responds with the body "The quick brown fox jumps over 34 // the lazy dog". 35 static std::string GetSimpleURL(); 36 // Returns URL which respond with echo of the method in response body. 37 static std::string GetEchoMethodURL(); 38 // Returns URL which respond with echo of header with |header_name| in 39 // response body. 40 static std::string GetEchoHeaderURL(const std::string& header_name); 41 // Returns URL which responds with "The quick brown fox jumps over the lazy 42 // dog" in specified encoding. 43 static std::string GetUseEncodingURL(const std::string& encoding_name); 44 // Returns URL which respond with setting cookie to |cookie_line| and echo it 45 // in response body. 46 static std::string GetSetCookieURL(const std::string& cookie_line); 47 // Returns URL which echoes all request headers. 48 static std::string GetEchoAllHeadersURL(); 49 // Returns URL which echoes data in a request body. 50 static std::string GetEchoRequestBodyURL(); 51 // Returns URL which redirects to URL that echoes data in a request body. 52 static std::string GetRedirectToEchoBodyURL(); 53 // Returns a URL that the server will return an Exabyte of data. 54 static std::string GetExabyteResponseURL(); 55 // Prepares response and returns URL which respond with |data_size| of bytes 56 // in response body. 57 static std::string PrepareBigDataURL(size_t data_size); 58 // Releases response created by PrepareBigDataURL(). 59 static void ReleaseBigDataURL(); 60 61 // The following URLs will make TestServer serve a response based on 62 // the contents of the corresponding file and its mock-http-headers file. 63 64 // Returns URL which responds with content of file at |file_path|. 65 static std::string GetFileURL(const std::string& file_path); 66 67 // Returns URL which responds with plain/text success. GetSuccessURL()68 static std::string GetSuccessURL() { return GetFileURL("/success.txt"); } 69 70 // Returns URL which redirects to plain/text success. GetRedirectURL()71 static std::string GetRedirectURL() { return GetFileURL("/redirect.html"); } 72 73 // Returns URL which redirects to redirect to plain/text success. GetMultiRedirectURL()74 static std::string GetMultiRedirectURL() { 75 return GetFileURL("/multiredirect.html"); 76 } 77 78 // Returns URL which responds with status code 404 - page not found.. GetNotFoundURL()79 static std::string GetNotFoundURL() { return GetFileURL("/notfound.html"); } 80 }; 81 82 } // namespace cronet 83 84 #endif // COMPONENTS_CRONET_TESTING_TEST_SERVER_TEST_SERVER_H_ 85