Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / public / test / web_contents_tester.h
blob1f28160f783b88c8f8c0b005d9f40b41f4911ada
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 <string>
10 #include "ui/base/page_transition_types.h"
12 class GURL;
14 namespace content {
16 class BrowserContext;
17 class RenderFrameHost;
18 class RenderViewHost;
19 class SiteInstance;
20 class WebContents;
21 struct Referrer;
23 // This interface allows embedders of content/ to write tests that depend on a
24 // test version of WebContents. This interface can be retrieved from any
25 // WebContents that was retrieved via a call to
26 // RenderViewHostTestHarness::GetWebContents() (directly or indirectly) or
27 // constructed explicitly via CreateTestWebContents.
29 // Tests within content/ can directly static_cast WebContents objects retrieved
30 // or created as described above to TestWebContents.
32 // Design note: We considered two alternatives to this separate test interface
33 // approach:
35 // a) Define a TestWebContents interface that inherits from WebContents, and
36 // have the concrete TestWebContents inherit from it as well as from
37 // WebContentsImpl. This approach was discarded as it introduces a diamond
38 // inheritance pattern, which means we wouldn't be e.g. able to downcast from
39 // WebContents to WebContentsImpl using static_cast.
41 // b) Define a TestWebContents interface that inherits from WebContents, and
42 // have the concrete TestWebContents implement it, using composition of a
43 // WebContentsImpl to implement most methods. This approach was discarded as
44 // there is a fundamental assumption in content/ that a WebContents* can be
45 // downcast to a WebContentsImpl*, and this wouldn't be true for TestWebContents
46 // objects.
47 class WebContentsTester {
48 public:
49 // Retrieves a WebContentsTester to drive tests of the specified WebContents.
50 // As noted above you need to be sure the 'contents' object supports testing,
51 // i.e. is either created using one of the Create... functions below, or is
52 // retrieved via RenderViewHostTestHarness::GetWebContents().
53 static WebContentsTester* For(WebContents* contents);
55 // Creates a WebContents enabled for testing.
56 static WebContents* CreateTestWebContents(
57 BrowserContext* browser_context,
58 SiteInstance* instance);
60 // Simulates the appropriate RenderView (pending if any, current otherwise)
61 // sending a navigate notification for the NavigationController pending entry.
62 virtual void CommitPendingNavigation() = 0;
64 // Gets the pending RenderFrameHost, if any, for the main frame. For the
65 // current RenderFrameHost of the main frame, use WebContents::GetMainFrame().
66 // PlzNavigate: When browser side navigation is enabled it returns the
67 // speculative RenderFrameHost for the main frame if one exists.
68 virtual RenderFrameHost* GetPendingMainFrame() const = 0;
70 // Creates a pending navigation to the given URL with the default parameters
71 // and then commits the load with a page ID one larger than any seen. This
72 // emulates what happens on a new navigation.
73 virtual void NavigateAndCommit(const GURL& url) = 0;
75 // Sets the loading state to the given value.
76 virtual void TestSetIsLoading(bool value) = 0;
78 // Simulates the current RVH notifying that it has unloaded so that the
79 // pending RVH navigation can proceed.
80 // Does nothing if no cross-navigation is pending.
81 virtual void ProceedWithCrossSiteNavigation() = 0;
83 // Simulates a navigation with the given information.
85 // Guidance for calling these:
86 // - nav_entry_id should be 0 if simulating a renderer-initiated navigation;
87 // if simulating a browser-initiated one, pass the GetUniqueID() value of
88 // the NavigationController's PendingEntry.
89 // - did_create_new_entry should be true if simulating a navigation that
90 // created a new navigation entry; false for history navigations, reloads,
91 // and other navigations that don't affect the history list.
92 virtual void TestDidNavigate(RenderFrameHost* render_frame_host,
93 int page_id,
94 int nav_entry_id,
95 bool did_create_new_entry,
96 const GURL& url,
97 ui::PageTransition transition) = 0;
98 virtual void TestDidNavigateWithReferrer(RenderFrameHost* render_frame_host,
99 int page_id,
100 int nav_entry_id,
101 bool did_create_new_entry,
102 const GURL& url,
103 const Referrer& referrer,
104 ui::PageTransition transition) = 0;
106 // Returns headers that were passed in the previous SaveFrameWithHeaders(...)
107 // call.
108 virtual const std::string& GetSaveFrameHeaders() = 0;
111 } // namespace content
113 #endif // CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_