summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-21 18:15:35 +0000
committermmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-21 18:15:35 +0000
commitd862fd9d396126f3f06a8061412def6d61d156fd (patch)
tree7052b96f95ac8b9b2f3d861daddbc82d4cdda99a
parent4167c3a50e73968cd47e0eb2502f017f432d367a (diff)
downloadchromium_src-d862fd9d396126f3f06a8061412def6d61d156fd.zip
chromium_src-d862fd9d396126f3f06a8061412def6d61d156fd.tar.gz
chromium_src-d862fd9d396126f3f06a8061412def6d61d156fd.tar.bz2
Port cookie_monster, net_util, and registry_controlled_domain to POSIXish platforms
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1164 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/base/cookie_monster.cc15
-rw-r--r--net/base/cookie_monster.h22
-rw-r--r--net/base/cookie_monster_unittest.cc20
-rw-r--r--net/base/net_util.cc73
-rw-r--r--net/base/registry_controlled_domain.cc41
-rw-r--r--net/base/registry_controlled_domain.h32
-rw-r--r--net/base/registry_controlled_domain_unittest.cc148
-rw-r--r--net/net.xcodeproj/project.pbxproj10
8 files changed, 203 insertions, 158 deletions
diff --git a/net/base/cookie_monster.cc b/net/base/cookie_monster.cc
index b8dd8e7..12b1b46d7 100644
--- a/net/base/cookie_monster.cc
+++ b/net/base/cookie_monster.cc
@@ -192,8 +192,13 @@ Time CookieMonster::ParseCookieTime(const std::string& time_string) {
// Numeric field w/ a colon
} else if (token.find(':') != std::string::npos) {
if (!found_time &&
- sscanf_s(token.c_str(), "%2hu:%2hu:%2hu", &exploded.hour,
- &exploded.minute, &exploded.second) == 3) {
+#ifdef COMPILER_MSVC
+ sscanf_s(
+#else
+ sscanf(
+#endif
+ token.c_str(), "%2u:%2u:%2u", &exploded.hour,
+ &exploded.minute, &exploded.second) == 3) {
found_time = true;
} else {
// We should only ever encounter one time-like thing. If we're here,
@@ -334,7 +339,12 @@ static Time CanonExpiration(const CookieMonster::ParsedCookie& pc,
// First, try the Max-Age attribute.
uint64 max_age = 0;
if (pc.HasMaxAge() &&
+#if defined(COMPILER_MSVC)
sscanf_s(pc.MaxAge().c_str(), " %I64u", &max_age) == 1) {
+
+#else
+ sscanf(pc.MaxAge().c_str(), " %llu", &max_age) == 1) {
+#endif
return current + TimeDelta::FromSeconds(max_age);
}
@@ -420,6 +430,7 @@ bool CookieMonster::SetCookieWithCreationTime(const GURL& url,
// We should have only purged at most one matching cookie.
int num_deleted = DeleteEquivalentCookies(cookie_domain, *cc);
+ DCHECK(num_deleted <= 1);
COOKIE_DLOG(INFO) << "SetCookie() cc: " << cc->DebugString();
diff --git a/net/base/cookie_monster.h b/net/base/cookie_monster.h
index 9c1a6f5..80f8b34 100644
--- a/net/base/cookie_monster.h
+++ b/net/base/cookie_monster.h
@@ -29,13 +29,13 @@
// Brought to you by the letter D and the number 2.
-#ifndef NET_BASE_COOKIE_MONSTER_H__
-#define NET_BASE_COOKIE_MONSTER_H__
+#ifndef NET_BASE_COOKIE_MONSTER_H_
+#define NET_BASE_COOKIE_MONSTER_H_
+#include <map>
#include <string>
-#include <vector>
#include <utility>
-#include <map>
+#include <vector>
#include "base/basictypes.h"
#include "base/lock.h"
@@ -199,7 +199,7 @@ class CookieMonster {
// Lock for thread-safety
Lock lock_;
- DISALLOW_EVIL_CONSTRUCTORS(CookieMonster);
+ DISALLOW_COPY_AND_ASSIGN(CookieMonster);
};
class CookieMonster::ParsedCookie {
@@ -208,7 +208,7 @@ class CookieMonster::ParsedCookie {
typedef std::vector<TokenValuePair> PairList;
// The maximum length of a cookie string we will try to parse
- static const int kMaxCookieSize = 4096;
+ static const size_t kMaxCookieSize = 4096;
// The maximum number of Token/Value pairs. Shouldn't have more than 8.
static const int kMaxPairs = 16;
@@ -267,11 +267,11 @@ class CookieMonster::CanonicalCookie {
: name_(name),
value_(value),
path_(path),
- secure_(secure),
- httponly_(httponly),
creation_date_(creation),
+ expiry_date_(expires),
has_expires_(has_expires),
- expiry_date_(expires) {
+ secure_(secure),
+ httponly_(httponly) {
}
// Supports the default copy constructor.
@@ -306,8 +306,8 @@ class CookieMonster::CanonicalCookie {
std::string value_;
std::string path_;
Time creation_date_;
- bool has_expires_;
Time expiry_date_;
+ bool has_expires_;
bool secure_;
bool httponly_;
};
@@ -332,4 +332,4 @@ class CookieMonster::PersistentCookieStore {
} // namespace net
-#endif // NET_BASE_COOKIE_MONSTER_H__
+#endif // NET_BASE_COOKIE_MONSTER_H_
diff --git a/net/base/cookie_monster_unittest.cc b/net/base/cookie_monster_unittest.cc
index 9de1464..47eb90c 100644
--- a/net/base/cookie_monster_unittest.cc
+++ b/net/base/cookie_monster_unittest.cc
@@ -495,12 +495,18 @@ TEST(CookieMonsterTest, HttpOnlyTest) {
url_google, net::CookieMonster::INCLUDE_HTTPONLY), "A=B");
}
+namespace {
+
+struct CookieDateParsingCase {
+ const char* str;
+ const bool valid;
+ const time_t epoch;
+};
+
+} // namespace
+
TEST(CookieMonsterTest, TestCookieDateParsing) {
- const struct {
- const char* str;
- const bool valid;
- const time_t epoch;
- } tests[] = {
+ const CookieDateParsingCase tests[] = {
{ "Sat, 15-Apr-17 21:01:22 GMT", true, 1492290082 },
{ "Thu, 19-Apr-2007 16:00:00 GMT", true, 1176998400 },
{ "Wed, 25 Apr 2007 21:02:13 GMT", true, 1177534933 },
@@ -572,7 +578,7 @@ TEST(CookieMonsterTest, TestCookieDateParsing) {
};
Time parsed_time;
- for (int i = 0; i < arraysize(tests); ++i) {
+ for (size_t i = 0; i < arraysize(tests); ++i) {
parsed_time = net::CookieMonster::ParseCookieTime(tests[i].str);
if (!tests[i].valid) {
EXPECT_FALSE(!parsed_time.is_null()) << tests[i].str;
@@ -783,7 +789,7 @@ TEST(CookieMonsterTest, TestTotalGarbageCollection) {
// Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling.
TEST(CookieMonsterTest, NetUtilCookieTest) {
- const GURL test_url(L"http://mojo.jojo.google.izzle/");
+ const GURL test_url("http://mojo.jojo.google.izzle/");
net::CookieMonster cm;
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index e0cbd04..c2f9c7c 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -451,8 +451,8 @@ UScriptCode NormalizeScript(UScriptCode code) {
}
}
-bool IsIDNComponentInSingleScript(const wchar_t* str, int str_len) {
- UScriptCode first_script;
+bool IsIDNComponentInSingleScript(const char16* str, int str_len) {
+ UScriptCode first_script = USCRIPT_INVALID_CODE;
bool is_first = true;
int i = 0;
@@ -491,7 +491,7 @@ bool IsCompatibleWithASCIILetters(const std::string& lang) {
// Returns true if the given Unicode host component is safe to display to the
// user.
-bool IsIDNComponentSafe(const wchar_t* str,
+bool IsIDNComponentSafe(const char16* str,
int str_len,
const std::wstring& languages) {
// Most common cases (non-IDN) do not reach here so that we don't
@@ -532,14 +532,7 @@ bool IsIDNComponentSafe(const wchar_t* str,
#endif
DCHECK(U_SUCCESS(status));
UnicodeSet component_characters;
-#ifdef WCHAR_T_IS_UTF32
- std::string16 converted_str;
- WideToUTF16(str, str_len, &converted_str);
- component_characters.addAll(UnicodeString(converted_str.c_str(),
- converted_str.length()));
-#else
component_characters.addAll(UnicodeString(str, str_len));
-#endif
if (dangerous_characters.containsSome(component_characters))
return false;
@@ -598,10 +591,10 @@ bool IsIDNComponentSafe(const wchar_t* str,
// Converts one component of a host (between dots) to IDN if safe. The result
// will be APPENDED to the given output string and will be the same as the
// input if it is not IDN or the IDN is unsafe to display.
-void IDNToUnicodeOneComponent(const wchar_t* comp,
+void IDNToUnicodeOneComponent(const char16* comp,
int comp_len,
const std::wstring& languages,
- std::wstring* out) {
+ std::string16* out) {
DCHECK(comp_len >= 0);
if (comp_len == 0)
return;
@@ -612,7 +605,8 @@ void IDNToUnicodeOneComponent(const wchar_t* comp,
size_t host_begin_in_output = out->size();
// Just copy the input if it can't be an IDN component.
- if (comp_len < 4 || wcsncmp(comp, L"xn--", 4)) {
+ if (comp_len < 4 ||
+ comp[0] != 'x' || comp[1] != 'n' || comp[2] != '-' || comp[3] != '-') {
out->resize(host_begin_in_output + comp_len);
for (int i = 0; i < comp_len; i++)
(*out)[host_begin_in_output + i] = comp[i];
@@ -621,23 +615,10 @@ void IDNToUnicodeOneComponent(const wchar_t* comp,
while (true) {
UErrorCode status = U_ZERO_ERROR;
-#if defined(WCHAR_T_IS_UTF32)
- std::string16 comp16;
- WideToUTF16(comp, comp_len, &comp16);
- std::string16 out16;
- WideToUTF16(out->c_str(), out->length(), &out16);
- out16.resize(out16.size() + extra_space);
- int output_chars =
- uidna_IDNToUnicode(comp16.data(), static_cast<int32>(comp16.length()),
- &(out16)[host_begin_in_output], extra_space,
- UIDNA_DEFAULT, NULL, &status);
- *out = UTF16ToWide(out16);
-#else
out->resize(out->size() + extra_space);
int output_chars =
uidna_IDNToUnicode(comp, comp_len, &(*out)[host_begin_in_output],
- extra_space, UIDNA_DEFAULT, NULL, &status);
-#endif
+ extra_space, UIDNA_DEFAULT, NULL, &status);
if (status == U_ZERO_ERROR) {
// Converted successfully.
out->resize(host_begin_in_output + output_chars);
@@ -812,37 +793,53 @@ void IDNToUnicode(const char* host,
const std::wstring& languages,
std::wstring* out) {
// Convert the ASCII input to a wide string for ICU.
- std::wstring wide_input;
- wide_input.reserve(host_len);
+ std::string16 input16;
+ input16.reserve(host_len);
for (int i = 0; i < host_len; i++)
- wide_input.push_back(host[i]);
+ input16.push_back(host[i]);
+
+ std::string16 out16;
+ // The output string is appended to, so convert what's already there if
+ // needed.
+#if defined(WCHAR_T_IS_UTF32)
+ WideToUTF16(out->data(), out->length(), &out16);
+ out->clear(); // for equivalence with the swap below
+#elif defined(WCHAR_T_IS_UTF16)
+ out->swap(out16);
+#endif
// Do each component of the host separately, since we enforce script matching
// on a per-component basis.
size_t cur_begin = 0; // Beginning of the current component (inclusive).
- while (cur_begin < wide_input.size()) {
+ while (cur_begin < input16.size()) {
// Find the next dot or the end of the string.
- size_t next_dot = wide_input.find_first_of('.', cur_begin);
+ size_t next_dot = input16.find_first_of('.', cur_begin);
if (next_dot == std::wstring::npos)
- next_dot = wide_input.size(); // For getting the last component.
+ next_dot = input16.size(); // For getting the last component.
if (next_dot > cur_begin) {
// Add the substring that we just found.
- IDNToUnicodeOneComponent(&wide_input[cur_begin],
+ IDNToUnicodeOneComponent(&input16[cur_begin],
static_cast<int>(next_dot - cur_begin),
languages,
- out);
+ &out16);
}
// Need to add the dot we just found (if we found one). This needs to be
// done before we break out below in case the URL ends in a dot.
- if (next_dot < wide_input.size())
- out->push_back('.');
+ if (next_dot < input16.size())
+ out16.push_back('.');
else
break; // No more components left.
cur_begin = next_dot + 1;
}
+
+#if defined(WCHAR_T_IS_UTF32)
+ UTF16ToWide(out16.data(), out16.length(), out);
+#elif defined(WCHAR_T_IS_UTF16)
+ out->swap(out16);
+#endif
}
std::string CanonicalizeHost(const std::string& host, bool* is_ip_address) {
@@ -872,7 +869,7 @@ std::string CanonicalizeHost(const std::string& host, bool* is_ip_address) {
// Return the host as a string, stripping any unnecessary bits off the ends.
if ((canon_host_component.begin == 0) &&
- (canon_host_component.len == canon_host.length()))
+ (static_cast<size_t>(canon_host_component.len) == canon_host.length()))
return canon_host;
return canon_host.substr(canon_host_component.begin,
canon_host_component.len);
diff --git a/net/base/registry_controlled_domain.cc b/net/base/registry_controlled_domain.cc
index f0aad4c..3f4f024 100644
--- a/net/base/registry_controlled_domain.cc
+++ b/net/base/registry_controlled_domain.cc
@@ -37,16 +37,16 @@
*
* ***** END LICENSE BLOCK ***** */
-#include <windows.h>
+#include "net/base/registry_controlled_domain.h"
#include "base/logging.h"
+#include "base/singleton.h"
#include "base/string_util.h"
#include "googleurl/src/gurl.h"
#include "googleurl/src/url_parse.h"
#include "net/base/net_module.h"
#include "net/base/net_resources.h"
#include "net/base/net_util.h"
-#include "net/base/registry_controlled_domain.h"
namespace net {
@@ -258,23 +258,34 @@ size_t RegistryControlledDomainService::GetRegistryLengthImpl(
return allow_unknown_registries ? (host.length() - curr_start) : 0;
}
-RegistryControlledDomainService* RegistryControlledDomainService::instance_ =
- NULL;
+static RegistryControlledDomainService* test_instance_;
+
+// static
+RegistryControlledDomainService* RegistryControlledDomainService::SetInstance(
+ RegistryControlledDomainService* instance) {
+ RegistryControlledDomainService* old_instance = test_instance_;
+ test_instance_ = instance;
+ return old_instance;
+}
+
+struct RegistryControlledDomainServiceSingletonTraits :
+ public DefaultSingletonTraits<RegistryControlledDomainService> {
+ static RegistryControlledDomainService* New() {
+ RegistryControlledDomainService* instance =
+ new RegistryControlledDomainService();
+ instance->Init();
+ return instance;
+ }
+};
// static
RegistryControlledDomainService* RegistryControlledDomainService::GetInstance()
{
- if (!instance_) {
- RegistryControlledDomainService* s = new RegistryControlledDomainService();
- s->Init();
- // TODO(darin): use fix_wp64.h once it lives in base/
- if (InterlockedCompareExchangePointer(
- reinterpret_cast<PVOID*>(&instance_), s, NULL)) {
- // Oops, another thread initialized instance_ out from under us.
- delete s;
- }
- }
- return instance_;
+ if (test_instance_)
+ return test_instance_;
+
+ return Singleton<RegistryControlledDomainService,
+ RegistryControlledDomainServiceSingletonTraits>::get();
}
// static
diff --git a/net/base/registry_controlled_domain.h b/net/base/registry_controlled_domain.h
index 72d7512..b5ba97f6 100644
--- a/net/base/registry_controlled_domain.h
+++ b/net/base/registry_controlled_domain.h
@@ -107,8 +107,8 @@
GURL to normalize rules, and validating the rules.
*/
-#ifndef NET_BASE_REGISTRY_CONTROLLED_DOMAIN_H__
-#define NET_BASE_REGISTRY_CONTROLLED_DOMAIN_H__
+#ifndef NET_BASE_REGISTRY_CONTROLLED_DOMAIN_H_
+#define NET_BASE_REGISTRY_CONTROLLED_DOMAIN_H_
#include <map>
#include <string>
@@ -119,9 +119,13 @@ class GURL;
namespace net {
+struct RegistryControlledDomainServiceSingletonTraits;
+
// This class is a singleton.
class RegistryControlledDomainService {
public:
+ ~RegistryControlledDomainService() { }
+
// Returns the registered, organization-identifying host and all its registry
// information, but no subdomains, from the given GURL. Returns an empty
// string if the GURL is invalid, has no host (e.g. a file: URL), has multiple
@@ -194,20 +198,23 @@ class RegistryControlledDomainService {
// The entire protected API is only for unit testing. I mean it. Don't make
// me come over there!
RegistryControlledDomainService() { }
- ~RegistryControlledDomainService() { }
- // Clears the static singleton instance. This is used by unit tests to
- // create a new instance for each test, to help ensure test independence.
- static void ResetInstance() {
- delete instance_;
- instance_ = NULL;
- }
+ // Set the RegistryControledDomainService instance to be used internally.
+ // |instance| will supersede the singleton instance normally used. If
+ // |instance| is NULL, normal behavior is restored, and internal operations
+ // will return to using the singleton. This function always returns the
+ // instance set by the most recent call to SetInstance.
+ static RegistryControlledDomainService* SetInstance(
+ RegistryControlledDomainService* instance);
// Sets the domain_data_ of the current instance (creating one, if necessary),
// then parses it.
static void UseDomainData(const std::string& data);
private:
+ // To allow construction of the internal singleton instance.
+ friend struct RegistryControlledDomainServiceSingletonTraits;
+
// Using the StringSegment class, we can compare portions of strings without
// needing to allocate or copy them.
class StringSegment {
@@ -272,9 +279,6 @@ class RegistryControlledDomainService {
// assumed to be syntactically valid.
void ParseDomainData();
- // The class's singleton instance.
- static RegistryControlledDomainService* instance_;
-
// Returns the singleton instance, after attempting to initialize it.
// NOTE that if the effective-TLD data resource can't be found, the instance
// will be initialized and continue operation with an empty domain_map_.
@@ -294,9 +298,9 @@ class RegistryControlledDomainService {
size_t GetRegistryLengthImpl(const std::string& host,
bool allow_unknown_registries);
- DISALLOW_EVIL_CONSTRUCTORS(RegistryControlledDomainService);
+ DISALLOW_COPY_AND_ASSIGN(RegistryControlledDomainService);
};
} // namespace net
-#endif // NET_BASE_REGISTRY_CONTROLLED_DOMAIN_H__
+#endif // NET_BASE_REGISTRY_CONTROLLED_DOMAIN_H_
diff --git a/net/base/registry_controlled_domain_unittest.cc b/net/base/registry_controlled_domain_unittest.cc
index 590f17b..05bfea3 100644
--- a/net/base/registry_controlled_domain_unittest.cc
+++ b/net/base/registry_controlled_domain_unittest.cc
@@ -33,33 +33,36 @@
namespace {
-class TestRegistryControlledDomainService;
-static TestRegistryControlledDomainService* test_instance_;
-
class TestRegistryControlledDomainService :
public net::RegistryControlledDomainService {
public:
-
- // Deletes the instance so a new one will be created.
- static void ResetInstance() {
- net::RegistryControlledDomainService::ResetInstance();
- }
-
// Sets and parses the given data.
static void UseDomainData(const std::string& data) {
net::RegistryControlledDomainService::UseDomainData(data);
}
- private:
- TestRegistryControlledDomainService::TestRegistryControlledDomainService() { }
- TestRegistryControlledDomainService::~TestRegistryControlledDomainService() {
+ // Creates a new dedicated instance to be used for testing, deleting any
+ // previously-set one.
+ static void UseDedicatedInstance() {
+ delete static_cast<TestRegistryControlledDomainService*>(
+ SetInstance(new TestRegistryControlledDomainService()));
+ }
+
+ // Restores RegistryControlledDomainService to using its default instance,
+ // deleting any previously-set test instance.
+ static void UseDefaultInstance() {
+ delete static_cast<TestRegistryControlledDomainService*>(SetInstance(NULL));
}
};
class RegistryControlledDomainTest : public testing::Test {
protected:
virtual void SetUp() {
- TestRegistryControlledDomainService::ResetInstance();
+ TestRegistryControlledDomainService::UseDedicatedInstance();
+ }
+
+ virtual void TearDown() {
+ TestRegistryControlledDomainService::UseDefaultInstance();
}
};
@@ -186,73 +189,74 @@ TEST_F(RegistryControlledDomainTest, TestGetRegistryLength) {
SetTestData(kTestData);
// Test GURL version of GetRegistryLength().
- EXPECT_EQ(2, GetRegistryLengthFromURL("http://a.baz.jp/file.html", false));
+ EXPECT_EQ(2U, GetRegistryLengthFromURL("http://a.baz.jp/file.html", false));
// 1
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://a.baz.jp./file.html", false));
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://a.baz.jp./file.html", false));
// 1
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://ac.jp", false)); // 2
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://a.bar.jp", false)); // 3
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://bar.jp", false)); // 3
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://baz.bar.jp", false)); // 3 4
- EXPECT_EQ(12, GetRegistryLengthFromURL("http://a.b.baz.bar.jp", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://ac.jp", false)); // 2
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://a.bar.jp", false)); // 3
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://bar.jp", false)); // 3
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.bar.jp", false)); // 3 4
+ EXPECT_EQ(12U, GetRegistryLengthFromURL("http://a.b.baz.bar.jp", false));
// 4
- EXPECT_EQ(6, GetRegistryLengthFromURL("http://foo.bar.jp", false)); // 3 5 6
- EXPECT_EQ(6, GetRegistryLengthFromURL("http://baz.pref.bar.jp", false));
+ EXPECT_EQ(6U, GetRegistryLengthFromURL("http://foo.bar.jp", false)); // 3 5 6
+ EXPECT_EQ(6U, GetRegistryLengthFromURL("http://baz.pref.bar.jp", false));
// 7
- EXPECT_EQ(11, GetRegistryLengthFromURL("http://a.b.bar.baz.com", false));
+ EXPECT_EQ(11U, GetRegistryLengthFromURL("http://a.b.bar.baz.com", false));
// 8
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://a.d.c", false)); // 9
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://.a.d.c", false)); // 9
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://..a.d.c", false)); // 9
- EXPECT_EQ(1, GetRegistryLengthFromURL("http://a.b.c", false)); // 9 10
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://baz.com", false)); // none
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://baz.com.", false)); // none
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://baz.com", true)); // none
- EXPECT_EQ(4, GetRegistryLengthFromURL("http://baz.com.", true)); // none
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://a.d.c", false)); // 9
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://.a.d.c", false)); // 9
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://..a.d.c", false)); // 9
+ EXPECT_EQ(1U, GetRegistryLengthFromURL("http://a.b.c", false)); // 9 10
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.com", false)); // none
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://baz.com.", false)); // none
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://baz.com", true)); // none
+ EXPECT_EQ(4U, GetRegistryLengthFromURL("http://baz.com.", true)); // none
EXPECT_EQ(std::string::npos, GetRegistryLengthFromURL("", false));
EXPECT_EQ(std::string::npos, GetRegistryLengthFromURL("http://", false));
EXPECT_EQ(std::string::npos,
GetRegistryLengthFromURL("file:///C:/file.html", false));
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://foo.com..", false));
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://...", false));
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://192.168.0.1", false));
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://localhost", false));
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://localhost", true));
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://localhost.", false));
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://localhost.", true));
- EXPECT_EQ(0, GetRegistryLengthFromURL("http:////Comment", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://foo.com..", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://...", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://192.168.0.1", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost", true));
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost.", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://localhost.", true));
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http:////Comment", false));
// Test std::wstring version of GetRegistryLength(). Uses the same
// underpinnings as the GURL version, so this is really more of a check of
// CanonicalizeHost().
- EXPECT_EQ(2, GetRegistryLengthFromHost(L"a.baz.jp", false)); // 1
- EXPECT_EQ(3, GetRegistryLengthFromHost(L"a.baz.jp.", false)); // 1
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"ac.jp", false)); // 2
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"a.bar.jp", false)); // 3
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"bar.jp", false)); // 3
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"baz.bar.jp", false)); // 3 4
- EXPECT_EQ(12, GetRegistryLengthFromHost(L"a.b.baz.bar.jp", false)); // 4
- EXPECT_EQ(6, GetRegistryLengthFromHost(L"foo.bar.jp", false)); // 3 5 6
- EXPECT_EQ(6, GetRegistryLengthFromHost(L"baz.pref.bar.jp", false)); // 7
- EXPECT_EQ(11, GetRegistryLengthFromHost(L"a.b.bar.baz.com", false)); // 8
- EXPECT_EQ(3, GetRegistryLengthFromHost(L"a.d.c", false)); // 9
- EXPECT_EQ(3, GetRegistryLengthFromHost(L".a.d.c", false)); // 9
- EXPECT_EQ(3, GetRegistryLengthFromHost(L"..a.d.c", false)); // 9
- EXPECT_EQ(1, GetRegistryLengthFromHost(L"a.b.c", false)); // 9 10
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"baz.com", false)); // none
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"baz.com.", false)); // none
- EXPECT_EQ(3, GetRegistryLengthFromHost(L"baz.com", true)); // none
- EXPECT_EQ(4, GetRegistryLengthFromHost(L"baz.com.", true)); // none
+ EXPECT_EQ(2U, GetRegistryLengthFromHost(L"a.baz.jp", false)); // 1
+ EXPECT_EQ(3U, GetRegistryLengthFromHost(L"a.baz.jp.", false)); // 1
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"ac.jp", false)); // 2
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"a.bar.jp", false)); // 3
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"bar.jp", false)); // 3
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"baz.bar.jp", false)); // 3 4
+ EXPECT_EQ(12U, GetRegistryLengthFromHost(L"a.b.baz.bar.jp", false)); // 4
+ EXPECT_EQ(6U, GetRegistryLengthFromHost(L"foo.bar.jp", false)); // 3 5 6
+ EXPECT_EQ(6U, GetRegistryLengthFromHost(L"baz.pref.bar.jp", false)); // 7
+ EXPECT_EQ(11U, GetRegistryLengthFromHost(L"a.b.bar.baz.com", false));
+ // 8
+ EXPECT_EQ(3U, GetRegistryLengthFromHost(L"a.d.c", false)); // 9
+ EXPECT_EQ(3U, GetRegistryLengthFromHost(L".a.d.c", false)); // 9
+ EXPECT_EQ(3U, GetRegistryLengthFromHost(L"..a.d.c", false)); // 9
+ EXPECT_EQ(1U, GetRegistryLengthFromHost(L"a.b.c", false)); // 9 10
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"baz.com", false)); // none
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"baz.com.", false)); // none
+ EXPECT_EQ(3U, GetRegistryLengthFromHost(L"baz.com", true)); // none
+ EXPECT_EQ(4U, GetRegistryLengthFromHost(L"baz.com.", true)); // none
EXPECT_EQ(std::string::npos, GetRegistryLengthFromHost(L"", false));
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"foo.com..", false));
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"..", false));
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"192.168.0.1", false));
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"localhost", false));
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"localhost", true));
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"localhost.", false));
- EXPECT_EQ(0, GetRegistryLengthFromHost(L"localhost.", true));
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"foo.com..", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"..", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"192.168.0.1", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"localhost", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"localhost", true));
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"localhost.", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromHost(L"localhost.", true));
}
TEST_F(RegistryControlledDomainTest, TestSameDomainOrHost) {
@@ -285,12 +289,14 @@ TEST_F(RegistryControlledDomainTest, TestSameDomainOrHost) {
}
TEST_F(RegistryControlledDomainTest, TestDefaultData) {
+ TestRegistryControlledDomainService::UseDefaultInstance();
+
// Note that no data is set: we're using the default rules.
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://google.com", false));
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://stanford.edu", false));
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://ustreas.gov", false));
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://icann.net", false));
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://ferretcentral.org", false));
- EXPECT_EQ(0, GetRegistryLengthFromURL("http://nowhere.foo", false));
- EXPECT_EQ(3, GetRegistryLengthFromURL("http://nowhere.foo", true));
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://google.com", false));
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://stanford.edu", false));
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://ustreas.gov", false));
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://icann.net", false));
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://ferretcentral.org", false));
+ EXPECT_EQ(0U, GetRegistryLengthFromURL("http://nowhere.foo", false));
+ EXPECT_EQ(3U, GetRegistryLengthFromURL("http://nowhere.foo", true));
}
diff --git a/net/net.xcodeproj/project.pbxproj b/net/net.xcodeproj/project.pbxproj
index 23d3c3c..384bf39 100644
--- a/net/net.xcodeproj/project.pbxproj
+++ b/net/net.xcodeproj/project.pbxproj
@@ -63,6 +63,11 @@
7B85044A0E5B2E9600730B43 /* url_request_error_job.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED33B20E5A198600A747DB /* url_request_error_job.cc */; };
7B8504530E5B2E9600730B43 /* url_request_job_metrics.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED33A00E5A198600A747DB /* url_request_job_metrics.cc */; };
7B8504540E5B2E9600730B43 /* url_request_job_tracker.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED339E0E5A198600A747DB /* url_request_job_tracker.cc */; };
+ 7B8B5A430E5CD1FD002F9A97 /* cookie_monster.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32690E5A181C00A747DB /* cookie_monster.cc */; };
+ 7B8B5AE30E5CDC00002F9A97 /* net_util.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32A10E5A181C00A747DB /* net_util.cc */; };
+ 7B8B5B530E5CEAC7002F9A97 /* cookie_monster_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32660E5A181C00A747DB /* cookie_monster_unittest.cc */; };
+ 7B8B5B560E5CEADE002F9A97 /* registry_controlled_domain.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED329B0E5A181C00A747DB /* registry_controlled_domain.cc */; };
+ 7B8B5B9E0E5D188E002F9A97 /* registry_controlled_domain_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32990E5A181C00A747DB /* registry_controlled_domain_unittest.cc */; };
7BA0151F0E5A1B9200044150 /* gzip_filter_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32B80E5A181C00A747DB /* gzip_filter_unittest.cc */; };
7BA015210E5A1B9800044150 /* bzip2_filter_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32730E5A181C00A747DB /* bzip2_filter_unittest.cc */; };
7BA0152E0E5A1BF400044150 /* auth_cache.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED327C0E5A181C00A747DB /* auth_cache.cc */; };
@@ -1176,6 +1181,7 @@
821F207B0E5CD342003C7E38 /* cert_status_cache.cc in Sources */,
7B8504080E5B2DD800730B43 /* client_socket_handle.cc in Sources */,
7B8504090E5B2DD800730B43 /* client_socket_pool.cc in Sources */,
+ 7B8B5A430E5CD1FD002F9A97 /* cookie_monster.cc in Sources */,
7B85040C0E5B2DD800730B43 /* cookie_policy.cc in Sources */,
7B85040D0E5B2DD800730B43 /* data_url.cc in Sources */,
7B8504100E5B2DF000730B43 /* entry_impl.cc in Sources */,
@@ -1201,9 +1207,11 @@
048268070E5B3B1000A30786 /* mime_util.cc in Sources */,
7BA015550E5A1C1000044150 /* net_errors.cc in Sources */,
7B8504390E5B2E5700730B43 /* net_module.cc in Sources */,
+ 7B8B5AE30E5CDC00002F9A97 /* net_util.cc in Sources */,
7B85043B0E5B2E6400730B43 /* os_file_posix.cc in Sources */,
7B85043C0E5B2E6400730B43 /* platform_mime_util_mac.mm in Sources */,
7B85043D0E5B2E6400730B43 /* rankings.cc in Sources */,
+ 7B8B5B560E5CEADE002F9A97 /* registry_controlled_domain.cc in Sources */,
7B8504410E5B2E9600730B43 /* stats.cc in Sources */,
7B8504450E5B2E9600730B43 /* trace.cc in Sources */,
7B85044A0E5B2E9600730B43 /* url_request_error_job.cc in Sources */,
@@ -1222,6 +1230,7 @@
7B8502120E5A37A800730B43 /* base64_unittest.cc in Sources */,
7BA015210E5A1B9800044150 /* bzip2_filter_unittest.cc in Sources */,
7B4DF64A0E5B98DF004D7619 /* client_socket_pool_unittest.cc in Sources */,
+ 7B8B5B530E5CEAC7002F9A97 /* cookie_monster_unittest.cc in Sources */,
7B4DF6A90E5B98E7004D7619 /* data_url_unittest.cc in Sources */,
7B4DF6B10E5B98ED004D7619 /* escape_unittest.cc in Sources */,
7BA0151F0E5A1B9200044150 /* gzip_filter_unittest.cc in Sources */,
@@ -1230,6 +1239,7 @@
821F21130E5CD662003C7E38 /* http_vary_data_unittest.cc in Sources */,
7B4DF9AC0E5C906A004D7619 /* mime_sniffer_unittest.cc in Sources */,
048268090E5B3B4800A30786 /* mime_util_unittest.cc in Sources */,
+ 7B8B5B9E0E5D188E002F9A97 /* registry_controlled_domain_unittest.cc in Sources */,
E4AFA6430E5241B400201347 /* run_all_unittests.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;