OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // RenderViewFakeResourcesTest can be used as a base class for tests that need | 5 // RenderViewFakeResourcesTest can be used as a base class for tests that need |
6 // to simulate loading network resources (such as http: urls) into a | 6 // to simulate loading network resources (such as http: urls) into a |
7 // RenderView. It does this by handling the relevant IPC messages that the | 7 // RenderView. It does this by handling the relevant IPC messages that the |
8 // renderer would normally send to the browser, and responding with static | 8 // renderer would normally send to the browser, and responding with static |
9 // content from an internal map. A request for a url that is not in the map | 9 // content from an internal map. A request for a url that is not in the map |
10 // will return a 404. Currently, content is always returned as text/html, and | 10 // will return a 404. Currently, content is always returned as text/html, and |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 #include "ipc/ipc_channel.h" | 51 #include "ipc/ipc_channel.h" |
52 #include "testing/gtest/include/gtest/gtest.h" | 52 #include "testing/gtest/include/gtest/gtest.h" |
53 | 53 |
54 class CommandLine; | 54 class CommandLine; |
55 class MockRenderProcess; | 55 class MockRenderProcess; |
56 class RendererMainPlatformDelegate; | 56 class RendererMainPlatformDelegate; |
57 class RenderThread; | 57 class RenderThread; |
58 class RenderView; | 58 class RenderView; |
59 class SandboxInitWrapper; | 59 class SandboxInitWrapper; |
60 struct MainFunctionParams; | 60 struct MainFunctionParams; |
61 struct ViewHostMsg_Resource_Request; | 61 struct ResourceHostMsg_Request; |
62 | 62 |
63 namespace WebKit { | 63 namespace WebKit { |
64 class WebFrame; | 64 class WebFrame; |
65 } | 65 } |
66 | 66 |
67 namespace safe_browsing { | 67 namespace safe_browsing { |
68 | 68 |
69 class RenderViewFakeResourcesTest : public ::testing::Test, | 69 class RenderViewFakeResourcesTest : public ::testing::Test, |
70 public IPC::Channel::Listener, | 70 public IPC::Channel::Listener, |
71 public RenderViewVisitor { | 71 public RenderViewVisitor { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 // Notification that page load has finished. Exit the message loop | 105 // Notification that page load has finished. Exit the message loop |
106 // so that the test can continue. | 106 // so that the test can continue. |
107 void OnDidStopLoading(); | 107 void OnDidStopLoading(); |
108 | 108 |
109 // Notification that the renderer wants to load a resource. | 109 // Notification that the renderer wants to load a resource. |
110 // If the requested url is in responses_, we send the renderer a 200 | 110 // If the requested url is in responses_, we send the renderer a 200 |
111 // and the supplied content, otherwise we send it a 404 error. | 111 // and the supplied content, otherwise we send it a 404 error. |
112 void OnRequestResource(const IPC::Message& message, | 112 void OnRequestResource(const IPC::Message& message, |
113 int request_id, | 113 int request_id, |
114 const ViewHostMsg_Resource_Request& request_data); | 114 const ResourceHostMsg_Request& request_data); |
115 | 115 |
116 // Notification that the render view we've created is ready to use. | 116 // Notification that the render view we've created is ready to use. |
117 void OnRenderViewReady(); | 117 void OnRenderViewReady(); |
118 | 118 |
119 static const int32 kViewId; // arbitrary id for our testing view | 119 static const int32 kViewId; // arbitrary id for our testing view |
120 | 120 |
121 MessageLoopForIO message_loop_; | 121 MessageLoopForIO message_loop_; |
122 // channel that the renderer uses to talk to the browser. | 122 // channel that the renderer uses to talk to the browser. |
123 // For this test, we will handle the browser end of the channel. | 123 // For this test, we will handle the browser end of the channel. |
124 scoped_ptr<IPC::Channel> channel_; | 124 scoped_ptr<IPC::Channel> channel_; |
125 RenderThread* render_thread_; // owned by mock_process_ | 125 RenderThread* render_thread_; // owned by mock_process_ |
126 scoped_ptr<MockRenderProcess> mock_process_; | 126 scoped_ptr<MockRenderProcess> mock_process_; |
127 RenderView* view_; // not owned, deletes itself on close | 127 RenderView* view_; // not owned, deletes itself on close |
128 scoped_ptr<RendererMainPlatformDelegate> platform_; | 128 scoped_ptr<RendererMainPlatformDelegate> platform_; |
129 scoped_ptr<MainFunctionParams> params_; | 129 scoped_ptr<MainFunctionParams> params_; |
130 scoped_ptr<CommandLine> command_line_; | 130 scoped_ptr<CommandLine> command_line_; |
131 scoped_ptr<SandboxInitWrapper> sandbox_init_wrapper_; | 131 scoped_ptr<SandboxInitWrapper> sandbox_init_wrapper_; |
132 | 132 |
133 // Map of url -> response body for network requests from the renderer. | 133 // Map of url -> response body for network requests from the renderer. |
134 // Any urls not in this map are served a 404 error. | 134 // Any urls not in this map are served a 404 error. |
135 std::map<std::string, std::string> responses_; | 135 std::map<std::string, std::string> responses_; |
136 | 136 |
137 private: | 137 private: |
138 DISALLOW_COPY_AND_ASSIGN(RenderViewFakeResourcesTest); | 138 DISALLOW_COPY_AND_ASSIGN(RenderViewFakeResourcesTest); |
139 }; | 139 }; |
140 | 140 |
141 } // namespace safe_browsing | 141 } // namespace safe_browsing |
142 | 142 |
143 #endif // CHROME_RENDERER_SAFE_BROWSING_RENDER_VIEW_FAKE_RESOURCES_TEST_H_ | 143 #endif // CHROME_RENDERER_SAFE_BROWSING_RENDER_VIEW_FAKE_RESOURCES_TEST_H_ |
OLD | NEW |