| 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 // 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 history::RedirectList(), ui::PAGE_TRANSITION_LINK, | 197 history::RedirectList(), ui::PAGE_TRANSITION_LINK, |
| 198 history::SOURCE_BROWSED, false); | 198 history::SOURCE_BROWSED, false); |
| 199 EXPECT_TRUE(QueryURL(history_service_.get(), test_url)); | 199 EXPECT_TRUE(QueryURL(history_service_.get(), test_url)); |
| 200 EXPECT_EQ(2, query_url_row_.visit_count()); // Added twice. | 200 EXPECT_EQ(2, query_url_row_.visit_count()); // Added twice. |
| 201 EXPECT_EQ(0, query_url_row_.typed_count()); // Never typed. | 201 EXPECT_EQ(0, query_url_row_.typed_count()); // Never typed. |
| 202 EXPECT_FALSE(query_url_row_.hidden()); // Because loaded in main frame. | 202 EXPECT_FALSE(query_url_row_.hidden()); // Because loaded in main frame. |
| 203 } | 203 } |
| 204 | 204 |
| 205 TEST_F(HistoryServiceTest, AddRedirect) { | 205 TEST_F(HistoryServiceTest, AddRedirect) { |
| 206 ASSERT_TRUE(history_service_.get()); | 206 ASSERT_TRUE(history_service_.get()); |
| 207 const char* first_sequence[] = { | 207 history::RedirectList first_redirects = {GURL("http://first.page.com/"), |
| 208 "http://first.page.com/", | 208 GURL("http://second.page.com/")}; |
| 209 "http://second.page.com/"}; | |
| 210 int first_count = arraysize(first_sequence); | |
| 211 history::RedirectList first_redirects; | |
| 212 for (int i = 0; i < first_count; i++) | |
| 213 first_redirects.push_back(GURL(first_sequence[i])); | |
| 214 | 209 |
| 215 // Add the sequence of pages as a server with no referrer. Note that we need | 210 // Add the sequence of pages as a server with no referrer. Note that we need |
| 216 // to have a non-NULL page ID scope. | 211 // to have a non-NULL page ID scope. |
| 217 history_service_->AddPage( | 212 history_service_->AddPage( |
| 218 first_redirects.back(), base::Time::Now(), | 213 first_redirects.back(), base::Time::Now(), |
| 219 reinterpret_cast<ContextID>(1), 0, GURL(), first_redirects, | 214 reinterpret_cast<ContextID>(1), 0, GURL(), first_redirects, |
| 220 ui::PAGE_TRANSITION_LINK, history::SOURCE_BROWSED, true); | 215 ui::PAGE_TRANSITION_LINK, history::SOURCE_BROWSED, true); |
| 221 | 216 |
| 222 // The first page should be added once with a link visit type (because we set | 217 // The first page should be added once with a link visit type (because we set |
| 223 // LINK when we added the original URL, and a referrer of nowhere (0). | 218 // LINK when we added the original URL, and a referrer of nowhere (0). |
| (...skipping 21 matching lines...) Expand all Loading... |
| 245 | 240 |
| 246 // Check that the redirect finding function successfully reports it. | 241 // Check that the redirect finding function successfully reports it. |
| 247 saved_redirects_.clear(); | 242 saved_redirects_.clear(); |
| 248 QueryRedirectsFrom(history_service_.get(), first_redirects[0]); | 243 QueryRedirectsFrom(history_service_.get(), first_redirects[0]); |
| 249 ASSERT_EQ(1U, saved_redirects_.size()); | 244 ASSERT_EQ(1U, saved_redirects_.size()); |
| 250 EXPECT_EQ(first_redirects[1], saved_redirects_[0]); | 245 EXPECT_EQ(first_redirects[1], saved_redirects_[0]); |
| 251 | 246 |
| 252 // Now add a client redirect from that second visit to a third, client | 247 // Now add a client redirect from that second visit to a third, client |
| 253 // redirects are tracked by the RenderView prior to updating history, | 248 // redirects are tracked by the RenderView prior to updating history, |
| 254 // so we pass in a CLIENT_REDIRECT qualifier to mock that behavior. | 249 // so we pass in a CLIENT_REDIRECT qualifier to mock that behavior. |
| 255 history::RedirectList second_redirects; | 250 history::RedirectList second_redirects = {first_redirects[1], |
| 256 second_redirects.push_back(first_redirects[1]); | 251 GURL("http://last.page.com/")}; |
| 257 second_redirects.push_back(GURL("http://last.page.com/")); | |
| 258 history_service_->AddPage(second_redirects[1], base::Time::Now(), | 252 history_service_->AddPage(second_redirects[1], base::Time::Now(), |
| 259 reinterpret_cast<ContextID>(1), 1, | 253 reinterpret_cast<ContextID>(1), 1, |
| 260 second_redirects[0], second_redirects, | 254 second_redirects[0], second_redirects, |
| 261 ui::PageTransitionFromInt( | 255 ui::PageTransitionFromInt( |
| 262 ui::PAGE_TRANSITION_LINK | | 256 ui::PAGE_TRANSITION_LINK | |
| 263 ui::PAGE_TRANSITION_CLIENT_REDIRECT), | 257 ui::PAGE_TRANSITION_CLIENT_REDIRECT), |
| 264 history::SOURCE_BROWSED, true); | 258 history::SOURCE_BROWSED, true); |
| 265 | 259 |
| 266 // The last page (source of the client redirect) should NOT have an | 260 // The last page (source of the client redirect) should NOT have an |
| 267 // additional visit added, because it was a client redirect (normally it | 261 // additional visit added, because it was a client redirect (normally it |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 history_service_->AddPage( | 351 history_service_->AddPage( |
| 358 test_url, base::Time::Now(), NULL, 0, GURL(), | 352 test_url, base::Time::Now(), NULL, 0, GURL(), |
| 359 history::RedirectList(), ui::PAGE_TRANSITION_LINK, | 353 history::RedirectList(), ui::PAGE_TRANSITION_LINK, |
| 360 history::SOURCE_BROWSED, false); | 354 history::SOURCE_BROWSED, false); |
| 361 EXPECT_TRUE(QueryURL(history_service_.get(), test_url)); | 355 EXPECT_TRUE(QueryURL(history_service_.get(), test_url)); |
| 362 EXPECT_EQ(2, query_url_row_.visit_count()); | 356 EXPECT_EQ(2, query_url_row_.visit_count()); |
| 363 EXPECT_EQ(1, query_url_row_.typed_count()); | 357 EXPECT_EQ(1, query_url_row_.typed_count()); |
| 364 ASSERT_EQ(2U, query_url_visits_.size()); | 358 ASSERT_EQ(2U, query_url_visits_.size()); |
| 365 EXPECT_TRUE(ui::PageTransitionCoreTypeIs(query_url_visits_[1].transition, | 359 EXPECT_TRUE(ui::PageTransitionCoreTypeIs(query_url_visits_[1].transition, |
| 366 ui::PAGE_TRANSITION_LINK)); | 360 ui::PAGE_TRANSITION_LINK)); |
| 361 |
| 362 // A redirect chain with an intranet URL at the head should be promoted. |
| 363 history::RedirectList redirects1 = {GURL("http://intranet1/path"), |
| 364 GURL("http://second1.com/"), |
| 365 GURL("http://third1.com/")}; |
| 366 history_service_->AddPage(redirects1.back(), base::Time::Now(), NULL, 0, |
| 367 GURL(), redirects1, ui::PAGE_TRANSITION_LINK, |
| 368 history::SOURCE_BROWSED, false); |
| 369 EXPECT_TRUE(QueryURL(history_service_.get(), redirects1.front())); |
| 370 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 371 EXPECT_EQ(1, query_url_row_.typed_count()); |
| 372 ASSERT_EQ(1U, query_url_visits_.size()); |
| 373 EXPECT_TRUE(ui::PageTransitionCoreTypeIs(query_url_visits_[0].transition, |
| 374 ui::PAGE_TRANSITION_TYPED)); |
| 375 |
| 376 // As should one with an intranet URL at the tail. |
| 377 history::RedirectList redirects2 = {GURL("http://first2.com/"), |
| 378 GURL("http://second2.com/"), |
| 379 GURL("http://intranet2/path")}; |
| 380 history_service_->AddPage(redirects2.back(), base::Time::Now(), NULL, 0, |
| 381 GURL(), redirects2, ui::PAGE_TRANSITION_LINK, |
| 382 history::SOURCE_BROWSED, false); |
| 383 EXPECT_TRUE(QueryURL(history_service_.get(), redirects2.back())); |
| 384 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 385 EXPECT_EQ(0, query_url_row_.typed_count()); |
| 386 ASSERT_EQ(1U, query_url_visits_.size()); |
| 387 EXPECT_TRUE(ui::PageTransitionCoreTypeIs(query_url_visits_[0].transition, |
| 388 ui::PAGE_TRANSITION_TYPED)); |
| 389 |
| 390 // But not one with an intranet URL in the middle. |
| 391 history::RedirectList redirects3 = {GURL("http://first3.com/"), |
| 392 GURL("http://intranet3/path"), |
| 393 GURL("http://third3.com/")}; |
| 394 history_service_->AddPage(redirects3.back(), base::Time::Now(), NULL, 0, |
| 395 GURL(), redirects3, ui::PAGE_TRANSITION_LINK, |
| 396 history::SOURCE_BROWSED, false); |
| 397 EXPECT_TRUE(QueryURL(history_service_.get(), redirects3[1])); |
| 398 EXPECT_EQ(1, query_url_row_.visit_count()); |
| 399 EXPECT_EQ(0, query_url_row_.typed_count()); |
| 400 ASSERT_EQ(1U, query_url_visits_.size()); |
| 401 EXPECT_TRUE(ui::PageTransitionCoreTypeIs(query_url_visits_[0].transition, |
| 402 ui::PAGE_TRANSITION_LINK)); |
| 367 } | 403 } |
| 368 | 404 |
| 369 TEST_F(HistoryServiceTest, Typed) { | 405 TEST_F(HistoryServiceTest, Typed) { |
| 370 const ContextID context_id = reinterpret_cast<ContextID>(1); | 406 const ContextID context_id = reinterpret_cast<ContextID>(1); |
| 371 | 407 |
| 372 ASSERT_TRUE(history_service_.get()); | 408 ASSERT_TRUE(history_service_.get()); |
| 373 | 409 |
| 374 // Add the page once as typed. | 410 // Add the page once as typed. |
| 375 const GURL test_url("http://www.google.com/"); | 411 const GURL test_url("http://www.google.com/"); |
| 376 history_service_->AddPage( | 412 history_service_->AddPage( |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 base::Bind(&HistoryServiceTest::OnMostVisitedURLsAvailable, | 561 base::Bind(&HistoryServiceTest::OnMostVisitedURLsAvailable, |
| 526 base::Unretained(this)), | 562 base::Unretained(this)), |
| 527 &tracker_); | 563 &tracker_); |
| 528 base::RunLoop().Run(); | 564 base::RunLoop().Run(); |
| 529 | 565 |
| 530 EXPECT_EQ(3U, most_visited_urls_.size()); | 566 EXPECT_EQ(3U, most_visited_urls_.size()); |
| 531 EXPECT_EQ(url1, most_visited_urls_[0].url); | 567 EXPECT_EQ(url1, most_visited_urls_[0].url); |
| 532 EXPECT_EQ(url2, most_visited_urls_[1].url); | 568 EXPECT_EQ(url2, most_visited_urls_[1].url); |
| 533 EXPECT_EQ(url0, most_visited_urls_[2].url); | 569 EXPECT_EQ(url0, most_visited_urls_[2].url); |
| 534 | 570 |
| 535 // Redirects | |
| 536 history::RedirectList redirects; | |
| 537 redirects.push_back(url3); | |
| 538 redirects.push_back(url4); | |
| 539 | |
| 540 // Visit url4 using redirects. | 571 // Visit url4 using redirects. |
| 572 history::RedirectList redirects = {url3, url4}; |
| 541 history_service_->AddPage( | 573 history_service_->AddPage( |
| 542 url4, base::Time::Now(), context_id, 0, GURL(), | 574 url4, base::Time::Now(), context_id, 0, GURL(), |
| 543 redirects, ui::PAGE_TRANSITION_TYPED, | 575 redirects, ui::PAGE_TRANSITION_TYPED, |
| 544 history::SOURCE_BROWSED, false); | 576 history::SOURCE_BROWSED, false); |
| 545 history_service_->QueryMostVisitedURLs( | 577 history_service_->QueryMostVisitedURLs( |
| 546 20, | 578 20, |
| 547 90, | 579 90, |
| 548 base::Bind(&HistoryServiceTest::OnMostVisitedURLsAvailable, | 580 base::Bind(&HistoryServiceTest::OnMostVisitedURLsAvailable, |
| 549 base::Unretained(this)), | 581 base::Unretained(this)), |
| 550 &tracker_); | 582 &tracker_); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 // Expect two sync changes for deleting processed directives. | 894 // Expect two sync changes for deleting processed directives. |
| 863 const syncer::SyncChangeList& sync_changes = change_processor.changes(); | 895 const syncer::SyncChangeList& sync_changes = change_processor.changes(); |
| 864 ASSERT_EQ(2u, sync_changes.size()); | 896 ASSERT_EQ(2u, sync_changes.size()); |
| 865 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[0].change_type()); | 897 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[0].change_type()); |
| 866 EXPECT_EQ(1, syncer::SyncDataRemote(sync_changes[0].sync_data()).GetId()); | 898 EXPECT_EQ(1, syncer::SyncDataRemote(sync_changes[0].sync_data()).GetId()); |
| 867 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[1].change_type()); | 899 EXPECT_EQ(syncer::SyncChange::ACTION_DELETE, sync_changes[1].change_type()); |
| 868 EXPECT_EQ(2, syncer::SyncDataRemote(sync_changes[1].sync_data()).GetId()); | 900 EXPECT_EQ(2, syncer::SyncDataRemote(sync_changes[1].sync_data()).GetId()); |
| 869 } | 901 } |
| 870 | 902 |
| 871 } // namespace history | 903 } // namespace history |
| OLD | NEW |