Index: chrome/browser/renderer_host/test_navigation_listener.cc |
diff --git a/chrome/browser/renderer_host/test_navigation_listener.cc b/chrome/browser/renderer_host/test_navigation_listener.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b6e2f13850b901b930bd5fd0ea472451a82bab48 |
--- /dev/null |
+++ b/chrome/browser/renderer_host/test_navigation_listener.cc |
@@ -0,0 +1,69 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/renderer_host/test_navigation_listener.h" |
+ |
+#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/resource_controller.h" |
+#include "content/public/browser/resource_throttle.h" |
+#include "googleurl/src/gurl.h" |
+ |
+class TestNavigationListener::Throttle |
+ : public content::ResourceThrottle, |
+ public base::SupportsWeakPtr<TestNavigationListener::Throttle> { |
+ public: |
+ void Resume() { |
+ controller()->Resume(); |
+ } |
+ |
+ // content::ResourceThrottle implementation. |
+ virtual void WillStartRequest(bool* defer) { |
+ *defer = true; |
+ } |
+}; |
+ |
+TestNavigationListener::TestNavigationListener() {} |
+ |
+TestNavigationListener::~TestNavigationListener() {} |
+ |
+void TestNavigationListener::DelayRequestsForURL(const GURL& url) |
+{ |
battre
2012/08/07 13:34:40
nit: { in previous line
|
+ if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&TestNavigationListener::DelayRequestsForURL, this, url)); |
+ return; |
+ } |
+ urls_to_delay_.insert(url); |
+} |
+ |
+void TestNavigationListener::ResumeAll() |
+{ |
battre
2012/08/07 13:34:40
nit: { in previous line
|
+ if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
+ content::BrowserThread::PostTask( |
+ content::BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&TestNavigationListener::ResumeAll, this)); |
+ return; |
+ } |
+ WeakThrottleList::const_iterator it; |
+ for (it = throttles_.begin(); it != throttles_.end(); ++it) { |
+ if (*it) |
+ (*it)->Resume(); |
+ } |
+ throttles_.clear(); |
+} |
+ |
+content::ResourceThrottle* TestNavigationListener::CreateResourceThrottle( |
+ const GURL& url, |
+ ResourceType::Type resource_type) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
+ if (urls_to_delay_.find(url) == urls_to_delay_.end()) |
+ return NULL; |
+ |
+ Throttle* throttle = new Throttle(); |
+ throttles_.push_back(throttle->AsWeakPtr()); |
+ return throttle; |
+} |