| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 #if defined(OS_WIN) | 237 #if defined(OS_WIN) |
| 238 #define MAYBE_TestLongSafePureFilename DISABLED_TestLongSafePureFilename | 238 #define MAYBE_TestLongSafePureFilename DISABLED_TestLongSafePureFilename |
| 239 #else | 239 #else |
| 240 #define MAYBE_TestLongSafePureFilename TestLongSafePureFilename | 240 #define MAYBE_TestLongSafePureFilename TestLongSafePureFilename |
| 241 #endif | 241 #endif |
| 242 TEST_F(SavePackageTest, MAYBE_TestLongSafePureFilename) { | 242 TEST_F(SavePackageTest, MAYBE_TestLongSafePureFilename) { |
| 243 const base::FilePath save_dir(FPL("test_dir")); | 243 const base::FilePath save_dir(FPL("test_dir")); |
| 244 const base::FilePath::StringType ext(FPL_HTML_EXTENSION); | 244 const base::FilePath::StringType ext(FPL_HTML_EXTENSION); |
| 245 base::FilePath::StringType filename = | 245 base::FilePath::StringType filename = |
| 246 #if defined(OS_WIN) | 246 #if defined(OS_WIN) |
| 247 ASCIIToWide(long_file_name); | 247 base::ASCIIToWide(long_file_name); |
| 248 #else | 248 #else |
| 249 long_file_name; | 249 long_file_name; |
| 250 #endif | 250 #endif |
| 251 | 251 |
| 252 // Test that the filename + extension doesn't exceed kMaxFileNameLength | 252 // Test that the filename + extension doesn't exceed kMaxFileNameLength |
| 253 uint32 max_path = SavePackage::GetMaxPathLengthForDirectory(save_dir); | 253 uint32 max_path = SavePackage::GetMaxPathLengthForDirectory(save_dir); |
| 254 ASSERT_TRUE(SavePackage::GetSafePureFileName(save_dir, ext, max_path, | 254 ASSERT_TRUE(SavePackage::GetSafePureFileName(save_dir, ext, max_path, |
| 255 &filename)); | 255 &filename)); |
| 256 EXPECT_TRUE(filename.length() <= kMaxFileNameLength-ext.length()); | 256 EXPECT_TRUE(filename.length() <= kMaxFileNameLength-ext.length()); |
| 257 } | 257 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 // "http www.foo.com a path name.txt", when we want to save it as "name.txt". | 345 // "http www.foo.com a path name.txt", when we want to save it as "name.txt". |
| 346 | 346 |
| 347 static const struct SuggestedSaveNameTestCase { | 347 static const struct SuggestedSaveNameTestCase { |
| 348 const char* page_url; | 348 const char* page_url; |
| 349 const base::string16 page_title; | 349 const base::string16 page_title; |
| 350 const base::FilePath::CharType* expected_name; | 350 const base::FilePath::CharType* expected_name; |
| 351 bool ensure_html_extension; | 351 bool ensure_html_extension; |
| 352 } kSuggestedSaveNames[] = { | 352 } kSuggestedSaveNames[] = { |
| 353 // Title overrides the URL. | 353 // Title overrides the URL. |
| 354 { "http://foo.com", | 354 { "http://foo.com", |
| 355 ASCIIToUTF16("A page title"), | 355 base::ASCIIToUTF16("A page title"), |
| 356 FPL("A page title") FPL_HTML_EXTENSION, | 356 FPL("A page title") FPL_HTML_EXTENSION, |
| 357 true | 357 true |
| 358 }, | 358 }, |
| 359 // Extension is preserved. | 359 // Extension is preserved. |
| 360 { "http://foo.com", | 360 { "http://foo.com", |
| 361 ASCIIToUTF16("A page title with.ext"), | 361 base::ASCIIToUTF16("A page title with.ext"), |
| 362 FPL("A page title with.ext"), | 362 FPL("A page title with.ext"), |
| 363 false | 363 false |
| 364 }, | 364 }, |
| 365 // If the title matches the URL, use the last component of the URL. | 365 // If the title matches the URL, use the last component of the URL. |
| 366 { "http://foo.com/bar", | 366 { "http://foo.com/bar", |
| 367 ASCIIToUTF16("foo.com/bar"), | 367 base::ASCIIToUTF16("foo.com/bar"), |
| 368 FPL("bar"), | 368 FPL("bar"), |
| 369 false | 369 false |
| 370 }, | 370 }, |
| 371 // If the title matches the URL, but there is no "filename" component, | 371 // If the title matches the URL, but there is no "filename" component, |
| 372 // use the domain. | 372 // use the domain. |
| 373 { "http://foo.com", | 373 { "http://foo.com", |
| 374 ASCIIToUTF16("foo.com"), | 374 base::ASCIIToUTF16("foo.com"), |
| 375 FPL("foo.com"), | 375 FPL("foo.com"), |
| 376 false | 376 false |
| 377 }, | 377 }, |
| 378 // Make sure fuzzy matching works. | 378 // Make sure fuzzy matching works. |
| 379 { "http://foo.com/bar", | 379 { "http://foo.com/bar", |
| 380 ASCIIToUTF16("foo.com/bar"), | 380 base::ASCIIToUTF16("foo.com/bar"), |
| 381 FPL("bar"), | 381 FPL("bar"), |
| 382 false | 382 false |
| 383 }, | 383 }, |
| 384 // A URL-like title that does not match the title is respected in full. | 384 // A URL-like title that does not match the title is respected in full. |
| 385 { "http://foo.com", | 385 { "http://foo.com", |
| 386 ASCIIToUTF16("http://www.foo.com/path/title.txt"), | 386 base::ASCIIToUTF16("http://www.foo.com/path/title.txt"), |
| 387 FPL("http www.foo.com path title.txt"), | 387 FPL("http www.foo.com path title.txt"), |
| 388 false | 388 false |
| 389 }, | 389 }, |
| 390 }; | 390 }; |
| 391 | 391 |
| 392 // Crashing on Windows, see http://crbug.com/79365 | 392 // Crashing on Windows, see http://crbug.com/79365 |
| 393 #if defined(OS_WIN) | 393 #if defined(OS_WIN) |
| 394 #define MAYBE_TestSuggestedSaveNames DISABLED_TestSuggestedSaveNames | 394 #define MAYBE_TestSuggestedSaveNames DISABLED_TestSuggestedSaveNames |
| 395 #else | 395 #else |
| 396 #define MAYBE_TestSuggestedSaveNames TestSuggestedSaveNames | 396 #define MAYBE_TestSuggestedSaveNames TestSuggestedSaveNames |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( | 431 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( |
| 432 base::FilePath(kTestDir).Append(file_name)); | 432 base::FilePath(kTestDir).Append(file_name)); |
| 433 GURL actual_url = URLRequestMockHTTPJob::GetMockUrl( | 433 GURL actual_url = URLRequestMockHTTPJob::GetMockUrl( |
| 434 base::FilePath(kTestDir).Append(file_name)); | 434 base::FilePath(kTestDir).Append(file_name)); |
| 435 NavigateAndCommit(view_source_url); | 435 NavigateAndCommit(view_source_url); |
| 436 EXPECT_EQ(actual_url, GetUrlToBeSaved()); | 436 EXPECT_EQ(actual_url, GetUrlToBeSaved()); |
| 437 EXPECT_EQ(view_source_url, contents()->GetLastCommittedURL()); | 437 EXPECT_EQ(view_source_url, contents()->GetLastCommittedURL()); |
| 438 } | 438 } |
| 439 | 439 |
| 440 } // namespace content | 440 } // namespace content |
| OLD | NEW |