Commit 9e3c2684 authored by calvinlo@chromium.org's avatar calvinlo@chromium.org

Add automated test for chrome.onFileSynced JavsScript event.

BUG=167739
Test=SyncFileSystemApiTest.OnFileSynced

Review URL: https://chromiumcodereview.appspot.com/11699004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175743 0039d316-1c4b-4281-b951-d872f2087c98
parent f7798c43
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/common/extensions/features/feature.h" #include "chrome/common/extensions/features/feature.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "webkit/fileapi/file_system_url.h"
#include "webkit/fileapi/syncable/sync_status_code.h" #include "webkit/fileapi/syncable/sync_status_code.h"
#include "webkit/quota/quota_manager.h" #include "webkit/quota/quota_manager.h"
...@@ -68,6 +69,23 @@ ACTION_P(NotifyOkStateAndCallback, mock_remote_service) { ...@@ -68,6 +69,23 @@ ACTION_P(NotifyOkStateAndCallback, mock_remote_service) {
FROM_HERE, base::Bind(arg1, fileapi::SYNC_STATUS_OK)); FROM_HERE, base::Bind(arg1, fileapi::SYNC_STATUS_OK));
} }
ACTION_P2(UpdateRemoteChangeQueue, origin, mock_remote_service) {
*origin = arg0;
mock_remote_service->NotifyRemoteChangeQueueUpdated(1);
}
ACTION_P2(ReturnWithFakeFileAddedStatus, origin, mock_remote_service) {
fileapi::FileSystemURL mock_url(*origin,
fileapi::kFileSystemTypeTest,
FilePath(FILE_PATH_LITERAL("foo")));
mock_remote_service->NotifyRemoteChangeQueueUpdated(0);
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(arg1,
fileapi::SYNC_STATUS_OK,
mock_url,
fileapi::SYNC_OPERATION_ADDED));
}
} // namespace } // namespace
// TODO(calvinlo): Add Chrome OS support for syncable file system // TODO(calvinlo): Add Chrome OS support for syncable file system
...@@ -90,9 +108,20 @@ IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetUsageAndQuota) { ...@@ -90,9 +108,20 @@ IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetUsageAndQuota) {
<< message_; << message_;
} }
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnFileSynced) {
// Mock a pending remote change to be synced.
GURL origin;
EXPECT_CALL(*mock_remote_service(), RegisterOriginForTrackingChanges(_, _))
.WillOnce(UpdateRemoteChangeQueue(&origin, mock_remote_service()));
EXPECT_CALL(*mock_remote_service(), ProcessRemoteChange(_, _))
.WillOnce(ReturnWithFakeFileAddedStatus(&origin,
mock_remote_service()));
ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_file_synced"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnSyncStateChanged) { IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnSyncStateChanged) {
EXPECT_CALL(*mock_remote_service(), EXPECT_CALL(*mock_remote_service(), RegisterOriginForTrackingChanges(_, _))
RegisterOriginForTrackingChanges(_, _))
.WillOnce(NotifyOkStateAndCallback(mock_remote_service())); .WillOnce(NotifyOkStateAndCallback(mock_remote_service()));
ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_sync_state_changed")) ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_sync_state_changed"))
<< message_; << message_;
......
{
"name": "chrome.syncFileSystem.onFileSynced",
"version": "0.1",
"manifest_version": 2,
"description": "end-to-end browser test to listen to chrome.syncFileSystem.onFileSynced events",
"permissions": ["syncFileSystem"],
"app": {
"background": {
"scripts": ["test.js"]
}
}
}
// 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.
function setupListener() {
chrome.syncFileSystem.onFileSynced.addListener(fileSyncEventReceived);
chrome.syncFileSystem.requestFileSystem('drive', function() {});
}
function fileSyncEventReceived(file_entry_path, sync_operation_result) {
chrome.test.assertEq("foo", file_entry_path);
chrome.test.assertEq("added", sync_operation_result);
chrome.test.succeed();
}
chrome.test.runTests([
setupListener
]);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment