OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/callback.h" | 6 #include "base/callback.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/utf_string_conversions.h" | |
11 #include "chrome/browser/history/history.h" | 10 #include "chrome/browser/history/history.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
13 | 12 |
14 using base::Time; | 13 using base::Time; |
15 using base::TimeDelta; | 14 using base::TimeDelta; |
16 | 15 |
17 // Tests the history service for querying functionality. | 16 // Tests the history service for querying functionality. |
18 | 17 |
19 namespace history { | 18 namespace history { |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 struct TestEntry { | 22 struct TestEntry { |
24 const char* url; | 23 const char* url; |
25 const wchar_t* title; | 24 const wchar_t* title; |
26 const int days_ago; | 25 const int days_ago; |
27 const char* body; | 26 const wchar_t* body; |
28 Time time; // Filled by SetUp. | 27 Time time; // Filled by SetUp. |
29 } test_entries[] = { | 28 } test_entries[] = { |
30 // This one is visited super long ago so it will be in a different database | 29 // This one is visited super long ago so it will be in a different database |
31 // from the next appearance of it at the end. | 30 // from the next appearance of it at the end. |
32 {"http://example.com/", L"Other", 180, "Other"}, | 31 {"http://example.com/", L"Other", 180, L"Other"}, |
33 | 32 |
34 // These are deliberately added out of chronological order. The history | 33 // These are deliberately added out of chronological order. The history |
35 // service should sort them by visit time when returning query results. | 34 // service should sort them by visit time when returning query results. |
36 // The correct index sort order is 4 2 3 1 0. | 35 // The correct index sort order is 4 2 3 1 0. |
37 {"http://www.google.com/1", L"Title 1", 10, | 36 {"http://www.google.com/1", L"Title 1", 10, |
38 "PAGEONE FOO some body text"}, | 37 L"PAGEONE FOO some body text"}, |
39 {"http://www.google.com/3", L"Title 3", 8, | 38 {"http://www.google.com/3", L"Title 3", 8, |
40 "PAGETHREE BAR some hello world for you"}, | 39 L"PAGETHREE BAR some hello world for you"}, |
41 {"http://www.google.com/2", L"Title 2", 9, | 40 {"http://www.google.com/2", L"Title 2", 9, |
42 "PAGETWO FOO some more blah blah blah"}, | 41 L"PAGETWO FOO some more blah blah blah"}, |
43 | 42 |
44 // A more recent visit of the first one. | 43 // A more recent visit of the first one. |
45 {"http://example.com/", L"Other", 6, "Other"}, | 44 {"http://example.com/", L"Other", 6, L"Other"}, |
46 }; | 45 }; |
47 | 46 |
48 // Returns true if the nth result in the given results set matches. It will | 47 // Returns true if the nth result in the given results set matches. It will |
49 // return false on a non-match or if there aren't enough results. | 48 // return false on a non-match or if there aren't enough results. |
50 bool NthResultIs(const QueryResults& results, | 49 bool NthResultIs(const QueryResults& results, |
51 int n, // Result index to check. | 50 int n, // Result index to check. |
52 int test_entry_index) { // Index of test_entries to compare. | 51 int test_entry_index) { // Index of test_entries to compare. |
53 if (static_cast<int>(results.size()) <= n) | 52 if (static_cast<int>(results.size()) <= n) |
54 return false; | 53 return false; |
55 | 54 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 105 |
107 // We need the ID scope and page ID so that the visit tracker can find it. | 106 // We need the ID scope and page ID so that the visit tracker can find it. |
108 const void* id_scope = reinterpret_cast<void*>(1); | 107 const void* id_scope = reinterpret_cast<void*>(1); |
109 int32 page_id = i; | 108 int32 page_id = i; |
110 GURL url(test_entries[i].url); | 109 GURL url(test_entries[i].url); |
111 | 110 |
112 history_->AddPage(url, test_entries[i].time, id_scope, page_id, GURL(), | 111 history_->AddPage(url, test_entries[i].time, id_scope, page_id, GURL(), |
113 PageTransition::LINK, history::RedirectList(), | 112 PageTransition::LINK, history::RedirectList(), |
114 false); | 113 false); |
115 history_->SetPageTitle(url, test_entries[i].title); | 114 history_->SetPageTitle(url, test_entries[i].title); |
116 history_->SetPageContents(url, UTF8ToUTF16(test_entries[i].body)); | 115 history_->SetPageContents(url, test_entries[i].body); |
117 } | 116 } |
118 } | 117 } |
119 | 118 |
120 virtual void TearDown() { | 119 virtual void TearDown() { |
121 if (history_.get()) { | 120 if (history_.get()) { |
122 history_->SetOnBackendDestroyTask(new MessageLoop::QuitTask); | 121 history_->SetOnBackendDestroyTask(new MessageLoop::QuitTask); |
123 history_->Cleanup(); | 122 history_->Cleanup(); |
124 history_ = NULL; | 123 history_ = NULL; |
125 MessageLoop::current()->Run(); // Wait for the other thread. | 124 MessageLoop::current()->Run(); // Wait for the other thread. |
126 } | 125 } |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 QueryOptions options; | 340 QueryOptions options; |
342 QueryResults results; | 341 QueryResults results; |
343 | 342 |
344 QueryHistory(std::wstring(L"Other"), options, &results); | 343 QueryHistory(std::wstring(L"Other"), options, &results); |
345 EXPECT_EQ(1, results.urls().size()); | 344 EXPECT_EQ(1, results.urls().size()); |
346 EXPECT_TRUE(NthResultIs(results, 0, 4)); | 345 EXPECT_TRUE(NthResultIs(results, 0, 4)); |
347 } | 346 } |
348 */ | 347 */ |
349 | 348 |
350 } // namespace history | 349 } // namespace history |
OLD | NEW |