| 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.com/", |
| 473 "http://second.page/"}; | 473 "http://second.page.com/"}; |
| 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 content::PAGE_TRANSITION_LINK, first_redirects, | 482 content::PAGE_TRANSITION_LINK, first_redirects, |
| 483 history::SOURCE_BROWSED, true); | 483 history::SOURCE_BROWSED, true); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 508 saved_redirects_.clear(); | 508 saved_redirects_.clear(); |
| 509 QueryRedirectsFrom(history, first_redirects[0]); | 509 QueryRedirectsFrom(history, first_redirects[0]); |
| 510 ASSERT_EQ(1U, saved_redirects_.size()); | 510 ASSERT_EQ(1U, saved_redirects_.size()); |
| 511 EXPECT_EQ(first_redirects[1], saved_redirects_[0]); | 511 EXPECT_EQ(first_redirects[1], saved_redirects_[0]); |
| 512 | 512 |
| 513 // 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 |
| 514 // redirects are tracked by the RenderView prior to updating history, | 514 // redirects are tracked by the RenderView prior to updating history, |
| 515 // 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. |
| 516 history::RedirectList second_redirects; | 516 history::RedirectList second_redirects; |
| 517 second_redirects.push_back(first_redirects[1]); | 517 second_redirects.push_back(first_redirects[1]); |
| 518 second_redirects.push_back(GURL("http://last.page/")); | 518 second_redirects.push_back(GURL("http://last.page.com/")); |
| 519 history->AddPage(second_redirects[1], MakeFakeHost(1), 1, | 519 history->AddPage(second_redirects[1], MakeFakeHost(1), 1, |
| 520 second_redirects[0], | 520 second_redirects[0], |
| 521 static_cast<content::PageTransition>( | 521 static_cast<content::PageTransition>( |
| 522 content::PAGE_TRANSITION_LINK | | 522 content::PAGE_TRANSITION_LINK | |
| 523 content::PAGE_TRANSITION_CLIENT_REDIRECT), | 523 content::PAGE_TRANSITION_CLIENT_REDIRECT), |
| 524 second_redirects, history::SOURCE_BROWSED, true); | 524 second_redirects, history::SOURCE_BROWSED, true); |
| 525 | 525 |
| 526 // 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 |
| 527 // additional visit added, because it was a client redirect (normally it | 527 // additional visit added, because it was a client redirect (normally it |
| 528 // 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. |
| 529 EXPECT_TRUE(QueryURL(history, second_redirects[0])); | 529 EXPECT_TRUE(QueryURL(history, second_redirects[0])); |
| 530 EXPECT_EQ(1, query_url_row_.visit_count()); | 530 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 531 | 531 |
| 532 // 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. |
| 533 EXPECT_TRUE(QueryURL(history, second_redirects[1])); | 533 EXPECT_TRUE(QueryURL(history, second_redirects[1])); |
| 534 EXPECT_EQ(1, query_url_row_.visit_count()); | 534 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 535 ASSERT_EQ(1U, query_url_visits_.size()); | 535 ASSERT_EQ(1U, query_url_visits_.size()); |
| 536 EXPECT_EQ(content::PAGE_TRANSITION_CLIENT_REDIRECT | | 536 EXPECT_EQ(content::PAGE_TRANSITION_CLIENT_REDIRECT | |
| 537 content::PAGE_TRANSITION_CHAIN_END, query_url_visits_[0].transition)
; | 537 content::PAGE_TRANSITION_CHAIN_END, |
| 538 query_url_visits_[0].transition); |
| 538 EXPECT_EQ(second_visit, query_url_visits_[0].referring_visit); | 539 EXPECT_EQ(second_visit, query_url_visits_[0].referring_visit); |
| 539 } | 540 } |
| 540 | 541 |
| 542 TEST_F(HistoryTest, MakeIntranetURLsTyped) { |
| 543 scoped_refptr<HistoryService> history(new HistoryService); |
| 544 history_service_ = history; |
| 545 ASSERT_TRUE(history->Init(history_dir_, NULL)); |
| 546 |
| 547 // Add a non-typed visit to an intranet URL on an unvisited host. This should |
| 548 // get promoted to a typed visit. |
| 549 const GURL test_url("http://intranet_host/path"); |
| 550 history->AddPage(test_url, NULL, 0, GURL(), content::PAGE_TRANSITION_LINK, |
| 551 history::RedirectList(), history::SOURCE_BROWSED, false); |
| 552 EXPECT_TRUE(QueryURL(history, test_url)); |
| 553 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 554 EXPECT_EQ(1, query_url_row_.typed_count()); |
| 555 ASSERT_EQ(1U, query_url_visits_.size()); |
| 556 EXPECT_EQ(content::PAGE_TRANSITION_TYPED, |
| 557 content::PageTransitionStripQualifier(query_url_visits_[0].transition)); |
| 558 |
| 559 // Add more visits on the same host. None of these should be promoted since |
| 560 // there is already a typed visit. |
| 561 |
| 562 // Different path. |
| 563 const GURL test_url2("http://intranet_host/different_path"); |
| 564 history->AddPage(test_url2, NULL, 0, GURL(), content::PAGE_TRANSITION_LINK, |
| 565 history::RedirectList(), history::SOURCE_BROWSED, false); |
| 566 EXPECT_TRUE(QueryURL(history, test_url2)); |
| 567 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 568 EXPECT_EQ(0, query_url_row_.typed_count()); |
| 569 ASSERT_EQ(1U, query_url_visits_.size()); |
| 570 EXPECT_EQ(content::PAGE_TRANSITION_LINK, |
| 571 content::PageTransitionStripQualifier(query_url_visits_[0].transition)); |
| 572 |
| 573 // No path. |
| 574 const GURL test_url3("http://intranet_host/"); |
| 575 history->AddPage(test_url3, NULL, 0, GURL(), content::PAGE_TRANSITION_LINK, |
| 576 history::RedirectList(), history::SOURCE_BROWSED, false); |
| 577 EXPECT_TRUE(QueryURL(history, test_url3)); |
| 578 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 579 EXPECT_EQ(0, query_url_row_.typed_count()); |
| 580 ASSERT_EQ(1U, query_url_visits_.size()); |
| 581 EXPECT_EQ(content::PAGE_TRANSITION_LINK, |
| 582 content::PageTransitionStripQualifier(query_url_visits_[0].transition)); |
| 583 |
| 584 // Different scheme. |
| 585 const GURL test_url4("https://intranet_host/"); |
| 586 history->AddPage(test_url4, NULL, 0, GURL(), content::PAGE_TRANSITION_LINK, |
| 587 history::RedirectList(), history::SOURCE_BROWSED, false); |
| 588 EXPECT_TRUE(QueryURL(history, test_url4)); |
| 589 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 590 EXPECT_EQ(0, query_url_row_.typed_count()); |
| 591 ASSERT_EQ(1U, query_url_visits_.size()); |
| 592 EXPECT_EQ(content::PAGE_TRANSITION_LINK, |
| 593 content::PageTransitionStripQualifier(query_url_visits_[0].transition)); |
| 594 |
| 595 // Different transition. |
| 596 const GURL test_url5("http://intranet_host/another_path"); |
| 597 history->AddPage(test_url5, NULL, 0, GURL(), |
| 598 content::PAGE_TRANSITION_AUTO_BOOKMARK, |
| 599 history::RedirectList(), history::SOURCE_BROWSED, false); |
| 600 EXPECT_TRUE(QueryURL(history, test_url5)); |
| 601 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 602 EXPECT_EQ(0, query_url_row_.typed_count()); |
| 603 ASSERT_EQ(1U, query_url_visits_.size()); |
| 604 EXPECT_EQ(content::PAGE_TRANSITION_AUTO_BOOKMARK, |
| 605 content::PageTransitionStripQualifier(query_url_visits_[0].transition)); |
| 606 |
| 607 // Original URL. |
| 608 history->AddPage(test_url, NULL, 0, GURL(), content::PAGE_TRANSITION_LINK, |
| 609 history::RedirectList(), history::SOURCE_BROWSED, false); |
| 610 EXPECT_TRUE(QueryURL(history, test_url)); |
| 611 EXPECT_EQ(2, query_url_row_.visit_count()); |
| 612 EXPECT_EQ(1, query_url_row_.typed_count()); |
| 613 ASSERT_EQ(2U, query_url_visits_.size()); |
| 614 EXPECT_EQ(content::PAGE_TRANSITION_LINK, |
| 615 content::PageTransitionStripQualifier(query_url_visits_[1].transition)); |
| 616 } |
| 617 |
| 541 TEST_F(HistoryTest, Typed) { | 618 TEST_F(HistoryTest, Typed) { |
| 542 scoped_refptr<HistoryService> history(new HistoryService); | 619 scoped_refptr<HistoryService> history(new HistoryService); |
| 543 history_service_ = history; | 620 history_service_ = history; |
| 544 ASSERT_TRUE(history->Init(history_dir_, NULL)); | 621 ASSERT_TRUE(history->Init(history_dir_, NULL)); |
| 545 | 622 |
| 546 // Add the page once as typed. | 623 // Add the page once as typed. |
| 547 const GURL test_url("http://www.google.com/"); | 624 const GURL test_url("http://www.google.com/"); |
| 548 history->AddPage(test_url, NULL, 0, GURL(), content::PAGE_TRANSITION_TYPED, | 625 history->AddPage(test_url, NULL, 0, GURL(), content::PAGE_TRANSITION_TYPED, |
| 549 history::RedirectList(), | 626 history::RedirectList(), |
| 550 history::SOURCE_BROWSED, false); | 627 history::SOURCE_BROWSED, false); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 history_service_ = history; | 948 history_service_ = history; |
| 872 history->ScheduleDBTask(task.get(), &request_consumer); | 949 history->ScheduleDBTask(task.get(), &request_consumer); |
| 873 request_consumer.CancelAllRequests(); | 950 request_consumer.CancelAllRequests(); |
| 874 CleanupHistoryService(); | 951 CleanupHistoryService(); |
| 875 // WARNING: history has now been deleted. | 952 // WARNING: history has now been deleted. |
| 876 history = NULL; | 953 history = NULL; |
| 877 ASSERT_FALSE(task->done_invoked); | 954 ASSERT_FALSE(task->done_invoked); |
| 878 } | 955 } |
| 879 | 956 |
| 880 } // namespace history | 957 } // namespace history |
| OLD | NEW |