OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/platform_thread.h" | 7 #include "base/platform_thread.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/test_file_util.h" | 9 #include "base/test_file_util.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 virtual void TearDown() { | 78 virtual void TearDown() { |
79 UITest::TearDown(); | 79 UITest::TearDown(); |
80 file_util::DieFileDie(save_dir_, true); | 80 file_util::DieFileDie(save_dir_, true); |
81 } | 81 } |
82 | 82 |
83 FilePath save_dir_; | 83 FilePath save_dir_; |
84 FilePath download_dir_; | 84 FilePath download_dir_; |
85 }; | 85 }; |
86 | 86 |
87 TEST_F(SavePageTest, NoSave) { | |
88 std::string file_name = "c.htm"; | |
89 FilePath full_file_name = save_dir_.AppendASCII(file_name); | |
90 FilePath dir = save_dir_.AppendASCII("c_files"); | |
91 | |
92 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
93 ASSERT_TRUE(tab.get()); | |
94 ASSERT_TRUE(tab->NavigateToURL(GURL("about:blank"))); | |
95 WaitUntilTabCount(1); | |
96 | |
97 EXPECT_FALSE(tab->SavePage(full_file_name.ToWStringHack(), | |
98 dir.ToWStringHack(), | |
99 SavePackage::SAVE_AS_ONLY_HTML)); | |
100 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
101 EXPECT_FALSE(WaitForDownloadShelfVisible(browser.get())); | |
102 } | |
103 | |
104 TEST_F(SavePageTest, FilenameFromPageTitle) { | |
105 std::string file_name = "b.htm"; | |
106 | |
107 FilePath full_file_name = download_dir_.AppendASCII( | |
108 std::string("Test page for saving page feature") + kAppendedExtension); | |
109 FilePath dir = download_dir_.AppendASCII( | |
110 "Test page for saving page feature_files"); | |
111 | |
112 GURL url = URLRequestMockHTTPJob::GetMockUrl( | |
113 UTF8ToWide(std::string(kTestDir) + "/" + file_name)); | |
114 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
115 ASSERT_TRUE(tab.get()); | |
116 ASSERT_TRUE(tab->NavigateToURL(url)); | |
117 WaitUntilTabCount(1); | |
118 | |
119 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
120 automation()->SavePackageShouldPromptUser(false); | |
121 EXPECT_TRUE(browser->RunCommandAsync(IDC_SAVE_PAGE)); | |
122 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); | |
123 automation()->SavePackageShouldPromptUser(true); | |
124 | |
125 CheckFile(dir.AppendASCII("1.png"), FilePath(FILE_PATH_LITERAL("1.png")), | |
126 true); | |
127 CheckFile(dir.AppendASCII("1.css"), FilePath(FILE_PATH_LITERAL("1.css")), | |
128 true); | |
129 CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), | |
130 false); | |
131 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false)); | |
132 EXPECT_TRUE(file_util::DieFileDie(dir, true)); | |
133 } | |
134 | |
135 // This tests that a webpage with the title "test.exe" is saved as | 87 // This tests that a webpage with the title "test.exe" is saved as |
136 // "test.exe.htm". | 88 // "test.exe.htm". |
137 // We probably don't care to handle this on Linux or Mac. | 89 // We probably don't care to handle this on Linux or Mac. |
138 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
139 TEST_F(SavePageTest, CleanFilenameFromPageTitle) { | 91 TEST_F(SavePageTest, CleanFilenameFromPageTitle) { |
140 std::string file_name = "c.htm"; | 92 std::string file_name = "c.htm"; |
141 FilePath full_file_name = | 93 FilePath full_file_name = |
142 download_dir_.AppendASCII(std::string("test.exe") + kAppendedExtension); | 94 download_dir_.AppendASCII(std::string("test.exe") + kAppendedExtension); |
143 FilePath dir = download_dir_.AppendASCII("test.exe_files"); | 95 FilePath dir = download_dir_.AppendASCII("test.exe_files"); |
144 | 96 |
145 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 97 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
146 UTF8ToWide(std::string(kTestDir) + "/" + file_name)); | 98 UTF8ToWide(std::string(kTestDir) + "/" + file_name)); |
147 scoped_refptr<TabProxy> tab(GetActiveTab()); | 99 scoped_refptr<TabProxy> tab(GetActiveTab()); |
148 ASSERT_TRUE(tab.get()); | 100 ASSERT_TRUE(tab.get()); |
149 ASSERT_TRUE(tab->NavigateToURL(url)); | 101 ASSERT_TRUE(tab->NavigateToURL(url)); |
150 WaitUntilTabCount(1); | 102 WaitUntilTabCount(1); |
151 | 103 |
152 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 104 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
153 automation()->SavePackageShouldPromptUser(false); | 105 automation()->SavePackageShouldPromptUser(false); |
154 EXPECT_TRUE(browser->RunCommandAsync(IDC_SAVE_PAGE)); | 106 EXPECT_TRUE(browser->RunCommandAsync(IDC_SAVE_PAGE)); |
155 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); | 107 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); |
156 automation()->SavePackageShouldPromptUser(true); | 108 automation()->SavePackageShouldPromptUser(true); |
157 | 109 |
158 CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), | 110 CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), |
159 false); | 111 false); |
160 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false)); | 112 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false)); |
161 EXPECT_TRUE(file_util::DieFileDie(dir, true)); | 113 EXPECT_TRUE(file_util::DieFileDie(dir, true)); |
162 } | 114 } |
163 #endif | 115 #endif |
OLD | NEW |