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 1896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1921 TEST_F(CookieMonsterTest, HistogramCheck) { | 1922 TEST_F(CookieMonsterTest, HistogramCheck) { |
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 scoped_ptr<base::HistogramSamples> samples1( |
1932 expired_histogram->SnapshotSample(&histogram_set_1); | 1933 expired_histogram->SnapshotSamples()); |
1933 ASSERT_TRUE(SetCookieWithDetails( | 1934 ASSERT_TRUE(SetCookieWithDetails( |
1934 cm, GURL("http://fake.a.url"), "a", "b", "a.url", "/", | 1935 cm, GURL("http://fake.a.url"), "a", "b", "a.url", "/", |
1935 base::Time::Now() + base::TimeDelta::FromMinutes(59), | 1936 base::Time::Now() + base::TimeDelta::FromMinutes(59), |
1936 false, false)); | 1937 false, false)); |
1937 | 1938 |
1938 base::Histogram::SampleSet histogram_set_2; | 1939 scoped_ptr<base::HistogramSamples> samples2( |
1939 expired_histogram->SnapshotSample(&histogram_set_2); | 1940 expired_histogram->SnapshotSamples()); |
1940 EXPECT_EQ(histogram_set_1.TotalCount() + 1, | 1941 EXPECT_EQ(samples1->TotalCount() + 1, samples2->TotalCount()); |
1941 histogram_set_2.TotalCount()); | |
1942 | 1942 |
1943 // kValidCookieLine creates a session cookie. | 1943 // kValidCookieLine creates a session cookie. |
1944 ASSERT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); | 1944 ASSERT_TRUE(SetCookie(cm, url_google_, kValidCookieLine)); |
1945 expired_histogram->SnapshotSample(&histogram_set_1); | 1945 |
1946 EXPECT_EQ(histogram_set_2.TotalCount(), | 1946 scoped_ptr<base::HistogramSamples> samples3( |
1947 histogram_set_1.TotalCount()); | 1947 expired_histogram->SnapshotSamples()); |
| 1948 EXPECT_EQ(samples2->TotalCount(), samples3->TotalCount()); |
1948 } | 1949 } |
1949 | 1950 |
1950 namespace { | 1951 namespace { |
1951 | 1952 |
1952 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { | 1953 class MultiThreadedCookieMonsterTest : public CookieMonsterTest { |
1953 public: | 1954 public: |
1954 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} | 1955 MultiThreadedCookieMonsterTest() : other_thread_("CMTthread") {} |
1955 | 1956 |
1956 // Helper methods for calling the asynchronous CookieMonster methods | 1957 // Helper methods for calling the asynchronous CookieMonster methods |
1957 // from a different thread. | 1958 // 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); | 2256 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); |
2256 | 2257 |
2257 // Create some non-persistent cookies and check that they don't go to the | 2258 // Create some non-persistent cookies and check that they don't go to the |
2258 // persistent storage. | 2259 // persistent storage. |
2259 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); | 2260 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); |
2260 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); | 2261 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); |
2261 EXPECT_EQ(5u, store->commands().size()); | 2262 EXPECT_EQ(5u, store->commands().size()); |
2262 } | 2263 } |
2263 | 2264 |
2264 } // namespace net | 2265 } // namespace net |
OLD | NEW |