| 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" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "content/public/browser/render_frame_host.h" | 12 #include "content/public/browser/render_frame_host.h" |
| 13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/common/service_registry.h" | |
| 15 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
| 16 #include "content/public/test/content_browser_test.h" | 15 #include "content/public/test/content_browser_test.h" |
| 17 #include "content/public/test/content_browser_test_utils.h" | 16 #include "content/public/test/content_browser_test_utils.h" |
| 18 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
| 19 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
| 20 #include "device/vibration/vibration_manager.mojom.h" | 19 #include "device/vibration/vibration_manager.mojom.h" |
| 21 #include "mojo/public/cpp/bindings/strong_binding.h" | 20 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 21 #include "services/shell/public/cpp/interface_registry.h" |
| 22 | 22 |
| 23 // These tests run against a dummy implementation of the VibrationManager | 23 // These tests run against a dummy implementation of the VibrationManager |
| 24 // service. That is, they verify that the service implementation is correctly | 24 // service. That is, they verify that the service implementation is correctly |
| 25 // exposed to the renderer, whatever the implementation is. | 25 // exposed to the renderer, whatever the implementation is. |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // Global, record milliseconds when FakeVibrationManager::Vibrate got called. | 31 // Global, record milliseconds when FakeVibrationManager::Vibrate got called. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 mojo::StrongBinding<VibrationManager> binding_; | 75 mojo::StrongBinding<VibrationManager> binding_; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 class VibrationTest : public ContentBrowserTest { | 78 class VibrationTest : public ContentBrowserTest { |
| 79 public: | 79 public: |
| 80 VibrationTest() {} | 80 VibrationTest() {} |
| 81 | 81 |
| 82 void SetUpOnMainThread() override { | 82 void SetUpOnMainThread() override { |
| 83 ResetGlobalValues(); | 83 ResetGlobalValues(); |
| 84 GetMainFrame()->GetServiceRegistry()->AddService( | 84 GetMainFrame()->GetInterfaceRegistry()->AddInterface( |
| 85 base::Bind(&FakeVibrationManager::Create)); | 85 base::Bind(&FakeVibrationManager::Create)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 bool Vibrate(int duration) { return Vibrate(duration, GetMainFrame()); } | 88 bool Vibrate(int duration) { return Vibrate(duration, GetMainFrame()); } |
| 89 | 89 |
| 90 bool Vibrate(int duration, RenderFrameHost* frame) { | 90 bool Vibrate(int duration, RenderFrameHost* frame) { |
| 91 bool result; | 91 bool result; |
| 92 std::string script = "domAutomationController.send(navigator.vibrate(" + | 92 std::string script = "domAutomationController.send(navigator.vibrate(" + |
| 93 base::IntToString(duration) + "))"; | 93 base::IntToString(duration) + "))"; |
| 94 EXPECT_TRUE(ExecuteScriptAndExtractBool(frame, script, &result)); | 94 EXPECT_TRUE(ExecuteScriptAndExtractBool(frame, script, &result)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 ASSERT_TRUE(g_cancelled); | 151 ASSERT_TRUE(g_cancelled); |
| 152 } | 152 } |
| 153 | 153 |
| 154 IN_PROC_BROWSER_TEST_F(VibrationTest, | 154 IN_PROC_BROWSER_TEST_F(VibrationTest, |
| 155 CancelVibrationFromSubFrameWhenSubFrameIsReloaded) { | 155 CancelVibrationFromSubFrameWhenSubFrameIsReloaded) { |
| 156 ASSERT_FALSE(g_cancelled); | 156 ASSERT_FALSE(g_cancelled); |
| 157 | 157 |
| 158 ASSERT_TRUE(NavigateToURL(shell(), GetTestUrl(".", "page_with_iframe.html"))); | 158 ASSERT_TRUE(NavigateToURL(shell(), GetTestUrl(".", "page_with_iframe.html"))); |
| 159 RenderFrameHost* iframe = ChildFrameAt(GetMainFrame(), 0); | 159 RenderFrameHost* iframe = ChildFrameAt(GetMainFrame(), 0); |
| 160 iframe->GetServiceRegistry()->AddService( | 160 iframe->GetInterfaceRegistry()->AddInterface( |
| 161 base::Bind(&FakeVibrationManager::Create)); | 161 base::Bind(&FakeVibrationManager::Create)); |
| 162 ASSERT_TRUE(Vibrate(1234, iframe)); | 162 ASSERT_TRUE(Vibrate(1234, iframe)); |
| 163 g_wait_vibrate_runner->Run(); | 163 g_wait_vibrate_runner->Run(); |
| 164 ASSERT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test_iframe", | 164 ASSERT_TRUE(NavigateIframeToURL(shell()->web_contents(), "test_iframe", |
| 165 GetTestUrl(".", "title1.html"))); | 165 GetTestUrl(".", "title1.html"))); |
| 166 g_wait_cancel_runner->Run(); | 166 g_wait_cancel_runner->Run(); |
| 167 | 167 |
| 168 ASSERT_TRUE(g_cancelled); | 168 ASSERT_TRUE(g_cancelled); |
| 169 } | 169 } |
| 170 | 170 |
| 171 IN_PROC_BROWSER_TEST_F(VibrationTest, | 171 IN_PROC_BROWSER_TEST_F(VibrationTest, |
| 172 CancelVibrationFromSubFrameWhenMainFrameIsReloaded) { | 172 CancelVibrationFromSubFrameWhenMainFrameIsReloaded) { |
| 173 ASSERT_FALSE(g_cancelled); | 173 ASSERT_FALSE(g_cancelled); |
| 174 | 174 |
| 175 ASSERT_TRUE(NavigateToURL(shell(), GetTestUrl(".", "page_with_iframe.html"))); | 175 ASSERT_TRUE(NavigateToURL(shell(), GetTestUrl(".", "page_with_iframe.html"))); |
| 176 RenderFrameHost* iframe = ChildFrameAt(GetMainFrame(), 0); | 176 RenderFrameHost* iframe = ChildFrameAt(GetMainFrame(), 0); |
| 177 iframe->GetServiceRegistry()->AddService( | 177 iframe->GetInterfaceRegistry()->AddInterface( |
| 178 base::Bind(&FakeVibrationManager::Create)); | 178 base::Bind(&FakeVibrationManager::Create)); |
| 179 ASSERT_TRUE(Vibrate(1234, iframe)); | 179 ASSERT_TRUE(Vibrate(1234, iframe)); |
| 180 g_wait_vibrate_runner->Run(); | 180 g_wait_vibrate_runner->Run(); |
| 181 ASSERT_TRUE(NavigateToURL(shell(), GetTestUrl(".", "page_with_iframe.html"))); | 181 ASSERT_TRUE(NavigateToURL(shell(), GetTestUrl(".", "page_with_iframe.html"))); |
| 182 g_wait_cancel_runner->Run(); | 182 g_wait_cancel_runner->Run(); |
| 183 | 183 |
| 184 ASSERT_TRUE(g_cancelled); | 184 ASSERT_TRUE(g_cancelled); |
| 185 } | 185 } |
| 186 | 186 |
| 187 IN_PROC_BROWSER_TEST_F(VibrationTest, | 187 IN_PROC_BROWSER_TEST_F(VibrationTest, |
| 188 CancelVibrationFromSubFrameWhenSubFrameIsDestroyed) { | 188 CancelVibrationFromSubFrameWhenSubFrameIsDestroyed) { |
| 189 ASSERT_FALSE(g_cancelled); | 189 ASSERT_FALSE(g_cancelled); |
| 190 | 190 |
| 191 ASSERT_TRUE(NavigateToURL(shell(), GetTestUrl(".", "page_with_iframe.html"))); | 191 ASSERT_TRUE(NavigateToURL(shell(), GetTestUrl(".", "page_with_iframe.html"))); |
| 192 RenderFrameHost* iframe = ChildFrameAt(GetMainFrame(), 0); | 192 RenderFrameHost* iframe = ChildFrameAt(GetMainFrame(), 0); |
| 193 iframe->GetServiceRegistry()->AddService( | 193 iframe->GetInterfaceRegistry()->AddInterface( |
| 194 base::Bind(&FakeVibrationManager::Create)); | 194 base::Bind(&FakeVibrationManager::Create)); |
| 195 ASSERT_TRUE(Vibrate(1234, iframe)); | 195 ASSERT_TRUE(Vibrate(1234, iframe)); |
| 196 g_wait_vibrate_runner->Run(); | 196 g_wait_vibrate_runner->Run(); |
| 197 ASSERT_TRUE(DestroyIframe()); | 197 ASSERT_TRUE(DestroyIframe()); |
| 198 g_wait_cancel_runner->Run(); | 198 g_wait_cancel_runner->Run(); |
| 199 | 199 |
| 200 ASSERT_TRUE(g_cancelled); | 200 ASSERT_TRUE(g_cancelled); |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace | 203 } // namespace |
| 204 | 204 |
| 205 } // namespace content | 205 } // namespace content |
| OLD | NEW |