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

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

Issue 823273003: Switch the history backend from using page ids to navigation entry unique ids. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 11 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
OLDNEW
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // Now check the URL & title. 65 // Now check the URL & title.
66 return result.url() == GURL(test_entries[test_entry_index].url) && 66 return result.url() == GURL(test_entries[test_entry_index].url) &&
67 result.title() == 67 result.title() ==
68 base::UTF8ToUTF16(test_entries[test_entry_index].title); 68 base::UTF8ToUTF16(test_entries[test_entry_index].title);
69 } 69 }
70 70
71 } // namespace 71 } // namespace
72 72
73 class HistoryQueryTest : public testing::Test { 73 class HistoryQueryTest : public testing::Test {
74 public: 74 public:
75 HistoryQueryTest() : page_id_(0) { 75 HistoryQueryTest() : nav_entry_id_(0) {
76 } 76 }
77 77
78 // Acts like a synchronous call to history's QueryHistory. 78 // Acts like a synchronous call to history's QueryHistory.
79 void QueryHistory(const std::string& text_query, 79 void QueryHistory(const std::string& text_query,
80 const QueryOptions& options, 80 const QueryOptions& options,
81 QueryResults* results) { 81 QueryResults* results) {
82 history_->QueryHistory(base::UTF8ToUTF16(text_query), 82 history_->QueryHistory(base::UTF8ToUTF16(text_query),
83 options, 83 options,
84 base::Bind(&HistoryQueryTest::QueryHistoryComplete, 84 base::Bind(&HistoryQueryTest::QueryHistoryComplete,
85 base::Unretained(this)), 85 base::Unretained(this)),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 QueryHistory(query_text, options, &results); 138 QueryHistory(query_text, options, &results);
139 ASSERT_NE(options.end_time, results.back().visit_time()); 139 ASSERT_NE(options.end_time, results.back().visit_time());
140 options.end_time = results.back().visit_time(); 140 options.end_time = results.back().visit_time();
141 } while (!results.reached_beginning()); 141 } while (!results.reached_beginning());
142 } 142 }
143 143
144 protected: 144 protected:
145 scoped_ptr<HistoryService> history_; 145 scoped_ptr<HistoryService> history_;
146 146
147 // Counter used to generate a unique ID for each page added to the history. 147 // Counter used to generate a unique ID for each page added to the history.
148 int32 page_id_; 148 int nav_entry_id_;
149 149
150 void AddEntryToHistory(const TestEntry& entry) { 150 void AddEntryToHistory(const TestEntry& entry) {
151 // We need the ID scope and page ID so that the visit tracker can find it. 151 // We need the ID scope and page ID so that the visit tracker can find it.
152 ContextID context_id = reinterpret_cast<ContextID>(1); 152 ContextID context_id = reinterpret_cast<ContextID>(1);
153 GURL url(entry.url); 153 GURL url(entry.url);
154 154
155 history_->AddPage(url, entry.time, context_id, page_id_++, GURL(), 155 history_->AddPage(url, entry.time, context_id, nav_entry_id_++, GURL(),
156 history::RedirectList(), ui::PAGE_TRANSITION_LINK, 156 history::RedirectList(), ui::PAGE_TRANSITION_LINK,
157 history::SOURCE_BROWSED, false); 157 history::SOURCE_BROWSED, false);
158 history_->SetPageTitle(url, base::UTF8ToUTF16(entry.title)); 158 history_->SetPageTitle(url, base::UTF8ToUTF16(entry.title));
159 } 159 }
160 160
161 private: 161 private:
162 void SetUp() override { 162 void SetUp() override {
163 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 163 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
164 history_dir_ = temp_dir_.path().AppendASCII("HistoryTest"); 164 history_dir_ = temp_dir_.path().AppendASCII("HistoryTest");
165 ASSERT_TRUE(base::CreateDirectory(history_dir_)); 165 ASSERT_TRUE(base::CreateDirectory(history_dir_));
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 421
422 TEST_F(HistoryQueryTest, TextSearchPaging) { 422 TEST_F(HistoryQueryTest, TextSearchPaging) {
423 // Since results are fetched 1 and 2 at a time, entry #0 and #6 will not 423 // Since results are fetched 1 and 2 at a time, entry #0 and #6 will not
424 // be de-duplicated. Entry #4 does not contain the text "title", so it 424 // be de-duplicated. Entry #4 does not contain the text "title", so it
425 // shouldn't appear. 425 // shouldn't appear.
426 int expected_results[] = { 2, 3, 1, 7, 6, 5 }; 426 int expected_results[] = { 2, 3, 1, 7, 6, 5 };
427 TestPaging("title", expected_results, arraysize(expected_results)); 427 TestPaging("title", expected_results, arraysize(expected_results));
428 } 428 }
429 429
430 } // namespace history 430 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend_unittest.cc ('k') | chrome/browser/history/history_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698