Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / public / test / web_contents_tester.h
bloba96d86deeb1064e3acb56c54bca1956320a2b773
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;
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 // Gets the pending RenderFrameHost, if any, for the main frame. For the
63 // current RenderFrameHost of the main frame, use WebContents::GetMainFrame().
64 // PlzNavigate: When browser side navigation is enabled it returns the
65 // speculative RenderFrameHost for the main frame if one exists.
66 virtual RenderFrameHost* GetPendingMainFrame() const = 0;
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;
73 // Sets the loading state to the given value.
74 virtual void TestSetIsLoading(bool value) = 0;
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;
81 virtual void TestDidNavigate(RenderFrameHost* render_frame_host,
82 int page_id,
83 const GURL& url,
84 ui::PageTransition transition) = 0;
86 virtual void TestDidNavigateWithReferrer(
87 RenderFrameHost* render_frame_host,
88 int page_id,
89 const GURL& url,
90 const Referrer& referrer,
91 ui::PageTransition transition) = 0;
94 } // namespace content
96 #endif // CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_