| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <list> | 5 #include <list> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 // This class can defer requests for arbitrary URLs. | 67 // This class can defer requests for arbitrary URLs. |
| 68 class TestNavigationListener | 68 class TestNavigationListener |
| 69 : public base::RefCountedThreadSafe<TestNavigationListener> { | 69 : public base::RefCountedThreadSafe<TestNavigationListener> { |
| 70 public: | 70 public: |
| 71 TestNavigationListener() {} | 71 TestNavigationListener() {} |
| 72 | 72 |
| 73 // Add |url| to the set of URLs we should delay. | 73 // Add |url| to the set of URLs we should delay. |
| 74 void DelayRequestsForURL(const GURL& url) { | 74 void DelayRequestsForURL(const GURL& url) { |
| 75 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { | 75 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
| 76 content::BrowserThread::PostTask( | 76 content::BrowserThread::PostTask( |
| 77 content::BrowserThread::IO, | 77 content::BrowserThread::IO, FROM_HERE, |
| 78 FROM_HERE, | 78 base::BindOnce(&TestNavigationListener::DelayRequestsForURL, this, |
| 79 base::Bind(&TestNavigationListener::DelayRequestsForURL, this, url)); | 79 url)); |
| 80 return; | 80 return; |
| 81 } | 81 } |
| 82 urls_to_delay_.insert(url); | 82 urls_to_delay_.insert(url); |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Resume all deferred requests. | 85 // Resume all deferred requests. |
| 86 void ResumeAll() { | 86 void ResumeAll() { |
| 87 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { | 87 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
| 88 content::BrowserThread::PostTask( | 88 content::BrowserThread::PostTask( |
| 89 content::BrowserThread::IO, | 89 content::BrowserThread::IO, FROM_HERE, |
| 90 FROM_HERE, | 90 base::BindOnce(&TestNavigationListener::ResumeAll, this)); |
| 91 base::Bind(&TestNavigationListener::ResumeAll, this)); | |
| 92 return; | 91 return; |
| 93 } | 92 } |
| 94 WeakThrottleList::const_iterator it; | 93 WeakThrottleList::const_iterator it; |
| 95 for (it = throttles_.begin(); it != throttles_.end(); ++it) { | 94 for (it = throttles_.begin(); it != throttles_.end(); ++it) { |
| 96 if (it->get()) | 95 if (it->get()) |
| 97 (*it)->ResumeHandler(); | 96 (*it)->ResumeHandler(); |
| 98 } | 97 } |
| 99 throttles_.clear(); | 98 throttles_.clear(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 // Resume a specific request. | 101 // Resume a specific request. |
| 103 void Resume(const GURL& url) { | 102 void Resume(const GURL& url) { |
| 104 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { | 103 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
| 105 content::BrowserThread::PostTask( | 104 content::BrowserThread::PostTask( |
| 106 content::BrowserThread::IO, FROM_HERE, | 105 content::BrowserThread::IO, FROM_HERE, |
| 107 base::Bind(&TestNavigationListener::Resume, this, url)); | 106 base::BindOnce(&TestNavigationListener::Resume, this, url)); |
| 108 return; | 107 return; |
| 109 } | 108 } |
| 110 WeakThrottleList::iterator it; | 109 WeakThrottleList::iterator it; |
| 111 for (it = throttles_.begin(); it != throttles_.end(); ++it) { | 110 for (it = throttles_.begin(); it != throttles_.end(); ++it) { |
| 112 if (it->get() && it->get()->url() == url) { | 111 if (it->get() && it->get()->url() == url) { |
| 113 (*it)->ResumeHandler(); | 112 (*it)->ResumeHandler(); |
| 114 throttles_.erase(it); | 113 throttles_.erase(it); |
| 115 break; | 114 break; |
| 116 } | 115 } |
| 117 } | 116 } |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 "extensions/api_test/webnavigation/crash/b.html", | 807 "extensions/api_test/webnavigation/crash/b.html", |
| 809 embedded_test_server()->port())); | 808 embedded_test_server()->port())); |
| 810 ui_test_utils::NavigateToURL(browser(), url); | 809 ui_test_utils::NavigateToURL(browser(), url); |
| 811 | 810 |
| 812 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 811 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 813 } | 812 } |
| 814 | 813 |
| 815 #endif | 814 #endif |
| 816 | 815 |
| 817 } // namespace extensions | 816 } // namespace extensions |
| OLD | NEW |