| 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 <set> | 5 #include <set> |
| 6 #include <utility> | 6 #include <utility> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 PrefetchDataMap expected_host_data; | 160 PrefetchDataMap expected_host_data; |
| 161 AddKey(&expected_host_data, "www.yahoo.com"); | 161 AddKey(&expected_host_data, "www.yahoo.com"); |
| 162 | 162 |
| 163 TestPrefetchDataAreEqual(expected_url_data, actual_url_data); | 163 TestPrefetchDataAreEqual(expected_url_data, actual_url_data); |
| 164 TestPrefetchDataAreEqual(expected_host_data, actual_host_data); | 164 TestPrefetchDataAreEqual(expected_host_data, actual_host_data); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void ResourcePrefetchPredictorTablesTest::TestUpdateData() { | 167 void ResourcePrefetchPredictorTablesTest::TestUpdateData() { |
| 168 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com"); | 168 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com"); |
| 169 google.last_visit = base::Time::FromInternalValue(10); | 169 google.last_visit = base::Time::FromInternalValue(10); |
| 170 google.resources.push_back(ResourceRow( | 170 google.resources.push_back(ResourceRow(std::string(), |
| 171 "", | 171 "http://www.google.com/style.css", |
| 172 "http://www.google.com/style.css", | 172 ResourceType::STYLESHEET, |
| 173 ResourceType::STYLESHEET, | 173 6, |
| 174 6, 2, 0, 1.0)); | 174 2, |
| 175 google.resources.push_back(ResourceRow( | 175 0, |
| 176 "", | 176 1.0)); |
| 177 "http://www.google.com/image.png", | 177 google.resources.push_back(ResourceRow(std::string(), |
| 178 ResourceType::IMAGE, | 178 "http://www.google.com/image.png", |
| 179 6, 4, 1, 4.2)); | 179 ResourceType::IMAGE, |
| 180 google.resources.push_back(ResourceRow( | 180 6, |
| 181 "", | 181 4, |
| 182 "http://www.google.com/a.xml", | 182 1, |
| 183 ResourceType::LAST_TYPE, | 183 4.2)); |
| 184 1, 0, 0, 6.1)); | 184 google.resources.push_back(ResourceRow(std::string(), |
| 185 google.resources.push_back(ResourceRow( | 185 "http://www.google.com/a.xml", |
| 186 "", | 186 ResourceType::LAST_TYPE, |
| 187 "http://www.resources.google.com/script.js", | 187 1, |
| 188 ResourceType::SCRIPT, | 188 0, |
| 189 12, 0, 0, 8.5)); | 189 0, |
| 190 6.1)); |
| 191 google.resources |
| 192 .push_back(ResourceRow(std::string(), |
| 193 "http://www.resources.google.com/script.js", |
| 194 ResourceType::SCRIPT, |
| 195 12, |
| 196 0, |
| 197 0, |
| 198 8.5)); |
| 190 | 199 |
| 191 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); | 200 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); |
| 192 yahoo.last_visit = base::Time::FromInternalValue(7); | 201 yahoo.last_visit = base::Time::FromInternalValue(7); |
| 193 yahoo.resources.push_back(ResourceRow( | 202 yahoo.resources.push_back(ResourceRow(std::string(), |
| 194 "", | 203 "http://www.yahoo.com/image.png", |
| 195 "http://www.yahoo.com/image.png", | 204 ResourceType::IMAGE, |
| 196 ResourceType::IMAGE, | 205 120, |
| 197 120, 1, 1, 10.0)); | 206 1, |
| 207 1, |
| 208 10.0)); |
| 198 | 209 |
| 199 tables_->UpdateData(google, yahoo); | 210 tables_->UpdateData(google, yahoo); |
| 200 | 211 |
| 201 PrefetchDataMap actual_url_data, actual_host_data; | 212 PrefetchDataMap actual_url_data, actual_host_data; |
| 202 tables_->GetAllData(&actual_url_data, &actual_host_data); | 213 tables_->GetAllData(&actual_url_data, &actual_host_data); |
| 203 | 214 |
| 204 PrefetchDataMap expected_url_data, expected_host_data; | 215 PrefetchDataMap expected_url_data, expected_host_data; |
| 205 AddKey(&expected_url_data, "http://www.reddit.com"); | 216 AddKey(&expected_url_data, "http://www.reddit.com"); |
| 206 AddKey(&expected_url_data, "http://www.yahoo.com"); | 217 AddKey(&expected_url_data, "http://www.yahoo.com"); |
| 207 expected_url_data.insert(std::make_pair("http://www.google.com", google)); | 218 expected_url_data.insert(std::make_pair("http://www.google.com", google)); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 280 } |
| 270 it = test_host_data_.find(key); | 281 it = test_host_data_.find(key); |
| 271 EXPECT_TRUE(it != test_host_data_.end()); | 282 EXPECT_TRUE(it != test_host_data_.end()); |
| 272 m->insert(std::make_pair(it->first, it->second)); | 283 m->insert(std::make_pair(it->first, it->second)); |
| 273 } | 284 } |
| 274 | 285 |
| 275 void ResourcePrefetchPredictorTablesTest::InitializeSampleData() { | 286 void ResourcePrefetchPredictorTablesTest::InitializeSampleData() { |
| 276 { // Url data. | 287 { // Url data. |
| 277 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com"); | 288 PrefetchData google(PREFETCH_KEY_TYPE_URL, "http://www.google.com"); |
| 278 google.last_visit = base::Time::FromInternalValue(1); | 289 google.last_visit = base::Time::FromInternalValue(1); |
| 279 google.resources.push_back(ResourceRow( | 290 google.resources.push_back(ResourceRow(std::string(), |
| 280 "", | 291 "http://www.google.com/style.css", |
| 281 "http://www.google.com/style.css", | 292 ResourceType::STYLESHEET, |
| 282 ResourceType::STYLESHEET, | 293 5, |
| 283 5, 2, 1, 1.1)); | 294 2, |
| 284 google.resources.push_back(ResourceRow( | 295 1, |
| 285 "", | 296 1.1)); |
| 286 "http://www.google.com/script.js", | 297 google.resources.push_back(ResourceRow(std::string(), |
| 287 ResourceType::SCRIPT, | 298 "http://www.google.com/script.js", |
| 288 4, 0, 1, 2.1)); | 299 ResourceType::SCRIPT, |
| 289 google.resources.push_back(ResourceRow( | 300 4, |
| 290 "", | 301 0, |
| 291 "http://www.google.com/image.png", | 302 1, |
| 292 ResourceType::IMAGE, | 303 2.1)); |
| 293 6, 3, 0, 2.2)); | 304 google.resources.push_back(ResourceRow(std::string(), |
| 294 google.resources.push_back(ResourceRow( | 305 "http://www.google.com/image.png", |
| 295 "", | 306 ResourceType::IMAGE, |
| 296 "http://www.google.com/a.font", | 307 6, |
| 297 ResourceType::LAST_TYPE, | 308 3, |
| 298 2, 0, 0, 5.1)); | 309 0, |
| 299 google.resources.push_back(ResourceRow( | 310 2.2)); |
| 300 "", | 311 google.resources.push_back(ResourceRow(std::string(), |
| 301 "http://www.resources.google.com/script.js", | 312 "http://www.google.com/a.font", |
| 302 ResourceType::SCRIPT, | 313 ResourceType::LAST_TYPE, |
| 303 11, 0, 0, 8.5)); | 314 2, |
| 315 0, |
| 316 0, |
| 317 5.1)); |
| 318 google.resources |
| 319 .push_back(ResourceRow(std::string(), |
| 320 "http://www.resources.google.com/script.js", |
| 321 ResourceType::SCRIPT, |
| 322 11, |
| 323 0, |
| 324 0, |
| 325 8.5)); |
| 304 | 326 |
| 305 PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com"); | 327 PrefetchData reddit(PREFETCH_KEY_TYPE_URL, "http://www.reddit.com"); |
| 306 reddit.last_visit = base::Time::FromInternalValue(2); | 328 reddit.last_visit = base::Time::FromInternalValue(2); |
| 307 reddit.resources.push_back(ResourceRow( | 329 reddit.resources |
| 308 "", | 330 .push_back(ResourceRow(std::string(), |
| 309 "http://reddit-resource.com/script1.js", | 331 "http://reddit-resource.com/script1.js", |
| 310 ResourceType::SCRIPT, | 332 ResourceType::SCRIPT, |
| 311 4, 0, 1, 1.0)); | 333 4, |
| 312 reddit.resources.push_back(ResourceRow( | 334 0, |
| 313 "", | 335 1, |
| 314 "http://reddit-resource.com/script2.js", | 336 1.0)); |
| 315 ResourceType::SCRIPT, | 337 reddit.resources |
| 316 2, 0, 0, 2.1)); | 338 .push_back(ResourceRow(std::string(), |
| 339 "http://reddit-resource.com/script2.js", |
| 340 ResourceType::SCRIPT, |
| 341 2, |
| 342 0, |
| 343 0, |
| 344 2.1)); |
| 317 | 345 |
| 318 PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com"); | 346 PrefetchData yahoo(PREFETCH_KEY_TYPE_URL, "http://www.yahoo.com"); |
| 319 yahoo.last_visit = base::Time::FromInternalValue(3); | 347 yahoo.last_visit = base::Time::FromInternalValue(3); |
| 320 yahoo.resources.push_back(ResourceRow( | 348 yahoo.resources.push_back(ResourceRow(std::string(), |
| 321 "", | 349 "http://www.google.com/image.png", |
| 322 "http://www.google.com/image.png", | 350 ResourceType::IMAGE, |
| 323 ResourceType::IMAGE, | 351 20, |
| 324 20, 1, 0, 10.0)); | 352 1, |
| 353 0, |
| 354 10.0)); |
| 325 | 355 |
| 326 test_url_data_.clear(); | 356 test_url_data_.clear(); |
| 327 test_url_data_.insert(std::make_pair("http://www.google.com", google)); | 357 test_url_data_.insert(std::make_pair("http://www.google.com", google)); |
| 328 test_url_data_.insert(std::make_pair("http://www.reddit.com", reddit)); | 358 test_url_data_.insert(std::make_pair("http://www.reddit.com", reddit)); |
| 329 test_url_data_.insert(std::make_pair("http://www.yahoo.com", yahoo)); | 359 test_url_data_.insert(std::make_pair("http://www.yahoo.com", yahoo)); |
| 330 | 360 |
| 331 PrefetchData empty_host_data(PREFETCH_KEY_TYPE_HOST, ""); | 361 PrefetchData empty_host_data(PREFETCH_KEY_TYPE_HOST, std::string()); |
| 332 tables_->UpdateData(google, empty_host_data); | 362 tables_->UpdateData(google, empty_host_data); |
| 333 tables_->UpdateData(reddit, empty_host_data); | 363 tables_->UpdateData(reddit, empty_host_data); |
| 334 tables_->UpdateData(yahoo, empty_host_data); | 364 tables_->UpdateData(yahoo, empty_host_data); |
| 335 } | 365 } |
| 336 | 366 |
| 337 { // Host data. | 367 { // Host data. |
| 338 PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com"); | 368 PrefetchData facebook(PREFETCH_KEY_TYPE_HOST, "www.facebook.com"); |
| 339 facebook.last_visit = base::Time::FromInternalValue(4); | 369 facebook.last_visit = base::Time::FromInternalValue(4); |
| 340 facebook.resources.push_back(ResourceRow( | 370 facebook.resources |
| 341 "", | 371 .push_back(ResourceRow(std::string(), |
| 342 "http://www.facebook.com/style.css", | 372 "http://www.facebook.com/style.css", |
| 343 ResourceType::STYLESHEET, | 373 ResourceType::STYLESHEET, |
| 344 5, 2, 1, 1.1)); | 374 5, |
| 345 facebook.resources.push_back(ResourceRow( | 375 2, |
| 346 "", | 376 1, |
| 347 "http://www.facebook.com/script.js", | 377 1.1)); |
| 348 ResourceType::SCRIPT, | 378 facebook.resources |
| 349 4, 0, 1, 2.1)); | 379 .push_back(ResourceRow(std::string(), |
| 350 facebook.resources.push_back(ResourceRow( | 380 "http://www.facebook.com/script.js", |
| 351 "", | 381 ResourceType::SCRIPT, |
| 352 "http://www.facebook.com/image.png", | 382 4, |
| 353 ResourceType::IMAGE, | 383 0, |
| 354 6, 3, 0, 2.2)); | 384 1, |
| 355 facebook.resources.push_back(ResourceRow( | 385 2.1)); |
| 356 "", | 386 facebook.resources |
| 357 "http://www.facebook.com/a.font", | 387 .push_back(ResourceRow(std::string(), |
| 358 ResourceType::LAST_TYPE, | 388 "http://www.facebook.com/image.png", |
| 359 2, 0, 0, 5.1)); | 389 ResourceType::IMAGE, |
| 360 facebook.resources.push_back(ResourceRow( | 390 6, |
| 361 "", | 391 3, |
| 362 "http://www.resources.facebook.com/script.js", | 392 0, |
| 363 ResourceType::SCRIPT, | 393 2.2)); |
| 364 11, 0, 0, 8.5)); | 394 facebook.resources.push_back(ResourceRow(std::string(), |
| 395 "http://www.facebook.com/a.font", |
| 396 ResourceType::LAST_TYPE, |
| 397 2, |
| 398 0, |
| 399 0, |
| 400 5.1)); |
| 401 facebook.resources |
| 402 .push_back(ResourceRow(std::string(), |
| 403 "http://www.resources.facebook.com/script.js", |
| 404 ResourceType::SCRIPT, |
| 405 11, |
| 406 0, |
| 407 0, |
| 408 8.5)); |
| 365 | 409 |
| 366 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); | 410 PrefetchData yahoo(PREFETCH_KEY_TYPE_HOST, "www.yahoo.com"); |
| 367 yahoo.last_visit = base::Time::FromInternalValue(5); | 411 yahoo.last_visit = base::Time::FromInternalValue(5); |
| 368 yahoo.resources.push_back(ResourceRow( | 412 yahoo.resources.push_back(ResourceRow(std::string(), |
| 369 "", | 413 "http://www.google.com/image.png", |
| 370 "http://www.google.com/image.png", | 414 ResourceType::IMAGE, |
| 371 ResourceType::IMAGE, | 415 20, |
| 372 20, 1, 0, 10.0)); | 416 1, |
| 417 0, |
| 418 10.0)); |
| 373 | 419 |
| 374 test_host_data_.clear(); | 420 test_host_data_.clear(); |
| 375 test_host_data_.insert(std::make_pair("www.facebook.com", facebook)); | 421 test_host_data_.insert(std::make_pair("www.facebook.com", facebook)); |
| 376 test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo)); | 422 test_host_data_.insert(std::make_pair("www.yahoo.com", yahoo)); |
| 377 | 423 |
| 378 PrefetchData empty_url_data(PREFETCH_KEY_TYPE_URL, ""); | 424 PrefetchData empty_url_data(PREFETCH_KEY_TYPE_URL, std::string()); |
| 379 tables_->UpdateData(empty_url_data, facebook); | 425 tables_->UpdateData(empty_url_data, facebook); |
| 380 tables_->UpdateData(empty_url_data, yahoo); | 426 tables_->UpdateData(empty_url_data, yahoo); |
| 381 } | 427 } |
| 382 } | 428 } |
| 383 | 429 |
| 384 // Test cases. | 430 // Test cases. |
| 385 | 431 |
| 386 TEST_F(ResourcePrefetchPredictorTablesTest, GetAllData) { | 432 TEST_F(ResourcePrefetchPredictorTablesTest, GetAllData) { |
| 387 TestGetAllData(); | 433 TestGetAllData(); |
| 388 } | 434 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 417 | 463 |
| 418 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteSingleDataPoint) { | 464 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteSingleDataPoint) { |
| 419 TestDeleteSingleDataPoint(); | 465 TestDeleteSingleDataPoint(); |
| 420 } | 466 } |
| 421 | 467 |
| 422 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteAllData) { | 468 TEST_F(ResourcePrefetchPredictorTablesReopenTest, DeleteAllData) { |
| 423 TestDeleteAllData(); | 469 TestDeleteAllData(); |
| 424 } | 470 } |
| 425 | 471 |
| 426 } // namespace predictors | 472 } // namespace predictors |
| OLD | NEW |