1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/base_switches.h"
6 #include "base/command_line.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/history/history_service.h"
11 #include "chrome/browser/history/history_service_factory.h"
12 #include "chrome/browser/history/history_types.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/pref_names.h"
16 #include "extensions/common/switches.h"
17 #include "net/dns/mock_host_resolver.h"
20 namespace extensions {
22 class HistoryApiTest : public ExtensionApiTest {
24 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
25 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
27 host_resolver()->AddRule("www.a.com", "127.0.0.1");
28 host_resolver()->AddRule("www.b.com", "127.0.0.1");
31 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
32 ExtensionApiTest::SetUpCommandLine(command_line);
33 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
37 // Full text search indexing sometimes exceeds a timeout. (http://crbug/119505)
38 IN_PROC_BROWSER_TEST_F(HistoryApiTest, DISABLED_MiscSearch) {
39 ASSERT_TRUE(StartEmbeddedTestServer());
40 ASSERT_TRUE(RunExtensionSubtest("history", "misc_search.html")) << message_;
43 // Same could happen here without the FTS (http://crbug/119505)
44 IN_PROC_BROWSER_TEST_F(HistoryApiTest, DISABLED_TimedSearch) {
45 ASSERT_TRUE(StartEmbeddedTestServer());
46 ASSERT_TRUE(RunExtensionSubtest("history", "timed_search.html")) << message_;
50 // Flaky on Windows: crbug.com/88318
51 #define MAYBE_Delete DISABLED_Delete
53 #define MAYBE_Delete Delete
55 IN_PROC_BROWSER_TEST_F(HistoryApiTest, MAYBE_Delete) {
56 ASSERT_TRUE(StartEmbeddedTestServer());
57 ASSERT_TRUE(RunExtensionSubtest("history", "delete.html")) << message_;
60 IN_PROC_BROWSER_TEST_F(HistoryApiTest, DeleteProhibited) {
61 browser()->profile()->GetPrefs()->
62 SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
63 ASSERT_TRUE(StartEmbeddedTestServer());
64 ASSERT_TRUE(RunExtensionSubtest("history", "delete_prohibited.html")) <<
68 // See crbug.com/79074
69 IN_PROC_BROWSER_TEST_F(HistoryApiTest, DISABLED_GetVisits) {
70 ASSERT_TRUE(StartEmbeddedTestServer());
71 ASSERT_TRUE(RunExtensionSubtest("history", "get_visits.html")) << message_;
75 // Searching for a URL right after adding it fails on win XP.
76 // Fix this as part of crbug/76170.
77 #define MAYBE_SearchAfterAdd DISABLED_SearchAfterAdd
79 #define MAYBE_SearchAfterAdd SearchAfterAdd
82 IN_PROC_BROWSER_TEST_F(HistoryApiTest, MAYBE_SearchAfterAdd) {
83 ASSERT_TRUE(StartEmbeddedTestServer());
84 ASSERT_TRUE(RunExtensionSubtest("history", "search_after_add.html"))
88 IN_PROC_BROWSER_TEST_F(HistoryApiTest, MostVisited) {
89 ASSERT_TRUE(StartEmbeddedTestServer());
91 // Add entries to the history database that we can query for (using the
92 // extension history API for this doesn't work as it only adds URLs with
93 // LINK transition type).
94 HistoryService* hs = HistoryServiceFactory::GetForProfile(
96 Profile::EXPLICIT_ACCESS);
98 GURL google_url = GURL("http://www.google.com");
99 base::Time google_time;
100 ASSERT_TRUE(base::Time::FromString("Tue, 24 Apr 2012, 13:00:00",
102 hs->AddPage(google_url, google_time, NULL, 0, GURL(), history::RedirectList(),
103 content::PAGE_TRANSITION_TYPED, history::SOURCE_EXTENSION, false);
104 hs->SetPageTitle(google_url, UTF8ToUTF16("Google"));
106 GURL picasa_url = GURL("http://www.picasa.com");
107 base::Time picasa_time;
108 ASSERT_TRUE(base::Time::FromString("Tue, 24 Apr 2012, 14:00:00",
110 hs->AddPage(picasa_url, picasa_time, NULL, 0, GURL(), history::RedirectList(),
111 content::PAGE_TRANSITION_TYPED, history::SOURCE_EXTENSION, false);
112 hs->SetPageTitle(picasa_url, UTF8ToUTF16("Picasa"));
115 ASSERT_TRUE(RunExtensionSubtest("history", "most_visited.html"))
119 } // namespace extensions