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