OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/browsing_data_appcache_helper.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/bind_helpers.h" | |
9 #include "base/stl_util.h" | |
10 #include "chrome/test/base/testing_profile.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 namespace { | |
14 class TestCompletionCallback { | |
15 public: | |
16 TestCompletionCallback() | |
17 : have_result_(false) { | |
18 } | |
19 | |
20 bool have_result() const { return have_result_; } | |
21 | |
22 void callback() { | |
23 have_result_ = true; | |
24 } | |
25 | |
26 private: | |
27 bool have_result_; | |
28 }; | |
29 | |
30 } // namespace | |
31 | |
32 typedef testing::Test CannedBrowsingDataAppCacheHelperTest; | |
33 | |
34 TEST_F(CannedBrowsingDataAppCacheHelperTest, SetInfo) { | |
35 TestingProfile profile; | |
36 | |
37 GURL manifest1("http://example1.com/manifest.xml"); | |
38 GURL manifest2("http://example2.com/path1/manifest.xml"); | |
39 GURL manifest3("http://example2.com/path2/manifest.xml"); | |
40 | |
41 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | |
42 new CannedBrowsingDataAppCacheHelper(&profile)); | |
43 helper->AddAppCache(manifest1); | |
44 helper->AddAppCache(manifest2); | |
45 helper->AddAppCache(manifest3); | |
46 | |
47 TestCompletionCallback callback; | |
48 helper->StartFetching(base::Bind(&TestCompletionCallback::callback, | |
49 base::Unretained(&callback))); | |
50 ASSERT_TRUE(callback.have_result()); | |
51 | |
52 std::map<GURL, appcache::AppCacheInfoVector>& collection = | |
53 helper->info_collection()->infos_by_origin; | |
54 | |
55 ASSERT_EQ(2u, collection.size()); | |
56 EXPECT_TRUE(ContainsKey(collection, manifest1.GetOrigin())); | |
57 ASSERT_EQ(1u, collection[manifest1.GetOrigin()].size()); | |
58 EXPECT_EQ(manifest1, collection[manifest1.GetOrigin()].at(0).manifest_url); | |
59 | |
60 EXPECT_TRUE(ContainsKey(collection, manifest2.GetOrigin())); | |
61 EXPECT_EQ(2u, collection[manifest2.GetOrigin()].size()); | |
62 std::set<GURL> manifest_results; | |
63 manifest_results.insert(collection[manifest2.GetOrigin()].at(0).manifest_url); | |
64 manifest_results.insert(collection[manifest2.GetOrigin()].at(1).manifest_url); | |
65 EXPECT_TRUE(ContainsKey(manifest_results, manifest2)); | |
66 EXPECT_TRUE(ContainsKey(manifest_results, manifest3)); | |
67 } | |
68 | |
69 TEST_F(CannedBrowsingDataAppCacheHelperTest, Unique) { | |
70 TestingProfile profile; | |
71 | |
72 GURL manifest("http://example.com/manifest.xml"); | |
73 | |
74 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | |
75 new CannedBrowsingDataAppCacheHelper(&profile)); | |
76 helper->AddAppCache(manifest); | |
77 helper->AddAppCache(manifest); | |
78 | |
79 TestCompletionCallback callback; | |
80 helper->StartFetching(base::Bind(&TestCompletionCallback::callback, | |
81 base::Unretained(&callback))); | |
82 ASSERT_TRUE(callback.have_result()); | |
83 | |
84 std::map<GURL, appcache::AppCacheInfoVector>& collection = | |
85 helper->info_collection()->infos_by_origin; | |
86 | |
87 ASSERT_EQ(1u, collection.size()); | |
88 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin())); | |
89 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size()); | |
90 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url); | |
91 } | |
92 | |
93 TEST_F(CannedBrowsingDataAppCacheHelperTest, Empty) { | |
94 TestingProfile profile; | |
95 | |
96 GURL manifest("http://example.com/manifest.xml"); | |
97 | |
98 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | |
99 new CannedBrowsingDataAppCacheHelper(&profile)); | |
100 | |
101 ASSERT_TRUE(helper->empty()); | |
102 helper->AddAppCache(manifest); | |
103 ASSERT_FALSE(helper->empty()); | |
104 helper->Reset(); | |
105 ASSERT_TRUE(helper->empty()); | |
106 } | |
107 | |
108 TEST_F(CannedBrowsingDataAppCacheHelperTest, IgnoreExtensionsAndDevTools) { | |
109 TestingProfile profile; | |
110 | |
111 GURL manifest1("chrome-extension://abcdefghijklmnopqrstuvwxyz/manifest.xml"); | |
112 GURL manifest2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/manifest.xml"); | |
113 | |
114 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | |
115 new CannedBrowsingDataAppCacheHelper(&profile)); | |
116 | |
117 ASSERT_TRUE(helper->empty()); | |
118 helper->AddAppCache(manifest1); | |
119 ASSERT_TRUE(helper->empty()); | |
120 helper->AddAppCache(manifest2); | |
121 ASSERT_TRUE(helper->empty()); | |
122 } | |
OLD | NEW |