diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-04 21:48:59 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-04 21:48:59 +0000 |
commit | cdf6cc8f2b5036894359123804d28b92b9cfa9ee (patch) | |
tree | be30780055ca1a5d2daf611ce8105368537d62ed | |
parent | 021063dc65429dc606676bdd160239e9d1401262 (diff) | |
download | chromium_src-cdf6cc8f2b5036894359123804d28b92b9cfa9ee.zip chromium_src-cdf6cc8f2b5036894359123804d28b92b9cfa9ee.tar.gz chromium_src-cdf6cc8f2b5036894359123804d28b92b9cfa9ee.tar.bz2 |
Port more tests from save_page_uitest.cc to save_page_browsertest.cc.
Also add more detailed checks for saved page contents.
TEST=Covered by browser_tests.
http://crbug.com/3791
Review URL: http://codereview.chromium.org/159858
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22413 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/download/save_page_browsertest.cc | 63 | ||||
-rw-r--r-- | chrome/browser/download/save_page_uitest.cc | 48 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.cc | 4 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents.h | 5 | ||||
-rw-r--r-- | chrome/test/data/save_page/b.saved1.htm | 12 | ||||
-rw-r--r-- | chrome/test/data/save_page/b.saved2.htm | 12 |
6 files changed, 87 insertions, 57 deletions
diff --git a/chrome/browser/download/save_page_browsertest.cc b/chrome/browser/download/save_page_browsertest.cc index 88859b3e..4c4df11 100644 --- a/chrome/browser/download/save_page_browsertest.cc +++ b/chrome/browser/download/save_page_browsertest.cc @@ -4,6 +4,7 @@ #include "base/file_path.h" #include "base/scoped_temp_dir.h" +#include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/net/url_request_mock_http_job.h" @@ -16,6 +17,13 @@ static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page"); +static const char* kAppendedExtension = +#if defined(OS_WIN) + ".htm"; +#else + ".html"; +#endif + namespace { class SavePageFinishedObserver : public NotificationObserver { @@ -73,8 +81,9 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { FilePath full_file_name = save_dir_.path().Append(file_name); FilePath dir = save_dir_.path().AppendASCII("a_files"); - current_tab->SavePage(full_file_name.ToWStringHack(), dir.ToWStringHack(), - SavePackage::SAVE_AS_ONLY_HTML); + ASSERT_TRUE(current_tab->SavePage(full_file_name.ToWStringHack(), + dir.ToWStringHack(), + SavePackage::SAVE_AS_ONLY_HTML)); SavePageFinishedObserver observer; @@ -98,8 +107,9 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { FilePath full_file_name = save_dir_.path().Append(file_name); FilePath dir = save_dir_.path().AppendASCII("b_files"); - current_tab->SavePage(full_file_name.ToWStringHack(), dir.ToWStringHack(), - SavePackage::SAVE_AS_COMPLETE_HTML); + ASSERT_TRUE(current_tab->SavePage(full_file_name.ToWStringHack(), + dir.ToWStringHack(), + SavePackage::SAVE_AS_COMPLETE_HTML)); SavePageFinishedObserver observer; @@ -107,7 +117,50 @@ IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); EXPECT_TRUE(file_util::PathExists(full_file_name)); EXPECT_TRUE(file_util::PathExists(dir)); - // TODO(phajdan.jr): Check saved html file's contents (http://crbug.com/3791). + EXPECT_TRUE(file_util::TextContentsEqual( + test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), + full_file_name)); + EXPECT_TRUE(file_util::ContentsEqual( + test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), + dir.AppendASCII("1.png"))); + EXPECT_TRUE(file_util::ContentsEqual( + test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), + dir.AppendASCII("1.css"))); +} + +IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, NoSave) { + ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); + ASSERT_TRUE(browser()->command_updater()->SupportsCommand(IDC_SAVE_PAGE)); + EXPECT_FALSE(browser()->command_updater()->IsCommandEnabled(IDC_SAVE_PAGE)); +} + +IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, FileNameFromPageTitle) { + FilePath file_name(FILE_PATH_LITERAL("b.htm")); + + GURL url = URLRequestMockHTTPJob::GetMockUrl( + FilePath(kTestDir).Append(file_name).ToWStringHack()); + ui_test_utils::NavigateToURL(browser(), url); + + FilePath full_file_name = save_dir_.path().AppendASCII( + std::string("Test page for saving page feature") + kAppendedExtension); + FilePath dir = save_dir_.path().AppendASCII( + "Test page for saving page feature_files"); + + TabContents* current_tab = browser()->GetSelectedTabContents(); + ASSERT_TRUE(current_tab); + + ASSERT_TRUE(current_tab->SavePage(full_file_name.ToWStringHack(), + dir.ToWStringHack(), + SavePackage::SAVE_AS_COMPLETE_HTML)); + SavePageFinishedObserver observer; + + EXPECT_EQ(url, observer.page_url()); + EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); + EXPECT_TRUE(file_util::PathExists(full_file_name)); + EXPECT_TRUE(file_util::PathExists(dir)); + EXPECT_TRUE(file_util::TextContentsEqual( + test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), + full_file_name)); EXPECT_TRUE(file_util::ContentsEqual( test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), dir.AppendASCII("1.png"))); diff --git a/chrome/browser/download/save_page_uitest.cc b/chrome/browser/download/save_page_uitest.cc index 31a0fd6..f78fdf4 100644 --- a/chrome/browser/download/save_page_uitest.cc +++ b/chrome/browser/download/save_page_uitest.cc @@ -84,54 +84,6 @@ class SavePageTest : public UITest { FilePath download_dir_; }; -TEST_F(SavePageTest, NoSave) { - std::string file_name = "c.htm"; - FilePath full_file_name = save_dir_.AppendASCII(file_name); - FilePath dir = save_dir_.AppendASCII("c_files"); - - scoped_refptr<TabProxy> tab(GetActiveTab()); - ASSERT_TRUE(tab.get()); - ASSERT_TRUE(tab->NavigateToURL(GURL("about:blank"))); - WaitUntilTabCount(1); - - EXPECT_FALSE(tab->SavePage(full_file_name.ToWStringHack(), - dir.ToWStringHack(), - SavePackage::SAVE_AS_ONLY_HTML)); - scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - EXPECT_FALSE(WaitForDownloadShelfVisible(browser.get())); -} - -TEST_F(SavePageTest, FilenameFromPageTitle) { - std::string file_name = "b.htm"; - - FilePath full_file_name = download_dir_.AppendASCII( - std::string("Test page for saving page feature") + kAppendedExtension); - FilePath dir = download_dir_.AppendASCII( - "Test page for saving page feature_files"); - - GURL url = URLRequestMockHTTPJob::GetMockUrl( - UTF8ToWide(std::string(kTestDir) + "/" + file_name)); - scoped_refptr<TabProxy> tab(GetActiveTab()); - ASSERT_TRUE(tab.get()); - ASSERT_TRUE(tab->NavigateToURL(url)); - WaitUntilTabCount(1); - - scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - automation()->SavePackageShouldPromptUser(false); - EXPECT_TRUE(browser->RunCommandAsync(IDC_SAVE_PAGE)); - EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); - automation()->SavePackageShouldPromptUser(true); - - CheckFile(dir.AppendASCII("1.png"), FilePath(FILE_PATH_LITERAL("1.png")), - true); - CheckFile(dir.AppendASCII("1.css"), FilePath(FILE_PATH_LITERAL("1.css")), - true); - CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), - false); - EXPECT_TRUE(file_util::DieFileDie(full_file_name, false)); - EXPECT_TRUE(file_util::DieFileDie(dir, true)); -} - // This tests that a webpage with the title "test.exe" is saved as // "test.exe.htm". // We probably don't care to handle this on Linux or Mac. diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 9b11bdc..5446bb5 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -1029,7 +1029,7 @@ void TabContents::OnSavePage() { // Used in automated testing to bypass prompting the user for file names. // Instead, the names and paths are hard coded rather than running them through // file name sanitation and extension / mime checking. -void TabContents::SavePage(const std::wstring& main_file, +bool TabContents::SavePage(const std::wstring& main_file, const std::wstring& dir_path, SavePackage::SavePackageType save_type) { // Stop the page from navigating. @@ -1038,7 +1038,7 @@ void TabContents::SavePage(const std::wstring& main_file, save_package_ = new SavePackage(this, save_type, FilePath::FromWStringHack(main_file), FilePath::FromWStringHack(dir_path)); - save_package_->Init(); + return save_package_->Init(); } void TabContents::PrintPreview() { diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 5d987a2..0536436 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -524,8 +524,9 @@ class TabContents : public PageNavigator, void OnSavePage(); // Save page with the main HTML file path, the directory for saving resources, - // and the save type: HTML only or complete web page. - void SavePage(const std::wstring& main_file, + // and the save type: HTML only or complete web page. Returns true if the + // saving process has been initiated successfully. + bool SavePage(const std::wstring& main_file, const std::wstring& dir_path, SavePackage::SavePackageType save_type); diff --git a/chrome/test/data/save_page/b.saved1.htm b/chrome/test/data/save_page/b.saved1.htm new file mode 100644 index 0000000..52d509e --- /dev/null +++ b/chrome/test/data/save_page/b.saved1.htm @@ -0,0 +1,12 @@ + +<!-- saved from url=(0032)http://mock.http/save_page/b.htm --> +<HTML><HEAD><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> + <TITLE> + Test page for saving page feature + </TITLE> + <LINK type="text/css" href="./b_files/1.css" rel="stylesheet"> + </HEAD><BODY> + The picture below is the back button.<BR> + <IMG src="./b_files/1.png"> + +</BODY></HTML>
\ No newline at end of file diff --git a/chrome/test/data/save_page/b.saved2.htm b/chrome/test/data/save_page/b.saved2.htm new file mode 100644 index 0000000..fa9ab03 --- /dev/null +++ b/chrome/test/data/save_page/b.saved2.htm @@ -0,0 +1,12 @@ + +<!-- saved from url=(0032)http://mock.http/save_page/b.htm --> +<HTML><HEAD><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> + <TITLE> + Test page for saving page feature + </TITLE> + <LINK type="text/css" href="./Test page for saving page feature_files/1.css" rel="stylesheet"> + </HEAD><BODY> + The picture below is the back button.<BR> + <IMG src="./Test page for saving page feature_files/1.png"> + +</BODY></HTML>
\ No newline at end of file |