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_store_unittest.h" | 5 #include "net/cookies/cookie_store_unittest.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/metrics/histogram_samples.h" |
15 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
16 #include "base/string_tokenizer.h" | 17 #include "base/string_tokenizer.h" |
17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
18 #include "base/time.h" | 19 #include "base/time.h" |
19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
20 #include "net/cookies/canonical_cookie.h" | 21 #include "net/cookies/canonical_cookie.h" |
21 #include "net/cookies/cookie_monster.h" | 22 #include "net/cookies/cookie_monster.h" |
22 #include "net/cookies/cookie_monster_store_test.h" // For CookieStore mock | 23 #include "net/cookies/cookie_monster_store_test.h" // For CookieStore mock |
23 #include "net/cookies/cookie_util.h" | 24 #include "net/cookies/cookie_util.h" |
24 #include "net/cookies/parsed_cookie.h" | 25 #include "net/cookies/parsed_cookie.h" |
(...skipping 1897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); | 1923 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); |
1923 // Should match call in InitializeHistograms, but doesn't really matter | 1924 // Should match call in InitializeHistograms, but doesn't really matter |
1924 // since the histogram should have been initialized by the CM construction | 1925 // since the histogram should have been initialized by the CM construction |
1925 // above. | 1926 // above. |
1926 base::Histogram* expired_histogram = | 1927 base::Histogram* expired_histogram = |
1927 base::Histogram::FactoryGet( | 1928 base::Histogram::FactoryGet( |
1928 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, | 1929 "Cookie.ExpirationDurationMinutes", 1, 10 * 365 * 24 * 60, 50, |
1929 base::Histogram::kUmaTargetedHistogramFlag); | 1930 base::Histogram::kUmaTargetedHistogramFlag); |
1930 | 1931 |
1931 base::Histogram::SampleSet histogram_set_1; | 1932 base::Histogram::SampleSet histogram_set_1; |
1932 expired_histogram->SnapshotSample(&histogram_set_1); | 1933 scoped_ptr<base::HistogramSamples> samples1( |
| 1934 expired_histogram->SnapshotSamples()); |
1933 ASSERT_TRUE(SetCookieWithDetails( | 1935 ASSERT_TRUE(SetCookieWithDetails( |
1934 cm, GURL("http://fake.a.url"), "a", "b", "a.url", "/", | 1936 cm, GURL("http://fake.a.url"), "a", "b", "a.url", "/", |
1935 base::Time::Now() + base::TimeDelta::FromMinutes(59), | 1937 base::Time::Now() + base::TimeDelta::FromMinutes(59), |
1936 false, false)); | 1938 false, false)); |
1937 | 1939 |
1938 base::Histogram::SampleSet histogram_set_2; | 1940 scoped_ptr<base::HistogramSamples> samples2( |
1939 expired_histogram->SnapshotSample(&histogram_set_2); | 1941 expired_histogram->SnapshotSamples()); |
1940 EXPECT_EQ(histogram_set_1.TotalCount() + 1, | 1942 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); |
1941 histogram_set_2.TotalCount()); | |
1942 | 1943 |
1943 // kValidCookieLine creates a session cookie. | 1944 // kValidCookieLine creates a session cookie. |
1944 ASSERT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); | 1945 ASSERT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); |
1945 expired_histogram->SnapshotSample(&histogram_set_1); | 1946 |
1946 EXPECT_EQ(histogram_set_2.TotalCount(), | 1947 scoped_ptr<base::HistogramSamples> samples3( |
1947 histogram_set_1.TotalCount()); | 1948 expired_histogram->SnapshotSamples()); |
| 1949 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount()); |
1948 } | 1950 } |
1949 | 1951 |
1950 namespace { | 1952 namespace { |
1951 | 1953 |
1952 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { | 1954 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { |
1953 public: | 1955 public: |
1954 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} | 1956 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} |
1955 | 1957 |
1956 // Helper methods for calling the asynchronous CookieMonster methods | 1958 // Helper methods for calling the asynchronous CookieMonster methods |
1957 // from a different thread. | 1959 // from a different thread. |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2255 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); | 2257 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); |
2256 | 2258 |
2257 // Create some non-persistent cookies and check that they don't go to the | 2259 // Create some non-persistent cookies and check that they don't go to the |
2258 // persistent storage. | 2260 // persistent storage. |
2259 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); | 2261 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); |
2260 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); | 2262 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); |
2261 EXPECT_EQ(5u, store->commands().size()); | 2263 EXPECT_EQ(5u, store->commands().size()); |
2262 } | 2264 } |
2263 | 2265 |
2264 } // namespace net | 2266 } // namespace net |
OLD | NEW |