| 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_browser_process_test.h" |
| 8 #include "chrome/test/testing_profile.h" | 9 #include "chrome/test/testing_profile.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 11 |
| 11 namespace { | 12 namespace { |
| 12 class TestCompletionCallback { | 13 class TestCompletionCallback { |
| 13 public: | 14 public: |
| 14 TestCompletionCallback() | 15 TestCompletionCallback() |
| 15 : have_result_(false) { | 16 : have_result_(false) { |
| 16 } | 17 } |
| 17 | 18 |
| 18 bool have_result() const { return have_result_; } | 19 bool have_result() const { return have_result_; } |
| 19 | 20 |
| 20 void callback() { | 21 void callback() { |
| 21 have_result_ = true; | 22 have_result_ = true; |
| 22 } | 23 } |
| 23 | 24 |
| 24 private: | 25 private: |
| 25 bool have_result_; | 26 bool have_result_; |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 } // namespace | 29 } // namespace |
| 29 | 30 |
| 30 TEST(CannedBrowsingDataAppCacheHelperTest, SetInfo) { | 31 typedef TestingBrowserProcessTest CannedBrowsingDataAppCacheHelperTest; |
| 32 |
| 33 TEST_F(CannedBrowsingDataAppCacheHelperTest, SetInfo) { |
| 31 TestingProfile profile; | 34 TestingProfile profile; |
| 32 | 35 |
| 33 GURL manifest1("http://example1.com/manifest.xml"); | 36 GURL manifest1("http://example1.com/manifest.xml"); |
| 34 GURL manifest2("http://example2.com/path1/manifest.xml"); | 37 GURL manifest2("http://example2.com/path1/manifest.xml"); |
| 35 GURL manifest3("http://example2.com/path2/manifest.xml"); | 38 GURL manifest3("http://example2.com/path2/manifest.xml"); |
| 36 | 39 |
| 37 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | 40 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
| 38 new CannedBrowsingDataAppCacheHelper(&profile)); | 41 new CannedBrowsingDataAppCacheHelper(&profile)); |
| 39 helper->AddAppCache(manifest1); | 42 helper->AddAppCache(manifest1); |
| 40 helper->AddAppCache(manifest2); | 43 helper->AddAppCache(manifest2); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 55 | 58 |
| 56 EXPECT_TRUE(ContainsKey(collection, manifest2.GetOrigin())); | 59 EXPECT_TRUE(ContainsKey(collection, manifest2.GetOrigin())); |
| 57 EXPECT_EQ(2u, collection[manifest2.GetOrigin()].size()); | 60 EXPECT_EQ(2u, collection[manifest2.GetOrigin()].size()); |
| 58 std::set<GURL> manifest_results; | 61 std::set<GURL> manifest_results; |
| 59 manifest_results.insert(collection[manifest2.GetOrigin()].at(0).manifest_url); | 62 manifest_results.insert(collection[manifest2.GetOrigin()].at(0).manifest_url); |
| 60 manifest_results.insert(collection[manifest2.GetOrigin()].at(1).manifest_url); | 63 manifest_results.insert(collection[manifest2.GetOrigin()].at(1).manifest_url); |
| 61 EXPECT_TRUE(ContainsKey(manifest_results, manifest2)); | 64 EXPECT_TRUE(ContainsKey(manifest_results, manifest2)); |
| 62 EXPECT_TRUE(ContainsKey(manifest_results, manifest3)); | 65 EXPECT_TRUE(ContainsKey(manifest_results, manifest3)); |
| 63 } | 66 } |
| 64 | 67 |
| 65 TEST(CannedBrowsingDataAppCacheHelperTest, Unique) { | 68 TEST_F(CannedBrowsingDataAppCacheHelperTest, Unique) { |
| 66 TestingProfile profile; | 69 TestingProfile profile; |
| 67 | 70 |
| 68 GURL manifest("http://example.com/manifest.xml"); | 71 GURL manifest("http://example.com/manifest.xml"); |
| 69 | 72 |
| 70 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | 73 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
| 71 new CannedBrowsingDataAppCacheHelper(&profile)); | 74 new CannedBrowsingDataAppCacheHelper(&profile)); |
| 72 helper->AddAppCache(manifest); | 75 helper->AddAppCache(manifest); |
| 73 helper->AddAppCache(manifest); | 76 helper->AddAppCache(manifest); |
| 74 | 77 |
| 75 TestCompletionCallback callback; | 78 TestCompletionCallback callback; |
| 76 helper->StartFetching( | 79 helper->StartFetching( |
| 77 NewCallback(&callback, &TestCompletionCallback::callback)); | 80 NewCallback(&callback, &TestCompletionCallback::callback)); |
| 78 ASSERT_TRUE(callback.have_result()); | 81 ASSERT_TRUE(callback.have_result()); |
| 79 | 82 |
| 80 std::map<GURL, appcache::AppCacheInfoVector>& collection = | 83 std::map<GURL, appcache::AppCacheInfoVector>& collection = |
| 81 helper->info_collection()->infos_by_origin; | 84 helper->info_collection()->infos_by_origin; |
| 82 | 85 |
| 83 ASSERT_EQ(1u, collection.size()); | 86 ASSERT_EQ(1u, collection.size()); |
| 84 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin())); | 87 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin())); |
| 85 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size()); | 88 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size()); |
| 86 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url); | 89 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url); |
| 87 } | 90 } |
| 88 | 91 |
| 89 TEST(CannedBrowsingDataAppCacheHelperTest, Empty) { | 92 TEST_F(CannedBrowsingDataAppCacheHelperTest, Empty) { |
| 90 TestingProfile profile; | 93 TestingProfile profile; |
| 91 | 94 |
| 92 GURL manifest("http://example.com/manifest.xml"); | 95 GURL manifest("http://example.com/manifest.xml"); |
| 93 | 96 |
| 94 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( | 97 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper( |
| 95 new CannedBrowsingDataAppCacheHelper(&profile)); | 98 new CannedBrowsingDataAppCacheHelper(&profile)); |
| 96 | 99 |
| 97 ASSERT_TRUE(helper->empty()); | 100 ASSERT_TRUE(helper->empty()); |
| 98 helper->AddAppCache(manifest); | 101 helper->AddAppCache(manifest); |
| 99 ASSERT_FALSE(helper->empty()); | 102 ASSERT_FALSE(helper->empty()); |
| 100 helper->Reset(); | 103 helper->Reset(); |
| 101 ASSERT_TRUE(helper->empty()); | 104 ASSERT_TRUE(helper->empty()); |
| 102 } | 105 } |
| OLD | NEW |