Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/bind.h" | |
| 6 #include "base/message_loop.h" | |
| 7 #include "base/perftimer.h" | |
| 8 #include "base/scoped_temp_dir.h" | |
| 9 #include "base/stringprintf.h" | |
| 10 #include "base/synchronization/waitable_event.h" | |
| 11 #include "base/test/thread_test_helper.h" | |
| 12 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | |
| 13 #include "chrome/common/chrome_constants.h" | |
| 14 #include "content/browser/browser_thread.h" | |
| 15 #include "googleurl/src/gurl.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 class SQLitePersistentCookieStorePerfTest : public testing::Test { | |
| 19 public: | |
| 20 SQLitePersistentCookieStorePerfTest() | |
| 21 : ui_thread_(BrowserThread::UI), | |
|
erikwright (departed)
2011/10/14 01:34:28
I'm surprised you need a UI thread here.
guohui
2011/10/14 15:39:00
Done.
| |
| 22 db_thread_(BrowserThread::DB), | |
| 23 io_thread_(BrowserThread::IO), | |
| 24 loaded_event_(false, false), | |
| 25 key_loaded_event_(false, false) { | |
| 26 } | |
| 27 | |
| 28 void OnLoaded( | |
| 29 const std::vector<net::CookieMonster::CanonicalCookie*>& cookies) { | |
| 30 cookies_ = cookies; | |
| 31 loaded_event_.Signal(); | |
| 32 } | |
| 33 | |
| 34 void OnKeyLoaded( | |
| 35 const std::vector<net::CookieMonster::CanonicalCookie*>& cookies) { | |
| 36 cookies_ = cookies; | |
| 37 key_loaded_event_.Signal(); | |
| 38 } | |
| 39 | |
| 40 void Load() { | |
| 41 store_->Load(base::Bind(&SQLitePersistentCookieStorePerfTest::OnLoaded, | |
| 42 base::Unretained(this))); | |
| 43 loaded_event_.Wait(); | |
| 44 } | |
| 45 | |
| 46 virtual void SetUp() { | |
| 47 ui_thread_.Start(); | |
| 48 db_thread_.Start(); | |
| 49 io_thread_.Start(); | |
| 50 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 51 store_ = new SQLitePersistentCookieStore( | |
| 52 temp_dir_.path().Append(chrome::kCookieFilename)); | |
| 53 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | |
| 54 Load(); | |
| 55 ASSERT_EQ(0u, cookies_.size()); | |
| 56 // Creates 15000 cookies from 300 eTLD+1s. | |
| 57 base::Time t = base::Time::Now(); | |
| 58 for (int domain_num = 0; domain_num < 300; domain_num++) { | |
| 59 std::string domain_name(base::StringPrintf(".domain_%d.com", domain_num)); | |
| 60 GURL gurl("www" + domain_name); | |
| 61 for (int cookie_num = 0; cookie_num < 50; ++cookie_num) { | |
| 62 t += base::TimeDelta::FromInternalValue(10); | |
| 63 store_->AddCookie( | |
| 64 net::CookieMonster::CanonicalCookie(gurl, | |
| 65 base::StringPrintf("Cookie_%d", cookie_num), "1", | |
| 66 domain_name, "/", std::string(), std::string(), | |
| 67 t, t, t, false, false, true)); | |
| 68 } | |
| 69 } | |
| 70 // Replace the store effectively destroying the current one and forcing it | |
| 71 // to write it's data to disk. | |
| 72 store_ = NULL; | |
| 73 scoped_refptr<base::ThreadTestHelper> helper( | |
| 74 new base::ThreadTestHelper( | |
| 75 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB))); | |
| 76 // Make sure we wait until the destructor has run. | |
| 77 ASSERT_TRUE(helper->Run()); | |
| 78 | |
| 79 store_ = new SQLitePersistentCookieStore( | |
| 80 temp_dir_.path().Append(chrome::kCookieFilename)); | |
| 81 } | |
| 82 | |
| 83 protected: | |
| 84 BrowserThread ui_thread_; | |
| 85 BrowserThread db_thread_; | |
| 86 BrowserThread io_thread_; | |
| 87 base::WaitableEvent loaded_event_; | |
| 88 base::WaitableEvent key_loaded_event_; | |
| 89 std::vector<net::CookieMonster::CanonicalCookie*> cookies_; | |
| 90 ScopedTempDir temp_dir_; | |
| 91 scoped_refptr<SQLitePersistentCookieStore> store_; | |
| 92 }; | |
| 93 | |
| 94 // Test the performance of priority load of cookies for a specfic domain key | |
| 95 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadForKeyPerformance) { | |
| 96 PerfTimeLogger timer("Load cookies for a single eTLD+1"); | |
|
erikwright (departed)
2011/10/14 01:34:28
To be meaningful, you would need to do this multip
guohui
2011/10/14 15:39:00
Done.
| |
| 97 store_->LoadCookiesForKey("domain_1.com", | |
| 98 base::Bind(&SQLitePersistentCookieStorePerfTest::OnKeyLoaded, | |
| 99 base::Unretained(this))); | |
| 100 key_loaded_event_.Wait(); | |
| 101 timer.Done(); | |
| 102 | |
| 103 ASSERT_EQ(50U, cookies_.size()); | |
| 104 } | |
| 105 | |
| 106 // Test the performance of load | |
| 107 TEST_F(SQLitePersistentCookieStorePerfTest, TestLoadPerformance) { | |
| 108 PerfTimeLogger timer("Load all cookies"); | |
| 109 Load(); | |
| 110 timer.Done(); | |
| 111 | |
| 112 ASSERT_EQ(15000U, cookies_.size()); | |
| 113 } | |
| OLD | NEW |