Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Unified Diff: net/base/cookie_monster_store_test.h

Issue 9703011: Move the cookie store implementation into its own directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: net/base/cookies/ -> net/cookies/ Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/cookie_monster_perftest.cc ('k') | net/base/cookie_monster_store_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e341f7d9207026d7dbaf719b94077f2d0e87960d..cea2d296e4f3596b433c9de448806e8a917dfdba 100644
--- a/net/base/cookie_monster_store_test.h
+++ b/net/base/cookie_monster_store_test.h
@@ -2,205 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// This file contains test infrastructure for multiple files
-// (current cookie_monster_unittest.cc and cookie_monster_perftest.cc)
-// that need to test out CookieMonster interactions with the backing store.
-// It should only be included by test code.
+// Provides a temporary redirection while clients are updated to use the new
+// path.
#ifndef NET_BASE_COOKIE_MONSTER_STORE_TEST_H_
#define NET_BASE_COOKIE_MONSTER_STORE_TEST_H_
#pragma once
-#include <map>
-#include <string>
-#include <utility>
-#include <vector>
-#include "net/base/cookie_monster.h"
-
-namespace base {
-class Time;
-}
-
-namespace net {
-
-// Wrapper class for posting a loaded callback. Since the Callback class is not
-// reference counted, we cannot post a callback to the message loop directly,
-// instead we post a LoadedCallbackTask.
-class LoadedCallbackTask
- : public base::RefCountedThreadSafe<LoadedCallbackTask> {
- public:
- typedef CookieMonster::PersistentCookieStore::LoadedCallback LoadedCallback;
-
- LoadedCallbackTask(LoadedCallback loaded_callback,
- std::vector<CookieMonster::CanonicalCookie*> cookies);
- ~LoadedCallbackTask();
-
- void Run() {
- loaded_callback_.Run(cookies_);
- }
-
- private:
- LoadedCallback loaded_callback_;
- std::vector<CookieMonster::CanonicalCookie*> cookies_;
-
- DISALLOW_COPY_AND_ASSIGN(LoadedCallbackTask);
-}; // Wrapper class LoadedCallbackTask
-
-// Describes a call to one of the 3 functions of PersistentCookieStore.
-struct CookieStoreCommand {
- enum Type {
- ADD,
- UPDATE_ACCESS_TIME,
- REMOVE,
- };
-
- CookieStoreCommand(Type type,
- const CookieMonster::CanonicalCookie& cookie)
- : type(type),
- cookie(cookie) {}
-
- Type type;
- CookieMonster::CanonicalCookie cookie;
-};
-
-// Implementation of PersistentCookieStore that captures the
-// received commands and saves them to a list.
-// The result of calls to Load() can be configured using SetLoadExpectation().
-class MockPersistentCookieStore
- : public CookieMonster::PersistentCookieStore {
- public:
- typedef std::vector<CookieStoreCommand> CommandList;
-
- MockPersistentCookieStore();
- virtual ~MockPersistentCookieStore();
-
- void SetLoadExpectation(
- bool return_value,
- const std::vector<CookieMonster::CanonicalCookie*>& result);
-
- const CommandList& commands() const {
- return commands_;
- }
-
- virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE;
-
- virtual void LoadCookiesForKey(const std::string& key,
- const LoadedCallback& loaded_callback) OVERRIDE;
-
- virtual void AddCookie(const CookieMonster::CanonicalCookie& cookie) OVERRIDE;
-
- virtual void UpdateCookieAccessTime(
- const CookieMonster::CanonicalCookie& cookie) OVERRIDE;
-
- virtual void DeleteCookie(
- const CookieMonster::CanonicalCookie& cookie) OVERRIDE;
-
- virtual void Flush(const base::Closure& callback) OVERRIDE;
-
- // No files are created so nothing to clear either
- virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE;
-
- private:
- CommandList commands_;
-
- // Deferred result to use when Load() is called.
- bool load_return_value_;
- std::vector<CookieMonster::CanonicalCookie*> load_result_;
- // Indicates if the store has been fully loaded to avoid returning duplicate
- // cookies.
- bool loaded_;
-
- DISALLOW_COPY_AND_ASSIGN(MockPersistentCookieStore);
-};
-
-// Mock for CookieMonster::Delegate
-class MockCookieMonsterDelegate : public CookieMonster::Delegate {
- public:
- typedef std::pair<CookieMonster::CanonicalCookie, bool>
- CookieNotification;
-
- MockCookieMonsterDelegate();
-
- const std::vector<CookieNotification>& changes() const { return changes_; }
-
- void reset() { changes_.clear(); }
-
- virtual void OnCookieChanged(
- const CookieMonster::CanonicalCookie& cookie,
- bool removed,
- CookieMonster::Delegate::ChangeCause cause) OVERRIDE;
-
- private:
- virtual ~MockCookieMonsterDelegate();
-
- std::vector<CookieNotification> changes_;
-
- DISALLOW_COPY_AND_ASSIGN(MockCookieMonsterDelegate);
-};
-
-// Helper to build a single CanonicalCookie.
-CookieMonster::CanonicalCookie BuildCanonicalCookie(
- const std::string& key,
- const std::string& cookie_line,
- const base::Time& creation_time);
-
-// Helper to build a list of CanonicalCookie*s.
-void AddCookieToList(
- const std::string& key,
- const std::string& cookie_line,
- const base::Time& creation_time,
- std::vector<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 CookieMonster::PersistentCookieStore {
- public:
- MockSimplePersistentCookieStore();
- virtual ~MockSimplePersistentCookieStore();
-
- virtual void Load(const LoadedCallback& loaded_callback) OVERRIDE;
-
- virtual void LoadCookiesForKey(const std::string& key,
- const LoadedCallback& loaded_callback) OVERRIDE;
-
- virtual void AddCookie(
- const CookieMonster::CanonicalCookie& cookie) OVERRIDE;
-
- virtual void UpdateCookieAccessTime(
- const CookieMonster::CanonicalCookie& cookie) OVERRIDE;
-
- virtual void DeleteCookie(
- const CookieMonster::CanonicalCookie& cookie) OVERRIDE;
-
- virtual void Flush(const base::Closure& callback) OVERRIDE;
-
- virtual void SetClearLocalStateOnExit(bool clear_local_state) OVERRIDE;
-
- private:
- typedef std::map<int64, CookieMonster::CanonicalCookie>
- CanonicalCookieMap;
-
- CanonicalCookieMap cookies_;
-
- // Indicates if the store has been fully loaded to avoid return duplicate
- // cookies in subsequent load requests
- bool loaded_;
-};
-
-// Helper function for creating a CookieMonster backed by a
-// MockSimplePersistentCookieStore for garbage collection testing.
-//
-// Fill the store through import with |num_cookies| cookies, |num_old_cookies|
-// with access time Now()-days_old, the rest with access time Now().
-// 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.
-CookieMonster* CreateMonsterFromStoreForGC(
- int num_cookies,
- int num_old_cookies,
- int days_old);
-
-} // namespace net
+#include "net/cookies/cookie_monster_store_test.h"
#endif // NET_BASE_COOKIE_MONSTER_STORE_TEST_H_
« no previous file with comments | « net/base/cookie_monster_perftest.cc ('k') | net/base/cookie_monster_store_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698