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

Side by Side Diff: webkit/fileapi/local_file_system_operation_unittest.cc

Issue 10915202: Cleanup: merge MockQuotaManager in multiple places (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase2 Created 8 years, 3 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 | « webkit/appcache/appcache_storage_unittest.cc ('k') | webkit/quota/mock_quota_manager.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 "webkit/fileapi/local_file_system_operation.h" 5 #include "webkit/fileapi/local_file_system_operation.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/scoped_temp_dir.h" 12 #include "base/scoped_temp_dir.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webkit/blob/shareable_file_reference.h" 16 #include "webkit/blob/shareable_file_reference.h"
17 #include "webkit/fileapi/file_system_context.h" 17 #include "webkit/fileapi/file_system_context.h"
18 #include "webkit/fileapi/file_system_file_util.h" 18 #include "webkit/fileapi/file_system_file_util.h"
19 #include "webkit/fileapi/file_system_mount_point_provider.h" 19 #include "webkit/fileapi/file_system_mount_point_provider.h"
20 #include "webkit/fileapi/file_system_quota_util.h" 20 #include "webkit/fileapi/file_system_quota_util.h"
21 #include "webkit/fileapi/file_system_util.h" 21 #include "webkit/fileapi/file_system_util.h"
22 #include "webkit/fileapi/file_util_helper.h" 22 #include "webkit/fileapi/file_util_helper.h"
23 #include "webkit/fileapi/local_file_system_test_helper.h" 23 #include "webkit/fileapi/local_file_system_test_helper.h"
24 #include "webkit/fileapi/mock_file_change_observer.h" 24 #include "webkit/fileapi/mock_file_change_observer.h"
25 #include "webkit/quota/quota_manager.h" 25 #include "webkit/quota/quota_manager.h"
26 #include "webkit/quota/mock_quota_manager.h"
26 27
27 using quota::QuotaClient;
28 using quota::QuotaManager; 28 using quota::QuotaManager;
29 using quota::QuotaManagerProxy; 29 using quota::QuotaManagerProxy;
30 using quota::StorageType;
31 using webkit_blob::ShareableFileReference; 30 using webkit_blob::ShareableFileReference;
32 31
33 namespace fileapi { 32 namespace fileapi {
34 33
35 namespace { 34 namespace {
36 35
37 const int kFileOperationStatusNotSet = 1; 36 const int kFileOperationStatusNotSet = 1;
38 37
39 void AssertFileErrorEq(base::PlatformFileError expected, 38 void AssertFileErrorEq(base::PlatformFileError expected,
40 base::PlatformFileError actual) { 39 base::PlatformFileError actual) {
41 ASSERT_EQ(expected, actual); 40 ASSERT_EQ(expected, actual);
42 } 41 }
43 42
44 class MockQuotaManager : public QuotaManager {
45 public:
46 MockQuotaManager(const FilePath& base_dir,
47 const GURL& origin,
48 StorageType type)
49 : QuotaManager(false /* is_incognito */, base_dir,
50 base::MessageLoopProxy::current(),
51 base::MessageLoopProxy::current(),
52 NULL),
53 origin_(origin),
54 type_(type),
55 usage_(0),
56 quota_(kint64max),
57 accessed_(0) {}
58
59 virtual void GetUsageAndQuota(
60 const GURL& origin, quota::StorageType type,
61 const GetUsageAndQuotaCallback& callback) OVERRIDE {
62 EXPECT_EQ(origin_, origin);
63 EXPECT_EQ(type_, type);
64 callback.Run(quota::kQuotaStatusOk, usage_, quota_);
65 }
66
67 protected:
68 virtual ~MockQuotaManager() {}
69
70 private:
71 friend class MockQuotaManagerProxy;
72
73 void SetQuota(const GURL& origin, StorageType type, int64 quota) {
74 EXPECT_EQ(origin_, origin);
75 EXPECT_EQ(type_, type);
76 quota_ = quota;
77 }
78
79 void RecordStorageAccessed(const GURL& origin, StorageType type) {
80 EXPECT_EQ(origin_, origin);
81 EXPECT_EQ(type_, type);
82 ++accessed_;
83 }
84
85 void UpdateUsage(const GURL& origin, StorageType type, int64 delta) {
86 EXPECT_EQ(origin_, origin);
87 EXPECT_EQ(type_, type);
88 usage_ += delta;
89 }
90
91 const GURL& origin_;
92 const StorageType type_;
93 int64 usage_;
94 int64 quota_;
95 int accessed_;
96 };
97
98 class MockQuotaManagerProxy : public QuotaManagerProxy {
99 public:
100 explicit MockQuotaManagerProxy(QuotaManager* quota_manager)
101 : QuotaManagerProxy(quota_manager,
102 base::MessageLoopProxy::current()),
103 registered_client_(NULL) {
104 }
105
106 virtual void RegisterClient(QuotaClient* client) OVERRIDE {
107 EXPECT_FALSE(registered_client_);
108 registered_client_ = client;
109 }
110
111 void SimulateQuotaManagerDestroyed() {
112 if (registered_client_) {
113 // We cannot call this in the destructor as the client (indirectly)
114 // holds a refptr of the proxy.
115 registered_client_->OnQuotaManagerDestroyed();
116 registered_client_ = NULL;
117 }
118 }
119
120 // We don't mock them.
121 virtual void NotifyOriginInUse(const GURL& origin) OVERRIDE {}
122 virtual void NotifyOriginNoLongerInUse(const GURL& origin) OVERRIDE {}
123
124 virtual void NotifyStorageAccessed(QuotaClient::ID client_id,
125 const GURL& origin,
126 StorageType type) OVERRIDE {
127 mock_manager()->RecordStorageAccessed(origin, type);
128 }
129
130 virtual void NotifyStorageModified(QuotaClient::ID client_id,
131 const GURL& origin,
132 StorageType type,
133 int64 delta) OVERRIDE {
134 mock_manager()->UpdateUsage(origin, type, delta);
135 }
136
137 int storage_accessed_count() const {
138 return mock_manager()->accessed_;
139 }
140
141 void SetQuota(const GURL& origin, StorageType type, int64 quota) {
142 mock_manager()->SetQuota(origin, type, quota);
143 }
144
145 protected:
146 virtual ~MockQuotaManagerProxy() {
147 EXPECT_FALSE(registered_client_);
148 }
149
150 private:
151 MockQuotaManager* mock_manager() const {
152 return static_cast<MockQuotaManager*>(quota_manager());
153 }
154
155 QuotaClient* registered_client_;
156 };
157
158 FilePath ASCIIToFilePath(const std::string& str) { 43 FilePath ASCIIToFilePath(const std::string& str) {
159 return FilePath().AppendASCII(str); 44 return FilePath().AppendASCII(str);
160 } 45 }
161 46
162 } // namespace (anonymous) 47 } // namespace (anonymous)
163 48
164 // Test class for LocalFileSystemOperation. 49 // Test class for LocalFileSystemOperation.
165 class LocalFileSystemOperationTest 50 class LocalFileSystemOperationTest
166 : public testing::Test, 51 : public testing::Test,
167 public base::SupportsWeakPtr<LocalFileSystemOperationTest> { 52 public base::SupportsWeakPtr<LocalFileSystemOperationTest> {
(...skipping 17 matching lines...) Expand all
185 return shareable_file_ref_; 70 return shareable_file_ref_;
186 } 71 }
187 72
188 virtual void SetUp() OVERRIDE; 73 virtual void SetUp() OVERRIDE;
189 virtual void TearDown() OVERRIDE; 74 virtual void TearDown() OVERRIDE;
190 75
191 protected: 76 protected:
192 // Common temp base for nondestructive uses. 77 // Common temp base for nondestructive uses.
193 ScopedTempDir base_; 78 ScopedTempDir base_;
194 79
195 MockQuotaManagerProxy* quota_manager_proxy() { 80 quota::MockQuotaManager* quota_manager() {
196 return static_cast<MockQuotaManagerProxy*>(quota_manager_proxy_.get()); 81 return static_cast<quota::MockQuotaManager*>(quota_manager_.get());
82 }
83
84 quota::MockQuotaManagerProxy* quota_manager_proxy() {
85 return static_cast<quota::MockQuotaManagerProxy*>(
86 quota_manager_proxy_.get());
197 } 87 }
198 88
199 FileSystemFileUtil* file_util() { 89 FileSystemFileUtil* file_util() {
200 return test_helper_.file_util(); 90 return test_helper_.file_util();
201 } 91 }
202 92
203 const ChangeObserverList& change_observers() const { 93 const ChangeObserverList& change_observers() const {
204 return change_observers_; 94 return change_observers_;
205 } 95 }
206 96
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 MessageLoop::current()->RunAllPending(); 253 MessageLoop::current()->RunAllPending();
364 254
365 int64 total_usage; 255 int64 total_usage;
366 GetUsageAndQuota(&total_usage, NULL); 256 GetUsageAndQuota(&total_usage, NULL);
367 *path_cost = total_usage - base_usage; 257 *path_cost = total_usage - base_usage;
368 } 258 }
369 259
370 void GrantQuotaForCurrentUsage() { 260 void GrantQuotaForCurrentUsage() {
371 int64 usage; 261 int64 usage;
372 GetUsageAndQuota(&usage, NULL); 262 GetUsageAndQuota(&usage, NULL);
373 quota_manager_proxy()->SetQuota(test_helper_.origin(), 263 quota_manager()->SetQuota(test_helper_.origin(),
374 test_helper_.storage_type(), 264 test_helper_.storage_type(),
375 usage); 265 usage);
376 } 266 }
377 267
378 void AddQuota(int64 quota_delta) { 268 void AddQuota(int64 quota_delta) {
379 int64 quota; 269 int64 quota;
380 GetUsageAndQuota(NULL, &quota); 270 GetUsageAndQuota(NULL, &quota);
381 quota_manager_proxy()->SetQuota(test_helper_.origin(), 271 quota_manager()->SetQuota(test_helper_.origin(),
382 test_helper_.storage_type(), 272 test_helper_.storage_type(),
383 quota + quota_delta); 273 quota + quota_delta);
384 } 274 }
385 275
386 // For post-operation status. 276 // For post-operation status.
387 int status_; 277 int status_;
388 base::PlatformFileInfo info_; 278 base::PlatformFileInfo info_;
389 FilePath path_; 279 FilePath path_;
390 std::vector<base::FileUtilProxy::Entry> entries_; 280 std::vector<base::FileUtilProxy::Entry> entries_;
391 scoped_refptr<ShareableFileReference> shareable_file_ref_; 281 scoped_refptr<ShareableFileReference> shareable_file_ref_;
392 282
393 private: 283 private:
394 MessageLoop message_loop_; 284 MessageLoop message_loop_;
395 scoped_refptr<QuotaManager> quota_manager_; 285 scoped_refptr<QuotaManager> quota_manager_;
396 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_; 286 scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
397 287
398 MockFileChangeObserver change_observer_; 288 MockFileChangeObserver change_observer_;
399 ChangeObserverList change_observers_; 289 ChangeObserverList change_observers_;
400 290
401 int next_unique_path_suffix_; 291 int next_unique_path_suffix_;
402 292
403 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperationTest); 293 DISALLOW_COPY_AND_ASSIGN(LocalFileSystemOperationTest);
404 }; 294 };
405 295
406 void LocalFileSystemOperationTest::SetUp() { 296 void LocalFileSystemOperationTest::SetUp() {
407 FilePath base_dir = base_.path().AppendASCII("filesystem"); 297 FilePath base_dir = base_.path().AppendASCII("filesystem");
408 quota_manager_ = new MockQuotaManager( 298 quota_manager_ = new quota::MockQuotaManager(
409 base_dir, test_helper_.origin(), test_helper_.storage_type()); 299 false /* is_incognito */, base_dir,
410 quota_manager_proxy_ = new MockQuotaManagerProxy(quota_manager_.get()); 300 base::MessageLoopProxy::current(),
301 base::MessageLoopProxy::current(),
302 NULL /* special storage policy */);
303 quota_manager_proxy_ = new quota::MockQuotaManagerProxy(
304 quota_manager(),
305 base::MessageLoopProxy::current());
411 test_helper_.SetUp(base_dir, 306 test_helper_.SetUp(base_dir,
412 false /* unlimited quota */, 307 false /* unlimited quota */,
413 quota_manager_proxy_.get(), 308 quota_manager_proxy_.get(),
414 NULL); 309 NULL);
415 } 310 }
416 311
417 void LocalFileSystemOperationTest::TearDown() { 312 void LocalFileSystemOperationTest::TearDown() {
418 // Let the client go away before dropping a ref of the quota manager proxy. 313 // Let the client go away before dropping a ref of the quota manager proxy.
419 quota_manager_proxy()->SimulateQuotaManagerDestroyed(); 314 quota_manager_proxy()->SimulateQuotaManagerDestroyed();
420 quota_manager_ = NULL; 315 quota_manager_ = NULL;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 MessageLoop::current()->RunAllPending(); 407 MessageLoop::current()->RunAllPending();
513 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 408 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
514 EXPECT_TRUE(FileExists(dest_file_path)); 409 EXPECT_TRUE(FileExists(dest_file_path));
515 410
516 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 411 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
517 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); 412 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
518 EXPECT_TRUE(change_observer()->HasNoChange()); 413 EXPECT_TRUE(change_observer()->HasNoChange());
519 414
520 // Move is considered 'write' access (for both side), and won't be counted 415 // Move is considered 'write' access (for both side), and won't be counted
521 // as read access. 416 // as read access.
522 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); 417 EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count());
523 } 418 }
524 419
525 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { 420 TEST_F(LocalFileSystemOperationTest, TestMoveSuccessSrcFileAndNew) {
526 FilePath src_dir_path(CreateUniqueDir()); 421 FilePath src_dir_path(CreateUniqueDir());
527 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); 422 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path));
528 FilePath dest_dir_path(CreateUniqueDir()); 423 FilePath dest_dir_path(CreateUniqueDir());
529 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); 424 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile")));
530 425
531 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path), 426 operation()->Move(URLForPath(src_file_path), URLForPath(dest_file_path),
532 RecordStatusCallback()); 427 RecordStatusCallback());
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 FilePath src_dir_path(CreateUniqueDir()); 607 FilePath src_dir_path(CreateUniqueDir());
713 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); 608 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path));
714 FilePath dest_dir_path(CreateUniqueDir()); 609 FilePath dest_dir_path(CreateUniqueDir());
715 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path)); 610 FilePath dest_file_path(CreateUniqueFileInDir(dest_dir_path));
716 611
717 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), 612 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path),
718 RecordStatusCallback()); 613 RecordStatusCallback());
719 MessageLoop::current()->RunAllPending(); 614 MessageLoop::current()->RunAllPending();
720 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 615 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
721 EXPECT_TRUE(FileExists(dest_file_path)); 616 EXPECT_TRUE(FileExists(dest_file_path));
722 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 617 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
723 618
724 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); 619 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
725 EXPECT_TRUE(change_observer()->HasNoChange()); 620 EXPECT_TRUE(change_observer()->HasNoChange());
726 } 621 }
727 622
728 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndNew) { 623 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcFileAndNew) {
729 FilePath src_dir_path(CreateUniqueDir()); 624 FilePath src_dir_path(CreateUniqueDir());
730 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path)); 625 FilePath src_file_path(CreateUniqueFileInDir(src_dir_path));
731 FilePath dest_dir_path(CreateUniqueDir()); 626 FilePath dest_dir_path(CreateUniqueDir());
732 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile"))); 627 FilePath dest_file_path(dest_dir_path.Append(FILE_PATH_LITERAL("NewFile")));
733 628
734 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path), 629 operation()->Copy(URLForPath(src_file_path), URLForPath(dest_file_path),
735 RecordStatusCallback()); 630 RecordStatusCallback());
736 MessageLoop::current()->RunAllPending(); 631 MessageLoop::current()->RunAllPending();
737 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 632 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
738 EXPECT_TRUE(FileExists(dest_file_path)); 633 EXPECT_TRUE(FileExists(dest_file_path));
739 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 634 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
740 635
741 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); 636 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count());
742 EXPECT_TRUE(change_observer()->HasNoChange()); 637 EXPECT_TRUE(change_observer()->HasNoChange());
743 } 638 }
744 639
745 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { 640 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) {
746 FilePath src_dir_path(CreateUniqueDir()); 641 FilePath src_dir_path(CreateUniqueDir());
747 FilePath dest_dir_path(CreateUniqueDir()); 642 FilePath dest_dir_path(CreateUniqueDir());
748 643
749 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), 644 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path),
750 RecordStatusCallback()); 645 RecordStatusCallback());
751 MessageLoop::current()->RunAllPending(); 646 MessageLoop::current()->RunAllPending();
752 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 647 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
753 648
754 // Make sure we've overwritten but not copied the source under the |dest_dir|. 649 // Make sure we've overwritten but not copied the source under the |dest_dir|.
755 EXPECT_TRUE(DirectoryExists(dest_dir_path)); 650 EXPECT_TRUE(DirectoryExists(dest_dir_path));
756 EXPECT_FALSE(DirectoryExists( 651 EXPECT_FALSE(DirectoryExists(
757 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path)))); 652 dest_dir_path.Append(VirtualPath::BaseName(src_dir_path))));
758 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 653 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
759 654
760 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 655 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
761 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 656 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
762 EXPECT_TRUE(change_observer()->HasNoChange()); 657 EXPECT_TRUE(change_observer()->HasNoChange());
763 } 658 }
764 659
765 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndNew) { 660 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirAndNew) {
766 FilePath src_dir_path(CreateUniqueDir()); 661 FilePath src_dir_path(CreateUniqueDir());
767 FilePath dest_parent_dir_path(CreateUniqueDir()); 662 FilePath dest_parent_dir_path(CreateUniqueDir());
768 FilePath dest_child_dir_path(dest_parent_dir_path. 663 FilePath dest_child_dir_path(dest_parent_dir_path.
769 Append(FILE_PATH_LITERAL("NewDirectory"))); 664 Append(FILE_PATH_LITERAL("NewDirectory")));
770 665
771 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path), 666 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_child_dir_path),
772 RecordStatusCallback()); 667 RecordStatusCallback());
773 MessageLoop::current()->RunAllPending(); 668 MessageLoop::current()->RunAllPending();
774 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 669 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
775 EXPECT_TRUE(DirectoryExists(dest_child_dir_path)); 670 EXPECT_TRUE(DirectoryExists(dest_child_dir_path));
776 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 671 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
777 672
778 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); 673 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
779 EXPECT_TRUE(change_observer()->HasNoChange()); 674 EXPECT_TRUE(change_observer()->HasNoChange());
780 } 675 }
781 676
782 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirRecursive) { 677 TEST_F(LocalFileSystemOperationTest, TestCopySuccessSrcDirRecursive) {
783 FilePath src_dir_path(CreateUniqueDir()); 678 FilePath src_dir_path(CreateUniqueDir());
784 FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path)); 679 FilePath child_dir_path(CreateUniqueDirInDir(src_dir_path));
785 FilePath grandchild_file_path( 680 FilePath grandchild_file_path(
786 CreateUniqueFileInDir(child_dir_path)); 681 CreateUniqueFileInDir(child_dir_path));
787 682
788 FilePath dest_dir_path(CreateUniqueDir()); 683 FilePath dest_dir_path(CreateUniqueDir());
789 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path), 684 operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir_path),
790 RecordStatusCallback()); 685 RecordStatusCallback());
791 MessageLoop::current()->RunAllPending(); 686 MessageLoop::current()->RunAllPending();
792 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 687 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
793 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append( 688 EXPECT_TRUE(DirectoryExists(dest_dir_path.Append(
794 VirtualPath::BaseName(child_dir_path)))); 689 VirtualPath::BaseName(child_dir_path))));
795 EXPECT_TRUE(FileExists(dest_dir_path.Append( 690 EXPECT_TRUE(FileExists(dest_dir_path.Append(
796 VirtualPath::BaseName(child_dir_path)).Append( 691 VirtualPath::BaseName(child_dir_path)).Append(
797 VirtualPath::BaseName(grandchild_file_path)))); 692 VirtualPath::BaseName(grandchild_file_path))));
798 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 693 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
799 694
800 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count()); 695 EXPECT_EQ(2, change_observer()->get_and_reset_create_directory_count());
801 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count()); 696 EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
802 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count()); 697 EXPECT_EQ(1, change_observer()->get_and_reset_create_file_from_count());
803 EXPECT_TRUE(change_observer()->HasNoChange()); 698 EXPECT_TRUE(change_observer()->HasNoChange());
804 } 699 }
805 700
806 TEST_F(LocalFileSystemOperationTest, TestCopyInForeignFileSuccess) { 701 TEST_F(LocalFileSystemOperationTest, TestCopyInForeignFileSuccess) {
807 FilePath src_local_disk_file_path; 702 FilePath src_local_disk_file_path;
808 file_util::CreateTemporaryFile(&src_local_disk_file_path); 703 file_util::CreateTemporaryFile(&src_local_disk_file_path);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 const char test_data[] = "foo"; 737 const char test_data[] = "foo";
843 file_util::WriteFile(src_local_disk_file_path, test_data, 738 file_util::WriteFile(src_local_disk_file_path, test_data,
844 ARRAYSIZE_UNSAFE(test_data)); 739 ARRAYSIZE_UNSAFE(test_data));
845 740
846 FilePath dest_dir_path(CreateUniqueDir()); 741 FilePath dest_dir_path(CreateUniqueDir());
847 FilePath dest_file_path(dest_dir_path.Append( 742 FilePath dest_file_path(dest_dir_path.Append(
848 src_local_disk_file_path.BaseName())); 743 src_local_disk_file_path.BaseName()));
849 FileSystemURL dest_file_url = URLForPath(dest_file_path); 744 FileSystemURL dest_file_url = URLForPath(dest_file_path);
850 745
851 // Set quota of 0 which should force copy to fail by quota. 746 // Set quota of 0 which should force copy to fail by quota.
852 quota_manager_proxy()->SetQuota(dest_file_url.origin(), 747 quota_manager()->SetQuota(dest_file_url.origin(),
853 test_helper_.storage_type(), 748 test_helper_.storage_type(),
854 static_cast<int64>(0)); 749 static_cast<int64>(0));
855 operation()->CopyInForeignFile(src_local_disk_file_path, 750 operation()->CopyInForeignFile(src_local_disk_file_path,
856 dest_file_url, 751 dest_file_url,
857 RecordStatusCallback()); 752 RecordStatusCallback());
858 MessageLoop::current()->RunAllPending(); 753 MessageLoop::current()->RunAllPending();
859 754
860 EXPECT_TRUE(!FileExists(dest_file_path)); 755 EXPECT_TRUE(!FileExists(dest_file_path));
861 EXPECT_EQ(0, change_observer()->create_file_count()); 756 EXPECT_EQ(0, change_observer()->create_file_count());
862 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status()); 757 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE, status());
863 } 758 }
864 759
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 918 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
1024 ++read_access; 919 ++read_access;
1025 920
1026 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback()); 921 operation()->GetMetadata(URLForPath(file_path), RecordMetadataCallback());
1027 MessageLoop::current()->RunAllPending(); 922 MessageLoop::current()->RunAllPending();
1028 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 923 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
1029 EXPECT_FALSE(info().is_directory); 924 EXPECT_FALSE(info().is_directory);
1030 EXPECT_EQ(PlatformPath(file_path), path()); 925 EXPECT_EQ(PlatformPath(file_path), path());
1031 ++read_access; 926 ++read_access;
1032 927
1033 EXPECT_EQ(read_access, quota_manager_proxy()->storage_accessed_count()); 928 EXPECT_EQ(read_access,
929 quota_manager_proxy()->notify_storage_accessed_count());
1034 EXPECT_TRUE(change_observer()->HasNoChange()); 930 EXPECT_TRUE(change_observer()->HasNoChange());
1035 } 931 }
1036 932
1037 TEST_F(LocalFileSystemOperationTest, TestTypeMismatchErrors) { 933 TEST_F(LocalFileSystemOperationTest, TestTypeMismatchErrors) {
1038 FilePath dir_path(CreateUniqueDir()); 934 FilePath dir_path(CreateUniqueDir());
1039 operation()->FileExists(URLForPath(dir_path), RecordStatusCallback()); 935 operation()->FileExists(URLForPath(dir_path), RecordStatusCallback());
1040 MessageLoop::current()->RunAllPending(); 936 MessageLoop::current()->RunAllPending();
1041 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); 937 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
1042 938
1043 FilePath file_path(CreateUniqueFileInDir(dir_path)); 939 FilePath file_path(CreateUniqueFileInDir(dir_path));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 982
1087 for (size_t i = 0; i < entries().size(); ++i) { 983 for (size_t i = 0; i < entries().size(); ++i) {
1088 if (entries()[i].is_directory) { 984 if (entries()[i].is_directory) {
1089 EXPECT_EQ(VirtualPath::BaseName(child_dir_path).value(), 985 EXPECT_EQ(VirtualPath::BaseName(child_dir_path).value(),
1090 entries()[i].name); 986 entries()[i].name);
1091 } else { 987 } else {
1092 EXPECT_EQ(VirtualPath::BaseName(child_file_path).value(), 988 EXPECT_EQ(VirtualPath::BaseName(child_file_path).value(),
1093 entries()[i].name); 989 entries()[i].name);
1094 } 990 }
1095 } 991 }
1096 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 992 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
1097 EXPECT_TRUE(change_observer()->HasNoChange()); 993 EXPECT_TRUE(change_observer()->HasNoChange());
1098 } 994 }
1099 995
1100 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) { 996 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) {
1101 // Path doesn't exist. 997 // Path doesn't exist.
1102 FilePath nonexisting_path(FilePath( 998 FilePath nonexisting_path(FilePath(
1103 FILE_PATH_LITERAL("NonExistingDir"))); 999 FILE_PATH_LITERAL("NonExistingDir")));
1104 file_util::EnsureEndsWithSeparator(&nonexisting_path); 1000 file_util::EnsureEndsWithSeparator(&nonexisting_path);
1105 1001
1106 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */, 1002 operation()->Remove(URLForPath(nonexisting_path), false /* recursive */,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path)); 1046 FilePath child_dir_path(CreateUniqueDirInDir(parent_dir_path));
1151 ASSERT_FALSE(child_dir_path.empty()); 1047 ASSERT_FALSE(child_dir_path.empty());
1152 1048
1153 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */, 1049 operation()->Remove(URLForPath(parent_dir_path), true /* recursive */,
1154 RecordStatusCallback()); 1050 RecordStatusCallback());
1155 MessageLoop::current()->RunAllPending(); 1051 MessageLoop::current()->RunAllPending();
1156 EXPECT_EQ(base::PLATFORM_FILE_OK, status()); 1052 EXPECT_EQ(base::PLATFORM_FILE_OK, status());
1157 EXPECT_FALSE(DirectoryExists(parent_dir_path)); 1053 EXPECT_FALSE(DirectoryExists(parent_dir_path));
1158 1054
1159 // Remove is not a 'read' access. 1055 // Remove is not a 'read' access.
1160 EXPECT_EQ(0, quota_manager_proxy()->storage_accessed_count()); 1056 EXPECT_EQ(0, quota_manager_proxy()->notify_storage_accessed_count());
1161 1057
1162 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count()); 1058 EXPECT_EQ(2, change_observer()->get_and_reset_remove_directory_count());
1163 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count()); 1059 EXPECT_EQ(1, change_observer()->get_and_reset_remove_file_count());
1164 EXPECT_TRUE(change_observer()->HasNoChange()); 1060 EXPECT_TRUE(change_observer()->HasNoChange());
1165 } 1061 }
1166 1062
1167 TEST_F(LocalFileSystemOperationTest, TestTruncate) { 1063 TEST_F(LocalFileSystemOperationTest, TestTruncate) {
1168 FilePath dir_path(CreateUniqueDir()); 1064 FilePath dir_path(CreateUniqueDir());
1169 FilePath file_path(CreateUniqueFileInDir(dir_path)); 1065 FilePath file_path(CreateUniqueFileInDir(dir_path));
1170 1066
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 1112
1217 // Check that its length is now 3 and that it contains only bits of test data. 1113 // Check that its length is now 3 and that it contains only bits of test data.
1218 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info)); 1114 EXPECT_TRUE(file_util::GetFileInfo(PlatformPath(file_path), &info));
1219 EXPECT_EQ(length, info.size); 1115 EXPECT_EQ(length, info.size);
1220 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length)); 1116 EXPECT_EQ(length, file_util::ReadFile(PlatformPath(file_path), data, length));
1221 for (int i = 0; i < length; ++i) 1117 for (int i = 0; i < length; ++i)
1222 EXPECT_EQ(test_data[i], data[i]); 1118 EXPECT_EQ(test_data[i], data[i]);
1223 1119
1224 // Truncate is not a 'read' access. (Here expected access count is 1 1120 // Truncate is not a 'read' access. (Here expected access count is 1
1225 // since we made 1 read access for GetMetadata.) 1121 // since we made 1 read access for GetMetadata.)
1226 EXPECT_EQ(1, quota_manager_proxy()->storage_accessed_count()); 1122 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count());
1227 } 1123 }
1228 1124
1229 TEST_F(LocalFileSystemOperationTest, TestTruncateFailureByQuota) { 1125 TEST_F(LocalFileSystemOperationTest, TestTruncateFailureByQuota) {
1230 base::PlatformFileInfo info; 1126 base::PlatformFileInfo info;
1231 1127
1232 FilePath dir_path(CreateUniqueDir()); 1128 FilePath dir_path(CreateUniqueDir());
1233 FilePath file_path(CreateUniqueFileInDir(dir_path)); 1129 FilePath file_path(CreateUniqueFileInDir(dir_path));
1234 1130
1235 GrantQuotaForCurrentUsage(); 1131 GrantQuotaForCurrentUsage();
1236 AddQuota(10); 1132 AddQuota(10);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 EXPECT_FALSE(info().is_directory); 1204 EXPECT_FALSE(info().is_directory);
1309 EXPECT_EQ(PlatformPath(file_path), path()); 1205 EXPECT_EQ(PlatformPath(file_path), path());
1310 EXPECT_TRUE(change_observer()->HasNoChange()); 1206 EXPECT_TRUE(change_observer()->HasNoChange());
1311 1207
1312 // The FileSystemOpration implementation does not create a 1208 // The FileSystemOpration implementation does not create a
1313 // shareable file reference. 1209 // shareable file reference.
1314 EXPECT_EQ(NULL, shareable_file_ref()); 1210 EXPECT_EQ(NULL, shareable_file_ref());
1315 } 1211 }
1316 1212
1317 } // namespace fileapi 1213 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_storage_unittest.cc ('k') | webkit/quota/mock_quota_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698