| 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 91ce84b7d9030865555b1ab12583b242bc810e58..0cd56462555c046ab7ae28ce7fa16f1995524a4b 100644
 | 
| --- a/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
 | 
| +++ b/mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc
 | 
| @@ -2,9 +2,7 @@
 | 
|  // Use of this source code is governed by a BSD-style license that can be
 | 
|  // found in the LICENSE file.
 | 
|  
 | 
| -#include "mojo/public/cpp/bindings/binding.h"
 | 
|  #include "mojo/public/cpp/bindings/error_handler.h"
 | 
| -#include "mojo/public/cpp/bindings/strong_binding.h"
 | 
|  #include "mojo/public/cpp/environment/environment.h"
 | 
|  #include "mojo/public/cpp/utility/run_loop.h"
 | 
|  #include "mojo/public/interfaces/bindings/tests/math_calculator.mojom.h"
 | 
| @@ -31,7 +29,9 @@
 | 
|   public:
 | 
|    ~MathCalculatorImpl() override {}
 | 
|  
 | 
| -  MathCalculatorImpl() : total_(0.0) {}
 | 
| +  MathCalculatorImpl() : total_(0.0), got_connection_(false) {}
 | 
| +
 | 
| +  void OnConnectionEstablished() override { got_connection_ = true; }
 | 
|  
 | 
|    void Clear() override { client()->Output(total_); }
 | 
|  
 | 
| @@ -45,8 +45,11 @@
 | 
|      client()->Output(total_);
 | 
|    }
 | 
|  
 | 
| +  bool got_connection() const { return got_connection_; }
 | 
| +
 | 
|   private:
 | 
|    double total_;
 | 
| +  bool got_connection_;
 | 
|  };
 | 
|  
 | 
|  class MathCalculatorUIImpl : public math::CalculatorUI {
 | 
| @@ -120,7 +123,12 @@
 | 
|   public:
 | 
|    ~ReentrantServiceImpl() override {}
 | 
|  
 | 
| -  ReentrantServiceImpl() : call_depth_(0), max_call_depth_(0) {}
 | 
| +  ReentrantServiceImpl()
 | 
| +      : got_connection_(false), call_depth_(0), max_call_depth_(0) {}
 | 
| +
 | 
| +  void OnConnectionEstablished() override { got_connection_ = true; }
 | 
| +
 | 
| +  bool got_connection() const { return got_connection_; }
 | 
|  
 | 
|    int max_call_depth() { return max_call_depth_; }
 | 
|  
 | 
| @@ -137,6 +145,7 @@
 | 
|    void GetPort(mojo::InterfaceRequest<sample::Port> port) override {}
 | 
|  
 | 
|   private:
 | 
| +  bool got_connection_;
 | 
|    int call_depth_;
 | 
|    int max_call_depth_;
 | 
|  };
 | 
| @@ -154,7 +163,8 @@
 | 
|  
 | 
