| OLD | NEW |
| 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 #include "net/cookies/cookie_monster.h" | 5 #include "net/cookies/cookie_monster.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "base/test/mock_callback.h" | 26 #include "base/test/mock_callback.h" |
| 27 #include "base/threading/thread.h" | 27 #include "base/threading/thread.h" |
| 28 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "base/time/time.h" | 29 #include "base/time/time.h" |
| 30 #include "net/cookies/canonical_cookie.h" | 30 #include "net/cookies/canonical_cookie.h" |
| 31 #include "net/cookies/cookie_constants.h" | 31 #include "net/cookies/cookie_constants.h" |
| 32 #include "net/cookies/cookie_monster_store_test.h" // For CookieStore mock | 32 #include "net/cookies/cookie_monster_store_test.h" // For CookieStore mock |
| 33 #include "net/cookies/cookie_store_unittest.h" | 33 #include "net/cookies/cookie_store_unittest.h" |
| 34 #include "net/cookies/cookie_util.h" | 34 #include "net/cookies/cookie_util.h" |
| 35 #include "net/cookies/parsed_cookie.h" | 35 #include "net/cookies/parsed_cookie.h" |
| 36 #include "net/ssl/channel_id_service.h" |
| 37 #include "net/ssl/default_channel_id_store.h" |
| 36 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 38 #include "url/gurl.h" | 40 #include "url/gurl.h" |
| 39 | 41 |
| 40 namespace net { | 42 namespace net { |
| 41 | 43 |
| 42 using CookiePredicate = CookieStore::CookiePredicate; | 44 using CookiePredicate = CookieStore::CookiePredicate; |
| 43 using base::Time; | 45 using base::Time; |
| 44 using base::TimeDelta; | 46 using base::TimeDelta; |
| 45 | 47 |
| (...skipping 2416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2462 | 2464 |
| 2463 int callback_count() { return callback_count_; } | 2465 int callback_count() { return callback_count_; } |
| 2464 | 2466 |
| 2465 private: | 2467 private: |
| 2466 friend class base::RefCountedThreadSafe<CallbackCounter>; | 2468 friend class base::RefCountedThreadSafe<CallbackCounter>; |
| 2467 ~CallbackCounter() {} | 2469 ~CallbackCounter() {} |
| 2468 | 2470 |
| 2469 volatile int callback_count_; | 2471 volatile int callback_count_; |
| 2470 }; | 2472 }; |
| 2471 | 2473 |
| 2474 class FlushCountingChannelIDStore : public DefaultChannelIDStore { |
| 2475 public: |
| 2476 FlushCountingChannelIDStore() |
| 2477 : DefaultChannelIDStore(nullptr), flush_count_(0) {} |
| 2478 |
| 2479 void Flush() override { flush_count_++; } |
| 2480 |
| 2481 int flush_count() { return flush_count_; } |
| 2482 |
| 2483 private: |
| 2484 int flush_count_; |
| 2485 }; |
| 2486 |
| 2472 } // namespace | 2487 } // namespace |
| 2473 | 2488 |
| 2474 // Test that FlushStore() is forwarded to the store and callbacks are posted. | 2489 // Test that FlushStore() is forwarded to the store and callbacks are posted. |
| 2475 TEST_F(CookieMonsterTest, FlushStore) { | 2490 TEST_F(CookieMonsterTest, FlushStore) { |
| 2476 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); | 2491 scoped_refptr<CallbackCounter> counter(new CallbackCounter()); |
| 2477 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2492 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2478 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2493 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2479 | 2494 |
| 2480 ASSERT_EQ(0, store->flush_count()); | 2495 ASSERT_EQ(0, store->flush_count()); |
| 2481 ASSERT_EQ(0, counter->callback_count()); | 2496 ASSERT_EQ(0, counter->callback_count()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2516 base::RunLoop().RunUntilIdle(); | 2531 base::RunLoop().RunUntilIdle(); |
| 2517 | 2532 |
| 2518 ASSERT_EQ(2, counter->callback_count()); | 2533 ASSERT_EQ(2, counter->callback_count()); |
| 2519 | 2534 |
| 2520 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter)); | 2535 cm->FlushStore(base::Bind(&CallbackCounter::Callback, counter)); |
| 2521 base::RunLoop().RunUntilIdle(); | 2536 base::RunLoop().RunUntilIdle(); |
| 2522 | 2537 |
| 2523 ASSERT_EQ(3, counter->callback_count()); | 2538 ASSERT_EQ(3, counter->callback_count()); |
| 2524 } | 2539 } |
| 2525 | 2540 |
| 2541 TEST_F(CookieMonsterTest, FlushChannelIDs) { |
| 2542 // |channel_id_service| owns |channel_id_store|. |
| 2543 FlushCountingChannelIDStore* channel_id_store = |
| 2544 new FlushCountingChannelIDStore(); |
| 2545 std::unique_ptr<ChannelIDService> channel_id_service( |
| 2546 new ChannelIDService(channel_id_store)); |
| 2547 |
| 2548 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2549 std::unique_ptr<CookieMonster> cm( |
| 2550 new CookieMonster(store.get(), nullptr, channel_id_service.get())); |
| 2551 EXPECT_EQ(0, channel_id_store->flush_count()); |
| 2552 |
| 2553 // Before initialization, FlushStore() doesn't propagate to the |
| 2554 // ChannelIDStore. |
| 2555 cm->FlushStore(base::Closure()); |
| 2556 base::RunLoop().RunUntilIdle(); |
| 2557 |
| 2558 EXPECT_EQ(0, channel_id_store->flush_count()); |
| 2559 |
| 2560 // After initialization, FlushStore() propagates to the ChannelIDStore. |
| 2561 GetAllCookies(cm.get()); // Force init. |
| 2562 cm->FlushStore(base::Closure()); |
| 2563 base::RunLoop().RunUntilIdle(); |
| 2564 |
| 2565 EXPECT_EQ(1, channel_id_store->flush_count()); |
| 2566 |
| 2567 // If there is no persistent store, then a ChannelIDStore won't be notified. |
| 2568 cm.reset(new CookieMonster(nullptr, nullptr, channel_id_service.get())); |
| 2569 GetAllCookies(cm.get()); // Force init. |
| 2570 cm->FlushStore(base::Closure()); |
| 2571 base::RunLoop().RunUntilIdle(); |
| 2572 |
| 2573 EXPECT_EQ(1, channel_id_store->flush_count()); |
| 2574 } |
| 2575 |
| 2526 TEST_F(CookieMonsterTest, SetAllCookies) { | 2576 TEST_F(CookieMonsterTest, SetAllCookies) { |
| 2527 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); | 2577 scoped_refptr<FlushablePersistentStore> store(new FlushablePersistentStore()); |
| 2528 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); | 2578 std::unique_ptr<CookieMonster> cm(new CookieMonster(store.get(), nullptr)); |
| 2529 cm->SetPersistSessionCookies(true); | 2579 cm->SetPersistSessionCookies(true); |
| 2530 | 2580 |
| 2531 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); | 2581 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "U=V; path=/")); |
| 2532 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); | 2582 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "W=X; path=/foo")); |
| 2533 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); | 2583 EXPECT_TRUE(SetCookie(cm.get(), http_www_google_.url(), "Y=Z; path=/")); |
| 2534 | 2584 |
| 2535 CookieList list; | 2585 CookieList list; |
| (...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3371 monster()->AddCallbackForCookie( | 3421 monster()->AddCallbackForCookie( |
| 3372 test_url_, "abc", | 3422 test_url_, "abc", |
| 3373 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 3423 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 3374 SetCookie(monster(), test_url_, "abc=def"); | 3424 SetCookie(monster(), test_url_, "abc=def"); |
| 3375 base::RunLoop().RunUntilIdle(); | 3425 base::RunLoop().RunUntilIdle(); |
| 3376 EXPECT_EQ(1U, cookies0.size()); | 3426 EXPECT_EQ(1U, cookies0.size()); |
| 3377 EXPECT_EQ(1U, cookies0.size()); | 3427 EXPECT_EQ(1U, cookies0.size()); |
| 3378 } | 3428 } |
| 3379 | 3429 |
| 3380 } // namespace net | 3430 } // namespace net |
| OLD | NEW |