@@ -1915,18 +1915,23 @@ public void testSendReferrer() {
19151915 }
19161916
19171917 @ Test
1918- public void testGetAttribution () {
1918+ public void testCheckAttributionState () {
19191919 // assert test name to read better in logcat
1920- mockLogger .Assert ("TestActivityHandler testGetAttribution" );
1920+ mockLogger .Assert ("TestActivityHandler testCheckAttributionState" );
1921+
1922+ // if it's the first launch
1923+ //if (internalState.isFirstLaunch()) {
1924+ // if (!internalState.isSessionResponseProcessed()) {
1925+ // return;
1926+ // }
1927+ //}
1928+ //if (attribution != null && !activityState.askingAttribution) {
1929+ // return;
1930+ //}
1931+ //attributionHandler.getAttribution();
19211932
19221933 AdjustFactory .setSessionInterval (4000 );
19231934
1924- /// if (activityState.subsessionCount > 1) {
1925- /// if (attribution == null || activityState.askingAttribution) {
1926- /// getAttributionHandler().getAttribution();
1927- /// }
1928- /// }
1929-
19301935 // create the config to start the session
19311936 AdjustConfig config = getConfig ();
19321937
@@ -1949,119 +1954,141 @@ public void onAttributionChanged(AdjustAttribution attribution) {
19491954
19501955 SystemClock .sleep (1500 );
19511956
1952- // subsession count is 1
1953- // attribution is null,
1954- // askingAttribution is false by default,
1955- // -> Not called
1957+ // it's first launch
1958+ // session response has not been processed
1959+ // attribution is null
1960+ // -> not called
19561961
1957- // test first session start
19581962 StateSession newSessionState = new StateSession (StateSession .SessionType .NEW_SESSION );
19591963 newSessionState .getAttributionIsCalled = false ;
19601964 checkStartInternal (newSessionState );
19611965
1962- // subsession count increased to 2
1963- // attribution is still null,
1964- // askingAttribution is still false,
1965- // -> Called
1966+ ActivityPackage firstSessionPackage = mockPackageHandler .queue .get (0 );
19661967
19671968 // trigger a new sub session
19681969 activityHandler .onResume ();
19691970 SystemClock .sleep (2000 );
19701971
1971- checkSubSession (1 , 2 , true );
1972+ // does not call because the session has not been processed
1973+ checkSubSession (1 , 2 , false );
19721974
1973- // subsession count increased to 3
1974- // attribution is still null,
1975- // askingAttribution is set to true,
1976- // -> Called
1975+ // it's first launch
1976+ // session response has been processed
1977+ // attribution is null
1978+ // -> called
19771979
1978- // set asking attribution
1979- activityHandler .setAskingAttribution (true );
1980- assertUtil .debug ("Wrote Activity state: ec:0 sc:1 ssc:2" );
1980+ // simulate a successful session
1981+ SessionResponseData successSessionResponseData = (SessionResponseData ) ResponseData .buildResponseData (firstSessionPackage );
1982+ successSessionResponseData .success = true ;
1983+ successSessionResponseData .message = "Session successfully tracked" ;
1984+ successSessionResponseData .adid = "adidValue" ;
19811985
1982- // trigger a new session
1986+ activityHandler .launchSessionResponseTasks (successSessionResponseData );
1987+
1988+ // trigger a new sub session
19831989 activityHandler .onResume ();
19841990 SystemClock .sleep (2000 );
19851991
1992+ // does call because the session has been processed
19861993 checkSubSession (1 , 3 , true );
19871994
1988- // subsession is reset to 1 with new session
1989- // attribution is still null,
1990- // askingAttribution is set to true,
1991- // -> Not called
1992-
1993- SystemClock .sleep (3000 ); // 5 seconds = 2 + 3
1994- activityHandler .onResume ();
1995- SystemClock .sleep (2000 );
1995+ // it's first launch
1996+ // session response has been processed
1997+ // attribution is not null
1998+ // askingAttribution is false
1999+ // -> not called
19962000
1997- checkFurtherSessions (2 , false );
2001+ // save the new attribution
2002+ successSessionResponseData .attribution = new AdjustAttribution ();
2003+ successSessionResponseData .attribution .trackerName = "trackerName" ;
2004+ activityHandler .launchSessionResponseTasks (successSessionResponseData );
19982005
1999- // subsession count increased to 2
2000- // attribution is set,
2001- // askingAttribution is set to true,
2002- // -> Called
2006+ activityHandler .setAskingAttribution (false );
20032007
2004- JSONObject jsonAttribution = null ;
2008+ // trigger a new sub session
2009+ activityHandler .onResume ();
2010+ SystemClock .sleep (2000 );
20052011
2006- try {
2007- jsonAttribution = new JSONObject ("{ " +
2008- "\" tracker_token\" : \" ttValue\" , " +
2009- "\" tracker_name\" : \" tnValue\" , " +
2010- "\" network\" : \" nValue\" , " +
2011- "\" campaign\" : \" cpValue\" , " +
2012- "\" adgroup\" : \" aValue\" , " +
2013- "\" creative\" : \" ctValue\" , " +
2014- "\" click_label\" : \" clValue\" }" );
2015- } catch (JSONException e ) {
2016- assertUtil .fail (e .getMessage ());
2017- }
2018- AdjustAttribution attribution = AdjustAttribution .fromJson (jsonAttribution , null ); // XXX
2012+ // does call because the session has been processed
2013+ checkSubSession (1 , 4 , false );
20192014
2020- // update the attribution
2021- activityHandler .updateAttributionI (attribution );
2015+ // it's first launch
2016+ // session response has been processed
2017+ // attribution is not null
2018+ // askingAttribution is true
2019+ // -> called
20222020
2023- // attribution was updated
2024- assertUtil .debug ("Wrote Attribution: tt:ttValue tn:tnValue net:nValue cam:cpValue adg:aValue cre:ctValue cl:clValue" );
2021+ activityHandler .setAskingAttribution (true );
20252022
20262023 // trigger a new sub session
20272024 activityHandler .onResume ();
20282025 SystemClock .sleep (2000 );
20292026
2030- checkSubSession (2 , 2 , true );
2031- // subsession count is reset to 1
2032- // attribution is set,
2033- // askingAttribution is set to true,
2034- // -> Not called
2027+ // does call because the session has been processed
2028+ checkSubSession (1 , 5 , true );
20352029
2036- SystemClock . sleep ( 3000 ); // 5 seconds = 2 + 3
2037- activityHandler . onResume ();
2038- SystemClock . sleep ( 2000 );
2030+ // it's not first launch
2031+ // attribution is null
2032+ // -> called
20392033
2040- checkFurtherSessions (3 , false );
2041- // subsession increased to 2
2042- // attribution is set,
2043- // askingAttribution is set to false
2044- // -> Not called
2034+ // finish activity handler
2035+ activityHandler .teardown (false );
2036+ // delete attribution
2037+ ActivityHandler .deleteAttribution (context );
20452038
2046- activityHandler .setAskingAttribution (false );
2047- assertUtil .debug ("Wrote Activity state: ec:0 sc:3 ssc:1" );
2039+ // start new activity handler
2040+ SystemClock .sleep (5000 );
2041+ activityHandler = getActivityHandler (config );
2042+
2043+ SystemClock .sleep (1500 );
2044+
2045+ // test init values
2046+ StateActivityHandlerInit stateActivityHandlerInit = new StateActivityHandlerInit (activityHandler );
2047+ stateActivityHandlerInit .readActivityState = "ec:0 sc:1 ssc:5" ;
2048+
2049+ checkInitTests (stateActivityHandlerInit );
2050+
2051+ resumeActivity (activityHandler );
2052+
2053+ SystemClock .sleep (1500 );
2054+
2055+ newSessionState = new StateSession (StateSession .SessionType .NEW_SESSION );
2056+ newSessionState .getAttributionIsCalled = true ;
2057+ newSessionState .sessionCount = 2 ;
2058+ checkStartInternal (newSessionState );
2059+
2060+ // it's not first launch
2061+ // attribution is not null
2062+ // askingAttribution is true
2063+ // -> called
2064+
2065+ // save the new attribution
2066+ successSessionResponseData .attribution = new AdjustAttribution ();
2067+ successSessionResponseData .attribution .trackerName = "trackerName" ;
2068+ activityHandler .launchSessionResponseTasks (successSessionResponseData );
2069+
2070+ activityHandler .setAskingAttribution (true );
20482071
20492072 // trigger a new sub session
20502073 activityHandler .onResume ();
20512074 SystemClock .sleep (2000 );
20522075
2053- checkSubSession (3 , 2 , false );
2076+ // does call because the session has been processed
2077+ checkSubSession (2 , 2 , true );
20542078
2055- // subsession is reset to 1
2056- // attribution is set,
2057- // askingAttribution is set to false
2058- // -> Not called
2079+ // it's not first launch
2080+ // attribution is not null
2081+ // askingAttribution is false
2082+ // -> not called
20592083
2060- SystemClock .sleep (3000 ); // 5 seconds = 2 + 3
2084+ activityHandler .setAskingAttribution (false );
2085+
2086+ // trigger a new sub session
20612087 activityHandler .onResume ();
20622088 SystemClock .sleep (2000 );
20632089
2064- checkFurtherSessions (4 , false );
2090+ // does call because the session has been processed
2091+ checkSubSession (2 , 3 , false );
20652092 }
20662093
20672094 @ Test
0 commit comments