Falkon Develop
Cross-platform Qt-based web browser
cookiestest.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#include "cookiestest.h"
19#include "autotests.h"
20#include "datapaths.h"
21#include "settings.h"
22
23#include <QDir>
24
25void CookiesTest::initTestCase()
26{
27 m_cookieJar = new CookieJar_Tst;
28}
29
30void CookiesTest::cleanupTestCase()
31{
32 delete m_cookieJar;
33}
34
35void CookiesTest::domainMatchingTest_data()
36{
37 QTest::addColumn<QString>("cookieDomain");
38 QTest::addColumn<QString>("siteDomain");
39 QTest::addColumn<bool>("result");
40
41 /* http://stackoverflow.com/questions/1062963/how-do-browser-cookie-domains-work
42 1) Cookie with Domain=.example.com will be available for www.example.com
43 2) Cookie with Domain=.example.com will be available for example.com
44 3) Cookie with Domain=example.com will be converted to .example.com and thus will also be available for www.example.com
45 4) Cookie with Domain=example.com will not be available for anotherexample.com
46 */
47
48 QTest::newRow("test1") << ".example.com" << "www.example.com" << true;
49 QTest::newRow("test2") << ".example.com" << "example.com" << true;
50 QTest::newRow("test3") << "example.com" << "www.example.com" << true;
51 QTest::newRow("test4") << ".example.com" << "anotherexample.com" << false;
52 QTest::newRow("test5") << "test.example.com" << "example.com" << false;
53 QTest::newRow("test6") << ".www.example.com" << "www.example.com" << true;
54 QTest::newRow("test7") << ".www.example.com" << "example.com" << false;
55 QTest::newRow("test_empty") << ".www.example.com" << "" << false;
56 QTest::newRow("test_empty2") << "" << "example.com" << false;
57}
58
59void CookiesTest::domainMatchingTest()
60{
61 QFETCH(QString, cookieDomain);
62 QFETCH(QString, siteDomain);
63 QFETCH(bool, result);
64
65 QCOMPARE(m_cookieJar->matchDomain(cookieDomain, siteDomain), result);
66}
67
68void CookiesTest::listMatchesDomainTest_data()
69{
70 QTest::addColumn<QStringList>("list");
71 QTest::addColumn<QString>("cookieDomain");
72 QTest::addColumn<bool>("result");
73
74 QStringList list;
75 list << QSL("www.example.com") << QSL("accounts.google.com");
76 QStringList list2;
77 list2 << QSL("anotherexample.com") << QSL("a.b.x.google.com");
78
79 QTest::newRow("test1") << list << ".www.example.com" << true;
80 QTest::newRow("test2") << list << ".google.com" << false;
81 QTest::newRow("test3") << list << ".accounts.google.com" << true;
82 QTest::newRow("test4") << list << ".example.com" << false;
83 QTest::newRow("test5") << list2 << "example.com" << false;
84 QTest::newRow("test6") << list2 << "tst.anotherexample.com" << true;
85 QTest::newRow("test7") << list2 << "b.x.google.com" << false;
86 QTest::newRow("test8") << list2 << "c.a.b.x.google.com" << true;
87 QTest::newRow("test9") << list2 << ".a.b.x.google.com" << true;
88 QTest::newRow("test_empty") << list2 << "" << false;
89}
90
91void CookiesTest::listMatchesDomainTest()
92{
93 QFETCH(QStringList, list);
94 QFETCH(QString, cookieDomain);
95 QFETCH(bool, result);
96
97 QCOMPARE(m_cookieJar->listMatchesDomain(list, cookieDomain), result);
98}
99
#define FALKONTEST_MAIN(Test)
Definition: autotests.h:23
#define QSL(x)
Definition: qzcommon.h:40