| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/ui/webui/browsing_history_handler.h" | 5 #include "chrome/browser/ui/webui/browsing_history_handler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> |
| 10 | 11 |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/simple_test_clock.h" | 15 #include "base/test/simple_test_clock.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/history/browsing_history_service.h" |
| 16 #include "chrome/browser/history/web_history_service_factory.h" | 18 #include "chrome/browser/history/web_history_service_factory.h" |
| 17 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 19 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 18 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 20 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| 19 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 21 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 20 #include "chrome/browser/signin/signin_manager_factory.h" | 22 #include "chrome/browser/signin/signin_manager_factory.h" |
| 21 #include "chrome/browser/sync/profile_sync_service_factory.h" | 23 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 22 #include "chrome/browser/sync/profile_sync_test_util.h" | 24 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
| 24 #include "components/browser_sync/test_profile_sync_service.h" | 26 #include "components/browser_sync/test_profile_sync_service.h" |
| 25 #include "components/history/core/test/fake_web_history_service.h" | 27 #include "components/history/core/test/fake_web_history_service.h" |
| 26 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 28 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 27 #include "components/signin/core/browser/fake_signin_manager.h" | 29 #include "components/signin/core/browser/fake_signin_manager.h" |
| 28 #include "components/sync/base/model_type.h" | 30 #include "components/sync/base/model_type.h" |
| 29 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/test/test_browser_thread_bundle.h" | 33 #include "content/public/test/test_browser_thread_bundle.h" |
| 32 #include "content/public/test/test_web_ui.h" | 34 #include "content/public/test/test_web_ui.h" |
| 33 #include "net/http/http_status_code.h" | 35 #include "net/http/http_status_code.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 35 #include "url/gurl.h" | 37 #include "url/gurl.h" |
| 36 | 38 |
| 37 #if !defined(OS_ANDROID) | 39 #if !defined(OS_ANDROID) |
| 38 #include "chrome/browser/ui/webui/md_history_ui.h" | 40 #include "chrome/browser/ui/webui/md_history_ui.h" |
| 39 #endif | 41 #endif |
| 40 | 42 |
| 41 namespace { | 43 namespace { |
| 42 | 44 |
| 43 struct TestResult { | |
| 44 std::string url; | |
| 45 int64_t hour_offset; // Visit time in hours past the baseline time. | |
| 46 }; | |
| 47 | |
| 48 // Duplicates on the same day in the local timezone are removed, so set a | 45 // Duplicates on the same day in the local timezone are removed, so set a |
| 49 // baseline time in local time. | 46 // baseline time in local time. |
| 50 const base::Time baseline_time = base::Time::UnixEpoch().LocalMidnight(); | 47 const base::Time baseline_time = base::Time::UnixEpoch().LocalMidnight(); |
| 51 | 48 |
| 52 base::Time PretendNow() { | 49 base::Time PretendNow() { |
| 53 base::Time::Exploded exploded_reference_time; | 50 base::Time::Exploded exploded_reference_time; |
| 54 exploded_reference_time.year = 2015; | 51 exploded_reference_time.year = 2015; |
| 55 exploded_reference_time.month = 1; | 52 exploded_reference_time.month = 1; |
| 56 exploded_reference_time.day_of_month = 2; | 53 exploded_reference_time.day_of_month = 2; |
| 57 exploded_reference_time.day_of_week = 5; | 54 exploded_reference_time.day_of_week = 5; |
| 58 exploded_reference_time.hour = 11; | 55 exploded_reference_time.hour = 11; |
| 59 exploded_reference_time.minute = 0; | 56 exploded_reference_time.minute = 0; |
| 60 exploded_reference_time.second = 0; | 57 exploded_reference_time.second = 0; |
| 61 exploded_reference_time.millisecond = 0; | 58 exploded_reference_time.millisecond = 0; |
| 62 | 59 |
| 63 base::Time out_time; | 60 base::Time out_time; |
| 64 EXPECT_TRUE( | 61 EXPECT_TRUE( |
| 65 base::Time::FromLocalExploded(exploded_reference_time, &out_time)); | 62 base::Time::FromLocalExploded(exploded_reference_time, &out_time)); |
| 66 return out_time; | 63 return out_time; |
| 67 } | 64 } |
| 68 | 65 |
| 69 // For each item in |results|, create a new Value representing the visit, and | |
| 70 // insert it into |list_value|. | |
| 71 void AddQueryResults( | |
| 72 TestResult* test_results, | |
| 73 int test_results_size, | |
| 74 std::vector<BrowsingHistoryHandler::HistoryEntry>* results) { | |
| 75 for (int i = 0; i < test_results_size; ++i) { | |
| 76 BrowsingHistoryHandler::HistoryEntry entry; | |
| 77 entry.time = baseline_time + | |
| 78 base::TimeDelta::FromHours(test_results[i].hour_offset); | |
| 79 entry.url = GURL(test_results[i].url); | |
| 80 entry.all_timestamps.insert(entry.time.ToInternalValue()); | |
| 81 results->push_back(entry); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 // Returns true if |result| matches the test data given by |correct_result|, | |
| 86 // otherwise returns false. | |
| 87 bool ResultEquals( | |
| 88 const BrowsingHistoryHandler::HistoryEntry& result, | |
| 89 const TestResult& correct_result) { | |
| 90 base::Time correct_time = | |
| 91 baseline_time + base::TimeDelta::FromHours(correct_result.hour_offset); | |
| 92 | |
| 93 return result.time == correct_time && result.url == correct_result.url; | |
| 94 } | |
| 95 | |
| 96 void IgnoreBoolAndDoNothing(bool ignored_argument) {} | 66 void IgnoreBoolAndDoNothing(bool ignored_argument) {} |
| 97 | 67 |
| 98 class TestSyncService : public browser_sync::TestProfileSyncService { | 68 class TestSyncService : public browser_sync::TestProfileSyncService { |
| 99 public: | 69 public: |
| 100 explicit TestSyncService(Profile* profile) | 70 explicit TestSyncService(Profile* profile) |
| 101 : browser_sync::TestProfileSyncService( | 71 : browser_sync::TestProfileSyncService( |
| 102 CreateProfileSyncServiceParamsForTest(profile)), | 72 CreateProfileSyncServiceParamsForTest(profile)), |
| 103 sync_active_(true) {} | 73 sync_active_(true) {} |
| 104 | 74 |
| 105 bool IsSyncActive() const override { return sync_active_; } | 75 bool IsSyncActive() const override { return sync_active_; } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 120 class BrowsingHistoryHandlerWithWebUIForTesting | 90 class BrowsingHistoryHandlerWithWebUIForTesting |
| 121 : public BrowsingHistoryHandler { | 91 : public BrowsingHistoryHandler { |
| 122 public: | 92 public: |
| 123 explicit BrowsingHistoryHandlerWithWebUIForTesting(content::WebUI* web_ui) | 93 explicit BrowsingHistoryHandlerWithWebUIForTesting(content::WebUI* web_ui) |
| 124 : test_clock_(new base::SimpleTestClock()) { | 94 : test_clock_(new base::SimpleTestClock()) { |
| 125 set_clock(base::WrapUnique(test_clock_)); | 95 set_clock(base::WrapUnique(test_clock_)); |
| 126 set_web_ui(web_ui); | 96 set_web_ui(web_ui); |
| 127 test_clock_->SetNow(PretendNow()); | 97 test_clock_->SetNow(PretendNow()); |
| 128 | 98 |
| 129 } | 99 } |
| 130 using BrowsingHistoryHandler::QueryComplete; | |
| 131 | 100 |
| 132 base::SimpleTestClock* test_clock() { return test_clock_; } | 101 base::SimpleTestClock* test_clock() { return test_clock_; } |
| 133 | 102 |
| 134 private: | 103 private: |
| 135 base::SimpleTestClock* test_clock_; | 104 base::SimpleTestClock* test_clock_; |
| 136 }; | 105 }; |
| 137 | 106 |
| 138 } // namespace | 107 } // namespace |
| 139 | 108 |
| 140 class BrowsingHistoryHandlerTest : public ::testing::Test { | 109 class BrowsingHistoryHandlerTest : public ::testing::Test { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 166 } |
| 198 | 167 |
| 199 content::TestBrowserThreadBundle thread_bundle_; | 168 content::TestBrowserThreadBundle thread_bundle_; |
| 200 std::unique_ptr<TestingProfile> profile_; | 169 std::unique_ptr<TestingProfile> profile_; |
| 201 TestSyncService* sync_service_; | 170 TestSyncService* sync_service_; |
| 202 history::FakeWebHistoryService* web_history_service_; | 171 history::FakeWebHistoryService* web_history_service_; |
| 203 std::unique_ptr<content::TestWebUI> web_ui_; | 172 std::unique_ptr<content::TestWebUI> web_ui_; |
| 204 std::unique_ptr<content::WebContents> web_contents_; | 173 std::unique_ptr<content::WebContents> web_contents_; |
| 205 }; | 174 }; |
| 206 | 175 |
| 207 // Tests that the MergeDuplicateResults method correctly removes duplicate | |
| 208 // visits to the same URL on the same day. | |
| 209 // Fails on Android. http://crbug.com/2345 | |
| 210 #if defined(OS_ANDROID) | |
| 211 #define MAYBE_MergeDuplicateResults DISABLED_MergeDuplicateResults | |
| 212 #else | |
| 213 #define MAYBE_MergeDuplicateResults MergeDuplicateResults | |
| 214 #endif | |
| 215 TEST_F(BrowsingHistoryHandlerTest, MAYBE_MergeDuplicateResults) { | |
| 216 { | |
| 217 // Basic test that duplicates on the same day are removed. | |
| 218 TestResult test_data[] = { | |
| 219 { "http://google.com/", 0 }, | |
| 220 { "http://google.de/", 1 }, | |
| 221 { "http://google.com/", 2 }, | |
| 222 { "http://google.com/", 3 } // Most recent. | |
| 223 }; | |
| 224 std::vector<BrowsingHistoryHandler::HistoryEntry> results; | |
| 225 AddQueryResults(test_data, arraysize(test_data), &results); | |
| 226 BrowsingHistoryHandler::MergeDuplicateResults(&results); | |
| 227 | |
| 228 ASSERT_EQ(2U, results.size()); | |
| 229 EXPECT_TRUE(ResultEquals(results[0], test_data[3])); | |
| 230 EXPECT_TRUE(ResultEquals(results[1], test_data[1])); | |
| 231 } | |
| 232 | |
| 233 { | |
| 234 // Test that a duplicate URL on the next day is not removed. | |
| 235 TestResult test_data[] = { | |
| 236 { "http://google.com/", 0 }, | |
| 237 { "http://google.com/", 23 }, | |
| 238 { "http://google.com/", 24 }, // Most recent. | |
| 239 }; | |
| 240 std::vector<BrowsingHistoryHandler::HistoryEntry> results; | |
| 241 AddQueryResults(test_data, arraysize(test_data), &results); | |
| 242 BrowsingHistoryHandler::MergeDuplicateResults(&results); | |
| 243 | |
| 244 ASSERT_EQ(2U, results.size()); | |
| 245 EXPECT_TRUE(ResultEquals(results[0], test_data[2])); | |
| 246 EXPECT_TRUE(ResultEquals(results[1], test_data[1])); | |
| 247 } | |
| 248 | |
| 249 { | |
| 250 // Test multiple duplicates across multiple days. | |
| 251 TestResult test_data[] = { | |
| 252 // First day. | |
| 253 { "http://google.de/", 0 }, | |
| 254 { "http://google.com/", 1 }, | |
| 255 { "http://google.de/", 2 }, | |
| 256 { "http://google.com/", 3 }, | |
| 257 | |
| 258 // Second day. | |
| 259 { "http://google.de/", 24 }, | |
| 260 { "http://google.com/", 25 }, | |
| 261 { "http://google.de/", 26 }, | |
| 262 { "http://google.com/", 27 }, // Most recent. | |
| 263 }; | |
| 264 std::vector<BrowsingHistoryHandler::HistoryEntry> results; | |
| 265 AddQueryResults(test_data, arraysize(test_data), &results); | |
| 266 BrowsingHistoryHandler::MergeDuplicateResults(&results); | |
| 267 | |
| 268 ASSERT_EQ(4U, results.size()); | |
| 269 EXPECT_TRUE(ResultEquals(results[0], test_data[7])); | |
| 270 EXPECT_TRUE(ResultEquals(results[1], test_data[6])); | |
| 271 EXPECT_TRUE(ResultEquals(results[2], test_data[3])); | |
| 272 EXPECT_TRUE(ResultEquals(results[3], test_data[2])); | |
| 273 } | |
| 274 | |
| 275 { | |
| 276 // Test that timestamps for duplicates are properly saved. | |
| 277 TestResult test_data[] = { | |
| 278 { "http://google.com/", 0 }, | |
| 279 { "http://google.de/", 1 }, | |
| 280 { "http://google.com/", 2 }, | |
| 281 { "http://google.com/", 3 } // Most recent. | |
| 282 }; | |
| 283 std::vector<BrowsingHistoryHandler::HistoryEntry> results; | |
| 284 AddQueryResults(test_data, arraysize(test_data), &results); | |
| 285 BrowsingHistoryHandler::MergeDuplicateResults(&results); | |
| 286 | |
| 287 ASSERT_EQ(2U, results.size()); | |
| 288 EXPECT_TRUE(ResultEquals(results[0], test_data[3])); | |
| 289 EXPECT_TRUE(ResultEquals(results[1], test_data[1])); | |
| 290 EXPECT_EQ(3u, results[0].all_timestamps.size()); | |
| 291 EXPECT_EQ(1u, results[1].all_timestamps.size()); | |
| 292 } | |
| 293 } | |
| 294 | |
| 295 TEST_F(BrowsingHistoryHandlerTest, SetQueryTimeInWeeks) { | 176 TEST_F(BrowsingHistoryHandlerTest, SetQueryTimeInWeeks) { |
| 296 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); | 177 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); |
| 297 history::QueryOptions options; | 178 history::QueryOptions options; |
| 298 | 179 |
| 299 // Querying this week should result in end time being midnight tonight and | 180 // Querying this week should result in end time being midnight tonight and |
| 300 // begin time being midnight a week ago. | 181 // begin time being midnight a week ago. |
| 301 handler.SetQueryTimeInWeeks(0, &options); | 182 handler.SetQueryTimeInWeeks(0, &options); |
| 302 base::Time midnight_tonight = | 183 base::Time midnight_tonight = |
| 303 PretendNow().LocalMidnight() + base::TimeDelta::FromDays(1); | 184 PretendNow().LocalMidnight() + base::TimeDelta::FromDays(1); |
| 304 EXPECT_EQ(midnight_tonight, options.end_time); | 185 EXPECT_EQ(midnight_tonight, options.end_time); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 EXPECT_TRUE(base::Time::FromLocalExploded(exploded_expected_time, | 227 EXPECT_TRUE(base::Time::FromLocalExploded(exploded_expected_time, |
| 347 &first_aug_2014_midnight)); | 228 &first_aug_2014_midnight)); |
| 348 EXPECT_EQ(first_aug_2014_midnight, options.end_time); | 229 EXPECT_EQ(first_aug_2014_midnight, options.end_time); |
| 349 exploded_expected_time.month = 7; | 230 exploded_expected_time.month = 7; |
| 350 base::Time first_jul_2014_midnight; | 231 base::Time first_jul_2014_midnight; |
| 351 EXPECT_TRUE(base::Time::FromLocalExploded(exploded_expected_time, | 232 EXPECT_TRUE(base::Time::FromLocalExploded(exploded_expected_time, |
| 352 &first_jul_2014_midnight)); | 233 &first_jul_2014_midnight)); |
| 353 EXPECT_EQ(first_jul_2014_midnight, options.begin_time); | 234 EXPECT_EQ(first_jul_2014_midnight, options.begin_time); |
| 354 } | 235 } |
| 355 | 236 |
| 356 // Tests that BrowsingHistoryHandler observes WebHistoryService deletions. | 237 // Tests that BrowsingHistoryHandler is informed about WebHistoryService |
| 238 // deletions. |
| 357 TEST_F(BrowsingHistoryHandlerTest, ObservingWebHistoryDeletions) { | 239 TEST_F(BrowsingHistoryHandlerTest, ObservingWebHistoryDeletions) { |
| 358 base::Callback<void(bool)> callback = base::Bind(&IgnoreBoolAndDoNothing); | 240 base::Callback<void(bool)> callback = base::Bind(&IgnoreBoolAndDoNothing); |
| 359 | 241 |
| 360 // BrowsingHistoryHandler listens to WebHistoryService history deletions. | 242 // BrowsingHistoryHandler is informed about WebHistoryService history |
| 243 // deletions. |
| 361 { | 244 { |
| 362 sync_service()->SetSyncActive(true); | 245 sync_service()->SetSyncActive(true); |
| 363 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); | 246 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); |
| 364 handler.RegisterMessages(); | 247 handler.RegisterMessages(); |
| 365 | 248 |
| 366 web_history_service()->ExpireHistoryBetween(std::set<GURL>(), base::Time(), | 249 web_history_service()->ExpireHistoryBetween(std::set<GURL>(), base::Time(), |
| 367 base::Time::Max(), callback); | 250 base::Time::Max(), callback); |
| 368 | 251 |
| 369 EXPECT_EQ(1U, web_ui()->call_data().size()); | 252 EXPECT_EQ(1U, web_ui()->call_data().size()); |
| 370 EXPECT_EQ("historyDeleted", web_ui()->call_data().back()->function_name()); | 253 EXPECT_EQ("historyDeleted", web_ui()->call_data().back()->function_name()); |
| 371 } | 254 } |
| 372 | 255 |
| 373 // BrowsingHistoryHandler will listen to WebHistoryService deletions even if | 256 // BrowsingHistoryHandler will be informed about WebHistoryService deletions |
| 374 // history sync is activated later. | 257 // even if history sync is activated later. |
| 375 { | 258 { |
| 376 sync_service()->SetSyncActive(false); | 259 sync_service()->SetSyncActive(false); |
| 377 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); | 260 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); |
| 378 handler.RegisterMessages(); | 261 handler.RegisterMessages(); |
| 379 sync_service()->SetSyncActive(true); | 262 sync_service()->SetSyncActive(true); |
| 380 | 263 |
| 381 web_history_service()->ExpireHistoryBetween(std::set<GURL>(), base::Time(), | 264 web_history_service()->ExpireHistoryBetween(std::set<GURL>(), base::Time(), |
| 382 base::Time::Max(), callback); | 265 base::Time::Max(), callback); |
| 383 | 266 |
| 384 EXPECT_EQ(2U, web_ui()->call_data().size()); | 267 EXPECT_EQ(2U, web_ui()->call_data().size()); |
| 385 EXPECT_EQ("historyDeleted", web_ui()->call_data().back()->function_name()); | 268 EXPECT_EQ("historyDeleted", web_ui()->call_data().back()->function_name()); |
| 386 } | 269 } |
| 387 | 270 |
| 388 // BrowsingHistoryHandler does not fire historyDeleted while a web history | 271 // BrowsingHistoryHandler does not fire historyDeleted while a web history |
| 389 // delete request is happening. | 272 // delete request is happening. |
| 390 { | 273 { |
| 391 sync_service()->SetSyncActive(true); | 274 sync_service()->SetSyncActive(true); |
| 392 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); | 275 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); |
| 393 handler.RegisterMessages(); | 276 handler.RegisterMessages(); |
| 394 | 277 |
| 395 // Simulate an ongoing delete request. | 278 // Simulate an ongoing delete request. |
| 396 handler.has_pending_delete_request_ = true; | 279 handler.browsing_history_service_->has_pending_delete_request_ = true; |
| 397 | 280 |
| 398 web_history_service()->ExpireHistoryBetween( | 281 web_history_service()->ExpireHistoryBetween( |
| 399 std::set<GURL>(), base::Time(), base::Time::Max(), | 282 std::set<GURL>(), base::Time(), base::Time::Max(), |
| 400 base::Bind(&BrowsingHistoryHandler::RemoveWebHistoryComplete, | 283 base::Bind( |
| 401 handler.weak_factory_.GetWeakPtr())); | 284 &BrowsingHistoryService::RemoveWebHistoryComplete, |
| 285 handler.browsing_history_service_->weak_factory_.GetWeakPtr())); |
| 402 | 286 |
| 403 EXPECT_EQ(3U, web_ui()->call_data().size()); | 287 EXPECT_EQ(3U, web_ui()->call_data().size()); |
| 404 EXPECT_EQ("deleteComplete", web_ui()->call_data().back()->function_name()); | 288 EXPECT_EQ("deleteComplete", web_ui()->call_data().back()->function_name()); |
| 405 } | 289 } |
| 406 | 290 |
| 407 // When history sync is not active, we don't listen to WebHistoryService | 291 // When history sync is not active, we don't listen to WebHistoryService |
| 408 // deletions. The WebHistoryService object still exists (because it's a | 292 // deletions. The WebHistoryService object still exists (because it's a |
| 409 // BrowserContextKeyedService), but is not visible to BrowsingHistoryHandler. | 293 // BrowserContextKeyedService), but is not visible to BrowsingHistoryHandler. |
| 410 { | 294 { |
| 411 sync_service()->SetSyncActive(false); | 295 sync_service()->SetSyncActive(false); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 431 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" | 315 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" |
| 432 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" | 316 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" |
| 433 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" | 317 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" |
| 434 "ngurlislong.com"), base::Time()); | 318 "ngurlislong.com"), base::Time()); |
| 435 ASSERT_GT(long_result.url().spec().size(), 300u); | 319 ASSERT_GT(long_result.url().spec().size(), 300u); |
| 436 | 320 |
| 437 history::QueryResults results; | 321 history::QueryResults results; |
| 438 results.AppendURLBySwapping(&long_result); | 322 results.AppendURLBySwapping(&long_result); |
| 439 | 323 |
| 440 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); | 324 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); |
| 325 handler.RegisterMessages(); // Needed to create BrowsingHistoryService. |
| 441 web_ui()->ClearTrackedCalls(); | 326 web_ui()->ClearTrackedCalls(); |
| 442 | 327 |
| 443 handler.QueryComplete(base::string16(), history::QueryOptions(), &results); | 328 handler.browsing_history_service_->QueryComplete( |
| 329 base::string16(), history::QueryOptions(), &results); |
| 444 ASSERT_FALSE(web_ui()->call_data().empty()); | 330 ASSERT_FALSE(web_ui()->call_data().empty()); |
| 445 | 331 |
| 446 const base::ListValue* arg2; | 332 const base::ListValue* arg2; |
| 447 ASSERT_TRUE(web_ui()->call_data().front()->arg2()->GetAsList(&arg2)); | 333 ASSERT_TRUE(web_ui()->call_data().front()->arg2()->GetAsList(&arg2)); |
| 448 | 334 |
| 449 const base::DictionaryValue* first_entry; | 335 const base::DictionaryValue* first_entry; |
| 450 ASSERT_TRUE(arg2->GetDictionary(0, &first_entry)); | 336 ASSERT_TRUE(arg2->GetDictionary(0, &first_entry)); |
| 451 | 337 |
| 452 base::string16 title; | 338 base::string16 title; |
| 453 ASSERT_TRUE(first_entry->GetString("title", &title)); | 339 ASSERT_TRUE(first_entry->GetString("title", &title)); |
| 454 | 340 |
| 455 ASSERT_EQ(0u, title.find(base::ASCIIToUTF16("http://loooo"))); | 341 ASSERT_EQ(0u, title.find(base::ASCIIToUTF16("http://loooo"))); |
| 456 EXPECT_EQ(300u, title.size()); | 342 EXPECT_EQ(300u, title.size()); |
| 457 } | 343 } |
| 458 #endif | 344 #endif |
| OLD | NEW |