#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_unittest_base.h"
-#include "chrome/browser/history/in_memory_database.h"
#include "chrome/browser/history/in_memory_history_backend.h"
-#include "chrome/browser/history/page_usage_data.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/tools/profiles/thumbnail-inl.h"
+#include "components/history/core/browser/in_memory_database.h"
+#include "components/history/core/browser/page_usage_data.h"
#include "components/history/core/common/thumbnail_score.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/notification_details.h"
#include "sql/connection.h"
#include "sql/statement.h"
#include "sync/api/attachments/attachment_id.h"
-#include "sync/api/attachments/attachment_service_proxy_for_test.h"
#include "sync/api/fake_sync_change_processor.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_change_processor.h"
#include "sync/api/sync_error.h"
#include "sync/api/sync_error_factory.h"
#include "sync/api/sync_merge_result.h"
+#include "sync/internal_api/public/attachments/attachment_service_proxy_for_test.h"
#include "sync/protocol/history_delete_directive_specifics.pb.h"
#include "sync/protocol/sync.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
{"SERVER_NO_RANGE", 31},
{"SERVER_PRECONDITION", 32},
{"SERVER_BAD_CONTENT", 33},
+ {"SERVER_UNAUTHORIZED", 34},
+ {"SERVER_CERT_PROBLEM", 35},
{"USER_CANCELED", 40},
{"USER_SHUTDOWN", 41},
{"CRASH", 50},
public:
HistoryTest()
: got_thumbnail_callback_(false),
- redirect_query_success_(false),
query_url_success_(false) {
}
virtual ~HistoryTest() {
}
- void OnSegmentUsageAvailable(CancelableRequestProvider::Handle handle,
- std::vector<PageUsageData*>* data) {
- page_usage_data_.swap(*data);
- base::MessageLoop::current()->Quit();
- }
-
- void OnDeleteURLsDone(CancelableRequestProvider::Handle handle) {
- base::MessageLoop::current()->Quit();
- }
-
- void OnMostVisitedURLsAvailable(CancelableRequestProvider::Handle handle,
- MostVisitedURLList url_list) {
- most_visited_urls_.swap(url_list);
+ void OnMostVisitedURLsAvailable(const MostVisitedURLList* url_list) {
+ most_visited_urls_ = *url_list;
base::MessageLoop::current()->Quit();
}
// Fills in saved_redirects_ with the redirect information for the given URL,
// returning true on success. False means the URL was not found.
- bool QueryRedirectsFrom(HistoryService* history, const GURL& url) {
+ void QueryRedirectsFrom(HistoryService* history, const GURL& url) {
history_service_->QueryRedirectsFrom(
- url, &consumer_,
+ url,
base::Bind(&HistoryTest::OnRedirectQueryComplete,
- base::Unretained(this)));
+ base::Unretained(this)),
+ &tracker_);
base::MessageLoop::current()->Run(); // Will be exited in *QueryComplete.
- return redirect_query_success_;
}
// Callback for QueryRedirects.
- void OnRedirectQueryComplete(HistoryService::Handle handle,
- GURL url,
- bool success,
- history::RedirectList* redirects) {
- redirect_query_success_ = success;
- if (redirect_query_success_)
- saved_redirects_.swap(*redirects);
- else
- saved_redirects_.clear();
+ void OnRedirectQueryComplete(const history::RedirectList* redirects) {
+ saved_redirects_.clear();
+ if (!redirects->empty()) {
+ saved_redirects_.insert(
+ saved_redirects_.end(), redirects->begin(), redirects->end());
+ }
base::MessageLoop::current()->Quit();
}
base::MessageLoopForUI message_loop_;
- // PageUsageData vector to test segments.
- ScopedVector<PageUsageData> page_usage_data_;
-
MostVisitedURLList most_visited_urls_;
// When non-NULL, this will be deleted on tear down and we will block until
// Set by the redirect callback when we get data. You should be sure to
// clear this before issuing a redirect request.
history::RedirectList saved_redirects_;
- bool redirect_query_success_;
// For history requests.
base::CancelableTaskTracker tracker_;
- CancelableRequestConsumer consumer_;
// For saving URL info after a call to QueryURL
bool query_url_success_;
}
TEST_F(HistoryTest, Typed) {
+ const ContextID context_id = reinterpret_cast<ContextID>(1);
+
ASSERT_TRUE(history_service_.get());
// Add the page once as typed.
const GURL test_url("http://www.google.com/");
history_service_->AddPage(
- test_url, base::Time::Now(), NULL, 0, GURL(),
+ test_url, base::Time::Now(), context_id, 0, GURL(),
history::RedirectList(), content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED, false);
EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
// Add the page again not typed.
history_service_->AddPage(
- test_url, base::Time::Now(), NULL, 0, GURL(),
+ test_url, base::Time::Now(), context_id, 0, GURL(),
history::RedirectList(), content::PAGE_TRANSITION_LINK,
history::SOURCE_BROWSED, false);
EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
// Add the page again as a generated URL.
history_service_->AddPage(
- test_url, base::Time::Now(), NULL, 0, GURL(),
+ test_url, base::Time::Now(), context_id, 0, GURL(),
history::RedirectList(), content::PAGE_TRANSITION_GENERATED,
history::SOURCE_BROWSED, false);
EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
// Add the page again as a reload.
history_service_->AddPage(
- test_url, base::Time::Now(), NULL, 0, GURL(),
+ test_url, base::Time::Now(), context_id, 0, GURL(),
history::RedirectList(), content::PAGE_TRANSITION_RELOAD,
history::SOURCE_BROWSED, false);
EXPECT_TRUE(QueryURL(history_service_.get(), test_url));
// destination page.
}
-// crbug.com/159387: This test fails when daylight savings time ends.
-TEST_F(HistoryTest, DISABLED_Segments) {
- ASSERT_TRUE(history_service_.get());
-
- static ContextID context_id = static_cast<ContextID>(this);
-
- // Add a URL.
- const GURL existing_url("http://www.google.com/");
- history_service_->AddPage(
- existing_url, base::Time::Now(), context_id, 0, GURL(),
- history::RedirectList(), content::PAGE_TRANSITION_TYPED,
- history::SOURCE_BROWSED, false);
-
- // Make sure a segment was created.
- history_service_->QuerySegmentUsageSince(
- &consumer_, Time::Now() - TimeDelta::FromDays(1), 10,
- base::Bind(&HistoryTest::OnSegmentUsageAvailable,
- base::Unretained(this)));
-
- // Wait for processing.
- base::MessageLoop::current()->Run();
-
- ASSERT_EQ(1U, page_usage_data_.size());
- EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url);
- EXPECT_DOUBLE_EQ(3.0, page_usage_data_[0]->GetScore());
-
- // Add a URL which doesn't create a segment.
- const GURL link_url("http://yahoo.com/");
- history_service_->AddPage(
- link_url, base::Time::Now(), context_id, 0, GURL(),
- history::RedirectList(), content::PAGE_TRANSITION_LINK,
- history::SOURCE_BROWSED, false);
-
- // Query again
- history_service_->QuerySegmentUsageSince(
- &consumer_, Time::Now() - TimeDelta::FromDays(1), 10,
- base::Bind(&HistoryTest::OnSegmentUsageAvailable,
- base::Unretained(this)));
-
- // Wait for processing.
- base::MessageLoop::current()->Run();
-
- // Make sure we still have one segment.
- ASSERT_EQ(1U, page_usage_data_.size());
- EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url);
-
- // Add a page linked from existing_url.
- history_service_->AddPage(
- GURL("http://www.google.com/foo"), base::Time::Now(),
- context_id, 3, existing_url, history::RedirectList(),
- content::PAGE_TRANSITION_LINK, history::SOURCE_BROWSED,
- false);
-
- // Query again
- history_service_->QuerySegmentUsageSince(
- &consumer_, Time::Now() - TimeDelta::FromDays(1), 10,
- base::Bind(&HistoryTest::OnSegmentUsageAvailable,
- base::Unretained(this)));
-
- // Wait for processing.
- base::MessageLoop::current()->Run();
-
- // Make sure we still have one segment.
- ASSERT_EQ(1U, page_usage_data_.size());
- EXPECT_TRUE(page_usage_data_[0]->GetURL() == existing_url);
-
- // However, the score should have increased.
- EXPECT_GT(page_usage_data_[0]->GetScore(), 5.0);
-}
-
TEST_F(HistoryTest, MostVisitedURLs) {
ASSERT_TRUE(history_service_.get());
const GURL url3("http://www.google.com/url3/");
const GURL url4("http://www.google.com/url4/");
- static ContextID context_id = static_cast<ContextID>(this);
+ const ContextID context_id = reinterpret_cast<ContextID>(1);
// Add two pages.
history_service_->AddPage(
history::RedirectList(), content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED, false);
history_service_->QueryMostVisitedURLs(
- 20, 90, &consumer_,
- base::Bind(
- &HistoryTest::OnMostVisitedURLsAvailable,
- base::Unretained(this)));
+ 20,
+ 90,
+ base::Bind(&HistoryTest::OnMostVisitedURLsAvailable,
+ base::Unretained(this)),
+ &tracker_);
base::MessageLoop::current()->Run();
EXPECT_EQ(2U, most_visited_urls_.size());
history::RedirectList(), content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED, false);
history_service_->QueryMostVisitedURLs(
- 20, 90, &consumer_,
- base::Bind(
- &HistoryTest::OnMostVisitedURLsAvailable,
- base::Unretained(this)));
+ 20,
+ 90,
+ base::Bind(&HistoryTest::OnMostVisitedURLsAvailable,
+ base::Unretained(this)),
+ &tracker_);
base::MessageLoop::current()->Run();
EXPECT_EQ(3U, most_visited_urls_.size());
history::RedirectList(), content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED, false);
history_service_->QueryMostVisitedURLs(
- 20, 90, &consumer_,
- base::Bind(
- &HistoryTest::OnMostVisitedURLsAvailable,
- base::Unretained(this)));
+ 20,
+ 90,
+ base::Bind(&HistoryTest::OnMostVisitedURLsAvailable,
+ base::Unretained(this)),
+ &tracker_);
base::MessageLoop::current()->Run();
EXPECT_EQ(3U, most_visited_urls_.size());
history::RedirectList(), content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED, false);
history_service_->QueryMostVisitedURLs(
- 20, 90, &consumer_,
- base::Bind(
- &HistoryTest::OnMostVisitedURLsAvailable,
- base::Unretained(this)));
+ 20,
+ 90,
+ base::Bind(&HistoryTest::OnMostVisitedURLsAvailable,
+ base::Unretained(this)),
+ &tracker_);
base::MessageLoop::current()->Run();
EXPECT_EQ(3U, most_visited_urls_.size());
redirects, content::PAGE_TRANSITION_TYPED,
history::SOURCE_BROWSED, false);
history_service_->QueryMostVisitedURLs(
- 20, 90, &consumer_,
- base::Bind(
- &HistoryTest::OnMostVisitedURLsAvailable,
- base::Unretained(this)));
+ 20,
+ 90,
+ base::Bind(&HistoryTest::OnMostVisitedURLsAvailable,
+ base::Unretained(this)),
+ &tracker_);
base::MessageLoop::current()->Run();
EXPECT_EQ(4U, most_visited_urls_.size());
public:
static const int kWantInvokeCount;
- HistoryDBTaskImpl() : invoke_count(0), done_invoked(false) {}
+ HistoryDBTaskImpl(int* invoke_count, bool* done_invoked)
+ : invoke_count_(invoke_count), done_invoked_(done_invoked) {}
virtual bool RunOnDBThread(HistoryBackend* backend,
HistoryDatabase* db) OVERRIDE {
- return (++invoke_count == kWantInvokeCount);
+ return (++*invoke_count_ == kWantInvokeCount);
}
virtual void DoneRunOnMainThread() OVERRIDE {
- done_invoked = true;
+ *done_invoked_ = true;
base::MessageLoop::current()->Quit();
}
- int invoke_count;
- bool done_invoked;
+ int* invoke_count_;
+ bool* done_invoked_;
private:
virtual ~HistoryDBTaskImpl() {}
TEST_F(HistoryTest, HistoryDBTask) {
ASSERT_TRUE(history_service_.get());
- CancelableRequestConsumerT<int, 0> request_consumer;
- scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
- history_service_->ScheduleDBTask(task.get(), &request_consumer);
+ base::CancelableTaskTracker task_tracker;
+ int invoke_count = 0;
+ bool done_invoked = false;
+ history_service_->ScheduleDBTask(
+ scoped_ptr<history::HistoryDBTask>(
+ new HistoryDBTaskImpl(&invoke_count, &done_invoked)),
+ &task_tracker);
// Run the message loop. When HistoryDBTaskImpl::DoneRunOnMainThread runs,
// it will stop the message loop. If the test hangs here, it means
// DoneRunOnMainThread isn't being invoked correctly.
CleanupHistoryService();
// WARNING: history has now been deleted.
history_service_.reset();
- ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, task->invoke_count);
- ASSERT_TRUE(task->done_invoked);
+ ASSERT_EQ(HistoryDBTaskImpl::kWantInvokeCount, invoke_count);
+ ASSERT_TRUE(done_invoked);
}
TEST_F(HistoryTest, HistoryDBTaskCanceled) {
ASSERT_TRUE(history_service_.get());
- CancelableRequestConsumerT<int, 0> request_consumer;
- scoped_refptr<HistoryDBTaskImpl> task(new HistoryDBTaskImpl());
- history_service_->ScheduleDBTask(task.get(), &request_consumer);
- request_consumer.CancelAllRequests();
+ base::CancelableTaskTracker task_tracker;
+ int invoke_count = 0;
+ bool done_invoked = false;
+ history_service_->ScheduleDBTask(
+ scoped_ptr<history::HistoryDBTask>(
+ new HistoryDBTaskImpl(&invoke_count, &done_invoked)),
+ &task_tracker);
+ task_tracker.TryCancelAll();
CleanupHistoryService();
// WARNING: history has now been deleted.
history_service_.reset();
- ASSERT_FALSE(task->done_invoked);
+ ASSERT_FALSE(done_invoked);
}
// Create a local delete directive and process it while sync is