| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "bindings/core/v8/ScriptController.h" | 5 #include "bindings/core/v8/ScriptController.h" |
| 6 #include "core/layout/LayoutTestHelper.h" | 6 #include "core/layout/LayoutTestHelper.h" |
| 7 #include "platform/testing/HistogramTester.h" | 7 #include "platform/testing/HistogramTester.h" |
| 8 | 8 |
| 9 namespace blink { | 9 namespace blink { |
| 10 | 10 |
| 11 enum PassiveForcedListenerResultType { | 11 enum PassiveForcedListenerResultType { |
| 12 kPreventDefaultNotCalled, | 12 kPreventDefaultNotCalled, |
| 13 kDocumentLevelTouchPreventDefaultCalled | 13 kDocumentLevelTouchPreventDefaultCalled |
| 14 }; | 14 }; |
| 15 | 15 |
| 16 class EventTargetTest : public RenderingTest { | 16 class EventTargetTest : public RenderingTest { |
| 17 public: | 17 public: |
| 18 EventTargetTest() {} | 18 EventTargetTest() {} |
| 19 ~EventTargetTest() {} | 19 ~EventTargetTest() {} |
| 20 }; | 20 }; |
| 21 | 21 |
| 22 TEST_F(EventTargetTest, PreventDefaultNotCalled) { | 22 TEST_F(EventTargetTest, PreventDefaultNotCalled) { |
| 23 GetDocument().GetSettings()->SetScriptEnabled(true); | 23 GetDocument().GetSettings()->SetScriptEnabled(true); |
| 24 HistogramTester histogram_tester; | 24 HistogramTester histogram_tester; |
| 25 GetDocument().GetFrame()->Script().ExecuteScriptInMainWorld( | 25 GetDocument().GetFrame()->GetScriptController().ExecuteScriptInMainWorld( |
| 26 "window.addEventListener('touchstart', function(e) {}, {});" | 26 "window.addEventListener('touchstart', function(e) {}, {});" |
| 27 "window.dispatchEvent(new TouchEvent('touchstart', {cancelable: " | 27 "window.dispatchEvent(new TouchEvent('touchstart', {cancelable: " |
| 28 "false}));"); | 28 "false}));"); |
| 29 | 29 |
| 30 histogram_tester.ExpectTotalCount("Event.PassiveForcedEventDispatchCancelled", | 30 histogram_tester.ExpectTotalCount("Event.PassiveForcedEventDispatchCancelled", |
| 31 1); | 31 1); |
| 32 histogram_tester.ExpectUniqueSample( | 32 histogram_tester.ExpectUniqueSample( |
| 33 "Event.PassiveForcedEventDispatchCancelled", kPreventDefaultNotCalled, 1); | 33 "Event.PassiveForcedEventDispatchCancelled", kPreventDefaultNotCalled, 1); |
| 34 } | 34 } |
| 35 | 35 |
| 36 TEST_F(EventTargetTest, PreventDefaultCalled) { | 36 TEST_F(EventTargetTest, PreventDefaultCalled) { |
| 37 GetDocument().GetSettings()->SetScriptEnabled(true); | 37 GetDocument().GetSettings()->SetScriptEnabled(true); |
| 38 HistogramTester histogram_tester; | 38 HistogramTester histogram_tester; |
| 39 GetDocument().GetFrame()->Script().ExecuteScriptInMainWorld( | 39 GetDocument().GetFrame()->GetScriptController().ExecuteScriptInMainWorld( |
| 40 "window.addEventListener('touchstart', function(e) " | 40 "window.addEventListener('touchstart', function(e) " |
| 41 "{e.preventDefault();}, {});" | 41 "{e.preventDefault();}, {});" |
| 42 "window.dispatchEvent(new TouchEvent('touchstart', {cancelable: " | 42 "window.dispatchEvent(new TouchEvent('touchstart', {cancelable: " |
| 43 "false}));"); | 43 "false}));"); |
| 44 | 44 |
| 45 histogram_tester.ExpectTotalCount("Event.PassiveForcedEventDispatchCancelled", | 45 histogram_tester.ExpectTotalCount("Event.PassiveForcedEventDispatchCancelled", |
| 46 1); | 46 1); |
| 47 histogram_tester.ExpectUniqueSample( | 47 histogram_tester.ExpectUniqueSample( |
| 48 "Event.PassiveForcedEventDispatchCancelled", | 48 "Event.PassiveForcedEventDispatchCancelled", |
| 49 kDocumentLevelTouchPreventDefaultCalled, 1); | 49 kDocumentLevelTouchPreventDefaultCalled, 1); |
| 50 } | 50 } |
| 51 | 51 |
| 52 } // namespace blink | 52 } // namespace blink |
| OLD | NEW |