author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
#include <QtCore/QUrl> |
|
45 |
#include <QtNetwork/QNetworkCookie> |
|
46 |
||
47 |
||
48 |
class tst_QNetworkCookie: public QObject |
|
49 |
{ |
|
50 |
Q_OBJECT |
|
51 |
||
52 |
private slots: |
|
53 |
void getterSetter(); |
|
54 |
||
55 |
void parseSingleCookie_data(); |
|
56 |
void parseSingleCookie(); |
|
57 |
||
58 |
void parseMultipleCookies_data(); |
|
59 |
void parseMultipleCookies(); |
|
60 |
}; |
|
61 |
||
62 |
QT_BEGIN_NAMESPACE |
|
63 |
||
64 |
namespace QTest { |
|
65 |
template<> |
|
66 |
char *toString(const QNetworkCookie &cookie) |
|
67 |
{ |
|
68 |
return qstrdup(cookie.toRawForm()); |
|
69 |
} |
|
70 |
||
71 |
template<> |
|
72 |
char *toString(const QList<QNetworkCookie> &list) |
|
73 |
{ |
|
74 |
QString result = "QList("; |
|
75 |
bool first = true; |
|
76 |
foreach (QNetworkCookie cookie, list) { |
|
77 |
if (!first) |
|
78 |
result += ", "; |
|
79 |
first = false; |
|
80 |
result += QString::fromLatin1("QNetworkCookie(%1)").arg(QLatin1String(cookie.toRawForm())); |
|
81 |
} |
|
82 |
||
83 |
return qstrdup(result.append(')').toLocal8Bit()); |
|
84 |
} |
|
85 |
} |
|
86 |
||
87 |
QT_END_NAMESPACE |
|
88 |
||
89 |
void tst_QNetworkCookie::getterSetter() |
|
90 |
{ |
|
91 |
QNetworkCookie cookie; |
|
92 |
QNetworkCookie otherCookie; |
|
93 |
||
94 |
QVERIFY(cookie == otherCookie); |
|
95 |
QCOMPARE(cookie, otherCookie); |
|
96 |
QVERIFY(!(cookie != otherCookie)); |
|
97 |
||
98 |
QVERIFY(!cookie.isSecure()); |
|
99 |
QVERIFY(cookie.isSessionCookie()); |
|
100 |
QVERIFY(!cookie.expirationDate().isValid()); |
|
101 |
QVERIFY(cookie.domain().isEmpty()); |
|
102 |
QVERIFY(cookie.path().isEmpty()); |
|
103 |
QVERIFY(cookie.name().isEmpty()); |
|
104 |
QVERIFY(cookie.value().isEmpty()); |
|
105 |
||
106 |
// change something |
|
107 |
cookie.setName("foo"); |
|
108 |
QVERIFY(!(cookie == otherCookie)); |
|
109 |
QVERIFY(cookie != otherCookie); |
|
110 |
||
111 |
// test getters and setters: |
|
112 |
QCOMPARE(cookie.name(), QByteArray("foo")); |
|
113 |
cookie.setName(0); |
|
114 |
QVERIFY(cookie.name().isEmpty()); |
|
115 |
||
116 |
cookie.setValue("bar"); |
|
117 |
QCOMPARE(cookie.value(), QByteArray("bar")); |
|
118 |
cookie.setValue(0); |
|
119 |
QVERIFY(cookie.value().isEmpty()); |
|
120 |
||
121 |
cookie.setPath("/"); |
|
122 |
QCOMPARE(cookie.path(), QString("/")); |
|
123 |
cookie.setPath(QString()); |
|
124 |
QVERIFY(cookie.path().isEmpty()); |
|
125 |
||
126 |
cookie.setDomain(".tld"); |
|
127 |
QCOMPARE(cookie.domain(), QString(".tld")); |
|
128 |
cookie.setDomain(QString()); |
|
129 |
QVERIFY(cookie.domain().isEmpty()); |
|
130 |
||
131 |
QDateTime now = QDateTime::currentDateTime(); |
|
132 |
cookie.setExpirationDate(now); |
|
133 |
QCOMPARE(cookie.expirationDate(), now); |
|
134 |
QVERIFY(!cookie.isSessionCookie()); |
|
135 |
cookie.setExpirationDate(QDateTime()); |
|
136 |
QVERIFY(!cookie.expirationDate().isValid()); |
|
137 |
QVERIFY(cookie.isSessionCookie()); |
|
138 |
||
139 |
cookie.setSecure(true); |
|
140 |
QVERIFY(cookie.isSecure()); |
|
141 |
cookie.setSecure(false); |
|
142 |
QVERIFY(!cookie.isSecure()); |
|
143 |
||
144 |
QVERIFY(cookie == otherCookie); |
|
145 |
} |
|
146 |
||
147 |
void tst_QNetworkCookie::parseSingleCookie_data() |
|
148 |
{ |
|
149 |
QTest::addColumn<QString>("cookieString"); |
|
150 |
QTest::addColumn<QNetworkCookie>("expectedCookie"); |
|
151 |
||
152 |
QNetworkCookie cookie; |
|
153 |
cookie.setName("a"); |
|
154 |
QTest::newRow("basic") << "a=" << cookie; |
|
155 |
QTest::newRow("basic2") << " a=" << cookie; |
|
156 |
QTest::newRow("basic3") << "a= " << cookie; |
|
157 |
QTest::newRow("basic4") << " a= " << cookie; |
|
158 |
QTest::newRow("basic5") << " a= ;" << cookie; |
|
159 |
QTest::newRow("basic6") << " a=; " << cookie; |
|
160 |
QTest::newRow("basic7") << " a =" << cookie; |
|
161 |
QTest::newRow("basic8") << " a = " << cookie; |
|
162 |
||
163 |
cookie.setValue("b"); |
|
164 |
QTest::newRow("with-value") << "a=b" << cookie; |
|
165 |
QTest::newRow("with-value2") << " a=b" << cookie; |
|
166 |
QTest::newRow("with-value3") << "a=b " << cookie; |
|
167 |
QTest::newRow("with-value4") << " a=b " << cookie; |
|
168 |
QTest::newRow("with-value4") << " a=b ;" << cookie; |
|
169 |
QTest::newRow("with-value5") << "a =b" << cookie; |
|
170 |
QTest::newRow("with-value6") << "a= b" << cookie; |
|
171 |
QTest::newRow("with-value7") << "a = b" << cookie; |
|
172 |
QTest::newRow("with-value8") << "a = b " << cookie; |
|
173 |
||
174 |
cookie.setValue(","); |
|
175 |
QTest::newRow("with-value-with-special1") << "a = \",\" " << cookie; |
|
176 |
cookie.setValue(";"); |
|
177 |
QTest::newRow("with-value-with-special2") << "a = \";\" " << cookie; |
|
178 |
cookie.setValue(" "); |
|
179 |
QTest::newRow("with-value-with-special3") << "a = \" \" " << cookie; |
|
180 |
cookie.setValue("\""); |
|
181 |
QTest::newRow("with-value-with-special3") << "a = \"\\\"\" " << cookie; |
|
182 |
cookie.setValue("\"a, b; c\""); |
|
183 |
QTest::newRow("with-value-with-special4") << "a = \"\\\"a, b; c\\\"\"" << cookie; |
|
184 |
||
185 |
cookie.setValue("b"); |
|
186 |
cookie.setSecure(true); |
|
187 |
QTest::newRow("secure") << "a=b;secure" << cookie; |
|
188 |
QTest::newRow("secure2") << "a=b;secure " << cookie; |
|
189 |
QTest::newRow("secure3") << "a=b; secure" << cookie; |
|
190 |
QTest::newRow("secure4") << "a=b; secure " << cookie; |
|
191 |
QTest::newRow("secure5") << "a=b ;secure" << cookie; |
|
192 |
QTest::newRow("secure6") << "a=b ;secure " << cookie; |
|
193 |
QTest::newRow("secure7") << "a=b ; secure " << cookie; |
|
194 |
QTest::newRow("secure8") << "a=b; Secure" << cookie; |
|
195 |
||
196 |
cookie.setSecure(false); |
|
197 |
cookie.setHttpOnly(true); |
|
198 |
QTest::newRow("httponly") << "a=b;httponly" << cookie; |
|
199 |
QTest::newRow("httponly2") << "a=b;HttpOnly " << cookie; |
|
200 |
QTest::newRow("httponly3") << "a=b; httpOnly" << cookie; |
|
201 |
QTest::newRow("httponly4") << "a=b; HttpOnly " << cookie; |
|
202 |
QTest::newRow("httponly5") << "a=b ;HttpOnly" << cookie; |
|
203 |
QTest::newRow("httponly6") << "a=b ;httponly " << cookie; |
|
204 |
QTest::newRow("httponly7") << "a=b ; HttpOnly " << cookie; |
|
205 |
QTest::newRow("httponly8") << "a=b; Httponly" << cookie; |
|
206 |
||
207 |
cookie.setHttpOnly(false); |
|
208 |
cookie.setPath("/"); |
|
209 |
QTest::newRow("path1") << "a=b;path=/" << cookie; |
|
210 |
QTest::newRow("path2") << "a=b; path=/" << cookie; |
|
211 |
QTest::newRow("path3") << "a=b;path=/ " << cookie; |
|
212 |
QTest::newRow("path4") << "a=b;path =/ " << cookie; |
|
213 |
QTest::newRow("path5") << "a=b;path= / " << cookie; |
|
214 |
QTest::newRow("path6") << "a=b;path = / " << cookie; |
|
215 |
QTest::newRow("path7") << "a=b;Path = / " << cookie; |
|
216 |
QTest::newRow("path8") << "a=b; PATH = / " << cookie; |
|
217 |
||
218 |
cookie.setPath("/foo"); |
|
219 |
QTest::newRow("path9") << "a=b;path=/foo" << cookie; |
|
220 |
||
221 |
// some weird paths: |
|
222 |
cookie.setPath("/with spaces"); |
|
223 |
QTest::newRow("path-with-spaces") << "a=b;path=/with%20spaces" << cookie; |
|
224 |
QTest::newRow("path-with-spaces2") << "a=b; path=/with%20spaces " << cookie; |
|
225 |
QTest::newRow("path-with-spaces3") << "a=b; path=\"/with spaces\"" << cookie; |
|
226 |
QTest::newRow("path-with-spaces4") << "a=b; path = \"/with spaces\" " << cookie; |
|
227 |
||
228 |
cookie.setPath("/with\"Quotes"); |
|
229 |
QTest::newRow("path-with-quotes") << "a=b; path = /with%22Quotes" << cookie; |
|
230 |
QTest::newRow("path-with-quotes2") << "a=b; path = \"/with\\\"Quotes\"" << cookie; |
|
231 |
||
232 |
cookie.setPath(QString::fromUtf8("/R\303\251sum\303\251")); |
|
233 |
QTest::newRow("path-with-utf8") << "a=b;path=/R\303\251sum\303\251" << cookie; |
|
234 |
QTest::newRow("path-with-utf8-2") << "a=b;path=/R%C3%A9sum%C3%A9" << cookie; |
|
235 |
||
236 |
cookie.setPath(QString()); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
237 |
cookie.setDomain("qt.nokia.com"); |
0 | 238 |
QTest::newRow("plain-domain1") << "a=b;domain=qt.nokia.com" << cookie; |
239 |
QTest::newRow("plain-domain2") << "a=b; domain=qt.nokia.com " << cookie; |
|
240 |
QTest::newRow("plain-domain3") << "a=b;domain=QT.NOKIA.COM" << cookie; |
|
241 |
QTest::newRow("plain-domain4") << "a=b;DOMAIN = QT.NOKIA.COM" << cookie; |
|
242 |
||
243 |
cookie.setDomain(".qt.nokia.com"); |
|
244 |
QTest::newRow("dot-domain1") << "a=b;domain=.qt.nokia.com" << cookie; |
|
245 |
QTest::newRow("dot-domain2") << "a=b; domain=.qt.nokia.com" << cookie; |
|
246 |
QTest::newRow("dot-domain3") << "a=b; domain=.QT.NOKIA.COM" << cookie; |
|
247 |
QTest::newRow("dot-domain4") << "a=b; Domain = .QT.NOKIA.COM" << cookie; |
|
248 |
||
249 |
cookie.setDomain(QString::fromUtf8(".d\303\270gn\303\245pent.troll.no")); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
QTest::newRow("idn-domain1") << "a=b;domain=.xn--dgnpent-gxa2o.troll.no" << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
QTest::newRow("idn-domain2") << "a=b;domain=.d\303\270gn\303\245pent.troll.no" << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
QTest::newRow("idn-domain3") << "a=b;domain=.XN--DGNPENT-GXA2O.TROLL.NO" << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
QTest::newRow("idn-domain4") << "a=b;domain=.D\303\230GN\303\205PENT.troll.NO" << cookie; |
0 | 254 |
|
255 |
cookie.setDomain(".qt.nokia.com"); |
|
256 |
cookie.setPath("/"); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
QTest::newRow("two-fields") << "a=b;domain=.qt.nokia.com;path=/" << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
258 |
QTest::newRow("two-fields2") << "a=b; domain=.qt.nokia.com; path=/" << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
QTest::newRow("two-fields3") << "a=b; domain=.qt.nokia.com ; path=/ " << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
QTest::newRow("two-fields4") << "a=b;path=/; domain=.qt.nokia.com" << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
261 |
QTest::newRow("two-fields5") << "a=b; path=/ ; domain=.qt.nokia.com" << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
QTest::newRow("two-fields6") << "a=b; path= / ; domain =.qt.nokia.com" << cookie; |
0 | 263 |
|
264 |
cookie.setSecure(true); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
QTest::newRow("three-fields") << "a=b;domain=.qt.nokia.com;path=/;secure" << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
QTest::newRow("three-fields2") << "a=b;secure;path=/;domain=.qt.nokia.com" << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
267 |
QTest::newRow("three-fields3") << "a=b;secure;domain=.qt.nokia.com; path=/" << cookie; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
QTest::newRow("three-fields4") << "a = b;secure;domain=.qt.nokia.com; path=/" << cookie; |
0 | 269 |
|
270 |
cookie = QNetworkCookie(); |
|
271 |
cookie.setName("a"); |
|
272 |
cookie.setValue("b"); |
|
273 |
cookie.setExpirationDate(QDateTime(QDate(2012, 1, 29), QTime(23, 59, 59), Qt::UTC)); |
|
274 |
QTest::newRow("broken-expiration1") << "a=b; expires=Sun, 29-Jan-2012 23:59:59;" << cookie; |
|
275 |
||
276 |
cookie.setExpirationDate(QDateTime(QDate(1999, 11, 9), QTime(23, 12, 40), Qt::UTC)); |
|
277 |
QTest::newRow("expiration1") << "a=b;expires=Wednesday, 09-Nov-1999 23:12:40 GMT" << cookie; |
|
278 |
QTest::newRow("expiration2") << "a=b;expires=Wed, 09-Nov-1999 23:12:40 GMT" << cookie; |
|
279 |
QTest::newRow("expiration3") << "a=b; expires=Wednesday, 09-Nov-1999 23:12:40 GMT " << cookie; |
|
280 |
QTest::newRow("expiration-utc") << "a=b;expires=Wednesday, 09-Nov-1999 23:12:40 UTC" << cookie; |
|
281 |
||
282 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 0, 0), Qt::UTC)); |
|
283 |
QTest::newRow("time-0") << "a=b;expires=14 Apr 89 03:20" << cookie; |
|
284 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 12, 0), Qt::UTC)); |
|
285 |
QTest::newRow("time-1") << "a=b;expires=14 Apr 89 03:20:12" << cookie; |
|
286 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 12, 88), Qt::UTC)); |
|
287 |
QTest::newRow("time-2") << "a=b;expires=14 Apr 89 03:20:12.88" << cookie; |
|
288 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 12, 88), Qt::UTC)); |
|
289 |
QTest::newRow("time-3") << "a=b;expires=14 Apr 89 03:20:12.88am" << cookie; |
|
290 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(15, 20, 12, 88), Qt::UTC)); |
|
291 |
QTest::newRow("time-4") << "a=b;expires=14 Apr 89 03:20:12.88pm" << cookie; |
|
292 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 12, 88), Qt::UTC)); |
|
293 |
QTest::newRow("time-5") << "a=b;expires=14 Apr 89 03:20:12.88 Am" << cookie; |
|
294 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(15, 20, 12, 88), Qt::UTC)); |
|
295 |
QTest::newRow("time-6") << "a=b;expires=14 Apr 89 03:20:12.88 PM" << cookie; |
|
296 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(15, 20, 12, 88), Qt::UTC)); |
|
297 |
QTest::newRow("time-7") << "a=b;expires=14 Apr 89 3:20:12.88 PM" << cookie; |
|
298 |
||
299 |
// normal months |
|
300 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 1), Qt::UTC)); |
|
301 |
QTest::newRow("months-1") << "a=b;expires=Jan 1 89 1:1" << cookie; |
|
302 |
cookie.setExpirationDate(QDateTime(QDate(1989, 2, 1), QTime(1, 1), Qt::UTC)); |
|
303 |
QTest::newRow("months-2") << "a=b;expires=Feb 1 89 1:1" << cookie; |
|
304 |
cookie.setExpirationDate(QDateTime(QDate(1989, 3, 1), QTime(1, 1), Qt::UTC)); |
|
305 |
QTest::newRow("months-3") << "a=b;expires=mar 1 89 1:1" << cookie; |
|
306 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 1), QTime(1, 1), Qt::UTC)); |
|
307 |
QTest::newRow("months-4") << "a=b;expires=Apr 1 89 1:1" << cookie; |
|
308 |
cookie.setExpirationDate(QDateTime(QDate(1989, 5, 1), QTime(1, 1), Qt::UTC)); |
|
309 |
QTest::newRow("months-5") << "a=b;expires=May 1 89 1:1" << cookie; |
|
310 |
cookie.setExpirationDate(QDateTime(QDate(1989, 6, 1), QTime(1, 1), Qt::UTC)); |
|
311 |
QTest::newRow("months-6") << "a=b;expires=Jun 1 89 1:1" << cookie; |
|
312 |
cookie.setExpirationDate(QDateTime(QDate(1989, 7, 1), QTime(1, 1), Qt::UTC)); |
|
313 |
QTest::newRow("months-7") << "a=b;expires=Jul 1 89 1:1" << cookie; |
|
314 |
cookie.setExpirationDate(QDateTime(QDate(1989, 8, 1), QTime(1, 1), Qt::UTC)); |
|
315 |
QTest::newRow("months-8") << "a=b;expires=Aug 1 89 1:1" << cookie; |
|
316 |
cookie.setExpirationDate(QDateTime(QDate(1989, 9, 1), QTime(1, 1), Qt::UTC)); |
|
317 |
QTest::newRow("months-9") << "a=b;expires=Sep 1 89 1:1" << cookie; |
|
318 |
cookie.setExpirationDate(QDateTime(QDate(1989, 10, 1), QTime(1, 1), Qt::UTC)); |
|
319 |
QTest::newRow("months-10") << "a=b;expires=Oct 1 89 1:1" << cookie; |
|
320 |
cookie.setExpirationDate(QDateTime(QDate(1989, 11, 1), QTime(1, 1), Qt::UTC)); |
|
321 |
QTest::newRow("months-11") << "a=b;expires=Nov 1 89 1:1" << cookie; |
|
322 |
cookie.setExpirationDate(QDateTime(QDate(1989, 12, 1), QTime(1, 1), Qt::UTC)); |
|
323 |
QTest::newRow("months-12") << "a=b;expires=Dec 1 89 1:1" << cookie; |
|
324 |
||
325 |
// extra months |
|
326 |
cookie.setExpirationDate(QDateTime(QDate(1989, 12, 1), QTime(1, 1), Qt::UTC)); |
|
327 |
QTest::newRow("months-13") << "a=b;expires=December 1 89 1:1" << cookie; |
|
328 |
QTest::newRow("months-14") << "a=b;expires=1 89 1:1 Dec" << cookie; |
|
329 |
//cookie.setExpirationDate(QDateTime()); |
|
330 |
//QTest::newRow("months-15") << "a=b;expires=1 89 1:1 De" << cookie; |
|
331 |
cookie.setExpirationDate(QDateTime(QDate(2024, 2, 29), QTime(1, 1), Qt::UTC)); |
|
332 |
QTest::newRow("months-16") << "a=b;expires=2024 29 Feb 1:1" << cookie; |
|
333 |
cookie.setExpirationDate(QDateTime(QDate(2024, 2, 29), QTime(1, 1), Qt::UTC)); |
|
334 |
QTest::newRow("months-17") << "a=b;expires=Fri, 29-Feb-2024 01:01:00 GMT" << cookie; |
|
335 |
QTest::newRow("months-18") << "a=b;expires=2024 29 Feb 1:1 GMT" << cookie; |
|
336 |
||
337 |
// normal offsets |
|
338 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
339 |
QTest::newRow("zoneoffset-0") << "a=b;expires=Jan 1 89 8:0 PST" << cookie; |
|
340 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
341 |
QTest::newRow("zoneoffset-1") << "a=b;expires=Jan 1 89 8:0 PDT" << cookie; |
|
342 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
343 |
QTest::newRow("zoneoffset-2") << "a=b;expires=Jan 1 89 7:0 MST" << cookie; |
|
344 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
345 |
QTest::newRow("zoneoffset-3") << "a=b;expires=Jan 1 89 7:0 MDT" << cookie; |
|
346 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
347 |
QTest::newRow("zoneoffset-4") << "a=b;expires=Jan 1 89 6:0 CST" << cookie; |
|
348 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
349 |
QTest::newRow("zoneoffset-5") << "a=b;expires=Jan 1 89 6:0 CDT" << cookie; |
|
350 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
351 |
QTest::newRow("zoneoffset-6") << "a=b;expires=Jan 1 89 5:0 EST" << cookie; |
|
352 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
353 |
QTest::newRow("zoneoffset-7") << "a=b;expires=Jan 1 89 5:0 EDT" << cookie; |
|
354 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
355 |
QTest::newRow("zoneoffset-8") << "a=b;expires=Jan 1 89 4:0 AST" << cookie; |
|
356 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
357 |
QTest::newRow("zoneoffset-9") << "a=b;expires=Jan 1 89 3:0 NST" << cookie; |
|
358 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
359 |
QTest::newRow("zoneoffset-10") << "a=b;expires=Jan 1 89 0:0 GMT" << cookie; |
|
360 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
361 |
QTest::newRow("zoneoffset-11") << "a=b;expires=Jan 1 89 0:0 BST" << cookie; |
|
362 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 2), QTime(0, 0), Qt::UTC)); |
|
363 |
QTest::newRow("zoneoffset-12") << "a=b;expires=Jan 1 89 23:0 MET" << cookie; |
|
364 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 2), QTime(0, 0), Qt::UTC)); |
|
365 |
QTest::newRow("zoneoffset-13") << "a=b;expires=Jan 1 89 22:0 EET" << cookie; |
|
366 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 2), QTime(0, 0), Qt::UTC)); |
|
367 |
QTest::newRow("zoneoffset-14") << "a=b;expires=Jan 1 89 15:0 JST" << cookie; |
|
368 |
||
369 |
// extra offsets |
|
370 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 2), QTime(0, 0), Qt::UTC)); |
|
371 |
QTest::newRow("zoneoffset-14") << "a=b;expires=Jan 1 89 15:0 JST+1" << cookie; |
|
372 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC)); |
|
373 |
QTest::newRow("zoneoffset-15") << "a=b;expires=Jan 1 89 0:0 GMT+1" << cookie; |
|
374 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
375 |
QTest::newRow("zoneoffset-15b") << "a=b;expires=Jan 1 89 1:0 GMT-1" << cookie; |
|
376 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC)); |
|
377 |
QTest::newRow("zoneoffset-16") << "a=b;expires=Jan 1 89 0:0 GMT+01" << cookie; |
|
378 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 5), Qt::UTC)); |
|
379 |
QTest::newRow("zoneoffset-17") << "a=b;expires=Jan 1 89 0:0 GMT+0105" << cookie; |
|
380 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
381 |
QTest::newRow("zoneoffset-18") << "a=b;expires=Jan 1 89 0:0 GMT+015" << cookie; |
|
382 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
383 |
QTest::newRow("zoneoffset-19") << "a=b;expires=Jan 1 89 0:0 GM" << cookie; |
|
384 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
385 |
QTest::newRow("zoneoffset-19b") << "a=b;expires=Jan 1 89 0:0 GMT" << cookie; |
|
386 |
||
387 |
// offsets from gmt |
|
388 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC)); |
|
389 |
QTest::newRow("zoneoffset-20") << "a=b;expires=Jan 1 89 0:0 +1" << cookie; |
|
390 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 0), Qt::UTC)); |
|
391 |
QTest::newRow("zoneoffset-21") << "a=b;expires=Jan 1 89 0:0 +01" << cookie; |
|
392 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(1, 1), Qt::UTC)); |
|
393 |
QTest::newRow("zoneoffset-22") << "a=b;expires=Jan 1 89 0:0 +0101" << cookie; |
|
394 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 1), QTime(0, 0), Qt::UTC)); |
|
395 |
QTest::newRow("zoneoffset-23") << "a=b;expires=Jan 1 89 1:0 -1" << cookie; |
|
396 |
||
397 |
// Y2k |
|
398 |
cookie.setExpirationDate(QDateTime(QDate(2000, 1, 1), QTime(0, 0), Qt::UTC)); |
|
399 |
QTest::newRow("year-0") << "a=b;expires=Jan 1 00 0:0" << cookie; |
|
400 |
cookie.setExpirationDate(QDateTime(QDate(1970, 1, 1), QTime(0, 0), Qt::UTC)); |
|
401 |
QTest::newRow("year-1") << "a=b;expires=Jan 1 70 0:0" << cookie; |
|
402 |
cookie.setExpirationDate(QDateTime(QDate(1971, 1, 1), QTime(0, 0), Qt::UTC)); |
|
403 |
QTest::newRow("year-2") << "a=b;expires=Jan 1 71 0:0" << cookie; |
|
404 |
||
405 |
// Day, month, year |
|
406 |
cookie.setExpirationDate(QDateTime(QDate(2013, 1, 2), QTime(0, 0), Qt::UTC)); |
|
407 |
QTest::newRow("date-0") << "a=b;expires=Jan 2 13 0:0" << cookie; |
|
408 |
QTest::newRow("date-1") << "a=b;expires=1-2-13 0:0" << cookie; |
|
409 |
QTest::newRow("date-2") << "a=b;expires=1/2/13 0:0" << cookie; |
|
410 |
QTest::newRow("date-3") << "a=b;expires=Jan 2 13 0:0" << cookie; |
|
411 |
QTest::newRow("date-4") << "a=b;expires=Jan 2, 13 0:0" << cookie; |
|
412 |
QTest::newRow("date-5") << "a=b;expires=1-2-13 0:0" << cookie; |
|
413 |
QTest::newRow("date-6") << "a=b;expires=1/2/13 0:0" << cookie; |
|
414 |
||
415 |
// Known Year, determine month and day |
|
416 |
cookie.setExpirationDate(QDateTime(QDate(1995, 1, 13), QTime(0, 0), Qt::UTC)); |
|
417 |
QTest::newRow("knownyear-0") << "a=b;expires=13/1/95 0:0" << cookie; |
|
418 |
QTest::newRow("knownyear-1") << "a=b;expires=95/13/1 0:0" << cookie; |
|
419 |
QTest::newRow("knownyear-2") << "a=b;expires=1995/1/13 0:0" << cookie; |
|
420 |
QTest::newRow("knownyear-3") << "a=b;expires=1995/13/1 0:0" << cookie; |
|
421 |
cookie.setExpirationDate(QDateTime(QDate(1995, 1, 2), QTime(0, 0), Qt::UTC)); |
|
422 |
QTest::newRow("knownyear-4") << "a=b;expires=1/2/95 0:0" << cookie; |
|
423 |
QTest::newRow("knownyear-5") << "a=b;expires=95/1/2 0:0" << cookie; |
|
424 |
||
425 |
// Known Year, Known day, determining month |
|
426 |
cookie.setExpirationDate(QDateTime(QDate(1995, 1, 13), QTime(0, 0), Qt::UTC)); |
|
427 |
QTest::newRow("knownYD-0") << "a=b;expires=13/1/95 0:0" << cookie; |
|
428 |
QTest::newRow("knownYD-1") << "a=b;expires=1/13/95 0:0" << cookie; |
|
429 |
QTest::newRow("knownYD-2") << "a=b;expires=95/13/1 0:0" << cookie; |
|
430 |
QTest::newRow("knownYD-3") << "a=b;expires=95/1/13 0:0" << cookie; |
|
431 |
||
432 |
// Month comes before Year |
|
433 |
cookie.setExpirationDate(QDateTime(QDate(2021, 03, 26), QTime(0, 0), Qt::UTC)); |
|
434 |
QTest::newRow("month-0") << "a=b;expires=26/03/21 0:0" << cookie; |
|
435 |
cookie.setExpirationDate(QDateTime(QDate(2015, 12, 30), QTime(16, 25, 0, 0), Qt::UTC)); |
|
436 |
QTest::newRow("month-1") << "a=b;expires=wed 16:25pm December 2015 30" << cookie; |
|
437 |
cookie.setExpirationDate(QDateTime(QDate(2031, 11, 11), QTime(16, 25, 0, 0), Qt::UTC)); |
|
438 |
QTest::newRow("month-2") << "a=b;expires=16:25 11 31 11" << cookie; |
|
439 |
||
440 |
// The very ambiguous cases |
|
441 |
// Matching Firefox's behavior of guessing month, day, year in those cases |
|
442 |
cookie.setExpirationDate(QDateTime(QDate(2013, 10, 2), QTime(0, 0), Qt::UTC)); |
|
443 |
QTest::newRow("ambiguousd-0") << "a=b;expires=10/2/13 0:0" << cookie; |
|
444 |
cookie.setExpirationDate(QDateTime(QDate(2013, 2, 10), QTime(0, 0), Qt::UTC)); |
|
445 |
QTest::newRow("ambiguousd-1") << "a=b;expires=2/10/13 0:0" << cookie; |
|
446 |
cookie.setExpirationDate(QDateTime(QDate(2010, 2, 3), QTime(0, 0), Qt::UTC)); |
|
447 |
QTest::newRow("ambiguousd-2") << "a=b;expires=2/3/10 0:0" << cookie; |
|
448 |
||
449 |
// FYI If you try these in Firefox it wont set a cookie for the following two string |
|
450 |
// because 03 is turned into the year at which point it is expired |
|
451 |
cookie.setExpirationDate(QDateTime(QDate(2003, 2, 10), QTime(0, 0), Qt::UTC)); |
|
452 |
QTest::newRow("ambiguousd-3") << "a=b;expires=2/10/3 0:0" << cookie; |
|
453 |
cookie.setExpirationDate(QDateTime(QDate(2003, 10, 2), QTime(0, 0), Qt::UTC)); |
|
454 |
QTest::newRow("ambiguousd-4") << "a=b;expires=10/2/3 0:0" << cookie; |
|
455 |
||
456 |
// These are the cookies that firefox's source says it can parse |
|
457 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 0, 0), Qt::UTC)); |
|
458 |
QTest::newRow("firefox-0") << "a=b;expires=14 Apr 89 03:20" << cookie; |
|
459 |
||
460 |
cookie.setExpirationDate(QDateTime(QDate(1989, 4, 14), QTime(3, 20, 0, 0), Qt::UTC)); |
|
461 |
QTest::newRow("firefox-1") << "a=b;expires=14 Apr 89 03:20 GMT" << cookie; |
|
462 |
||
463 |
cookie.setExpirationDate(QDateTime(QDate(1989, 3, 17), QTime(4, 1, 33, 0), Qt::UTC)); |
|
464 |
QTest::newRow("firefox-2") << "a=b;expires=Fri, 17 Mar 89 4:01:33" << cookie; |
|
465 |
||
466 |
cookie.setExpirationDate(QDateTime(QDate(1989, 3, 17), QTime(4, 1, 0, 0), Qt::UTC)); |
|
467 |
QTest::newRow("firefox-3") << "a=b;expires=Fri, 17 Mar 89 4:01 GMT" << cookie; |
|
468 |
||
469 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 16), QTime(16-8, 12, 0, 0), Qt::UTC)); |
|
470 |
QTest::newRow("firefox-4") << "a=b;expires=Mon Jan 16 16:12 PDT 1989" << cookie; |
|
471 |
||
472 |
cookie.setExpirationDate(QDateTime(QDate(1989, 1, 16), QTime(17, 42, 0, 0), Qt::UTC)); |
|
473 |
QTest::newRow("firefox-5") << "a=b;expires=Mon Jan 16 16:12 +0130 1989" << cookie; |
|
474 |
||
475 |
cookie.setExpirationDate(QDateTime(QDate(1992, 5, 6), QTime(16-9, 41, 0, 0), Qt::UTC)); |
|
476 |
QTest::newRow("firefox-6") << "a=b;expires=6 May 1992 16:41-JST (Wednesday)" << cookie; |
|
477 |
||
478 |
cookie.setExpirationDate(QDateTime(QDate(1993, 8, 22), QTime(10, 59, 12, 82), Qt::UTC)); |
|
479 |
QTest::newRow("firefox-7") << "a=b;expires=22-AUG-1993 10:59:12.82" << cookie; |
|
480 |
||
481 |
cookie.setExpirationDate(QDateTime(QDate(1993, 8, 22), QTime(22, 59, 0, 0), Qt::UTC)); |
|
482 |
QTest::newRow("firefox-8") << "a=b;expires=22-AUG-1993 10:59pm" << cookie; |
|
483 |
||
484 |
cookie.setExpirationDate(QDateTime(QDate(1993, 8, 22), QTime(12, 59, 0, 0), Qt::UTC)); |
|
485 |
QTest::newRow("firefox-9") << "a=b;expires=22-AUG-1993 12:59am" << cookie; |
|
486 |
||
487 |
cookie.setExpirationDate(QDateTime(QDate(1993, 8, 22), QTime(12, 59, 0, 0), Qt::UTC)); |
|
488 |
QTest::newRow("firefox-10") << "a=b;expires=22-AUG-1993 12:59 PM" << cookie; |
|
489 |
||
490 |
cookie.setExpirationDate(QDateTime(QDate(1995, 8, 4), QTime(15, 54, 0, 0), Qt::UTC)); |
|
491 |
QTest::newRow("firefox-11") << "a=b;expires=Friday, August 04, 1995 3:54 PM" << cookie; |
|
492 |
||
493 |
cookie.setExpirationDate(QDateTime(QDate(1995, 6, 21), QTime(16, 24, 34, 0), Qt::UTC)); |
|
494 |
QTest::newRow("firefox-12") << "a=b;expires=06/21/95 04:24:34 PM" << cookie; |
|
495 |
||
496 |
cookie.setExpirationDate(QDateTime(QDate(1995, 6, 20), QTime(21, 7, 0, 0), Qt::UTC)); |
|
497 |
QTest::newRow("firefox-13") << "a=b;expires=20/06/95 21:07" << cookie; |
|
498 |
||
499 |
cookie.setExpirationDate(QDateTime(QDate(1995, 6, 8), QTime(19-5, 32, 48, 0), Qt::UTC)); |
|
500 |
QTest::newRow("firefox-14") << "a=b;expires=95-06-08 19:32:48 EDT" << cookie; |
|
501 |
||
502 |
// Edge cases caught by fuzzing |
|
503 |
// These are about the default cause creates dates that don't exits |
|
504 |
cookie.setExpirationDate(QDateTime(QDate(2030, 2, 25), QTime(1, 1, 0, 0), Qt::UTC)); |
|
505 |
QTest::newRow("fuzz-0") << "a=b; expires=30 -000002 1:1 25;" << cookie; |
|
506 |
||
507 |
cookie.setExpirationDate(QDateTime(QDate(2031, 11, 20), QTime(1, 1, 0, 0), Qt::UTC)); |
|
508 |
QTest::newRow("fuzz-1") << "a=b; expires=31 11 20 1:1;" << cookie; |
|
509 |
||
510 |
// April only has 30 days |
|
511 |
cookie.setExpirationDate(QDateTime(QDate(2031, 4, 30), QTime(1, 1, 0, 0), Qt::UTC)); |
|
512 |
QTest::newRow("fuzz-2") << "a=b; expires=31 30 4 1:1" << cookie; |
|
513 |
||
514 |
// 9 must be the month so 31 can't be the day |
|
515 |
cookie.setExpirationDate(QDateTime(QDate(2031, 9, 21), QTime(1, 1, 0, 0), Qt::UTC)); |
|
516 |
QTest::newRow("fuzz-3") << "a=b; expires=31 21 9 1:1" << cookie; |
|
517 |
||
518 |
// Year is known, then fallback to defaults of filling in month and day |
|
519 |
cookie.setExpirationDate(QDateTime(QDate(2031, 11, 1), QTime(1, 1, 0, 0), Qt::UTC)); |
|
520 |
QTest::newRow("fuzz-4") << "a=b; expires=31 11 01 1:1" << cookie; |
|
521 |
||
522 |
// 2 must be the month so 30 can't be the day |
|
523 |
cookie.setExpirationDate(QDateTime(QDate(2030, 2, 20), QTime(1, 1, 0, 0), Qt::UTC)); |
|
524 |
QTest::newRow("fuzz-5") << "a=b; expires=30 02 20 1:1" << cookie; |
|
525 |
||
526 |
cookie.setExpirationDate(QDateTime(QDate(2021, 12, 22), QTime(1, 1, 0, 0), Qt::UTC)); |
|
527 |
QTest::newRow("fuzz-6") << "a=b; expires=2021 12 22 1:1" << cookie; |
|
528 |
||
529 |
cookie.setExpirationDate(QDateTime(QDate(2029, 2, 23), QTime(1, 1, 0, 0), Qt::UTC)); |
|
530 |
QTest::newRow("fuzz-7") << "a=b; expires=29 23 Feb 1:1" << cookie; |
|
531 |
||
532 |
// 11 and 6 don't have 31 days |
|
533 |
cookie.setExpirationDate(QDateTime(QDate(2031, 11, 06), QTime(1, 1, 0, 0), Qt::UTC)); |
|
534 |
QTest::newRow("fuzz-8") << "a=b; expires=31 11 06 1:1" << cookie; |
|
535 |
||
536 |
// two-digit years: |
|
537 |
// from 70 until 99, we assume 20th century |
|
538 |
cookie.setExpirationDate(QDateTime(QDate(1999, 11, 9), QTime(23, 12, 40), Qt::UTC)); |
|
539 |
QTest::newRow("expiration-2digit1") << "a=b; expires=Wednesday, 09-Nov-99 23:12:40 GMT " << cookie; |
|
540 |
cookie.setExpirationDate(QDateTime(QDate(1970, 1, 1), QTime(23, 12, 40), Qt::UTC)); |
|
541 |
QTest::newRow("expiration-2digit2") << "a=b; expires=Thursday, 01-Jan-70 23:12:40 GMT " << cookie; |
|
542 |
// from 00 until 69, we assume 21st century |
|
543 |
cookie.setExpirationDate(QDateTime(QDate(2000, 1, 1), QTime(23, 12, 40), Qt::UTC)); |
|
544 |
QTest::newRow("expiration-2digit3") << "a=b; expires=Saturday, 01-Jan-00 23:12:40 GMT " << cookie; |
|
545 |
cookie.setExpirationDate(QDateTime(QDate(2020, 1, 1), QTime(23, 12, 40), Qt::UTC)); |
|
546 |
QTest::newRow("expiration-2digit4") << "a=b; expires=Wednesday, 01-Jan-20 23:12:40 GMT " << cookie; |
|
547 |
cookie.setExpirationDate(QDateTime(QDate(2069, 1, 1), QTime(23, 12, 40), Qt::UTC)); |
|
548 |
QTest::newRow("expiration-2digit5") << "a=b; expires=Wednesday, 01-Jan-69 23:12:40 GMT " << cookie; |
|
549 |
||
550 |
cookie.setExpirationDate(QDateTime(QDate(1999, 11, 9), QTime(23, 12, 40), Qt::UTC)); |
|
551 |
||
552 |
cookie.setPath("/"); |
|
553 |
QTest::newRow("expires+path") << "a=b; expires=Wed, 09-Nov-1999 23:12:40 GMT; path=/" << cookie; |
|
554 |
QTest::newRow("path+expires") << "a=b; path=/;expires=Wed, 09-Nov-1999 23:12:40 GMT " << cookie; |
|
555 |
||
556 |
cookie.setDomain(".qt.nokia.com"); |
|
557 |
QTest::newRow("full") << "a=b; domain=.qt.nokia.com;expires=Wed, 09-Nov-1999 23:12:40 GMT;path=/" << cookie; |
|
558 |
QTest::newRow("full2") << "a=b;path=/; expires=Wed, 09-Nov-1999 23:12:40 GMT ;domain=.qt.nokia.com" << cookie; |
|
559 |
||
560 |
// cookies obtained from the network: |
|
561 |
cookie = QNetworkCookie("__siteid", "1"); |
|
562 |
cookie.setPath("/"); |
|
563 |
cookie.setExpirationDate(QDateTime(QDate(9999, 12, 31), QTime(23, 59, 59), Qt::UTC)); |
|
564 |
QTest::newRow("network2") << "__siteid=1; expires=Fri, 31-Dec-9999 23:59:59 GMT; path=/" << cookie; |
|
565 |
||
566 |
cookie = QNetworkCookie("YM.LC", "v=2&m=9993_262838_159_1558_1063_0_5649_4012_3776161073,9426_260205_549_1295_1336_0_5141_4738_3922731647,6733_258196_952_1364_643_0_3560_-1_0,3677_237633_1294_1294_19267_0_3244_29483_4102206176,1315_235149_1693_1541_941_0_3224_1691_1861378060,1858_214311_2100_1298_19538_0_2873_30900_716411652,6258_212007_2506_1285_1017_0_2868_3606_4288540264,3743_207884_2895_1362_2759_0_2545_7114_3388520216,2654_205253_3257_1297_1332_0_2504_4682_3048534803,1891_184881_3660_1291_19079_0_978_29178_2592538685&f=1&n=20&s=date&o=down&e=1196548712&b=Inbox&u=removed"); |
|
567 |
cookie.setPath("/"); |
|
568 |
cookie.setDomain("mail.yahoo.com"); |
|
569 |
QTest::newRow("network3") << "YM.LC=v=2&m=9993_262838_159_1558_1063_0_5649_4012_3776161073,9426_260205_549_1295_1336_0_5141_4738_3922731647,6733_258196_952_1364_643_0_3560_-1_0,3677_237633_1294_1294_19267_0_3244_29483_4102206176,1315_235149_1693_1541_941_0_3224_1691_1861378060,1858_214311_2100_1298_19538_0_2873_30900_716411652,6258_212007_2506_1285_1017_0_2868_3606_4288540264,3743_207884_2895_1362_2759_0_2545_7114_3388520216,2654_205253_3257_1297_1332_0_2504_4682_3048534803,1891_184881_3660_1291_19079_0_978_29178_2592538685&f=1&n=20&s=date&o=down&e=1196548712&b=Inbox&u=removed; path=/; domain=mail.yahoo.com" << cookie; |
|
570 |
||
571 |
cookie = QNetworkCookie("__ac", "c2hhdXNtYW46U2FTYW80Wm8%3D"); |
|
572 |
cookie.setPath("/"); |
|
573 |
cookie.setExpirationDate(QDateTime(QDate(2008, 8, 30), QTime(20, 21, 49), Qt::UTC)); |
|
574 |
QTest::newRow("network4") << "__ac=\"c2hhdXNtYW46U2FTYW80Wm8%3D\"; Path=/; Expires=Sat, 30 Aug 2008 20:21:49 +0000" << cookie; |
|
575 |
} |
|
576 |
||
577 |
void tst_QNetworkCookie::parseSingleCookie() |
|
578 |
{ |
|
579 |
QFETCH(QString, cookieString); |
|
580 |
QFETCH(QNetworkCookie, expectedCookie); |
|
581 |
||
582 |
QList<QNetworkCookie> result = QNetworkCookie::parseCookies(cookieString.toLatin1()); |
|
583 |
||
584 |
//QEXPECT_FAIL("network2", "QDateTime parsing problem: the date is beyond year 8000", Abort); |
|
585 |
QCOMPARE(result.count(), 1); |
|
586 |
QEXPECT_FAIL("network3", "Cookie value contains commas, violating the HTTP spec", Abort); |
|
587 |
QCOMPARE(result.at(0), expectedCookie); |
|
588 |
||
589 |
result = QNetworkCookie::parseCookies(result.at(0).toRawForm()); |
|
590 |
QCOMPARE(result.count(), 1); |
|
591 |
||
592 |
// Drop any millisecond information, if there's any |
|
593 |
QDateTime dt = expectedCookie.expirationDate(); |
|
594 |
if (dt.isValid()) { |
|
595 |
QTime t = dt.time(); |
|
596 |
dt.setTime(t.addMSecs(-t.msec())); |
|
597 |
expectedCookie.setExpirationDate(dt); |
|
598 |
} |
|
599 |
||
600 |
QCOMPARE(result.at(0), expectedCookie); |
|
601 |
} |
|
602 |
||
603 |
void tst_QNetworkCookie::parseMultipleCookies_data() |
|
604 |
{ |
|
605 |
QTest::addColumn<QString>("cookieString"); |
|
606 |
QTest::addColumn<QList<QNetworkCookie> >("expectedCookies"); |
|
607 |
||
608 |
QList<QNetworkCookie> list; |
|
609 |
QTest::newRow("empty") << "" << list; |
|
610 |
||
611 |
// these are technically empty cookies: |
|
612 |
QTest::newRow("invalid-01") << ";" << list; |
|
613 |
QTest::newRow("invalid-02") << " " << list; |
|
614 |
QTest::newRow("invalid-03") << " ," << list; |
|
615 |
QTest::newRow("invalid-04") << ";;,, ; ; , , ; , ;" << list; |
|
616 |
||
617 |
// these are really invalid: |
|
618 |
// reason: malformed NAME=VALUE pair |
|
619 |
QTest::newRow("invalid-05") << "foo" << list; |
|
620 |
QTest::newRow("invalid-06") << "=b" << list; |
|
621 |
QTest::newRow("invalid-09") << "foo,a=b" << list; |
|
622 |
QTest::newRow("invalid-11") << ";path=/" << list; |
|
623 |
||
624 |
// reason: malformed expiration date string |
|
625 |
QTest::newRow("invalid-12") << "a=b;expires=" << list; |
|
626 |
QTest::newRow("invalid-13") << "a=b;expires=foobar" << list; |
|
627 |
QTest::newRow("invalid-14") << "a=b;expires=foobar, abc" << list; |
|
628 |
QTest::newRow("invalid-15") << "a=b;expires=foobar, dd-mmm-yyyy hh:mm:ss GMT; path=/" << list; |
|
629 |
QTest::newRow("invalid-16") << "a=b;expires=foobar, 32-Caz-1999 24:01:60 GMT; path=/" << list; |
|
630 |
||
631 |
QNetworkCookie cookie; |
|
632 |
cookie.setName("a"); |
|
633 |
list += cookie; |
|
634 |
cookie.setName("c"); |
|
635 |
cookie.setValue("d"); |
|
636 |
list += cookie; |
|
637 |
QTest::newRow("two-1") << "a=,c=d" << list; |
|
638 |
QTest::newRow("two-2") << "a=, c=d" << list; |
|
639 |
QTest::newRow("two-3") << "a= ,c=d" << list; |
|
640 |
QTest::newRow("two-4") << "a= , c=d" << list; |
|
641 |
||
642 |
list.clear(); |
|
643 |
list += cookie; |
|
644 |
cookie.setName("a"); |
|
645 |
cookie.setValue(QByteArray()); |
|
646 |
list += cookie; |
|
647 |
QTest::newRow("two-5") << "c=d,a=" << list; |
|
648 |
QTest::newRow("two-6") << "c=d, a=" << list; |
|
649 |
QTest::newRow("two-7") << "c=d , a=" << list; |
|
650 |
||
651 |
cookie.setName("foo"); |
|
652 |
cookie.setValue("bar"); |
|
653 |
cookie.setPath("/"); |
|
654 |
list += cookie; |
|
655 |
QTest::newRow("complex-1") << "c=d, a=, foo=bar; path=/" << list; |
|
656 |
||
657 |
cookie.setName("baz"); |
|
658 |
cookie.setDomain(".qt.nokia.com"); |
|
659 |
list.prepend(cookie); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
660 |
QTest::newRow("complex-2") << "baz=bar; path=/; domain=.qt.nokia.com, c=d,a=,foo=bar; path=/" << list; |
0 | 661 |
|
662 |
// cookies obtained from the network: |
|
663 |
cookie = QNetworkCookie("id", "51706646077999719"); |
|
664 |
cookie.setDomain(".bluestreak.com"); |
|
665 |
cookie.setPath("/"); |
|
666 |
cookie.setExpirationDate(QDateTime(QDate(2017, 12, 05), QTime(9, 11, 7), Qt::UTC)); |
|
667 |
list << cookie; |
|
668 |
cookie.setName("bb"); |
|
669 |
cookie.setValue("\\\"K14144t\\\"_AAQ\\\"ototrK_A_ttot44AQ4KwoRQtoto|"); |
|
670 |
list << cookie; |
|
671 |
cookie.setName("adv"); |
|
672 |
cookie.setValue(QByteArray()); |
|
673 |
list << cookie; |
|
674 |
QTest::newRow("network1") << "id=51706646077999719 bb=\"K14144t\"_AAQ\"ototrK_A_ttot44AQ4KwoRQtoto| adv=; Domain=.bluestreak.com; expires=Tuesday 05-Dec-2017 09:11:07 GMT; path=/;" << list; |
|
675 |
||
676 |
QNetworkCookie cookieA; |
|
677 |
cookieA.setName("a"); |
|
678 |
cookieA.setValue("b"); |
|
679 |
||
680 |
QNetworkCookie cookieB; |
|
681 |
cookieB.setName("c"); |
|
682 |
cookieB.setValue("d"); |
|
683 |
||
684 |
// NewLine |
|
685 |
cookieA.setExpirationDate(QDateTime(QDate(2009, 3, 10), QTime(7, 0, 0, 0), Qt::UTC)); |
|
686 |
cookieB.setExpirationDate(QDateTime(QDate(2009, 3, 20), QTime(7, 0, 0, 0), Qt::UTC)); |
|
687 |
list = QList<QNetworkCookie>() << cookieA << cookieB; |
|
688 |
QTest::newRow("real-0") << "a=b; expires=Tue Mar 10 07:00:00 2009 GMT\nc=d; expires=Fri Mar 20 07:00:00 2009 GMT" << list; |
|
689 |
QTest::newRow("real-1") << "a=b; expires=Tue Mar 10 07:00:00 2009 GMT\n\nc=d; expires=Fri Mar 20 07:00:00 2009 GMT" << list; |
|
690 |
QTest::newRow("real-2") << "a=b; expires=Mar 10 07:00:00 2009 GMT, Tue\nc=d; expires=Fri Mar 20 07:00:00 2009 GMT" << list; |
|
691 |
||
692 |
// Match firefox's behavior |
|
693 |
cookieA.setPath("/foo"); |
|
694 |
list = QList<QNetworkCookie>() << cookieA << cookieB; |
|
695 |
QTest::newRow("real-3") << "a=b; expires=Mar 10 07:00:00 2009 GMT, Tue; path=/foo\nc=d; expires=Fri Mar 20 07:00:00 2009 GMT" << list; |
|
696 |
} |
|
697 |
||
698 |
void tst_QNetworkCookie::parseMultipleCookies() |
|
699 |
{ |
|
700 |
QFETCH(QString, cookieString); |
|
701 |
QFETCH(QList<QNetworkCookie>, expectedCookies); |
|
702 |
||
703 |
QList<QNetworkCookie> result = QNetworkCookie::parseCookies(cookieString.toLatin1()); |
|
704 |
||
705 |
QEXPECT_FAIL("network1", "Apparently multiple cookies set in one request (and an invalid date)", Abort); |
|
706 |
QCOMPARE(result, expectedCookies); |
|
707 |
} |
|
708 |
||
709 |
QTEST_MAIN(tst_QNetworkCookie) |
|
710 |
#include "tst_qnetworkcookie.moc" |