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 "chrome/browser/browsing_data/browsing_data_appcache_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
15 #include "content/public/test/test_utils.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace { | 18 namespace { |
18 class TestCompletionCallback { | 19 class TestCompletionCallback { |
19 public: | 20 public: |
20 TestCompletionCallback() {} | 21 TestCompletionCallback() {} |
21 | 22 |
22 bool have_result() const { return info_collection_.get(); } | 23 bool have_result() const { return info_collection_.get(); } |
23 | 24 |
24 content::AppCacheInfoCollection* info_collection() const { | 25 content::AppCacheInfoCollection* info_collection() const { |
(...skipping 11 matching lines...) Expand all Loading... | |
36 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback); | 37 DISALLOW_COPY_AND_ASSIGN(TestCompletionCallback); |
37 }; | 38 }; |
38 | 39 |
39 } // namespace | 40 } // namespace |
40 | 41 |
41 class CannedBrowsingDataAppCacheHelperTest : public testing::Test { | 42 class CannedBrowsingDataAppCacheHelperTest : public testing::Test { |
42 public: | 43 public: |
43 CannedBrowsingDataAppCacheHelperTest() | 44 CannedBrowsingDataAppCacheHelperTest() |
44 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) {} | 45 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) {} |
45 | 46 |
47 void TearDown() override { | |
48 // Make sure we run all pending tasks on IO thread before testing | |
49 // profile is destructed. | |
50 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); | |
kinuko
2016/07/21 03:06:25
This wasn't necessary before this CL because Testi
| |
51 } | |
52 | |
46 content::TestBrowserThreadBundle thread_bundle_; | 53 content::TestBrowserThreadBundle thread_bundle_; |
mmenke
2016/07/21 15:27:20
Doesn't really matter, but these should probably b
kinuko
2016/07/22 04:16:20
Done.
| |
54 TestingProfile profile; | |
mmenke
2016/07/21 15:27:20
profile_
kinuko
2016/07/22 04:16:20
Done.
| |
47 }; | 55 }; |
48 | 56 |
49 TEST_F(CannedBrowsingDataAppCacheHelperTest, SetInfo) { | 57 TEST_F(CannedBrowsingDataAppCacheHelperTest, SetInfo) { |
50 TestingProfile profile; | |
51 | |
52 GURL manifest1("http://example1.com/manifest.xml"); | 58 GURL manifest1("http://example1.com/manifest.xml"); |
53 GURL manifest2("http://example2.com/path1/manifest.xml"); | 59 GURL manifest2("http://example2.com/path1/manifest.xml"); |
54 GURL manifest3("http://example2.com/path2/manifest.xml"); | 60 GURL manifest3("http://example2.com/path2/manifest.xml"); |
55 | 61 |
56 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | 62 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
57 new CannedBrowsingDataAppCacheHelper(&profile)); | 63 new CannedBrowsingDataAppCacheHelper(&profile)); |
58 helper->AddAppCache(manifest1); | 64 helper->AddAppCache(manifest1); |
59 helper->AddAppCache(manifest2); | 65 helper->AddAppCache(manifest2); |
60 helper->AddAppCache(manifest3); | 66 helper->AddAppCache(manifest3); |
61 | 67 |
(...skipping 13 matching lines...) Expand all Loading... | |
75 EXPECT_TRUE(ContainsKey(collection, manifest2.GetOrigin())); | 81 EXPECT_TRUE(ContainsKey(collection, manifest2.GetOrigin())); |
76 EXPECT_EQ(2u, collection[manifest2.GetOrigin()].size()); | 82 EXPECT_EQ(2u, collection[manifest2.GetOrigin()].size()); |
77 std::set<GURL> manifest_results; | 83 std::set<GURL> manifest_results; |
78 manifest_results.insert(collection[manifest2.GetOrigin()].at(0).manifest_url); | 84 manifest_results.insert(collection[manifest2.GetOrigin()].at(0).manifest_url); |
79 manifest_results.insert(collection[manifest2.GetOrigin()].at(1).manifest_url); | 85 manifest_results.insert(collection[manifest2.GetOrigin()].at(1).manifest_url); |
80 EXPECT_TRUE(ContainsKey(manifest_results, manifest2)); | 86 EXPECT_TRUE(ContainsKey(manifest_results, manifest2)); |
81 EXPECT_TRUE(ContainsKey(manifest_results, manifest3)); | 87 EXPECT_TRUE(ContainsKey(manifest_results, manifest3)); |
82 } | 88 } |
83 | 89 |
84 TEST_F(CannedBrowsingDataAppCacheHelperTest, Unique) { | 90 TEST_F(CannedBrowsingDataAppCacheHelperTest, Unique) { |
85 TestingProfile profile; | |
86 | |
87 GURL manifest("http://example.com/manifest.xml"); | 91 GURL manifest("http://example.com/manifest.xml"); |
88 | 92 |
89 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | 93 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
90 new CannedBrowsingDataAppCacheHelper(&profile)); | 94 new CannedBrowsingDataAppCacheHelper(&profile)); |
91 helper->AddAppCache(manifest); | 95 helper->AddAppCache(manifest); |
92 helper->AddAppCache(manifest); | 96 helper->AddAppCache(manifest); |
93 | 97 |
94 TestCompletionCallback callback; | 98 TestCompletionCallback callback; |
95 helper->StartFetching(base::Bind(&TestCompletionCallback::set_info_collection, | 99 helper->StartFetching(base::Bind(&TestCompletionCallback::set_info_collection, |
96 base::Unretained(&callback))); | 100 base::Unretained(&callback))); |
97 ASSERT_TRUE(callback.have_result()); | 101 ASSERT_TRUE(callback.have_result()); |
98 | 102 |
99 std::map<GURL, content::AppCacheInfoVector>& collection = | 103 std::map<GURL, content::AppCacheInfoVector>& collection = |
100 callback.info_collection()->infos_by_origin; | 104 callback.info_collection()->infos_by_origin; |
101 | 105 |
102 ASSERT_EQ(1u, collection.size()); | 106 ASSERT_EQ(1u, collection.size()); |
103 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin())); | 107 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin())); |
104 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size()); | 108 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size()); |
105 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url); | 109 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url); |
106 } | 110 } |
107 | 111 |
108 TEST_F(CannedBrowsingDataAppCacheHelperTest, Empty) { | 112 TEST_F(CannedBrowsingDataAppCacheHelperTest, Empty) { |
109 TestingProfile profile; | |
110 | |
111 GURL manifest("http://example.com/manifest.xml"); | 113 GURL manifest("http://example.com/manifest.xml"); |
112 | 114 |
113 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | 115 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
114 new CannedBrowsingDataAppCacheHelper(&profile)); | 116 new CannedBrowsingDataAppCacheHelper(&profile)); |
115 | 117 |
116 ASSERT_TRUE(helper->empty()); | 118 ASSERT_TRUE(helper->empty()); |
117 helper->AddAppCache(manifest); | 119 helper->AddAppCache(manifest); |
118 ASSERT_FALSE(helper->empty()); | 120 ASSERT_FALSE(helper->empty()); |
119 helper->Reset(); | 121 helper->Reset(); |
120 ASSERT_TRUE(helper->empty()); | 122 ASSERT_TRUE(helper->empty()); |
121 } | 123 } |
122 | 124 |
123 TEST_F(CannedBrowsingDataAppCacheHelperTest, Delete) { | 125 TEST_F(CannedBrowsingDataAppCacheHelperTest, Delete) { |
124 TestingProfile profile; | |
125 | |
126 GURL manifest1("http://example.com/manifest1.xml"); | 126 GURL manifest1("http://example.com/manifest1.xml"); |
127 GURL manifest2("http://foo.example.com/manifest2.xml"); | 127 GURL manifest2("http://foo.example.com/manifest2.xml"); |
128 GURL manifest3("http://bar.example.com/manifest3.xml"); | 128 GURL manifest3("http://bar.example.com/manifest3.xml"); |
129 | 129 |
130 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | 130 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
131 new CannedBrowsingDataAppCacheHelper(&profile)); | 131 new CannedBrowsingDataAppCacheHelper(&profile)); |
132 | 132 |
133 EXPECT_TRUE(helper->empty()); | 133 EXPECT_TRUE(helper->empty()); |
134 helper->AddAppCache(manifest1); | 134 helper->AddAppCache(manifest1); |
135 helper->AddAppCache(manifest2); | 135 helper->AddAppCache(manifest2); |
136 helper->AddAppCache(manifest3); | 136 helper->AddAppCache(manifest3); |
137 EXPECT_FALSE(helper->empty()); | 137 EXPECT_FALSE(helper->empty()); |
138 EXPECT_EQ(3u, helper->GetAppCacheCount()); | 138 EXPECT_EQ(3u, helper->GetAppCacheCount()); |
139 helper->DeleteAppCacheGroup(manifest2); | 139 helper->DeleteAppCacheGroup(manifest2); |
140 EXPECT_EQ(2u, helper->GetAppCacheCount()); | 140 EXPECT_EQ(2u, helper->GetAppCacheCount()); |
141 EXPECT_FALSE(ContainsKey(helper->GetOriginAppCacheInfoMap(), manifest2)); | 141 EXPECT_FALSE(ContainsKey(helper->GetOriginAppCacheInfoMap(), manifest2)); |
142 } | 142 } |
143 | 143 |
144 TEST_F(CannedBrowsingDataAppCacheHelperTest, IgnoreExtensionsAndDevTools) { | 144 TEST_F(CannedBrowsingDataAppCacheHelperTest, IgnoreExtensionsAndDevTools) { |
145 TestingProfile profile; | |
146 | |
147 GURL manifest1("chrome-extension://abcdefghijklmnopqrstuvwxyz/manifest.xml"); | 145 GURL manifest1("chrome-extension://abcdefghijklmnopqrstuvwxyz/manifest.xml"); |
148 GURL manifest2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/manifest.xml"); | 146 GURL manifest2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/manifest.xml"); |
149 | 147 |
150 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | 148 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
151 new CannedBrowsingDataAppCacheHelper(&profile)); | 149 new CannedBrowsingDataAppCacheHelper(&profile)); |
152 | 150 |
153 ASSERT_TRUE(helper->empty()); | 151 ASSERT_TRUE(helper->empty()); |
154 helper->AddAppCache(manifest1); | 152 helper->AddAppCache(manifest1); |
155 ASSERT_TRUE(helper->empty()); | 153 ASSERT_TRUE(helper->empty()); |
156 helper->AddAppCache(manifest2); | 154 helper->AddAppCache(manifest2); |
157 ASSERT_TRUE(helper->empty()); | 155 ASSERT_TRUE(helper->empty()); |
158 } | 156 } |
OLD | NEW |