This source file includes following definitions.
- getPublicSuffixLength
- publicSuffixList
- cryptographicallyRandomValues
- TEST
#include "config.h"
#include "platform/weborigin/OriginAccessEntry.h"
#include "platform/weborigin/KURL.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "public/platform/Platform.h"
#include "public/platform/WebPublicSuffixList.h"
#include <gtest/gtest.h>
using WebCore::SecurityOrigin;
using WebCore::OriginAccessEntry;
namespace {
class OriginAccessEntryTestSuffixList : public blink::WebPublicSuffixList {
public:
virtual size_t getPublicSuffixLength(const blink::WebString&)
{
return 3;
}
};
class OriginAccessEntryTestPlatform : public blink::Platform {
public:
virtual blink::WebPublicSuffixList* publicSuffixList()
{
return &m_suffixList;
}
virtual void cryptographicallyRandomValues(unsigned char*, size_t) { ASSERT_NOT_REACHED(); }
private:
OriginAccessEntryTestSuffixList m_suffixList;
};
TEST(OriginAccessEntryTest, PublicSuffixListTest)
{
OriginAccessEntryTestPlatform platform;
blink::Platform::initialize(&platform);
RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("http://www.google.com");
OriginAccessEntry entry1("http", "google.com", OriginAccessEntry::AllowSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress);
OriginAccessEntry entry2("http", "hamster.com", OriginAccessEntry::AllowSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress);
OriginAccessEntry entry3("http", "com", OriginAccessEntry::AllowSubdomains, OriginAccessEntry::TreatIPAddressAsIPAddress);
EXPECT_EQ(OriginAccessEntry::MatchesOrigin, entry1.matchesOrigin(*origin));
EXPECT_EQ(OriginAccessEntry::DoesNotMatchOrigin, entry2.matchesOrigin(*origin));
EXPECT_EQ(OriginAccessEntry::MatchesOriginButIsPublicSuffix, entry3.matchesOrigin(*origin));
blink::Platform::shutdown();
}
}