web_contents_tester.h revision 116680a4aac90f2aa7413d9095a592090648e557
1069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// Use of this source code is governed by a BSD-style license that can be 3069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// found in the LICENSE file. 4069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 5069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project#ifndef CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_ 6069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project#define CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_ 7069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 8069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project#include "content/public/common/page_transition_types.h" 9069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 10069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectclass GURL; 11069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 12069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectnamespace content { 13069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 14069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectclass BrowserContext; 15069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectclass RenderViewHost; 16069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectclass SiteInstance; 17069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectclass WebContents; 18069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectstruct Referrer; 19069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectstruct WebPreferences; 20069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 21069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// This interface allows embedders of content/ to write tests that depend on a 22069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// test version of WebContents. This interface can be retrieved from any 23069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// WebContents that was retrieved via a call to 24069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// RenderViewHostTestHarness::GetWebContents() (directly or indirectly) or 25069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// constructed explicitly via CreateTestWebContents. 26069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// 27069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// Tests within content/ can directly static_cast WebContents objects retrieved 28069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// or created as described above to TestWebContents. 29069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// 30069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// Design note: We considered two alternatives to this separate test interface 31069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// approach: 32069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// 33069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// a) Define a TestWebContents interface that inherits from WebContents, and 34069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// have the concrete TestWebContents inherit from it as well as from 35069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// WebContentsImpl. This approach was discarded as it introduces a diamond 36069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// inheritance pattern, which means we wouldn't be e.g. able to downcast from 37069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// WebContents to WebContentsImpl using static_cast. 38069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// 39069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// b) Define a TestWebContents interface that inherits from WebContents, and 40069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// have the concrete TestWebContents implement it, using composition of a 41069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// WebContentsImpl to implement most methods. This approach was discarded as 42069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// there is a fundamental assumption in content/ that a WebContents* can be 43069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// downcast to a WebContentsImpl*, and this wouldn't be true for TestWebContents 44069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project// objects. 45069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectclass WebContentsTester { 46069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project public: 47069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // Retrieves a WebContentsTester to drive tests of the specified WebContents. 48069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // As noted above you need to be sure the 'contents' object supports testing, 49d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath // i.e. is either created using one of the Create... functions below, or is 50d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath // retrieved via RenderViewHostTestHarness::GetWebContents(). 51d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath static WebContentsTester* For(WebContents* contents); 52d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath 53069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // Creates a WebContents enabled for testing. 54d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath static WebContents* CreateTestWebContents( 55069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project BrowserContext* browser_context, 56069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project SiteInstance* instance); 57069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 58069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // Simulates the appropriate RenderView (pending if any, current otherwise) 59069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // sending a navigate notification for the NavigationController pending entry. 60069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project virtual void CommitPendingNavigation() = 0; 61069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 62069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project virtual RenderViewHost* GetPendingRenderViewHost() const = 0; 63069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 64069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // Creates a pending navigation to the given URL with the default parameters 65069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // and then commits the load with a page ID one larger than any seen. This 66069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // emulates what happens on a new navigation. 67069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project virtual void NavigateAndCommit(const GURL& url) = 0; 68069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 69069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // Sets the loading state to the given value. 70069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project virtual void TestSetIsLoading(bool value) = 0; 71069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 72069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // Simulates the current RVH notifying that it has unloaded so that the 73069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // pending RVH navigation can proceed. 74069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // Does nothing if no cross-navigation is pending. 75069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project virtual void ProceedWithCrossSiteNavigation() = 0; 76069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 77069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project virtual void TestDidNavigate(RenderViewHost* render_view_host, 78069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project int page_id, 79069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project const GURL& url, 80069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project PageTransition transition) = 0; 81069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 82069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project virtual void TestDidNavigateWithReferrer( 83069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project RenderViewHost* render_view_host, 84069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project int page_id, 85069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project const GURL& url, 86069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project const Referrer& referrer, 87069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project PageTransition transition) = 0; 88069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 89069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project // Promote GetWebkitPrefs to public. 90069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project virtual WebPreferences TestGetWebkitPrefs() = 0; 91069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project}; 92069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 93069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project} // namespace content 94069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project 95069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project#endif // CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_ 96069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project