OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_database_helper.h" |
6 | 6 |
7 #include "chrome/test/base/testing_profile.h" | 7 #include "chrome/test/base/testing_profile.h" |
8 #include "content/public/test/test_browser_thread_bundle.h" | 8 #include "content/public/test/test_browser_thread_bundle.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "webkit/common/database/database_identifier.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
| 14 using webkit_database::DatabaseIdentifier; |
| 15 |
13 class CannedBrowsingDataDatabaseHelperTest : public testing::Test { | 16 class CannedBrowsingDataDatabaseHelperTest : public testing::Test { |
14 content::TestBrowserThreadBundle thread_bundle_; | 17 content::TestBrowserThreadBundle thread_bundle_; |
15 }; | 18 }; |
16 | 19 |
17 TEST_F(CannedBrowsingDataDatabaseHelperTest, Empty) { | 20 TEST_F(CannedBrowsingDataDatabaseHelperTest, Empty) { |
18 TestingProfile profile; | 21 TestingProfile profile; |
19 | 22 |
20 const GURL origin("http://host1:1/"); | 23 const GURL origin("http://host1:1/"); |
21 const char db[] = "db1"; | 24 const char db[] = "db1"; |
22 | 25 |
23 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( | 26 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( |
24 new CannedBrowsingDataDatabaseHelper(&profile)); | 27 new CannedBrowsingDataDatabaseHelper(&profile)); |
25 | 28 |
26 ASSERT_TRUE(helper->empty()); | 29 ASSERT_TRUE(helper->empty()); |
27 helper->AddDatabase(origin, db, std::string()); | 30 helper->AddDatabase(origin, db, std::string()); |
28 ASSERT_FALSE(helper->empty()); | 31 ASSERT_FALSE(helper->empty()); |
29 helper->Reset(); | 32 helper->Reset(); |
30 ASSERT_TRUE(helper->empty()); | 33 ASSERT_TRUE(helper->empty()); |
31 } | 34 } |
32 | 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 |
33 TEST_F(CannedBrowsingDataDatabaseHelperTest, IgnoreExtensionsAndDevTools) { | 64 TEST_F(CannedBrowsingDataDatabaseHelperTest, IgnoreExtensionsAndDevTools) { |
34 TestingProfile profile; | 65 TestingProfile profile; |
35 | 66 |
36 const GURL origin1("chrome-extension://abcdefghijklmnopqrstuvwxyz/"); | 67 const GURL origin1("chrome-extension://abcdefghijklmnopqrstuvwxyz/"); |
37 const GURL origin2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/"); | 68 const GURL origin2("chrome-devtools://abcdefghijklmnopqrstuvwxyz/"); |
38 const char db[] = "db1"; | 69 const char db[] = "db1"; |
39 | 70 |
40 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( | 71 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( |
41 new CannedBrowsingDataDatabaseHelper(&profile)); | 72 new CannedBrowsingDataDatabaseHelper(&profile)); |
42 | 73 |
43 ASSERT_TRUE(helper->empty()); | 74 ASSERT_TRUE(helper->empty()); |
44 helper->AddDatabase(origin1, db, std::string()); | 75 helper->AddDatabase(origin1, db, std::string()); |
45 ASSERT_TRUE(helper->empty()); | 76 ASSERT_TRUE(helper->empty()); |
46 helper->AddDatabase(origin2, db, std::string()); | 77 helper->AddDatabase(origin2, db, std::string()); |
47 ASSERT_TRUE(helper->empty()); | 78 ASSERT_TRUE(helper->empty()); |
48 helper->Reset(); | 79 helper->Reset(); |
49 ASSERT_TRUE(helper->empty()); | 80 ASSERT_TRUE(helper->empty()); |
50 } | 81 } |
51 | 82 |
52 } // namespace | 83 } // namespace |
OLD | NEW |