| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "chrome/browser/chromeos/gdata/gdata_wapi_service.h" | 10 #include "chrome/browser/chromeos/gdata/gdata_wapi_service.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 protected: | 43 protected: |
| 44 FilePath GetTestCachedFilePath(const FilePath& file_name) { | 44 FilePath GetTestCachedFilePath(const FilePath& file_name) { |
| 45 return browser()->profile()->GetPath().Append(file_name); | 45 return browser()->profile()->GetPath().Append(file_name); |
| 46 } | 46 } |
| 47 | 47 |
| 48 net::TestServer gdata_test_server_; | 48 net::TestServer gdata_test_server_; |
| 49 scoped_ptr<gdata::GDataWapiService> service_; | 49 scoped_ptr<gdata::GDataWapiService> service_; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 // The test callback for GDataWapiService::DownloadFile(). | 52 // The test callback for GDataWapiService::DownloadFile(). |
| 53 void TestDownloadCallback(gdata::GDataErrorCode* result, | 53 void TestDownloadCallback(gdata::DriveErrorCode* result, |
| 54 std::string* contents, | 54 std::string* contents, |
| 55 gdata::GDataErrorCode error, | 55 gdata::DriveErrorCode error, |
| 56 const GURL& content_url, | 56 const GURL& content_url, |
| 57 const FilePath& temp_file) { | 57 const FilePath& temp_file) { |
| 58 *result = error; | 58 *result = error; |
| 59 file_util::ReadFileToString(temp_file, contents); | 59 file_util::ReadFileToString(temp_file, contents); |
| 60 file_util::Delete(temp_file, false); | 60 file_util::Delete(temp_file, false); |
| 61 MessageLoop::current()->Quit(); | 61 MessageLoop::current()->Quit(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // The test callback for GDataWapiService::GetDocuments(). | 64 // The test callback for GDataWapiService::GetDocuments(). |
| 65 void TestGetDocumentsCallback(gdata::GDataErrorCode* result_code, | 65 void TestGetDocumentsCallback(gdata::DriveErrorCode* result_code, |
| 66 base::Value** result_data, | 66 base::Value** result_data, |
| 67 gdata::GDataErrorCode error, | 67 gdata::DriveErrorCode error, |
| 68 scoped_ptr<base::Value> feed_data) { | 68 scoped_ptr<base::Value> feed_data) { |
| 69 *result_code = error; | 69 *result_code = error; |
| 70 *result_data = feed_data.release(); | 70 *result_data = feed_data.release(); |
| 71 MessageLoop::current()->Quit(); | 71 MessageLoop::current()->Quit(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 IN_PROC_BROWSER_TEST_F(GDataTest, Download) { | 76 IN_PROC_BROWSER_TEST_F(GDataTest, Download) { |
| 77 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; | 77 gdata::DriveErrorCode result = gdata::DRIVE_OTHER_ERROR; |
| 78 std::string contents; | 78 std::string contents; |
| 79 service_->DownloadFile( | 79 service_->DownloadFile( |
| 80 FilePath("/dummy/gdata/testfile.txt"), | 80 FilePath("/dummy/gdata/testfile.txt"), |
| 81 GetTestCachedFilePath(FilePath("cached_testfile.txt")), | 81 GetTestCachedFilePath(FilePath("cached_testfile.txt")), |
| 82 gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"), | 82 gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"), |
| 83 base::Bind(&TestDownloadCallback, &result, &contents), | 83 base::Bind(&TestDownloadCallback, &result, &contents), |
| 84 gdata::GetContentCallback()); | 84 gdata::GetContentCallback()); |
| 85 content::RunMessageLoop(); | 85 content::RunMessageLoop(); |
| 86 | 86 |
| 87 EXPECT_EQ(gdata::HTTP_SUCCESS, result); | 87 EXPECT_EQ(gdata::HTTP_SUCCESS, result); |
| 88 FilePath expected_filepath = gdata_test_server_.document_root().Append( | 88 FilePath expected_filepath = gdata_test_server_.document_root().Append( |
| 89 FilePath(FILE_PATH_LITERAL("chromeos/gdata/testfile.txt"))); | 89 FilePath(FILE_PATH_LITERAL("chromeos/gdata/testfile.txt"))); |
| 90 std::string expected_contents; | 90 std::string expected_contents; |
| 91 file_util::ReadFileToString(expected_filepath, &expected_contents); | 91 file_util::ReadFileToString(expected_filepath, &expected_contents); |
| 92 EXPECT_EQ(expected_contents, contents); | 92 EXPECT_EQ(expected_contents, contents); |
| 93 } | 93 } |
| 94 | 94 |
| 95 IN_PROC_BROWSER_TEST_F(GDataTest, NonExistingDownload) { | 95 IN_PROC_BROWSER_TEST_F(GDataTest, NonExistingDownload) { |
| 96 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; | 96 gdata::DriveErrorCode result = gdata::DRIVE_OTHER_ERROR; |
| 97 std::string dummy_contents; | 97 std::string dummy_contents; |
| 98 service_->DownloadFile( | 98 service_->DownloadFile( |
| 99 FilePath("/dummy/gdata/no-such-file.txt"), | 99 FilePath("/dummy/gdata/no-such-file.txt"), |
| 100 GetTestCachedFilePath(FilePath("cache_no-such-file.txt")), | 100 GetTestCachedFilePath(FilePath("cache_no-such-file.txt")), |
| 101 gdata_test_server_.GetURL("files/chromeos/gdata/no-such-file.txt"), | 101 gdata_test_server_.GetURL("files/chromeos/gdata/no-such-file.txt"), |
| 102 base::Bind(&TestDownloadCallback, &result, &dummy_contents), | 102 base::Bind(&TestDownloadCallback, &result, &dummy_contents), |
| 103 gdata::GetContentCallback()); | 103 gdata::GetContentCallback()); |
| 104 content::RunMessageLoop(); | 104 content::RunMessageLoop(); |
| 105 | 105 |
| 106 EXPECT_EQ(gdata::HTTP_NOT_FOUND, result); | 106 EXPECT_EQ(gdata::HTTP_NOT_FOUND, result); |
| 107 // Do not verify the not found message. | 107 // Do not verify the not found message. |
| 108 } | 108 } |
| 109 | 109 |
| 110 IN_PROC_BROWSER_TEST_F(GDataTest, GetDocuments) { | 110 IN_PROC_BROWSER_TEST_F(GDataTest, GetDocuments) { |
| 111 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; | 111 gdata::DriveErrorCode result = gdata::DRIVE_OTHER_ERROR; |
| 112 base::Value* result_data = NULL; | 112 base::Value* result_data = NULL; |
| 113 service_->GetDocuments( | 113 service_->GetDocuments( |
| 114 gdata_test_server_.GetURL("files/chromeos/gdata/root_feed.json"), | 114 gdata_test_server_.GetURL("files/chromeos/gdata/root_feed.json"), |
| 115 0, // start_changestamp | 115 0, // start_changestamp |
| 116 std::string(), // search string | 116 std::string(), // search string |
| 117 std::string(), // directory resource ID | 117 std::string(), // directory resource ID |
| 118 base::Bind(&TestGetDocumentsCallback, &result, &result_data)); | 118 base::Bind(&TestGetDocumentsCallback, &result, &result_data)); |
| 119 content::RunMessageLoop(); | 119 content::RunMessageLoop(); |
| 120 | 120 |
| 121 EXPECT_EQ(gdata::HTTP_SUCCESS, result); | 121 EXPECT_EQ(gdata::HTTP_SUCCESS, result); |
| 122 ASSERT_TRUE(result_data); | 122 ASSERT_TRUE(result_data); |
| 123 FilePath expected_filepath = gdata_test_server_.document_root().Append( | 123 FilePath expected_filepath = gdata_test_server_.document_root().Append( |
| 124 FilePath(FILE_PATH_LITERAL("chromeos/gdata/root_feed.json"))); | 124 FilePath(FILE_PATH_LITERAL("chromeos/gdata/root_feed.json"))); |
| 125 std::string expected_contents; | 125 std::string expected_contents; |
| 126 file_util::ReadFileToString(expected_filepath, &expected_contents); | 126 file_util::ReadFileToString(expected_filepath, &expected_contents); |
| 127 scoped_ptr<base::Value> expected_data( | 127 scoped_ptr<base::Value> expected_data( |
| 128 base::JSONReader::Read(expected_contents)); | 128 base::JSONReader::Read(expected_contents)); |
| 129 EXPECT_TRUE(base::Value::Equals(expected_data.get(), result_data)); | 129 EXPECT_TRUE(base::Value::Equals(expected_data.get(), result_data)); |
| 130 delete result_data; | 130 delete result_data; |
| 131 } | 131 } |
| 132 | 132 |
| 133 IN_PROC_BROWSER_TEST_F(GDataTest, GetDocumentsFailure) { | 133 IN_PROC_BROWSER_TEST_F(GDataTest, GetDocumentsFailure) { |
| 134 // testfile.txt exists but the response is not JSON, so it should | 134 // testfile.txt exists but the response is not JSON, so it should |
| 135 // emit a parse error instead. | 135 // emit a parse error instead. |
| 136 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; | 136 gdata::DriveErrorCode result = gdata::DRIVE_OTHER_ERROR; |
| 137 base::Value* result_data = NULL; | 137 base::Value* result_data = NULL; |
| 138 service_->GetDocuments( | 138 service_->GetDocuments( |
| 139 gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"), | 139 gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"), |
| 140 0, // start_changestamp | 140 0, // start_changestamp |
| 141 std::string(), // search string | 141 std::string(), // search string |
| 142 std::string(), // directory resource ID | 142 std::string(), // directory resource ID |
| 143 base::Bind(&TestGetDocumentsCallback, &result, &result_data)); | 143 base::Bind(&TestGetDocumentsCallback, &result, &result_data)); |
| 144 content::RunMessageLoop(); | 144 content::RunMessageLoop(); |
| 145 | 145 |
| 146 EXPECT_EQ(gdata::GDATA_PARSE_ERROR, result); | 146 EXPECT_EQ(gdata::DRIVE_PARSE_ERROR, result); |
| 147 EXPECT_FALSE(result_data); | 147 EXPECT_FALSE(result_data); |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace gdata | 150 } // namespace gdata |
| OLD | NEW |