Removing uses of X11 native key events.
[chromium-blink-merge.git] / content / public / test / web_contents_tester.h
blob24953ed9c258111a4428ac22d0fee1d09a4b2981
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 "ui/base/page_transition_types.h"
10 class GURL;
12 namespace content {
14 class BrowserContext;
15 class RenderFrameHost;
16 class RenderViewHost;
17 class SiteInstance;
18 class WebContents;
19 struct Referrer;
20 struct WebPreferences;
22 // This interface allows embedders of content/ to write tests that depend on a
23 // test version of WebContents. This interface can be retrieved from any
24 // WebContents that was retrieved via a call to
25 // RenderViewHostTestHarness::GetWebContents() (directly or indirectly) or
26 // constructed explicitly via CreateTestWebContents.
28 // Tests within content/ can directly static_cast WebContents objects retrieved
29 // or created as described above to TestWebContents.
31 // Design note: We considered two alternatives to this separate test interface
32 // approach:
34 // a) Define a TestWebContents interface that inherits from WebContents, and
35 // have the concrete TestWebContents inherit from it as well as from
36 // WebContentsImpl. This approach was discarded as it introduces a diamond
37 // inheritance pattern, which means we wouldn't be e.g. able to downcast from
38 // WebContents to WebContentsImpl using static_cast.
40 // b) Define a TestWebContents interface that inherits from WebContents, and
41 // have the concrete TestWebContents implement it, using composition of a
42 // WebContentsImpl to implement most methods. This approach was discarded as
43 // there is a fundamental assumption in content/ that a WebContents* can be
44 // downcast to a WebContentsImpl*, and this wouldn't be true for TestWebContents
45 // objects.
46 class WebContentsTester {
47 public:
48 // Retrieves a WebContentsTester to drive tests of the specified WebContents.
49 // As noted above you need to be sure the 'contents' object supports testing,
50 // i.e. is either created using one of the Create... functions below, or is
51 // retrieved via RenderViewHostTestHarness::GetWebContents().
52 static WebContentsTester* For(WebContents* contents);
54 // Creates a WebContents enabled for testing.
55 static WebContents* CreateTestWebContents(
56 BrowserContext* browser_context,
57 SiteInstance* instance);
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;
63 // Gets the pending RenderFrameHost, if any, for the main frame. For the
64 // current RenderFrameHost of the main frame, use WebContents::GetMainFrame().
65 virtual RenderFrameHost* GetPendingMainFrame() const = 0;
67 // Creates a pending navigation to the given URL with the default parameters
68 // and then commits the load with a page ID one larger than any seen. This
69 // emulates what happens on a new navigation.
70 virtual void NavigateAndCommit(const GURL& url) = 0;
72 // Sets the loading state to the given value.
73 virtual void TestSetIsLoading(bool value) = 0;
75 // Simulates the current RVH notifying that it has unloaded so that the
76 // pending RVH navigation can proceed.
77 // Does nothing if no cross-navigation is pending.
78 virtual void ProceedWithCrossSiteNavigation() = 0;
80 virtual void TestDidNavigate(RenderFrameHost* render_frame_host,
81 int page_id,
82 const GURL& url,
83 ui::PageTransition transition) = 0;
85 virtual void TestDidNavigateWithReferrer(
86 RenderFrameHost* render_frame_host,
87 int page_id,
88 const GURL& url,
89 const Referrer& referrer,
90 ui::PageTransition transition) = 0;
92 // Promote ComputeWebkitPrefs to public.
93 virtual WebPreferences TestComputeWebkitPrefs() = 0;
96 } // namespace content
98 #endif // CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_