Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: sync/js/sync_js_controller_unittest.cc

Issue 67683005: Clean up TestProfileSyncService and related tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "sync/js/sync_js_controller.h" 5 #include "sync/js/sync_js_controller.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "sync/js/js_arg_list.h" 9 #include "sync/js/js_arg_list.h"
10 #include "sync/js/js_event_details.h" 10 #include "sync/js/js_event_details.h"
(...skipping 12 matching lines...) Expand all
23 class SyncJsControllerTest : public testing::Test { 23 class SyncJsControllerTest : public testing::Test {
24 protected: 24 protected:
25 void PumpLoop() { 25 void PumpLoop() {
26 message_loop_.RunUntilIdle(); 26 message_loop_.RunUntilIdle();
27 } 27 }
28 28
29 private: 29 private:
30 base::MessageLoop message_loop_; 30 base::MessageLoop message_loop_;
31 }; 31 };
32 32
33 ACTION_P(ReplyToMessage, reply_name) {
34 arg2.Call(FROM_HERE, &JsReplyHandler::HandleJsReply, reply_name, JsArgList());
35 }
36
33 TEST_F(SyncJsControllerTest, Messages) { 37 TEST_F(SyncJsControllerTest, Messages) {
34 InSequence dummy; 38 InSequence dummy;
35 // |mock_backend| needs to outlive |sync_js_controller|. 39 // |mock_backend| needs to outlive |sync_js_controller|.
36 StrictMock<MockJsBackend> mock_backend; 40 StrictMock<MockJsBackend> mock_backend;
41 StrictMock<MockJsReplyHandler> mock_reply_handler;
37 SyncJsController sync_js_controller; 42 SyncJsController sync_js_controller;
38 43
39 base::ListValue arg_list1, arg_list2; 44 base::ListValue arg_list1, arg_list2;
40 arg_list1.Append(new base::FundamentalValue(false)); 45 arg_list1.Append(new base::FundamentalValue(false));
41 arg_list2.Append(new base::FundamentalValue(5)); 46 arg_list2.Append(new base::FundamentalValue(5));
42 JsArgList args1(&arg_list1), args2(&arg_list2); 47 JsArgList args1(&arg_list1), args2(&arg_list2);
43 48
44 // TODO(akalin): Write matchers for WeakHandle and use them here
45 // instead of _.
46 EXPECT_CALL(mock_backend, SetJsEventHandler(_)); 49 EXPECT_CALL(mock_backend, SetJsEventHandler(_));
47 EXPECT_CALL(mock_backend, ProcessJsMessage("test1", HasArgs(args2), _)); 50 EXPECT_CALL(mock_backend, ProcessJsMessage("test1", HasArgs(args2), _))
48 EXPECT_CALL(mock_backend, ProcessJsMessage("test2", HasArgs(args1), _)); 51 .WillOnce(ReplyToMessage("test1_reply"));
52 EXPECT_CALL(mock_backend, ProcessJsMessage("test2", HasArgs(args1), _))
53 .WillOnce(ReplyToMessage("test2_reply"));
49 54
50 sync_js_controller.AttachJsBackend(mock_backend.AsWeakHandle()); 55 sync_js_controller.AttachJsBackend(mock_backend.AsWeakHandle());
51 sync_js_controller.ProcessJsMessage("test1", args2, 56 sync_js_controller.ProcessJsMessage("test1",
52 WeakHandle<JsReplyHandler>()); 57 args2,
53 sync_js_controller.ProcessJsMessage("test2", args1, 58 mock_reply_handler.AsWeakHandle());
54 WeakHandle<JsReplyHandler>()); 59 sync_js_controller.ProcessJsMessage("test2",
60 args1,
61 mock_reply_handler.AsWeakHandle());
62
63 // The replies should be waiting on our message loop.
64 EXPECT_CALL(mock_reply_handler, HandleJsReply("test1_reply", _));
65 EXPECT_CALL(mock_reply_handler, HandleJsReply("test2_reply", _));
55 PumpLoop(); 66 PumpLoop();
56 67
57 // Let destructor of |sync_js_controller| call RemoveBackend(). 68 // Let destructor of |sync_js_controller| call RemoveBackend().
58 } 69 }
59 70
60 TEST_F(SyncJsControllerTest, QueuedMessages) { 71 TEST_F(SyncJsControllerTest, QueuedMessages) {
61 // |mock_backend| needs to outlive |sync_js_controller|. 72 // |mock_backend| needs to outlive |sync_js_controller|.
62 StrictMock<MockJsBackend> mock_backend; 73 StrictMock<MockJsBackend> mock_backend;
74 StrictMock<MockJsReplyHandler> mock_reply_handler;
63 SyncJsController sync_js_controller; 75 SyncJsController sync_js_controller;
64 76
65 base::ListValue arg_list1, arg_list2; 77 base::ListValue arg_list1, arg_list2;
66 arg_list1.Append(new base::FundamentalValue(false)); 78 arg_list1.Append(new base::FundamentalValue(false));
67 arg_list2.Append(new base::FundamentalValue(5)); 79 arg_list2.Append(new base::FundamentalValue(5));
68 JsArgList args1(&arg_list1), args2(&arg_list2); 80 JsArgList args1(&arg_list1), args2(&arg_list2);
69 81
70 // Should queue messages. 82 // Should queue messages.
71 sync_js_controller.ProcessJsMessage("test1", args2, 83 sync_js_controller.ProcessJsMessage(
72 WeakHandle<JsReplyHandler>()); 84 "test1",
73 sync_js_controller.ProcessJsMessage("test2", args1, 85 args2,
74 WeakHandle<JsReplyHandler>()); 86 mock_reply_handler.AsWeakHandle());
87 sync_js_controller.ProcessJsMessage(
88 "test2",
89 args1,
90 mock_reply_handler.AsWeakHandle());
75 91
92 // Should do nothing.
93 PumpLoop();
76 Mock::VerifyAndClearExpectations(&mock_backend); 94 Mock::VerifyAndClearExpectations(&mock_backend);
77 95
78 // TODO(akalin): Write matchers for WeakHandle and use them here
79 // instead of _.
80 EXPECT_CALL(mock_backend, SetJsEventHandler(_));
81 EXPECT_CALL(mock_backend, ProcessJsMessage("test1", HasArgs(args2), _));
82 EXPECT_CALL(mock_backend, ProcessJsMessage("test2", HasArgs(args1), _));
83 96
84 // Should call the queued messages. 97 // Should call the queued messages.
98 EXPECT_CALL(mock_backend, SetJsEventHandler(_));
99 EXPECT_CALL(mock_backend, ProcessJsMessage("test1", HasArgs(args2), _))
100 .WillOnce(ReplyToMessage("test1_reply"));
101 EXPECT_CALL(mock_backend, ProcessJsMessage("test2", HasArgs(args1), _))
102 .WillOnce(ReplyToMessage("test2_reply"));
103 EXPECT_CALL(mock_reply_handler, HandleJsReply("test1_reply", _));
104 EXPECT_CALL(mock_reply_handler, HandleJsReply("test2_reply", _));
105
85 sync_js_controller.AttachJsBackend(mock_backend.AsWeakHandle()); 106 sync_js_controller.AttachJsBackend(mock_backend.AsWeakHandle());
86 PumpLoop(); 107 PumpLoop();
87 108
88 // Should do nothing. 109 // Should do nothing.
89 sync_js_controller.AttachJsBackend(WeakHandle<JsBackend>()); 110 sync_js_controller.AttachJsBackend(WeakHandle<JsBackend>());
90 PumpLoop(); 111 PumpLoop();
91 112
92 // Should also do nothing. 113 // Should also do nothing.
93 sync_js_controller.AttachJsBackend(WeakHandle<JsBackend>()); 114 sync_js_controller.AttachJsBackend(WeakHandle<JsBackend>());
94 PumpLoop(); 115 PumpLoop();
(...skipping 22 matching lines...) Expand all
117 sync_js_controller.HandleJsEvent("anotherevent", details2); 138 sync_js_controller.HandleJsEvent("anotherevent", details2);
118 sync_js_controller.RemoveJsEventHandler(&event_handler1); 139 sync_js_controller.RemoveJsEventHandler(&event_handler1);
119 sync_js_controller.RemoveJsEventHandler(&event_handler2); 140 sync_js_controller.RemoveJsEventHandler(&event_handler2);
120 sync_js_controller.HandleJsEvent("droppedevent", details2); 141 sync_js_controller.HandleJsEvent("droppedevent", details2);
121 142
122 PumpLoop(); 143 PumpLoop();
123 } 144 }
124 145
125 } // namespace 146 } // namespace
126 } // namespace syncer 147 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698