diff options
Diffstat (limited to 'chrome/test/nacl/pnacl_header_test.cc')
-rw-r--r-- | chrome/test/nacl/pnacl_header_test.cc | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/chrome/test/nacl/pnacl_header_test.cc b/chrome/test/nacl/pnacl_header_test.cc index e4922aa..8ba8dc8 100644 --- a/chrome/test/nacl/pnacl_header_test.cc +++ b/chrome/test/nacl/pnacl_header_test.cc @@ -12,16 +12,36 @@ #include "chrome/common/chrome_paths.h" #include "chrome/test/base/ui_test_utils.h" #include "chrome/test/nacl/nacl_browsertest_util.h" +#include "content/public/browser/resource_dispatcher_host.h" #include "content/public/browser/web_contents.h" #include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/http_request.h" #include "net/test/embedded_test_server/http_response.h" +#include "net/url_request/url_request.h" using net::test_server::BasicHttpResponse; using net::test_server::EmbeddedTestServer; using net::test_server::HttpRequest; using net::test_server::HttpResponse; +void TestDispatcherHostDelegate::RequestBeginning( + net::URLRequest* request, + content::ResourceContext* resource_context, + content::AppCacheService* appcache_service, + content::ResourceType resource_type, + ScopedVector<content::ResourceThrottle>* throttles) { + // This checks the same condition as the one for PNaCl in + // AppendComponentUpdaterThrottles. + if (resource_type == content::RESOURCE_TYPE_OBJECT) { + const net::HttpRequestHeaders& headers = request->extra_request_headers(); + std::string accept_headers; + if (headers.GetHeader("Accept", &accept_headers)) { + if (accept_headers.find("application/x-pnacl") != std::string::npos) + found_pnacl_header_ = true; + } + } +} + PnaclHeaderTest::PnaclHeaderTest() : noncors_loads_(0), cors_loads_(0) {} PnaclHeaderTest::~PnaclHeaderTest() {} @@ -41,6 +61,7 @@ void PnaclHeaderTest::StartServer() { void PnaclHeaderTest::RunLoadTest(const std::string& url, int expected_noncors, int expected_cors) { + content::ResourceDispatcherHost::Get()->SetDelegate(&test_delegate_); StartServer(); LoadTestMessageHandler handler; content::JavascriptTestObserver observer( @@ -57,6 +78,9 @@ void PnaclHeaderTest::RunLoadTest(const std::string& url, base::ScopedPathOverride component_dir(chrome::DIR_PNACL_COMPONENT); ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL(url)); + + content::ResourceDispatcherHost::Get()->SetDelegate(NULL); + // Wait until the NMF and pexe are also loaded, not just the HTML. // Do this by waiting till the LoadTestMessageHandler responds. EXPECT_TRUE(observer.Run()) << handler.error_message(); @@ -81,14 +105,14 @@ scoped_ptr<HttpResponse> PnaclHeaderTest::WatchForPexeFetch( if (absolute_url.path().find(".pexe") == std::string::npos) return scoped_ptr<HttpResponse>(); - // For pexe files, check for the special Accept header. - // This must match whatever is in: - // ppapi/native_client/src/trusted/plugin/pnacl_coordinator.cc + // For pexe files, check for the special Accept header, + // along with the expected ResourceType of the URL request. EXPECT_NE(0U, request.headers.count("Accept")); std::map<std::string, std::string>::const_iterator it = request.headers.find("Accept"); EXPECT_NE(std::string::npos, it->second.find("application/x-pnacl")); EXPECT_NE(std::string::npos, it->second.find("*/*")); + EXPECT_TRUE(test_delegate_.found_pnacl_header()); // Also make sure that other headers like CORS-related headers // are preserved when injecting the special Accept header. |