web_contents_tester.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_ 6#define CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_ 7 8#include "content/public/common/page_transition_types.h" 9 10class GURL; 11struct WebPreferences; 12 13namespace content { 14 15class BrowserContext; 16struct Referrer; 17class RenderViewHost; 18class SiteInstance; 19class WebContents; 20 21// This interface allows embedders of content/ to write tests that depend on a 22// test version of WebContents. This interface can be retrieved from any 23// WebContents that was retrieved via a call to 24// RenderViewHostTestHarness::GetWebContents() (directly or indirectly) or 25// constructed explicitly via CreateTestWebContents. 26// 27// Tests within content/ can directly static_cast WebContents objects retrieved 28// or created as described above to TestWebContents. 29// 30// Design note: We considered two alternatives to this separate test interface 31// approach: 32// 33// a) Define a TestWebContents interface that inherits from WebContents, and 34// have the concrete TestWebContents inherit from it as well as from 35// WebContentsImpl. This approach was discarded as it introduces a diamond 36// inheritance pattern, which means we wouldn't be e.g. able to downcast from 37// WebContents to WebContentsImpl using static_cast. 38// 39// b) Define a TestWebContents interface that inherits from WebContents, and 40// have the concrete TestWebContents implement it, using composition of a 41// WebContentsImpl to implement most methods. This approach was discarded as 42// there is a fundamental assumption in content/ that a WebContents* can be 43// downcast to a WebContentsImpl*, and this wouldn't be true for TestWebContents 44// objects. 45class WebContentsTester { 46 public: 47 // Retrieves a WebContentsTester to drive tests of the specified WebContents. 48 // As noted above you need to be sure the 'contents' object supports testing, 49 // i.e. is either created using one of the Create... functions below, or is 50 // retrieved via RenderViewHostTestHarness::GetWebContents(). 51 static WebContentsTester* For(WebContents* contents); 52 53 // Creates a WebContents enabled for testing. 54 static WebContents* CreateTestWebContents( 55 BrowserContext* browser_context, 56 SiteInstance* instance); 57 58 // Deprecated. Creates a WebContents enabled for testing, that 59 // Simulates the appropriate RenderView (pending if any, current otherwise) 60 // sending a navigate notification for the NavigationController pending entry. 61 virtual void CommitPendingNavigation() = 0; 62 63 virtual RenderViewHost* GetPendingRenderViewHost() const = 0; 64 65 // Creates a pending navigation to the given URL with the default parameters 66 // and then commits the load with a page ID one larger than any seen. This 67 // emulates what happens on a new navigation. 68 virtual void NavigateAndCommit(const GURL& url) = 0; 69 70 // Sets the loading state to the given value. 71 virtual void TestSetIsLoading(bool value) = 0; 72 73 // Simulates the current RVH notifying that it has unloaded so that the 74 // pending RVH navigation can proceed. 75 // Does nothing if no cross-navigation is pending. 76 virtual void ProceedWithCrossSiteNavigation() = 0; 77 78 virtual void TestDidNavigate(RenderViewHost* render_view_host, 79 int page_id, 80 const GURL& url, 81 PageTransition transition) = 0; 82 83 virtual void TestDidNavigateWithReferrer( 84 RenderViewHost* render_view_host, 85 int page_id, 86 const GURL& url, 87 const Referrer& referrer, 88 PageTransition transition) = 0; 89 90 // Promote GetWebkitPrefs to public. 91 virtual WebPreferences TestGetWebkitPrefs() = 0; 92}; 93 94} // namespace content 95 96#endif // CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_ 97