Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_appcache_helper_unittest.cc
blobce24b8d971260c9cea35a81a2ed426bd00e3e6e4
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()
20 : have_result_(false) {
23 bool have_result() const { return have_result_; }
25 void callback() {
26 have_result_ = true;
29 private:
30 bool have_result_;
33 } // namespace
35 class CannedBrowsingDataAppCacheHelperTest : public testing::Test {
36 public:
37 CannedBrowsingDataAppCacheHelperTest()
38 : thread_bundle_(content::TestBrowserThreadBundle::REAL_IO_THREAD) {}
40 content::TestBrowserThreadBundle thread_bundle_;
43 TEST_F(CannedBrowsingDataAppCacheHelperTest, SetInfo) {
44 TestingProfile profile;
46 GURL manifest1("http://example1.com/manifest.xml");
47 GURL manifest2("http://example2.com/path1/manifest.xml");
48 GURL manifest3("http://example2.com/path2/manifest.xml");
50 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper(
51 new CannedBrowsingDataAppCacheHelper(&profile));
52 helper->AddAppCache(manifest1);
53 helper->AddAppCache(manifest2);
54 helper->AddAppCache(manifest3);
56 TestCompletionCallback callback;
57 helper->StartFetching(base::Bind(&TestCompletionCallback::callback,
58 base::Unretained(&callback)));
59 ASSERT_TRUE(callback.have_result());
61 std::map<GURL, content::AppCacheInfoVector>& collection =
62 helper->info_collection()->infos_by_origin;
64 ASSERT_EQ(2u, collection.size());
65 EXPECT_TRUE(ContainsKey(collection, manifest1.GetOrigin()));
66 ASSERT_EQ(1u, collection[manifest1.GetOrigin()].size());
67 EXPECT_EQ(manifest1, collection[manifest1.GetOrigin()].at(0).manifest_url);
69 EXPECT_TRUE(ContainsKey(collection, manifest2.GetOrigin()));
70 EXPECT_EQ(2u, collection[manifest2.GetOrigin()].size());
71 std::set<GURL> manifest_results;
72 manifest_results.insert(collection[manifest2.GetOrigin()].at(0).manifest_url);
73 manifest_results.insert(collection[manifest2.GetOrigin()].at(1).manifest_url);
74 EXPECT_TRUE(ContainsKey(manifest_results, manifest2));
75 EXPECT_TRUE(ContainsKey(manifest_results, manifest3));
78 TEST_F(CannedBrowsingDataAppCacheHelperTest, Unique) {
79 TestingProfile profile;
81 GURL manifest("http://example.com/manifest.xml");
83 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper(
84 new CannedBrowsingDataAppCacheHelper(&profile));
85 helper->AddAppCache(manifest);
86 helper->AddAppCache(manifest);
88 TestCompletionCallback callback;
89 helper->StartFetching(base::Bind(&TestCompletionCallback::callback,
90 base::Unretained(&callback)));
91 ASSERT_TRUE(callback.have_result());
93 std::map<GURL, content::AppCacheInfoVector>& collection =
94 helper->info_collection()->infos_by_origin;
96 ASSERT_EQ(1u, collection.size());
97 EXPECT_TRUE(ContainsKey(collection, manifest.GetOrigin()));
98 ASSERT_EQ(1u, collection[manifest.GetOrigin()].size());
99 EXPECT_EQ(manifest, collection[manifest.GetOrigin()].at(0).manifest_url);
102 TEST_F(CannedBrowsingDataAppCacheHelperTest, Empty) {
103 TestingProfile profile;
105 GURL manifest("http://example.com/manifest.xml");
107 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper(
108 new CannedBrowsingDataAppCacheHelper(&profile));
110 ASSERT_TRUE(helper->empty());
111 helper->AddAppCache(manifest);
112 ASSERT_FALSE(helper->empty());
113 helper->Reset();
114 ASSERT_TRUE(helper->empty());
117 TEST_F(CannedBrowsingDataAppCacheHelperTest, Delete) {
118 TestingProfile profile;
120 GURL manifest1("http://example.com/manifest1.xml");
121 GURL manifest2("http://foo.example.com/manifest2.xml");
122 GURL manifest3("http://bar.example.com/manifest3.xml");
124 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper(
125 new CannedBrowsingDataAppCacheHelper(&profile));
127 EXPECT_TRUE(helper->empty());
128 helper->AddAppCache(manifest1);
129 helper->AddAppCache(manifest2);
130 helper->AddAppCache(manifest3);
131 EXPECT_FALSE(helper->empty());
132 EXPECT_EQ(3u, helper->GetAppCacheCount());
133 helper->DeleteAppCacheGroup(manifest2);
134 EXPECT_EQ(2u, helper->GetAppCacheCount());
135 EXPECT_TRUE(helper->GetOriginAppCacheInfoMap().find(manifest2) ==
136 helper->GetOriginAppCacheInfoMap().end());
139 TEST_F(CannedBrowsingDataAppCacheHelperTest, IgnoreExtensionsAndDevTools) {
140 TestingProfile profile;
142 GURL manifest1("chrome-extension://abcdefghijklmnopqrstuvwxyz/manifest.xml");
143 GURL manifest2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/manifest.xml");
145 scoped_refptr<CannedBrowsingDataAppCacheHelper> helper(
146 new CannedBrowsingDataAppCacheHelper(&profile));
148 ASSERT_TRUE(helper->empty());
149 helper->AddAppCache(manifest1);
150 ASSERT_TRUE(helper->empty());
151 helper->AddAppCache(manifest2);
152 ASSERT_TRUE(helper->empty());