Skip to content

Commit

Permalink
Release 2.0.0-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
jannenikula committed Aug 4, 2016
1 parent ee9cd2f commit d4b2056
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 23 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.unity3d.ads.example"
minSdkVersion 9
targetSdkVersion 23
versionCode = 2000
versionName = "2.0.0-beta5"
versionCode = 2001
versionName = "2.0.0-rc1"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void onClick(View v) {

SharedPreferences preferences = getSharedPreferences("Settings", MODE_PRIVATE);
gameIdEdit.setText(preferences.getString("gameId", defaultGameId));
testModeCheckbox.setChecked(true);

initializeButton.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -236,4 +237,4 @@ private void toast(String callback, String msg) {
Toast.makeText(getApplicationContext(), callback + ": " + msg, Toast.LENGTH_SHORT).show();
}
}
}
}
4 changes: 2 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode = 2000
versionName = "2.0.0-beta5"
versionCode = 2001
versionName = "2.0.0-rc1"

setProperty("archivesBaseName", "unity-ads")

Expand Down
13 changes: 8 additions & 5 deletions lib/src/androidTest/java/com/unity3d/ads/test/UnitTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@
@Suite.SuiteClasses({
AdUnitActivityTest.class,
AdvertisingIdentifierTest.class,
InvocationTest.class,
BroadcastTest.class,
CacheTest.class,
ClientPropertiesTest.class,
ConnectivityTest.class,
DeviceTest.class,
EventIdTest.class,
EnvironmentCheckTest.class,
EventIdTest.class,
InitializeThreadTest.class,
InvocationTest.class,
MetaDataTest.class,
NativeCallbackTest.class,
PackageManagerTest.class,
PlacementTest.class,
PublicApiTest.class,
RequestTest.class,
SdkPropertiesTest.class,
StorageDiskTest.class,
StorageGeneralTest.class,
StorageMemoryTest.class,
RequestTest.class,
VideoViewTest.class,
WebRequestTest.class,
WebViewAppTest.class,
WebViewBridgeInterfaceTest.class,
WebViewBridgeTest.class,
WebViewCallbackTest.class,
PlacementTest.class,
BroadcastTest.class
WebViewCallbackTest.class
})
public class UnitTestSuite {}
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public void eventCache(CacheEvent eventId, Object... params) {
break;

case DOWNLOAD_PROGRESS:
if(REMOTE_VIDEO.equals(params[0]) && (Long)params[1] > minDownloadBytes) {
if(REMOTE_VIDEO.equals(params[0]) && (Long)params[1] > 1) {
setFlag("cancelInvoked");
Invocation invocation = new Invocation();
WebViewCallback callback = new WebViewCallback("1234", invocation.getId());
Expand All @@ -416,7 +416,7 @@ public void eventCache(CacheEvent eventId, Object... params) {

case DOWNLOAD_STOPPED:
// params: url, total bytes
if(REMOTE_VIDEO.equals(params[0]) && (Long)params[1] > minDownloadBytes) {
if(REMOTE_VIDEO.equals(params[0]) && (Long)params[1] > 1) {
setFlag("stopEventReceived");
downloadPosition = (long)params[1];
cacheCv.open();
Expand All @@ -438,7 +438,7 @@ public void eventCache(CacheEvent eventId, Object... params) {

Invocation invocation = new Invocation();
WebViewCallback callback = new WebViewCallback("1234", invocation.getId());
CacheThread.setProgressInterval(10);
CacheThread.setProgressInterval(2);
Cache.download(REMOTE_VIDEO, REMOTE_VIDEO_FILE_ID, callback);
invocation.sendInvocationCallback();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.unity3d.ads.test.unit;

import android.os.ConditionVariable;
import android.os.Handler;
import android.os.Looper;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.view.ViewGroup;

import com.unity3d.ads.api.Connectivity;
import com.unity3d.ads.api.DeviceInfo;
import com.unity3d.ads.connectivity.ConnectivityEvent;
import com.unity3d.ads.connectivity.ConnectivityMonitor;
import com.unity3d.ads.connectivity.IConnectivityListener;
import com.unity3d.ads.log.DeviceLog;
import com.unity3d.ads.properties.ClientProperties;
import com.unity3d.ads.video.VideoPlayerView;
import com.unity3d.ads.webview.WebViewApp;
import com.unity3d.ads.webview.WebViewEventCategory;
import com.unity3d.ads.webview.bridge.CallbackStatus;
Expand Down Expand Up @@ -72,28 +78,65 @@ public void testWebappEvents() {
// Make sure connectivity monitor thinks it's connected when test starts
ConnectivityMonitor.connected();

MockWebViewApp webapp = new MockWebViewApp();
final MockWebViewApp webapp = new MockWebViewApp();
WebViewApp.setCurrentApp(webapp);
WebViewApp.getCurrentApp().setWebAppLoaded(true);

Connectivity.setConnectionMonitoring(true, webapp.getCallback());
Handler handler = new Handler(Looper.getMainLooper());
ConditionVariable cv = new ConditionVariable();
handler.post(new Runnable() {
@Override
public void run() {
Connectivity.setConnectionMonitoring(true, webapp.getCallback());
webapp.getInvocation().sendInvocationCallback();

}
});
boolean success = cv.block(1000);

assertTrue("Connectivity MockWebViewApp did not respond with success callback", webapp.getCallbackInvoked());

ConnectivityMonitor.disconnected();
cv = new ConditionVariable();
handler.post(new Runnable() {
@Override
public void run() {
ConnectivityMonitor.disconnected();
}
});
success = cv.block(1000);

assertEquals("Connectivity MockWebViewApp did not get one disconnect event", 1, webapp.getDisconnectedEvents());

ConnectivityMonitor.connected();
assertEquals("Connectivity MockWebViewApp did not get one connect event", 1, webapp.getConnectedEvents());
cv = new ConditionVariable();
handler.post(new Runnable() {
@Override
public void run() {
ConnectivityMonitor.connected();
}
});
success = cv.block(1000);

assertTrue("Connectivity MockWebViewApp did not get connect event", webapp.getConnectedEvents() > 0);
}

private class MockWebViewApp extends WebViewApp {
private int _disconnectedEvents = 0;
private int _connectedEvents = 0;
boolean _callbackInvoked = false;
Invocation _invocation = null;
ConditionVariable _cv = null;

public WebViewCallback getCallback() {
Invocation invocation = new Invocation();
return new WebViewCallback("1234", invocation.getId());
_invocation = new Invocation();
return new WebViewCallback("1234", _invocation.getId());
}

public Invocation getInvocation() {
return _invocation;
}

public void setCV(ConditionVariable cv) {
_cv = cv;
}

@Override
Expand All @@ -104,26 +147,43 @@ public boolean invokeCallback(Invocation invocation) {
_callbackInvoked = true;
}

return super.invokeCallback(invocation);
openCVAndReset();

return true;
}

public boolean getCallbackInvoked() {
return _callbackInvoked;
}

public void openCVAndReset () {
if (_cv != null) {
DeviceLog.debug("Opening CV");
_cv.open();
_cv = null;
}
if (_invocation != null) {
_invocation = null;
}
}

@Override
public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) {
if(eventCategory != WebViewEventCategory.CONNECTIVITY) {
throw new IllegalArgumentException("Event category not CONNECTIVITY");
}

DeviceLog.debug("EVENT: " + eventId.name());

switch((ConnectivityEvent)eventId) {
case CONNECTED:
_connectedEvents++;
openCVAndReset();
break;

case DISCONNECTED:
_disconnectedEvents++;
openCVAndReset();
break;

case NETWORK_CHANGE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void testPlayerMetaData () throws Exception {

HashMap<String, Object> params = (HashMap<String, Object>)((MetaDataWebApp)WebViewApp.getCurrentApp()).PARAMS[1];

assertEquals("Metadata doesn't have correct amount of values", params.size(), 4 * 2);
assertEquals("Metadata doesn't have correct amount of values", params.size(), 1 * 2);

HashMap<String, Object> metadataEntries = (HashMap<String, Object>)metaData.getEntries();
for (String k : params.keySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,18 @@ public void run() {

assertTrue("Condition Variable was not opened: VIDEO PROGRESS or PREPARE ERROR event was not received", success);

int failedIntervals = 0;

for (int idx = 0; idx < EVENT_POSITIONS.size(); idx++) {
if (idx + 1 < EVENT_POSITIONS.size()) {
long interval = Math.abs(300 - (EVENT_POSITIONS.get(idx + 1) - EVENT_POSITIONS.get(idx)));
DeviceLog.debug("Interval is: " + interval);
assertFalse("Interval of the events weren't as accurate as expected (threshold of 70ms, was: " + interval + ")", interval > 70);

if (interval > 80) {
failedIntervals++;
}

assertFalse("Too many intervals failed to arrive in 80ms threshold (" + failedIntervals + ")", failedIntervals > 3);
}
}

Expand Down
2 changes: 2 additions & 0 deletions lib/src/main/java/com/unity3d/ads/UnityAds.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public static void initialize(final Activity activity, final String gameId, fina
DeviceLog.info("Initializing Unity Ads " + SdkProperties.getVersionName() + " (" + SdkProperties.getVersionCode() + ") with game id " + gameId + " in production mode");
}

setDebugMode(_debugMode);

ClientProperties.setGameId(gameId);
ClientProperties.setListener(listener);
ClientProperties.setApplicationContext(activity.getApplicationContext());
Expand Down

0 comments on commit d4b2056

Please sign in to comment.