OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ | 5 #ifndef CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ |
6 #define CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ | 6 #define CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ |
7 | 7 |
8 // A collection of functions designed for use with content_shell based browser | 8 // A collection of functions designed for use with content_shell based browser |
9 // tests internal to the content/ module. | 9 // tests internal to the content/ module. |
10 // Note: If a function here also works with browser_tests, it should be in | 10 // Note: If a function here also works with browser_tests, it should be in |
11 // the content public API. | 11 // the content public API. |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/weak_ptr.h" |
17 #include "cc/surfaces/surface_id.h" | 18 #include "cc/surfaces/surface_id.h" |
| 19 #include "content/public/browser/navigation_handle.h" |
18 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 20 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 21 #include "content/public/browser/web_contents_observer.h" |
19 #include "url/gurl.h" | 22 #include "url/gurl.h" |
20 | 23 |
21 namespace cc { | 24 namespace cc { |
22 class SurfaceManager; | 25 class SurfaceManager; |
23 } | 26 } |
24 | 27 |
25 namespace content { | 28 namespace content { |
26 | 29 |
27 class FrameTreeNode; | 30 class FrameTreeNode; |
| 31 class MessageLoopRunner; |
28 class RenderWidgetHostViewChildFrame; | 32 class RenderWidgetHostViewChildFrame; |
29 class Shell; | 33 class Shell; |
30 class SiteInstance; | 34 class SiteInstance; |
31 class ToRenderFrameHost; | 35 class ToRenderFrameHost; |
32 | 36 |
33 // Navigates the frame represented by |node| to |url|, blocking until the | 37 // Navigates the frame represented by |node| to |url|, blocking until the |
34 // navigation finishes. | 38 // navigation finishes. |
35 void NavigateFrameToURL(FrameTreeNode* node, const GURL& url); | 39 void NavigateFrameToURL(FrameTreeNode* node, const GURL& url); |
36 | 40 |
| 41 // Sets the DialogManager to proceed by default or not when showing a |
| 42 // BeforeUnload dialog. |
| 43 void SetShouldProceedOnBeforeUnload(Shell* shell, bool proceed); |
| 44 |
37 // Creates compact textual representations of the state of the frame tree that | 45 // Creates compact textual representations of the state of the frame tree that |
38 // is appropriate for use in assertions. | 46 // is appropriate for use in assertions. |
39 // | 47 // |
40 // The diagrams show frame tree structure, the SiteInstance of current frames, | 48 // The diagrams show frame tree structure, the SiteInstance of current frames, |
41 // presence of pending frames, and the SiteInstances of any and all proxies. | 49 // presence of pending frames, and the SiteInstances of any and all proxies. |
42 // They look like this: | 50 // They look like this: |
43 // | 51 // |
44 // Site A (D pending) -- proxies for B C | 52 // Site A (D pending) -- proxies for B C |
45 // |--Site B --------- proxies for A C | 53 // |--Site B --------- proxies for A C |
46 // +--Site C --------- proxies for B A | 54 // +--Site C --------- proxies for B A |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 void RequestBeginning( | 104 void RequestBeginning( |
97 net::URLRequest* request, | 105 net::URLRequest* request, |
98 content::ResourceContext* resource_context, | 106 content::ResourceContext* resource_context, |
99 content::AppCacheService* appcache_service, | 107 content::AppCacheService* appcache_service, |
100 ResourceType resource_type, | 108 ResourceType resource_type, |
101 ScopedVector<content::ResourceThrottle>* throttles) override; | 109 ScopedVector<content::ResourceThrottle>* throttles) override; |
102 | 110 |
103 GURL url_; | 111 GURL url_; |
104 }; | 112 }; |
105 | 113 |
| 114 // This class can be used to pause and resume navigations, based on a URL |
| 115 // match. Note that it only keeps track of one navigation at a time. |
| 116 class TestNavigationManager : public WebContentsObserver { |
| 117 public: |
| 118 // Currently this monitors any frame in WebContents. |
| 119 // TODO(clamy): Extend this class so that it can monitor a specific frame. |
| 120 TestNavigationManager(WebContents* web_contents, const GURL& url); |
| 121 ~TestNavigationManager() override; |
| 122 |
| 123 // Waits until the navigation request is ready to be sent to the network |
| 124 // stack. The navigation will be paused until it is resumed by calling |
| 125 // ResumeNavigation. |
| 126 void WaitForWillStartRequest(); |
| 127 |
| 128 // Resumes the navigation if it was previously paused. |
| 129 void ResumeNavigation(); |
| 130 |
| 131 // Waits until the navigation has been finished. Users of this method should |
| 132 // first use WaitForWillStartRequest, then call ResumeNavigation, and only |
| 133 // then WaitForNavigationFinished. |
| 134 // TODO(clamy): Do not pause the navigation in WillStartRequest by default. |
| 135 void WaitForNavigationFinished(); |
| 136 |
| 137 private: |
| 138 // WebContentsObserver implementation. |
| 139 void DidStartNavigation(NavigationHandle* handle) override; |
| 140 void DidFinishNavigation(NavigationHandle* handle) override; |
| 141 |
| 142 // Called when the NavigationThrottle pauses the navigation in |
| 143 // WillStartRequest. |
| 144 void OnWillStartRequest(); |
| 145 |
| 146 const GURL url_; |
| 147 bool navigation_paused_; |
| 148 NavigationHandle* handle_; |
| 149 scoped_refptr<MessageLoopRunner> loop_runner_; |
| 150 |
| 151 base::WeakPtrFactory<TestNavigationManager> weak_factory_; |
| 152 }; |
| 153 |
106 // Helper class to assist with hit testing surfaces in multiple processes. | 154 // Helper class to assist with hit testing surfaces in multiple processes. |
107 // WaitForSurfaceReady() will only return after a Surface from |target_view| | 155 // WaitForSurfaceReady() will only return after a Surface from |target_view| |
108 // has been composited in the top-level frame's Surface. At that point, | 156 // has been composited in the top-level frame's Surface. At that point, |
109 // browser process hit testing to target_view's Surface can succeed. | 157 // browser process hit testing to target_view's Surface can succeed. |
110 class SurfaceHitTestReadyNotifier { | 158 class SurfaceHitTestReadyNotifier { |
111 public: | 159 public: |
112 SurfaceHitTestReadyNotifier(RenderWidgetHostViewChildFrame* target_view); | 160 SurfaceHitTestReadyNotifier(RenderWidgetHostViewChildFrame* target_view); |
113 ~SurfaceHitTestReadyNotifier() {} | 161 ~SurfaceHitTestReadyNotifier() {} |
114 | 162 |
115 void WaitForSurfaceReady(); | 163 void WaitForSurfaceReady(); |
116 | 164 |
117 private: | 165 private: |
118 bool ContainsSurfaceId(cc::SurfaceId container_surface_id); | 166 bool ContainsSurfaceId(cc::SurfaceId container_surface_id); |
119 | 167 |
120 cc::SurfaceManager* surface_manager_; | 168 cc::SurfaceManager* surface_manager_; |
121 cc::SurfaceId root_surface_id_; | 169 cc::SurfaceId root_surface_id_; |
122 RenderWidgetHostViewChildFrame* target_view_; | 170 RenderWidgetHostViewChildFrame* target_view_; |
123 | 171 |
124 DISALLOW_COPY_AND_ASSIGN(SurfaceHitTestReadyNotifier); | 172 DISALLOW_COPY_AND_ASSIGN(SurfaceHitTestReadyNotifier); |
125 }; | 173 }; |
126 | 174 |
127 } // namespace content | 175 } // namespace content |
128 | 176 |
129 #endif // CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ | 177 #endif // CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ |
OLD | NEW |