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

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: address comments 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 };
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
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