Chromium Code Reviews| 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/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "cc/surfaces/surface_id.h" | 19 #include "cc/surfaces/surface_id.h" |
| 20 #include "content/public/browser/navigation_handle.h" | |
| 21 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 20 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 22 #include "content/public/browser/web_contents_delegate.h" | 21 #include "content/public/browser/web_contents_delegate.h" |
| 23 #include "content/public/browser/web_contents_observer.h" | 22 #include "content/public/test/browser_test_utils.h" |
| 24 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 25 | 24 |
| 26 namespace cc { | 25 namespace cc { |
| 27 class SurfaceManager; | 26 class SurfaceManager; |
| 28 } | 27 } |
| 29 | 28 |
| 30 namespace content { | 29 namespace content { |
| 31 | 30 |
| 32 class FrameTreeNode; | 31 class FrameTreeNode; |
| 33 class MessageLoopRunner; | 32 class MessageLoopRunner; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 void RequestBeginning( | 109 void RequestBeginning( |
| 111 net::URLRequest* request, | 110 net::URLRequest* request, |
| 112 content::ResourceContext* resource_context, | 111 content::ResourceContext* resource_context, |
| 113 content::AppCacheService* appcache_service, | 112 content::AppCacheService* appcache_service, |
| 114 ResourceType resource_type, | 113 ResourceType resource_type, |
| 115 ScopedVector<content::ResourceThrottle>* throttles) override; | 114 ScopedVector<content::ResourceThrottle>* throttles) override; |
| 116 | 115 |
| 117 GURL url_; | 116 GURL url_; |
| 118 }; | 117 }; |
| 119 | 118 |
| 120 // This class can be used to pause and resume navigations, based on a URL | |
| 121 // match. Note that it only keeps track of one navigation at a time. | |
| 122 // Navigations are paused automatically before hitting the network, and are | |
| 123 // resumed automatically if a Wait method is called for a future event. | |
| 124 class TestNavigationManager : public WebContentsObserver { | |
| 125 public: | |
| 126 // Monitors notifications within the given frame tree node. Use the other | |
| 127 // constructor if the manager should monitor all frames, which is equivalent | |
| 128 // to passing kFrameTreeNodeInvalidId for |frame_tree_node_id|. | |
| 129 TestNavigationManager(int frame_tree_node_id, | |
| 130 WebContents* web_contents, | |
| 131 const GURL& url); | |
| 132 | |
| 133 // Monitors any frame in WebContents. | |
| 134 TestNavigationManager(WebContents* web_contents, const GURL& url); | |
| 135 | |
| 136 ~TestNavigationManager() override; | |
| 137 | |
| 138 // Waits until the navigation request is ready to be sent to the network | |
| 139 // stack. | |
| 140 void WaitForWillStartRequest(); | |
| 141 | |
| 142 // Waits until the navigation has been finished. Will automatically resume | |
| 143 // navigations paused before this point. | |
| 144 void WaitForNavigationFinished(); | |
| 145 | |
| 146 private: | |
| 147 // WebContentsObserver: | |
| 148 void DidStartNavigation(NavigationHandle* handle) override; | |
| 149 void DidFinishNavigation(NavigationHandle* handle) override; | |
| 150 | |
| 151 // Called when the NavigationThrottle pauses the navigation in | |
| 152 // WillStartRequest. | |
| 153 void OnWillStartRequest(); | |
| 154 | |
| 155 // Resumes the navigation. | |
| 156 void ResumeNavigation(); | |
| 157 | |
| 158 // If this member is not |kFrameTreeNodeInvalidId|, notifications are filtered | |
| 159 // so only this frame is monitored. | |
| 160 int filtering_frame_tree_node_id_; | |
| 161 | |
| 162 const GURL url_; | |
| 163 bool navigation_paused_; | |
| 164 NavigationHandle* handle_; | |
| 165 scoped_refptr<MessageLoopRunner> will_start_loop_runner_; | |
| 166 scoped_refptr<MessageLoopRunner> did_finish_loop_runner_; | |
| 167 | |
| 168 base::WeakPtrFactory<TestNavigationManager> weak_factory_; | |
| 169 }; | |
| 170 | |
| 171 // Helper class to assist with hit testing surfaces in multiple processes. | 119 // Helper class to assist with hit testing surfaces in multiple processes. |
| 172 // WaitForSurfaceReady() will only return after a Surface from |target_view| | 120 // WaitForSurfaceReady() will only return after a Surface from |target_view| |
| 173 // has been composited in the top-level frame's Surface. At that point, | 121 // has been composited in the top-level frame's Surface. At that point, |
| 174 // browser process hit testing to target_view's Surface can succeed. | 122 // browser process hit testing to target_view's Surface can succeed. |
| 175 class SurfaceHitTestReadyNotifier { | 123 class SurfaceHitTestReadyNotifier { |
| 176 public: | 124 public: |
| 177 SurfaceHitTestReadyNotifier(RenderWidgetHostViewChildFrame* target_view); | 125 SurfaceHitTestReadyNotifier(RenderWidgetHostViewChildFrame* target_view); |
| 178 ~SurfaceHitTestReadyNotifier() {} | 126 ~SurfaceHitTestReadyNotifier() {} |
| 179 | 127 |
| 180 void WaitForSurfaceReady(); | 128 void WaitForSurfaceReady(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 201 const FileChooserParams& params) override; | 149 const FileChooserParams& params) override; |
| 202 | 150 |
| 203 // Whether the file dialog was shown. | 151 // Whether the file dialog was shown. |
| 204 bool file_chosen() { return file_chosen_; } | 152 bool file_chosen() { return file_chosen_; } |
| 205 | 153 |
| 206 private: | 154 private: |
| 207 base::FilePath file_; | 155 base::FilePath file_; |
| 208 bool file_chosen_; | 156 bool file_chosen_; |
| 209 }; | 157 }; |
| 210 | 158 |
| 159 // This class is a TestNavigationManager that only monitors notifications within | |
| 160 // the given frame tree node. | |
| 161 class PerFrameTestNavigationManager : public TestNavigationManager { | |
|
nasko
2016/08/02 16:22:16
nit: Drop the "Per" prefix. We usually prefix some
Charlie Harrison
2016/08/02 16:47:13
Done.
| |
| 162 public: | |
| 163 PerFrameTestNavigationManager(int frame_tree_node_id, | |
| 164 WebContents* web_contents, | |
| 165 const GURL& url); | |
| 166 private: | |
| 167 // TestNavigationManager: | |
| 168 bool ShouldMonitorNavigation(NavigationHandle* handle) override; | |
| 169 | |
| 170 // Notifications are filtered so only this frame is monitored. | |
| 171 int filtering_frame_tree_node_id_; | |
| 172 | |
| 173 DISALLOW_COPY_AND_ASSIGN(PerFrameTestNavigationManager); | |
| 174 }; | |
| 175 | |
| 211 } // namespace content | 176 } // namespace content |
| 212 | 177 |
| 213 #endif // CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ | 178 #endif // CONTENT_TEST_CONTENT_BROWSER_TEST_UTILS_INTERNAL_H_ |
| OLD | NEW |