예제 #1
0
void
CookieTest::OrderTest()
{
	BNetworkCookieJar jar;
	status_t result;

	BUrl url("http://testsuites.opera.com/cookies/016.php");
	result = jar.AddCookie("016-01=1", url);
	CPPUNIT_ASSERT(result == B_OK);

	url.SetUrlString("http://testsuites.opera.com/cookies/016/016-1.php");
	result = jar.AddCookie("016-02=1", url);
	CPPUNIT_ASSERT(result == B_OK);

	url.SetUrlString("http://testsuites.opera.com/cookies/016/016-2.php");
	BNetworkCookieJar::UrlIterator it = jar.GetUrlIterator(url);
	int count = 0;

	// Check that the cookie with the most specific path is sent first
	while (it.HasNext()) {
		const BNetworkCookie* cookie = it.Next();
		switch(count)
		{
			case 0:
				CPPUNIT_ASSERT_EQUAL(BString("016-02"), cookie->Name());
				break;
			case 1:
				CPPUNIT_ASSERT_EQUAL(BString("016-01"), cookie->Name());
				break;
		}
		count++;
	}

	CPPUNIT_ASSERT_EQUAL(2, count);
}
예제 #2
0
void
CookieTest::OverwriteTest()
{
	BNetworkCookieJar jar;
	status_t result;

	BUrl url("http://testsuites.opera.com/cookies/015/015.php");
	result = jar.AddCookie("015-01=1", url);
	CPPUNIT_ASSERT(result == B_OK);

	url.SetUrlString("http://testsuites.opera.com/cookies/015-1.php");
	result = jar.AddCookie("015-01=1", url);
	result = jar.AddCookie("015-02=1", url);
	CPPUNIT_ASSERT(result == B_OK);

	url.SetUrlString("http://testsuites.opera.com/cookies/015/015-2.php");
	result = jar.AddCookie("015-01=1", url);
	result = jar.AddCookie("015-02=1", url);
	CPPUNIT_ASSERT(result == B_OK);

	url.SetUrlString("http://testsuites.opera.com/cookies/015/015-3.php");
	BNetworkCookieJar::UrlIterator it = jar.GetUrlIterator(url);
	int count = 0;

	while (it.HasNext()) {
		it.Next();
		count++;
	}

	CPPUNIT_ASSERT_EQUAL(4, count);
}
예제 #3
0
const BNetworkCookie*
CookieTest::_GetCookie(BNetworkCookieJar& jar, const BUrl& url,
	const char* name)
{
	BNetworkCookieJar::UrlIterator it = jar.GetUrlIterator(url);
	const BNetworkCookie* result = NULL;

	while (it.HasNext()) {
		const BNetworkCookie* cookie = it.Next();
		if (cookie->Name() == name) {
			// Make sure the cookie is found only once.
			CPPUNIT_ASSERT(result == NULL);

			result = cookie;
		}
	}

	return result;
}