OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_appcache_helper.h" | 5 #include "chrome/browser/browsing_data_appcache_helper.h" |
6 | 6 |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "chrome/test/testing_profile.h" | 8 #include "chrome/test/testing_profile.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 TEST(CannedBrowsingDataAppCacheHelperTest, SetInfo) { | 30 TEST(CannedBrowsingDataAppCacheHelperTest, SetInfo) { |
31 TestingProfile profile; | 31 TestingProfile profile; |
32 | 32 |
33 GURL manifest1("http://example1.com/manifest.xml"); | 33 GURL manifest1("http://example1.com/manifest.xml"); |
34 GURL manifest2("http://example2.com/path1/manifest.xml"); | 34 GURL manifest2("http://example2.com/path1/manifest.xml"); |
35 GURL manifest3("http://example2.com/path2/manifest.xml"); | 35 GURL manifest3("http://example2.com/path2/manifest.xml"); |
36 | 36 |
37 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper = | 37 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
38 new CannedBrowsingDataAppCacheHelper(&profile); | 38 new CannedBrowsingDataAppCacheHelper(&profile)); |
39 helper->AddAppCache(manifest1); | 39 helper->AddAppCache(manifest1); |
40 helper->AddAppCache(manifest2); | 40 helper->AddAppCache(manifest2); |
41 helper->AddAppCache(manifest3); | 41 helper->AddAppCache(manifest3); |
42 | 42 |
43 TestCompletionCallback callback; | 43 TestCompletionCallback callback; |
44 helper->StartFetching( | 44 helper->StartFetching( |
45 NewCallback(&callback, &TestCompletionCallback::callback)); | 45 NewCallback(&callback, &TestCompletionCallback::callback)); |
46 ASSERT_TRUE(callback.have_result()); | 46 ASSERT_TRUE(callback.have_result()); |
47 | 47 |
48 std::map<GURL, appcache::AppCacheInfoVector>& collection = | 48 std::map<GURL, appcache::AppCacheInfoVector>& collection = |
(...skipping 11 matching lines...) Expand all Loading... |
60 manifest_results.insert(collection[manifest2.GetOrigin()].at(1).manifest_url); | 60 manifest_results.insert(collection[manifest2.GetOrigin()].at(1).manifest_url); |
61 EXPECT_TRUE(ContainsKey(manifest_results, manifest2)); | 61 EXPECT_TRUE(ContainsKey(manifest_results, manifest2)); |
62 EXPECT_TRUE(ContainsKey(manifest_results, manifest3)); | 62 EXPECT_TRUE(ContainsKey(manifest_results, manifest3)); |
63 } | 63 } |
64 | 64 |
65 TEST(CannedBrowsingDataAppCacheHelperTest, Unique) { | 65 TEST(CannedBrowsingDataAppCacheHelperTest, Unique) { |
66 TestingProfile profile; | 66 TestingProfile profile; |
67 | 67 |
68 GURL manifest("http://example.com/manifest.xml"); | 68 GURL manifest("http://example.com/manifest.xml"); |
69 | 69 |
70 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper = | 70 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
71 new CannedBrowsingDataAppCacheHelper(&profile); | 71 new CannedBrowsingDataAppCacheHelper(&profile)); |
72 helper->AddAppCache(manifest); | 72 helper->AddAppCache(manifest); |
73 helper->AddAppCache(manifest); | 73 helper->AddAppCache(manifest); |
74 | 74 |
75 TestCompletionCallback callback; | 75 TestCompletionCallback callback; |
76 helper->StartFetching( | 76 helper->StartFetching( |
77 NewCallback(&callback, &TestCompletionCallback::callback)); | 77 NewCallback(&callback, &TestCompletionCallback::callback)); |
78 ASSERT_TRUE(callback.have_result()); | 78 ASSERT_TRUE(callback.have_result()); |
79 | 79 |
80 std::map<GURL, appcache::AppCacheInfoVector>& collection = | 80 std::map<GURL, appcache::AppCacheInfoVector>& collection = |
81 helper->info_collection()->infos_by_origin; | 81 helper->info_collection()->infos_by_origin; |
82 | 82 |
83 ASSERT_EQ(1u, collection.size()); | 83 ASSERT_EQ(1u, collection.size()); |
84 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin())); | 84 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin())); |
85 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size()); | 85 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size()); |
86 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url); | 86 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url); |
87 } | 87 } |
88 | 88 |
89 TEST(CannedBrowsingDataAppCacheHelperTest, Empty) { | 89 TEST(CannedBrowsingDataAppCacheHelperTest, Empty) { |
90 TestingProfile profile; | 90 TestingProfile profile; |
91 | 91 |
92 GURL manifest("http://example.com/manifest.xml"); | 92 GURL manifest("http://example.com/manifest.xml"); |
93 | 93 |
94 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper = | 94 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
95 new CannedBrowsingDataAppCacheHelper(&profile); | 95 new CannedBrowsingDataAppCacheHelper(&profile)); |
96 | 96 |
97 ASSERT_TRUE(helper->empty()); | 97 ASSERT_TRUE(helper->empty()); |
98 helper->AddAppCache(manifest); | 98 helper->AddAppCache(manifest); |
99 ASSERT_FALSE(helper->empty()); | 99 ASSERT_FALSE(helper->empty()); |
100 helper->Reset(); | 100 helper->Reset(); |
101 ASSERT_TRUE(helper->empty()); | 101 ASSERT_TRUE(helper->empty()); |
102 } | 102 } |
OLD | NEW |