From 32e6b5be0e662bbac22806bcc87259fd1a2e2ed0 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Fri, 29 Dec 2017 19:39:04 -0500 Subject: Feature/native notifs (#579) * Improve parser and add zip test * Remove ActivityOptionsCompat, resolves #555 * Create native notifs * Add animations * Add image rounder * Improve glide transformations * Add request service * Fix parser * Fix parser * Add thumbnail and fix notification text * Update parsers and regex * Auto mark as read * Add request implementation in pending intent * Remove unnecessary return data * Simplify command retrieval * Use name keys instead * Revamp all bundle calls * Fix up thumbnail layout --- .../test/kotlin/com/pitchedapps/frost/MiscTest.kt | 20 ++++++++++++--- .../com/pitchedapps/frost/facebook/FbParseTest.kt | 26 +++++++++++++++---- .../com/pitchedapps/frost/facebook/FbRegexTest.kt | 9 +++++-- .../pitchedapps/frost/facebook/FbRequestTest.kt | 8 +++--- .../com/pitchedapps/frost/internal/Internal.kt | 2 +- .../pitchedapps/frost/parsers/MessageParserTest.kt | 29 ---------------------- .../pitchedapps/frost/parsers/ParserTestHelper.kt | 22 ---------------- .../pitchedapps/frost/parsers/SearchParserTest.kt | 18 -------------- 8 files changed, 50 insertions(+), 84 deletions(-) delete mode 100644 app/src/test/kotlin/com/pitchedapps/frost/parsers/MessageParserTest.kt delete mode 100644 app/src/test/kotlin/com/pitchedapps/frost/parsers/ParserTestHelper.kt delete mode 100644 app/src/test/kotlin/com/pitchedapps/frost/parsers/SearchParserTest.kt (limited to 'app/src/test') diff --git a/app/src/test/kotlin/com/pitchedapps/frost/MiscTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/MiscTest.kt index 91e2149c..54792086 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/MiscTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/MiscTest.kt @@ -1,8 +1,9 @@ package com.pitchedapps.frost +import com.pitchedapps.frost.facebook.zip import com.pitchedapps.frost.injectors.CssHider import org.junit.Test -import kotlin.test.assertEquals +import kotlin.test.assertTrue /** * Created by Allan Wang on 2017-06-14. @@ -14,8 +15,21 @@ class MiscTest { print(CssHider.HEADER.injector.function) } + /** + * Spin off 15 threads + * Pause each for 1 - 2s + * Ensure that total zipped process does not take over 5s + */ @Test - fun nullPair() { - assertEquals(Pair(null, 2), Pair(null, 2)) + fun zip() { + val now = System.currentTimeMillis() + val base = 1 + val data = (0..15).map { Math.random() + base }.toTypedArray().zip( + List::toLongArray, + { Thread.sleep((it * 1000).toLong()); System.currentTimeMillis() - now } + ).blockingGet() + println(data.contentToString()) + assertTrue(data.all { it >= base * 1000 && it < base * 1000 * 5 }, + "zip did not seem to work on different threads") } } \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbParseTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbParseTest.kt index 65777f97..8c568279 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbParseTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbParseTest.kt @@ -7,6 +7,8 @@ import com.pitchedapps.frost.internal.authDependent import com.pitchedapps.frost.parsers.* import org.junit.BeforeClass import org.junit.Test +import kotlin.test.assertNotNull +import kotlin.test.assertTrue import kotlin.test.fail /** @@ -22,25 +24,39 @@ class FbParseTest { } } - private inline fun FrostParser.test(action: T.() -> Unit = {}) { - val response = parse(COOKIE) - ?: fail("${this::class.java.simpleName} returned null for $url") + private inline fun FrostParser.test(action: T.() -> Unit = {}) = + parse(COOKIE).test(url, action) + + private inline fun ParseResponse?.test(url: String, action: T.() -> Unit = {}) { + val response = this + ?: fail("${T::class.simpleName} parser returned null for $url") println(response) response.data.action() } @Test fun message() = MessageParser.test { - threads.forEach(FrostThread::assertComponentsNotEmpty) + threads.forEach { + it.assertComponentsNotEmpty() + assertTrue(it.id > FALLBACK_TIME_MOD, "id may not be properly matched") + assertNotNull(it.img, "img may not be properly matched") + } threads.map(FrostThread::time).assertDescending("thread time values") } + @Test + fun messageUser() = MessageParser.queryUser(COOKIE, "allan").test("allan query") + @Test fun search() = SearchParser.test() @Test fun notif() = NotifParser.test { - notifs.forEach(FrostNotif::assertComponentsNotEmpty) + notifs.forEach { + it.assertComponentsNotEmpty() + assertTrue(it.id > FALLBACK_TIME_MOD, "id may not be properly matched") + assertNotNull(it.img, "img may not be properly matched") + } notifs.map(FrostNotif::time).assertDescending("notif time values") } } \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRegexTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRegexTest.kt index a21bcb13..da815b34 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRegexTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRegexTest.kt @@ -25,8 +25,13 @@ class FbRegexTest { @Test fun ppRegex() { val img = "https\\3a //scontent-yyz1-1.xx.fbcdn.net/v/asdf1234.jpg?efg\\3d 333\\26 oh\\3d 77\\26 oe\\3d 444" - val ppStyle = "background:#d8dce6 url('$img') no-repeat center;background-size:100% 100%;-webkit-background-size:100% 100%;width:58px;height:58px;" - assertEquals(StringEscapeUtils.unescapeCsv(img), StringEscapeUtils.unescapeCsv(FB_CSS_URL_MATCHER.find(ppStyle)[1])) + val imgUnescaped = StringEscapeUtils.unescapeCsv(img) + val ppStyleSingleQuote = "background:#d8dce6 url('$img') no-repeat center;" + val ppStyleDoubleQuote = "background:#d8dce6 url(\"$img\") no-repeat center;" + val ppStyleNoQuote = "background:#d8dce6 url($img) no-repeat center;" + listOf(ppStyleSingleQuote, ppStyleDoubleQuote, ppStyleNoQuote).forEach { + assertEquals(imgUnescaped, StringEscapeUtils.unescapeCsv(FB_CSS_URL_MATCHER.find(it)[1])) + } } @Test diff --git a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt index 16894b16..c3b19727 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/facebook/FbRequestTest.kt @@ -23,7 +23,7 @@ class FbRequestTest { } /** - * Used to emulate [executeAndCheck] + * Used to emulate [executeForNoError] * Must be consistent with that method */ private fun Call.assertNoError() { @@ -35,7 +35,7 @@ class FbRequestTest { @Test fun auth() { - val auth = (USER_ID to COOKIE).getAuth() + val auth = COOKIE.getAuth() assertNotNull(auth) assertEquals(USER_ID, auth.userId) assertEquals(COOKIE, auth.cookie) @@ -44,8 +44,8 @@ class FbRequestTest { @Test fun markNotification() { - val notifId = 1513544657695779 - AUTH.markNotificationRead(notifId).assertNoError() + val notifId = 1514443903880 + AUTH.markNotificationRead(notifId).call.assertNoError() } } \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt b/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt index deaed333..ed88453a 100644 --- a/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt +++ b/app/src/test/kotlin/com/pitchedapps/frost/internal/Internal.kt @@ -32,7 +32,7 @@ val PROPS: Properties by lazy { val COOKIE: String by lazy { PROPS.getProperty("COOKIE") ?: "" } val USER_ID: Long by lazy { FB_USER_MATCHER.find(COOKIE)[1]?.toLong() ?: -1 } val AUTH: RequestAuth by lazy { - (USER_ID to COOKIE).getAuth().apply { + COOKIE.getAuth().apply { println("Auth:\nuser:$userId\nfb_dtsg: $fb_dtsg\nrev: $rev\nvalid: $isValid") } } diff --git a/app/src/test/kotlin/com/pitchedapps/frost/parsers/MessageParserTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/parsers/MessageParserTest.kt deleted file mode 100644 index ecebed04..00000000 --- a/app/src/test/kotlin/com/pitchedapps/frost/parsers/MessageParserTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.pitchedapps.frost.parsers - -import com.pitchedapps.frost.facebook.FB_EPOCH_MATCHER -import com.pitchedapps.frost.facebook.formattedFbUrl -import com.pitchedapps.frost.facebook.get -import org.junit.Test -import kotlin.test.assertEquals - -/** - * Created by Allan Wang on 2017-10-06. - */ -class MessageParserTest { - - @Test - fun basic() = debug("messages", MessageParser) - - @Test - fun parseEpoch() { - val input = "{\"time\":1507301642,\"short\":true,\"forceseconds\":false}" - assertEquals(1507301642, FB_EPOCH_MATCHER.find(input)[1]!!.toLong()) - } - - @Test - fun parseImage() { - var input = "https\\3a //scontent.fyhu1-1.fna.fbcdn.net/v/t1.0-1/cp0/e15/q65/p100x100/12994387_243040309382307_4586627375882013710_n.jpg?efg\\3d eyJpIjoidCJ9\\26 oh\\3d b9ae0d7a1298989fe24873e2ee4054b6\\26 oe\\3d 5A3A7FE1" - input = input.formattedFbUrl - println(input) - } -} \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/parsers/ParserTestHelper.kt b/app/src/test/kotlin/com/pitchedapps/frost/parsers/ParserTestHelper.kt deleted file mode 100644 index 53495ecb..00000000 --- a/app/src/test/kotlin/com/pitchedapps/frost/parsers/ParserTestHelper.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.pitchedapps.frost.parsers - -import java.net.URL -import java.nio.file.Paths - -/** - * Created by Allan Wang on 2017-10-06. - */ -fun T.getResource(path: String): String? { - Paths.get("src/test/resources/${path.trimStart('/')}") - val resource: URL? = this::class.java.classLoader.getResource(path) - if (resource == null) { - println("Resource at $path could not be found") - return null - } - return resource.readText() -} - -fun T.debug(path: String, parser: FrostParser

) { - val content = getResource("priv/$path.html") ?: return -// println(parser.debug(content)) -} \ No newline at end of file diff --git a/app/src/test/kotlin/com/pitchedapps/frost/parsers/SearchParserTest.kt b/app/src/test/kotlin/com/pitchedapps/frost/parsers/SearchParserTest.kt deleted file mode 100644 index 6a7b60ae..00000000 --- a/app/src/test/kotlin/com/pitchedapps/frost/parsers/SearchParserTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.pitchedapps.frost.parsers - -import org.junit.Test - -/** - * Created by Allan Wang on 2017-10-06. - */ -class SearchParserTest { - - @Test - fun debug() = debug("search", SearchParser) - - @Test - fun debug2() = debug("search2", SearchParser) - - @Test - fun debug3() = debug("search3", SearchParser) -} \ No newline at end of file -- cgit v1.2.3