| Index: net/base/cookie_monster_store_test.h
|
| diff --git a/net/base/cookie_monster_store_test.h b/net/base/cookie_monster_store_test.h
|
| index 84ead744c7ca49cf52ede2918c1e4d675c116d62..951c0554a9efd43e012bc6c5e9cdb8a29c67fd6c 100644
|
| --- a/net/base/cookie_monster_store_test.h
|
| +++ b/net/base/cookie_monster_store_test.h
|
| @@ -1,4 +1,4 @@
|
| -// Copyright (c) 2010 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -7,12 +7,13 @@
|
| // that need to test out CookieMonster interactions with the backing store.
|
| // It should only be included by test code.
|
|
|
| -#include "base/message_loop.h"
|
| -#include "base/time.h"
|
| #include "net/base/cookie_monster.h"
|
| -#include "testing/gtest/include/gtest/gtest.h"
|
|
|
| -namespace {
|
| +namespace base {
|
| +class Time;
|
| +}
|
| +
|
| +namespace net {
|
|
|
| // Describes a call to one of the 3 functions of PersistentCookieStore.
|
| struct CookieStoreCommand {
|
| @@ -39,52 +40,32 @@ class MockPersistentCookieStore
|
| public:
|
| typedef std::vector<CookieStoreCommand> CommandList;
|
|
|
| - MockPersistentCookieStore() : load_return_value_(true) {
|
| + MockPersistentCookieStore();
|
| + virtual ~MockPersistentCookieStore();
|
| +
|
| + void SetLoadExpectation(
|
| + bool return_value,
|
| + const std::vector<net::CookieMonster::CanonicalCookie*>& result);
|
| +
|
| + const CommandList& commands() const {
|
| + return commands_;
|
| }
|
|
|
| virtual bool Load(
|
| - std::vector<net::CookieMonster::CanonicalCookie*>* out_cookies) {
|
| - bool ok = load_return_value_;
|
| - if (ok)
|
| - *out_cookies = load_result_;
|
| - return ok;
|
| - }
|
| + std::vector<net::CookieMonster::CanonicalCookie*>* out_cookies);
|
|
|
| - virtual void AddCookie(const net::CookieMonster::CanonicalCookie& cookie) {
|
| - commands_.push_back(
|
| - CookieStoreCommand(CookieStoreCommand::ADD, cookie));
|
| - }
|
| + virtual void AddCookie(const net::CookieMonster::CanonicalCookie& cookie);
|
|
|
| virtual void UpdateCookieAccessTime(
|
| - const net::CookieMonster::CanonicalCookie& cookie) {
|
| - commands_.push_back(CookieStoreCommand(
|
| - CookieStoreCommand::UPDATE_ACCESS_TIME, cookie));
|
| - }
|
| + const net::CookieMonster::CanonicalCookie& cookie);
|
|
|
| virtual void DeleteCookie(
|
| - const net::CookieMonster::CanonicalCookie& cookie) {
|
| - commands_.push_back(
|
| - CookieStoreCommand(CookieStoreCommand::REMOVE, cookie));
|
| - }
|
| + const net::CookieMonster::CanonicalCookie& cookie);
|
|
|
| - virtual void Flush(Task* completion_task) {
|
| - if (completion_task)
|
| - MessageLoop::current()->PostTask(FROM_HERE, completion_task);
|
| - }
|
| + virtual void Flush(Task* completion_task);
|
|
|
| // No files are created so nothing to clear either
|
| - virtual void SetClearLocalStateOnExit(bool clear_local_state) {}
|
| -
|
| - void SetLoadExpectation(
|
| - bool return_value,
|
| - const std::vector<net::CookieMonster::CanonicalCookie*>& result) {
|
| - load_return_value_ = return_value;
|
| - load_result_ = result;
|
| - }
|
| -
|
| - const CommandList& commands() const {
|
| - return commands_;
|
| - }
|
| + virtual void SetClearLocalStateOnExit(bool clear_local_state);
|
|
|
| private:
|
| CommandList commands_;
|
| @@ -102,21 +83,18 @@ class MockCookieMonsterDelegate : public net::CookieMonster::Delegate {
|
| typedef std::pair<net::CookieMonster::CanonicalCookie, bool>
|
| CookieNotification;
|
|
|
| - MockCookieMonsterDelegate() {}
|
| -
|
| - virtual void OnCookieChanged(
|
| - const net::CookieMonster::CanonicalCookie& cookie,
|
| - bool removed) {
|
| - CookieNotification notification(cookie, removed);
|
| - changes_.push_back(notification);
|
| - }
|
| + MockCookieMonsterDelegate();
|
|
|
| const std::vector<CookieNotification>& changes() const { return changes_; }
|
|
|
| void reset() { changes_.clear(); }
|
|
|
| + virtual void OnCookieChanged(
|
| + const net::CookieMonster::CanonicalCookie& cookie,
|
| + bool removed);
|
| +
|
| private:
|
| - virtual ~MockCookieMonsterDelegate() {}
|
| + virtual ~MockCookieMonsterDelegate();
|
|
|
| std::vector<CookieNotification> changes_;
|
|
|
| @@ -124,84 +102,40 @@ class MockCookieMonsterDelegate : public net::CookieMonster::Delegate {
|
| };
|
|
|
| // Helper to build a list of CanonicalCookie*s.
|
| -static void AddCookieToList(
|
| +void AddCookieToList(
|
| const std::string& key,
|
| const std::string& cookie_line,
|
| const base::Time& creation_time,
|
| - std::vector<net::CookieMonster::CanonicalCookie*>* out_list) {
|
| -
|
| - // Parse the cookie line.
|
| - net::CookieMonster::ParsedCookie pc(cookie_line);
|
| - EXPECT_TRUE(pc.IsValid());
|
| -
|
| - // This helper is simplistic in interpreting a parsed cookie, in order to
|
| - // avoid duplicated CookieMonster's CanonPath() and CanonExpiration()
|
| - // functions. Would be nice to export them, and re-use here.
|
| - EXPECT_FALSE(pc.HasMaxAge());
|
| - EXPECT_TRUE(pc.HasPath());
|
| - base::Time cookie_expires = pc.HasExpires() ?
|
| - net::CookieMonster::ParseCookieTime(pc.Expires()) : base::Time();
|
| - std::string cookie_path = pc.Path();
|
| -
|
| - scoped_ptr<net::CookieMonster::CanonicalCookie> cookie(
|
| - new net::CookieMonster::CanonicalCookie(
|
| - pc.Name(), pc.Value(), key, cookie_path,
|
| - pc.IsSecure(), pc.IsHttpOnly(),
|
| - creation_time, creation_time,
|
| - !cookie_expires.is_null(),
|
| - cookie_expires));
|
| -
|
| - out_list->push_back(cookie.release());
|
| -}
|
| + std::vector<net::CookieMonster::CanonicalCookie*>* out_list);
|
|
|
| // Just act like a backing database. Keep cookie information from
|
| // Add/Update/Delete and regurgitate it when Load is called.
|
| class MockSimplePersistentCookieStore
|
| : public net::CookieMonster::PersistentCookieStore {
|
| - private:
|
| - typedef std::map<int64, net::CookieMonster::CanonicalCookie>
|
| - CanonicalCookieMap;
|
| -
|
| public:
|
| + MockSimplePersistentCookieStore();
|
| + virtual ~MockSimplePersistentCookieStore();
|
| +
|
| virtual bool Load(
|
| - std::vector<net::CookieMonster::CanonicalCookie*>* out_cookies) {
|
| - for (CanonicalCookieMap::const_iterator it = cookies_.begin();
|
| - it != cookies_.end(); it++)
|
| - out_cookies->push_back(
|
| - new net::CookieMonster::CanonicalCookie(it->second));
|
| - return true;
|
| - }
|
| + std::vector<net::CookieMonster::CanonicalCookie*>* out_cookies);
|
|
|
| virtual void AddCookie(
|
| - const net::CookieMonster::CanonicalCookie& cookie) {
|
| - int64 creation_time = cookie.CreationDate().ToInternalValue();
|
| - EXPECT_TRUE(cookies_.find(creation_time) == cookies_.end());
|
| - cookies_[creation_time] = cookie;
|
| - }
|
| + const net::CookieMonster::CanonicalCookie& cookie);
|
|
|
| virtual void UpdateCookieAccessTime(
|
| - const net::CookieMonster::CanonicalCookie& cookie) {
|
| - int64 creation_time = cookie.CreationDate().ToInternalValue();
|
| - ASSERT_TRUE(cookies_.find(creation_time) != cookies_.end());
|
| - cookies_[creation_time].SetLastAccessDate(base::Time::Now());
|
| - }
|
| + const net::CookieMonster::CanonicalCookie& cookie);
|
|
|
| virtual void DeleteCookie(
|
| - const net::CookieMonster::CanonicalCookie& cookie) {
|
| - int64 creation_time = cookie.CreationDate().ToInternalValue();
|
| - CanonicalCookieMap::iterator it = cookies_.find(creation_time);
|
| - ASSERT_TRUE(it != cookies_.end());
|
| - cookies_.erase(it);
|
| - }
|
| + const net::CookieMonster::CanonicalCookie& cookie);
|
|
|
| - virtual void Flush(Task* completion_task) {
|
| - if (completion_task)
|
| - MessageLoop::current()->PostTask(FROM_HERE, completion_task);
|
| - }
|
| + virtual void Flush(Task* completion_task);
|
|
|
| - virtual void SetClearLocalStateOnExit(bool clear_local_state) {}
|
| + virtual void SetClearLocalStateOnExit(bool clear_local_state);
|
|
|
| private:
|
| + typedef std::map<int64, net::CookieMonster::CanonicalCookie>
|
| + CanonicalCookieMap;
|
| +
|
| CanonicalCookieMap cookies_;
|
| };
|
|
|
| @@ -213,32 +147,9 @@ class MockSimplePersistentCookieStore
|
| // Do two SetCookies(). Return whether each of the two SetCookies() took
|
| // longer than |gc_perf_micros| to complete, and how many cookie were
|
| // left in the store afterwards.
|
| -static net::CookieMonster* CreateMonsterFromStoreForGC(
|
| +net::CookieMonster* CreateMonsterFromStoreForGC(
|
| int num_cookies,
|
| int num_old_cookies,
|
| - int days_old) {
|
| - base::Time current(base::Time::Now());
|
| - base::Time past_creation(base::Time::Now() - base::TimeDelta::FromDays(1000));
|
| - scoped_refptr<MockSimplePersistentCookieStore> store(
|
| - new MockSimplePersistentCookieStore);
|
| - // Must expire to be persistent
|
| - for (int i = 0; i < num_old_cookies; i++) {
|
| - net::CookieMonster::CanonicalCookie cc(
|
| - "a", "1", StringPrintf("h%05d.izzle", i), "/path", false, false,
|
| - past_creation + base::TimeDelta::FromMicroseconds(i),
|
| - current - base::TimeDelta::FromDays(days_old),
|
| - true, current + base::TimeDelta::FromDays(30));
|
| - store->AddCookie(cc);
|
| - }
|
| - for (int i = num_old_cookies; i < num_cookies; i++) {
|
| - net::CookieMonster::CanonicalCookie cc(
|
| - "a", "1", StringPrintf("h%05d.izzle", i), "/path", false, false,
|
| - past_creation + base::TimeDelta::FromMicroseconds(i), current,
|
| - true, current + base::TimeDelta::FromDays(30));
|
| - store->AddCookie(cc);
|
| - }
|
| -
|
| - return new net::CookieMonster(store, NULL);
|
| -}
|
| + int days_old);
|
|
|
| -} // namespace
|
| +} // namespace net
|
|
|