data_type_manager_mock.h revision 3345a6884c488ff3a535c2c9acdd33d74b37e311
1// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_MOCK_H__
6#define CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_MOCK_H__
7#pragma once
8
9#include "chrome/browser/sync/glue/data_type_manager.h"
10#include "chrome/browser/sync/profile_sync_test_util.h"
11#include "chrome/common/notification_details.h"
12#include "chrome/common/notification_service.h"
13#include "chrome/common/notification_type.h"
14#include "testing/gmock/include/gmock/gmock.h"
15
16ACTION_P3(NotifyFromDataTypeManagerWithResult, dtm, type, result) {
17  NotificationService::current()->Notify(
18      type,
19      Source<browser_sync::DataTypeManager>(dtm),
20      Details<browser_sync::DataTypeManager::ConfigureResult>(result));
21}
22
23ACTION_P2(NotifyFromDataTypeManager, dtm, type) {
24  NotificationService::current()->Notify(type,
25      Source<browser_sync::DataTypeManager>(dtm),
26      NotificationService::NoDetails());
27}
28
29namespace browser_sync {
30
31class DataTypeManagerMock : public DataTypeManager {
32 public:
33  DataTypeManagerMock() : result_(OK) {
34    // By default, calling Configure will send a SYNC_CONFIGURE_START
35    // and SYNC_CONFIGURE_DONE notification with a DataTypeManager::OK
36    // detail.
37    ON_CALL(*this, Configure(testing::_)).
38        WillByDefault(testing::DoAll(
39            NotifyFromDataTypeManager(this,
40                NotificationType::SYNC_CONFIGURE_START),
41            NotifyFromDataTypeManagerWithResult
42                 (this, NotificationType::SYNC_CONFIGURE_DONE, &result_)));
43  }
44
45  MOCK_METHOD1(Configure, void(const TypeSet&));
46  MOCK_METHOD0(Stop, void());
47  MOCK_METHOD0(controllers, const DataTypeController::TypeMap&());
48  MOCK_METHOD0(state, State());
49
50 private:
51  DataTypeManager::ConfigureResult result_;
52};
53
54}  // namespace browser_sync
55
56#endif  // CHROME_BROWSER_SYNC_GLUE_DATA_TYPE_MANAGER_MOCK_H__
57