OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_GLUE_UNITTEST_TEST_SERVER_H__ | 5 #ifndef WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__ |
6 #define WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__ | 6 #define WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__ |
7 | 7 |
8 #include "webkit/glue/resource_loader_bridge.h" | 8 #include "webkit/glue/resource_loader_bridge.h" |
9 #include "net/base/load_flags.h" | 9 #include "net/base/load_flags.h" |
10 #include "net/url_request/url_request_unittest.h" | 10 #include "net/url_request/url_request_unittest.h" |
11 | 11 |
12 using webkit_glue::ResourceLoaderBridge; | 12 using webkit_glue::ResourceLoaderBridge; |
13 | 13 |
14 // We need to use ResourceLoaderBridge to communicate with the testserver | 14 // We need to use ResourceLoaderBridge to communicate with the testserver |
15 // instead of using URLRequest directly because URLRequests need to be run on | 15 // instead of using URLRequest directly because URLRequests need to be run on |
16 // the test_shell's IO thread. | 16 // the test_shell's IO thread. |
17 class UnittestTestServer : public TestServer { | 17 class UnittestTestServer : public HTTPTestServer { |
18 public: | 18 protected: |
19 UnittestTestServer() : TestServer(TestServer::ManualInit()) { | 19 UnittestTestServer() { |
20 Init("localhost", 1337, L"webkit/data", std::wstring()); | |
21 } | 20 } |
22 | 21 |
23 ~UnittestTestServer() { | 22 public: |
24 Shutdown(); | 23 static UnittestTestServer* CreateServer() { |
| 24 UnittestTestServer* test_server = new UnittestTestServer(); |
| 25 if (!test_server->Init("localhost", 1337, L"webkit/data")) { |
| 26 delete test_server; |
| 27 return NULL; |
| 28 } |
| 29 return test_server; |
| 30 } |
| 31 |
| 32 virtual ~UnittestTestServer() { |
25 } | 33 } |
26 | 34 |
27 virtual bool MakeGETRequest(const std::string& page_name) { | 35 virtual bool MakeGETRequest(const std::string& page_name) { |
28 GURL url(TestServerPage(page_name)); | 36 GURL url(TestServerPage(page_name)); |
29 scoped_ptr<ResourceLoaderBridge> loader( | 37 scoped_ptr<ResourceLoaderBridge> loader( |
30 ResourceLoaderBridge::Create(NULL, "GET", | 38 ResourceLoaderBridge::Create(NULL, "GET", |
31 url, | 39 url, |
32 url, // policy_url | 40 url, // policy_url |
33 GURL(), // no referrer | 41 GURL(), // no referrer |
34 std::string(), // no extra headers | 42 std::string(), // no extra headers |
35 net::LOAD_NORMAL, | 43 net::LOAD_NORMAL, |
36 0, | 44 0, |
37 ResourceType::SUB_RESOURCE, | 45 ResourceType::SUB_RESOURCE, |
38 false)); | 46 false)); |
39 EXPECT_TRUE(loader.get()); | 47 EXPECT_TRUE(loader.get()); |
40 | 48 |
41 ResourceLoaderBridge::SyncLoadResponse resp; | 49 ResourceLoaderBridge::SyncLoadResponse resp; |
42 loader->SyncLoad(&resp); | 50 loader->SyncLoad(&resp); |
43 return resp.status.is_success(); | 51 return resp.status.is_success(); |
44 } | 52 } |
45 }; | 53 }; |
46 | 54 |
47 #endif // WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__ | 55 #endif // WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__ |
48 | 56 |
OLD | NEW |