OLD | NEW |
(Empty) | |
| 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_TEST_WEB_CONTENTS_TESTER_H_ |
| 6 #define CONTENT_TEST_WEB_CONTENTS_TESTER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "content/public/common/page_transition_types.h" |
| 10 |
| 11 class GURL; |
| 12 struct WebPreferences; |
| 13 |
| 14 namespace content { |
| 15 |
| 16 class BrowserContext; |
| 17 struct Referrer; |
| 18 class RenderViewHost; |
| 19 class SiteInstance; |
| 20 class WebContents; |
| 21 |
| 22 // This interface allows embedders of content/ to write tests that |
| 23 // depend on a test version of WebContents. This interface can be |
| 24 // retrieved from any content::WebContents that was retrieved via a |
| 25 // call to RenderViewHostTestHarness::GetWebContents() (directly or |
| 26 // indirectly) or constructed explicitly via one of the |
| 27 // WebContentsTester::Create... methods. |
| 28 // |
| 29 // Tests within content/ can directly static_cast WebContents objects |
| 30 // retrieved or created as described above to |
| 31 // content::TestWebContents. |
| 32 // |
| 33 // Design note: We considered two alternatives to this separate test |
| 34 // interface approach: |
| 35 // |
| 36 // a) Define a TestWebContents interface that inherits fromn |
| 37 // WebContents, and have the concrete TestWebContents inherit from it |
| 38 // as well as from content::WebContentsImpl. This approach was |
| 39 // discarded as it introduces a diamond inheritance pattern, which |
| 40 // means we wouldn't be e.g. able to downcast from WebContents to |
| 41 // WebContentsImpl using static_cast. |
| 42 // |
| 43 // b) Define a TestWebContents interface that inherits from |
| 44 // WebContents, and have the concrete TestWebContents implement it, |
| 45 // using composition of a content::WebContentsImpl to implement most |
| 46 // methods. This approach was discarded as there is a fundamental |
| 47 // assumption in content/ that a WebContents* can be downcast to a |
| 48 // WebContentsImpl*, and this wouldn't be true for TestWebContents |
| 49 // objects. |
| 50 class WebContentsTester { |
| 51 public: |
| 52 // Retrieves a WebContentsTester to drive tests of the specified |
| 53 // WebContents. As noted above you need to be sure the 'contents' |
| 54 // object supports testing, i.e. is either created using one of the |
| 55 // Create... functions below, or is retrieved via |
| 56 // RenderViewHostTestHarness::GetWebContents(). |
| 57 static WebContentsTester* For(WebContents* contents); |
| 58 |
| 59 // Creates a WebContents enabled for testing. |
| 60 static WebContents* CreateTestWebContents( |
| 61 BrowserContext* browser_context, |
| 62 SiteInstance* instance); |
| 63 |
| 64 // Deprecated. Creates a WebContents enabled for testing, that |
| 65 // counts the number of times SetFocusToLocationBar is called. |
| 66 static WebContents* |
| 67 CreateTestWebContentsCountSetFocusToLocationBar( |
| 68 BrowserContext* browser_context, |
| 69 SiteInstance* instance); |
| 70 |
| 71 // Deprecated. Creates a WebContents enabled for testing, that |
| 72 // counts the number of times Focus is called. |
| 73 static WebContents* CreateTestWebContentsCountFocus( |
| 74 BrowserContext* browser_context, |
| 75 SiteInstance* instance); |
| 76 |
| 77 // Simulates the appropriate RenderView (pending if any, current otherwise) |
| 78 // sending a navigate notification for the NavigationController pending entry. |
| 79 virtual void CommitPendingNavigation() = 0; |
| 80 |
| 81 // Only implementations retrieved via the deprecated |
| 82 // CreateTestWebContentsFor... methods above will implement this |
| 83 // method. It retrieves the number of times the focus-related calls |
| 84 // in question have been made. |
| 85 virtual int GetNumberOfFocusCalls() = 0; |
| 86 |
| 87 // TODO(joi): Rename this and other hacker_style virtual methods. |
| 88 virtual content::RenderViewHost* pending_rvh() const = 0; |
| 89 |
| 90 // Creates a pending navigation to the given URL with the default parameters |
| 91 // and then commits the load with a page ID one larger than any seen. This |
| 92 // emulates what happens on a new navigation. |
| 93 virtual void NavigateAndCommit(const GURL& url) = 0; |
| 94 |
| 95 // Simulates the current RVH notifying that it has unloaded so that the |
| 96 // pending RVH navigation can proceed. |
| 97 // Does nothing if no cross-navigation is pending. |
| 98 virtual void ProceedWithCrossSiteNavigation() = 0; |
| 99 |
| 100 virtual void TestDidNavigate(content::RenderViewHost* render_view_host, |
| 101 int page_id, |
| 102 const GURL& url, |
| 103 content::PageTransition transition) = 0; |
| 104 |
| 105 virtual void TestDidNavigateWithReferrer( |
| 106 content::RenderViewHost* render_view_host, |
| 107 int page_id, |
| 108 const GURL& url, |
| 109 const content::Referrer& referrer, |
| 110 content::PageTransition transition) = 0; |
| 111 |
| 112 // Promote GetWebkitPrefs to public. |
| 113 virtual WebPreferences TestGetWebkitPrefs() = 0; |
| 114 }; |
| 115 |
| 116 } // namespace content |
| 117 |
| 118 #endif // CONTENT_TEST_WEB_CONTENTS_TESTER_H_ |
OLD | NEW |