1 // Copyright 2015 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_cache_storage_helper.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/storage_partition.h"
12 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "testing/gtest/include/gtest/gtest.h"
17 class CannedBrowsingDataCacheStorageHelperTest
: public testing::Test
{
19 content::CacheStorageContext
* CacheStorageContext() {
20 return content::BrowserContext::GetDefaultStoragePartition(&profile_
)
21 ->GetCacheStorageContext();
25 content::TestBrowserThreadBundle thread_bundle_
;
26 TestingProfile profile_
;
29 TEST_F(CannedBrowsingDataCacheStorageHelperTest
, Empty
) {
30 const GURL
origin("http://host1:1/");
32 scoped_refptr
<CannedBrowsingDataCacheStorageHelper
> helper(
33 new CannedBrowsingDataCacheStorageHelper(CacheStorageContext()));
35 ASSERT_TRUE(helper
->empty());
36 helper
->AddCacheStorage(origin
);
37 ASSERT_FALSE(helper
->empty());
39 ASSERT_TRUE(helper
->empty());
42 TEST_F(CannedBrowsingDataCacheStorageHelperTest
, Delete
) {
43 const GURL
origin1("http://host1:9000");
44 const GURL
origin2("http://example.com");
46 scoped_refptr
<CannedBrowsingDataCacheStorageHelper
> helper(
47 new CannedBrowsingDataCacheStorageHelper(CacheStorageContext()));
49 EXPECT_TRUE(helper
->empty());
50 helper
->AddCacheStorage(origin1
);
51 helper
->AddCacheStorage(origin2
);
52 helper
->AddCacheStorage(origin2
);
53 EXPECT_EQ(2u, helper
->GetCacheStorageCount());
54 helper
->DeleteCacheStorage(origin2
);
55 EXPECT_EQ(1u, helper
->GetCacheStorageCount());
58 TEST_F(CannedBrowsingDataCacheStorageHelperTest
, IgnoreExtensionsAndDevTools
) {
59 const GURL
origin1("chrome-extension://abcdefghijklmnopqrstuvwxyz/");
60 const GURL
origin2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/");
62 scoped_refptr
<CannedBrowsingDataCacheStorageHelper
> helper(
63 new CannedBrowsingDataCacheStorageHelper(CacheStorageContext()));
65 ASSERT_TRUE(helper
->empty());
66 helper
->AddCacheStorage(origin1
);
67 ASSERT_TRUE(helper
->empty());
68 helper
->AddCacheStorage(origin2
);
69 ASSERT_TRUE(helper
->empty());