blob: e6cb57806db7cd4233d7a0a832d0e17d1238ac27 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
<!DOCTYPE html>
<html>
<head>
<title id='desc'> MouseEvent: mousedown - preventDefault() for text selection </title>
<script type="text/javascript">
var PassTest = function()
{
document.getElementById("testresult").firstChild.data = "PASS";
}
var FailTest = function()
{
document.getElementById("testresult").firstChild.data = "FAIL";
}
var EVENT1 = "mousedown";
var EVENT2 = "mouseup";
var TARGET;
var DisableSelection = false;
var DefaultPrevented = false;
var BEFORE = 0;
var AFTER = 0;
function DisableTextSelection()
{
DisableSelection = true;
}
function TestEvent(evt)
{
if ((true == DisableSelection) && (EVENT1 == evt.type))
{
evt.preventDefault();
DefaultPrevented = true;
BEFORE = evt.clientX;
}
if ((true == DisableSelection) && (EVENT2 == evt.type))
{
AFTER = evt.clientX;
}
}
function VerifyResult()
{
var distance = Math.abs(AFTER - BEFORE);
if ((true == DefaultPrevented) && (10 < distance) && ("" == window.getSelection()))
{
PassTest()
}
else
{
FailTest();
}
}
window.onload = function()
{
try
{
TARGET = document.getElementById("target");
TARGET.addEventListener(EVENT1, TestEvent, false);
TARGET.addEventListener(EVENT2, TestEvent, false);
}
catch(ex)
{
FailTest();
}
}
</script>
</head>
<body>
<h3>DOM Events</h3>
<h4>
Test Description: MouseEvent - Text selection is disabled after cancelling mousedown event.
</h4>
<span id="target" style="border:1px solid green; color:blue"> Use mouse to select the whole line here </span>
<p id="manualsteps">
Steps:
<ol>
<li> Make sure text in the above green box can be selected using mouse
<li> Dismiss the selection, if any, by clicking at the green box with mouse
<li> Now, click the button: <button onclick="DisableTextSelection()">Disable Selection</button>
<li> Drag mouse to select the whole line of the text inside the above green box
<li> Click the button: <button id="verify" onclick="VerifyResult()">VerifyResult</button>
</ol>
</p>
<p>Test passes if the word "PASS" appears below after following the above steps.</p>
<div>Test result: </div>
<div id='testresult'>FAIL</div>
</body>
</html>
|