fc023194946f41dfb8867dac9f50c7a7ff04fa6a
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / frames / resources / frame-programmatic-resize.js
1 var _testFrame;
2 var _testFrameId; // We keep the id of the test frame to make it easier for a person to interpret the test results.
3
4 function setTestFrameById(id)
5 {
6     _testFrameId = id;
7     _testFrame = document.getElementById(id);
8 }
9
10 function deltaWidth()
11 {
12     return 10; // A resonable amount to be able to detect that the frame width changed.
13 }
14
15 function shouldAllowFrameResize()
16 {
17     shouldAllowFrameResizeAfterProcessingFrame(function(frame) { /* Do nothing. */});
18 }
19
20 function shouldDisallowFrameResize()
21 {
22     shouldDisallowFrameResizeAfterProcessingFrame(function(frame) { /* Do nothing. */})
23 }
24
25 function shouldDisallowFrameResizeAfterProcessingFrame(processFrameFunction)
26 {
27     var expectedWidth = _testFrame.width;
28     processFrameFunction(_testFrame);
29     resizeTestFrameBy(deltaWidth());
30     checkTestFrameWidthEquals(expectedWidth);
31 }
32
33 function shouldAllowFrameResizeAfterProcessingFrame(processFrameFunction)
34 {
35     var expectedWidth = _testFrame.width + deltaWidth();
36     processFrameFunction(_testFrame);
37     resizeTestFrameBy(deltaWidth());
38     checkTestFrameWidthEquals(expectedWidth);
39 }
40
41 function checkTestFrameWidthEquals(expectedWidth)
42 {
43     if (_testFrame.width === expectedWidth)
44         log('PASS document.getElementById("' + _testFrameId + '").width is ' + expectedWidth);
45     else
46         log('FAIL document.getElementById("' + _testFrameId + '").width should be ' + expectedWidth + '. Was ' + _testFrame.width + '.');
47 }
48
49 function resizeTestFrameBy(deltaWidthInPixels)
50 {
51     var borderWidth = parseInt(_testFrame.parentNode.getAttribute("border"));
52
53     var startX = _testFrame.offsetWidth + borderWidth / 2;
54     var startY = _testFrame.offsetHeight / 2;
55     var endX = startX + deltaWidthInPixels;
56     var endY = startY;
57
58     eventSender.mouseMoveTo(startX, startY);
59     eventSender.mouseDown();
60     eventSender.leapForward(100);
61     eventSender.mouseMoveTo(endX, endY);
62     eventSender.mouseUp();
63 }
64
65 function log(message)
66 {
67     document.getElementById("results").contentDocument.getElementById("console").appendChild(document.createTextNode(message + "\n"));
68 }
69
70 function description(message)
71 {
72     document.getElementById("results").contentDocument.getElementById("description").innerText = message;
73 }