summaryrefslogtreecommitdiffstats
path: root/mojo/public/tests
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-07 03:34:00 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-07 03:34:00 +0000
commit8ec86a9477592995a5098567041f6fcae6a01a65 (patch)
tree18b4f325afd88338299fb7eb9b3b96bae1860ed4 /mojo/public/tests
parentb8342e09e739edeaa99b0c34e6e85b62f18b7277 (diff)
downloadchromium_src-8ec86a9477592995a5098567041f6fcae6a01a65.zip
chromium_src-8ec86a9477592995a5098567041f6fcae6a01a65.tar.gz
chromium_src-8ec86a9477592995a5098567041f6fcae6a01a65.tar.bz2
Mojo: Expose error state from Connector through RemotePtr
(This is part 1 of adding better error handling to the bindings system.) BUG=325321 Review URL: https://codereview.chromium.org/105693005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239305 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/public/tests')
-rw-r--r--mojo/public/tests/bindings_connector_unittest.cc2
-rw-r--r--mojo/public/tests/bindings_remote_ptr_unittest.cc45
2 files changed, 39 insertions, 8 deletions
diff --git a/mojo/public/tests/bindings_connector_unittest.cc b/mojo/public/tests/bindings_connector_unittest.cc
index 737f26a..a20190e 100644
--- a/mojo/public/tests/bindings_connector_unittest.cc
+++ b/mojo/public/tests/bindings_connector_unittest.cc
@@ -168,7 +168,7 @@ TEST_F(BindingsConnectorTest, WriteToClosedPipe) {
bool ok = connector0->Accept(&message);
EXPECT_FALSE(ok);
- EXPECT_TRUE(connector0->EncounteredError());
+ EXPECT_TRUE(connector0->encountered_error());
}
// Enable this test once MojoWriteMessage supports passing handles.
diff --git a/mojo/public/tests/bindings_remote_ptr_unittest.cc b/mojo/public/tests/bindings_remote_ptr_unittest.cc
index c236695..beada47 100644
--- a/mojo/public/tests/bindings_remote_ptr_unittest.cc
+++ b/mojo/public/tests/bindings_remote_ptr_unittest.cc
@@ -12,6 +12,8 @@ namespace test {
class MathCalculatorImpl : public math::CalculatorStub {
public:
+ virtual ~MathCalculatorImpl() {}
+
explicit MathCalculatorImpl(ScopedMessagePipeHandle pipe)
: ui_(pipe.Pass()),
total_(0.0) {
@@ -45,6 +47,10 @@ class MathCalculatorUIImpl : public math::CalculatorUIStub {
calculator_.SetPeer(this);
}
+ bool encountered_error() const {
+ return calculator_.encountered_error();
+ }
+
void Add(double value) {
calculator_->Add(value);
}
@@ -115,33 +121,58 @@ TEST_F(BindingsRemotePtrTest, Movable) {
RemotePtr<math::Calculator> a;
RemotePtr<math::Calculator> b(pipe0_.Pass());
- EXPECT_FALSE(a.is_valid());
- EXPECT_TRUE(b.is_valid());
+ EXPECT_TRUE(a.is_null());
+ EXPECT_FALSE(b.is_null());
a = b.Pass();
- EXPECT_TRUE(a.is_valid());
- EXPECT_FALSE(b.is_valid());
+ EXPECT_FALSE(a.is_null());
+ EXPECT_TRUE(b.is_null());
}
TEST_F(BindingsRemotePtrTest, Resettable) {
RemotePtr<math::Calculator> a;
- EXPECT_FALSE(a.is_valid());
+ EXPECT_TRUE(a.is_null());
MessagePipeHandle handle = pipe0_.get();
a.reset(pipe0_.Pass());
- EXPECT_TRUE(a.is_valid());
+ EXPECT_FALSE(a.is_null());
a.reset();
- EXPECT_FALSE(a.is_valid());
+ EXPECT_TRUE(a.is_null());
// Test that handle was closed.
EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, CloseRaw(handle));
}
+TEST_F(BindingsRemotePtrTest, EncounteredError) {
+ MathCalculatorImpl* calculator = new MathCalculatorImpl(pipe0_.Pass());
+
+ MathCalculatorUIImpl calculator_ui(pipe1_.Pass());
+
+ calculator_ui.Add(2.0);
+ PumpMessages();
+ EXPECT_EQ(2.0, calculator_ui.GetOutput());
+ EXPECT_FALSE(calculator_ui.encountered_error());
+
+ calculator_ui.Multiply(5.0);
+ EXPECT_FALSE(calculator_ui.encountered_error());
+
+ // Close the other side of the pipe.
+ delete calculator;
+
+ // The state change isn't picked up locally yet.
+ EXPECT_FALSE(calculator_ui.encountered_error());
+
+ PumpMessages();
+
+ // OK, now we see the error.
+ EXPECT_TRUE(calculator_ui.encountered_error());
+}
+
} // namespace test
} // namespace mojo