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

Unified Diff: mojo/edk/js/handle_unittest.cc

Issue 703273002: Update mojo sdk to rev 04a510fb37db10642e156957f9b2c11c2f6442ac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix content/child -> mojo/common linking Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/edk/js/handle_close_observer.h ('k') | mojo/edk/js/support.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/js/handle_unittest.cc
diff --git a/mojo/edk/js/handle_unittest.cc b/mojo/edk/js/handle_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..53f474edbbf57c30225b43b6d09d53e0a7f18433
--- /dev/null
+++ b/mojo/edk/js/handle_unittest.cc
@@ -0,0 +1,90 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/macros.h"
+#include "mojo/edk/js/handle.h"
+#include "mojo/edk/js/handle_close_observer.h"
+#include "mojo/public/cpp/system/core.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+namespace js {
+
+class HandleWrapperTest : public testing::Test,
+ public HandleCloseObserver {
+ public:
+ HandleWrapperTest() : closes_observed_(0) {}
+
+ void OnWillCloseHandle() override { closes_observed_++; }
+
+ protected:
+ int closes_observed_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(HandleWrapperTest);
+};
+
+class TestHandleWrapper : public HandleWrapper {
+ public:
+ explicit TestHandleWrapper(MojoHandle handle) : HandleWrapper(handle) {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TestHandleWrapper);
+};
+
+// Test that calling Close() on a HandleWrapper for an invalid handle does not
+// notify observers.
+TEST_F(HandleWrapperTest, CloseWithInvalidHandle) {
+ {
+ TestHandleWrapper wrapper(MOJO_HANDLE_INVALID);
+ wrapper.AddCloseObserver(this);
+ ASSERT_EQ(0, closes_observed_);
+ wrapper.Close();
+ EXPECT_EQ(0, closes_observed_);
+ }
+ EXPECT_EQ(0, closes_observed_);
+}
+
+// Test that destroying a HandleWrapper for an invalid handle does not notify
+// observers.
+TEST_F(HandleWrapperTest, DestroyWithInvalidHandle) {
+ {
+ TestHandleWrapper wrapper(MOJO_HANDLE_INVALID);
+ wrapper.AddCloseObserver(this);
+ ASSERT_EQ(0, closes_observed_);
+ }
+ EXPECT_EQ(0, closes_observed_);
+}
+
+// Test that calling Close on a HandleWrapper for a valid handle notifies
+// observers once.
+TEST_F(HandleWrapperTest, CloseWithValidHandle) {
+ {
+ mojo::MessagePipe pipe;
+ TestHandleWrapper wrapper(pipe.handle0.release().value());
+ wrapper.AddCloseObserver(this);
+ ASSERT_EQ(0, closes_observed_);
+ wrapper.Close();
+ EXPECT_EQ(1, closes_observed_);
+ // Check that calling close again doesn't notify observers.
+ wrapper.Close();
+ EXPECT_EQ(1, closes_observed_);
+ }
+ // Check that destroying a closed HandleWrapper doesn't notify observers.
+ EXPECT_EQ(1, closes_observed_);
+}
+
+// Test that destroying a HandleWrapper for a valid handle notifies observers.
+TEST_F(HandleWrapperTest, DestroyWithValidHandle) {
+ {
+ mojo::MessagePipe pipe;
+ TestHandleWrapper wrapper(pipe.handle0.release().value());
+ wrapper.AddCloseObserver(this);
+ ASSERT_EQ(0, closes_observed_);
+ }
+ EXPECT_EQ(1, closes_observed_);
+}
+
+} // namespace js
+} // namespace mojo
« no previous file with comments | « mojo/edk/js/handle_close_observer.h ('k') | mojo/edk/js/support.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698