| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" |
| 6 #include "base/bind_helpers.h" |
| 5 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 6 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/browsing_data_database_helper.h" | 9 #include "chrome/browser/browsing_data_database_helper.h" |
| 8 #include "chrome/browser/browsing_data_helper_browsertest.h" | 10 #include "chrome/browser/browsing_data_helper_browsertest.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/browser/browser_thread.h" | 15 #include "content/browser/browser_thread.h" |
| 14 | 16 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 BrowsingDataDatabaseHelper* database_helper_; | 74 BrowsingDataDatabaseHelper* database_helper_; |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 // Flaky on Win/Mac/Linux: http://crbug.com/92460 | 77 // Flaky on Win/Mac/Linux: http://crbug.com/92460 |
| 76 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, DISABLED_FetchData) { | 78 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, DISABLED_FetchData) { |
| 77 CreateDatabases(); | 79 CreateDatabases(); |
| 78 scoped_refptr<BrowsingDataDatabaseHelper> database_helper( | 80 scoped_refptr<BrowsingDataDatabaseHelper> database_helper( |
| 79 new BrowsingDataDatabaseHelper(browser()->profile())); | 81 new BrowsingDataDatabaseHelper(browser()->profile())); |
| 80 StopTestOnCallback stop_test_on_callback(database_helper); | 82 StopTestOnCallback stop_test_on_callback(database_helper); |
| 81 database_helper->StartFetching( | 83 database_helper->StartFetching( |
| 82 NewCallback(&stop_test_on_callback, &StopTestOnCallback::Callback)); | 84 base::Bind(&StopTestOnCallback::Callback, |
| 85 base::Unretained(&stop_test_on_callback))); |
| 83 // Blocks until StopTestOnCallback::Callback is notified. | 86 // Blocks until StopTestOnCallback::Callback is notified. |
| 84 ui_test_utils::RunMessageLoop(); | 87 ui_test_utils::RunMessageLoop(); |
| 85 } | 88 } |
| 86 | 89 |
| 87 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedAddDatabase) { | 90 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedAddDatabase) { |
| 88 const GURL origin1("http://host1:1/"); | 91 const GURL origin1("http://host1:1/"); |
| 89 const GURL origin2("http://host2:1/"); | 92 const GURL origin2("http://host2:1/"); |
| 90 const char origin_str1[] = "http_host1_1"; | 93 const char origin_str1[] = "http_host1_1"; |
| 91 const char origin_str2[] = "http_host2_1"; | 94 const char origin_str2[] = "http_host2_1"; |
| 92 const char db1[] = "db1"; | 95 const char db1[] = "db1"; |
| 93 const char db2[] = "db2"; | 96 const char db2[] = "db2"; |
| 94 const char db3[] = "db3"; | 97 const char db3[] = "db3"; |
| 95 | 98 |
| 96 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( | 99 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( |
| 97 new CannedBrowsingDataDatabaseHelper(browser()->profile())); | 100 new CannedBrowsingDataDatabaseHelper(browser()->profile())); |
| 98 helper->AddDatabase(origin1, db1, ""); | 101 helper->AddDatabase(origin1, db1, ""); |
| 99 helper->AddDatabase(origin1, db2, ""); | 102 helper->AddDatabase(origin1, db2, ""); |
| 100 helper->AddDatabase(origin2, db3, ""); | 103 helper->AddDatabase(origin2, db3, ""); |
| 101 | 104 |
| 102 TestCompletionCallback callback; | 105 TestCompletionCallback callback; |
| 103 helper->StartFetching( | 106 helper->StartFetching( |
| 104 NewCallback(&callback, &TestCompletionCallback::callback)); | 107 base::Bind(&TestCompletionCallback::callback, |
| 108 base::Unretained(&callback))); |
| 105 | 109 |
| 106 std::list<BrowsingDataDatabaseHelper::DatabaseInfo> result = | 110 std::list<BrowsingDataDatabaseHelper::DatabaseInfo> result = |
| 107 callback.result(); | 111 callback.result(); |
| 108 | 112 |
| 109 ASSERT_EQ(3u, result.size()); | 113 ASSERT_EQ(3u, result.size()); |
| 110 std::list<BrowsingDataDatabaseHelper::DatabaseInfo>::iterator info = | 114 std::list<BrowsingDataDatabaseHelper::DatabaseInfo>::iterator info = |
| 111 result.begin(); | 115 result.begin(); |
| 112 EXPECT_STREQ(origin_str1, info->origin_identifier.c_str()); | 116 EXPECT_STREQ(origin_str1, info->origin_identifier.c_str()); |
| 113 EXPECT_STREQ(db1, info->database_name.c_str()); | 117 EXPECT_STREQ(db1, info->database_name.c_str()); |
| 114 info++; | 118 info++; |
| 115 EXPECT_STREQ(origin_str1, info->origin_identifier.c_str()); | 119 EXPECT_STREQ(origin_str1, info->origin_identifier.c_str()); |
| 116 EXPECT_STREQ(db2, info->database_name.c_str()); | 120 EXPECT_STREQ(db2, info->database_name.c_str()); |
| 117 info++; | 121 info++; |
| 118 EXPECT_STREQ(origin_str2, info->origin_identifier.c_str()); | 122 EXPECT_STREQ(origin_str2, info->origin_identifier.c_str()); |
| 119 EXPECT_STREQ(db3, info->database_name.c_str()); | 123 EXPECT_STREQ(db3, info->database_name.c_str()); |
| 120 } | 124 } |
| 121 | 125 |
| 122 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedUnique) { | 126 IN_PROC_BROWSER_TEST_F(BrowsingDataDatabaseHelperTest, CannedUnique) { |
| 123 const GURL origin("http://host1:1/"); | 127 const GURL origin("http://host1:1/"); |
| 124 const char origin_str[] = "http_host1_1"; | 128 const char origin_str[] = "http_host1_1"; |
| 125 const char db[] = "db1"; | 129 const char db[] = "db1"; |
| 126 | 130 |
| 127 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( | 131 scoped_refptr<CannedBrowsingDataDatabaseHelper> helper( |
| 128 new CannedBrowsingDataDatabaseHelper(browser()->profile())); | 132 new CannedBrowsingDataDatabaseHelper(browser()->profile())); |
| 129 helper->AddDatabase(origin, db, ""); | 133 helper->AddDatabase(origin, db, ""); |
| 130 helper->AddDatabase(origin, db, ""); | 134 helper->AddDatabase(origin, db, ""); |
| 131 | 135 |
| 132 TestCompletionCallback callback; | 136 TestCompletionCallback callback; |
| 133 helper->StartFetching( | 137 helper->StartFetching( |
| 134 NewCallback(&callback, &TestCompletionCallback::callback)); | 138 base::Bind(&TestCompletionCallback::callback, |
| 139 base::Unretained(&callback))); |
| 135 | 140 |
| 136 std::list<BrowsingDataDatabaseHelper::DatabaseInfo> result = | 141 std::list<BrowsingDataDatabaseHelper::DatabaseInfo> result = |
| 137 callback.result(); | 142 callback.result(); |
| 138 | 143 |
| 139 ASSERT_EQ(1u, result.size()); | 144 ASSERT_EQ(1u, result.size()); |
| 140 EXPECT_STREQ(origin_str, result.begin()->origin_identifier.c_str()); | 145 EXPECT_STREQ(origin_str, result.begin()->origin_identifier.c_str()); |
| 141 EXPECT_STREQ(db, result.begin()->database_name.c_str()); | 146 EXPECT_STREQ(db, result.begin()->database_name.c_str()); |
| 142 } | 147 } |
| 143 } // namespace | 148 } // namespace |
| OLD | NEW |