Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ios / web / public / test / response_providers / file_based_response_provider_impl.cc
blobbb1b4c182e1fa933f9a3863835bb14e1afd89d8f
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/web/public/test/response_providers/file_based_response_provider_impl.h"
7 #include "base/files/file_util.h"
8 #include "ios/web/public/test/response_providers/response_provider.h"
9 #include "url/gurl.h"
11 namespace web {
13 FileBasedResponseProviderImpl::FileBasedResponseProviderImpl(
14 const base::FilePath& path)
15 : path_(path) {
18 FileBasedResponseProviderImpl::~FileBasedResponseProviderImpl() {
21 bool FileBasedResponseProviderImpl::CanHandleRequest(
22 const ResponseProvider::Request& request) {
23 return base::PathExists(BuildTargetPath(request.url));
26 base::FilePath FileBasedResponseProviderImpl::BuildTargetPath(const GURL& url) {
27 base::FilePath result = path_;
28 const std::string kLocalhostHost = "localhost";
29 if (url.host() != kLocalhostHost) {
30 result = result.Append(url.host());
32 std::string url_path = url.path();
33 // Remove the leading slash in url path.
34 if (url_path.length() > 0 && url_path[0] == '/') {
35 url_path.erase(0, 1);
37 if (!url_path.empty())
38 result = result.Append(url_path);
39 return result;
42 } // namespace web