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"
13 FileBasedResponseProviderImpl::FileBasedResponseProviderImpl(
14 const base::FilePath
& 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] == '/') {
37 if (!url_path
.empty())
38 result
= result
.Append(url_path
);