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 20 matching lines...) Expand all Loading... |
31 const int kInvalidRendererPID = 42; | 31 const int kInvalidRendererPID = 42; |
32 | 32 |
33 class TestIframeSource : public IframeSource { | 33 class TestIframeSource : public IframeSource { |
34 public: | 34 public: |
35 using IframeSource::GetMimeType; | 35 using IframeSource::GetMimeType; |
36 using IframeSource::ShouldServiceRequest; | 36 using IframeSource::ShouldServiceRequest; |
37 using IframeSource::SendResource; | 37 using IframeSource::SendResource; |
38 using IframeSource::SendJSWithOrigin; | 38 using IframeSource::SendJSWithOrigin; |
39 | 39 |
40 protected: | 40 protected: |
41 virtual std::string GetSource() const override { | 41 std::string GetSource() const override { return "test"; } |
42 return "test"; | |
43 } | |
44 | 42 |
45 virtual bool ServesPath(const std::string& path) const override { | 43 bool ServesPath(const std::string& path) const override { |
46 return path == "/valid.html" || path == "/valid.js"; | 44 return path == "/valid.html" || path == "/valid.js"; |
47 } | 45 } |
48 | 46 |
49 virtual void StartDataRequest( | 47 void StartDataRequest( |
50 const std::string& path, | 48 const std::string& path, |
51 int render_process_id, | 49 int render_process_id, |
52 int render_frame_id, | 50 int render_frame_id, |
53 const content::URLDataSource::GotDataCallback& callback) override { | 51 const content::URLDataSource::GotDataCallback& callback) override {} |
54 } | |
55 | 52 |
56 // RenderFrameHost is hard to mock in concert with everything else, so stub | 53 // RenderFrameHost is hard to mock in concert with everything else, so stub |
57 // this method out for testing. | 54 // this method out for testing. |
58 virtual bool GetOrigin( | 55 bool GetOrigin(int process_id, |
59 int process_id, | 56 int render_frame_id, |
60 int render_frame_id, | 57 std::string* origin) const override { |
61 std::string* origin) const override { | |
62 if (process_id == kInstantRendererPID) { | 58 if (process_id == kInstantRendererPID) { |
63 *origin = kInstantOrigin; | 59 *origin = kInstantOrigin; |
64 return true; | 60 return true; |
65 } | 61 } |
66 if (process_id == kNonInstantRendererPID) { | 62 if (process_id == kNonInstantRendererPID) { |
67 *origin = kNonInstantOrigin; | 63 *origin = kNonInstantOrigin; |
68 return true; | 64 return true; |
69 } | 65 } |
70 return false; | 66 return false; |
71 } | 67 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 192 } |
197 | 193 |
198 TEST_F(IframeSourceTest, SendJSWithOrigin) { | 194 TEST_F(IframeSourceTest, SendJSWithOrigin) { |
199 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInstantRendererPID, 0); | 195 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInstantRendererPID, 0); |
200 EXPECT_FALSE(response_string().empty()); | 196 EXPECT_FALSE(response_string().empty()); |
201 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kNonInstantRendererPID, 0); | 197 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kNonInstantRendererPID, 0); |
202 EXPECT_FALSE(response_string().empty()); | 198 EXPECT_FALSE(response_string().empty()); |
203 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInvalidRendererPID, 0); | 199 SendJSWithOrigin(IDR_MOST_VISITED_TITLE_JS, kInvalidRendererPID, 0); |
204 EXPECT_TRUE(response_string().empty()); | 200 EXPECT_TRUE(response_string().empty()); |
205 } | 201 } |
OLD | NEW |