Refactor chrome.cookies API to use JSON schema compiler.

BUG=121174


Review URL: https://chromiumcodereview.appspot.com/10702088

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147954 0039d316-1c4b-4281-b951-d872f2087c98
parent 145219f7
......@@ -11,10 +11,12 @@
#include <string>
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/time.h"
#include "chrome/browser/extensions/extension_function.h"
#include "chrome/browser/net/chrome_cookie_notification_details.h"
#include "chrome/common/extensions/api/cookies.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "googleurl/src/gurl.h"
......@@ -75,24 +77,19 @@ class CookiesFunction : public AsyncExtensionFunction {
protected:
virtual ~CookiesFunction() {}
// Looks for a 'url' value in the given details dictionary and constructs a
// GURL from it. Returns false and assigns the internal error_ value if the
// URL is invalid or isn't found in the dictionary. If check_host_permissions
// is true, the URL is also checked against the extension's host permissions,
// and if there is no permission for the URL, this function returns false.
bool ParseUrl(const base::DictionaryValue* details, GURL* url,
// Constructs a GURL from the given url string. Returns false and assigns the
// internal error_ value if the URL is invalid. If |check_host_permissions| is
// true, the URL is also checked against the extension's host permissions, and
// if there is no permission for the URL, this function returns false.
bool ParseUrl(const std::string& url_string, GURL* url,
bool check_host_permissions);
// Checks the given details dictionary for a 'storeId' value, and retrieves
// the cookie store context and the store ID associated with it. If the
// 'storeId' value isn't found in the dictionary, the current execution
// context's cookie store context is retrieved. Returns false on error and
// assigns the internal error_ value if that occurs.
// At least one of the output parameters store and store_id should be
// non-NULL.
bool ParseStoreContext(const base::DictionaryValue* details,
net::URLRequestContextGetter** context,
std::string* store_id);
// Gets the store identified by |store_id| and returns it in |context|.
// If |store_id| contains an empty string, retrieves the current execution
// context's store. In this case, |store_id| is populated with the found
// store, and |context| can be NULL if the caller only wants |store_id|.
bool ParseStoreContext(std::string* store_id,
net::URLRequestContextGetter** context);
};
// Implements the cookies.get() extension function.
......@@ -113,10 +110,9 @@ class GetCookieFunction : public CookiesFunction {
void RespondOnUIThread();
void GetCookieCallback(const net::CookieList& cookie_list);
std::string name_;
GURL url_;
std::string store_id_;
scoped_refptr<net::URLRequestContextGetter> store_context_;
scoped_ptr<extensions::api::cookies::Get::Params> parsed_args_;
};
// Implements the cookies.getAll() extension function.
......@@ -137,10 +133,9 @@ class GetAllCookiesFunction : public CookiesFunction {
void RespondOnUIThread();
void GetAllCookiesCallback(const net::CookieList& cookie_list);
base::DictionaryValue* details_;
GURL url_;
std::string store_id_;
scoped_refptr<net::URLRequestContextGetter> store_context_;
scoped_ptr<extensions::api::cookies::GetAll::Params> parsed_args_;
};
// Implements the cookies.set() extension function.
......@@ -161,16 +156,9 @@ class SetCookieFunction : public CookiesFunction {
void PullCookieCallback(const net::CookieList& cookie_list);
GURL url_;
std::string name_;
std::string value_;
std::string domain_;
std::string path_;
bool secure_;
bool http_only_;
base::Time expiration_time_;
bool success_;
std::string store_id_;
scoped_refptr<net::URLRequestContextGetter> store_context_;
scoped_ptr<extensions::api::cookies::Set::Params> parsed_args_;
};
// Implements the cookies.remove() extension function.
......@@ -192,9 +180,8 @@ class RemoveCookieFunction : public CookiesFunction {
void RemoveCookieCallback();
GURL url_;
std::string name_;
std::string store_id_;
scoped_refptr<net::URLRequestContextGetter> store_context_;
scoped_ptr<extensions::api::cookies::Remove::Params> parsed_args_;
};
// Implements the cookies.getAllCookieStores() extension function.
......
......@@ -11,19 +11,9 @@ namespace cookies_api_constants {
const char kCauseKey[] = "cause";
const char kCookieKey[] = "cookie";
const char kDomainKey[] = "domain";
const char kExpirationDateKey[] = "expirationDate";
const char kHostOnlyKey[] = "hostOnly";
const char kHttpOnlyKey[] = "httpOnly";
const char kIdKey[] = "id";
const char kNameKey[] = "name";
const char kPathKey[] = "path";
const char kRemovedKey[] = "removed";
const char kSecureKey[] = "secure";
const char kSessionKey[] = "session";
const char kStoreIdKey[] = "storeId";
const char kTabIdsKey[] = "tabIds";
const char kUrlKey[] = "url";
const char kValueKey[] = "value";
// Cause Constants
extern const char kEvictedChangeCause[] = "evicted";
......
......@@ -14,19 +14,9 @@ namespace cookies_api_constants {
extern const char kCauseKey[];
extern const char kCookieKey[];
extern const char kDomainKey[];
extern const char kExpirationDateKey[];
extern const char kHostOnlyKey[];
extern const char kHttpOnlyKey[];
extern const char kIdKey[];
extern const char kNameKey[];
extern const char kPathKey[];
extern const char kRemovedKey[];
extern const char kSecureKey[];
extern const char kSessionKey[];
extern const char kStoreIdKey[];
extern const char kTabIdsKey[];
extern const char kUrlKey[];
extern const char kValueKey[];
// Cause Constants
extern const char kEvictedChangeCause[];
......
......@@ -6,7 +6,11 @@
#include "chrome/browser/extensions/api/cookies/cookies_helpers.h"
#include <vector>
#include "base/logging.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
......@@ -16,6 +20,7 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/extensions/api/cookies.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/web_contents.h"
......@@ -23,6 +28,11 @@
#include "net/cookies/canonical_cookie.h"
#include "net/cookies/cookie_util.h"
using extensions::api::cookies::Cookie;
using extensions::api::cookies::CookieStore;
namespace GetAll = extensions::api::cookies::GetAll;
namespace extensions {
namespace keys = cookies_api_constants;
......@@ -52,42 +62,45 @@ const char* GetStoreIdFromProfile(Profile* profile) {
kOffTheRecordProfileStoreId : kOriginalProfileStoreId;
}
DictionaryValue* CreateCookieValue(const net::CanonicalCookie& cookie,
const std::string& store_id) {
DictionaryValue* result = new DictionaryValue();
// A cookie is a raw byte sequence. By explicitly parsing it as UTF8, we
// apply error correction, so the string can be safely passed to the
// renderer.
result->SetString(keys::kNameKey, UTF8ToUTF16(cookie.Name()));
result->SetString(keys::kValueKey, UTF8ToUTF16(cookie.Value()));
result->SetString(keys::kDomainKey, cookie.Domain());
result->SetBoolean(keys::kHostOnlyKey,
net::cookie_util::DomainIsHostOnly(cookie.Domain()));
scoped_ptr<Cookie> CreateCookie(
const net::CanonicalCookie& canonical_cookie,
const std::string& store_id) {
scoped_ptr<Cookie> cookie(new Cookie());
// A cookie is a raw byte sequence. By explicitly parsing it as UTF-8, we
// apply error correction, so the string can be safely passed to the renderer.
cookie->name = UTF16ToUTF8(UTF8ToUTF16(canonical_cookie.Name()));
cookie->value = UTF16ToUTF8(UTF8ToUTF16(canonical_cookie.Value()));
cookie->domain = canonical_cookie.Domain();
cookie->host_only = net::cookie_util::DomainIsHostOnly(
canonical_cookie.Domain());
// A non-UTF8 path is invalid, so we just replace it with an empty string.
result->SetString(keys::kPathKey,
IsStringUTF8(cookie.Path()) ? cookie.Path() : "");
result->SetBoolean(keys::kSecureKey, cookie.IsSecure());
result->SetBoolean(keys::kHttpOnlyKey, cookie.IsHttpOnly());
result->SetBoolean(keys::kSessionKey, !cookie.IsPersistent());
if (cookie.IsPersistent()) {
result->SetDouble(keys::kExpirationDateKey,
cookie.ExpiryDate().ToDoubleT());
cookie->path = IsStringUTF8(canonical_cookie.Path()) ?
canonical_cookie.Path() : "";
cookie->secure = canonical_cookie.IsSecure();
cookie->http_only = canonical_cookie.IsHttpOnly();
cookie->session = !canonical_cookie.IsPersistent();
if (canonical_cookie.IsPersistent()) {
cookie->expiration_date.reset(
new double(canonical_cookie.ExpiryDate().ToDoubleT()));
}
result->SetString(keys::kStoreIdKey, store_id);
cookie->store_id = store_id;
return result;
return cookie.Pass();
}
DictionaryValue* CreateCookieStoreValue(Profile* profile,
ListValue* tab_ids) {
scoped_ptr<CookieStore> CreateCookieStore(Profile* profile,
ListValue* tab_ids) {
DCHECK(profile);
DCHECK(tab_ids);
DictionaryValue* result = new DictionaryValue();
result->SetString(keys::kIdKey, GetStoreIdFromProfile(profile));
result->Set(keys::kTabIdsKey, tab_ids);
return result;
DictionaryValue dict;
dict.SetString(keys::kIdKey, GetStoreIdFromProfile(profile));
dict.Set(keys::kTabIdsKey, tab_ids);
CookieStore* cookie_store = new CookieStore();
bool rv = CookieStore::Populate(dict, cookie_store);
CHECK(rv);
return scoped_ptr<CookieStore>(cookie_store);
}
void GetCookieListFromStore(
......@@ -112,12 +125,11 @@ GURL GetURLFromCanonicalCookie(const net::CanonicalCookie& cookie) {
return GURL(scheme + content::kStandardSchemeSeparator + host + "/");
}
void AppendMatchingCookiesToList(
const net::CookieList& all_cookies,
const std::string& store_id,
const GURL& url, const DictionaryValue* details,
const Extension* extension,
ListValue* match_list) {
void AppendMatchingCookiesToVector(const net::CookieList& all_cookies,
const GURL& url,
const GetAll::Params::Details* details,
const Extension* extension,
LinkedCookieVec* match_vector) {
net::CookieList::const_iterator it;
for (it = all_cookies.begin(); it != all_cookies.end(); ++it) {
// Ignore any cookie whose domain doesn't match the extension's
......@@ -127,8 +139,10 @@ void AppendMatchingCookiesToList(
continue;
// Filter the cookie using the match filter.
cookies_helpers::MatchFilter filter(details);
if (filter.MatchesCookie(*it))
match_list->Append(CreateCookieValue(*it, store_id));
if (filter.MatchesCookie(*it)) {
match_vector->push_back(make_linked_ptr(
CreateCookie(*it, *details->store_id).release()));
}
}
}
......@@ -143,45 +157,38 @@ void AppendToTabIdList(Browser* browser, ListValue* tab_ids) {
}
}
MatchFilter::MatchFilter(const DictionaryValue* details)
MatchFilter::MatchFilter(const GetAll::Params::Details* details)
: details_(details) {
DCHECK(details_);
}
bool MatchFilter::MatchesCookie(const net::CanonicalCookie& cookie) {
return MatchesString(keys::kNameKey, cookie.Name()) &&
MatchesDomain(cookie.Domain()) &&
MatchesString(keys::kPathKey, cookie.Path()) &&
MatchesBoolean(keys::kSecureKey, cookie.IsSecure()) &&
MatchesBoolean(keys::kSessionKey, !cookie.IsPersistent());
}
bool MatchFilter::MatchesCookie(
const net::CanonicalCookie& cookie) {
if (details_->name.get() && *details_->name != cookie.Name())
return false;
bool MatchFilter::MatchesString(const char* key, const std::string& value) {
if (!details_->HasKey(key))
return true;
std::string filter_value;
return (details_->GetString(key, &filter_value) &&
value == filter_value);
}
if (!MatchesDomain(cookie.Domain()))
return false;
bool MatchFilter::MatchesBoolean(const char* key, bool value) {
if (!details_->HasKey(key))
return true;
bool filter_value = false;
return (details_->GetBoolean(key, &filter_value) &&
value == filter_value);
if (details_->path.get() && *details_->path != cookie.Path())
return false;
if (details_->secure.get() && *details_->secure != cookie.IsSecure())
return false;
if (details_->session.get() && *details_->session != !cookie.IsPersistent())
return false;
return true;
}
bool MatchFilter::MatchesDomain(const std::string& domain) {
if (!details_->HasKey(keys::kDomainKey))
if (!details_->domain.get())
return true;
std::string filter_value;
if (!details_->GetString(keys::kDomainKey, &filter_value))
return false;
// Add a leading '.' character to the filter domain if it doesn't exist.
if (net::cookie_util::DomainIsHostOnly(filter_value))
filter_value.insert(0, ".");
if (net::cookie_util::DomainIsHostOnly(*details_->domain))
details_->domain->insert(0, ".");
std::string sub_domain(domain);
// Strip any leading '.' character from the input cookie domain.
......@@ -190,8 +197,8 @@ bool MatchFilter::MatchesDomain(const std::string& domain) {
// Now check whether the domain argument is a subdomain of the filter domain.
for (sub_domain.insert(0, ".");
sub_domain.length() >= filter_value.length();) {
if (sub_domain == filter_value)
sub_domain.length() >= details_->domain->length();) {
if (sub_domain == *details_->domain)
return true;
const size_t next_dot = sub_domain.find('.', 1); // Skip over leading dot.
sub_domain.erase(0, next_dot);
......
......@@ -11,8 +11,13 @@
#define CHROME_BROWSER_EXTENSIONS_API_COOKIES_COOKIES_HELPERS_H_
#include <string>
#include <vector>
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/common/extensions/api/cookies.h"
#include "net/cookies/cookie_monster.h"
#include "net/cookies/canonical_cookie.h"
class Browser;
class Profile;
......@@ -32,6 +37,9 @@ class Extension;
namespace cookies_helpers {
typedef std::vector<linked_ptr<extensions::api::cookies::Cookie> >
LinkedCookieVec;
// Returns either the original profile or the incognito profile, based on the
// given store ID. Returns NULL if the profile doesn't exist or is not allowed
// (e.g. if incognito mode is not enabled for the extension).
......@@ -42,17 +50,17 @@ Profile* ChooseProfileFromStoreId(const std::string& store_id,
// Returns the store ID for a particular user profile.
const char* GetStoreIdFromProfile(Profile* profile);
// Constructs a Cookie object as defined by the cookies API. This function
// allocates a new DictionaryValue object; the caller is responsible for
// freeing it.
base::DictionaryValue* CreateCookieValue(const net::CanonicalCookie& cookie,
const std::string& store_id);
// Allocates and construct a new Cookie object representing a cookie as defined
// by the cookies API.
scoped_ptr<extensions::api::cookies::Cookie> CreateCookie(
const net::CanonicalCookie& cookie,
const std::string& store_id);
// Constructs a CookieStore object as defined by the cookies API. This function
// allocates a new DictionaryValue object; the caller is responsible for
// freeing it.
base::DictionaryValue* CreateCookieStoreValue(Profile* profile,
base::ListValue* tab_ids);
// Allocates and constructs a new CookieStore object as defined by the cookies
// API.
scoped_ptr<extensions::api::cookies::CookieStore> CreateCookieStore(
Profile* profile,
base::ListValue* tab_ids);
// Retrieves all cookies from the given cookie store corresponding to the given
// URL. If the URL is empty, all cookies in the cookie store are retrieved.
......@@ -65,17 +73,16 @@ void GetCookieListFromStore(
// a cookie against the extension's host permissions. The Secure
// property of the cookie defines the URL scheme, and the cookie's
// domain becomes the URL host.
GURL GetURLFromCanonicalCookie(const net::CanonicalCookie& cookie);
GURL GetURLFromCanonicalCookie(
const net::CanonicalCookie& cookie);
// Looks through all cookies in the given cookie store, and appends to the
// match list all the cookies that both match the given URL and cookie details
// match vector all the cookies that both match the given URL and cookie details
// and are allowed by extension host permissions.
void AppendMatchingCookiesToList(
const net::CookieList& all_cookies,
const std::string& store_id,
const GURL& url, const base::DictionaryValue* details,
const Extension* extension,
base::ListValue* match_list);
void AppendMatchingCookiesToVector(
const net::CookieList& all_cookies, const GURL& url,
const extensions::api::cookies::GetAll::Params::Details* details,
const Extension* extension, LinkedCookieVec* match_vector);
// Appends the IDs of all tabs belonging to the given browser to the
// given list.
......@@ -90,25 +97,16 @@ void AppendToTabIdList(Browser* browser, base::ListValue* tab_ids);
class MatchFilter {
public:
// Takes the details dictionary argument given by the user as input.
// This class does not take ownership of the lifetime of the DictionaryValue
// This class does not take ownership of the lifetime of the Details
// object.
explicit MatchFilter(const base::DictionaryValue* details);
explicit MatchFilter(
const extensions::api::cookies::GetAll::Params::Details* details);
// Returns true if the given cookie matches the properties in the match
// filter.
bool MatchesCookie(const net::CanonicalCookie& cookie);
private:
// Returns true if the details dictionary contains a string with the given
// key and value. Also returns true if the dictionary doesn't contain the
// given key at all (trival match).
bool MatchesString(const char* key, const std::string& value);
// Returns true if the details dictionary contains a boolean with the given
// key and value. Also returns true if the dictionary doesn't contain the
// given key at all (trival match).
bool MatchesBoolean(const char* key, bool value);
// Returns true if the given cookie domain string matches the filter's
// domain. Any cookie domain which is equal to or is a subdomain of the
// filter's domain will be matched; leading '.' characters indicating
......@@ -118,7 +116,7 @@ class MatchFilter {
// 'foo.bar.com', '.foo.bar.com', and 'baz.foo.bar.com'.
bool MatchesDomain(const std::string& domain);
const base::DictionaryValue* details_;
const extensions::api::cookies::GetAll::Params::Details* details_;
};
} // namespace cookies_helpers
......
......@@ -10,10 +10,16 @@
#include "base/values.h"
#include "chrome/browser/extensions/api/cookies/cookies_api_constants.h"
#include "chrome/browser/extensions/api/cookies/cookies_helpers.h"
#include "chrome/common/extensions/api/cookies.h"
#include "chrome/test/base/testing_profile.h"
#include "googleurl/src/gurl.h"
#include "net/cookies/canonical_cookie.h"
using extensions::api::cookies::Cookie;
using extensions::api::cookies::CookieStore;
namespace GetAll = extensions::api::cookies::GetAll;
namespace extensions {
namespace keys = cookies_api_constants;
......@@ -105,63 +111,44 @@ TEST_F(ExtensionCookiesTest, StoreIdProfileConversion) {
}
TEST_F(ExtensionCookiesTest, ExtensionTypeCreation) {
std::string string_value;
bool boolean_value;
double double_value;
Value* value;
net::CanonicalCookie cookie1(
net::CanonicalCookie canonical_cookie1(
GURL(), "ABC", "DEF", "www.foobar.com", "/",
std::string(), std::string(),
base::Time(), base::Time(), base::Time(),
false, false);
scoped_ptr<DictionaryValue> cookie_value1(
cookies_helpers::CreateCookieValue(
cookie1, "some cookie store"));
EXPECT_TRUE(cookie_value1->GetString(keys::kNameKey, &string_value));
EXPECT_EQ("ABC", string_value);
EXPECT_TRUE(cookie_value1->GetString(keys::kValueKey, &string_value));
EXPECT_EQ("DEF", string_value);
EXPECT_TRUE(cookie_value1->GetString(keys::kDomainKey, &string_value));
EXPECT_EQ("www.foobar.com", string_value);
EXPECT_TRUE(cookie_value1->GetBoolean(keys::kHostOnlyKey, &boolean_value));
EXPECT_TRUE(boolean_value);
EXPECT_TRUE(cookie_value1->GetString(keys::kPathKey, &string_value));
EXPECT_EQ("/", string_value);
EXPECT_TRUE(cookie_value1->GetBoolean(keys::kSecureKey, &boolean_value));
EXPECT_FALSE(boolean_value);
EXPECT_TRUE(cookie_value1->GetBoolean(keys::kHttpOnlyKey, &boolean_value));
EXPECT_FALSE(boolean_value);
EXPECT_TRUE(cookie_value1->GetBoolean(keys::kSessionKey, &boolean_value));
EXPECT_TRUE(boolean_value);
EXPECT_FALSE(
cookie_value1->GetDouble(keys::kExpirationDateKey, &double_value));
EXPECT_TRUE(cookie_value1->GetString(keys::kStoreIdKey, &string_value));
EXPECT_EQ("some cookie store", string_value);
net::CanonicalCookie cookie2(
scoped_ptr<Cookie> cookie1(
cookies_helpers::CreateCookie(
canonical_cookie1, "some cookie store"));
EXPECT_EQ("ABC", cookie1->name);
EXPECT_EQ("DEF", cookie1->value);
EXPECT_EQ("www.foobar.com", cookie1->domain);
EXPECT_TRUE(cookie1->host_only);
EXPECT_EQ("/", cookie1->path);
EXPECT_FALSE(cookie1->secure);
EXPECT_FALSE(cookie1->http_only);
EXPECT_TRUE(cookie1->session);
EXPECT_FALSE(cookie1->expiration_date.get());
EXPECT_EQ("some cookie store", cookie1->store_id);
net::CanonicalCookie canonical_cookie2(
GURL(), "ABC", "DEF", ".foobar.com", "/", std::string(), std::string(),
base::Time(), base::Time::FromDoubleT(10000), base::Time(),
false, false);
scoped_ptr<DictionaryValue> cookie_value2(
cookies_helpers::CreateCookieValue(
cookie2, "some cookie store"));
EXPECT_TRUE(cookie_value2->GetBoolean(keys::kHostOnlyKey, &boolean_value));
EXPECT_FALSE(boolean_value);
EXPECT_TRUE(cookie_value2->GetBoolean(keys::kSessionKey, &boolean_value));
EXPECT_FALSE(boolean_value);
EXPECT_TRUE(
cookie_value2->GetDouble(keys::kExpirationDateKey, &double_value));
EXPECT_EQ(10000, double_value);
scoped_ptr<Cookie> cookie2(
cookies_helpers::CreateCookie(
canonical_cookie2, "some cookie store"));
EXPECT_FALSE(cookie2->host_only);
EXPECT_FALSE(cookie2->session);
ASSERT_TRUE(cookie2->expiration_date.get());
EXPECT_EQ(10000, *cookie2->expiration_date);
TestingProfile profile;
ListValue* tab_ids = new ListValue();
scoped_ptr<DictionaryValue> cookie_store_value(
cookies_helpers::CreateCookieStoreValue(&profile, tab_ids));
EXPECT_TRUE(cookie_store_value->GetString(keys::kIdKey, &string_value));
EXPECT_EQ("0", string_value);
EXPECT_TRUE(cookie_store_value->Get(keys::kTabIdsKey, &value));
EXPECT_EQ(tab_ids, value);
ListValue* tab_ids_list = new ListValue();
std::vector<int> tab_ids;
scoped_ptr<CookieStore> cookie_store(
cookies_helpers::CreateCookieStore(&profile, tab_ids_list));
EXPECT_EQ("0", cookie_store->id);
EXPECT_EQ(tab_ids, cookie_store->tab_ids);
}
TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) {
......@@ -185,11 +172,12 @@ TEST_F(ExtensionCookiesTest, GetURLFromCanonicalCookie) {
}
TEST_F(ExtensionCookiesTest, EmptyDictionary) {
scoped_ptr<DictionaryValue> details(new DictionaryValue());
cookies_helpers::MatchFilter filter(details.get());
std::string domain;
DictionaryValue dict;
GetAll::Params::Details details;
bool rv = GetAll::Params::Details::Populate(dict, &details);
ASSERT_TRUE(rv);
cookies_helpers::MatchFilter filter(&details);
net::CanonicalCookie cookie;
EXPECT_TRUE(filter.MatchesCookie(cookie));
}
......@@ -204,29 +192,32 @@ TEST_F(ExtensionCookiesTest, DomainMatching) {
{ "foo.bar.com", ".bar.com", false }
};
scoped_ptr<DictionaryValue> details(new DictionaryValue());
for (size_t i = 0; i < arraysize(tests); ++i) {
details->SetString(keys::kDomainKey, std::string(tests[i].filter));
cookies_helpers::MatchFilter filter(details.get());
net::CanonicalCookie cookie(GURL(), "", "", tests[i].domain, "", "", "",
base::Time(), base::Time(), base::Time(), false,
false);
// Build up the Params struct.
ListValue args;
DictionaryValue* dict = new DictionaryValue();
dict->SetString(keys::kDomainKey, std::string(tests[i].filter));
args.Set(0, dict);
scoped_ptr<GetAll::Params> params(GetAll::Params::Create(args));
cookies_helpers::MatchFilter filter(&params->details);
net::CanonicalCookie cookie(GURL(), "", "", tests[i].domain,
"", "", "", base::Time(),
base::Time(), base::Time(),
false, false);
EXPECT_EQ(tests[i].matches, filter.MatchesCookie(cookie));
}
}
TEST_F(ExtensionCookiesTest, DecodeUTF8WithErrorHandling) {
net::CanonicalCookie cookie(GURL(), "", "011Q255bNX_1!yd\203e+", "test.com",
"/path\203", "", "", base::Time(), base::Time(),
base::Time(), false, false);
scoped_ptr<DictionaryValue> cookie_value(
cookies_helpers::CreateCookieValue(
cookie, "some cookie store"));
std::string string_value;
EXPECT_TRUE(cookie_value->GetString(keys::kValueKey, &string_value));
EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), string_value);
EXPECT_TRUE(cookie_value->GetString(keys::kPathKey, &string_value));
EXPECT_EQ(std::string(""), string_value);
net::CanonicalCookie canonical_cookie(
GURL(), "", "011Q255bNX_1!yd\203e+", "test.com", "/path\203", "", "",
base::Time(), base::Time(), base::Time(), false, false);
scoped_ptr<Cookie> cookie(
cookies_helpers::CreateCookie(
canonical_cookie, "some cookie store"));
EXPECT_EQ(std::string("011Q255bNX_1!yd\xEF\xBF\xBD" "e+"), cookie->value);
EXPECT_EQ(std::string(""), cookie->path);
}
} // namespace extensions
......@@ -19,6 +19,7 @@
'chromium_code': 1,
'json_schema_files': [
'content_settings.json',
'cookies.json',
'debugger.json',
'events.json',
'experimental_record.json',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment