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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "chrome/browser/extensions/event_names.h" | 8 #include "chrome/browser/extensions/event_names.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 9 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/sync_file_system/local_change_processor.h" | 10 #include "chrome/browser/sync_file_system/local_change_processor.h" |
11 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h" | 11 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h" |
12 #include "chrome/browser/sync_file_system/sync_file_system_service.h" | 12 #include "chrome/browser/sync_file_system/sync_file_system_service.h" |
13 #include "chrome/common/chrome_version_info.h" | 13 #include "chrome/common/chrome_version_info.h" |
14 #include "chrome/common/extensions/features/feature.h" | 14 #include "chrome/common/extensions/features/feature.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "webkit/fileapi/file_system_url.h" |
17 #include "webkit/fileapi/syncable/sync_status_code.h" | 18 #include "webkit/fileapi/syncable/sync_status_code.h" |
18 #include "webkit/quota/quota_manager.h" | 19 #include "webkit/quota/quota_manager.h" |
19 | 20 |
20 using ::testing::_; | 21 using ::testing::_; |
21 using ::testing::Return; | 22 using ::testing::Return; |
22 using sync_file_system::MockRemoteFileSyncService; | 23 using sync_file_system::MockRemoteFileSyncService; |
23 using sync_file_system::RemoteFileSyncService; | 24 using sync_file_system::RemoteFileSyncService; |
24 using sync_file_system::SyncFileSystemServiceFactory; | 25 using sync_file_system::SyncFileSystemServiceFactory; |
25 | 26 |
26 namespace chrome { | 27 namespace chrome { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 int64 real_default_quota_; | 62 int64 real_default_quota_; |
62 }; | 63 }; |
63 | 64 |
64 ACTION_P(NotifyOkStateAndCallback, mock_remote_service) { | 65 ACTION_P(NotifyOkStateAndCallback, mock_remote_service) { |
65 mock_remote_service->NotifyRemoteServiceStateUpdated( | 66 mock_remote_service->NotifyRemoteServiceStateUpdated( |
66 sync_file_system::REMOTE_SERVICE_OK, "Test event description."); | 67 sync_file_system::REMOTE_SERVICE_OK, "Test event description."); |
67 base::MessageLoopProxy::current()->PostTask( | 68 base::MessageLoopProxy::current()->PostTask( |
68 FROM_HERE, base::Bind(arg1, fileapi::SYNC_STATUS_OK)); | 69 FROM_HERE, base::Bind(arg1, fileapi::SYNC_STATUS_OK)); |
69 } | 70 } |
70 | 71 |
| 72 ACTION_P2(UpdateRemoteChangeQueue, origin, mock_remote_service) { |
| 73 *origin = arg0; |
| 74 mock_remote_service->NotifyRemoteChangeQueueUpdated(1); |
| 75 } |
| 76 |
| 77 ACTION_P2(ReturnWithFakeFileAddedStatus, origin, mock_remote_service) { |
| 78 fileapi::FileSystemURL mock_url(*origin, |
| 79 fileapi::kFileSystemTypeTest, |
| 80 FilePath(FILE_PATH_LITERAL("foo"))); |
| 81 mock_remote_service->NotifyRemoteChangeQueueUpdated(0); |
| 82 base::MessageLoopProxy::current()->PostTask( |
| 83 FROM_HERE, base::Bind(arg1, |
| 84 fileapi::SYNC_STATUS_OK, |
| 85 mock_url, |
| 86 fileapi::SYNC_OPERATION_ADDED)); |
| 87 } |
| 88 |
71 } // namespace | 89 } // namespace |
72 | 90 |
73 // TODO(calvinlo): Add Chrome OS support for syncable file system | 91 // TODO(calvinlo): Add Chrome OS support for syncable file system |
74 // (http://crbug.com/160693) | 92 // (http://crbug.com/160693) |
75 #if !defined(OS_CHROMEOS) | 93 #if !defined(OS_CHROMEOS) |
76 | 94 |
77 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, DeleteFileSystem) { | 95 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, DeleteFileSystem) { |
78 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/delete_file_system")) | 96 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/delete_file_system")) |
79 << message_; | 97 << message_; |
80 } | 98 } |
81 | 99 |
82 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetFileSyncStatus) { | 100 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetFileSyncStatus) { |
83 EXPECT_CALL(*mock_remote_service(), IsConflicting(_)).WillOnce(Return(true)); | 101 EXPECT_CALL(*mock_remote_service(), IsConflicting(_)).WillOnce(Return(true)); |
84 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_file_sync_status")) | 102 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_file_sync_status")) |
85 << message_; | 103 << message_; |
86 } | 104 } |
87 | 105 |
88 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetUsageAndQuota) { | 106 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetUsageAndQuota) { |
89 ASSERT_TRUE(RunExtensionTest("sync_file_system/get_usage_and_quota")) | 107 ASSERT_TRUE(RunExtensionTest("sync_file_system/get_usage_and_quota")) |
90 << message_; | 108 << message_; |
91 } | 109 } |
92 | 110 |
| 111 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnFileSynced) { |
| 112 // Mock a pending remote change to be synced. |
| 113 GURL origin; |
| 114 EXPECT_CALL(*mock_remote_service(), RegisterOriginForTrackingChanges(_, _)) |
| 115 .WillOnce(UpdateRemoteChangeQueue(&origin, mock_remote_service())); |
| 116 EXPECT_CALL(*mock_remote_service(), ProcessRemoteChange(_, _)) |
| 117 .WillOnce(ReturnWithFakeFileAddedStatus(&origin, |
| 118 mock_remote_service())); |
| 119 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_file_synced")) |
| 120 << message_; |
| 121 } |
| 122 |
93 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnSyncStateChanged) { | 123 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnSyncStateChanged) { |
94 EXPECT_CALL(*mock_remote_service(), | 124 EXPECT_CALL(*mock_remote_service(), RegisterOriginForTrackingChanges(_, _)) |
95 RegisterOriginForTrackingChanges(_, _)) | |
96 .WillOnce(NotifyOkStateAndCallback(mock_remote_service())); | 125 .WillOnce(NotifyOkStateAndCallback(mock_remote_service())); |
97 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_sync_state_changed")) | 126 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_sync_state_changed")) |
98 << message_; | 127 << message_; |
99 } | 128 } |
100 | 129 |
101 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, RequestFileSystem) { | 130 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, RequestFileSystem) { |
102 EXPECT_CALL(*mock_remote_service(), | 131 EXPECT_CALL(*mock_remote_service(), |
103 RegisterOriginForTrackingChanges(_, _)).Times(1); | 132 RegisterOriginForTrackingChanges(_, _)).Times(1); |
104 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/request_file_system")) | 133 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/request_file_system")) |
105 << message_; | 134 << message_; |
106 } | 135 } |
107 | 136 |
108 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, WriteFileThenGetUsage) { | 137 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, WriteFileThenGetUsage) { |
109 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/write_file_then_get_usage")) | 138 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/write_file_then_get_usage")) |
110 << message_; | 139 << message_; |
111 } | 140 } |
112 | 141 |
113 #endif // !defined(OS_CHROMEOS) | 142 #endif // !defined(OS_CHROMEOS) |
114 | 143 |
115 } // namespace chrome | 144 } // namespace chrome |
116 | 145 |
OLD | NEW |