OLD | NEW |
| (Empty) |
1 (function() { | |
2 var templateParagraph = null; | |
3 var templateRegion = null; | |
4 var DEFAULT_PARAGRAPH_COUNT = 100; | |
5 var DEFAULT_REGION_COUNT = 100; | |
6 | |
7 function createParagraphNode(breakChance) { | |
8 if (!templateParagraph) { | |
9 templateParagraph = document.createElement("p"); | |
10 templateParagraph.innerHTML = "Lorem ipsum dolor sit amet, consectet
ur adipiscing elit. Etiam at turpis placerat sapien congue viverra nec sed felis
.\ | |
11 Aenean aliquam, justo eu condimentum pharetra, arcu eros blandit
metus, nec lacinia nisi orci vitae nunc.\ | |
12 Proin orci libero, accumsan non dignissim at, sodales in sapien.
Curabitur dui nibh, venenatis vel tempus vel, accumsan nec velit.\ | |
13 Nam sit amet tempor lacus. Sed mollis dolor nibh, non tempus leo
. Donec magna odio, commodo id porta in, aliquam mollis eros.\ | |
14 Pellentesque vulputate gravida ligula in elementum. Fusce lacini
a massa justo, at porttitor orci.\ | |
15 Vestibulum ante ipsum primis in faucibus orci luctus et ultrices
posuere cubilia Curae; Donec odio quam, pulvinar ut porttitor ac, tempor vitae
ligula.\ | |
16 Cras aliquet sapien id sapien mollis nec pulvinar mauris adipisc
ing. Praesent porttitor consequat augue, sit amet mollis justo condimentum eu.\ | |
17 Etiam ut erat pellentesque orci congue interdum. Nulla eu eros m
i.\ | |
18 Curabitur rutrum, lorem ac malesuada pellentesque, sapien risus
consequat massa, eget pellentesque nunc nulla vel sem."; | |
19 templateParagraph.className = "contentParagraph"; | |
20 } | |
21 | |
22 var paragraph = templateParagraph.cloneNode(true); | |
23 var randomNumber = PerfTestRunner.random(); | |
24 if (randomNumber < breakChance) | |
25 paragraph.className = paragraph.className + " breakAfter"; | |
26 return paragraph; | |
27 } | |
28 | |
29 function createRegionNode(regionWidth, regionHeight, regionMaxHeight) { | |
30 if (!templateRegion) { | |
31 templateRegion = document.createElement("div"); | |
32 templateRegion.className = "region"; | |
33 } | |
34 | |
35 var region = templateRegion.cloneNode(false); | |
36 region.style.width = regionWidth; | |
37 region.style.height = regionHeight; | |
38 region.style.maxHeight = regionMaxHeight; | |
39 return region; | |
40 } | |
41 | |
42 function createArticle(paragraphCount, breakChance) { | |
43 var article = document.createElement("div"); | |
44 for (var i = 0 ; i < paragraphCount; ++i) { | |
45 article.appendChild(createParagraphNode(breakChance)); | |
46 } | |
47 article.className = "articleNone"; | |
48 return article; | |
49 } | |
50 | |
51 function createRegions(regionWidth, regionHeight, regionCount, regionMaxHeig
ht) { | |
52 var regionContainer = document.createElement("div"); | |
53 for (var i = 0; i < regionCount; ++i) { | |
54 regionContainer.appendChild(createRegionNode(regionWidth, regionHeig
ht, regionMaxHeight)); | |
55 } | |
56 regionContainer.className = "regionContainer"; | |
57 return regionContainer; | |
58 } | |
59 | |
60 function createRegionsTest(regionWidth, regionHeight, regionCount, paragraph
Count, regionMaxHeight, breakChance) { | |
61 paragraphCount = paragraphCount || DEFAULT_PARAGRAPH_COUNT; | |
62 regionCount = regionCount || DEFAULT_REGION_COUNT; | |
63 regionMaxHeight = regionMaxHeight || "auto"; | |
64 breakChance = breakChance || 0; | |
65 | |
66 var article = createArticle(paragraphCount, breakChance); | |
67 var regions = createRegions(regionWidth, regionHeight, regionCount, regi
onMaxHeight); | |
68 document.body.appendChild(article); | |
69 document.body.appendChild(regions); | |
70 return { | |
71 description: "Testing regions with " + regionCount + " regions @{wid
th: " + regionWidth + ", height: " + regionHeight + | |
72 ", maxHeight: " + regionMaxHeight + "} and " + paragraphCount + " pa
ragraphs", | |
73 run: function() { | |
74 article.className = "articleInFlow"; | |
75 document.body.offsetTop; | |
76 }, | |
77 setup: function() { | |
78 PerfTestRunner.resetRandomSeed(); | |
79 article.className = "articleNone"; | |
80 document.body.offsetTop; | |
81 }, | |
82 done: function() { | |
83 document.body.removeChild(article); | |
84 document.body.removeChild(regions); | |
85 templateParagraph = null; | |
86 templateRegion = null; | |
87 } | |
88 }; | |
89 } | |
90 | |
91 function mouseMoveToRegionCenter(region) { | |
92 var rect = region.getBoundingClientRect(); | |
93 eventSender.mouseMoveTo(rect.left + (rect.width / 2), rect.top + (rect.h
eight / 2)); | |
94 } | |
95 | |
96 function performSelection(regionCount) { | |
97 var regions = document.getElementsByClassName("region"); | |
98 | |
99 if (window.eventSender) { | |
100 mouseMoveToRegionCenter(regions[0]); | |
101 eventSender.mouseDown(); | |
102 | |
103 for (var i = 1; i < regionCount; i++) | |
104 mouseMoveToRegionCenter(regions[i]); | |
105 | |
106 eventSender.mouseUp(); | |
107 } | |
108 } | |
109 | |
110 function createRegionsSelectionTest(regionCount) { | |
111 var article = createArticle(regionCount, 1); | |
112 article.className = "articleInFlow"; | |
113 var regions = createRegions("600px", "auto", regionCount, "auto"); | |
114 document.body.appendChild(article); | |
115 document.body.appendChild(regions); | |
116 return { | |
117 description: "Testing selection with " + regionCount + " regions. Se
lect text from first region to last one passing through all the regions.", | |
118 run: function() { | |
119 performSelection(regionCount); | |
120 }, | |
121 setup: function() { | |
122 window.getSelection().removeAllRanges(); | |
123 }, | |
124 done: function() { | |
125 document.body.removeChild(article); | |
126 document.body.removeChild(regions); | |
127 templateParagraph = null; | |
128 templateRegion = null; | |
129 } | |
130 }; | |
131 } | |
132 | |
133 window.createRegionsTest = createRegionsTest; | |
134 window.createRegionsSelectionTest = createRegionsSelectionTest; | |
135 | |
136 })(); | |
OLD | NEW |