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 <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "chrome/browser/search/instant_io_context.h" | 12 #include "chrome/browser/search/instant_io_context.h" |
13 #include "chrome/grit/browser_resources.h" | 13 #include "chrome/grit/browser_resources.h" |
14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/resource_request_info.h" | 15 #include "content/public/browser/resource_request_info.h" |
| 16 #include "content/public/common/previews_state.h" |
16 #include "content/public/test/mock_resource_context.h" | 17 #include "content/public/test/mock_resource_context.h" |
17 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
19 #include "net/base/request_priority.h" | 20 #include "net/base/request_priority.h" |
20 #include "net/url_request/url_request.h" | 21 #include "net/url_request/url_request.h" |
21 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
22 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "url/gurl.h" | 25 #include "url/gurl.h" |
25 | 26 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 87 } |
87 return ""; | 88 return ""; |
88 } | 89 } |
89 | 90 |
90 std::unique_ptr<net::URLRequest> MockRequest(const std::string& url, | 91 std::unique_ptr<net::URLRequest> MockRequest(const std::string& url, |
91 int render_process_id) { | 92 int render_process_id) { |
92 std::unique_ptr<net::URLRequest> request( | 93 std::unique_ptr<net::URLRequest> request( |
93 resource_context_.GetRequestContext()->CreateRequest( | 94 resource_context_.GetRequestContext()->CreateRequest( |
94 GURL(url), net::DEFAULT_PRIORITY, NULL)); | 95 GURL(url), net::DEFAULT_PRIORITY, NULL)); |
95 content::ResourceRequestInfo::AllocateForTesting( | 96 content::ResourceRequestInfo::AllocateForTesting( |
96 request.get(), | 97 request.get(), content::RESOURCE_TYPE_SUB_FRAME, &resource_context_, |
97 content::RESOURCE_TYPE_SUB_FRAME, | 98 render_process_id, MSG_ROUTING_NONE, MSG_ROUTING_NONE, |
98 &resource_context_, | 99 /*is_main_frame=*/false, |
99 render_process_id, | 100 /*parent_is_main_frame=*/false, |
100 MSG_ROUTING_NONE, | 101 /*allow_download=*/true, |
101 MSG_ROUTING_NONE, | 102 /*is_async=*/false, content::PREVIEWS_OFF); |
102 false, // is_main_frame | |
103 false, // parent_is_main_frame | |
104 true, // allow_download | |
105 false, // is_async | |
106 false); // is_using_lofi | |
107 return request; | 103 return request; |
108 } | 104 } |
109 | 105 |
110 void SendResource(int resource_id) { | 106 void SendResource(int resource_id) { |
111 source()->SendResource(resource_id, callback_); | 107 source()->SendResource(resource_id, callback_); |
112 } | 108 } |
113 | 109 |
114 void SendJSWithOrigin(int resource_id) { | 110 void SendJSWithOrigin(int resource_id) { |
115 source()->SendJSWithOrigin( | 111 source()->SendJSWithOrigin( |
116 resource_id, content::ResourceRequestInfo::WebContentsGetter(), | 112 resource_id, content::ResourceRequestInfo::WebContentsGetter(), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 source()->set_origin(kInstantOrigin); | 183 source()->set_origin(kInstantOrigin); |
188 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS); | 184 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS); |
189 EXPECT_FALSE(response_string().empty()); | 185 EXPECT_FALSE(response_string().empty()); |
190 source()->set_origin(kNonInstantOrigin); | 186 source()->set_origin(kNonInstantOrigin); |
191 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS); | 187 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS); |
192 EXPECT_FALSE(response_string().empty()); | 188 EXPECT_FALSE(response_string().empty()); |
193 source()->set_origin(std::string()); | 189 source()->set_origin(std::string()); |
194 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS); | 190 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS); |
195 EXPECT_TRUE(response_string().empty()); | 191 EXPECT_TRUE(response_string().empty()); |
196 } | 192 } |
OLD | NEW |