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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "chrome/browser/download/download_file_icon_extractor.h" | 13 #include "chrome/browser/download/download_file_icon_extractor.h" |
14 #include "chrome/browser/download/download_service.h" | 14 #include "chrome/browser/download/download_service.h" |
15 #include "chrome/browser/download/download_service_factory.h" | 15 #include "chrome/browser/download/download_service_factory.h" |
16 #include "chrome/browser/download/download_test_file_chooser_observer.h" | 16 #include "chrome/browser/download/download_test_file_chooser_observer.h" |
17 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 17 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
18 #include "chrome/browser/extensions/event_names.h" | 18 #include "chrome/browser/extensions/event_names.h" |
19 #include "chrome/browser/extensions/extension_apitest.h" | 19 #include "chrome/browser/extensions/extension_apitest.h" |
20 #include "chrome/browser/extensions/extension_function_test_utils.h" | 20 #include "chrome/browser/extensions/extension_function_test_utils.h" |
21 #include "chrome/browser/extensions/extension_service.h" | |
21 #include "chrome/browser/history/download_row.h" | 22 #include "chrome/browser/history/download_row.h" |
22 #include "chrome/browser/net/url_request_mock_util.h" | 23 #include "chrome/browser/net/url_request_mock_util.h" |
23 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
25 #include "chrome/browser/ui/browser.h" | 26 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_tabstrip.h" | 27 #include "chrome/browser/ui/browser_tabstrip.h" |
27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
29 #include "chrome/test/base/in_process_browser_test.h" | 30 #include "chrome/test/base/in_process_browser_test.h" |
30 #include "chrome/test/base/ui_test_utils.h" | 31 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 args_(base::JSONReader::Read(json_args)), | 97 args_(base::JSONReader::Read(json_args)), |
97 caught_(caught) { | 98 caught_(caught) { |
98 } | 99 } |
99 | 100 |
100 const base::Time& caught() { return caught_; } | 101 const base::Time& caught() { return caught_; } |
101 | 102 |
102 bool Equals(const Event& other) { | 103 bool Equals(const Event& other) { |
103 if ((profile_ != other.profile_) || | 104 if ((profile_ != other.profile_) || |
104 (event_name_ != other.event_name_)) | 105 (event_name_ != other.event_name_)) |
105 return false; | 106 return false; |
106 if ((event_name_ == events::kOnDownloadCreated || | 107 if (((event_name_ == events::kOnDownloadCreated) || |
107 event_name_ == events::kOnDownloadChanged) && | 108 (event_name_.substr( |
109 0, strlen(events::kOnDownloadDeterminingFilename)) == | |
110 events::kOnDownloadDeterminingFilename) || | |
111 (event_name_ == events::kOnDownloadChanged)) && | |
108 args_.get() && | 112 args_.get() && |
109 other.args_.get()) { | 113 other.args_.get()) { |
110 base::ListValue* left_list = NULL; | 114 base::ListValue* left_list = NULL; |
111 base::DictionaryValue* left_dict = NULL; | 115 base::DictionaryValue* left_dict = NULL; |
112 base::ListValue* right_list = NULL; | 116 base::ListValue* right_list = NULL; |
113 base::DictionaryValue* right_dict = NULL; | 117 base::DictionaryValue* right_dict = NULL; |
114 if (!args_->GetAsList(&left_list) || | 118 if (!args_->GetAsList(&left_list) || |
115 !other.args_->GetAsList(&right_list) || | 119 !other.args_->GetAsList(&right_list) || |
116 !left_list->GetDictionary(0, &left_dict) || | 120 !left_list->GetDictionary(0, &left_dict) || |
117 !right_list->GetDictionary(0, &right_dict)) | 121 !right_list->GetDictionary(0, &right_dict)) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 const content::NotificationDetails& details) { | 166 const content::NotificationDetails& details) { |
163 switch (type) { | 167 switch (type) { |
164 case chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT: | 168 case chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT: |
165 { | 169 { |
166 DownloadsNotificationSource* dns = | 170 DownloadsNotificationSource* dns = |
167 content::Source<DownloadsNotificationSource>(source).ptr(); | 171 content::Source<DownloadsNotificationSource>(source).ptr(); |
168 Event* new_event = new Event( | 172 Event* new_event = new Event( |
169 dns->profile, | 173 dns->profile, |
170 dns->event_name, | 174 dns->event_name, |
171 *content::Details<std::string>(details).ptr(), base::Time::Now()); | 175 *content::Details<std::string>(details).ptr(), base::Time::Now()); |
176 LOG(INFO) << "occam caught " << new_event->Debug(); | |
172 events_.push_back(new_event); | 177 events_.push_back(new_event); |
173 if (waiting_ && | 178 if (waiting_ && |
174 waiting_for_.get() && | 179 waiting_for_.get() && |
175 waiting_for_->Equals(*new_event)) { | 180 waiting_for_->Equals(*new_event)) { |
176 waiting_ = false; | 181 waiting_ = false; |
177 MessageLoopForUI::current()->Quit(); | 182 MessageLoopForUI::current()->Quit(); |
178 } | 183 } |
179 break; | 184 break; |
180 } | 185 } |
181 default: | 186 default: |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 " \"state\": {" | 310 " \"state\": {" |
306 " \"previous\": \"in_progress\"," | 311 " \"previous\": \"in_progress\"," |
307 " \"current\": \"interrupted\"}}]", | 312 " \"current\": \"interrupted\"}}]", |
308 item->GetId(), | 313 item->GetId(), |
309 expected_error)); | 314 expected_error)); |
310 } | 315 } |
311 | 316 |
312 std::string GetExtensionURL() { | 317 std::string GetExtensionURL() { |
313 return extension_->url().spec(); | 318 return extension_->url().spec(); |
314 } | 319 } |
320 std::string GetExtensionId() { | |
321 return extension_->id(); | |
322 } | |
323 void DisableExtension() { | |
324 browser()->profile()->GetExtensionService()->DisableExtension( | |
325 GetExtensionId(), extensions::Extension::DISABLE_USER_ACTION); | |
326 } | |
327 void EnableExtension() { | |
328 browser()->profile()->GetExtensionService()->EnableExtension( | |
329 GetExtensionId()); | |
330 } | |
315 | 331 |
316 std::string GetFilename(const char* path) { | 332 std::string GetFilename(const char* path) { |
317 std::string result = | 333 std::string result = |
318 downloads_directory_.path().AppendASCII(path).AsUTF8Unsafe(); | 334 downloads_directory_.path().AppendASCII(path).AsUTF8Unsafe(); |
319 #if defined(OS_WIN) | 335 #if defined(OS_WIN) |
320 for (std::string::size_type next = result.find("\\"); | 336 for (std::string::size_type next = result.find("\\"); |
321 next != std::string::npos; | 337 next != std::string::npos; |
322 next = result.find("\\", next)) { | 338 next = result.find("\\", next)) { |
323 result.replace(next, 1, "\\\\"); | 339 result.replace(next, 1, "\\\\"); |
324 next += 2; | 340 next += 2; |
(...skipping 1377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1702 " \"current\": \"complete\"}}]", | 1718 " \"current\": \"complete\"}}]", |
1703 result_id, | 1719 result_id, |
1704 GetFilename("slow.txt.crdownload").c_str(), | 1720 GetFilename("slow.txt.crdownload").c_str(), |
1705 GetFilename("slow.txt").c_str()))); | 1721 GetFilename("slow.txt").c_str()))); |
1706 } | 1722 } |
1707 | 1723 |
1708 // Valid data URLs are valid URLs. | 1724 // Valid data URLs are valid URLs. |
1709 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1725 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1710 DownloadExtensionTest_Download_DataURL) { | 1726 DownloadExtensionTest_Download_DataURL) { |
1711 LoadExtension("downloads_split"); | 1727 LoadExtension("downloads_split"); |
1712 CHECK(StartTestServer()); | |
1713 std::string download_url = "data:text/plain,hello"; | 1728 std::string download_url = "data:text/plain,hello"; |
1714 GoOnTheRecord(); | 1729 GoOnTheRecord(); |
1715 | 1730 |
1716 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1731 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
1717 new DownloadsDownloadFunction(), base::StringPrintf( | 1732 new DownloadsDownloadFunction(), base::StringPrintf( |
1718 "[{\"url\": \"%s\"," | 1733 "[{\"url\": \"%s\"," |
1719 " \"filename\": \"data.txt\"}]", download_url.c_str()))); | 1734 " \"filename\": \"data.txt\"}]", download_url.c_str()))); |
1720 ASSERT_TRUE(result.get()); | 1735 ASSERT_TRUE(result.get()); |
1721 int result_id = -1; | 1736 int result_id = -1; |
1722 ASSERT_TRUE(result->GetAsInteger(&result_id)); | 1737 ASSERT_TRUE(result->GetAsInteger(&result_id)); |
(...skipping 19 matching lines...) Expand all Loading... | |
1742 " \"current\": \"complete\"}}]", | 1757 " \"current\": \"complete\"}}]", |
1743 result_id, | 1758 result_id, |
1744 GetFilename("data.txt.crdownload").c_str(), | 1759 GetFilename("data.txt.crdownload").c_str(), |
1745 GetFilename("data.txt").c_str()))); | 1760 GetFilename("data.txt").c_str()))); |
1746 } | 1761 } |
1747 | 1762 |
1748 // Valid file URLs are valid URLs. | 1763 // Valid file URLs are valid URLs. |
1749 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | 1764 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, |
1750 DownloadExtensionTest_Download_File) { | 1765 DownloadExtensionTest_Download_File) { |
1751 GoOnTheRecord(); | 1766 GoOnTheRecord(); |
1752 CHECK(StartTestServer()); | |
1753 LoadExtension("downloads_split"); | 1767 LoadExtension("downloads_split"); |
1754 std::string download_url = "file:///"; | 1768 std::string download_url = "file:///"; |
1755 #if defined(OS_WIN) | 1769 #if defined(OS_WIN) |
1756 download_url += "C:/"; | 1770 download_url += "C:/"; |
1757 #endif | 1771 #endif |
1758 | 1772 |
1759 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 1773 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
1760 new DownloadsDownloadFunction(), base::StringPrintf( | 1774 new DownloadsDownloadFunction(), base::StringPrintf( |
1761 "[{\"url\": \"%s\"," | 1775 "[{\"url\": \"%s\"," |
1762 " \"filename\": \"file.txt\"}]", download_url.c_str()))); | 1776 " \"filename\": \"file.txt\"}]", download_url.c_str()))); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2149 " \"state\": {" | 2163 " \"state\": {" |
2150 " \"previous\": \"in_progress\"," | 2164 " \"previous\": \"in_progress\"," |
2151 " \"current\": \"complete\"}}]", | 2165 " \"current\": \"complete\"}}]", |
2152 result_id, | 2166 result_id, |
2153 GetFilename("on_record.txt.crdownload").c_str(), | 2167 GetFilename("on_record.txt.crdownload").c_str(), |
2154 GetFilename("on_record.txt").c_str()))); | 2168 GetFilename("on_record.txt").c_str()))); |
2155 std::string disk_data; | 2169 std::string disk_data; |
2156 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); | 2170 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); |
2157 EXPECT_STREQ(kPayloadData, disk_data.c_str()); | 2171 EXPECT_STREQ(kPayloadData, disk_data.c_str()); |
2158 } | 2172 } |
2173 | |
2174 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, | |
Randy Smith (Not in Mondays)
2013/01/22 19:43:08
Could you put in some line breaks in the following
benjhayden
2013/01/23 21:30:10
Done.
| |
2175 DownloadExtensionTest_OnDeterminingFilename_NoChange) { | |
2176 GoOnTheRecord(); | |
2177 LoadExtension("downloads_split"); | |
2178 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2179 browser()->profile(), | |
2180 GetExtensionId(), | |
2181 "42")); | |
2182 CHECK(StartTestServer()); | |
2183 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
2184 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
2185 new DownloadsDownloadFunction(), base::StringPrintf( | |
2186 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2187 ASSERT_TRUE(result.get()); | |
2188 int result_id = -1; | |
2189 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2190 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | |
2191 ASSERT_TRUE(item); | |
2192 ScopedCancellingItem canceller(item); | |
2193 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2194 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2195 base::StringPrintf("[{\"danger\": \"safe\"," | |
2196 " \"incognito\": false," | |
2197 " \"id\": %d," | |
2198 " \"mime\": \"text/plain\"," | |
2199 " \"paused\": false," | |
2200 " \"url\": \"%s\"}]", | |
2201 result_id, | |
2202 download_url.c_str()))); | |
2203 ASSERT_TRUE(WaitFor( | |
2204 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2205 base::StringPrintf("[{\"id\": %d," | |
2206 " \"filename\":\"slow.txt\"}]", | |
2207 result_id))); | |
2208 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2209 ASSERT_TRUE(item->IsInProgress()); | |
2210 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2211 browser()->profile(), | |
2212 false, | |
2213 GetExtensionId(), | |
2214 "42", | |
2215 result_id, | |
2216 FilePath(), | |
2217 false)); | |
2218 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2219 base::StringPrintf("[{\"id\": %d," | |
2220 " \"filename\": {" | |
2221 " \"previous\": \"%s\"," | |
2222 " \"current\": \"%s\"}," | |
2223 " \"state\": {" | |
2224 " \"previous\": \"in_progress\"," | |
2225 " \"current\": \"complete\"}}]", | |
2226 result_id, | |
2227 GetFilename("slow.txt.crdownload").c_str(), | |
2228 GetFilename("slow.txt").c_str()))); | |
2229 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2230 base::StringPrintf("[{\"id\": %d," | |
2231 " \"state\": {" | |
2232 " \"previous\": \"in_progress\"," | |
2233 " \"current\": \"complete\"}}]", | |
2234 result_id))); | |
2235 } | |
2236 | |
2237 IN_PROC_BROWSER_TEST_F( | |
2238 DownloadExtensionTest, | |
2239 DownloadExtensionTest_OnDeterminingFilename_DangerousOverride) { | |
2240 GoOnTheRecord(); | |
2241 LoadExtension("downloads_split"); | |
2242 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2243 browser()->profile(), | |
2244 GetExtensionId(), | |
2245 "42")); | |
2246 CHECK(StartTestServer()); | |
2247 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
2248 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
2249 new DownloadsDownloadFunction(), base::StringPrintf( | |
2250 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2251 ASSERT_TRUE(result.get()); | |
2252 int result_id = -1; | |
2253 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2254 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | |
2255 ASSERT_TRUE(item); | |
2256 ScopedCancellingItem canceller(item); | |
2257 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2258 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2259 base::StringPrintf("[{\"danger\": \"safe\"," | |
2260 " \"incognito\": false," | |
2261 " \"id\": %d," | |
2262 " \"mime\": \"text/plain\"," | |
2263 " \"paused\": false," | |
2264 " \"url\": \"%s\"}]", | |
2265 result_id, | |
2266 download_url.c_str()))); | |
2267 ASSERT_TRUE(WaitFor( | |
2268 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2269 base::StringPrintf("[{\"id\": %d," | |
2270 " \"filename\":\"slow.txt\"}]", | |
2271 result_id))); | |
2272 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2273 ASSERT_TRUE(item->IsInProgress()); | |
2274 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2275 browser()->profile(), | |
2276 false, | |
2277 GetExtensionId(), | |
2278 "42", | |
2279 result_id, | |
2280 FilePath(FILE_PATH_LITERAL("overridden.swf")), | |
2281 false)); | |
2282 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2283 base::StringPrintf("[{\"id\": %d," | |
2284 " \"danger\": {" | |
2285 " \"previous\":\"safe\"," | |
2286 " \"current\":\"file\"}," | |
2287 " \"dangerAccepted\": {" | |
2288 " \"current\":false}}]", | |
2289 result_id))); | |
2290 item->DangerousDownloadValidated(); | |
2291 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2292 base::StringPrintf("[{\"id\": %d," | |
2293 " \"dangerAccepted\": {" | |
2294 " \"previous\":false," | |
2295 " \"current\":true}}]", | |
2296 result_id))); | |
2297 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2298 base::StringPrintf("[{\"id\": %d," | |
2299 " \"filename\": {" | |
2300 " \"previous\": \"%s\"," | |
2301 " \"current\": \"%s\"}," | |
2302 " \"state\": {" | |
2303 " \"previous\": \"in_progress\"," | |
2304 " \"current\": \"complete\"}}]", | |
2305 result_id, | |
2306 GetFilename("overridden.swf.crdownload").c_str(), | |
2307 GetFilename("overridden.swf").c_str()))); | |
2308 } | |
2309 | |
2310 IN_PROC_BROWSER_TEST_F( | |
2311 DownloadExtensionTest, | |
2312 DownloadExtensionTest_OnDeterminingFilename_ReferencesParentInvalid) { | |
2313 GoOnTheRecord(); | |
2314 LoadExtension("downloads_split"); | |
2315 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2316 browser()->profile(), | |
2317 GetExtensionId(), | |
2318 "42")); | |
2319 CHECK(StartTestServer()); | |
2320 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
2321 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
2322 new DownloadsDownloadFunction(), base::StringPrintf( | |
2323 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2324 ASSERT_TRUE(result.get()); | |
2325 int result_id = -1; | |
2326 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2327 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | |
2328 ASSERT_TRUE(item); | |
2329 ScopedCancellingItem canceller(item); | |
2330 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2331 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2332 base::StringPrintf("[{\"danger\": \"safe\"," | |
2333 " \"incognito\": false," | |
2334 " \"id\": %d," | |
2335 " \"mime\": \"text/plain\"," | |
2336 " \"paused\": false," | |
2337 " \"url\": \"%s\"}]", | |
2338 result_id, | |
2339 download_url.c_str()))); | |
2340 ASSERT_TRUE(WaitFor( | |
2341 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2342 base::StringPrintf("[{\"id\": %d," | |
2343 " \"filename\":\"slow.txt\"}]", | |
2344 result_id))); | |
2345 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2346 ASSERT_TRUE(item->IsInProgress()); | |
2347 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2348 browser()->profile(), | |
2349 false, | |
2350 GetExtensionId(), | |
2351 "42", | |
2352 result_id, | |
2353 FilePath(FILE_PATH_LITERAL("../sneaky.txt")), | |
Randy Smith (Not in Mondays)
2013/01/22 19:43:08
Just because I'm a paranoid control free, could yo
benjhayden
2013/01/23 21:30:10
Done.
| |
2354 false)); | |
2355 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2356 base::StringPrintf("[{\"id\": %d," | |
2357 " \"filename\": {" | |
2358 " \"previous\": \"%s\"," | |
2359 " \"current\": \"%s\"}," | |
2360 " \"state\": {" | |
2361 " \"previous\": \"in_progress\"," | |
2362 " \"current\": \"complete\"}}]", | |
2363 result_id, | |
2364 GetFilename("slow.txt.crdownload").c_str(), | |
2365 GetFilename("slow.txt").c_str()))); | |
2366 } | |
2367 | |
2368 IN_PROC_BROWSER_TEST_F( | |
2369 DownloadExtensionTest, | |
2370 DownloadExtensionTest_OnDeterminingFilename_CurDirInvalid) { | |
2371 GoOnTheRecord(); | |
2372 LoadExtension("downloads_split"); | |
2373 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2374 browser()->profile(), | |
2375 GetExtensionId(), | |
2376 "42")); | |
2377 CHECK(StartTestServer()); | |
2378 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
2379 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
2380 new DownloadsDownloadFunction(), base::StringPrintf( | |
2381 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2382 ASSERT_TRUE(result.get()); | |
2383 int result_id = -1; | |
2384 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2385 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | |
2386 ASSERT_TRUE(item); | |
2387 ScopedCancellingItem canceller(item); | |
2388 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2389 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2390 base::StringPrintf("[{\"danger\": \"safe\"," | |
2391 " \"incognito\": false," | |
2392 " \"id\": %d," | |
2393 " \"mime\": \"text/plain\"," | |
2394 " \"paused\": false," | |
2395 " \"url\": \"%s\"}]", | |
2396 result_id, | |
2397 download_url.c_str()))); | |
2398 ASSERT_TRUE(WaitFor( | |
2399 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2400 base::StringPrintf("[{\"id\": %d," | |
2401 " \"filename\":\"slow.txt\"}]", | |
2402 result_id))); | |
2403 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2404 ASSERT_TRUE(item->IsInProgress()); | |
2405 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2406 browser()->profile(), | |
2407 false, | |
2408 GetExtensionId(), | |
2409 "42", | |
2410 result_id, | |
2411 FilePath(FILE_PATH_LITERAL(".")), | |
2412 false)); | |
2413 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2414 base::StringPrintf("[{\"id\": %d," | |
2415 " \"filename\": {" | |
2416 " \"previous\": \"%s\"," | |
2417 " \"current\": \"%s\"}," | |
2418 " \"state\": {" | |
2419 " \"previous\": \"in_progress\"," | |
2420 " \"current\": \"complete\"}}]", | |
2421 result_id, | |
2422 GetFilename("slow.txt.crdownload").c_str(), | |
2423 GetFilename("slow.txt").c_str()))); | |
2424 } | |
2425 | |
2426 IN_PROC_BROWSER_TEST_F( | |
2427 DownloadExtensionTest, | |
2428 DownloadExtensionTest_OnDeterminingFilename_ParentDirInvalid) { | |
2429 CHECK(StartTestServer()); | |
2430 GoOnTheRecord(); | |
2431 LoadExtension("downloads_split"); | |
2432 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2433 browser()->profile(), | |
2434 GetExtensionId(), | |
2435 "42")); | |
2436 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
2437 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
2438 new DownloadsDownloadFunction(), base::StringPrintf( | |
2439 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2440 ASSERT_TRUE(result.get()); | |
2441 int result_id = -1; | |
2442 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2443 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | |
2444 ASSERT_TRUE(item); | |
2445 ScopedCancellingItem canceller(item); | |
2446 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2447 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2448 base::StringPrintf("[{\"danger\": \"safe\"," | |
2449 " \"incognito\": false," | |
2450 " \"id\": %d," | |
2451 " \"mime\": \"text/plain\"," | |
2452 " \"paused\": false," | |
2453 " \"url\": \"%s\"}]", | |
2454 result_id, | |
2455 download_url.c_str()))); | |
2456 ASSERT_TRUE(WaitFor( | |
2457 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2458 base::StringPrintf("[{\"id\": %d," | |
2459 " \"filename\":\"slow.txt\"}]", | |
2460 result_id))); | |
2461 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2462 ASSERT_TRUE(item->IsInProgress()); | |
2463 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2464 browser()->profile(), | |
2465 false, | |
2466 GetExtensionId(), | |
2467 "42", | |
2468 result_id, | |
2469 FilePath(FILE_PATH_LITERAL("..")), | |
2470 false)); | |
2471 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2472 base::StringPrintf("[{\"id\": %d," | |
2473 " \"filename\": {" | |
2474 " \"previous\": \"%s\"," | |
2475 " \"current\": \"%s\"}," | |
2476 " \"state\": {" | |
2477 " \"previous\": \"in_progress\"," | |
2478 " \"current\": \"complete\"}}]", | |
2479 result_id, | |
2480 GetFilename("slow.txt.crdownload").c_str(), | |
2481 GetFilename("slow.txt").c_str()))); | |
2482 } | |
2483 | |
2484 IN_PROC_BROWSER_TEST_F( | |
2485 DownloadExtensionTest, | |
2486 DownloadExtensionTest_OnDeterminingFilename_AbsPathInvalid) { | |
2487 GoOnTheRecord(); | |
2488 LoadExtension("downloads_split"); | |
2489 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2490 browser()->profile(), | |
2491 GetExtensionId(), | |
2492 "42")); | |
2493 CHECK(StartTestServer()); | |
2494 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
2495 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
2496 new DownloadsDownloadFunction(), base::StringPrintf( | |
2497 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2498 ASSERT_TRUE(result.get()); | |
2499 int result_id = -1; | |
2500 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2501 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | |
2502 ASSERT_TRUE(item); | |
2503 ScopedCancellingItem canceller(item); | |
2504 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2505 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2506 base::StringPrintf("[{\"danger\": \"safe\"," | |
2507 " \"incognito\": false," | |
2508 " \"id\": %d," | |
2509 " \"mime\": \"text/plain\"," | |
2510 " \"paused\": false," | |
2511 " \"url\": \"%s\"}]", | |
2512 result_id, | |
2513 download_url.c_str()))); | |
2514 ASSERT_TRUE(WaitFor( | |
2515 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2516 base::StringPrintf("[{\"id\": %d," | |
2517 " \"filename\":\"slow.txt\"}]", | |
2518 result_id))); | |
2519 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2520 ASSERT_TRUE(item->IsInProgress()); | |
2521 FilePath override; | |
2522 #if defined(OS_WIN) | |
2523 override = FilePath(FILE_PATH_LITERAL("C:\\windows\\system32\\mwahaha.dll")); | |
Randy Smith (Not in Mondays)
2013/01/22 19:43:08
Suggestion: Make these locations you could write t
benjhayden
2013/01/23 21:30:10
Done.
| |
2524 #else | |
2525 override = FilePath(FILE_PATH_LITERAL("/bin/cat")); | |
2526 #endif | |
2527 ASSERT_FALSE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2528 browser()->profile(), | |
2529 false, | |
2530 GetExtensionId(), | |
2531 "42", | |
2532 result_id, | |
2533 override, | |
2534 false)); | |
2535 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2536 base::StringPrintf("[{\"id\": %d," | |
2537 " \"filename\": {" | |
2538 " \"previous\": \"%s\"," | |
2539 " \"current\": \"%s\"}," | |
2540 " \"state\": {" | |
2541 " \"previous\": \"in_progress\"," | |
2542 " \"current\": \"complete\"}}]", | |
2543 result_id, | |
2544 GetFilename("slow.txt.crdownload").c_str(), | |
2545 GetFilename("slow.txt").c_str()))); | |
2546 } | |
2547 | |
2548 IN_PROC_BROWSER_TEST_F( | |
2549 DownloadExtensionTest, | |
2550 DownloadExtensionTest_OnDeterminingFilename_Override) { | |
2551 GoOnTheRecord(); | |
2552 LoadExtension("downloads_split"); | |
2553 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2554 browser()->profile(), | |
2555 GetExtensionId(), | |
2556 "42")); | |
2557 CHECK(StartTestServer()); | |
2558 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
2559 | |
2560 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
2561 new DownloadsDownloadFunction(), base::StringPrintf( | |
2562 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2563 ASSERT_TRUE(result.get()); | |
2564 int result_id = -1; | |
2565 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2566 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | |
2567 ASSERT_TRUE(item); | |
2568 ScopedCancellingItem canceller(item); | |
2569 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2570 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2571 base::StringPrintf("[{\"danger\": \"safe\"," | |
2572 " \"incognito\": false," | |
2573 " \"id\": %d," | |
2574 " \"mime\": \"text/plain\"," | |
2575 " \"paused\": false," | |
2576 " \"url\": \"%s\"}]", | |
2577 result_id, | |
2578 download_url.c_str()))); | |
2579 ASSERT_TRUE(WaitFor( | |
2580 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2581 base::StringPrintf("[{\"id\": %d," | |
2582 " \"filename\":\"slow.txt\"}]", | |
2583 result_id))); | |
2584 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2585 ASSERT_TRUE(item->IsInProgress()); | |
2586 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2587 browser()->profile(), | |
2588 false, | |
2589 GetExtensionId(), | |
2590 "42", | |
2591 result_id, | |
2592 FilePath(), | |
2593 false)); | |
2594 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2595 base::StringPrintf("[{\"id\": %d," | |
2596 " \"filename\": {" | |
2597 " \"previous\": \"%s\"," | |
2598 " \"current\": \"%s\"}," | |
2599 " \"state\": {" | |
2600 " \"previous\": \"in_progress\"," | |
2601 " \"current\": \"complete\"}}]", | |
2602 result_id, | |
2603 GetFilename("slow.txt.crdownload").c_str(), | |
2604 GetFilename("slow.txt").c_str()))); | |
2605 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2606 base::StringPrintf("[{\"id\": %d," | |
2607 " \"state\": {" | |
2608 " \"previous\": \"in_progress\"," | |
2609 " \"current\": \"complete\"}}]", | |
2610 result_id))); | |
2611 | |
2612 result.reset(RunFunctionAndReturnResult( | |
2613 new DownloadsDownloadFunction(), base::StringPrintf( | |
2614 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2615 ASSERT_TRUE(result.get()); | |
2616 result_id = -1; | |
2617 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2618 item = GetCurrentManager()->GetDownload(result_id); | |
2619 ASSERT_TRUE(item); | |
2620 ScopedCancellingItem canceller2(item); | |
2621 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2622 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2623 base::StringPrintf("[{\"danger\": \"safe\"," | |
2624 " \"incognito\": false," | |
2625 " \"id\": %d," | |
2626 " \"mime\": \"text/plain\"," | |
2627 " \"paused\": false," | |
2628 " \"url\": \"%s\"}]", | |
2629 result_id, | |
2630 download_url.c_str()))); | |
2631 ASSERT_TRUE(WaitFor( | |
2632 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2633 base::StringPrintf("[{\"id\": %d," | |
2634 " \"filename\":\"slow.txt\"}]", | |
2635 result_id))); | |
2636 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2637 ASSERT_TRUE(item->IsInProgress()); | |
2638 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2639 browser()->profile(), | |
2640 false, | |
2641 GetExtensionId(), | |
2642 "42", | |
2643 result_id, | |
2644 FilePath(FILE_PATH_LITERAL("slow.txt")), | |
2645 true)); | |
2646 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2647 base::StringPrintf("[{\"id\": %d," | |
2648 " \"filename\": {" | |
2649 " \"previous\": \"%s\"," | |
2650 " \"current\": \"%s\"}," | |
2651 " \"state\": {" | |
2652 " \"previous\": \"in_progress\"," | |
2653 " \"current\": \"complete\"}}]", | |
2654 result_id, | |
2655 GetFilename("slow.txt.crdownload").c_str(), | |
2656 GetFilename("slow.txt").c_str()))); | |
2657 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2658 base::StringPrintf("[{\"id\": %d," | |
2659 " \"state\": {" | |
2660 " \"previous\": \"in_progress\"," | |
2661 " \"current\": \"complete\"}}]", | |
2662 result_id))); | |
2663 } | |
2664 | |
2665 IN_PROC_BROWSER_TEST_F( | |
2666 DownloadExtensionTest, | |
2667 DownloadExtensionTest_OnDeterminingFilename_LaterDeterminerPrecedence) { | |
2668 CHECK(StartTestServer()); | |
2669 LOG(INFO) << "occam"; | |
2670 GoOnTheRecord(); | |
2671 LOG(INFO) << "occam"; | |
2672 LoadExtension("downloads_split"); | |
2673 LOG(INFO) << "occam"; | |
2674 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2675 browser()->profile(), | |
2676 GetExtensionId(), | |
2677 "42")); | |
2678 LOG(INFO) << "occam"; | |
2679 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2680 browser()->profile(), | |
2681 GetExtensionId(), | |
2682 "43")); | |
2683 LOG(INFO) << "occam"; | |
2684 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
2685 LOG(INFO) << "occam"; | |
2686 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
2687 new DownloadsDownloadFunction(), base::StringPrintf( | |
2688 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2689 LOG(INFO) << "occam"; | |
2690 ASSERT_TRUE(result.get()); | |
2691 LOG(INFO) << "occam"; | |
2692 int result_id = -1; | |
2693 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2694 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | |
2695 ASSERT_TRUE(item); | |
2696 ScopedCancellingItem canceller(item); | |
2697 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2698 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2699 base::StringPrintf("[{\"danger\": \"safe\"," | |
2700 " \"incognito\": false," | |
2701 " \"id\": %d," | |
2702 " \"mime\": \"text/plain\"," | |
2703 " \"paused\": false," | |
2704 " \"url\": \"%s\"}]", | |
2705 result_id, | |
2706 download_url.c_str()))); | |
2707 ASSERT_TRUE(WaitFor( | |
2708 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2709 base::StringPrintf("[{\"id\": %d," | |
2710 " \"filename\":\"slow.txt\"}]", | |
2711 result_id))); | |
2712 ASSERT_TRUE(WaitFor( | |
2713 std::string(events::kOnDownloadDeterminingFilename) + "/43", | |
2714 base::StringPrintf("[{\"id\": %d," | |
2715 " \"filename\":\"slow.txt\"}]", | |
2716 result_id))); | |
2717 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2718 ASSERT_TRUE(item->IsInProgress()); | |
2719 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2720 browser()->profile(), | |
2721 false, | |
2722 GetExtensionId(), | |
2723 "42", | |
2724 result_id, | |
2725 FilePath(FILE_PATH_LITERAL("42.txt")), | |
2726 false)); | |
2727 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2728 browser()->profile(), | |
2729 false, | |
2730 GetExtensionId(), | |
2731 "43", | |
2732 result_id, | |
2733 FilePath(FILE_PATH_LITERAL("43.txt")), | |
2734 false)); | |
2735 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2736 base::StringPrintf("[{\"id\": %d," | |
2737 " \"filename\": {" | |
2738 " \"previous\": \"%s\"," | |
2739 " \"current\": \"%s\"}," | |
2740 " \"state\": {" | |
2741 " \"previous\": \"in_progress\"," | |
2742 " \"current\": \"complete\"}}]", | |
2743 result_id, | |
2744 GetFilename("43.txt.crdownload").c_str(), | |
2745 GetFilename("43.txt").c_str()))); | |
2746 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2747 base::StringPrintf("[{\"id\": %d," | |
2748 " \"state\": {" | |
2749 " \"previous\": \"in_progress\"," | |
2750 " \"current\": \"complete\"}}]", | |
2751 result_id))); | |
2752 | |
2753 result.reset(RunFunctionAndReturnResult( | |
2754 new DownloadsDownloadFunction(), base::StringPrintf( | |
2755 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2756 ASSERT_TRUE(result.get()); | |
2757 result_id = -1; | |
2758 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2759 item = GetCurrentManager()->GetDownload(result_id); | |
2760 ASSERT_TRUE(item); | |
2761 ScopedCancellingItem canceller2(item); | |
2762 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2763 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2764 base::StringPrintf("[{\"danger\": \"safe\"," | |
2765 " \"incognito\": false," | |
2766 " \"id\": %d," | |
2767 " \"mime\": \"text/plain\"," | |
2768 " \"paused\": false," | |
2769 " \"url\": \"%s\"}]", | |
2770 result_id, | |
2771 download_url.c_str()))); | |
2772 ASSERT_TRUE(WaitFor( | |
2773 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2774 base::StringPrintf("[{\"id\": %d," | |
2775 " \"filename\":\"slow.txt\"}]", | |
2776 result_id))); | |
2777 ASSERT_TRUE(WaitFor( | |
2778 std::string(events::kOnDownloadDeterminingFilename) + "/43", | |
2779 base::StringPrintf("[{\"id\": %d," | |
2780 " \"filename\":\"slow.txt\"}]", | |
2781 result_id))); | |
2782 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2783 ASSERT_TRUE(item->IsInProgress()); | |
2784 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2785 browser()->profile(), | |
2786 false, | |
2787 GetExtensionId(), | |
2788 "43", | |
2789 result_id, | |
2790 FilePath(FILE_PATH_LITERAL("43b.txt")), | |
2791 false)); | |
2792 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2793 browser()->profile(), | |
2794 false, | |
2795 GetExtensionId(), | |
2796 "42", | |
2797 result_id, | |
2798 FilePath(FILE_PATH_LITERAL("42b.txt")), | |
2799 false)); | |
2800 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2801 base::StringPrintf("[{\"id\": %d," | |
2802 " \"filename\": {" | |
2803 " \"previous\": \"%s\"," | |
2804 " \"current\": \"%s\"}," | |
2805 " \"state\": {" | |
2806 " \"previous\": \"in_progress\"," | |
2807 " \"current\": \"complete\"}}]", | |
2808 result_id, | |
2809 GetFilename("43b.txt.crdownload").c_str(), | |
2810 GetFilename("43b.txt").c_str()))); | |
2811 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2812 base::StringPrintf("[{\"id\": %d," | |
2813 " \"state\": {" | |
2814 " \"previous\": \"in_progress\"," | |
2815 " \"current\": \"complete\"}}]", | |
2816 result_id))); | |
2817 } | |
2818 | |
2819 // TODO test precedence rules: install_time | |
2820 | |
2821 IN_PROC_BROWSER_TEST_F( | |
2822 DownloadExtensionTest, | |
2823 DownloadExtensionTest_OnDeterminingFilename_RemoveFilenameDeterminer) { | |
2824 CHECK(StartTestServer()); | |
2825 GoOnTheRecord(); | |
2826 LoadExtension("downloads_split"); | |
2827 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2828 browser()->profile(), | |
2829 GetExtensionId(), | |
2830 "42")); | |
2831 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2832 browser()->profile(), | |
2833 GetExtensionId(), | |
2834 "43")); | |
2835 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
2836 ASSERT_TRUE(ExtensionDownloadsEventRouter::RemoveFilenameDeterminer( | |
2837 browser()->profile(), | |
2838 GetExtensionId(), | |
2839 "42")); | |
2840 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
2841 new DownloadsDownloadFunction(), base::StringPrintf( | |
2842 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2843 ASSERT_TRUE(result.get()); | |
2844 int result_id = -1; | |
2845 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2846 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | |
2847 ASSERT_TRUE(item); | |
2848 ScopedCancellingItem canceller(item); | |
2849 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2850 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2851 base::StringPrintf("[{\"danger\": \"safe\"," | |
2852 " \"incognito\": false," | |
2853 " \"id\": %d," | |
2854 " \"mime\": \"text/plain\"," | |
2855 " \"paused\": false," | |
2856 " \"url\": \"%s\"}]", | |
2857 result_id, | |
2858 download_url.c_str()))); | |
2859 ASSERT_TRUE(WaitFor( | |
2860 std::string(events::kOnDownloadDeterminingFilename) + "/43", | |
2861 base::StringPrintf("[{\"id\": %d," | |
2862 " \"filename\":\"slow.txt\"}]", | |
2863 result_id))); | |
2864 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2865 ASSERT_TRUE(item->IsInProgress()); | |
2866 ASSERT_TRUE(ExtensionDownloadsEventRouter::DetermineFilename( | |
2867 browser()->profile(), | |
2868 false, | |
2869 GetExtensionId(), | |
2870 "43", | |
2871 result_id, | |
2872 FilePath(), | |
2873 false)); | |
2874 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2875 base::StringPrintf("[{\"id\": %d," | |
2876 " \"state\": {" | |
2877 " \"previous\": \"in_progress\"," | |
2878 " \"current\": \"complete\"}}]", | |
2879 result_id))); | |
2880 } | |
2881 | |
2882 // TODO test incognito | |
2883 // TODO test incognito=spanning | |
Randy Smith (Not in Mondays)
2013/01/22 19:43:08
Would it be possible to add a test that runs throu
benjhayden
2013/01/23 21:30:10
Done.
Randy Smith (Not in Mondays)
2013/01/24 19:12:46
I'm not sure you added the test I was looking for,
| |
2884 | |
2885 IN_PROC_BROWSER_TEST_F( | |
2886 DownloadExtensionTest, | |
2887 DownloadExtensionTest_OnDeterminingFilename_DisableExtension) { | |
2888 GoOnTheRecord(); | |
2889 LoadExtension("downloads_split"); | |
2890 ASSERT_TRUE(ExtensionDownloadsEventRouter::AddFilenameDeterminer( | |
2891 browser()->profile(), | |
2892 GetExtensionId(), | |
2893 "42")); | |
2894 CHECK(StartTestServer()); | |
2895 std::string download_url = test_server()->GetURL("slow?0").spec(); | |
2896 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | |
2897 new DownloadsDownloadFunction(), base::StringPrintf( | |
2898 "[{\"url\": \"%s\"}]", download_url.c_str()))); | |
2899 ASSERT_TRUE(result.get()); | |
2900 int result_id = -1; | |
2901 ASSERT_TRUE(result->GetAsInteger(&result_id)); | |
2902 DownloadItem* item = GetCurrentManager()->GetDownload(result_id); | |
2903 ASSERT_TRUE(item); | |
2904 ScopedCancellingItem canceller(item); | |
2905 ASSERT_EQ(download_url, item->GetOriginalUrl().spec()); | |
2906 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, | |
2907 base::StringPrintf("[{\"danger\": \"safe\"," | |
2908 " \"incognito\": false," | |
2909 " \"id\": %d," | |
2910 " \"mime\": \"text/plain\"," | |
2911 " \"paused\": false," | |
2912 " \"url\": \"%s\"}]", | |
2913 result_id, | |
2914 download_url.c_str()))); | |
2915 ASSERT_TRUE(WaitFor( | |
2916 std::string(events::kOnDownloadDeterminingFilename) + "/42", | |
2917 base::StringPrintf("[{\"id\": %d," | |
2918 " \"filename\":\"slow.txt\"}]", | |
2919 result_id))); | |
2920 ASSERT_TRUE(item->GetTargetFilePath().empty()); | |
2921 ASSERT_TRUE(item->IsInProgress()); | |
2922 DisableExtension(); | |
2923 ASSERT_TRUE(WaitFor(events::kOnDownloadChanged, | |
2924 base::StringPrintf("[{\"id\": %d," | |
2925 " \"state\": {" | |
2926 " \"previous\": \"in_progress\"," | |
2927 " \"current\": \"complete\"}}]", | |
2928 result_id))); | |
2929 } | |
OLD | NEW |