Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(550)

Unified Diff: editor/tools/plugins/com.google.dart.tools.ui_test/src-framework/com/google/dart/ui/test/driver/OperationExecutor.java

Issue 18548007: UI tests for 'Rename' and 'Extract Local Variable' refactorings. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixes for review comments Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: editor/tools/plugins/com.google.dart.tools.ui_test/src-framework/com/google/dart/ui/test/driver/OperationExecutor.java
diff --git a/editor/tools/plugins/com.google.dart.tools.ui_test/src-framework/com/google/dart/ui/test/driver/OperationExecutor.java b/editor/tools/plugins/com.google.dart.tools.ui_test/src-framework/com/google/dart/ui/test/driver/OperationExecutor.java
new file mode 100644
index 0000000000000000000000000000000000000000..f04a83a991a7811dafe1b9044575939a8299129a
--- /dev/null
+++ b/editor/tools/plugins/com.google.dart.tools.ui_test/src-framework/com/google/dart/ui/test/driver/OperationExecutor.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2013, the Dart project authors.
+ *
+ * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.google.dart.ui.test.driver;
+
+import com.google.common.collect.Lists;
+import com.google.dart.tools.internal.corext.refactoring.util.ExecutionUtils;
+import com.google.dart.ui.test.util.UiContext;
+
+import org.eclipse.swt.widgets.Display;
+
+import java.util.LinkedList;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * Executes a sequence of {@link Operation}s.
+ */
+public class OperationExecutor {
+ private final Display display = Display.getDefault();
+ private final UiContext context = new UiContext();
+ private final LinkedList<Operation> operations = Lists.newLinkedList();
+ private final AtomicBoolean operationsDone = new AtomicBoolean();
+ private Throwable exception = null;
+
+ /**
+ * Schedules the {@link Operation} for execution.
+ */
+ public void addOperation(Operation operation) {
+ operations.add(operation);
+ }
+
+ /**
+ * Runs the scheduled {@link Operation}s, waits for the given time at most.
+ */
+ public void runUiOperations(long waitFor, TimeUnit unit) throws Exception {
+ display.timerExec(5, new Runnable() {
+ @Override
+ public void run() {
+ // are we done?
+ if (operationsDone.get()) {
+ return;
+ }
+ // schedule again
+ display.timerExec(5, this);
+ // run single operation
+ try {
+ Operation operation = operations.getFirst();
+ if (operation.isReady(context)) {
+ operations.removeFirst();
+ try {
+ operation.run(context);
+ } catch (Throwable e) {
+ operation.onError(context);
+ ExecutionUtils.propagate(e);
+ } finally {
+ if (operations.isEmpty()) {
+ operationsDone.set(true);
+ }
+ }
+ }
+ } catch (Throwable e) {
+ exception = e;
+ // we are done - with failure
+ operationsDone.set(true);
+ }
+ }
+ });
+ // wait for successful completion or failure
+ {
+ long end = System.nanoTime() + unit.toNanos(waitFor);
+ while (!operationsDone.get()) {
+ if (System.nanoTime() >= end) {
+ throw new TimeoutException();
+ }
+ UiContext.runEventLoop(10);
+ }
+ }
+ // check for exception
+ if (exception != null) {
+ ExecutionUtils.propagate(exception);
+ }
+ // OK
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698