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/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webkit/fileapi/file_system_url.h" | |
16 #include "webkit/fileapi/syncable/sync_status_code.h" | 17 #include "webkit/fileapi/syncable/sync_status_code.h" |
17 #include "webkit/quota/quota_manager.h" | 18 #include "webkit/quota/quota_manager.h" |
18 | 19 |
19 using sync_file_system::MockRemoteFileSyncService; | 20 using sync_file_system::MockRemoteFileSyncService; |
20 using sync_file_system::RemoteFileSyncService; | 21 using sync_file_system::RemoteFileSyncService; |
21 using sync_file_system::SyncFileSystemServiceFactory; | 22 using sync_file_system::SyncFileSystemServiceFactory; |
22 using ::testing::_; | 23 using ::testing::_; |
23 | 24 |
24 namespace chrome { | 25 namespace chrome { |
25 | 26 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 int64 real_default_quota_; | 60 int64 real_default_quota_; |
60 }; | 61 }; |
61 | 62 |
62 ACTION_P(NotifyOkStateAndCallback, mock_remote_service) { | 63 ACTION_P(NotifyOkStateAndCallback, mock_remote_service) { |
63 mock_remote_service->NotifyRemoteServiceStateUpdated( | 64 mock_remote_service->NotifyRemoteServiceStateUpdated( |
64 sync_file_system::REMOTE_SERVICE_OK, "Test event description."); | 65 sync_file_system::REMOTE_SERVICE_OK, "Test event description."); |
65 base::MessageLoopProxy::current()->PostTask( | 66 base::MessageLoopProxy::current()->PostTask( |
66 FROM_HERE, base::Bind(arg1, fileapi::SYNC_STATUS_OK)); | 67 FROM_HERE, base::Bind(arg1, fileapi::SYNC_STATUS_OK)); |
67 } | 68 } |
68 | 69 |
70 ACTION_P(CaptureRemoteSyncObserver, observer_list) { | |
71 observer_list->AddObserver(arg0); | |
72 } | |
73 | |
74 ACTION_P2(UpdateRemoteChangeQueue, origin, observer_list) { | |
75 *origin = arg0; | |
76 FOR_EACH_OBSERVER( | |
77 RemoteFileSyncService::Observer, *observer_list, | |
78 OnRemoteChangeQueueUpdated(1)); | |
79 } | |
80 | |
81 ACTION_P3(ProcessRemoteChangeAndCallBack, | |
82 origin, mock_remote_servicem, observer_list) { | |
83 fileapi::FileSystemURL mockUrl(*origin, | |
kinuko
2013/01/08 06:02:38
naming: mockUrl -> mock_url (we're in c++!)
calvinlo
2013/01/08 08:32:21
Done.
| |
84 fileapi::kFileSystemTypeTest, | |
85 FilePath(FILE_PATH_LITERAL("foo"))); | |
86 FOR_EACH_OBSERVER( | |
87 RemoteFileSyncService::Observer, *observer_list, | |
88 OnRemoteChangeQueueUpdated(0)); | |
89 base::MessageLoopProxy::current()->PostTask( | |
90 FROM_HERE, base::Bind(arg1, | |
91 fileapi::SYNC_STATUS_OK, | |
92 mockUrl, | |
93 fileapi::SYNC_OPERATION_ADDED)); | |
94 } | |
95 | |
69 } // namespace | 96 } // namespace |
70 | 97 |
71 // TODO(calvinlo): Add Chrome OS support for syncable file system | 98 // TODO(calvinlo): Add Chrome OS support for syncable file system |
72 // (http://crbug.com/160693) | 99 // (http://crbug.com/160693) |
73 #if !defined(OS_CHROMEOS) | 100 #if !defined(OS_CHROMEOS) |
74 | 101 |
75 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, DeleteFileSystem) { | 102 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, DeleteFileSystem) { |
76 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/delete_file_system")) | 103 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/delete_file_system")) |
77 << message_; | 104 << message_; |
78 } | 105 } |
79 | 106 |
80 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetUsageAndQuota) { | 107 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetUsageAndQuota) { |
81 ASSERT_TRUE(RunExtensionTest("sync_file_system/get_usage_and_quota")) | 108 ASSERT_TRUE(RunExtensionTest("sync_file_system/get_usage_and_quota")) |
82 << message_; | 109 << message_; |
83 } | 110 } |
84 | 111 |
112 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnFileSynced) { | |
113 // Mock a pending remote change to be synced. | |
114 ObserverList<RemoteFileSyncService::Observer> observer_list; | |
115 EXPECT_CALL(*mock_remote_service(), AddObserver(_)) | |
116 .WillOnce(CaptureRemoteSyncObserver(&observer_list)); | |
kinuko
2013/01/08 06:02:38
I think you can omit this observer_list part but c
calvinlo
2013/01/08 08:32:21
Done. Sorry, I didn't know you could do that befor
| |
117 GURL origin; | |
118 EXPECT_CALL(*mock_remote_service(), RegisterOriginForTrackingChanges(_, _)) | |
119 .WillOnce(UpdateRemoteChangeQueue(&origin, &observer_list)); | |
120 EXPECT_CALL(*mock_remote_service(), ProcessRemoteChange(_, _)) | |
121 .WillOnce(ProcessRemoteChangeAndCallBack(&origin, mock_remote_service(), | |
122 &observer_list)); | |
123 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_file_synced")) | |
124 << message_; | |
125 } | |
126 | |
85 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnSyncStateChanged) { | 127 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnSyncStateChanged) { |
86 EXPECT_CALL(*mock_remote_service(), | 128 EXPECT_CALL(*mock_remote_service(), RegisterOriginForTrackingChanges(_, _)) |
87 RegisterOriginForTrackingChanges(_, _)) | |
88 .WillOnce(NotifyOkStateAndCallback(mock_remote_service())); | 129 .WillOnce(NotifyOkStateAndCallback(mock_remote_service())); |
89 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_sync_state_changed")) | 130 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_sync_state_changed")) |
90 << message_; | 131 << message_; |
91 } | 132 } |
92 | 133 |
93 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, RequestFileSystem) { | 134 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, RequestFileSystem) { |
94 EXPECT_CALL(*mock_remote_service(), | 135 EXPECT_CALL(*mock_remote_service(), |
95 RegisterOriginForTrackingChanges(_, _)).Times(1); | 136 RegisterOriginForTrackingChanges(_, _)).Times(1); |
96 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/request_file_system")) | 137 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/request_file_system")) |
97 << message_; | 138 << message_; |
98 } | 139 } |
99 | 140 |
100 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, WriteFileThenGetUsage) { | 141 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, WriteFileThenGetUsage) { |
101 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/write_file_then_get_usage")) | 142 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/write_file_then_get_usage")) |
102 << message_; | 143 << message_; |
103 } | 144 } |
104 | 145 |
105 #endif // !defined(OS_CHROMEOS) | 146 #endif // !defined(OS_CHROMEOS) |
106 | 147 |
107 } // namespace chrome | 148 } // namespace chrome |
108 | 149 |
OLD | NEW |