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

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

Issue 1174283002: Fix unit test style in Source/web/. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: remove static Created 5 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 | Annotate | Revision Log
« no previous file with comments | « Source/platform/scroll/ScrollAnimatorNone.h ('k') | Source/web/ExternalPopupMenuTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 29 matching lines...) Expand all
40 #include "public/platform/WebURLLoaderClient.h" 40 #include "public/platform/WebURLLoaderClient.h"
41 #include "public/platform/WebURLRequest.h" 41 #include "public/platform/WebURLRequest.h"
42 #include "public/platform/WebURLResponse.h" 42 #include "public/platform/WebURLResponse.h"
43 #include "public/platform/WebUnitTestSupport.h" 43 #include "public/platform/WebUnitTestSupport.h"
44 #include "public/web/WebFrame.h" 44 #include "public/web/WebFrame.h"
45 #include "public/web/WebURLLoaderOptions.h" 45 #include "public/web/WebURLLoaderOptions.h"
46 #include "public/web/WebView.h" 46 #include "public/web/WebView.h"
47 #include "web/tests/FrameTestHelpers.h" 47 #include "web/tests/FrameTestHelpers.h"
48 #include "wtf/text/CString.h" 48 #include "wtf/text/CString.h"
49 #include "wtf/text/WTFString.h" 49 #include "wtf/text/WTFString.h"
50
51 #include <gtest/gtest.h> 50 #include <gtest/gtest.h>
52 51
53 using namespace blink;
54 using blink::URLTestHelpers::toKURL; 52 using blink::URLTestHelpers::toKURL;
55 using blink::testing::runPendingTasks; 53 using blink::testing::runPendingTasks;
56 54
57 namespace { 55 namespace blink {
58 56
59 class AssociatedURLLoaderTest : public ::testing::Test, 57 class AssociatedURLLoaderTest : public ::testing::Test,
60 public WebURLLoaderClient { 58 public WebURLLoaderClient {
61 public: 59 public:
62 AssociatedURLLoaderTest() 60 AssociatedURLLoaderTest()
63 : m_willSendRequest(false) 61 : m_willSendRequest(false)
64 , m_didSendData(false) 62 , m_didSendData(false)
65 , m_didReceiveResponse(false) 63 , m_didReceiveResponse(false)
66 , m_didReceiveData(false) 64 , m_didReceiveData(false)
67 , m_didReceiveCachedMetadata(false) 65 , m_didReceiveCachedMetadata(false)
(...skipping 12 matching lines...) Expand all
80 WebURLResponse response; 78 WebURLResponse response;
81 response.initialize(); 79 response.initialize();
82 response.setMIMEType("text/html"); 80 response.setMIMEType("text/html");
83 WTF::String localPath = m_baseFilePath; 81 WTF::String localPath = m_baseFilePath;
84 localPath.append(filename); 82 localPath.append(filename);
85 KURL url = toKURL(urlRoot + filename.utf8().data()); 83 KURL url = toKURL(urlRoot + filename.utf8().data());
86 Platform::current()->unitTestSupport()->registerMockedURL(url, response, localPath); 84 Platform::current()->unitTestSupport()->registerMockedURL(url, response, localPath);
87 return url; 85 return url;
88 } 86 }
89 87
90 void SetUp() 88 void SetUp() override
91 { 89 {
92 m_helper.initialize(); 90 m_helper.initialize();
93 91
94 std::string urlRoot = "http://www.test.com/"; 92 std::string urlRoot = "http://www.test.com/";
95 KURL url = RegisterMockedUrl(urlRoot, "iframes_test.html"); 93 KURL url = RegisterMockedUrl(urlRoot, "iframes_test.html");
96 const char* iframeSupportFiles[] = { 94 const char* iframeSupportFiles[] = {
97 "invisible_iframe.html", 95 "invisible_iframe.html",
98 "visible_iframe.html", 96 "visible_iframe.html",
99 "zero_sized_iframe.html", 97 "zero_sized_iframe.html",
100 }; 98 };
101 for (size_t i = 0; i < arraysize(iframeSupportFiles); ++i) { 99 for (size_t i = 0; i < arraysize(iframeSupportFiles); ++i) {
102 RegisterMockedUrl(urlRoot, iframeSupportFiles[i]); 100 RegisterMockedUrl(urlRoot, iframeSupportFiles[i]);
103 } 101 }
104 102
105 FrameTestHelpers::loadFrame(mainFrame(), url.string().utf8().data()); 103 FrameTestHelpers::loadFrame(mainFrame(), url.string().utf8().data());
106 104
107 Platform::current()->unitTestSupport()->unregisterMockedURL(url); 105 Platform::current()->unitTestSupport()->unregisterMockedURL(url);
108 } 106 }
109 107
110 void TearDown() 108 void TearDown() override
111 { 109 {
112 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); 110 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
113 } 111 }
114 112
115 void serveRequests() 113 void serveRequests()
116 { 114 {
117 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( ); 115 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests( );
118 } 116 }
119 117
120 PassOwnPtr<WebURLLoader> createAssociatedURLLoader(const WebURLLoaderOptions options = WebURLLoaderOptions()) 118 PassOwnPtr<WebURLLoader> createAssociatedURLLoader(const WebURLLoaderOptions options = WebURLLoaderOptions())
121 { 119 {
122 return adoptPtr(mainFrame()->createAssociatedURLLoader(options)); 120 return adoptPtr(mainFrame()->createAssociatedURLLoader(options));
123 } 121 }
124 122
125 // WebURLLoaderClient implementation. 123 // WebURLLoaderClient implementation.
126 void willSendRequest(WebURLLoader* loader, WebURLRequest& newRequest, const WebURLResponse& redirectResponse) 124 void willSendRequest(WebURLLoader* loader, WebURLRequest& newRequest, const WebURLResponse& redirectResponse) override
127 { 125 {
128 m_willSendRequest = true; 126 m_willSendRequest = true;
129 EXPECT_EQ(m_expectedLoader, 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) 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, loader); 139 EXPECT_EQ(m_expectedLoader, loader);
142 } 140 }
143 141
144 void didReceiveResponse(WebURLLoader* loader, const WebURLResponse& response ) 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, 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) 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, loader); 154 EXPECT_EQ(m_expectedLoader, loader);
157 } 155 }
158 156
159 void didReceiveData(WebURLLoader* loader, const char* data, int dataLength, int encodedDataLength) 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, 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) 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, loader); 168 EXPECT_EQ(m_expectedLoader, loader);
171 } 169 }
172 170
173 void didFinishLoading(WebURLLoader* loader, double finishTime, int64_t encod edDataLength) 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, loader); 174 EXPECT_EQ(m_expectedLoader, loader);
177 } 175 }
178 176
179 void didFail(WebURLLoader* loader, const WebURLError& error) 177 void didFail(WebURLLoader* loader, const WebURLError& error) override
180 { 178 {
181 m_didFail = true; 179 m_didFail = true;
182 EXPECT_EQ(m_expectedLoader, 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"));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 EXPECT_TRUE(m_didReceiveResponse); 257 EXPECT_TRUE(m_didReceiveResponse);
260 EXPECT_TRUE(m_didReceiveData); 258 EXPECT_TRUE(m_didReceiveData);
261 EXPECT_TRUE(m_didFinishLoading); 259 EXPECT_TRUE(m_didFinishLoading);
262 260
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 WTF::String m_baseFilePath; 267 String m_baseFilePath;
270 WTF::String m_frameFilePath; 268 String m_frameFilePath;
271 FrameTestHelpers::WebViewHelper m_helper; 269 FrameTestHelpers::WebViewHelper m_helper;
272 270
273 OwnPtr<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_willSendRequest; 276 bool m_willSendRequest;
279 bool m_didSendData; 277 bool m_didSendData;
280 bool m_didReceiveResponse; 278 bool m_didReceiveResponse;
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 EXPECT_TRUE(m_expectedLoader); 708 EXPECT_TRUE(m_expectedLoader);
711 m_expectedLoader->loadAsynchronously(request, this); 709 m_expectedLoader->loadAsynchronously(request, this);
712 serveRequests(); 710 serveRequests();
713 EXPECT_TRUE(m_didReceiveResponse); 711 EXPECT_TRUE(m_didReceiveResponse);
714 EXPECT_TRUE(m_didReceiveData); 712 EXPECT_TRUE(m_didReceiveData);
715 EXPECT_TRUE(m_didFinishLoading); 713 EXPECT_TRUE(m_didFinishLoading);
716 714
717 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty()); 715 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty());
718 } 716 }
719 717
720 } 718 } // namespace blink
OLDNEW
« no previous file with comments | « Source/platform/scroll/ScrollAnimatorNone.h ('k') | Source/web/ExternalPopupMenuTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698