summaryrefslogtreecommitdiffstats
path: root/chrome/test/nacl/pnacl_header_test.h
blob: 6c75fdce00f27b4f5fac1906b8d7a3d40b065a04 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2013 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 CHROME_TEST_NACL_PNACL_HEADER_TEST_H_
#define CHROME_TEST_NACL_PNACL_HEADER_TEST_H_

#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/browser/resource_dispatcher_host_delegate.h"
#include "content/public/common/resource_type.h"

namespace base {
class FilePath;
}

namespace net {
namespace test_server {
struct HttpRequest;
class HttpResponse;
}
}

using content::ResourceDispatcherHostDelegate;

class TestDispatcherHostDelegate : public ResourceDispatcherHostDelegate {
 public:
  explicit TestDispatcherHostDelegate()
      : ResourceDispatcherHostDelegate(), found_pnacl_header_(false) {}

  virtual ~TestDispatcherHostDelegate() {}

  virtual void RequestBeginning(
      net::URLRequest* request,
      content::ResourceContext* resource_context,
      content::AppCacheService* appcache_service,
      content::ResourceType resource_type,
      ScopedVector<content::ResourceThrottle>* throttles) OVERRIDE;

  bool found_pnacl_header() const { return found_pnacl_header_; }

 private:
  bool found_pnacl_header_;

  DISALLOW_COPY_AND_ASSIGN(TestDispatcherHostDelegate);
};

class PnaclHeaderTest : public InProcessBrowserTest {
 public:
  PnaclHeaderTest();
  virtual ~PnaclHeaderTest();

  // Run a simple test that checks that the NaCl plugin sends the right
  // headers when doing |expected_noncors| same origin pexe load requests
  // and |expected_cors| cross origin pexe load requests.
  void RunLoadTest(const std::string& url,
                   int expected_noncors,
                   int expected_cors);

 private:
  void StartServer();

  scoped_ptr<net::test_server::HttpResponse> WatchForPexeFetch(
      const net::test_server::HttpRequest& request);

  int noncors_loads_;
  int cors_loads_;
  TestDispatcherHostDelegate test_delegate_;
  DISALLOW_COPY_AND_ASSIGN(PnaclHeaderTest);
};

#endif  // CHROME_TEST_NACL_PNACL_HEADER_TEST_H_