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 #include "content/test/content_browser_test_utils_internal.h" | 5 #include "content/test/content_browser_test_utils_internal.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/test/test_timeouts.h" |
| 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "cc/surfaces/surface.h" |
| 18 #include "cc/surfaces/surface_manager.h" |
| 19 #include "content/browser/compositor/delegated_frame_host.h" |
| 20 #include "content/browser/compositor/surface_utils.h" |
| 21 #include "content/browser/frame_host/cross_process_frame_connector.h" |
15 #include "content/browser/frame_host/frame_tree_node.h" | 22 #include "content/browser/frame_host/frame_tree_node.h" |
16 #include "content/browser/frame_host/navigator.h" | 23 #include "content/browser/frame_host/navigator.h" |
17 #include "content/browser/frame_host/render_frame_proxy_host.h" | 24 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 25 #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
| 26 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
18 #include "content/public/browser/resource_dispatcher_host.h" | 27 #include "content/public/browser/resource_dispatcher_host.h" |
19 #include "content/public/browser/resource_throttle.h" | 28 #include "content/public/browser/resource_throttle.h" |
20 #include "content/public/test/browser_test_utils.h" | 29 #include "content/public/test/browser_test_utils.h" |
21 #include "content/public/test/content_browser_test_utils.h" | 30 #include "content/public/test/content_browser_test_utils.h" |
22 #include "content/shell/browser/shell.h" | 31 #include "content/shell/browser/shell.h" |
23 #include "content/test/test_frame_navigation_observer.h" | 32 #include "content/test/test_frame_navigation_observer.h" |
24 #include "net/url_request/url_request.h" | 33 #include "net/url_request/url_request.h" |
25 | 34 |
26 namespace content { | 35 namespace content { |
27 | 36 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // ResourceThrottle | 258 // ResourceThrottle |
250 void WillStartRequest(bool* defer) override { *defer = true; } | 259 void WillStartRequest(bool* defer) override { *defer = true; } |
251 | 260 |
252 const char* GetNameForLogging() const override { | 261 const char* GetNameForLogging() const override { |
253 return "HttpRequestStallThrottle"; | 262 return "HttpRequestStallThrottle"; |
254 } | 263 } |
255 }; | 264 }; |
256 | 265 |
257 } // namespace | 266 } // namespace |
258 | 267 |
| 268 SurfaceHitTestReadyNotifier::SurfaceHitTestReadyNotifier( |
| 269 RenderWidgetHostViewChildFrame* target_view) |
| 270 : target_view_(target_view) { |
| 271 surface_manager_ = GetSurfaceManager(); |
| 272 } |
| 273 |
| 274 void SurfaceHitTestReadyNotifier::WaitForSurfaceReady() { |
| 275 root_surface_id_ = target_view_->FrameConnectorForTesting() |
| 276 ->GetRootRenderWidgetHostViewForTesting() |
| 277 ->SurfaceIdForTesting(); |
| 278 if (ContainsSurfaceId()) |
| 279 return; |
| 280 |
| 281 while (true) { |
| 282 // TODO(kenrb): Need a better way to do this. If |
| 283 // RenderWidgetHostViewBase lifetime observer lands (see |
| 284 // https://codereview.chromium.org/1711103002/), we can add a callback |
| 285 // from OnSwapCompositorFrame and avoid this busy waiting, which is very |
| 286 // frequent in tests in this file. |
| 287 base::RunLoop run_loop; |
| 288 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 289 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); |
| 290 run_loop.Run(); |
| 291 if (ContainsSurfaceId()) |
| 292 break; |
| 293 } |
| 294 } |
| 295 |
| 296 bool SurfaceHitTestReadyNotifier::ContainsSurfaceId() { |
| 297 if (root_surface_id_.is_null()) |
| 298 return false; |
| 299 for (cc::SurfaceId id : surface_manager_->GetSurfaceForId(root_surface_id_) |
| 300 ->referenced_surfaces()) { |
| 301 if (id == target_view_->SurfaceIdForTesting()) |
| 302 return true; |
| 303 } |
| 304 return false; |
| 305 } |
| 306 |
259 NavigationStallDelegate::NavigationStallDelegate(const GURL& url) : url_(url) {} | 307 NavigationStallDelegate::NavigationStallDelegate(const GURL& url) : url_(url) {} |
260 | 308 |
261 void NavigationStallDelegate::RequestBeginning( | 309 void NavigationStallDelegate::RequestBeginning( |
262 net::URLRequest* request, | 310 net::URLRequest* request, |
263 content::ResourceContext* resource_context, | 311 content::ResourceContext* resource_context, |
264 content::AppCacheService* appcache_service, | 312 content::AppCacheService* appcache_service, |
265 ResourceType resource_type, | 313 ResourceType resource_type, |
266 ScopedVector<content::ResourceThrottle>* throttles) { | 314 ScopedVector<content::ResourceThrottle>* throttles) { |
267 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 315 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
268 if (request->url() == url_) | 316 if (request->url() == url_) |
269 throttles->push_back(new HttpRequestStallThrottle); | 317 throttles->push_back(new HttpRequestStallThrottle); |
270 } | 318 } |
271 | 319 |
272 } // namespace content | 320 } // namespace content |
OLD | NEW |