15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_COOKIES_COOKIE_STORE_UNITTEST_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h"
99ab5563a3196760eb381d102cbb2bc0f7abc6a50Ben Murdoch#include "base/message_loop/message_loop.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/strings/string_tokenizer.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/thread.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/cookie_monster.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/cookie_store.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/cookie_store_test_callbacks.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "url/gurl.h"
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file declares unittest templates that can be used to test common
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// behavior of any CookieStore implementation.
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// See cookie_monster_unittest.cc for an example of an implementation.
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::Thread;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const int kTimeout = 1000;
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kUrlFtp[] = "ftp://ftp.google.izzle/";
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kUrlGoogle[] = "http://www.google.izzle";
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kUrlGoogleFoo[] = "http://www.google.izzle/foo";
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kUrlGoogleBar[] = "http://www.google.izzle/bar";
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kUrlGoogleSecure[] = "https://www.google.izzle";
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kValidCookieLine[] = "A=B; path=/";
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kValidDomainCookieLine[] = "A=B; path=/; domain=google.izzle";
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The CookieStoreTestTraits must have the following members:
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// struct CookieStoreTestTraits {
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // Factory function.
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   static scoped_refptr<CookieStore> Create();
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // The cookie store is a CookieMonster. Only used to test
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // GetCookieMonster().
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   static const bool is_cookie_monster;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // The cookie store supports cookies with the exclude_httponly() option.
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   static const bool supports_http_only;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // The cookie store is able to make the difference between the ".com"
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // and the "com" domains.
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   static const bool supports_non_dotted_domains;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // The cookie store handles the domains with trailing dots (such as "com.")
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // correctly.
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   static const bool supports_trailing_dots;
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // The cookie store rejects cookies for invalid schemes such as ftp.
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   static const bool filters_schemes;
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // The cookie store has a bug happening when a path is a substring of
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // another.
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   static const bool has_path_prefix_bug;
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // Time to wait between two cookie insertions to ensure that cookies have
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   // different creation times.
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   static const int creation_time_granularity_in_ms;
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// };
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)template <class CookieStoreTestTraits>
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CookieStoreTest : public testing::Test {
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieStoreTest()
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : url_google_(kUrlGoogle),
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url_google_secure_(kUrlGoogleSecure),
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url_google_foo_(kUrlGoogleFoo),
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url_google_bar_(kUrlGoogleBar) {
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // This test may be used outside of the net test suite, and thus may not
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // have a message loop.
7890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    if (!base::MessageLoop::current())
7990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      message_loop_.reset(new base::MessageLoop);
8090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    weak_factory_.reset(new base::WeakPtrFactory<base::MessageLoop>(
8190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::MessageLoop::current()));
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper methods for the asynchronous Cookie Store API that call the
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // asynchronous method and then pump the loop until the callback is invoked,
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // finally returning the value.
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string GetCookies(CookieStore* cs, const GURL& url) {
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(cs);
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CookieOptions options;
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!CookieStoreTestTraits::supports_http_only)
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      options.set_include_httponly();
9390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    StringResultCookieCallback callback;
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->GetCookiesWithOptionsAsync(
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, options,
9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&StringResultCookieCallback::Run,
9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                   base::Unretained(&callback)));
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RunFor(kTimeout);
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(callback.did_run());
10090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return callback.result();
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string GetCookiesWithOptions(CookieStore* cs,
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    const GURL& url,
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                    const CookieOptions& options) {
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(cs);
10790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    StringResultCookieCallback callback;
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->GetCookiesWithOptionsAsync(
10990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        url, options, base::Bind(&StringResultCookieCallback::Run,
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 base::Unretained(&callback)));
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RunFor(kTimeout);
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(callback.did_run());
11390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return callback.result();
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetCookieWithOptions(CookieStore* cs,
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const GURL& url,
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const std::string& cookie_line,
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const CookieOptions& options) {
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(cs);
12190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    BoolResultCookieCallback callback;
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->SetCookieWithOptionsAsync(
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, cookie_line, options,
12490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&BoolResultCookieCallback::Run,
12590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                   base::Unretained(&callback)));
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RunFor(kTimeout);
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(callback.did_run());
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return callback.result();
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetCookieWithServerTime(CookieStore* cs,
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               const GURL& url,
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               const std::string& cookie_line,
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               const base::Time& server_time) {
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CookieOptions options;
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!CookieStoreTestTraits::supports_http_only)
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      options.set_include_httponly();
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    options.set_server_time(server_time);
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SetCookieWithOptions(cs, url, cookie_line, options);
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool SetCookie(CookieStore* cs,
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 const GURL& url,
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                 const std::string& cookie_line) {
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CookieOptions options;
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!CookieStoreTestTraits::supports_http_only)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      options.set_include_httponly();
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return SetCookieWithOptions(cs, url, cookie_line, options);
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DeleteCookie(CookieStore* cs,
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const GURL& url,
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const std::string& cookie_name) {
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(cs);
15590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    NoResultCookieCallback callback;
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->DeleteCookieAsync(
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, cookie_name,
15890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&NoResultCookieCallback::Run, base::Unretained(&callback)));
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RunFor(kTimeout);
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(callback.did_run());
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DeleteCreatedBetween(CookieStore* cs,
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const base::Time& delete_begin,
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const base::Time& delete_end) {
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(cs);
16790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    IntResultCookieCallback callback;
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->DeleteAllCreatedBetweenAsync(
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        delete_begin, delete_end,
17090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&IntResultCookieCallback::Run, base::Unretained(&callback)));
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RunFor(kTimeout);
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(callback.did_run());
17390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return callback.result();
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int DeleteSessionCookies(CookieStore* cs) {
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DCHECK(cs);
17890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    IntResultCookieCallback callback;
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->DeleteSessionCookiesAsync(
18090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&IntResultCookieCallback::Run, base::Unretained(&callback)));
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RunFor(kTimeout);
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(callback.did_run());
18390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return callback.result();
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RunFor(int ms) {
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Runs the test thread message loop for up to |ms| milliseconds.
18890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    base::MessageLoop::current()->PostDelayedTask(
18990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        FROM_HERE,
19090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&base::MessageLoop::Quit, weak_factory_->GetWeakPtr()),
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        base::TimeDelta::FromMilliseconds(ms));
19290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    base::MessageLoop::current()->Run();
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    weak_factory_->InvalidateWeakPtrs();
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> GetCookieStore() {
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return CookieStoreTestTraits::Create();
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Compares two cookie lines.
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void MatchCookieLines(const std::string& line1, const std::string& line2) {
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_EQ(TokenizeCookieLine(line1), TokenizeCookieLine(line2));
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check the cookie line by polling until equality or a timeout is reached.
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void MatchCookieLineWithTimeout(CookieStore* cs,
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  const GURL& url,
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  const std::string& line) {
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::string cookies = GetCookies(cs, url);
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies));
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    base::Time polling_end_date = base::Time::Now() +
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        base::TimeDelta::FromMilliseconds(
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            CookieStoreTestTraits::creation_time_granularity_in_ms);
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    while (!matched &&  base::Time::Now() <= polling_end_date) {
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(10));
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cookies = GetCookies(cs, url);
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      matched = (TokenizeCookieLine(line) == TokenizeCookieLine(cookies));
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_TRUE(matched) << "\"" << cookies
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         << "\" does not match \"" << line << "\"";
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_google_;
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_google_secure_;
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_google_foo_;
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_google_bar_;
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
23090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<base::WeakPtrFactory<base::MessageLoop> > weak_factory_;
23190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<base::MessageLoop> message_loop_;
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a set of strings of type "name=value". Fails in case of duplicate.
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::set<std::string> TokenizeCookieLine(const std::string& line) {
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::set<std::string> tokens;
2372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    base::StringTokenizer tokenizer(line, " ;");
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    while (tokenizer.GetNext())
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      EXPECT_TRUE(tokens.insert(tokenizer.token()).second);
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return tokens;
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_CASE_P(CookieStoreTest);
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, TypeTest) {
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(cs->GetCookieMonster(),
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)            (TypeParam::is_cookie_monster) ?
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                static_cast<CookieMonster*>(cs.get()) : NULL);
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, DomainTest) {
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
255868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
256868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
257868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
258868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), this->url_google_, "C=D; domain=.google.izzle"));
259868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B; C=D",
260868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Verify that A=B was set as a host cookie rather than a domain
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cookie -- should not be accessible from a sub sub-domain.
264868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines(
265868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "C=D", this->GetCookies(cs.get(), GURL("http://foo.www.google.izzle")));
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Test and make sure we find domain cookies on the same domain.
268868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
269868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), this->url_google_, "E=F; domain=.www.google.izzle"));
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->MatchCookieLines("A=B; C=D; E=F",
271868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Test setting a domain= that doesn't start w/ a dot, should
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // treat it as a domain cookie, as if there was a pre-pended dot.
275868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
276868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), this->url_google_, "G=H; domain=www.google.izzle"));
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->MatchCookieLines("A=B; C=D; E=F; G=H",
278868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Test domain enforcement, should fail on a sub-domain or something too deep.
281868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(
282868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookie(cs.get(), this->url_google_, "I=J; domain=.izzle"));
283c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
284868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), GURL("http://a.izzle")));
285c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  EXPECT_FALSE(this->SetCookie(
286868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), this->url_google_, "K=L; domain=.bla.www.google.izzle"));
287868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines(
288868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "C=D; E=F; G=H",
289868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->GetCookies(cs.get(), GURL("http://bla.www.google.izzle")));
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->MatchCookieLines("A=B; C=D; E=F; G=H",
291868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// FireFox recognizes domains containing trailing periods as valid.
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// IE and Safari do not. Assert the expected policy here.
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, DomainWithTrailingDotTest) {
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
298868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(this->SetCookie(
299868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), this->url_google_, "a=1; domain=.www.google.com."));
300868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(this->SetCookie(
301868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), this->url_google_, "b=2; domain=.www.google.com.."));
302c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
303868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that cookies can bet set on higher level domains.
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// http://b/issue?id=896491
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, ValidSubdomainTest) {
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_abcd("http://a.b.c.d.com");
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_bcd("http://b.c.d.com");
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_cd("http://c.d.com");
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_d("http://d.com");
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
315868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), url_abcd, "a=1; domain=.a.b.c.d.com"));
316868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), url_abcd, "b=2; domain=.b.c.d.com"));
317868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), url_abcd, "c=3; domain=.c.d.com"));
318868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), url_abcd, "d=4; domain=.d.com"));
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
320868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("a=1; b=2; c=3; d=4",
321868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), url_abcd));
322868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("b=2; c=3; d=4", this->GetCookies(cs.get(), url_bcd));
323868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("c=3; d=4", this->GetCookies(cs.get(), url_cd));
324868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("d=4", this->GetCookies(cs.get(), url_d));
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check that the same cookie can exist on different sub-domains.
327868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), url_bcd, "X=bcd; domain=.b.c.d.com"));
328868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), url_bcd, "X=cd; domain=.c.d.com"));
3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->MatchCookieLines("b=2; c=3; d=4; X=bcd; X=cd",
330868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), url_bcd));
331868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("c=3; d=4; X=cd", this->GetCookies(cs.get(), url_cd));
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that setting a cookie which specifies an invalid domain has
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// no side-effect. An invalid domain in this context is one which does
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// not match the originating domain.
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// http://b/issue?id=896472
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, InvalidDomainTest) {
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url_foobar("http://foo.bar.com");
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // More specific sub-domain than allowed.
344868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
345868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_foobar, "a=1; domain=.yo.foo.bar.com"));
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
347868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url_foobar, "b=2; domain=.foo.com"));
348868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
349868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_foobar, "c=3; domain=.bar.foo.com"));
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Different TLD, but the rest is a substring.
352868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
353868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_foobar, "d=4; domain=.foo.bar.com.net"));
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // A substring that isn't really a parent domain.
356868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url_foobar, "e=5; domain=ar.com"));
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Completely invalid domains:
359868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url_foobar, "f=6; domain=."));
360868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url_foobar, "g=7; domain=/"));
361868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(
362868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        cs.get(), url_foobar, "h=8; domain=http://foo.bar.com"));
363868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
364868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_foobar, "i=9; domain=..foo.bar.com"));
365868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
366868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_foobar, "j=10; domain=..bar.com"));
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Make sure there isn't something quirky in the domain canonicalization
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // that supports full URL semantics.
370868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(
371868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        cs.get(), url_foobar, "k=11; domain=.foo.bar.com?blah"));
372868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(
373868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        cs.get(), url_foobar, "l=12; domain=.foo.bar.com/blah"));
374868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
375868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_foobar, "m=13; domain=.foo.bar.com:80"));
376868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
377868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_foobar, "n=14; domain=.foo.bar.com:"));
378868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
379868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_foobar, "o=15; domain=.foo.bar.com#sup"));
380868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
381868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(std::string(),
382868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                           this->GetCookies(cs.get(), url_foobar));
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Make sure the cookie code hasn't gotten its subdomain string handling
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // reversed, missed a suffix check, etc.  It's important here that the two
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // hosts below have the same domain + registry.
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url_foocom("http://foo.com.com");
391868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
392868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_foocom, "a=1; domain=.foo.com.com.com"));
393868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(std::string(),
394868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                           this->GetCookies(cs.get(), url_foocom));
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test the behavior of omitting dot prefix from domain, should
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// function the same as FireFox.
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// http://b/issue?id=889898
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, DomainWithoutLeadingDotTest) {
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {  // The omission of dot results in setting a domain cookie.
4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url_hosted("http://manage.hosted.filefront.com");
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url_filefront("http://www.filefront.com");
406868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_TRUE(
407868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_hosted, "sawAd=1; domain=filefront.com"));
408868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines("sawAd=1", this->GetCookies(cs.get(), url_hosted));
409868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines("sawAd=1",
410868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                           this->GetCookies(cs.get(), url_filefront));
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {  // Even when the domains match exactly, don't consider it host cookie.
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("http://www.google.com");
416868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=www.google.com"));
417868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url));
418868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(
419868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        "a=1", this->GetCookies(cs.get(), GURL("http://sub.www.google.com")));
420c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    this->MatchCookieLines(
421868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        std::string(),
422868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->GetCookies(cs.get(), GURL("http://something-else.com")));
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that the domain specified in cookie string is treated case-insensitive
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// http://b/issue?id=896475.
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, CaseInsensitiveDomainTest) {
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url("http://www.google.com");
431868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1; domain=.GOOGLE.COM"));
432868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), url, "b=2; domain=.wWw.gOOgLE.coM"));
433868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("a=1; b=2", this->GetCookies(cs.get(), url));
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, TestIpAddress) {
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_ip("http://1.2.3.4/weee");
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
440868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_TRUE(this->SetCookie(cs.get(), url_ip, kValidCookieLine));
441868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines("A=B", this->GetCookies(cs.get(), url_ip));
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {  // IP addresses should not be able to set domain cookies.
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
446868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url_ip, "b=2; domain=.1.2.3.4"));
447868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url_ip, "c=3; domain=.3.4"));
448868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(std::string(), this->GetCookies(cs.get(), url_ip));
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // It should be allowed to set a cookie if domain= matches the IP address
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // exactly.  This matches IE/Firefox, even though it seems a bit wrong.
451868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url_ip, "b=2; domain=1.2.3.3"));
452868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(std::string(), this->GetCookies(cs.get(), url_ip));
453868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_TRUE(this->SetCookie(cs.get(), url_ip, "b=2; domain=1.2.3.4"));
454868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines("b=2", this->GetCookies(cs.get(), url_ip));
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test host cookies, and setting of cookies on TLD.
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, TestNonDottedAndTLD) {
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("http://com/");
4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Allow setting on "com", (but only as a host cookie).
464868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1"));
465868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.com"));
466868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url, "c=3; domain=com"));
467868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url));
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Make sure it doesn't show up for a normal .com, it should be a host
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // not a domain cookie.
470c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    this->MatchCookieLines(
471c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        std::string(),
472868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/")));
4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (TypeParam::supports_non_dotted_domains) {
474c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      this->MatchCookieLines(std::string(),
475868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                             this->GetCookies(cs.get(), GURL("http://.com/")));
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {
4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // http://com. should be treated the same as http://com.
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("http://com./index.html");
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (TypeParam::supports_trailing_dots) {
484868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1"));
485868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url));
486c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      this->MatchCookieLines(
487c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)          std::string(),
488868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)          this->GetCookies(cs.get(),
489868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                           GURL("http://hopefully-no-cookies.com./")));
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    } else {
491868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      EXPECT_FALSE(this->SetCookie(cs.get(), url, "a=1"));
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    }
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {  // Should not be able to set host cookie from a subdomain.
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("http://a.b");
498868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url, "a=1; domain=.b"));
499868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=b"));
500868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(std::string(), this->GetCookies(cs.get(), url));
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {  // Same test as above, but explicitly on a known TLD (com).
5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("http://google.com");
506868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url, "a=1; domain=.com"));
507868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=com"));
508868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(std::string(), this->GetCookies(cs.get(), url));
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {  // Make sure can't set cookie on TLD which is dotted.
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
5135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("http://google.co.uk");
514868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url, "a=1; domain=.co.uk"));
515868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.uk"));
516868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(std::string(), this->GetCookies(cs.get(), url));
517c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    this->MatchCookieLines(
518c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        std::string(),
519868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->GetCookies(cs.get(), GURL("http://something-else.co.uk")));
520c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    this->MatchCookieLines(
521868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        std::string(),
522868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->GetCookies(cs.get(), GURL("http://something-else.uk")));
5235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  {  // Intranet URLs should only be able to set host cookies.
5265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
5275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("http://b");
528868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1"));
529868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url, "b=2; domain=.b"));
530868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(this->SetCookie(cs.get(), url, "c=3; domain=b"));
531868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url));
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test reading/writing cookies when the domain ends with a period,
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// as in "www.google.com."
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, TestHostEndsWithDot) {
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
5395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url("http://www.google.com");
5405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_with_dot("http://www.google.com.");
541868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), url, "a=1"));
542868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url));
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (TypeParam::supports_trailing_dots) {
5455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Do not share cookie space with the dot version of domain.
5465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Note: this is not what FireFox does, but it _is_ what IE+Safari do.
547868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
548868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url, "b=2; domain=.www.google.com."));
549868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines("a=1", this->GetCookies(cs.get(), url));
5505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
551868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_TRUE(
552868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_with_dot, "b=2; domain=.google.com."));
553868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines("b=2", this->GetCookies(cs.get(), url_with_dot));
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
555868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_TRUE(this->SetCookie(cs.get(), url, "b=2; domain=.www.google.com."));
556868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_FALSE(
557868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->SetCookie(cs.get(), url_with_dot, "b=2; domain=.google.com."));
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Make sure there weren't any side effects.
561c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(
562c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      std::string(),
563868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->GetCookies(cs.get(), GURL("http://hopefully-no-cookies.com/")));
564c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
565868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), GURL("http://.com/")));
5665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, InvalidScheme) {
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!TypeParam::filters_schemes)
5705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
5715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
573868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(this->SetCookie(cs.get(), GURL(kUrlFtp), kValidCookieLine));
5745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, InvalidScheme_Read) {
5775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!TypeParam::filters_schemes)
5785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
5795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
581868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
582868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookie(cs.get(), GURL(kUrlGoogle), kValidDomainCookieLine));
583868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines(std::string(),
584868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), GURL(kUrlFtp)));
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, PathTest) {
5885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
5895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string url("http://www.google.izzle");
590868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), GURL(url), "A=B; path=/wee"));
591868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), GURL(url + "/wee")));
592868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B",
593868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), GURL(url + "/wee/")));
5945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->MatchCookieLines("A=B",
595868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), GURL(url + "/wee/war")));
596868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines(
597868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "A=B", this->GetCookies(cs.get(), GURL(url + "/wee/war/more/more")));
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!TypeParam::has_path_prefix_bug)
599c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    this->MatchCookieLines(std::string(),
600868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                           this->GetCookies(cs.get(), GURL(url + "/weehee")));
601868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines(std::string(),
602868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), GURL(url + "/")));
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If we add a 0 length path, it should default to /
605868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), GURL(url), "A=C; path="));
606868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B; A=C",
607868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), GURL(url + "/wee")));
608868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=C", this->GetCookies(cs.get(), GURL(url + "/")));
6095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TYPED_TEST_P(CookieStoreTest, EmptyExpires) {
6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CookieOptions options;
6142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (!TypeParam::supports_http_only)
6152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    options.set_include_httponly();
6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  GURL url("http://www7.ipdl.inpit.go.jp/Tokujitu/tjkta.ipdl?N0000=108");
6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string set_cookie_line =
6182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      "ACSTM=20130308043820420042; path=/; domain=ipdl.inpit.go.jp; Expires=";
6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string cookie_line = "ACSTM=20130308043820420042";
6202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
621868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->SetCookieWithOptions(cs.get(), url, set_cookie_line, options);
6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  this->MatchCookieLines(cookie_line,
623868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookiesWithOptions(cs.get(), url, options));
6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  options.set_server_time(base::Time::Now() - base::TimeDelta::FromHours(1));
626868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->SetCookieWithOptions(cs.get(), url, set_cookie_line, options);
6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  this->MatchCookieLines(cookie_line,
628868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookiesWithOptions(cs.get(), url, options));
6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  options.set_server_time(base::Time::Now() + base::TimeDelta::FromHours(1));
631868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->SetCookieWithOptions(cs.get(), url, set_cookie_line, options);
6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  this->MatchCookieLines(cookie_line,
633868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookiesWithOptions(cs.get(), url, options));
6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, HttpOnlyTest) {
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!TypeParam::supports_http_only)
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return;
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieOptions options;
6425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  options.set_include_httponly();
6435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create a httponly cookie.
645868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookieWithOptions(
646868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), this->url_google_, "A=B; httponly", options));
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check httponly read protection.
649c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
650868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
651c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(
652868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check httponly overwrite protection.
655868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(this->SetCookie(cs.get(), this->url_google_, "A=C"));
656c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
657868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
658c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(
659868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
660868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
661868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookieWithOptions(cs.get(), this->url_google_, "A=C", options));
662868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=C", this->GetCookies(cs.get(), this->url_google_));
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check httponly create protection.
665868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_FALSE(this->SetCookie(cs.get(), this->url_google_, "B=A; httponly"));
666868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines(
667868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "A=C", this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
668868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookieWithOptions(
669868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), this->url_google_, "B=A; httponly", options));
670868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines(
671868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "A=C; B=A",
672868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
673868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=C", this->GetCookies(cs.get(), this->url_google_));
6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, TestCookieDeletion) {
6775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
6785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create a session cookie.
680868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, kValidCookieLine));
681868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
6825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete it via Max-Age.
683868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
684868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              this->url_google_,
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              std::string(kValidCookieLine) + "; max-age=0"));
686868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLineWithTimeout(cs.get(), this->url_google_, std::string());
6875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create a session cookie.
689868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, kValidCookieLine));
690868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete it via Expires.
692868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
693868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              this->url_google_,
6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              std::string(kValidCookieLine) +
695868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                  "; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
696c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
697868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create a persistent cookie.
700868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
701868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(),
702868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->url_google_,
703868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
7045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
705868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
7065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete it via Max-Age.
707868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
708868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              this->url_google_,
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              std::string(kValidCookieLine) + "; max-age=0"));
710868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLineWithTimeout(cs.get(), this->url_google_, std::string());
7115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create a persistent cookie.
713868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
714868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(),
715868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->url_google_,
716868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
717868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
7185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete it via Expires.
719868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
720868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              this->url_google_,
7215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              std::string(kValidCookieLine) +
722868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                  "; expires=Mon, 18-Apr-1977 22:50:13 GMT"));
723c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
724868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create a persistent cookie.
727868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
728868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(),
729868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->url_google_,
730868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
731868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
7325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check that it is not deleted with significant enough clock skew.
7335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Time server_time;
7345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(base::Time::FromString("Sun, 17-Apr-1977 22:50:13 GMT",
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     &server_time));
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(this->SetCookieWithServerTime(
737868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(),
738868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->url_google_,
739868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-1977 22:50:13 GMT",
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      server_time));
741868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
7425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Create a persistent cookie.
744868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
745868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(),
746868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->url_google_,
747868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      std::string(kValidCookieLine) + "; expires=Mon, 18-Apr-22 22:50:13 GMT"));
748868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
7495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Delete it via Expires, with a unix epoch of 0.
750868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
751868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              this->url_google_,
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              std::string(kValidCookieLine) +
753868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                  "; expires=Thu, 1-Jan-1970 00:00:00 GMT"));
754c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
755868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
7565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, TestDeleteAllCreatedBetween) {
7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::Time last_month = base::Time::Now() -
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                base::TimeDelta::FromDays(30);
7625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::Time last_minute = base::Time::Now() -
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 base::TimeDelta::FromMinutes(1);
7645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::Time next_minute = base::Time::Now() +
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 base::TimeDelta::FromMinutes(1);
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const base::Time next_month = base::Time::Now() +
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                base::TimeDelta::FromDays(30);
7685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add a cookie.
770868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
771868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  // Check that the cookie is in the store.
772868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
7735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Remove cookies in empty intervals.
775868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), last_month, last_minute));
776868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0, this->DeleteCreatedBetween(cs.get(), next_minute, next_month));
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check that the cookie is still there.
778868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Remove the cookie with an interval defined by two dates.
781868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, next_minute));
7825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check that the cookie disappeared.
783c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
784868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Add another cookie.
787868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "C=D"));
7885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check that the cookie is in the store.
789868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("C=D", this->GetCookies(cs.get(), this->url_google_));
7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Remove the cookie with a null ending time.
792868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1, this->DeleteCreatedBetween(cs.get(), last_minute, base::Time()));
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Check that the cookie disappeared.
794c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
795868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, TestSecure) {
7995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    scoped_refptr<CookieStore> cs(this->GetCookieStore());
8005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
801868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
802868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines("A=B",
803868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                           this->GetCookies(cs.get(), this->url_google_));
804868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(
805868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        "A=B", this->GetCookies(cs.get(), this->url_google_secure_));
8065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
807868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
808868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookie(cs.get(), this->url_google_secure_, "A=B; secure"));
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The secure should overwrite the non-secure.
810c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
811868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
812868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B",
813868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_secure_));
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
816868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookie(cs.get(), this->url_google_secure_, "D=E; secure"));
817c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines(std::string(),
818868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->MatchCookieLines("A=B; D=E",
820868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_secure_));
8215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
822868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_secure_, "A=B"));
8235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The non-secure should overwrite the secure.
824868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->MatchCookieLines("D=E; A=B",
826868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_secure_));
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static const int kLastAccessThresholdMilliseconds = 200;
8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Formerly NetUtilTest.CookieTest back when we used wininet's cookie handling.
8325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, NetUtilCookieTest) {
8335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const GURL test_url("http://mojo.jojo.google.izzle/");
8345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
8365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
837868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), test_url, "foo=bar"));
838868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  std::string value = this->GetCookies(cs.get(), test_url);
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->MatchCookieLines("foo=bar", value);
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // test that we can retrieve all cookies:
842868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), test_url, "x=1"));
843868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), test_url, "y=2"));
8445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
845868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  std::string result = this->GetCookies(cs.get(), test_url);
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_FALSE(result.empty());
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(result.find("x=1"), std::string::npos) << result;
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_NE(result.find("y=2"), std::string::npos) << result;
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, OverwritePersistentCookie) {
8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_google("http://www.google.com/");
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL url_chromium("http://chromium.org");
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Insert a cookie "a" for path "/path1"
857868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
858868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              url_google,
859868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              "a=val1; path=/path1; "
860868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              "expires=Mon, 18-Apr-22 22:50:13 GMT"));
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Insert a cookie "b" for path "/path1"
863868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
864868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              url_google,
865868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              "b=val1; path=/path1; "
866868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              "expires=Mon, 18-Apr-22 22:50:14 GMT"));
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Insert a cookie "b" for path "/path1", that is httponly. This should
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // overwrite the non-http-only version.
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieOptions allow_httponly;
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  allow_httponly.set_include_httponly();
872868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookieWithOptions(cs.get(),
873868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                         url_google,
874868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                         "b=val2; path=/path1; httponly; "
875868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                         "expires=Mon, 18-Apr-22 22:50:14 GMT",
876868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                         allow_httponly));
8775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Insert a cookie "a" for path "/path1". This should overwrite.
879868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
880868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              url_google,
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              "a=val33; path=/path1; "
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              "expires=Mon, 18-Apr-22 22:50:14 GMT"));
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Insert a cookie "a" for path "/path2". This should NOT overwrite
8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cookie "a", since the path is different.
886868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
887868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              url_google,
8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              "a=val9; path=/path2; "
8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              "expires=Mon, 18-Apr-22 22:50:14 GMT"));
8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Insert a cookie "a" for path "/path1", but this time for "chromium.org".
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Although the name and path match, the hostnames do not, so shouldn't
8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // overwrite.
894868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
895868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              url_chromium,
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              "a=val99; path=/path1; "
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              "expires=Mon, 18-Apr-22 22:50:14 GMT"));
8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (TypeParam::supports_http_only) {
900868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(
901868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        "a=val33",
902868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->GetCookies(cs.get(), GURL("http://www.google.com/path1")));
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
904868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    this->MatchCookieLines(
905868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        "a=val33; b=val2",
906868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)        this->GetCookies(cs.get(), GURL("http://www.google.com/path1")));
9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
908868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines(
909868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "a=val9",
910868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->GetCookies(cs.get(), GURL("http://www.google.com/path2")));
911868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines(
912868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "a=val99", this->GetCookies(cs.get(), GURL("http://chromium.org/path1")));
9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(CookieStoreTest, CookieOrdering) {
9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Put a random set of cookies into a store and make sure they're returned in
9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the right order.
9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Cookies should be sorted by path length and creation time, as per RFC6265.
9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
920868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
921868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), GURL("http://d.c.b.a.google.com/aa/x.html"), "c=1"));
922868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
923868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              GURL("http://b.a.google.com/aa/bb/cc/x.html"),
9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              "d=1; domain=b.a.google.com"));
9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      TypeParam::creation_time_granularity_in_ms));
927868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
928868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              GURL("http://b.a.google.com/aa/bb/cc/x.html"),
9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              "a=4; domain=b.a.google.com"));
9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(
9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      TypeParam::creation_time_granularity_in_ms));
932868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              GURL("http://c.b.a.google.com/aa/bb/cc/x.html"),
9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              "e=1; domain=c.b.a.google.com"));
935868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
936868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), GURL("http://d.c.b.a.google.com/aa/bb/x.html"), "b=1"));
937868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
938868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), GURL("http://news.bbc.co.uk/midpath/x.html"), "g=10"));
9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("d=1; a=4; e=1; b=1; c=1",
940868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)            this->GetCookies(cs.get(),
941868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                             GURL("http://d.c.b.a.google.com/aa/bb/cc/dd")));
9425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
944c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)TYPED_TEST_P(CookieStoreTest, DeleteSessionCookie) {
945c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
946c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Create a session cookie and a persistent cookie.
947868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(
948868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      cs.get(), this->url_google_, std::string(kValidCookieLine)));
949868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(),
950868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                              this->url_google_,
951c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                              "C=D; path=/; domain=google.izzle;"
952c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                              "expires=Mon, 18-Apr-22 22:50:13 GMT"));
953c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  this->MatchCookieLines("A=B; C=D",
954868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                         this->GetCookies(cs.get(), this->url_google_));
955c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Delete the session cookie.
956868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->DeleteSessionCookies(cs.get());
957c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Check that the session cookie has been deleted but not the persistent one.
958868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ("C=D", this->GetCookies(cs.get(), this->url_google_));
959c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)}
960c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
9615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)REGISTER_TYPED_TEST_CASE_P(CookieStoreTest,
9622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           TypeTest,
9632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           DomainTest,
9642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           DomainWithTrailingDotTest,
9652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           ValidSubdomainTest,
9662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           InvalidDomainTest,
9672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           DomainWithoutLeadingDotTest,
9682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           CaseInsensitiveDomainTest,
9692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           TestIpAddress,
9702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           TestNonDottedAndTLD,
9712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           TestHostEndsWithDot,
9722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           InvalidScheme,
9732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           InvalidScheme_Read,
9742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           PathTest,
9752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           EmptyExpires,
9762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           HttpOnlyTest,
9772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           TestCookieDeletion,
9782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           TestDeleteAllCreatedBetween,
9792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           TestSecure,
9802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           NetUtilCookieTest,
9812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           OverwritePersistentCookie,
982c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                           CookieOrdering,
983c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)                           DeleteSessionCookie);
9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)template<class CookieStoreTestTraits>
9865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MultiThreadedCookieStoreTest :
9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    public CookieStoreTest<CookieStoreTestTraits> {
9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MultiThreadedCookieStoreTest() : other_thread_("CMTthread") {}
9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Helper methods for calling the asynchronous CookieStore methods
9925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // from a different thread.
9935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetCookiesTask(CookieStore* cs,
9955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                      const GURL& url,
99690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                      StringResultCookieCallback* callback) {
9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CookieOptions options;
9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    if (!CookieStoreTestTraits::supports_http_only)
9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      options.set_include_httponly();
10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->GetCookiesWithOptionsAsync(
10015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, options,
100290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&StringResultCookieCallback::Run,
100390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                   base::Unretained(callback)));
10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GetCookiesWithOptionsTask(CookieStore* cs,
10075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const GURL& url,
10085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const CookieOptions& options,
100990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                 StringResultCookieCallback* callback) {
10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->GetCookiesWithOptionsAsync(
10115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, options,
101290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&StringResultCookieCallback::Run,
101390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                   base::Unretained(callback)));
10145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetCookieWithOptionsTask(CookieStore* cs,
10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                const GURL& url,
10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                const std::string& cookie_line,
10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                const CookieOptions& options,
102090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                BoolResultCookieCallback* callback) {
10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->SetCookieWithOptionsAsync(
10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, cookie_line, options,
102390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&BoolResultCookieCallback::Run, base::Unretained(callback)));
10245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void DeleteCookieTask(CookieStore* cs,
10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        const GURL& url,
10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                        const std::string& cookie_name,
102990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                        NoResultCookieCallback* callback) {
10305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->DeleteCookieAsync(
10315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        url, cookie_name,
103290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&NoResultCookieCallback::Run, base::Unretained(callback)));
10335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
103590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    void DeleteSessionCookiesTask(CookieStore* cs,
103690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                                  IntResultCookieCallback* callback) {
10375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    cs->DeleteSessionCookiesAsync(
103890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&IntResultCookieCallback::Run, base::Unretained(callback)));
10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
10425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void RunOnOtherThread(const base::Closure& task) {
10435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    other_thread_.Start();
10445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    other_thread_.message_loop()->PostTask(FROM_HERE, task);
10455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CookieStoreTest<CookieStoreTestTraits>::RunFor(kTimeout);
10465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    other_thread_.Stop();
10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
10485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Thread other_thread_;
10505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
10515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest);
10535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(ycxiao): Eventually, we will need to create a separate thread, create
10555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the cookie store on that thread (or at least its store, i.e., the DB
10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// thread).
10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) {
10585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
1059868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
1060868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines("A=B", this->GetCookies(cs.get(), this->url_google_));
106190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  StringResultCookieCallback callback(&this->other_thread_);
10625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Closure task = base::Bind(
10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      &net::MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask,
10645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::Unretained(this),
10655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cs, this->url_google_, &callback);
10665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->RunOnOtherThread(task);
10675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(callback.did_run());
106890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ("A=B", callback.result());
10695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) {
10725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
10735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieOptions options;
10745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!TypeParam::supports_http_only)
10755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    options.set_include_httponly();
1076868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(this->SetCookie(cs.get(), this->url_google_, "A=B"));
1077868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->MatchCookieLines(
1078868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      "A=B", this->GetCookiesWithOptions(cs.get(), this->url_google_, options));
107990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  StringResultCookieCallback callback(&this->other_thread_);
10805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Closure task = base::Bind(
10815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      &net::MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask,
10825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::Unretained(this),
10835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cs, this->url_google_, options, &callback);
10845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->RunOnOtherThread(task);
10855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(callback.did_run());
108690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ("A=B", callback.result());
10875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
10885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
10895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) {
10905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
10915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieOptions options;
10925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!TypeParam::supports_http_only)
10935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    options.set_include_httponly();
1094868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
1095868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
109690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  BoolResultCookieCallback callback(&this->other_thread_);
10975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Closure task = base::Bind(
10985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      &net::MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask,
10995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::Unretained(this),
11005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cs, this->url_google_, "A=B", options, &callback);
11015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->RunOnOtherThread(task);
11025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(callback.did_run());
11035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(callback.result());
11045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) {
11075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
11085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieOptions options;
11095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!TypeParam::supports_http_only)
11105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    options.set_include_httponly();
1111868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
1112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
1113868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  this->DeleteCookie(cs.get(), this->url_google_, "A");
1114868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
1115868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
111690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  NoResultCookieCallback callback(&this->other_thread_);
11175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Closure task = base::Bind(
11185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      &net::MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask,
11195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::Unretained(this),
11205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cs, this->url_google_, "A", &callback);
11215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->RunOnOtherThread(task);
11225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(callback.did_run());
11235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) {
11265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_refptr<CookieStore> cs(this->GetCookieStore());
11275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CookieOptions options;
11285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (!TypeParam::supports_http_only)
11295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    options.set_include_httponly();
1130868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
1131868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
1132868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
1133868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookieWithOptions(cs.get(),
1134868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                 this->url_google_,
1135868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT",
1136868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                                 options));
1137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(1, this->DeleteSessionCookies(cs.get()));
1138868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_EQ(0, this->DeleteSessionCookies(cs.get()));
1139868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  EXPECT_TRUE(
1140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      this->SetCookieWithOptions(cs.get(), this->url_google_, "A=B", options));
114190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  IntResultCookieCallback callback(&this->other_thread_);
11425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::Closure task = base::Bind(
11435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      &net::MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask,
11445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      base::Unretained(this),
11455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      cs, &callback);
11465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  this->RunOnOtherThread(task);
11475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_TRUE(callback.did_run());
114890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  EXPECT_EQ(1, callback.result());
11495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
11505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest,
11522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           ThreadCheckGetCookies,
11532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           ThreadCheckGetCookiesWithOptions,
11542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           ThreadCheckSetCookieWithOptions,
11552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           ThreadCheckDeleteCookie,
11562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           ThreadCheckDeleteSessionCookies);
11575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
11595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
11605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_COOKIES_COOKIE_STORE_UNITTEST_H_
1161