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