| Index: mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
 | 
| diff --git a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
 | 
| index 0a2f669597ccace6b3ec72d613d0fd28e8a73cd0..830a946cb79e562702bed9ae11210b8c45bdfe02 100644
 | 
| --- a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
 | 
| +++ b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
 | 
| @@ -851,6 +851,58 @@ TEST_F(InterfacePtrTest, ThreadSafeInterfacePointer) {
 | 
|    run_loop.Run();
 | 
|  }
 | 
|  
 | 
| +TEST_F(InterfacePtrTest, BindLaterThreadSafeInterfacePointer) {
 | 
| +  // Create a ThreadSafeInterfacePtr that we'll bind from a different thread.
 | 
| +  scoped_refptr<math::ThreadSafeCalculatorPtr> thread_safe_ptr =
 | 
| +      math::ThreadSafeCalculatorPtr::CreateUnbound();
 | 
| +  ASSERT_TRUE(thread_safe_ptr);
 | 
| +
 | 
| +  // Create and start the thread from where we'll bind the interface pointer.
 | 
| +  base::Thread other_thread("service test thread");
 | 
| +  other_thread.Start();
 | 
| +  const scoped_refptr<base::SingleThreadTaskRunner>& other_thread_task_runner =
 | 
| +      other_thread.message_loop()->task_runner();
 | 
| +  MathCalculatorImpl* math_calc_impl = nullptr;
 | 
| +  {
 | 
| +    base::RunLoop run_loop;
 | 
| +    auto run_method = base::Bind(
 | 
| +        [](const scoped_refptr<base::TaskRunner>& main_task_runner,
 | 
| +           const base::Closure& quit_closure,
 | 
| +           const scoped_refptr<math::ThreadSafeCalculatorPtr>& thread_safe_ptr,
 | 
| +           MathCalculatorImpl** math_calc_impl) {
 | 
| +          math::CalculatorPtr ptr;
 | 
| +          // In real life, the implementation would have a legitimate owner.
 | 
| +          *math_calc_impl = new MathCalculatorImpl(GetProxy(&ptr));
 | 
| +          thread_safe_ptr->BindToCurrentThread(std::move(ptr));
 | 
| +          main_task_runner->PostTask(FROM_HERE, quit_closure);
 | 
| +        },
 | 
| +        base::SequencedTaskRunnerHandle::Get(), run_loop.QuitClosure(),
 | 
| +        thread_safe_ptr, &math_calc_impl);
 | 
| +    other_thread.message_loop()->task_runner()->PostTask(FROM_HERE, run_method);
 | 
| +    run_loop.Run();
 | 
| +  }
 | 
| +
 | 
| +  {
 | 
| +    // The interface ptr is bound, we can call methods on it.
 | 
| +    auto calc_callback =
 | 
| +        base::Bind([](const base::Closure& quit_closure, double result) {
 | 
| +          EXPECT_EQ(123, result);
 | 
| +          quit_closure.Run();
 | 
| +        });
 | 
| +    base::RunLoop run_loop;
 | 
| +    (*thread_safe_ptr)
 | 
| +        ->Add(123, base::Bind(calc_callback, run_loop.QuitClosure()));
 | 
| +    // Block until the method callback is called.
 | 
| +    run_loop.Run();
 | 
| +  }
 | 
| +
 | 
| +  other_thread_task_runner->DeleteSoon(FROM_HERE, math_calc_impl);
 | 
| +
 | 
| +  // Reset the pointer now so the InterfacePtr associated resources can be
 | 
| +  // deleted before the background thread's message loop is invalidated.
 | 
| +  thread_safe_ptr = nullptr;
 | 
| +}
 | 
| +
 | 
|  }  // namespace
 | 
|  }  // namespace test
 | 
|  }  // namespace mojo
 | 
| 
 |