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

Side by Side Diff: chromeos/dbus/ibus/ibus_panel_service_unittest.cc

Issue 11416243: Change UpdateProperties to UpdateProperty (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only for mistake Created 8 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 | « chromeos/dbus/ibus/ibus_panel_service.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 "chromeos/dbus/ibus/ibus_panel_service.h" 5 #include "chromeos/dbus/ibus/ibus_panel_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 private: 48 private:
49 DISALLOW_COPY_AND_ASSIGN(MockIBusPanelCandidateWindowHandler); 49 DISALLOW_COPY_AND_ASSIGN(MockIBusPanelCandidateWindowHandler);
50 }; 50 };
51 51
52 class MockIBusPanelPropertyHandler : public IBusPanelPropertyHandlerInterface { 52 class MockIBusPanelPropertyHandler : public IBusPanelPropertyHandlerInterface {
53 public: 53 public:
54 MockIBusPanelPropertyHandler() {} 54 MockIBusPanelPropertyHandler() {}
55 MOCK_METHOD1(RegisterProperties, 55 MOCK_METHOD1(RegisterProperties,
56 void(const ibus::IBusPropertyList& properties)); 56 void(const ibus::IBusPropertyList& properties));
57 MOCK_METHOD1(UpdateProperties, 57 MOCK_METHOD1(UpdateProperty, void(const ibus::IBusProperty& property));
58 void(const ibus::IBusPropertyList& properties));
59 58
60 private: 59 private:
61 DISALLOW_COPY_AND_ASSIGN(MockIBusPanelPropertyHandler); 60 DISALLOW_COPY_AND_ASSIGN(MockIBusPanelPropertyHandler);
62 }; 61 };
63 62
64 class MockResponseSender { 63 class MockResponseSender {
65 public: 64 public:
66 MOCK_METHOD1(Run, void(dbus::Response* reponse)); 65 MOCK_METHOD1(Run, void(dbus::Response* reponse));
67 }; 66 };
68 67
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 ASSERT_EQ(expected_keys_.size(), properties.size()); 175 ASSERT_EQ(expected_keys_.size(), properties.size());
177 for (size_t i = 0; i < properties.size(); ++i) { 176 for (size_t i = 0; i < properties.size(); ++i) {
178 EXPECT_EQ(expected_keys_[i], properties[i]->key()); 177 EXPECT_EQ(expected_keys_[i], properties[i]->key());
179 } 178 }
180 } 179 }
181 180
182 private: 181 private:
183 const std::vector<std::string> expected_keys_; 182 const std::vector<std::string> expected_keys_;
184 }; 183 };
185 184
185 // This class is used to verify that a method call which has a Property object.
186 // This class verifies a method call has correct argument based on |key|.
187 class PropertyVerifier {
188 public:
189 explicit PropertyVerifier(const std::string& key) : key_(key) {}
190
191 // Verifies the given |resposne| has IBusPropertyList.
192 void Verify(const ibus::IBusProperty& property) {
193 EXPECT_EQ(key_, property.key());
194 }
195
196 private:
197 const std::string key_;
198 };
199
186 } // namespace 200 } // namespace
187 201
188 class IBusPanelServiceTest : public testing::Test { 202 class IBusPanelServiceTest : public testing::Test {
189 public: 203 public:
190 IBusPanelServiceTest() {} 204 IBusPanelServiceTest() {}
191 205
192 virtual void SetUp() OVERRIDE { 206 virtual void SetUp() OVERRIDE {
193 // Create a mock bus. 207 // Create a mock bus.
194 dbus::Bus::Options options; 208 dbus::Bus::Options options;
195 options.bus_type = dbus::Bus::SYSTEM; 209 options.bus_type = dbus::Bus::SYSTEM;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 256 Invoke(this, &IBusPanelServiceTest::OnMethodExported));
243 257
244 EXPECT_CALL(*mock_exported_object_, ExportMethod( 258 EXPECT_CALL(*mock_exported_object_, ExportMethod(
245 ibus::panel::kServiceInterface, 259 ibus::panel::kServiceInterface,
246 ibus::panel::kRegisterPropertiesMethod, _, _)) 260 ibus::panel::kRegisterPropertiesMethod, _, _))
247 .WillRepeatedly( 261 .WillRepeatedly(
248 Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 262 Invoke(this, &IBusPanelServiceTest::OnMethodExported));
249 263
250 EXPECT_CALL(*mock_exported_object_, ExportMethod( 264 EXPECT_CALL(*mock_exported_object_, ExportMethod(
251 ibus::panel::kServiceInterface, 265 ibus::panel::kServiceInterface,
252 ibus::panel::kUpdatePropertiesMethod, _, _)) 266 ibus::panel::kUpdatePropertyMethod, _, _))
253 .WillRepeatedly( 267 .WillRepeatedly(
254 Invoke(this, &IBusPanelServiceTest::OnMethodExported)); 268 Invoke(this, &IBusPanelServiceTest::OnMethodExported));
255 269
256 // Suppress uninteresting mock function call warning. 270 // Suppress uninteresting mock function call warning.
257 EXPECT_CALL(*mock_bus_.get(), 271 EXPECT_CALL(*mock_bus_.get(),
258 AssertOnOriginThread()) 272 AssertOnOriginThread())
259 .WillRepeatedly(Return()); 273 .WillRepeatedly(Return());
260 274
261 // Create a service 275 // Create a service
262 service_.reset(IBusPanelService::Create( 276 service_.reset(IBusPanelService::Create(
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 ibus::panel::kRegisterPropertiesMethod); 555 ibus::panel::kRegisterPropertiesMethod);
542 method_call.SetSerial(1UL); 556 method_call.SetSerial(1UL);
543 dbus::MessageWriter writer(&method_call); 557 dbus::MessageWriter writer(&method_call);
544 ibus::AppendIBusPropertyList(properties, &writer); 558 ibus::AppendIBusPropertyList(properties, &writer);
545 559
546 // Call exported function. 560 // Call exported function.
547 EXPECT_NE(method_callback_map_.find(ibus::panel::kRegisterPropertiesMethod), 561 EXPECT_NE(method_callback_map_.find(ibus::panel::kRegisterPropertiesMethod),
548 method_callback_map_.end()); 562 method_callback_map_.end());
549 method_callback_map_[ibus::panel::kRegisterPropertiesMethod].Run( 563 method_callback_map_[ibus::panel::kRegisterPropertiesMethod].Run(
550 &method_call, 564 &method_call,
551 base::Bind(&MockResponseSender::Run, 565 base::Bind(&MockResponseSender::Run, base::Unretained(&response_sender)));
552 base::Unretained(&response_sender)));
553 } 566 }
554 567
555 TEST_F(IBusPanelServiceTest, UpdatePropertiesTest) { 568 TEST_F(IBusPanelServiceTest, UpdatePropertyTest) {
556 // Set expectations. 569 // Set expectations.
557 std::vector<std::string> keys; 570 const char kKey[] = "key";
558 keys.push_back("key1"); 571 ibus::IBusProperty property;
559 keys.push_back("key2"); 572 property.set_key(kKey);
560 keys.push_back("key3");
561 ibus::IBusPropertyList properties;
562 for (size_t i = 0; i < keys.size(); ++i) {
563 ibus::IBusProperty* property = new ibus::IBusProperty;
564 property->set_key(keys[i]);
565 properties.push_back(property);
566 }
567 573
568 PropertyListVerifier response_expectation(keys); 574 PropertyVerifier response_expectation(kKey);
569 EXPECT_CALL(*property_handler_, UpdateProperties(_)) 575 EXPECT_CALL(*property_handler_, UpdateProperty(_))
570 .WillOnce(Invoke(&response_expectation, 576 .WillOnce(Invoke(&response_expectation, &PropertyVerifier::Verify));
571 &PropertyListVerifier::Verify));
572 577
573 MockResponseSender response_sender; 578 MockResponseSender response_sender;
574 EXPECT_CALL(response_sender, Run(_)); 579 EXPECT_CALL(response_sender, Run(_));
575 580
576 // Create method call; 581 // Create method call;
577 dbus::MethodCall method_call(ibus::panel::kServiceInterface, 582 dbus::MethodCall method_call(ibus::panel::kServiceInterface,
578 ibus::panel::kUpdatePropertiesMethod); 583 ibus::panel::kUpdatePropertyMethod);
579 method_call.SetSerial(1UL); 584 method_call.SetSerial(1UL);
580 dbus::MessageWriter writer(&method_call); 585 dbus::MessageWriter writer(&method_call);
581 ibus::AppendIBusPropertyList(properties, &writer); 586 ibus::AppendIBusProperty(property, &writer);
582 587
583 // Call exported function. 588 // Call exported function.
584 EXPECT_NE(method_callback_map_.find(ibus::panel::kUpdatePropertiesMethod), 589 EXPECT_NE(method_callback_map_.find(ibus::panel::kUpdatePropertyMethod),
585 method_callback_map_.end()); 590 method_callback_map_.end());
586 method_callback_map_[ibus::panel::kUpdatePropertiesMethod].Run( 591 method_callback_map_[ibus::panel::kUpdatePropertyMethod].Run(
587 &method_call, 592 &method_call,
588 base::Bind(&MockResponseSender::Run, 593 base::Bind(&MockResponseSender::Run,
589 base::Unretained(&response_sender))); 594 base::Unretained(&response_sender)));
590 } 595 }
591 596
592 } // namespace ibus 597 } // namespace ibus
593 } // namespace chromeos 598 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/ibus/ibus_panel_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698