summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-21 08:57:51 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-21 08:57:51 +0000
commit452b2d089a56abcedb8ee0749971f501997ba687 (patch)
tree10b2ed0b1793eda6aea5db112f37bd7ba40d0bcf
parent4f0501b5849de6f8b4cadc6d91b9419abd4582c3 (diff)
downloadchromium_src-452b2d089a56abcedb8ee0749971f501997ba687.zip
chromium_src-452b2d089a56abcedb8ee0749971f501997ba687.tar.gz
chromium_src-452b2d089a56abcedb8ee0749971f501997ba687.tar.bz2
Add MockLocalChangeProcessor class and default implementation
Moved MockLocalChangeProcessor local implementation from local_file_sync_service_unittest.cc into its own file and added default implementation of MockRemoteFileSyncService::GetLocalChangeProcessor using the mock class. Similarly separating out MockSyncStatusObserver class into its own class. BUG=161436 TEST=LocalFileSyncServiceTest.* Review URL: https://codereview.chromium.org/11414108 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169008 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/sync_file_system/local_file_sync_service_unittest.cc27
-rw-r--r--chrome/browser/sync_file_system/mock_local_change_processor.cc37
-rw-r--r--chrome/browser/sync_file_system/mock_local_change_processor.h37
-rw-r--r--chrome/browser/sync_file_system/mock_remote_file_sync_service.cc4
-rw-r--r--chrome/browser/sync_file_system/mock_remote_file_sync_service.h12
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/chrome_tests_unit.gypi6
-rw-r--r--webkit/fileapi/syncable/mock_sync_status_observer.cc15
-rw-r--r--webkit/fileapi/syncable/mock_sync_status_observer.h28
9 files changed, 132 insertions, 36 deletions
diff --git a/chrome/browser/sync_file_system/local_file_sync_service_unittest.cc b/chrome/browser/sync_file_system/local_file_sync_service_unittest.cc
index de7e0e2..ae51108 100644
--- a/chrome/browser/sync_file_system/local_file_sync_service_unittest.cc
+++ b/chrome/browser/sync_file_system/local_file_sync_service_unittest.cc
@@ -9,8 +9,8 @@
#include "base/message_loop_proxy.h"
#include "base/run_loop.h"
#include "base/threading/thread.h"
-#include "chrome/browser/sync_file_system/local_change_processor.h"
#include "chrome/browser/sync_file_system/local_file_sync_service.h"
+#include "chrome/browser/sync_file_system/mock_local_change_processor.h"
#include "chrome/browser/sync_file_system/sync_file_system_test_util.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -20,6 +20,7 @@
#include "webkit/fileapi/syncable/local_file_change_tracker.h"
#include "webkit/fileapi/syncable/local_file_sync_context.h"
#include "webkit/fileapi/syncable/local_file_sync_status.h"
+#include "webkit/fileapi/syncable/mock_sync_status_observer.h"
#include "webkit/fileapi/syncable/sync_file_metadata.h"
#include "webkit/fileapi/syncable/sync_status_code.h"
#include "webkit/fileapi/syncable/syncable_file_system_util.h"
@@ -28,6 +29,7 @@ using fileapi::FileChange;
using fileapi::FileChangeList;
using fileapi::FileSystemURL;
using fileapi::LocalFileSyncStatus;
+using fileapi::MockSyncStatusObserver;
using fileapi::SyncFileMetadata;
using fileapi::SyncFileType;
using fileapi::SyncStatusCallback;
@@ -84,29 +86,6 @@ void OnGetFileMetadata(const tracked_objects::Location& where,
oncompleted.Run();
}
-class MockLocalChangeProcessor : public LocalChangeProcessor {
- public:
- MockLocalChangeProcessor() {}
- virtual ~MockLocalChangeProcessor() {}
-
- // LocalChangeProcessor override.
- MOCK_METHOD4(ApplyLocalChange,
- void(const FileChange& change,
- const FilePath& local_path,
- const FileSystemURL& url,
- const SyncStatusCallback& callback));
-};
-
-class MockSyncStatusObserver : public LocalFileSyncStatus::Observer {
- public:
- MockSyncStatusObserver() {}
- virtual ~MockSyncStatusObserver() {}
-
- // LocalFileSyncStatus::Observer overrides.
- MOCK_METHOD1(OnSyncEnabled, void(const FileSystemURL& url));
- MOCK_METHOD1(OnWriteEnabled, void(const FileSystemURL& url));
-};
-
ACTION_P(MockStatusCallback, status) {
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(arg3, status));
diff --git a/chrome/browser/sync_file_system/mock_local_change_processor.cc b/chrome/browser/sync_file_system/mock_local_change_processor.cc
new file mode 100644
index 0000000..9363c84
--- /dev/null
+++ b/chrome/browser/sync_file_system/mock_local_change_processor.cc
@@ -0,0 +1,37 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync_file_system/mock_local_change_processor.h"
+
+#include "base/bind.h"
+#include "base/location.h"
+#include "base/message_loop_proxy.h"
+#include "webkit/fileapi/file_system_url.h"
+#include "webkit/fileapi/syncable/file_change.h"
+
+using ::testing::_;
+using ::testing::Invoke;
+using ::testing::Return;
+
+namespace sync_file_system {
+
+MockLocalChangeProcessor::MockLocalChangeProcessor() {
+ ON_CALL(*this, ApplyLocalChange(_, _, _, _))
+ .WillByDefault(Invoke(this,
+ &MockLocalChangeProcessor::ApplyLocalChangeStub));
+}
+
+MockLocalChangeProcessor::~MockLocalChangeProcessor() {
+}
+
+void MockLocalChangeProcessor::ApplyLocalChangeStub(
+ const fileapi::FileChange& change,
+ const FilePath& local_path,
+ const fileapi::FileSystemURL& url,
+ const fileapi::SyncStatusCallback& callback) {
+ base::MessageLoopProxy::current()->PostTask(
+ FROM_HERE, base::Bind(callback, fileapi::SYNC_STATUS_OK));
+}
+
+} // namespace sync_file_system
diff --git a/chrome/browser/sync_file_system/mock_local_change_processor.h b/chrome/browser/sync_file_system/mock_local_change_processor.h
new file mode 100644
index 0000000..7573dfb
--- /dev/null
+++ b/chrome/browser/sync_file_system/mock_local_change_processor.h
@@ -0,0 +1,37 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_MOCK_LOCAL_CHANGE_PROCESSOR_H_
+#define CHROME_BROWSER_SYNC_FILE_SYSTEM_MOCK_LOCAL_CHANGE_PROCESSOR_H_
+
+#include "base/basictypes.h"
+#include "chrome/browser/sync_file_system/local_change_processor.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace sync_file_system {
+
+class MockLocalChangeProcessor : public LocalChangeProcessor {
+ public:
+ MockLocalChangeProcessor();
+ virtual ~MockLocalChangeProcessor();
+
+ // LocalChangeProcessor override.
+ MOCK_METHOD4(ApplyLocalChange,
+ void(const fileapi::FileChange& change,
+ const FilePath& local_path,
+ const fileapi::FileSystemURL& url,
+ const fileapi::SyncStatusCallback& callback));
+
+ private:
+ void ApplyLocalChangeStub(const fileapi::FileChange& change,
+ const FilePath& local_path,
+ const fileapi::FileSystemURL& url,
+ const fileapi::SyncStatusCallback& callback);
+
+ DISALLOW_COPY_AND_ASSIGN(MockLocalChangeProcessor);
+};
+
+} // namespace sync_file_system
+
+#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_MOCK_LOCAL_CHANGE_PROCESSOR_H_
diff --git a/chrome/browser/sync_file_system/mock_remote_file_sync_service.cc b/chrome/browser/sync_file_system/mock_remote_file_sync_service.cc
index dddda62..03f6493 100644
--- a/chrome/browser/sync_file_system/mock_remote_file_sync_service.cc
+++ b/chrome/browser/sync_file_system/mock_remote_file_sync_service.cc
@@ -22,8 +22,6 @@ MockRemoteFileSyncService::MockRemoteFileSyncService() {
.WillByDefault(Invoke(this, &self::AddObserverStub));
ON_CALL(*this, RemoveObserver(_))
.WillByDefault(Invoke(this, &self::RemoveObserverStub));
- ON_CALL(*this, GetLocalChangeProcessor())
- .WillByDefault(Return(local_change_processor_.get()));
ON_CALL(*this, RegisterOriginForTrackingChanges(_, _))
.WillByDefault(Invoke(this, &self::RegisterOriginForTrackingChangesStub));
ON_CALL(*this, UnregisterOriginForTrackingChanges(_, _))
@@ -32,7 +30,7 @@ MockRemoteFileSyncService::MockRemoteFileSyncService() {
ON_CALL(*this, ProcessRemoteChange(_, _))
.WillByDefault(Invoke(this, &self::ProcessRemoteChangeStub));
ON_CALL(*this, GetLocalChangeProcessor())
- .WillByDefault(Return(local_change_processor_.get()));
+ .WillByDefault(Return(&mock_local_change_processor_));
ON_CALL(*this, GetConflictFiles(_, _))
.WillByDefault(Invoke(this, &self::GetConflictFilesStub));
ON_CALL(*this, GetRemoteFileMetadata(_, _))
diff --git a/chrome/browser/sync_file_system/mock_remote_file_sync_service.h b/chrome/browser/sync_file_system/mock_remote_file_sync_service.h
index 8dc6456..7122912 100644
--- a/chrome/browser/sync_file_system/mock_remote_file_sync_service.h
+++ b/chrome/browser/sync_file_system/mock_remote_file_sync_service.h
@@ -9,7 +9,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
-#include "chrome/browser/sync_file_system/local_change_processor.h"
+#include "chrome/browser/sync_file_system/mock_local_change_processor.h"
#include "chrome/browser/sync_file_system/remote_change_processor.h"
#include "chrome/browser/sync_file_system/remote_file_sync_service.h"
#include "googleurl/src/gurl.h"
@@ -53,11 +53,6 @@ class MockRemoteFileSyncService : public RemoteFileSyncService {
// Sets a mock local change processor. The value is returned by
// the default action for GetLocalChangeProcessor.
- void set_local_change_processor(
- scoped_ptr<LocalChangeProcessor> processor) {
- local_change_processor_ = processor.Pass();
- }
-
// Sets conflict file information. The information is returned by
// the default action for GetConflictFiles and GetRemoteConflictFileInfo.
void add_conflict_file(const fileapi::FileSystemURL& url,
@@ -94,11 +89,12 @@ class MockRemoteFileSyncService : public RemoteFileSyncService {
const fileapi::FileSystemURL& url,
const fileapi::SyncFileMetadataCallback& callback);
- scoped_ptr<LocalChangeProcessor> local_change_processor_;
-
OriginToURLSetMap conflict_file_urls_;
FileMetadataMap conflict_file_metadata_;
+ // For default implementation.
+ MockLocalChangeProcessor mock_local_change_processor_;
+
ObserverList<Observer> observers_;
DISALLOW_COPY_AND_ASSIGN(MockRemoteFileSyncService);
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index cf81b0d..605488d 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1025,6 +1025,8 @@
'browser/speech/speech_recognition_bubble_browsertest.cc',
'browser/spellchecker/spellcheck_service_browsertest.cc',
'browser/ssl/ssl_browser_tests.cc',
+ 'browser/sync_file_system/mock_local_change_processor.cc',
+ 'browser/sync_file_system/mock_local_change_processor.h',
'browser/sync_file_system/mock_remote_file_sync_service.cc',
'browser/sync_file_system/mock_remote_file_sync_service.h',
'browser/tab_contents/render_view_context_menu_browsertest.cc',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index fbfeb90..90c56e0 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1135,6 +1135,8 @@
'browser/sync_file_system/drive_file_sync_service_unittest.cc',
'browser/sync_file_system/drive_metadata_store_unittest.cc',
'browser/sync_file_system/local_file_sync_service_unittest.cc',
+ 'browser/sync_file_system/mock_local_change_processor.cc',
+ 'browser/sync_file_system/mock_local_change_processor.h',
'browser/sync_file_system/mock_remote_file_sync_service.cc',
'browser/sync_file_system/mock_remote_file_sync_service.h',
'browser/sync_file_system/sync_file_system_service_unittest.cc',
@@ -1637,7 +1639,9 @@
'../webkit/blob/mock_blob_url_request_context.cc',
'../webkit/blob/mock_blob_url_request_context.h',
'../webkit/fileapi/syncable/canned_syncable_file_system.cc',
- '../webkit/fileapi/syncable/canned_syncable_file_system.h',
+ '../webkit/fileapi/syncable/canned_syncable_file_system.cc',
+ '../webkit/fileapi/syncable/mock_sync_status_observer.cc',
+ '../webkit/fileapi/syncable/mock_sync_status_observer.h',
'../webkit/glue/web_intent_reply_data_unittest.cc',
'../webkit/glue/web_intent_service_data_unittest.cc',
'../webkit/quota/mock_storage_client.cc',
diff --git a/webkit/fileapi/syncable/mock_sync_status_observer.cc b/webkit/fileapi/syncable/mock_sync_status_observer.cc
new file mode 100644
index 0000000..80ae893
--- /dev/null
+++ b/webkit/fileapi/syncable/mock_sync_status_observer.cc
@@ -0,0 +1,15 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/fileapi/syncable/mock_sync_status_observer.h"
+
+namespace fileapi {
+
+MockSyncStatusObserver::MockSyncStatusObserver() {
+}
+
+MockSyncStatusObserver::~MockSyncStatusObserver() {
+}
+
+} // namespace fileapi
diff --git a/webkit/fileapi/syncable/mock_sync_status_observer.h b/webkit/fileapi/syncable/mock_sync_status_observer.h
new file mode 100644
index 0000000..59c89b3
--- /dev/null
+++ b/webkit/fileapi/syncable/mock_sync_status_observer.h
@@ -0,0 +1,28 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef WEBKIT_FILEAPI_SYNCABLE_MOCK_SYNC_STATUS_OBSERVER_H_
+#define WEBKIT_FILEAPI_SYNCABLE_MOCK_SYNC_STATUS_OBSERVER_H_
+
+#include "testing/gmock/include/gmock/gmock.h"
+#include "webkit/fileapi/syncable/local_file_sync_status.h"
+
+namespace fileapi {
+
+class MockSyncStatusObserver : public LocalFileSyncStatus::Observer {
+ public:
+ MockSyncStatusObserver();
+ virtual ~MockSyncStatusObserver();
+
+ // LocalFileSyncStatus::Observer overrides.
+ MOCK_METHOD1(OnSyncEnabled, void(const FileSystemURL& url));
+ MOCK_METHOD1(OnWriteEnabled, void(const FileSystemURL& url));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockSyncStatusObserver);
+};
+
+} // namespace fileapi
+
+#endif // WEBKIT_FILEAPI_SYNCABLE_MOCK_SYNC_STATUS_OBSERVER_H_