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

Unified Diff: chrome/browser/ui/webui/browsing_history_handler_unittest.cc

Issue 2318643003: MD History: truncate title to 300 chars in C++ instead of JS (Closed)
Patch Set: !android in tests as well Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/browsing_history_handler_unittest.cc
diff --git a/chrome/browser/ui/webui/browsing_history_handler_unittest.cc b/chrome/browser/ui/webui/browsing_history_handler_unittest.cc
index 36b15a87eebbd482cb8bf83607829bfc31aacc9f..25115506925a2c9b068706123dc8a272eb3b00d1 100644
--- a/chrome/browser/ui/webui/browsing_history_handler_unittest.cc
+++ b/chrome/browser/ui/webui/browsing_history_handler_unittest.cc
@@ -11,6 +11,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
#include "chrome/browser/history/web_history_service_factory.h"
#include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
#include "chrome/browser/signin/fake_signin_manager_builder.h"
@@ -18,6 +19,7 @@
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/sync/profile_sync_test_util.h"
+#include "chrome/browser/ui/webui/md_history_ui.h"
#include "chrome/test/base/testing_profile.h"
#include "components/browser_sync/browser/test_profile_sync_service.h"
#include "components/history/core/test/fake_web_history_service.h"
@@ -99,6 +101,7 @@ class BrowsingHistoryHandlerWithWebUIForTesting
explicit BrowsingHistoryHandlerWithWebUIForTesting(content::WebUI* web_ui) {
set_web_ui(web_ui);
}
+ using BrowsingHistoryHandler::QueryComplete;
};
} // namespace
@@ -116,6 +119,7 @@ class BrowsingHistoryHandlerTest : public ::testing::Test {
builder.AddTestingFactory(WebHistoryServiceFactory::GetInstance(),
&BuildFakeWebHistoryService);
profile_ = builder.Build();
+ profile_->CreateBookmarkModel(false);
sync_service_ = static_cast<TestSyncService*>(
ProfileSyncServiceFactory::GetForProfile(profile_.get()));
@@ -304,3 +308,49 @@ TEST_F(BrowsingHistoryHandlerTest, ObservingWebHistoryDeletions) {
EXPECT_EQ(2U, web_ui()->call_data().size());
}
}
+
+#if !defined(OS_ANDROID)
+TEST_F(BrowsingHistoryHandlerTest, MdTruncatesTitles) {
+ MdHistoryUI::SetEnabledForTesting(true);
+
+ BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui());
+
+ base::ListValue args;
+ args.AppendDouble(0); // Offset.
+ args.AppendDouble(0); // Range. (BrowsingHistoryHandler::Range::ALL_TIME)
+ args.AppendDouble(0); // End time.
+ args.AppendDouble(1); // Max count.
+
+ handler.RegisterMessages();
+ handler.HandleQueryHistory(&args);
+
+ history::URLResult long_result(
+ GURL("http://looooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
+ "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
+ "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
+ "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
+ "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
+ "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
+ "ngurlislong.com"), base::Time());
+ ASSERT_GT(long_result.url().spec().size(), 300u);
+
+ history::QueryResults results;
+ results.AppendURLBySwapping(&long_result);
+
+ web_ui()->ClearTrackedCalls();
+ handler.QueryComplete(base::string16(), history::QueryOptions(), &results);
+ ASSERT_FALSE(web_ui()->call_data().empty());
+
+ const base::ListValue* arg2;
+ ASSERT_TRUE(web_ui()->call_data().front()->arg2()->GetAsList(&arg2));
+
+ const base::DictionaryValue* first_entry;
+ ASSERT_TRUE(arg2->GetDictionary(0, &first_entry));
+
+ base::string16 title;
+ ASSERT_TRUE(first_entry->GetString("title", &title));
+
+ ASSERT_EQ(0u, title.find(base::ASCIIToUTF16("http://loooo")));
+ EXPECT_EQ(300u, title.size());
+}
+#endif

Powered by Google App Engine
This is Rietveld 408576698