IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / public / test / web_contents_tester.h
blobbf03dae06cb2c138e8cd03e5adbe8e9ca3dc4bec
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.
5 #ifndef CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_
6 #define CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_
8 #include "content/public/common/page_transition_types.h"
10 class GURL;
11 struct WebPreferences;
13 namespace content {
15 class BrowserContext;
16 struct Referrer;
17 class RenderViewHost;
18 class SiteInstance;
19 class WebContents;
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.
27 // Tests within content/ can directly static_cast WebContents objects retrieved
28 // or created as described above to TestWebContents.
30 // Design note: We considered two alternatives to this separate test interface
31 // approach:
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.
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.
45 class 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);
53 // Creates a WebContents enabled for testing.
54 static WebContents* CreateTestWebContents(
55 BrowserContext* browser_context,
56 SiteInstance* instance);
58 // Simulates the appropriate RenderView (pending if any, current otherwise)
59 // sending a navigate notification for the NavigationController pending entry.
60 virtual void CommitPendingNavigation() = 0;
62 virtual RenderViewHost* GetPendingRenderViewHost() const = 0;
64 // Creates a pending navigation to the given URL with the default parameters
65 // and then commits the load with a page ID one larger than any seen. This
66 // emulates what happens on a new navigation.
67 virtual void NavigateAndCommit(const GURL& url) = 0;
69 // Sets the loading state to the given value.
70 virtual void TestSetIsLoading(bool value) = 0;
72 // Simulates the current RVH notifying that it has unloaded so that the
73 // pending RVH navigation can proceed.
74 // Does nothing if no cross-navigation is pending.
75 virtual void ProceedWithCrossSiteNavigation() = 0;
77 virtual void TestDidNavigate(RenderViewHost* render_view_host,
78 int page_id,
79 const GURL& url,
80 PageTransition transition) = 0;
82 virtual void TestDidNavigateWithReferrer(
83 RenderViewHost* render_view_host,
84 int page_id,
85 const GURL& url,
86 const Referrer& referrer,
87 PageTransition transition) = 0;
89 // Promote GetWebkitPrefs to public.
90 virtual WebPreferences TestGetWebkitPrefs() = 0;
93 } // namespace content
95 #endif // CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_