• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_
6 #define CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_
7 
8 #include "content/public/common/page_transition_types.h"
9 
10 class GURL;
11 struct WebPreferences;
12 
13 namespace content {
14 
15 class BrowserContext;
16 struct Referrer;
17 class RenderViewHost;
18 class SiteInstance;
19 class WebContents;
20 
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.
26 //
27 // Tests within content/ can directly static_cast WebContents objects retrieved
28 // or created as described above to TestWebContents.
29 //
30 // Design note: We considered two alternatives to this separate test interface
31 // approach:
32 //
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.
38 //
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);
52 
53   // Creates a WebContents enabled for testing.
54   static WebContents* CreateTestWebContents(
55       BrowserContext* browser_context,
56       SiteInstance* instance);
57 
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;
61 
62   virtual RenderViewHost* GetPendingRenderViewHost() const = 0;
63 
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;
68 
69   // Sets the loading state to the given value.
70   virtual void TestSetIsLoading(bool value) = 0;
71 
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;
76 
77   virtual void TestDidNavigate(RenderViewHost* render_view_host,
78                                int page_id,
79                                const GURL& url,
80                                PageTransition transition) = 0;
81 
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;
88 
89   // Promote GetWebkitPrefs to public.
90   virtual WebPreferences TestGetWebkitPrefs() = 0;
91 };
92 
93 }  // namespace content
94 
95 #endif  // CONTENT_PUBLIC_TEST_WEB_CONTENTS_TESTER_H_
96