Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: chrome/browser/history/history_backend_unittest.cc

Issue 147145: Fix: Certain redirections remove sites from the history... (Closed) Base URL: svn://chrome-svn.corp.google.com/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_marshaling.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/gfx/jpeg_codec.h" 7 #include "base/gfx/jpeg_codec.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 HistoryService::RedirectList redirects; 63 HistoryService::RedirectList redirects;
64 for (int i = 0; sequence[i] != NULL; ++i) 64 for (int i = 0; sequence[i] != NULL; ++i)
65 redirects.push_back(GURL(sequence[i])); 65 redirects.push_back(GURL(sequence[i]));
66 66
67 int int_scope = 1; 67 int int_scope = 1;
68 void* scope = 0; 68 void* scope = 0;
69 memcpy(&scope, &int_scope, sizeof(int_scope)); 69 memcpy(&scope, &int_scope, sizeof(int_scope));
70 scoped_refptr<history::HistoryAddPageArgs> request( 70 scoped_refptr<history::HistoryAddPageArgs> request(
71 new history::HistoryAddPageArgs( 71 new history::HistoryAddPageArgs(
72 redirects.back(), Time::Now(), scope, page_id, GURL(), 72 redirects.back(), Time::Now(), scope, page_id, GURL(),
73 redirects, PageTransition::LINK)); 73 redirects, PageTransition::LINK, true));
74 backend_->AddPage(request); 74 backend_->AddPage(request);
75 } 75 }
76 76
77 // Adds CLIENT_REDIRECT page transition.
78 // |url1| is the source URL and |url2| is the destination.
79 // |did_replace| is true if the transition is non-user initiated and the
80 // navigation entry for |url2| has replaced that for |url1|. The possibly
81 // updated transition code of the visit records for |url1| and |url2| is
82 // returned by filling in |*transition1| and |*transition2|, respectively.
83 void AddClientRedirect(const GURL& url1, const GURL& url2, bool did_replace,
84 int* transition1, int* transition2) {
85 void* const dummy_scope = reinterpret_cast<void*>(0x87654321);
86 HistoryService::RedirectList redirects;
87 if (url1.is_valid())
88 redirects.push_back(url1);
89 if (url2.is_valid())
90 redirects.push_back(url2);
91 scoped_refptr<HistoryAddPageArgs> request(
92 new HistoryAddPageArgs(url2, base::Time(), dummy_scope, 0, url1,
93 redirects, PageTransition::CLIENT_REDIRECT, did_replace));
94 backend_->AddPage(request);
95
96 *transition1 = getTransition(url1);
97 *transition2 = getTransition(url2);
98 }
99
100 int getTransition(const GURL& url) {
101 if (!url.is_valid())
102 return 0;
103 URLRow row;
104 URLID id = backend_->db()->GetRowForURL(url, &row);
105 VisitVector visits;
106 EXPECT_TRUE(backend_->db()->GetVisitsForURL(id, &visits));
107 return visits[0].transition;
108 }
109
77 BookmarkModel bookmark_model_; 110 BookmarkModel bookmark_model_;
78 111
79 protected: 112 protected:
80 bool loaded_; 113 bool loaded_;
81 114
82 private: 115 private:
83 friend class HistoryBackendTestDelegate; 116 friend class HistoryBackendTestDelegate;
84 117
85 // testing::Test 118 // testing::Test
86 virtual void SetUp() { 119 virtual void SetUp() {
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 // KEYWORD_GENERATED. 432 // KEYWORD_GENERATED.
400 TEST_F(HistoryBackendTest, KeywordGenerated) { 433 TEST_F(HistoryBackendTest, KeywordGenerated) {
401 ASSERT_TRUE(backend_.get()); 434 ASSERT_TRUE(backend_.get());
402 435
403 GURL url("http://google.com"); 436 GURL url("http://google.com");
404 437
405 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1); 438 Time visit_time = Time::Now() - base::TimeDelta::FromDays(1);
406 scoped_refptr<HistoryAddPageArgs> request( 439 scoped_refptr<HistoryAddPageArgs> request(
407 new HistoryAddPageArgs(url, visit_time, NULL, 0, GURL(), 440 new HistoryAddPageArgs(url, visit_time, NULL, 0, GURL(),
408 HistoryService::RedirectList(), 441 HistoryService::RedirectList(),
409 PageTransition::KEYWORD_GENERATED)); 442 PageTransition::KEYWORD_GENERATED, false));
410 backend_->AddPage(request); 443 backend_->AddPage(request);
411 444
412 // A row should have been added for the url. 445 // A row should have been added for the url.
413 URLRow row; 446 URLRow row;
414 URLID url_id = backend_->db()->GetRowForURL(url, &row); 447 URLID url_id = backend_->db()->GetRowForURL(url, &row);
415 ASSERT_NE(0, url_id); 448 ASSERT_NE(0, url_id);
416 449
417 // The typed count should be 1. 450 // The typed count should be 1.
418 ASSERT_EQ(1, row.typed_count()); 451 ASSERT_EQ(1, row.typed_count());
419 452
(...skipping 17 matching lines...) Expand all
437 470
438 // The visit should have been nuked. 471 // The visit should have been nuked.
439 visits.clear(); 472 visits.clear();
440 EXPECT_TRUE(backend_->db()->GetVisitsForURL(url_id, &visits)); 473 EXPECT_TRUE(backend_->db()->GetVisitsForURL(url_id, &visits));
441 EXPECT_TRUE(visits.empty()); 474 EXPECT_TRUE(visits.empty());
442 475
443 // As well as the url. 476 // As well as the url.
444 ASSERT_EQ(0, backend_->db()->GetRowForURL(url, &row)); 477 ASSERT_EQ(0, backend_->db()->GetRowForURL(url, &row));
445 } 478 }
446 479
480 TEST_F(HistoryBackendTest, ClientRedirect) {
481 ASSERT_TRUE(backend_.get());
482
483 int transition1;
484 int transition2;
485
486 // Initial transition to page A.
487 GURL url_a("http://google.com/a");
488 AddClientRedirect(GURL(), url_a, false, &transition1, &transition2);
489 EXPECT_TRUE(transition2 & PageTransition::CHAIN_END);
490
491 // User initiated redirect to page B.
492 GURL url_b("http://google.com/b");
493 AddClientRedirect(url_a, url_b, false, &transition1, &transition2);
494 EXPECT_TRUE(transition1 & PageTransition::CHAIN_END);
495 EXPECT_TRUE(transition2 & PageTransition::CHAIN_END);
496
497 // Non-user initiated redirect to page C.
498 GURL url_c("http://google.com/c");
499 AddClientRedirect(url_b, url_c, true, &transition1, &transition2);
500 EXPECT_FALSE(transition1 & PageTransition::CHAIN_END);
501 EXPECT_TRUE(transition2 & PageTransition::CHAIN_END);
502 }
503
447 } // namespace history 504 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_marshaling.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698