Commit 2869a13e authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Set webViewString directly to bypass event from blocks (#1320)

Setting the WebViewString from blocks will also trigger a
WebViewStringChange event. This forces users to have to work around
the extra change event when they are typically expecting the change
from within JavaScript code only. This change sets the internal value
directly to bypass firing the event.

Change-Id: Ic8f38bfb34faad1f67ee0bcc29289417ef780eb3
parent 37c4a0cd
...@@ -153,7 +153,7 @@ public final class WebViewer extends AndroidViewComponent { ...@@ -153,7 +153,7 @@ public final class WebViewer extends AndroidViewComponent {
*/ */
@SimpleProperty(category = PropertyCategory.BEHAVIOR) @SimpleProperty(category = PropertyCategory.BEHAVIOR)
public void WebViewString(String newString) { public void WebViewString(String newString) {
wvInterface.setWebViewString(newString); wvInterface.setWebViewStringFromBlocks(newString);
} }
@Override @Override
...@@ -484,6 +484,10 @@ public final class WebViewer extends AndroidViewComponent { ...@@ -484,6 +484,10 @@ public final class WebViewer extends AndroidViewComponent {
}); });
} }
public void setWebViewStringFromBlocks(final String newString) {
webViewString = newString;
}
} }
} }
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright © 2018 Massachusetts Institute of Technology, All rights reserved.
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
package com.google.appinventor.components.runtime;
import com.google.appinventor.components.runtime.shadows.ShadowEventDispatcher;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class WebViewerTest extends RobolectricTestBase {
private WebViewer webViewer;
@Before
public void setUp() {
super.setUp();
webViewer = new WebViewer(getForm());
}
/**
* Tests that setting a WebViewer's WebViewString property does not cause
*/
@Test
public void testWebViewStringChange() {
final String TEST_STRING = "teststring";
webViewer.WebViewString(TEST_STRING);
runAllEvents();
ShadowEventDispatcher.assertEventNotFired(webViewer, "WebViewStringChange");
assertEquals(TEST_STRING, webViewer.WebViewString());
}
}
...@@ -7,7 +7,7 @@ package com.google.appinventor.components.runtime.shadows; ...@@ -7,7 +7,7 @@ package com.google.appinventor.components.runtime.shadows;
import com.google.appinventor.components.runtime.Component; import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.EventDispatcher; import com.google.appinventor.components.runtime.EventDispatcher;
import org.easymock.internal.AssertionErrorWrapper; import org.junit.Assert;
import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements; import org.robolectric.annotation.Implements;
...@@ -60,6 +60,23 @@ public class ShadowEventDispatcher { ...@@ -60,6 +60,23 @@ public class ShadowEventDispatcher {
throw new AssertionError(String.format("Component %s did not receive event %s", component, eventName)); throw new AssertionError(String.format("Component %s did not receive event %s", component, eventName));
} }
/**
* Checks whether or not the given {@code eventName} has fired for {@code component}. If so, the
* test fails.
* @param component The component to check for events
* @param eventName An event name to check that should not have fired
*/
public static void assertEventNotFired(Component component, String eventName) {
Set<EventWithArgs> events = firedEvents.get(component);
if (events != null) {
for (EventWithArgs e : events) {
if (e.eventName.equals(eventName)) {
Assert.fail("Expected " + eventName + " of " + component + " to not fire, but it did.");
}
}
}
}
public static void assertEventFiredAny(Component component, String eventName) { public static void assertEventFiredAny(Component component, String eventName) {
Set<EventWithArgs> events = firedEvents.get(component); Set<EventWithArgs> events = firedEvents.get(component);
if (events != null) { if (events != null) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment