summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/webui/history_ui_browsertest.cc
blob: e4ff21eed9f86d62895bd8f0ec9ec85cbe072eb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/test/data/webui/history_ui_browsertest.h"

#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/history/core/browser/history_service.h"
#include "components/prefs/pref_service.h"

HistoryUIBrowserTest::HistoryUIBrowserTest()
    : history_(NULL),
      baseline_time_(base::Time::Now().LocalMidnight()),
      nav_entry_id_(0) {
}

HistoryUIBrowserTest::~HistoryUIBrowserTest() {
}

void HistoryUIBrowserTest::SetUpOnMainThread() {
  WebUIBrowserTest::SetUpOnMainThread();

  history_ = HistoryServiceFactory::GetForProfile(
      browser()->profile(), ServiceAccessType::EXPLICIT_ACCESS);
  ui_test_utils::WaitForHistoryToLoad(history_);
}

void HistoryUIBrowserTest::AddPageToHistory(
    int hour_offset, const std::string& url, const std::string& title) {
  // We need the ID scope and page ID so that the visit tracker can find it.
  const history::ContextID id_scope = reinterpret_cast<history::ContextID>(1);

  base::Time time = baseline_time_ + base::TimeDelta::FromHours(hour_offset);
  GURL gurl = GURL(url);
  history_->AddPage(gurl, time, id_scope, nav_entry_id_++, GURL(),
                    history::RedirectList(), ui::PAGE_TRANSITION_LINK,
                    history::SOURCE_BROWSED, false);
  history_->SetPageTitle(gurl, base::UTF8ToUTF16(title));
}

void HistoryUIBrowserTest::SetDeleteAllowed(bool allowed) {
  browser()->profile()->GetPrefs()->
      SetBoolean(prefs::kAllowDeletingBrowserHistory, allowed);
}

void HistoryUIBrowserTest::ClearAcceptLanguages() {
  browser()->profile()->GetPrefs()->
      SetString(prefs::kAcceptLanguages, "");
}