| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 void ResetGlobalValues() { | 43 void ResetGlobalValues() { |
| 44 g_vibrate_milliseconds = -1; | 44 g_vibrate_milliseconds = -1; |
| 45 g_cancelled = false; | 45 g_cancelled = false; |
| 46 | 46 |
| 47 g_wait_vibrate_runner = new MessageLoopRunner(); | 47 g_wait_vibrate_runner = new MessageLoopRunner(); |
| 48 g_wait_cancel_runner = new MessageLoopRunner(); | 48 g_wait_cancel_runner = new MessageLoopRunner(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 class FakeVibrationManager : public device::VibrationManager { | 51 class FakeVibrationManager : public device::VibrationManager { |
| 52 public: | 52 public: |
| 53 static void Create(mojo::InterfaceRequest<VibrationManager> request) { | 53 FakeVibrationManager() {} |
| 54 new FakeVibrationManager(std::move(request)); | 54 ~FakeVibrationManager() override {} |
| 55 |
| 56 static void Create(device::VibrationManagerRequest request) { |
| 57 mojo::MakeStrongBinding(base::MakeUnique<FakeVibrationManager>(), |
| 58 std::move(request)); |
| 55 } | 59 } |
| 56 | 60 |
| 57 private: | 61 private: |
| 58 FakeVibrationManager(mojo::InterfaceRequest<VibrationManager> request) | |
| 59 : binding_(this, std::move(request)) {} | |
| 60 | |
| 61 ~FakeVibrationManager() override {} | |
| 62 | |
| 63 void Vibrate(int64_t milliseconds, const VibrateCallback& callback) override { | 62 void Vibrate(int64_t milliseconds, const VibrateCallback& callback) override { |
| 64 g_vibrate_milliseconds = milliseconds; | 63 g_vibrate_milliseconds = milliseconds; |
| 65 callback.Run(); | 64 callback.Run(); |
| 66 g_wait_vibrate_runner->Quit(); | 65 g_wait_vibrate_runner->Quit(); |
| 67 } | 66 } |
| 68 | 67 |
| 69 void Cancel(const CancelCallback& callback) override { | 68 void Cancel(const CancelCallback& callback) override { |
| 70 g_cancelled = true; | 69 g_cancelled = true; |
| 71 callback.Run(); | 70 callback.Run(); |
| 72 g_wait_cancel_runner->Quit(); | 71 g_wait_cancel_runner->Quit(); |
| 73 } | 72 } |
| 74 | |
| 75 mojo::StrongBinding<VibrationManager> binding_; | |
| 76 }; | 73 }; |
| 77 | 74 |
| 78 class VibrationTest : public ContentBrowserTest { | 75 class VibrationTest : public ContentBrowserTest { |
| 79 public: | 76 public: |
| 80 VibrationTest() {} | 77 VibrationTest() {} |
| 81 | 78 |
| 82 void SetUpOnMainThread() override { | 79 void SetUpOnMainThread() override { |
| 83 ResetGlobalValues(); | 80 ResetGlobalValues(); |
| 84 GetMainFrame()->GetInterfaceRegistry()->AddInterface( | 81 GetMainFrame()->GetInterfaceRegistry()->AddInterface( |
| 85 base::Bind(&FakeVibrationManager::Create)); | 82 base::Bind(&FakeVibrationManager::Create)); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 g_wait_vibrate_runner->Run(); | 193 g_wait_vibrate_runner->Run(); |
| 197 ASSERT_TRUE(DestroyIframe()); | 194 ASSERT_TRUE(DestroyIframe()); |
| 198 g_wait_cancel_runner->Run(); | 195 g_wait_cancel_runner->Run(); |
| 199 | 196 |
| 200 ASSERT_TRUE(g_cancelled); | 197 ASSERT_TRUE(g_cancelled); |
| 201 } | 198 } |
| 202 | 199 |
| 203 } // namespace | 200 } // namespace |
| 204 | 201 |
| 205 } // namespace content | 202 } // namespace content |
| OLD | NEW |