Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: net/url_request/url_fetcher_impl_unittest.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/tools/crash_cache/crash_cache.cc ('k') | sql/connection.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/url_request/url_fetcher_impl.h" 5 #include "net/url_request/url_fetcher_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 1362
1363 // Get a small file. 1363 // Get a small file.
1364 static const char kFileToFetch[] = "simple.html"; 1364 static const char kFileToFetch[] = "simple.html";
1365 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); 1365 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch);
1366 CreateFetcherForFile( 1366 CreateFetcherForFile(
1367 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), 1367 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch),
1368 temp_dir.path().AppendASCII(kFileToFetch)); 1368 temp_dir.path().AppendASCII(kFileToFetch));
1369 1369
1370 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1370 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1371 1371
1372 ASSERT_FALSE(file_util::PathExists(file_path_)) 1372 ASSERT_FALSE(base::PathExists(file_path_))
1373 << file_path_.value() << " not removed."; 1373 << file_path_.value() << " not removed.";
1374 } 1374 }
1375 1375
1376 TEST_F(URLFetcherFileTest, LargeGet) { 1376 TEST_F(URLFetcherFileTest, LargeGet) {
1377 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, 1377 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP,
1378 SpawnedTestServer::kLocalhost, 1378 SpawnedTestServer::kLocalhost,
1379 base::FilePath(kDocRoot)); 1379 base::FilePath(kDocRoot));
1380 ASSERT_TRUE(test_server.Start()); 1380 ASSERT_TRUE(test_server.Start());
1381 1381
1382 base::ScopedTempDir temp_dir; 1382 base::ScopedTempDir temp_dir;
(...skipping 27 matching lines...) Expand all
1410 // Get a small file. 1410 // Get a small file.
1411 static const char kFileToFetch[] = "simple.html"; 1411 static const char kFileToFetch[] = "simple.html";
1412 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); 1412 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch);
1413 CreateFetcherForFile( 1413 CreateFetcherForFile(
1414 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), 1414 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch),
1415 temp_dir.path().AppendASCII(kFileToFetch)); 1415 temp_dir.path().AppendASCII(kFileToFetch));
1416 1416
1417 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1417 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1418 1418
1419 base::MessageLoop::current()->RunUntilIdle(); 1419 base::MessageLoop::current()->RunUntilIdle();
1420 ASSERT_EQ(kTake[i], file_util::PathExists(file_path_)) << 1420 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) <<
1421 "FilePath: " << file_path_.value(); 1421 "FilePath: " << file_path_.value();
1422 } 1422 }
1423 } 1423 }
1424 1424
1425 TEST_F(URLFetcherFileTest, OverwriteExistingFile) { 1425 TEST_F(URLFetcherFileTest, OverwriteExistingFile) {
1426 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, 1426 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP,
1427 SpawnedTestServer::kLocalhost, 1427 SpawnedTestServer::kLocalhost,
1428 base::FilePath(kDocRoot)); 1428 base::FilePath(kDocRoot));
1429 ASSERT_TRUE(test_server.Start()); 1429 ASSERT_TRUE(test_server.Start());
1430 1430
1431 base::ScopedTempDir temp_dir; 1431 base::ScopedTempDir temp_dir;
1432 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1432 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1433 1433
1434 // Create a file before trying to fetch. 1434 // Create a file before trying to fetch.
1435 static const char kFileToFetch[] = "simple.html"; 1435 static const char kFileToFetch[] = "simple.html";
1436 std::string data(10000, '?'); // Meant to be larger than simple.html. 1436 std::string data(10000, '?'); // Meant to be larger than simple.html.
1437 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); 1437 file_path_ = temp_dir.path().AppendASCII(kFileToFetch);
1438 ASSERT_EQ(static_cast<int>(data.size()), 1438 ASSERT_EQ(static_cast<int>(data.size()),
1439 file_util::WriteFile(file_path_, data.data(), data.size())); 1439 file_util::WriteFile(file_path_, data.data(), data.size()));
1440 ASSERT_TRUE(file_util::PathExists(file_path_)); 1440 ASSERT_TRUE(base::PathExists(file_path_));
1441 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); 1441 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch);
1442 ASSERT_FALSE(file_util::ContentsEqual(file_path_, expected_file_)); 1442 ASSERT_FALSE(file_util::ContentsEqual(file_path_, expected_file_));
1443 1443
1444 // Get a small file. 1444 // Get a small file.
1445 CreateFetcherForFile( 1445 CreateFetcherForFile(
1446 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), 1446 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch),
1447 file_path_); 1447 file_path_);
1448 1448
1449 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1449 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1450 } 1450 }
1451 1451
1452 TEST_F(URLFetcherFileTest, TryToOverwriteDirectory) { 1452 TEST_F(URLFetcherFileTest, TryToOverwriteDirectory) {
1453 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, 1453 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP,
1454 SpawnedTestServer::kLocalhost, 1454 SpawnedTestServer::kLocalhost,
1455 base::FilePath(kDocRoot)); 1455 base::FilePath(kDocRoot));
1456 ASSERT_TRUE(test_server.Start()); 1456 ASSERT_TRUE(test_server.Start());
1457 1457
1458 base::ScopedTempDir temp_dir; 1458 base::ScopedTempDir temp_dir;
1459 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1459 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1460 1460
1461 // Create a directory before trying to fetch. 1461 // Create a directory before trying to fetch.
1462 static const char kFileToFetch[] = "simple.html"; 1462 static const char kFileToFetch[] = "simple.html";
1463 file_path_ = temp_dir.path().AppendASCII(kFileToFetch); 1463 file_path_ = temp_dir.path().AppendASCII(kFileToFetch);
1464 ASSERT_TRUE(file_util::CreateDirectory(file_path_)); 1464 ASSERT_TRUE(file_util::CreateDirectory(file_path_));
1465 ASSERT_TRUE(file_util::PathExists(file_path_)); 1465 ASSERT_TRUE(base::PathExists(file_path_));
1466 1466
1467 // Get a small file. 1467 // Get a small file.
1468 expected_file_error_ = ERR_ACCESS_DENIED; 1468 expected_file_error_ = ERR_ACCESS_DENIED;
1469 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); 1469 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch);
1470 CreateFetcherForFile( 1470 CreateFetcherForFile(
1471 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch), 1471 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch),
1472 file_path_); 1472 file_path_);
1473 1473
1474 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1474 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1475 1475
1476 base::MessageLoop::current()->RunUntilIdle(); 1476 base::MessageLoop::current()->RunUntilIdle();
1477 } 1477 }
1478 1478
1479 TEST_F(URLFetcherFileTest, SmallGetToTempFile) { 1479 TEST_F(URLFetcherFileTest, SmallGetToTempFile) {
1480 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, 1480 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP,
1481 SpawnedTestServer::kLocalhost, 1481 SpawnedTestServer::kLocalhost,
1482 base::FilePath(kDocRoot)); 1482 base::FilePath(kDocRoot));
1483 ASSERT_TRUE(test_server.Start()); 1483 ASSERT_TRUE(test_server.Start());
1484 1484
1485 // Get a small file. 1485 // Get a small file.
1486 static const char kFileToFetch[] = "simple.html"; 1486 static const char kFileToFetch[] = "simple.html";
1487 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); 1487 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch);
1488 CreateFetcherForTempFile( 1488 CreateFetcherForTempFile(
1489 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch)); 1489 test_server.GetURL(std::string(kTestServerFilePrefix) + kFileToFetch));
1490 1490
1491 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1491 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1492 1492
1493 ASSERT_FALSE(file_util::PathExists(file_path_)) 1493 ASSERT_FALSE(base::PathExists(file_path_))
1494 << file_path_.value() << " not removed."; 1494 << file_path_.value() << " not removed.";
1495 } 1495 }
1496 1496
1497 TEST_F(URLFetcherFileTest, LargeGetToTempFile) { 1497 TEST_F(URLFetcherFileTest, LargeGetToTempFile) {
1498 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP, 1498 SpawnedTestServer test_server(SpawnedTestServer::TYPE_HTTP,
1499 SpawnedTestServer::kLocalhost, 1499 SpawnedTestServer::kLocalhost,
1500 base::FilePath(kDocRoot)); 1500 base::FilePath(kDocRoot));
1501 ASSERT_TRUE(test_server.Start()); 1501 ASSERT_TRUE(test_server.Start());
1502 1502
1503 // Get a file large enough to require more than one read into 1503 // Get a file large enough to require more than one read into
(...skipping 20 matching lines...) Expand all
1524 1524
1525 // Get a small file. 1525 // Get a small file.
1526 static const char kFileToFetch[] = "simple.html"; 1526 static const char kFileToFetch[] = "simple.html";
1527 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch); 1527 expected_file_ = test_server.GetDocumentRoot().AppendASCII(kFileToFetch);
1528 CreateFetcherForTempFile(test_server.GetURL( 1528 CreateFetcherForTempFile(test_server.GetURL(
1529 std::string(kTestServerFilePrefix) + kFileToFetch)); 1529 std::string(kTestServerFilePrefix) + kFileToFetch));
1530 1530
1531 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit(). 1531 base::MessageLoop::current()->Run(); // OnURLFetchComplete() will Quit().
1532 1532
1533 base::MessageLoop::current()->RunUntilIdle(); 1533 base::MessageLoop::current()->RunUntilIdle();
1534 ASSERT_EQ(kTake[i], file_util::PathExists(file_path_)) << 1534 ASSERT_EQ(kTake[i], base::PathExists(file_path_)) <<
1535 "FilePath: " << file_path_.value(); 1535 "FilePath: " << file_path_.value();
1536 } 1536 }
1537 } 1537 }
1538 1538
1539 } // namespace 1539 } // namespace
1540 1540
1541 } // namespace net 1541 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/crash_cache/crash_cache.cc ('k') | sql/connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698