| 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 // Browser tests targeted at the RenderView that run in browser context. | 5 // Browser tests targeted at the RenderView that run in browser context. |
| 6 // Note that these tests rely on single-process mode, and hence may be | 6 // Note that these tests rely on single-process mode, and hence may be |
| 7 // disabled in some configurations (check gyp files). | 7 // disabled in some configurations (check gyp files). |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 bool latest_error_valid_; | 74 bool latest_error_valid_; |
| 75 int latest_error_reason_; | 75 int latest_error_reason_; |
| 76 bool latest_error_stale_copy_in_cache_; | 76 bool latest_error_stale_copy_in_cache_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 // Must be called on IO thread. | 79 // Must be called on IO thread. |
| 80 void InterceptNetworkTransactions(net::URLRequestContextGetter* getter, | 80 void InterceptNetworkTransactions(net::URLRequestContextGetter* getter, |
| 81 net::Error error) { | 81 net::Error error) { |
| 82 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::IO)); | 82 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 83 net::HttpCache* cache( | 83 net::HttpCache* cache( |
| 84 getter->GetURLRequestContext()->http_transaction_factory()->GetCache()); | 84 getter->GetURLRequestContext()->http_transaction_factory()->GetCache()); |
| 85 DCHECK(cache); | 85 DCHECK(cache); |
| 86 scoped_ptr<net::FailingHttpTransactionFactory> factory( | 86 scoped_ptr<net::FailingHttpTransactionFactory> factory( |
| 87 new net::FailingHttpTransactionFactory(cache->GetSession(), error)); | 87 new net::FailingHttpTransactionFactory(cache->GetSession(), error)); |
| 88 // Throw away old version; since this is a browser test, there is no | 88 // Throw away old version; since this is a browser test, there is no |
| 89 // need to restore the old state. | 89 // need to restore the old state. |
| 90 cache->SetHttpNetworkTransactionFactoryForTesting(factory.Pass()); | 90 cache->SetHttpNetworkTransactionFactoryForTesting(factory.Pass()); |
| 91 } | 91 } |
| 92 | 92 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 105 DCHECK(*backend); | 105 DCHECK(*backend); |
| 106 DCHECK_EQ(net::OK, rv); | 106 DCHECK_EQ(net::OK, rv); |
| 107 (*backend)->DoomAllEntries( | 107 (*backend)->DoomAllEntries( |
| 108 base::Bind(&CallOnUIThreadValidatingReturn, callback)); | 108 base::Bind(&CallOnUIThreadValidatingReturn, callback)); |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Must be called on IO thread. The callback will be called on | 111 // Must be called on IO thread. The callback will be called on |
| 112 // completion of cache clearing on the UI thread. | 112 // completion of cache clearing on the UI thread. |
| 113 void ClearCache(net::URLRequestContextGetter* getter, | 113 void ClearCache(net::URLRequestContextGetter* getter, |
| 114 const base::Closure& callback) { | 114 const base::Closure& callback) { |
| 115 DCHECK(content::BrowserThread::CurrentlyOn(BrowserThread::IO)); | 115 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 116 net::HttpCache* cache( | 116 net::HttpCache* cache( |
| 117 getter->GetURLRequestContext()->http_transaction_factory()->GetCache()); | 117 getter->GetURLRequestContext()->http_transaction_factory()->GetCache()); |
| 118 DCHECK(cache); | 118 DCHECK(cache); |
| 119 scoped_ptr<disk_cache::Backend*> backend(new disk_cache::Backend*); | 119 scoped_ptr<disk_cache::Backend*> backend(new disk_cache::Backend*); |
| 120 *backend = NULL; | 120 *backend = NULL; |
| 121 disk_cache::Backend** backend_ptr = backend.get(); | 121 disk_cache::Backend** backend_ptr = backend.get(); |
| 122 | 122 |
| 123 net::CompletionCallback backend_callback( | 123 net::CompletionCallback backend_callback( |
| 124 base::Bind(&BackendClearCache, base::Passed(backend.Pass()), callback)); | 124 base::Bind(&BackendClearCache, base::Passed(backend.Pass()), callback)); |
| 125 | 125 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 234 |
| 235 error_code = net::OK; | 235 error_code = net::OK; |
| 236 stale_cache_entry_present = true; | 236 stale_cache_entry_present = true; |
| 237 ASSERT_TRUE(GetLatestErrorFromRendererClient( | 237 ASSERT_TRUE(GetLatestErrorFromRendererClient( |
| 238 &error_code, &stale_cache_entry_present)); | 238 &error_code, &stale_cache_entry_present)); |
| 239 EXPECT_EQ(net::ERR_FAILED, error_code); | 239 EXPECT_EQ(net::ERR_FAILED, error_code); |
| 240 EXPECT_FALSE(stale_cache_entry_present); | 240 EXPECT_FALSE(stale_cache_entry_present); |
| 241 } | 241 } |
| 242 | 242 |
| 243 } // namespace content | 243 } // namespace content |
| OLD | NEW |