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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 return path == "/valid.html" || path == "/valid.js"; | 44 return path == "/valid.html" || path == "/valid.js"; |
45 } | 45 } |
46 | 46 |
47 virtual void StartDataRequest( | 47 virtual void StartDataRequest( |
48 const std::string& path, | 48 const std::string& path, |
49 int render_process_id, | 49 int render_process_id, |
50 int render_frame_id, | 50 int render_frame_id, |
51 const content::URLDataSource::GotDataCallback& callback) OVERRIDE { | 51 const content::URLDataSource::GotDataCallback& callback) OVERRIDE { |
52 } | 52 } |
53 | 53 |
54 // RenderViewHost is hard to mock in concert with everything else, so stub | 54 // RenderFrameHost is hard to mock in concert with everything else, so stub |
55 // this method out for testing. | 55 // this method out for testing. |
56 virtual bool GetOrigin( | 56 virtual bool GetOrigin( |
57 int process_id, | 57 int process_id, |
58 int render_view_id, | 58 int render_frame_id, |
59 std::string* origin) const OVERRIDE { | 59 std::string* origin) const OVERRIDE { |
60 if (process_id == kInstantRendererPID) { | 60 if (process_id == kInstantRendererPID) { |
61 *origin = kInstantOrigin; | 61 *origin = kInstantOrigin; |
62 return true; | 62 return true; |
63 } | 63 } |
64 if (process_id == kNonInstantRendererPID) { | 64 if (process_id == kNonInstantRendererPID) { |
65 *origin = kNonInstantOrigin; | 65 *origin = kNonInstantOrigin; |
66 return true; | 66 return true; |
67 } | 67 } |
68 return false; | 68 return false; |
(...skipping 20 matching lines...) Expand all Loading... |
89 return std::string(reinterpret_cast<const char*>(response_->front()), | 89 return std::string(reinterpret_cast<const char*>(response_->front()), |
90 response_->size()); | 90 response_->size()); |
91 } | 91 } |
92 return ""; | 92 return ""; |
93 } | 93 } |
94 | 94 |
95 net::URLRequest* MockRequest( | 95 net::URLRequest* MockRequest( |
96 const std::string& url, | 96 const std::string& url, |
97 bool allocate_info, | 97 bool allocate_info, |
98 int render_process_id, | 98 int render_process_id, |
99 int render_view_id) { | 99 int render_frame_id) { |
100 net::URLRequest* request = | 100 net::URLRequest* request = |
101 new net::URLRequest(GURL(url), | 101 new net::URLRequest(GURL(url), |
102 net::DEFAULT_PRIORITY, | 102 net::DEFAULT_PRIORITY, |
103 NULL, | 103 NULL, |
104 resource_context_.GetRequestContext()); | 104 resource_context_.GetRequestContext()); |
105 if (allocate_info) { | 105 if (allocate_info) { |
106 content::ResourceRequestInfo::AllocateForTesting(request, | 106 content::ResourceRequestInfo::AllocateForTesting(request, |
107 ResourceType::SUB_FRAME, | 107 ResourceType::SUB_FRAME, |
108 &resource_context_, | 108 &resource_context_, |
109 render_process_id, | 109 render_process_id, |
110 render_view_id, | 110 render_frame_id, |
111 MSG_ROUTING_NONE, | 111 MSG_ROUTING_NONE, |
112 false); | 112 false); |
113 } | 113 } |
114 return request; | 114 return request; |
115 } | 115 } |
116 | 116 |
117 void SendResource(int resource_id) { | 117 void SendResource(int resource_id) { |
118 source()->SendResource(resource_id, callback_); | 118 source()->SendResource(resource_id, callback_); |
119 } | 119 } |
120 | 120 |
121 void SendJSWithOrigin( | 121 void SendJSWithOrigin( |
122 int resource_id, | 122 int resource_id, |
123 int render_process_id, | 123 int render_process_id, |
124 int render_view_id) { | 124 int render_frame_id) { |
125 source()->SendJSWithOrigin(resource_id, render_process_id, render_view_id, | 125 source()->SendJSWithOrigin(resource_id, render_process_id, render_frame_id, |
126 callback_); | 126 callback_); |
127 } | 127 } |
128 | 128 |
129 private: | 129 private: |
130 virtual void SetUp() OVERRIDE { | 130 virtual void SetUp() OVERRIDE { |
131 source_.reset(new TestIframeSource()); | 131 source_.reset(new TestIframeSource()); |
132 callback_ = base::Bind(&IframeSourceTest::SaveResponse, | 132 callback_ = base::Bind(&IframeSourceTest::SaveResponse, |
133 base::Unretained(this)); | 133 base::Unretained(this)); |
134 instant_io_context_ = new InstantIOContext; | 134 instant_io_context_ = new InstantIOContext; |
135 InstantIOContext::SetUserDataOnIO(&resource_context_, instant_io_context_); | 135 InstantIOContext::SetUserDataOnIO(&resource_context_, instant_io_context_); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 193 } |
194 | 194 |
195 TEST_F(IframeSourceTest, SendJSWithOrigin) { | 195 TEST_F(IframeSourceTest, SendJSWithOrigin) { |
196 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInstantRendererPID, 0); | 196 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInstantRendererPID, 0); |
197 EXPECT_FALSE(response_string().empty()); | 197 EXPECT_FALSE(response_string().empty()); |
198 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kNonInstantRendererPID, 0); | 198 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kNonInstantRendererPID, 0); |
199 EXPECT_FALSE(response_string().empty()); | 199 EXPECT_FALSE(response_string().empty()); |
200 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInvalidRendererPID, 0); | 200 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInvalidRendererPID, 0); |
201 EXPECT_TRUE(response_string().empty()); | 201 EXPECT_TRUE(response_string().empty()); |
202 } | 202 } |
OLD | NEW |