| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "extensions/browser/stash_backend.h" | 8 #include "extensions/browser/stash_backend.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace extensions { | 11 namespace extensions { |
| 12 | 12 |
| 13 class StashServiceTest : public testing::Test, public mojo::ErrorHandler { | 13 class StashServiceTest : public testing::Test, public mojo::ErrorHandler { |
| 14 public: | 14 public: |
| 15 enum Event { | 15 enum Event { |
| 16 EVENT_NONE, | 16 EVENT_NONE, |
| 17 EVENT_STASH_RETRIEVED, | 17 EVENT_STASH_RETRIEVED, |
| 18 }; | 18 }; |
| 19 | 19 |
| 20 StashServiceTest() {} | 20 StashServiceTest() {} |
| 21 | 21 |
| 22 virtual void SetUp() override { | 22 virtual void SetUp() override { |
| 23 expecting_error_ = false; | 23 expecting_error_ = false; |
| 24 expected_event_ = EVENT_NONE; | 24 expected_event_ = EVENT_NONE; |
| 25 stash_backend_.reset(new StashBackend); | 25 stash_backend_.reset(new StashBackend); |
| 26 stash_backend_->BindToRequest(mojo::GetProxy(&stash_service_)); | 26 stash_backend_->BindToRequest(mojo::GetProxy(&stash_service_)); |
| 27 stash_service_.set_error_handler(this); | 27 stash_service_.set_error_handler(this); |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual void OnConnectionError() override { | 30 void OnConnectionError() override { FAIL() << "Unexpected connection error"; } |
| 31 FAIL() << "Unexpected connection error"; | |
| 32 } | |
| 33 | 31 |
| 34 mojo::Array<StashedObjectPtr> RetrieveStash() { | 32 mojo::Array<StashedObjectPtr> RetrieveStash() { |
| 35 mojo::Array<StashedObjectPtr> stash; | 33 mojo::Array<StashedObjectPtr> stash; |
| 36 stash_service_->RetrieveStash(base::Bind( | 34 stash_service_->RetrieveStash(base::Bind( |
| 37 &StashServiceTest::StashRetrieved, base::Unretained(this), &stash)); | 35 &StashServiceTest::StashRetrieved, base::Unretained(this), &stash)); |
| 38 WaitForEvent(EVENT_STASH_RETRIEVED); | 36 WaitForEvent(EVENT_STASH_RETRIEVED); |
| 39 return stash.Pass(); | 37 return stash.Pass(); |
| 40 } | 38 } |
| 41 | 39 |
| 42 void StashRetrieved(mojo::Array<StashedObjectPtr>* output, | 40 void StashRetrieved(mojo::Array<StashedObjectPtr>* output, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 ASSERT_EQ(0u, stashed_objects.size()); | 165 ASSERT_EQ(0u, stashed_objects.size()); |
| 168 // Check that the stashed handle has been closed. | 166 // Check that the stashed handle has been closed. |
| 169 MojoResult result = | 167 MojoResult result = |
| 170 mojo::Wait(message_pipe.handle1.get(), | 168 mojo::Wait(message_pipe.handle1.get(), |
| 171 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_READABLE, | 169 MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_READABLE, |
| 172 MOJO_DEADLINE_INDEFINITE); | 170 MOJO_DEADLINE_INDEFINITE); |
| 173 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); | 171 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, result); |
| 174 } | 172 } |
| 175 | 173 |
| 176 } // namespace extensions | 174 } // namespace extensions |
| OLD | NEW |