Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "mojo/bindings/js/handle.h" | |
| 6 #include "mojo/bindings/js/handle_close_observer.h" | |
| 7 #include "mojo/public/cpp/system/core.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 namespace mojo { | |
| 11 namespace js { | |
| 12 | |
| 13 class HandleWrapperTest : public testing::Test, | |
| 14 public gin::HandleCloseObserver { | |
| 15 public: | |
| 16 HandleWrapperTest() : closes_observed_(0) {} | |
| 17 | |
| 18 virtual void OnWillCloseHandle() OVERRIDE { closes_observed_++; } | |
| 19 | |
| 20 protected: | |
| 21 int closes_observed_; | |
| 22 | |
| 23 private: | |
| 24 DISALLOW_COPY_AND_ASSIGN(HandleWrapperTest); | |
| 25 }; | |
| 26 | |
| 27 class TestHandleWrapper : public gin::HandleWrapper { | |
| 28 public: | |
| 29 explicit TestHandleWrapper(MojoHandle handle) : HandleWrapper(handle) {} | |
| 30 }; | |
|
sky
2014/09/08 16:07:01
private:DISALLOW...
Sam McNally
2014/09/09 00:02:46
Done.
| |
| 31 | |
| 32 // Test that calling Close() on a HandleWrapper for an invalid handle does not | |
| 33 // notify observers. | |
| 34 TEST_F(HandleWrapperTest, CloseWithInvalidHandle) { | |
| 35 { | |
| 36 TestHandleWrapper wrapper(MOJO_HANDLE_INVALID); | |
| 37 wrapper.AddCloseObserver(this); | |
| 38 ASSERT_EQ(0, closes_observed_); | |
| 39 wrapper.Close(); | |
| 40 EXPECT_EQ(0, closes_observed_); | |
| 41 } | |
| 42 EXPECT_EQ(0, closes_observed_); | |
| 43 } | |
| 44 | |
| 45 // Test that destroying a HandleWrapper for an invalid handle does not notify | |
| 46 // observers. | |
| 47 TEST_F(HandleWrapperTest, DestroyWithInvalidHandle) { | |
| 48 { | |
| 49 TestHandleWrapper wrapper(MOJO_HANDLE_INVALID); | |
| 50 wrapper.AddCloseObserver(this); | |
| 51 ASSERT_EQ(0, closes_observed_); | |
| 52 } | |
| 53 EXPECT_EQ(0, closes_observed_); | |
| 54 } | |
| 55 | |
| 56 // Test that calling Close on a HandleWrapper for a valid handle notifies | |
| 57 // observers once. | |
| 58 TEST_F(HandleWrapperTest, CloseWithValidHandle) { | |
| 59 { | |
| 60 mojo::MessagePipe pipe; | |
| 61 TestHandleWrapper wrapper(pipe.handle0.release().value()); | |
| 62 wrapper.AddCloseObserver(this); | |
| 63 ASSERT_EQ(0, closes_observed_); | |
| 64 wrapper.Close(); | |
| 65 EXPECT_EQ(1, closes_observed_); | |
| 66 // Check that calling close again doesn't notify observers. | |
| 67 wrapper.Close(); | |
| 68 EXPECT_EQ(1, closes_observed_); | |
| 69 } | |
| 70 // Check that destroying a closed HandleWrapper doesn't notify observers. | |
| 71 EXPECT_EQ(1, closes_observed_); | |
| 72 } | |
| 73 | |
| 74 // Test that destroying a HandleWrapper for a valid handle notifies observers. | |
| 75 TEST_F(HandleWrapperTest, DestroyWithValidHandle) { | |
| 76 { | |
| 77 mojo::MessagePipe pipe; | |
| 78 TestHandleWrapper wrapper(pipe.handle0.release().value()); | |
| 79 wrapper.AddCloseObserver(this); | |
| 80 ASSERT_EQ(0, closes_observed_); | |
| 81 } | |
| 82 EXPECT_EQ(1, closes_observed_); | |
| 83 } | |
| 84 | |
| 85 } // namespace js | |
| 86 } // namespace mojo | |
| OLD | NEW |