This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
5294: Closes #4556: Passwords sync telemetry support r=rocketsroger,liuche a=grigoryk This adds a new ping to `support-telemetry-sync` - passwords_sync, which is then used in `services-firefox-accounts` and in `service-sync-logins` to emit password sync telemetry whenever this engine is synchronized. New ping is a verbatim copy of the history_sync ping. `samples-sync` app was also updated to demonstrate to how synchronize passwords, and how to protect encryption key at rest used for the password storage. 5360: Closes #5315 - Create a Top Sites storage component r=pocmo a=gabrielluong Co-authored-by: Grisha Kruglov <gkruglov@mozilla.com> Co-authored-by: Gabriel Luong <gabriel.luong@gmail.com>
- Loading branch information
Showing
28 changed files
with
1,164 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# [Android Components](../../../README.md) > Feature > Top Sites | ||
|
||
Feature implementation for saving and removing top sites. | ||
|
||
## Usage | ||
|
||
### Setting up the dependency | ||
|
||
Use Gradle to download the library from [maven.mozilla.org](https://maven.mozilla.org/) ([Setup repository](../../../README.md#maven-repository)): | ||
|
||
```Groovy | ||
implementation "org.mozilla.components:feature-top-sites:{latest-version}" | ||
``` | ||
|
||
## License | ||
|
||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-kapt' | ||
|
||
android { | ||
compileSdkVersion config.compileSdkVersion | ||
|
||
defaultConfig { | ||
minSdkVersion config.minSdkVersion | ||
targetSdkVersion config.targetSdkVersion | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
|
||
kapt { | ||
arguments { | ||
arg("room.schemaLocation", "$projectDir/schemas".toString()) | ||
} | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
packagingOptions { | ||
exclude 'META-INF/proguard/androidx-annotations.pro' | ||
} | ||
|
||
sourceSets { | ||
androidTest.assets.srcDirs += files("$projectDir/schemas".toString()) | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation project(':support-ktx') | ||
implementation project(':support-base') | ||
|
||
implementation Dependencies.kotlin_stdlib | ||
implementation Dependencies.kotlin_coroutines | ||
|
||
implementation Dependencies.androidx_paging | ||
implementation Dependencies.androidx_lifecycle_extensions | ||
kapt Dependencies.androidx_lifecycle_compiler | ||
|
||
implementation Dependencies.androidx_room_runtime | ||
kapt Dependencies.androidx_room_compiler | ||
|
||
testImplementation project(':support-test') | ||
|
||
testImplementation Dependencies.androidx_test_core | ||
testImplementation Dependencies.testing_junit | ||
testImplementation Dependencies.testing_mockito | ||
testImplementation Dependencies.testing_robolectric | ||
testImplementation Dependencies.kotlin_coroutines | ||
|
||
androidTestImplementation project(':support-android-test') | ||
|
||
androidTestImplementation Dependencies.androidx_room_testing | ||
androidTestImplementation Dependencies.androidx_arch_core_testing | ||
androidTestImplementation Dependencies.androidx_test_core | ||
androidTestImplementation Dependencies.androidx_test_runner | ||
androidTestImplementation Dependencies.androidx_test_rules | ||
} | ||
|
||
apply from: '../../../publish.gradle' | ||
ext.configurePublish(config.componentsGroupId, archivesBaseName, project.ext.description) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
52 changes: 52 additions & 0 deletions
52
.../feature/top-sites/schemas/mozilla.components.feature.top.sites.db.TopSiteDatabase/1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"formatVersion": 1, | ||
"database": { | ||
"version": 1, | ||
"identityHash": "ce733d9c47cd10312a1c13de8efb7e8d", | ||
"entities": [ | ||
{ | ||
"tableName": "top_sites", | ||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `title` TEXT NOT NULL, `url` TEXT NOT NULL, `created_at` INTEGER NOT NULL)", | ||
"fields": [ | ||
{ | ||
"fieldPath": "id", | ||
"columnName": "id", | ||
"affinity": "INTEGER", | ||
"notNull": false | ||
}, | ||
{ | ||
"fieldPath": "title", | ||
"columnName": "title", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "url", | ||
"columnName": "url", | ||
"affinity": "TEXT", | ||
"notNull": true | ||
}, | ||
{ | ||
"fieldPath": "createdAt", | ||
"columnName": "created_at", | ||
"affinity": "INTEGER", | ||
"notNull": true | ||
} | ||
], | ||
"primaryKey": { | ||
"columnNames": [ | ||
"id" | ||
], | ||
"autoGenerate": true | ||
}, | ||
"indices": [], | ||
"foreignKeys": [] | ||
} | ||
], | ||
"views": [], | ||
"setupQueries": [ | ||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", | ||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ce733d9c47cd10312a1c13de8efb7e8d')" | ||
] | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...top-sites/src/androidTest/java/mozilla/components/feature/top/sites/TopSiteStorageTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.feature.top.sites | ||
|
||
import android.content.Context | ||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule | ||
import androidx.paging.PagedList | ||
import androidx.room.Room | ||
import androidx.test.core.app.ApplicationProvider | ||
import mozilla.components.feature.top.sites.db.TopSiteDatabase | ||
import mozilla.components.support.android.test.awaitValue | ||
import org.junit.After | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNotNull | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import java.util.concurrent.ExecutorService | ||
import java.util.concurrent.Executors | ||
|
||
@Suppress("LargeClass") | ||
class TopSiteStorageTest { | ||
private lateinit var context: Context | ||
private lateinit var storage: TopSiteStorage | ||
private lateinit var executor: ExecutorService | ||
|
||
@get:Rule | ||
var instantTaskExecutorRule = InstantTaskExecutorRule() | ||
|
||
@Before | ||
fun setUp() { | ||
executor = Executors.newSingleThreadExecutor() | ||
|
||
context = ApplicationProvider.getApplicationContext() | ||
val database = Room.inMemoryDatabaseBuilder(context, TopSiteDatabase::class.java).build() | ||
|
||
storage = TopSiteStorage(context) | ||
storage.database = lazy { database } | ||
} | ||
|
||
@After | ||
fun tearDown() { | ||
executor.shutdown() | ||
} | ||
|
||
@Test | ||
fun testAddingTopSite() { | ||
storage.addTopSite("Mozilla", "https://www.mozilla.org") | ||
storage.addTopSite("Firefox", "https://www.firefox.com") | ||
|
||
val topSites = getAllTopSites() | ||
|
||
assertEquals(2, topSites.size) | ||
|
||
assertEquals("Mozilla", topSites[0].title) | ||
assertEquals("https://www.mozilla.org", topSites[0].url) | ||
assertEquals("Firefox", topSites[1].title) | ||
assertEquals("https://www.firefox.com", topSites[1].url) | ||
} | ||
|
||
@Test | ||
fun testRemovingTopSites() { | ||
storage.addTopSite("Mozilla", "https://www.mozilla.org") | ||
storage.addTopSite("Firefox", "https://www.firefox.com") | ||
|
||
getAllTopSites().let { topSites -> | ||
assertEquals(2, topSites.size) | ||
|
||
storage.removeTopSite(topSites[0]) | ||
} | ||
|
||
getAllTopSites().let { topSites -> | ||
assertEquals(1, topSites.size) | ||
|
||
assertEquals("Firefox", topSites[0].title) | ||
assertEquals("https://www.firefox.com", topSites[0].url) | ||
} | ||
} | ||
|
||
@Test | ||
fun testGettingTopSites() { | ||
storage.addTopSite("Mozilla", "https://www.mozilla.org") | ||
storage.addTopSite("Firefox", "https://www.firefox.com") | ||
|
||
val topSites = storage.getTopSites().awaitValue() | ||
|
||
assertNotNull(topSites!!) | ||
assertEquals(2, topSites.size) | ||
|
||
with(topSites[0]) { | ||
assertEquals("Mozilla", title) | ||
assertEquals("https://www.mozilla.org", url) | ||
} | ||
|
||
with(topSites[1]) { | ||
assertEquals("Firefox", title) | ||
assertEquals("https://www.firefox.com", url) | ||
} | ||
} | ||
|
||
private fun getAllTopSites(): List<TopSite> { | ||
val dataSource = storage.getTopSitesPaged().create() | ||
|
||
val pagedList = PagedList.Builder(dataSource, 10) | ||
.setNotifyExecutor(executor) | ||
.setFetchExecutor(executor) | ||
.build() | ||
|
||
return pagedList.toList() | ||
} | ||
} |
Oops, something went wrong.