summaryrefslogtreecommitdiffstats
path: root/webkit/glue/unittest_test_server.h
blob: 2a8359956ba8b4312f281a7f59c4a64d9b13cf4b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__
#define WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__

#include "webkit/glue/resource_loader_bridge.h"
#include "net/base/load_flags.h"
#include "net/url_request/url_request_unittest.h"

using webkit_glue::ResourceLoaderBridge;

// We need to use ResourceLoaderBridge to communicate with the testserver
// instead of using URLRequest directly because URLRequests need to be run on
// the test_shell's IO thread.
class UnittestTestServer : public HTTPTestServer {
 protected:
  UnittestTestServer() {
  }

 public:
  static UnittestTestServer* CreateServer() {
    UnittestTestServer* test_server = new UnittestTestServer();
    FilePath no_cert;
    FilePath docroot = FilePath::FromWStringHack(L"webkit/data");
    if (!test_server->Start(net::TestServerLauncher::ProtoHTTP,
        "localhost", 1337, docroot, no_cert)) {
      delete test_server;
      return NULL;
    }
    return test_server;
  }

  virtual ~UnittestTestServer() {
  }

  virtual bool MakeGETRequest(const std::string& page_name) {
    GURL url(TestServerPage(page_name));
    scoped_ptr<ResourceLoaderBridge> loader(
      ResourceLoaderBridge::Create(NULL, "GET",
                                   url,
                                   url,            // policy_url
                                   GURL(),         // no referrer
                                   std::string(),  // no extra headers
                                   net::LOAD_NORMAL,
                                   0,
                                   ResourceType::SUB_RESOURCE,
                                   false));
    EXPECT_TRUE(loader.get());

    ResourceLoaderBridge::SyncLoadResponse resp;
    loader->SyncLoad(&resp);
    return resp.status.is_success();
  }
};

#endif  // WEBKIT_GLUE_UNITTEST_TEST_SERVER_H__