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

Side by Side Diff: chrome/browser/google_apis/fake_drive_service_unittest.cc

Issue 14362022: Extract testing utility TestGetContentCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 | « no previous file | chrome/browser/google_apis/test_util.h » ('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 "chrome/browser/google_apis/fake_drive_service.h" 5 #include "chrome/browser/google_apis/fake_drive_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 test_util::CreateCopyResultCallback(&error, &about_resource)); 84 test_util::CreateCopyResultCallback(&error, &about_resource));
85 message_loop_.RunUntilIdle(); 85 message_loop_.RunUntilIdle();
86 return about_resource->largest_change_id(); 86 return about_resource->largest_change_id();
87 } 87 }
88 88
89 MessageLoopForUI message_loop_; 89 MessageLoopForUI message_loop_;
90 content::TestBrowserThread ui_thread_; 90 content::TestBrowserThread ui_thread_;
91 FakeDriveService fake_service_; 91 FakeDriveService fake_service_;
92 }; 92 };
93 93
94 void AppendGetContentCallbackResult(
95 std::vector<std::string>* values,
96 GDataErrorCode error,
97 scoped_ptr<std::string> content) {
98 DCHECK_EQ(error, HTTP_SUCCESS); // Should always HTTP_SUCCESS.
99 values->push_back(*content);
100 }
101
102 void AppendProgressCallbackResult(std::vector<int64>* values, int64 progress) { 94 void AppendProgressCallbackResult(std::vector<int64>* values, int64 progress) {
103 values->push_back(progress); 95 values->push_back(progress);
104 } 96 }
105 97
106 TEST_F(FakeDriveServiceTest, GetAllResourceList) { 98 TEST_F(FakeDriveServiceTest, GetAllResourceList) {
107 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( 99 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
108 "chromeos/gdata/root_feed.json")); 100 "chromeos/gdata/root_feed.json"));
109 101
110 GDataErrorCode error = GDATA_OTHER_ERROR; 102 GDataErrorCode error = GDATA_OTHER_ERROR;
111 scoped_ptr<ResourceList> resource_list; 103 scoped_ptr<ResourceList> resource_list;
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 base::ScopedTempDir temp_dir; 849 base::ScopedTempDir temp_dir;
858 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 850 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
859 851
860 std::vector<test_util::ProgressInfo> download_progress_values; 852 std::vector<test_util::ProgressInfo> download_progress_values;
861 853
862 const GURL kContentUrl("https://file_content_url/"); 854 const GURL kContentUrl("https://file_content_url/");
863 const base::FilePath kOutputFilePath = 855 const base::FilePath kOutputFilePath =
864 temp_dir.path().AppendASCII("whatever.txt"); 856 temp_dir.path().AppendASCII("whatever.txt");
865 GDataErrorCode error = GDATA_OTHER_ERROR; 857 GDataErrorCode error = GDATA_OTHER_ERROR;
866 base::FilePath output_file_path; 858 base::FilePath output_file_path;
867 std::vector<std::string> content_buffer; 859 test_util::TestGetContentCallback get_content_callback;
868 fake_service_.DownloadFile( 860 fake_service_.DownloadFile(
869 base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path 861 base::FilePath::FromUTF8Unsafe("/drive/whatever.txt"), // virtual path
870 kOutputFilePath, 862 kOutputFilePath,
871 kContentUrl, 863 kContentUrl,
872 test_util::CreateCopyResultCallback(&error, &output_file_path), 864 test_util::CreateCopyResultCallback(&error, &output_file_path),
873 base::Bind(&AppendGetContentCallbackResult, &content_buffer), 865 get_content_callback.callback(),
874 base::Bind(&test_util::AppendProgressCallbackResult, 866 base::Bind(&test_util::AppendProgressCallbackResult,
875 &download_progress_values)); 867 &download_progress_values));
876 message_loop_.RunUntilIdle(); 868 message_loop_.RunUntilIdle();
877 869
878 EXPECT_EQ(HTTP_SUCCESS, error); 870 EXPECT_EQ(HTTP_SUCCESS, error);
879 EXPECT_EQ(output_file_path, kOutputFilePath); 871 EXPECT_EQ(output_file_path, kOutputFilePath);
880 std::string content; 872 std::string content;
881 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); 873 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content));
882 // The content is "x"s of the file size specified in root_feed.json. 874 // The content is "x"s of the file size specified in root_feed.json.
883 EXPECT_EQ("xxxxxxxxxx", content); 875 EXPECT_EQ("xxxxxxxxxx", content);
884 ASSERT_TRUE(!download_progress_values.empty()); 876 ASSERT_TRUE(!download_progress_values.empty());
885 EXPECT_TRUE(base::STLIsSorted(download_progress_values)); 877 EXPECT_TRUE(base::STLIsSorted(download_progress_values));
886 EXPECT_GE(download_progress_values.front().first, 0); 878 EXPECT_GE(download_progress_values.front().first, 0);
887 EXPECT_LE(download_progress_values.back().first, 10); 879 EXPECT_LE(download_progress_values.back().first, 10);
888 880 EXPECT_EQ(content, get_content_callback.GetConcatenatedData());
889 std::string concatenated_content;
890 for (size_t i = 0; i < content_buffer.size(); ++i) {
891 concatenated_content += content_buffer[i];
892 }
893 EXPECT_EQ(content, concatenated_content);
894 } 881 }
895 882
896 TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) { 883 TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) {
897 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( 884 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
898 "chromeos/gdata/root_feed.json")); 885 "chromeos/gdata/root_feed.json"));
899 886
900 base::ScopedTempDir temp_dir; 887 base::ScopedTempDir temp_dir;
901 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 888 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
902 889
903 const GURL kContentUrl("https://non_existing_content_url/"); 890 const GURL kContentUrl("https://non_existing_content_url/");
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 test_util::CreateCopyResultCallback(&error, &resource_entry)); 1995 test_util::CreateCopyResultCallback(&error, &resource_entry));
2009 message_loop_.RunUntilIdle(); 1996 message_loop_.RunUntilIdle();
2010 1997
2011 EXPECT_EQ(GDATA_NO_CONNECTION, error); 1998 EXPECT_EQ(GDATA_NO_CONNECTION, error);
2012 EXPECT_FALSE(resource_entry); 1999 EXPECT_FALSE(resource_entry);
2013 } 2000 }
2014 2001
2015 } // namespace 2002 } // namespace
2016 2003
2017 } // namespace google_apis 2004 } // namespace google_apis
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/google_apis/test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698