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

Side by Side 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 unified diff | Download patch
OLDNEW
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"
22 #include "chrome/browser/ui/webui/md_history_ui.h"
21 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
22 #include "components/browser_sync/browser/test_profile_sync_service.h" 24 #include "components/browser_sync/browser/test_profile_sync_service.h"
23 #include "components/history/core/test/fake_web_history_service.h" 25 #include "components/history/core/test/fake_web_history_service.h"
24 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" 26 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h"
25 #include "components/signin/core/browser/fake_signin_manager.h" 27 #include "components/signin/core/browser/fake_signin_manager.h"
26 #include "components/sync/base/model_type.h" 28 #include "components/sync/base/model_type.h"
27 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
28 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "content/public/test/test_web_ui.h" 32 #include "content/public/test/test_web_ui.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 private: 94 private:
93 bool sync_active_; 95 bool sync_active_;
94 }; 96 };
95 97
96 class BrowsingHistoryHandlerWithWebUIForTesting 98 class BrowsingHistoryHandlerWithWebUIForTesting
97 : public BrowsingHistoryHandler { 99 : public BrowsingHistoryHandler {
98 public: 100 public:
99 explicit BrowsingHistoryHandlerWithWebUIForTesting(content::WebUI* web_ui) { 101 explicit BrowsingHistoryHandlerWithWebUIForTesting(content::WebUI* web_ui) {
100 set_web_ui(web_ui); 102 set_web_ui(web_ui);
101 } 103 }
104 using BrowsingHistoryHandler::QueryComplete;
102 }; 105 };
103 106
104 } // namespace 107 } // namespace
105 108
106 class BrowsingHistoryHandlerTest : public ::testing::Test { 109 class BrowsingHistoryHandlerTest : public ::testing::Test {
107 public: 110 public:
108 void SetUp() override { 111 void SetUp() override {
109 TestingProfile::Builder builder; 112 TestingProfile::Builder builder;
110 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(), 113 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
111 &BuildFakeProfileOAuth2TokenService); 114 &BuildFakeProfileOAuth2TokenService);
112 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), 115 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
113 &BuildFakeSigninManagerBase); 116 &BuildFakeSigninManagerBase);
114 builder.AddTestingFactory(ProfileSyncServiceFactory::GetInstance(), 117 builder.AddTestingFactory(ProfileSyncServiceFactory::GetInstance(),
115 &BuildFakeSyncService); 118 &BuildFakeSyncService);
116 builder.AddTestingFactory(WebHistoryServiceFactory::GetInstance(), 119 builder.AddTestingFactory(WebHistoryServiceFactory::GetInstance(),
117 &BuildFakeWebHistoryService); 120 &BuildFakeWebHistoryService);
118 profile_ = builder.Build(); 121 profile_ = builder.Build();
122 profile_->CreateBookmarkModel(false);
119 123
120 sync_service_ = static_cast<TestSyncService*>( 124 sync_service_ = static_cast<TestSyncService*>(
121 ProfileSyncServiceFactory::GetForProfile(profile_.get())); 125 ProfileSyncServiceFactory::GetForProfile(profile_.get()));
122 web_history_service_ = static_cast<history::FakeWebHistoryService*>( 126 web_history_service_ = static_cast<history::FakeWebHistoryService*>(
123 WebHistoryServiceFactory::GetForProfile(profile_.get())); 127 WebHistoryServiceFactory::GetForProfile(profile_.get()));
124 128
125 web_contents_.reset(content::WebContents::Create( 129 web_contents_.reset(content::WebContents::Create(
126 content::WebContents::CreateParams(profile_.get()))); 130 content::WebContents::CreateParams(profile_.get())));
127 web_ui_.reset(new content::TestWebUI); 131 web_ui_.reset(new content::TestWebUI);
128 web_ui_->set_web_contents(web_contents_.get()); 132 web_ui_->set_web_contents(web_contents_.get());
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui()); 301 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui());
298 handler.RegisterMessages(); 302 handler.RegisterMessages();
299 303
300 web_history_service()->ExpireHistoryBetween(std::set<GURL>(), base::Time(), 304 web_history_service()->ExpireHistoryBetween(std::set<GURL>(), base::Time(),
301 base::Time::Max(), callback); 305 base::Time::Max(), callback);
302 306
303 // No additional WebUI calls were made. 307 // No additional WebUI calls were made.
304 EXPECT_EQ(2U, web_ui()->call_data().size()); 308 EXPECT_EQ(2U, web_ui()->call_data().size());
305 } 309 }
306 } 310 }
311
312 #if !defined(OS_ANDROID)
313 TEST_F(BrowsingHistoryHandlerTest, MdTruncatesTitles) {
314 MdHistoryUI::SetEnabledForTesting(true);
315
316 BrowsingHistoryHandlerWithWebUIForTesting handler(web_ui());
317
318 base::ListValue args;
319 args.AppendDouble(0); // Offset.
320 args.AppendDouble(0); // Range. (BrowsingHistoryHandler::Range::ALL_TIME)
321 args.AppendDouble(0); // End time.
322 args.AppendDouble(1); // Max count.
323
324 handler.RegisterMessages();
325 handler.HandleQueryHistory(&args);
326
327 history::URLResult long_result(
328 GURL("http://looooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
329 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
330 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
331 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
332 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
333 "oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo"
334 "ngurlislong.com"), base::Time());
335 ASSERT_GT(long_result.url().spec().size(), 300u);
336
337 history::QueryResults results;
338 results.AppendURLBySwapping(&long_result);
339
340 web_ui()->ClearTrackedCalls();
341 handler.QueryComplete(base::string16(), history::QueryOptions(), &results);
342 ASSERT_FALSE(web_ui()->call_data().empty());
343
344 const base::ListValue* arg2;
345 ASSERT_TRUE(web_ui()->call_data().front()->arg2()->GetAsList(&arg2));
346
347 const base::DictionaryValue* first_entry;
348 ASSERT_TRUE(arg2->GetDictionary(0, &first_entry));
349
350 base::string16 title;
351 ASSERT_TRUE(first_entry->GetString("title", &title));
352
353 ASSERT_EQ(0u, title.find(base::ASCIIToUTF16("http://loooo")));
354 EXPECT_EQ(300u, title.size());
355 }
356 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698