OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/engagement/important_sites_usage_counter.h" | 5 #include "chrome/browser/engagement/important_sites_usage_counter.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
12 #include "base/threading/thread_task_runner_handle.h" | |
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 13 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
13 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | 17 #include "content/public/test/test_browser_thread_bundle.h" |
17 #include "storage/browser/quota/quota_manager_proxy.h" | 18 #include "storage/browser/quota/quota_manager_proxy.h" |
18 #include "storage/browser/test/mock_storage_client.h" | 19 #include "storage/browser/test/mock_storage_client.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 | 21 |
21 using ImportantDomainInfo = ImportantSitesUtil::ImportantDomainInfo; | 22 using ImportantDomainInfo = ImportantSitesUtil::ImportantDomainInfo; |
22 using content::BrowserThread; | 23 using content::BrowserThread; |
23 using content::DOMStorageContext; | 24 using content::DOMStorageContext; |
24 using storage::QuotaManager; | 25 using storage::QuotaManager; |
25 | 26 |
26 class ImportantSitesUsageCounterTest : public testing::Test { | 27 class ImportantSitesUsageCounterTest : public testing::Test { |
27 public: | 28 public: |
28 void SetUp() override { | 29 void SetUp() override { |
29 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
30 run_loop_.reset(new base::RunLoop()); | 31 run_loop_.reset(new base::RunLoop()); |
31 } | 32 } |
32 | 33 |
33 void TearDown() override { base::RunLoop().RunUntilIdle(); } | 34 void TearDown() override { base::RunLoop().RunUntilIdle(); } |
34 | 35 |
35 TestingProfile* profile() { return &profile_; } | 36 TestingProfile* profile() { return &profile_; } |
36 | 37 |
37 QuotaManager* CreateQuotaManager() { | 38 QuotaManager* CreateQuotaManager() { |
38 quota_manager_ = new QuotaManager( | 39 quota_manager_ = new QuotaManager(false, temp_dir_.GetPath(), |
39 false, temp_dir_.GetPath(), | 40 base::ThreadTaskRunnerHandle::Get(), |
40 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(), | 41 base::ThreadTaskRunnerHandle::Get(), |
41 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB).get(), nullptr, | 42 nullptr, storage::GetQuotaSettingsFunc()); |
42 storage::GetQuotaSettingsFunc()); | |
43 return quota_manager_.get(); | 43 return quota_manager_.get(); |
44 } | 44 } |
45 | 45 |
46 void RegisterClient(const std::vector<content::MockOriginData>& data) { | 46 void RegisterClient(const std::vector<content::MockOriginData>& data) { |
47 auto* client = new content::MockStorageClient( | 47 auto* client = new content::MockStorageClient( |
48 quota_manager_->proxy(), data.data(), storage::QuotaClient::kFileSystem, | 48 quota_manager_->proxy(), data.data(), storage::QuotaClient::kFileSystem, |
49 data.size()); | 49 data.size()); |
50 quota_manager_->proxy()->RegisterClient(client); | 50 quota_manager_->proxy()->RegisterClient(client); |
51 client->TouchAllOriginsAndNotify(); | 51 client->TouchAllOriginsAndNotify(); |
52 } | 52 } |
(...skipping 22 matching lines...) Expand all Loading... | |
75 } | 75 } |
76 | 76 |
77 void WaitForResult() { | 77 void WaitForResult() { |
78 run_loop_->Run(); | 78 run_loop_->Run(); |
79 run_loop_.reset(new base::RunLoop()); | 79 run_loop_.reset(new base::RunLoop()); |
80 } | 80 } |
81 | 81 |
82 const std::vector<ImportantDomainInfo>& domain_info() { return domain_info_; } | 82 const std::vector<ImportantDomainInfo>& domain_info() { return domain_info_; } |
83 | 83 |
84 private: | 84 private: |
85 content::TestBrowserThreadBundle thread_bundle_; | 85 content::TestBrowserThreadBundle thread_bundle; |
fdoray
2017/06/27 13:28:56
Do not remove the trailing underscore.
| |
86 TestingProfile profile_; | 86 TestingProfile profile_; |
87 base::ScopedTempDir temp_dir_; | 87 base::ScopedTempDir temp_dir_; |
88 scoped_refptr<QuotaManager> quota_manager_; | 88 scoped_refptr<QuotaManager> quota_manager_; |
89 std::vector<ImportantDomainInfo> domain_info_; | 89 std::vector<ImportantDomainInfo> domain_info_; |
90 std::unique_ptr<base::RunLoop> run_loop_; | 90 std::unique_ptr<base::RunLoop> run_loop_; |
91 }; | 91 }; |
92 | 92 |
93 TEST_F(ImportantSitesUsageCounterTest, PopulateUsage) { | 93 TEST_F(ImportantSitesUsageCounterTest, PopulateUsage) { |
94 std::vector<ImportantDomainInfo> important_sites; | 94 std::vector<ImportantDomainInfo> important_sites; |
95 ImportantDomainInfo i1; | 95 ImportantDomainInfo i1; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 // The first important site is example.com. It uses 1B quota storage for | 128 // The first important site is example.com. It uses 1B quota storage for |
129 // http://example.com/, 2B for https://example.com and 4B for | 129 // http://example.com/, 2B for https://example.com and 4B for |
130 // https://maps.example.com. On top of that it uses 16B local storage. | 130 // https://maps.example.com. On top of that it uses 16B local storage. |
131 EXPECT_EQ("example.com", domain_info()[0].registerable_domain); | 131 EXPECT_EQ("example.com", domain_info()[0].registerable_domain); |
132 EXPECT_EQ(1 + 2 + 4 + 16, domain_info()[0].usage); | 132 EXPECT_EQ(1 + 2 + 4 + 16, domain_info()[0].usage); |
133 // The second important site is somethingelse.com but it doesn't use any | 133 // The second important site is somethingelse.com but it doesn't use any |
134 // quota. We still expect it to be returned and not dropped. | 134 // quota. We still expect it to be returned and not dropped. |
135 EXPECT_EQ("somethingelse.com", domain_info()[1].registerable_domain); | 135 EXPECT_EQ("somethingelse.com", domain_info()[1].registerable_domain); |
136 EXPECT_EQ(0, domain_info()[1].usage); | 136 EXPECT_EQ(0, domain_info()[1].usage); |
137 } | 137 } |
OLD | NEW |