OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_TEST_TEST_RENDERER_HOST_H_ |
| 6 #define CONTENT_TEST_TEST_RENDERER_HOST_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" |
| 11 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/common/page_transition_types.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 class TestTabContents; |
| 16 class MockRenderProcessHost; |
| 17 class MockRenderProcessHostFactory; |
| 18 |
| 19 #if defined(USE_AURA) |
| 20 namespace aura { |
| 21 class RootWindow; |
| 22 namespace test { |
| 23 class TestStackingClient; |
| 24 } |
| 25 } |
| 26 #endif |
| 27 |
| 28 namespace content { |
| 29 |
| 30 class BrowserContext; |
| 31 class NavigationController; |
| 32 class RenderProcessHostFactory; |
| 33 class RenderViewHostDelegate; |
| 34 class TestRenderViewHostFactory; |
| 35 |
| 36 // An interface and utility for driving tests of RenderViewHost. |
| 37 class RenderViewHostTester { |
| 38 public: |
| 39 // Retrieves the RenderViewHostTester that drives the specified |
| 40 // RenderViewHost. The RenderViewHost must have been created while |
| 41 // RenderViewHost testing was enabled; use a |
| 42 // RenderViewHostTestEnabler instance (see below) to do this. |
| 43 static RenderViewHostTester* For(RenderViewHost* host); |
| 44 |
| 45 // This removes the need to expose |
| 46 // RenderViewHostImpl::set_send_accessibility_updated_notifications() |
| 47 // outside of content. |
| 48 static void EnableAccessibilityUpdatedNotifications(RenderViewHost* host); |
| 49 |
| 50 // If the given TabContents has a pending RVH, returns it, otherwise NULL. |
| 51 static RenderViewHost* GetPendingForController( |
| 52 NavigationController* controller); |
| 53 |
| 54 // This removes the need to expose |
| 55 // RenderViewHostImpl::is_swapped_out() outside of content. |
| 56 // |
| 57 // This is safe to call on any RenderViewHost, not just ones |
| 58 // constructed while a RenderViewHostTestEnabler is in play. |
| 59 static bool IsRenderViewHostSwappedOut(RenderViewHost* rvh); |
| 60 |
| 61 virtual ~RenderViewHostTester() {} |
| 62 |
| 63 // Gives tests access to RenderViewHostImpl::CreateRenderView. |
| 64 virtual bool CreateRenderView(const string16& frame_name, |
| 65 int32 max_page_id) = 0; |
| 66 |
| 67 // Calls OnMsgNavigate on the RenderViewHost with the given information, |
| 68 // setting the rest of the parameters in the message to the "typical" values. |
| 69 // This is a helper function for simulating the most common types of loads. |
| 70 virtual void SendNavigate(int page_id, const GURL& url) = 0; |
| 71 |
| 72 // Calls OnMsgNavigate on the RenderViewHost with the given information, |
| 73 // including a custom PageTransition. Sets the rest of the |
| 74 // parameters in the message to the "typical" values. This is a helper |
| 75 // function for simulating the most common types of loads. |
| 76 virtual void SendNavigateWithTransition(int page_id, const GURL& url, |
| 77 PageTransition transition) = 0; |
| 78 |
| 79 // Calls OnMsgShouldCloseACK on the RenderViewHost with the given parameter. |
| 80 virtual void SendShouldCloseACK(bool proceed) = 0; |
| 81 |
| 82 // If set, future loads will have |mime_type| set as the mime type. |
| 83 // If not set, the mime type will default to "text/html". |
| 84 virtual void SetContentsMimeType(const std::string& mime_type) = 0; |
| 85 |
| 86 // Simulates the SwapOut_ACK that fires if you commit a cross-site |
| 87 // navigation without making any network requests. |
| 88 virtual void SimulateSwapOutACK() = 0; |
| 89 |
| 90 // Makes the WasHidden/WasRestored calls to the RenderWidget that |
| 91 // tell it it has been hidden or restored from having been hidden. |
| 92 virtual void SimulateWasHidden() = 0; |
| 93 virtual void SimulateWasRestored() = 0; |
| 94 |
| 95 // Calls the RenderViewHosts' private OnMessageReceived function with the |
| 96 // given message. |
| 97 virtual bool TestOnMessageReceived(const IPC::Message& msg) = 0; |
| 98 }; |
| 99 |
| 100 // You can instantiate only one class like this at a time. During its |
| 101 // lifetime, RenderViewHost objects created may be used via |
| 102 // RenderViewHostTester. |
| 103 class RenderViewHostTestEnabler { |
| 104 public: |
| 105 RenderViewHostTestEnabler(); |
| 106 ~RenderViewHostTestEnabler(); |
| 107 |
| 108 private: |
| 109 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestEnabler); |
| 110 friend class RenderViewHostTestHarness; |
| 111 |
| 112 scoped_ptr<MockRenderProcessHostFactory> rph_factory_; |
| 113 scoped_ptr<TestRenderViewHostFactory> rvh_factory_; |
| 114 }; |
| 115 |
| 116 // RenderViewHostTestHarness --------------------------------------------------- |
| 117 class RenderViewHostTestHarness : public testing::Test { |
| 118 public: |
| 119 RenderViewHostTestHarness(); |
| 120 virtual ~RenderViewHostTestHarness(); |
| 121 |
| 122 NavigationController& controller(); |
| 123 virtual TestTabContents* contents(); |
| 124 RenderViewHost* rvh(); |
| 125 RenderViewHost* pending_rvh(); |
| 126 RenderViewHost* active_rvh(); |
| 127 BrowserContext* browser_context(); |
| 128 MockRenderProcessHost* process(); |
| 129 |
| 130 // Frees the current tab contents for tests that want to test destruction. |
| 131 void DeleteContents(); |
| 132 |
| 133 // Sets the current tab contents for tests that want to alter it. Takes |
| 134 // ownership of the TestTabContents passed. |
| 135 virtual void SetContents(TestTabContents* contents); |
| 136 |
| 137 // Creates a new TestTabContents. Ownership passes to the caller. |
| 138 TestTabContents* CreateTestTabContents(); |
| 139 |
| 140 // Cover for |contents()->NavigateAndCommit(url)|. See |
| 141 // TestTabContents::NavigateAndCommit for details. |
| 142 void NavigateAndCommit(const GURL& url); |
| 143 |
| 144 // Simulates a reload of the current page. |
| 145 void Reload(); |
| 146 |
| 147 protected: |
| 148 // testing::Test |
| 149 virtual void SetUp() OVERRIDE; |
| 150 virtual void TearDown() OVERRIDE; |
| 151 |
| 152 // Replaces the RPH being used. |
| 153 void SetRenderProcessHostFactory(RenderProcessHostFactory* factory); |
| 154 |
| 155 // This browser context will be created in SetUp if it has not already been |
| 156 // created. This allows tests to override the browser context if they so |
| 157 // choose in their own SetUp function before calling the base class's (us) |
| 158 // SetUp(). |
| 159 scoped_ptr<BrowserContext> browser_context_; |
| 160 |
| 161 MessageLoopForUI message_loop_; |
| 162 |
| 163 private: |
| 164 scoped_ptr<TestTabContents> contents_; |
| 165 #if defined(USE_AURA) |
| 166 scoped_ptr<aura::RootWindow> root_window_; |
| 167 scoped_ptr<aura::test::TestStackingClient> test_stacking_client_; |
| 168 #endif |
| 169 RenderViewHostTestEnabler rvh_test_enabler_; |
| 170 |
| 171 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestHarness); |
| 172 }; |
| 173 |
| 174 } // namespace content |
| 175 |
| 176 // TODO(joi): Remove this after converting all clients. |
| 177 using content::RenderViewHostTestHarness; |
| 178 |
| 179 #endif // CONTENT_TEST_TEST_RENDERER_HOST_H_ |
OLD | NEW |