diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-07 18:19:17 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-07 18:19:17 +0000 |
commit | e0cddf658dbe07f9c981590b6dcd92a0288902c1 (patch) | |
tree | 152e79c2286f569748a7c55daa59a7265d19d6c1 | |
parent | 1dc61f9cf567addf043d7d402a4f93ad6091d4a1 (diff) | |
download | chromium_src-e0cddf658dbe07f9c981590b6dcd92a0288902c1.zip chromium_src-e0cddf658dbe07f9c981590b6dcd92a0288902c1.tar.gz chromium_src-e0cddf658dbe07f9c981590b6dcd92a0288902c1.tar.bz2 |
gdata: Add a missing file.
Should have been included in crrev.com/125404
BUG=none
TEST=browser_tests built
Review URL: https://chromiumcodereview.appspot.com/9620011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125410 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/chromeos/gdata/gdata_browsertest.cc | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/gdata/gdata_browsertest.cc b/chrome/browser/chromeos/gdata/gdata_browsertest.cc new file mode 100644 index 0000000..a3b463b --- /dev/null +++ b/chrome/browser/chromeos/gdata/gdata_browsertest.cc @@ -0,0 +1,124 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "base/bind.h" +#include "base/command_line.h" +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/json/json_reader.h" +#include "chrome/browser/chromeos/gdata/gdata.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "chrome/test/base/ui_test_utils.h" +#include "net/test/test_server.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +class GDataTest : public InProcessBrowserTest { + public: + GDataTest() + : InProcessBrowserTest(), + gdata_test_server_(net::TestServer::TYPE_GDATA, + net::TestServer::kLocalhost, + FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { + } + + virtual void SetUpOnMainThread() OVERRIDE { + ASSERT_TRUE(gdata_test_server_.Start()); + service_.Initialize(browser()->profile()); + service_.gdata_auth_service()->set_oauth2_auth_token_for_testing( + net::TestServer::kGDataAuthToken); + } + + protected: + net::TestServer gdata_test_server_; + gdata::DocumentsService service_; +}; + +// The test callback for DocumentsService::DownloadFile(). +void TestDownloadCallback(gdata::GDataErrorCode* result, + std::string* contents, + gdata::GDataErrorCode error, + const GURL& content_url, + const FilePath& temp_file) { + *result = error; + file_util::ReadFileToString(temp_file, contents); + file_util::Delete(temp_file, false); + MessageLoop::current()->Quit(); +} + +// The test callback for DocumentsService::GetDocuments(). +void TestGetDocumentsCallback(gdata::GDataErrorCode* result_code, + base::Value** result_data, + gdata::GDataErrorCode error, + base::Value* feed_data) { + *result_code = error; + *result_data = feed_data; + MessageLoop::current()->Quit(); +} + +} // namespace + +IN_PROC_BROWSER_TEST_F(GDataTest, Download) { + gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; + std::string contents; + service_.DownloadFile( + gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"), + base::Bind(&TestDownloadCallback, &result, &contents)); + ui_test_utils::RunMessageLoop(); + + EXPECT_EQ(gdata::HTTP_SUCCESS, result); + FilePath expected_filepath = gdata_test_server_.document_root().Append( + FilePath(FILE_PATH_LITERAL("chromeos/gdata/testfile.txt"))); + std::string expected_contents; + file_util::ReadFileToString(expected_filepath, &expected_contents); + EXPECT_EQ(expected_contents, contents); +} + +IN_PROC_BROWSER_TEST_F(GDataTest, NonExistingDownload) { + gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; + std::string dummy_contents; + service_.DownloadFile( + gdata_test_server_.GetURL("files/chromeos/gdata/no-such-file.txt"), + base::Bind(&TestDownloadCallback, &result, &dummy_contents)); + ui_test_utils::RunMessageLoop(); + + EXPECT_EQ(gdata::HTTP_NOT_FOUND, result); + // Do not verify the not found message. +} + +IN_PROC_BROWSER_TEST_F(GDataTest, GetDocuments) { + gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; + base::Value* result_data = NULL; + service_.GetDocuments( + gdata_test_server_.GetURL("files/chromeos/gdata/root_feed.json"), + base::Bind(&TestGetDocumentsCallback, &result, &result_data)); + ui_test_utils::RunMessageLoop(); + + EXPECT_EQ(gdata::HTTP_SUCCESS, result); + ASSERT_TRUE(result_data); + FilePath expected_filepath = gdata_test_server_.document_root().Append( + FilePath(FILE_PATH_LITERAL("chromeos/gdata/root_feed.json"))); + std::string expected_contents; + file_util::ReadFileToString(expected_filepath, &expected_contents); + scoped_ptr<base::Value> expected_data( + base::JSONReader::Read(expected_contents, false)); + EXPECT_TRUE(base::Value::Equals(expected_data.get(), result_data)); + delete result_data; +} + +IN_PROC_BROWSER_TEST_F(GDataTest, GetDocumentsFailure) { + // testfile.txt exists but the response is not JSON, so it should + // emit a parse error instead. + gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; + base::Value* result_data = NULL; + service_.GetDocuments( + gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"), + base::Bind(&TestGetDocumentsCallback, &result, &result_data)); + ui_test_utils::RunMessageLoop(); + + EXPECT_EQ(gdata::GDATA_PARSE_ERROR, result); + EXPECT_FALSE(result_data); +} |