diff options
author | Kristian Monsen <kristianm@google.com> | 2011-05-31 20:30:28 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-06-14 20:31:41 -0700 |
commit | 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801 (patch) | |
tree | 382278a54ce7a744d62fa510a9a80688cc12434b /net/base/cookie_monster_store_test.h | |
parent | c4becdd46e31d261b930e4b5a539cbc1d45c23a6 (diff) | |
download | external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.zip external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.gz external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.bz2 |
Merge Chromium.org at r11.0.672.0: Initial merge by git.
Change-Id: I8b4aaf611a2a405fe3fe10e8a94ea7658645c192
Diffstat (limited to 'net/base/cookie_monster_store_test.h')
-rw-r--r-- | net/base/cookie_monster_store_test.h | 177 |
1 files changed, 44 insertions, 133 deletions
diff --git a/net/base/cookie_monster_store_test.h b/net/base/cookie_monster_store_test.h index 84ead74..951c055 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 |