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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_documents_service_browsertest.cc

Issue 9742002: Wired GDataFileSystem::GetFile() method with internal cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 9 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 "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_documents_service.h" 10 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
11 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
12 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
14 #include "net/test/test_server.h" 15 #include "net/test/test_server.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace { 18 namespace {
18 19
19 class GDataTest : public InProcessBrowserTest { 20 class GDataTest : public InProcessBrowserTest {
20 public: 21 public:
21 GDataTest() 22 GDataTest()
22 : InProcessBrowserTest(), 23 : InProcessBrowserTest(),
23 gdata_test_server_(net::TestServer::TYPE_GDATA, 24 gdata_test_server_(net::TestServer::TYPE_GDATA,
24 net::TestServer::kLocalhost, 25 net::TestServer::kLocalhost,
25 FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { 26 FilePath(FILE_PATH_LITERAL("chrome/test/data"))) {
26 } 27 }
27 28
28 virtual void SetUpOnMainThread() OVERRIDE { 29 virtual void SetUpOnMainThread() OVERRIDE {
29 ASSERT_TRUE(gdata_test_server_.Start()); 30 ASSERT_TRUE(gdata_test_server_.Start());
30 service_.reset(new gdata::DocumentsService); 31 service_.reset(new gdata::DocumentsService);
31 service_->Initialize(browser()->profile()); 32 service_->Initialize(browser()->profile());
32 service_->gdata_auth_service()->set_oauth2_auth_token_for_testing( 33 service_->gdata_auth_service()->set_oauth2_auth_token_for_testing(
33 net::TestServer::kGDataAuthToken); 34 net::TestServer::kGDataAuthToken);
34 } 35 }
35 36
36 protected: 37 protected:
38 FilePath GetTestCachedFilePath(const FilePath& file_name) {
39 return browser()->profile()->GetPath().Append(file_name);
40 }
41
37 net::TestServer gdata_test_server_; 42 net::TestServer gdata_test_server_;
38 scoped_ptr<gdata::DocumentsService> service_; 43 scoped_ptr<gdata::DocumentsService> service_;
39 }; 44 };
40 45
41 // The test callback for DocumentsService::DownloadFile(). 46 // The test callback for DocumentsService::DownloadFile().
42 void TestDownloadCallback(gdata::GDataErrorCode* result, 47 void TestDownloadCallback(gdata::GDataErrorCode* result,
43 std::string* contents, 48 std::string* contents,
44 gdata::GDataErrorCode error, 49 gdata::GDataErrorCode error,
45 const GURL& content_url, 50 const GURL& content_url,
46 const FilePath& temp_file) { 51 const FilePath& temp_file) {
(...skipping 13 matching lines...) Expand all
60 MessageLoop::current()->Quit(); 65 MessageLoop::current()->Quit();
61 } 66 }
62 67
63 } // namespace 68 } // namespace
64 69
65 IN_PROC_BROWSER_TEST_F(GDataTest, Download) { 70 IN_PROC_BROWSER_TEST_F(GDataTest, Download) {
66 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; 71 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR;
67 std::string contents; 72 std::string contents;
68 service_->DownloadFile( 73 service_->DownloadFile(
69 FilePath("/dummy/gdata/testfile.txt"), 74 FilePath("/dummy/gdata/testfile.txt"),
75 GetTestCachedFilePath(FilePath("cached_testfile.txt")),
70 gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"), 76 gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"),
71 base::Bind(&TestDownloadCallback, &result, &contents)); 77 base::Bind(&TestDownloadCallback, &result, &contents));
72 ui_test_utils::RunMessageLoop(); 78 ui_test_utils::RunMessageLoop();
73 79
74 EXPECT_EQ(gdata::HTTP_SUCCESS, result); 80 EXPECT_EQ(gdata::HTTP_SUCCESS, result);
75 FilePath expected_filepath = gdata_test_server_.document_root().Append( 81 FilePath expected_filepath = gdata_test_server_.document_root().Append(
76 FilePath(FILE_PATH_LITERAL("chromeos/gdata/testfile.txt"))); 82 FilePath(FILE_PATH_LITERAL("chromeos/gdata/testfile.txt")));
77 std::string expected_contents; 83 std::string expected_contents;
78 file_util::ReadFileToString(expected_filepath, &expected_contents); 84 file_util::ReadFileToString(expected_filepath, &expected_contents);
79 EXPECT_EQ(expected_contents, contents); 85 EXPECT_EQ(expected_contents, contents);
80 } 86 }
81 87
82 IN_PROC_BROWSER_TEST_F(GDataTest, NonExistingDownload) { 88 IN_PROC_BROWSER_TEST_F(GDataTest, NonExistingDownload) {
83 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; 89 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR;
84 std::string dummy_contents; 90 std::string dummy_contents;
85 service_->DownloadFile( 91 service_->DownloadFile(
86 FilePath("/dummy/gdata/no-such-file.txt"), 92 FilePath("/dummy/gdata/no-such-file.txt"),
93 GetTestCachedFilePath(FilePath("cache_no-such-file.txt")),
87 gdata_test_server_.GetURL("files/chromeos/gdata/no-such-file.txt"), 94 gdata_test_server_.GetURL("files/chromeos/gdata/no-such-file.txt"),
88 base::Bind(&TestDownloadCallback, &result, &dummy_contents)); 95 base::Bind(&TestDownloadCallback, &result, &dummy_contents));
89 ui_test_utils::RunMessageLoop(); 96 ui_test_utils::RunMessageLoop();
90 97
91 EXPECT_EQ(gdata::HTTP_NOT_FOUND, result); 98 EXPECT_EQ(gdata::HTTP_NOT_FOUND, result);
92 // Do not verify the not found message. 99 // Do not verify the not found message.
93 } 100 }
94 101
95 IN_PROC_BROWSER_TEST_F(GDataTest, GetDocuments) { 102 IN_PROC_BROWSER_TEST_F(GDataTest, GetDocuments) {
96 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; 103 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR;
(...skipping 21 matching lines...) Expand all
118 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR; 125 gdata::GDataErrorCode result = gdata::GDATA_OTHER_ERROR;
119 base::Value* result_data = NULL; 126 base::Value* result_data = NULL;
120 service_->GetDocuments( 127 service_->GetDocuments(
121 gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"), 128 gdata_test_server_.GetURL("files/chromeos/gdata/testfile.txt"),
122 base::Bind(&TestGetDocumentsCallback, &result, &result_data)); 129 base::Bind(&TestGetDocumentsCallback, &result, &result_data));
123 ui_test_utils::RunMessageLoop(); 130 ui_test_utils::RunMessageLoop();
124 131
125 EXPECT_EQ(gdata::GDATA_PARSE_ERROR, result); 132 EXPECT_EQ(gdata::GDATA_PARSE_ERROR, result);
126 EXPECT_FALSE(result_data); 133 EXPECT_FALSE(result_data);
127 } 134 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_documents_service.cc ('k') | chrome/browser/chromeos/gdata/gdata_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698