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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/update_operation_unittest.cc

Issue 15989002: Add UpdateOperationTest for drive::file_system::UpdateOperationTest. (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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/drive/file_system/update_operation.h"
6
7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
8 #include "chrome/browser/google_apis/fake_drive_service.h"
9 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
10 #include "chrome/browser/google_apis/test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace drive {
14 namespace file_system {
15
16 class UpdateOperationTest : public OperationTestBase {
17 protected:
18 virtual void SetUp() OVERRIDE {
19 OperationTestBase::SetUp();
20 operation_.reset(
21 new UpdateOperation(observer(), scheduler(), metadata(), cache()));
22 }
23
24 virtual void TearDown() OVERRIDE {
25 operation_.reset();
26 OperationTestBase::TearDown();
27 }
28
29 scoped_ptr<UpdateOperation> operation_;
30 };
31
32 TEST_F(UpdateOperationTest, UpdateFileByResourceId_PersistentFile) {
33 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt"));
34 const std::string kResourceId("file:2_file_resource_id");
35 const std::string kMd5("3b4382ebefec6e743578c76bbd0575ce");
36
37 const base::FilePath kTestFile = temp_dir().Append(FILE_PATH_LITERAL("foo"));
38 const std::string kTestFileContent = "I'm being uploaded! Yay!";
39 google_apis::test_util::WriteStringToFile(kTestFile, kTestFileContent);
40
41 // Pin the file so it'll be store in "persistent" directory.
42 FileError error = FILE_ERROR_OK;
43 cache()->PinOnUIThread(
44 kResourceId, kMd5,
45 google_apis::test_util::CreateCopyResultCallback(&error));
46 google_apis::test_util::RunBlockingPoolTask();
47 EXPECT_EQ(FILE_ERROR_OK, error);
48
49 // First store a file to cache.
50 cache()->StoreOnUIThread(
hidehiko 2013/05/24 12:45:42 nit: How about reassign a value other than FILE_ER
kinaba 2013/05/27 01:33:52 Good catch! Done.
51 kResourceId, kMd5, kTestFile,
52 internal::FileCache::FILE_OPERATION_COPY,
53 google_apis::test_util::CreateCopyResultCallback(&error));
54 google_apis::test_util::RunBlockingPoolTask();
55 EXPECT_EQ(FILE_ERROR_OK, error);
56
57 // Add the dirty bit.
58 cache()->MarkDirtyOnUIThread(
59 kResourceId, kMd5,
60 google_apis::test_util::CreateCopyResultCallback(&error));
61 google_apis::test_util::RunBlockingPoolTask();
62 EXPECT_EQ(FILE_ERROR_OK, error);
63
64 // Commit the dirty bit.
65 cache()->CommitDirtyOnUIThread(
66 kResourceId, kMd5,
67 google_apis::test_util::CreateCopyResultCallback(&error));
68 google_apis::test_util::RunBlockingPoolTask();
69 EXPECT_EQ(FILE_ERROR_OK, error);
70
71 int64 original_changestamp = fake_service()->largest_changestamp();
72
73 // The callback will be called upon completion of
74 // UpdateFileByResourceId().
75 operation_->UpdateFileByResourceId(
76 kResourceId,
77 DriveClientContext(USER_INITIATED),
78 google_apis::test_util::CreateCopyResultCallback(&error));
79 google_apis::test_util::RunBlockingPoolTask();
80 EXPECT_EQ(FILE_ERROR_OK, error);
81
82 // Check that the server has received an update.
83 EXPECT_LT(original_changestamp, fake_service()->largest_changestamp());
84
85 // Check that the file size is updated to that of the updated content.
86 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR;
87 scoped_ptr<google_apis::ResourceEntry> server_entry;
88 fake_service()->GetResourceEntry(
89 kResourceId,
90 google_apis::test_util::CreateCopyResultCallback(&gdata_error,
91 &server_entry));
92 google_apis::test_util::RunBlockingPoolTask();
93 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error);
94 EXPECT_EQ(static_cast<int64>(kTestFileContent.size()),
95 server_entry->file_size());
96 }
97
98 TEST_F(UpdateOperationTest, UpdateFileByResourceId_NonexistentFile) {
99 FileError error = FILE_ERROR_OK;
100 operation_->UpdateFileByResourceId(
101 "file:nonexistent_resource_id",
102 DriveClientContext(USER_INITIATED),
103 google_apis::test_util::CreateCopyResultCallback(&error));
104 google_apis::test_util::RunBlockingPoolTask();
105 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
106 }
107
108 } // namespace file_system
109 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/operation_test_base.h ('k') | chrome/browser/chromeos/drive/file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698