| 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/autocomplete/network_action_predictor.h" | 5 #include "chrome/browser/autocomplete/network_action_predictor.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 db_cache()->find(key); | 163 db_cache()->find(key); |
| 164 ASSERT_TRUE(it != db_cache()->end()); | 164 ASSERT_TRUE(it != db_cache()->end()); |
| 165 | 165 |
| 166 predictor_->UpdateRow(it, row); | 166 predictor_->UpdateRow(it, row); |
| 167 } | 167 } |
| 168 | 168 |
| 169 void DeleteAllRows() { | 169 void DeleteAllRows() { |
| 170 predictor_->DeleteAllRows(); | 170 predictor_->DeleteAllRows(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void DeleteRowsWithURLs(const std::set<GURL>& urls) { | 173 void DeleteRowsWithURLs(const history::URLRows& rows) { |
| 174 predictor_->DeleteRowsWithURLs(urls); | 174 predictor_->DeleteRowsWithURLs(rows); |
| 175 } | 175 } |
| 176 | 176 |
| 177 void DeleteOldIdsFromCaches( | 177 void DeleteOldIdsFromCaches( |
| 178 std::vector<NetworkActionPredictorDatabase::Row::Id>* id_list) { | 178 std::vector<NetworkActionPredictorDatabase::Row::Id>* id_list) { |
| 179 HistoryService* history_service = | 179 HistoryService* history_service = |
| 180 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); | 180 profile_.GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 181 ASSERT_TRUE(history_service); | 181 ASSERT_TRUE(history_service); |
| 182 | 182 |
| 183 history::URLDatabase* url_db = history_service->InMemoryDatabase(); | 183 history::URLDatabase* url_db = history_service->InMemoryDatabase(); |
| 184 ASSERT_TRUE(url_db); | 184 ASSERT_TRUE(url_db); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 EXPECT_TRUE(db_cache()->empty()); | 271 EXPECT_TRUE(db_cache()->empty()); |
| 272 EXPECT_TRUE(db_id_cache()->empty()); | 272 EXPECT_TRUE(db_id_cache()->empty()); |
| 273 } | 273 } |
| 274 | 274 |
| 275 TEST_F(NetworkActionPredictorTest, DeleteRowsWithURLs) { | 275 TEST_F(NetworkActionPredictorTest, DeleteRowsWithURLs) { |
| 276 ASSERT_NO_FATAL_FAILURE(AddAllRows()); | 276 ASSERT_NO_FATAL_FAILURE(AddAllRows()); |
| 277 | 277 |
| 278 EXPECT_EQ(arraysize(test_url_db), db_cache()->size()); | 278 EXPECT_EQ(arraysize(test_url_db), db_cache()->size()); |
| 279 EXPECT_EQ(arraysize(test_url_db), db_id_cache()->size()); | 279 EXPECT_EQ(arraysize(test_url_db), db_id_cache()->size()); |
| 280 | 280 |
| 281 std::set<GURL> urls; | 281 history::URLRows rows; |
| 282 for (size_t i = 0; i < 2; ++i) | 282 for (size_t i = 0; i < 2; ++i) |
| 283 urls.insert(test_url_db[i].url); | 283 rows.push_back(history::URLRow(test_url_db[i].url)); |
| 284 | 284 |
| 285 DeleteRowsWithURLs(urls); | 285 DeleteRowsWithURLs(rows); |
| 286 | 286 |
| 287 EXPECT_EQ(arraysize(test_url_db) - 2, db_cache()->size()); | 287 EXPECT_EQ(arraysize(test_url_db) - 2, db_cache()->size()); |
| 288 EXPECT_EQ(arraysize(test_url_db) - 2, db_id_cache()->size()); | 288 EXPECT_EQ(arraysize(test_url_db) - 2, db_id_cache()->size()); |
| 289 | 289 |
| 290 for (size_t i = 0; i < arraysize(test_url_db); ++i) { | 290 for (size_t i = 0; i < arraysize(test_url_db); ++i) { |
| 291 DBCacheKey key = { test_url_db[i].user_text, test_url_db[i].url }; | 291 DBCacheKey key = { test_url_db[i].user_text, test_url_db[i].url }; |
| 292 | 292 |
| 293 bool deleted = (i < 2); | 293 bool deleted = (i < 2); |
| 294 EXPECT_EQ(deleted, db_cache()->find(key) == db_cache()->end()); | 294 EXPECT_EQ(deleted, db_cache()->find(key) == db_cache()->end()); |
| 295 EXPECT_EQ(deleted, db_id_cache()->find(key) == db_id_cache()->end()); | 295 EXPECT_EQ(deleted, db_id_cache()->find(key) == db_id_cache()->end()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 NetworkActionPredictor::Action expected_action = | 355 NetworkActionPredictor::Action expected_action = |
| 356 (test_url_db[i].expected_action == | 356 (test_url_db[i].expected_action == |
| 357 NetworkActionPredictor::ACTION_PRERENDER) ? | 357 NetworkActionPredictor::ACTION_PRERENDER) ? |
| 358 NetworkActionPredictor::ACTION_PRECONNECT : | 358 NetworkActionPredictor::ACTION_PRECONNECT : |
| 359 test_url_db[i].expected_action; | 359 test_url_db[i].expected_action; |
| 360 EXPECT_EQ(expected_action, | 360 EXPECT_EQ(expected_action, |
| 361 predictor()->RecommendAction(test_url_db[i].user_text, match)) | 361 predictor()->RecommendAction(test_url_db[i].user_text, match)) |
| 362 << "Unexpected action for " << match.destination_url; | 362 << "Unexpected action for " << match.destination_url; |
| 363 } | 363 } |
| 364 } | 364 } |
| OLD | NEW |