1 // Copyright 2014 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.
5 #include "content/test/appcache_test_helper.h"
8 #include "base/bind_helpers.h"
9 #include "base/message_loop/message_loop.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "webkit/browser/appcache/appcache.h"
12 #include "webkit/browser/appcache/appcache_entry.h"
13 #include "webkit/browser/appcache/appcache_group.h"
14 #include "webkit/browser/appcache/appcache_service.h"
18 AppCacheTestHelper::AppCacheTestHelper()
24 AppCacheTestHelper::~AppCacheTestHelper() {}
26 void AppCacheTestHelper::OnGroupAndNewestCacheStored(
27 appcache::AppCacheGroup
* /*group*/,
28 appcache::AppCache
* /*newest_cache*/,
30 bool /*would_exceed_quota*/) {
32 base::MessageLoop::current()->Quit();
35 void AppCacheTestHelper::AddGroupAndCache(appcache::AppCacheService
*
36 appcache_service
, const GURL
& manifest_url
) {
37 appcache::AppCacheGroup
* appcache_group
=
38 new appcache::AppCacheGroup(appcache_service
->storage(),
41 appcache::AppCache
* appcache
= new appcache::AppCache(
42 appcache_service
->storage(), ++appcache_id_
);
43 appcache::AppCacheEntry
entry(appcache::AppCacheEntry::MANIFEST
,
45 appcache
->AddEntry(manifest_url
, entry
);
46 appcache
->set_complete(true);
47 appcache_group
->AddCache(appcache
);
48 appcache_service
->storage()->StoreGroupAndNewestCache(appcache_group
,
51 // OnGroupAndNewestCacheStored will quit the message loop.
52 base::MessageLoop::current()->Run();
55 void AppCacheTestHelper::GetOriginsWithCaches(appcache::AppCacheService
*
56 appcache_service
, std::set
<GURL
>* origins
) {
57 appcache_info_
= new appcache::AppCacheInfoCollection
;
59 appcache_service
->GetAllAppCacheInfo(
61 base::Bind(&AppCacheTestHelper::OnGotAppCacheInfo
,
62 base::Unretained(this)));
64 // OnGotAppCacheInfo will quit the message loop.
65 base::MessageLoop::current()->Run();
68 void AppCacheTestHelper::OnGotAppCacheInfo(int rv
) {
69 typedef std::map
<GURL
, appcache::AppCacheInfoVector
> InfoByOrigin
;
72 for (InfoByOrigin::const_iterator origin
=
73 appcache_info_
->infos_by_origin
.begin();
74 origin
!= appcache_info_
->infos_by_origin
.end(); ++origin
) {
75 origins_
->insert(origin
->first
);
77 base::MessageLoop::current()->Quit();
80 } // namespace content