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

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

Issue 98323003: Revert 238348 "Clean up TestProfileSyncService and related tests" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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
« no previous file with comments | « trunk/src/sync/internal_api/test/sync_manager_for_profile_sync_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
37 TEST_F(SyncJsControllerTest, Messages) { 33 TEST_F(SyncJsControllerTest, Messages) {
38 InSequence dummy; 34 InSequence dummy;
39 // |mock_backend| needs to outlive |sync_js_controller|. 35 // |mock_backend| needs to outlive |sync_js_controller|.
40 StrictMock<MockJsBackend> mock_backend; 36 StrictMock<MockJsBackend> mock_backend;
41 StrictMock<MockJsReplyHandler> mock_reply_handler;
42 SyncJsController sync_js_controller; 37 SyncJsController sync_js_controller;
43 38
44 base::ListValue arg_list1, arg_list2; 39 base::ListValue arg_list1, arg_list2;
45 arg_list1.Append(new base::FundamentalValue(false)); 40 arg_list1.Append(new base::FundamentalValue(false));
46 arg_list2.Append(new base::FundamentalValue(5)); 41 arg_list2.Append(new base::FundamentalValue(5));
47 JsArgList args1(&arg_list1), args2(&arg_list2); 42 JsArgList args1(&arg_list1), args2(&arg_list2);
48 43
44 // TODO(akalin): Write matchers for WeakHandle and use them here
45 // instead of _.
49 EXPECT_CALL(mock_backend, SetJsEventHandler(_)); 46 EXPECT_CALL(mock_backend, SetJsEventHandler(_));
50 EXPECT_CALL(mock_backend, ProcessJsMessage("test1", HasArgs(args2), _)) 47 EXPECT_CALL(mock_backend, ProcessJsMessage("test1", HasArgs(args2), _));
51 .WillOnce(ReplyToMessage("test1_reply")); 48 EXPECT_CALL(mock_backend, ProcessJsMessage("test2", HasArgs(args1), _));
52 EXPECT_CALL(mock_backend, ProcessJsMessage("test2", HasArgs(args1), _))
53 .WillOnce(ReplyToMessage("test2_reply"));
54 49
55 sync_js_controller.AttachJsBackend(mock_backend.AsWeakHandle()); 50 sync_js_controller.AttachJsBackend(mock_backend.AsWeakHandle());
56 sync_js_controller.ProcessJsMessage("test1", 51 sync_js_controller.ProcessJsMessage("test1", args2,
57 args2, 52 WeakHandle<JsReplyHandler>());
58 mock_reply_handler.AsWeakHandle()); 53 sync_js_controller.ProcessJsMessage("test2", args1,
59 sync_js_controller.ProcessJsMessage("test2", 54 WeakHandle<JsReplyHandler>());
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", _));
66 PumpLoop(); 55 PumpLoop();
67 56
68 // Let destructor of |sync_js_controller| call RemoveBackend(). 57 // Let destructor of |sync_js_controller| call RemoveBackend().
69 } 58 }
70 59
71 TEST_F(SyncJsControllerTest, QueuedMessages) { 60 TEST_F(SyncJsControllerTest, QueuedMessages) {
72 // |mock_backend| needs to outlive |sync_js_controller|. 61 // |mock_backend| needs to outlive |sync_js_controller|.
73 StrictMock<MockJsBackend> mock_backend; 62 StrictMock<MockJsBackend> mock_backend;
74 StrictMock<MockJsReplyHandler> mock_reply_handler;
75 SyncJsController sync_js_controller; 63 SyncJsController sync_js_controller;
76 64
77 base::ListValue arg_list1, arg_list2; 65 base::ListValue arg_list1, arg_list2;
78 arg_list1.Append(new base::FundamentalValue(false)); 66 arg_list1.Append(new base::FundamentalValue(false));
79 arg_list2.Append(new base::FundamentalValue(5)); 67 arg_list2.Append(new base::FundamentalValue(5));
80 JsArgList args1(&arg_list1), args2(&arg_list2); 68 JsArgList args1(&arg_list1), args2(&arg_list2);
81 69
82 // Should queue messages. 70 // Should queue messages.
83 sync_js_controller.ProcessJsMessage( 71 sync_js_controller.ProcessJsMessage("test1", args2,
84 "test1", 72 WeakHandle<JsReplyHandler>());
85 args2, 73 sync_js_controller.ProcessJsMessage("test2", args1,
86 mock_reply_handler.AsWeakHandle()); 74 WeakHandle<JsReplyHandler>());
87 sync_js_controller.ProcessJsMessage(
88 "test2",
89 args1,
90 mock_reply_handler.AsWeakHandle());
91 75
92 // Should do nothing.
93 PumpLoop();
94 Mock::VerifyAndClearExpectations(&mock_backend); 76 Mock::VerifyAndClearExpectations(&mock_backend);
95 77
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), _));
96 83
97 // Should call the queued messages. 84 // 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
106 sync_js_controller.AttachJsBackend(mock_backend.AsWeakHandle()); 85 sync_js_controller.AttachJsBackend(mock_backend.AsWeakHandle());
107 PumpLoop(); 86 PumpLoop();
108 87
109 // Should do nothing. 88 // Should do nothing.
110 sync_js_controller.AttachJsBackend(WeakHandle<JsBackend>()); 89 sync_js_controller.AttachJsBackend(WeakHandle<JsBackend>());
111 PumpLoop(); 90 PumpLoop();
112 91
113 // Should also do nothing. 92 // Should also do nothing.
114 sync_js_controller.AttachJsBackend(WeakHandle<JsBackend>()); 93 sync_js_controller.AttachJsBackend(WeakHandle<JsBackend>());
115 PumpLoop(); 94 PumpLoop();
(...skipping 22 matching lines...) Expand all
138 sync_js_controller.HandleJsEvent("anotherevent", details2); 117 sync_js_controller.HandleJsEvent("anotherevent", details2);
139 sync_js_controller.RemoveJsEventHandler(&event_handler1); 118 sync_js_controller.RemoveJsEventHandler(&event_handler1);
140 sync_js_controller.RemoveJsEventHandler(&event_handler2); 119 sync_js_controller.RemoveJsEventHandler(&event_handler2);
141 sync_js_controller.HandleJsEvent("droppedevent", details2); 120 sync_js_controller.HandleJsEvent("droppedevent", details2);
142 121
143 PumpLoop(); 122 PumpLoop();
144 } 123 }
145 124
146 } // namespace 125 } // namespace
147 } // namespace syncer 126 } // namespace syncer
OLDNEW
« no previous file with comments | « trunk/src/sync/internal_api/test/sync_manager_for_profile_sync_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698