Index: mojo/public/cpp/bindings/tests/handle_passing_unittest.cc |
diff --git a/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc b/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc |
index 485937d8291e8fad2caf910efd8df5b34ee6482c..7f886b69f5f2e7282bc7a55ae805fa0b8bfeeb8c 100644 |
--- a/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc |
+++ b/mojo/public/cpp/bindings/tests/handle_passing_unittest.cc |
@@ -15,6 +15,36 @@ namespace { |
const char kText1[] = "hello"; |
const char kText2[] = "world"; |
+class StringRecorder { |
+ public: |
+ explicit StringRecorder(std::string* buf) : buf_(buf) { |
+ } |
+ void Run(const String& a) const { |
+ *buf_ = a.To<std::string>(); |
+ } |
+ private: |
+ std::string* buf_; |
+}; |
+ |
+class SampleObjectImpl : public InterfaceImpl<sample::Object> { |
+ public: |
+ virtual void OnConnectionError() MOJO_OVERRIDE { |
+ delete this; |
+ } |
+ |
+ virtual void SetName(const mojo::String& name) MOJO_OVERRIDE { |
+ name_ = name; |
+ } |
+ |
+ virtual void GetName(const mojo::Callback<void(mojo::String)>& callback) |
+ MOJO_OVERRIDE { |
+ callback.Run(name_); |
+ } |
+ |
+ private: |
+ std::string name_; |
+}; |
+ |
class SampleFactoryImpl : public InterfaceImpl<sample::Factory> { |
public: |
virtual void OnConnectionError() MOJO_OVERRIDE { |
@@ -65,6 +95,12 @@ class SampleFactoryImpl : public InterfaceImpl<sample::Factory> { |
client()->DidStuff2(data); |
} |
+ virtual void CreateObject(InterfaceRequest<sample::Object> object_request) |
+ MOJO_OVERRIDE { |
+ EXPECT_TRUE(object_request.is_pending()); |
+ BindToRequest(new SampleObjectImpl(), &object_request); |
+ } |
+ |
private: |
ScopedMessagePipeHandle pipe1_; |
}; |
@@ -259,6 +295,37 @@ TEST_F(HandlePassingTest, IsHandle) { |
EXPECT_FALSE(internal::IsHandle<String>::value); |
} |
+TEST_F(HandlePassingTest, CreateObject) { |
+ sample::FactoryPtr factory; |
+ BindToProxy(new SampleFactoryImpl(), &factory); |
+ |
+ sample::ObjectPtr object1; |
+ EXPECT_FALSE(object1.get()); |
+ |
+ InterfaceRequest<sample::Object> object1_request = Get(&object1); |
+ EXPECT_TRUE(object1_request.is_pending()); |
+ factory->CreateObject(object1_request.Pass()); |
+ EXPECT_FALSE(object1_request.is_pending()); // We've passed the request. |
+ |
+ ASSERT_TRUE(object1.get()); |
+ object1->SetName("object1"); |
+ |
+ sample::ObjectPtr object2; |
+ factory->CreateObject(Get(&object2)); |
+ object2->SetName("object2"); |
+ |
+ std::string name1; |
+ object1->GetName(StringRecorder(&name1)); |
+ |
+ std::string name2; |
+ object2->GetName(StringRecorder(&name2)); |
+ |
+ PumpMessages(); // Yield for results. |
+ |
+ EXPECT_EQ(std::string("object1"), name1); |
+ EXPECT_EQ(std::string("object2"), name2); |
+} |
+ |
} // namespace |
} // namespace test |
} // namespace mojo |