Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1885141 - Add logs to MockBrowserDataHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiAJ committed Mar 13, 2024
1 parent f7542f3 commit a42b065
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ package org.mozilla.fenix.helpers

import android.graphics.Bitmap
import android.graphics.Color
import android.util.Log
import org.junit.Assert.assertEquals
import org.mozilla.fenix.helpers.Constants.TAG

/**
* Asserts the two bitmaps are the same by ensuring their dimensions, config, and
* pixel data are the same (within the provided delta): this is the same metrics that
* [Bitmap.sameAs] uses.
*/
fun assertEqualsWithDelta(expectedB: Bitmap, actualB: Bitmap, delta: Float) {
Log.i(TAG, "assertEqualsWithDelta: Trying to verify that the Bitmap of $expectedB is equal with the Bitmap of $actualB within delta: $delta")
assertEquals("widths should be equal", expectedB.width, actualB.width)
assertEquals("heights should be equal", expectedB.height, actualB.height)
assertEquals("config should be equal", expectedB.config, actualB.config)
Expand All @@ -29,4 +32,5 @@ fun assertEqualsWithDelta(expectedB: Bitmap, actualB: Bitmap, delta: Float) {
assertEquals("$warn b", Color.blue(ePx).toFloat(), Color.blue(aPx).toFloat(), delta)
}
}
Log.i(TAG, "assertEqualsWithDelta: Verified that the Bitmap of $expectedB is equal with the Bitmap of $actualB within delta: $delta")
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,16 @@

package org.mozilla.fenix.helpers

import android.util.Log
import androidx.test.espresso.IdlingRegistry
import androidx.test.rule.ActivityTestRule
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.helpers.idlingresource.AddonsInstallingIdlingResource
import org.mozilla.fenix.helpers.Constants.TAG

object IdlingResourceHelper {

// Idling Resource to manage installing an addon
fun registerAddonInstallingIdlingResource(activityTestRule: ActivityTestRule<HomeActivity>) {
IdlingRegistry.getInstance().register(
AddonsInstallingIdlingResource(
activityTestRule.activity.supportFragmentManager,
),
)
}

fun unregisterAddonInstallingIdlingResource(activityTestRule: ActivityTestRule<HomeActivity>) {
IdlingRegistry.getInstance().unregister(
AddonsInstallingIdlingResource(
activityTestRule.activity.supportFragmentManager,
),
)
}

fun unregisterAllIdlingResources() {
for (resource in IdlingRegistry.getInstance().resources) {
Log.i(TAG, "unregisterAllIdlingResources: Trying to unregister ${resource.name} resource")
IdlingRegistry.getInstance().unregister(resource)
Log.i(TAG, "unregisterAllIdlingResources: Unregistered ${resource.name} resource")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.mozilla.fenix.helpers

import android.content.Context
import android.util.Log
import androidx.test.platform.app.InstrumentationRegistry
import kotlinx.coroutines.runBlocking
import mozilla.appservices.places.BookmarkRoot
Expand All @@ -18,6 +19,7 @@ import mozilla.components.concept.storage.VisitType
import mozilla.components.feature.search.ext.createSearchEngine
import okhttp3.mockwebserver.MockWebServer
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.Constants.TAG
import org.mozilla.fenix.helpers.TestHelper.appContext
import org.mozilla.fenix.search.SearchEngineSource.None.searchEngine

Expand All @@ -32,6 +34,7 @@ object MockBrowserDataHelper {
* @param position Example for the position param: 1u, 2u, etc.
*/
fun createBookmarkItem(url: String, title: String, position: UInt?) {
Log.i(TAG, "createBookmarkItem: Trying to add bookmark item at position: $position, with url: $url, and with title: $title")
runBlocking {
PlacesBookmarksStorage(context)
.addItem(
Expand All @@ -41,6 +44,7 @@ object MockBrowserDataHelper {
position,
)
}
Log.i(TAG, "createBookmarkItem: Added bookmark item at position: $position, with url: $url, and with title: $title")
}

/**
Expand All @@ -49,13 +53,15 @@ object MockBrowserDataHelper {
* @param url The URL of the history item to add. URLs should use the "https://example.com" format.
*/
fun createHistoryItem(url: String) {
Log.i(TAG, "createHistoryItem: Trying to add history item with url: $url")
runBlocking {
PlacesHistoryStorage(appContext)
.recordVisit(
url,
PageVisit(VisitType.LINK),
)
}
Log.i(TAG, "createHistoryItem: Added history item with url: $url")
}

/**
Expand All @@ -64,17 +70,21 @@ object MockBrowserDataHelper {
* URLs should use the "https://example.com" format.
*/
fun createTabItem(url: String) {
Log.i(TAG, "createTabItem: Trying to create a new tab with url: $url")
runBlocking {
appContext.components.useCases.tabsUseCases.addTab(url)
}
Log.i(TAG, "createTabItem: Created a new tab with url: $url")
}

/**
* Triggers a search for the provided search term in a new tab.
*
*/
fun createSearchHistory(searchTerm: String) {
Log.i(TAG, "createSearchHistory: Trying to perform a new search with search term: $searchTerm")
appContext.components.useCases.searchUseCases.newTabSearch.invoke(searchTerm)
Log.i(TAG, "createSearchHistory: Performed a new search with search term: $searchTerm")
}

/**
Expand All @@ -86,6 +96,7 @@ object MockBrowserDataHelper {
private fun createCustomSearchEngine(mockWebServer: MockWebServer, searchEngineName: String): SearchEngine {
val searchString =
"http://localhost:${mockWebServer.port}/pages/searchResults.html?search={searchTerms}"
Log.i(TAG, "createCustomSearchEngine: Trying to create a custom search engine named: $searchEngineName and search string: $searchString")
return createSearchEngine(
name = searchEngineName,
url = searchString,
Expand All @@ -100,8 +111,9 @@ object MockBrowserDataHelper {
*/
fun addCustomSearchEngine(mockWebServer: MockWebServer, searchEngineName: String) {
val searchEngine = createCustomSearchEngine(mockWebServer, searchEngineName)

Log.i(TAG, "addCustomSearchEngine: Trying to add a custom search engine named: $searchEngineName")
appContext.components.useCases.searchUseCases.addSearchEngine(searchEngine)
Log.i(TAG, "addCustomSearchEngine: Added a custom search engine named: $searchEngineName")
}

/**
Expand All @@ -111,10 +123,11 @@ object MockBrowserDataHelper {
*/
fun setCustomSearchEngine(mockWebServer: MockWebServer, searchEngineName: String) {
val searchEngine = createCustomSearchEngine(mockWebServer, searchEngineName)

Log.i(TAG, "setCustomSearchEngine: Trying to set a custom search engine named: $searchEngineName")
with(appContext.components.useCases.searchUseCases) {
addSearchEngine(searchEngine)
selectSearchEngine(searchEngine)
}
Log.i(TAG, "setCustomSearchEngine: A custom search engine named: $searchEngineName was set")
}
}

0 comments on commit a42b065

Please sign in to comment.