| 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/browser/search/iframe_source.h" | 5 #include "chrome/browser/search/iframe_source.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted_memory.h" | 8 #include "base/memory/ref_counted_memory.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "chrome/browser/search/instant_io_context.h" | 11 #include "chrome/browser/search/instant_io_context.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/resource_request_info.h" | 13 #include "content/public/browser/resource_request_info.h" |
| 14 #include "content/public/test/mock_resource_context.h" | 14 #include "content/public/test/mock_resource_context.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "grit/browser_resources.h" | 16 #include "grit/browser_resources.h" |
| 17 #include "net/base/request_priority.h" |
| 17 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 18 #include "net/url_request/url_request_context.h" | 19 #include "net/url_request/url_request_context.h" |
| 19 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 const int kNonInstantRendererPID = 0; | 24 const int kNonInstantRendererPID = 0; |
| 24 const char kNonInstantOrigin[] = "http://evil"; | 25 const char kNonInstantOrigin[] = "http://evil"; |
| 25 const int kInstantRendererPID = 1; | 26 const int kInstantRendererPID = 1; |
| 26 const char kInstantOrigin[] = "chrome-search://instant"; | 27 const char kInstantOrigin[] = "chrome-search://instant"; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 } | 90 } |
| 90 return ""; | 91 return ""; |
| 91 } | 92 } |
| 92 | 93 |
| 93 net::URLRequest* MockRequest( | 94 net::URLRequest* MockRequest( |
| 94 const std::string& url, | 95 const std::string& url, |
| 95 bool allocate_info, | 96 bool allocate_info, |
| 96 int render_process_id, | 97 int render_process_id, |
| 97 int render_view_id) { | 98 int render_view_id) { |
| 98 net::URLRequest* request = | 99 net::URLRequest* request = |
| 99 new net::URLRequest(GURL(url), NULL, | 100 new net::URLRequest(GURL(url), |
| 101 net::DEFAULT_PRIORITY, |
| 102 NULL, |
| 100 resource_context_.GetRequestContext()); | 103 resource_context_.GetRequestContext()); |
| 101 if (allocate_info) { | 104 if (allocate_info) { |
| 102 content::ResourceRequestInfo::AllocateForTesting(request, | 105 content::ResourceRequestInfo::AllocateForTesting(request, |
| 103 ResourceType::SUB_FRAME, | 106 ResourceType::SUB_FRAME, |
| 104 &resource_context_, | 107 &resource_context_, |
| 105 render_process_id, | 108 render_process_id, |
| 106 render_view_id, | 109 render_view_id, |
| 107 false); | 110 false); |
| 108 } | 111 } |
| 109 return request; | 112 return request; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 191 } |
| 189 | 192 |
| 190 TEST_F(IframeSourceTest, SendJSWithOrigin) { | 193 TEST_F(IframeSourceTest, SendJSWithOrigin) { |
| 191 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInstantRendererPID, 0); | 194 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInstantRendererPID, 0); |
| 192 EXPECT_FALSE(response_string().empty()); | 195 EXPECT_FALSE(response_string().empty()); |
| 193 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kNonInstantRendererPID, 0); | 196 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kNonInstantRendererPID, 0); |
| 194 EXPECT_FALSE(response_string().empty()); | 197 EXPECT_FALSE(response_string().empty()); |
| 195 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInvalidRendererPID, 0); | 198 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInvalidRendererPID, 0); |
| 196 EXPECT_TRUE(response_string().empty()); | 199 EXPECT_TRUE(response_string().empty()); |
| 197 } | 200 } |
| OLD | NEW |