Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / sync / js / sync_js_controller_unittest.cc
blobbb834c535fea0db57732283b07b50e4af863d059
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
3 // found in the LICENSE file.
5 #include "sync/js/sync_js_controller.h"
7 #include "base/run_loop.h"
8 #include "base/values.h"
9 #include "sync/js/js_event_details.h"
10 #include "sync/js/js_test_util.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace syncer {
15 namespace {
17 using ::testing::_;
18 using ::testing::InSequence;
19 using ::testing::Mock;
20 using ::testing::StrictMock;
22 class SyncJsControllerTest : public testing::Test {
23 protected:
24 void PumpLoop() {
25 base::RunLoop().RunUntilIdle();
28 private:
29 base::MessageLoop message_loop_;
32 TEST_F(SyncJsControllerTest, Events) {
33 InSequence dummy;
34 SyncJsController sync_js_controller;
36 base::DictionaryValue details_dict1, details_dict2;
37 details_dict1.SetString("foo", "bar");
38 details_dict2.SetInteger("baz", 5);
39 JsEventDetails details1(&details_dict1), details2(&details_dict2);
41 StrictMock<MockJsEventHandler> event_handler1, event_handler2;
42 EXPECT_CALL(event_handler1, HandleJsEvent("event", HasDetails(details1)));
43 EXPECT_CALL(event_handler2, HandleJsEvent("event", HasDetails(details1)));
44 EXPECT_CALL(event_handler1,
45 HandleJsEvent("anotherevent", HasDetails(details2)));
46 EXPECT_CALL(event_handler2,
47 HandleJsEvent("anotherevent", HasDetails(details2)));
49 sync_js_controller.AddJsEventHandler(&event_handler1);
50 sync_js_controller.AddJsEventHandler(&event_handler2);
51 sync_js_controller.HandleJsEvent("event", details1);
52 sync_js_controller.HandleJsEvent("anotherevent", details2);
53 sync_js_controller.RemoveJsEventHandler(&event_handler1);
54 sync_js_controller.RemoveJsEventHandler(&event_handler2);
55 sync_js_controller.HandleJsEvent("droppedevent", details2);
57 PumpLoop();
60 } // namespace
61 } // namespace syncer