Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_appcache_helper_unittest.cc
blob1bee13d5b59bc6d7d2545a0494b6f97291dfbf49
1 // Copyright (c) 2012 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 "chrome/browser/browsing_data/browsing_data_appcache_helper.h"
7 #include <set>
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
11 #include "base/stl_util.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/test/test_browser_thread_bundle.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace {
17 class TestCompletionCallback {
18 public:
19 TestCompletionCallback() {}
21 bool have_result() const { return have_result_; }
23 void callback() {
24 have_result_ = true;
27 private:
28 bool have_result_ = false;
31 } // namespace
33 class CannedBrowsingDataAppCacheHelperTest : public testing::Test {
34 public:
35 CannedBrowsingDataAppCacheHelperTest()
36 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
38 content::TestBrowserThreadBundle thread_bundle_;
41 TEST_F(CannedBrowsingDataAppCacheHelperTest, SetInfo) {
42 TestingProfile profile;
44 GURL manifest1("http://example1.com/manifest.xml");
45 GURL manifest2("http://example2.com/path1/manifest.xml");
46 GURL manifest3("http://example2.com/path2/manifest.xml");
48 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper(
49 new CannedBrowsingDataAppCacheHelper(&profile));
50 helper->AddAppCache(manifest1);
51 helper->AddAppCache(manifest2);
52 helper->AddAppCache(manifest3);
54 TestCompletionCallback callback;
55 helper->StartFetching(base::Bind(&TestCompletionCallback::callback,
56 base::Unretained(&callback)));
57 ASSERT_TRUE(callback.have_result());
59 std::map<GURL, content::AppCacheInfoVector>& collection =
60 helper->info_collection()->infos_by_origin;
62 ASSERT_EQ(2u, collection.size());
63 EXPECT_TRUE(ContainsKey(collection, manifest1.GetOrigin()));
64 ASSERT_EQ(1u, collection[manifest1.GetOrigin()].size());
65 EXPECT_EQ(manifest1, collection[manifest1.GetOrigin()].at(0).manifest_url);
67 EXPECT_TRUE(ContainsKey(collection, manifest2.GetOrigin()));
68 EXPECT_EQ(2u, collection[manifest2.GetOrigin()].size());
69 std::set<GURL> manifest_results;
70 manifest_results.insert(collection[manifest2.GetOrigin()].at(0).manifest_url);
71 manifest_results.insert(collection[manifest2.GetOrigin()].at(1).manifest_url);
72 EXPECT_TRUE(ContainsKey(manifest_results, manifest2));
73 EXPECT_TRUE(ContainsKey(manifest_results, manifest3));
76 TEST_F(CannedBrowsingDataAppCacheHelperTest, Unique) {
77 TestingProfile profile;
79 GURL manifest("http://example.com/manifest.xml");
81 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper(
82 new CannedBrowsingDataAppCacheHelper(&profile));
83 helper->AddAppCache(manifest);
84 helper->AddAppCache(manifest);
86 TestCompletionCallback callback;
87 helper->StartFetching(base::Bind(&TestCompletionCallback::callback,
88 base::Unretained(&callback)));
89 ASSERT_TRUE(callback.have_result());
91 std::map<GURL, content::AppCacheInfoVector>& collection =
92 helper->info_collection()->infos_by_origin;
94 ASSERT_EQ(1u, collection.size());
95 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin()));
96 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size());
97 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url);
100 TEST_F(CannedBrowsingDataAppCacheHelperTest, Empty) {
101 TestingProfile profile;
103 GURL manifest("http://example.com/manifest.xml");
105 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper(
106 new CannedBrowsingDataAppCacheHelper(&profile));
108 ASSERT_TRUE(helper->empty());
109 helper->AddAppCache(manifest);
110 ASSERT_FALSE(helper->empty());
111 helper->Reset();
112 ASSERT_TRUE(helper->empty());
115 TEST_F(CannedBrowsingDataAppCacheHelperTest, Delete) {
116 TestingProfile profile;
118 GURL manifest1("http://example.com/manifest1.xml");
119 GURL manifest2("http://foo.example.com/manifest2.xml");
120 GURL manifest3("http://bar.example.com/manifest3.xml");
122 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper(
123 new CannedBrowsingDataAppCacheHelper(&profile));
125 EXPECT_TRUE(helper->empty());
126 helper->AddAppCache(manifest1);
127 helper->AddAppCache(manifest2);
128 helper->AddAppCache(manifest3);
129 EXPECT_FALSE(helper->empty());
130 EXPECT_EQ(3u, helper->GetAppCacheCount());
131 helper->DeleteAppCacheGroup(manifest2);
132 EXPECT_EQ(2u, helper->GetAppCacheCount());
133 EXPECT_FALSE(ContainsKey(helper->GetOriginAppCacheInfoMap(), manifest2));
136 TEST_F(CannedBrowsingDataAppCacheHelperTest, IgnoreExtensionsAndDevTools) {
137 TestingProfile profile;
139 GURL manifest1("chrome-extension://abcdefghijklmnopqrstuvwxyz/manifest.xml");
140 GURL manifest2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/manifest.xml");
142 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper(
143 new CannedBrowsingDataAppCacheHelper(&profile));
145 ASSERT_TRUE(helper->empty());
146 helper->AddAppCache(manifest1);
147 ASSERT_TRUE(helper->empty());
148 helper->AddAppCache(manifest2);
149 ASSERT_TRUE(helper->empty());