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. 4 5 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" 6 7 #include "chrome/test/base/testing_profile.h" 8 #include "content/public/test/test_browser_thread_bundle.h" 9 #include "storage/common/database/database_identifier.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 12 namespace { 13 14 using storage::DatabaseIdentifier; 15 16 class CannedBrowsingDataDatabaseHelperTest : public testing::Test { 17 content::TestBrowserThreadBundle thread_bundle_; 18 }; 19 20 TEST_F(CannedBrowsingDataDatabaseHelperTest, Empty) { 21 TestingProfile profile; 22 23 const GURL origin("http://host1:1/"); 24 const char db[] = "db1"; 25 26 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( 27 new CannedBrowsingDataDatabaseHelper(&profile)); 28 29 ASSERT_TRUE(helper->empty()); 30 helper->AddDatabase(origin, db, std::string()); 31 ASSERT_FALSE(helper->empty()); 32 helper->Reset(); 33 ASSERT_TRUE(helper->empty()); 34 } 35 36 TEST_F(CannedBrowsingDataDatabaseHelperTest, Delete) { 37 TestingProfile profile; 38 39 const GURL origin1("http://host1:9000"); 40 const char db1[] = "db1"; 41 42 const GURL origin2("http://example.com"); 43 const char db2[] = "db2"; 44 45 const GURL origin3("http://foo.example.com"); 46 const char db3[] = "db3"; 47 48 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( 49 new CannedBrowsingDataDatabaseHelper(&profile)); 50 51 EXPECT_TRUE(helper->empty()); 52 helper->AddDatabase(origin1, db1, std::string()); 53 helper->AddDatabase(origin2, db2, std::string()); 54 helper->AddDatabase(origin3, db3, std::string()); 55 EXPECT_EQ(3u, helper->GetDatabaseCount()); 56 helper->DeleteDatabase( 57 DatabaseIdentifier::CreateFromOrigin(origin2).ToString(), db1); 58 EXPECT_EQ(3u, helper->GetDatabaseCount()); 59 helper->DeleteDatabase( 60 DatabaseIdentifier::CreateFromOrigin(origin2).ToString(), db2); 61 EXPECT_EQ(2u, helper->GetDatabaseCount()); 62 } 63 64 TEST_F(CannedBrowsingDataDatabaseHelperTest, IgnoreExtensionsAndDevTools) { 65 TestingProfile profile; 66 67 const GURL origin1("chrome-extension://abcdefghijklmnopqrstuvwxyz/"); 68 const GURL origin2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/"); 69 const char db[] = "db1"; 70 71 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( 72 new CannedBrowsingDataDatabaseHelper(&profile)); 73 74 ASSERT_TRUE(helper->empty()); 75 helper->AddDatabase(origin1, db, std::string()); 76 ASSERT_TRUE(helper->empty()); 77 helper->AddDatabase(origin2, db, std::string()); 78 ASSERT_TRUE(helper->empty()); 79 helper->Reset(); 80 ASSERT_TRUE(helper->empty()); 81 } 82 83 } // namespace 84