From dd205feda0fabd096a56a6758a42aff900c87ab4 Mon Sep 17 00:00:00 2001
From: Rachel Fenichel
Date: Tue, 31 May 2016 11:06:17 -0700
Subject: [PATCH] Add a button to randomly click and drag blocks in the
playground.
---
tests/playground.html | 63 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 62 insertions(+), 1 deletion(-)
diff --git a/tests/playground.html b/tests/playground.html
index 6b6c81333..c74695d17 100644
--- a/tests/playground.html
+++ b/tests/playground.html
@@ -63,6 +63,7 @@
// Depending on the URL argument, render as LTR or RTL.
var rtl = (document.location.search == '?rtl');
var workspace = null;
+var fakeDragQueue = [];
function start() {
var toolbox = document.getElementById('toolbox');
@@ -178,6 +179,65 @@ function airstrike(n) {
}
}
+function fakeDrag(id, dx, dy, opt_workspace) {
+ var ws = opt_workspace ? opt_workspace : Blockly.getMainWorkspace();
+ var blockToDrag = ws.getBlockById(id);
+
+ if (!blockToDrag) {
+ return;
+ }
+ var blockTop = blockToDrag.svgGroup_.getBoundingClientRect().top;
+ var blockLeft = blockToDrag.svgGroup_.getBoundingClientRect().left;
+
+ // Click somewhere on the block.
+ var mouseDownEvent = new MouseEvent('mousedown',
+ {clientX: blockLeft + 5, clientY: blockTop + 5});
+ blockToDrag.onMouseDown_(mouseDownEvent);
+
+ // Throw in a move for good measure.
+ window.setTimeout(
+ function() {
+ var mouseMoveEvent = new MouseEvent('mousemove',
+ {clientX: blockLeft + dx,
+ clientY: blockTop + dy});
+ blockToDrag.onMouseMove_(mouseMoveEvent);
+
+ // Drop at dx, dy.
+ window.setTimeout(
+ function() {
+ var mouseUpEvent = new MouseEvent('mouseup',
+ {clientX: blockLeft + dx,
+ clientY: blockTop + dy});
+ blockToDrag.onMouseUp_(mouseUpEvent);
+
+ window.setTimeout(fakeDragWrapper(), 100);
+ }, 30);
+ }, 30);
+};
+
+function fakeDragWrapper() {
+ var dragInfo = fakeDragQueue.pop();
+ if (dragInfo) {
+ fakeDrag(dragInfo.id, dragInfo.dx, dragInfo.dy, dragInfo.workspace);
+ }
+}
+
+function fakeManyDrags() {
+ var ws = Blockly.getMainWorkspace();
+ var blockList = ws.getAllBlocks();
+ for (var i = 0; i < 2 * blockList.length; i++) {
+ fakeDragQueue.push(
+ {
+ id: blockList[Math.round(Math.random() * (blockList.length - 1))].id,
+ // Move some blocks up and to the left, but mostly down and to the right.
+ dx: Math.round((Math.random() - 0.25) * 200),
+ dy: Math.round((Math.random() - 0.25)* 200),
+ workspace: ws
+ });
+ }
+ fakeDragWrapper();
+}
+
function spaghetti(n) {
var xml = spaghettiXml;
for(var i = 0; i < n; i++) {
@@ -591,7 +651,8 @@ h1 {
Stress test:
-
+
+
Log events: