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

Side by Side Diff: net/cookies/cookie_monster_unittest.cc

Issue 859663003: GetEffectiveDomain should handle ws scheme as same as http scheme. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « no previous file | net/cookies/cookie_store_unittest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "net/cookies/cookie_store_unittest.h" 5 #include "net/cookies/cookie_store_unittest.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after
2604 it = cookies.begin(); 2604 it = cookies.begin();
2605 base::Closure task = base::Bind( 2605 base::Closure task = base::Bind(
2606 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, 2606 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask,
2607 base::Unretained(this), 2607 base::Unretained(this),
2608 cm, *it, &callback); 2608 cm, *it, &callback);
2609 RunOnOtherThread(task); 2609 RunOnOtherThread(task);
2610 EXPECT_TRUE(callback.did_run()); 2610 EXPECT_TRUE(callback.did_run());
2611 EXPECT_TRUE(callback.result()); 2611 EXPECT_TRUE(callback.result());
2612 } 2612 }
2613 2613
2614 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
Ryan Sleevi 2015/01/24 03:46:59 Can you add a description to this test explaining
yhirano 2015/01/26 04:45:25 Done.
2615 std::vector<CanonicalCookie*> cookies;
2616 // This cookie will be freed by the CookieMonster.
2617 cookies.push_back(CanonicalCookie::Create(url_google_, kValidCookieLine,
2618 Time::Now(), CookieOptions()));
2619 CanonicalCookie cookie = *cookies[0];
2620 scoped_refptr<NewMockPersistentCookieStore> store(
2621 new NewMockPersistentCookieStore);
2622 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
2623
2624 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback;
2625 ::testing::StrictMock<::testing::MockFunction<void(int)>> checkpoint;
2626 const std::string key =
2627 cookie_util::GetEffectiveDomain(url_google_.scheme(), url_google_.host());
2628
2629 {
2630 ::testing::InSequence s;
2631 EXPECT_CALL(checkpoint, Call(0));
2632 EXPECT_CALL(*store, Load(::testing::_));
2633 EXPECT_CALL(*store, LoadCookiesForKey(key, ::testing::_))
2634 .WillOnce(::testing::SaveArg<1>(&loaded_callback));
2635 EXPECT_CALL(checkpoint, Call(1));
2636 // LoadCookiesForKey will never be called, because all URLS below share
2637 // the same key.
2638 }
2639
2640 {
2641 GetCookieListCallback callback;
2642 checkpoint.Call(0);
2643 GetAllCookiesForURLTask(cm.get(), url_google_, &callback);
2644 checkpoint.Call(1);
Ryan Sleevi 2015/01/24 03:46:59 I'm confused; Why is this in a separate section th
yhirano 2015/01/26 04:45:25 (All line numbers represents line numbers in PS9 i
Ryan Sleevi 2015/01/26 19:49:54 [Same in mine]
yhirano 2015/01/27 02:07:10 Yes. I created blocks L2640-L2653, L2654-L2662, L2
2645 EXPECT_FALSE(callback.did_run());
Ryan Sleevi 2015/01/24 03:46:59 Historically, tests with EXPECTS on callback runni
yhirano 2015/01/26 04:45:25 Done.
2646 // Pass the cookies to the CookieMonster.
2647 loaded_callback.Run(cookies);
2648 // Now GetAllCookiesForURLTask is done.
2649 EXPECT_TRUE(callback.did_run());
2650 // See that the callback was called with the cookies.
2651 ASSERT_EQ(1u, callback.cookies().size());
2652 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0]));
2653 }
2654 {
2655 // Call the function with the same URL and see if it is done synchronously
Ryan Sleevi 2015/01/24 03:46:59 s/see if it/verify it/ The wording suggests it's
yhirano 2015/01/26 04:45:25 Done.
2656 // without calling LoadCookiesForKey.
2657 GetCookieListCallback callback;
2658 GetAllCookiesForURLTask(cm.get(), url_google_, &callback);
2659 EXPECT_TRUE(callback.did_run());
2660 ASSERT_EQ(1u, callback.cookies().size());
2661 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0]));
2662 }
2663 {
2664 // Call the function with an https URL and see if it is done synchronously
2665 // without calling LoadCookiesForKey.
2666 GetCookieListCallback callback;
2667 GetAllCookiesForURLTask(cm.get(), url_google_secure_, &callback);
2668 EXPECT_TRUE(callback.did_run());
2669 ASSERT_EQ(1u, callback.cookies().size());
2670 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0]));
2671 }
2672 {
2673 // Call the function with a ws URL and see if it is done synchronously
2674 // without calling LoadCookiesForKey.
2675 GetCookieListCallback callback;
2676 GetAllCookiesForURLTask(cm.get(), GURL(kUrlGoogleWebSocket), &callback);
2677 EXPECT_TRUE(callback.did_run());
2678 ASSERT_EQ(1u, callback.cookies().size());
2679 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0]));
2680 }
2681 {
2682 // Call the function with a wss URL and see if it is done synchronously
2683 // without calling LoadCookiesForKey.
2684 GetCookieListCallback callback;
2685 GetAllCookiesForURLTask(cm.get(), GURL(kUrlGoogleWebSocketSecure),
2686 &callback);
2687 EXPECT_TRUE(callback.did_run());
2688 ASSERT_EQ(1u, callback.cookies().size());
2689 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0]));
2690 }
Ryan Sleevi 2015/01/24 03:46:59 Should this code be refactored to a loop over the
yhirano 2015/01/26 04:45:25 Done.
2691 }
2692
2614 TEST_F(CookieMonsterTest, InvalidExpiryTime) { 2693 TEST_F(CookieMonsterTest, InvalidExpiryTime) {
2615 std::string cookie_line = 2694 std::string cookie_line =
2616 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; 2695 std::string(kValidCookieLine) + "; expires=Blarg arg arg";
2617 scoped_ptr<CanonicalCookie> cookie( 2696 scoped_ptr<CanonicalCookie> cookie(
2618 CanonicalCookie::Create(url_google_, cookie_line, Time::Now(), 2697 CanonicalCookie::Create(url_google_, cookie_line, Time::Now(),
2619 CookieOptions())); 2698 CookieOptions()));
2620 ASSERT_FALSE(cookie->IsPersistent()); 2699 ASSERT_FALSE(cookie->IsPersistent());
2621 } 2700 }
2622 2701
2623 // Test that CookieMonster writes session cookies into the underlying 2702 // Test that CookieMonster writes session cookies into the underlying
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
2879 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( 2958 scoped_ptr<CookieStore::CookieChangedSubscription> sub1(
2880 monster()->AddCallbackForCookie(test_url_, "abc", 2959 monster()->AddCallbackForCookie(test_url_, "abc",
2881 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); 2960 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
2882 SetCookie(monster(), test_url_, "abc=def"); 2961 SetCookie(monster(), test_url_, "abc=def");
2883 base::MessageLoop::current()->RunUntilIdle(); 2962 base::MessageLoop::current()->RunUntilIdle();
2884 EXPECT_EQ(1U, cookies0.size()); 2963 EXPECT_EQ(1U, cookies0.size());
2885 EXPECT_EQ(1U, cookies0.size()); 2964 EXPECT_EQ(1U, cookies0.size());
2886 } 2965 }
2887 2966
2888 } // namespace net 2967 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/cookies/cookie_store_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698