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

Side by Side Diff: net/cookies/cookie_store_unittest.h

Issue 1698693002: Make CookieStore no longer threadsafe. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@getcookiemonster
Patch Set: merge Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 5 #ifndef NET_COOKIES_COOKIE_STORE_UNITTEST_H_
6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 6 #define NET_COOKIES_COOKIE_STORE_UNITTEST_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 TestDeleteAllCreatedBetween, 1390 TestDeleteAllCreatedBetween,
1391 TestDeleteAllCreatedBetweenForHost, 1391 TestDeleteAllCreatedBetweenForHost,
1392 TestSecure, 1392 TestSecure,
1393 NetUtilCookieTest, 1393 NetUtilCookieTest,
1394 OverwritePersistentCookie, 1394 OverwritePersistentCookie,
1395 CookieOrdering, 1395 CookieOrdering,
1396 GetAllCookiesAsync, 1396 GetAllCookiesAsync,
1397 DeleteCanonicalCookieAsync, 1397 DeleteCanonicalCookieAsync,
1398 DeleteSessionCookie); 1398 DeleteSessionCookie);
1399 1399
1400 template<class CookieStoreTestTraits>
1401 class MultiThreadedCookieStoreTest :
1402 public CookieStoreTest<CookieStoreTestTraits> {
1403 public:
1404 MultiThreadedCookieStoreTest() : other_thread_("CMTthread") {}
1405
1406 // Helper methods for calling the asynchronous CookieStore methods
1407 // from a different thread.
1408
1409 void GetCookiesTask(CookieStore* cs,
1410 const GURL& url,
1411 StringResultCookieCallback* callback) {
1412 CookieOptions options;
1413 if (!CookieStoreTestTraits::supports_http_only)
1414 options.set_include_httponly();
1415 cs->GetCookiesWithOptionsAsync(
1416 url, options,
1417 base::Bind(&StringResultCookieCallback::Run,
1418 base::Unretained(callback)));
1419 }
1420
1421 void GetCookiesWithOptionsTask(CookieStore* cs,
1422 const GURL& url,
1423 const CookieOptions& options,
1424 StringResultCookieCallback* callback) {
1425 cs->GetCookiesWithOptionsAsync(
1426 url, options,
1427 base::Bind(&StringResultCookieCallback::Run,
1428 base::Unretained(callback)));
1429 }
1430
1431 void SetCookieWithOptionsTask(CookieStore* cs,
1432 const GURL& url,
1433 const std::string& cookie_line,
1434 const CookieOptions& options,
1435 ResultSavingCookieCallback<bool>* callback) {
1436 cs->SetCookieWithOptionsAsync(
1437 url, cookie_line, options,
1438 base::Bind(
1439 &ResultSavingCookieCallback<bool>::Run,
1440 base::Unretained(callback)));
1441 }
1442
1443 void DeleteCookieTask(CookieStore* cs,
1444 const GURL& url,
1445 const std::string& cookie_name,
1446 NoResultCookieCallback* callback) {
1447 cs->DeleteCookieAsync(
1448 url, cookie_name,
1449 base::Bind(&NoResultCookieCallback::Run, base::Unretained(callback)));
1450 }
1451
1452 void DeleteSessionCookiesTask(CookieStore* cs,
1453 ResultSavingCookieCallback<int>* callback) {
1454 cs->DeleteSessionCookiesAsync(
1455 base::Bind(
1456 &ResultSavingCookieCallback<int>::Run,
1457 base::Unretained(callback)));
1458 }
1459
1460 protected:
1461 void RunOnOtherThread(const base::Closure& task) {
1462 other_thread_.Start();
1463 other_thread_.task_runner()->PostTask(FROM_HERE, task);
1464 other_thread_.Stop();
1465 }
1466
1467 Thread other_thread_;
1468 };
1469
1470 TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest);
1471
1472 // TODO(ycxiao): Eventually, we will need to create a separate thread, create
1473 // the cookie store on that thread (or at least its store, i.e., the DB
1474 // thread).
1475 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookies) {
1476 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1477 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
1478 this->MatchCookieLines(
1479 "A=B", this->GetCookies(cs.get(), this->http_www_google_.url()));
1480 StringResultCookieCallback callback(&this->other_thread_);
1481 base::Closure task = base::Bind(
1482 &MultiThreadedCookieStoreTest<TypeParam>::GetCookiesTask,
1483 base::Unretained(this), cs, this->http_www_google_.url(), &callback);
1484 this->RunOnOtherThread(task);
1485 callback.WaitUntilDone();
1486 EXPECT_EQ("A=B", callback.result());
1487 }
1488
1489 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckGetCookiesWithOptions) {
1490 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1491 CookieOptions options;
1492 if (!TypeParam::supports_http_only)
1493 options.set_include_httponly();
1494 EXPECT_TRUE(this->SetCookie(cs.get(), this->http_www_google_.url(), "A=B"));
1495 this->MatchCookieLines(
1496 "A=B", this->GetCookiesWithOptions(cs.get(), this->http_www_google_.url(),
1497 options));
1498 StringResultCookieCallback callback(&this->other_thread_);
1499 base::Closure task = base::Bind(
1500 &MultiThreadedCookieStoreTest<TypeParam>::GetCookiesWithOptionsTask,
1501 base::Unretained(this), cs, this->http_www_google_.url(), options,
1502 &callback);
1503 this->RunOnOtherThread(task);
1504 callback.WaitUntilDone();
1505 EXPECT_EQ("A=B", callback.result());
1506 }
1507
1508 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckSetCookieWithOptions) {
1509 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1510 CookieOptions options;
1511 if (!TypeParam::supports_http_only)
1512 options.set_include_httponly();
1513 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
1514 "A=B", options));
1515 ResultSavingCookieCallback<bool> callback(&this->other_thread_);
1516 base::Closure task = base::Bind(
1517 &MultiThreadedCookieStoreTest<TypeParam>::SetCookieWithOptionsTask,
1518 base::Unretained(this), cs, this->http_www_google_.url(), "A=B", options,
1519 &callback);
1520 this->RunOnOtherThread(task);
1521 callback.WaitUntilDone();
1522 EXPECT_TRUE(callback.result());
1523 }
1524
1525 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteCookie) {
1526 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1527 CookieOptions options;
1528 if (!TypeParam::supports_http_only)
1529 options.set_include_httponly();
1530 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
1531 "A=B", options));
1532 this->DeleteCookie(cs.get(), this->http_www_google_.url(), "A");
1533 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
1534 "A=B", options));
1535 NoResultCookieCallback callback(&this->other_thread_);
1536 base::Closure task = base::Bind(
1537 &MultiThreadedCookieStoreTest<TypeParam>::DeleteCookieTask,
1538 base::Unretained(this), cs, this->http_www_google_.url(), "A", &callback);
1539 this->RunOnOtherThread(task);
1540 callback.WaitUntilDone();
1541 }
1542
1543 TYPED_TEST_P(MultiThreadedCookieStoreTest, ThreadCheckDeleteSessionCookies) {
1544 scoped_refptr<CookieStore> cs(this->GetCookieStore());
1545 CookieOptions options;
1546 if (!TypeParam::supports_http_only)
1547 options.set_include_httponly();
1548 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
1549 "A=B", options));
1550 EXPECT_TRUE(this->SetCookieWithOptions(
1551 cs.get(), this->http_www_google_.url(),
1552 "B=C; expires=Mon, 18-Apr-22 22:50:13 GMT", options));
1553 EXPECT_EQ(1, this->DeleteSessionCookies(cs.get()));
1554 EXPECT_EQ(0, this->DeleteSessionCookies(cs.get()));
1555 EXPECT_TRUE(this->SetCookieWithOptions(cs.get(), this->http_www_google_.url(),
1556 "A=B", options));
1557 ResultSavingCookieCallback<int> callback(&this->other_thread_);
1558 base::Closure task = base::Bind(
1559 &MultiThreadedCookieStoreTest<TypeParam>::DeleteSessionCookiesTask,
1560 base::Unretained(this), cs, &callback);
1561 this->RunOnOtherThread(task);
1562 callback.WaitUntilDone();
1563 EXPECT_EQ(1, callback.result());
1564 }
1565
1566 REGISTER_TYPED_TEST_CASE_P(MultiThreadedCookieStoreTest,
1567 ThreadCheckGetCookies,
1568 ThreadCheckGetCookiesWithOptions,
1569 ThreadCheckSetCookieWithOptions,
1570 ThreadCheckDeleteCookie,
1571 ThreadCheckDeleteSessionCookies);
1572
1573 } // namespace net 1400 } // namespace net
1574 1401
1575 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_ 1402 #endif // NET_COOKIES_COOKIE_STORE_UNITTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698