| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_FACTORY_H_ | 5 #ifndef WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_FACTORY_H_ |
| 6 #define WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_FACTORY_H_ | 6 #define WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_FACTORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 class WebURLLoaderMock; | 21 class WebURLLoaderMock; |
| 22 | 22 |
| 23 // A factory that creates WebURLLoaderMock to simulate resource loading in | 23 // A factory that creates WebURLLoaderMock to simulate resource loading in |
| 24 // tests. | 24 // tests. |
| 25 // You register files for specific URLs, the content of the file is then served | 25 // You register files for specific URLs, the content of the file is then served |
| 26 // when these URLs are loaded. | 26 // when these URLs are loaded. |
| 27 // In order to serve the asynchronous requests, you need to invoke | 27 // In order to serve the asynchronous requests, you need to invoke |
| 28 // ServeAsynchronousRequest. | 28 // ServeAsynchronousRequest. |
| 29 class WebURLLoaderMockFactory { | 29 class WebURLLoaderMockFactory { |
| 30 public: | 30 public: |
| 31 WebURLLoaderMockFactory() {} | 31 WebURLLoaderMockFactory(); |
| 32 virtual ~WebURLLoaderMockFactory() {} | 32 virtual ~WebURLLoaderMockFactory(); |
| 33 | 33 |
| 34 // Called by TestWebKitClient to create a WebURLLoader. | 34 // Called by TestWebKitClient to create a WebURLLoader. |
| 35 // Non-mocked request are forwarded to |default_loader| which should not be | 35 // Non-mocked request are forwarded to |default_loader| which should not be |
| 36 // NULL. | 36 // NULL. |
| 37 virtual WebKit::WebURLLoader* CreateURLLoader( | 37 virtual WebKit::WebURLLoader* CreateURLLoader( |
| 38 WebKit::WebURLLoader* default_loader); | 38 WebKit::WebURLLoader* default_loader); |
| 39 | 39 |
| 40 // Registers a response and the contents to be served when the specified URL | 40 // Registers a response and the contents to be served when the specified URL |
| 41 // is loaded. | 41 // is loaded. |
| 42 void RegisterURL(const WebKit::WebURL& url, | 42 void RegisterURL(const WebKit::WebURL& url, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 60 WebKit::WebURLResponse* response, | 60 WebKit::WebURLResponse* response, |
| 61 WebKit::WebURLError* error, | 61 WebKit::WebURLError* error, |
| 62 WebKit::WebData* data); | 62 WebKit::WebData* data); |
| 63 void LoadAsynchronouly(const WebKit::WebURLRequest& request, | 63 void LoadAsynchronouly(const WebKit::WebURLRequest& request, |
| 64 WebURLLoaderMock* loader); | 64 WebURLLoaderMock* loader); |
| 65 | 65 |
| 66 // Removes the loader from the list of pending loaders. | 66 // Removes the loader from the list of pending loaders. |
| 67 void CancelLoad(WebURLLoaderMock* loader); | 67 void CancelLoad(WebURLLoaderMock* loader); |
| 68 | 68 |
| 69 private: | 69 private: |
| 70 struct ResponseInfo { | 70 struct ResponseInfo; |
| 71 WebKit::WebURLResponse response; | |
| 72 FilePath file_path; | |
| 73 }; | |
| 74 | 71 |
| 75 // Loads the specified request and populates the response, error and data | 72 // Loads the specified request and populates the response, error and data |
| 76 // accordingly. | 73 // accordingly. |
| 77 void LoadRequest(const WebKit::WebURLRequest& request, | 74 void LoadRequest(const WebKit::WebURLRequest& request, |
| 78 WebKit::WebURLResponse* response, | 75 WebKit::WebURLResponse* response, |
| 79 WebKit::WebURLError* error, | 76 WebKit::WebURLError* error, |
| 80 WebKit::WebData* data); | 77 WebKit::WebData* data); |
| 81 | 78 |
| 82 // Reads |m_filePath| and puts its content in |data|. | 79 // Reads |m_filePath| and puts its content in |data|. |
| 83 // Returns true if it successfully read the file. | 80 // Returns true if it successfully read the file. |
| 84 static bool ReadFile(const FilePath& file_path, WebKit::WebData* data); | 81 static bool ReadFile(const FilePath& file_path, WebKit::WebData* data); |
| 85 | 82 |
| 86 // The loaders that have not being served data yet. | 83 // The loaders that have not being served data yet. |
| 87 typedef std::map<WebURLLoaderMock*, WebKit::WebURLRequest> LoaderToRequestMap; | 84 typedef std::map<WebURLLoaderMock*, WebKit::WebURLRequest> LoaderToRequestMap; |
| 88 LoaderToRequestMap pending_loaders_; | 85 LoaderToRequestMap pending_loaders_; |
| 89 | 86 |
| 90 // Table of the registered URLs and the responses that they should receive. | 87 // Table of the registered URLs and the responses that they should receive. |
| 91 typedef std::map<WebKit::WebURL, ResponseInfo> URLToResponseMap; | 88 typedef std::map<WebKit::WebURL, ResponseInfo> URLToResponseMap; |
| 92 URLToResponseMap url_to_reponse_info_; | 89 URLToResponseMap url_to_reponse_info_; |
| 93 | 90 |
| 94 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderMockFactory); | 91 DISALLOW_COPY_AND_ASSIGN(WebURLLoaderMockFactory); |
| 95 }; | 92 }; |
| 96 | 93 |
| 97 #endif // WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_FACTORY_H_ | 94 #endif // WEBKIT_SUPPORT_WEBURL_LOADER_MOCK_FACTORY_H_ |
| 98 | 95 |
| OLD | NEW |