| 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 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" |
| 14 #include "chrome/browser/history/web_history_service_factory.h" | 15 #include "chrome/browser/history/web_history_service_factory.h" |
| 15 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 16 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| 16 #include "chrome/browser/signin/fake_signin_manager_builder.h" | 17 #include "chrome/browser/signin/fake_signin_manager_builder.h" |
| 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 19 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/browser/sync/profile_sync_service_factory.h" | 20 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 20 #include "chrome/browser/sync/profile_sync_test_util.h" | 21 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 21 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
| 22 #include "components/browser_sync/browser/test_profile_sync_service.h" | 23 #include "components/browser_sync/browser/test_profile_sync_service.h" |
| 23 #include "components/history/core/test/fake_web_history_service.h" | 24 #include "components/history/core/test/fake_web_history_service.h" |
| 24 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 25 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 25 #include "components/signin/core/browser/fake_signin_manager.h" | 26 #include "components/signin/core/browser/fake_signin_manager.h" |
| 26 #include "components/sync/base/model_type.h" | 27 #include "components/sync/base/model_type.h" |
| 27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/test/test_browser_thread_bundle.h" | 30 #include "content/public/test/test_browser_thread_bundle.h" |
| 30 #include "content/public/test/test_web_ui.h" | 31 #include "content/public/test/test_web_ui.h" |
| 31 #include "net/http/http_status_code.h" | 32 #include "net/http/http_status_code.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "url/gurl.h" | 34 #include "url/gurl.h" |
| 34 | 35 |
| 36 #if !defined(OS_ANDROID) |
| 37 #include "chrome/browser/ui/webui/md_history_ui.h" |
| 38 #endif |
| 39 |
| 35 namespace { | 40 namespace { |
| 36 | 41 |
| 37 struct TestResult { | 42 struct TestResult { |
| 38 std::string url; | 43 std::string url; |
| 39 int64_t hour_offset; // Visit time in hours past the baseline time. | 44 int64_t hour_offset; // Visit time in hours past the baseline time. |
| 40 }; | 45 }; |
| 41 | 46 |
| 42 // Duplicates on the same day in the local timezone are removed, so set a | 47 // Duplicates on the same day in the local timezone are removed, so set a |
| 43 // baseline time in local time. | 48 // baseline time in local time. |
| 44 const base::Time baseline_time = base::Time::UnixEpoch().LocalMidnight(); | 49 const base::Time baseline_time = base::Time::UnixEpoch().LocalMidnight(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 private: | 97 private: |
| 93 bool sync_active_; | 98 bool sync_active_; |
| 94 }; | 99 }; |
| 95 | 100 |
| 96 class BrowsingHistoryHandlerWithWebUIForTesting | 101 class BrowsingHistoryHandlerWithWebUIForTesting |
| 97 : public BrowsingHistoryHandler { | 102 : public BrowsingHistoryHandler { |
| 98 public: | 103 public: |
| 99 explicit BrowsingHistoryHandlerWithWebUIForTesting(content::WebUI* web_ui) { | 104 explicit BrowsingHistoryHandlerWithWebUIForTesting(content::WebUI* web_ui) { |
| 100 set_web_ui(web_ui); | 105 set_web_ui(web_ui); |
| 101 } | 106 } |
| 107 using BrowsingHistoryHandler::QueryComplete; |
| 102 }; | 108 }; |
| 103 | 109 |
| 104 } // namespace | 110 } // namespace |
| 105 | 111 |
| 106 class BrowsingHistoryHandlerTest : public ::testing::Test { | 112 class BrowsingHistoryHandlerTest : public ::testing::Test { |
| 107 public: | 113 public: |
| 108 void SetUp() override { | 114 void SetUp() override { |
| 109 TestingProfile::Builder builder; | 115 TestingProfile::Builder builder; |
| 110 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), | 116 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 111 &BuildFakeProfileOAuth2TokenService); | 117 &BuildFakeProfileOAuth2TokenService); |
| 112 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | 118 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
| 113 &BuildFakeSigninManagerBase); | 119 &BuildFakeSigninManagerBase); |
| 114 builder.AddTestingFactory(ProfileSyncServiceFactory::GetInstance(), | 120 builder.AddTestingFactory(ProfileSyncServiceFactory::GetInstance(), |
| 115 &BuildFakeSyncService); | 121 &BuildFakeSyncService); |
| 116 builder.AddTestingFactory(WebHistoryServiceFactory::GetInstance(), | 122 builder.AddTestingFactory(WebHistoryServiceFactory::GetInstance(), |
| 117 &BuildFakeWebHistoryService); | 123 &BuildFakeWebHistoryService); |
| 118 profile_ = builder.Build(); | 124 profile_ = builder.Build(); |
| 125 profile_->CreateBookmarkModel(false); |
| 119 | 126 |
| 120 sync_service_ = static_cast<TestSyncService*>( | 127 sync_service_ = static_cast<TestSyncService*>( |
| 121 ProfileSyncServiceFactory::GetForProfile(profile_.get())); | 128 ProfileSyncServiceFactory::GetForProfile(profile_.get())); |
| 122 web_history_service_ = static_cast<history::FakeWebHistoryService*>( | 129 web_history_service_ = static_cast<history::FakeWebHistoryService*>( |
| 123 WebHistoryServiceFactory::GetForProfile(profile_.get())); | 130 WebHistoryServiceFactory::GetForProfile(profile_.get())); |
| 124 | 131 |
| 125 web_contents_.reset(content::WebContents::Create( | 132 web_contents_.reset(content::WebContents::Create( |
| 126 content::WebContents::CreateParams(profile_.get()))); | 133 content::WebContents::CreateParams(profile_.get()))); |
| 127 web_ui_.reset(new content::TestWebUI); | 134 web_ui_.reset(new content::TestWebUI); |
| 128 web_ui_->set_web_contents(web_contents_.get()); | 135 web_ui_->set_web_contents(web_contents_.get()); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); | 304 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); |
| 298 handler.RegisterMessages(); | 305 handler.RegisterMessages(); |
| 299 | 306 |
| 300 web_history_service()->ExpireHistoryBetween(std::set<GURL>(), base::Time(), | 307 web_history_service()->ExpireHistoryBetween(std::set<GURL>(), base::Time(), |
| 301 base::Time::Max(), callback); | 308 base::Time::Max(), callback); |
| 302 | 309 |
| 303 // No additional WebUI calls were made. | 310 // No additional WebUI calls were made. |
| 304 EXPECT_EQ(2U, web_ui()->call_data().size()); | 311 EXPECT_EQ(2U, web_ui()->call_data().size()); |
| 305 } | 312 } |
| 306 } | 313 } |
| 314 |
| 315 #if !defined(OS_ANDROID) |
| 316 TEST_F(BrowsingHistoryHandlerTest, MdTruncatesTitles) { |
| 317 MdHistoryUI::SetEnabledForTesting(true); |
| 318 |
| 319 history::URLResult long_result( |
| 320 GURL("http://looooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" |
| 321 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" |
| 322 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" |
| 323 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" |
| 324 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" |
| 325 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo" |
| 326 "ngurlislong.com"), base::Time()); |
| 327 ASSERT_GT(long_result.url().spec().size(), 300u); |
| 328 |
| 329 history::QueryResults results; |
| 330 results.AppendURLBySwapping(&long_result); |
| 331 |
| 332 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); |
| 333 web_ui()->ClearTrackedCalls(); |
| 334 |
| 335 handler.QueryComplete(base::string16(), history::QueryOptions(), &results); |
| 336 ASSERT_FALSE(web_ui()->call_data().empty()); |
| 337 |
| 338 const base::ListValue* arg2; |
| 339 ASSERT_TRUE(web_ui()->call_data().front()->arg2()->GetAsList(&arg2)); |
| 340 |
| 341 const base::DictionaryValue* first_entry; |
| 342 ASSERT_TRUE(arg2->GetDictionary(0, &first_entry)); |
| 343 |
| 344 base::string16 title; |
| 345 ASSERT_TRUE(first_entry->GetString("title", &title)); |
| 346 |
| 347 ASSERT_EQ(0u, title.find(base::ASCIIToUTF16("http://loooo"))); |
| 348 EXPECT_EQ(300u, title.size()); |
| 349 } |
| 350 #endif |
| OLD | NEW |