|  TEST_F(InterfacePtrTest, EndToEnd) {
 | 
|    math::CalculatorPtr calc;
 | 
| -  BindToProxy(new MathCalculatorImpl(), &calc);
 | 
| +  MathCalculatorImpl* impl = BindToProxy(new MathCalculatorImpl(), &calc);
 | 
| +  EXPECT_TRUE(impl->got_connection());
 | 
|  
 | 
|    // Suppose this is instantiated in a process that has pipe1_.
 | 
|    MathCalculatorUIImpl calculator_ui(calc.Pass());
 | 
| @@ -170,6 +180,7 @@
 | 
|  TEST_F(InterfacePtrTest, EndToEnd_Synchronous) {
 | 
|    math::CalculatorPtr calc;
 | 
|    MathCalculatorImpl* impl = BindToProxy(new MathCalculatorImpl(), &calc);
 | 
| +  EXPECT_TRUE(impl->got_connection());
 | 
|  
 | 
|    // Suppose this is instantiated in a process that has pipe1_.
 | 
|    MathCalculatorUIImpl calculator_ui(calc.Pass());
 | 
| @@ -241,7 +252,7 @@
 | 
|    EXPECT_FALSE(calculator_ui.encountered_error());
 | 
|  
 | 
|    // Close the server.
 | 
| -  server->internal_router()->CloseMessagePipe();
 | 
| +  server->internal_state()->router()->CloseMessagePipe();
 | 
|  
 | 
|    // The state change isn't picked up locally yet.
 | 
|    EXPECT_FALSE(calculator_ui.encountered_error());
 | 
| @@ -270,7 +281,7 @@
 | 
|    EXPECT_FALSE(calculator_ui.encountered_error());
 | 
|  
 | 
|    // Close the server.
 | 
| -  server->internal_router()->CloseMessagePipe();
 | 
| +  server->internal_state()->router()->CloseMessagePipe();
 | 
|  
 | 
|    // The state change isn't picked up locally yet.
 | 
|    EXPECT_FALSE(calculator_ui.encountered_error());
 | 
| @@ -326,6 +337,7 @@
 | 
|  TEST_F(InterfacePtrTest, ReentrantWaitForIncomingMethodCall) {
 | 
|    sample::ServicePtr proxy;
 | 
|    ReentrantServiceImpl* impl = BindToProxy(new ReentrantServiceImpl(), &proxy);
 | 
| +  EXPECT_TRUE(impl->got_connection());
 | 
|  
 | 
|    proxy->Frobinate(sample::FooPtr(),
 | 
|                     sample::Service::BAZ_OPTIONS_REGULAR,
 | 
| @@ -339,148 +351,6 @@
 | 
|    EXPECT_EQ(2, impl->max_call_depth());
 | 
|  }
 | 
|  
 | 
| -class StrongMathCalculatorImpl : public math::Calculator, public ErrorHandler {
 | 
| - public:
 | 
| -  StrongMathCalculatorImpl(ScopedMessagePipeHandle handle,
 | 
| -                           bool* error_received,
 | 
| -                           bool* destroyed)
 | 
| -      : error_received_(error_received),
 | 
| -        destroyed_(destroyed),
 | 
| -        binding_(this, handle.Pass()) {
 | 
| -    binding_.set_error_handler(this);
 | 
| -  }
 | 
| -  ~StrongMathCalculatorImpl() override { *destroyed_ = true; }
 | 
| -
 | 
| -  // math::Calculator implementation.
 | 
| -  void Clear() override { binding_.client()->Output(total_); }
 | 
| -
 | 
| -  void Add(double value) override {
 | 
| -    total_ += value;
 | 
| -    binding_.client()->Output(total_);
 | 
| -  }
 | 
| -
 | 
| -  void Multiply(double value) override {
 | 
| -    total_ *= value;
 | 
| -    binding_.client()->Output(total_);
 | 
| -  }
 | 
| -
 | 
| -  // ErrorHandler implementation.
 | 
| -  void OnConnectionError() override { *error_received_ = true; }
 | 
| -
 | 
| - private:
 | 
| -  double total_ = 0.0;
 | 
| -  bool* error_received_;
 | 
| -  bool* destroyed_;
 | 
| -
 | 
| -  StrongBinding<math::Calculator> binding_;
 | 
| -};
 | 
| -
 | 
| -TEST(StrongConnectorTest, Math) {
 | 
| -  Environment env;
 | 
| -  RunLoop loop;
 | 
| -
 | 
| -  bool error_received = false;
 | 
| -  bool destroyed = false;
 | 
| -  MessagePipe pipe;
 | 
| -  new StrongMathCalculatorImpl(pipe.handle0.Pass(), &error_received,
 | 
| -                               &destroyed);
 | 
| -
 | 
| -  math::CalculatorPtr calc;
 | 
| -  calc.Bind(pipe.handle1.Pass());
 | 
| -
 | 
| -  {
 | 
| -    // Suppose this is instantiated in a process that has the other end of the
 | 
| -    // message pipe.
 | 
| -    MathCalculatorUIImpl calculator_ui(calc.Pass());
 | 
| -
 | 
| -    calculator_ui.Add(2.0);
 | 
| -    calculator_ui.Multiply(5.0);
 | 
| -
 | 
| -    loop.RunUntilIdle();
 | 
| -
 | 
| -    EXPECT_EQ(10.0, calculator_ui.GetOutput());
 | 
| -    EXPECT_FALSE(error_received);
 | 
| -    EXPECT_FALSE(destroyed);
 | 
| -  }
 | 
| -  // Destroying calculator_ui should close the pipe and generate an error on the
 | 
| -  // other
 | 
| -  // end which will destroy the instance since it is strongly bound.
 | 
| -
 | 
| -  loop.RunUntilIdle();
 | 
| -  EXPECT_TRUE(error_received);
 | 
| -  EXPECT_TRUE(destroyed);
 | 
| -}
 | 
| -
 | 
| -class WeakMathCalculatorImpl : public math::Calculator, public ErrorHandler {
 | 
| - public:
 | 
| -  WeakMathCalculatorImpl(ScopedMessagePipeHandle handle,
 | 
| -                         bool* error_received,
 | 
| -                         bool* destroyed)
 | 
| -      : error_received_(error_received),
 | 
| -        destroyed_(destroyed),
 | 
| -        binding_(this, handle.Pass()) {
 | 
| -    binding_.set_error_handler(this);
 | 
| -  }
 | 
| -  ~WeakMathCalculatorImpl() override { *destroyed_ = true; }
 | 
| -
 | 
| -  void Clear() override { binding_.client()->Output(total_); }
 | 
| -
 | 
| -  void Add(double value) override {
 | 
| -    total_ += value;
 | 
| -    binding_.client()->Output(total_);
 | 
| -  }
 | 
| -
 | 
| -  void Multiply(double value) override {
 | 
| -    total_ *= value;
 | 
| -    binding_.client()->Output(total_);
 | 
| -  }
 | 
| -
 | 
| -  // ErrorHandler implementation.
 | 
| -  void OnConnectionError() override { *error_received_ = true; }
 | 
| -
 | 
| - private:
 | 
| -  double total_ = 0.0;
 | 
| -  bool* error_received_;
 | 
| -  bool* destroyed_;
 | 
| -
 | 
| -  Binding<math::Calculator> binding_;
 | 
| -};
 | 
| -
 | 
| -TEST(WeakConnectorTest, Math) {
 | 
| -  Environment env;
 | 
| -  RunLoop loop;
 | 
| -
 | 
| -  bool error_received = false;
 | 
| -  bool destroyed = false;
 | 
| -  MessagePipe pipe;
 | 
| -  WeakMathCalculatorImpl impl(pipe.handle0.Pass(), &error_received, &destroyed);
 | 
| -
 | 
| -  math::CalculatorPtr calc;
 | 
| -  calc.Bind(pipe.handle1.Pass());
 | 
| -
 | 
| -  {
 | 
| -    // Suppose this is instantiated in a process that has the other end of the
 | 
| -    // message pipe.
 | 
| -    MathCalculatorUIImpl calculator_ui(calc.Pass());
 | 
| -
 | 
| -    calculator_ui.Add(2.0);
 | 
| -    calculator_ui.Multiply(5.0);
 | 
| -
 | 
| -    loop.RunUntilIdle();
 | 
| -
 | 
| -    EXPECT_EQ(10.0, calculator_ui.GetOutput());
 | 
| -    EXPECT_FALSE(error_received);
 | 
| -    EXPECT_FALSE(destroyed);
 | 
| -    // Destroying calculator_ui should close the pipe and generate an error on
 | 
| -    // the other
 | 
| -    // end which will destroy the instance since it is strongly bound.
 | 
| -  }
 | 
| -
 | 
| -  loop.RunUntilIdle();
 | 
| -  EXPECT_TRUE(error_received);
 | 
| -  EXPECT_FALSE(destroyed);
 | 
| -}
 | 
| -
 | 
|  }  // namespace
 | 
|  }  // namespace test
 | 
|  }  // namespace mojo
 | 
| 
 |