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 "testing/gtest/include/gtest/gtest.h" | |
6 | |
7 #include "base/memory/scoped_callback_factory.h" | |
8 #include "base/message_loop_proxy.h" | |
9 #include "base/scoped_temp_dir.h" | |
10 #include "chrome/browser/browsing_data_quota_helper_impl.h" | |
11 #include "webkit/quota/mock_storage_client.h" | |
12 #include "webkit/quota/quota_manager.h" | |
13 | |
14 class BrowsingDataQuotaHelperTest : public testing::Test { | |
15 public: | |
16 typedef BrowsingDataQuotaHelper::QuotaInfo QuotaInfo; | |
17 typedef BrowsingDataQuotaHelper::QuotaInfoList QuotaInfoList; | |
18 | |
19 BrowsingDataQuotaHelperTest() | |
20 : ui_thread_(BrowserThread::UI, &message_loop_), | |
21 db_thread_(BrowserThread::DB, &message_loop_), | |
22 io_thread_(BrowserThread::IO, &message_loop_), | |
23 fetching_completed_(true), | |
24 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { } | |
25 | |
26 virtual ~BrowsingDataQuotaHelperTest() { } | |
27 | |
28 virtual void SetUp() OVERRIDE { | |
29 EXPECT_TRUE(dir_.CreateUniqueTempDir()); | |
30 quota_manager_ = new quota::QuotaManager( | |
31 false, dir_.path(), | |
32 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | |
33 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB), | |
34 NULL); | |
35 helper_ = new BrowsingDataQuotaHelperImpl( | |
36 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI), | |
37 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO), | |
38 quota_manager_); | |
39 } | |
40 | |
41 virtual void TearDown() OVERRIDE { | |
42 helper_ = NULL; | |
43 quota_manager_ = NULL; | |
44 quota_info_.clear(); | |
45 } | |
46 | |
47 protected: | |
48 const QuotaInfoList& quota_info() { | |
49 return quota_info_; | |
50 } | |
51 | |
52 bool fetching_completed() { | |
kinuko
2011/08/02 09:09:30
nit: could be a const method?
tzik
2011/08/03 04:15:00
Done.
| |
53 return fetching_completed_; | |
54 } | |
55 | |
56 void StartFetching() { | |
57 fetching_completed_ = false; | |
58 helper_->StartFetching( | |
59 callback_factory_.NewCallback( | |
60 &BrowsingDataQuotaHelperTest::FetchCompleted)); | |
61 } | |
62 | |
63 void RegisterClient(const quota::MockOriginData* data, std::size_t data_len) { | |
64 quota::MockStorageClient* client = | |
65 new quota::MockStorageClient( | |
66 quota_manager_->proxy(), data, data_len); | |
67 quota_manager_->proxy()->RegisterClient(client); | |
68 client->NotifyAllOrigins(); | |
69 } | |
70 | |
71 private: | |
72 void FetchCompleted(const QuotaInfoList& quota_info) { | |
73 quota_info_ = quota_info; | |
74 fetching_completed_ = true; | |
75 } | |
76 | |
77 MessageLoop message_loop_; | |
78 BrowserThread ui_thread_; | |
79 BrowserThread db_thread_; | |
80 BrowserThread io_thread_; | |
81 scoped_refptr<quota::QuotaManager> quota_manager_; | |
82 | |
83 ScopedTempDir dir_; | |
84 scoped_refptr<BrowsingDataQuotaHelper> helper_; | |
85 | |
86 bool fetching_completed_; | |
87 QuotaInfoList quota_info_; | |
88 base::ScopedCallbackFactory<BrowsingDataQuotaHelperTest> callback_factory_; | |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(BrowsingDataQuotaHelperTest); | |
91 }; | |
92 | |
93 TEST_F(BrowsingDataQuotaHelperTest, Empty) { | |
94 StartFetching(); | |
95 MessageLoop::current()->RunAllPending(); | |
96 EXPECT_TRUE(fetching_completed()); | |
97 EXPECT_TRUE(quota_info().empty()); | |
98 } | |
99 | |
100 TEST_F(BrowsingDataQuotaHelperTest, FetchData) { | |
101 const quota::MockOriginData kOrigins[] = { | |
102 {"http://example.com/", quota::kStorageTypeTemporary, 1}, | |
103 {"https://example.com/", quota::kStorageTypeTemporary, 10}, | |
104 {"http://example.com/", quota::kStorageTypePersistent, 100}, | |
105 {"http://example2.com/", quota::kStorageTypeTemporary, 1000}, | |
106 }; | |
107 | |
108 RegisterClient(kOrigins, arraysize(kOrigins)); | |
109 StartFetching(); | |
110 MessageLoop::current()->RunAllPending(); | |
111 EXPECT_TRUE(fetching_completed()); | |
112 | |
113 std::set<QuotaInfo> expected, actual; | |
114 actual.insert(quota_info().begin(), quota_info().end()); | |
115 expected.insert(QuotaInfo("example.com", 11, 100)); | |
116 expected.insert(QuotaInfo("example2.com", 1000, 0)); | |
117 EXPECT_TRUE(expected == actual); | |
118 } | |
OLD | NEW |