| 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 |
| 11 namespace { | 11 namespace { |
| 12 class TestCompletionCallback : public CallbackRunner<Tuple0> { | 12 class TestCompletionCallback { |
| 13 public: | 13 public: |
| 14 TestCompletionCallback() | 14 TestCompletionCallback() |
| 15 : have_result_(false) { | 15 : have_result_(false) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 bool have_result() const { return have_result_; } | 18 bool have_result() const { return have_result_; } |
| 19 | 19 |
| 20 virtual void RunWithParams(const Tuple0& params) { | 20 void callback() { |
| 21 have_result_ = true; | 21 have_result_ = true; |
| 22 } | 22 } |
| 23 |
| 23 private: | 24 private: |
| 24 bool have_result_; | 25 bool have_result_; |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 } // namespace | 28 } // namespace |
| 28 | 29 |
| 29 TEST(CannedBrowsingDataAppCacheHelperTest, SetInfo) { | 30 TEST(CannedBrowsingDataAppCacheHelperTest, SetInfo) { |
| 30 TestingProfile profile; | 31 TestingProfile profile; |
| 31 | 32 |
| 32 GURL manifest1("http://example1.com/manifest.xml"); | 33 GURL manifest1("http://example1.com/manifest.xml"); |
| 33 GURL manifest2("http://example2.com/path1/manifest.xml"); | 34 GURL manifest2("http://example2.com/path1/manifest.xml"); |
| 34 GURL manifest3("http://example2.com/path2/manifest.xml"); | 35 GURL manifest3("http://example2.com/path2/manifest.xml"); |
| 35 | 36 |
| 36 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper = | 37 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper = |
| 37 new CannedBrowsingDataAppCacheHelper(&profile); | 38 new CannedBrowsingDataAppCacheHelper(&profile); |
| 38 helper->AddAppCache(manifest1); | 39 helper->AddAppCache(manifest1); |
| 39 helper->AddAppCache(manifest2); | 40 helper->AddAppCache(manifest2); |
| 40 helper->AddAppCache(manifest3); | 41 helper->AddAppCache(manifest3); |
| 41 | 42 |
| 42 TestCompletionCallback callback; | 43 TestCompletionCallback callback; |
| 43 helper->StartFetching(&callback); | 44 helper->StartFetching( |
| 45 NewCallback(&callback, &TestCompletionCallback::callback)); |
| 44 ASSERT_TRUE(callback.have_result()); | 46 ASSERT_TRUE(callback.have_result()); |
| 45 | 47 |
| 46 std::map<GURL, appcache::AppCacheInfoVector>& collection = | 48 std::map<GURL, appcache::AppCacheInfoVector>& collection = |
| 47 helper->info_collection()->infos_by_origin; | 49 helper->info_collection()->infos_by_origin; |
| 48 | 50 |
| 49 ASSERT_EQ(2u, collection.size()); | 51 ASSERT_EQ(2u, collection.size()); |
| 50 EXPECT_TRUE(ContainsKey(collection, manifest1.GetOrigin())); | 52 EXPECT_TRUE(ContainsKey(collection, manifest1.GetOrigin())); |
| 51 ASSERT_EQ(1u, collection[manifest1.GetOrigin()].size()); | 53 ASSERT_EQ(1u, collection[manifest1.GetOrigin()].size()); |
| 52 EXPECT_EQ(manifest1, collection[manifest1.GetOrigin()].at(0).manifest_url); | 54 EXPECT_EQ(manifest1, collection[manifest1.GetOrigin()].at(0).manifest_url); |
| 53 | 55 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 64 TestingProfile profile; | 66 TestingProfile profile; |
| 65 | 67 |
| 66 GURL manifest("http://example.com/manifest.xml"); | 68 GURL manifest("http://example.com/manifest.xml"); |
| 67 | 69 |
| 68 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper = | 70 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper = |
| 69 new CannedBrowsingDataAppCacheHelper(&profile); | 71 new CannedBrowsingDataAppCacheHelper(&profile); |
| 70 helper->AddAppCache(manifest); | 72 helper->AddAppCache(manifest); |
| 71 helper->AddAppCache(manifest); | 73 helper->AddAppCache(manifest); |
| 72 | 74 |
| 73 TestCompletionCallback callback; | 75 TestCompletionCallback callback; |
| 74 helper->StartFetching(&callback); | 76 helper->StartFetching( |
| 77 NewCallback(&callback, &TestCompletionCallback::callback)); |
| 75 ASSERT_TRUE(callback.have_result()); | 78 ASSERT_TRUE(callback.have_result()); |
| 76 | 79 |
| 77 std::map<GURL, appcache::AppCacheInfoVector>& collection = | 80 std::map<GURL, appcache::AppCacheInfoVector>& collection = |
| 78 helper->info_collection()->infos_by_origin; | 81 helper->info_collection()->infos_by_origin; |
| 79 | 82 |
| 80 ASSERT_EQ(1u, collection.size()); | 83 ASSERT_EQ(1u, collection.size()); |
| 81 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin())); | 84 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin())); |
| 82 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size()); | 85 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size()); |
| 83 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url); | 86 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url); |
| 84 } | 87 } |
| OLD | NEW |