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

Side by Side Diff: mojo/apps/js/test/handle_unittest.cc

Issue 534953002: Mojo: Cancel WaitingCallbacks when their HandleWrappers are closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DISALLOW_COPY_AND_ASSIGN Created 6 years, 3 months 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 unified diff | Download patch
« no previous file with comments | « mojo/apps/js/test/BUILD.gn ('k') | mojo/bindings/js/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
31 private:
32 DISALLOW_COPY_AND_ASSIGN(TestHandleWrapper);
33 };
34
35 // Test that calling Close() on a HandleWrapper for an invalid handle does not
36 // notify observers.
37 TEST_F(HandleWrapperTest, CloseWithInvalidHandle) {
38 {
39 TestHandleWrapper wrapper(MOJO_HANDLE_INVALID);
40 wrapper.AddCloseObserver(this);
41 ASSERT_EQ(0, closes_observed_);
42 wrapper.Close();
43 EXPECT_EQ(0, closes_observed_);
44 }
45 EXPECT_EQ(0, closes_observed_);
46 }
47
48 // Test that destroying a HandleWrapper for an invalid handle does not notify
49 // observers.
50 TEST_F(HandleWrapperTest, DestroyWithInvalidHandle) {
51 {
52 TestHandleWrapper wrapper(MOJO_HANDLE_INVALID);
53 wrapper.AddCloseObserver(this);
54 ASSERT_EQ(0, closes_observed_);
55 }
56 EXPECT_EQ(0, closes_observed_);
57 }
58
59 // Test that calling Close on a HandleWrapper for a valid handle notifies
60 // observers once.
61 TEST_F(HandleWrapperTest, CloseWithValidHandle) {
62 {
63 mojo::MessagePipe pipe;
64 TestHandleWrapper wrapper(pipe.handle0.release().value());
65 wrapper.AddCloseObserver(this);
66 ASSERT_EQ(0, closes_observed_);
67 wrapper.Close();
68 EXPECT_EQ(1, closes_observed_);
69 // Check that calling close again doesn't notify observers.
70 wrapper.Close();
71 EXPECT_EQ(1, closes_observed_);
72 }
73 // Check that destroying a closed HandleWrapper doesn't notify observers.
74 EXPECT_EQ(1, closes_observed_);
75 }
76
77 // Test that destroying a HandleWrapper for a valid handle notifies observers.
78 TEST_F(HandleWrapperTest, DestroyWithValidHandle) {
79 {
80 mojo::MessagePipe pipe;
81 TestHandleWrapper wrapper(pipe.handle0.release().value());
82 wrapper.AddCloseObserver(this);
83 ASSERT_EQ(0, closes_observed_);
84 }
85 EXPECT_EQ(1, closes_observed_);
86 }
87
88 } // namespace js
89 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/apps/js/test/BUILD.gn ('k') | mojo/bindings/js/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698