Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 13 #include "chrome/browser/history/history_service_factory.h" | 13 #include "chrome/browser/history/history_service_factory.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 23 #include "components/history/core/browser/history_db_task.h" | 23 #include "components/history/core/browser/history_db_task.h" |
| 24 #include "components/history/core/browser/history_service.h" | 24 #include "components/history/core/browser/history_service.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
| 27 #include "content/public/test/test_browser_thread.h" | 27 #include "content/public/test/test_browser_thread.h" |
| 28 #include "net/test/spawned_test_server/spawned_test_server.h" | |
| 28 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 29 | 30 |
| 30 using content::BrowserThread; | 31 using content::BrowserThread; |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 35 const base::FilePath::CharType kDocRoot[] = | |
|
erikwright (departed)
2015/03/30 14:22:30
include base/files/file_path.h
| |
| 36 FILE_PATH_LITERAL("chrome/test/data"); | |
| 37 | |
| 34 // Note: WaitableEvent is not used for synchronization between the main thread | 38 // Note: WaitableEvent is not used for synchronization between the main thread |
| 35 // and history backend thread because the history subsystem posts tasks back | 39 // and history backend thread because the history subsystem posts tasks back |
| 36 // to the main thread. Had we tried to Signal an event in such a task | 40 // to the main thread. Had we tried to Signal an event in such a task |
| 37 // and Wait for it on the main thread, the task would not run at all because | 41 // and Wait for it on the main thread, the task would not run at all because |
| 38 // the main thread would be blocked on the Wait call, resulting in a deadlock. | 42 // the main thread would be blocked on the Wait call, resulting in a deadlock. |
| 39 | 43 |
| 40 // A task to be scheduled on the history backend thread. | 44 // A task to be scheduled on the history backend thread. |
| 41 // Notifies the main thread after all history backend thread tasks have run. | 45 // Notifies the main thread after all history backend thread tasks have run. |
| 42 class WaitForHistoryTask : public history::HistoryDBTask { | 46 class WaitForHistoryTask : public history::HistoryDBTask { |
| 43 public: | 47 public: |
| 44 WaitForHistoryTask() {} | 48 WaitForHistoryTask() {} |
| 45 | 49 |
| 46 bool RunOnDBThread(history::HistoryBackend* backend, | 50 bool RunOnDBThread(history::HistoryBackend* backend, |
| 47 history::HistoryDatabase* db) override { | 51 history::HistoryDatabase* db) override { |
| 48 return true; | 52 return true; |
| 49 } | 53 } |
| 50 | 54 |
| 51 void DoneRunOnMainThread() override { base::MessageLoop::current()->Quit(); } | 55 void DoneRunOnMainThread() override { base::MessageLoop::current()->Quit(); } |
| 52 | 56 |
| 53 private: | 57 private: |
| 54 ~WaitForHistoryTask() override {} | 58 ~WaitForHistoryTask() override {} |
| 55 | 59 |
| 56 DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask); | 60 DISALLOW_COPY_AND_ASSIGN(WaitForHistoryTask); |
| 57 }; | 61 }; |
| 58 | 62 |
| 59 } // namespace | 63 } // namespace |
| 60 | 64 |
| 61 class HistoryBrowserTest : public InProcessBrowserTest { | 65 class HistoryBrowserTest : public InProcessBrowserTest { |
| 62 protected: | 66 protected: |
| 63 void SetUpCommandLine(base::CommandLine* command_line) override { | 67 HistoryBrowserTest() |
| 64 command_line->AppendSwitch(switches::kEnableFileCookies); | 68 : test_server_(net::SpawnedTestServer::TYPE_HTTP, |
| 65 } | 69 net::SpawnedTestServer::kLocalhost, |
| 70 base::FilePath(kDocRoot)) {} | |
| 71 | |
| 72 void SetUp() override { ASSERT_TRUE(test_server_.Start()); } | |
| 66 | 73 |
| 67 PrefService* GetPrefs() { | 74 PrefService* GetPrefs() { |
| 68 return GetProfile()->GetPrefs(); | 75 return GetProfile()->GetPrefs(); |
| 69 } | 76 } |
| 70 | 77 |
| 71 Profile* GetProfile() { | 78 Profile* GetProfile() { |
| 72 return browser()->profile(); | 79 return browser()->profile(); |
| 73 } | 80 } |
| 74 | 81 |
| 75 std::vector<GURL> GetHistoryContents() { | 82 std::vector<GURL> GetHistoryContents() { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 100 void LoadAndWaitForURL(const GURL& url) { | 107 void LoadAndWaitForURL(const GURL& url) { |
| 101 base::string16 expected_title(base::ASCIIToUTF16("OK")); | 108 base::string16 expected_title(base::ASCIIToUTF16("OK")); |
| 102 content::TitleWatcher title_watcher( | 109 content::TitleWatcher title_watcher( |
| 103 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); | 110 browser()->tab_strip_model()->GetActiveWebContents(), expected_title); |
| 104 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); | 111 title_watcher.AlsoWaitForTitle(base::ASCIIToUTF16("FAIL")); |
| 105 ui_test_utils::NavigateToURL(browser(), url); | 112 ui_test_utils::NavigateToURL(browser(), url); |
| 106 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 113 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 107 } | 114 } |
| 108 | 115 |
| 109 void LoadAndWaitForFile(const char* filename) { | 116 void LoadAndWaitForFile(const char* filename) { |
| 110 GURL url = ui_test_utils::GetTestUrl( | 117 GURL url = test_server_.GetURL(std::string("History") + filename); |
| 111 base::FilePath().AppendASCII("History"), | |
| 112 base::FilePath().AppendASCII(filename)); | |
| 113 LoadAndWaitForURL(url); | 118 LoadAndWaitForURL(url); |
| 114 } | 119 } |
| 120 | |
| 121 net::SpawnedTestServer test_server_; | |
| 115 }; | 122 }; |
| 116 | 123 |
| 117 // Test that the browser history is saved (default setting). | 124 // Test that the browser history is saved (default setting). |
| 118 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryEnabled) { | 125 IN_PROC_BROWSER_TEST_F(HistoryBrowserTest, SavingHistoryEnabled) { |
| 119 EXPECT_FALSE(GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled)); | 126 EXPECT_FALSE(GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled)); |
| 120 | 127 |
| 121 EXPECT_TRUE(HistoryServiceFactory::GetForProfile( | 128 EXPECT_TRUE(HistoryServiceFactory::GetForProfile( |
| 122 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS)); | 129 GetProfile(), ServiceAccessType::EXPLICIT_ACCESS)); |
| 123 EXPECT_TRUE(HistoryServiceFactory::GetForProfile( | 130 EXPECT_TRUE(HistoryServiceFactory::GetForProfile( |
| 124 GetProfile(), ServiceAccessType::IMPLICIT_ACCESS)); | 131 GetProfile(), ServiceAccessType::IMPLICIT_ACCESS)); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 | 506 |
| 500 content::WebContents* active_web_contents = | 507 content::WebContents* active_web_contents = |
| 501 browser()->tab_strip_model()->GetActiveWebContents(); | 508 browser()->tab_strip_model()->GetActiveWebContents(); |
| 502 ASSERT_EQ(web_contents, active_web_contents); | 509 ASSERT_EQ(web_contents, active_web_contents); |
| 503 ASSERT_EQ(history_url, active_web_contents->GetURL()); | 510 ASSERT_EQ(history_url, active_web_contents->GetURL()); |
| 504 | 511 |
| 505 content::WebContents* second_tab = | 512 content::WebContents* second_tab = |
| 506 browser()->tab_strip_model()->GetWebContentsAt(1); | 513 browser()->tab_strip_model()->GetWebContentsAt(1); |
| 507 ASSERT_NE(history_url, second_tab->GetURL()); | 514 ASSERT_NE(history_url, second_tab->GetURL()); |
| 508 } | 515 } |
| OLD | NEW |