[email protected] | 2a18ee22 | 2013-11-21 07:52:44 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 4bfd461 | 2013-12-05 18:12:48 | [diff] [blame] | 5 | #ifndef CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_ |
| 6 | #define CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_ |
[email protected] | 2a18ee22 | 2013-11-21 07:52:44 | [diff] [blame] | 7 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | c1982ff | 2014-04-23 03:37:21 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 12 | #include "base/macros.h" |
[email protected] | 2a18ee22 | 2013-11-21 07:52:44 | [diff] [blame] | 13 | #include "content/browser/frame_host/render_frame_host_impl.h" |
[email protected] | e2d2d420 | 2014-07-03 12:17:48 | [diff] [blame] | 14 | #include "content/public/browser/web_contents_observer.h" |
nick | ddc9d53 | 2015-04-16 17:46:29 | [diff] [blame] | 15 | #include "content/public/test/mock_render_process_host.h" |
[email protected] | e2d2d420 | 2014-07-03 12:17:48 | [diff] [blame] | 16 | #include "content/public/test/test_renderer_host.h" |
[email protected] | 6b50e36 | 2014-08-15 05:15:59 | [diff] [blame] | 17 | #include "content/test/test_render_view_host.h" |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 18 | #include "ui/base/page_transition_types.h" |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 19 | |
| 20 | struct FrameHostMsg_DidCommitProvisionalLoad_Params; |
[email protected] | 2a18ee22 | 2013-11-21 07:52:44 | [diff] [blame] | 21 | |
| 22 | namespace content { |
| 23 | |
[email protected] | e2d2d420 | 2014-07-03 12:17:48 | [diff] [blame] | 24 | class TestRenderFrameHostCreationObserver : public WebContentsObserver { |
| 25 | public: |
| 26 | explicit TestRenderFrameHostCreationObserver(WebContents* web_contents); |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 27 | ~TestRenderFrameHostCreationObserver() override; |
[email protected] | e2d2d420 | 2014-07-03 12:17:48 | [diff] [blame] | 28 | |
| 29 | // WebContentsObserver implementation. |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 30 | void RenderFrameCreated(RenderFrameHost* render_frame_host) override; |
[email protected] | e2d2d420 | 2014-07-03 12:17:48 | [diff] [blame] | 31 | |
| 32 | RenderFrameHost* last_created_frame() const { return last_created_frame_; } |
| 33 | |
| 34 | private: |
| 35 | RenderFrameHost* last_created_frame_; |
| 36 | }; |
| 37 | |
| 38 | class TestRenderFrameHost : public RenderFrameHostImpl, |
| 39 | public RenderFrameHostTester { |
[email protected] | 2a18ee22 | 2013-11-21 07:52:44 | [diff] [blame] | 40 | public: |
nasko | 9a45a9a | 2015-01-27 22:42:54 | [diff] [blame] | 41 | TestRenderFrameHost(SiteInstance* site_instance, |
| 42 | RenderViewHostImpl* render_view_host, |
[email protected] | 92404c6 | 2013-12-04 16:40:46 | [diff] [blame] | 43 | RenderFrameHostDelegate* delegate, |
kenrb | a719983 | 2015-01-22 23:44:59 | [diff] [blame] | 44 | RenderWidgetHostDelegate* rwh_delegate, |
[email protected] | 2a18ee22 | 2013-11-21 07:52:44 | [diff] [blame] | 45 | FrameTree* frame_tree, |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 46 | FrameTreeNode* frame_tree_node, |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 47 | int32_t routing_id, |
| 48 | int32_t widget_routing_id, |
kenrb | 32d18a4 | 2014-11-17 22:16:07 | [diff] [blame] | 49 | int flags); |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 50 | ~TestRenderFrameHost() override; |
[email protected] | 2a18ee22 | 2013-11-21 07:52:44 | [diff] [blame] | 51 | |
nick | ddc9d53 | 2015-04-16 17:46:29 | [diff] [blame] | 52 | // RenderFrameHostImpl overrides (same values, but in Test*/Mock* types) |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 53 | TestRenderViewHost* GetRenderViewHost() override; |
nick | ddc9d53 | 2015-04-16 17:46:29 | [diff] [blame] | 54 | MockRenderProcessHost* GetProcess() override; |
[email protected] | 6b50e36 | 2014-08-15 05:15:59 | [diff] [blame] | 55 | |
[email protected] | e2d2d420 | 2014-07-03 12:17:48 | [diff] [blame] | 56 | // RenderFrameHostTester implementation. |
nasko | 8c95dcf5 | 2015-06-02 13:44:48 | [diff] [blame] | 57 | void InitializeRenderFrameIfNeeded() override; |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 58 | TestRenderFrameHost* AppendChild(const std::string& frame_name) override; |
jyasskin | 4a12e67 | 2016-02-09 22:39:07 | [diff] [blame] | 59 | void Detach() override; |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 60 | void SimulateNavigationStart(const GURL& url) override; |
| 61 | void SimulateRedirect(const GURL& new_url) override; |
| 62 | void SimulateNavigationCommit(const GURL& url) override; |
| 63 | void SimulateNavigationError(const GURL& url, int error_code) override; |
| 64 | void SimulateNavigationErrorPageCommit() override; |
| 65 | void SimulateNavigationStop() override; |
avi | f9a94c7e | 2016-10-14 15:54:11 | [diff] [blame] | 66 | void SendNavigate(int nav_entry_id, |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 67 | bool did_create_new_entry, |
| 68 | const GURL& url) override; |
avi | f9a94c7e | 2016-10-14 15:54:11 | [diff] [blame] | 69 | void SendFailedNavigate(int nav_entry_id, |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 70 | bool did_create_new_entry, |
| 71 | const GURL& url) override; |
avi | f9a94c7e | 2016-10-14 15:54:11 | [diff] [blame] | 72 | void SendNavigateWithTransition(int nav_entry_id, |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 73 | bool did_create_new_entry, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 74 | const GURL& url, |
| 75 | ui::PageTransition transition) override; |
| 76 | void SetContentsMimeType(const std::string& mime_type) override; |
| 77 | void SendBeforeUnloadACK(bool proceed) override; |
| 78 | void SimulateSwapOutACK() override; |
avi | f9a94c7e | 2016-10-14 15:54:11 | [diff] [blame] | 79 | void NavigateAndCommitRendererInitiated(bool did_create_new_entry, |
scottmg | 045680d | 2016-09-08 19:56:14 | [diff] [blame] | 80 | const GURL& url) override; |
[email protected] | e2d2d420 | 2014-07-03 12:17:48 | [diff] [blame] | 81 | |
avi | f9a94c7e | 2016-10-14 15:54:11 | [diff] [blame] | 82 | void SendNavigateWithReplacement(int nav_entry_id, |
creis | 865ad44 | 2016-03-15 16:43:09 | [diff] [blame] | 83 | bool did_create_new_entry, |
| 84 | const GURL& url); |
| 85 | |
avi | 13963b6 | 2015-06-12 23:10:58 | [diff] [blame] | 86 | using ModificationCallback = |
| 87 | base::Callback<void(FrameHostMsg_DidCommitProvisionalLoad_Params*)>; |
| 88 | |
| 89 | void SendNavigateWithModificationCallback( |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 90 | int nav_entry_id, |
| 91 | bool did_create_new_entry, |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 92 | const GURL& url, |
avi | 13963b6 | 2015-06-12 23:10:58 | [diff] [blame] | 93 | const ModificationCallback& callback); |
| 94 | void SendNavigateWithParams( |
| 95 | FrameHostMsg_DidCommitProvisionalLoad_Params* params); |
carlosk | d6a4ef36 | 2015-03-04 10:46:17 | [diff] [blame] | 96 | |
| 97 | // With the current navigation logic this method is a no-op. |
| 98 | // PlzNavigate: this method simulates receiving a BeginNavigation IPC. |
| 99 | void SendRendererInitiatedNavigationRequest(const GURL& url, |
| 100 | bool has_user_gesture); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 101 | |
alexmos | 9573300 | 2015-08-24 16:38:09 | [diff] [blame] | 102 | void DidChangeOpener(int opener_routing_id); |
[email protected] | eaece547 | 2014-08-22 23:36:47 | [diff] [blame] | 103 | |
mkwst | f672e7ef | 2016-06-09 20:51:07 | [diff] [blame] | 104 | void DidEnforceInsecureRequestPolicy(blink::WebInsecureRequestPolicy policy); |
estark | a886b8d | 2015-12-18 21:53:08 | [diff] [blame] | 105 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 106 | // If set, navigations will appear to have cleared the history list in the |
| 107 | // RenderFrame |
| 108 | // (FrameHostMsg_DidCommitProvisionalLoad_Params::history_list_was_cleared). |
| 109 | // False by default. |
| 110 | void set_simulate_history_list_was_cleared(bool cleared) { |
| 111 | simulate_history_list_was_cleared_ = cleared; |
| 112 | } |
| 113 | |
clamy | 7c5016cc | 2014-12-19 15:58:29 | [diff] [blame] | 114 | // Advances the RenderFrameHost (and through it the RenderFrameHostManager) to |
| 115 | // a state where a new navigation can be committed by a renderer. Currently, |
| 116 | // this simulates a BeforeUnload ACK from the renderer. |
| 117 | // PlzNavigate: this simulates a BeforeUnload ACK from the renderer, and the |
| 118 | // interaction with the IO thread up until the response is ready to commit. |
carlosk | d6a4ef36 | 2015-03-04 10:46:17 | [diff] [blame] | 119 | void PrepareForCommit(); |
| 120 | |
| 121 | // This method does the same as PrepareForCommit. |
| 122 | // PlzNavigate: Beyond doing the same as PrepareForCommit, this method will |
| 123 | // also simulate a server redirect to |redirect_url|. If the URL is empty the |
| 124 | // redirect step is ignored. |
| 125 | void PrepareForCommitWithServerRedirect(const GURL& redirect_url); |
clamy | 7c5016cc | 2014-12-19 15:58:29 | [diff] [blame] | 126 | |
scottmg | d2b6c5d | 2016-09-01 18:36:25 | [diff] [blame] | 127 | // If we are doing a cross-site navigation, this simulates the current |
| 128 | // RenderFrameHost notifying that BeforeUnload has executed so the pending |
| 129 | // RenderFrameHost is resumed and can navigate. |
| 130 | // PlzNavigate: This simulates a BeforeUnload ACK from the renderer, and the |
| 131 | // interaction with the IO thread up until the response is ready to commit. |
| 132 | void PrepareForCommitIfNecessary(); |
| 133 | |
clamy | 5bf3611 | 2015-04-17 15:23:22 | [diff] [blame] | 134 | // PlzNavigate |
| 135 | void set_pending_commit(bool pending) { pending_commit_ = pending; } |
| 136 | bool pending_commit() const { return pending_commit_; } |
| 137 | |
ortuno | 77bb42c | 2016-08-01 18:41:09 | [diff] [blame] | 138 | // Creates a WebBluetooth Service with a dummy InterfaceRequest. |
| 139 | WebBluetoothServiceImpl* CreateWebBluetoothServiceForTesting(); |
| 140 | |
[email protected] | 2a18ee22 | 2013-11-21 07:52:44 | [diff] [blame] | 141 | private: |
avi | f9a94c7e | 2016-10-14 15:54:11 | [diff] [blame] | 142 | void SendNavigateWithParameters(int nav_entry_id, |
avi | 13963b6 | 2015-06-12 23:10:58 | [diff] [blame] | 143 | bool did_create_new_entry, |
creis | 865ad44 | 2016-03-15 16:43:09 | [diff] [blame] | 144 | bool should_replace_entry, |
avi | 13963b6 | 2015-06-12 23:10:58 | [diff] [blame] | 145 | const GURL& url, |
| 146 | ui::PageTransition transition, |
| 147 | int response_code, |
| 148 | const ModificationCallback& callback); |
| 149 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 150 | // Computes the page ID for a pending navigation in this RenderFrameHost; |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 151 | int32_t ComputeNextPageID(); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 152 | |
csharrison | dd06bab | 2016-07-22 14:15:02 | [diff] [blame] | 153 | void SimulateWillStartRequest(ui::PageTransition transition); |
| 154 | |
[email protected] | e2d2d420 | 2014-07-03 12:17:48 | [diff] [blame] | 155 | TestRenderFrameHostCreationObserver child_creation_observer_; |
| 156 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 157 | std::string contents_mime_type_; |
| 158 | |
| 159 | // See set_simulate_history_list_was_cleared() above. |
| 160 | bool simulate_history_list_was_cleared_; |
| 161 | |
[email protected] | 2a18ee22 | 2013-11-21 07:52:44 | [diff] [blame] | 162 | DISALLOW_COPY_AND_ASSIGN(TestRenderFrameHost); |
| 163 | }; |
| 164 | |
| 165 | } // namespace content |
| 166 | |
[email protected] | 4bfd461 | 2013-12-05 18:12:48 | [diff] [blame] | 167 | #endif // CONTENT_TEST_TEST_RENDER_FRAME_HOST_H_ |