| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/renderer/render_view_visitor.h" | 51 #include "content/public/renderer/render_view_visitor.h" |
| 52 #include "ipc/ipc_listener.h" | 52 #include "ipc/ipc_listener.h" |
| 53 #include "testing/gtest/include/gtest/gtest.h" | 53 #include "testing/gtest/include/gtest/gtest.h" |
| 54 | 54 |
| 55 struct ResourceHostMsg_Request; | 55 struct ResourceHostMsg_Request; |
| 56 | 56 |
| 57 namespace IPC { | 57 namespace IPC { |
| 58 class Channel; | 58 class Channel; |
| 59 } | 59 } |
| 60 | 60 |
| 61 namespace WebKit { | 61 namespace blink { |
| 62 class WebFrame; | 62 class WebFrame; |
| 63 class WebHistoryItem; | 63 class WebHistoryItem; |
| 64 } | 64 } |
| 65 | 65 |
| 66 namespace content { | 66 namespace content { |
| 67 class MockRenderProcess; | 67 class MockRenderProcess; |
| 68 class RenderThreadImpl; | 68 class RenderThreadImpl; |
| 69 | 69 |
| 70 class RenderViewFakeResourcesTest : public ::testing::Test, | 70 class RenderViewFakeResourcesTest : public ::testing::Test, |
| 71 public IPC::Listener, | 71 public IPC::Listener, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 97 // not supported. | 97 // not supported. |
| 98 void LoadURLWithPost(const std::string& url); | 98 void LoadURLWithPost(const std::string& url); |
| 99 | 99 |
| 100 // Navigates the main frame back in session history. | 100 // Navigates the main frame back in session history. |
| 101 void GoBack(); | 101 void GoBack(); |
| 102 | 102 |
| 103 // Navigates the main frame forward in session history. Note that for | 103 // Navigates the main frame forward in session history. Note that for |
| 104 // forward navigations, the caller needs to capture the WebHistoryItem | 104 // forward navigations, the caller needs to capture the WebHistoryItem |
| 105 // for the page to go forward to (before going back) and pass it to | 105 // for the page to go forward to (before going back) and pass it to |
| 106 // this method. The WebHistoryItem is available from the WebFrame. | 106 // this method. The WebHistoryItem is available from the WebFrame. |
| 107 void GoForward(const WebKit::WebHistoryItem& history_item); | 107 void GoForward(const blink::WebHistoryItem& history_item); |
| 108 | 108 |
| 109 // Returns the main WebFrame for our RenderView. | 109 // Returns the main WebFrame for our RenderView. |
| 110 WebKit::WebFrame* GetMainFrame(); | 110 blink::WebFrame* GetMainFrame(); |
| 111 | 111 |
| 112 // IPC message handlers below | 112 // IPC message handlers below |
| 113 | 113 |
| 114 // Notification that page load has finished. Exit the message loop | 114 // Notification that page load has finished. Exit the message loop |
| 115 // so that the test can continue. | 115 // so that the test can continue. |
| 116 void OnDidStopLoading(); | 116 void OnDidStopLoading(); |
| 117 | 117 |
| 118 // Notification that the renderer wants to load a resource. | 118 // Notification that the renderer wants to load a resource. |
| 119 // If the requested url is in responses_, we send the renderer a 200 | 119 // If the requested url is in responses_, we send the renderer a 200 |
| 120 // and the supplied content, otherwise we send it a 404 error. | 120 // and the supplied content, otherwise we send it a 404 error. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 135 RenderThreadImpl* render_thread_; // owned by mock_process_ | 135 RenderThreadImpl* render_thread_; // owned by mock_process_ |
| 136 scoped_ptr<MockRenderProcess> mock_process_; | 136 scoped_ptr<MockRenderProcess> mock_process_; |
| 137 RenderView* view_; // not owned, deletes itself on close | 137 RenderView* view_; // not owned, deletes itself on close |
| 138 | 138 |
| 139 // Map of url -> response body for network requests from the renderer. | 139 // Map of url -> response body for network requests from the renderer. |
| 140 // Any urls not in this map are served a 404 error. | 140 // Any urls not in this map are served a 404 error. |
| 141 std::map<std::string, std::string> responses_; | 141 std::map<std::string, std::string> responses_; |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 // A helper for GoBack and GoForward. | 144 // A helper for GoBack and GoForward. |
| 145 void GoToOffset(int offset, const WebKit::WebHistoryItem& history_item); | 145 void GoToOffset(int offset, const blink::WebHistoryItem& history_item); |
| 146 | 146 |
| 147 // The previous state for whether sandbox support was enabled in | 147 // The previous state for whether sandbox support was enabled in |
| 148 // RenderViewWebKitPlatformSupportImpl. | 148 // RenderViewWebKitPlatformSupportImpl. |
| 149 bool sandbox_was_enabled_; | 149 bool sandbox_was_enabled_; |
| 150 | 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(RenderViewFakeResourcesTest); | 151 DISALLOW_COPY_AND_ASSIGN(RenderViewFakeResourcesTest); |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 } // namespace content | 154 } // namespace content |
| 155 | 155 |
| 156 #endif // CONTENT_PUBLIC_TEST_RENDER_VIEW_FAKE_RESOURCES_TEST_H_ | 156 #endif // CONTENT_PUBLIC_TEST_RENDER_VIEW_FAKE_RESOURCES_TEST_H_ |
| OLD | NEW |