Home | History | Annotate | Download | only in history
      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.
      4 
      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"
     18 #include "url/gurl.h"
     19 
     20 namespace extensions {
     21 
     22 class HistoryApiTest : public ExtensionApiTest {
     23  public:
     24   virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
     25     ExtensionApiTest::SetUpInProcessBrowserTestFixture();
     26 
     27     host_resolver()->AddRule("www.a.com", "127.0.0.1");
     28     host_resolver()->AddRule("www.b.com", "127.0.0.1");
     29   }
     30 
     31   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
     32     ExtensionApiTest::SetUpCommandLine(command_line);
     33     command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
     34   }
     35 };
     36 
     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_;
     41 }
     42 
     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_;
     47 }
     48 
     49 #if defined(OS_WIN)
     50 // Flaky on Windows: crbug.com/88318
     51 #define MAYBE_Delete DISABLED_Delete
     52 #else
     53 #define MAYBE_Delete Delete
     54 #endif
     55 IN_PROC_BROWSER_TEST_F(HistoryApiTest, MAYBE_Delete) {
     56   ASSERT_TRUE(StartEmbeddedTestServer());
     57   ASSERT_TRUE(RunExtensionSubtest("history", "delete.html")) << message_;
     58 }
     59 
     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")) <<
     65       message_;
     66 }
     67 
     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_;
     72 }
     73 
     74 #if defined(OS_WIN)
     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
     78 #else
     79 #define MAYBE_SearchAfterAdd SearchAfterAdd
     80 #endif
     81 
     82 IN_PROC_BROWSER_TEST_F(HistoryApiTest, MAYBE_SearchAfterAdd) {
     83   ASSERT_TRUE(StartEmbeddedTestServer());
     84   ASSERT_TRUE(RunExtensionSubtest("history", "search_after_add.html"))
     85       << message_;
     86 }
     87 
     88 IN_PROC_BROWSER_TEST_F(HistoryApiTest, MostVisited) {
     89   ASSERT_TRUE(StartEmbeddedTestServer());
     90 
     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(
     95       browser()->profile(),
     96       Profile::EXPLICIT_ACCESS);
     97 
     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",
    101                                      &google_time));
    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"));
    105 
    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",
    109                                      &picasa_time));
    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"));
    113 
    114   // Run the test.
    115   ASSERT_TRUE(RunExtensionSubtest("history", "most_visited.html"))
    116     << message_;
    117 }
    118 
    119 }  // namespace extensions
    120