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

Side by Side Diff: third_party/WebKit/Source/web/AssociatedURLLoaderTest.cpp

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 27 matching lines...) Expand all
38 #include "public/platform/WebURLLoaderClient.h" 38 #include "public/platform/WebURLLoaderClient.h"
39 #include "public/platform/WebURLLoaderMockFactory.h" 39 #include "public/platform/WebURLLoaderMockFactory.h"
40 #include "public/platform/WebURLRequest.h" 40 #include "public/platform/WebURLRequest.h"
41 #include "public/platform/WebURLResponse.h" 41 #include "public/platform/WebURLResponse.h"
42 #include "public/web/WebCache.h" 42 #include "public/web/WebCache.h"
43 #include "public/web/WebFrame.h" 43 #include "public/web/WebFrame.h"
44 #include "public/web/WebURLLoaderOptions.h" 44 #include "public/web/WebURLLoaderOptions.h"
45 #include "public/web/WebView.h" 45 #include "public/web/WebView.h"
46 #include "testing/gtest/include/gtest/gtest.h" 46 #include "testing/gtest/include/gtest/gtest.h"
47 #include "web/tests/FrameTestHelpers.h" 47 #include "web/tests/FrameTestHelpers.h"
48 #include "wtf/PtrUtil.h"
49 #include "wtf/text/CString.h" 48 #include "wtf/text/CString.h"
50 #include "wtf/text/WTFString.h" 49 #include "wtf/text/WTFString.h"
51 #include <memory>
52 50
53 using blink::URLTestHelpers::toKURL; 51 using blink::URLTestHelpers::toKURL;
54 using blink::testing::runPendingTasks; 52 using blink::testing::runPendingTasks;
55 53
56 namespace blink { 54 namespace blink {
57 55
58 class AssociatedURLLoaderTest : public ::testing::Test, 56 class AssociatedURLLoaderTest : public ::testing::Test,
59 public WebURLLoaderClient { 57 public WebURLLoaderClient {
60 public: 58 public:
61 AssociatedURLLoaderTest() 59 AssociatedURLLoaderTest()
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 { 108 {
111 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs(); 109 Platform::current()->getURLLoaderMockFactory()->unregisterAllURLs();
112 WebCache::clear(); 110 WebCache::clear();
113 } 111 }
114 112
115 void serveRequests() 113 void serveRequests()
116 { 114 {
117 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest s(); 115 Platform::current()->getURLLoaderMockFactory()->serveAsynchronousRequest s();
118 } 116 }
119 117
120 std::unique_ptr<WebURLLoader> createAssociatedURLLoader(const WebURLLoaderOp tions options = WebURLLoaderOptions()) 118 PassOwnPtr<WebURLLoader> createAssociatedURLLoader(const WebURLLoaderOptions options = WebURLLoaderOptions())
121 { 119 {
122 return wrapUnique(mainFrame()->createAssociatedURLLoader(options)); 120 return adoptPtr(mainFrame()->createAssociatedURLLoader(options));
123 } 121 }
124 122
125 // WebURLLoaderClient implementation. 123 // WebURLLoaderClient implementation.
126 void willFollowRedirect(WebURLLoader* loader, WebURLRequest& newRequest, con st WebURLResponse& redirectResponse) override 124 void willFollowRedirect(WebURLLoader* loader, WebURLRequest& newRequest, con st WebURLResponse& redirectResponse) override
127 { 125 {
128 m_willFollowRedirect = true; 126 m_willFollowRedirect = true;
129 EXPECT_EQ(m_expectedLoader.get(), loader); 127 EXPECT_EQ(m_expectedLoader, loader);
130 EXPECT_EQ(m_expectedNewRequest.url(), newRequest.url()); 128 EXPECT_EQ(m_expectedNewRequest.url(), newRequest.url());
131 // Check that CORS simple headers are transferred to the new request. 129 // Check that CORS simple headers are transferred to the new request.
132 EXPECT_EQ(m_expectedNewRequest.httpHeaderField("accept"), newRequest.htt pHeaderField("accept")); 130 EXPECT_EQ(m_expectedNewRequest.httpHeaderField("accept"), newRequest.htt pHeaderField("accept"));
133 EXPECT_EQ(m_expectedRedirectResponse.url(), redirectResponse.url()); 131 EXPECT_EQ(m_expectedRedirectResponse.url(), redirectResponse.url());
134 EXPECT_EQ(m_expectedRedirectResponse.httpStatusCode(), redirectResponse. httpStatusCode()); 132 EXPECT_EQ(m_expectedRedirectResponse.httpStatusCode(), redirectResponse. httpStatusCode());
135 EXPECT_EQ(m_expectedRedirectResponse.mimeType(), redirectResponse.mimeTy pe()); 133 EXPECT_EQ(m_expectedRedirectResponse.mimeType(), redirectResponse.mimeTy pe());
136 } 134 }
137 135
138 void didSendData(WebURLLoader* loader, unsigned long long bytesSent, unsigne d long long totalBytesToBeSent) override 136 void didSendData(WebURLLoader* loader, unsigned long long bytesSent, unsigne d long long totalBytesToBeSent) override
139 { 137 {
140 m_didSendData = true; 138 m_didSendData = true;
141 EXPECT_EQ(m_expectedLoader.get(), loader); 139 EXPECT_EQ(m_expectedLoader, loader);
142 } 140 }
143 141
144 void didReceiveResponse(WebURLLoader* loader, const WebURLResponse& response ) override 142 void didReceiveResponse(WebURLLoader* loader, const WebURLResponse& response ) override
145 { 143 {
146 m_didReceiveResponse = true; 144 m_didReceiveResponse = true;
147 m_actualResponse = WebURLResponse(response); 145 m_actualResponse = WebURLResponse(response);
148 EXPECT_EQ(m_expectedLoader.get(), loader); 146 EXPECT_EQ(m_expectedLoader, loader);
149 EXPECT_EQ(m_expectedResponse.url(), response.url()); 147 EXPECT_EQ(m_expectedResponse.url(), response.url());
150 EXPECT_EQ(m_expectedResponse.httpStatusCode(), response.httpStatusCode() ); 148 EXPECT_EQ(m_expectedResponse.httpStatusCode(), response.httpStatusCode() );
151 } 149 }
152 150
153 void didDownloadData(WebURLLoader* loader, int dataLength, int encodedDataLe ngth) override 151 void didDownloadData(WebURLLoader* loader, int dataLength, int encodedDataLe ngth) override
154 { 152 {
155 m_didDownloadData = true; 153 m_didDownloadData = true;
156 EXPECT_EQ(m_expectedLoader.get(), loader); 154 EXPECT_EQ(m_expectedLoader, loader);
157 } 155 }
158 156
159 void didReceiveData(WebURLLoader* loader, const char* data, int dataLength, int encodedDataLength) override 157 void didReceiveData(WebURLLoader* loader, const char* data, int dataLength, int encodedDataLength) override
160 { 158 {
161 m_didReceiveData = true; 159 m_didReceiveData = true;
162 EXPECT_EQ(m_expectedLoader.get(), loader); 160 EXPECT_EQ(m_expectedLoader, loader);
163 EXPECT_TRUE(data); 161 EXPECT_TRUE(data);
164 EXPECT_GT(dataLength, 0); 162 EXPECT_GT(dataLength, 0);
165 } 163 }
166 164
167 void didReceiveCachedMetadata(WebURLLoader* loader, const char* data, int da taLength) override 165 void didReceiveCachedMetadata(WebURLLoader* loader, const char* data, int da taLength) override
168 { 166 {
169 m_didReceiveCachedMetadata = true; 167 m_didReceiveCachedMetadata = true;
170 EXPECT_EQ(m_expectedLoader.get(), loader); 168 EXPECT_EQ(m_expectedLoader, loader);
171 } 169 }
172 170
173 void didFinishLoading(WebURLLoader* loader, double finishTime, int64_t encod edDataLength) override 171 void didFinishLoading(WebURLLoader* loader, double finishTime, int64_t encod edDataLength) override
174 { 172 {
175 m_didFinishLoading = true; 173 m_didFinishLoading = true;
176 EXPECT_EQ(m_expectedLoader.get(), loader); 174 EXPECT_EQ(m_expectedLoader, loader);
177 } 175 }
178 176
179 void didFail(WebURLLoader* loader, const WebURLError& error) override 177 void didFail(WebURLLoader* loader, const WebURLError& error) override
180 { 178 {
181 m_didFail = true; 179 m_didFail = true;
182 EXPECT_EQ(m_expectedLoader.get(), loader); 180 EXPECT_EQ(m_expectedLoader, loader);
183 } 181 }
184 182
185 void CheckMethodFails(const char* unsafeMethod) 183 void CheckMethodFails(const char* unsafeMethod)
186 { 184 {
187 WebURLRequest request; 185 WebURLRequest request;
188 request.initialize(); 186 request.initialize();
189 request.setURL(toKURL("http://www.test.com/success.html")); 187 request.setURL(toKURL("http://www.test.com/success.html"));
190 request.setHTTPMethod(WebString::fromUTF8(unsafeMethod)); 188 request.setHTTPMethod(WebString::fromUTF8(unsafeMethod));
191 WebURLLoaderOptions options; 189 WebURLLoaderOptions options;
192 options.untrustedHTTP = true; 190 options.untrustedHTTP = true;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 return !m_actualResponse.httpHeaderField(headerNameString).isEmpty(); 261 return !m_actualResponse.httpHeaderField(headerNameString).isEmpty();
264 } 262 }
265 263
266 WebFrame* mainFrame() const { return m_helper.webView()->mainFrame(); } 264 WebFrame* mainFrame() const { return m_helper.webView()->mainFrame(); }
267 265
268 protected: 266 protected:
269 String m_baseFilePath; 267 String m_baseFilePath;
270 String m_frameFilePath; 268 String m_frameFilePath;
271 FrameTestHelpers::WebViewHelper m_helper; 269 FrameTestHelpers::WebViewHelper m_helper;
272 270
273 std::unique_ptr<WebURLLoader> m_expectedLoader; 271 OwnPtr<WebURLLoader> m_expectedLoader;
274 WebURLResponse m_actualResponse; 272 WebURLResponse m_actualResponse;
275 WebURLResponse m_expectedResponse; 273 WebURLResponse m_expectedResponse;
276 WebURLRequest m_expectedNewRequest; 274 WebURLRequest m_expectedNewRequest;
277 WebURLResponse m_expectedRedirectResponse; 275 WebURLResponse m_expectedRedirectResponse;
278 bool m_willFollowRedirect; 276 bool m_willFollowRedirect;
279 bool m_didSendData; 277 bool m_didSendData;
280 bool m_didReceiveResponse; 278 bool m_didReceiveResponse;
281 bool m_didDownloadData; 279 bool m_didDownloadData;
282 bool m_didReceiveData; 280 bool m_didReceiveData;
283 bool m_didReceiveCachedMetadata; 281 bool m_didReceiveCachedMetadata;
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 m_expectedLoader->loadAsynchronously(request, this); 712 m_expectedLoader->loadAsynchronously(request, this);
715 serveRequests(); 713 serveRequests();
716 EXPECT_TRUE(m_didReceiveResponse); 714 EXPECT_TRUE(m_didReceiveResponse);
717 EXPECT_TRUE(m_didReceiveData); 715 EXPECT_TRUE(m_didReceiveData);
718 EXPECT_TRUE(m_didFinishLoading); 716 EXPECT_TRUE(m_didFinishLoading);
719 717
720 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty()); 718 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty());
721 } 719 }
722 720
723 } // namespace blink 721 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/AssociatedURLLoader.cpp ('k') | third_party/WebKit/Source/web/AudioOutputDeviceClientImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698