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

Side by Side Diff: chrome/browser/chromeos/drive/file_system_unittest.cc

Issue 15843006: Random clean up in c/b/cros/drive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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
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 "chrome/browser/chromeos/drive/file_system.h" 5 #include "chrome/browser/chromeos/drive/file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // value of |counter| is different from the expected one. 95 // value of |counter| is different from the expected one.
96 message_loop->Quit(); 96 message_loop->Quit();
97 return; 97 return;
98 } 98 }
99 99
100 (*counter)++; 100 (*counter)++;
101 if (*counter >= expected_counter) 101 if (*counter >= expected_counter)
102 message_loop->Quit(); 102 message_loop->Quit();
103 } 103 }
104 104
105 void AppendContent(std::vector<std::string>* buffer,
106 google_apis::GDataErrorCode error,
107 scoped_ptr<std::string> content) {
108 DCHECK_EQ(error, google_apis::HTTP_SUCCESS);
109 buffer->push_back(*content);
110 }
111
112 } // namespace 105 } // namespace
113 106
114 class FileSystemTest : public testing::Test { 107 class FileSystemTest : public testing::Test {
115 protected: 108 protected:
116 FileSystemTest() 109 FileSystemTest()
117 : ui_thread_(content::BrowserThread::UI, &message_loop_), 110 : ui_thread_(content::BrowserThread::UI, &message_loop_),
118 // |root_feed_changestamp_| should be set to the largest changestamp in 111 // |root_feed_changestamp_| should be set to the largest changestamp in
119 // about resource feed. But we fake it by some non-zero positive 112 // about resource feed. But we fake it by some non-zero positive
120 // increasing value. See |LoadFeed()|. 113 // increasing value. See |LoadFeed()|.
121 root_feed_changestamp_(1) { 114 root_feed_changestamp_(1) {
(...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 1540
1548 ASSERT_TRUE(LoadRootFeedDocument()); 1541 ASSERT_TRUE(LoadRootFeedDocument());
1549 1542
1550 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1543 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1551 1544
1552 { 1545 {
1553 FileError initialized_error = FILE_ERROR_FAILED; 1546 FileError initialized_error = FILE_ERROR_FAILED;
1554 scoped_ptr<ResourceEntry> entry; 1547 scoped_ptr<ResourceEntry> entry;
1555 base::FilePath local_path; 1548 base::FilePath local_path;
1556 base::Closure cancel_download; 1549 base::Closure cancel_download;
1557 1550 google_apis::test_util::TestGetContentCallback get_content_callback;
1558 std::vector<std::string> content_buffer;
1559 1551
1560 FileError completion_error = FILE_ERROR_FAILED; 1552 FileError completion_error = FILE_ERROR_FAILED;
1561 1553
1562 file_system_->GetFileContentByPath( 1554 file_system_->GetFileContentByPath(
1563 file_in_root, 1555 file_in_root,
1564 google_apis::test_util::CreateCopyResultCallback( 1556 google_apis::test_util::CreateCopyResultCallback(
1565 &initialized_error, &entry, &local_path, &cancel_download), 1557 &initialized_error, &entry, &local_path, &cancel_download),
1566 base::Bind(&AppendContent, &content_buffer), 1558 get_content_callback.callback(),
1567 google_apis::test_util::CreateCopyResultCallback(&completion_error)); 1559 google_apis::test_util::CreateCopyResultCallback(&completion_error));
1568 google_apis::test_util::RunBlockingPoolTask(); 1560 google_apis::test_util::RunBlockingPoolTask();
1569 1561
1570 // For the first time, file is downloaded from the remote server. 1562 // For the first time, file is downloaded from the remote server.
1571 // In this case, |local_path| is empty while |cancel_download| is not. 1563 // In this case, |local_path| is empty while |cancel_download| is not.
1572 EXPECT_EQ(FILE_ERROR_OK, initialized_error); 1564 EXPECT_EQ(FILE_ERROR_OK, initialized_error);
1573 ASSERT_TRUE(entry); 1565 ASSERT_TRUE(entry);
1574 ASSERT_TRUE(local_path.empty()); 1566 ASSERT_TRUE(local_path.empty());
1575 EXPECT_TRUE(!cancel_download.is_null()); 1567 EXPECT_TRUE(!cancel_download.is_null());
1576 // Content is available through the second callback arguemnt. 1568 // Content is available through the second callback argument.
1577 size_t content_size = 0;
1578 for (size_t i = 0; i < content_buffer.size(); ++i) {
1579 content_size += content_buffer[i].size();
1580 }
1581 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()), 1569 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()),
1582 content_size); 1570 get_content_callback.GetConcatenatedData().size());
1583 EXPECT_EQ(FILE_ERROR_OK, completion_error); 1571 EXPECT_EQ(FILE_ERROR_OK, completion_error);
1584 } 1572 }
1585 1573
1586 { 1574 {
1587 FileError initialized_error = FILE_ERROR_FAILED; 1575 FileError initialized_error = FILE_ERROR_FAILED;
1588 scoped_ptr<ResourceEntry> entry; 1576 scoped_ptr<ResourceEntry> entry;
1589 base::FilePath local_path; 1577 base::FilePath local_path;
1590 base::Closure cancel_download; 1578 base::Closure cancel_download;
1591 1579 google_apis::test_util::TestGetContentCallback get_content_callback;
1592 std::vector<std::string> content_buffer;
1593 1580
1594 FileError completion_error = FILE_ERROR_FAILED; 1581 FileError completion_error = FILE_ERROR_FAILED;
1595 1582
1596 file_system_->GetFileContentByPath( 1583 file_system_->GetFileContentByPath(
1597 file_in_root, 1584 file_in_root,
1598 google_apis::test_util::CreateCopyResultCallback( 1585 google_apis::test_util::CreateCopyResultCallback(
1599 &initialized_error, &entry, &local_path, &cancel_download), 1586 &initialized_error, &entry, &local_path, &cancel_download),
1600 base::Bind(&AppendContent, &content_buffer), 1587 get_content_callback.callback(),
1601 google_apis::test_util::CreateCopyResultCallback(&completion_error)); 1588 google_apis::test_util::CreateCopyResultCallback(&completion_error));
1602 google_apis::test_util::RunBlockingPoolTask(); 1589 google_apis::test_util::RunBlockingPoolTask();
1603 1590
1604 // Try second download. In this case, the file should be cached, so 1591 // Try second download. In this case, the file should be cached, so
1605 // |local_path| should not be empty while |cancel_download| is empty. 1592 // |local_path| should not be empty while |cancel_download| is empty.
1606 EXPECT_EQ(FILE_ERROR_OK, initialized_error); 1593 EXPECT_EQ(FILE_ERROR_OK, initialized_error);
1607 ASSERT_TRUE(entry); 1594 ASSERT_TRUE(entry);
1608 ASSERT_TRUE(!local_path.empty()); 1595 ASSERT_TRUE(!local_path.empty());
1609 EXPECT_TRUE(cancel_download.is_null()); 1596 EXPECT_TRUE(cancel_download.is_null());
1610 // The content is available from the cache file. 1597 // The content is available from the cache file.
1611 EXPECT_TRUE(content_buffer.empty()); 1598 EXPECT_TRUE(get_content_callback.data().empty());
1612 int64 local_file_size = 0; 1599 int64 local_file_size = 0;
1613 file_util::GetFileSize(local_path, &local_file_size); 1600 file_util::GetFileSize(local_path, &local_file_size);
1614 EXPECT_EQ(entry->file_info().size(), local_file_size); 1601 EXPECT_EQ(entry->file_info().size(), local_file_size);
1615 EXPECT_EQ(FILE_ERROR_OK, completion_error); 1602 EXPECT_EQ(FILE_ERROR_OK, completion_error);
1616 } 1603 }
1617 } 1604 }
1618 1605
1619 TEST_F(FileSystemTest, GetFileByResourceId_FromCache) { 1606 TEST_F(FileSystemTest, GetFileByResourceId_FromCache) {
1620 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1607 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1621 1608
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1986 entry->resource_id(), 1973 entry->resource_id(),
1987 entry->file_specific_info().file_md5(), 1974 entry->file_specific_info().file_md5(),
1988 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); 1975 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry));
1989 google_apis::test_util::RunBlockingPoolTask(); 1976 google_apis::test_util::RunBlockingPoolTask();
1990 1977
1991 EXPECT_TRUE(success); 1978 EXPECT_TRUE(success);
1992 EXPECT_FALSE(cache_entry.is_mounted()); 1979 EXPECT_FALSE(cache_entry.is_mounted());
1993 } 1980 }
1994 1981
1995 } // namespace drive 1982 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_interface.h ('k') | chrome/browser/chromeos/drive/resource_metadata.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698