OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 "webkit/appcache/appcache_test_helper.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "webkit/appcache/appcache.h" |
| 10 #include "webkit/appcache/appcache_entry.h" |
| 11 #include "webkit/appcache/appcache_group.h" |
| 12 #include "webkit/appcache/appcache_service.h" |
| 13 |
| 14 namespace appcache { |
| 15 |
| 16 AppCacheTestHelper::AppCacheTestHelper() |
| 17 : group_id_(0), |
| 18 appcache_id_(0), |
| 19 response_id_(0), |
| 20 ALLOW_THIS_IN_INITIALIZER_LIST(appcache_got_info_callback_( |
| 21 this, &AppCacheTestHelper::OnGotAppCacheInfo)), |
| 22 origins_(NULL) {} |
| 23 |
| 24 AppCacheTestHelper::~AppCacheTestHelper() {} |
| 25 |
| 26 void AppCacheTestHelper::OnGroupAndNewestCacheStored( |
| 27 AppCacheGroup* /*group*/, |
| 28 AppCache* /*newest_cache*/, |
| 29 bool success, |
| 30 bool /*would_exceed_quota*/) { |
| 31 ASSERT_TRUE(success); |
| 32 MessageLoop::current()->Quit(); |
| 33 } |
| 34 |
| 35 void AppCacheTestHelper::AddGroupAndCache(AppCacheService* appcache_service, |
| 36 const GURL& manifest_url) { |
| 37 AppCacheGroup* appcache_group = |
| 38 new AppCacheGroup(appcache_service, |
| 39 manifest_url, |
| 40 ++group_id_); |
| 41 AppCache* appcache = new AppCache(appcache_service, |
| 42 ++appcache_id_); |
| 43 AppCacheEntry entry(AppCacheEntry::MANIFEST, |
| 44 ++response_id_); |
| 45 appcache->AddEntry(manifest_url, entry); |
| 46 appcache->set_complete(true); |
| 47 appcache_group->AddCache(appcache); |
| 48 appcache_service->storage()->StoreGroupAndNewestCache(appcache_group, |
| 49 appcache, |
| 50 this); |
| 51 // OnGroupAndNewestCacheStored will quit the message loop. |
| 52 MessageLoop::current()->Run(); |
| 53 } |
| 54 |
| 55 void AppCacheTestHelper::GetOriginsWithCaches(AppCacheService* appcache_service, |
| 56 std::set<GURL>* origins) { |
| 57 appcache_info_ = new AppCacheInfoCollection; |
| 58 origins_ = origins; |
| 59 appcache_service->GetAllAppCacheInfo( |
| 60 appcache_info_, &appcache_got_info_callback_); |
| 61 // OnGotAppCacheInfo will quit the message loop. |
| 62 MessageLoop::current()->Run(); |
| 63 } |
| 64 |
| 65 void AppCacheTestHelper::OnGotAppCacheInfo(int rv) { |
| 66 typedef std::map<GURL, AppCacheInfoVector> InfoByOrigin; |
| 67 |
| 68 origins_->clear(); |
| 69 for (InfoByOrigin::const_iterator origin = |
| 70 appcache_info_->infos_by_origin.begin(); |
| 71 origin != appcache_info_->infos_by_origin.end(); ++origin) { |
| 72 origins_->insert(origin->first); |
| 73 } |
| 74 MessageLoop::current()->Quit(); |
| 75 } |
| 76 |
| 77 } // namespace appcache |
OLD | NEW |