Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(406)

Side by Side Diff: content/test/weburl_loader_mock.cc

Issue 1743783002: Use WeakPtr and do not use pointer equality in WebURLLoaderMockFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Loader_URLTestHelpers
Patch Set: Rebase. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/test/weburl_loader_mock.h ('k') | content/test/weburl_loader_mock_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/weburl_loader_mock.h" 5 #include "content/test/weburl_loader_mock.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "content/child/web_url_loader_impl.h" 9 #include "content/child/web_url_loader_impl.h"
10 #include "content/test/weburl_loader_mock_factory.h" 10 #include "content/test/weburl_loader_mock_factory.h"
(...skipping 28 matching lines...) Expand all
39 // If no delegate is provided then create an empty one. The default behavior 39 // If no delegate is provided then create an empty one. The default behavior
40 // will just proxy to the client. 40 // will just proxy to the client.
41 scoped_ptr<blink::WebURLLoaderTestDelegate> defaultDelegate; 41 scoped_ptr<blink::WebURLLoaderTestDelegate> defaultDelegate;
42 if (!delegate) { 42 if (!delegate) {
43 defaultDelegate.reset(new blink::WebURLLoaderTestDelegate()); 43 defaultDelegate.reset(new blink::WebURLLoaderTestDelegate());
44 delegate = defaultDelegate.get(); 44 delegate = defaultDelegate.get();
45 } 45 }
46 46
47 // didReceiveResponse() and didReceiveData() might end up getting ::cancel() 47 // didReceiveResponse() and didReceiveData() might end up getting ::cancel()
48 // to be called which will make the ResourceLoader to delete |this|. 48 // to be called which will make the ResourceLoader to delete |this|.
49 base::WeakPtr<WebURLLoaderMock> self(weak_factory_.GetWeakPtr()); 49 base::WeakPtr<WebURLLoaderMock> self(GetWeakPtr());
50 50
51 delegate->didReceiveResponse(client_, this, response); 51 delegate->didReceiveResponse(client_, this, response);
52 if (!self) 52 if (!self)
53 return; 53 return;
54 54
55 if (error.reason) { 55 if (error.reason) {
56 delegate->didFail(client_, this, error); 56 delegate->didFail(client_, this, error);
57 return; 57 return;
58 } 58 }
59 delegate->didReceiveData(client_, this, data.data(), data.size(), 59 delegate->didReceiveData(client_, this, data.data(), data.size(),
(...skipping 17 matching lines...) Expand all
77 77
78 blink::WebURLRequest newRequest; 78 blink::WebURLRequest newRequest;
79 newRequest.initialize(); 79 newRequest.initialize();
80 content::WebURLLoaderImpl::PopulateURLRequestForRedirect( 80 content::WebURLLoaderImpl::PopulateURLRequestForRedirect(
81 request, 81 request,
82 redirectInfo, 82 redirectInfo,
83 request.referrerPolicy(), 83 request.referrerPolicy(),
84 request.skipServiceWorker(), 84 request.skipServiceWorker(),
85 &newRequest); 85 &newRequest);
86 86
87 base::WeakPtr<WebURLLoaderMock> self(weak_factory_.GetWeakPtr()); 87 base::WeakPtr<WebURLLoaderMock> self(GetWeakPtr());
88 88
89 client_->willFollowRedirect(this, newRequest, redirectResponse); 89 client_->willFollowRedirect(this, newRequest, redirectResponse);
90 90
91 // |this| might be deleted in willFollowRedirect(). 91 // |this| might be deleted in willFollowRedirect().
92 if (!self) 92 if (!self)
93 return newRequest; 93 return newRequest;
94 94
95 if (redirectURL != GURL(newRequest.url())) { 95 if (redirectURL != GURL(newRequest.url())) {
96 // Only follow the redirect if WebKit left the URL unmodified. 96 // Only follow the redirect if WebKit left the URL unmodified.
97 // We assume that WebKit only changes the URL to suppress a redirect, and we 97 // We assume that WebKit only changes the URL to suppress a redirect, and we
(...skipping 15 matching lines...) Expand all
113 } 113 }
114 DCHECK(static_cast<const GURL&>(request.url()).SchemeIs("data")) 114 DCHECK(static_cast<const GURL&>(request.url()).SchemeIs("data"))
115 << "loadSynchronously shouldn't be falling back: " 115 << "loadSynchronously shouldn't be falling back: "
116 << request.url().string().utf8(); 116 << request.url().string().utf8();
117 using_default_loader_ = true; 117 using_default_loader_ = true;
118 default_loader_->loadSynchronously(request, response, error, data); 118 default_loader_->loadSynchronously(request, response, error, data);
119 } 119 }
120 120
121 void WebURLLoaderMock::loadAsynchronously(const blink::WebURLRequest& request, 121 void WebURLLoaderMock::loadAsynchronously(const blink::WebURLRequest& request,
122 blink::WebURLLoaderClient* client) { 122 blink::WebURLLoaderClient* client) {
123 CHECK(client);
123 if (factory_->IsMockedURL(request.url())) { 124 if (factory_->IsMockedURL(request.url())) {
124 client_ = client; 125 client_ = client;
125 factory_->LoadAsynchronouly(request, this); 126 factory_->LoadAsynchronouly(request, this);
126 return; 127 return;
127 } 128 }
128 DCHECK(static_cast<const GURL&>(request.url()).SchemeIs("data")) 129 DCHECK(static_cast<const GURL&>(request.url()).SchemeIs("data"))
129 << "loadAsynchronously shouldn't be falling back: " 130 << "loadAsynchronously shouldn't be falling back: "
130 << request.url().string().utf8(); 131 << request.url().string().utf8();
131 using_default_loader_ = true; 132 using_default_loader_ = true;
132 default_loader_->loadAsynchronously(request, client); 133 default_loader_->loadAsynchronously(request, client);
(...skipping 14 matching lines...) Expand all
147 default_loader_->setDefersLoading(deferred); 148 default_loader_->setDefersLoading(deferred);
148 return; 149 return;
149 } 150 }
150 NOTIMPLEMENTED(); 151 NOTIMPLEMENTED();
151 } 152 }
152 153
153 void WebURLLoaderMock::setLoadingTaskRunner(blink::WebTaskRunner*) { 154 void WebURLLoaderMock::setLoadingTaskRunner(blink::WebTaskRunner*) {
154 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods 155 // In principle this is NOTIMPLEMENTED(), but if we put that here it floods
155 // the console during webkit unit tests, so we leave the function empty. 156 // the console during webkit unit tests, so we leave the function empty.
156 } 157 }
158
159 base::WeakPtr<WebURLLoaderMock> WebURLLoaderMock::GetWeakPtr() {
160 return weak_factory_.GetWeakPtr();
161 }
OLDNEW
« no previous file with comments | « content/test/weburl_loader_mock.h ('k') | content/test/weburl_loader_mock_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698