OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/test/nacl/pnacl_header_test.h" | 5 #include "chrome/test/nacl/pnacl_header_test.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/test/scoped_path_override.h" | 9 #include "base/test/scoped_path_override.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
14 #include "chrome/test/nacl/nacl_browsertest_util.h" | 14 #include "chrome/test/nacl/nacl_browsertest_util.h" |
15 #include "content/public/browser/resource_dispatcher_host.h" | 15 #include "content/public/browser/resource_dispatcher_host.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "net/test/embedded_test_server/embedded_test_server.h" | 17 #include "net/test/embedded_test_server/embedded_test_server.h" |
18 #include "net/test/embedded_test_server/http_request.h" | 18 #include "net/test/embedded_test_server/http_request.h" |
19 #include "net/test/embedded_test_server/http_response.h" | 19 #include "net/test/embedded_test_server/http_response.h" |
20 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
21 | 21 |
22 using net::test_server::BasicHttpResponse; | 22 using net::test_server::BasicHttpResponse; |
23 using net::test_server::EmbeddedTestServer; | |
24 using net::test_server::HttpRequest; | 23 using net::test_server::HttpRequest; |
25 using net::test_server::HttpResponse; | 24 using net::test_server::HttpResponse; |
26 | 25 |
27 void TestDispatcherHostDelegate::RequestBeginning( | 26 void TestDispatcherHostDelegate::RequestBeginning( |
28 net::URLRequest* request, | 27 net::URLRequest* request, |
29 content::ResourceContext* resource_context, | 28 content::ResourceContext* resource_context, |
30 content::AppCacheService* appcache_service, | 29 content::AppCacheService* appcache_service, |
31 content::ResourceType resource_type, | 30 content::ResourceType resource_type, |
32 ScopedVector<content::ResourceThrottle>* throttles) { | 31 ScopedVector<content::ResourceThrottle>* throttles) { |
33 // This checks the same condition as the one for PNaCl in | 32 // This checks the same condition as the one for PNaCl in |
34 // AppendComponentUpdaterThrottles. | 33 // AppendComponentUpdaterThrottles. |
35 if (resource_type == content::RESOURCE_TYPE_OBJECT) { | 34 if (resource_type == content::RESOURCE_TYPE_OBJECT) { |
36 const net::HttpRequestHeaders& headers = request->extra_request_headers(); | 35 const net::HttpRequestHeaders& headers = request->extra_request_headers(); |
37 std::string accept_headers; | 36 std::string accept_headers; |
38 if (headers.GetHeader("Accept", &accept_headers)) { | 37 if (headers.GetHeader("Accept", &accept_headers)) { |
39 if (accept_headers.find("application/x-pnacl") != std::string::npos) | 38 if (accept_headers.find("application/x-pnacl") != std::string::npos) |
40 found_pnacl_header_ = true; | 39 found_pnacl_header_ = true; |
41 } | 40 } |
42 } | 41 } |
43 } | 42 } |
44 | 43 |
45 PnaclHeaderTest::PnaclHeaderTest() : noncors_loads_(0), cors_loads_(0) {} | 44 PnaclHeaderTest::PnaclHeaderTest() : noncors_loads_(0), cors_loads_(0) {} |
46 | 45 |
47 PnaclHeaderTest::~PnaclHeaderTest() {} | 46 PnaclHeaderTest::~PnaclHeaderTest() {} |
48 | 47 |
49 void PnaclHeaderTest::StartServer() { | 48 void PnaclHeaderTest::StartServer() { |
50 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 49 ASSERT_TRUE(embedded_test_server()->Start()); |
51 | 50 |
52 // For most requests, just serve files, but register a special test handler | 51 // For most requests, just serve files, but register a special test handler |
53 // that watches for the .pexe fetch also. | 52 // that watches for the .pexe fetch also. |
54 base::FilePath test_data_dir; | 53 base::FilePath test_data_dir; |
55 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); | 54 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir)); |
56 embedded_test_server()->RegisterRequestHandler( | 55 embedded_test_server()->RegisterRequestHandler( |
57 base::Bind(&PnaclHeaderTest::WatchForPexeFetch, base::Unretained(this))); | 56 base::Bind(&PnaclHeaderTest::WatchForPexeFetch, base::Unretained(this))); |
58 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 57 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
59 } | 58 } |
60 | 59 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 http_response->set_code(net::HTTP_NOT_FOUND); | 131 http_response->set_code(net::HTTP_NOT_FOUND); |
133 http_response->set_content("PEXE ... not found"); | 132 http_response->set_content("PEXE ... not found"); |
134 http_response->set_content_type("application/octet-stream"); | 133 http_response->set_content_type("application/octet-stream"); |
135 return http_response.Pass(); | 134 return http_response.Pass(); |
136 } | 135 } |
137 | 136 |
138 IN_PROC_BROWSER_TEST_F(PnaclHeaderTest, TestHasPnaclHeader) { | 137 IN_PROC_BROWSER_TEST_F(PnaclHeaderTest, TestHasPnaclHeader) { |
139 // Load 2 pexes, one same origin and one cross orgin. | 138 // Load 2 pexes, one same origin and one cross orgin. |
140 RunLoadTest("/nacl/pnacl_request_header/pnacl_request_header.html", 1, 1); | 139 RunLoadTest("/nacl/pnacl_request_header/pnacl_request_header.html", 1, 1); |
141 } | 140 } |
OLD | NEW |