| 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 // History unit tests come in two flavors: | 5 // History unit tests come in two flavors: |
| 6 // | 6 // |
| 7 // 1. The more complicated style is that the unit test creates a full history | 7 // 1. The more complicated style is that the unit test creates a full history |
| 8 // service. This spawns a background thread for the history backend, and | 8 // service. This spawns a background thread for the history backend, and |
| 9 // all communication is asynchronous. This is useful for testing more | 9 // all communication is asynchronous. This is useful for testing more |
| 10 // complicated things or end-to-end behavior. | 10 // complicated things or end-to-end behavior. |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 } | 395 } |
| 396 | 396 |
| 397 TEST_F(HistoryTest, AddPage) { | 397 TEST_F(HistoryTest, AddPage) { |
| 398 scoped_refptr<HistoryService> history(new HistoryService); | 398 scoped_refptr<HistoryService> history(new HistoryService); |
| 399 history_service_ = history; | 399 history_service_ = history; |
| 400 ASSERT_TRUE(history->Init(history_dir_, NULL)); | 400 ASSERT_TRUE(history->Init(history_dir_, NULL)); |
| 401 | 401 |
| 402 // Add the page once from a child frame. | 402 // Add the page once from a child frame. |
| 403 const GURL test_url("http://www.google.com/"); | 403 const GURL test_url("http://www.google.com/"); |
| 404 history->AddPage(test_url, NULL, 0, GURL(), | 404 history->AddPage(test_url, NULL, 0, GURL(), |
| 405 PageTransition::MANUAL_SUBFRAME, | 405 content::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 406 history::RedirectList(), | 406 history::RedirectList(), |
| 407 history::SOURCE_BROWSED, false); | 407 history::SOURCE_BROWSED, false); |
| 408 EXPECT_TRUE(QueryURL(history, test_url)); | 408 EXPECT_TRUE(QueryURL(history, test_url)); |
| 409 EXPECT_EQ(1, query_url_row_.visit_count()); | 409 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 410 EXPECT_EQ(0, query_url_row_.typed_count()); | 410 EXPECT_EQ(0, query_url_row_.typed_count()); |
| 411 EXPECT_TRUE(query_url_row_.hidden()); // Hidden because of child frame. | 411 EXPECT_TRUE(query_url_row_.hidden()); // Hidden because of child frame. |
| 412 | 412 |
| 413 // Add the page once from the main frame (should unhide it). | 413 // Add the page once from the main frame (should unhide it). |
| 414 history->AddPage(test_url, NULL, 0, GURL(), PageTransition::LINK, | 414 history->AddPage(test_url, NULL, 0, GURL(), content::PAGE_TRANSITION_LINK, |
| 415 history::RedirectList(), | 415 history::RedirectList(), |
| 416 history::SOURCE_BROWSED, false); | 416 history::SOURCE_BROWSED, false); |
| 417 EXPECT_TRUE(QueryURL(history, test_url)); | 417 EXPECT_TRUE(QueryURL(history, test_url)); |
| 418 EXPECT_EQ(2, query_url_row_.visit_count()); // Added twice. | 418 EXPECT_EQ(2, query_url_row_.visit_count()); // Added twice. |
| 419 EXPECT_EQ(0, query_url_row_.typed_count()); // Never typed. | 419 EXPECT_EQ(0, query_url_row_.typed_count()); // Never typed. |
| 420 EXPECT_FALSE(query_url_row_.hidden()); // Because loaded in main frame. | 420 EXPECT_FALSE(query_url_row_.hidden()); // Because loaded in main frame. |
| 421 } | 421 } |
| 422 | 422 |
| 423 TEST_F(HistoryTest, AddPageSameTimes) { | 423 TEST_F(HistoryTest, AddPageSameTimes) { |
| 424 scoped_refptr<HistoryService> history(new HistoryService); | 424 scoped_refptr<HistoryService> history(new HistoryService); |
| 425 history_service_ = history; | 425 history_service_ = history; |
| 426 ASSERT_TRUE(history->Init(history_dir_, NULL)); | 426 ASSERT_TRUE(history->Init(history_dir_, NULL)); |
| 427 | 427 |
| 428 Time now = Time::Now(); | 428 Time now = Time::Now(); |
| 429 const GURL test_urls[] = { | 429 const GURL test_urls[] = { |
| 430 GURL("http://timer.first.page/"), | 430 GURL("http://timer.first.page/"), |
| 431 GURL("http://timer.second.page/"), | 431 GURL("http://timer.second.page/"), |
| 432 GURL("http://timer.third.page/"), | 432 GURL("http://timer.third.page/"), |
| 433 }; | 433 }; |
| 434 | 434 |
| 435 // Make sure that two pages added at the same time with no intervening | 435 // Make sure that two pages added at the same time with no intervening |
| 436 // additions have different timestamps. | 436 // additions have different timestamps. |
| 437 history->AddPage(test_urls[0], now, NULL, 0, GURL(), | 437 history->AddPage(test_urls[0], now, NULL, 0, GURL(), |
| 438 PageTransition::LINK, | 438 content::PAGE_TRANSITION_LINK, |
| 439 history::RedirectList(), | 439 history::RedirectList(), |
| 440 history::SOURCE_BROWSED, false); | 440 history::SOURCE_BROWSED, false); |
| 441 EXPECT_TRUE(QueryURL(history, test_urls[0])); | 441 EXPECT_TRUE(QueryURL(history, test_urls[0])); |
| 442 EXPECT_EQ(1, query_url_row_.visit_count()); | 442 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 443 EXPECT_TRUE(now == query_url_row_.last_visit()); // gtest doesn't like Time | 443 EXPECT_TRUE(now == query_url_row_.last_visit()); // gtest doesn't like Time |
| 444 | 444 |
| 445 history->AddPage(test_urls[1], now, NULL, 0, GURL(), | 445 history->AddPage(test_urls[1], now, NULL, 0, GURL(), |
| 446 PageTransition::LINK, | 446 content::PAGE_TRANSITION_LINK, |
| 447 history::RedirectList(), | 447 history::RedirectList(), |
| 448 history::SOURCE_BROWSED, false); | 448 history::SOURCE_BROWSED, false); |
| 449 EXPECT_TRUE(QueryURL(history, test_urls[1])); | 449 EXPECT_TRUE(QueryURL(history, test_urls[1])); |
| 450 EXPECT_EQ(1, query_url_row_.visit_count()); | 450 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 451 EXPECT_TRUE(now + TimeDelta::FromMicroseconds(1) == | 451 EXPECT_TRUE(now + TimeDelta::FromMicroseconds(1) == |
| 452 query_url_row_.last_visit()); | 452 query_url_row_.last_visit()); |
| 453 | 453 |
| 454 // Make sure the next page, at a different time, is also correct. | 454 // Make sure the next page, at a different time, is also correct. |
| 455 history->AddPage(test_urls[2], now + TimeDelta::FromMinutes(1), | 455 history->AddPage(test_urls[2], now + TimeDelta::FromMinutes(1), |
| 456 NULL, 0, GURL(), | 456 NULL, 0, GURL(), |
| 457 PageTransition::LINK, | 457 content::PAGE_TRANSITION_LINK, |
| 458 history::RedirectList(), | 458 history::RedirectList(), |
| 459 history::SOURCE_BROWSED, false); | 459 history::SOURCE_BROWSED, false); |
| 460 EXPECT_TRUE(QueryURL(history, test_urls[2])); | 460 EXPECT_TRUE(QueryURL(history, test_urls[2])); |
| 461 EXPECT_EQ(1, query_url_row_.visit_count()); | 461 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 462 EXPECT_TRUE(now + TimeDelta::FromMinutes(1) == | 462 EXPECT_TRUE(now + TimeDelta::FromMinutes(1) == |
| 463 query_url_row_.last_visit()); | 463 query_url_row_.last_visit()); |
| 464 } | 464 } |
| 465 | 465 |
| 466 TEST_F(HistoryTest, AddRedirect) { | 466 TEST_F(HistoryTest, AddRedirect) { |
| 467 scoped_refptr<HistoryService> history(new HistoryService); | 467 scoped_refptr<HistoryService> history(new HistoryService); |
| 468 history_service_ = history; | 468 history_service_ = history; |
| 469 ASSERT_TRUE(history->Init(history_dir_, NULL)); | 469 ASSERT_TRUE(history->Init(history_dir_, NULL)); |
| 470 | 470 |
| 471 const char* first_sequence[] = { | 471 const char* first_sequence[] = { |
| 472 "http://first.page/", | 472 "http://first.page/", |
| 473 "http://second.page/"}; | 473 "http://second.page/"}; |
| 474 int first_count = arraysize(first_sequence); | 474 int first_count = arraysize(first_sequence); |
| 475 history::RedirectList first_redirects; | 475 history::RedirectList first_redirects; |
| 476 for (int i = 0; i < first_count; i++) | 476 for (int i = 0; i < first_count; i++) |
| 477 first_redirects.push_back(GURL(first_sequence[i])); | 477 first_redirects.push_back(GURL(first_sequence[i])); |
| 478 | 478 |
| 479 // Add the sequence of pages as a server with no referrer. Note that we need | 479 // Add the sequence of pages as a server with no referrer. Note that we need |
| 480 // to have a non-NULL page ID scope. | 480 // to have a non-NULL page ID scope. |
| 481 history->AddPage(first_redirects.back(), MakeFakeHost(1), 0, GURL(), | 481 history->AddPage(first_redirects.back(), MakeFakeHost(1), 0, GURL(), |
| 482 PageTransition::LINK, first_redirects, | 482 content::PAGE_TRANSITION_LINK, first_redirects, |
| 483 history::SOURCE_BROWSED, true); | 483 history::SOURCE_BROWSED, true); |
| 484 | 484 |
| 485 // The first page should be added once with a link visit type (because we set | 485 // The first page should be added once with a link visit type (because we set |
| 486 // LINK when we added the original URL, and a referrer of nowhere (0). | 486 // LINK when we added the original URL, and a referrer of nowhere (0). |
| 487 EXPECT_TRUE(QueryURL(history, first_redirects[0])); | 487 EXPECT_TRUE(QueryURL(history, first_redirects[0])); |
| 488 EXPECT_EQ(1, query_url_row_.visit_count()); | 488 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 489 ASSERT_EQ(1U, query_url_visits_.size()); | 489 ASSERT_EQ(1U, query_url_visits_.size()); |
| 490 int64 first_visit = query_url_visits_[0].visit_id; | 490 int64 first_visit = query_url_visits_[0].visit_id; |
| 491 EXPECT_EQ(PageTransition::LINK | | 491 EXPECT_EQ(content::PAGE_TRANSITION_LINK | |
| 492 PageTransition::CHAIN_START, query_url_visits_[0].transition); | 492 content::PAGE_TRANSITION_CHAIN_START, |
| 493 query_url_visits_[0].transition); |
| 493 EXPECT_EQ(0, query_url_visits_[0].referring_visit); // No referrer. | 494 EXPECT_EQ(0, query_url_visits_[0].referring_visit); // No referrer. |
| 494 | 495 |
| 495 // The second page should be a server redirect type with a referrer of the | 496 // The second page should be a server redirect type with a referrer of the |
| 496 // first page. | 497 // first page. |
| 497 EXPECT_TRUE(QueryURL(history, first_redirects[1])); | 498 EXPECT_TRUE(QueryURL(history, first_redirects[1])); |
| 498 EXPECT_EQ(1, query_url_row_.visit_count()); | 499 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 499 ASSERT_EQ(1U, query_url_visits_.size()); | 500 ASSERT_EQ(1U, query_url_visits_.size()); |
| 500 int64 second_visit = query_url_visits_[0].visit_id; | 501 int64 second_visit = query_url_visits_[0].visit_id; |
| 501 EXPECT_EQ(PageTransition::SERVER_REDIRECT | | 502 EXPECT_EQ(content::PAGE_TRANSITION_SERVER_REDIRECT | |
| 502 PageTransition::CHAIN_END, query_url_visits_[0].transition); | 503 content::PAGE_TRANSITION_CHAIN_END, |
| 504 query_url_visits_[0].transition); |
| 503 EXPECT_EQ(first_visit, query_url_visits_[0].referring_visit); | 505 EXPECT_EQ(first_visit, query_url_visits_[0].referring_visit); |
| 504 | 506 |
| 505 // Check that the redirect finding function successfully reports it. | 507 // Check that the redirect finding function successfully reports it. |
| 506 saved_redirects_.clear(); | 508 saved_redirects_.clear(); |
| 507 QueryRedirectsFrom(history, first_redirects[0]); | 509 QueryRedirectsFrom(history, first_redirects[0]); |
| 508 ASSERT_EQ(1U, saved_redirects_.size()); | 510 ASSERT_EQ(1U, saved_redirects_.size()); |
| 509 EXPECT_EQ(first_redirects[1], saved_redirects_[0]); | 511 EXPECT_EQ(first_redirects[1], saved_redirects_[0]); |
| 510 | 512 |
| 511 // Now add a client redirect from that second visit to a third, client | 513 // Now add a client redirect from that second visit to a third, client |
| 512 // redirects are tracked by the RenderView prior to updating history, | 514 // redirects are tracked by the RenderView prior to updating history, |
| 513 // so we pass in a CLIENT_REDIRECT qualifier to mock that behavior. | 515 // so we pass in a CLIENT_REDIRECT qualifier to mock that behavior. |
| 514 history::RedirectList second_redirects; | 516 history::RedirectList second_redirects; |
| 515 second_redirects.push_back(first_redirects[1]); | 517 second_redirects.push_back(first_redirects[1]); |
| 516 second_redirects.push_back(GURL("http://last.page/")); | 518 second_redirects.push_back(GURL("http://last.page/")); |
| 517 history->AddPage(second_redirects[1], MakeFakeHost(1), 1, | 519 history->AddPage(second_redirects[1], MakeFakeHost(1), 1, |
| 518 second_redirects[0], | 520 second_redirects[0], |
| 519 static_cast<PageTransition::Type>(PageTransition::LINK | | 521 static_cast<content::PageTransition>( |
| 520 PageTransition::CLIENT_REDIRECT), | 522 content::PAGE_TRANSITION_LINK | |
| 523 content::PAGE_TRANSITION_CLIENT_REDIRECT), |
| 521 second_redirects, history::SOURCE_BROWSED, true); | 524 second_redirects, history::SOURCE_BROWSED, true); |
| 522 | 525 |
| 523 // The last page (source of the client redirect) should NOT have an | 526 // The last page (source of the client redirect) should NOT have an |
| 524 // additional visit added, because it was a client redirect (normally it | 527 // additional visit added, because it was a client redirect (normally it |
| 525 // would). We should only have 1 left over from the first sequence. | 528 // would). We should only have 1 left over from the first sequence. |
| 526 EXPECT_TRUE(QueryURL(history, second_redirects[0])); | 529 EXPECT_TRUE(QueryURL(history, second_redirects[0])); |
| 527 EXPECT_EQ(1, query_url_row_.visit_count()); | 530 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 528 | 531 |
| 529 // The final page should be set as a client redirect from the previous visit. | 532 // The final page should be set as a client redirect from the previous visit. |
| 530 EXPECT_TRUE(QueryURL(history, second_redirects[1])); | 533 EXPECT_TRUE(QueryURL(history, second_redirects[1])); |
| 531 EXPECT_EQ(1, query_url_row_.visit_count()); | 534 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 532 ASSERT_EQ(1U, query_url_visits_.size()); | 535 ASSERT_EQ(1U, query_url_visits_.size()); |
| 533 EXPECT_EQ(PageTransition::CLIENT_REDIRECT | | 536 EXPECT_EQ(content::PAGE_TRANSITION_CLIENT_REDIRECT | |
| 534 PageTransition::CHAIN_END, query_url_visits_[0].transition); | 537 content::PAGE_TRANSITION_CHAIN_END, query_url_visits_[0].transition)
; |
| 535 EXPECT_EQ(second_visit, query_url_visits_[0].referring_visit); | 538 EXPECT_EQ(second_visit, query_url_visits_[0].referring_visit); |
| 536 } | 539 } |
| 537 | 540 |
| 538 TEST_F(HistoryTest, Typed) { | 541 TEST_F(HistoryTest, Typed) { |
| 539 scoped_refptr<HistoryService> history(new HistoryService); | 542 scoped_refptr<HistoryService> history(new HistoryService); |
| 540 history_service_ = history; | 543 history_service_ = history; |
| 541 ASSERT_TRUE(history->Init(history_dir_, NULL)); | 544 ASSERT_TRUE(history->Init(history_dir_, NULL)); |
| 542 | 545 |
| 543 // Add the page once as typed. | 546 // Add the page once as typed. |
| 544 const GURL test_url("http://www.google.com/"); | 547 const GURL test_url("http://www.google.com/"); |
| 545 history->AddPage(test_url, NULL, 0, GURL(), PageTransition::TYPED, | 548 history->AddPage(test_url, NULL, 0, GURL(), content::PAGE_TRANSITION_TYPED, |
| 546 history::RedirectList(), | 549 history::RedirectList(), |
| 547 history::SOURCE_BROWSED, false); | 550 history::SOURCE_BROWSED, false); |
| 548 EXPECT_TRUE(QueryURL(history, test_url)); | 551 EXPECT_TRUE(QueryURL(history, test_url)); |
| 549 | 552 |
| 550 // We should have the same typed & visit count. | 553 // We should have the same typed & visit count. |
| 551 EXPECT_EQ(1, query_url_row_.visit_count()); | 554 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 552 EXPECT_EQ(1, query_url_row_.typed_count()); | 555 EXPECT_EQ(1, query_url_row_.typed_count()); |
| 553 | 556 |
| 554 // Add the page again not typed. | 557 // Add the page again not typed. |
| 555 history->AddPage(test_url, NULL, 0, GURL(), PageTransition::LINK, | 558 history->AddPage(test_url, NULL, 0, GURL(), content::PAGE_TRANSITION_LINK, |
| 556 history::RedirectList(), | 559 history::RedirectList(), |
| 557 history::SOURCE_BROWSED, false); | 560 history::SOURCE_BROWSED, false); |
| 558 EXPECT_TRUE(QueryURL(history, test_url)); | 561 EXPECT_TRUE(QueryURL(history, test_url)); |
| 559 | 562 |
| 560 // The second time should not have updated the typed count. | 563 // The second time should not have updated the typed count. |
| 561 EXPECT_EQ(2, query_url_row_.visit_count()); | 564 EXPECT_EQ(2, query_url_row_.visit_count()); |
| 562 EXPECT_EQ(1, query_url_row_.typed_count()); | 565 EXPECT_EQ(1, query_url_row_.typed_count()); |
| 563 | 566 |
| 564 // Add the page again as a generated URL. | 567 // Add the page again as a generated URL. |
| 565 history->AddPage(test_url, NULL, 0, GURL(), | 568 history->AddPage(test_url, NULL, 0, GURL(), |
| 566 PageTransition::GENERATED, history::RedirectList(), | 569 content::PAGE_TRANSITION_GENERATED, history::RedirectList(), |
| 567 history::SOURCE_BROWSED, false); | 570 history::SOURCE_BROWSED, false); |
| 568 EXPECT_TRUE(QueryURL(history, test_url)); | 571 EXPECT_TRUE(QueryURL(history, test_url)); |
| 569 | 572 |
| 570 // This should have worked like a link click. | 573 // This should have worked like a link click. |
| 571 EXPECT_EQ(3, query_url_row_.visit_count()); | 574 EXPECT_EQ(3, query_url_row_.visit_count()); |
| 572 EXPECT_EQ(1, query_url_row_.typed_count()); | 575 EXPECT_EQ(1, query_url_row_.typed_count()); |
| 573 | 576 |
| 574 // Add the page again as a reload. | 577 // Add the page again as a reload. |
| 575 history->AddPage(test_url, NULL, 0, GURL(), | 578 history->AddPage(test_url, NULL, 0, GURL(), |
| 576 PageTransition::RELOAD, history::RedirectList(), | 579 content::PAGE_TRANSITION_RELOAD, history::RedirectList(), |
| 577 history::SOURCE_BROWSED, false); | 580 history::SOURCE_BROWSED, false); |
| 578 EXPECT_TRUE(QueryURL(history, test_url)); | 581 EXPECT_TRUE(QueryURL(history, test_url)); |
| 579 | 582 |
| 580 // This should not have incremented any visit counts. | 583 // This should not have incremented any visit counts. |
| 581 EXPECT_EQ(3, query_url_row_.visit_count()); | 584 EXPECT_EQ(3, query_url_row_.visit_count()); |
| 582 EXPECT_EQ(1, query_url_row_.typed_count()); | 585 EXPECT_EQ(1, query_url_row_.typed_count()); |
| 583 } | 586 } |
| 584 | 587 |
| 585 TEST_F(HistoryTest, SetTitle) { | 588 TEST_F(HistoryTest, SetTitle) { |
| 586 scoped_refptr<HistoryService> history(new HistoryService); | 589 scoped_refptr<HistoryService> history(new HistoryService); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 616 scoped_refptr<HistoryService> history(new HistoryService); | 619 scoped_refptr<HistoryService> history(new HistoryService); |
| 617 history_service_ = history; | 620 history_service_ = history; |
| 618 | 621 |
| 619 ASSERT_TRUE(history->Init(history_dir_, NULL)); | 622 ASSERT_TRUE(history->Init(history_dir_, NULL)); |
| 620 | 623 |
| 621 static const void* scope = static_cast<void*>(this); | 624 static const void* scope = static_cast<void*>(this); |
| 622 | 625 |
| 623 // Add a URL. | 626 // Add a URL. |
| 624 const GURL existing_url("http://www.google.com/"); | 627 const GURL existing_url("http://www.google.com/"); |
| 625 history->AddPage(existing_url, scope, 0, GURL(), | 628 history->AddPage(existing_url, scope, 0, GURL(), |
| 626 PageTransition::TYPED, history::RedirectList(), | 629 content::PAGE_TRANSITION_TYPED, history::RedirectList(), |
| 627 history::SOURCE_BROWSED, false); | 630 history::SOURCE_BROWSED, false); |
| 628 | 631 |
| 629 // Make sure a segment was created. | 632 // Make sure a segment was created. |
| 630 history->QuerySegmentUsageSince( | 633 history->QuerySegmentUsageSince( |
| 631 &consumer_, Time::Now() - TimeDelta::FromDays(1), 10, | 634 &consumer_, Time::Now() - TimeDelta::FromDays(1), 10, |
| 632 base::Bind(&HistoryTest::OnSegmentUsageAvailable, | 635 base::Bind(&HistoryTest::OnSegmentUsageAvailable, |
| 633 base::Unretained(this))); | 636 base::Unretained(this))); |
| 634 | 637 |
| 635 // Wait for processing. | 638 // Wait for processing. |
| 636 MessageLoop::current()->Run(); | 639 MessageLoop::current()->Run(); |
| 637 | 640 |
| 638 ASSERT_EQ(1U, page_usage_data_->size()); | 641 ASSERT_EQ(1U, page_usage_data_->size()); |
| 639 EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url); | 642 EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url); |
| 640 EXPECT_DOUBLE_EQ(3.0, page_usage_data_[0]->GetScore()); | 643 EXPECT_DOUBLE_EQ(3.0, page_usage_data_[0]->GetScore()); |
| 641 | 644 |
| 642 // Add a URL which doesn't create a segment. | 645 // Add a URL which doesn't create a segment. |
| 643 const GURL link_url("http://yahoo.com/"); | 646 const GURL link_url("http://yahoo.com/"); |
| 644 history->AddPage(link_url, scope, 0, GURL(), | 647 history->AddPage(link_url, scope, 0, GURL(), |
| 645 PageTransition::LINK, history::RedirectList(), | 648 content::PAGE_TRANSITION_LINK, history::RedirectList(), |
| 646 history::SOURCE_BROWSED, false); | 649 history::SOURCE_BROWSED, false); |
| 647 | 650 |
| 648 // Query again | 651 // Query again |
| 649 history->QuerySegmentUsageSince( | 652 history->QuerySegmentUsageSince( |
| 650 &consumer_, Time::Now() - TimeDelta::FromDays(1), 10, | 653 &consumer_, Time::Now() - TimeDelta::FromDays(1), 10, |
| 651 base::Bind(&HistoryTest::OnSegmentUsageAvailable, | 654 base::Bind(&HistoryTest::OnSegmentUsageAvailable, |
| 652 base::Unretained(this))); | 655 base::Unretained(this))); |
| 653 | 656 |
| 654 // Wait for processing. | 657 // Wait for processing. |
| 655 MessageLoop::current()->Run(); | 658 MessageLoop::current()->Run(); |
| 656 | 659 |
| 657 // Make sure we still have one segment. | 660 // Make sure we still have one segment. |
| 658 ASSERT_EQ(1U, page_usage_data_->size()); | 661 ASSERT_EQ(1U, page_usage_data_->size()); |
| 659 EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url); | 662 EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url); |
| 660 | 663 |
| 661 // Add a page linked from existing_url. | 664 // Add a page linked from existing_url. |
| 662 history->AddPage(GURL("http://www.google.com/foo"), scope, 3, existing_url, | 665 history->AddPage(GURL("http://www.google.com/foo"), scope, 3, existing_url, |
| 663 PageTransition::LINK, history::RedirectList(), | 666 content::PAGE_TRANSITION_LINK, history::RedirectList(), |
| 664 history::SOURCE_BROWSED, false); | 667 history::SOURCE_BROWSED, false); |
| 665 | 668 |
| 666 // Query again | 669 // Query again |
| 667 history->QuerySegmentUsageSince( | 670 history->QuerySegmentUsageSince( |
| 668 &consumer_, Time::Now() - TimeDelta::FromDays(1), 10, | 671 &consumer_, Time::Now() - TimeDelta::FromDays(1), 10, |
| 669 base::Bind(&HistoryTest::OnSegmentUsageAvailable, | 672 base::Bind(&HistoryTest::OnSegmentUsageAvailable, |
| 670 base::Unretained(this))); | 673 base::Unretained(this))); |
| 671 | 674 |
| 672 // Wait for processing. | 675 // Wait for processing. |
| 673 MessageLoop::current()->Run(); | 676 MessageLoop::current()->Run(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 688 const GURL url0("http://www.google.com/url0/"); | 691 const GURL url0("http://www.google.com/url0/"); |
| 689 const GURL url1("http://www.google.com/url1/"); | 692 const GURL url1("http://www.google.com/url1/"); |
| 690 const GURL url2("http://www.google.com/url2/"); | 693 const GURL url2("http://www.google.com/url2/"); |
| 691 const GURL url3("http://www.google.com/url3/"); | 694 const GURL url3("http://www.google.com/url3/"); |
| 692 const GURL url4("http://www.google.com/url4/"); | 695 const GURL url4("http://www.google.com/url4/"); |
| 693 | 696 |
| 694 static const void* scope = static_cast<void*>(this); | 697 static const void* scope = static_cast<void*>(this); |
| 695 | 698 |
| 696 // Add two pages. | 699 // Add two pages. |
| 697 history->AddPage(url0, scope, 0, GURL(), | 700 history->AddPage(url0, scope, 0, GURL(), |
| 698 PageTransition::TYPED, history::RedirectList(), | 701 content::PAGE_TRANSITION_TYPED, history::RedirectList(), |
| 699 history::SOURCE_BROWSED, false); | 702 history::SOURCE_BROWSED, false); |
| 700 history->AddPage(url1, scope, 0, GURL(), | 703 history->AddPage(url1, scope, 0, GURL(), |
| 701 PageTransition::TYPED, history::RedirectList(), | 704 content::PAGE_TRANSITION_TYPED, history::RedirectList(), |
| 702 history::SOURCE_BROWSED, false); | 705 history::SOURCE_BROWSED, false); |
| 703 history->QueryMostVisitedURLs(20, 90, &consumer_, | 706 history->QueryMostVisitedURLs(20, 90, &consumer_, |
| 704 base::Bind( | 707 base::Bind( |
| 705 &HistoryTest::OnMostVisitedURLsAvailable, | 708 &HistoryTest::OnMostVisitedURLsAvailable, |
| 706 base::Unretained(this))); | 709 base::Unretained(this))); |
| 707 MessageLoop::current()->Run(); | 710 MessageLoop::current()->Run(); |
| 708 | 711 |
| 709 EXPECT_EQ(2U, most_visited_urls_.size()); | 712 EXPECT_EQ(2U, most_visited_urls_.size()); |
| 710 EXPECT_EQ(url0, most_visited_urls_[0].url); | 713 EXPECT_EQ(url0, most_visited_urls_[0].url); |
| 711 EXPECT_EQ(url1, most_visited_urls_[1].url); | 714 EXPECT_EQ(url1, most_visited_urls_[1].url); |
| 712 | 715 |
| 713 // Add another page. | 716 // Add another page. |
| 714 history->AddPage(url2, scope, 0, GURL(), | 717 history->AddPage(url2, scope, 0, GURL(), |
| 715 PageTransition::TYPED, history::RedirectList(), | 718 content::PAGE_TRANSITION_TYPED, history::RedirectList(), |
| 716 history::SOURCE_BROWSED, false); | 719 history::SOURCE_BROWSED, false); |
| 717 history->QueryMostVisitedURLs(20, 90, &consumer_, | 720 history->QueryMostVisitedURLs(20, 90, &consumer_, |
| 718 base::Bind( | 721 base::Bind( |
| 719 &HistoryTest::OnMostVisitedURLsAvailable, | 722 &HistoryTest::OnMostVisitedURLsAvailable, |
| 720 base::Unretained(this))); | 723 base::Unretained(this))); |
| 721 MessageLoop::current()->Run(); | 724 MessageLoop::current()->Run(); |
| 722 | 725 |
| 723 EXPECT_EQ(3U, most_visited_urls_.size()); | 726 EXPECT_EQ(3U, most_visited_urls_.size()); |
| 724 EXPECT_EQ(url0, most_visited_urls_[0].url); | 727 EXPECT_EQ(url0, most_visited_urls_[0].url); |
| 725 EXPECT_EQ(url1, most_visited_urls_[1].url); | 728 EXPECT_EQ(url1, most_visited_urls_[1].url); |
| 726 EXPECT_EQ(url2, most_visited_urls_[2].url); | 729 EXPECT_EQ(url2, most_visited_urls_[2].url); |
| 727 | 730 |
| 728 // Revisit url2, making it the top URL. | 731 // Revisit url2, making it the top URL. |
| 729 history->AddPage(url2, scope, 0, GURL(), | 732 history->AddPage(url2, scope, 0, GURL(), |
| 730 PageTransition::TYPED, history::RedirectList(), | 733 content::PAGE_TRANSITION_TYPED, history::RedirectList(), |
| 731 history::SOURCE_BROWSED, false); | 734 history::SOURCE_BROWSED, false); |
| 732 history->QueryMostVisitedURLs(20, 90, &consumer_, | 735 history->QueryMostVisitedURLs(20, 90, &consumer_, |
| 733 base::Bind( | 736 base::Bind( |
| 734 &HistoryTest::OnMostVisitedURLsAvailable, | 737 &HistoryTest::OnMostVisitedURLsAvailable, |
| 735 base::Unretained(this))); | 738 base::Unretained(this))); |
| 736 MessageLoop::current()->Run(); | 739 MessageLoop::current()->Run(); |
| 737 | 740 |
| 738 EXPECT_EQ(3U, most_visited_urls_.size()); | 741 EXPECT_EQ(3U, most_visited_urls_.size()); |
| 739 EXPECT_EQ(url2, most_visited_urls_[0].url); | 742 EXPECT_EQ(url2, most_visited_urls_[0].url); |
| 740 EXPECT_EQ(url0, most_visited_urls_[1].url); | 743 EXPECT_EQ(url0, most_visited_urls_[1].url); |
| 741 EXPECT_EQ(url1, most_visited_urls_[2].url); | 744 EXPECT_EQ(url1, most_visited_urls_[2].url); |
| 742 | 745 |
| 743 // Revisit url1, making it the top URL. | 746 // Revisit url1, making it the top URL. |
| 744 history->AddPage(url1, scope, 0, GURL(), | 747 history->AddPage(url1, scope, 0, GURL(), |
| 745 PageTransition::TYPED, history::RedirectList(), | 748 content::PAGE_TRANSITION_TYPED, history::RedirectList(), |
| 746 history::SOURCE_BROWSED, false); | 749 history::SOURCE_BROWSED, false); |
| 747 history->QueryMostVisitedURLs(20, 90, &consumer_, | 750 history->QueryMostVisitedURLs(20, 90, &consumer_, |
| 748 base::Bind( | 751 base::Bind( |
| 749 &HistoryTest::OnMostVisitedURLsAvailable, | 752 &HistoryTest::OnMostVisitedURLsAvailable, |
| 750 base::Unretained(this))); | 753 base::Unretained(this))); |
| 751 MessageLoop::current()->Run(); | 754 MessageLoop::current()->Run(); |
| 752 | 755 |
| 753 EXPECT_EQ(3U, most_visited_urls_.size()); | 756 EXPECT_EQ(3U, most_visited_urls_.size()); |
| 754 EXPECT_EQ(url1, most_visited_urls_[0].url); | 757 EXPECT_EQ(url1, most_visited_urls_[0].url); |
| 755 EXPECT_EQ(url2, most_visited_urls_[1].url); | 758 EXPECT_EQ(url2, most_visited_urls_[1].url); |
| 756 EXPECT_EQ(url0, most_visited_urls_[2].url); | 759 EXPECT_EQ(url0, most_visited_urls_[2].url); |
| 757 | 760 |
| 758 // Redirects | 761 // Redirects |
| 759 history::RedirectList redirects; | 762 history::RedirectList redirects; |
| 760 redirects.push_back(url3); | 763 redirects.push_back(url3); |
| 761 redirects.push_back(url4); | 764 redirects.push_back(url4); |
| 762 | 765 |
| 763 // Visit url4 using redirects. | 766 // Visit url4 using redirects. |
| 764 history->AddPage(url4, scope, 0, GURL(), | 767 history->AddPage(url4, scope, 0, GURL(), |
| 765 PageTransition::TYPED, redirects, | 768 content::PAGE_TRANSITION_TYPED, redirects, |
| 766 history::SOURCE_BROWSED, false); | 769 history::SOURCE_BROWSED, false); |
| 767 history->QueryMostVisitedURLs(20, 90, &consumer_, | 770 history->QueryMostVisitedURLs(20, 90, &consumer_, |
| 768 base::Bind( | 771 base::Bind( |
| 769 &HistoryTest::OnMostVisitedURLsAvailable, | 772 &HistoryTest::OnMostVisitedURLsAvailable, |
| 770 base::Unretained(this))); | 773 base::Unretained(this))); |
| 771 MessageLoop::current()->Run(); | 774 MessageLoop::current()->Run(); |
| 772 | 775 |
| 773 EXPECT_EQ(4U, most_visited_urls_.size()); | 776 EXPECT_EQ(4U, most_visited_urls_.size()); |
| 774 EXPECT_EQ(url1, most_visited_urls_[0].url); | 777 EXPECT_EQ(url1, most_visited_urls_[0].url); |
| 775 EXPECT_EQ(url2, most_visited_urls_[1].url); | 778 EXPECT_EQ(url2, most_visited_urls_[1].url); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 history_service_ = history; | 871 history_service_ = history; |
| 869 history->ScheduleDBTask(task.get(), &request_consumer); | 872 history->ScheduleDBTask(task.get(), &request_consumer); |
| 870 request_consumer.CancelAllRequests(); | 873 request_consumer.CancelAllRequests(); |
| 871 CleanupHistoryService(); | 874 CleanupHistoryService(); |
| 872 // WARNING: history has now been deleted. | 875 // WARNING: history has now been deleted. |
| 873 history = NULL; | 876 history = NULL; |
| 874 ASSERT_FALSE(task->done_invoked); | 877 ASSERT_FALSE(task->done_invoked); |
| 875 } | 878 } |
| 876 | 879 |
| 877 } // namespace history | 880 } // namespace history |
| OLD | NEW |