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_database_helper.h"
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"
14 using storage::DatabaseIdentifier
;
16 class CannedBrowsingDataDatabaseHelperTest
: public testing::Test
{
17 content::TestBrowserThreadBundle thread_bundle_
;
20 TEST_F(CannedBrowsingDataDatabaseHelperTest
, Empty
) {
21 TestingProfile profile
;
23 const GURL
origin("http://host1:1/");
24 const char db
[] = "db1";
26 scoped_refptr
<CannedBrowsingDataDatabaseHelper
> helper(
27 new CannedBrowsingDataDatabaseHelper(&profile
));
29 ASSERT_TRUE(helper
->empty());
30 helper
->AddDatabase(origin
, db
, std::string());
31 ASSERT_FALSE(helper
->empty());
33 ASSERT_TRUE(helper
->empty());
36 TEST_F(CannedBrowsingDataDatabaseHelperTest
, Delete
) {
37 TestingProfile profile
;
39 const GURL
origin1("http://host1:9000");
40 const char db1
[] = "db1";
42 const GURL
origin2("http://example.com");
43 const char db2
[] = "db2";
45 const GURL
origin3("http://foo.example.com");
46 const char db3
[] = "db3";
48 scoped_refptr
<CannedBrowsingDataDatabaseHelper
> helper(
49 new CannedBrowsingDataDatabaseHelper(&profile
));
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());
64 TEST_F(CannedBrowsingDataDatabaseHelperTest
, IgnoreExtensionsAndDevTools
) {
65 TestingProfile profile
;
67 const GURL
origin1("chrome-extension://abcdefghijklmnopqrstuvwxyz/");
68 const GURL
origin2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/");
69 const char db
[] = "db1";
71 scoped_refptr
<CannedBrowsingDataDatabaseHelper
> helper(
72 new CannedBrowsingDataDatabaseHelper(&profile
));
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());
80 ASSERT_TRUE(helper
->empty());