| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "content/browser/webui/url_data_manager_backend.h" | 7 #include "content/browser/webui/url_data_manager_backend.h" |
| 8 #include "content/public/test/mock_resource_context.h" | 8 #include "content/public/test/mock_resource_context.h" |
| 9 #include "content/public/test/test_browser_thread_bundle.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
| 10 #include "net/http/http_response_headers.h" | 10 #include "net/http/http_response_headers.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 void RunAccessControlAllowOriginTest( | 23 void RunAccessControlAllowOriginTest( |
| 24 const std::string& origin, | 24 const std::string& origin, |
| 25 const std::string& expected_access_control_allow_origin_value) { | 25 const std::string& expected_access_control_allow_origin_value) { |
| 26 TestBrowserThreadBundle thread_bundle; | 26 TestBrowserThreadBundle thread_bundle; |
| 27 MockResourceContext resource_context; | 27 MockResourceContext resource_context; |
| 28 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> protocol_handler( | 28 scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> protocol_handler( |
| 29 URLDataManagerBackend::CreateProtocolHandler(&resource_context, false, | 29 URLDataManagerBackend::CreateProtocolHandler(&resource_context, false, |
| 30 nullptr, nullptr)); | 30 nullptr, nullptr)); |
| 31 net::URLRequestContext url_request_context; | 31 net::URLRequestContext url_request_context; |
| 32 scoped_ptr<net::URLRequest> request = url_request_context.CreateRequest( | 32 scoped_ptr<net::URLRequest> request = url_request_context.CreateRequest( |
| 33 GURL("chrome://resources/polymer/polymer/polymer.js"), net::HIGHEST, | 33 GURL("chrome://resources/polymer/v1_0/polymer/polymer-extracted.js"), |
| 34 nullptr); | 34 net::HIGHEST, nullptr); |
| 35 request->SetExtraRequestHeaderByName("Origin", origin, true); | 35 request->SetExtraRequestHeaderByName("Origin", origin, true); |
| 36 scoped_refptr<net::URLRequestJob> job = | 36 scoped_refptr<net::URLRequestJob> job = |
| 37 protocol_handler->MaybeCreateJob(request.get(), nullptr); | 37 protocol_handler->MaybeCreateJob(request.get(), nullptr); |
| 38 ASSERT_TRUE(job); | 38 ASSERT_TRUE(job); |
| 39 job->Start(); | 39 job->Start(); |
| 40 base::RunLoop().RunUntilIdle(); | 40 base::RunLoop().RunUntilIdle(); |
| 41 net::HttpResponseInfo response; | 41 net::HttpResponseInfo response; |
| 42 job->GetResponseInfo(&response); | 42 job->GetResponseInfo(&response); |
| 43 EXPECT_TRUE(response.headers->HasHeaderValue( | 43 EXPECT_TRUE(response.headers->HasHeaderValue( |
| 44 "Access-Control-Allow-Origin", | 44 "Access-Control-Allow-Origin", |
| 45 expected_access_control_allow_origin_value)); | 45 expected_access_control_allow_origin_value)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 TEST(UrlDataManagerBackendTest, AccessControlAllowOriginChromeUrl) { | 50 TEST(UrlDataManagerBackendTest, AccessControlAllowOriginChromeUrl) { |
| 51 RunAccessControlAllowOriginTest("chrome://webui", "chrome://webui"); | 51 RunAccessControlAllowOriginTest("chrome://webui", "chrome://webui"); |
| 52 } | 52 } |
| 53 | 53 |
| 54 TEST(UrlDataManagerBackendTest, AccessControlAllowOriginNonChromeUrl) { | 54 TEST(UrlDataManagerBackendTest, AccessControlAllowOriginNonChromeUrl) { |
| 55 RunAccessControlAllowOriginTest("http://www.example.com", "null"); | 55 RunAccessControlAllowOriginTest("http://www.example.com", "null"); |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace content | 58 } // namespace content |
| OLD | NEW |