From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- .../tests/background/junit3/AndroidManifest.xml.in | 23 + mobile/android/tests/background/junit3/Makefile.in | 13 + .../junit3/background_junit3_sources.mozbuild | 78 + .../tests/background/junit3/instrumentation.ini | 22 + mobile/android/tests/background/junit3/moz.build | 42 + .../background/junit3/res/drawable-hdpi/icon.png | Bin 0 -> 7639 bytes .../background/junit3/res/drawable-ldpi/icon.png | Bin 0 -> 2979 bytes .../background/junit3/res/drawable-mdpi/icon.png | Bin 0 -> 4625 bytes .../tests/background/junit3/res/layout/main.xml | 12 + .../tests/background/junit3/res/values/strings.xml | 6 + .../background/common/TestAndroidLogWriters.java | 68 + .../mozilla/gecko/background/common/TestUtils.java | 159 + .../gecko/background/common/TestWaitHelper.java | 356 ++ .../db/AndroidBrowserRepositoryTestCase.java | 818 ++++ .../db/TestAndroidBrowserBookmarksRepository.java | 636 +++ .../db/TestAndroidBrowserHistoryRepository.java | 450 ++ .../mozilla/gecko/background/db/TestBookmarks.java | 1063 +++++ .../gecko/background/db/TestClientsDatabase.java | 200 + .../background/db/TestClientsDatabaseAccessor.java | 128 + .../db/TestFennecTabsRepositorySession.java | 297 ++ .../db/TestFormHistoryRepositorySession.java | 441 ++ .../background/db/TestPasswordsRepository.java | 482 ++ .../mozilla/gecko/background/db/TestTopSites.java | 92 + .../gecko/background/fxa/TestAccountLoader.java | 163 + .../fxa/TestBrowserIDKeyPairGeneration.java | 49 + .../fxa/authenticator/TestAccountPickler.java | 134 + .../background/helpers/AndroidSyncTestCase.java | 52 + .../gecko/background/helpers/DBHelpers.java | 84 + .../background/helpers/DBProviderTestCase.java | 73 + .../nativecode/test/TestNativeCrypto.java | 175 + .../sync/AndroidSyncTestCaseWithAccounts.java | 128 + .../gecko/background/sync/TestClientsStage.java | 95 + .../gecko/background/sync/TestResetting.java | 198 + .../gecko/background/sync/TestStoreTracking.java | 377 ++ .../background/sync/TestSyncConfiguration.java | 146 + .../gecko/background/sync/TestWebURLFinder.java | 49 + .../background/sync/helpers/BookmarkHelpers.java | 216 + .../sync/helpers/DefaultBeginDelegate.java | 33 + .../sync/helpers/DefaultCleanDelegate.java | 21 + .../background/sync/helpers/DefaultDelegate.java | 52 + .../sync/helpers/DefaultFetchDelegate.java | 106 + .../sync/helpers/DefaultFinishDelegate.java | 60 + .../sync/helpers/DefaultGuidsSinceDelegate.java | 19 + .../helpers/DefaultSessionCreationDelegate.java | 53 + .../sync/helpers/DefaultStoreDelegate.java | 71 + .../sync/helpers/ExpectBeginDelegate.java | 22 + .../sync/helpers/ExpectBeginFailDelegate.java | 16 + .../sync/helpers/ExpectFetchDelegate.java | 32 + .../sync/helpers/ExpectFetchSinceDelegate.java | 47 + .../sync/helpers/ExpectFinishDelegate.java | 17 + .../sync/helpers/ExpectFinishFailDelegate.java | 15 + .../sync/helpers/ExpectGuidsSinceDelegate.java | 41 + .../helpers/ExpectInvalidRequestFetchDelegate.java | 24 + .../helpers/ExpectInvalidTypeStoreDelegate.java | 18 + .../sync/helpers/ExpectManyStoredDelegate.java | 48 + .../sync/helpers/ExpectNoGUIDsSinceDelegate.java | 33 + .../sync/helpers/ExpectNoStoreDelegate.java | 11 + .../sync/helpers/ExpectStoreCompletedDelegate.java | 17 + .../sync/helpers/ExpectStoredDelegate.java | 39 + .../background/sync/helpers/HistoryHelpers.java | 90 + .../background/sync/helpers/PasswordHelpers.java | 94 + .../background/sync/helpers/SessionTestHelper.java | 82 + .../sync/helpers/SimpleSuccessBeginDelegate.java | 20 + .../helpers/SimpleSuccessCreationDelegate.java | 18 + .../sync/helpers/SimpleSuccessFetchDelegate.java | 22 + .../sync/helpers/SimpleSuccessFinishDelegate.java | 20 + .../sync/helpers/SimpleSuccessStoreDelegate.java | 20 + .../testhelpers/BaseMockServerSyncStage.java | 69 + .../background/testhelpers/CommandHelpers.java | 40 + .../testhelpers/DefaultGlobalSessionCallback.java | 52 + .../MockAbstractNonRepositorySyncStage.java | 13 + .../testhelpers/MockClientsDataDelegate.java | 66 + .../testhelpers/MockClientsDatabaseAccessor.java | 76 + .../background/testhelpers/MockGlobalSession.java | 57 + .../testhelpers/MockPrefsGlobalSession.java | 63 + .../gecko/background/testhelpers/MockRecord.java | 34 + .../testhelpers/MockServerSyncStage.java | 12 + .../testhelpers/MockSharedPreferences.java | 137 + .../background/testhelpers/WBORepository.java | 231 + .../gecko/background/testhelpers/WaitHelper.java | 171 + .../junit4/resources/dlc_sync_deleted_item.json | 8 + .../junit4/resources/dlc_sync_old_format.json | 23 + .../junit4/resources/dlc_sync_single_font.json | 23 + .../background/junit4/resources/experiments.json | 99 + .../junit4/resources/feed_atom_blogger.xml | 13 + .../junit4/resources/feed_atom_feedburner.xml | 2 + .../junit4/resources/feed_atom_planetmozilla.xml | 4996 ++++++++++++++++++++ .../junit4/resources/feed_atom_wikipedia.xml | 34 + .../junit4/resources/feed_rss10_planetmozilla.xml | 3860 +++++++++++++++ .../junit4/resources/feed_rss20_planetmozilla.xml | 3853 +++++++++++++++ .../background/junit4/resources/feed_rss_heise.xml | 1965 ++++++++ .../junit4/resources/feed_rss_medium.xml | 100 + .../background/junit4/resources/feed_rss_spon.xml | 314 ++ .../junit4/resources/feed_rss_tumblr.xml | 95 + .../junit4/resources/feed_rss_wikipedia.xml | 21 + .../junit4/resources/feed_rss_wordpress.xml | 84 + .../junit4/resources/robolectric.properties | 3 + .../com/keepsafe/switchboard/TestSwitchboard.java | 142 + .../mozilla/android/sync/net/test/TestBackoff.java | 114 + .../net/test/TestBrowserIDAuthHeaderProvider.java | 23 + .../sync/net/test/TestClientsEngineStage.java | 806 ++++ .../sync/net/test/TestCredentialsEndToEnd.java | 72 + .../android/sync/net/test/TestGlobalSession.java | 436 ++ .../android/sync/net/test/TestHeaderParsing.java | 29 + .../sync/net/test/TestLineByLineHandling.java | 115 + .../android/sync/net/test/TestMetaGlobal.java | 347 ++ .../android/sync/net/test/TestResource.java | 102 + .../android/sync/net/test/TestRetryAfter.java | 87 + .../sync/net/test/TestServer11Repository.java | 48 + .../sync/net/test/TestSyncStorageRequest.java | 269 ++ .../android/sync/test/SynchronizerHelpers.java | 282 ++ .../android/sync/test/TestCollectionKeys.java | 197 + .../android/sync/test/TestCommandProcessor.java | 117 + .../android/sync/test/TestCryptoRecord.java | 302 ++ .../org/mozilla/android/sync/test/TestRecord.java | 330 ++ .../android/sync/test/TestRecordsChannel.java | 229 + .../android/sync/test/TestResetCommands.java | 153 + .../sync/test/TestServer11RepositorySession.java | 231 + .../sync/test/TestServerLocalSynchronizer.java | 237 + .../android/sync/test/TestSyncConfiguration.java | 39 + .../android/sync/test/TestSynchronizer.java | 398 ++ .../android/sync/test/TestSynchronizerSession.java | 306 ++ .../org/mozilla/android/sync/test/TestUtils.java | 154 + .../helpers/BaseTestStorageRequestDelegate.java | 61 + .../sync/test/helpers/ExpectSuccessDelegate.java | 35 + ...xpectSuccessRepositorySessionBeginDelegate.java | 38 + ...ctSuccessRepositorySessionCreationDelegate.java | 36 + ...ccessRepositorySessionFetchRecordsDelegate.java | 44 + ...pectSuccessRepositorySessionFinishDelegate.java | 37 + ...xpectSuccessRepositorySessionStoreDelegate.java | 39 + .../ExpectSuccessRepositoryWipeDelegate.java | 36 + .../sync/test/helpers/HTTPServerTestHelper.java | 226 + .../test/helpers/MockGlobalSessionCallback.java | 91 + .../sync/test/helpers/MockResourceDelegate.java | 85 + .../android/sync/test/helpers/MockServer.java | 73 + .../test/helpers/MockSyncClientsEngineStage.java | 71 + .../android/sync/test/helpers/MockWBOServer.java | 28 + .../helpers/test/TestHTTPServerTestHelper.java | 102 + .../org/mozilla/gecko/GeckoNetworkManagerTest.java | 51 + .../org/mozilla/gecko/GlobalPageMetadataTest.java | 174 + .../src/org/mozilla/gecko/TestGeckoProfile.java | 254 + .../gecko/activitystream/TestActivityStream.java | 85 + .../common/log/writers/test/TestLogWriters.java | 179 + .../db/DelegatingTestContentProvider.java | 86 + .../gecko/background/db/TestTabsProvider.java | 338 ++ .../background/db/TestTabsProviderRemoteTabs.java | 244 + .../background/fxa/test/TestFxAccountClient20.java | 41 + .../background/fxa/test/TestFxAccountUtils.java | 131 + .../gecko/background/test/EntityTestHelper.java | 34 + .../testhelpers/BaseMockServerSyncStage.java | 72 + .../background/testhelpers/CommandHelpers.java | 40 + .../testhelpers/DefaultGlobalSessionCallback.java | 51 + .../MockAbstractNonRepositorySyncStage.java | 13 + .../testhelpers/MockClientsDataDelegate.java | 66 + .../testhelpers/MockClientsDatabaseAccessor.java | 76 + .../background/testhelpers/MockGlobalSession.java | 57 + .../testhelpers/MockPrefsGlobalSession.java | 60 + .../gecko/background/testhelpers/MockRecord.java | 51 + .../testhelpers/MockServerSyncStage.java | 11 + .../testhelpers/MockSharedPreferences.java | 137 + .../gecko/background/testhelpers/TestRunner.java | 125 + .../background/testhelpers/WBORepository.java | 230 + .../gecko/background/testhelpers/WaitHelper.java | 172 + .../mozilla/gecko/browserid/test/TestASNUtils.java | 45 + .../test/TestDSACryptoImplementation.java | 60 + .../browserid/test/TestJSONWebTokenUtils.java | 151 + .../test/TestRSACryptoImplementation.java | 56 + .../gecko/cleanup/TestFileCleanupController.java | 92 + .../gecko/cleanup/TestFileCleanupService.java | 106 + .../org/mozilla/gecko/db/BrowserContractTest.java | 67 + .../gecko/db/BrowserProviderHighlightsTest.java | 438 ++ .../gecko/db/BrowserProviderHistoryTest.java | 341 ++ .../gecko/db/BrowserProviderHistoryVisitsTest.java | 338 ++ .../db/BrowserProviderHistoryVisitsTestBase.java | 77 + .../gecko/db/BrowserProviderVisitsTest.java | 301 ++ .../gecko/distribution/TestReferrerDescriptor.java | 33 + .../org/mozilla/gecko/dlc/TestDownloadAction.java | 607 +++ .../src/org/mozilla/gecko/dlc/TestStudyAction.java | 119 + .../src/org/mozilla/gecko/dlc/TestSyncAction.java | 276 ++ .../org/mozilla/gecko/dlc/TestVerifyAction.java | 123 + .../dlc/catalog/TestDownloadContentBuilder.java | 69 + .../dlc/catalog/TestDownloadContentCatalog.java | 262 + .../feeds/knownsites/TestKnownSiteBlogger.java | 74 + .../feeds/knownsites/TestKnownSiteMedium.java | 66 + .../feeds/knownsites/TestKnownSiteTumblr.java | 62 + .../gecko/feeds/parser/TestSimpleFeedParser.java | 323 ++ .../src/org/mozilla/gecko/fxa/TestSkewHandler.java | 70 + .../gecko/fxa/login/MockFxAccountClient.java | 226 + .../fxa/login/TestFxAccountLoginStateMachine.java | 205 + .../mozilla/gecko/fxa/login/TestStateFactory.java | 91 + .../src/org/mozilla/gecko/helpers/AssertUtil.java | 29 + .../home/TestHomeConfigPrefsBackendMigration.java | 264 ++ .../mozilla/gecko/icons/TestIconDescriptor.java | 56 + .../gecko/icons/TestIconDescriptorComparator.java | 152 + .../org/mozilla/gecko/icons/TestIconRequest.java | 81 + .../gecko/icons/TestIconRequestBuilder.java | 159 + .../org/mozilla/gecko/icons/TestIconResponse.java | 148 + .../src/org/mozilla/gecko/icons/TestIconTask.java | 575 +++ .../org/mozilla/gecko/icons/TestIconsHelper.java | 139 + .../icons/loader/TestContentProviderLoader.java | 31 + .../gecko/icons/loader/TestDataUriLoader.java | 46 + .../mozilla/gecko/icons/loader/TestDiskLoader.java | 94 + .../gecko/icons/loader/TestIconDownloader.java | 112 + .../gecko/icons/loader/TestIconGenerator.java | 128 + .../mozilla/gecko/icons/loader/TestJarLoader.java | 31 + .../gecko/icons/loader/TestLegacyLoader.java | 152 + .../gecko/icons/loader/TestMemoryLoader.java | 78 + .../icons/preparation/TestAboutPagesPreparer.java | 73 + .../icons/preparation/TestAddDefaultIconUrl.java | 79 + .../preparation/TestFilterKnownFailureUrls.java | 60 + .../icons/preparation/TestFilterMimeTypes.java | 67 + .../preparation/TestFilterPrivilegedUrls.java | 86 + .../gecko/icons/preparation/TestLookupIconUrl.java | 101 + .../gecko/icons/processing/TestColorProcessor.java | 59 + .../gecko/icons/processing/TestDiskProcessor.java | 100 + .../icons/processing/TestMemoryProcessor.java | 134 + .../icons/processing/TestResizingProcessor.java | 111 + .../mozilla/gecko/permissions/TestPermissions.java | 253 + .../org/mozilla/gecko/push/TestPushManager.java | 238 + .../src/org/mozilla/gecko/push/TestPushState.java | 70 + .../push/autopush/test/TestAutopushClient.java | 30 + .../push/autopush/test/TestLiveAutopushClient.java | 171 + .../mozilla/gecko/sync/crypto/test/TestBase32.java | 53 + .../gecko/sync/crypto/test/TestCryptoInfo.java | 144 + .../mozilla/gecko/sync/crypto/test/TestHKDF.java | 143 + .../gecko/sync/crypto/test/TestKeyBundle.java | 65 + .../mozilla/gecko/sync/crypto/test/TestPBKDF2.java | 124 + .../sync/crypto/test/TestPersistedCrypto5Keys.java | 83 + .../gecko/sync/crypto/test/TestSRPConstants.java | 45 + .../TestCrypto5MiddlewareRepositorySession.java | 291 ++ .../sync/net/test/TestHMACAuthHeaderProvider.java | 165 + .../sync/net/test/TestHawkAuthHeaderProvider.java | 145 + .../gecko/sync/net/test/TestLiveHawkAuth.java | 181 + .../gecko/sync/net/test/TestUserAgentHeaders.java | 131 + .../android/BrowserContractHelpersTest.java | 33 + .../repositories/android/VisitsHelperTest.java | 144 + .../test/TestBookmarksInsertionManager.java | 221 + .../sync/repositories/domain/TestClientRecord.java | 103 + .../domain/test/TestFormHistoryRecord.java | 92 + .../BatchingDownloaderDelegateTest.java | 186 + .../downloaders/BatchingDownloaderTest.java | 543 +++ .../test/TestRepositorySessionBundle.java | 47 + .../TestSafeConstrainedServer11Repository.java | 144 + .../sync/repositories/uploaders/BatchMetaTest.java | 282 ++ .../uploaders/BatchingUploaderTest.java | 441 ++ .../sync/repositories/uploaders/PayloadTest.java | 137 + .../uploaders/PayloadUploadDelegateTest.java | 404 ++ .../uploaders/RecordUploadRunnableTest.java | 38 + .../stage/test/TestEnsureCrypto5KeysStage.java | 237 + .../sync/stage/test/TestFetchMetaGlobalStage.java | 391 ++ .../gecko/sync/stage/test/TestStageLookup.java | 41 + .../gecko/sync/test/TestExtendedJSONObject.java | 203 + .../gecko/sync/test/TestInfoCollections.java | 101 + .../gecko/sync/test/TestPersistedMetaGlobal.java | 105 + .../measurements/TestSearchCountMeasurements.java | 161 + .../measurements/TestSessionMeasurements.java | 124 + .../pingbuilders/TestTelemetryPingBuilder.java | 84 + ...elemetryUploadAllPingsImmediatelyScheduler.java | 59 + .../stores/TestTelemetryJSONFilePingStore.java | 250 + .../tokenserver/test/TestTokenServerClient.java | 335 ++ .../org/mozilla/gecko/util/NetworkUtilsTest.java | 185 + .../org/mozilla/gecko/util/TestContextUtils.java | 38 + .../src/org/mozilla/gecko/util/TestDateUtil.java | 89 + .../src/org/mozilla/gecko/util/TestFileUtils.java | 339 ++ .../org/mozilla/gecko/util/TestIntentUtils.java | 73 + .../org/mozilla/gecko/util/TestStringUtils.java | 122 + .../src/org/mozilla/gecko/util/TestUUIDUtil.java | 51 + .../gecko/util/publicsuffix/TestPublicSuffix.java | 62 + mobile/android/tests/background/moz.build | 9 + 269 files changed, 50374 insertions(+) create mode 100644 mobile/android/tests/background/junit3/AndroidManifest.xml.in create mode 100644 mobile/android/tests/background/junit3/Makefile.in create mode 100644 mobile/android/tests/background/junit3/background_junit3_sources.mozbuild create mode 100644 mobile/android/tests/background/junit3/instrumentation.ini create mode 100644 mobile/android/tests/background/junit3/moz.build create mode 100644 mobile/android/tests/background/junit3/res/drawable-hdpi/icon.png create mode 100644 mobile/android/tests/background/junit3/res/drawable-ldpi/icon.png create mode 100644 mobile/android/tests/background/junit3/res/drawable-mdpi/icon.png create mode 100644 mobile/android/tests/background/junit3/res/layout/main.xml create mode 100644 mobile/android/tests/background/junit3/res/values/strings.xml create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestAndroidLogWriters.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestUtils.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestWaitHelper.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/AndroidBrowserRepositoryTestCase.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestAndroidBrowserBookmarksRepository.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryRepository.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestClientsDatabase.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestClientsDatabaseAccessor.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestFormHistoryRepositorySession.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestPasswordsRepository.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestTopSites.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestAccountLoader.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestBrowserIDKeyPairGeneration.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/authenticator/TestAccountPickler.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/AndroidSyncTestCase.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/DBHelpers.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/DBProviderTestCase.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/nativecode/test/TestNativeCrypto.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/AndroidSyncTestCaseWithAccounts.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestClientsStage.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestResetting.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestSyncConfiguration.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestWebURLFinder.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/BookmarkHelpers.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultBeginDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultCleanDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFinishDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultGuidsSinceDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultSessionCreationDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultStoreDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectBeginDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectBeginFailDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFetchDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFetchSinceDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFinishDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFinishFailDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectGuidsSinceDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectInvalidRequestFetchDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectInvalidTypeStoreDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectManyStoredDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectNoGUIDsSinceDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectNoStoreDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectStoreCompletedDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectStoredDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/HistoryHelpers.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/PasswordHelpers.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SessionTestHelper.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessBeginDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessCreationDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFetchDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFinishDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessStoreDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/BaseMockServerSyncStage.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/CommandHelpers.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/DefaultGlobalSessionCallback.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockAbstractNonRepositorySyncStage.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockClientsDataDelegate.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockClientsDatabaseAccessor.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockGlobalSession.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockPrefsGlobalSession.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockRecord.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockServerSyncStage.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockSharedPreferences.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/WBORepository.java create mode 100644 mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java create mode 100644 mobile/android/tests/background/junit4/resources/dlc_sync_deleted_item.json create mode 100644 mobile/android/tests/background/junit4/resources/dlc_sync_old_format.json create mode 100644 mobile/android/tests/background/junit4/resources/dlc_sync_single_font.json create mode 100644 mobile/android/tests/background/junit4/resources/experiments.json create mode 100644 mobile/android/tests/background/junit4/resources/feed_atom_blogger.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_atom_feedburner.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_atom_planetmozilla.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_atom_wikipedia.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_rss10_planetmozilla.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_rss20_planetmozilla.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_rss_heise.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_rss_medium.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_rss_spon.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_rss_tumblr.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_rss_wikipedia.xml create mode 100644 mobile/android/tests/background/junit4/resources/feed_rss_wordpress.xml create mode 100644 mobile/android/tests/background/junit4/resources/robolectric.properties create mode 100644 mobile/android/tests/background/junit4/src/com/keepsafe/switchboard/TestSwitchboard.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestBackoff.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestBrowserIDAuthHeaderProvider.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestClientsEngineStage.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestCredentialsEndToEnd.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestGlobalSession.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestHeaderParsing.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestLineByLineHandling.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestMetaGlobal.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestResource.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestRetryAfter.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestServer11Repository.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestSyncStorageRequest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCollectionKeys.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCommandProcessor.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCryptoRecord.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestRecord.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestRecordsChannel.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestResetCommands.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestServer11RepositorySession.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestServerLocalSynchronizer.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSyncConfiguration.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSynchronizer.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSynchronizerSession.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestUtils.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/BaseTestStorageRequestDelegate.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessDelegate.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionBeginDelegate.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionCreationDelegate.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFinishDelegate.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionStoreDelegate.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositoryWipeDelegate.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/HTTPServerTestHelper.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockGlobalSessionCallback.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockResourceDelegate.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockServer.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockSyncClientsEngineStage.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockWBOServer.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/test/TestHTTPServerTestHelper.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/GeckoNetworkManagerTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/GlobalPageMetadataTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/TestGeckoProfile.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/activitystream/TestActivityStream.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/common/log/writers/test/TestLogWriters.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/DelegatingTestContentProvider.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/TestTabsProvider.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/TestTabsProviderRemoteTabs.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/fxa/test/TestFxAccountClient20.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/fxa/test/TestFxAccountUtils.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/test/EntityTestHelper.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/BaseMockServerSyncStage.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/CommandHelpers.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/DefaultGlobalSessionCallback.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockAbstractNonRepositorySyncStage.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockClientsDataDelegate.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockClientsDatabaseAccessor.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockGlobalSession.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockPrefsGlobalSession.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockRecord.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockServerSyncStage.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockSharedPreferences.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/TestRunner.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WBORepository.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestASNUtils.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestDSACryptoImplementation.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestJSONWebTokenUtils.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestRSACryptoImplementation.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/cleanup/TestFileCleanupController.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/cleanup/TestFileCleanupService.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserContractTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHighlightsTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryVisitsTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryVisitsTestBase.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderVisitsTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/distribution/TestReferrerDescriptor.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestDownloadAction.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestStudyAction.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestSyncAction.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestVerifyAction.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/catalog/TestDownloadContentBuilder.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/catalog/TestDownloadContentCatalog.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteBlogger.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteMedium.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteTumblr.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/parser/TestSimpleFeedParser.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/TestSkewHandler.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/TestFxAccountLoginStateMachine.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/TestStateFactory.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/helpers/AssertUtil.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/home/TestHomeConfigPrefsBackendMigration.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconDescriptor.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconDescriptorComparator.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequestBuilder.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconResponse.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconTask.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconsHelper.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestContentProviderLoader.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestDataUriLoader.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestDiskLoader.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestIconDownloader.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestIconGenerator.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestJarLoader.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestLegacyLoader.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestMemoryLoader.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestAboutPagesPreparer.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestAddDefaultIconUrl.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterKnownFailureUrls.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterMimeTypes.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterPrivilegedUrls.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestLookupIconUrl.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestColorProcessor.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestDiskProcessor.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestMemoryProcessor.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestResizingProcessor.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/permissions/TestPermissions.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/TestPushManager.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/TestPushState.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestAutopushClient.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestLiveAutopushClient.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestBase32.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestCryptoInfo.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestHKDF.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestKeyBundle.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestPBKDF2.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestPersistedCrypto5Keys.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestSRPConstants.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/middleware/test/TestCrypto5MiddlewareRepositorySession.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestHMACAuthHeaderProvider.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestHawkAuthHeaderProvider.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestLiveHawkAuth.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestUserAgentHeaders.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/BrowserContractHelpersTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/VisitsHelperTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/test/TestBookmarksInsertionManager.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/domain/TestClientRecord.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/domain/test/TestFormHistoryRecord.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/test/TestRepositorySessionBundle.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/test/TestSafeConstrainedServer11Repository.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/BatchMetaTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/BatchingUploaderTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/PayloadTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/PayloadUploadDelegateTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/RecordUploadRunnableTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestEnsureCrypto5KeysStage.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestFetchMetaGlobalStage.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestStageLookup.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestExtendedJSONObject.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestInfoCollections.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestPersistedMetaGlobal.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/measurements/TestSearchCountMeasurements.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/measurements/TestSessionMeasurements.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/pingbuilders/TestTelemetryPingBuilder.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/schedulers/TestTelemetryUploadAllPingsImmediatelyScheduler.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/stores/TestTelemetryJSONFilePingStore.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/tokenserver/test/TestTokenServerClient.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/NetworkUtilsTest.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestContextUtils.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestDateUtil.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestFileUtils.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestIntentUtils.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestStringUtils.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestUUIDUtil.java create mode 100644 mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/publicsuffix/TestPublicSuffix.java create mode 100644 mobile/android/tests/background/moz.build (limited to 'mobile/android/tests/background') diff --git a/mobile/android/tests/background/junit3/AndroidManifest.xml.in b/mobile/android/tests/background/junit3/AndroidManifest.xml.in new file mode 100644 index 000000000..09f1a25a1 --- /dev/null +++ b/mobile/android/tests/background/junit3/AndroidManifest.xml.in @@ -0,0 +1,23 @@ +#filter substitution + + + + + + + + + + + diff --git a/mobile/android/tests/background/junit3/Makefile.in b/mobile/android/tests/background/junit3/Makefile.in new file mode 100644 index 000000000..f7f40ca78 --- /dev/null +++ b/mobile/android/tests/background/junit3/Makefile.in @@ -0,0 +1,13 @@ +# 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/. + +ANDROID_EXTRA_JARS := \ + background-junit3.jar \ + $(NULL) + +ANDROID_MANIFEST_FILE := $(CURDIR)/AndroidManifest.xml + +include $(topsrcdir)/config/rules.mk + +tools:: $(ANDROID_APK_NAME).apk diff --git a/mobile/android/tests/background/junit3/background_junit3_sources.mozbuild b/mobile/android/tests/background/junit3/background_junit3_sources.mozbuild new file mode 100644 index 000000000..021af2eb8 --- /dev/null +++ b/mobile/android/tests/background/junit3/background_junit3_sources.mozbuild @@ -0,0 +1,78 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +background_junit3_sources = [ + 'src/org/mozilla/gecko/background/common/TestAndroidLogWriters.java', + 'src/org/mozilla/gecko/background/common/TestUtils.java', + 'src/org/mozilla/gecko/background/common/TestWaitHelper.java', + 'src/org/mozilla/gecko/background/db/AndroidBrowserRepositoryTestCase.java', + 'src/org/mozilla/gecko/background/db/TestAndroidBrowserBookmarksRepository.java', + 'src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryRepository.java', + 'src/org/mozilla/gecko/background/db/TestBookmarks.java', + 'src/org/mozilla/gecko/background/db/TestClientsDatabase.java', + 'src/org/mozilla/gecko/background/db/TestClientsDatabaseAccessor.java', + 'src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java', + 'src/org/mozilla/gecko/background/db/TestFormHistoryRepositorySession.java', + 'src/org/mozilla/gecko/background/db/TestPasswordsRepository.java', + 'src/org/mozilla/gecko/background/db/TestTopSites.java', + 'src/org/mozilla/gecko/background/fxa/authenticator/TestAccountPickler.java', + 'src/org/mozilla/gecko/background/fxa/TestAccountLoader.java', + 'src/org/mozilla/gecko/background/fxa/TestBrowserIDKeyPairGeneration.java', + 'src/org/mozilla/gecko/background/helpers/AndroidSyncTestCase.java', + 'src/org/mozilla/gecko/background/helpers/DBHelpers.java', + 'src/org/mozilla/gecko/background/helpers/DBProviderTestCase.java', + 'src/org/mozilla/gecko/background/nativecode/test/TestNativeCrypto.java', + 'src/org/mozilla/gecko/background/sync/AndroidSyncTestCaseWithAccounts.java', + 'src/org/mozilla/gecko/background/sync/helpers/BookmarkHelpers.java', + 'src/org/mozilla/gecko/background/sync/helpers/DefaultBeginDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/DefaultCleanDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/DefaultDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/DefaultFinishDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/DefaultGuidsSinceDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/DefaultSessionCreationDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/DefaultStoreDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectBeginDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectBeginFailDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectFetchDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectFetchSinceDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectFinishDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectFinishFailDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectGuidsSinceDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectInvalidRequestFetchDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectInvalidTypeStoreDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectManyStoredDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectNoGUIDsSinceDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectNoStoreDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectStoreCompletedDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/ExpectStoredDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/HistoryHelpers.java', + 'src/org/mozilla/gecko/background/sync/helpers/PasswordHelpers.java', + 'src/org/mozilla/gecko/background/sync/helpers/SessionTestHelper.java', + 'src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessBeginDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessCreationDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFetchDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFinishDelegate.java', + 'src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessStoreDelegate.java', + 'src/org/mozilla/gecko/background/sync/TestClientsStage.java', + 'src/org/mozilla/gecko/background/sync/TestResetting.java', + 'src/org/mozilla/gecko/background/sync/TestStoreTracking.java', + 'src/org/mozilla/gecko/background/sync/TestSyncConfiguration.java', + 'src/org/mozilla/gecko/background/sync/TestWebURLFinder.java', + 'src/org/mozilla/gecko/background/testhelpers/BaseMockServerSyncStage.java', + 'src/org/mozilla/gecko/background/testhelpers/CommandHelpers.java', + 'src/org/mozilla/gecko/background/testhelpers/DefaultGlobalSessionCallback.java', + 'src/org/mozilla/gecko/background/testhelpers/MockAbstractNonRepositorySyncStage.java', + 'src/org/mozilla/gecko/background/testhelpers/MockClientsDatabaseAccessor.java', + 'src/org/mozilla/gecko/background/testhelpers/MockClientsDataDelegate.java', + 'src/org/mozilla/gecko/background/testhelpers/MockGlobalSession.java', + 'src/org/mozilla/gecko/background/testhelpers/MockPrefsGlobalSession.java', + 'src/org/mozilla/gecko/background/testhelpers/MockRecord.java', + 'src/org/mozilla/gecko/background/testhelpers/MockServerSyncStage.java', + 'src/org/mozilla/gecko/background/testhelpers/MockSharedPreferences.java', + 'src/org/mozilla/gecko/background/testhelpers/WaitHelper.java', + 'src/org/mozilla/gecko/background/testhelpers/WBORepository.java', +] diff --git a/mobile/android/tests/background/junit3/instrumentation.ini b/mobile/android/tests/background/junit3/instrumentation.ini new file mode 100644 index 000000000..e2c7b2ea1 --- /dev/null +++ b/mobile/android/tests/background/junit3/instrumentation.ini @@ -0,0 +1,22 @@ +[DEFAULT] +subsuite = background + +[src/org/mozilla/gecko/background/common/TestAndroidLogWriters.java] +[src/org/mozilla/gecko/background/common/TestUtils.java] +[src/org/mozilla/gecko/background/common/TestWaitHelper.java] +[src/org/mozilla/gecko/background/db/TestAndroidBrowserBookmarksRepository.java] +[src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryRepository.java] +[src/org/mozilla/gecko/background/db/TestBookmarks.java] +[src/org/mozilla/gecko/background/db/TestClientsDatabase.java] +[src/org/mozilla/gecko/background/db/TestClientsDatabaseAccessor.java] +[src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java] +[src/org/mozilla/gecko/background/db/TestFormHistoryRepositorySession.java] +[src/org/mozilla/gecko/background/db/TestPasswordsRepository.java] +[src/org/mozilla/gecko/background/fxa/TestBrowserIDKeyPairGeneration.java] +[src/org/mozilla/gecko/background/fxa/authenticator/TestAccountPickler.java] +[src/org/mozilla/gecko/background/nativecode/test/TestNativeCrypto.java] +[src/org/mozilla/gecko/background/sync/TestClientsStage.java] +[src/org/mozilla/gecko/background/sync/TestResetting.java] +[src/org/mozilla/gecko/background/sync/TestStoreTracking.java] +[src/org/mozilla/gecko/background/sync/TestSyncConfiguration.java] +[src/org/mozilla/gecko/background/sync/TestWebURLFinder.java] diff --git a/mobile/android/tests/background/junit3/moz.build b/mobile/android/tests/background/junit3/moz.build new file mode 100644 index 000000000..3e81e1e32 --- /dev/null +++ b/mobile/android/tests/background/junit3/moz.build @@ -0,0 +1,42 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +DEFINES['ANDROID_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME'] + +ANDROID_APK_NAME = 'background-junit3-debug' +ANDROID_APK_PACKAGE = 'org.mozilla.gecko.background.tests' + +include('background_junit3_sources.mozbuild') + +jar = add_java_jar('background-junit3') +jar.sources += background_junit3_sources +jar.extra_jars += [ + CONFIG['ANDROID_SUPPORT_V4_AAR_LIB'], + CONFIG['ANDROID_RECYCLERVIEW_V7_AAR_LIB'], + TOPOBJDIR + '/mobile/android/base/constants.jar', + TOPOBJDIR + '/mobile/android/base/gecko-R.jar', + TOPOBJDIR + '/mobile/android/base/gecko-browser.jar', + TOPOBJDIR + '/mobile/android/base/gecko-mozglue.jar', + TOPOBJDIR + '/mobile/android/base/gecko-thirdparty.jar', + TOPOBJDIR + '/mobile/android/base/gecko-util.jar', + TOPOBJDIR + '/mobile/android/base/gecko-view.jar', + TOPOBJDIR + '/mobile/android/base/services.jar', + TOPOBJDIR + '/mobile/android/base/sync-thirdparty.jar', +] + +if CONFIG['MOZ_ANDROID_MLS_STUMBLER']: + jar.extra_jars += [ + TOPOBJDIR + '/mobile/android/stumbler/stumbler.jar', + ] + +ANDROID_INSTRUMENTATION_MANIFESTS += ['instrumentation.ini'] + +DEFINES['ANDROID_BACKGROUND_TARGET_PACKAGE_NAME'] = CONFIG['ANDROID_PACKAGE_NAME'] +DEFINES['ANDROID_BACKGROUND_APP_DISPLAYNAME'] = '%s Background Tests' % CONFIG['MOZ_APP_DISPLAYNAME'] +DEFINES['MOZ_ANDROID_SHARED_ID'] = CONFIG['MOZ_ANDROID_SHARED_ID'] +OBJDIR_PP_FILES.mobile.android.tests.background.junit3 += [ + 'AndroidManifest.xml.in', +] diff --git a/mobile/android/tests/background/junit3/res/drawable-hdpi/icon.png b/mobile/android/tests/background/junit3/res/drawable-hdpi/icon.png new file mode 100644 index 000000000..e83438eee Binary files /dev/null and b/mobile/android/tests/background/junit3/res/drawable-hdpi/icon.png differ diff --git a/mobile/android/tests/background/junit3/res/drawable-ldpi/icon.png b/mobile/android/tests/background/junit3/res/drawable-ldpi/icon.png new file mode 100644 index 000000000..0483c95e9 Binary files /dev/null and b/mobile/android/tests/background/junit3/res/drawable-ldpi/icon.png differ diff --git a/mobile/android/tests/background/junit3/res/drawable-mdpi/icon.png b/mobile/android/tests/background/junit3/res/drawable-mdpi/icon.png new file mode 100644 index 000000000..86b4dee54 Binary files /dev/null and b/mobile/android/tests/background/junit3/res/drawable-mdpi/icon.png differ diff --git a/mobile/android/tests/background/junit3/res/layout/main.xml b/mobile/android/tests/background/junit3/res/layout/main.xml new file mode 100644 index 000000000..14dbff7e0 --- /dev/null +++ b/mobile/android/tests/background/junit3/res/layout/main.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/mobile/android/tests/background/junit3/res/values/strings.xml b/mobile/android/tests/background/junit3/res/values/strings.xml new file mode 100644 index 000000000..d6534d7fa --- /dev/null +++ b/mobile/android/tests/background/junit3/res/values/strings.xml @@ -0,0 +1,6 @@ + + + + Gecko Background Tests + + diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestAndroidLogWriters.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestAndroidLogWriters.java new file mode 100644 index 000000000..7f4b9bb9c --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestAndroidLogWriters.java @@ -0,0 +1,68 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.common; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.common.log.writers.AndroidLevelCachingLogWriter; +import org.mozilla.gecko.background.common.log.writers.AndroidLogWriter; +import org.mozilla.gecko.background.common.log.writers.LogWriter; +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; + +public class TestAndroidLogWriters extends AndroidSyncTestCase { + public static final String TEST_LOG_TAG = "TestAndroidLogWriters"; + + public static final String TEST_MESSAGE_1 = "LOG TEST MESSAGE one"; + public static final String TEST_MESSAGE_2 = "LOG TEST MESSAGE two"; + public static final String TEST_MESSAGE_3 = "LOG TEST MESSAGE three"; + + public void setUp() { + Logger.stopLoggingToAll(); + } + + public void tearDown() { + Logger.resetLogging(); + } + + /** + * Verify these *all* appear in the Android log by using + * adb logcat | grep TestAndroidLogWriters after executing + * adb shell setprop log.tag.TestAndroidLogWriters ERROR. + *

+ * This writer does not use the Android log levels! + */ + public void testAndroidLogWriter() { + LogWriter lw = new AndroidLogWriter(); + + Logger.error(TEST_LOG_TAG, TEST_MESSAGE_1, new RuntimeException()); + Logger.startLoggingTo(lw); + Logger.error(TEST_LOG_TAG, TEST_MESSAGE_2); + Logger.warn(TEST_LOG_TAG, TEST_MESSAGE_2); + Logger.info(TEST_LOG_TAG, TEST_MESSAGE_2); + Logger.debug(TEST_LOG_TAG, TEST_MESSAGE_2); + Logger.trace(TEST_LOG_TAG, TEST_MESSAGE_2); + Logger.stopLoggingTo(lw); + Logger.error(TEST_LOG_TAG, TEST_MESSAGE_3, new RuntimeException()); + } + + /** + * Verify only *some* of these appear in the Android log by using + * adb logcat | grep TestAndroidLogWriters after executing + * adb shell setprop log.tag.TestAndroidLogWriters INFO. + *

+ * This writer should use the Android log levels! + */ + public void testAndroidLevelCachingLogWriter() throws Exception { + LogWriter lw = new AndroidLevelCachingLogWriter(new AndroidLogWriter()); + + Logger.error(TEST_LOG_TAG, TEST_MESSAGE_1, new RuntimeException()); + Logger.startLoggingTo(lw); + Logger.error(TEST_LOG_TAG, TEST_MESSAGE_2); + Logger.warn(TEST_LOG_TAG, TEST_MESSAGE_2); + Logger.info(TEST_LOG_TAG, TEST_MESSAGE_2); + Logger.debug(TEST_LOG_TAG, TEST_MESSAGE_2); + Logger.trace(TEST_LOG_TAG, TEST_MESSAGE_2); + Logger.stopLoggingTo(lw); + Logger.error(TEST_LOG_TAG, TEST_MESSAGE_3, new RuntimeException()); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestUtils.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestUtils.java new file mode 100644 index 000000000..270eae6f6 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestUtils.java @@ -0,0 +1,159 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.common; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.sync.Utils; + +import android.os.Bundle; + +public class TestUtils extends AndroidSyncTestCase { + protected static void assertStages(String[] all, String[] sync, String[] skip, String[] expected) { + final Set sAll = new HashSet(); + for (String s : all) { + sAll.add(s); + } + List sSync = null; + if (sync != null) { + sSync = new ArrayList(); + for (String s : sync) { + sSync.add(s); + } + } + List sSkip = null; + if (skip != null) { + sSkip = new ArrayList(); + for (String s : skip) { + sSkip.add(s); + } + } + List stages = new ArrayList(Utils.getStagesToSync(sAll, sSync, sSkip)); + Collections.sort(stages); + List exp = new ArrayList(); + for (String e : expected) { + exp.add(e); + } + assertEquals(exp, stages); + } + + public void testGetStagesToSync() { + final String[] all = new String[] { "other1", "other2", "skip1", "skip2", "sync1", "sync2" }; + assertStages(all, null, null, all); + assertStages(all, new String[] { "sync1" }, null, new String[] { "sync1" }); + assertStages(all, null, new String[] { "skip1", "skip2" }, new String[] { "other1", "other2", "sync1", "sync2" }); + assertStages(all, new String[] { "sync1", "sync2" }, new String[] { "skip1", "skip2" }, new String[] { "sync1", "sync2" }); + } + + protected static void assertStagesFromBundle(String[] all, String[] sync, String[] skip, String[] expected) { + final Set sAll = new HashSet(); + for (String s : all) { + sAll.add(s); + } + final Bundle bundle = new Bundle(); + Utils.putStageNamesToSync(bundle, sync, skip); + + Collection ss = Utils.getStagesToSyncFromBundle(sAll, bundle); + List stages = new ArrayList(ss); + Collections.sort(stages); + List exp = new ArrayList(); + for (String e : expected) { + exp.add(e); + } + assertEquals(exp, stages); + } + + public void testGetStagesToSyncFromBundle() { + final String[] all = new String[] { "other1", "other2", "skip1", "skip2", "sync1", "sync2" }; + assertStagesFromBundle(all, null, null, all); + assertStagesFromBundle(all, new String[] { "sync1" }, null, new String[] { "sync1" }); + assertStagesFromBundle(all, null, new String[] { "skip1", "skip2" }, new String[] { "other1", "other2", "sync1", "sync2" }); + assertStagesFromBundle(all, new String[] { "sync1", "sync2" }, new String[] { "skip1", "skip2" }, new String[] { "sync1", "sync2" }); + } + + public static void deleteDirectoryRecursively(final File dir) throws IOException { + if (!dir.isDirectory()) { + throw new IllegalStateException("Given directory, " + dir + ", is not a directory!"); + } + + for (File f : dir.listFiles()) { + if (f.isDirectory()) { + deleteDirectoryRecursively(f); + } else if (!f.delete()) { + // Since this method is for testing, we assume we should be able to do this. + throw new IOException("Could not delete file, " + f.getAbsolutePath() + ". Permissions?"); + } + } + + if (!dir.delete()) { + throw new IOException("Could not delete dir, " + dir.getAbsolutePath() + "."); + } + } + + public void testDeleteDirectoryRecursively() throws Exception { + final String TEST_DIR = getApplicationContext().getCacheDir().getAbsolutePath() + + "-testDeleteDirectory-" + System.currentTimeMillis(); + + // Non-existent directory. + final File nonexistent = new File("nonexistentDirectory"); // Hopefully. ;) + assertFalse(nonexistent.exists()); + try { + deleteDirectoryRecursively(nonexistent); + fail("deleteDirectoryRecursively on a nonexistent directory should throw Exception"); + } catch (IllegalStateException e) { } + + // Empty dir. + File dir = mkdir(TEST_DIR); + deleteDirectoryRecursively(dir); + assertFalse(dir.exists()); + + // Filled dir. + dir = mkdir(TEST_DIR); + populateDir(dir); + deleteDirectoryRecursively(dir); + assertFalse(dir.exists()); + + // Filled dir with empty dir. + dir = mkdir(TEST_DIR); + populateDir(dir); + File subDir = new File(TEST_DIR + File.separator + "subDir"); + assertTrue(subDir.mkdir()); + deleteDirectoryRecursively(dir); + assertFalse(subDir.exists()); // For short-circuiting errors. + assertFalse(dir.exists()); + + // Filled dir with filled dir. + dir = mkdir(TEST_DIR); + populateDir(dir); + subDir = new File(TEST_DIR + File.separator + "subDir"); + assertTrue(subDir.mkdir()); + populateDir(subDir); + deleteDirectoryRecursively(dir); + assertFalse(subDir.exists()); // For short-circuiting errors. + assertFalse(dir.exists()); + } + + private File mkdir(final String name) { + final File dir = new File(name); + assertTrue(dir.mkdir()); + return dir; + } + + private void populateDir(final File dir) throws IOException { + assertTrue(dir.isDirectory()); + final String dirPath = dir.getAbsolutePath(); + for (int i = 0; i < 3; i++) { + final File f = new File(dirPath + File.separator + i); + assertTrue(f.createNewFile()); // Throws IOException if file could not be created. + } + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestWaitHelper.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestWaitHelper.java new file mode 100644 index 000000000..1f818e0cf --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/common/TestWaitHelper.java @@ -0,0 +1,356 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.common; + +import junit.framework.AssertionFailedError; + +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.background.testhelpers.WaitHelper.InnerError; +import org.mozilla.gecko.background.testhelpers.WaitHelper.TimeoutError; +import org.mozilla.gecko.sync.ThreadPool; + +public class TestWaitHelper extends AndroidSyncTestCase { + private static final String ERROR_UNIQUE_IDENTIFIER = "error unique identifier"; + + public static int NO_WAIT = 1; // Milliseconds. + public static int SHORT_WAIT = 100; // Milliseconds. + public static int LONG_WAIT = 3 * SHORT_WAIT; + + private Object notifyMonitor = new Object(); + // Guarded by notifyMonitor. + private boolean performNotifyCalled = false; + private boolean performNotifyErrorCalled = false; + private void setPerformNotifyCalled() { + synchronized (notifyMonitor) { + performNotifyCalled = true; + } + } + private void setPerformNotifyErrorCalled() { + synchronized (notifyMonitor) { + performNotifyErrorCalled = true; + } + } + private void resetNotifyCalled() { + synchronized (notifyMonitor) { + performNotifyCalled = false; + performNotifyErrorCalled = false; + } + } + private void assertBothCalled() { + synchronized (notifyMonitor) { + assertTrue(performNotifyCalled); + assertTrue(performNotifyErrorCalled); + } + } + private void assertErrorCalled() { + synchronized (notifyMonitor) { + assertFalse(performNotifyCalled); + assertTrue(performNotifyErrorCalled); + } + } + private void assertCalled() { + synchronized (notifyMonitor) { + assertTrue(performNotifyCalled); + assertFalse(performNotifyErrorCalled); + } + } + + public WaitHelper waitHelper; + + public TestWaitHelper() { + super(); + } + + public void setUp() { + WaitHelper.resetTestWaiter(); + waitHelper = WaitHelper.getTestWaiter(); + resetNotifyCalled(); + } + + public void tearDown() { + assertTrue(waitHelper.isIdle()); + } + + public Runnable performNothingRunnable() { + return new Runnable() { + public void run() { + } + }; + } + + public Runnable performNotifyRunnable() { + return new Runnable() { + public void run() { + setPerformNotifyCalled(); + waitHelper.performNotify(); + } + }; + } + + public Runnable performNotifyAfterDelayRunnable(final int delayInMillis) { + return new Runnable() { + public void run() { + try { + Thread.sleep(delayInMillis); + } catch (InterruptedException e) { + fail("Interrupted."); + } + + setPerformNotifyCalled(); + waitHelper.performNotify(); + } + }; + } + + public Runnable performNotifyErrorRunnable() { + return new Runnable() { + public void run() { + setPerformNotifyCalled(); + waitHelper.performNotify(new AssertionFailedError(ERROR_UNIQUE_IDENTIFIER)); + } + }; + } + + public Runnable inThreadPool(final Runnable runnable) { + return new Runnable() { + @Override + public void run() { + ThreadPool.run(runnable); + } + }; + } + + public Runnable inThread(final Runnable runnable) { + return new Runnable() { + @Override + public void run() { + new Thread(runnable).start(); + } + }; + } + + protected void expectAssertionFailedError(Runnable runnable) { + try { + waitHelper.performWait(runnable); + } catch (InnerError e) { + AssertionFailedError inner = (AssertionFailedError)e.innerError; + setPerformNotifyErrorCalled(); + String message = inner.getMessage(); + assertTrue("Expected '" + message + "' to contain '" + ERROR_UNIQUE_IDENTIFIER + "'", + message.contains(ERROR_UNIQUE_IDENTIFIER)); + } + } + + protected void expectAssertionFailedErrorAfterDelay(int wait, Runnable runnable) { + try { + waitHelper.performWait(wait, runnable); + } catch (InnerError e) { + AssertionFailedError inner = (AssertionFailedError)e.innerError; + setPerformNotifyErrorCalled(); + String message = inner.getMessage(); + assertTrue("Expected '" + message + "' to contain '" + ERROR_UNIQUE_IDENTIFIER + "'", + message.contains(ERROR_UNIQUE_IDENTIFIER)); + } + } + + public void testPerformWait() { + waitHelper.performWait(performNotifyRunnable()); + assertCalled(); + } + + public void testPerformWaitInThread() { + waitHelper.performWait(inThread(performNotifyRunnable())); + assertCalled(); + } + + public void testPerformWaitInThreadPool() { + waitHelper.performWait(inThreadPool(performNotifyRunnable())); + assertCalled(); + } + + public void testPerformTimeoutWait() { + waitHelper.performWait(SHORT_WAIT, performNotifyRunnable()); + assertCalled(); + } + + public void testPerformTimeoutWaitInThread() { + waitHelper.performWait(SHORT_WAIT, inThread(performNotifyRunnable())); + assertCalled(); + } + + public void testPerformTimeoutWaitInThreadPool() { + waitHelper.performWait(SHORT_WAIT, inThreadPool(performNotifyRunnable())); + assertCalled(); + } + + public void testPerformErrorWaitInThread() { + expectAssertionFailedError(inThread(performNotifyErrorRunnable())); + assertBothCalled(); + } + + public void testPerformErrorWaitInThreadPool() { + expectAssertionFailedError(inThreadPool(performNotifyErrorRunnable())); + assertBothCalled(); + } + + public void testPerformErrorTimeoutWaitInThread() { + expectAssertionFailedErrorAfterDelay(SHORT_WAIT, inThread(performNotifyErrorRunnable())); + assertBothCalled(); + } + + public void testPerformErrorTimeoutWaitInThreadPool() { + expectAssertionFailedErrorAfterDelay(SHORT_WAIT, inThreadPool(performNotifyErrorRunnable())); + assertBothCalled(); + } + + public void testTimeout() { + try { + waitHelper.performWait(SHORT_WAIT, performNothingRunnable()); + } catch (TimeoutError e) { + setPerformNotifyErrorCalled(); + assertEquals(SHORT_WAIT, e.waitTimeInMillis); + } + assertErrorCalled(); + } + + /** + * This will pass. The sequence in the main thread is: + * - A short delay. + * - performNotify is called. + * - performWait is called and immediately finds that performNotify was called before. + */ + public void testDelay() { + try { + waitHelper.performWait(1, performNotifyAfterDelayRunnable(SHORT_WAIT)); + } catch (AssertionFailedError e) { + setPerformNotifyErrorCalled(); + assertTrue(e.getMessage(), e.getMessage().contains("TIMEOUT")); + } + assertCalled(); + } + + public Runnable performNotifyMultipleTimesRunnable() { + return new Runnable() { + public void run() { + waitHelper.performNotify(); + setPerformNotifyCalled(); + waitHelper.performNotify(); + } + }; + } + + public void testPerformNotifyMultipleTimesFails() { + try { + waitHelper.performWait(NO_WAIT, performNotifyMultipleTimesRunnable()); // Not run on thread, so runnable executes before performWait looks for notifications. + } catch (WaitHelper.MultipleNotificationsError e) { + setPerformNotifyErrorCalled(); + } + assertBothCalled(); + assertFalse(waitHelper.isIdle()); // First perform notify should be hanging around. + waitHelper.performWait(NO_WAIT, performNothingRunnable()); + } + + public void testNestedWaitsAndNotifies() { + waitHelper.performWait(new Runnable() { + @Override + public void run() { + waitHelper.performWait(new Runnable() { + public void run() { + setPerformNotifyCalled(); + waitHelper.performNotify(); + } + }); + setPerformNotifyErrorCalled(); + waitHelper.performNotify(); + } + }); + assertBothCalled(); + } + + public void testAssertIsReported() { + try { + waitHelper.performWait(1, new Runnable() { + @Override + public void run() { + assertTrue("unique identifier", false); + } + }); + } catch (AssertionFailedError e) { + setPerformNotifyErrorCalled(); + assertTrue(e.getMessage(), e.getMessage().contains("unique identifier")); + } + assertErrorCalled(); + } + + /** + * The inner wait will timeout, but the outer wait will succeed. The sequence in the helper thread is: + * - A short delay. + * - performNotify is called. + * + * The sequence in the main thread is: + * - performWait is called and times out because the helper thread does not call + * performNotify quickly enough. + */ + public void testDelayInThread() throws InterruptedException { + waitHelper.performWait(new Runnable() { + @Override + public void run() { + try { + waitHelper.performWait(NO_WAIT, inThread(new Runnable() { + public void run() { + try { + Thread.sleep(SHORT_WAIT); + } catch (InterruptedException e) { + fail("Interrupted."); + } + + setPerformNotifyCalled(); + waitHelper.performNotify(); + } + })); + } catch (WaitHelper.TimeoutError e) { + setPerformNotifyErrorCalled(); + assertEquals(NO_WAIT, e.waitTimeInMillis); + } + } + }); + assertBothCalled(); + } + + /** + * The inner wait will timeout, but the outer wait will succeed. The sequence in the helper thread is: + * - A short delay. + * - performNotify is called. + * + * The sequence in the main thread is: + * - performWait is called and times out because the helper thread does not call + * performNotify quickly enough. + */ + public void testDelayInThreadPool() throws InterruptedException { + waitHelper.performWait(new Runnable() { + @Override + public void run() { + try { + waitHelper.performWait(NO_WAIT, inThreadPool(new Runnable() { + public void run() { + try { + Thread.sleep(SHORT_WAIT); + } catch (InterruptedException e) { + fail("Interrupted."); + } + + setPerformNotifyCalled(); + waitHelper.performNotify(); + } + })); + } catch (WaitHelper.TimeoutError e) { + setPerformNotifyErrorCalled(); + assertEquals(NO_WAIT, e.waitTimeInMillis); + } + } + }); + assertBothCalled(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/AndroidBrowserRepositoryTestCase.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/AndroidBrowserRepositoryTestCase.java new file mode 100644 index 000000000..da980735b --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/AndroidBrowserRepositoryTestCase.java @@ -0,0 +1,818 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import java.util.concurrent.ExecutorService; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.background.sync.helpers.DefaultBeginDelegate; +import org.mozilla.gecko.background.sync.helpers.DefaultCleanDelegate; +import org.mozilla.gecko.background.sync.helpers.DefaultFetchDelegate; +import org.mozilla.gecko.background.sync.helpers.DefaultFinishDelegate; +import org.mozilla.gecko.background.sync.helpers.DefaultSessionCreationDelegate; +import org.mozilla.gecko.background.sync.helpers.DefaultStoreDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectBeginDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectBeginFailDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectFetchDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectFetchSinceDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectFinishDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectFinishFailDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectGuidsSinceDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectInvalidRequestFetchDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectManyStoredDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectStoreCompletedDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectStoredDelegate; +import org.mozilla.gecko.background.sync.helpers.SessionTestHelper; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; +import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserRepositoryDataAccessor; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionGuidsSinceDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import android.content.ContentValues; +import android.content.Context; + +public abstract class AndroidBrowserRepositoryTestCase extends AndroidSyncTestCase { + protected static String LOG_TAG = "BrowserRepositoryTest"; + + protected static void wipe(AndroidBrowserRepositoryDataAccessor helper) { + Logger.debug(LOG_TAG, "Wiping."); + try { + helper.wipe(); + } catch (NullPointerException e) { + // This will be handled in begin, here we can just ignore + // the error if it actually occurs since this is just test + // code. We will throw a ProfileDatabaseException. This + // error shouldn't occur in the future, but results from + // trying to access content providers before Fennec has + // been run at least once. + Logger.error(LOG_TAG, "ProfileDatabaseException seen in wipe. Begin should fail"); + fail("NullPointerException in wipe."); + } + } + + @Override + public void setUp() { + AndroidBrowserRepositoryDataAccessor helper = getDataAccessor(); + wipe(helper); + assertTrue(WaitHelper.getTestWaiter().isIdle()); + closeDataAccessor(helper); + } + + public void tearDown() { + assertTrue(WaitHelper.getTestWaiter().isIdle()); + } + + protected RepositorySession createSession() { + return SessionTestHelper.createSession( + getApplicationContext(), + getRepository()); + } + + protected RepositorySession createAndBeginSession() { + return SessionTestHelper.createAndBeginSession( + getApplicationContext(), + getRepository()); + } + + protected static void dispose(RepositorySession session) { + if (session != null) { + session.abort(); + } + } + + /** + * Hook to return an ExpectFetchDelegate, possibly with special GUIDs ignored. + */ + public ExpectFetchDelegate preparedExpectFetchDelegate(Record[] expected) { + return new ExpectFetchDelegate(expected); + } + + /** + * Hook to return an ExpectGuidsSinceDelegate, possibly with special GUIDs ignored. + */ + public ExpectGuidsSinceDelegate preparedExpectGuidsSinceDelegate(String[] expected) { + return new ExpectGuidsSinceDelegate(expected); + } + + /** + * Hook to return an ExpectGuidsSinceDelegate expecting only special GUIDs (if there are any). + */ + public ExpectGuidsSinceDelegate preparedExpectOnlySpecialGuidsSinceDelegate() { + return new ExpectGuidsSinceDelegate(new String[] {}); + } + + /** + * Hook to return an ExpectFetchSinceDelegate, possibly with special GUIDs ignored. + */ + public ExpectFetchSinceDelegate preparedExpectFetchSinceDelegate(long timestamp, String[] expected) { + return new ExpectFetchSinceDelegate(timestamp, expected); + } + + public static Runnable storeRunnable(final RepositorySession session, final Record record, final DefaultStoreDelegate delegate) { + return new Runnable() { + @Override + public void run() { + session.setStoreDelegate(delegate); + try { + session.store(record); + session.storeDone(); + } catch (NoStoreDelegateException e) { + fail("NoStoreDelegateException should not occur."); + } + } + }; + } + + public static Runnable storeRunnable(final RepositorySession session, final Record record) { + return storeRunnable(session, record, new ExpectStoredDelegate(record.guid)); + } + + public static Runnable storeManyRunnable(final RepositorySession session, final Record[] records, final DefaultStoreDelegate delegate) { + return new Runnable() { + @Override + public void run() { + session.setStoreDelegate(delegate); + try { + for (Record record : records) { + session.store(record); + } + session.storeDone(); + } catch (NoStoreDelegateException e) { + fail("NoStoreDelegateException should not occur."); + } + } + }; + } + + public static Runnable storeManyRunnable(final RepositorySession session, final Record[] records) { + return storeManyRunnable(session, records, new ExpectManyStoredDelegate(records)); + } + + /** + * Store a record and don't expect a store callback until we're done. + * + * @param session + * @param record + * @return Runnable. + */ + public static Runnable quietStoreRunnable(final RepositorySession session, final Record record) { + return storeRunnable(session, record, new ExpectStoreCompletedDelegate()); + } + + public static Runnable beginRunnable(final RepositorySession session, final DefaultBeginDelegate delegate) { + return new Runnable() { + @Override + public void run() { + try { + session.begin(delegate); + } catch (InvalidSessionTransitionException e) { + performNotify(e); + } + } + }; + } + + public static Runnable finishRunnable(final RepositorySession session, final DefaultFinishDelegate delegate) { + return new Runnable() { + @Override + public void run() { + try { + session.finish(delegate); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + }; + } + + public static Runnable fetchAllRunnable(final RepositorySession session, final ExpectFetchDelegate delegate) { + return new Runnable() { + @Override + public void run() { + session.fetchAll(delegate); + } + }; + } + + public Runnable fetchAllRunnable(final RepositorySession session, final Record[] expectedRecords) { + return fetchAllRunnable(session, preparedExpectFetchDelegate(expectedRecords)); + } + + public Runnable guidsSinceRunnable(final RepositorySession session, final long timestamp, final String[] expected) { + return new Runnable() { + @Override + public void run() { + session.guidsSince(timestamp, preparedExpectGuidsSinceDelegate(expected)); + } + }; + } + + public Runnable fetchSinceRunnable(final RepositorySession session, final long timestamp, final String[] expected) { + return new Runnable() { + @Override + public void run() { + session.fetchSince(timestamp, preparedExpectFetchSinceDelegate(timestamp, expected)); + } + }; + } + + public static Runnable fetchRunnable(final RepositorySession session, final String[] guids, final DefaultFetchDelegate delegate) { + return new Runnable() { + @Override + public void run() { + try { + session.fetch(guids, delegate); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + }; + } + public Runnable fetchRunnable(final RepositorySession session, final String[] guids, final Record[] expected) { + return fetchRunnable(session, guids, preparedExpectFetchDelegate(expected)); + } + + public static Runnable cleanRunnable(final Repository repository, final boolean success, final Context context, final DefaultCleanDelegate delegate) { + return new Runnable() { + @Override + public void run() { + repository.clean(success, delegate, context); + } + }; + } + + protected abstract Repository getRepository(); + protected abstract AndroidBrowserRepositoryDataAccessor getDataAccessor(); + + protected static void doStore(RepositorySession session, Record[] records) { + performWait(storeManyRunnable(session, records)); + } + + // Tests to implement + public abstract void testFetchAll(); + public abstract void testGuidsSinceReturnMultipleRecords(); + public abstract void testGuidsSinceReturnNoRecords(); + public abstract void testFetchSinceOneRecord(); + public abstract void testFetchSinceReturnNoRecords(); + public abstract void testFetchOneRecordByGuid(); + public abstract void testFetchMultipleRecordsByGuids(); + public abstract void testFetchNoRecordByGuid(); + public abstract void testWipe(); + public abstract void testStore(); + public abstract void testRemoteNewerTimeStamp(); + public abstract void testLocalNewerTimeStamp(); + public abstract void testDeleteRemoteNewer(); + public abstract void testDeleteLocalNewer(); + public abstract void testDeleteRemoteLocalNonexistent(); + public abstract void testStoreIdenticalExceptGuid(); + public abstract void testCleanMultipleRecords(); + + + /* + * Test abstractions + */ + protected void basicStoreTest(Record record) { + final RepositorySession session = createAndBeginSession(); + performWait(storeRunnable(session, record)); + } + + protected void basicFetchAllTest(Record[] expected) { + Logger.debug("rnewman", "Starting testFetchAll."); + RepositorySession session = createAndBeginSession(); + Logger.debug("rnewman", "Prepared."); + + AndroidBrowserRepositoryDataAccessor helper = getDataAccessor(); + helper.dumpDB(); + performWait(storeManyRunnable(session, expected)); + + helper.dumpDB(); + performWait(fetchAllRunnable(session, expected)); + + closeDataAccessor(helper); + dispose(session); + } + + /* + * Tests for clean + */ + // Input: 4 records; 2 which are to be cleaned, 2 which should remain after the clean + protected void cleanMultipleRecords(Record delete0, Record delete1, Record keep0, Record keep1, Record keep2) { + RepositorySession session = createAndBeginSession(); + doStore(session, new Record[] { + delete0, delete1, keep0, keep1, keep2 + }); + + // Force two records to appear deleted. + AndroidBrowserRepositoryDataAccessor db = getDataAccessor(); + ContentValues cv = new ContentValues(); + cv.put(BrowserContract.SyncColumns.IS_DELETED, 1); + db.updateByGuid(delete0.guid, cv); + db.updateByGuid(delete1.guid, cv); + + final DefaultCleanDelegate delegate = new DefaultCleanDelegate() { + public void onCleaned(Repository repo) { + performNotify(); + } + }; + + final Runnable cleanRunnable = cleanRunnable( + getRepository(), + true, + getApplicationContext(), + delegate); + + performWait(cleanRunnable); + performWait(fetchAllRunnable(session, preparedExpectFetchDelegate(new Record[] { keep0, keep1, keep2}))); + closeDataAccessor(db); + dispose(session); + } + + /* + * Tests for guidsSince + */ + protected void guidsSinceReturnMultipleRecords(Record record0, Record record1) { + RepositorySession session = createAndBeginSession(); + long timestamp = System.currentTimeMillis(); + + String[] expected = new String[2]; + expected[0] = record0.guid; + expected[1] = record1.guid; + + Logger.debug(getName(), "Storing two records..."); + performWait(storeManyRunnable(session, new Record[] { record0, record1 })); + Logger.debug(getName(), "Getting guids since " + timestamp + "; expecting " + expected.length); + performWait(guidsSinceRunnable(session, timestamp, expected)); + dispose(session); + } + + protected void guidsSinceReturnNoRecords(Record record0) { + RepositorySession session = createAndBeginSession(); + + // Store 1 record in the past. + performWait(storeRunnable(session, record0)); + + String[] expected = {}; + performWait(guidsSinceRunnable(session, System.currentTimeMillis() + 1000, expected)); + dispose(session); + } + + /* + * Tests for fetchSince + */ + protected void fetchSinceOneRecord(Record record0, Record record1) { + RepositorySession session = createAndBeginSession(); + + performWait(storeRunnable(session, record0)); + long timestamp = System.currentTimeMillis(); + Logger.debug("fetchSinceOneRecord", "Entering synchronized section. Timestamp " + timestamp); + synchronized(this) { + try { + wait(1000); + } catch (InterruptedException e) { + Logger.warn("fetchSinceOneRecord", "Interrupted.", e); + } + } + Logger.debug("fetchSinceOneRecord", "Storing."); + performWait(storeRunnable(session, record1)); + + Logger.debug("fetchSinceOneRecord", "Fetching record 1."); + String[] expectedOne = new String[] { record1.guid }; + performWait(fetchSinceRunnable(session, timestamp + 10, expectedOne)); + + Logger.debug("fetchSinceOneRecord", "Fetching both, relying on inclusiveness."); + String[] expectedBoth = new String[] { record0.guid, record1.guid }; + performWait(fetchSinceRunnable(session, timestamp - 3000, expectedBoth)); + + Logger.debug("fetchSinceOneRecord", "Done."); + dispose(session); + } + + protected void fetchSinceReturnNoRecords(Record record) { + RepositorySession session = createAndBeginSession(); + + performWait(storeRunnable(session, record)); + + long timestamp = System.currentTimeMillis(); + + performWait(fetchSinceRunnable(session, timestamp + 2000, new String[] {})); + dispose(session); + } + + protected void fetchOneRecordByGuid(Record record0, Record record1) { + RepositorySession session = createAndBeginSession(); + + Record[] store = new Record[] { record0, record1 }; + performWait(storeManyRunnable(session, store)); + + String[] guids = new String[] { record0.guid }; + Record[] expected = new Record[] { record0 }; + performWait(fetchRunnable(session, guids, expected)); + dispose(session); + } + + protected void fetchMultipleRecordsByGuids(Record record0, + Record record1, Record record2) { + RepositorySession session = createAndBeginSession(); + + Record[] store = new Record[] { record0, record1, record2 }; + performWait(storeManyRunnable(session, store)); + + String[] guids = new String[] { record0.guid, record2.guid }; + Record[] expected = new Record[] { record0, record2 }; + performWait(fetchRunnable(session, guids, expected)); + dispose(session); + } + + protected void fetchNoRecordByGuid(Record record) { + RepositorySession session = createAndBeginSession(); + + performWait(storeRunnable(session, record)); + performWait(fetchRunnable(session, + new String[] { Utils.generateGuid() }, + new Record[] {})); + dispose(session); + } + + /* + * Test wipe + */ + protected void doWipe(final Record record0, final Record record1) { + final RepositorySession session = createAndBeginSession(); + final Runnable run = new Runnable() { + @Override + public void run() { + session.wipe(new RepositorySessionWipeDelegate() { + public void onWipeSucceeded() { + performNotify(); + } + public void onWipeFailed(Exception ex) { + fail("wipe should have succeeded"); + performNotify(); + } + @Override + public RepositorySessionWipeDelegate deferredWipeDelegate(final ExecutorService executor) { + final RepositorySessionWipeDelegate self = this; + return new RepositorySessionWipeDelegate() { + + @Override + public void onWipeSucceeded() { + new Thread(new Runnable() { + @Override + public void run() { + self.onWipeSucceeded(); + }}).start(); + } + + @Override + public void onWipeFailed(final Exception ex) { + new Thread(new Runnable() { + @Override + public void run() { + self.onWipeFailed(ex); + }}).start(); + } + + @Override + public RepositorySessionWipeDelegate deferredWipeDelegate(ExecutorService newExecutor) { + if (newExecutor == executor) { + return this; + } + throw new IllegalArgumentException("Can't re-defer this delegate."); + } + }; + } + }); + } + }; + + // Store 2 records. + Record[] records = new Record[] { record0, record1 }; + performWait(storeManyRunnable(session, records)); + performWait(fetchAllRunnable(session, records)); + + // Wipe. + performWait(run); + dispose(session); + } + + /* + * TODO adding or subtracting from lastModified timestamps does NOTHING + * since it gets overwritten when we store stuff. See other tests + * for ways to do this properly. + */ + + /* + * Record being stored has newer timestamp than existing local record, local + * record has not been modified since last sync. + */ + protected void remoteNewerTimeStamp(Record local, Record remote) { + final RepositorySession session = createAndBeginSession(); + + // Record existing and hasn't changed since before lastSync. + // Automatically will be assigned lastModified = current time. + performWait(storeRunnable(session, local)); + + remote.guid = local.guid; + + // Get the timestamp and make remote newer than it + ExpectFetchDelegate timestampDelegate = preparedExpectFetchDelegate(new Record[] { local }); + performWait(fetchRunnable(session, new String[] { remote.guid }, timestampDelegate)); + remote.lastModified = timestampDelegate.records.get(0).lastModified + 1000; + performWait(storeRunnable(session, remote)); + + Record[] expected = new Record[] { remote }; + ExpectFetchDelegate delegate = preparedExpectFetchDelegate(expected); + performWait(fetchAllRunnable(session, delegate)); + dispose(session); + } + + /* + * Local record has a newer timestamp than the record being stored. For now, + * we just take newer (local) record) + */ + protected void localNewerTimeStamp(Record local, Record remote) { + final RepositorySession session = createAndBeginSession(); + + performWait(storeRunnable(session, local)); + + remote.guid = local.guid; + + // Get the timestamp and make remote older than it + ExpectFetchDelegate timestampDelegate = preparedExpectFetchDelegate(new Record[] { local }); + performWait(fetchRunnable(session, new String[] { remote.guid }, timestampDelegate)); + remote.lastModified = timestampDelegate.records.get(0).lastModified - 1000; + performWait(storeRunnable(session, remote)); + + // Do a fetch and make sure that we get back the local record. + Record[] expected = new Record[] { local }; + performWait(fetchAllRunnable(session, preparedExpectFetchDelegate(expected))); + dispose(session); + } + + /* + * Insert a record that is marked as deleted, remote has newer timestamp + */ + protected void deleteRemoteNewer(Record local, Record remote) { + final RepositorySession session = createAndBeginSession(); + + // Record existing and hasn't changed since before lastSync. + // Automatically will be assigned lastModified = current time. + performWait(storeRunnable(session, local)); + + // Pass the same record to store, but mark it deleted and modified + // more recently + ExpectFetchDelegate timestampDelegate = preparedExpectFetchDelegate(new Record[] { local }); + performWait(fetchRunnable(session, new String[] { local.guid }, timestampDelegate)); + remote.lastModified = timestampDelegate.records.get(0).lastModified + 1000; + remote.deleted = true; + remote.guid = local.guid; + performWait(storeRunnable(session, remote)); + + performWait(fetchAllRunnable(session, preparedExpectFetchDelegate(new Record[]{}))); + dispose(session); + } + + // Store two records that are identical (this has different meanings based on the + // type of record) other than their guids. The record existing locally already + // should have its guid replaced (the assumption is that the record existed locally + // and then sync was enabled and this record existed on another sync'd device). + public void storeIdenticalExceptGuid(Record record0) { + Logger.debug("storeIdenticalExceptGuid", "Started."); + final RepositorySession session = createAndBeginSession(); + Logger.debug("storeIdenticalExceptGuid", "Session is " + session); + performWait(storeRunnable(session, record0)); + Logger.debug("storeIdenticalExceptGuid", "Stored record0."); + DefaultFetchDelegate timestampDelegate = getTimestampDelegate(record0.guid); + + performWait(fetchRunnable(session, new String[] { record0.guid }, timestampDelegate)); + Logger.debug("storeIdenticalExceptGuid", "fetchRunnable done."); + record0.lastModified = timestampDelegate.records.get(0).lastModified + 3000; + record0.guid = Utils.generateGuid(); + Logger.debug("storeIdenticalExceptGuid", "Storing modified..."); + performWait(storeRunnable(session, record0)); + Logger.debug("storeIdenticalExceptGuid", "Stored modified."); + + Record[] expected = new Record[] { record0 }; + performWait(fetchAllRunnable(session, preparedExpectFetchDelegate(expected))); + Logger.debug("storeIdenticalExceptGuid", "Fetched all. Returning."); + dispose(session); + } + + // Special delegate so that we don't verify parenting is correct since + // at some points it won't be since parent folder hasn't been stored. + private DefaultFetchDelegate getTimestampDelegate(final String guid) { + return new DefaultFetchDelegate() { + @Override + public void onFetchCompleted(final long fetchEnd) { + assertEquals(guid, this.records.get(0).guid); + performNotify(); + } + }; + } + + /* + * Insert a record that is marked as deleted, local has newer timestamp + * and was not marked deleted (so keep it) + */ + protected void deleteLocalNewer(Record local, Record remote) { + Logger.debug("deleteLocalNewer", "Begin."); + final RepositorySession session = createAndBeginSession(); + + Logger.debug("deleteLocalNewer", "Storing local..."); + performWait(storeRunnable(session, local)); + + // Create an older version of a record with the same GUID. + remote.guid = local.guid; + + Logger.debug("deleteLocalNewer", "Fetching..."); + + // Get the timestamp and make remote older than it + Record[] expected = new Record[] { local }; + ExpectFetchDelegate timestampDelegate = preparedExpectFetchDelegate(expected); + performWait(fetchRunnable(session, new String[] { remote.guid }, timestampDelegate)); + + Logger.debug("deleteLocalNewer", "Fetched."); + remote.lastModified = timestampDelegate.records.get(0).lastModified - 1000; + + Logger.debug("deleteLocalNewer", "Last modified is " + remote.lastModified); + remote.deleted = true; + Logger.debug("deleteLocalNewer", "Storing deleted..."); + performWait(quietStoreRunnable(session, remote)); // This appears to do a lot of work...?! + + // Do a fetch and make sure that we get back the first (local) record. + performWait(fetchAllRunnable(session, preparedExpectFetchDelegate(expected))); + Logger.debug("deleteLocalNewer", "Fetched and done!"); + dispose(session); + } + + /* + * Insert a record that is marked as deleted, record never existed locally + */ + protected void deleteRemoteLocalNonexistent(Record remote) { + final RepositorySession session = createAndBeginSession(); + + long timestamp = 1000000000; + + // Pass a record marked deleted to store, doesn't exist locally + remote.lastModified = timestamp; + remote.deleted = true; + performWait(quietStoreRunnable(session, remote)); + + ExpectFetchDelegate delegate = preparedExpectFetchDelegate(new Record[]{}); + performWait(fetchAllRunnable(session, delegate)); + dispose(session); + } + + /* + * Tests that don't require specific records based on type of repository. + * These tests don't need to be overriden in subclasses, they will just work. + */ + public void testCreateSessionNullContext() { + Logger.debug(LOG_TAG, "In testCreateSessionNullContext."); + Repository repo = getRepository(); + try { + repo.createSession(new DefaultSessionCreationDelegate(), null); + fail("Should throw."); + } catch (Exception ex) { + assertNotNull(ex); + } + } + + public void testStoreNullRecord() { + final RepositorySession session = createAndBeginSession(); + try { + session.setStoreDelegate(new DefaultStoreDelegate()); + session.store(null); + fail("Should throw."); + } catch (Exception ex) { + assertNotNull(ex); + } + dispose(session); + } + + public void testFetchNoGuids() { + final RepositorySession session = createAndBeginSession(); + performWait(fetchRunnable(session, new String[] {}, new ExpectInvalidRequestFetchDelegate())); + dispose(session); + } + + public void testFetchNullGuids() { + final RepositorySession session = createAndBeginSession(); + performWait(fetchRunnable(session, null, new ExpectInvalidRequestFetchDelegate())); + dispose(session); + } + + public void testBeginOnNewSession() { + final RepositorySession session = createSession(); + performWait(beginRunnable(session, new ExpectBeginDelegate())); + dispose(session); + } + + public void testBeginOnRunningSession() { + final RepositorySession session = createAndBeginSession(); + try { + session.begin(new ExpectBeginFailDelegate()); + } catch (InvalidSessionTransitionException e) { + dispose(session); + return; + } + fail("Should have caught InvalidSessionTransitionException."); + } + + public void testBeginOnFinishedSession() throws InactiveSessionException { + final RepositorySession session = createAndBeginSession(); + performWait(finishRunnable(session, new ExpectFinishDelegate())); + try { + session.begin(new ExpectBeginFailDelegate()); + } catch (InvalidSessionTransitionException e) { + Logger.debug(getName(), "Yay! Got an exception.", e); + dispose(session); + return; + } catch (Exception e) { + Logger.debug(getName(), "Yay! Got an exception.", e); + dispose(session); + return; + } + fail("Should have caught InvalidSessionTransitionException."); + } + + public void testFinishOnFinishedSession() throws InactiveSessionException { + final RepositorySession session = createAndBeginSession(); + performWait(finishRunnable(session, new ExpectFinishDelegate())); + try { + session.finish(new ExpectFinishFailDelegate()); + } catch (InactiveSessionException e) { + dispose(session); + return; + } + fail("Should have caught InactiveSessionException."); + } + + public void testFetchOnInactiveSession() throws InactiveSessionException { + final RepositorySession session = createSession(); + try { + session.fetch(new String[] { Utils.generateGuid() }, new DefaultFetchDelegate()); + } catch (InactiveSessionException e) { + // Yay. + dispose(session); + return; + }; + fail("Should have caught InactiveSessionException."); + } + + public void testFetchOnFinishedSession() { + final RepositorySession session = createAndBeginSession(); + Logger.debug(getName(), "Finishing..."); + performWait(finishRunnable(session, new ExpectFinishDelegate())); + try { + session.fetch(new String[] { Utils.generateGuid() }, new DefaultFetchDelegate()); + } catch (InactiveSessionException e) { + // Yay. + dispose(session); + return; + }; + fail("Should have caught InactiveSessionException."); + } + + public void testGuidsSinceOnUnstartedSession() { + final RepositorySession session = createSession(); + Runnable run = new Runnable() { + @Override + public void run() { + session.guidsSince(System.currentTimeMillis(), + new RepositorySessionGuidsSinceDelegate() { + public void onGuidsSinceSucceeded(String[] guids) { + fail("Session inactive, should fail"); + performNotify(); + } + + public void onGuidsSinceFailed(Exception ex) { + verifyInactiveException(ex); + performNotify(); + } + }); + } + }; + performWait(run); + dispose(session); + } + + private static void verifyInactiveException(Exception ex) { + if (!(ex instanceof InactiveSessionException)) { + fail("Wrong exception type"); + } + } + + protected void closeDataAccessor(AndroidBrowserRepositoryDataAccessor dataAccessor) { + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestAndroidBrowserBookmarksRepository.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestAndroidBrowserBookmarksRepository.java new file mode 100644 index 000000000..71563a46c --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestAndroidBrowserBookmarksRepository.java @@ -0,0 +1,636 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import java.util.ArrayList; + +import org.json.simple.JSONArray; +import org.mozilla.gecko.background.sync.helpers.BookmarkHelpers; +import org.mozilla.gecko.background.sync.helpers.ExpectFetchDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectFetchSinceDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectFinishDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectGuidsSinceDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectInvalidTypeStoreDelegate; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.NullCursorException; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksDataAccessor; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksRepository; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksRepositorySession; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserRepository; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserRepositoryDataAccessor; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; +import org.mozilla.gecko.sync.repositories.android.RepoUtils; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; + +public class TestAndroidBrowserBookmarksRepository extends AndroidBrowserRepositoryTestCase { + + @Override + protected AndroidBrowserRepository getRepository() { + + /** + * Override this chain in order to avoid our test code having to create two + * sessions all the time. + */ + return new AndroidBrowserBookmarksRepository() { + @Override + protected void sessionCreator(RepositorySessionCreationDelegate delegate, Context context) { + AndroidBrowserBookmarksRepositorySession session; + session = new AndroidBrowserBookmarksRepositorySession(this, context) { + @Override + protected synchronized void trackGUID(String guid) { + System.out.println("Ignoring trackGUID call: this is a test!"); + } + }; + delegate.deferredCreationDelegate().onSessionCreated(session); + } + }; + } + + @Override + protected AndroidBrowserRepositoryDataAccessor getDataAccessor() { + return new AndroidBrowserBookmarksDataAccessor(getApplicationContext()); + } + + /** + * Hook to return an ExpectFetchDelegate, possibly with special GUIDs ignored. + */ + @Override + public ExpectFetchDelegate preparedExpectFetchDelegate(Record[] expected) { + ExpectFetchDelegate delegate = new ExpectFetchDelegate(expected); + delegate.ignore.addAll(AndroidBrowserBookmarksRepositorySession.SPECIAL_GUIDS_MAP.keySet()); + return delegate; + } + + /** + * Hook to return an ExpectGuidsSinceDelegate expecting only special GUIDs (if there are any). + */ + public ExpectGuidsSinceDelegate preparedExpectOnlySpecialGuidsSinceDelegate() { + ExpectGuidsSinceDelegate delegate = new ExpectGuidsSinceDelegate(AndroidBrowserBookmarksRepositorySession.SPECIAL_GUIDS_MAP.keySet().toArray(new String[] {})); + return delegate; + } + + /** + * Hook to return an ExpectGuidsSinceDelegate, possibly with special GUIDs ignored. + */ + @Override + public ExpectGuidsSinceDelegate preparedExpectGuidsSinceDelegate(String[] expected) { + ExpectGuidsSinceDelegate delegate = new ExpectGuidsSinceDelegate(expected); + delegate.ignore.addAll(AndroidBrowserBookmarksRepositorySession.SPECIAL_GUIDS_MAP.keySet()); + return delegate; + } + + /** + * Hook to return an ExpectFetchSinceDelegate, possibly with special GUIDs ignored. + */ + public ExpectFetchSinceDelegate preparedExpectFetchSinceDelegate(long timestamp, String[] expected) { + ExpectFetchSinceDelegate delegate = new ExpectFetchSinceDelegate(timestamp, expected); + delegate.ignore.addAll(AndroidBrowserBookmarksRepositorySession.SPECIAL_GUIDS_MAP.keySet()); + return delegate; + } + + // NOTE NOTE NOTE + // Must store folder before records if we we are checking that the + // records returned are the same as those sent in. If the folder isn't stored + // first, the returned records won't be identical to those stored because we + // aren't able to find the parent name/guid when we do a fetch. If you don't want + // to store a folder first, store your record in "mobile" or one of the folders + // that always exists. + + public void testFetchOneWithChildren() { + BookmarkRecord folder = BookmarkHelpers.createFolder1(); + BookmarkRecord bookmark1 = BookmarkHelpers.createBookmark1(); + BookmarkRecord bookmark2 = BookmarkHelpers.createBookmark2(); + + RepositorySession session = createAndBeginSession(); + + Record[] records = new Record[] { folder, bookmark1, bookmark2 }; + performWait(storeManyRunnable(session, records)); + + AndroidBrowserRepositoryDataAccessor helper = getDataAccessor(); + helper.dumpDB(); + closeDataAccessor(helper); + + String[] guids = new String[] { folder.guid }; + Record[] expected = new Record[] { folder }; + performWait(fetchRunnable(session, guids, expected)); + dispose(session); + } + + @Override + public void testFetchAll() { + Record[] expected = new Record[3]; + expected[0] = BookmarkHelpers.createFolder1(); + expected[1] = BookmarkHelpers.createBookmark1(); + expected[2] = BookmarkHelpers.createBookmark2(); + basicFetchAllTest(expected); + } + + @Override + public void testGuidsSinceReturnMultipleRecords() { + BookmarkRecord record0 = BookmarkHelpers.createBookmark1(); + BookmarkRecord record1 = BookmarkHelpers.createBookmark2(); + guidsSinceReturnMultipleRecords(record0, record1); + } + + @Override + public void testGuidsSinceReturnNoRecords() { + guidsSinceReturnNoRecords(BookmarkHelpers.createBookmarkInMobileFolder1()); + } + + @Override + public void testFetchSinceOneRecord() { + fetchSinceOneRecord(BookmarkHelpers.createBookmarkInMobileFolder1(), + BookmarkHelpers.createBookmarkInMobileFolder2()); + } + + @Override + public void testFetchSinceReturnNoRecords() { + fetchSinceReturnNoRecords(BookmarkHelpers.createBookmark1()); + } + + @Override + public void testFetchOneRecordByGuid() { + fetchOneRecordByGuid(BookmarkHelpers.createBookmarkInMobileFolder1(), + BookmarkHelpers.createBookmarkInMobileFolder2()); + } + + @Override + public void testFetchMultipleRecordsByGuids() { + BookmarkRecord record0 = BookmarkHelpers.createFolder1(); + BookmarkRecord record1 = BookmarkHelpers.createBookmark1(); + BookmarkRecord record2 = BookmarkHelpers.createBookmark2(); + fetchMultipleRecordsByGuids(record0, record1, record2); + } + + @Override + public void testFetchNoRecordByGuid() { + fetchNoRecordByGuid(BookmarkHelpers.createBookmark1()); + } + + + @Override + public void testWipe() { + doWipe(BookmarkHelpers.createBookmarkInMobileFolder1(), + BookmarkHelpers.createBookmarkInMobileFolder2()); + } + + @Override + public void testStore() { + basicStoreTest(BookmarkHelpers.createBookmark1()); + } + + + public void testStoreFolder() { + basicStoreTest(BookmarkHelpers.createFolder1()); + } + + /** + * TODO: 2011-12-24, tests disabled because we no longer fail + * a store call if we get an unknown record type. + */ + /* + * Test storing each different type of Bookmark record. + * We expect any records with type other than "bookmark" + * or "folder" to fail. For now we throw these away. + */ + /* + public void testStoreMicrosummary() { + basicStoreFailTest(BookmarkHelpers.createMicrosummary()); + } + + public void testStoreQuery() { + basicStoreFailTest(BookmarkHelpers.createQuery()); + } + + public void testStoreLivemark() { + basicStoreFailTest(BookmarkHelpers.createLivemark()); + } + + public void testStoreSeparator() { + basicStoreFailTest(BookmarkHelpers.createSeparator()); + } + */ + + protected void basicStoreFailTest(Record record) { + final RepositorySession session = createAndBeginSession(); + performWait(storeRunnable(session, record, new ExpectInvalidTypeStoreDelegate())); + dispose(session); + } + + /* + * Re-parenting tests + */ + // Insert two records missing parent, then insert their parent. + // Make sure they end up with the correct parent on fetch. + public void testBasicReparenting() throws InactiveSessionException { + Record[] expected = new Record[] { + BookmarkHelpers.createBookmark1(), + BookmarkHelpers.createBookmark2(), + BookmarkHelpers.createFolder1() + }; + doMultipleFolderReparentingTest(expected); + } + + // Insert 3 folders and 4 bookmarks in different orders + // and make sure they come out parented correctly + public void testMultipleFolderReparenting1() throws InactiveSessionException { + Record[] expected = new Record[] { + BookmarkHelpers.createBookmark1(), + BookmarkHelpers.createBookmark2(), + BookmarkHelpers.createBookmark3(), + BookmarkHelpers.createFolder1(), + BookmarkHelpers.createBookmark4(), + BookmarkHelpers.createFolder3(), + BookmarkHelpers.createFolder2(), + }; + doMultipleFolderReparentingTest(expected); + } + + public void testMultipleFolderReparenting2() throws InactiveSessionException { + Record[] expected = new Record[] { + BookmarkHelpers.createBookmark1(), + BookmarkHelpers.createBookmark2(), + BookmarkHelpers.createBookmark3(), + BookmarkHelpers.createFolder1(), + BookmarkHelpers.createBookmark4(), + BookmarkHelpers.createFolder3(), + BookmarkHelpers.createFolder2(), + }; + doMultipleFolderReparentingTest(expected); + } + + public void testMultipleFolderReparenting3() throws InactiveSessionException { + Record[] expected = new Record[] { + BookmarkHelpers.createBookmark1(), + BookmarkHelpers.createBookmark2(), + BookmarkHelpers.createBookmark3(), + BookmarkHelpers.createFolder1(), + BookmarkHelpers.createBookmark4(), + BookmarkHelpers.createFolder3(), + BookmarkHelpers.createFolder2(), + }; + doMultipleFolderReparentingTest(expected); + } + + private void doMultipleFolderReparentingTest(Record[] expected) throws InactiveSessionException { + final RepositorySession session = createAndBeginSession(); + doStore(session, expected); + ExpectFetchDelegate delegate = preparedExpectFetchDelegate(expected); + performWait(fetchAllRunnable(session, delegate)); + performWait(finishRunnable(session, new ExpectFinishDelegate())); + } + + /* + * Test storing identical records with different guids. + * For bookmarks identical is defined by the following fields + * being the same: title, uri, type, parentName + */ + @Override + public void testStoreIdenticalExceptGuid() { + storeIdenticalExceptGuid(BookmarkHelpers.createBookmarkInMobileFolder1()); + } + + /* + * More complicated situation in which we insert a folder + * followed by a couple of its children. We then insert + * the folder again but with a different guid. Children + * must still get correct parent when they are fetched. + * Store a record after with the new guid as the parent + * and make sure it works as well. + */ + public void testStoreIdenticalFoldersWithChildren() { + final RepositorySession session = createAndBeginSession(); + Record record0 = BookmarkHelpers.createFolder1(); + + // Get timestamp so that the conflicting folder that we store below is newer. + // Children won't come back on this fetch since they haven't been stored, so remove them + // before our delegate throws a failure. + BookmarkRecord rec0 = (BookmarkRecord) record0; + rec0.children = new JSONArray(); + performWait(storeRunnable(session, record0)); + + ExpectFetchDelegate timestampDelegate = preparedExpectFetchDelegate(new Record[] { rec0 }); + performWait(fetchRunnable(session, new String[] { record0.guid }, timestampDelegate)); + + AndroidBrowserRepositoryDataAccessor helper = getDataAccessor(); + helper.dumpDB(); + closeDataAccessor(helper); + + Record record1 = BookmarkHelpers.createBookmark1(); + Record record2 = BookmarkHelpers.createBookmark2(); + Record record3 = BookmarkHelpers.createFolder1(); + BookmarkRecord bmk3 = (BookmarkRecord) record3; + record3.guid = Utils.generateGuid(); + record3.lastModified = timestampDelegate.records.get(0).lastModified + 3000; + assertFalse(record0.guid.equals(record3.guid)); + + // Store an additional record after inserting the duplicate folder + // with new GUID. Make sure it comes back as well. + Record record4 = BookmarkHelpers.createBookmark3(); + BookmarkRecord bmk4 = (BookmarkRecord) record4; + bmk4.parentID = bmk3.guid; + bmk4.parentName = bmk3.parentName; + + doStore(session, new Record[] { + record1, record2, record3, bmk4 + }); + BookmarkRecord bmk1 = (BookmarkRecord) record1; + bmk1.parentID = record3.guid; + BookmarkRecord bmk2 = (BookmarkRecord) record2; + bmk2.parentID = record3.guid; + Record[] expect = new Record[] { + bmk1, bmk2, record3 + }; + fetchAllRunnable(session, preparedExpectFetchDelegate(expect)); + dispose(session); + } + + @Override + public void testRemoteNewerTimeStamp() { + BookmarkRecord local = BookmarkHelpers.createBookmarkInMobileFolder1(); + BookmarkRecord remote = BookmarkHelpers.createBookmarkInMobileFolder2(); + remoteNewerTimeStamp(local, remote); + } + + @Override + public void testLocalNewerTimeStamp() { + BookmarkRecord local = BookmarkHelpers.createBookmarkInMobileFolder1(); + BookmarkRecord remote = BookmarkHelpers.createBookmarkInMobileFolder2(); + localNewerTimeStamp(local, remote); + } + + @Override + public void testDeleteRemoteNewer() { + BookmarkRecord local = BookmarkHelpers.createBookmarkInMobileFolder1(); + BookmarkRecord remote = BookmarkHelpers.createBookmarkInMobileFolder2(); + deleteRemoteNewer(local, remote); + } + + @Override + public void testDeleteLocalNewer() { + BookmarkRecord local = BookmarkHelpers.createBookmarkInMobileFolder1(); + BookmarkRecord remote = BookmarkHelpers.createBookmarkInMobileFolder2(); + deleteLocalNewer(local, remote); + } + + @Override + public void testDeleteRemoteLocalNonexistent() { + BookmarkRecord remote = BookmarkHelpers.createBookmark2(); + deleteRemoteLocalNonexistent(remote); + } + + @Override + public void testCleanMultipleRecords() { + cleanMultipleRecords( + BookmarkHelpers.createBookmarkInMobileFolder1(), + BookmarkHelpers.createBookmarkInMobileFolder2(), + BookmarkHelpers.createBookmark1(), + BookmarkHelpers.createBookmark2(), + BookmarkHelpers.createFolder1()); + } + + public void testBasicPositioning() { + final RepositorySession session = createAndBeginSession(); + Record[] expected = new Record[] { + BookmarkHelpers.createBookmark1(), + BookmarkHelpers.createFolder1(), + BookmarkHelpers.createBookmark2() + }; + System.out.println("TEST: Inserting " + expected[0].guid + ", " + + expected[1].guid + ", " + + expected[2].guid); + doStore(session, expected); + + ExpectFetchDelegate delegate = preparedExpectFetchDelegate(expected); + performWait(fetchAllRunnable(session, delegate)); + + int found = 0; + boolean foundFolder = false; + for (int i = 0; i < delegate.records.size(); i++) { + BookmarkRecord rec = (BookmarkRecord) delegate.records.get(i); + if (rec.guid.equals(expected[0].guid)) { + assertEquals(0, ((BookmarkRecord) delegate.records.get(i)).androidPosition); + found++; + } else if (rec.guid.equals(expected[2].guid)) { + assertEquals(1, ((BookmarkRecord) delegate.records.get(i)).androidPosition); + found++; + } else if (rec.guid.equals(expected[1].guid)) { + foundFolder = true; + } else { + System.out.println("TEST: found " + rec.guid); + } + } + assertTrue(foundFolder); + assertEquals(2, found); + dispose(session); + } + + public void testSqlInjectPurgeDeleteAndUpdateByGuid() { + // Some setup. + RepositorySession session = createAndBeginSession(); + AndroidBrowserRepositoryDataAccessor db = getDataAccessor(); + + ContentValues cv = new ContentValues(); + cv.put(BrowserContract.SyncColumns.IS_DELETED, 1); + + // Create and insert 2 bookmarks, 2nd one is evil (attempts injection). + BookmarkRecord bmk1 = BookmarkHelpers.createBookmark1(); + BookmarkRecord bmk2 = BookmarkHelpers.createBookmark2(); + bmk2.guid = "' or '1'='1"; + + db.insert(bmk1); + db.insert(bmk2); + + // Test 1 - updateByGuid() handles evil bookmarks correctly. + db.updateByGuid(bmk2.guid, cv); + + // Query bookmarks table. + Cursor cur = getAllBookmarks(); + int numBookmarks = cur.getCount(); + + // Ensure only the evil bookmark is marked for deletion. + try { + cur.moveToFirst(); + while (!cur.isAfterLast()) { + String guid = RepoUtils.getStringFromCursor(cur, BrowserContract.SyncColumns.GUID); + boolean deleted = RepoUtils.getLongFromCursor(cur, BrowserContract.SyncColumns.IS_DELETED) == 1; + + if (guid.equals(bmk2.guid)) { + assertTrue(deleted); + } else { + assertFalse(deleted); + } + cur.moveToNext(); + } + } finally { + cur.close(); + } + + // Test 2 - Ensure purgeDelete()'s call to delete() deletes only 1 record. + try { + db.purgeDeleted(); + } catch (NullCursorException e) { + e.printStackTrace(); + } + + cur = getAllBookmarks(); + int numBookmarksAfterDeletion = cur.getCount(); + + // Ensure we have only 1 deleted row. + assertEquals(numBookmarksAfterDeletion, numBookmarks - 1); + + // Ensure only the evil bookmark is deleted. + try { + cur.moveToFirst(); + while (!cur.isAfterLast()) { + String guid = RepoUtils.getStringFromCursor(cur, BrowserContract.SyncColumns.GUID); + boolean deleted = RepoUtils.getLongFromCursor(cur, BrowserContract.SyncColumns.IS_DELETED) == 1; + + if (guid.equals(bmk2.guid)) { + fail("Evil guid was not deleted!"); + } else { + assertFalse(deleted); + } + cur.moveToNext(); + } + } finally { + cur.close(); + } + dispose(session); + } + + protected Cursor getAllBookmarks() { + Context context = getApplicationContext(); + Cursor cur = context.getContentResolver().query(BrowserContractHelpers.BOOKMARKS_CONTENT_URI, + BrowserContractHelpers.BookmarkColumns, null, null, null); + return cur; + } + + public void testSqlInjectFetch() { + // Some setup. + RepositorySession session = createAndBeginSession(); + AndroidBrowserRepositoryDataAccessor db = getDataAccessor(); + + // Create and insert 4 bookmarks, last one is evil (attempts injection). + BookmarkRecord bmk1 = BookmarkHelpers.createBookmark1(); + BookmarkRecord bmk2 = BookmarkHelpers.createBookmark2(); + BookmarkRecord bmk3 = BookmarkHelpers.createBookmark3(); + BookmarkRecord bmk4 = BookmarkHelpers.createBookmark4(); + bmk4.guid = "' or '1'='1"; + + db.insert(bmk1); + db.insert(bmk2); + db.insert(bmk3); + db.insert(bmk4); + + // Perform a fetch. + Cursor cur = null; + try { + cur = db.fetch(new String[] { bmk3.guid, bmk4.guid }); + } catch (NullCursorException e1) { + e1.printStackTrace(); + } + + // Ensure the correct number (2) of records were fetched and with the correct guids. + if (cur == null) { + fail("No records were fetched."); + } + + try { + if (cur.getCount() != 2) { + fail("Wrong number of guids fetched!"); + } + cur.moveToFirst(); + while (!cur.isAfterLast()) { + String guid = RepoUtils.getStringFromCursor(cur, BrowserContract.SyncColumns.GUID); + if (!guid.equals(bmk3.guid) && !guid.equals(bmk4.guid)) { + fail("Wrong guids were fetched!"); + } + cur.moveToNext(); + } + } finally { + cur.close(); + } + dispose(session); + } + + public void testSqlInjectDelete() { + // Some setup. + RepositorySession session = createAndBeginSession(); + AndroidBrowserRepositoryDataAccessor db = getDataAccessor(); + + // Create and insert 2 bookmarks, 2nd one is evil (attempts injection). + BookmarkRecord bmk1 = BookmarkHelpers.createBookmark1(); + BookmarkRecord bmk2 = BookmarkHelpers.createBookmark2(); + bmk2.guid = "' or '1'='1"; + + db.insert(bmk1); + db.insert(bmk2); + + // Note size of table before delete. + Cursor cur = getAllBookmarks(); + int numBookmarks = cur.getCount(); + + db.purgeGuid(bmk2.guid); + + // Note size of table after delete. + cur = getAllBookmarks(); + int numBookmarksAfterDelete = cur.getCount(); + + // Ensure size of table after delete is *only* 1 less. + assertEquals(numBookmarksAfterDelete, numBookmarks - 1); + + try { + cur.moveToFirst(); + while (!cur.isAfterLast()) { + String guid = RepoUtils.getStringFromCursor(cur, BrowserContract.SyncColumns.GUID); + if (guid.equals(bmk2.guid)) { + fail("Guid was not deleted!"); + } + cur.moveToNext(); + } + } finally { + cur.close(); + } + dispose(session); + } + + /** + * Verify that data accessor's bulkInsert actually inserts. + * @throws NullCursorException + */ + public void testBulkInsert() throws NullCursorException { + RepositorySession session = createAndBeginSession(); + AndroidBrowserRepositoryDataAccessor db = getDataAccessor(); + + // Have to set androidID of parent manually. + Cursor cur = db.fetch(new String[] { "mobile" } ); + assertEquals(1, cur.getCount()); + cur.moveToFirst(); + int mobileAndroidID = RepoUtils.getIntFromCursor(cur, BrowserContract.Bookmarks._ID); + + BookmarkRecord bookmark1 = BookmarkHelpers.createBookmarkInMobileFolder1(); + BookmarkRecord bookmark2 = BookmarkHelpers.createBookmarkInMobileFolder2(); + bookmark1.androidParentID = mobileAndroidID; + bookmark2.androidParentID = mobileAndroidID; + ArrayList recordList = new ArrayList(); + recordList.add(bookmark1); + recordList.add(bookmark2); + db.bulkInsert(recordList); + + String[] guids = new String[] { bookmark1.guid, bookmark2.guid }; + Record[] expected = new Record[] { bookmark1, bookmark2 }; + performWait(fetchRunnable(session, guids, expected)); + dispose(session); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryRepository.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryRepository.java new file mode 100644 index 000000000..ffde59575 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestAndroidBrowserHistoryRepository.java @@ -0,0 +1,450 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import java.util.ArrayList; + +import org.json.simple.JSONObject; +import org.mozilla.gecko.background.sync.helpers.ExpectFetchDelegate; +import org.mozilla.gecko.background.sync.helpers.HistoryHelpers; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.NullCursorException; +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryDataAccessor; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryRepository; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserHistoryRepositorySession; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserRepository; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserRepositoryDataAccessor; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; +import org.mozilla.gecko.sync.repositories.android.RepoUtils; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.domain.HistoryRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; + +public class TestAndroidBrowserHistoryRepository extends AndroidBrowserRepositoryTestCase { + + @Override + protected AndroidBrowserRepository getRepository() { + + /** + * Override this chain in order to avoid our test code having to create two + * sessions all the time. + */ + return new AndroidBrowserHistoryRepository() { + @Override + protected void sessionCreator(RepositorySessionCreationDelegate delegate, Context context) { + AndroidBrowserHistoryRepositorySession session; + session = new AndroidBrowserHistoryRepositorySession(this, context) { + @Override + protected synchronized void trackGUID(String guid) { + System.out.println("Ignoring trackGUID call: this is a test!"); + } + }; + delegate.onSessionCreated(session); + } + }; + } + + @Override + protected AndroidBrowserRepositoryDataAccessor getDataAccessor() { + return new AndroidBrowserHistoryDataAccessor(getApplicationContext()); + } + + @Override + public void testFetchAll() { + Record[] expected = new Record[2]; + expected[0] = HistoryHelpers.createHistory3(); + expected[1] = HistoryHelpers.createHistory2(); + basicFetchAllTest(expected); + } + + /* + * Test storing identical records with different guids. + * For bookmarks identical is defined by the following fields + * being the same: title, uri, type, parentName + */ + @Override + public void testStoreIdenticalExceptGuid() { + storeIdenticalExceptGuid(HistoryHelpers.createHistory1()); + } + + @Override + public void testCleanMultipleRecords() { + cleanMultipleRecords( + HistoryHelpers.createHistory1(), + HistoryHelpers.createHistory2(), + HistoryHelpers.createHistory3(), + HistoryHelpers.createHistory4(), + HistoryHelpers.createHistory5() + ); + } + + @Override + public void testGuidsSinceReturnMultipleRecords() { + HistoryRecord record0 = HistoryHelpers.createHistory1(); + HistoryRecord record1 = HistoryHelpers.createHistory2(); + guidsSinceReturnMultipleRecords(record0, record1); + } + + @Override + public void testGuidsSinceReturnNoRecords() { + guidsSinceReturnNoRecords(HistoryHelpers.createHistory3()); + } + + @Override + public void testFetchSinceOneRecord() { + fetchSinceOneRecord(HistoryHelpers.createHistory1(), + HistoryHelpers.createHistory2()); + } + + @Override + public void testFetchSinceReturnNoRecords() { + fetchSinceReturnNoRecords(HistoryHelpers.createHistory3()); + } + + @Override + public void testFetchOneRecordByGuid() { + fetchOneRecordByGuid(HistoryHelpers.createHistory1(), + HistoryHelpers.createHistory2()); + } + + @Override + public void testFetchMultipleRecordsByGuids() { + HistoryRecord record0 = HistoryHelpers.createHistory1(); + HistoryRecord record1 = HistoryHelpers.createHistory2(); + HistoryRecord record2 = HistoryHelpers.createHistory3(); + fetchMultipleRecordsByGuids(record0, record1, record2); + } + + @Override + public void testFetchNoRecordByGuid() { + fetchNoRecordByGuid(HistoryHelpers.createHistory1()); + } + + @Override + public void testWipe() { + doWipe(HistoryHelpers.createHistory2(), HistoryHelpers.createHistory3()); + } + + @Override + public void testStore() { + basicStoreTest(HistoryHelpers.createHistory1()); + } + + @Override + public void testRemoteNewerTimeStamp() { + HistoryRecord local = HistoryHelpers.createHistory1(); + HistoryRecord remote = HistoryHelpers.createHistory2(); + remoteNewerTimeStamp(local, remote); + } + + @Override + public void testLocalNewerTimeStamp() { + HistoryRecord local = HistoryHelpers.createHistory1(); + HistoryRecord remote = HistoryHelpers.createHistory2(); + localNewerTimeStamp(local, remote); + } + + @Override + public void testDeleteRemoteNewer() { + HistoryRecord local = HistoryHelpers.createHistory1(); + HistoryRecord remote = HistoryHelpers.createHistory2(); + deleteRemoteNewer(local, remote); + } + + @Override + public void testDeleteLocalNewer() { + HistoryRecord local = HistoryHelpers.createHistory1(); + HistoryRecord remote = HistoryHelpers.createHistory2(); + deleteLocalNewer(local, remote); + } + + @Override + public void testDeleteRemoteLocalNonexistent() { + deleteRemoteLocalNonexistent(HistoryHelpers.createHistory2()); + } + + /** + * Exists to provide access to record string logic. + */ + protected class HelperHistorySession extends AndroidBrowserHistoryRepositorySession { + public HelperHistorySession(Repository repository, Context context) { + super(repository, context); + } + + public boolean sameRecordString(HistoryRecord r1, HistoryRecord r2) { + return buildRecordString(r1).equals(buildRecordString(r2)); + } + } + + /** + * Verifies that two history records with the same URI but different + * titles will be reconciled locally. + */ + public void testRecordStringCollisionAndEquality() { + final AndroidBrowserHistoryRepository repo = new AndroidBrowserHistoryRepository(); + final HelperHistorySession testSession = new HelperHistorySession(repo, getApplicationContext()); + + final long now = RepositorySession.now(); + + final HistoryRecord record0 = new HistoryRecord(null, "history", now + 1, false); + final HistoryRecord record1 = new HistoryRecord(null, "history", now + 2, false); + final HistoryRecord record2 = new HistoryRecord(null, "history", now + 3, false); + + record0.histURI = "http://example.com/foo"; + record1.histURI = "http://example.com/foo"; + record2.histURI = "http://example.com/bar"; + record0.title = "Foo 0"; + record1.title = "Foo 1"; + record2.title = "Foo 2"; + + // Ensure that two records with the same URI produce the same record string, + // and two records with different URIs do not. + assertTrue(testSession.sameRecordString(record0, record1)); + assertFalse(testSession.sameRecordString(record0, record2)); + + // Two records are congruent if they have the same URI and their + // identifiers match (which is why these all have null GUIDs). + assertTrue(record0.congruentWith(record0)); + assertTrue(record0.congruentWith(record1)); + assertTrue(record1.congruentWith(record0)); + assertFalse(record0.congruentWith(record2)); + assertFalse(record1.congruentWith(record2)); + assertFalse(record2.congruentWith(record1)); + assertFalse(record2.congruentWith(record0)); + + // None of these records are equal, because they have different titles. + // (Except for being equal to themselves, of course.) + assertTrue(record0.equalPayloads(record0)); + assertTrue(record1.equalPayloads(record1)); + assertTrue(record2.equalPayloads(record2)); + assertFalse(record0.equalPayloads(record1)); + assertFalse(record1.equalPayloads(record0)); + assertFalse(record1.equalPayloads(record2)); + } + + /* + * Tests for adding some visits to a history record + * and doing a fetch. + */ + @SuppressWarnings("unchecked") + public void testAddOneVisit() { + final RepositorySession session = createAndBeginSession(); + + HistoryRecord record0 = HistoryHelpers.createHistory3(); + performWait(storeRunnable(session, record0)); + + // Add one visit to the count and put in a new + // last visited date. + ContentValues cv = new ContentValues(); + int visits = record0.visits.size() + 1; + long newVisitTime = System.currentTimeMillis(); + cv.put(BrowserContract.History.VISITS, visits); + cv.put(BrowserContract.History.DATE_LAST_VISITED, newVisitTime); + final AndroidBrowserRepositoryDataAccessor dataAccessor = getDataAccessor(); + dataAccessor.updateByGuid(record0.guid, cv); + + // Add expected visit to record for verification. + JSONObject expectedVisit = new JSONObject(); + expectedVisit.put("date", newVisitTime * 1000); // Microseconds. + expectedVisit.put("type", 1L); + record0.visits.add(expectedVisit); + + performWait(fetchRunnable(session, new String[] { record0.guid }, new ExpectFetchDelegate(new Record[] { record0 }))); + closeDataAccessor(dataAccessor); + } + + @SuppressWarnings("unchecked") + public void testAddMultipleVisits() { + final RepositorySession session = createAndBeginSession(); + + HistoryRecord record0 = HistoryHelpers.createHistory4(); + performWait(storeRunnable(session, record0)); + + // Add three visits to the count and put in a new + // last visited date. + ContentValues cv = new ContentValues(); + int visits = record0.visits.size() + 3; + long newVisitTime = System.currentTimeMillis(); + cv.put(BrowserContract.History.VISITS, visits); + cv.put(BrowserContract.History.DATE_LAST_VISITED, newVisitTime); + final AndroidBrowserRepositoryDataAccessor dataAccessor = getDataAccessor(); + dataAccessor.updateByGuid(record0.guid, cv); + + // Now shift to microsecond timing for visits. + long newMicroVisitTime = newVisitTime * 1000; + + // Add expected visits to record for verification + JSONObject expectedVisit = new JSONObject(); + expectedVisit.put("date", newMicroVisitTime); + expectedVisit.put("type", 1L); + record0.visits.add(expectedVisit); + expectedVisit = new JSONObject(); + expectedVisit.put("date", newMicroVisitTime - 1000); + expectedVisit.put("type", 1L); + record0.visits.add(expectedVisit); + expectedVisit = new JSONObject(); + expectedVisit.put("date", newMicroVisitTime - 2000); + expectedVisit.put("type", 1L); + record0.visits.add(expectedVisit); + + ExpectFetchDelegate delegate = new ExpectFetchDelegate(new Record[] { record0 }); + performWait(fetchRunnable(session, new String[] { record0.guid }, delegate)); + + Record fetched = delegate.records.get(0); + assertTrue(record0.equalPayloads(fetched)); + closeDataAccessor(dataAccessor); + } + + public void testInvalidHistoryItemIsSkipped() throws NullCursorException { + final AndroidBrowserHistoryRepositorySession session = (AndroidBrowserHistoryRepositorySession) createAndBeginSession(); + final AndroidBrowserRepositoryDataAccessor dbHelper = session.getDBHelper(); + + final long now = System.currentTimeMillis(); + final HistoryRecord emptyURL = new HistoryRecord(Utils.generateGuid(), "history", now, false); + final HistoryRecord noVisits = new HistoryRecord(Utils.generateGuid(), "history", now, false); + final HistoryRecord aboutURL = new HistoryRecord(Utils.generateGuid(), "history", now, false); + + emptyURL.fennecDateVisited = now; + emptyURL.fennecVisitCount = 1; + emptyURL.histURI = ""; + emptyURL.title = "Something"; + + noVisits.fennecDateVisited = now; + noVisits.fennecVisitCount = 0; + noVisits.histURI = "http://example.org/novisits"; + noVisits.title = "Something Else"; + + aboutURL.fennecDateVisited = now; + aboutURL.fennecVisitCount = 1; + aboutURL.histURI = "about:home"; + aboutURL.title = "Fennec Home"; + + Uri one = dbHelper.insert(emptyURL); + Uri two = dbHelper.insert(noVisits); + Uri tre = dbHelper.insert(aboutURL); + assertNotNull(one); + assertNotNull(two); + assertNotNull(tre); + + // The records are in the DB. + final Cursor all = dbHelper.fetchAll(); + assertEquals(3, all.getCount()); + all.close(); + + // But aren't returned by fetching. + performWait(fetchAllRunnable(session, new Record[] {})); + + // And we'd ignore about:home if we downloaded it. + assertTrue(session.shouldIgnore(aboutURL)); + + session.abort(); + } + + public void testSqlInjectPurgeDelete() { + // Some setup. + RepositorySession session = createAndBeginSession(); + final AndroidBrowserRepositoryDataAccessor db = getDataAccessor(); + + try { + ContentValues cv = new ContentValues(); + cv.put(BrowserContract.SyncColumns.IS_DELETED, 1); + + // Create and insert 2 history entries, 2nd one is evil (attempts injection). + HistoryRecord h1 = HistoryHelpers.createHistory1(); + HistoryRecord h2 = HistoryHelpers.createHistory2(); + h2.guid = "' or '1'='1"; + + db.insert(h1); + db.insert(h2); + + // Test 1 - updateByGuid() handles evil history entries correctly. + db.updateByGuid(h2.guid, cv); + + // Query history table. + Cursor cur = getAllHistory(); + int numHistory = cur.getCount(); + + // Ensure only the evil history entry is marked for deletion. + try { + cur.moveToFirst(); + while (!cur.isAfterLast()) { + String guid = RepoUtils.getStringFromCursor(cur, BrowserContract.SyncColumns.GUID); + boolean deleted = RepoUtils.getLongFromCursor(cur, BrowserContract.SyncColumns.IS_DELETED) == 1; + + if (guid.equals(h2.guid)) { + assertTrue(deleted); + } else { + assertFalse(deleted); + } + cur.moveToNext(); + } + } finally { + cur.close(); + } + + // Test 2 - Ensure purgeDelete()'s call to delete() deletes only 1 record. + try { + db.purgeDeleted(); + } catch (NullCursorException e) { + e.printStackTrace(); + } + + cur = getAllHistory(); + int numHistoryAfterDeletion = cur.getCount(); + + // Ensure we have only 1 deleted row. + assertEquals(numHistoryAfterDeletion, numHistory - 1); + + // Ensure only the evil history is deleted. + try { + cur.moveToFirst(); + while (!cur.isAfterLast()) { + String guid = RepoUtils.getStringFromCursor(cur, BrowserContract.SyncColumns.GUID); + boolean deleted = RepoUtils.getLongFromCursor(cur, BrowserContract.SyncColumns.IS_DELETED) == 1; + + if (guid.equals(h2.guid)) { + fail("Evil guid was not deleted!"); + } else { + assertFalse(deleted); + } + cur.moveToNext(); + } + } finally { + cur.close(); + } + } finally { + closeDataAccessor(db); + session.abort(); + } + } + + protected Cursor getAllHistory() { + Context context = getApplicationContext(); + Cursor cur = context.getContentResolver().query(BrowserContractHelpers.HISTORY_CONTENT_URI, + BrowserContractHelpers.HistoryColumns, null, null, null); + return cur; + } + + public void testDataAccessorBulkInsert() throws NullCursorException { + final AndroidBrowserHistoryRepositorySession session = (AndroidBrowserHistoryRepositorySession) createAndBeginSession(); + AndroidBrowserHistoryDataAccessor db = (AndroidBrowserHistoryDataAccessor) session.getDBHelper(); + + ArrayList records = new ArrayList(); + records.add(HistoryHelpers.createHistory1()); + records.add(HistoryHelpers.createHistory2()); + records.add(HistoryHelpers.createHistory3()); + db.bulkInsert(records); + + performWait(fetchAllRunnable(session, preparedExpectFetchDelegate(records.toArray(new Record[records.size()])))); + session.abort(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java new file mode 100644 index 000000000..783aea1ff --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestBookmarks.java @@ -0,0 +1,1063 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; + +import org.json.simple.JSONArray; +import org.mozilla.gecko.R; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.background.sync.helpers.BookmarkHelpers; +import org.mozilla.gecko.background.sync.helpers.SimpleSuccessBeginDelegate; +import org.mozilla.gecko.background.sync.helpers.SimpleSuccessCreationDelegate; +import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFetchDelegate; +import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFinishDelegate; +import org.mozilla.gecko.background.sync.helpers.SimpleSuccessStoreDelegate; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.db.BrowserContract.Bookmarks; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; +import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; +import org.mozilla.gecko.sync.repositories.NullCursorException; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksDataAccessor; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksRepository; +import org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksRepositorySession; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import android.content.ContentResolver; +import android.content.ContentUris; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; + +public class TestBookmarks extends AndroidSyncTestCase { + + protected static final String LOG_TAG = "BookmarksTest"; + + /** + * Trivial test that forbidden records such as pinned items + * will be ignored if processed. + */ + public void testForbiddenItemsAreIgnored() { + final AndroidBrowserBookmarksRepository repo = new AndroidBrowserBookmarksRepository(); + final long now = System.currentTimeMillis(); + final String bookmarksCollection = "bookmarks"; + + final BookmarkRecord pinned = new BookmarkRecord("pinpinpinpin", "bookmarks", now - 1, false); + final BookmarkRecord normal = new BookmarkRecord("baaaaaaaaaaa", "bookmarks", now - 2, false); + + final BookmarkRecord pinnedItems = new BookmarkRecord(Bookmarks.PINNED_FOLDER_GUID, + bookmarksCollection, now - 4, false); + + normal.type = "bookmark"; + pinned.type = "bookmark"; + pinnedItems.type = "folder"; + + pinned.parentID = Bookmarks.PINNED_FOLDER_GUID; + normal.parentID = Bookmarks.TOOLBAR_FOLDER_GUID; + + pinnedItems.parentID = Bookmarks.PLACES_FOLDER_GUID; + + inBegunSession(repo, new SimpleSuccessBeginDelegate() { + @Override + public void onBeginSucceeded(RepositorySession session) { + assertTrue(((AndroidBrowserBookmarksRepositorySession) session).shouldIgnore(pinned)); + assertTrue(((AndroidBrowserBookmarksRepositorySession) session).shouldIgnore(pinnedItems)); + assertFalse(((AndroidBrowserBookmarksRepositorySession) session).shouldIgnore(normal)); + finishAndNotify(session); + } + }); + } + + /** + * Trivial test that pinned items will be skipped if present in the DB. + */ + public void testPinnedItemsAreNotRetrieved() { + final AndroidBrowserBookmarksRepository repo = new AndroidBrowserBookmarksRepository(); + + // Ensure that they exist. + setUpFennecPinnedItemsRecord(); + + // They're there in the DB… + final ArrayList roots = fetchChildrenDirect(Bookmarks.FIXED_ROOT_ID); + Logger.info(LOG_TAG, "Roots: " + roots); + assertTrue(roots.contains(Bookmarks.PINNED_FOLDER_GUID)); + + final ArrayList pinned = fetchChildrenDirect(Bookmarks.FIXED_PINNED_LIST_ID); + Logger.info(LOG_TAG, "Pinned: " + pinned); + assertTrue(pinned.contains("dapinneditem")); + + // … but not when we fetch. + final ArrayList guids = fetchGUIDs(repo); + assertFalse(guids.contains(Bookmarks.PINNED_FOLDER_GUID)); + assertFalse(guids.contains("dapinneditem")); + } + + public void testRetrieveFolderHasAccurateChildren() { + AndroidBrowserBookmarksRepository repo = new AndroidBrowserBookmarksRepository(); + + final long now = System.currentTimeMillis(); + + final String folderGUID = "eaaaaaaaafff"; + BookmarkRecord folder = new BookmarkRecord(folderGUID, "bookmarks", now - 5, false); + BookmarkRecord bookmarkA = new BookmarkRecord("daaaaaaaaaaa", "bookmarks", now - 1, false); + BookmarkRecord bookmarkB = new BookmarkRecord("baaaaaaaabbb", "bookmarks", now - 3, false); + BookmarkRecord bookmarkC = new BookmarkRecord("aaaaaaaaaccc", "bookmarks", now - 2, false); + + folder.children = childrenFromRecords(bookmarkA, bookmarkB, bookmarkC); + folder.sortIndex = 150; + folder.title = "Test items"; + folder.parentID = "toolbar"; + folder.parentName = "Bookmarks Toolbar"; + folder.type = "folder"; + + bookmarkA.parentID = folderGUID; + bookmarkA.bookmarkURI = "http://example.com/A"; + bookmarkA.title = "Title A"; + bookmarkA.type = "bookmark"; + + bookmarkB.parentID = folderGUID; + bookmarkB.bookmarkURI = "http://example.com/B"; + bookmarkB.title = "Title B"; + bookmarkB.type = "bookmark"; + + bookmarkC.parentID = folderGUID; + bookmarkC.bookmarkURI = "http://example.com/C"; + bookmarkC.title = "Title C"; + bookmarkC.type = "bookmark"; + + BookmarkRecord[] folderOnly = new BookmarkRecord[1]; + BookmarkRecord[] children = new BookmarkRecord[3]; + + folderOnly[0] = folder; + + children[0] = bookmarkA; + children[1] = bookmarkB; + children[2] = bookmarkC; + + wipe(); + Logger.debug(getName(), "Storing just folder..."); + storeRecordsInSession(repo, folderOnly, null); + + // We don't have any children, despite our insistence upon storing. + assertChildrenAreOrdered(repo, folderGUID, new Record[] {}); + + // Now store the children. + Logger.debug(getName(), "Storing children..."); + storeRecordsInSession(repo, children, null); + + // Now we have children, but their order is not determined, because + // they were stored out-of-session with the original folder. + assertChildrenAreUnordered(repo, folderGUID, children); + + // Now if we store the folder record again, they'll be put in the + // right place. + folder.lastModified++; + Logger.debug(getName(), "Storing just folder again..."); + storeRecordsInSession(repo, folderOnly, null); + Logger.debug(getName(), "Fetching children yet again..."); + assertChildrenAreOrdered(repo, folderGUID, children); + + // Now let's see what happens when we see records in the same session. + BookmarkRecord[] parentMixed = new BookmarkRecord[4]; + BookmarkRecord[] parentFirst = new BookmarkRecord[4]; + BookmarkRecord[] parentLast = new BookmarkRecord[4]; + + // None of our records have a position set. + assertTrue(bookmarkA.androidPosition <= 0); + assertTrue(bookmarkB.androidPosition <= 0); + assertTrue(bookmarkC.androidPosition <= 0); + + parentMixed[1] = folder; + parentMixed[0] = bookmarkA; + parentMixed[2] = bookmarkC; + parentMixed[3] = bookmarkB; + + parentFirst[0] = folder; + parentFirst[1] = bookmarkC; + parentFirst[2] = bookmarkA; + parentFirst[3] = bookmarkB; + + parentLast[3] = folder; + parentLast[0] = bookmarkB; + parentLast[1] = bookmarkA; + parentLast[2] = bookmarkC; + + wipe(); + storeRecordsInSession(repo, parentMixed, null); + assertChildrenAreOrdered(repo, folderGUID, children); + + wipe(); + storeRecordsInSession(repo, parentFirst, null); + assertChildrenAreOrdered(repo, folderGUID, children); + + wipe(); + storeRecordsInSession(repo, parentLast, null); + assertChildrenAreOrdered(repo, folderGUID, children); + + // Ensure that records are ordered even if we re-process the folder. + wipe(); + storeRecordsInSession(repo, parentLast, null); + folder.lastModified++; + storeRecordsInSession(repo, folderOnly, null); + assertChildrenAreOrdered(repo, folderGUID, children); + } + + public void testMergeFoldersPreservesSaneOrder() { + AndroidBrowserBookmarksRepository repo = new AndroidBrowserBookmarksRepository(); + + final long now = System.currentTimeMillis(); + final String folderGUID = "mobile"; + + wipe(); + final long mobile = setUpFennecMobileRecord(); + + // No children. + assertChildrenAreUnordered(repo, folderGUID, new Record[] {}); + + // Add some, as Fennec would. + fennecAddBookmark("Bookmark One", "http://example.com/fennec/One"); + fennecAddBookmark("Bookmark Two", "http://example.com/fennec/Two"); + + Logger.debug(getName(), "Fetching children..."); + JSONArray folderChildren = fetchChildrenForGUID(repo, folderGUID); + + assertTrue(folderChildren != null); + Logger.debug(getName(), "Children are " + folderChildren.toJSONString()); + assertEquals(2, folderChildren.size()); + String guidOne = (String) folderChildren.get(0); + String guidTwo = (String) folderChildren.get(1); + + // Make sure positions were saved. + assertChildrenAreDirect(mobile, new String[] { + guidOne, + guidTwo + }); + + // Add some through Sync. + BookmarkRecord folder = new BookmarkRecord(folderGUID, "bookmarks", now, false); + BookmarkRecord bookmarkA = new BookmarkRecord("daaaaaaaaaaa", "bookmarks", now, false); + BookmarkRecord bookmarkB = new BookmarkRecord("baaaaaaaabbb", "bookmarks", now, false); + + folder.children = childrenFromRecords(bookmarkA, bookmarkB); + folder.sortIndex = 150; + folder.title = "Mobile Bookmarks"; + folder.parentID = "places"; + folder.parentName = ""; + folder.type = "folder"; + + bookmarkA.parentID = folderGUID; + bookmarkA.parentName = "Mobile Bookmarks"; // Using this title exercises Bug 748898. + bookmarkA.bookmarkURI = "http://example.com/A"; + bookmarkA.title = "Title A"; + bookmarkA.type = "bookmark"; + + bookmarkB.parentID = folderGUID; + bookmarkB.parentName = "mobile"; + bookmarkB.bookmarkURI = "http://example.com/B"; + bookmarkB.title = "Title B"; + bookmarkB.type = "bookmark"; + + BookmarkRecord[] parentMixed = new BookmarkRecord[3]; + parentMixed[0] = bookmarkA; + parentMixed[1] = folder; + parentMixed[2] = bookmarkB; + + storeRecordsInSession(repo, parentMixed, null); + + BookmarkRecord expectedOne = new BookmarkRecord(guidOne, "bookmarks", now - 10, false); + BookmarkRecord expectedTwo = new BookmarkRecord(guidTwo, "bookmarks", now - 10, false); + + // We want the server to win in this case, and otherwise to preserve order. + // TODO + assertChildrenAreOrdered(repo, folderGUID, new Record[] { + bookmarkA, + bookmarkB, + expectedOne, + expectedTwo + }); + + // Furthermore, the children of that folder should be correct in the DB. + ContentResolver cr = getApplicationContext().getContentResolver(); + final long folderId = fennecGetFolderId(cr, folderGUID); + Logger.debug(getName(), "Folder " + folderGUID + " => " + folderId); + + assertChildrenAreDirect(folderId, new String[] { + bookmarkA.guid, + bookmarkB.guid, + expectedOne.guid, + expectedTwo.guid + }); + } + + /** + * Apply a folder record whose children array is already accurately + * stored in the database. Verify that the parent folder is not flagged + * for reupload (i.e., that its modified time is *ahem* unmodified). + */ + public void testNoReorderingMeansNoReupload() { + AndroidBrowserBookmarksRepository repo = new AndroidBrowserBookmarksRepository(); + + final long now = System.currentTimeMillis(); + + final String folderGUID = "eaaaaaaaafff"; + BookmarkRecord folder = new BookmarkRecord(folderGUID, "bookmarks", now -5, false); + BookmarkRecord bookmarkA = new BookmarkRecord("daaaaaaaaaaa", "bookmarks", now -1, false); + BookmarkRecord bookmarkB = new BookmarkRecord("baaaaaaaabbb", "bookmarks", now -3, false); + + folder.children = childrenFromRecords(bookmarkA, bookmarkB); + folder.sortIndex = 150; + folder.title = "Test items"; + folder.parentID = "toolbar"; + folder.parentName = "Bookmarks Toolbar"; + folder.type = "folder"; + + bookmarkA.parentID = folderGUID; + bookmarkA.bookmarkURI = "http://example.com/A"; + bookmarkA.title = "Title A"; + bookmarkA.type = "bookmark"; + + bookmarkB.parentID = folderGUID; + bookmarkB.bookmarkURI = "http://example.com/B"; + bookmarkB.title = "Title B"; + bookmarkB.type = "bookmark"; + + BookmarkRecord[] abf = new BookmarkRecord[3]; + BookmarkRecord[] justFolder = new BookmarkRecord[1]; + + abf[0] = bookmarkA; + abf[1] = bookmarkB; + abf[2] = folder; + + justFolder[0] = folder; + + final String[] abGUIDs = new String[] { bookmarkA.guid, bookmarkB.guid }; + final Record[] abRecords = new Record[] { bookmarkA, bookmarkB }; + final String[] baGUIDs = new String[] { bookmarkB.guid, bookmarkA.guid }; + final Record[] baRecords = new Record[] { bookmarkB, bookmarkA }; + + wipe(); + Logger.debug(getName(), "Storing A, B, folder..."); + storeRecordsInSession(repo, abf, null); + + ContentResolver cr = getApplicationContext().getContentResolver(); + final long folderID = fennecGetFolderId(cr, folderGUID); + assertChildrenAreOrdered(repo, folderGUID, abRecords); + assertChildrenAreDirect(folderID, abGUIDs); + + // To ensure an interval. + try { + Thread.sleep(100); + } catch (InterruptedException e) { + } + + // Store the same folder record again, and check the tracking. + // Because the folder array didn't change, + // the item is still tracked to not be uploaded. + folder.lastModified = System.currentTimeMillis() + 1; + HashSet tracked = new HashSet(); + storeRecordsInSession(repo, justFolder, tracked); + assertChildrenAreOrdered(repo, folderGUID, abRecords); + assertChildrenAreDirect(folderID, abGUIDs); + + assertTrue(tracked.contains(folderGUID)); + + // Store again, but with a different order. + tracked = new HashSet(); + folder.children = childrenFromRecords(bookmarkB, bookmarkA); + folder.lastModified = System.currentTimeMillis() + 1; + storeRecordsInSession(repo, justFolder, tracked); + assertChildrenAreOrdered(repo, folderGUID, baRecords); + assertChildrenAreDirect(folderID, baGUIDs); + + // Now it's going to be reuploaded. + assertFalse(tracked.contains(folderGUID)); + } + + /** + * Exercise the deletion of folders when their children have not been + * marked as deleted. In a database with constraints, this would fail + * if we simply deleted the records, so we move them first. + */ + public void testFolderDeletionOrphansChildren() { + AndroidBrowserBookmarksRepository repo = new AndroidBrowserBookmarksRepository(); + + long now = System.currentTimeMillis(); + + // Add a folder and four children. + final String folderGUID = "eaaaaaaaafff"; + BookmarkRecord folder = new BookmarkRecord(folderGUID, "bookmarks", now -5, false); + BookmarkRecord bookmarkA = new BookmarkRecord("daaaaaaaaaaa", "bookmarks", now -1, false); + BookmarkRecord bookmarkB = new BookmarkRecord("baaaaaaaabbb", "bookmarks", now -3, false); + BookmarkRecord bookmarkC = new BookmarkRecord("daaaaaaaaccc", "bookmarks", now -7, false); + BookmarkRecord bookmarkD = new BookmarkRecord("baaaaaaaaddd", "bookmarks", now -4, false); + + folder.children = childrenFromRecords(bookmarkA, bookmarkB, bookmarkC, bookmarkD); + folder.sortIndex = 150; + folder.title = "Test items"; + folder.parentID = "toolbar"; + folder.parentName = "Bookmarks Toolbar"; + folder.type = "folder"; + + bookmarkA.parentID = folderGUID; + bookmarkA.bookmarkURI = "http://example.com/A"; + bookmarkA.title = "Title A"; + bookmarkA.type = "bookmark"; + + bookmarkB.parentID = folderGUID; + bookmarkB.bookmarkURI = "http://example.com/B"; + bookmarkB.title = "Title B"; + bookmarkB.type = "bookmark"; + + bookmarkC.parentID = folderGUID; + bookmarkC.bookmarkURI = "http://example.com/C"; + bookmarkC.title = "Title C"; + bookmarkC.type = "bookmark"; + + bookmarkD.parentID = folderGUID; + bookmarkD.bookmarkURI = "http://example.com/D"; + bookmarkD.title = "Title D"; + bookmarkD.type = "bookmark"; + + BookmarkRecord[] abfcd = new BookmarkRecord[5]; + BookmarkRecord[] justFolder = new BookmarkRecord[1]; + abfcd[0] = bookmarkA; + abfcd[1] = bookmarkB; + abfcd[2] = folder; + abfcd[3] = bookmarkC; + abfcd[4] = bookmarkD; + + justFolder[0] = folder; + + final String[] abcdGUIDs = new String[] { bookmarkA.guid, bookmarkB.guid, bookmarkC.guid, bookmarkD.guid }; + final Record[] abcdRecords = new Record[] { bookmarkA, bookmarkB, bookmarkC, bookmarkD }; + + wipe(); + Logger.debug(getName(), "Storing A, B, folder, C, D..."); + storeRecordsInSession(repo, abfcd, null); + + // Verify that it worked. + ContentResolver cr = getApplicationContext().getContentResolver(); + final long folderID = fennecGetFolderId(cr, folderGUID); + assertChildrenAreOrdered(repo, folderGUID, abcdRecords); + assertChildrenAreDirect(folderID, abcdGUIDs); + + now = System.currentTimeMillis(); + + // Add one child to unsorted bookmarks. + BookmarkRecord unsortedA = new BookmarkRecord("yiamunsorted", "bookmarks", now, false); + unsortedA.parentID = "unfiled"; + unsortedA.title = "Unsorted A"; + unsortedA.type = "bookmark"; + unsortedA.androidPosition = 0; + + BookmarkRecord[] ua = new BookmarkRecord[1]; + ua[0] = unsortedA; + + storeRecordsInSession(repo, ua, null); + + // Ensure that the database is in this state. + assertChildrenAreOrdered(repo, "unfiled", ua); + + // Delete the second child, the folder, and then the third child. + bookmarkB.bookmarkURI = bookmarkC.bookmarkURI = folder.bookmarkURI = null; + bookmarkB.deleted = bookmarkC.deleted = folder.deleted = true; + bookmarkB.title = bookmarkC.title = folder.title = null; + + // Nulling the type of folder is very important: it verifies + // that the session can behave correctly according to local type. + bookmarkB.type = bookmarkC.type = folder.type = null; + + bookmarkB.lastModified = bookmarkC.lastModified = folder.lastModified = now = System.currentTimeMillis(); + + BookmarkRecord[] deletions = new BookmarkRecord[] { bookmarkB, folder, bookmarkC }; + storeRecordsInSession(repo, deletions, null); + + // Verify that the unsorted bookmarks folder contains its child and the + // first and fourth children of the now-deleted folder. + // Also verify that the folder is gone. + long unsortedID = fennecGetFolderId(cr, "unfiled"); + long toolbarID = fennecGetFolderId(cr, "toolbar"); + String[] expected = new String[] { unsortedA.guid, bookmarkA.guid, bookmarkD.guid }; + + // This will trigger positioning. + assertChildrenAreUnordered(repo, "unfiled", new Record[] { unsortedA, bookmarkA, bookmarkD }); + assertChildrenAreDirect(unsortedID, expected); + assertChildrenAreDirect(toolbarID, new String[] {}); + } + + /** + * A test where we expect to replace a local folder with a new folder (with a + * new GUID), whilst adding children to it. Verifies that replace and insert + * co-operate. + */ + public void testInsertAndReplaceGuid() { + AndroidBrowserBookmarksRepository repo = new AndroidBrowserBookmarksRepository(); + wipe(); + + BookmarkRecord folder1 = BookmarkHelpers.createFolder1(); + BookmarkRecord folder2 = BookmarkHelpers.createFolder2(); // child of folder1 + BookmarkRecord folder3 = BookmarkHelpers.createFolder3(); // child of folder2 + BookmarkRecord bmk1 = BookmarkHelpers.createBookmark1(); // child of folder1 + BookmarkRecord bmk2 = BookmarkHelpers.createBookmark2(); // child of folder1 + BookmarkRecord bmk3 = BookmarkHelpers.createBookmark3(); // child of folder2 + BookmarkRecord bmk4 = BookmarkHelpers.createBookmark4(); // child of folder3 + + BookmarkRecord[] records = new BookmarkRecord[] { + folder1, folder2, folder3, + bmk1, bmk4 + }; + storeRecordsInSession(repo, records, null); + + assertChildrenAreUnordered(repo, folder1.guid, new Record[] { bmk1, folder2 }); + assertChildrenAreUnordered(repo, folder2.guid, new Record[] { folder3 }); + assertChildrenAreUnordered(repo, folder3.guid, new Record[] { bmk4 }); + + // Replace folder3 with a record with a new GUID, and add bmk4 as folder3's child. + final long now = System.currentTimeMillis(); + folder3.guid = Utils.generateGuid(); + folder3.lastModified = now; + bmk4.title = bmk4.title + "/NEW"; + bmk4.parentID = folder3.guid; // Incoming child knows its parent. + bmk4.parentName = folder3.title; + bmk4.lastModified = now; + + // Order of store should not matter. + ArrayList changedRecords = new ArrayList(); + changedRecords.add(bmk2); changedRecords.add(bmk3); changedRecords.add(bmk4); changedRecords.add(folder3); + Collections.shuffle(changedRecords); + storeRecordsInSession(repo, changedRecords.toArray(new BookmarkRecord[changedRecords.size()]), null); + + assertChildrenAreUnordered(repo, folder1.guid, new Record[] { bmk1, bmk2, folder2 }); + assertChildrenAreUnordered(repo, folder2.guid, new Record[] { bmk3, folder3 }); + assertChildrenAreUnordered(repo, folder3.guid, new Record[] { bmk4 }); + + assertNotNull(fetchGUID(repo, folder3.guid)); + assertEquals(bmk4.title, fetchGUID(repo, bmk4.guid).title); + } + + /** + * A test where we expect to replace a local folder with a new folder (with a + * new title but the same GUID), whilst adding children to it. Verifies that + * replace and insert co-operate. + */ + public void testInsertAndReplaceTitle() { + AndroidBrowserBookmarksRepository repo = new AndroidBrowserBookmarksRepository(); + wipe(); + + BookmarkRecord folder1 = BookmarkHelpers.createFolder1(); + BookmarkRecord folder2 = BookmarkHelpers.createFolder2(); // child of folder1 + BookmarkRecord folder3 = BookmarkHelpers.createFolder3(); // child of folder2 + BookmarkRecord bmk1 = BookmarkHelpers.createBookmark1(); // child of folder1 + BookmarkRecord bmk2 = BookmarkHelpers.createBookmark2(); // child of folder1 + BookmarkRecord bmk3 = BookmarkHelpers.createBookmark3(); // child of folder2 + BookmarkRecord bmk4 = BookmarkHelpers.createBookmark4(); // child of folder3 + + BookmarkRecord[] records = new BookmarkRecord[] { + folder1, folder2, folder3, + bmk1, bmk4 + }; + storeRecordsInSession(repo, records, null); + + assertChildrenAreUnordered(repo, folder1.guid, new Record[] { bmk1, folder2 }); + assertChildrenAreUnordered(repo, folder2.guid, new Record[] { folder3 }); + assertChildrenAreUnordered(repo, folder3.guid, new Record[] { bmk4 }); + + // Rename folder1, and add bmk2 as folder1's child. + final long now = System.currentTimeMillis(); + folder1.title = folder1.title + "/NEW"; + folder1.lastModified = now; + bmk2.title = bmk2.title + "/NEW"; + bmk2.parentID = folder1.guid; // Incoming child knows its parent. + bmk2.parentName = folder1.title; + bmk2.lastModified = now; + + // Order of store should not matter. + ArrayList changedRecords = new ArrayList(); + changedRecords.add(bmk2); changedRecords.add(bmk3); changedRecords.add(folder1); + Collections.shuffle(changedRecords); + storeRecordsInSession(repo, changedRecords.toArray(new BookmarkRecord[changedRecords.size()]), null); + + assertChildrenAreUnordered(repo, folder1.guid, new Record[] { bmk1, bmk2, folder2 }); + assertChildrenAreUnordered(repo, folder2.guid, new Record[] { bmk3, folder3 }); + assertChildrenAreUnordered(repo, folder3.guid, new Record[] { bmk4 }); + + assertEquals(folder1.title, fetchGUID(repo, folder1.guid).title); + assertEquals(bmk2.title, fetchGUID(repo, bmk2.guid).title); + } + + /** + * Create and begin a new session, handing control to the delegate when started. + * Returns when the delegate has notified. + */ + public void inBegunSession(final AndroidBrowserBookmarksRepository repo, + final RepositorySessionBeginDelegate beginDelegate) { + Runnable go = new Runnable() { + @Override + public void run() { + RepositorySessionCreationDelegate delegate = new SimpleSuccessCreationDelegate() { + @Override + public void onSessionCreated(final RepositorySession session) { + try { + session.begin(beginDelegate); + } catch (InvalidSessionTransitionException e) { + performNotify(e); + } + } + }; + repo.createSession(delegate, getApplicationContext()); + } + }; + performWait(go); + } + + /** + * Finish the provided session, notifying on success. + * + * @param session + */ + public void finishAndNotify(final RepositorySession session) { + try { + session.finish(new SimpleSuccessFinishDelegate() { + @Override + public void onFinishSucceeded(RepositorySession session, + RepositorySessionBundle bundle) { + performNotify(); + } + }); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + + /** + * Simple helper class for fetching all records. + * The fetched records' GUIDs are stored in `fetchedGUIDs`. + */ + public class SimpleFetchAllBeginDelegate extends SimpleSuccessBeginDelegate { + public final ArrayList fetchedGUIDs = new ArrayList(); + + @Override + public void onBeginSucceeded(final RepositorySession session) { + RepositorySessionFetchRecordsDelegate fetchDelegate = new SimpleSuccessFetchDelegate() { + + @Override + public void onFetchedRecord(Record record) { + fetchedGUIDs.add(record.guid); + } + + @Override + public void onFetchCompleted(long end) { + finishAndNotify(session); + } + }; + session.fetchSince(0, fetchDelegate); + } + } + + /** + * Simple helper class for fetching a single record by GUID. + * The fetched record is stored in `fetchedRecord`. + */ + public class SimpleFetchOneBeginDelegate extends SimpleSuccessBeginDelegate { + public final String guid; + public Record fetchedRecord = null; + + public SimpleFetchOneBeginDelegate(String guid) { + this.guid = guid; + } + + @Override + public void onBeginSucceeded(final RepositorySession session) { + RepositorySessionFetchRecordsDelegate fetchDelegate = new SimpleSuccessFetchDelegate() { + + @Override + public void onFetchedRecord(Record record) { + fetchedRecord = record; + } + + @Override + public void onFetchCompleted(long end) { + finishAndNotify(session); + } + }; + try { + session.fetch(new String[] { guid }, fetchDelegate); + } catch (InactiveSessionException e) { + performNotify("Session is inactive.", e); + } + } + } + + /** + * Create a new session for the given repository, storing each record + * from the provided array. Notifies on failure or success. + * + * Optionally populates a provided Collection with tracked items. + * @param repo + * @param records + * @param tracked + */ + public void storeRecordsInSession(AndroidBrowserBookmarksRepository repo, + final BookmarkRecord[] records, + final Collection tracked) { + SimpleSuccessBeginDelegate beginDelegate = new SimpleSuccessBeginDelegate() { + @Override + public void onBeginSucceeded(final RepositorySession session) { + RepositorySessionStoreDelegate storeDelegate = new SimpleSuccessStoreDelegate() { + + @Override + public void onStoreCompleted(final long storeEnd) { + // Pass back whatever we tracked. + if (tracked != null) { + Iterator iter = session.getTrackedRecordIDs(); + while (iter.hasNext()) { + tracked.add(iter.next()); + } + } + finishAndNotify(session); + } + + @Override + public void onRecordStoreSucceeded(String guid) { + } + }; + session.setStoreDelegate(storeDelegate); + for (BookmarkRecord record : records) { + try { + session.store(record); + } catch (NoStoreDelegateException e) { + // Never happens. + } + } + session.storeDone(); + } + }; + inBegunSession(repo, beginDelegate); + } + + public ArrayList fetchGUIDs(AndroidBrowserBookmarksRepository repo) { + SimpleFetchAllBeginDelegate beginDelegate = new SimpleFetchAllBeginDelegate(); + inBegunSession(repo, beginDelegate); + return beginDelegate.fetchedGUIDs; + } + + public BookmarkRecord fetchGUID(AndroidBrowserBookmarksRepository repo, + final String guid) { + Logger.info(LOG_TAG, "Fetching for " + guid); + SimpleFetchOneBeginDelegate beginDelegate = new SimpleFetchOneBeginDelegate(guid); + inBegunSession(repo, beginDelegate); + Logger.info(LOG_TAG, "Fetched " + beginDelegate.fetchedRecord); + assertTrue(beginDelegate.fetchedRecord != null); + return (BookmarkRecord) beginDelegate.fetchedRecord; + } + + public JSONArray fetchChildrenForGUID(AndroidBrowserBookmarksRepository repo, + final String guid) { + return fetchGUID(repo, guid).children; + } + + @SuppressWarnings("unchecked") + protected static JSONArray childrenFromRecords(BookmarkRecord... records) { + JSONArray children = new JSONArray(); + for (BookmarkRecord record : records) { + children.add(record.guid); + } + return children; + } + + + protected void updateRow(ContentValues values) { + Uri uri = BrowserContractHelpers.BOOKMARKS_CONTENT_URI; + final String where = BrowserContract.Bookmarks.GUID + " = ?"; + final String[] args = new String[] { values.getAsString(BrowserContract.Bookmarks.GUID) }; + getApplicationContext().getContentResolver().update(uri, values, where, args); + } + + protected Uri insertRow(ContentValues values) { + Uri uri = BrowserContractHelpers.BOOKMARKS_CONTENT_URI; + return getApplicationContext().getContentResolver().insert(uri, values); + } + + protected static ContentValues specialFolder() { + ContentValues values = new ContentValues(); + + final long now = System.currentTimeMillis(); + values.put(Bookmarks.DATE_CREATED, now); + values.put(Bookmarks.DATE_MODIFIED, now); + values.put(Bookmarks.TYPE, BrowserContract.Bookmarks.TYPE_FOLDER); + + return values; + } + + protected static ContentValues fennecMobileRecordWithoutTitle() { + ContentValues values = specialFolder(); + values.put(BrowserContract.SyncColumns.GUID, "mobile"); + values.putNull(BrowserContract.Bookmarks.TITLE); + + return values; + } + + protected ContentValues fennecPinnedItemsRecord() { + final ContentValues values = specialFolder(); + final String title = getApplicationContext().getResources().getString(R.string.bookmarks_folder_pinned); + + values.put(BrowserContract.SyncColumns.GUID, Bookmarks.PINNED_FOLDER_GUID); + values.put(Bookmarks._ID, Bookmarks.FIXED_PINNED_LIST_ID); + values.put(Bookmarks.PARENT, Bookmarks.FIXED_ROOT_ID); + values.put(Bookmarks.TITLE, title); + return values; + } + + protected static ContentValues fennecPinnedChildItemRecord() { + ContentValues values = new ContentValues(); + + final long now = System.currentTimeMillis(); + + values.put(BrowserContract.SyncColumns.GUID, "dapinneditem"); + values.put(Bookmarks.DATE_CREATED, now); + values.put(Bookmarks.DATE_MODIFIED, now); + values.put(Bookmarks.TYPE, BrowserContract.Bookmarks.TYPE_BOOKMARK); + values.put(Bookmarks.URL, "user-entered:foobar"); + values.put(Bookmarks.PARENT, Bookmarks.FIXED_PINNED_LIST_ID); + values.put(Bookmarks.TITLE, "Foobar"); + return values; + } + + protected long setUpFennecMobileRecordWithoutTitle() { + ContentResolver cr = getApplicationContext().getContentResolver(); + ContentValues values = fennecMobileRecordWithoutTitle(); + updateRow(values); + return fennecGetMobileBookmarksFolderId(cr); + } + + protected long setUpFennecMobileRecord() { + ContentResolver cr = getApplicationContext().getContentResolver(); + ContentValues values = fennecMobileRecordWithoutTitle(); + values.put(BrowserContract.Bookmarks.PARENT, BrowserContract.Bookmarks.FIXED_ROOT_ID); + String title = getApplicationContext().getResources().getString(R.string.bookmarks_folder_mobile); + values.put(BrowserContract.Bookmarks.TITLE, title); + updateRow(values); + return fennecGetMobileBookmarksFolderId(cr); + } + + protected void setUpFennecPinnedItemsRecord() { + insertRow(fennecPinnedItemsRecord()); + insertRow(fennecPinnedChildItemRecord()); + } + + // + // Fennec fake layer. + // + private Uri appendProfile(Uri uri) { + final String defaultProfile = "default"; // Fennec constant removed in Bug 715307. + return uri.buildUpon().appendQueryParameter(BrowserContract.PARAM_PROFILE, defaultProfile).build(); + } + + private long fennecGetFolderId(ContentResolver cr, String guid) { + Cursor c = null; + try { + c = cr.query(appendProfile(BrowserContractHelpers.BOOKMARKS_CONTENT_URI), + new String[] { BrowserContract.Bookmarks._ID }, + BrowserContract.Bookmarks.GUID + " = ?", + new String[] { guid }, + null); + + if (c.moveToFirst()) { + return c.getLong(c.getColumnIndexOrThrow(BrowserContract.Bookmarks._ID)); + } + return -1; + } finally { + if (c != null) { + c.close(); + } + } + } + + private long fennecGetMobileBookmarksFolderId(ContentResolver cr) { + return fennecGetFolderId(cr, BrowserContract.Bookmarks.MOBILE_FOLDER_GUID); + } + + public void fennecAddBookmark(String title, String uri) { + ContentResolver cr = getApplicationContext().getContentResolver(); + + long folderId = fennecGetMobileBookmarksFolderId(cr); + if (folderId < 0) { + return; + } + + ContentValues values = new ContentValues(); + values.put(BrowserContract.Bookmarks.TITLE, title); + values.put(BrowserContract.Bookmarks.URL, uri); + values.put(BrowserContract.Bookmarks.PARENT, folderId); + + // Restore deleted record if possible + values.put(BrowserContract.Bookmarks.IS_DELETED, 0); + + Logger.debug(getName(), "Adding bookmark " + title + ", " + uri + " in " + folderId); + int updated = cr.update(appendProfile(BrowserContractHelpers.BOOKMARKS_CONTENT_URI), + values, + BrowserContract.Bookmarks.URL + " = ?", + new String[] { uri }); + + if (updated == 0) { + Uri insert = cr.insert(appendProfile(BrowserContractHelpers.BOOKMARKS_CONTENT_URI), values); + long idFromUri = ContentUris.parseId(insert); + Logger.debug(getName(), "Inserted " + uri + " as " + idFromUri); + Logger.debug(getName(), "Position is " + getPosition(idFromUri)); + } + } + + private long getPosition(long idFromUri) { + ContentResolver cr = getApplicationContext().getContentResolver(); + Cursor c = cr.query(appendProfile(BrowserContractHelpers.BOOKMARKS_CONTENT_URI), + new String[] { BrowserContract.Bookmarks.POSITION }, + BrowserContract.Bookmarks._ID + " = ?", + new String[] { String.valueOf(idFromUri) }, + null); + if (!c.moveToFirst()) { + return -2; + } + return c.getLong(0); + } + + protected AndroidBrowserBookmarksDataAccessor dataAccessor = null; + protected AndroidBrowserBookmarksDataAccessor getDataAccessor() { + if (dataAccessor == null) { + dataAccessor = new AndroidBrowserBookmarksDataAccessor(getApplicationContext()); + } + return dataAccessor; + } + + protected void wipe() { + Logger.debug(getName(), "Wiping."); + getDataAccessor().wipe(); + } + + protected void assertChildrenAreOrdered(AndroidBrowserBookmarksRepository repo, String guid, Record[] expected) { + Logger.debug(getName(), "Fetching children..."); + JSONArray folderChildren = fetchChildrenForGUID(repo, guid); + + assertTrue(folderChildren != null); + Logger.debug(getName(), "Children are " + folderChildren.toJSONString()); + assertEquals(expected.length, folderChildren.size()); + for (int i = 0; i < expected.length; ++i) { + assertEquals(expected[i].guid, ((String) folderChildren.get(i))); + } + } + + protected void assertChildrenAreUnordered(AndroidBrowserBookmarksRepository repo, String guid, Record[] expected) { + Logger.debug(getName(), "Fetching children..."); + JSONArray folderChildren = fetchChildrenForGUID(repo, guid); + + assertTrue(folderChildren != null); + Logger.debug(getName(), "Children are " + folderChildren.toJSONString()); + assertEquals(expected.length, folderChildren.size()); + for (Record record : expected) { + folderChildren.contains(record.guid); + } + } + + /** + * Return a sequence of children GUIDs for the provided folder ID. + */ + protected ArrayList fetchChildrenDirect(long id) { + Logger.debug(getName(), "Fetching children directly from DB..."); + final ArrayList out = new ArrayList(); + final AndroidBrowserBookmarksDataAccessor accessor = new AndroidBrowserBookmarksDataAccessor(getApplicationContext()); + Cursor cur = null; + try { + cur = accessor.getChildren(id); + } catch (NullCursorException e) { + fail("Got null cursor."); + } + try { + if (!cur.moveToFirst()) { + return out; + } + final int guidCol = cur.getColumnIndex(BrowserContract.SyncColumns.GUID); + while (!cur.isAfterLast()) { + out.add(cur.getString(guidCol)); + cur.moveToNext(); + } + } finally { + cur.close(); + } + return out; + } + + /** + * Assert that the children of the provided ID are correct and positioned in the database. + * @param id + * @param guids + */ + protected void assertChildrenAreDirect(long id, String[] guids) { + Logger.debug(getName(), "Fetching children directly from DB..."); + AndroidBrowserBookmarksDataAccessor accessor = new AndroidBrowserBookmarksDataAccessor(getApplicationContext()); + Cursor cur = null; + try { + cur = accessor.getChildren(id); + } catch (NullCursorException e) { + fail("Got null cursor."); + } + try { + if (guids == null || guids.length == 0) { + assertFalse(cur.moveToFirst()); + return; + } + + assertTrue(cur.moveToFirst()); + int i = 0; + final int guidCol = cur.getColumnIndex(BrowserContract.SyncColumns.GUID); + final int posCol = cur.getColumnIndex(BrowserContract.Bookmarks.POSITION); + while (!cur.isAfterLast()) { + assertTrue(i < guids.length); + final String guid = cur.getString(guidCol); + final int pos = cur.getInt(posCol); + Logger.debug(getName(), "Fetched child: " + guid + " has position " + pos); + assertEquals(guids[i], guid); + assertEquals(i, pos); + + ++i; + cur.moveToNext(); + } + assertEquals(guids.length, i); + } finally { + cur.close(); + } + } +} + +/** +TODO + +Test for storing a record that will reconcile to mobile; postcondition is +that there's still a directory called mobile that includes all the items that +it used to. + +mobile folder created without title. +Unsorted put in mobile??? +Tests for children retrieval +Tests for children merge +Tests for modify retrieve parent when child added, removed, reordered (oh, reorder is hard! Any change, then.) +Safety mode? +Test storing folder first, contents first. +Store folder in next session. Verify order recovery. + + +*/ diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestClientsDatabase.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestClientsDatabase.java new file mode 100644 index 000000000..198073fcf --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestClientsDatabase.java @@ -0,0 +1,200 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import java.util.ArrayList; + +import org.json.simple.JSONArray; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.NullCursorException; +import org.mozilla.gecko.sync.repositories.android.ClientsDatabase; +import org.mozilla.gecko.sync.repositories.android.RepoUtils; +import org.mozilla.gecko.sync.repositories.domain.ClientRecord; +import org.mozilla.gecko.sync.setup.Constants; + +import android.database.Cursor; +import android.test.AndroidTestCase; + +public class TestClientsDatabase extends AndroidTestCase { + + protected ClientsDatabase db; + + public void setUp() { + db = new ClientsDatabase(mContext); + db.wipeDB(); + } + + public void testStoreAndFetch() { + ClientRecord record = new ClientRecord(); + String profileConst = Constants.DEFAULT_PROFILE; + db.store(profileConst, record); + + Cursor cur = null; + try { + // Test stored item gets fetched correctly. + cur = db.fetchClientsCursor(record.guid, profileConst); + assertTrue(cur.moveToFirst()); + assertEquals(1, cur.getCount()); + + String guid = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_ACCOUNT_GUID); + String profileId = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_PROFILE); + String clientName = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_NAME); + String clientType = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_TYPE); + + assertEquals(record.guid, guid); + assertEquals(profileConst, profileId); + assertEquals(record.name, clientName); + assertEquals(record.type, clientType); + } catch (NullCursorException e) { + fail("Should not have NullCursorException"); + } finally { + if (cur != null) { + cur.close(); + } + } + } + + public void testStoreAndFetchSpecificCommands() { + String accountGUID = Utils.generateGuid(); + ArrayList args = new ArrayList(); + args.add("URI of Page"); + args.add("Sender GUID"); + args.add("Title of Page"); + String jsonArgs = JSONArray.toJSONString(args); + + Cursor cur = null; + try { + db.store(accountGUID, "displayURI", jsonArgs); + + // This row should not show up in the fetch. + args.add("Another arg."); + db.store(accountGUID, "displayURI", JSONArray.toJSONString(args)); + + // Test stored item gets fetched correctly. + cur = db.fetchSpecificCommand(accountGUID, "displayURI", jsonArgs); + assertTrue(cur.moveToFirst()); + assertEquals(1, cur.getCount()); + + String guid = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_ACCOUNT_GUID); + String commandType = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_COMMAND); + String fetchedArgs = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_ARGS); + + assertEquals(accountGUID, guid); + assertEquals("displayURI", commandType); + assertEquals(jsonArgs, fetchedArgs); + } catch (NullCursorException e) { + fail("Should not have NullCursorException"); + } finally { + if (cur != null) { + cur.close(); + } + } + } + + public void testFetchCommandsForClient() { + String accountGUID = Utils.generateGuid(); + ArrayList args = new ArrayList(); + args.add("URI of Page"); + args.add("Sender GUID"); + args.add("Title of Page"); + String jsonArgs = JSONArray.toJSONString(args); + + Cursor cur = null; + try { + db.store(accountGUID, "displayURI", jsonArgs); + + // This row should ALSO show up in the fetch. + args.add("Another arg."); + db.store(accountGUID, "displayURI", JSONArray.toJSONString(args)); + + // Test both stored items with the same GUID but different command are fetched. + cur = db.fetchCommandsForClient(accountGUID); + assertTrue(cur.moveToFirst()); + assertEquals(2, cur.getCount()); + } catch (NullCursorException e) { + fail("Should not have NullCursorException"); + } finally { + if (cur != null) { + cur.close(); + } + } + } + + @SuppressWarnings("resource") + public void testDelete() { + ClientRecord record1 = new ClientRecord(); + ClientRecord record2 = new ClientRecord(); + String profileConst = Constants.DEFAULT_PROFILE; + + db.store(profileConst, record1); + db.store(profileConst, record2); + + Cursor cur = null; + try { + // Test record doesn't exist after delete. + db.deleteClient(record1.guid, profileConst); + cur = db.fetchClientsCursor(record1.guid, profileConst); + assertFalse(cur.moveToFirst()); + assertEquals(0, cur.getCount()); + + // Test record2 still there after deleting record1. + cur = db.fetchClientsCursor(record2.guid, profileConst); + assertTrue(cur.moveToFirst()); + assertEquals(1, cur.getCount()); + + String guid = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_ACCOUNT_GUID); + String profileId = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_PROFILE); + String clientName = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_NAME); + String clientType = RepoUtils.getStringFromCursor(cur, ClientsDatabase.COL_TYPE); + + assertEquals(record2.guid, guid); + assertEquals(profileConst, profileId); + assertEquals(record2.name, clientName); + assertEquals(record2.type, clientType); + } catch (NullCursorException e) { + fail("Should not have NullCursorException"); + } finally { + if (cur != null) { + cur.close(); + } + } + } + + @SuppressWarnings("resource") + public void testWipe() { + ClientRecord record1 = new ClientRecord(); + ClientRecord record2 = new ClientRecord(); + String profileConst = Constants.DEFAULT_PROFILE; + + db.store(profileConst, record1); + db.store(profileConst, record2); + + + Cursor cur = null; + try { + // Test before wipe the records are there. + cur = db.fetchClientsCursor(record2.guid, profileConst); + assertTrue(cur.moveToFirst()); + assertEquals(1, cur.getCount()); + cur = db.fetchClientsCursor(record2.guid, profileConst); + assertTrue(cur.moveToFirst()); + assertEquals(1, cur.getCount()); + + // Test after wipe neither record exists. + db.wipeClientsTable(); + cur = db.fetchClientsCursor(record2.guid, profileConst); + assertFalse(cur.moveToFirst()); + assertEquals(0, cur.getCount()); + cur = db.fetchClientsCursor(record1.guid, profileConst); + assertFalse(cur.moveToFirst()); + assertEquals(0, cur.getCount()); + } catch (NullCursorException e) { + fail("Should not have NullCursorException"); + } finally { + if (cur != null) { + cur.close(); + } + } + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestClientsDatabaseAccessor.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestClientsDatabaseAccessor.java new file mode 100644 index 000000000..65b14e860 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestClientsDatabaseAccessor.java @@ -0,0 +1,128 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.mozilla.gecko.background.testhelpers.CommandHelpers; +import org.mozilla.gecko.sync.CommandProcessor.Command; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.NullCursorException; +import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor; +import org.mozilla.gecko.sync.repositories.domain.ClientRecord; + +import android.content.Context; +import android.database.Cursor; +import android.test.AndroidTestCase; + +public class TestClientsDatabaseAccessor extends AndroidTestCase { + + public class StubbedClientsDatabaseAccessor extends ClientsDatabaseAccessor { + public StubbedClientsDatabaseAccessor(Context mContext) { + super(mContext); + } + } + + StubbedClientsDatabaseAccessor db; + + public void setUp() { + db = new StubbedClientsDatabaseAccessor(mContext); + db.wipeDB(); + } + + public void tearDown() { + db.close(); + } + + public void testStoreArrayListAndFetch() throws NullCursorException { + ArrayList list = new ArrayList(); + ClientRecord record1 = new ClientRecord(Utils.generateGuid()); + ClientRecord record2 = new ClientRecord(Utils.generateGuid()); + ClientRecord record3 = new ClientRecord(Utils.generateGuid()); + + list.add(record1); + list.add(record2); + db.store(list); + + ClientRecord r1 = db.fetchClient(record1.guid); + ClientRecord r2 = db.fetchClient(record2.guid); + ClientRecord r3 = db.fetchClient(record3.guid); + + assertNotNull(r1); + assertNotNull(r2); + assertNull(r3); + assertTrue(record1.equals(r1)); + assertTrue(record2.equals(r2)); + assertFalse(record3.equals(r3)); + } + + public void testStoreAndFetchCommandsForClient() { + String accountGUID1 = Utils.generateGuid(); + String accountGUID2 = Utils.generateGuid(); + + Command command1 = CommandHelpers.getCommand1(); + Command command2 = CommandHelpers.getCommand2(); + Command command3 = CommandHelpers.getCommand3(); + + Cursor cur = null; + try { + db.store(accountGUID1, command1); + db.store(accountGUID1, command2); + db.store(accountGUID2, command3); + + List commands = db.fetchCommandsForClient(accountGUID1); + assertEquals(2, commands.size()); + assertEquals(1, commands.get(0).args.size()); + assertEquals(1, commands.get(1).args.size()); + } catch (NullCursorException e) { + fail("Should not have NullCursorException"); + } finally { + if (cur != null) { + cur.close(); + } + } + } + + public void testNumClients() { + final int COUNT = 5; + ArrayList list = new ArrayList(); + for (int i = 0; i < 5; i++) { + list.add(new ClientRecord()); + } + db.store(list); + assertEquals(COUNT, db.clientsCount()); + } + + public void testFetchAll() throws NullCursorException { + ArrayList list = new ArrayList(); + ClientRecord record1 = new ClientRecord(Utils.generateGuid()); + ClientRecord record2 = new ClientRecord(Utils.generateGuid()); + + list.add(record1); + list.add(record2); + + boolean thrown = false; + try { + Map records = db.fetchAllClients(); + + assertNotNull(records); + assertEquals(0, records.size()); + + db.store(list); + records = db.fetchAllClients(); + assertNotNull(records); + assertEquals(2, records.size()); + assertTrue(record1.equals(records.get(record1.guid))); + assertTrue(record2.equals(records.get(record2.guid))); + + // put() should throw an exception since records is immutable. + records.put(null, null); + } catch (UnsupportedOperationException e) { + thrown = true; + } + assertTrue(thrown); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java new file mode 100644 index 000000000..02d393ce8 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestFennecTabsRepositorySession.java @@ -0,0 +1,297 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import org.json.simple.JSONArray; +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.background.sync.helpers.ExpectFetchDelegate; +import org.mozilla.gecko.background.sync.helpers.SessionTestHelper; +import org.mozilla.gecko.background.testhelpers.MockClientsDataDelegate; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.db.BrowserContract.Clients; +import org.mozilla.gecko.sync.repositories.NoContentProviderException; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; +import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor; +import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository; +import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository.FennecTabsRepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.domain.ClientRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; +import org.mozilla.gecko.sync.repositories.domain.TabsRecord; + +import android.content.ContentProviderClient; +import android.content.ContentResolver; +import android.content.Context; +import android.database.Cursor; +import android.os.RemoteException; + +public class TestFennecTabsRepositorySession extends AndroidSyncTestCase { + public static final MockClientsDataDelegate clientsDataDelegate = new MockClientsDataDelegate(); + public static final String TEST_CLIENT_GUID = clientsDataDelegate.getAccountGUID(); + public static final String TEST_CLIENT_NAME = clientsDataDelegate.getClientName(); + public static final String TEST_CLIENT_DEVICE_TYPE = "phablet"; + + // Override these to test against data that is not live. + public static final String TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION = BrowserContract.Tabs.CLIENT_GUID + " IS ?"; + public static final String[] TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS = new String[] { TEST_CLIENT_GUID }; + + public static final String TEST_CLIENTS_GUID_IS_LOCAL_SELECTION = BrowserContract.Clients.GUID + " IS ?"; + public static final String[] TEST_CLIENTS_GUID_IS_LOCAL_SELECTION_ARGS = new String[] { TEST_CLIENT_GUID }; + + protected ContentProviderClient tabsClient = null; + protected ContentProviderClient clientsClient = null; + + protected ContentProviderClient getTabsClient() { + final ContentResolver cr = getApplicationContext().getContentResolver(); + return cr.acquireContentProviderClient(BrowserContractHelpers.TABS_CONTENT_URI); + } + + protected ContentProviderClient getClientsClient() { + final ContentResolver cr = getApplicationContext().getContentResolver(); + return cr.acquireContentProviderClient(BrowserContractHelpers.CLIENTS_CONTENT_URI); + } + + public TestFennecTabsRepositorySession() throws NoContentProviderException { + super(); + } + + @Override + public void setUp() { + if (tabsClient == null) { + tabsClient = getTabsClient(); + } + if (clientsClient == null) { + clientsClient = getClientsClient(); + } + } + + protected int deleteTestClient(final ContentProviderClient clientsClient) throws RemoteException { + if (clientsClient == null) { + return -1; + } + return clientsClient.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, TEST_CLIENTS_GUID_IS_LOCAL_SELECTION, TEST_CLIENTS_GUID_IS_LOCAL_SELECTION_ARGS); + } + + protected int deleteAllTestTabs(final ContentProviderClient tabsClient) throws RemoteException { + if (tabsClient == null) { + return -1; + } + return tabsClient.delete(BrowserContractHelpers.TABS_CONTENT_URI, + TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION, TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS); + } + + @Override + protected void tearDown() throws Exception { + if (tabsClient != null) { + deleteAllTestTabs(tabsClient); + + tabsClient.release(); + tabsClient = null; + } + + if (clientsClient != null) { + deleteTestClient(clientsClient); + + clientsClient.release(); + clientsClient = null; + } + } + + protected FennecTabsRepository getRepository() { + /** + * Override this chain in order to avoid our test code having to create two + * sessions all the time. + */ + return new FennecTabsRepository(clientsDataDelegate) { + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + try { + final FennecTabsRepositorySession session = new FennecTabsRepositorySession(this, context) { + @Override + protected synchronized void trackGUID(String guid) { + } + + @Override + protected String localClientSelection() { + return TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION; + } + + @Override + protected String[] localClientSelectionArgs() { + return TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS; + } + }; + delegate.onSessionCreated(session); + } catch (Exception e) { + delegate.onSessionCreateFailed(e); + } + } + }; + } + + protected FennecTabsRepositorySession createSession() { + return (FennecTabsRepositorySession) SessionTestHelper.createSession( + getApplicationContext(), + getRepository()); + } + + protected FennecTabsRepositorySession createAndBeginSession() { + return (FennecTabsRepositorySession) SessionTestHelper.createAndBeginSession( + getApplicationContext(), + getRepository()); + } + + protected Runnable fetchSinceRunnable(final RepositorySession session, final long timestamp, final Record[] expectedRecords) { + return new Runnable() { + @Override + public void run() { + session.fetchSince(timestamp, new ExpectFetchDelegate(expectedRecords)); + } + }; + } + + protected Runnable fetchAllRunnable(final RepositorySession session, final Record[] expectedRecords) { + return new Runnable() { + @Override + public void run() { + session.fetchAll(new ExpectFetchDelegate(expectedRecords)); + } + }; + } + + protected Tab testTab1; + protected Tab testTab2; + protected Tab testTab3; + + @SuppressWarnings("unchecked") + private void insertSomeTestTabs(ContentProviderClient tabsClient) throws RemoteException { + final JSONArray history1 = new JSONArray(); + history1.add("http://test.com/test1.html"); + testTab1 = new Tab("test title 1", "http://test.com/test1.png", history1, 1000); + + final JSONArray history2 = new JSONArray(); + history2.add("http://test.com/test2.html#1"); + history2.add("http://test.com/test2.html#2"); + history2.add("http://test.com/test2.html#3"); + testTab2 = new Tab("test title 2", "http://test.com/test2.png", history2, 2000); + + final JSONArray history3 = new JSONArray(); + history3.add("http://test.com/test3.html#1"); + history3.add("http://test.com/test3.html#2"); + testTab3 = new Tab("test title 3", "http://test.com/test3.png", history3, 3000); + + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab1.toContentValues(TEST_CLIENT_GUID, 0)); + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab2.toContentValues(TEST_CLIENT_GUID, 1)); + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab3.toContentValues(TEST_CLIENT_GUID, 2)); + } + + protected TabsRecord insertTestTabsAndExtractTabsRecord() throws RemoteException { + insertSomeTestTabs(tabsClient); + + final String positionAscending = BrowserContract.Tabs.POSITION + " ASC"; + Cursor cursor = null; + try { + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, + TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION, TEST_TABS_CLIENT_GUID_IS_LOCAL_SELECTION_ARGS, positionAscending); + CursorDumper.dumpCursor(cursor); + + final TabsRecord tabsRecord = FennecTabsRepository.tabsRecordFromCursor(cursor, TEST_CLIENT_GUID, TEST_CLIENT_NAME); + + assertEquals(TEST_CLIENT_GUID, tabsRecord.guid); + assertEquals(TEST_CLIENT_NAME, tabsRecord.clientName); + + assertNotNull(tabsRecord.tabs); + assertEquals(cursor.getCount(), tabsRecord.tabs.size()); + + return tabsRecord; + } finally { + cursor.close(); + } + } + + public void testFetchAll() throws NoContentProviderException, RemoteException { + final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord(); + + final FennecTabsRepositorySession session = createAndBeginSession(); + performWait(fetchAllRunnable(session, new Record[] { tabsRecord })); + + session.abort(); + } + + public void testFetchSince() throws NoContentProviderException, RemoteException { + final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord(); + + final FennecTabsRepositorySession session = createAndBeginSession(); + + // Not all tabs are modified after this, but the record should contain them all. + performWait(fetchSinceRunnable(session, 1000, new Record[] { tabsRecord })); + + // No tabs are modified after this, but our client name has changed in the interim. + performWait(fetchSinceRunnable(session, 4000, new Record[] { tabsRecord })); + + // No tabs are modified after this, and our client name hasn't changed, so + // we shouldn't get a record at all. Note: this runs after our static + // initializer that sets the client data timestamp. + final long now = System.currentTimeMillis(); + performWait(fetchSinceRunnable(session, now, new Record[] { })); + + // No tabs are modified after this, but our client name has changed, so + // again we get a record. + clientsDataDelegate.setClientName("new client name", System.currentTimeMillis()); + performWait(fetchSinceRunnable(session, now, new Record[] { tabsRecord })); + + session.abort(); + } + + // Verify that storing a tabs record writes a clients record with the correct + // device type to the Fennec clients provider. + public void testStore() throws NoContentProviderException, RemoteException { + // Get a valid tabsRecord to write. + final TabsRecord tabsRecord = insertTestTabsAndExtractTabsRecord(); + deleteAllTestTabs(tabsClient); + deleteTestClient(clientsClient); + + final ContentResolver cr = getApplicationContext().getContentResolver(); + final ContentProviderClient clientsClient = cr.acquireContentProviderClient(BrowserContractHelpers.CLIENTS_CONTENT_URI); + + try { + // This clients DB is not the Fennec DB; it's Sync's own clients DB. + final ClientsDatabaseAccessor db = new ClientsDatabaseAccessor(getApplicationContext()); + try { + ClientRecord clientRecord = new ClientRecord(TEST_CLIENT_GUID); + clientRecord.name = TEST_CLIENT_NAME; + clientRecord.type = TEST_CLIENT_DEVICE_TYPE; + db.store(clientRecord); + } finally { + db.close(); + } + + final FennecTabsRepositorySession session = createAndBeginSession(); + performWait(AndroidBrowserRepositoryTestCase.storeRunnable(session, tabsRecord)); + + session.abort(); + + // This store should write Sync's idea of the client's device_type to Fennec's clients CP. + final Cursor cursor = clientsClient.query(BrowserContractHelpers.CLIENTS_CONTENT_URI, null, + TEST_CLIENTS_GUID_IS_LOCAL_SELECTION, TEST_CLIENTS_GUID_IS_LOCAL_SELECTION_ARGS, null); + assertNotNull(cursor); + + try { + assertTrue(cursor.moveToFirst()); + assertEquals(TEST_CLIENT_GUID, cursor.getString(cursor.getColumnIndex(Clients.GUID))); + assertEquals(TEST_CLIENT_NAME, cursor.getString(cursor.getColumnIndex(Clients.NAME))); + assertEquals(TEST_CLIENT_DEVICE_TYPE, cursor.getString(cursor.getColumnIndex(Clients.DEVICE_TYPE))); + assertTrue(cursor.isLast()); + } finally { + cursor.close(); + } + } finally { + // We can't delete only our test client due to a Fennec CP issue with guid vs. client_guid. + clientsClient.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, null, null); + clientsClient.release(); + } + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestFormHistoryRepositorySession.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestFormHistoryRepositorySession.java new file mode 100644 index 000000000..5d5014b75 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestFormHistoryRepositorySession.java @@ -0,0 +1,441 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import java.util.concurrent.ExecutorService; + +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.background.sync.helpers.ExpectFetchDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectFetchSinceDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectGuidsSinceDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectNoStoreDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectStoredDelegate; +import org.mozilla.gecko.background.sync.helpers.SessionTestHelper; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.NoContentProviderException; +import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; +import org.mozilla.gecko.sync.repositories.android.FormHistoryRepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; +import org.mozilla.gecko.sync.repositories.domain.FormHistoryRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import android.content.ContentProviderClient; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; +import android.os.RemoteException; + +public class TestFormHistoryRepositorySession extends AndroidSyncTestCase { + protected ContentProviderClient formsProvider = null; + + public TestFormHistoryRepositorySession() throws NoContentProviderException { + super(); + } + + public void setUp() { + if (formsProvider == null) { + try { + formsProvider = FormHistoryRepositorySession.acquireContentProvider(getApplicationContext()); + } catch (NoContentProviderException e) { + fail("Failed to acquireContentProvider: " + e); + } + } + + try { + FormHistoryRepositorySession.purgeDatabases(formsProvider); + } catch (RemoteException e) { + fail("Failed to purgeDatabases: " + e); + } + } + + public void tearDown() { + if (formsProvider != null) { + formsProvider.release(); + formsProvider = null; + } + } + + protected FormHistoryRepositorySession.FormHistoryRepository getRepository() { + /** + * Override this chain in order to avoid our test code having to create two + * sessions all the time. + */ + return new FormHistoryRepositorySession.FormHistoryRepository() { + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + try { + final FormHistoryRepositorySession session = new FormHistoryRepositorySession(this, context) { + @Override + protected synchronized void trackGUID(String guid) { + } + }; + delegate.onSessionCreated(session); + } catch (Exception e) { + delegate.onSessionCreateFailed(e); + } + } + }; + } + + + protected FormHistoryRepositorySession createSession() { + return (FormHistoryRepositorySession) SessionTestHelper.createSession( + getApplicationContext(), + getRepository()); + } + + protected FormHistoryRepositorySession createAndBeginSession() { + return (FormHistoryRepositorySession) SessionTestHelper.createAndBeginSession( + getApplicationContext(), + getRepository()); + } + + public void testAcquire() throws NoContentProviderException { + final FormHistoryRepositorySession session = createAndBeginSession(); + assertNotNull(session.getFormsProvider()); + session.abort(); + } + + protected int numRecords(FormHistoryRepositorySession session, Uri uri) throws RemoteException { + Cursor cur = null; + try { + cur = session.getFormsProvider().query(uri, null, null, null, null); + return cur.getCount(); + } finally { + if (cur != null) { + cur.close(); + } + } + } + + protected long after0; + protected long after1; + protected long after2; + protected long after3; + protected long after4; + protected FormHistoryRecord regular1; + protected FormHistoryRecord regular2; + protected FormHistoryRecord deleted1; + protected FormHistoryRecord deleted2; + + public void insertTwoRecords(FormHistoryRepositorySession session) throws RemoteException { + Uri regularUri = BrowserContractHelpers.FORM_HISTORY_CONTENT_URI; + Uri deletedUri = BrowserContractHelpers.DELETED_FORM_HISTORY_CONTENT_URI; + after0 = System.currentTimeMillis(); + + regular1 = new FormHistoryRecord("guid1", "forms", System.currentTimeMillis(), false); + regular1.fieldName = "fieldName1"; + regular1.fieldValue = "value1"; + final ContentValues cv1 = new ContentValues(); + cv1.put(BrowserContract.FormHistory.GUID, regular1.guid); + cv1.put(BrowserContract.FormHistory.FIELD_NAME, regular1.fieldName); + cv1.put(BrowserContract.FormHistory.VALUE, regular1.fieldValue); + cv1.put(BrowserContract.FormHistory.FIRST_USED, 1000 * regular1.lastModified); // Microseconds. + + int regularInserted = session.getFormsProvider().bulkInsert(regularUri, new ContentValues[] { cv1 }); + assertEquals(1, regularInserted); + after1 = System.currentTimeMillis(); + + deleted1 = new FormHistoryRecord("guid3", "forms", -1, true); + final ContentValues cv3 = new ContentValues(); + cv3.put(BrowserContract.FormHistory.GUID, deleted1.guid); + // cv3.put(BrowserContract.DeletedFormHistory.TIME_DELETED, record3.lastModified); // Set by CP. + + int deletedInserted = session.getFormsProvider().bulkInsert(deletedUri, new ContentValues[] { cv3 }); + assertEquals(1, deletedInserted); + after2 = System.currentTimeMillis(); + + regular2 = null; + deleted2 = null; + } + + public void insertFourRecords(FormHistoryRepositorySession session) throws RemoteException { + Uri regularUri = BrowserContractHelpers.FORM_HISTORY_CONTENT_URI; + Uri deletedUri = BrowserContractHelpers.DELETED_FORM_HISTORY_CONTENT_URI; + + insertTwoRecords(session); + + regular2 = new FormHistoryRecord("guid2", "forms", System.currentTimeMillis(), false); + regular2.fieldName = "fieldName2"; + regular2.fieldValue = "value2"; + final ContentValues cv2 = new ContentValues(); + cv2.put(BrowserContract.FormHistory.GUID, regular2.guid); + cv2.put(BrowserContract.FormHistory.FIELD_NAME, regular2.fieldName); + cv2.put(BrowserContract.FormHistory.VALUE, regular2.fieldValue); + cv2.put(BrowserContract.FormHistory.FIRST_USED, 1000 * regular2.lastModified); // Microseconds. + + int regularInserted = session.getFormsProvider().bulkInsert(regularUri, new ContentValues[] { cv2 }); + assertEquals(1, regularInserted); + after3 = System.currentTimeMillis(); + + deleted2 = new FormHistoryRecord("guid4", "forms", -1, true); + final ContentValues cv4 = new ContentValues(); + cv4.put(BrowserContract.FormHistory.GUID, deleted2.guid); + // cv4.put(BrowserContract.DeletedFormHistory.TIME_DELETED, record4.lastModified); // Set by CP. + + int deletedInserted = session.getFormsProvider().bulkInsert(deletedUri, new ContentValues[] { cv4 }); + assertEquals(1, deletedInserted); + after4 = System.currentTimeMillis(); + } + + public void testWipe() throws NoContentProviderException, RemoteException { + final FormHistoryRepositorySession session = createAndBeginSession(); + + insertTwoRecords(session); + assertTrue(numRecords(session, BrowserContractHelpers.FORM_HISTORY_CONTENT_URI) > 0); + assertTrue(numRecords(session, BrowserContractHelpers.DELETED_FORM_HISTORY_CONTENT_URI) > 0); + + performWait(WaitHelper.onThreadRunnable(new Runnable() { + @Override + public void run() { + session.wipe(new RepositorySessionWipeDelegate() { + public void onWipeSucceeded() { + performNotify(); + } + public void onWipeFailed(Exception ex) { + performNotify("Wipe should have succeeded", ex); + } + @Override + public RepositorySessionWipeDelegate deferredWipeDelegate(final ExecutorService executor) { + return this; + } + }); + } + })); + + assertEquals(0, numRecords(session, BrowserContractHelpers.FORM_HISTORY_CONTENT_URI)); + assertEquals(0, numRecords(session, BrowserContractHelpers.DELETED_FORM_HISTORY_CONTENT_URI)); + + session.abort(); + } + + protected Runnable fetchSinceRunnable(final RepositorySession session, final long timestamp, final String[] expectedGuids) { + return new Runnable() { + @Override + public void run() { + session.fetchSince(timestamp, new ExpectFetchSinceDelegate(timestamp, expectedGuids)); + } + }; + } + + protected Runnable fetchAllRunnable(final RepositorySession session, final Record[] expectedRecords) { + return new Runnable() { + @Override + public void run() { + session.fetchAll(new ExpectFetchDelegate(expectedRecords)); + } + }; + } + + protected Runnable fetchRunnable(final RepositorySession session, final String[] guids, final Record[] expectedRecords) { + return new Runnable() { + @Override + public void run() { + try { + session.fetch(guids, new ExpectFetchDelegate(expectedRecords)); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + }; + } + + public void testFetchAll() throws NoContentProviderException, RemoteException { + final FormHistoryRepositorySession session = createAndBeginSession(); + + insertTwoRecords(session); + + performWait(fetchAllRunnable(session, new Record[] { regular1, deleted1 })); + + session.abort(); + } + + public void testFetchByGuid() throws NoContentProviderException, RemoteException { + final FormHistoryRepositorySession session = createAndBeginSession(); + + insertTwoRecords(session); + + performWait(fetchRunnable(session, + new String[] { regular1.guid, deleted1.guid }, + new Record[] { regular1, deleted1 })); + performWait(fetchRunnable(session, + new String[] { regular1.guid }, + new Record[] { regular1 })); + performWait(fetchRunnable(session, + new String[] { deleted1.guid, "NON_EXISTENT_GUID?" }, + new Record[] { deleted1 })); + performWait(fetchRunnable(session, + new String[] { "FIRST_NON_EXISTENT_GUID", "SECOND_NON_EXISTENT_GUID?" }, + new Record[] { })); + + session.abort(); + } + + public void testFetchSince() throws NoContentProviderException, RemoteException { + final FormHistoryRepositorySession session = createAndBeginSession(); + + insertFourRecords(session); + + performWait(fetchSinceRunnable(session, + after0, new String[] { regular1.guid, deleted1.guid, regular2.guid, deleted2.guid })); + performWait(fetchSinceRunnable(session, + after1, new String[] { deleted1.guid, regular2.guid, deleted2.guid })); + performWait(fetchSinceRunnable(session, + after2, new String[] { regular2.guid, deleted2.guid })); + performWait(fetchSinceRunnable(session, + after3, new String[] { deleted2.guid })); + performWait(fetchSinceRunnable(session, + after4, new String[] { })); + + session.abort(); + } + + protected Runnable guidsSinceRunnable(final RepositorySession session, final long timestamp, final String[] expectedGuids) { + return new Runnable() { + @Override + public void run() { + session.guidsSince(timestamp, new ExpectGuidsSinceDelegate(expectedGuids)); + } + }; + } + + public void testGuidsSince() throws NoContentProviderException, RemoteException { + final FormHistoryRepositorySession session = createAndBeginSession(); + + insertTwoRecords(session); + + performWait(guidsSinceRunnable(session, + after0, new String[] { regular1.guid, deleted1.guid })); + performWait(guidsSinceRunnable(session, + after1, new String[] { deleted1.guid})); + performWait(guidsSinceRunnable(session, + after2, new String[] { })); + + session.abort(); + } + + protected Runnable storeRunnable(final RepositorySession session, final Record record, final RepositorySessionStoreDelegate delegate) { + return new Runnable() { + @Override + public void run() { + session.setStoreDelegate(delegate); + try { + session.store(record); + session.storeDone(); + } catch (NoStoreDelegateException e) { + performNotify("NoStoreDelegateException should not occur.", e); + } + } + }; + } + + public void testStoreRemoteNew() throws NoContentProviderException, RemoteException { + final FormHistoryRepositorySession session = createAndBeginSession(); + + insertTwoRecords(session); + + FormHistoryRecord rec; + + // remote regular, local missing => should store. + rec = new FormHistoryRecord("new1", "forms", System.currentTimeMillis(), false); + rec.fieldName = "fieldName1"; + rec.fieldValue = "fieldValue1"; + performWait(storeRunnable(session, rec, new ExpectStoredDelegate(rec.guid))); + performWait(fetchRunnable(session, new String[] { rec.guid }, new Record[] { rec })); + + // remote deleted, local missing => should delete, but at the moment we ignore. + rec = new FormHistoryRecord("new2", "forms", System.currentTimeMillis(), true); + performWait(storeRunnable(session, rec, new ExpectNoStoreDelegate())); + performWait(fetchRunnable(session, new String[] { rec.guid }, new Record[] { })); + + session.abort(); + } + + public void testStoreRemoteNewer() throws NoContentProviderException, RemoteException { + final FormHistoryRepositorySession session = createAndBeginSession(); + + insertFourRecords(session); + long newTimestamp = System.currentTimeMillis(); + + FormHistoryRecord rec; + + // remote regular, local regular, remote newer => should update. + rec = new FormHistoryRecord(regular1.guid, regular1.collection, newTimestamp, false); + rec.fieldName = regular1.fieldName; + rec.fieldValue = regular1.fieldValue + "NEW"; + performWait(storeRunnable(session, rec, new ExpectStoredDelegate(rec.guid))); + performWait(fetchRunnable(session, new String[] { regular1.guid }, new Record[] { rec })); + + // remote deleted, local regular, remote newer => should delete everything. + rec = new FormHistoryRecord(regular2.guid, regular2.collection, newTimestamp, true); + performWait(storeRunnable(session, rec, new ExpectStoredDelegate(rec.guid))); + performWait(fetchRunnable(session, new String[] { regular2.guid }, new Record[] { })); + + // remote regular, local deleted, remote newer => should update. + rec = new FormHistoryRecord(deleted1.guid, deleted1.collection, newTimestamp, false); + rec.fieldName = regular1.fieldName; + rec.fieldValue = regular1.fieldValue + "NEW"; + performWait(storeRunnable(session, rec, new ExpectStoredDelegate(rec.guid))); + performWait(fetchRunnable(session, new String[] { deleted1.guid }, new Record[] { rec })); + + // remote deleted, local deleted, remote newer => should delete everything. + rec = new FormHistoryRecord(deleted2.guid, deleted2.collection, newTimestamp, true); + performWait(storeRunnable(session, rec, new ExpectNoStoreDelegate())); + performWait(fetchRunnable(session, new String[] { deleted2.guid }, new Record[] { })); + + session.abort(); + } + + public void testStoreRemoteOlder() throws NoContentProviderException, RemoteException { + final FormHistoryRepositorySession session = createAndBeginSession(); + + long oldTimestamp = System.currentTimeMillis() - 100; + insertFourRecords(session); + + FormHistoryRecord rec; + + // remote regular, local regular, remote older => should ignore. + rec = new FormHistoryRecord(regular1.guid, regular1.collection, oldTimestamp, false); + rec.fieldName = regular1.fieldName; + rec.fieldValue = regular1.fieldValue + "NEW"; + performWait(storeRunnable(session, rec, new ExpectNoStoreDelegate())); + + // remote deleted, local regular, remote older => should ignore. + rec = new FormHistoryRecord(regular2.guid, regular2.collection, oldTimestamp, true); + performWait(storeRunnable(session, rec, new ExpectNoStoreDelegate())); + + // remote regular, local deleted, remote older => should ignore. + rec = new FormHistoryRecord(deleted1.guid, deleted1.collection, oldTimestamp, false); + rec.fieldName = regular1.fieldName; + rec.fieldValue = regular1.fieldValue + "NEW"; + performWait(storeRunnable(session, rec, new ExpectNoStoreDelegate())); + + // remote deleted, local deleted, remote older => should ignore. + rec = new FormHistoryRecord(deleted2.guid, deleted2.collection, oldTimestamp, true); + performWait(storeRunnable(session, rec, new ExpectNoStoreDelegate())); + + session.abort(); + } + + public void testStoreDifferentGuid() throws NoContentProviderException, RemoteException { + final FormHistoryRepositorySession session = createAndBeginSession(); + + insertTwoRecords(session); + + FormHistoryRecord rec = (FormHistoryRecord) regular1.copyWithIDs("distinct", 999); + performWait(storeRunnable(session, rec, new ExpectStoredDelegate(rec.guid))); + // Existing record should take remote record's GUID. + performWait(fetchAllRunnable(session, new Record[] { rec, deleted1 })); + + session.abort(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestPasswordsRepository.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestPasswordsRepository.java new file mode 100644 index 000000000..210c8ca8c --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestPasswordsRepository.java @@ -0,0 +1,482 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import java.util.HashSet; +import java.util.Set; + +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.background.sync.helpers.ExpectFetchDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectFetchSinceDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectGuidsSinceDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectNoStoreDelegate; +import org.mozilla.gecko.background.sync.helpers.ExpectStoredDelegate; +import org.mozilla.gecko.background.sync.helpers.PasswordHelpers; +import org.mozilla.gecko.background.sync.helpers.SessionTestHelper; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; +import org.mozilla.gecko.sync.repositories.android.PasswordsRepositorySession; +import org.mozilla.gecko.sync.repositories.android.RepoUtils; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; +import org.mozilla.gecko.sync.repositories.domain.PasswordRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import android.content.ContentProviderClient; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.os.RemoteException; + +public class TestPasswordsRepository extends AndroidSyncTestCase { + private final String NEW_PASSWORD1 = "password"; + private final String NEW_PASSWORD2 = "drowssap"; + + @Override + public void setUp() { + wipe(); + assertTrue(WaitHelper.getTestWaiter().isIdle()); + } + + public void testFetchAll() { + RepositorySession session = createAndBeginSession(); + Record[] expected = new Record[] { PasswordHelpers.createPassword1(), + PasswordHelpers.createPassword2() }; + + performWait(storeRunnable(session, expected[0])); + performWait(storeRunnable(session, expected[1])); + + performWait(fetchAllRunnable(session, expected)); + dispose(session); + } + + public void testGuidsSinceReturnMultipleRecords() { + RepositorySession session = createAndBeginSession(); + + PasswordRecord record1 = PasswordHelpers.createPassword1(); + PasswordRecord record2 = PasswordHelpers.createPassword2(); + + updatePassword(NEW_PASSWORD1, record1); + long timestamp = updatePassword(NEW_PASSWORD2, record2); + + String[] expected = new String[] { record1.guid, record2.guid }; + + performWait(storeRunnable(session, record1)); + performWait(storeRunnable(session, record2)); + + performWait(guidsSinceRunnable(session, timestamp, expected)); + dispose(session); + } + + public void testGuidsSinceReturnNoRecords() { + RepositorySession session = createAndBeginSession(); + + // Store 1 record in the past. + performWait(storeRunnable(session, PasswordHelpers.createPassword1())); + + String[] expected = {}; + performWait(guidsSinceRunnable(session, System.currentTimeMillis() + 1000, expected)); + dispose(session); + } + + public void testFetchSinceOneRecord() { + RepositorySession session = createAndBeginSession(); + + // Passwords fetchSince checks timePasswordChanged, not insertion time. + PasswordRecord record1 = PasswordHelpers.createPassword1(); + long timeModified1 = updatePassword(NEW_PASSWORD1, record1); + performWait(storeRunnable(session, record1)); + + PasswordRecord record2 = PasswordHelpers.createPassword2(); + long timeModified2 = updatePassword(NEW_PASSWORD2, record2); + performWait(storeRunnable(session, record2)); + + String[] expectedOne = new String[] { record2.guid }; + performWait(fetchSinceRunnable(session, timeModified2 - 10, expectedOne)); + + String[] expectedBoth = new String[] { record1.guid, record2.guid }; + performWait(fetchSinceRunnable(session, timeModified1 - 10, expectedBoth)); + + dispose(session); + } + + public void testFetchSinceReturnNoRecords() { + RepositorySession session = createAndBeginSession(); + + performWait(storeRunnable(session, PasswordHelpers.createPassword2())); + + long timestamp = System.currentTimeMillis(); + + performWait(fetchSinceRunnable(session, timestamp + 2000, new String[] {})); + dispose(session); + } + + public void testFetchOneRecordByGuid() { + RepositorySession session = createAndBeginSession(); + Record record = PasswordHelpers.createPassword1(); + performWait(storeRunnable(session, record)); + performWait(storeRunnable(session, PasswordHelpers.createPassword2())); + + String[] guids = new String[] { record.guid }; + Record[] expected = new Record[] { record }; + performWait(fetchRunnable(session, guids, expected)); + dispose(session); + } + + public void testFetchMultipleRecordsByGuids() { + RepositorySession session = createAndBeginSession(); + PasswordRecord record1 = PasswordHelpers.createPassword1(); + PasswordRecord record2 = PasswordHelpers.createPassword2(); + PasswordRecord record3 = PasswordHelpers.createPassword3(); + + performWait(storeRunnable(session, record1)); + performWait(storeRunnable(session, record2)); + performWait(storeRunnable(session, record3)); + + String[] guids = new String[] { record1.guid, record2.guid }; + Record[] expected = new Record[] { record1, record2 }; + performWait(fetchRunnable(session, guids, expected)); + dispose(session); + } + + public void testFetchNoRecordByGuid() { + RepositorySession session = createAndBeginSession(); + Record record = PasswordHelpers.createPassword1(); + + performWait(storeRunnable(session, record)); + performWait(fetchRunnable(session, + new String[] { Utils.generateGuid() }, + new Record[] {})); + dispose(session); + } + + public void testStore() { + final RepositorySession session = createAndBeginSession(); + performWait(storeRunnable(session, PasswordHelpers.createPassword1())); + dispose(session); + } + + public void testRemoteNewerTimeStamp() { + final RepositorySession session = createAndBeginSession(); + + // Store updated local record. + PasswordRecord local = PasswordHelpers.createPassword1(); + updatePassword(NEW_PASSWORD1, local, System.currentTimeMillis() - 1000); + performWait(storeRunnable(session, local)); + + // Sync a remote record version that is newer. + PasswordRecord remote = PasswordHelpers.createPassword2(); + remote.guid = local.guid; + updatePassword(NEW_PASSWORD2, remote); + performWait(storeRunnable(session, remote)); + + // Make a fetch, expecting only the newer (remote) record. + performWait(fetchAllRunnable(session, new Record[] { remote })); + + // Store an older local record. + PasswordRecord local2 = PasswordHelpers.createPassword3(); + updatePassword(NEW_PASSWORD2, local2, System.currentTimeMillis() - 1000); + performWait(storeRunnable(session, local2)); + + // Sync a remote record version that is newer and is deleted. + PasswordRecord remote2 = PasswordHelpers.createPassword3(); + remote2.guid = local2.guid; + remote2.deleted = true; + updatePassword(NEW_PASSWORD2, remote2); + performWait(storeRunnable(session, remote2)); + + // Make a fetch, expecting the local record to be deleted. + performWait(fetchRunnable(session, new String[] { remote2.guid }, new Record[] {})); + + // Store an older deleted local record. + PasswordRecord local3 = PasswordHelpers.createPassword4(); + updatePassword(NEW_PASSWORD2, local3, System.currentTimeMillis() - 1000); + local3.deleted = true; + storeLocalDeletedRecord(local3, System.currentTimeMillis() - 1000); + + // Sync a remote record version that is newer and is deleted. + PasswordRecord remote3 = PasswordHelpers.createPassword5(); + remote3.guid = local3.guid; + remote3.deleted = true; + updatePassword(NEW_PASSWORD2, remote3); + performWait(storeRunnable(session, remote3)); + + // Make a fetch, expecting the local record to be deleted. + performWait(fetchRunnable(session, new String[] { remote3.guid }, new Record[] {})); + dispose(session); + } + + public void testLocalNewerTimeStamp() { + final RepositorySession session = createAndBeginSession(); + // Remote record updated before local record. + PasswordRecord remote = PasswordHelpers.createPassword1(); + updatePassword(NEW_PASSWORD1, remote, System.currentTimeMillis() - 1000); + + // Store updated local record. + PasswordRecord local = PasswordHelpers.createPassword2(); + updatePassword(NEW_PASSWORD2, local); + performWait(storeRunnable(session, local)); + + // Sync a remote record version that is older. + remote.guid = local.guid; + performWait(storeRunnable(session, remote)); + + // Make a fetch, expecting only the newer (local) record. + performWait(fetchAllRunnable(session, new Record[] { local })); + + // Remote record updated before local record. + PasswordRecord remote2 = PasswordHelpers.createPassword3(); + updatePassword(NEW_PASSWORD1, remote2, System.currentTimeMillis() - 1000); + + // Store updated local record that is deleted. + PasswordRecord local2 = PasswordHelpers.createPassword3(); + updatePassword(NEW_PASSWORD2, local2); + local2.deleted = true; + storeLocalDeletedRecord(local2, System.currentTimeMillis()); + + // Sync a remote record version that is older. + remote2.guid = local2.guid; + performWait(storeRunnable(session, remote2, new ExpectNoStoreDelegate())); + + // Make a fetch, expecting only the deleted newer (local) record. + performWait(fetchRunnable(session, new String[] { local2.guid }, new Record[] { local2 })); + + // Remote record updated before local record. + PasswordRecord remote3 = PasswordHelpers.createPassword4(); + updatePassword(NEW_PASSWORD1, remote3, System.currentTimeMillis() - 1000); + + // Store updated local record that is deleted. + PasswordRecord local3 = PasswordHelpers.createPassword4(); + updatePassword(NEW_PASSWORD2, local3); + local3.deleted = true; + storeLocalDeletedRecord(local3, System.currentTimeMillis()); + + // Sync a remote record version that is older and is deleted. + remote3.guid = local3.guid; + remote3.deleted = true; + performWait(storeRunnable(session, remote3)); + + // Make a fetch, expecting the local record to be deleted. + performWait(fetchRunnable(session, new String[] { local3.guid }, new Record[] {})); + dispose(session); + } + + /* + * Store two records that are identical except for guid. Expect to find the + * remote one after reconciling. + */ + public void testStoreIdenticalExceptGuid() { + RepositorySession session = createAndBeginSession(); + PasswordRecord record = PasswordHelpers.createPassword1(); + record.guid = "before1"; + // Store record. + performWait(storeRunnable(session, record)); + + // Store same record, but with different guid. + record.guid = Utils.generateGuid(); + performWait(storeRunnable(session, record)); + + performWait(fetchAllRunnable(session, new Record[] { record })); + dispose(session); + + session = createAndBeginSession(); + + PasswordRecord record2 = PasswordHelpers.createPassword2(); + record2.guid = "before2"; + // Store record. + performWait(storeRunnable(session, record2)); + + // Store same record, but with different guid. + record2.guid = Utils.generateGuid(); + performWait(storeRunnable(session, record2)); + + performWait(fetchAllRunnable(session, new Record[] { record, record2 })); + dispose(session); + } + + /* + * Store two records that are identical except for guid when they both point + * to the same site and there are multiple records for that site. Expect to + * find the remote one after reconciling. + */ + public void testStoreIdenticalExceptGuidOnSameSite() { + RepositorySession session = createAndBeginSession(); + PasswordRecord record1 = PasswordHelpers.createPassword1(); + record1.encryptedUsername = "original"; + record1.guid = "before1"; + PasswordRecord record2 = PasswordHelpers.createPassword1(); + record2.encryptedUsername = "different"; + record1.guid = "before2"; + // Store records. + performWait(storeRunnable(session, record1)); + performWait(storeRunnable(session, record2)); + performWait(fetchAllRunnable(session, new Record[] { record1, record2 })); + + dispose(session); + session = createAndBeginSession(); + + // Store same records, but with different guids. + record1.guid = Utils.generateGuid(); + performWait(storeRunnable(session, record1)); + performWait(fetchAllRunnable(session, new Record[] { record1, record2 })); + + record2.guid = Utils.generateGuid(); + performWait(storeRunnable(session, record2)); + performWait(fetchAllRunnable(session, new Record[] { record1, record2 })); + + dispose(session); + } + + public void testRawFetch() throws RemoteException { + RepositorySession session = createAndBeginSession(); + Record[] expected = new Record[] { PasswordHelpers.createPassword1(), + PasswordHelpers.createPassword2() }; + + performWait(storeRunnable(session, expected[0])); + performWait(storeRunnable(session, expected[1])); + + ContentProviderClient client = getApplicationContext().getContentResolver().acquireContentProviderClient(BrowserContract.PASSWORDS_AUTHORITY_URI); + Cursor cursor = client.query(BrowserContractHelpers.PASSWORDS_CONTENT_URI, null, null, null, null); + assertEquals(2, cursor.getCount()); + cursor.moveToFirst(); + Set guids = new HashSet(); + while (!cursor.isAfterLast()) { + String guid = RepoUtils.getStringFromCursor(cursor, BrowserContract.Passwords.GUID); + guids.add(guid); + cursor.moveToNext(); + } + cursor.close(); + assertEquals(2, guids.size()); + assertTrue(guids.contains(expected[0].guid)); + assertTrue(guids.contains(expected[1].guid)); + dispose(session); + } + + // Helper methods. + private RepositorySession createAndBeginSession() { + return SessionTestHelper.createAndBeginSession( + getApplicationContext(), + getRepository()); + } + + private Repository getRepository() { + /** + * Override this chain in order to avoid our test code having to create two + * sessions all the time. Don't track records, so they filtering doesn't happen. + */ + return new PasswordsRepositorySession.PasswordsRepository() { + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + PasswordsRepositorySession session; + session = new PasswordsRepositorySession(this, context) { + @Override + protected synchronized void trackGUID(String guid) { + } + }; + delegate.onSessionCreated(session); + } + }; + } + + private void wipe() { + Context context = getApplicationContext(); + context.getContentResolver().delete(BrowserContractHelpers.PASSWORDS_CONTENT_URI, null, null); + context.getContentResolver().delete(BrowserContractHelpers.DELETED_PASSWORDS_CONTENT_URI, null, null); + } + + private void storeLocalDeletedRecord(Record record, long time) { + // Wipe data-store + wipe(); + // Store record in deleted table. + ContentValues contentValues = new ContentValues(); + contentValues.put(BrowserContract.DeletedColumns.GUID, record.guid); + contentValues.put(BrowserContract.DeletedColumns.TIME_DELETED, time); + contentValues.put(BrowserContract.DeletedColumns.ID, record.androidID); + getApplicationContext().getContentResolver().insert(BrowserContractHelpers.DELETED_PASSWORDS_CONTENT_URI, contentValues); + } + + private static void dispose(RepositorySession session) { + if (session != null) { + session.abort(); + } + } + + private static long updatePassword(String password, PasswordRecord record, long timestamp) { + record.encryptedPassword = password; + long modifiedTime = System.currentTimeMillis(); + record.timePasswordChanged = record.lastModified = modifiedTime; + return modifiedTime; + } + + private static long updatePassword(String password, PasswordRecord record) { + return updatePassword(password, record, System.currentTimeMillis()); + } + + // Runnable Helpers. + private static Runnable storeRunnable(final RepositorySession session, final Record record) { + return storeRunnable(session, record, new ExpectStoredDelegate(record.guid)); + } + + private static Runnable storeRunnable(final RepositorySession session, final Record record, final RepositorySessionStoreDelegate delegate) { + return new Runnable() { + @Override + public void run() { + session.setStoreDelegate(delegate); + try { + session.store(record); + session.storeDone(); + } catch (NoStoreDelegateException e) { + fail("NoStoreDelegateException should not occur."); + } + } + }; + } + + private static Runnable fetchAllRunnable(final RepositorySession session, final Record[] records) { + return new Runnable() { + @Override + public void run() { + session.fetchAll(new ExpectFetchDelegate(records)); + } + }; + } + + private static Runnable guidsSinceRunnable(final RepositorySession session, final long timestamp, final String[] expected) { + return new Runnable() { + @Override + public void run() { + session.guidsSince(timestamp, new ExpectGuidsSinceDelegate(expected)); + } + }; + } + + private static Runnable fetchSinceRunnable(final RepositorySession session, final long timestamp, final String[] expected) { + return new Runnable() { + @Override + public void run() { + session.fetchSince(timestamp, new ExpectFetchSinceDelegate(timestamp, expected)); + } + }; + } + + private static Runnable fetchRunnable(final RepositorySession session, final String[] guids, final Record[] expected) { + return new Runnable() { + @Override + public void run() { + try { + session.fetch(guids, new ExpectFetchDelegate(expected)); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + }; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestTopSites.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestTopSites.java new file mode 100644 index 000000000..003fc7172 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/db/TestTopSites.java @@ -0,0 +1,92 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + + +import org.mozilla.gecko.GeckoProfile; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.db.BrowserDB; +import org.mozilla.gecko.db.BrowserContract.Combined; +import org.mozilla.gecko.db.SuggestedSites; +import org.mozilla.gecko.sync.setup.Constants; + +import android.app.Activity; +import android.content.ContentResolver; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; +import android.test.ActivityInstrumentationTestCase2; + +/** + * Exercise BrowserDB's getTopSites + * + * @author ahunt + * + */ +public class TestTopSites extends ActivityInstrumentationTestCase2 { + Context mContext; + SuggestedSites mSuggestedSites; + + public TestTopSites() { + super(Activity.class); + } + + @Override + public void setUp() { + mContext = getInstrumentation().getTargetContext(); + mSuggestedSites = new SuggestedSites(mContext); + + // By default we're using StubBrowserDB which has no suggested sites available. + BrowserDB.from(GeckoProfile.get(mContext, Constants.DEFAULT_PROFILE)).setSuggestedSites(mSuggestedSites); + } + + @Override + public void tearDown() { + BrowserDB.from(GeckoProfile.get(mContext, Constants.DEFAULT_PROFILE)).setSuggestedSites(null); + } + + public void testGetTopSites() { + final int SUGGESTED_LIMIT = 6; + final int TOTAL_LIMIT = 50; + + ContentResolver cr = mContext.getContentResolver(); + + final Uri uri = BrowserContract.TopSites.CONTENT_URI + .buildUpon() + .appendQueryParameter(BrowserContract.PARAM_PROFILE, + Constants.DEFAULT_PROFILE) + .appendQueryParameter(BrowserContract.PARAM_LIMIT, + String.valueOf(SUGGESTED_LIMIT)) + .appendQueryParameter(BrowserContract.PARAM_SUGGESTEDSITES_LIMIT, + String.valueOf(TOTAL_LIMIT)) + .build(); + + final Cursor c = cr.query(uri, + new String[] { Combined._ID, + Combined.URL, + Combined.TITLE, + Combined.BOOKMARK_ID, + Combined.HISTORY_ID }, + null, + null, + null); + + int suggestedCount = 0; + try { + while (c.moveToNext()) { + int type = c.getInt(c.getColumnIndexOrThrow(BrowserContract.Bookmarks.TYPE)); + assertEquals(BrowserContract.TopSites.TYPE_SUGGESTED, type); + suggestedCount++; + } + } finally { + c.close(); + } + + Cursor suggestedSitesCursor = mSuggestedSites.get(SUGGESTED_LIMIT); + + assertEquals(suggestedSitesCursor.getCount(), suggestedCount); + + suggestedSitesCursor.close(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestAccountLoader.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestAccountLoader.java new file mode 100644 index 000000000..3009cac3e --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestAccountLoader.java @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package org.mozilla.gecko.background.fxa; + +import android.accounts.Account; +import android.content.Context; +import android.content.Loader; +import android.os.AsyncTask; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; + +import org.mozilla.gecko.background.sync.AndroidSyncTestCaseWithAccounts; +import org.mozilla.gecko.fxa.AccountLoader; +import org.mozilla.gecko.fxa.FirefoxAccounts; +import org.mozilla.gecko.fxa.FxAccountConstants; +import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount; +import org.mozilla.gecko.fxa.login.Separated; +import org.mozilla.gecko.fxa.login.State; + +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.security.GeneralSecurityException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.atomic.AtomicReference; + +/** + * A version of https://android.googlesource.com/platform/frameworks/base/+/c91893511dc1b9e634648406c9ae61b15476e65d/test-runner/src/android/test/LoaderTestCase.java, + * hacked to work with the v4 support library, and patched to work around + * https://code.google.com/p/android/issues/detail?id=40987. + */ +public class TestAccountLoader extends AndroidSyncTestCaseWithAccounts { + // Test account names must start with TEST_USERNAME in order to be recognized + // as test accounts and deleted in tearDown. + private static final String TEST_USERNAME = "testAccount@mozilla.com"; + private static final String TEST_ACCOUNTTYPE = FxAccountConstants.ACCOUNT_TYPE; + + private static final String TEST_SYNCKEY = "testSyncKey"; + private static final String TEST_SYNCPASSWORD = "testSyncPassword"; + + private static final String TEST_TOKEN_SERVER_URI = "testTokenServerURI"; + private static final String TEST_PROFILE_SERVER_URI = "testProfileServerURI"; + private static final String TEST_AUTH_SERVER_URI = "testAuthServerURI"; + private static final String TEST_PROFILE = "testProfile"; + + public TestAccountLoader() { + super(TEST_ACCOUNTTYPE, TEST_USERNAME); + } + + static { + // Force class loading of AsyncTask on the main thread so that it's handlers are tied to + // the main thread and responses from the worker thread get delivered on the main thread. + // The tests are run on another thread, allowing them to block waiting on a response from + // the code running on the main thread. The main thread can't block since the AsyncTask + // results come in via the event loop. + new AsyncTask() { + @Override + protected Void doInBackground(Void... args) { + return null; + } + + @Override + protected void onPostExecute(Void result) { + } + }; + } + + /** + * Runs a Loader synchronously and returns the result of the load. The loader will + * be started, stopped, and destroyed by this method so it cannot be reused. + * + * @param loader The loader to run synchronously + * @return The result from the loader + */ + public T getLoaderResultSynchronously(final Loader loader) { + // The test thread blocks on this queue until the loader puts it's result in + final ArrayBlockingQueue> queue = new ArrayBlockingQueue>(1); + + // This callback runs on the "main" thread and unblocks the test thread + // when it puts the result into the blocking queue + final Loader.OnLoadCompleteListener listener = new Loader.OnLoadCompleteListener() { + @Override + public void onLoadComplete(Loader completedLoader, T data) { + // Shut the loader down + completedLoader.unregisterListener(this); + completedLoader.stopLoading(); + completedLoader.reset(); + // Store the result, unblocking the test thread + queue.add(new AtomicReference(data)); + } + }; + + // This handler runs on the "main" thread of the process since AsyncTask + // is documented as needing to run on the main thread and many Loaders use + // AsyncTask + final Handler mainThreadHandler = new Handler(Looper.getMainLooper()) { + @Override + public void handleMessage(Message msg) { + loader.registerListener(0, listener); + loader.startLoading(); + } + }; + + // Ask the main thread to start the loading process + mainThreadHandler.sendEmptyMessage(0); + + // Block on the queue waiting for the result of the load to be inserted + T result; + while (true) { + try { + result = queue.take().get(); + break; + } catch (InterruptedException e) { + throw new RuntimeException("waiting thread interrupted", e); + } + } + return result; + } + + public void testInitialLoad() throws UnsupportedEncodingException, GeneralSecurityException, URISyntaxException { + // This is tricky. We can't mock the AccountManager easily -- see + // https://groups.google.com/d/msg/android-mock/VXyzvKTMUGs/Y26wVPrl50sJ -- + // and we don't want to delete any existing accounts on device. So our test + // needs to be adaptive (and therefore a little race-prone). + + final Context context = getApplicationContext(); + final AccountLoader loader = new AccountLoader(context); + + final boolean firefoxAccountsExist = FirefoxAccounts.firefoxAccountsExist(context); + + if (firefoxAccountsExist) { + assertFirefoxAccount(getLoaderResultSynchronously((Loader) loader)); + return; + } + + // This account will get cleaned up in tearDown. + final State state = new Separated(TEST_USERNAME, "uid", false); // State choice is arbitrary. + final AndroidFxAccount account = AndroidFxAccount.addAndroidAccount(context, + TEST_USERNAME, TEST_PROFILE, TEST_AUTH_SERVER_URI, TEST_TOKEN_SERVER_URI, TEST_PROFILE_SERVER_URI, + state, AndroidSyncTestCaseWithAccounts.TEST_SYNC_AUTOMATICALLY_MAP_WITH_ALL_AUTHORITIES_DISABLED); + assertNotNull(account); + assertFirefoxAccount(getLoaderResultSynchronously((Loader) loader)); + } + + protected void assertFirefoxAccount(Account account) { + assertNotNull(account); + assertEquals(FxAccountConstants.ACCOUNT_TYPE, account.type); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestBrowserIDKeyPairGeneration.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestBrowserIDKeyPairGeneration.java new file mode 100644 index 000000000..18fb58a97 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/TestBrowserIDKeyPairGeneration.java @@ -0,0 +1,49 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.fxa; + +import java.security.GeneralSecurityException; + +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.browserid.BrowserIDKeyPair; +import org.mozilla.gecko.browserid.DSACryptoImplementation; +import org.mozilla.gecko.browserid.JSONWebTokenUtils; +import org.mozilla.gecko.browserid.RSACryptoImplementation; +import org.mozilla.gecko.browserid.SigningPrivateKey; +import org.mozilla.gecko.browserid.VerifyingPublicKey; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.Utils; + +public class TestBrowserIDKeyPairGeneration extends AndroidSyncTestCase { + public void doTestEncodeDecode(BrowserIDKeyPair keyPair) throws Exception { + SigningPrivateKey privateKey = keyPair.getPrivate(); + VerifyingPublicKey publicKey = keyPair.getPublic(); + + ExtendedJSONObject o = new ExtendedJSONObject(); + o.put("key", Utils.generateGuid()); + + String token = JSONWebTokenUtils.encode(o.toJSONString(), privateKey); + assertNotNull(token); + + String payload = JSONWebTokenUtils.decode(token, publicKey); + assertEquals(o.toJSONString(), payload); + + try { + JSONWebTokenUtils.decode(token + "x", publicKey); + fail("Expected exception."); + } catch (GeneralSecurityException e) { + // Do nothing. + } + } + + public void testEncodeDecodeSuccessRSA() throws Exception { + doTestEncodeDecode(RSACryptoImplementation.generateKeyPair(1024)); + doTestEncodeDecode(RSACryptoImplementation.generateKeyPair(2048)); + } + + public void testEncodeDecodeSuccessDSA() throws Exception { + doTestEncodeDecode(DSACryptoImplementation.generateKeyPair(512)); + doTestEncodeDecode(DSACryptoImplementation.generateKeyPair(1024)); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/authenticator/TestAccountPickler.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/authenticator/TestAccountPickler.java new file mode 100644 index 000000000..d50bd47e0 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/fxa/authenticator/TestAccountPickler.java @@ -0,0 +1,134 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.fxa.authenticator; + +import org.mozilla.gecko.background.sync.AndroidSyncTestCaseWithAccounts; +import org.mozilla.gecko.fxa.FxAccountConstants; +import org.mozilla.gecko.fxa.authenticator.AccountPickler; +import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount; +import org.mozilla.gecko.fxa.login.Separated; +import org.mozilla.gecko.fxa.login.State; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.Utils; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.test.RenamingDelegatingContext; + +public class TestAccountPickler extends AndroidSyncTestCaseWithAccounts { + private static final String TEST_TOKEN_SERVER_URI = "tokenServerURI"; + private static final String TEST_PROFILE_SERVER_URI = "profileServerURI"; + private static final String TEST_AUTH_SERVER_URI = "serverURI"; + private static final String TEST_PROFILE = "profile"; + private final static String FILENAME_PREFIX = "TestAccountPickler-"; + private final static String PICKLE_FILENAME = "pickle"; + + private final static String TEST_ACCOUNTTYPE = FxAccountConstants.ACCOUNT_TYPE; + + // Test account names must start with TEST_USERNAME in order to be recognized + // as test accounts and deleted in tearDown. + public static final String TEST_USERNAME = "testFirefoxAccount@mozilla.com"; + + public Account account; + public RenamingDelegatingContext context; + + public TestAccountPickler() { + super(TEST_ACCOUNTTYPE, TEST_USERNAME); + } + + @Override + public void setUp() { + super.setUp(); + this.account = null; + // Randomize the filename prefix in case we don't clean up correctly. + this.context = new RenamingDelegatingContext(getApplicationContext(), FILENAME_PREFIX + + Math.random() * 1000001 + "-"); + this.accountManager = AccountManager.get(context); + } + + @Override + public void tearDown() { + super.tearDown(); + this.context.deleteFile(PICKLE_FILENAME); + } + + public AndroidFxAccount addTestAccount() throws Exception { + final State state = new Separated(TEST_USERNAME, "uid", false); // State choice is arbitrary. + final AndroidFxAccount account = AndroidFxAccount.addAndroidAccount(context, TEST_USERNAME, + TEST_PROFILE, TEST_AUTH_SERVER_URI, TEST_TOKEN_SERVER_URI, TEST_PROFILE_SERVER_URI, state, + AndroidSyncTestCaseWithAccounts.TEST_SYNC_AUTOMATICALLY_MAP_WITH_ALL_AUTHORITIES_DISABLED); + assertNotNull(account); + assertNotNull(account.getProfile()); + assertTrue(testAccountsExist()); // Sanity check. + this.account = account.getAndroidAccount(); // To remove in tearDown() if we throw. + return account; + } + + public void testPickle() throws Exception { + final AndroidFxAccount account = addTestAccount(); + + final long now = System.currentTimeMillis(); + final ExtendedJSONObject o = AccountPickler.toJSON(account, now); + assertNotNull(o.toJSONString()); + + assertEquals(3, o.getLong(AccountPickler.KEY_PICKLE_VERSION).longValue()); + assertTrue(o.getLong(AccountPickler.KEY_PICKLE_TIMESTAMP).longValue() < System.currentTimeMillis()); + + assertEquals(AndroidFxAccount.CURRENT_ACCOUNT_VERSION, o.getIntegerSafely(AccountPickler.KEY_ACCOUNT_VERSION).intValue()); + assertEquals(FxAccountConstants.ACCOUNT_TYPE, o.getString(AccountPickler.KEY_ACCOUNT_TYPE)); + + assertEquals(TEST_USERNAME, o.getString(AccountPickler.KEY_EMAIL)); + assertEquals(TEST_PROFILE, o.getString(AccountPickler.KEY_PROFILE)); + assertEquals(TEST_AUTH_SERVER_URI, o.getString(AccountPickler.KEY_IDP_SERVER_URI)); + assertEquals(TEST_TOKEN_SERVER_URI, o.getString(AccountPickler.KEY_TOKEN_SERVER_URI)); + assertEquals(TEST_PROFILE_SERVER_URI, o.getString(AccountPickler.KEY_PROFILE_SERVER_URI)); + + assertNotNull(o.getObject(AccountPickler.KEY_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP)); + assertNotNull(o.get(AccountPickler.KEY_BUNDLE)); + } + + public void testPickleAndUnpickle() throws Exception { + final AndroidFxAccount inputAccount = addTestAccount(); + + AccountPickler.pickle(inputAccount, PICKLE_FILENAME); + final ExtendedJSONObject inputJSON = AccountPickler.toJSON(inputAccount, 0); + final State inputState = inputAccount.getState(); + assertNotNull(inputJSON); + assertNotNull(inputState); + + // unpickle adds an account to the AccountManager so delete it first. + deleteTestAccounts(); + assertFalse(testAccountsExist()); + + final AndroidFxAccount unpickledAccount = AccountPickler.unpickle(context, PICKLE_FILENAME); + assertNotNull(unpickledAccount); + final ExtendedJSONObject unpickledJSON = AccountPickler.toJSON(unpickledAccount, 0); + final State unpickledState = unpickledAccount.getState(); + assertNotNull(unpickledJSON); + assertNotNull(unpickledState); + + assertEquals(inputJSON, unpickledJSON); + assertStateEquals(inputState, unpickledState); + } + + public void testDeletePickle() throws Exception { + final AndroidFxAccount account = addTestAccount(); + AccountPickler.pickle(account, PICKLE_FILENAME); + + final String s = Utils.readFile(context, PICKLE_FILENAME); + assertNotNull(s); + assertTrue(s.length() > 0); + + AccountPickler.deletePickle(context, PICKLE_FILENAME); + assertFileNotPresent(context, PICKLE_FILENAME); + } + + private void assertStateEquals(final State expected, final State actual) throws Exception { + // TODO: Write and use State.equals. Thus, this is only thorough for the State base class. + assertEquals(expected.getStateLabel(), actual.getStateLabel()); + assertEquals(expected.email, actual.email); + assertEquals(expected.uid, actual.uid); + assertEquals(expected.verified, actual.verified); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/AndroidSyncTestCase.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/AndroidSyncTestCase.java new file mode 100644 index 000000000..5cdbe44f4 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/AndroidSyncTestCase.java @@ -0,0 +1,52 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.helpers; + +import junit.framework.AssertionFailedError; + +import org.mozilla.gecko.background.testhelpers.WaitHelper; + +import android.app.Activity; +import android.content.Context; +import android.test.ActivityInstrumentationTestCase2; + +/** + * AndroidSyncTestCase provides helper methods for testing. + */ +public class AndroidSyncTestCase extends ActivityInstrumentationTestCase2 { + protected static String LOG_TAG = "AndroidSyncTestCase"; + + public AndroidSyncTestCase() { + super(Activity.class); + WaitHelper.resetTestWaiter(); + } + + public Context getApplicationContext() { + return this.getInstrumentation().getTargetContext(); + } + + public static void performWait(Runnable runnable) { + try { + WaitHelper.getTestWaiter().performWait(runnable); + } catch (WaitHelper.InnerError e) { + AssertionFailedError inner = new AssertionFailedError("Caught error in performWait"); + inner.initCause(e.innerError); + throw inner; + } + } + + public static void performNotify() { + WaitHelper.getTestWaiter().performNotify(); + } + + public static void performNotify(Throwable e) { + WaitHelper.getTestWaiter().performNotify(e); + } + + public static void performNotify(String reason, Throwable e) { + AssertionFailedError er = new AssertionFailedError(reason + ": " + e.getMessage()); + er.initCause(e); + WaitHelper.getTestWaiter().performNotify(er); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/DBHelpers.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/DBHelpers.java new file mode 100644 index 000000000..c37f1e8bd --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/DBHelpers.java @@ -0,0 +1,84 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.helpers; + +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import junit.framework.Assert; + +public class DBHelpers { + + /* + * Works for strings and int-ish values. + */ + public static void assertCursorContains(Object[][] expected, Cursor actual) { + Assert.assertEquals(expected.length, actual.getCount()); + int i = 0, j = 0; + Object[] row; + + do { + row = expected[i]; + for (j = 0; j < row.length; ++j) { + Object atIndex = row[j]; + if (atIndex == null) { + continue; + } + if (atIndex instanceof String) { + Assert.assertEquals(atIndex, actual.getString(j)); + } else { + Assert.assertEquals(atIndex, actual.getInt(j)); + } + } + ++i; + } while (actual.moveToPosition(i)); + } + + public static int getRowCount(SQLiteDatabase db, String table) { + return getRowCount(db, table, null, null); + } + + public static int getRowCount(SQLiteDatabase db, String table, String selection, String[] selectionArgs) { + final Cursor c = db.query(table, null, selection, selectionArgs, null, null, null); + try { + return c.getCount(); + } finally { + c.close(); + } + } + + /** + * Returns an ID that is non-existent in the given sqlite table. Assumes that a column named + * "id" exists. + */ + public static int getNonExistentID(SQLiteDatabase db, String table) { + // XXX: We should use selectionArgs to concatenate table, but sqlite throws a syntax error on + // "?" because it wants to ensure id is a valid column in table. + final Cursor c = db.rawQuery("SELECT MAX(id) + 1 FROM " + table, null); + try { + if (!c.moveToNext()) { + return 0; + } + return c.getInt(0); + } finally { + c.close(); + } + } + + /** + * Returns an ID that exists in the given sqlite table. Assumes that a column named * "id" + * exists. + */ + public static long getExistentID(SQLiteDatabase db, String table) { + final Cursor c = db.query(table, new String[] {"id"}, null, null, null, null, null, "1"); + try { + if (!c.moveToNext()) { + throw new IllegalStateException("Given table does not contain any entries."); + } + return c.getInt(0); + } finally { + c.close(); + } + } + +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/DBProviderTestCase.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/DBProviderTestCase.java new file mode 100644 index 000000000..ccfeb8d63 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/helpers/DBProviderTestCase.java @@ -0,0 +1,73 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.helpers; + +import java.io.File; + +import android.content.ContentProvider; +import android.content.Context; +import android.test.AndroidTestCase; +import android.test.mock.MockContentResolver; + +/** + * Because ProviderTestCase2 is unable to handle custom DB paths. + */ +public abstract class DBProviderTestCase extends + AndroidTestCase { + + Class providerClass; + String providerAuthority; + + protected File fakeProfileDirectory; + private MockContentResolver resolver; + private T provider; + + public DBProviderTestCase(Class providerClass, String providerAuthority) { + this.providerClass = providerClass; + this.providerAuthority = providerAuthority; + } + + public T getProvider() { + return provider; + } + + public MockContentResolver getMockContentResolver() { + return resolver; + } + + protected String getCacheSuffix() { + return this.getClass().getName() + "-" + System.currentTimeMillis(); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + File cache = getContext().getCacheDir(); + fakeProfileDirectory = new File(cache.getAbsolutePath() + getCacheSuffix()); + System.out.println("Test: Creating profile directory " + fakeProfileDirectory.getAbsolutePath()); + if (!fakeProfileDirectory.mkdir()) { + throw new IllegalStateException("Could not create temporary directory."); + } + + final Context context = getContext(); + assertNotNull(context); + resolver = new MockContentResolver(); + provider = providerClass.newInstance(); + provider.attachInfo(context, null); + assertNotNull(provider); + resolver.addProvider(providerAuthority, getProvider()); + } + + @Override + protected void tearDown() throws Exception { + // We don't check return values. + System.out.println("Test: Cleaning up " + fakeProfileDirectory.getAbsolutePath()); + for (File child : fakeProfileDirectory.listFiles()) { + child.delete(); + } + fakeProfileDirectory.delete(); + super.tearDown(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/nativecode/test/TestNativeCrypto.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/nativecode/test/TestNativeCrypto.java new file mode 100644 index 000000000..d24f28491 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/nativecode/test/TestNativeCrypto.java @@ -0,0 +1,175 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.nativecode.test; + +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; + +import junit.framework.TestCase; + +import org.mozilla.gecko.background.nativecode.NativeCrypto; +import org.mozilla.gecko.sync.Utils; + +/* + * Tests the Java wrapper over native implementations of crypto code. Test vectors from: + * * PBKDF2SHA256: + * - + * - + * * SHA-1: + * - + */ +public class TestNativeCrypto extends TestCase { + + public final void testPBKDF2SHA256A() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "password"; + String s = "salt"; + int dkLen = 32; + + checkPBKDF2SHA256(p, s, 1, dkLen, "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b"); + checkPBKDF2SHA256(p, s, 4096, dkLen, "c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a"); + } + + public final void testPBKDF2SHA256B() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "passwordPASSWORDpassword"; + String s = "saltSALTsaltSALTsaltSALTsaltSALTsalt"; + int dkLen = 40; + + checkPBKDF2SHA256(p, s, 4096, dkLen, "348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1c635518c7dac47e9"); + } + + public final void testPBKDF2SHA256scryptA() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "passwd"; + String s = "salt"; + int dkLen = 64; + + checkPBKDF2SHA256(p, s, 1, dkLen, "55ac046e56e3089fec1691c22544b605f94185216dde0465e68b9d57c20dacbc49ca9cccf179b645991664b39d77ef317c71b845b1e30bd509112041d3a19783"); + } + + public final void testPBKDF2SHA256scryptB() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "Password"; + String s = "NaCl"; + int dkLen = 64; + + checkPBKDF2SHA256(p, s, 80000, dkLen, "4ddcd8f60b98be21830cee5ef22701f9641a4418d04c0414aeff08876b34ab56a1d425a1225833549adb841b51c9b3176a272bdebba1d078478f62b397f33c8d"); + } + + public final void testPBKDF2SHA256C() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "pass\0word"; + String s = "sa\0lt"; + int dkLen = 16; + + checkPBKDF2SHA256(p, s, 4096, dkLen, "89b69d0516f829893c696226650a8687"); + } + + /* + // This test takes two or three minutes to run, so we don't. + public final void testPBKDF2SHA256D() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "password"; + String s = "salt"; + int dkLen = 32; + + checkPBKDF2SHA256(p, s, 16777216, dkLen, "cf81c66fe8cfc04d1f31ecb65dab4089f7f179e89b3b0bcb17ad10e3ac6eba46"); + } + */ + + public final void testTimePBKDF2SHA256() throws UnsupportedEncodingException, GeneralSecurityException { + checkPBKDF2SHA256("password", "salt", 80000, 32, null); + } + + public final void testPBKDF2SHA256InvalidLenArg() throws UnsupportedEncodingException, GeneralSecurityException { + final String p = "password"; + final String s = "salt"; + final int c = 1; + final int dkLen = -1; // Should always be positive. + + try { + NativeCrypto.pbkdf2SHA256(p.getBytes("US-ASCII"), s.getBytes("US-ASCII"), c, dkLen); + fail("Expected sha256 to throw with negative dkLen argument."); + } catch (IllegalArgumentException e) { } // Expected. + } + + public final void testSHA1() throws UnsupportedEncodingException { + final String[] inputs = new String[] { + "abc", + "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "" // To be filled in below. + }; + final String baseStr = "01234567"; + final int repetitions = 80; + final StringBuilder builder = new StringBuilder(baseStr.length() * repetitions); + for (int i = 0; i < 80; ++i) { + builder.append(baseStr); + } + inputs[2] = builder.toString(); + + final String[] expecteds = new String[] { + "a9993e364706816aba3e25717850c26c9cd0d89d", + "84983e441c3bd26ebaae4aa1f95129e5e54670f1", + "dea356a2cddd90c7a7ecedc5ebb563934f460452" + }; + + for (int i = 0; i < inputs.length; ++i) { + final byte[] input = inputs[i].getBytes("US-ASCII"); + final String expected = expecteds[i]; + + final byte[] actual = NativeCrypto.sha1(input); + assertNotNull("Hashed value is non-null", actual); + assertExpectedBytes(expected, actual); + } + } + + /** + * Test to ensure the output of our SHA1 algo is the same as MessageDigest's. This is important + * because we intend to replace MessageDigest in FHR with this SHA-1 algo (bug 959652). + */ + public final void testSHA1AgainstMessageDigest() throws UnsupportedEncodingException, + NoSuchAlgorithmException { + final String[] inputs = { + "password", + "saranghae", + "aoeusnthaoeusnthaoeusnth \0 12345098765432109876_!" + }; + + final MessageDigest digest = MessageDigest.getInstance("SHA-1"); + for (final String input : inputs) { + final byte[] inputBytes = input.getBytes("US-ASCII"); + + final byte[] mdBytes = digest.digest(inputBytes); + final byte[] ourBytes = NativeCrypto.sha1(inputBytes); + assertTrue("MessageDigest hash is the same as NativeCrypto SHA-1 hash", + Arrays.equals(ourBytes, mdBytes)); + } + } + + private void checkPBKDF2SHA256(String p, String s, int c, int dkLen, + final String expectedStr) + throws GeneralSecurityException, UnsupportedEncodingException { + long start = System.currentTimeMillis(); + byte[] key = NativeCrypto.pbkdf2SHA256(p.getBytes("US-ASCII"), s.getBytes("US-ASCII"), c, dkLen); + assertNotNull(key); + + long end = System.currentTimeMillis(); + + System.err.println("SHA-256 " + c + " took " + (end - start) + "ms"); + if (expectedStr == null) { + return; + } + + assertEquals(dkLen, Utils.hex2Byte(expectedStr).length); + assertExpectedBytes(expectedStr, key); + } + + private void assertExpectedBytes(final String expectedStr, byte[] key) { + assertEquals(expectedStr, Utils.byte2Hex(key)); + byte[] expected = Utils.hex2Byte(expectedStr); + + assertEquals(expected.length, key.length); + for (int i = 0; i < key.length; i++) { + assertEquals(expected[i], key[i]); + } + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/AndroidSyncTestCaseWithAccounts.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/AndroidSyncTestCaseWithAccounts.java new file mode 100644 index 000000000..e0e4e8bb1 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/AndroidSyncTestCaseWithAccounts.java @@ -0,0 +1,128 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync; + +import android.accounts.Account; +import android.accounts.AccountManager; +import android.accounts.AccountManagerCallback; +import android.accounts.AccountManagerFuture; +import android.content.Context; +import android.test.InstrumentationTestCase; + +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.fxa.authenticator.AndroidFxAccount; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +public class AndroidSyncTestCaseWithAccounts extends AndroidSyncTestCase { + public final String testAccountType; + public final String testAccountPrefix; + + protected Context context; + protected AccountManager accountManager; + protected int numAccounts; + + public static final Map TEST_SYNC_AUTOMATICALLY_MAP_WITH_ALL_AUTHORITIES_DISABLED; + static { + final Map m = new HashMap(); + for (String authority : AndroidFxAccount.DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP.keySet()) { + m.put(authority, false); + } + TEST_SYNC_AUTOMATICALLY_MAP_WITH_ALL_AUTHORITIES_DISABLED = m; + } + + public AndroidSyncTestCaseWithAccounts(String accountType, String accountPrefix) { + super(); + this.testAccountType = accountType; + this.testAccountPrefix = accountPrefix; + } + + @Override + public void setUp() { + context = getApplicationContext(); + accountManager = AccountManager.get(context); + deleteTestAccounts(); // Always start with no test accounts. + numAccounts = accountManager.getAccountsByType(testAccountType).length; + } + + public List getTestAccounts() { + final List testAccounts = new ArrayList(); + + final Account[] accounts = accountManager.getAccountsByType(testAccountType); + for (Account account : accounts) { + if (account.name.startsWith(testAccountPrefix)) { + testAccounts.add(account); + } + } + + return testAccounts; + } + + public static void deleteAccount(final InstrumentationTestCase test, final AccountManager accountManager, final Account account) { + performWait(new Runnable() { + @Override + public void run() { + try { + test.runTestOnUiThread(new Runnable() { + final AccountManagerCallback callback = new AccountManagerCallback() { + @Override + public void run(AccountManagerFuture future) { + try { + future.getResult(5L, TimeUnit.SECONDS); + } catch (Exception e) { + } + performNotify(); + } + }; + + @Override + public void run() { + accountManager.removeAccount(account, callback, null); + } + }); + } catch (Throwable e) { + performNotify(e); + } + } + }); + } + + public void deleteTestAccounts() { + for (Account account : getTestAccounts()) { + deleteAccount(this, accountManager, account); + } + } + + public boolean testAccountsExist() { + // Note that we don't use FirefoxAccounts.firefoxAccountsExist because it unpickles. + return !getTestAccounts().isEmpty(); + } + + @Override + public void tearDown() { + deleteTestAccounts(); + assertEquals(numAccounts, accountManager.getAccountsByType(testAccountType).length); + } + + public static void assertFileNotPresent(final Context context, final String filename) throws Exception { + // Verify file is not present. + FileInputStream fis = null; + try { + fis = context.openFileInput(filename); + fail("Should get FileNotFoundException."); + } catch (FileNotFoundException e) { + // Do nothing; file should not exist. + } finally { + if (fis != null) { + fis.close(); + } + } + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestClientsStage.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestClientsStage.java new file mode 100644 index 000000000..39e24b4d4 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestClientsStage.java @@ -0,0 +1,95 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync; + +import org.json.simple.JSONArray; +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.background.testhelpers.DefaultGlobalSessionCallback; +import org.mozilla.gecko.background.testhelpers.MockClientsDataDelegate; +import org.mozilla.gecko.background.testhelpers.MockSharedPreferences; +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.SyncConfiguration; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor; +import org.mozilla.gecko.sync.repositories.domain.ClientRecord; +import org.mozilla.gecko.sync.stage.SyncClientsEngineStage; + +import android.content.Context; +import android.content.SharedPreferences; + +public class TestClientsStage extends AndroidSyncTestCase { + private static final String TEST_USERNAME = "johndoe"; + private static final String TEST_PASSWORD = "password"; + private static final String TEST_SYNC_KEY = "abcdeabcdeabcdeabcdeabcdea"; + + @Override + public void setUp() { + ClientsDatabaseAccessor db = new ClientsDatabaseAccessor(getApplicationContext()); + db.wipeDB(); + db.close(); + } + + public void testWipeClearsClients() throws Exception { + + // Wiping clients is equivalent to a reset and dropping all local stored client records. + // Resetting is defined as being the same as for other engines -- discard local + // and remote timestamps, tracked failed records, and tracked records to fetch. + + final Context context = getApplicationContext(); + final ClientsDatabaseAccessor dataAccessor = new ClientsDatabaseAccessor(context); + final GlobalSessionCallback callback = new DefaultGlobalSessionCallback(); + final ClientsDataDelegate delegate = new MockClientsDataDelegate(); + + final KeyBundle keyBundle = new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY); + final AuthHeaderProvider authHeaderProvider = new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD); + final SharedPreferences prefs = new MockSharedPreferences(); + final SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, authHeaderProvider, prefs); + config.syncKeyBundle = keyBundle; + GlobalSession session = new GlobalSession(config, callback, context, delegate); + + SyncClientsEngineStage stage = new SyncClientsEngineStage() { + + @Override + public synchronized ClientsDatabaseAccessor getClientsDatabaseAccessor() { + if (db == null) { + db = dataAccessor; + } + return db; + } + }; + + final String guid = "clientabcdef"; + long lastModified = System.currentTimeMillis(); + ClientRecord record = new ClientRecord(guid, "clients", lastModified , false); + record.name = "John's Phone"; + record.type = "mobile"; + record.device = "Some Device"; + record.os = "iOS"; + record.commands = new JSONArray(); + + dataAccessor.store(record); + assertEquals(1, dataAccessor.clientsCount()); + + final ClientRecord stored = dataAccessor.fetchAllClients().get(guid); + assertNotNull(stored); + assertEquals("John's Phone", stored.name); + assertEquals("mobile", stored.type); + assertEquals("Some Device", stored.device); + assertEquals("iOS", stored.os); + + stage.wipeLocal(session); + + try { + assertEquals(0, dataAccessor.clientsCount()); + assertEquals(0L, session.config.getPersistedServerClientRecordTimestamp()); + assertEquals(0, session.getClientsDelegate().getClientsCount()); + } finally { + dataAccessor.close(); + } + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestResetting.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestResetting.java new file mode 100644 index 000000000..52af2ad01 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestResetting.java @@ -0,0 +1,198 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync; + +import android.content.SharedPreferences; + +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.background.testhelpers.BaseMockServerSyncStage; +import org.mozilla.gecko.background.testhelpers.DefaultGlobalSessionCallback; +import org.mozilla.gecko.background.testhelpers.MockRecord; +import org.mozilla.gecko.background.testhelpers.MockSharedPreferences; +import org.mozilla.gecko.background.testhelpers.WBORepository; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.EngineSettings; +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.MetaGlobalException; +import org.mozilla.gecko.sync.SyncConfiguration; +import org.mozilla.gecko.sync.SynchronizerConfiguration; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.repositories.domain.Record; +import org.mozilla.gecko.sync.stage.NoSuchStageException; +import org.mozilla.gecko.sync.synchronizer.Synchronizer; + +/** + * Test the on-device side effects of reset operations on a stage. + * + * See also "TestResetCommands" in the unit test suite. + */ +public class TestResetting extends AndroidSyncTestCase { + private static final String TEST_USERNAME = "johndoe"; + private static final String TEST_PASSWORD = "password"; + private static final String TEST_SYNC_KEY = "abcdeabcdeabcdeabcdeabcdea"; + + @Override + public void setUp() { + assertTrue(WaitHelper.getTestWaiter().isIdle()); + } + + /** + * Set up a mock stage that synchronizes two mock repositories. Apply various + * reset/sync/wipe permutations and check state. + */ + public void testResetAndWipeStage() throws Exception { + + final long startTime = System.currentTimeMillis(); + final GlobalSessionCallback callback = createGlobalSessionCallback(); + final GlobalSession session = createDefaultGlobalSession(callback); + + final ExecutableMockServerSyncStage stage = new ExecutableMockServerSyncStage() { + @Override + public void onSynchronized(Synchronizer synchronizer) { + try { + assertTrue(startTime <= synchronizer.bundleA.getTimestamp()); + assertTrue(startTime <= synchronizer.bundleB.getTimestamp()); + + // Call up to allow the usual persistence etc. to happen. + super.onSynchronized(synchronizer); + } catch (Throwable e) { + performNotify(e); + return; + } + performNotify(); + } + }; + + final boolean bumpTimestamps = true; + WBORepository local = new WBORepository(bumpTimestamps); + WBORepository remote = new WBORepository(bumpTimestamps); + + stage.name = "mock"; + stage.collection = "mock"; + stage.local = local; + stage.remote = remote; + + stage.executeSynchronously(session); + + // Verify the persisted values. + assertConfigTimestampsGreaterThan(stage.leakConfig(), startTime, startTime); + + // Reset. + stage.resetLocal(session); + + // Verify that they're gone. + assertConfigTimestampsEqual(stage.leakConfig(), 0, 0); + + // Now sync data, ensure that timestamps come back. + final long afterReset = System.currentTimeMillis(); + final String recordGUID = "abcdefghijkl"; + local.wbos.put(recordGUID, new MockRecord(recordGUID, "mock", startTime, false)); + + // Sync again with data and verify timestamps and data. + stage.executeSynchronously(session); + + assertConfigTimestampsGreaterThan(stage.leakConfig(), afterReset, afterReset); + assertEquals(1, remote.wbos.size()); + assertEquals(1, local.wbos.size()); + + Record remoteRecord = remote.wbos.get(recordGUID); + assertNotNull(remoteRecord); + assertNotNull(local.wbos.get(recordGUID)); + assertEquals(recordGUID, remoteRecord.guid); + assertTrue(afterReset <= remoteRecord.lastModified); + + // Reset doesn't clear data. + stage.resetLocal(session); + assertConfigTimestampsEqual(stage.leakConfig(), 0, 0); + assertEquals(1, remote.wbos.size()); + assertEquals(1, local.wbos.size()); + remoteRecord = remote.wbos.get(recordGUID); + assertNotNull(remoteRecord); + assertNotNull(local.wbos.get(recordGUID)); + + // Wipe does. Recover from reset... + final long beforeWipe = System.currentTimeMillis(); + stage.executeSynchronously(session); + assertEquals(1, remote.wbos.size()); + assertEquals(1, local.wbos.size()); + assertConfigTimestampsGreaterThan(stage.leakConfig(), beforeWipe, beforeWipe); + + // ... then wipe. + stage.wipeLocal(session); + assertConfigTimestampsEqual(stage.leakConfig(), 0, 0); + assertEquals(1, remote.wbos.size()); // We don't wipe the server. + assertEquals(0, local.wbos.size()); // We do wipe local. + } + + /** + * A stage that joins two Repositories with no wrapping. + */ + public class ExecutableMockServerSyncStage extends BaseMockServerSyncStage { + /** + * Run this stage synchronously. + */ + public void executeSynchronously(final GlobalSession session) { + final BaseMockServerSyncStage self = this; + performWait(new Runnable() { + @Override + public void run() { + try { + self.execute(session); + } catch (NoSuchStageException e) { + performNotify(e); + } + } + }); + } + } + + private GlobalSession createDefaultGlobalSession(final GlobalSessionCallback callback) throws Exception { + final KeyBundle keyBundle = new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY); + final AuthHeaderProvider authHeaderProvider = new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD); + final SharedPreferences prefs = new MockSharedPreferences(); + final SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, authHeaderProvider, prefs); + config.syncKeyBundle = keyBundle; + return new GlobalSession(config, callback, getApplicationContext(), null) { + @Override + public boolean isEngineRemotelyEnabled(String engineName, + EngineSettings engineSettings) + throws MetaGlobalException { + return true; + } + + @Override + public void advance() { + // So we don't proceed and run other stages. + } + }; + } + + private static GlobalSessionCallback createGlobalSessionCallback() { + return new DefaultGlobalSessionCallback() { + + @Override + public void handleAborted(GlobalSession globalSession, String reason) { + performNotify(new Exception("Aborted")); + } + + @Override + public void handleError(GlobalSession globalSession, Exception ex) { + performNotify(ex); + } + }; + } + + private static void assertConfigTimestampsGreaterThan(SynchronizerConfiguration config, long local, long remote) { + assertTrue(local <= config.localBundle.getTimestamp()); + assertTrue(remote <= config.remoteBundle.getTimestamp()); + } + + private static void assertConfigTimestampsEqual(SynchronizerConfiguration config, long local, long remote) { + assertEquals(local, config.localBundle.getTimestamp()); + assertEquals(remote, config.remoteBundle.getTimestamp()); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java new file mode 100644 index 000000000..bac6c7f49 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestStoreTracking.java @@ -0,0 +1,377 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; + +import junit.framework.AssertionFailedError; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.background.sync.helpers.SimpleSuccessBeginDelegate; +import org.mozilla.gecko.background.sync.helpers.SimpleSuccessCreationDelegate; +import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFetchDelegate; +import org.mozilla.gecko.background.sync.helpers.SimpleSuccessFinishDelegate; +import org.mozilla.gecko.background.sync.helpers.SimpleSuccessStoreDelegate; +import org.mozilla.gecko.background.testhelpers.WBORepository; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; +import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; +import org.mozilla.gecko.sync.synchronizer.Synchronizer; +import org.mozilla.gecko.sync.synchronizer.SynchronizerDelegate; + +import android.content.Context; + +public class TestStoreTracking extends AndroidSyncTestCase { + public void assertEq(Object expected, Object actual) { + try { + assertEquals(expected, actual); + } catch (AssertionFailedError e) { + performNotify(e); + } + } + + public class TrackingWBORepository extends WBORepository { + @Override + public synchronized boolean shouldTrack() { + return true; + } + } + + public void doTestStoreRetrieveByGUID(final WBORepository repository, + final RepositorySession session, + final String expectedGUID, + final Record record) { + + final SimpleSuccessStoreDelegate storeDelegate = new SimpleSuccessStoreDelegate() { + + @Override + public void onRecordStoreSucceeded(String guid) { + Logger.debug(getName(), "Stored " + guid); + assertEq(expectedGUID, guid); + } + + @Override + public void onStoreCompleted(long storeEnd) { + Logger.debug(getName(), "Store completed at " + storeEnd + "."); + try { + session.fetch(new String[] { expectedGUID }, new SimpleSuccessFetchDelegate() { + @Override + public void onFetchedRecord(Record record) { + Logger.debug(getName(), "Hurrah! Fetched record " + record.guid); + assertEq(expectedGUID, record.guid); + } + + @Override + public void onFetchCompleted(final long fetchEnd) { + Logger.debug(getName(), "Fetch completed at " + fetchEnd + "."); + + // But fetching by time returns nothing. + session.fetchSince(0, new SimpleSuccessFetchDelegate() { + private AtomicBoolean fetched = new AtomicBoolean(false); + + @Override + public void onFetchedRecord(Record record) { + Logger.debug(getName(), "Fetched record " + record.guid); + fetched.set(true); + performNotify(new AssertionFailedError("Should have fetched no record!")); + } + + @Override + public void onFetchCompleted(final long fetchEnd) { + if (fetched.get()) { + Logger.debug(getName(), "Not finishing session: record retrieved."); + return; + } + try { + session.finish(new SimpleSuccessFinishDelegate() { + @Override + public void onFinishSucceeded(RepositorySession session, + RepositorySessionBundle bundle) { + performNotify(); + } + }); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + }); + } + }); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + }; + + session.setStoreDelegate(storeDelegate); + try { + Logger.debug(getName(), "Storing..."); + session.store(record); + session.storeDone(); + } catch (NoStoreDelegateException e) { + // Should not happen. + } + } + + private void doTestNewSessionRetrieveByTime(final WBORepository repository, + final String expectedGUID) { + final SimpleSuccessCreationDelegate createDelegate = new SimpleSuccessCreationDelegate() { + @Override + public void onSessionCreated(final RepositorySession session) { + Logger.debug(getName(), "Session created."); + try { + session.begin(new SimpleSuccessBeginDelegate() { + @Override + public void onBeginSucceeded(final RepositorySession session) { + // Now we get a result. + session.fetchSince(0, new SimpleSuccessFetchDelegate() { + + @Override + public void onFetchedRecord(Record record) { + assertEq(expectedGUID, record.guid); + } + + @Override + public void onFetchCompleted(long end) { + try { + session.finish(new SimpleSuccessFinishDelegate() { + @Override + public void onFinishSucceeded(RepositorySession session, + RepositorySessionBundle bundle) { + // Hooray! + performNotify(); + } + }); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + }); + } + }); + } catch (InvalidSessionTransitionException e) { + performNotify(e); + } + } + }; + Runnable create = new Runnable() { + @Override + public void run() { + repository.createSession(createDelegate, getApplicationContext()); + } + }; + + performWait(create); + } + + /** + * Store a record in one session. Verify that fetching by GUID returns + * the record. Verify that fetching by timestamp fails to return records. + * Start a new session. Verify that fetching by timestamp returns the + * stored record. + * + * Invokes doTestStoreRetrieveByGUID, doTestNewSessionRetrieveByTime. + */ + public void testStoreRetrieveByGUID() { + Logger.debug(getName(), "Started."); + final WBORepository r = new TrackingWBORepository(); + final long now = System.currentTimeMillis(); + final String expectedGUID = "abcdefghijkl"; + final Record record = new BookmarkRecord(expectedGUID, "bookmarks", now , false); + + final RepositorySessionCreationDelegate createDelegate = new SimpleSuccessCreationDelegate() { + @Override + public void onSessionCreated(RepositorySession session) { + Logger.debug(getName(), "Session created: " + session); + try { + session.begin(new SimpleSuccessBeginDelegate() { + @Override + public void onBeginSucceeded(final RepositorySession session) { + doTestStoreRetrieveByGUID(r, session, expectedGUID, record); + } + }); + } catch (InvalidSessionTransitionException e) { + performNotify(e); + } + } + }; + + final Context applicationContext = getApplicationContext(); + + // This has to happen on a new thread so that we + // can wait for it! + Runnable create = onThreadRunnable(new Runnable() { + @Override + public void run() { + r.createSession(createDelegate, applicationContext); + } + }); + + Runnable retrieve = onThreadRunnable(new Runnable() { + @Override + public void run() { + doTestNewSessionRetrieveByTime(r, expectedGUID); + performNotify(); + } + }); + + performWait(create); + performWait(retrieve); + } + + private Runnable onThreadRunnable(final Runnable r) { + return new Runnable() { + @Override + public void run() { + new Thread(r).start(); + } + }; + } + + + public class CountingWBORepository extends TrackingWBORepository { + public AtomicLong counter = new AtomicLong(0L); + public class CountingWBORepositorySession extends WBORepositorySession { + private static final String LOG_TAG = "CountingRepoSession"; + + public CountingWBORepositorySession(WBORepository repository) { + super(repository); + } + + @Override + public void store(final Record record) throws NoStoreDelegateException { + Logger.debug(LOG_TAG, "Counter now " + counter.incrementAndGet()); + super.store(record); + } + } + + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + delegate.deferredCreationDelegate().onSessionCreated(new CountingWBORepositorySession(this)); + } + } + + public class TestRecord extends Record { + public TestRecord(String guid, String collection, long lastModified, + boolean deleted) { + super(guid, collection, lastModified, deleted); + } + + @Override + public void initFromEnvelope(CryptoRecord payload) { + return; + } + + @Override + public CryptoRecord getEnvelope() { + return null; + } + + @Override + protected void populatePayload(ExtendedJSONObject payload) { + } + + @Override + protected void initFromPayload(ExtendedJSONObject payload) { + } + + @Override + public Record copyWithIDs(String guid, long androidID) { + return new TestRecord(guid, this.collection, this.lastModified, this.deleted); + } + } + + /** + * Create two repositories, syncing from one to the other. Ensure + * that records stored from one aren't re-uploaded. + */ + public void testStoreBetweenRepositories() { + final CountingWBORepository repoA = new CountingWBORepository(); // "Remote". First source. + final CountingWBORepository repoB = new CountingWBORepository(); // "Local". First sink. + long now = System.currentTimeMillis(); + + TestRecord recordA1 = new TestRecord("aacdefghiaaa", "coll", now - 30, false); + TestRecord recordA2 = new TestRecord("aacdefghibbb", "coll", now - 20, false); + TestRecord recordB1 = new TestRecord("aacdefghiaaa", "coll", now - 10, false); + TestRecord recordB2 = new TestRecord("aacdefghibbb", "coll", now - 40, false); + + TestRecord recordA3 = new TestRecord("nncdefghibbb", "coll", now, false); + TestRecord recordB3 = new TestRecord("nncdefghiaaa", "coll", now, false); + + // A1 and B1 are the same, but B's version is newer. We expect A1 to be downloaded + // and B1 to be uploaded. + // A2 and B2 are the same, but A's version is newer. We expect A2 to be downloaded + // and B2 to not be uploaded. + // Both A3 and B3 are new. We expect them to go in each direction. + // Expected counts, then: + // Repo A: B1 + B3 + // Repo B: A1 + A2 + A3 + repoB.wbos.put(recordB1.guid, recordB1); + repoB.wbos.put(recordB2.guid, recordB2); + repoB.wbos.put(recordB3.guid, recordB3); + repoA.wbos.put(recordA1.guid, recordA1); + repoA.wbos.put(recordA2.guid, recordA2); + repoA.wbos.put(recordA3.guid, recordA3); + + final Synchronizer s = new Synchronizer(); + s.repositoryA = repoA; + s.repositoryB = repoB; + + Runnable r = new Runnable() { + @Override + public void run() { + s.synchronize(getApplicationContext(), new SynchronizerDelegate() { + + @Override + public void onSynchronized(Synchronizer synchronizer) { + long countA = repoA.counter.get(); + long countB = repoB.counter.get(); + Logger.debug(getName(), "Counts: " + countA + ", " + countB); + assertEq(2L, countA); + assertEq(3L, countB); + + // Testing for store timestamp 'hack'. + // We fetched from A first, and so its bundle timestamp will be the last + // stored time. We fetched from B second, so its bundle timestamp will be + // the last fetched time. + final long timestampA = synchronizer.bundleA.getTimestamp(); + final long timestampB = synchronizer.bundleB.getTimestamp(); + Logger.debug(getName(), "Repo A timestamp: " + timestampA); + Logger.debug(getName(), "Repo B timestamp: " + timestampB); + Logger.debug(getName(), "Repo A fetch done: " + repoA.stats.fetchCompleted); + Logger.debug(getName(), "Repo A store done: " + repoA.stats.storeCompleted); + Logger.debug(getName(), "Repo B fetch done: " + repoB.stats.fetchCompleted); + Logger.debug(getName(), "Repo B store done: " + repoB.stats.storeCompleted); + + assertTrue(timestampB <= timestampA); + assertTrue(repoA.stats.fetchCompleted <= timestampA); + assertTrue(repoA.stats.storeCompleted >= repoA.stats.fetchCompleted); + assertEquals(repoA.stats.storeCompleted, timestampA); + assertEquals(repoB.stats.fetchCompleted, timestampB); + performNotify(); + } + + @Override + public void onSynchronizeFailed(Synchronizer synchronizer, + Exception lastException, String reason) { + Logger.debug(getName(), "Failed."); + performNotify(new AssertionFailedError("Should not fail.")); + } + }); + } + }; + + performWait(onThreadRunnable(r)); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestSyncConfiguration.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestSyncConfiguration.java new file mode 100644 index 000000000..389aaf891 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestSyncConfiguration.java @@ -0,0 +1,146 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.sync.SyncConfiguration; + +import android.content.SharedPreferences; + +public class TestSyncConfiguration extends AndroidSyncTestCase { + public static final String TEST_PREFS_NAME = "test"; + + public SharedPreferences getPrefs(String name, int mode) { + return this.getApplicationContext().getSharedPreferences(name, mode); + } + + /** + * Ensure that declined engines persist through prefs. + */ + public void testDeclinedEngineNames() { + SyncConfiguration config = null; + SharedPreferences prefs = getPrefs(TEST_PREFS_NAME, 0); + + config = newSyncConfiguration(); + config.declinedEngineNames = new HashSet(); + config.declinedEngineNames.add("test1"); + config.declinedEngineNames.add("test2"); + config.persistToPrefs(); + assertTrue(prefs.contains(SyncConfiguration.PREF_DECLINED_ENGINE_NAMES)); + config = newSyncConfiguration(); + Set expected = new HashSet(); + for (String name : new String[] { "test1", "test2" }) { + expected.add(name); + } + assertEquals(expected, config.declinedEngineNames); + + config.declinedEngineNames = null; + config.persistToPrefs(); + assertFalse(prefs.contains(SyncConfiguration.PREF_DECLINED_ENGINE_NAMES)); + config = newSyncConfiguration(); + assertNotNull(config.declinedEngineNames); + assertTrue(config.declinedEngineNames.isEmpty()); + } + + public void testEnabledEngineNames() { + SyncConfiguration config = null; + SharedPreferences prefs = getPrefs(TEST_PREFS_NAME, 0); + + config = newSyncConfiguration(); + config.enabledEngineNames = new HashSet(); + config.enabledEngineNames.add("test1"); + config.enabledEngineNames.add("test2"); + config.persistToPrefs(); + assertTrue(prefs.contains(SyncConfiguration.PREF_ENABLED_ENGINE_NAMES)); + config = newSyncConfiguration(); + Set expected = new HashSet(); + for (String name : new String[] { "test1", "test2" }) { + expected.add(name); + } + assertEquals(expected, config.enabledEngineNames); + + config.enabledEngineNames = null; + config.persistToPrefs(); + assertFalse(prefs.contains(SyncConfiguration.PREF_ENABLED_ENGINE_NAMES)); + config = newSyncConfiguration(); + assertNull(config.enabledEngineNames); + } + + public void testSyncID() { + SyncConfiguration config = null; + SharedPreferences prefs = getPrefs(TEST_PREFS_NAME, 0); + + config = newSyncConfiguration(); + config.syncID = "test1"; + config.persistToPrefs(); + assertTrue(prefs.contains(SyncConfiguration.PREF_SYNC_ID)); + config = newSyncConfiguration(); + assertEquals("test1", config.syncID); + } + + public void testStoreSelectedEnginesToPrefs() { + SharedPreferences prefs = getPrefs(TEST_PREFS_NAME, 0); + // Store engines, excluding history/forms special case. + Map expectedEngines = new HashMap(); + expectedEngines.put("test1", true); + expectedEngines.put("test2", false); + expectedEngines.put("test3", true); + + SyncConfiguration.storeSelectedEnginesToPrefs(prefs, expectedEngines); + + // Read values from selectedEngines. + assertTrue(prefs.contains(SyncConfiguration.PREF_USER_SELECTED_ENGINES_TO_SYNC)); + SyncConfiguration config = null; + config = newSyncConfiguration(); + config.loadFromPrefs(prefs); + assertEquals(expectedEngines, config.userSelectedEngines); + } + + /** + * Tests dependency of forms engine on history engine. + */ + public void testSelectedEnginesHistoryAndForms() { + SharedPreferences prefs = getPrefs(TEST_PREFS_NAME, 0); + // Store engines, excluding history/forms special case. + Map storedEngines = new HashMap(); + storedEngines.put("history", true); + + SyncConfiguration.storeSelectedEnginesToPrefs(prefs, storedEngines); + + // Expected engines. + storedEngines.put("forms", true); + // Read values from selectedEngines. + assertTrue(prefs.contains(SyncConfiguration.PREF_USER_SELECTED_ENGINES_TO_SYNC)); + SyncConfiguration config = null; + config = newSyncConfiguration(); + config.loadFromPrefs(prefs); + assertEquals(storedEngines, config.userSelectedEngines); + } + + public void testsSelectedEnginesNoHistoryNorForms() { + SharedPreferences prefs = getPrefs(TEST_PREFS_NAME, 0); + // Store engines, excluding history/forms special case. + Map storedEngines = new HashMap(); + storedEngines.put("forms", true); + + SyncConfiguration.storeSelectedEnginesToPrefs(prefs, storedEngines); + + // Read values from selectedEngines. + assertTrue(prefs.contains(SyncConfiguration.PREF_USER_SELECTED_ENGINES_TO_SYNC)); + SyncConfiguration config = null; + config = newSyncConfiguration(); + config.loadFromPrefs(prefs); + // Forms should not be selected if history is not present. + assertTrue(config.userSelectedEngines.isEmpty()); + } + + protected SyncConfiguration newSyncConfiguration() { + return new SyncConfiguration(null, null, getPrefs(TEST_PREFS_NAME, 0)); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestWebURLFinder.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestWebURLFinder.java new file mode 100644 index 000000000..a7ebb71d5 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/TestWebURLFinder.java @@ -0,0 +1,49 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync; + +import java.util.Arrays; + +import org.mozilla.gecko.background.helpers.AndroidSyncTestCase; +import org.mozilla.gecko.sync.setup.activities.WebURLFinder; + +/** + * These tests are on device because the WebKit APIs are stubs on desktop. + */ +public class TestWebURLFinder extends AndroidSyncTestCase { + public String find(String string) { + return new WebURLFinder(string).bestWebURL(); + } + + public String find(String[] strings) { + return new WebURLFinder(Arrays.asList(strings)).bestWebURL(); + } + + public void testNoEmail() { + assertNull(find("test@test.com")); + } + + public void testSchemeFirst() { + assertEquals("http://scheme.com", find("test.com http://scheme.com")); + } + + public void testFullURL() { + assertEquals("http://scheme.com:8080/inner#anchor&arg=1", find("test.com http://scheme.com:8080/inner#anchor&arg=1")); + } + + public void testNoScheme() { + assertEquals("noscheme.com", find("noscheme.com")); + } + + public void testNoBadScheme() { + assertNull(find("file:///test javascript:///test.js")); + } + + public void testStrings() { + assertEquals("http://test.com", find(new String[] { "http://test.com", "noscheme.com" })); + assertEquals("http://test.com", find(new String[] { "noschemefirst.com", "http://test.com" })); + assertEquals("http://test.com/inner#test", find(new String[] { "noschemefirst.com", "http://test.com/inner#test", "http://second.org/fark" })); + assertEquals("http://test.com", find(new String[] { "javascript:///test.js", "http://test.com" })); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/BookmarkHelpers.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/BookmarkHelpers.java new file mode 100644 index 000000000..0fcd762f4 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/BookmarkHelpers.java @@ -0,0 +1,216 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.json.simple.JSONArray; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; + +public class BookmarkHelpers { + + private static String mobileFolderGuid = "mobile"; + private static String mobileFolderName = "mobile"; + private static String topFolderGuid = Utils.generateGuid(); + private static String topFolderName = "My Top Folder"; + private static String middleFolderGuid = Utils.generateGuid(); + private static String middleFolderName = "My Middle Folder"; + private static String bottomFolderGuid = Utils.generateGuid(); + private static String bottomFolderName = "My Bottom Folder"; + private static String bmk1Guid = Utils.generateGuid(); + private static String bmk2Guid = Utils.generateGuid(); + private static String bmk3Guid = Utils.generateGuid(); + private static String bmk4Guid = Utils.generateGuid(); + + /* + * Helpers for creating bookmark records of different types + */ + public static BookmarkRecord createBookmarkInMobileFolder1() { + BookmarkRecord rec = createBookmark1(); + rec.guid = Utils.generateGuid(); + rec.parentID = mobileFolderGuid; + rec.parentName = mobileFolderName; + return rec; + } + + public static BookmarkRecord createBookmarkInMobileFolder2() { + BookmarkRecord rec = createBookmark2(); + rec.guid = Utils.generateGuid(); + rec.parentID = mobileFolderGuid; + rec.parentName = mobileFolderName; + return rec; + } + + @SuppressWarnings("unchecked") + public static BookmarkRecord createBookmark1() { + BookmarkRecord record = new BookmarkRecord(); + JSONArray tags = new JSONArray(); + tags.add("tag1"); + tags.add("tag2"); + tags.add("tag3"); + record.guid = bmk1Guid; + record.title = "Foo!!!"; + record.bookmarkURI = "http://foo.bar.com"; + record.description = "This is a description for foo.bar.com"; + record.tags = tags; + record.keyword = "fooooozzzzz"; + record.parentID = topFolderGuid; + record.parentName = topFolderName; + record.type = "bookmark"; + return record; + } + + @SuppressWarnings("unchecked") + public static BookmarkRecord createBookmark2() { + BookmarkRecord record = new BookmarkRecord(); + JSONArray tags = new JSONArray(); + tags.add("tag1"); + tags.add("tag2"); + record.guid = bmk2Guid; + record.title = "Bar???"; + record.bookmarkURI = "http://bar.foo.com"; + record.description = "This is a description for Bar???"; + record.tags = tags; + record.keyword = "keywordzzz"; + record.parentID = topFolderGuid; + record.parentName = topFolderName; + record.type = "bookmark"; + return record; + } + + @SuppressWarnings("unchecked") + public static BookmarkRecord createBookmark3() { + BookmarkRecord record = new BookmarkRecord(); + JSONArray tags = new JSONArray(); + tags.add("tag1"); + tags.add("tag2"); + record.guid = bmk3Guid; + record.title = "Bmk3"; + record.bookmarkURI = "http://bmk3.com"; + record.description = "This is a description for bmk3"; + record.tags = tags; + record.keyword = "snooozzz"; + record.parentID = middleFolderGuid; + record.parentName = middleFolderName; + record.type = "bookmark"; + return record; + } + + @SuppressWarnings("unchecked") + public static BookmarkRecord createBookmark4() { + BookmarkRecord record = new BookmarkRecord(); + JSONArray tags = new JSONArray(); + tags.add("tag1"); + tags.add("tag2"); + record.guid = bmk4Guid; + record.title = "Bmk4"; + record.bookmarkURI = "http://bmk4.com"; + record.description = "This is a description for bmk4?"; + record.tags = tags; + record.keyword = "booooozzz"; + record.parentID = bottomFolderGuid; + record.parentName = bottomFolderName; + record.type = "bookmark"; + return record; + } + + @SuppressWarnings("unchecked") + public static BookmarkRecord createMicrosummary() { + BookmarkRecord record = new BookmarkRecord(); + JSONArray tags = new JSONArray(); + tags.add("tag1"); + tags.add("tag2"); + record.guid = Utils.generateGuid(); + record.title = "Microsummary 1"; + record.bookmarkURI = "www.bmkuri.com"; + record.description = "microsummary description"; + record.tags = tags; + record.keyword = "keywordzzz"; + record.parentID = topFolderGuid; + record.parentName = topFolderName; + record.type = "microsummary"; + return record; + } + + public static BookmarkRecord createQuery() { + BookmarkRecord record = new BookmarkRecord(); + record.guid = Utils.generateGuid(); + record.title = "Query 1"; + record.bookmarkURI = "http://www.query.com"; + record.description = "Query 1 description"; + record.tags = new JSONArray(); + record.keyword = "queryKeyword"; + record.parentID = topFolderGuid; + record.parentName = topFolderName; + record.type = "query"; + return record; + } + + @SuppressWarnings("unchecked") + public static BookmarkRecord createFolder1() { + BookmarkRecord record = new BookmarkRecord(); + record.guid = topFolderGuid; + record.title = topFolderName; + record.parentID = "mobile"; + record.parentName = "mobile"; + JSONArray children = new JSONArray(); + children.add(bmk1Guid); + children.add(bmk2Guid); + record.children = children; + record.type = "folder"; + return record; + } + + @SuppressWarnings("unchecked") + public static BookmarkRecord createFolder2() { + BookmarkRecord record = new BookmarkRecord(); + record.guid = middleFolderGuid; + record.title = middleFolderName; + record.parentID = topFolderGuid; + record.parentName = topFolderName; + JSONArray children = new JSONArray(); + children.add(bmk3Guid); + record.children = children; + record.type = "folder"; + return record; + } + + @SuppressWarnings("unchecked") + public static BookmarkRecord createFolder3() { + BookmarkRecord record = new BookmarkRecord(); + record.guid = bottomFolderGuid; + record.title = bottomFolderName; + record.parentID = middleFolderGuid; + record.parentName = middleFolderName; + JSONArray children = new JSONArray(); + children.add(bmk4Guid); + record.children = children; + record.type = "folder"; + return record; + } + + @SuppressWarnings("unchecked") + public static BookmarkRecord createLivemark() { + BookmarkRecord record = new BookmarkRecord(); + record.guid = Utils.generateGuid(); + record.title = "Livemark title"; + record.parentID = topFolderGuid; + record.parentName = topFolderName; + JSONArray children = new JSONArray(); + children.add(Utils.generateGuid()); + children.add(Utils.generateGuid()); + record.children = children; + record.type = "livemark"; + return record; + } + + public static BookmarkRecord createSeparator() { + BookmarkRecord record = new BookmarkRecord(); + record.guid = Utils.generateGuid(); + record.androidPosition = 3; + record.parentID = topFolderGuid; + record.parentName = topFolderName; + record.type = "separator"; + return record; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultBeginDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultBeginDelegate.java new file mode 100644 index 000000000..67aa81fff --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultBeginDelegate.java @@ -0,0 +1,33 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import java.util.concurrent.ExecutorService; + +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate; + +public class DefaultBeginDelegate extends DefaultDelegate implements RepositorySessionBeginDelegate { + @Override + public void onBeginFailed(Exception ex) { + performNotify("Begin failed", ex); + } + + @Override + public void onBeginSucceeded(RepositorySession session) { + performNotify("Default begin delegate hit.", null); + } + + @Override + public RepositorySessionBeginDelegate deferredBeginDelegate(ExecutorService executor) { + DefaultBeginDelegate copy; + try { + copy = (DefaultBeginDelegate) this.clone(); + copy.executor = executor; + return copy; + } catch (CloneNotSupportedException e) { + return this; + } + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultCleanDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultCleanDelegate.java new file mode 100644 index 000000000..a1f5b7a97 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultCleanDelegate.java @@ -0,0 +1,21 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCleanDelegate; + +public class DefaultCleanDelegate extends DefaultDelegate implements RepositorySessionCleanDelegate { + + @Override + public void onCleaned(Repository repo) { + performNotify("Default begin delegate hit.", null); + } + + @Override + public void onCleanFailed(Repository repo, Exception ex) { + performNotify("Clean failed.", ex); + } + +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultDelegate.java new file mode 100644 index 000000000..7e9341f02 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultDelegate.java @@ -0,0 +1,52 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import java.util.concurrent.ExecutorService; + +import junit.framework.AssertionFailedError; + +import org.mozilla.gecko.background.testhelpers.WaitHelper; + +public abstract class DefaultDelegate { + protected ExecutorService executor; + + protected final WaitHelper waitHelper; + + public DefaultDelegate() { + waitHelper = WaitHelper.getTestWaiter(); + } + + public DefaultDelegate(WaitHelper waitHelper) { + this.waitHelper = waitHelper; + } + + protected WaitHelper getTestWaiter() { + return waitHelper; + } + + public void performWait(Runnable runnable) throws AssertionFailedError { + getTestWaiter().performWait(runnable); + } + + public void performNotify() { + getTestWaiter().performNotify(); + } + + public void performNotify(Throwable e) { + getTestWaiter().performNotify(e); + } + + public void performNotify(String reason, Throwable e) { + String message = reason; + if (e != null) { + message += ": " + e.getMessage(); + } + AssertionFailedError ex = new AssertionFailedError(message); + if (e != null) { + ex.initCause(e); + } + getTestWaiter().performNotify(ex); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java new file mode 100644 index 000000000..3d7d23bab --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFetchDelegate.java @@ -0,0 +1,106 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; +import static junit.framework.Assert.fail; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.ExecutorService; + +import junit.framework.AssertionFailedError; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.sync.repositories.delegates.DeferredRepositorySessionFetchRecordsDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; +import org.mozilla.gecko.sync.repositories.domain.Record; + +public class DefaultFetchDelegate extends DefaultDelegate implements RepositorySessionFetchRecordsDelegate { + + private static final String LOG_TAG = "DefaultFetchDelegate"; + public ArrayList records = new ArrayList(); + public Set ignore = new HashSet(); + + @Override + public void onFetchFailed(Exception ex, Record record) { + performNotify("Fetch failed.", ex); + } + + protected void onDone(ArrayList records, HashMap expected, long end) { + Logger.debug(LOG_TAG, "onDone."); + Logger.debug(LOG_TAG, "End timestamp is " + end); + Logger.debug(LOG_TAG, "Expected is " + expected); + Logger.debug(LOG_TAG, "Records is " + records); + Set foundGuids = new HashSet(); + try { + int expectedCount = 0; + int expectedFound = 0; + Logger.debug(LOG_TAG, "Counting expected keys."); + for (String key : expected.keySet()) { + if (!ignore.contains(key)) { + expectedCount++; + } + } + Logger.debug(LOG_TAG, "Expected keys: " + expectedCount); + for (Record record : records) { + Logger.debug(LOG_TAG, "Record."); + Logger.debug(LOG_TAG, record.guid); + + // Ignore special GUIDs (e.g., for bookmarks). + if (!ignore.contains(record.guid)) { + if (foundGuids.contains(record.guid)) { + fail("Found duplicate guid " + record.guid); + } + Record expect = expected.get(record.guid); + if (expect == null) { + fail("Do not expect to get back a record with guid: " + record.guid); // Caught below + } + Logger.debug(LOG_TAG, "Checking equality."); + try { + assertTrue(expect.equalPayloads(record)); // Caught below + } catch (Exception e) { + Logger.error(LOG_TAG, "ONOZ!", e); + } + Logger.debug(LOG_TAG, "Checked equality."); + expectedFound += 1; + // Track record once we've found it. + foundGuids.add(record.guid); + } + } + assertEquals(expectedCount, expectedFound); // Caught below + Logger.debug(LOG_TAG, "Notifying success."); + performNotify(); + } catch (AssertionFailedError e) { + Logger.error(LOG_TAG, "Notifying assertion failure."); + performNotify(e); + } catch (Exception e) { + Logger.error(LOG_TAG, "No!"); + performNotify(); + } + } + + public int recordCount() { + return (this.records == null) ? 0 : this.records.size(); + } + + @Override + public void onFetchedRecord(Record record) { + Logger.debug(LOG_TAG, "onFetchedRecord(" + record.guid + ")"); + records.add(record); + } + + @Override + public void onFetchCompleted(final long fetchEnd) { + Logger.debug(LOG_TAG, "onFetchCompleted. Doing nothing."); + } + + @Override + public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(final ExecutorService executor) { + return new DeferredRepositorySessionFetchRecordsDelegate(this, executor); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFinishDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFinishDelegate.java new file mode 100644 index 000000000..11e451e82 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultFinishDelegate.java @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import java.util.concurrent.ExecutorService; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; + +public class DefaultFinishDelegate extends DefaultDelegate implements RepositorySessionFinishDelegate { + + @Override + public void onFinishFailed(Exception ex) { + performNotify("Finish failed", ex); + } + + @Override + public void onFinishSucceeded(RepositorySession session, RepositorySessionBundle bundle) { + performNotify("Hit default finish delegate", null); + } + + @Override + public RepositorySessionFinishDelegate deferredFinishDelegate(final ExecutorService executor) { + final RepositorySessionFinishDelegate self = this; + + Logger.info("DefaultFinishDelegate", "Deferring…"); + return new RepositorySessionFinishDelegate() { + @Override + public void onFinishSucceeded(final RepositorySession session, + final RepositorySessionBundle bundle) { + Logger.info("DefaultFinishDelegate", "Executing onFinishSucceeded Runnable…"); + executor.execute(new Runnable() { + @Override + public void run() { + self.onFinishSucceeded(session, bundle); + }}); + } + + @Override + public void onFinishFailed(final Exception ex) { + executor.execute(new Runnable() { + @Override + public void run() { + self.onFinishFailed(ex); + }}); + } + + @Override + public RepositorySessionFinishDelegate deferredFinishDelegate(ExecutorService newExecutor) { + if (newExecutor == executor) { + return this; + } + throw new IllegalArgumentException("Can't re-defer this delegate."); + } + }; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultGuidsSinceDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultGuidsSinceDelegate.java new file mode 100644 index 000000000..78e3cc84f --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultGuidsSinceDelegate.java @@ -0,0 +1,19 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionGuidsSinceDelegate; + +public class DefaultGuidsSinceDelegate extends DefaultDelegate implements RepositorySessionGuidsSinceDelegate { + + @Override + public void onGuidsSinceFailed(Exception ex) { + performNotify("shouldn't fail", ex); + } + + @Override + public void onGuidsSinceSucceeded(String[] guids) { + performNotify("default guids since delegate called", null); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultSessionCreationDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultSessionCreationDelegate.java new file mode 100644 index 000000000..5d52df84d --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultSessionCreationDelegate.java @@ -0,0 +1,53 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; + +public class DefaultSessionCreationDelegate extends DefaultDelegate implements + RepositorySessionCreationDelegate { + + @Override + public void onSessionCreateFailed(Exception ex) { + performNotify("Session creation failed", ex); + } + + @Override + public void onSessionCreated(RepositorySession session) { + performNotify("Should not have been created.", null); + } + + @Override + public RepositorySessionCreationDelegate deferredCreationDelegate() { + final RepositorySessionCreationDelegate self = this; + return new RepositorySessionCreationDelegate() { + + @Override + public void onSessionCreated(final RepositorySession session) { + new Thread(new Runnable() { + @Override + public void run() { + self.onSessionCreated(session); + } + }).start(); + } + + @Override + public void onSessionCreateFailed(final Exception ex) { + new Thread(new Runnable() { + @Override + public void run() { + self.onSessionCreateFailed(ex); + } + }).start(); + } + + @Override + public RepositorySessionCreationDelegate deferredCreationDelegate() { + return this; + } + }; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultStoreDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultStoreDelegate.java new file mode 100644 index 000000000..7ba2e6df6 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/DefaultStoreDelegate.java @@ -0,0 +1,71 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import java.util.concurrent.ExecutorService; + +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; + +public class DefaultStoreDelegate extends DefaultDelegate implements RepositorySessionStoreDelegate { + + @Override + public void onRecordStoreFailed(Exception ex, String guid) { + performNotify("Store failed", ex); + } + + @Override + public void onRecordStoreSucceeded(String guid) { + performNotify("DefaultStoreDelegate used", null); + } + + @Override + public void onStoreCompleted(long storeEnd) { + performNotify("DefaultStoreDelegate used", null); + } + + @Override + public RepositorySessionStoreDelegate deferredStoreDelegate(final ExecutorService executor) { + final RepositorySessionStoreDelegate self = this; + return new RepositorySessionStoreDelegate() { + + @Override + public void onRecordStoreSucceeded(final String guid) { + executor.execute(new Runnable() { + @Override + public void run() { + self.onRecordStoreSucceeded(guid); + } + }); + } + + @Override + public void onRecordStoreFailed(final Exception ex, final String guid) { + executor.execute(new Runnable() { + @Override + public void run() { + self.onRecordStoreFailed(ex, guid); + } + }); + } + + @Override + public void onStoreCompleted(final long storeEnd) { + executor.execute(new Runnable() { + @Override + public void run() { + self.onStoreCompleted(storeEnd); + } + }); + } + + @Override + public RepositorySessionStoreDelegate deferredStoreDelegate(ExecutorService newExecutor) { + if (newExecutor == executor) { + return this; + } + throw new IllegalArgumentException("Can't re-defer this delegate."); + } + }; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectBeginDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectBeginDelegate.java new file mode 100644 index 000000000..d320cfd7a --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectBeginDelegate.java @@ -0,0 +1,22 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import static junit.framework.Assert.assertNotNull; +import junit.framework.AssertionFailedError; + +import org.mozilla.gecko.sync.repositories.RepositorySession; + +public class ExpectBeginDelegate extends DefaultBeginDelegate { + @Override + public void onBeginSucceeded(RepositorySession session) { + try { + assertNotNull(session); + } catch (AssertionFailedError e) { + performNotify("Expected non-null session", e); + return; + } + performNotify(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectBeginFailDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectBeginFailDelegate.java new file mode 100644 index 000000000..ff1807d51 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectBeginFailDelegate.java @@ -0,0 +1,16 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; + +public class ExpectBeginFailDelegate extends DefaultBeginDelegate { + + @Override + public void onBeginFailed(Exception ex) { + if (!(ex instanceof InvalidSessionTransitionException)) { + performNotify("Expected InvalidSessionTransititionException but got ", ex); + } + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFetchDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFetchDelegate.java new file mode 100644 index 000000000..5cfe5327a --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFetchDelegate.java @@ -0,0 +1,32 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import java.util.HashMap; + +import org.mozilla.gecko.sync.repositories.domain.Record; + +public class ExpectFetchDelegate extends DefaultFetchDelegate { + private HashMap expect = new HashMap(); + + public ExpectFetchDelegate(Record[] records) { + for(int i = 0; i < records.length; i++) { + expect.put(records[i].guid, records[i]); + } + } + + @Override + public void onFetchedRecord(Record record) { + this.records.add(record); + } + + @Override + public void onFetchCompleted(final long fetchEnd) { + super.onDone(this.records, this.expect, fetchEnd); + } + + public Record recordAt(int i) { + return this.records.get(i); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFetchSinceDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFetchSinceDelegate.java new file mode 100644 index 000000000..7dcada0d4 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFetchSinceDelegate.java @@ -0,0 +1,47 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; + +import java.util.Arrays; + +import org.mozilla.gecko.sync.repositories.domain.Record; + +import junit.framework.AssertionFailedError; + +public class ExpectFetchSinceDelegate extends DefaultFetchDelegate { + private String[] expected; + private long earliest; + + public ExpectFetchSinceDelegate(long timestamp, String[] guids) { + expected = guids; + earliest = timestamp; + Arrays.sort(expected); + } + + @Override + public void onFetchCompleted(final long fetchEnd) { + AssertionFailedError err = null; + try { + int countSpecials = 0; + for (Record record : records) { + // Check if record should be ignored. + if (!ignore.contains(record.guid)) { + assertFalse(-1 == Arrays.binarySearch(this.expected, record.guid)); + } else { + countSpecials++; + } + // Check that record is later than timestamp-earliest. + assertTrue(record.lastModified >= this.earliest); + } + assertEquals(this.expected.length, records.size() - countSpecials); + } catch (AssertionFailedError e) { + err = e; + } + performNotify(err); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFinishDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFinishDelegate.java new file mode 100644 index 000000000..0b6f1de88 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFinishDelegate.java @@ -0,0 +1,17 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; + +public class ExpectFinishDelegate extends DefaultFinishDelegate { + + @Override + public void onFinishSucceeded(RepositorySession session, RepositorySessionBundle bundle) { + Logger.info("ExpectFinishDelegate", "Finish succeeded."); + performNotify(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFinishFailDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFinishFailDelegate.java new file mode 100644 index 000000000..df83432bc --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectFinishFailDelegate.java @@ -0,0 +1,15 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; + +public class ExpectFinishFailDelegate extends DefaultFinishDelegate { + @Override + public void onFinishFailed(Exception ex) { + if (!(ex instanceof InvalidSessionTransitionException)) { + performNotify("Expected InvalidSessionTransititionException but got ", ex); + } + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectGuidsSinceDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectGuidsSinceDelegate.java new file mode 100644 index 000000000..435ba7502 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectGuidsSinceDelegate.java @@ -0,0 +1,41 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import junit.framework.AssertionFailedError; + +public class ExpectGuidsSinceDelegate extends DefaultGuidsSinceDelegate { + private String[] expected; + public Set ignore = new HashSet(); + + public ExpectGuidsSinceDelegate(String[] guids) { + expected = guids; + Arrays.sort(expected); + } + + @Override + public void onGuidsSinceSucceeded(String[] guids) { + AssertionFailedError err = null; + try { + int notIgnored = 0; + for (String guid : guids) { + if (!ignore.contains(guid)) { + notIgnored++; + assertFalse(-1 == Arrays.binarySearch(this.expected, guid)); + } + } + assertEquals(this.expected.length, notIgnored); + } catch (AssertionFailedError e) { + err = e; + } + performNotify(err); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectInvalidRequestFetchDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectInvalidRequestFetchDelegate.java new file mode 100644 index 000000000..73035869c --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectInvalidRequestFetchDelegate.java @@ -0,0 +1,24 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.mozilla.gecko.sync.repositories.InvalidRequestException; +import org.mozilla.gecko.sync.repositories.domain.Record; + +public class ExpectInvalidRequestFetchDelegate extends DefaultFetchDelegate { + public static final String LOG_TAG = "ExpInvRequestFetchDel"; + + @Override + public void onFetchFailed(Exception ex, Record rec) { + if (ex instanceof InvalidRequestException) { + onDone(); + } else { + performNotify("Expected InvalidRequestException but got ", ex); + } + } + + private void onDone() { + performNotify(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectInvalidTypeStoreDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectInvalidTypeStoreDelegate.java new file mode 100644 index 000000000..5ce56ee5f --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectInvalidTypeStoreDelegate.java @@ -0,0 +1,18 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import static junit.framework.Assert.assertEquals; + +import org.mozilla.gecko.sync.repositories.InvalidBookmarkTypeException; + +public class ExpectInvalidTypeStoreDelegate extends DefaultStoreDelegate { + + @Override + public void onRecordStoreFailed(Exception ex, String guid) { + assertEquals(InvalidBookmarkTypeException.class, ex.getClass()); + performNotify(); + } + +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectManyStoredDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectManyStoredDelegate.java new file mode 100644 index 000000000..2a8df0228 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectManyStoredDelegate.java @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + +import java.util.HashSet; +import java.util.concurrent.atomic.AtomicLong; + +import junit.framework.AssertionFailedError; + +import org.mozilla.gecko.sync.repositories.domain.Record; + +public class ExpectManyStoredDelegate extends DefaultStoreDelegate { + HashSet expectedGUIDs; + AtomicLong stored; + + public ExpectManyStoredDelegate(Record[] records) { + HashSet s = new HashSet(); + for (Record record : records) { + s.add(record.guid); + } + expectedGUIDs = s; + stored = new AtomicLong(0); + } + + @Override + public void onStoreCompleted(long storeEnd) { + try { + assertEquals(expectedGUIDs.size(), stored.get()); + performNotify(); + } catch (AssertionFailedError e) { + performNotify(e); + } + } + + @Override + public void onRecordStoreSucceeded(String guid) { + try { + assertTrue(expectedGUIDs.contains(guid)); + } catch (AssertionFailedError e) { + performNotify(e); + } + stored.incrementAndGet(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectNoGUIDsSinceDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectNoGUIDsSinceDelegate.java new file mode 100644 index 000000000..a9f11d7b0 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectNoGUIDsSinceDelegate.java @@ -0,0 +1,33 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import static junit.framework.Assert.assertEquals; + +import java.util.HashSet; +import java.util.Set; + +import junit.framework.AssertionFailedError; + +public class ExpectNoGUIDsSinceDelegate extends DefaultGuidsSinceDelegate { + + public Set ignore = new HashSet(); + + @Override + public void onGuidsSinceSucceeded(String[] guids) { + AssertionFailedError err = null; + try { + int nonIgnored = 0; + for (int i = 0; i < guids.length; i++) { + if (!ignore.contains(guids[i])) { + nonIgnored++; + } + } + assertEquals(0, nonIgnored); + } catch (AssertionFailedError e) { + err = e; + } + performNotify(err); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectNoStoreDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectNoStoreDelegate.java new file mode 100644 index 000000000..93626898e --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectNoStoreDelegate.java @@ -0,0 +1,11 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +public class ExpectNoStoreDelegate extends ExpectStoreCompletedDelegate { + @Override + public void onRecordStoreSucceeded(String guid) { + performNotify("Should not have stored record " + guid, null); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectStoreCompletedDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectStoreCompletedDelegate.java new file mode 100644 index 000000000..b3cc909a1 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectStoreCompletedDelegate.java @@ -0,0 +1,17 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +public class ExpectStoreCompletedDelegate extends DefaultStoreDelegate { + + @Override + public void onRecordStoreSucceeded(String guid) { + // That's fine. + } + + @Override + public void onStoreCompleted(long storeEnd) { + performNotify(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectStoredDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectStoredDelegate.java new file mode 100644 index 000000000..dc2e8a2d1 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/ExpectStoredDelegate.java @@ -0,0 +1,39 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import junit.framework.AssertionFailedError; + +public class ExpectStoredDelegate extends DefaultStoreDelegate { + String expectedGUID; + String storedGuid; + + public ExpectStoredDelegate(String guid) { + this.expectedGUID = guid; + } + + @Override + public synchronized void onStoreCompleted(long storeEnd) { + try { + assertNotNull(storedGuid); + performNotify(); + } catch (AssertionFailedError e) { + performNotify("GUID " + this.expectedGUID + " was not stored", e); + } + } + + @Override + public synchronized void onRecordStoreSucceeded(String guid) { + this.storedGuid = guid; + try { + if (this.expectedGUID != null) { + assertEquals(this.expectedGUID, guid); + } + } catch (AssertionFailedError e) { + performNotify(e); + } + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/HistoryHelpers.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/HistoryHelpers.java new file mode 100644 index 000000000..68f80043e --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/HistoryHelpers.java @@ -0,0 +1,90 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.mozilla.gecko.sync.repositories.domain.HistoryRecord; + +public class HistoryHelpers { + + @SuppressWarnings("unchecked") + private static JSONArray getVisits1() { + JSONArray json = new JSONArray(); + JSONObject obj = new JSONObject(); + obj.put("date", 1320087601465600000L); + obj.put("type", 2L); + json.add(obj); + obj = new JSONObject(); + obj.put("date", 1320084970724990000L); + obj.put("type", 1L); + json.add(obj); + obj = new JSONObject(); + obj.put("date", 1319764134412287000L); + obj.put("type", 1L); + json.add(obj); + obj = new JSONObject(); + obj.put("date", 1319681306455594000L); + obj.put("type", 2L); + json.add(obj); + return json; + } + + @SuppressWarnings("unchecked") + private static JSONArray getVisits2() { + JSONArray json = new JSONArray(); + JSONObject obj = new JSONObject(); + obj = new JSONObject(); + obj.put("date", 1319764134412345000L); + obj.put("type", 4L); + json.add(obj); + obj = new JSONObject(); + obj.put("date", 1319681306454321000L); + obj.put("type", 3L); + json.add(obj); + return json; + } + + public static HistoryRecord createHistory1() { + HistoryRecord record = new HistoryRecord(); + record.title = "History 1"; + record.histURI = "http://history.page1.com"; + record.visits = getVisits1(); + return record; + } + + + public static HistoryRecord createHistory2() { + HistoryRecord record = new HistoryRecord(); + record.title = "History 2"; + record.histURI = "http://history.page2.com"; + record.visits = getVisits2(); + return record; + } + + public static HistoryRecord createHistory3() { + HistoryRecord record = new HistoryRecord(); + record.title = "History 3"; + record.histURI = "http://history.page3.com"; + record.visits = getVisits2(); + return record; + } + + public static HistoryRecord createHistory4() { + HistoryRecord record = new HistoryRecord(); + record.title = "History 4"; + record.histURI = "http://history.page4.com"; + record.visits = getVisits1(); + return record; + } + + public static HistoryRecord createHistory5() { + HistoryRecord record = new HistoryRecord(); + record.title = "History 5"; + record.histURI = "http://history.page5.com"; + record.visits = getVisits2(); + return record; + } + +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/PasswordHelpers.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/PasswordHelpers.java new file mode 100644 index 000000000..87400a2b0 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/PasswordHelpers.java @@ -0,0 +1,94 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.mozilla.gecko.sync.repositories.domain.PasswordRecord; + +public class PasswordHelpers { + + public static PasswordRecord createPassword1() { + PasswordRecord rec = new PasswordRecord(); + rec.encType = "some type"; + rec.formSubmitURL = "http://submit.html"; + rec.hostname = "http://hostname"; + rec.httpRealm = "httpRealm"; + rec.encryptedPassword ="12345"; + rec.passwordField = "box.pass.field"; + rec.timeCreated = 111111111L; + rec.timeLastUsed = 123412352435L; + rec.timePasswordChanged = 121111111L; + rec.timesUsed = 5L; + rec.encryptedUsername = "jvoll"; + rec.usernameField = "box.user.field"; + return rec; + } + + public static PasswordRecord createPassword2() { + PasswordRecord rec = new PasswordRecord(); + rec.encType = "some type"; + rec.formSubmitURL = "http://submit2.html"; + rec.hostname = "http://hostname2"; + rec.httpRealm = "httpRealm2"; + rec.encryptedPassword ="54321"; + rec.passwordField = "box.pass.field2"; + rec.timeCreated = 12111111111L; + rec.timeLastUsed = 123412352213L; + rec.timePasswordChanged = 123111111111L; + rec.timesUsed = 2L; + rec.encryptedUsername = "rnewman"; + rec.usernameField = "box.user.field2"; + return rec; + } + + public static PasswordRecord createPassword3() { + PasswordRecord rec = new PasswordRecord(); + rec.encType = "some type3"; + rec.formSubmitURL = "http://submit3.html"; + rec.hostname = "http://hostname3"; + rec.httpRealm = "httpRealm3"; + rec.encryptedPassword ="54321"; + rec.passwordField = "box.pass.field3"; + rec.timeCreated = 100000000000L; + rec.timeLastUsed = 123412352213L; + rec.timePasswordChanged = 110000000000L; + rec.timesUsed = 2L; + rec.encryptedUsername = "rnewman"; + rec.usernameField = "box.user.field3"; + return rec; + } + + public static PasswordRecord createPassword4() { + PasswordRecord rec = new PasswordRecord(); + rec.encType = "some type"; + rec.formSubmitURL = "http://submit4.html"; + rec.hostname = "http://hostname4"; + rec.httpRealm = "httpRealm4"; + rec.encryptedPassword ="54324"; + rec.passwordField = "box.pass.field4"; + rec.timeCreated = 101000000000L; + rec.timeLastUsed = 123412354444L; + rec.timePasswordChanged = 110000000000L; + rec.timesUsed = 4L; + rec.encryptedUsername = "rnewman4"; + rec.usernameField = "box.user.field4"; + return rec; + } + + public static PasswordRecord createPassword5() { + PasswordRecord rec = new PasswordRecord(); + rec.encType = "some type5"; + rec.formSubmitURL = "http://submit5.html"; + rec.hostname = "http://hostname5"; + rec.httpRealm = "httpRealm5"; + rec.encryptedPassword ="54325"; + rec.passwordField = "box.pass.field5"; + rec.timeCreated = 101000000000L; + rec.timeLastUsed = 123412352555L; + rec.timePasswordChanged = 111111111111L; + rec.timesUsed = 5L; + rec.encryptedUsername = "jvoll5"; + rec.usernameField = "box.user.field5"; + return rec; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SessionTestHelper.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SessionTestHelper.java new file mode 100644 index 000000000..9c9e6719b --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SessionTestHelper.java @@ -0,0 +1,82 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import static junit.framework.Assert.assertNotNull; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.repositories.RepositorySession; + +import android.content.Context; + +public class SessionTestHelper { + + protected static RepositorySession prepareRepositorySession( + final Context context, + final boolean begin, + final Repository repository) { + + final WaitHelper testWaiter = WaitHelper.getTestWaiter(); + + final String logTag = "prepareRepositorySession"; + class CreationDelegate extends DefaultSessionCreationDelegate { + private RepositorySession session; + synchronized void setSession(RepositorySession session) { + this.session = session; + } + synchronized RepositorySession getSession() { + return this.session; + } + + @Override + public void onSessionCreated(final RepositorySession session) { + assertNotNull(session); + Logger.info(logTag, "Setting session to " + session); + setSession(session); + if (begin) { + Logger.info(logTag, "Calling session.begin on new session."); + // The begin callbacks will notify. + try { + session.begin(new ExpectBeginDelegate()); + } catch (InvalidSessionTransitionException e) { + testWaiter.performNotify(e); + } + } else { + Logger.info(logTag, "Notifying after setting new session."); + testWaiter.performNotify(); + } + } + } + + final CreationDelegate delegate = new CreationDelegate(); + try { + Runnable runnable = new Runnable() { + @Override + public void run() { + repository.createSession(delegate, context); + } + }; + testWaiter.performWait(runnable); + } catch (IllegalArgumentException ex) { + Logger.warn(logTag, "Caught IllegalArgumentException."); + } + + Logger.info(logTag, "Retrieving new session."); + final RepositorySession session = delegate.getSession(); + assertNotNull(session); + + return session; + } + + public static RepositorySession createSession(final Context context, final Repository repository) { + return prepareRepositorySession(context, false, repository); + } + + public static RepositorySession createAndBeginSession(Context context, Repository repository) { + return prepareRepositorySession(context, true, repository); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessBeginDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessBeginDelegate.java new file mode 100644 index 000000000..0eb477be7 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessBeginDelegate.java @@ -0,0 +1,20 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import java.util.concurrent.ExecutorService; + +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate; + +public abstract class SimpleSuccessBeginDelegate extends DefaultDelegate implements RepositorySessionBeginDelegate { + @Override + public void onBeginFailed(Exception ex) { + performNotify("Begin failed", ex); + } + + @Override + public RepositorySessionBeginDelegate deferredBeginDelegate(ExecutorService executor) { + return this; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessCreationDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessCreationDelegate.java new file mode 100644 index 000000000..3b3b3d5fa --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessCreationDelegate.java @@ -0,0 +1,18 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; + +public abstract class SimpleSuccessCreationDelegate extends DefaultDelegate implements RepositorySessionCreationDelegate { + @Override + public void onSessionCreateFailed(Exception ex) { + performNotify("Session creation failed", ex); + } + + @Override + public RepositorySessionCreationDelegate deferredCreationDelegate() { + return this; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFetchDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFetchDelegate.java new file mode 100644 index 000000000..f0e9428ba --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFetchDelegate.java @@ -0,0 +1,22 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import java.util.concurrent.ExecutorService; + +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; +import org.mozilla.gecko.sync.repositories.domain.Record; + +public abstract class SimpleSuccessFetchDelegate extends DefaultDelegate implements + RepositorySessionFetchRecordsDelegate { + @Override + public void onFetchFailed(Exception ex, Record record) { + performNotify("Fetch failed", ex); + } + + @Override + public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) { + return this; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFinishDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFinishDelegate.java new file mode 100644 index 000000000..5ac1bcde7 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessFinishDelegate.java @@ -0,0 +1,20 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import java.util.concurrent.ExecutorService; + +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; + +public abstract class SimpleSuccessFinishDelegate extends DefaultDelegate implements RepositorySessionFinishDelegate { + @Override + public void onFinishFailed(Exception ex) { + performNotify("Finish failed", ex); + } + + @Override + public RepositorySessionFinishDelegate deferredFinishDelegate(ExecutorService executor) { + return this; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessStoreDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessStoreDelegate.java new file mode 100644 index 000000000..c725c4a46 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/sync/helpers/SimpleSuccessStoreDelegate.java @@ -0,0 +1,20 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.sync.helpers; + +import java.util.concurrent.ExecutorService; + +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; + +public abstract class SimpleSuccessStoreDelegate extends DefaultDelegate implements RepositorySessionStoreDelegate { + @Override + public void onRecordStoreFailed(Exception ex, String guid) { + performNotify("Store failed", ex); + } + + @Override + public RepositorySessionStoreDelegate deferredStoreDelegate(ExecutorService executor) { + return this; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/BaseMockServerSyncStage.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/BaseMockServerSyncStage.java new file mode 100644 index 000000000..d2a8b8476 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/BaseMockServerSyncStage.java @@ -0,0 +1,69 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.NoCollectionKeysSetException; +import org.mozilla.gecko.sync.SynchronizerConfiguration; +import org.mozilla.gecko.sync.repositories.RecordFactory; +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.stage.ServerSyncStage; + +import java.net.URISyntaxException; + +/** + * A stage that joins two Repositories with no wrapping. + */ +public abstract class BaseMockServerSyncStage extends ServerSyncStage { + + public Repository local; + public Repository remote; + public String name; + public String collection; + public int version = 1; + + @Override + public boolean isEnabled() { + return true; + } + + @Override + protected String getCollection() { + return collection; + } + + @Override + protected Repository getLocalRepository() { + return local; + } + + @Override + protected Repository getRemoteRepository() throws URISyntaxException { + return remote; + } + + @Override + protected String getEngineName() { + return name; + } + + @Override + public Integer getStorageVersion() { + return version; + } + + @Override + protected RecordFactory getRecordFactory() { + return null; + } + + @Override + protected Repository wrappedServerRepo() + throws NoCollectionKeysSetException, URISyntaxException { + return getRemoteRepository(); + } + + public SynchronizerConfiguration leakConfig() throws Exception { + return this.getConfig(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/CommandHelpers.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/CommandHelpers.java new file mode 100644 index 000000000..48217f1b0 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/CommandHelpers.java @@ -0,0 +1,40 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.json.simple.JSONArray; +import org.mozilla.gecko.sync.CommandProcessor.Command; + +public class CommandHelpers { + + @SuppressWarnings("unchecked") + public static Command getCommand1() { + JSONArray args = new JSONArray(); + args.add("argsA"); + return new Command("displayURI", args); + } + + @SuppressWarnings("unchecked") + public static Command getCommand2() { + JSONArray args = new JSONArray(); + args.add("argsB"); + return new Command("displayURI", args); + } + + @SuppressWarnings("unchecked") + public static Command getCommand3() { + JSONArray args = new JSONArray(); + args.add("argsC"); + return new Command("displayURI", args); + } + + @SuppressWarnings("unchecked") + public static Command getCommand4() { + JSONArray args = new JSONArray(); + args.add("URI of Page"); + args.add("Sender ID"); + args.add("Title of Page"); + return new Command("displayURI", args); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/DefaultGlobalSessionCallback.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/DefaultGlobalSessionCallback.java new file mode 100644 index 000000000..c8be7e330 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/DefaultGlobalSessionCallback.java @@ -0,0 +1,52 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import java.net.URI; + +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; + +public class DefaultGlobalSessionCallback implements GlobalSessionCallback { + + @Override + public void requestBackoff(long backoff) { + } + + @Override + public void informUnauthorizedResponse(GlobalSession globalSession, + URI oldClusterURL) { + } + + @Override + public void informUpgradeRequiredResponse(GlobalSession session) { + } + + @Override + public void informMigrated(GlobalSession globalSession) { + } + + @Override + public void handleAborted(GlobalSession globalSession, String reason) { + } + + @Override + public void handleError(GlobalSession globalSession, Exception ex) { + } + + @Override + public void handleSuccess(GlobalSession globalSession) { + } + + @Override + public void handleStageCompleted(Stage currentState, + GlobalSession globalSession) { + } + + @Override + public boolean shouldBackOffStorage() { + return false; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockAbstractNonRepositorySyncStage.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockAbstractNonRepositorySyncStage.java new file mode 100644 index 000000000..d8380df97 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockAbstractNonRepositorySyncStage.java @@ -0,0 +1,13 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.stage.AbstractNonRepositorySyncStage; + +public class MockAbstractNonRepositorySyncStage extends AbstractNonRepositorySyncStage { + @Override + public void execute() { + session.advance(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockClientsDataDelegate.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockClientsDataDelegate.java new file mode 100644 index 000000000..f4af51f64 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockClientsDataDelegate.java @@ -0,0 +1,66 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; + +public class MockClientsDataDelegate implements ClientsDataDelegate { + private String accountGUID; + private String clientName; + private int clientsCount; + private long clientDataTimestamp = 0; + + @Override + public synchronized String getAccountGUID() { + if (accountGUID == null) { + accountGUID = Utils.generateGuid(); + } + return accountGUID; + } + + @Override + public synchronized String getDefaultClientName() { + return "Default client"; + } + + @Override + public synchronized void setClientName(String clientName, long now) { + this.clientName = clientName; + this.clientDataTimestamp = now; + } + + @Override + public synchronized String getClientName() { + if (clientName == null) { + setClientName(getDefaultClientName(), System.currentTimeMillis()); + } + return clientName; + } + + @Override + public synchronized void setClientsCount(int clientsCount) { + this.clientsCount = clientsCount; + } + + @Override + public synchronized int getClientsCount() { + return clientsCount; + } + + @Override + public synchronized boolean isLocalGUID(String guid) { + return getAccountGUID().equals(guid); + } + + @Override + public synchronized long getLastModifiedTimestamp() { + return clientDataTimestamp; + } + + @Override + public String getFormFactor() { + return "phone"; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockClientsDatabaseAccessor.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockClientsDatabaseAccessor.java new file mode 100644 index 000000000..5e574e33d --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockClientsDatabaseAccessor.java @@ -0,0 +1,76 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.mozilla.gecko.sync.CommandProcessor.Command; +import org.mozilla.gecko.sync.repositories.NullCursorException; +import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor; +import org.mozilla.gecko.sync.repositories.domain.ClientRecord; + +public class MockClientsDatabaseAccessor extends ClientsDatabaseAccessor { + public boolean storedRecord = false; + public boolean dbWiped = false; + public boolean clientsTableWiped = false; + public boolean closed = false; + public boolean storedArrayList = false; + public boolean storedCommand; + + @Override + public void store(ClientRecord record) { + storedRecord = true; + } + + @Override + public void store(Collection records) { + storedArrayList = false; + } + + @Override + public void store(String accountGUID, Command command) throws NullCursorException { + storedCommand = true; + } + + @Override + public ClientRecord fetchClient(String profileID) throws NullCursorException { + return null; + } + + @Override + public Map fetchAllClients() throws NullCursorException { + return null; + } + + @Override + public List fetchCommandsForClient(String accountGUID) throws NullCursorException { + return null; + } + + @Override + public int clientsCount() { + return 0; + } + + @Override + public void wipeDB() { + dbWiped = true; + } + + @Override + public void wipeClientsTable() { + clientsTableWiped = true; + } + + @Override + public void close() { + closed = true; + } + + public void resetVars() { + storedRecord = dbWiped = clientsTableWiped = closed = storedArrayList = false; + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockGlobalSession.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockGlobalSession.java new file mode 100644 index 000000000..63afdd1ac --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockGlobalSession.java @@ -0,0 +1,57 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.EngineSettings; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.SyncConfiguration; +import org.mozilla.gecko.sync.SyncConfigurationException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.stage.CompletedStage; +import org.mozilla.gecko.sync.stage.GlobalSyncStage; +import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; + +import java.io.IOException; +import java.util.HashMap; + + +public class MockGlobalSession extends MockPrefsGlobalSession { + + public MockGlobalSession(String username, String password, KeyBundle keyBundle, GlobalSessionCallback callback) throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException { + this(new SyncConfiguration(username, new BasicAuthHeaderProvider(username, password), new MockSharedPreferences(), keyBundle), callback); + } + + public MockGlobalSession(SyncConfiguration config, GlobalSessionCallback callback) + throws SyncConfigurationException, IllegalArgumentException, IOException, NonObjectJSONException { + super(config, callback, null, null); + } + + @Override + public boolean isEngineRemotelyEnabled(String engine, EngineSettings engineSettings) { + return false; + } + + @Override + protected void prepareStages() { + super.prepareStages(); + HashMap newStages = new HashMap(this.stages); + + for (Stage stage : this.stages.keySet()) { + newStages.put(stage, new MockServerSyncStage()); + } + + // This signals that the global session is complete. + newStages.put(Stage.completed, new CompletedStage()); + + this.stages = newStages; + } + + public MockGlobalSession withStage(Stage stage, GlobalSyncStage syncStage) { + stages.put(stage, syncStage); + + return this; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockPrefsGlobalSession.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockPrefsGlobalSession.java new file mode 100644 index 000000000..2ff29453f --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockPrefsGlobalSession.java @@ -0,0 +1,63 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import android.content.Context; +import android.content.SharedPreferences; + +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.SyncConfiguration; +import org.mozilla.gecko.sync.SyncConfigurationException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; + +import java.io.IOException; + +/** + * GlobalSession touches the Android prefs system. Stub that out. + */ +public class MockPrefsGlobalSession extends GlobalSession { + + public MockSharedPreferences prefs; + + public MockPrefsGlobalSession( + SyncConfiguration config, GlobalSessionCallback callback, Context context, + ClientsDataDelegate clientsDelegate) + throws SyncConfigurationException, IllegalArgumentException, IOException, + NonObjectJSONException { + super(config, callback, context, clientsDelegate); + } + + public static MockPrefsGlobalSession getSession( + String username, String password, + KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context, + ClientsDataDelegate clientsDelegate) + throws SyncConfigurationException, IllegalArgumentException, IOException, + NonObjectJSONException { + return getSession(username, new BasicAuthHeaderProvider(username, password), null, + syncKeyBundle, callback, context, clientsDelegate); + } + + public static MockPrefsGlobalSession getSession( + String username, AuthHeaderProvider authHeaderProvider, String prefsPath, + KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context, + ClientsDataDelegate clientsDelegate) + throws SyncConfigurationException, IllegalArgumentException, IOException, + NonObjectJSONException { + + final SharedPreferences prefs = new MockSharedPreferences(); + final SyncConfiguration config = new SyncConfiguration(username, authHeaderProvider, prefs); + config.syncKeyBundle = syncKeyBundle; + return new MockPrefsGlobalSession(config, callback, context, clientsDelegate); + } + + @Override + public Context getContext() { + return null; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockRecord.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockRecord.java new file mode 100644 index 000000000..d3a05bcec --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockRecord.java @@ -0,0 +1,34 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.repositories.domain.Record; + +public class MockRecord extends Record { + + public MockRecord(String guid, String collection, long lastModified, boolean deleted) { + super(guid, collection, lastModified, deleted); + } + + @Override + protected void populatePayload(ExtendedJSONObject payload) { + } + + @Override + protected void initFromPayload(ExtendedJSONObject payload) { + } + + @Override + public Record copyWithIDs(String guid, long androidID) { + MockRecord r = new MockRecord(guid, this.collection, this.lastModified, this.deleted); + r.androidID = androidID; + return r; + } + + @Override + public String toJSONString() { + return "{\"id\":\"" + guid + "\", \"payload\": \"foo\"}"; + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockServerSyncStage.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockServerSyncStage.java new file mode 100644 index 000000000..02b72b676 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockServerSyncStage.java @@ -0,0 +1,12 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + + +public class MockServerSyncStage extends BaseMockServerSyncStage { + @Override + public void execute() { + session.advance(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockSharedPreferences.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockSharedPreferences.java new file mode 100644 index 000000000..bc49fa7fb --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/MockSharedPreferences.java @@ -0,0 +1,137 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import android.content.SharedPreferences; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * A programmable mock content provider. + */ +public class MockSharedPreferences implements SharedPreferences, SharedPreferences.Editor { + private HashMap mValues; + private HashMap mTempValues; + + public MockSharedPreferences() { + mValues = new HashMap(); + mTempValues = new HashMap(); + } + + public Editor edit() { + return this; + } + + public boolean contains(String key) { + return mValues.containsKey(key); + } + + public Map getAll() { + return new HashMap(mValues); + } + + public boolean getBoolean(String key, boolean defValue) { + if (mValues.containsKey(key)) { + return ((Boolean)mValues.get(key)).booleanValue(); + } + return defValue; + } + + public float getFloat(String key, float defValue) { + if (mValues.containsKey(key)) { + return ((Float)mValues.get(key)).floatValue(); + } + return defValue; + } + + public int getInt(String key, int defValue) { + if (mValues.containsKey(key)) { + return ((Integer)mValues.get(key)).intValue(); + } + return defValue; + } + + public long getLong(String key, long defValue) { + if (mValues.containsKey(key)) { + return ((Long)mValues.get(key)).longValue(); + } + return defValue; + } + + public String getString(String key, String defValue) { + if (mValues.containsKey(key)) + return (String)mValues.get(key); + return defValue; + } + + @SuppressWarnings("unchecked") + public Set getStringSet(String key, Set defValues) { + if (mValues.containsKey(key)) { + return (Set) mValues.get(key); + } + return defValues; + } + + public void registerOnSharedPreferenceChangeListener( + OnSharedPreferenceChangeListener listener) { + throw new UnsupportedOperationException(); + } + + public void unregisterOnSharedPreferenceChangeListener( + OnSharedPreferenceChangeListener listener) { + throw new UnsupportedOperationException(); + } + + public Editor putBoolean(String key, boolean value) { + mTempValues.put(key, Boolean.valueOf(value)); + return this; + } + + public Editor putFloat(String key, float value) { + mTempValues.put(key, value); + return this; + } + + public Editor putInt(String key, int value) { + mTempValues.put(key, value); + return this; + } + + public Editor putLong(String key, long value) { + mTempValues.put(key, value); + return this; + } + + public Editor putString(String key, String value) { + mTempValues.put(key, value); + return this; + } + + public Editor putStringSet(String key, Set values) { + mTempValues.put(key, values); + return this; + } + + public Editor remove(String key) { + mTempValues.remove(key); + return this; + } + + public Editor clear() { + mTempValues.clear(); + return this; + } + + @SuppressWarnings("unchecked") + public boolean commit() { + mValues = (HashMap)mTempValues.clone(); + return true; + } + + public void apply() { + commit(); + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/WBORepository.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/WBORepository.java new file mode 100644 index 000000000..bd2e7f791 --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/WBORepository.java @@ -0,0 +1,231 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; +import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; +import org.mozilla.gecko.sync.repositories.RecordFilter; +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionGuidsSinceDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import android.content.Context; + +public class WBORepository extends Repository { + + public class WBORepositoryStats { + public long created = -1; + public long begun = -1; + public long fetchBegan = -1; + public long fetchCompleted = -1; + public long storeBegan = -1; + public long storeCompleted = -1; + public long finished = -1; + } + + public static final String LOG_TAG = "WBORepository"; + + // Access to stats is not guarded. + public WBORepositoryStats stats; + + // Whether or not to increment the timestamp of stored records. + public final boolean bumpTimestamps; + + public class WBORepositorySession extends StoreTrackingRepositorySession { + + protected WBORepository wboRepository; + protected ExecutorService delegateExecutor = Executors.newSingleThreadExecutor(); + public ConcurrentHashMap wbos; + + public WBORepositorySession(WBORepository repository) { + super(repository); + + wboRepository = repository; + wbos = new ConcurrentHashMap(); + stats = new WBORepositoryStats(); + stats.created = now(); + } + + @Override + protected synchronized void trackGUID(String guid) { + if (wboRepository.shouldTrack()) { + super.trackGUID(guid); + } + } + + @Override + public void guidsSince(long timestamp, + RepositorySessionGuidsSinceDelegate delegate) { + throw new RuntimeException("guidsSince not implemented."); + } + + @Override + public void fetchSince(long timestamp, + RepositorySessionFetchRecordsDelegate delegate) { + long fetchBegan = now(); + stats.fetchBegan = fetchBegan; + RecordFilter filter = storeTracker.getFilter(); + + for (Entry entry : wbos.entrySet()) { + Record record = entry.getValue(); + if (record.lastModified >= timestamp) { + if (filter != null && + filter.excludeRecord(record)) { + Logger.debug(LOG_TAG, "Excluding record " + record.guid); + continue; + } + delegate.deferredFetchDelegate(delegateExecutor).onFetchedRecord(record); + } + } + long fetchCompleted = now(); + stats.fetchCompleted = fetchCompleted; + delegate.deferredFetchDelegate(delegateExecutor).onFetchCompleted(fetchCompleted); + } + + @Override + public void fetch(final String[] guids, + final RepositorySessionFetchRecordsDelegate delegate) { + long fetchBegan = now(); + stats.fetchBegan = fetchBegan; + for (String guid : guids) { + if (wbos.containsKey(guid)) { + delegate.deferredFetchDelegate(delegateExecutor).onFetchedRecord(wbos.get(guid)); + } + } + long fetchCompleted = now(); + stats.fetchCompleted = fetchCompleted; + delegate.deferredFetchDelegate(delegateExecutor).onFetchCompleted(fetchCompleted); + } + + @Override + public void fetchAll(final RepositorySessionFetchRecordsDelegate delegate) { + long fetchBegan = now(); + stats.fetchBegan = fetchBegan; + for (Entry entry : wbos.entrySet()) { + Record record = entry.getValue(); + delegate.deferredFetchDelegate(delegateExecutor).onFetchedRecord(record); + } + long fetchCompleted = now(); + stats.fetchCompleted = fetchCompleted; + delegate.deferredFetchDelegate(delegateExecutor).onFetchCompleted(fetchCompleted); + } + + @Override + public void store(final Record record) throws NoStoreDelegateException { + if (delegate == null) { + throw new NoStoreDelegateException(); + } + final long now = now(); + if (stats.storeBegan < 0) { + stats.storeBegan = now; + } + Record existing = wbos.get(record.guid); + Logger.debug(LOG_TAG, "Existing record is " + (existing == null ? "" : (existing.guid + ", " + existing))); + if (existing != null && + existing.lastModified > record.lastModified) { + Logger.debug(LOG_TAG, "Local record is newer. Not storing."); + delegate.deferredStoreDelegate(delegateExecutor).onRecordStoreSucceeded(record.guid); + return; + } + if (existing != null) { + Logger.debug(LOG_TAG, "Replacing local record."); + } + + // Store a copy of the record with an updated modified time. + Record toStore = record.copyWithIDs(record.guid, record.androidID); + if (bumpTimestamps) { + toStore.lastModified = now; + } + wbos.put(record.guid, toStore); + + trackRecord(toStore); + delegate.deferredStoreDelegate(delegateExecutor).onRecordStoreSucceeded(record.guid); + } + + @Override + public void wipe(final RepositorySessionWipeDelegate delegate) { + if (!isActive()) { + delegate.onWipeFailed(new InactiveSessionException(null)); + return; + } + + Logger.info(LOG_TAG, "Wiping WBORepositorySession."); + this.wbos = new ConcurrentHashMap(); + + // Wipe immediately for the convenience of test code. + wboRepository.wbos = new ConcurrentHashMap(); + delegate.deferredWipeDelegate(delegateExecutor).onWipeSucceeded(); + } + + @Override + public void finish(RepositorySessionFinishDelegate delegate) throws InactiveSessionException { + Logger.info(LOG_TAG, "Finishing WBORepositorySession: handing back " + this.wbos.size() + " WBOs."); + wboRepository.wbos = this.wbos; + stats.finished = now(); + super.finish(delegate); + } + + @Override + public void begin(RepositorySessionBeginDelegate delegate) throws InvalidSessionTransitionException { + this.wbos = wboRepository.cloneWBOs(); + stats.begun = now(); + super.begin(delegate); + } + + @Override + public void storeDone(long end) { + // TODO: this is not guaranteed to be called after all of the record + // store callbacks have completed! + if (stats.storeBegan < 0) { + stats.storeBegan = end; + } + stats.storeCompleted = end; + delegate.deferredStoreDelegate(delegateExecutor).onStoreCompleted(end); + } + } + + public ConcurrentHashMap wbos; + + public WBORepository(boolean bumpTimestamps) { + super(); + this.bumpTimestamps = bumpTimestamps; + this.wbos = new ConcurrentHashMap(); + } + + public WBORepository() { + this(false); + } + + public synchronized boolean shouldTrack() { + return false; + } + + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this)); + } + + public ConcurrentHashMap cloneWBOs() { + ConcurrentHashMap out = new ConcurrentHashMap(); + for (Entry entry : wbos.entrySet()) { + out.put(entry.getKey(), entry.getValue()); // Assume that records are + // immutable. + } + return out; + } +} diff --git a/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java new file mode 100644 index 000000000..1a84977cf --- /dev/null +++ b/mobile/android/tests/background/junit3/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java @@ -0,0 +1,171 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.TimeUnit; + +import org.mozilla.gecko.background.common.log.Logger; + +/** + * Implements waiting for asynchronous test events. + * + * Call WaitHelper.getTestWaiter() to get the unique instance. + * + * Call performWait(runnable) to execute runnable synchronously. + * runnable *must* call performNotify() on all exit paths to signal to + * the TestWaiter that the runnable has completed. + * + * @author rnewman + * @author nalexander + */ +public class WaitHelper { + + public static final String LOG_TAG = "WaitHelper"; + + public static class Result { + public Throwable error; + public Result() { + error = null; + } + + public Result(Throwable error) { + this.error = error; + } + } + + public static abstract class WaitHelperError extends Error { + private static final long serialVersionUID = 7074690961681883619L; + } + + /** + * Immutable. + * + * @author rnewman + */ + public static class TimeoutError extends WaitHelperError { + private static final long serialVersionUID = 8591672555848651736L; + public final int waitTimeInMillis; + + public TimeoutError(int waitTimeInMillis) { + this.waitTimeInMillis = waitTimeInMillis; + } + } + + public static class MultipleNotificationsError extends WaitHelperError { + private static final long serialVersionUID = -9072736521571635495L; + } + + public static class InterruptedError extends WaitHelperError { + private static final long serialVersionUID = 8383948170038639308L; + } + + public static class InnerError extends WaitHelperError { + private static final long serialVersionUID = 3008502618576773778L; + public Throwable innerError; + + public InnerError(Throwable e) { + innerError = e; + if (e != null) { + // Eclipse prints the stack trace of the cause. + this.initCause(e); + } + } + } + + public BlockingQueue queue = new ArrayBlockingQueue(1); + + /** + * How long performWait should wait for, in milliseconds, with the + * convention that a negative value means "wait forever". + */ + public static int defaultWaitTimeoutInMillis = -1; + + public void performWait(Runnable action) throws WaitHelperError { + this.performWait(defaultWaitTimeoutInMillis, action); + } + + public void performWait(int waitTimeoutInMillis, Runnable action) throws WaitHelperError { + Logger.debug(LOG_TAG, "performWait called."); + + Result result = null; + + try { + if (action != null) { + try { + action.run(); + Logger.debug(LOG_TAG, "Action done."); + } catch (Exception ex) { + Logger.debug(LOG_TAG, "Performing action threw: " + ex.getMessage()); + throw new InnerError(ex); + } + } + + if (waitTimeoutInMillis < 0) { + result = queue.take(); + } else { + result = queue.poll(waitTimeoutInMillis, TimeUnit.MILLISECONDS); + } + Logger.debug(LOG_TAG, "Got result from queue: " + result); + } catch (InterruptedException e) { + // We were interrupted. + Logger.debug(LOG_TAG, "performNotify interrupted with InterruptedException " + e); + final InterruptedError interruptedError = new InterruptedError(); + interruptedError.initCause(e); + throw interruptedError; + } + + if (result == null) { + // We timed out. + throw new TimeoutError(waitTimeoutInMillis); + } else if (result.error != null) { + Logger.debug(LOG_TAG, "Notified with error: " + result.error.getMessage()); + + // Rethrow any assertion with which we were notified. + InnerError innerError = new InnerError(result.error); + throw innerError; + } + // Success! + } + + public void performNotify(final Throwable e) { + if (e != null) { + Logger.debug(LOG_TAG, "performNotify called with Throwable: " + e.getMessage()); + } else { + Logger.debug(LOG_TAG, "performNotify called."); + } + + if (!queue.offer(new Result(e))) { + // This could happen if performNotify is called multiple times (which is an error). + throw new MultipleNotificationsError(); + } + } + + public void performNotify() { + this.performNotify(null); + } + + public static Runnable onThreadRunnable(final Runnable r) { + return new Runnable() { + @Override + public void run() { + new Thread(r).start(); + } + }; + } + + private static WaitHelper singleWaiter = new WaitHelper(); + public static WaitHelper getTestWaiter() { + return singleWaiter; + } + + public static void resetTestWaiter() { + singleWaiter = new WaitHelper(); + } + + public boolean isIdle() { + return queue.isEmpty(); + } +} diff --git a/mobile/android/tests/background/junit4/resources/dlc_sync_deleted_item.json b/mobile/android/tests/background/junit4/resources/dlc_sync_deleted_item.json new file mode 100644 index 000000000..50b04f0e2 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/dlc_sync_deleted_item.json @@ -0,0 +1,8 @@ +{ + "data":[ + { + "id":"c906275c-3747-fe27-426f-6187526a6f06", + "deleted": true + } + ] +} diff --git a/mobile/android/tests/background/junit4/resources/dlc_sync_old_format.json b/mobile/android/tests/background/junit4/resources/dlc_sync_old_format.json new file mode 100644 index 000000000..378bc64c6 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/dlc_sync_old_format.json @@ -0,0 +1,23 @@ +{ + "data":[ + { + "kind":"font", + "original": { + "mimetype":"application/x-font-ttf", + "filename":"CharisSILCompact-R.ttf", + "hash":"4ed509317f1bb441b185ea13bf1c9d19d1a0b396962efa3b5dc3190ad88f2067", + "size":1727656 + }, + "last_modified":1455710632607, + "attachment": { + "mimetype":"application/x-gzip", + "size":548720, + "hash":"960be4fc5a92c1dc488582b215d5d75429fd4ffbee463105d29992cd792a912e", + "location":"/attachments/0d28a72d-a51f-46f8-9e5a-f95c61de904e.gz", + "filename":"CharisSILCompact-R.ttf.gz" + }, + "type":"asset-archive", + "id":"c906275c-3747-fe27-426f-6187526a6f06" + } + ] +} diff --git a/mobile/android/tests/background/junit4/resources/dlc_sync_single_font.json b/mobile/android/tests/background/junit4/resources/dlc_sync_single_font.json new file mode 100644 index 000000000..0de84b85d --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/dlc_sync_single_font.json @@ -0,0 +1,23 @@ +{ + "data":[ + { + "kind":"font", + "last_modified":1455710632607, + "attachment": { + "mimetype":"application/x-gzip", + "size":548720, + "hash":"960be4fc5a92c1dc488582b215d5d75429fd4ffbee463105d29992cd792a912e", + "location":"/attachments/0d28a72d-a51f-46f8-9e5a-f95c61de904e.gz", + "filename":"CharisSILCompact-R.ttf.gz", + "original": { + "mimetype":"application/x-font-ttf", + "filename":"CharisSILCompact-R.ttf", + "hash":"4ed509317f1bb441b185ea13bf1c9d19d1a0b396962efa3b5dc3190ad88f2067", + "size":1727656 + } + }, + "type":"asset-archive", + "id":"c906275c-3747-fe27-426f-6187526a6f06" + } + ] +} diff --git a/mobile/android/tests/background/junit4/resources/experiments.json b/mobile/android/tests/background/junit4/resources/experiments.json new file mode 100644 index 000000000..870a57778 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/experiments.json @@ -0,0 +1,99 @@ + +{ + "data": [ + { + "name": "active-experiment", + "match": { + }, + "buckets": { + "min": "0", + "max": "100" + }, + "values": { + "foo": true + } + }, + + { + "name": "inactive-experiment", + "match": { + "appId": "^NOPE$" + }, + "buckets": { + "min": "0", + "max": "0" + } + }, + { + "name": "bookmark-history-menu", + "match": { + }, + "buckets": { + "min": "0", + "max": "100" + } + }, + { + "name": "is-matching", + "match": { + "appId": "^org.mozilla.gecko$" + }, + "buckets": { + "min": "0", + "max": "100" + } + }, + { + "name": "is-not-matching", + "match": { + "appId": "^org.mozilla.fennec|^org.mozilla.firefox_beta$" + }, + "buckets": { + "min": "0", + "max": "100" + } + }, + { + "name": "promote-add-to-homescreen", + "buckets": { + "max": "100", + "min": "50" + }, + "last_modified": 1467705654772, + "values": { + "lastVisitMaximumAgeMs": 600000, + "minimumTotalVisits": 5, + "lastVisitMinimumAgeMs": 30000 + }, + "id": "20d278d7-0d35-4811-8f01-bf24e31ba51b", + "match": { + "appId": "^org.mozilla.fennec|^org.mozilla.firefox_beta$" + }, + "schema": 1467705310595 + }, + { + "name": "offline-cache", + "buckets": { + "max": "100", + "min": "0" + }, + "last_modified": 1467705429859, + "id": "9f1ea043-c1d8-48ba-802d-aeabaf667afe", + "match": { + "appId": "^org.mozilla.fennec|^org.mozilla.firefox_beta$" + }, + "schema": 1467705310595 + }, + { + "name": "bookmark-history-menu", + "buckets": { + "max": "100", + "min": "0" + }, + "last_modified": 1467705381971, + "id": "29988035-1a59-4671-b679-2c717a68bd12", + "match": {}, + "schema": 1467705310595 + } + ] +} diff --git a/mobile/android/tests/background/junit4/resources/feed_atom_blogger.xml b/mobile/android/tests/background/junit4/resources/feed_atom_blogger.xml new file mode 100644 index 000000000..994876d76 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_atom_blogger.xml @@ -0,0 +1,13 @@ +tag:blogger.com,1999:blog-189292772016-02-18T09:07:17.583-08:00mykzillaMyk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.comBlogger114125tag:blogger.com,1999:blog-18929277.post-35380293082242392922016-01-11T08:57:00.001-08:002016-01-11T08:57:31.366-08:00URL Has Been Changed<dl><dd>The URL you have reached, <a href="http://mykzilla.blogspot.com/">http://mykzilla.blogspot.com/</a>, has been changed. The new URL is <a href="https://mykzilla.org/">https://mykzilla.org/</a>. Please make a note of it.</dd></dl>Myk Melezhttp://www.blogger.com/profile/08518329693863067865noreply@blogger.com0tag:blogger.com,1999:blog-18929277.post-76589399590037997972015-06-23T16:05:00.000-07:002015-06-23T16:07:06.667-07:00Introducing PluotSorbet<a href="https://github.com/mozilla/pluotsorbet">PluotSorbet</a> is a <a href="https://en.wikipedia.org/wiki/Java_Platform,_Micro_Edition">J2ME</a>-compatible virtual machine written in JavaScript. Its goal is to enable users you run J2ME apps (i.e. <a href="https://en.wikipedia.org/wiki/MIDlet">MIDlets</a>) in web apps without a native plugin. It does this by interpreting Java bytecode and compiling it to JavaScript code. It also provides a virtual filesystem (via <a href="https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API">IndexedDB</a>), network sockets (through the <a href="https://developer.mozilla.org/en-US/docs/Web/API/TCPSocket">TCPSocket API</a>), and other common J2ME APIs, like <a href="https://developer.mozilla.org/en-US/docs/Web/API/Contacts_API">Contacts</a>.<br /><br />The project reuses as much existing code as possible, to minimize its surface area and maximize its compatibility with other J2ME implementations. It incorporates the <a href="https://java.net/projects/phoneme">PhoneME</a> reference implementation, numerous tests from <a href="https://www.sourceware.org/mauve/">Mauve</a>, and a variety of JavaScript libraries (including <a href="http://www-cs-students.stanford.edu/%7Etjw/jsbn/">jsbn</a>, <a href="https://github.com/digitalbazaar/forge">Forge</a>, and <a href="https://github.com/eligrey/FileSaver.js">FileSaver.js</a>). The virtual machine is originally based on <a href="https://github.com/YaroslavGaponov/node-jvm">node-jvm</a>.<br /><br />PluotSorbet makes it possible to bring J2ME apps to Firefox OS. J2ME may be a moribund platform, but it still has <a href="http://netmarketshare.com/operating-system-market-share.aspx?qprid=9&amp;qpcustom=Java+ME&amp;qpcustomb=1">non-negligible market share</a>, not to mention a number of useful apps. So it retains residual value, which PluotSorbet can extend to Firefox OS devices.<br /><br />PluotSorbet is also still under development, with a variety of issues to address. To learn more about PluotSorbet, check out its <a href="https://github.com/mozilla/pluotsorbet/blob/master/README.md">README</a>, clone its <a href="https://github.com/mozilla/pluotsorbet">Git repository</a>, peruse its <a href="https://github.com/mozilla/pluotsorbet/issues">issue tracker</a>, and say hello to its developers in <a href="irc://irc.mozilla.org/pluotsorbet">irc.mozilla.org#pluotsorbet</a>!<br /><br />Myk Melezhttp://www.blogger.com/profile/08518329693863067865noreply@blogger.com0tag:blogger.com,1999:blog-18929277.post-21460071983071904042014-03-28T16:58:00.002-07:002014-03-28T16:58:42.947-07:00simplify asynchronous method declarations with Task.async()In Mozilla code, <span style="font-family: &quot;Courier New&quot;,Courier,monospace;">Task.spawn()</span> is becoming a common way to implement asynchronous operations, especially methods like the <span style="font-family: &quot;Courier New&quot;,Courier,monospace;">greet</span> method in this <span style="font-family: &quot;Courier New&quot;,Courier,monospace;">greeter</span> object:<br /><br /><div style="background: #202020; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><pre style="line-height: 125%; margin: 0;"><span style="color: #6ab825; font-weight: bold;">let</span> <span style="color: #d0d0d0;">greeter</span> <span style="color: #d0d0d0;">=</span> <span style="color: #d0d0d0;">{</span><br /> <span style="color: #d0d0d0;">message:</span> <span style="color: #ed9d13;">"Hello, NAME!"</span><span style="color: #d0d0d0;">,</span><br /> <span style="color: #d0d0d0;">greet:</span> <span style="color: #6ab825; font-weight: bold;">function</span><span style="color: #d0d0d0;">(name)</span> <span style="color: #d0d0d0;">{</span><br /> <span style="color: #6ab825; font-weight: bold;">return</span> <span style="color: #d0d0d0;">Task.spawn((</span><span style="color: #6ab825; font-weight: bold;">function</span><span style="color: #d0d0d0;">*()</span> <span style="color: #d0d0d0;">{</span><br /> <span style="color: #6ab825; font-weight: bold;">return</span> <span style="color: #d0d0d0;">yield</span> <span style="color: #d0d0d0;">sendGreeting(</span><span style="color: #6ab825; font-weight: bold;">this</span><span style="color: #d0d0d0;">.message.replace(</span><span style="color: #ed9d13;">/NAME/</span><span style="color: #d0d0d0;">,</span> <span style="color: #d0d0d0;">name));</span><br /> <span style="color: #d0d0d0;">}).bind(</span><span style="color: #6ab825; font-weight: bold;">this</span><span style="color: #d0d0d0;">);</span><br /> <span style="color: #d0d0d0;">})</span><br /><span style="color: #d0d0d0;">};</span><br /></pre></div><br /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">Task.spawn()</span> makes the operation logic simple, but the wrapper function and <span style="font-family: &quot;Courier New&quot;,Courier,monospace;">bind()</span> call required to start the task on method invocation and bind its <span style="font-family: &quot;Courier New&quot;,Courier,monospace;">this</span> reference make the overall implementation complex.<br /><br />Enter <span style="font-family: &quot;Courier New&quot;,Courier,monospace;">Task.async()</span>.<br /><br />Like <span style="font-family: &quot;Courier New&quot;,Courier,monospace;">Task.spawn()</span>, it creates a task, but it doesn't immediately start it. Instead, it returns an "async function" whose invocation starts the task, and the async function binds the task to its own <span style="font-family: &quot;Courier New&quot;,Courier,monospace;">this</span> reference at invocation time. That makes it simpler to declare the method:<br /><br /><!-- HTML generated using hilite.me --> <div style="background: #202020; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><pre style="line-height: 125%; margin: 0;"><span style="color: #6ab825; font-weight: bold;">let</span> <span style="color: #d0d0d0;">greeter</span> <span style="color: #d0d0d0;">=</span> <span style="color: #d0d0d0;">{</span><br /> <span style="color: #d0d0d0;">message:</span> <span style="color: #ed9d13;">"Hello, NAME!"</span><span style="color: #d0d0d0;">,</span><br /> <span style="color: #d0d0d0;">greet:</span> <span style="color: #d0d0d0;">Task.async(</span><span style="color: #6ab825; font-weight: bold;">function</span><span style="color: #d0d0d0;">*(name)</span> <span style="color: #d0d0d0;">{</span><br /> <span style="color: #6ab825; font-weight: bold;">return</span> <span style="color: #d0d0d0;">yield</span> <span style="color: #d0d0d0;">sendGreeting(</span><span style="color: #6ab825; font-weight: bold;">this</span><span style="color: #d0d0d0;">.message.replace(</span><span style="color: #ed9d13;">/NAME/</span><span style="color: #d0d0d0;">,</span> <span style="color: #d0d0d0;">name));</span><br /> <span style="color: #d0d0d0;">})</span><br /><span style="color: #d0d0d0;">};</span><br /></pre></div><br />With identical semantics:<br /><br /><div style="background: #202020; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><pre style="line-height: 125%; margin: 0;"><span style="color: #d0d0d0;">greeter.greet(</span><span style="color: #ed9d13;">"Mitchell"</span><span style="color: #d0d0d0;">).then((reply)</span> <span style="color: #d0d0d0;">=&gt;</span> <span style="color: #d0d0d0;">{</span> <span style="color: #d0d0d0;">...</span> <span style="color: #d0d0d0;">});</span> <span style="color: #999999; font-style: italic;">// behaves the same</span><br /></pre></div><br />(And it avoids a couple anti-patterns in the process.)<br /><br /><span style="font-family: &quot;Courier New&quot;,Courier,monospace;">Task.async()</span> is inspired by ECMAScript's <a href="http://wiki.ecmascript.org/doku.php?id=strawman:async_functions">Async Functions strawman proposal</a> and <a href="http://msdn.microsoft.com/en-us/library/hh191443.aspx">C#'s Async modifier</a> and was implemented in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=966182">bug 966182</a>. It isn't limited to use in method declarations, although it's particularly helpful for them.<br /><br />Use it to implement your next asynchronous operation!<br /><br />Myk Melezhttp://www.blogger.com/profile/08518329693863067865noreply@blogger.com2tag:blogger.com,1999:blog-18929277.post-76037655943533196062014-03-27T13:14:00.000-07:002014-03-27T13:14:20.326-07:00qualifications for leadershipI've been surprised by the negative reaction to Brendan's promotion by some of my fellow supporters of marriage equality. Perhaps I take it too much for granted that Mozillians recognize the diversity of their community in every possible respect, including politically and religiously, and that the <span style="font-style: italic;">only</span> thing we share in common is our commitment to Mozilla's mission and the principles for participation.<br /><br />Those principles are reflected in our <a href="http://www.mozilla.org/en-US/about/governance/policies/participation/">Community Participation Agreement</a>, to which Brendan has always shown fealty (since long before it was formalized, in my 15-year experience with him), and which could not possibly be clearer about the welcoming nature of Mozilla to all constructive contributors.<br /> <br />I know that marriage equality has been a long, difficult, and painful battle, the kind that rubs nerves raw and makes it challenging to show any charity to its opponents. But they aren't all bigots, and I take Brendan at his <a href="https://brendaneich.com/2014/03/inclusiveness-at-mozilla/">word and deed</a> that he's as committed as I am to the community's inclusive ideals (and the organization's employment policies).<br /> <br />As Andrew Sullivan eloquently states in his recent blog post on <a href="http://dish.andrewsullivan.com/2014/03/24/religious-belief-and-bigotry/">Religious Belief and Bigotry</a>:<br /><br /><div style="margin-left: 40px;">"Twenty years ago, I was confidently told by my leftist gay friends that Americans were all anti-gay bigots and would never, ever back marriage rights so I should stop trying to reason them out of their opposition. My friends were wrong. Americans are not all bigots. Not even close. They can be persuaded rather than attacked. And if we behave magnanimously and give maximal space for those who sincerely oppose us, then eventual persuasion will be more likely. And our victory more moral and more enduring." </div><br />I'm chastened to admit that I substantially shared his friends' opinion twenty years ago. But I'm happy to realize I was wrong. And perhaps Brendan will one day do the same. Either way, he qualifies to be a leader at any level in the Mozilla community (and organization), as do the many other Mozilla leaders whose beliefs undoubtedly differ sharply from my own.<br /><br />Myk Melezhttp://www.blogger.com/profile/08518329693863067865noreply@blogger.com21tag:blogger.com,1999:blog-18929277.post-49078357323891417042013-10-15T17:05:00.003-07:002013-10-15T17:05:53.226-07:00from Webapp SDK to r2d2b2g, Firefox OS Simulator, and the App ManagerA little over a year ago, on August 31, 2012, I brainstormed the outline of a "Webapp SDK":<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-qFEN48-NFBI/Ul2-QToFUkI/AAAAAAAAAEY/Pah7FtanWfo/s1600/2012-08-31+10.57.00.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="http://2.bp.blogspot.com/-qFEN48-NFBI/Ul2-QToFUkI/AAAAAAAAAEY/Pah7FtanWfo/s400/2012-08-31+10.57.00.jpg" width="400" /></a></div><br />That outline was the genesis for the <a href="https://hacks.mozilla.org/2012/10/r2d2b2g-an-experimental-prototype-firefox-os-test-environment/">r2d2b2g experiment</a>, which built the <a href="http://www.blueskyonmars.com/2012/11/08/r2d2b2g-is-becoming-the-firefox-os-simulator/">Firefox OS Simulator</a>, whose initial version hit the web on September 14, 2012 and which has gone through numerous iterations since then as we evaluated various features to enhance app development.<br /><br />And that experiment spurred Mozilla's <a href="https://wiki.mozilla.org/DevTools">Developer Tools group</a>, particularly its nascent <a href="https://wiki.mozilla.org/DevTools/AppTools">App Tools team</a>, to build Firefox's new App Manager, which landed last month and was <a href="https://hacks.mozilla.org/2013/10/introducing-the-firefox-os-app-manager/">introduced today on Hacks</a>!<br /><br />Despite the twisty passage from experiment to product, that initial outline bears a surprising resemblance to the App Manager feature set. The Manager checks off three of the four features on the outline's primary list—"start Gaia in B2G," "package app," and "test app in Gaia/B2G"—plus a few on its secondary list, like "debug from Firefox" and "test on mobile device," with "edit manifest in GUI" well underway over in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=912912">bug 912912</a>. And the Simulator continues to provide B2G/Gaia via an easy-to-install addon that integrates with the Manager.<br /><br />Like any good product of a successful experiment, however, the Manager's reach has exceeded its progenitor's grasp! So it also gives you access to pre-installed apps, lets you take screenshots of device/Simulator screens, and will doubtless continue to sprout handy features to make app development great.<br /><br />So kudos to the folks who built it, and long live the App Manager!<br /><br />Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com3tag:blogger.com,1999:blog-18929277.post-47754731254098518132013-08-23T10:55:00.001-07:002013-08-23T10:55:06.641-07:00fixing this morning's mach OS X psutil bustageIf mach is broken in your mozilla-central clone on Mac OS X this morning:<br> <blockquote><tt>08-23 10:20 &gt; ./mach build</tt><br> <tt>Error running mach:</tt><br> <br> <tt>&nbsp;&nbsp;&nbsp; ['build']</tt><br> <br> <tt>The error occurred in code that was called by the mach command. This is either</tt><br> <tt>a bug in the called code itself or in the way that mach is calling it.</tt><br> <br> <tt>You should consider filing a bug for this issue.</tt><br> <br> <tt>If filing a bug, please include the full output of mach, including this error</tt><br> <tt>message.</tt><br> <br> <tt>The details of the failure are as follows:</tt><br> <br> <tt>AttributeError: 'module' object has no attribute 'TCPS_ESTABLISHED'</tt><br> <br> <tt>&nbsp; File "/Users/myk/Mozilla/central/python/mozbuild/mozbuild/mach_commands.py", line 293, in build</tt><br> <tt>&nbsp;&nbsp;&nbsp; from mozbuild.controller.building import BuildMonitor</tt><br> <tt>&nbsp; File "/Users/myk/Mozilla/central/python/mozbuild/mozbuild/controller/building.py", line 22, in &lt;module&gt;</tt><br> <tt>&nbsp;&nbsp;&nbsp; import psutil</tt><br> <tt>&nbsp; File "/Users/myk/Mozilla/central/python/psutil/psutil/__init__.py", line 95, in &lt;module&gt;</tt><br> <tt>&nbsp;&nbsp;&nbsp; import psutil._psosx as _psplatform</tt><br> <tt>&nbsp; File "/Users/myk/Mozilla/central/python/psutil/psutil/_psosx.py", line 48, in &lt;module&gt;</tt><br> <tt>&nbsp;&nbsp;&nbsp; _TCP_STATES_TABLE = {_psutil_osx.TCPS_ESTABLISHED : CONN_ESTABLISHED,</tt><br> </blockquote> <br> Then you've been bit by the fix for <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=908296">bug 908296</a>. To resolve the bustage, run this command in your Hg clone:<br> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <blockquote>hg status -in python/psutil | xargs rm<br> </blockquote> <br> Or, if you've cloned the <a href="https://github.com/mozilla/mozilla-central">Git mirror</a>, run this instead:<br> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <blockquote>git clean -xf python/psutil<br> </blockquote> <br> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com0tag:blogger.com,1999:blog-18929277.post-76581760422278796832013-06-07T16:04:00.000-07:002013-06-07T16:04:04.952-07:0064-bit Linux ADB for SimulatorThanks to the efforts of new Mozilla intern <a href="https://github.com/bkase">Brandon Kase</a>, the <a href="https://ftp.mozilla.org/pub/mozilla.org/labs/r2d2b2g/r2d2b2g-linux.xpi">latest preview build of Firefox OS Simulator for Linux</a> includes a 64-bit version of ADB, so you can push an app to an FxOS device from 64-bit Linux installations without any extra packages!<br /> <br /> Building it was tricky, because the Android SDK build scripts don't support that target. Brandon first tried simply specifying the target, which worked on an older version of ADB (1.0.24). But it failed on the latest version (1.0.31), which links with a bundled copy of libcrypto that includes 32-bit assembly.<br /> <br /> Ubuntu 13.04 (Raring) ships a 64-bit <a href="http://packages.ubuntu.com/raring/android-tools-adb">android-tools-adb package</a>, though, so we knew it could be done. And its <a href="http://packages.ubuntu.com/source/raring/android-tools">source package</a>'s build system is much simpler than the SDK's. We just needed a binary that works on distributions with older versions of glibc than Raring's 2.17. And one that doesn't depend on a specific version of libcrypto, which varies around the Linux world; whereas Raring's ADB executable appears to need the specific version that comes with that distribution.<br /> <br /> So Brandon modified the source package's Makefile to link libcrypto statically (note the absolute path to libcrypto.a, which may vary):<br /><blockquote class="tr_bq"> <tt>--- debian/makefiles/adb.mk&nbsp;&nbsp;&nbsp; 2013-03-26 14:15:41.000000000 -0700</tt><br /><tt> </tt><tt>+++ adb-static-crypto.mk&nbsp;&nbsp;&nbsp; 2013-06-06 16:51:52.794521267 -0700</tt><br /><tt> </tt><tt>@@ -40,15 +40,16 @@</tt><br /><tt> </tt><tt>&nbsp;CPPFLAGS+= -I.</tt><br /><tt> </tt><tt>&nbsp;CPPFLAGS+= -I../include</tt><br /><tt> </tt><tt>&nbsp;CPPFLAGS+= -I../../../external/zlib</tt><br /><tt> </tt><tt>+CPPFLAGS+= -I/usr/include/openssl</tt><br /><tt> </tt><tt>&nbsp;</tt><br /><tt> </tt><tt>-LIBS+= -lc -lpthread -lz -lcrypto</tt><br /><tt> </tt><tt>+LIBS+= -lc -lpthread -lz -ldl</tt><br /><tt> </tt><tt>&nbsp;</tt><br /><tt> </tt><tt>&nbsp;OBJS= $(SRCS:.c=.o)</tt><br /><tt> </tt><tt>&nbsp;</tt><br /><tt> </tt><tt>&nbsp;all: adb</tt><br /><tt> </tt><tt>&nbsp;</tt><br /><tt> </tt><tt>&nbsp;adb: $(OBJS)</tt><br /><tt> </tt><tt>-&nbsp;&nbsp;&nbsp; $(CC) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)</tt><br /><tt> </tt><tt>+&nbsp;&nbsp;&nbsp; $(CC) -o $@ $(LDFLAGS) $(OBJS) /usr/lib/x86_64-linux-gnu/libcrypto.a $(LIBS)</tt><br /><tt> </tt><tt>&nbsp;</tt><br /><tt> </tt><tt>&nbsp;clean:</tt><br /><tt> </tt><tt>&nbsp;&nbsp;&nbsp;&nbsp; rm -rf $(OBJS) adb</tt></blockquote><br /> Then I copied the source package to my CentOS 16 build machine (which has glibc 2.12) and built it there. After which the resultant executable worked on all the distributions we tested: Ubuntu 13.04, Ubuntu 10.04, CentOS 16, and Arch Linux (kernel 3.9.3-1-ARCH).<br /> <br /> Presumably it will work on others too. But if it still doesn't work for you, <a href="https://github.com/mozilla/r2d2b2g/issues">let us know</a>!<br /> <br /> And if you just want the ADB executable, sans Simulator, <a href="https://ftp.mozilla.org/pub/mozilla.org/labs/r2d2b2g/adb-1.0.31-linux64.zip">here it is</a>.<br /><br />Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com2tag:blogger.com,1999:blog-18929277.post-29501405359225214802012-10-02T12:08:00.001-07:002012-10-02T12:13:24.657-07:00r2d2b2g implementation detailsOver at Mozilla Hacks, I just <a href="https://hacks.mozilla.org/2012/10/r2d2b2g-an-experimental-prototype-firefox-os-test-environment/">blogged about r2d2b2g</a> (ratta-datta-batta-ga), an experimental prototype test environment for Firefox OS that makes it drop-dead simple to test your app in <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Boot_to_Gecko/Using_the_B2G_desktop_client">B2G Desktop</a>.<br /><br />r2d2b2g is an addon, but it bundles <a href="https://ftp.mozilla.org/pub/mozilla.org/b2g/nightly/latest-mozilla-central/">B2G Desktop nightly builds</a>, which are native executables, and thus the addon is platform-specific, with packages available for <a href="https://ftp.mozilla.org/pub/mozilla.org/labs/r2d2b2g/r2d2b2g-mac.xpi">Mac</a>, <a href="https://ftp.mozilla.org/pub/mozilla.org/labs/r2d2b2g/r2d2b2g-linux.xpi">Linux 32-bit</a>, and <a href="https://ftp.mozilla.org/pub/mozilla.org/labs/r2d2b2g/r2d2b2g-windows.xpi">Windows</a> (caveat: B2G Desktop for Windows currently crashes on startup due to bug <strike><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=794662">794662</a></strike> <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=795484">795484</a>).<br /><br />The packages are large, 50-60MB each, partly because of the executables, but mostly because they also bundle <a href="https://wiki.mozilla.org/Gaia">Gaia</a> profiles, including all default apps. (It's probably worth bundling a few of these, for demonstration purposes, but we could make the packages much smaller by removing the rest.)<br /><br />r2d2b2g uses the <a href="https://addons.mozilla.org/en-US/developers/builder">Add-on SDK</a> as its addon framework and relies on several third-party addon modules (<a href="https://github.com/ochameau/jetpack-subprocess">subprocess</a>, <a href="https://github.com/voldsoftware/menuitems-jplib">menuitems</a>) along with some Python utilities (<a href="https://github.com/mozilla/mozdownload">mozdownload</a>, <a href="https://github.com/mozilla/mozbase">mozbase</a>) to download and unpack B2G Desktop builds. Plus Gaia, although recent work to bundle Gaia profiles with B2G Desktop builds may break that dependency.<br /><br />I've demoed the project to a variety of folks over the last couple weeks, and I've received a bunch of positive feedback about it. B2G Desktop combines approachability with phoneliness and is the best existing test environment for Firefox OS. But its configuration is a challenge, and it provides no obvious affordances for installing and testing your own app. r2d2b2g shows that these problems are tractable (even if it doesn't yet solve them all) and demonstrates a promising product path.<br /><br />After seeing r2d2b2g, Kevin Dangoor drafted a <a href="https://docs.google.com/document/d/1OptOCWO4b_b1aa4Gtwr82_q-mW5ybteoWNpPAJUIFNk/edit">PRD for a Firefox OS Simulator</a> that I'll use to guide further development. Interested in participating? Clone the code from its <a href="https://github.com/mozilla/r2d2b2g">GitHub repository</a> and contribute your improvements!<br /><br />Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com5tag:blogger.com,1999:blog-18929277.post-7044908640968977792012-03-07T18:04:00.001-08:002012-03-07T18:04:16.546-08:00Next/Previous Tab on Mac Consistent At LastAfter blogging about the <a href="http://mykzilla.blogspot.com/2011/09/nextprevious-tab-keyboard-shortcuts-on.html">inconsistency of keyboard shortcuts for Next/Previous Tab on Mac</a> last year, I found out that Firefox, Thunderbird, and Komodo also support Command + Option + LeftArrow|RightArrow, and Adium has a General &gt; "Switch tabs with" pref that I can set to the same chord.<br> <br> (Later, I switched IM clients from Adium to InstantBird, which also supports that combination.)<br> <br> That left Terminal, which I couldn't figure out how to configure to support the same shortcut. Until now.<br> <br> I'm not sure if it's because I have since upgraded to Mac OS X 10.7 (Lion). I could've sworn I tried something like this back when I wrote that previous blog post, and it didn't work.<br> <ol> <li>Go to System Preferences &gt; Keyboard &gt; Keyboard Shortcuts &gt; Application Shortcuts.</li> <li>Press the + (plus) button.</li> <li>Select "Other..." from the Application menu and select Utilities &gt; Terminal from the file picker dialog.</li> <li>Enter "Select Next Tab" (without the quotes) into the Menu Title field.</li> <li>Focus the Keyboard Shortcut field and press Command + Option + RightArrow to set the keyboard shortcut, which will appear as <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> &#8997;&#8984;&#8594;.</li> <li>Press the Add button.</li> </ol> <p>Repeat steps 4-6 with "Select Previous Tab" and Command + Option + LeftArrow, which will appear as <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> &#8997;&#8984;&#8592;.<br> </p> <p>Those shortcuts should now work in Terminal.<br> </p> <p>With this change, all five of my current primary productivity applications on Mac (Firefox, Thunderbird, Instantbird, Komodo, and Terminal) support a consistent pair of keyboard shortcuts for Next/Previous Tab, which are two of the most common commands I issue in all of those apps.<br> </p> <p>Woot!<br> <br> </p> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com2tag:blogger.com,1999:blog-18929277.post-47172728442873974082012-03-07T13:46:00.001-08:002012-03-07T13:46:45.454-08:00generating a fingerprint for an SSH keyAfter recently <a href="https://github.com/blog/1068-public-key-security-vulnerability-and-mitigation">discovering a security vulnerability</a> that allows an attacker to add an SSH key to a GitHub user account, GitHub is requiring all users to audit their SSH keys. Its <a href="https://github.com/settings/ssh/audit">audit page</a> lists one's keys by type and fingerprint, but it doesn't say how it generated the fingerprint or how to generate one for your local copy of a key to compare it with. Nor does it let you see the whole key.<br> <br> And since I don't generate such fingerprints very often, I didn't know how to do it. So I tried <tt>cksum</tt>, <tt>md5</tt>, and <tt>shasum</tt> on my Mac, but none of their checksums matched. Turns out the tool to use is <tt>ssh-keygen</tt>:<br> <br> <tt> &nbsp;&nbsp;&nbsp; ssh-keygen -l -f path/to/keyfile</tt><br> <br> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com2tag:blogger.com,1999:blog-18929277.post-35380112160134008902011-10-17T10:38:00.001-07:002011-10-17T10:38:52.345-07:00Mozilla Status Board Text is MarkdownIt isn't documented anywhere that I can find, but Benjamin Smedberg's handy <a href="http://benjamin.smedbergs.us/weekly-updates.fcgi/">Mozilla Status Board</a> tool parses status text as <a href="http://daringfireball.net/projects/markdown/">Markdown</a>, which is how I added a <b>Didn't</b> header to the <b>Done</b> section of my <a href="http://benjamin.smedbergs.us/weekly-updates.fcgi/user/mykmelez">status update</a> with all the things I planned to do last week but didn't make happen. (The <b>Done</b>, <b>Next</b>, and <b>Coordination</b> headers are all <b>H4</b>s, so I prepended four hash marks to <tt>#### <b>Didn't</b></tt> to make it the same size).<br> <br> (Note that <tt>[<a href="http://daringfireball.net/projects/markdown/basics">Markdown-style links</a>](<a class="moz-txt-link-freetext" href="http://daringfireball.net/projects/markdown/basics">http://daringfireball.net/projects/markdown/basics</a>)</tt> don't work and cause the entire section in which they appear to remain unparsed. However angle-bracketed URLs, as recommended by <tt><a href="http://labs.apache.org/webarch/uri/rfc/rfc3986.html#delimiting">RFC 3986</a> <a class="moz-txt-link-rfc2396E" href="http://labs.apache.org/webarch/uri/rfc/rfc3986.html#delimiting">&lt;http://labs.apache.org/webarch/uri/rfc/rfc3986.html#delimiting&gt;</a></tt>, work when added to the ends of lines. And "<tt>bug ###</tt>" references are auto-linkified.)<br> <br> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com1tag:blogger.com,1999:blog-18929277.post-30022291827949270512011-09-16T08:32:00.001-07:002011-09-16T08:32:13.528-07:00to all the bugs I've filed beforeThe <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=20142">first bug I filed</a> was marked as <i>duplicate</i>; the <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=20187">second</a> was <i>worksforme</i> (although Chris Petersen could reproduce it before he couldn't anymore); and the <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=24840">third</a> was <i>invalid</i> (it was the spec, not the code, that was errant). The <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=25082">fourth</a> is the first that was <i>fixed</i>.<br> <br> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com2tag:blogger.com,1999:blog-18929277.post-24817524474935415182011-09-09T17:01:00.000-07:002011-09-09T17:00:36.580-07:00"Next/Previous Tab" Keyboard Shortcuts on WindowsOn my Windows laptop, I use the following four programs with tabbed interfaces on a regular basis:<br> <ul> <li>Firefox</li> <li>Thunderbird</li> <li>Instantbird</li> <li>Komodo IDE</li> </ul> (I'd love to have tabs in my Windows terminal app of choice, <a href="http://code.google.com/p/mintty/">Mintty</a>, but its developer <a href="http://code.google.com/p/mintty/issues/detail?id=8">thinks tabs should be implemented at the window manager level</a>.)<br> <br> Unlike <a href="http://mykzilla.blogspot.com/2011/09/nextprevious-tab-keyboard-shortcuts-on.html">on my Mac</a>, all those programs implement the same keyboard shortcut for switching to the previous/next tab, and it's a simple one with just a two-key chord: Control + PageUp / PageDown.<br> <br> Ha!<br> <br> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com8tag:blogger.com,1999:blog-18929277.post-16396965693833688562011-09-08T17:03:00.001-07:002011-09-08T17:03:31.723-07:00"Next/Previous Tab" Keyboard Shortcuts on MacOn my Mac, I use the following five programs with tabbed interfaces on a regular basis:<br> <ul> <li>Firefox</li> <li>Thunderbird</li> <li>Adium</li> <li>Terminal</li> <li>Komodo IDE</li> </ul> <br> And those programs implement the following five different keyboard shortcuts for switching to the previous/next tab:<br> <ul> <li>Control + PageUp / PageDown (Firefox, Thunderbird)<br> </li> <li>Command + LeftArrow / RightArrow (Adium)</li> <li>Command + PageUp / PageDown (Komodo IDE)</li> <li>Command + Shift + [ / ] (Terminal)</li> <li>Command + Shift + LeftArrow / RightArrow (Terminal)</li> </ul> Hrm.<br> <br> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com6tag:blogger.com,1999:blog-18929277.post-44353983979280219572011-09-07T14:25:00.000-07:002011-09-20T11:37:47.397-07:00gitflow vs. the SDK<a href="http://nvie.com/posts/a-successful-git-branching-model/">gitflow</a> is a model for developing and shipping software using <a href="http://git-scm.com/">Git</a>. <a href="https://addons.mozilla.org/en-US/developers/builder">Add-on SDK</a> uses Git, and <a href="https://wiki.mozilla.org/Jetpack/Development_Process">it too has a model</a>, which is similar to gitflow in some ways and different in others. Here's a comparison of the two and some thoughts on why they vary.<br /><br />First, some similarities: both models use multiple branches, including an ongoing branch for general development and another ongoing branch that is always ready for release (their names vary, but that's a trivial difference). Both also permit development on temporary feature (topic) branches and utilize a branch for stabilization of the codebase leading up to a release. And both accommodate the occasional hotfix release in similar ways.<br /><br />(Aside: gitflow appears to encourage feature branches, but I tend to agree with <a href="http://martinfowler.com/bliki/FeatureBranch.html">Martin Fowler</a> through <a href="http://pauljulius.com/blog/2009/09/03/feature-branches-are-poor-mans-modular-architecture/">Paul Julius</a> that continuously integrating with a central development branch is preferable.)<br /><br />Second, some differences: the SDK uses a single ongoing stabilization branch, while gitflow uses multiple short-lived stabilization branches, one per release. And in the SDK, stabilization fixes land on the development branch and then get cherry-picked to the stabilization branch; whereas in gitflow, stabilization fixes land on the stabilization branch and then get merged to the development branch.<br /><br />(Also, the SDK releases on a regular time/quality-driven "train" schedule similar to <a href="http://mozilla.github.com/process-releases/draft/development_overview/">Firefox's</a>, while gitflow may anticipate an irregular feature/quality-driven release schedule, although it can be applied to projects with train schedules, like <a href="http://lloyd.io/applying-gitflow">BrowserID</a>.)<br /><br />A benefit of gitflow's approach to stabilization is that its change graph includes only distinct changes, whereas cherry-picking adds duplicate, semi-associated changes to the SDK's graph. However, a downside of gitflow's approach is that developers must attend to where they land changes, whereas SDK developers always land changes on its development branch, and its release manager takes on the chore of getting those changes onto the stabilization branch.<br /><br />(It isn't clear what happens in gitflow if a change lands on the development branch while a release is being stabilized and afterward is identified as being wanted for the release. Perhaps it gets cherry-picked?)<br /><br />Overall, these models seem fairly similar, and it wouldn't be too hard to make the SDK's be essentially gitflow. We would just need to stipulate that developers land stabilization fixes on the stabilization branch, and the release manager's job would then be to merge that branch back to the development branch periodically instead of cherry-picking in the other direction.<br /><br />However, it isn't clear to me that such a change would be preferable. What do you think?Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com5tag:blogger.com,1999:blog-18929277.post-80208540275935571592011-08-21T22:51:00.000-07:002011-09-20T11:38:43.594-07:00Administer Git? Get a job!As I <a href="http://mykzilla.blogspot.com/2011/08/why-add-on-sdk-doesnt-land-in-mozilla.html">mentioned recently</a>, <a href="http://git-scm.com/">Git</a> (on <a href="https://github.com/">GitHub</a>) has become a popular VCS for Mozilla-related projects.<br> <br> GitHub is a fantastic tool for collaboration, and the site does a great job running a Git server, but given the importance of the VCS, and because Mozilla's automated test machines don't have access to servers outside the Mozilla firewall, Mozilla should <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=528360">run its own Git server</a> (that syncs with GitHub, so developers can continue to use that site for collaboration).<br> <br> Unfortunately, the organization doesn't have a great deal of in-house Git server administration experience, but we're <a href="http://hire.jobvite.com/CompanyJobs/Careers.aspx?c=qpX9Vfwa&amp;cs=9Kt9Vfw1&amp;page=Job%20Description&amp;j=oIfPVfwr">hiring systems administrators</a>, so if you grok Git hosting and meet the other requirements, <a href="http://hire.jobvite.com/CompanyJobs/Careers.aspx?c=qpX9Vfwa&amp;page=Apply&amp;j=oIfPVfwr">send in your resume</a>!<br> <br> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com5tag:blogger.com,1999:blog-18929277.post-13078517539939578112011-08-11T13:33:00.000-07:002011-09-20T11:38:43.545-07:00Why the Add-on SDK Doesn't "Land in mozilla-central"Various Mozillians sometimes suggest that the Add-on SDK should "land in mozilla-central" and wonder why it doesn't. Here's why.<br /><br /><br />The Add-on SDK depends on features of Firefox (and Gecko), and the SDK's development process synchronizes its release schedule with Firefox's. Nevertheless, the SDK isn't a component of Firefox, it's a distinct product with its own codebase, development process, and release schedule.<br /><br />Mozilla makes multiple products that interact with Firefox (addons.mozilla.org, a.k.a. AMO, is another), and distinct product development efforts should generally utilize separate code repositories, to avoid contention between the projects regarding tree management, the stages of the software development lifecycle (i.e. when which branch is in alpha, beta, etc.), and the schedules for merging between branches.<br /><br />There can be exceptions to that principle, for products that share a bunch of code, use the same development process, and have the same release schedule (cf. the Firefoxes for desktop and mobile). But the SDK is not one of those exceptions.<br /><br /><br />It shares no code with Firefox. Its process utilizes one fewer branch and six fewer weeks of development than the Firefox development process, to minimize the burden of branch management and stabilization build testing on its much smaller development team and testing community. And it merges its branches and ships its releases two weeks before Firefox, to give AMO and addon developers time to update addons for each new version of the browser.<br /><br />Living in its own repository makes it possible for the SDK to have these differences in its process, and it also makes it possible for us to change the process in the future, for example to move up the branch/release dates one week, if we discover that AMO and addon developers would benefit from three weeks of lead time; or to ship twice as frequently, if we determine that doing so would get APIs for new Firefox features into developers' hands faster.<br /><br />Finally, the Jetpack project has a vibrant community of contributors (including both organization staff and volunteers) who strongly prefer contributing via Git and <a href="https://github.com/">GitHub</a>, because they find it easier, more efficient, and more enjoyable, and for whom working in mozilla-central would mean taking too great a hit on their productivity, passion, and participation.<br /><br />Mozilla Labs innovates not only on features and user experience but also on development process and tools, and while Jetpack didn't lead the way to GitHub, we were a fast follower once early experiments validated its benefits. And our experience since then has only confirmed our decision, as GitHub has proven to be a fantastic tool for branch management, code review/integration, and other software development tasks.<br /><br />Other Mozillians agree: there are now almost two hundred members and over one hundred repositories (not counting forks) in the Mozilla organization on GitHub, with major initiatives like <a href="https://github.com/mozilla/openwebapps">Open Web Apps</a> and <a href="https://github.com/mozilla/browserid">BrowserID</a> being hosted there, not to mention all the Mozilla projects in user repositories, including <a href="https://github.com/graydon/rust">Rust</a> and <a href="https://github.com/jbalogh/zamboni">Zamboni</a>.<br /><br /><br />Even if we don't make mozilla-central the canonical repository for SDK development, however, we could still periodically drop a copy of the SDK source against which Firefox changes should be tested into mozilla-central. And doing so would theoretically make it easier for Firefox developers to run SDK tests when they discover that a Firefox change breaks the SDK, because they wouldn't have to get the SDK first.<br /><br />But the benefit to Firefox developers is minimal. Currently, we periodically drop a reference to the SDK revision against which Firefox changes should be tested, and developers have to do the following to initiate testing:<br /><br /><pre>&nbsp; wget -i testing/jetpack/jetpack-location.txt -O addon-sdk.tar.bz2 + <br />&nbsp; tar xjf addon-sdk.tar.bz2 + <br />&nbsp; cd addon-sdk-[revision] + <br />&nbsp; source bin/activate + <br />&nbsp; cfx testall --binary path/to/Firefox/build + <br /></pre><br />We can simplify this to:<br /><br /><pre>&nbsp; testing/jetpack/clone + <br />&nbsp; cd addon-sdk + <br />&nbsp; source bin/activate + <br />&nbsp; cfx testall --binary path/to/Firefox/build + <br /></pre><br />Whereas if we dropped the source instead of just a reference to it, it would instead be the only slightly simpler: <br /><br /><pre>&nbsp; cd testing/jetpack/addon-sdk + <br />&nbsp; source bin/activate + <br />&nbsp; cfx testall --binary path/to/Firefox/build + <br /></pre><br />Either of which can be abstracted to a single make target.<br /><br />But if we were to drop source instead of a reference thereto, the drops would be larger and riskier changes. And test automation would still need to be updated to support Git (or at least continue to use brittle Git -&gt; Mercurial mirroring), in order to run tests on SDK changes, which periodic source drops do not address.<br /><br /><br />Now, this doesn't mean that no SDK code will ever land in mozilla-central.<br /><br />Various folks have discussed integrating parts of the SDK into core Firefox<span class="st">—</span>including stable API implementations, the module loader, and possibly the bootstrapper<span class="st">—</span>to reduce the size of addon packages, improve addon startup times, and decrease addon memory consumption. I have written a very preliminary draft of a <a href="https://wiki.mozilla.org/Features/Jetpack/Land_Parts_of_Add-on_SDK_In_Core">feature page describing this work</a>, although I do not think it is a high priority at the moment, relative to the other priorities identified in the <a href="https://wiki.mozilla.org/Jetpack/Roadmap">Jetpack roadmap</a>.<br /><br />And Dietrich Ayala recently suggested <a href="http://groups.google.com/group/mozilla.dev.planning/browse_frm/thread/2b57ebe15aad4130">integrating the SDK into core Firefox for use by core features</a>, by which he presumably also means the API implementations/module loader/bootstrapper rather than the command-line tool for testing and packaging addons.<br /><br />Nevertheless, I am (and, I suspect, the whole Jetpack team is) even open to discussing integration of the command-line tool (or its replacement by a graphical equivalent), merging together the two products, and erasing the distinction between them, just as Firefox ships with core features for web development.&nbsp; We've even drafted a <a href="https://wiki.mozilla.org/Features/Jetpack/Add-on_SDK_as_an_Addon">feature page for converting the SDK into an addon</a>, which is a big step in that direction.<br /><br />But until that happens, farther on up the road, the SDK is its own product that we develop with its own process and ship on its own schedule. And it has good reason to live in its own repository, and a Git one at that, as do the many (and growing number of) other Mozilla projects using similar processes and tools, which our community-wide development, collaboration, and testing infrastructure must evolve to accommodate.Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com6tag:blogger.com,1999:blog-18929277.post-67156088595128483442010-12-02T11:07:00.001-08:002011-09-20T11:38:43.568-07:00SDK Training and More at Add-on-Con<div class="moz-text-html" lang="x-western">Next Wednesday, December 8, I'll be at <a href="http://addoncon.com/">Add-on-Con</a>.<br> <br> In the morning, I'll conduct a training session introducing Mozilla's new Add-on SDK, which makes it faster and easier to build Firefox add-ons. Afterwards, I'll be around and about to discuss add-ons and answer questions about the SDK and add-on development generally.<br> <br> Lots of other Mozilla folks will also be on hand over the course of the two-day conference, including <a href="http://www.oxymoronical.com/">Dave Townsend</a>, Jorge Villalobos, <a href="http://jboriss.wordpress.com/">Jeniffer Boriss</a>, <a href="http://starkravingfinkle.org/blog/">Mark Finkle</a>, and <a href="http://blog.fligtar.com/">Justin Scott</a>. A rockin' time should be had by all. Join us!<br> <br> </div> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com0tag:blogger.com,1999:blog-18929277.post-13235514220462353022010-11-27T20:47:00.001-08:002011-09-20T11:38:43.550-07:00Further Adventures In Git(/Hub)ery<div class="moz-text-html" lang="x-western"> This evening I decided to check if there were any outstanding pull requests for the SDK repository (to which I haven't been paying attention).<br> <br> There were! The oldest was <a href="https://github.com/mozilla/addon-sdk/pull/29">pull request 29</a> from Thomas Bassetto, which contains two small fixes (<a href="https://github.com/tbassetto/addon-sdk/commit/8268334070d03a896d5c006d1b4db94d4cb44b17">first</a>, <a href="https://github.com/tbassetto/addon-sdk/commit/666ad7a99e05e338348dfc579d5b1f75e8d3bb1b">second</a>) to the docs.<br> <br> So I fetched the branch of his fork in which the changes reside:<br> <br> <blockquote><tt>$ git fetch <a class="moz-txt-link-freetext" href="https://github.com/tbassetto/addon-sdk.git">https://github.com/tbassetto/addon-sdk.git</a> master</tt><br> </blockquote> <br> But that branch (and the fork in general) is a few weeks out-of-date, so "<tt>git diff HEAD FETCH_HEAD</tt>" showed a bunch of changes, and it was unclear how painful the merge would be.<br> <br> Thus I decided to try cherry-picking the changes, my first time using "<tt>git cherry-pick</tt>".<br> <br> The first one went great:<br> <br> <blockquote><tt>$ git cherry-pick 8268334070d03a896d5c006d1b4db94d4cb44b17</tt><br> <tt>Finished one cherry-pick.</tt><br> <tt>[master ceadb1f] Fixed an internal link in the widget doc</tt><br> <tt>&nbsp;1 files changed, 1 insertions(+), 1 deletions(-)</tt><br> </blockquote> <br> Except that I realized afterward I hadn't added "r,a=myk" to the commit message. So I tried "<tt>git commit --amend</tt>" for the first time, which worked just fine:<br> <br> <blockquote><tt>$ git commit --amend</tt><br> <tt>[master 2d674a6] Fixed an internal link in the widget doc; r,a=myk</tt><br> <tt>&nbsp;1 files changed, 1 insertions(+), 1 deletions(-)</tt><br> </blockquote> <br> Next time I'll remember to use the "<tt>--edit</tt>" flag to "<tt>git cherry-pick</tt>", which lets one "edit the commit message prior to committing."<br> <br> The second cherry-pick was more complicated, because I only wanted one of the two changes in the commit (in <a href="https://github.com/tbassetto/addon-sdk/commit/666ad7a99e05e338348dfc579d5b1f75e8d3bb1b#commitcomment-204023">my review</a>, I had identified the second change as unnecessary); and, as it turned out, also because there was a merge conflict with other commits.<br> <br> I started by cherry-picking the commit with the "<tt>--no-commit</tt>" option (so I could remove the second change):<br> <br> <blockquote><tt>$ git cherry-pick --no-commit 666ad7a99e05e338348dfc579d5b1f75e8d3bb1b</tt><br> <tt>Automatic cherry-pick failed.&nbsp; After resolving the conflicts,</tt><br> <tt>mark the corrected paths with 'git add &lt;paths&gt;' or 'git rm &lt;paths&gt;' and commit the result.</tt><br> <tt>When commiting, use the option '-c 666ad7a' to retain authorship and message.</tt><br> </blockquote> <br> The conflict was trivial, and I knew where it was, so I resolved it manually (instead of trying "<tt>git mergetool</tt>" for the first time), removed the second change, added the merged file, and committed the result, using the "<tt>-c</tt>" option to preserve the original author and commit message while allowing me to edit the message to add "r,a=myk":<br> <br> <blockquote><tt>$ git add packages/addon-kit/docs/request.md</tt><br> <tt>$ git commit -c 666ad7a</tt><br> <tt>[master 774d1cb] Completed the example in the Request module documentation; r,a=myk</tt><br> <tt>&nbsp;1 files changed, 1 insertions(+), 0 deletions(-)</tt><br> </blockquote> <br> Then I used "<tt>gitg</tt>" and "<tt>git log master ^upstream/master</tt>" to verify that the commits looked good to go, after which I pushed them:<br> <br> <blockquote><tt>$ git push upstream master</tt><br> <tt>[git's standard obscure and disconcerting gobbledygook]</tt><br> </blockquote> <br> Finally, I closed the pull request with <a href="https://github.com/mozilla/addon-sdk/pull/29#issuecomment-570630">this comment</a> that summarized what I did and provided links to the cherry-picked commits.<br> <br> It would have been nice if the cherry-picked commit that didn't have merge conflicts (and which I didn't change in the process of merging) had kept its original commit ID, but I sense that that is somehow a fundamental violation of the model.<br> <br> It would also have been nice if the cherry-picked commit messages had been automatically annotated with references to the original commits.<br> <br> But overall the process seemed pretty reasonable, it was fairly easy to do what I wanted and recover from mistakes, and the author, committer, reviewer, and approver are clearly indicated in the cherry-picked commits (<a href="https://github.com/mozilla/addon-sdk/commit/2d674a6ea84d3be88b5365b2d24b994297a60d7a">first</a>, <a href="https://github.com/mozilla/addon-sdk/commit/774d1cbf49e152a030a0bf6cbde7b4139c8c3f49">second</a>).<br> <br> [Also <a href="http://groups.google.com/group/mozilla-labs-jetpack/browse_thread/thread/430750c65fe80231">posted to the discussion group</a>.]<br> <br> </div> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com3tag:blogger.com,1999:blog-18929277.post-79604338409996471742010-11-27T20:39:00.001-08:002011-09-20T11:38:43.583-07:00More Git/Hub Workflow ExperiencesAfter posting about my <a href="http://mykzilla.blogspot.com/2010/11/github-workflow-experiences.html">first Git/Hub workflow experiences</a>, I got lots of helpful input from various folks, particularly Erik Vold, Irakli Gozalishvili, and Brian Warner, which led me to refine my process for handling pull requests:<br /><br /><ol><li>From the "how to merge this pull request" section of the pull request page (f.e. <a href="https://github.com/mozilla/addon-sdk/pull/43">pull request 34</a>), copy the command from step two, but change the word "pull" to "fetch" to fetch the remote branch containing the changes without also merging it:<br /><br /><code>git fetch <a class="moz-txt-link-freetext" href="https://github.com/toolness/jetpack-sdk.git">https://github.com/toolness/jetpack-sdk.git</a> bug-610507<br /><br /></code></li><li>Use the magic FETCH_HEAD reference to the last fetched branch to verify that the set of changes is what you expect:<br /><br /><tt>git diff </tt><tt>HEAD </tt><tt>FETCH_HEAD</tt><br /><br />(The exact syntax here may need some work; HEAD..FETCH_HEAD? three dots?)<br /><br /></li><li>Merge the remote branch into your local branch with a custom commit message:<br /><br /><tt>git merge FETCH_HEAD --no-ff -m"bug 610507: get rid of the nsjetpack package; r=myk"</tt><br /><br /></li><li>Push the changes upstream:<br /><br /><tt>git push upstream master</tt><br /></li></ol><br />I like this set of commands because it doesn't require me to add a remote, I can copy/paste the fetch command from GitHub (being careful not to issue the pull before I change it to a fetch), and I always type the same FETCH_HEAD reference to the remote branch in step three.<br /><br />However, I wish the <a href="https://github.com/mozilla/addon-sdk/commit/0e23d1c1555d5de228ed7ad62c8715e2775d2390">merge commit page</a> explicitly referenced the <a href="https://github.com/mozilla/addon-sdk/commit/68b6e306dfeccef103b071e0812dc3a375830ac0">specific</a> <a href="https://github.com/mozilla/addon-sdk/commit/715cb47c720bcdd11846cae6c6cab325bb1a982b">commits</a> that were merged. It does mention that it's a branch merge, it isn't obvious how to get from that page to the pages for the commits I merged from the branch.<br /><br />"<tt>git log --oneline --graph</tt>", <tt>gitg</tt>, and <tt>gitk</tt> do give me that information, though, so I'm ok on the command line, anyway.<br /><br />[More discussion can be found in the <a href="http://groups.google.com/group/mozilla-labs-jetpack/browse_thread/thread/2c6cb3e7f3bec468">discussion group thread</a>.]Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com0tag:blogger.com,1999:blog-18929277.post-70371894287736813602010-11-12T18:55:00.000-08:002011-09-20T11:38:43.577-07:00Git/Hub Workflow Experiences<div class="moz-text-html" lang="x-western">The Jetpack project recently migrated its SDK repository to Git (hosted on GitHub), and we've been working out changes to the bug/review/commit workflow that GitHub's tools enable (specifically, pull requests).</div><div class="moz-text-html" lang="x-western">&nbsp;</div><div class="moz-text-html" lang="x-western">Here are some of my initial experiences and my thoughts on them (which I've also <a href="http://groups.google.com/group/mozilla-labs-jetpack/browse_thread/thread/2c6cb3e7f3bec468">posted to the Jetpack discussion group</a>).</div><div class="moz-text-html" lang="x-western">&nbsp;</div><div class="moz-text-html" lang="x-western"> </div><div class="moz-text-html" lang="x-western"> Warning: Git wonkery ahead, with excruciating details. I would not want to read this post. I recommend you skip it. ;-)<br /><br /><br /><span style="font-size: large;"><b> Part 1: Wherein I Handle My First Pull Request</b></span><br /><br />To fix some test failures, Atul submitted <a href="https://github.com/mozilla/addon-sdk/pull/33">GitHub pull request 33</a>, I reviewed the changes (comprising <a href="https://github.com/toolness/jetpack-sdk/commit/97619b0b25554712756827de883883c9b810319d">two</a> <a href="https://github.com/toolness/jetpack-sdk/commit/405390a586f6c09bad2b26183fe2925d09bcd52b">commits</a>) on GitHub, and then I pushed them to the canonical repository via the following set of commands:<br /><ol><li>git checkout -b toolness-<span class="commit-ref from">4.0b7-bustage-fixes</span> master</li><li>git pull <a class="moz-txt-link-freetext" href="https://github.com/toolness/jetpack-sdk.git">https://github.com/toolness/jetpack-sdk.git</a> <span class="commit-ref from">4.0b7-bustage-fixes</span></li><li>git checkout master</li><li>git merge toolness-<span class="commit-ref from">4.0b7-bustage-fixes</span></li><li>git push upstream master</li></ol><br />That landed the <a href="https://github.com/mozilla/addon-sdk/commit/97619b0b25554712756827de883883c9b810319d">two</a> <a href="https://github.com/mozilla/addon-sdk/commit/405390a586f6c09bad2b26183fe2925d09bcd52b">commits</a> in the canonical repository, but it isn't obvious that they were related (i.e. part of the same pull request), that I was the one who reviewed them, or that I was the one who pushed them.<br /><br /><br /><span style="font-size: large;"><b>Part 2: Wherein I Handle My Second Pull Request</b></span><br /><br />Thus, for the fix for <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=611042">bug 611042</a>, for which Atul submitted <a href="https://github.com/mozilla/addon-sdk/pull/34">GitHub pull request 34</a>, I again reviewed the changes (also comprising <a href="https://github.com/toolness/jetpack-sdk/commit/5e6ca0e1834e65623f6ac87d3828965da420847c">two</a> <a href="https://github.com/toolness/jetpack-sdk/commit/1ab9c78c94fb08610460ad19fd763a7402fc233c">commits</a>) on GitHub, but then I pushed them to the <a href="https://github.com/mozilla/addon-sdk">canonical repository</a> via this different set of commands (after discussion with Atul and Patrick Walton of the Rust team):<br /><ol><li>git checkout -b toolness-bug-611042 master</li><li>git pull <a class="moz-txt-link-freetext" href="https://github.com/toolness/jetpack-sdk.git">https://github.com/toolness/jetpack-sdk.git</a> bug-611042</li><li>(There might have been something else here, since the pull request resulted in a merge; I don't quite remember.)<br /></li><li>git checkout master</li><li>git merge --no-ff --no-commit toolness-bug-611042</li><li>git commit --signoff -m "bug 611042: remove request.response.xml for e10s compatibility; r=myk" --author "atul"</li><li>git push upstream master</li></ol><br />Because Atul's pull request was no longer against the tip (since I had just merged those previous changes), when I pulled the remote bug-611042 branch into my local toolness-bug-611042 branch (step 2), I had to merge his changes, which resulted in a <a href="https://github.com/mozilla/addon-sdk/commit/6a3c9e2a614f29b61e580a7a7619f91dd1306eea">merge commit</a>.<br /><br />Merging the changes to my local master with "--no-ff" and "--no-commit" (step 5) then allowed me to commit the merge to my master branch manually (step 6), resulting in another <a href="https://github.com/mozilla/addon-sdk/commit/9f202a3003cddace040bc695ab7137d4a31051ec">merge commit</a>.<br /><br />For the second merge commit, I specified "--signoff", which added "Signed-off-by: Myk Melez <a class="moz-txt-link-rfc2396E" href="mailto:myk@mozilla.org"><myk@mozilla.org></myk@mozilla.org></a>" to the commit message; crafted a custom commit message that included "r=myk"; and specified '--author "atul"', which made Atul the author of the merge.<br /><br />I dislike having the former merge commit in history, since it's extraneous, unuseful details about how I did the merging locally before I pushed to the canonical repository. I'm not sure how to avoid it, though.<br /><br />On the other hand, I like having the latter merge commit in history, since it provides context for Atul's <a href="https://github.com/mozilla/addon-sdk/commit/5e6ca0e1834e65623f6ac87d3828965da420847c">two</a> <a href="https://github.com/mozilla/addon-sdk/commit/1ab9c78c94fb08610460ad19fd763a7402fc233c">commits</a>: the bug number, the fact that the changes were reviewed, and a commit message that describes the changes as a whole.<br /><br />I'm ambivalent about --signoff vs. adding "r=myk" to the commit message, as they seem equivalentish, with --signoff being more explicit (so in theory it might form part of an enlightened workflow in the future), while "r=myk" is simpler.<br /><br />And I dislike having made Atul the author of the merge, since it's incorrect: he wasn't the author of the merge, he was only the author of the changes (for which he is correctly credited). And if the merge itself caused problems (f.e. I accidentally backed out other recent changes in the process), I would be the one responsible for fixing those problems, not Atul.<br /><br /><br /><span style="font-size: large;"><b>Part 3: Pushing Patches</b></span><br /><br />In addition to pull requests, one can also contribute via patches. I've pushed a few of these via something like the following set of commands:<br /><ol><li>git apply patch.diff</li><li>git commit -a -m "bug <number>: <description changes="" of="">; r=myk" --author "<author name="">"<br /></author></description></number></li><li>git push upstream master</li></ol>That results in a commit like <a href="https://github.com/mozilla/addon-sdk/commit/026b4e8e78336c2dbbf30edb14e5db78ca4afb21">this one</a>, which shows me as the committer and the patch author as the author. And that seems like a fine record of what happened.<br /><br /><br /><span style="font-size: large;"><b>Part 4: To Bug or Not To Bug?</b></span><br /><br />One of the questions GitHub raises is whether or not every change deserves a bug report. And if not, how do we differentiate those that do from the rest?<br /><br />I don't have the definitive answers to these questions, but my sense, from my experience so far, is that we shouldn't require all changes to be accompanied by bug reports, but larger, riskier, time-consuming, and/or controversial changes should have reports to capture history, provide a forum for discussion, and permit project planning; while bug reports should be optional for smaller, safer, quickly-resolved, and/or non-controversial changes.<br /><br /></div>Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com3tag:blogger.com,1999:blog-18929277.post-2362543200025899312010-07-15T14:22:00.000-07:002011-09-20T11:38:43.557-07:00My Recent Jetpack PresentationsThe last few weeks have been presentation-heavy.<br /><br />First, I gave a presentation about the Jetpack project (past accomplishments, present status, future plans) at the <a href="https://wiki.mozilla.org/MAOW:2010:London">2010 London Mozilla Add-ons Workshop</a> (MAOW), including a demo of using <a href="https://builder.mozillalabs.com/">Add-on Builder</a> to build an add-on in five minutes.<br /><br />Then I reprised the Add-on Builder demo as part of the opening day keynote at the <a href="https://wiki.mozilla.org/Summit2010">Mozilla Summit</a>, where it got a great reception. You can watch it in <a href="http://www.youtube.com/watch?v=lKN4_fOKEWQ">this Youtube video</a>.<br /><br />Finally, I gave an updated version of the MAOW presentation on the third day of the summit. The slides are available in <a href="https://people.mozilla.com/%7Emyk/presentations/Prepare%20for%20Liftoff%20-%20Summit%202010.odp">OpenDocument</a> and <a href="https://people.mozilla.com/%7Emyk/presentations/Prepare%20for%20Liftoff%20-%20Summit%202010.pdf">PDF</a> formats, and Jetpack presentation materials generally are all available from the <a href="https://wiki.mozilla.org/Labs/Jetpack/Presentations">Jetpack Presentations wiki page</a>.Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com6tag:blogger.com,1999:blog-18929277.post-65834685429750898932010-03-05T23:03:00.001-08:002010-04-18T23:58:52.841-07:00This blog has moved<br /> This blog is now located at http://mykzilla.blogspot.com/.<br /> You will be automatically redirected in 30 seconds, or you may click <a href='http://mykzilla.blogspot.com/'>here</a>.<br /><br /> For feed subscribers, please update your feed subscriptions to<br /> http://mykzilla.blogspot.com/feeds/posts/default.<br /> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com0tag:blogger.com,1999:blog-18929277.post-70157768874119079342009-11-17T17:26:00.000-08:002009-11-17T17:26:50.807-08:00The Skinny on Raindrop's Mailing List ExtensionsRaindrop is an exploration of messaging innovation that strives to intelligently assist people in managing their flood of incoming messages. And mailing lists are a common source of messages you need to manage. So, with assistance from the Raindrop hackers, I wrote extensions that make it easier to deal with messages from mailing lists.<br /><br />Their goal is to soothe two particular pain points when dealing with mailing lists: grouping their messages together by list and unsubscribing from them once you're no longer interested in their subject matter.<br /><br />This post explains how the extensions do this; touches on some aspects of Raindrop's message processing and data storage models; and speculates about possible future directions for the extensions.<br /><h3>Raindrop Extensibility</h3>Raindrop is being built with the explicit goal of being broadly and deeply extensible, and it includes a number of APIs for adding and modifying functionality. The mailing list enhancements comprise two related extensions, one in the backend and one in the user interface.<br /><br />The backend extension plugs into Raindrop's incoming message processor, intercepting incoming email messages and extracting info about the mailing lists to which they belong. It also handles much of the work of unsubscribing from a list.<br /><br />The frontend extension plugs into Raindrop's Inflow application, modifying its interface to show you the most recent mailing list messages at a glance, group mailing list conversations together by list, and provide a button you can press to easily unsubscribe from a mailing list.<br /><h3>Message Processing and Data Storage<br /></h3>Before getting into how the extensions work, it's useful to know a bit about how Raindrop processes and stores messages.<br /><br />Raindrop stores information using <a href="http://couchdb.apache.org/">CouchDB</a>, a document-centric database whose principal unit of information storage and retrieval is the document (the equivalent of a record in SQL databases). Documents are just JSON blobs that can contain arbitrary name -> value pairs (unlike SQL records, which can only contain values for predeclared columns).<br /><br />To distinguish between different kinds of documents, Raindrop assigns each a schema (similar to a table in SQL parlance) that describes (and may one day constrain) its properties. The <tt>rd.msg.email</tt> schema is the primary schema representing an email message, while the <tt>rd.mailing-list</tt> is the schema representing a mailing list, and the <tt>rd.msg.email.mailing-list</tt> is a simple schema that associates messages with their lists.<br /><br />(In an SQL database, <tt>rd.msg.email</tt> and <tt>rd.mailing-list</tt> would be tables whose rows represent email messages and mailing lists, while <tt>rd.msg.email.mailing-list</tt> would be a table whose rows map one to the other.)<br /><br />Note that there's a many-to-one relationship between messages and lists, since messages belong to a single list, although lists contain many messages, so <tt>rd.msg.email.mailing-list</tt> isn't strictly necessary. Its <tt>list-id</tt> property (which identifies the list to which the message belongs) could simply be a property of <tt>rd.msg.email</tt> docs (or, in SQL terms, a foreign key in the <tt>rd.msg.email</tt> table).<br /><br />But putting it into its own document has several advantages. First, it improves robustness, as it reduces the possibility of conflicts between extensions and core code writing to the same documents.<br /><br />It also improves write performance, as it's faster to add a document than to modify an existing one (although index generation and read performance can be an issue).<br /><br />Finally, it improves extensibility, because it makes it possible to write an extension that extends the backend mailing list extension.<br /><br />That's because Raindrop's incoming message processing model allows extensions to observe the creation of any kind of document, including those created by other extensions.<br /><br />So just as the mailing list extension observes the creation of <tt>rd.msg.email</tt> documents, another extension can observe the creation of <tt>rd.msg.email.mailing-list</tt> documents and process them further in some useful way. If the mailing list extension simply modified the original document instead of creating its own, that would require some additional and more complicated API.<br /><h3>The Backend Extension</h3>The primary function of the backend extension is to examine every incoming message and dress the ones from mailing lists with some additional structured information that the frontend can use to organize them.<br /><br />Backend extensions are accompanied by a JSON manifest that tells Raindrop what kinds of incoming documents it wants to intercept. The mailing list extension's manifest registers it as an observer of incoming <tt>rd.msg.email</tt> documents, which get created when Raindrop retrieves an email message:<br /><pre style="background-color: rgb(238, 238, 238); border: 1px solid rgb(187, 187, 187); color: black; padding: 10px;">"schemas" : {<br /> "rd.ext.workqueue" : {<br /> "source_schemas" : ["rd.msg.email"],<br />...</pre><br />The extension itself is a Python script with a <tt>handler</tt> function that gets passed the <tt>rd.msg.email</tt> document and looks to see if it contains a <tt>List-ID</tt> header (or, in certain cases, another identifier) identifying the mailing list from which the message comes:<br /><pre style="background-color: rgb(238, 238, 238); border: 1px solid rgb(187, 187, 187); color: black; padding: 10px;">def handler(message):<br /> ...<br /> if 'list-id' in message['headers']:<br /> # Extract the ID and name of the mailing list from the list-id header.<br /> # Some mailing lists give only the ID, but others (Google Groups,<br /> # Mailman) provide both using the format 'NAME &lt;id&gt;', so we extract them<br /> # separately if we detect that format.<br /> list_id = message['headers']['list-id'][0]<br /> ...</pre><br />If it doesn't find a list identifier, it simply returns, and Raindrop continues processing the message:<br /><pre style="background-color: rgb(238, 238, 238); border: 1px solid rgb(187, 187, 187); color: black; padding: 10px;">if not list_id:<br /> logger.debug("NO LIST ID; ignoring message %s", message_id)<br /> return</pre><br />Otherwise, it calls Raindrop's <tt>emit_schema</tt> function to create an <tt>rd.msg.email.mailing-list</tt> document linking the message document to an <tt>rd.mailing-list</tt> document representing the mailing list:<br /><pre style="background-color: rgb(238, 238, 238); border: 1px solid rgb(187, 187, 187); color: black; padding: 10px;">emit_schema('rd.msg.email.mailing-list', { 'list_id': list_id })</pre><br />In this function call, <tt>rd.msg.email.mailing-list</tt> is the type of document to create, while <tt>{ 'list_id': list_id }</tt> is the document itself, written as Python that will get serialized to JSON.<br /><br />A document created inside a backend extension like this automatically gets a reference to the document the extension is processing (i.e. the <tt>rd.msg.email</tt> document), so the only thing it has to explicitly include is a reference to the list document, in the form of a <tt>list_id</tt> property whose value is the list identifier.<br /><br />The extension also checks if there's an <tt>rd.mailing-list</tt> document in the database for the mailing list itself, and if not, it creates one, populating it with information from the message's <tt>List-*</tt> headers, like how to unsubscribe from the list. Otherwise, it updates the existing mailing list document if the message's <tt>List-*</tt> headers contain updates.<br /><h3>The Frontend Extension</h3>The frontend extension uses the information extracted by the backend to help users manage mailing lists in the Inflow application.<br /><br />It adds a widget to the Home view that shows you the last few messages from your lists at the bottom of the page, so you can keep an eye on those messages without having to give them your full attention:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://www.melez.com/mykzilla/uploaded_images/latest-list-messages-714113.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://www.melez.com/mykzilla/uploaded_images/latest-list-messages-714111.png" height="176" width="320" border="0" /></a><br /></div><br /><br />It adds a list of your mailing lists to the Organizer widget:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://www.melez.com/mykzilla/uploaded_images/mailing-list-list-722772.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://www.melez.com/mykzilla/uploaded_images/mailing-list-list-722768.png" height="320" width="190" border="0" /></a><br /></div><br /><br />And when you click on the name of a list, it shows you its conversations in the conversation pane:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://www.melez.com/mykzilla/uploaded_images/list-conversations-763392.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://www.melez.com/mykzilla/uploaded_images/list-conversations-763369.png" height="201" width="320" border="0" /></a><br /></div><br /><br />In traditional mail clients, users who want to break out their list messages into separate buckets like this typically have to create a folder for each list to contain its messages and then a filter for each list to move incoming list messages into the appropriate folders. The extension does this for you automatically!<br /><br />Finally, while viewing list conversations, if the extension knows how to unsubscribe you from the list, it displays an Unsubscribe button:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://www.melez.com/mykzilla/uploaded_images/unsubscribe-button-794151.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img src="http://www.melez.com/mykzilla/uploaded_images/unsubscribe-button-794149.png" height="201" width="320" border="0" /></a><br /></div><br /><br />Pressing the button (and then confirming your decision) unsubscribes you from the list. You don't have to do anything else, like remembering your username/password for some web page, sending an email, or confirming your request with the list admin. The extensions handle all those details for you so you don't have to know about them!<br /><h3>List Unsubscription</h3>In case you do want to know the details, however, it goes like this...<br /><br />First, the frontend extension sends a message to the list's admin address requesting unsubscription, with a certain command (like "unsubscribe") in the subject or body of the message (lists often specify exactly what command to send in the <tt>mailto:</tt> link they include in the <tt>List-Unsubscribe</tt> header):<br /><pre style="background-color: rgb(238, 238, 238); border: 1px solid rgb(187, 187, 187); color: black; padding: 10px;">From: Jan Reilly <jan@example.com><br />To: wasbigtalk-admin@example.com<br />Subject: unsubscribe</jan@example.com></pre><br />Then the server responds with a message requesting confirmation of the request, often putting a unique token into the Subject or Reply-To header to track the request:<br /><pre style="background-color: rgb(238, 238, 238); border: 1px solid rgb(187, 187, 187); color: black; padding: 10px;">From: wasbigtalk-admin@example.com<br />To: jan@example.com<br />Subject: please confirm unsubscribe from wasbigtalk (4bc3b7e439fd)<br /><br />Hello jan@example.com,<br /><br />We have received a request to unsubscribe you from wasbigtalk.<br />Please confirm this request to unsubscribe by replying to this email.<br />...</pre><br />Then the backend extension responds with a message confirming the request that includes the unique token:<br /><pre style="background-color: rgb(238, 238, 238); border: 1px solid rgb(187, 187, 187); color: black; padding: 10px;">From: jan@example.com<br />To: wasbigtalk-admin@example.com<br />Subject: Re: please confirm unsubscribe from wasbigtalk (4bc3b7e439fd)</pre><br />Finally, the server responds with a message confirming that the subscriber has, indeed, been unsubscribed:<br /><pre style="background-color: rgb(238, 238, 238); border: 1px solid rgb(187, 187, 187); color: black; padding: 10px;">From: wasbigtalk-admin@example.com<br />To: jan@example.com<br />Subject: you have been unsubscribed from wasbigtalk<br /><br />Hello jan@example.com,<br /><br />Your unsubscription from wasbigtalk was successful.<br />...</pre><br />At this point, the backend extension marks the list unsubscribed in the database, and the frontend extension marks it unsubscribed in the user interface.<br /><br />This process matches the way much mailing list server software works, although there are daemons in the details, so the extensions have to be programmed to support each server individually.<br /><br />Currently, they know how to handle <a href="http://groups.google.com/">Google Groups</a> and <a href="http://www.gnu.org/software/mailman/">Mailman</a> lists. <a href="http://www.mj2.org/">Majordomo2</a> (used by the <a href="http://www.bugzilla.org/">Bugzilla</a> and <a href="http://www.openbsd.org/">OpenBSD</a> projects, among others) is not supported, because it doesn't send <tt>List-*</tt> headers (alhough supposedly it can be configured to do so). The <a href="http://www.w3.org/">W3C</a>'s list server is not yet supported, although it does send <tt>List-*</tt> headers, and support should be fairly easy to add.<br /><br />Note that some of the processing the extension does is (locale-dependent) "screen"-scraping, as Google Groups and Mailman don't consistently identify the list ID and message type in some of their correspondence. In the long run, hopefully server software will improve in that regard. Perhaps someone can spearhead an effort to make it so?<br /><h3>The Future</h3>The extensions' current features fit in well with Raindrop's goal of helping people better handle their flood of incoming messages. But there is surely much more they could do to help in this regard.<br /><br />Besides general improvements to reliability and robustness--like support for additional list servers and handling of localized admin messages--they could let you resubscribe to a mailing list from which you've unsubscribed. And perhaps they could automatically fetch the messages you missed while you were away. Or even retrieve the entire archive of a list to which you're subscribed, so you can browse the archive in Raindrop!<br /><br />What bugs you about mailing lists? And how might Raindrop's mailing list extensions make them easier (and even funner) to use?Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com7tag:blogger.com,1999:blog-18929277.post-77407194706568152762009-11-04T15:58:00.001-08:002009-11-04T15:58:03.687-08:00Building/Releasing PersonasWant to know how a popular extension like Personas gets built and released? Neither do I! Yet I know anyway. And I've written it down for your edification! So <a href="https://wiki.mozilla.org/Labs/Personas/Build">check it out</a>.<br> <br> Myk Melezhttp://www.blogger.com/profile/01837818348188071923noreply@blogger.com0 \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/resources/feed_atom_feedburner.xml b/mobile/android/tests/background/junit4/resources/feed_atom_feedburner.xml new file mode 100644 index 000000000..85c4aaddf --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_atom_feedburner.xml @@ -0,0 +1,2 @@ + +tag:blogger.com,1999:blog-15318295164270133332016-01-21T16:20:29.143+01:00Android ZeitgeistSebastian Kasparinoreply@blogger.comBlogger23125tag:blogger.com,1999:blog-1531829516427013333.post-44357026163017838692015-09-17T19:46:00.000+02:002015-09-17T19:46:08.239+02:00Support for restricted profiles in Firefox 42One of our goals for <a href="https://www.mozilla.org/en-US/firefox/android/">Firefox for Android</a> 42.0 was to create a kid and parent-friendly web experience (Project <i>KinderFox / KidFox</i>): The browser should be easy to use for a kid and at the same time parents want to be in control and decide what the kid can do with it.<br /><br />There are a lot of things you can do to create a kid-friendly browsing experience. In this first version we focused on making the browser simpler by hiding complex or kid-unfriendly features and utilizing the parental controls of the Android system: <i>Restricted profiles</i>.<br /><br /><h3>What are restricted profiles?</h3><br />Restricted Profiles have been introduced in Android 4.3. The device administrator can create these profiles and restrict access to apps and features on the device. In addition to that restrictions inside an app can be configured if supported by the app.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-2nsGZS3PMBQ/VeSXR42xZcI/AAAAAAAAluA/eXr4RUP6QQs/s1600/restricted-profiles-settings.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="http://4.bp.blogspot.com/-2nsGZS3PMBQ/VeSXR42xZcI/AAAAAAAAluA/eXr4RUP6QQs/s640/restricted-profiles-settings.png" width="640" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Configuring which apps the restricted profile can acccess.</td></tr></tbody></table><br />A unique feature of restricted profiles is that they share the Google account of the device owner. It does not allow full-access to everything connected to the account but it allows the restricted user to watch content (e.g. movies and music) bought with that account or use paid applications. Of course only if the device owner explicitly allowed this. <br /><br />Unfortunately Restricted Profiles are only supported on tablets so far. It is a pity because in the meantime Google allowed to create full-featured and guest profiles on phones too.<br /><br />The following DevBytes episodes gives a good overview about the Restricted Profiles APIs:<br /><br /><iframe allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/pdUcANNm72o" width="560"></iframe> <br /><br /><br /><h3>Being in control</h3><br />Our final list of restrictable features for Firefox 42 contains 10 items:<br /><br /><ul></ul><ul><li><i>Disable add-on installation </i></li><li><i>Disable 'Import from Android' (Bookmark import) </i></li><li><i>Disable developer tools </i></li><li><i>Disable Home customization (<a href="https://hacks.mozilla.org/2014/07/building-firefox-hub-add-ons-for-firefox-for-android/">Home panels</a>) </i></li><li><i>Disable Private Browsing </i></li><li><i>Disable Location Services (Contributing to <a href="https://location.services.mozilla.com/">Mozilla's Location Service</a>) </i></li><li><i>Disable Display settings </i></li><li><i>Disable 'Clear browsing history' </i></li><li><i>Disable master password </i></li><li><i>Disable Guest Browsing </i></li></ul><ul></ul><br />Limiting access to features is a very personal decision. Not every parent wants to control every aspect of the browsing experience. That's why we decided to make these restrictions configurable by the parent. By implementing a broadcast receiver that listens to <a href="https://developer.android.com/reference/android/content/Intent.html#ACTION_GET_RESTRICTION_ENTRIES">ACTION_GET_RESTRICTION_ENTRIES</a> actions it's possible to send a list of restrictions to the system and so they will show up in the admin interface:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-9loC85f7nwM/VfrYo9ck7lI/AAAAAAAAmXo/ffox2Np3nZk/s1600/app-restrictions.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="http://1.bp.blogspot.com/-9loC85f7nwM/VfrYo9ck7lI/AAAAAAAAmXo/ffox2Np3nZk/s640/app-restrictions.png" width="640" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Configuring restrictions of an application.</td></tr></tbody></table>Later the application can query the <a href="http://developer.android.com/reference/android/os/UserManager.html">UserManager</a> to ask which restrictions have been enabled or disabled.<br /><br /><h3>Technical details</h3><br /><b>User restrictions vs. application restrictions</b><br />There are two kinds of restrictions. <a href="http://developer.android.com/reference/android/os/UserManager.html#getUserRestrictions%28%29">User restrictions</a> are imposed on the user by the system and <a href="http://developer.android.com/reference/android/os/UserManager.html#getApplicationRestrictions%28java.lang.String%29">application restrictions</a> are added by an application via the broadcast mechanism mentioned above. An application can query the <a href="http://developer.android.com/reference/android/os/UserManager.html">UserManager</a> only for its own and global user restrictions.<br /><br /><b>Detecting restricted profiles</b><br />One of the first things you might want to do in your app is to detect if the current user is using a restricted or a normal profile. There's no API method to do that and the video linked above suggests to query the user restrictions from the <a href="http://developer.android.com/reference/android/os/UserManager.html">UserManager</a> and if the returned bundle is not empty then you are in a restricted profile.<br /><br />This worked fine until we deployed the application to a phone running an Android M preview build. On this phone - that doesn't even support restricted profiles - the <a href="http://developer.android.com/reference/android/os/UserManager.html">UserManager</a> always returned a restriction. Whoops, suddenly everyone with Android M on their phones had a very limited <a href="https://nightly.mozilla.org/">Firefox Nightly</a>. We then switched to iterating over the returned Bundles (for application and user restrictions) and only assuming we are in a restricted profile if at least one restriction in those bundles is enabled (<i>getBoolean()</i> returns true).<br /><br />In general it is a better approach to never detect whether you are in a restricted profile or not but instead always check whether a specific (application) restriction is enabled or not.<b>&nbsp;</b><br /><br /><b>A resource qualifier would be nice</b><br />Hiding features and UI in restricted profiles will add a lot of <i>if</i> statements to the code base. It would have been nice to have a <a href="http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources">resource qualifier</a> for restricted profiles to load different layouts, drawables and other configurations. Besides that this would also solve the "detect restricted profile" problem quite elegant.<br /><br /><b>Strict mode: Disk read violation</b><br />At runtime we noticed that we have been triggering a lot of disk read violations. Looking at <a href="http://androidxref.com/5.1.1_r6/xref/frameworks/base/services/core/java/com/android/server/pm/UserManagerService.java#readApplicationRestrictionsLocked">Android's source code</a> it turns out that <a href="http://developer.android.com/reference/android/os/UserManager.html#getApplicationRestrictions%28java.lang.String%29">UserManager.getApplicationRestrictions()</a> reads and parses an XML file on every call. Without caching anything like <a href="http://developer.android.com/reference/android/content/SharedPreferences.html">SharedPreferences</a> do. We worked around that by implementing our own memory cache and refreshing the list of restrictions whenever the application is resumed. To update restrictions the user will always have to switch to the admin profile and therefore leave (and later resume) the application.<br /><br /><b>No Fun</b><br /><div class="separator" style="clear: both; text-align: left;">Android Marshmallow (6.0) introduced a new <i>Easter egg</i> system restriction: <a href="http://developer.android.com/reference/android/os/UserManager.html#DISALLOW_FUN">UserManager.DISALLOW_FUN</a> - <i>Specifies if the user is not allowed to have fun. In some cases, the device owner may wish to prevent the user from experiencing amusement or joy while using the device. The default value is false</i>.&nbsp;</div><div class="separator" style="clear: both; text-align: left;"><br /></div><h3>What's next?</h3><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-8hdHsE2sf6Q/Vfr6lwJChxI/AAAAAAAAmZA/lSpXgbzrKsQ/s1600/kidbrowser.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="http://3.bp.blogspot.com/-8hdHsE2sf6Q/Vfr6lwJChxI/AAAAAAAAmZA/lSpXgbzrKsQ/s640/kidbrowser.png" width="640" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Simplified browser UI with custom theme using a restricted profile (Firefox 42).</td></tr></tbody></table><br />With the current set of restrictions parents can create a kid-friendly and simplified browsing experience. Of course there are a lot of more possible features around parental controls that come to mind like block lists and restricting Web APIs (Microphone, Webcam). Some of these ideas have already been filed (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1125710">Bug 1125710</a>) and in addition to that we just started planning features for the next version (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1205615">Bug 1205615</a>). More ideas are definitely welcome!<br /><br /><h3>Testing and feedback</h3><br />At the time of this writing support for restricted profiles is available in <a href="https://ftp.mozilla.org/pub/mozilla.org/mobile/nightly/latest-mozilla-aurora-android-api-11/">Aurora</a> (42.0) and <a href="https://nightly.mozilla.org/">Nightly</a> (43.0) builds of Firefox. Restricted Profiles serve a very specific use case and therefore do not get as much usage coverage like other browser features. If you do have a tablet and are interested in restricted profiles then help us testing it! :)<br /><br /><h3>Contributing </h3><br />Firefox for Android is open-source software and contributors are very welcome!&nbsp;You can find me on IRC (irc.mozilla.org) in #mobile (my nickname is "sebastian"), on <a href="https://twitter.com/Anti_Hype">Twitter</a> and <a href="http://plus.google.com/+SebastianKaspari">Google+</a>. <a href="https://wiki.mozilla.org/Mobile/Get_Involved">Get involved with Firefox for Android</a>.<br /><br /><h3>More resources about Project <i>KidFox</i></h3><ul></ul><br /><ul><li><a href="https://wiki.mozilla.org/Mobile/Projects/Kinderfox">Mozilla Wiki: Project KinderFox</a> </li><li><a href="https://wiki.mozilla.org/Mobile/Projects/Kid_browsing">Mozilla Wiki: KidFox proposal</a></li><li><a href="https://wiki.mozilla.org/Mobile/Briefs/Kidfox">Mozilla wiki: KidFox brief</a></li><li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1125710">Generic meta bug </a></li><li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1125984">Bugzilla meta bug for v1</a></li><li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1205615">Bugzilla meta bug for v2</a></li></ul><ul></ul><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/xaSicfGuwOU" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com0http://www.androidzeitgeist.com/2015/09/support-restricted-profiles-firefox.htmltag:blogger.com,1999:blog-1531829516427013333.post-18339368837510202122014-11-20T08:30:00.001+01:002014-11-20T08:32:09.334+01:00Introducing Android Network Intents<a href="https://github.com/pocmo/Android-Network-Intents">Android Network Intents</a> is a library that I wrote for <a href="http://landsofruin.com/">Lands of Ruin</a> - a game that two friends and I are developing. To avoid a complicated network setup to play the game against a friend, we needed a way to discover games running on the local network. Android offers a <a href="http://developer.android.com/training/connect-devices-wirelessly/nsd.html">Network Service Discovery (NSD)</a> since API level 16 (Android 4.1) but we kept running into problems using it. This lead to writing this library.<br /><br /><span style="font-size: large;"><b>What does the library do?</b></span><br />The library allows you to send <a href="http://developer.android.com/reference/android/content/Intent.html">Intents</a> to listening clients on the local network (WiFi) without knowing who these clients are. Sender and receiver do not need to connect to each other. Therefore the library can be used to write custom discovery protocols.<br /><br /><span style="font-size: large;"><b>Sending Intents (Transmitter)</b></span><br />An <i>Intent</i> is sent by using the&nbsp;<i>Transmitter</i>&nbsp;class. A&nbsp;<i>TransmitterException</i>&nbsp;is thrown in case of error.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-r6N5E7HFdJc/VGyPPqvem4I/AAAAAAAAbn8/aJ_XtPS7lkU/s1600/Screen%2BShot%2B2014-11-19%2Bat%2B13.33.29.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-r6N5E7HFdJc/VGyPPqvem4I/AAAAAAAAbn8/aJ_XtPS7lkU/s1600/Screen%2BShot%2B2014-11-19%2Bat%2B13.33.29.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Network-Intents/wiki/Sending-Intents">Sending an Intent</a></td></tr></tbody></table><br /><span style="font-size: large;"><b>Receiving Intents (Receiver)</b></span><br />Intents are received using the&nbsp;<i>Discovery</i>&nbsp;class. Once started by calling&nbsp;<i>enable()</i>&nbsp;the&nbsp;<i>Discovery</i>&nbsp;class will spawn a background thread that will wait for incoming&nbsp;<i>Intent</i>&nbsp;objects. A&nbsp;<i>DiscoveryListener</i>&nbsp;instance will be notified about every incoming&nbsp;<i>Intent</i>.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-fNRqCrKBhbg/VGyPnT00VdI/AAAAAAAAboE/XnejMaKLuyw/s1600/Screen%2BShot%2B2014-11-19%2Bat%2B13.37.46.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-fNRqCrKBhbg/VGyPnT00VdI/AAAAAAAAboE/XnejMaKLuyw/s1600/Screen%2BShot%2B2014-11-19%2Bat%2B13.37.46.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Network-Intents/wiki/Receiving-Intents">Writing a DiscoveryListener to receive events.</a></td></tr></tbody></table><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-_GOcgSh-4qY/VGyPpC2sA-I/AAAAAAAAboM/TVMtxnj-zKk/s1600/Screen%2BShot%2B2014-11-19%2Bat%2B13.37.55.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-_GOcgSh-4qY/VGyPpC2sA-I/AAAAAAAAboM/TVMtxnj-zKk/s1600/Screen%2BShot%2B2014-11-19%2Bat%2B13.37.55.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Network-Intents/wiki/Receiving-Intents">Starting and stoping the discovery.</a></td></tr></tbody></table><br /><span style="font-size: large;"><b>Things you should know</b></span><br />The Intents are sent as <a href="http://en.wikipedia.org/wiki/Multicast">UDP multicast</a> packets. Unlike TCP the UDP protocol does not guarantee that a sent packet will be received and there is no confirmation or retry mechanism. Even though losing a packet only happens rarely in a stable WiFi, the library is not intended for using as a stable <i>communication</i> protocol. Instead you can use it to find other clients (by sending an Intent in a periodic interval) and then establish a stable TCP connection for communication.<br /><br />On GitHub you can find a <a href="https://github.com/pocmo/Android-Network-Intents/tree/master/samples">chat sample application</a> using the library. While this is a convenient example, it is not a good use of the library for the reasons state above. You obviously do not want to lose chat messages.<br /><br />We are using the library for almost two years in Lands of Ruin and didn't observe any problems. However the game only runs on tablets so far. In theory the library should run on all Android versions back to API level 3 (Android 1.5) but this has obviously never been tested.<br /><br />You can find <a href="https://github.com/pocmo/Android-Network-Intents">Android Network Intents on GitHub</a>.<img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/frg0Ba2z4H0" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com0http://www.androidzeitgeist.com/2014/11/introducing-android-network-intents17.htmltag:blogger.com,1999:blog-1531829516427013333.post-86540312464992561122013-12-24T15:24:00.001+01:002013-12-24T15:24:38.598+01:00Hello World Immersion - Developing for Google Glass #2This article describes how to create a simple hello world application for Google Glass using the&nbsp;Glass Development Kit (GDK). As described in the <a href="http://www.androidzeitgeist.com/2013/12/mirror-api-gdk-developing-google-glass.html">previous article</a> you have two options how your Glassware should show up on the device: As a <i>live card</i> that is part of the timeline or as an <i>immersion</i>&nbsp;that is displayed outside of the context of the timeline. This article focuses on how to write an immersion.<br /><b><span style="font-size: large;"><br /></span></b><b><span style="font-size: large;">What is an immersion?</span></b><br />An immersion is basically an Android activity. The name immersion implies that it is not part of the normal Glass timeline. Instead it takes full control of the device - except for the back gesture (Swipe down). To go back to the timeline you need to leave the immersion.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-75TfF3lNoWs/UrhgTb9OPZI/AAAAAAAASH4/wESuu-yTUy4/s1600/glass_timeline_immersion.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-75TfF3lNoWs/UrhgTb9OPZI/AAAAAAAASH4/wESuu-yTUy4/s1600/glass_timeline_immersion.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Once started an immersion takes full control of the screen.</td></tr></tbody></table><br /><b><span style="font-size: large;">Project setup</span></b><br />Create a normal Android project with the following settings:<br /><br /><ul><li>Set <i>minSdkVersion</i> and <i>targetSdkVersion</i> to 15 (Android 4.0.3)</li><li>Set <i>compileSdkVersion</i> to&nbsp;<i>"Google Inc.:Glass Development Kit Sneak Peek:15"</i></li><li>Do not assign a theme to your application or derive your own theme from&nbsp;<i>Theme.DeviceDefault</i></li></ul><div><i><br /></i></div><span style="font-size: large;"><b>Creating the immersion</b></span><br />Let's create a simple activity. The <a href="https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/app/Card">Card</a> class helps us to create a layout that looks like a timeline card.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-Fj2t5BJi7yk/Urlo4Z4_FYI/AAAAAAAASI0/4qv2fF4ElX8/s1600/helloworldactivity.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-Fj2t5BJi7yk/Urlo4Z4_FYI/AAAAAAAASI0/4qv2fF4ElX8/s1600/helloworldactivity.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Zeitgeist-Samples/blob/master/Glass/HelloWorldImmersion/HelloWorld/src/main/java/de/androidzeitgeist/glass/helloworld/immersion/HelloWorldActivity.java">HelloWorldActivity.java</a></td></tr></tbody></table><br /><b><span style="font-size: large;">Launching the Glassware - Voice commands</span></b><br />After creating the activity we need a way to start our Glassware. A common way to launch Glassware is to use a voice trigger. Let's add a simple voice trigger to start our <i>hello world</i> activity.<br /><br />First we need to declare a string resource for our voice command.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-MnJseZKHYxY/Url83ImZEZI/AAAAAAAASJc/Lrxu_J2gZ8w/s1600/resource_hello_world.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-MnJseZKHYxY/Url83ImZEZI/AAAAAAAASJc/Lrxu_J2gZ8w/s1600/resource_hello_world.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Zeitgeist-Samples/blob/master/Glass/HelloWorldImmersion/HelloWorld/src/main/res/values/strings.xml">strings.xml</a></td></tr></tbody></table><br />The next step is to create an XML resource file for the voice trigger using the previously created string value.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-8y21kaJD3fI/Url839921yI/AAAAAAAASJw/HUZ4Po3-lr4/s1600/trigger_hello_world.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://4.bp.blogspot.com/-8y21kaJD3fI/Url839921yI/AAAAAAAASJw/HUZ4Po3-lr4/s1600/trigger_hello_world.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Zeitgeist-Samples/blob/master/Glass/HelloWorldImmersion/HelloWorld/src/main/res/xml/voice_trigger.xml">voice_trigger.xml</a></td></tr></tbody></table><br />Now we can add an intent filter for the VOICE_TRIGGER action to our activity. A meta-data tag links it to the XML file we wrote above.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-GfHAXMZTDas/Url83illC8I/AAAAAAAASJs/oBmo7h4_Tuk/s1600/hello_world_activity.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-GfHAXMZTDas/Url83illC8I/AAAAAAAASJs/oBmo7h4_Tuk/s1600/hello_world_activity.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Zeitgeist-Samples/blob/master/Glass/HelloWorldImmersion/HelloWorld/src/main/AndroidManifest.xml">AndroidManifest.xml</a></td></tr></tbody></table><br />The developer guide requires you to add an icon for the touch menu to the activity (white in color on transparent background, 50x50 pixels). The&nbsp;<a href="http://glass-asset-utils.appspot.com/icons-submission.html">Glass Asset Studio</a>&nbsp;is a helpful tool to generate these icons.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-MWCSEYXWpUQ/UrmYIdPJp6I/AAAAAAAASKE/h2c7egiWuNs/s1600/50x50_icon.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-MWCSEYXWpUQ/UrmYIdPJp6I/AAAAAAAASKE/h2c7egiWuNs/s1600/50x50_icon.png" /></a></div><br /><span style="font-size: large;"><b>The final Glassware</b></span><br />Now we can start our Glassware by saying "<i>ok glass, show hello world</i>":<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-R3N3nwLXIIg/UrlsMbHPgkI/AAAAAAAASJA/9P6foH55OUc/s1600/hello_world_glassware.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="340" src="http://4.bp.blogspot.com/-R3N3nwLXIIg/UrlsMbHPgkI/AAAAAAAASJA/9P6foH55OUc/s400/hello_world_glassware.png" width="400" /></a></div><br />Another option to start our Glassware is to use the touch menu and scroll to the "<i>show hello world</i>" command:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-5KjJBjb5qn4/UrlupI3MTuI/AAAAAAAASJM/j6-nNCKgWJM/s1600/hello_world_glassware_menu.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="340" src="http://2.bp.blogspot.com/-5KjJBjb5qn4/UrlupI3MTuI/AAAAAAAASJM/j6-nNCKgWJM/s400/hello_world_glassware_menu.png" width="400" /></a></div><br />The source code for this <a href="https://github.com/pocmo/Android-Zeitgeist-Samples/tree/master/Glass/HelloWorldImmersion">Hello World Glassware is available on GitHub</a>.<img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/fr-WO1v1SIU" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com0http://www.androidzeitgeist.com/2013/12/google-glass-immersion-hello-world.htmltag:blogger.com,1999:blog-1531829516427013333.post-56055365831116637352013-12-22T13:03:00.001+01:002013-12-22T13:03:25.308+01:00Android 2013<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-swoL-7rAksk/UrbIgrRXS0I/AAAAAAAASEk/FuB-KSnuxuU/s1600/android_2013.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://4.bp.blogspot.com/-swoL-7rAksk/UrbIgrRXS0I/AAAAAAAASEk/FuB-KSnuxuU/s1600/android_2013.png" /></a></div><br />It's the end of the year - <a href="http://www.youtube.com/watch?v=H7jtC8vjXw8">YouTube</a> and <a href="http://www.youtube.com/watch?v=Lv-sY_z8MNs">Google Zeitgeist</a> have posted their reviews. Let's have a look on what happened in the Android world in 2013.<br /><br /><br /><a href="http://4.bp.blogspot.com/-S2ecXdl66_I/UrbQgaKZPxI/AAAAAAAASFE/qChEPdoly-w/s1600/nexus4.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="200" src="http://4.bp.blogspot.com/-S2ecXdl66_I/UrbQgaKZPxI/AAAAAAAASFE/qChEPdoly-w/s200/nexus4.png" width="200" /></a><span style="font-size: large;"><b>January</b></span><br />2012 is over and the Nexus 4 is the current flagship phone made by Google and LG.<br /><br /><span style="font-size: large;"><b>February</b></span><br /><a href="http://android-developers.blogspot.de/2013/02/google-sign-in-now-part-of-google-play.html">Google+ Sign-In is integrated</a> into the Google Play Services and Google starts accepting <a href="http://www.nytimes.com/2013/02/21/technology/google-looks-to-make-its-computer-glasses-stylish.html?_r=0">applications for the Google Glass Explorer program</a>.<br /><span style="font-size: large;"><b><br /></b></span><span style="font-size: large;"><b>March</b></span><br />The new <a href="http://android-developers.blogspot.de/2013/03/now-is-time-to-switch-to-new-google.html">Android developer console is out of preview</a>. While <a href="http://officialandroid.blogspot.de/2013/03/celebrating-google-plays-first-birthday.html">Google Play celebrates it first birthday</a>, the <a href="http://techcrunch.com/2013/07/01/android-led-by-samsung-continues-to-storm-the-smartphone-market-pushing-a-global-70-market-share/?ncid=tcdaily">market share of Android hits 64%</a>.<br /><br /><span style="font-size: large;"><b>April</b></span><br />The <a href="http://android-developers.blogspot.de/2013/04/update-on-tablet-app-guidelines-and.html">tablet guidelines are updated</a> and the Android developer console starts to <a href="http://android-developers.blogspot.de/2013_04_01_archive.html">show tablet optimization tips</a>. Google pushes a <a href="http://android-developers.blogspot.de/2013/04/new-look-new-purchase-flow-in-google.html">Google Play app update</a> that features a redesigned UI. Samsung releases it new flaship phone - <a href="http://en.wikipedia.org/wiki/Samsung_Galaxy_S4">the Samsung Galaxy S4</a>.<br /><span style="font-size: large;"><b><br /></b></span><span style="font-size: large;"><b>May</b></span><br /><a href="http://3.bp.blogspot.com/-wZeaMyx7VUs/UrbPAzv69mI/AAAAAAAASE4/-VEbnrV9MF4/s1600/io2013.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="http://3.bp.blogspot.com/-wZeaMyx7VUs/UrbPAzv69mI/AAAAAAAASE4/-VEbnrV9MF4/s1600/io2013.png" /></a>The <a href="https://developers.google.com/events/io/">Google I/O</a>&nbsp;takes place for three days from May 15th to 17th. This time there won't be a new Android release. Instead Google releases <a href="http://android-developers.blogspot.de/2013/05/social-gaming-location-and-more-in.html">new game services and a new location API</a>. At the Google I/O a new IDE for Android development is introduced: <a href="http://android-developers.blogspot.de/2013/05/android-studio-ide-built-for-android.html">Android Studio</a>. Since then every couple of weeks a new Android Studio update is pushed to the developer community.<br /><br /><br /><span style="font-size: large;"><b><br /></b></span> <span style="font-size: large;"><b>July</b></span><br />A new flavor of Android Jelly Bean is released: <a href="http://android-developers.blogspot.de/2013/07/android-43-and-updated-developer-tools.html">Android 4.3</a>. Open GL ES 3.0 and support for&nbsp;low-power Bluetooth Smart devices are some of the new features. Furthermore a new version of the Nexus 7 is released. Together with the new tablet Google <a href="http://officialandroid.blogspot.de/2013/07/from-tvs-to-tablets-everything-you-love.html">releases the Chromecast dongle</a> and the <a href="http://googledevelopers.blogspot.de/2013/07/cast-content-from-your-apps-to-tv-with.html">Google Cast SDK preview</a>.<br /><span style="font-size: large;"><b><br /></b></span><span style="font-size: large;"><b>August</b></span><br />Google releases <a href="http://android-developers.blogspot.de/2013/08/google-play-services-32.html">version 3.2 of the Google Play Services</a>. The update&nbsp;includes several enhancements to the Location Based Services. With the r18 release of the support library Google&nbsp;released a new backward-compatible <a href="http://android-developers.blogspot.de/2013/08/actionbarcompat-and-io-2013-app-source.html">Action Bar implementation called ActionBarCompat</a>. Motorola is releasing the <a href="http://en.wikipedia.org/wiki/Moto_X">Moto X</a> - its first phone since the company has been acquired by Google. The same month <a href="https://plus.google.com/u/0/+HugoBarra/posts/BzZMqRht1xQ">Hugo Barra announces to leave Google</a> after 5½ years to join the Xiaomi team in China.<br /><span style="font-size: large;"><b><br /></b></span><span style="font-size: large;"><b>September</b></span><br /><a href="http://android-developers.blogspot.de/2013/09/renderscript-in-android-support-library.html">RenderScript is now part of the support library</a> and can be used&nbsp;on plaform versions all the way back to Android 2.2 (Froyo). Jean-Baptiste Queru, who worked on the Android Open Source Project at Google, <a href="http://www.androidpolice.com/2013/09/17/jean-baptiste-queru-now-at-yahoo-as-senior-principal-engineer-working-on-mobile-apps/">starts a new job at Yahoo</a>. Google launches the <a href="http://officialandroid.blogspot.de/2013/08/find-your-lost-phone-with-android.html">Android device manager website</a> to&nbsp;locate, lock and ring misplaced devices.<br /><br /> <a href="http://1.bp.blogspot.com/-qksojJjcafk/UrbQ_JNFI_I/AAAAAAAASFM/mOaNvKPz2d0/s1600/nexus5.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="200" src="http://1.bp.blogspot.com/-qksojJjcafk/UrbQ_JNFI_I/AAAAAAAASFM/mOaNvKPz2d0/s200/nexus5.png" width="200" /></a><span style="font-size: large;"><b>October</b></span><br />After a lot of leaks and rumors <a href="https://www.google.com/nexus/5/">a new Nexus phone is released</a> on Halloween. Together with the Nexus 5 a new Android version - <a href="http://www.android.com/kitkat/">Android 4.4 KitKat</a> - is published.&nbsp;Full-screen immersive mode, a new transitions framework, a printing framework and a storage access framework are some of the many new features. In addition to that he <a href="http://android-developers.blogspot.de/2013/10/google-play-services-40.html">Google Play Services are updated to version 4.0</a>. With <a href="https://plus.google.com/+RomainGuy/posts/faCzPs6GKtg">Romain Guy another popular Android team member is leaving</a> - but remaining at Google.<br /><span style="font-size: large;"><b><br /></b></span><span style="font-size: large;"><b>November</b></span><br />The <a href="http://android-developers.blogspot.de/2013/11/app-translation-service-now-available.html">App Translation Service</a>, announced at Google I/O, is now available for every developer. Motorola releases a second phone - the <a href="http://en.wikipedia.org/wiki/Moto_G">Moto G</a>. Android hits a new record with <a href="http://www.highlightpress.com/android-tops-80-global-smartphone-market-share-windows-phone-up-156-year-on-year/6708/tharper">80% market share</a>. The Google Glass team releases a first sneak peek version of the <a href="https://developers.google.com/glass/develop/gdk/">Glass development kit (GDK)</a>.<br /><span style="font-size: large;"><b><br /></b></span><span style="font-size: large;"><b>December</b></span><br />Two small updates for Android KitKat are released: <a href="http://en.wikipedia.org/wiki/Android_version_history#Android_4.4_KitKat_.28API_level_19.29">Android 4.4.1 and 4.4.2</a>. The Android device manager <a href="http://techcrunch.com/2013/12/11/google-android-device-manager-play-store/">is now available as an app</a>.<br /><br />The <i>Android Design in Action</i> team releases its 2013 Recap:<br /><br /><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/ajO2zFEtEYs" width="560"></iframe></div><br /><br /><b><span style="font-size: large;">2014?</span></b><br />What has been your Android highlight in 2013 and what are your wishes for 2014?<img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/f-NE_F-73GY" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com0http://www.androidzeitgeist.com/2013/12/android-2013.htmltag:blogger.com,1999:blog-1531829516427013333.post-31392841734804830992013-12-16T21:21:00.004+01:002013-12-16T21:21:56.392+01:00Mirror API and GDK - Developing for Google Glass #1I recently got my hands on<a href="http://www.google.com/glass/start/"> Google Glass</a> and decided to write some articles about developing applications for Glass. After all it's Android that is running on Glass.<br /><br /><span style="font-size: large;"><b>What is Glass?</b></span><br />It's very complicated to explain Google Glass just using text. Only wearing and using it will give you this aha moment. However the following video, made by Google, gives you a good impression about how it feels like.<br /><br /><div class="separator" style="clear: both; text-align: center;"><iframe allowfullscreen="" frameborder="0" height="315" src="//www.youtube.com/embed/v1uyQZNg2vE" width="560"></iframe></div><br /><span style="font-size: large;"><b>What is Glass from a developer's point of view?</b></span><br />Google Glass is an Android device running Android 4.0.3. What you see through Glass is basically a customized <i>Launcher</i> / <i>Home screen</i> application (a timeline of cards about current and past events) and a slightly different theme. This makes it really interesting for Android developers to develop for Glass: You can use almost all the familiar Android framework APIs. However wearing Glass feels totally different than using a mobile phone. So there's a big difference in designing applications. But not only the UI is different: You can't just port an existing application to Glass. Use cases have to be designed especially for Glass. Some features of your app might not make sense on Glass. Some other interesting features might only be possible on Glass. It's almost impossible to get a feeling for that without using Glass for some days.<br /><div><br /></div><div>Back to writing code.. Currently we can decide between two ways to develop for Glass: The Mirror API or an early preview of the Glass Development Kit (GDK). Let's have a look at both and see what they are capable of.</div><div><br /></div><div><b><span style="font-size: large;">The Mirror API</span></b></div><div><div>The Mirror API has been the first API that has been introduced by the Glass team. It's a server-side API meaning the applications don't run on Glass itself but on your server and it's your server that interacts with Glass.</div><div><br /></div><div>The Mirror API is great for pushing cards to the timeline of Glass and sharing content from Glass with your server application.</div><div><br /></div><div>Some examples of applications that could use the Mirror API:</div></div><div><ul><li><b>Twitter client</b>: The server pushes interesting tweets to the timeline of the Glass owner. The user can share photos and messages with the application and they will be posted to the Twitter timeline.</li><li><b>Context-aware notifications</b>: Your server subscribes to the user's location. Every now and then your server will receive the latest user location. You use this location to post interesting and related cards to the timeline of the user.</li></ul><div><b><br /></b><b>More about the Mirror API</b>:</div></div><div><ul><li><a href="https://developers.google.com/glass/develop/mirror/quickstart/">Google Developers: Mirror API Quick Start</a></li><li><a href="http://www.youtube.com/watch?v=CxB1DuwGRqk">YouTube: Google I/O 2013 - Building Glass Services with the Google Mirror API</a></li></ul><div><span style="font-size: large;"><b><br /></b></span><span style="font-size: large;"><b>The Glass Development Kit (GDK)</b></span></div></div><div>With the GDK you can build Android applications that run directly on Glass. Think of the GDK as Android 4.0.3 SDK with some extra APIs for Google Glass. It's worth mentioning that the GDK is currently in an early preview state. The API is not complete and some important parts are missing.</div><div><br /></div><div>When developing Glass you have two options how your application should show up on Glass:</div><div><br /></div><div><b>Live Cards</b><br /><b><br /></b><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-wpH3qxEjT_Y/Uq9XLpCVIJI/AAAAAAAAR4A/my3NMMsA1SQ/s1600/glass_timeline_livecard.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-wpH3qxEjT_Y/Uq9XLpCVIJI/AAAAAAAAR4A/my3NMMsA1SQ/s1600/glass_timeline_livecard.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">How a live card shows up in the Glass timeline.</td></tr></tbody></table><br />Your application shows up as a card in the timeline (left of the Glass clock). You have again two options how to render these cards:</div><div><ul><li><b>Low-Frequency Rendering</b>: Your card is rendered using <a href="https://developer.android.com/reference/android/widget/RemoteViews.html">Remote Views</a>. Think of it as a Home screen widget on Android phones. A background service is responsible for updating these views. You only update the views every now and then.</li><li><b>High Frequency Rendering</b>: Your background service renders directly on the live card's surface. You can draw anything and are not limited to Android views. Furthermore you can update the card many times a second.</li></ul><div><b>Immersion</b><br /><b><br /></b><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-9Wv_J7QV5AM/Uq9XdQLAvuI/AAAAAAAAR4I/AwZ0p8RzYPM/s1600/glass_timeline_immersion.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-9Wv_J7QV5AM/Uq9XdQLAvuI/AAAAAAAAR4I/AwZ0p8RzYPM/s1600/glass_timeline_immersion.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">An Immersion is not part of the timeline but "replaces" it.</td></tr></tbody></table><b><br /></b><b><br /></b></div></div><div><div>An immersion is at the bottom a regular Android activity. For your activity to look like a timeline card:</div></div><div><ul><li>Don't assign a theme to your activity or use the DeviceDefault theme as base for your customization.</li><li>Even though you can use the touch pad of Glass almost like a d-pad: Try to avoid most input-related Android widgets. They don't make much sense on Glass because you are not using a touch screen. Instead try to use gestures with the <a href="https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/touchpad/GestureDetector">GestureDetector</a>&nbsp;class or <a href="https://developers.google.com/glass/develop/gdk/input/voice">voice input</a>.</li><li>Use the <a href="https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/app/Card">Card class</a> and its <a href="https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/app/Card#toView()">toView()</a> method to create a view that looks like regular Glass card.</li></ul><div><b><br /></b><b>More about the GDK</b></div></div><div><ul><li><a href="https://developers.google.com/glass/develop/gdk/quick-start">Google Developers: GDK Quick Start</a></li><li><a href="https://www.youtube.com/watch?v=oZSLKtpgQkc">YouTube: Glass Development Kit Sneak Peek</a></li></ul></div><div><br /></div><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/JXGHhmdRusw" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com0http://www.androidzeitgeist.com/2013/12/mirror-api-gdk-developing-google-glass.htmltag:blogger.com,1999:blog-1531829516427013333.post-30961758642896545122013-08-22T12:43:00.002+02:002013-08-22T12:43:53.597+02:00Read the code: IntentService<span style="font-size: x-small;">In the new category <b>Read the code</b> I’m going to show the internals of the Android framework. Reading the code of the framework can give you a good impression about what’s going on under the hood. In addition to that knowing how the framework developers solved common problems can help you to find the best solutions when facing problems in your own app code.</span><br /><br /><span style="font-size: large;"><b>What is the IntentService class good for?</b></span><br />This article is about the <a href="https://developer.android.com/reference/android/app/IntentService.html">IntentService</a> class of Android. Extending the IntentService class is the best solution for implementing a background service that is going to process something in a queue-like fashion. You can pass data via <a href="https://developer.android.com/reference/android/content/Intent.html">Intents</a> to the IntentService and it will take care of queuing and processing the Intents on a worker thread one at a time. When writing your IntentService implementation you are required to override the <a href="https://developer.android.com/reference/android/app/IntentService.html#onHandleIntent(android.content.Intent)">onHandleIntent()</a> method to process the data of the supplied Intents.<br /><br />Let’s take a look at a simple example: This DownloadService class receives Uris to download data from. It will download only one thing at a time with the other requests waiting in a queue.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-VJ13VmPcpx4/UhXgpEhsitI/AAAAAAAANSk/ZLzJYR-7ypE/s1600/DownloadService.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-VJ13VmPcpx4/UhXgpEhsitI/AAAAAAAANSk/ZLzJYR-7ypE/s1600/DownloadService.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Zeitgeist-Samples/blob/master/IntentService/DownloadService.java">DownloadService</a></td></tr></tbody></table><br /><br /><b><span style="font-size: large;">The components</span></b><br />Before we dip into the source code of the IntentService class, let's first take a look at the different components that we need to know in order to understand the source code.<br /><br /><b>Handler</b>&nbsp;(<a href="https://developer.android.com/reference/android/os/Handler.html">documentation</a>) (<a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/os/Handler.java">source code</a>)<br />You may already have used Handler objects. When a Handler is created on the UI thread, messages can be posted to it and these messages will be processed on the UI thread.<br /><br /><b>ServiceHandler</b>&nbsp;(<a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/app/IntentService.java#58">source code</a>)<br />The ServiceHandler inner-class is a helper class extending the Handler class to delegate the Intent wrapped inside a Message object to the IntentService for processing.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/--OVWzXz_dlQ/UhXZNL7nZII/AAAAAAAANR0/3pWwyp_Iw3g/s1600/ServiceHandler.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/--OVWzXz_dlQ/UhXZNL7nZII/AAAAAAAANR0/3pWwyp_Iw3g/s1600/ServiceHandler.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/app/IntentService.java#58">ServiceHandler inner class of&nbsp;android.app.IntentService</a></td></tr></tbody></table><br /><b>Looper</b>&nbsp;(<a href="https://developer.android.com/reference/android/os/Looper.html">documentation</a>) (<a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/os/Looper.java#Looper">source code</a>)<br />The Looper class has a MessageQueue object attached to it and blocks the current thread until a Message is received. This message will be passed to the assigned Handler. After that the Looper processes the next message in the queue or blocks again until a message is received.<br /><br /><b>HandlerThread</b>&nbsp;(<a href="https://developer.android.com/reference/android/os/HandlerThread.html">documentation</a>) (<a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/os/HandlerThread.java#HandlerThread">source code</a>)<br />A HandlerThread is a Thread implementation that does all the Looper setup for you. By creating and starting a HandlerThread instance you will have a running thread with a Looper attached to it waiting for messages to process.<br /><br /><span style="font-size: large;"><b>Read the code!</b></span><br /><br />Now we know enough about all the components to understand the <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/app/IntentService.java">IntentService code</a>.<br /><br /><b>onCreate()</b><br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-YHAG_7OKKhI/UhXazQgkmkI/AAAAAAAANSA/57KqOScdP9k/s1600/IntentService_oncreate.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://4.bp.blogspot.com/-YHAG_7OKKhI/UhXazQgkmkI/AAAAAAAANSA/57KqOScdP9k/s1600/IntentService_oncreate.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/app/IntentService.java#101">IntentService.onCreate()</a></td></tr></tbody></table><br />At first a HandlerThread is created and started. We now have a background thread running that already has a Looper assigned. This Looper is waiting on the background thread for messages to process.<br /><br />Next a ServiceHandler is created for this Looper. The Handler’s <a href="https://developer.android.com/reference/android/os/Handler.html#handleMessage(android.os.Message)">handleMessage</a>() method will be called for every message received by the Looper. The ServiceHandler obtains the Intent object from the Message and passes it to the onHandleIntent() method of the IntentService.<br /><br /><b>onStart()</b><br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-C91WSSI62cw/UhXbfPQsAJI/AAAAAAAANSI/k5Hyb0QB9qI/s1600/IntentService_onstart.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-C91WSSI62cw/UhXbfPQsAJI/AAAAAAAANSI/k5Hyb0QB9qI/s1600/IntentService_onstart.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/app/IntentService.java#115">IntentService.onStart()</a></td></tr></tbody></table><br />The onStart() method is called every time <a href="https://developer.android.com/reference/android/content/Context.html#startService(android.content.Intent)">startService()</a> is called. We wrap the Intent in a Message object and post it to the Handler. The Handler will enqueue it in the message queue of the Looper. The onStart() method is deprecated since API level 5 (Android 2.0). Instead onStartCommand() should be implemented.<br /><br /><b>onStartCommand()</b><br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-HB0fPJbsY8A/UhXcBOrAYAI/AAAAAAAANSQ/pfU3UUXUmE8/s1600/IntentService_onstartcommand.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-HB0fPJbsY8A/UhXcBOrAYAI/AAAAAAAANSQ/pfU3UUXUmE8/s1600/IntentService_onstartcommand.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/app/IntentService.java#129">IntentService.onStartCommand()</a></td></tr></tbody></table>In onStartCommand() we call onStart() to enqueue the Intent. We return <a href="https://developer.android.com/reference/android/app/Service.html#START_REDELIVER_INTENT">START_REDELIVER_INTENT</a> or <a href="https://developer.android.com/reference/android/app/Service.html#START_NOT_STICKY">START_NOT_STICK</a> depending on what the child class has set via&nbsp;<a href="https://developer.android.com/reference/android/app/IntentService.html#setIntentRedelivery(boolean)">setIntentRedelivery()</a>. Depending on this setting an Intent will be redelivered to the service if the process dies before onHandleIntent() returns or the Intent will die as well.<br /><br /><b>onDestroy()</b><br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-GkK4xWmOWu0/UhXcmqOLkQI/AAAAAAAANSY/M8oZn2GF5FY/s1600/IntentService_ondestroy.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-GkK4xWmOWu0/UhXcmqOLkQI/AAAAAAAANSY/M8oZn2GF5FY/s1600/IntentService_ondestroy.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/app/IntentService.java#134">IntentService.onDestroy()</a></td></tr></tbody></table>In onDestroy() we just need to stop the Looper.<br /><br /><span style="font-size: large;"><b>Conclusion</b></span><br /><br />The IntentService code is quite short and simple, yet a powerful pattern. With the <a href="https://developer.android.com/reference/android/os/Handler.html">Handler</a>, <a href="https://developer.android.com/reference/android/os/Looper.html">Looper</a> and <a href="https://developer.android.com/reference/java/lang/Thread.html">Thread</a> class you can easily build your own simple processing queues.<br /><br />Oh, and if you are looking for an exercise. The code of the onCreate() method contains a TODO comment that I omitted above:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-QlS7sJHfj1I/UhXp96c9r_I/AAAAAAAANS0/iRXyCb9E7NI/s1600/oncreate_todo.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://4.bp.blogspot.com/-QlS7sJHfj1I/UhXp96c9r_I/AAAAAAAANS0/iRXyCb9E7NI/s1600/oncreate_todo.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.3_r2.1/android/app/IntentService.java#101">TODO in onCreate()</a></td></tr></tbody></table><br /><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/ohV1Ybma6A4" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com0http://www.androidzeitgeist.com/2013/08/read-code-intentservice.htmltag:blogger.com,1999:blog-1531829516427013333.post-50503744328427817632013-05-27T19:31:00.001+02:002013-05-27T19:31:31.801+02:00Sharing the taken picture - Instant Mustache #9<div><span style="font-size: x-small;">This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection.&nbsp;<a href="http://www.androidzeitgeist.com/p/instant-mustache.html">Click here</a>&nbsp;to get a chronological list of all published&nbsp;<a href="http://www.androidzeitgeist.com/p/instant-mustache.html">articles about Instant Mustache</a>.</span></div><br /><a href="http://www.androidzeitgeist.com/p/instant-mustache.html">Up to now</a> our app can take and view pictures. The next step is to share the taken picture with other Android apps. This is done via <a href="https://developer.android.com/guide/components/intents-filters.html">Intents</a>. The Intent system is one of the most powerful features of Android. It allows us to interact with any app that accepts images with almost no extra afford.<br /><br />We could create an <a href="https://developer.android.com/guide/topics/ui/actionbar.html">ActionBar</a> item and when clicked launch an <a href="https://developer.android.com/reference/android/content/Intent.html">Intent</a>&nbsp;to share the image but instead we are going to use a <a href="http://developer.android.com/training/sharing/shareaction.html">ShareActionProvider</a>. The ShareActionProvider adds a share icon to the ActionBar as well as the icon of the app that the user has shared pictures the most with. By clicking this icon the user can share directly with this app. In addition to that the ShareActionProvider shows a sub menu with more apps that the given picture can be shared with.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-pDiZ5iw7DMw/UaOT6GqMHuI/AAAAAAAALjk/oLbP5J6_nok/s1600/shareactionprovider.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-pDiZ5iw7DMw/UaOT6GqMHuI/AAAAAAAALjk/oLbP5J6_nok/s1600/shareactionprovider.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">A ShareActionProvider with Google+ as default share action.</td></tr></tbody></table><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-L_-glPQZGF8/UaOXqTIYImI/AAAAAAAALkE/ofFypChT2Ew/s1600/shareactionprovider_menu.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="285" src="http://4.bp.blogspot.com/-L_-glPQZGF8/UaOXqTIYImI/AAAAAAAALkE/ofFypChT2Ew/s320/shareactionprovider_menu.png" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Sub menu of a ShareActionProvider.</td></tr></tbody></table><br /><b>If sharing is a key feature of your activity, you should consider using the ShareActionProvider.</b><br /><br />We start by creating an XML menu file for adding the share action. For legacy reasons the ActionBar uses the same approach for creating action items as the menu in Android 2.x.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-KWMveO6nNuo/UaOTQWFlM1I/AAAAAAAALjc/OXqcUuxPmhg/s1600/activity_photo_menu.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-KWMveO6nNuo/UaOTQWFlM1I/AAAAAAAALjc/OXqcUuxPmhg/s1600/activity_photo_menu.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-09/res/menu/activity_photo.xml">activity_photo.xml</a></td></tr></tbody></table><br />Once we inflated the menu in <a href="https://developer.android.com/reference/android/app/Activity.html#onCreateOptionsMenu(android.view.Menu)">onCreateOptionsMenu()</a> we need to set the Intent used to share the photo.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-0eTGVnhBo_0/UaOVjb4aX-I/AAAAAAAALj0/mXc2KKjxi0k/s1600/initialize_share_action.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-0eTGVnhBo_0/UaOVjb4aX-I/AAAAAAAALj0/mXc2KKjxi0k/s1600/initialize_share_action.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-09/src/com/androidzeitgeist/mustache/activity/PhotoActivity.java#L45">PhotoActivity.initializeShareAction()</a></td></tr></tbody></table><br />Let's take a look at the different components of the Intent:<br /><ul><li><b>ACTION_SEND</b>: The default action used for “sending” data to an other unspecified activity.</li><li><b>MIME</b> type: The MIME type of the data being sent. Other apps can define multiple MIME types they accept. We are sending a JPEG image and therefore we are using the MIME type “image/jpeg”. To learn more about MIME types start with the <a href="https://en.wikipedia.org/wiki/Internet_media_type">"Internet media type" Wikipedia article</a>.</li><li><b>EXTRA_STREAM</b>: <a href="https://developer.android.com/reference/android/net/Uri.html">Uri</a> that points to the data that should be sent. In our case the Uri is pointing to the image file on the external storage.</li></ul><div><br />That's it already. For all changes done to the code base, see the <a href="https://github.com/pocmo/Instant-Mustache/commit/4bded2002dfd56f63245d59e07a44e71deb04172">repository on GitHub</a>. In the next article we'll polish some aspects of the app before we start implementing the Face detection feature.</div><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/APLuQCN5xxA" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com0http://www.androidzeitgeist.com/2013/05/sharing-taken-picture-instant-mustache-9.htmltag:blogger.com,1999:blog-1531829516427013333.post-83536581659699564412013-01-14T20:47:00.000+01:002013-01-14T20:47:04.700+01:00Fixing the rotation - Instant Mustache #8<div><span style="font-size: x-small;">This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection.&nbsp;<a href="http://www.androidzeitgeist.com/p/instant-mustache.html">Click here</a>&nbsp;to get a chronological list of all published&nbsp;<a href="http://www.androidzeitgeist.com/p/instant-mustache.html">articles about Instant Mustache</a>.</span></div><div></div><br /><b><span style="font-size: large;">Wrong orientation</span></b><br /><br />If you run the current version of Instant Mustache and take some pictures you'll notice something odd: The orientation of the taken pictures is sometimes wrong. This may depend on the device you are using. When using a Galaxy Nexus the picture will be rotated 90° to the left when taking a picture in portrait mode but will be rotated correctly when taking a picture in landscape mode.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-RDkIH8Iw8VY/UPRZTnyZA2I/AAAAAAAAH0Q/BU7sRAlQQOw/s1600/rotation_error.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="239" src="http://1.bp.blogspot.com/-RDkIH8Iw8VY/UPRZTnyZA2I/AAAAAAAAH0Q/BU7sRAlQQOw/s320/rotation_error.png" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Wrong orientation of photo that has been taken in portrait mode</td></tr></tbody></table><br />How does this happen? You may remember that we've used <a href="https://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)">Camera.setDisplayOrientation()</a> in one of the <a href="http://www.androidzeitgeist.com/2012/10/displaying-camera-preview-instant.html">previous articles</a> to explicitly set the display rotation. First, this setting only affects the preview picture. The picture passed to the <a href="https://developer.android.com/reference/android/hardware/Camera.ShutterCallback.html">Camera.ShutterCallback</a> isn't affected by this setting. And second, we still have to account into how the device is rotated in the moment of taking the picture.<br /><br /><b><span style="font-size: large;">Detecting and remembering the orientation</span></b><br /><br />What we need to do in our code is to register an <a href="https://developer.android.com/reference/android/view/OrientationEventListener.html">OrientationEventListener</a> to get notified whenever the orientation changes. We'll remember this orientation and use this to rotate the taken image once the callback returns.<br /><br />Whenever the orientation changes <a href="https://developer.android.com/reference/android/view/OrientationEventListener.html#onOrientationChanged(int)">onOrientationChanged(int)</a> of the listener will be called. The orientation will be passed to the method in degrees, ranging from 0 to 359. We need to normalize this value as we are only interested in 90° steps for rotating the picture.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-JQ2Rm-uZ0gQ/UPRahx8kf2I/AAAAAAAAH0c/v7NIwzqReBM/s1600/cameraorientationlistener_normalize.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-JQ2Rm-uZ0gQ/UPRahx8kf2I/AAAAAAAAH0c/v7NIwzqReBM/s1600/cameraorientationlistener_normalize.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-08/src/com/androidzeitgeist/mustache/listener/CameraOrientationListener.java#L31">CameraOrientationListener.normalize()</a></td></tr></tbody></table>Another method called <a href="https://github.com/pocmo/Instant-Mustache/blob/article-08/src/com/androidzeitgeist/mustache/listener/CameraOrientationListener.java#L51">rememberOrientation()</a> will be used to save the orientation of the device in the moment of the user pressing the shutter button.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-rqdv0tzl52Y/UPRbbrb1vBI/AAAAAAAAH00/2Ldj2OrPXBM/s1600/camerafragment_takepicture.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-rqdv0tzl52Y/UPRbbrb1vBI/AAAAAAAAH00/2Ldj2OrPXBM/s1600/camerafragment_takepicture.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-08/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java#L231">CameraFragment.takePicture()</a></td></tr></tbody></table><span style="font-size: large;"><b><br /></b></span><span style="font-size: large;"><b>Rotating the picture</b></span><br /><br />Now we just need to rotate the Bitmap. We do this by creating a new Bitmap object and applying a rotated <a href="http://developer.android.com/reference/android/graphics/Matrix.html">Matrix</a> to the pixels. The rotation angle is calculated by summing the remembered orientation, the display orientation and the natural rotation of the device.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-Kp9GQ7CSHik/UPRcKSjRiBI/AAAAAAAAH1I/cTRdA_NYgjI/s1600/camerafragment_onpicturetaken.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-Kp9GQ7CSHik/UPRcKSjRiBI/AAAAAAAAH1I/cTRdA_NYgjI/s1600/camerafragment_onpicturetaken.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-08/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java#L241">CameraFragment.onPictureTaken()</a></td></tr></tbody></table><br /><span style="font-size: large;"><b>Result</b></span><br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-3lBP-pDo5cQ/UPRd8jZp-LI/AAAAAAAAH14/kJaLh3-Mdak/s1600/result_rotation.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="242" src="http://3.bp.blogspot.com/-3lBP-pDo5cQ/UPRd8jZp-LI/AAAAAAAAH14/kJaLh3-Mdak/s320/result_rotation.png" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Photos rotated correctly in portrait and landscape mode</td></tr></tbody></table><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/17oriJk6I8w" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com1http://www.androidzeitgeist.com/2013/01/fixing-rotation-camera-picture.htmltag:blogger.com,1999:blog-1531829516427013333.post-15980312326138766372012-12-22T14:21:00.000+01:002012-12-22T14:27:19.476+01:00Android 2012<div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-dKfHvBySVQk/UNWsnfVSK6I/AAAAAAAAHR8/FYWEUfw0yeU/s1600/android2012.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-dKfHvBySVQk/UNWsnfVSK6I/AAAAAAAAHR8/FYWEUfw0yeU/s1600/android2012.png" /></a></div><br />After <a href="http://www.youtube.com/watch?v=xY_MUB8adEQ">Google Zeitgeist</a> and&nbsp;<a href="http://www.youtube.com/watch?v=iCkYw3cRwLo">YouTube</a>&nbsp;looked back on 2012 it’s time to do the same for Android.<span id="goog_2128203782"></span><br /><br /><span style="font-size: large;"><b>January</b></span><br /><div><br /></div><a href="http://4.bp.blogspot.com/-4cV7er0VgPI/UNWw0GXYL5I/AAAAAAAAHSQ/nDFaspNqWns/s1600/androiddesign.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="157" src="http://4.bp.blogspot.com/-4cV7er0VgPI/UNWw0GXYL5I/AAAAAAAAHSQ/nDFaspNqWns/s200/androiddesign.png" width="200" /></a>The year 2011 has just ended and the <b>Galaxy Nexus</b> is the current flagship phone. 12 days later on January 12th the <b><a href="http://developer.android.com/design/index.html">Android Design</a></b> website launched. Followed by the <b><a href="https://plus.google.com/u/0/+AndroidDevelopers/posts">Android developers Google+ page</a></b> on January 30th.<br /><br /><span style="font-size: large;"><b>February</b></span><br /><br />The first numbers of the year are published. <b>850,000</b> Android phones are activated every day. <b>300 million </b>devices have been activated so far.<br /><br /><span style="font-size: large;"><b>March</b></span><br /><br />On March 5th <b><a href="http://android-developers.blogspot.de/2012/03/android-apps-break-50mb-barrier.html">expansion files</a></b> are introduced and <b>Android apps break the 50MB barrier</b> expanding the size limit to <b>4GB</b>. The Android market retires and is reborn as <b>Google play</b> on March 6th. The same month on March 21st the <b>SDK tools and ADT revision 17</b> are released, adding an emulator that supports running x86 system images on Windows and Mac OS X. An update to the Android Developer Console on March 29th allows <b>multiple users</b> to manage published Android apps.<br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-qPqhAtg_PVg/UNWxPkos_2I/AAAAAAAAHSY/ivgQD4D4Nmo/s1600/appclinic.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="150" src="http://1.bp.blogspot.com/-qPqhAtg_PVg/UNWxPkos_2I/AAAAAAAAHSY/ivgQD4D4Nmo/s200/appclinic.jpg" width="200" /></a></div><br /><span style="font-size: large;"><b>April</b></span><br /><br />The emulator gets even more faster on April 9th by adding <b>GPU support</b>. On April 20th the first episode of <b><a href="http://www.youtube.com/playlist?list=PLB7B9B23D864A55C3">Friday App Review</a></b> airs and is later called <b><a href="http://www.youtube.com/playlist?list=PLB7B9B23D864A55C3">The app clinic</a></b>.<br /><br /><b><span style="font-size: large;">May</span></b><br /><br />On May 4th Wolfram Rittmeyer publishes the first posting on his blog <b><a href="http://www.grokkingandroid.com/">Grokking Android</a></b>. Followed by the first article published on <a href="http://www.androidzeitgeist.com/"><b>Android Zeitgeist</b></a> on May 27th. 3 days before on May 24th <b><a href="http://android-developers.blogspot.de/2012/05/in-app-subscriptions-in-google-play.html">In-app Subscriptions</a></b> are launched on Google Play.<br /><br /><span style="font-size: large;"><b>June</b></span><br /><a href="http://1.bp.blogspot.com/-HvAwcdnUaq4/UNWxlZCN7XI/AAAAAAAAHSg/jM3slhIq--k/s1600/google-io-logo.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="40" src="http://1.bp.blogspot.com/-HvAwcdnUaq4/UNWxlZCN7XI/AAAAAAAAHSg/jM3slhIq--k/s200/google-io-logo.png" width="200" /></a><br />The <b><a href="https://developers.google.com/events/io/">Google I/O</a></b> takes place for three days from June 27th to 29th. There are now <b>900,000</b> Android devices activated every day and <b>400 million</b> devices have been activated up to now. <b>Android 4.1 (Jelly Bean)</b> is publicly shown for the first time on June 27th. The same day the <b>Android 4.1 SDK</b> is released. In addition to that the first tablet by Google is unveiled: The <b>Nexus 7</b>. On the second day of the Google I/O the <b>Android SDK tools</b> are updated to <b>revision 20</b>. At the end of the Google I/O there have been 3.5 million live streams seen from 170 countries.<br /><br /><span style="font-size: large;"><b>July</b></span><br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-iu-C9xVT-_U/UNWyPKppPJI/AAAAAAAAHS4/JfRWJvOp7dg/s1600/ouya.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="200" src="http://3.bp.blogspot.com/-iu-C9xVT-_U/UNWyPKppPJI/AAAAAAAAHS4/JfRWJvOp7dg/s200/ouya.png" width="200" /></a></div>On July 3rd the <b><a href="http://www.ouya.tv/">Ouya</a></b>, an Android based console, is unveiled and a Kickstarter campaign is started on July 10th. On July 9th the <b>Android 4.1 source code</b> is published as part of the Android Open Source Project (AOSP).<br /><br /><span style="font-size: large;"><b>August</b></span><br /><br />The funding phase for the <b>Ouya</b> is completed. The campaign collected $8,596,475. That’s 904% more than the initial campaign goal.<br /><br /><span style="font-size: large;"><b>September</b></span><br /><br />New numbers are released. There are now <b>1.3 million devices</b> activated every a day. About <b>70,000</b> of these devices are tablets. <b>480 million</b> devices have been activated up to now. On September 9th the first episode of <b><a href="http://www.youtube.com/playlist?list=PLWz5rJ2EKKc9Wam5jE-9oY8l6RpeAx-XM">This week in Android development</a></b> airs. A day later the first episode of <b><a href="http://www.youtube.com/playlist?list=PLWz5rJ2EKKc8j2B95zGMb8muZvrIy-wcF">Android Design in Action</a></b> is uploaded to YouTube.<br /><br /><span style="font-size: large;"><b>October</b></span><br /><br /><a href="http://3.bp.blogspot.com/-iMCBRXK31yE/UNWx_vXgIjI/AAAAAAAAHSw/9PXrh3tQBs4/s1600/nexus4.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="167" src="http://3.bp.blogspot.com/-iMCBRXK31yE/UNWx_vXgIjI/AAAAAAAAHSw/9PXrh3tQBs4/s200/nexus4.png" width="200" /></a>Till mid October <b>3 million Nexus 7</b> units have been sold. Starting from October 15th the <b>new Google Play Developer Console</b> is available to everyone. Google planned a <b>launch event</b> on October 29th in New York but it has been cancelled due to Hurricane Sandy. Nevertheless the <b>Nexus 4</b> and <b>Nexus 10</b> are introduced online this day. These are the first devices to run <b>Android 4.2</b>.<br /><br /><span style="font-size: large;"><b>November</b></span><br /><br />The first episode of <a href="http://www.youtube.com/playlist?list=PLWz5rJ2EKKc9loen4OjS03gdjI0JhF4cW">(╯°□°)╯︵ ┻━┻</a> airs on November 8th. On November 13th the <b>Nexus 4</b> and <b>Nexus 10</b> went on sale and are sold out in minutes. Later that day the <b>Android 4.2 SDK platform</b> is released. Another day later the <b>Android SDK tools revision 21</b> are released.<br /><br /><span style="font-size: large;"><b>December</b></span><br /><br />Google releases a new <b><a href="http://android-developers.blogspot.de/2012/12/new-google-maps-android-api-now-part-of.html">Google Maps API</a></b> for Android on December 3rd. On December 10th a new version of the<b> <a href="http://android-developers.blogspot.de/2012/12/in-app-billing-version-3.html">In-App billing API</a></b> is released.<br /><br />The Android team releases their <b>Happy Holidays</b> video:<br /><br /><iframe allowfullscreen="allowfullscreen" frameborder="0" height="315" src="http://www.youtube.com/embed/967nio2LF7s" width="560"></iframe><br /><br /><span style="font-size: large;"><b>2013?</b></span><br /><br /><b>What has been your Android highlight in 2012 and what are your wishes for 2013?</b><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/6_wXwDjJRdc" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com1http://www.androidzeitgeist.com/2012/12/android-2012.htmltag:blogger.com,1999:blog-1531829516427013333.post-87340048280907552042012-12-11T20:41:00.000+01:002012-12-11T20:41:51.969+01:00Mind the gap: String.isEmpty()<span style="font-size: x-small;">Articles labeled "Mind the gap" are short articles mostly about simple problems that arise from using different API levels of Android. They are more short trivia postings than big teachings about Android development.</span><br /><br />I try to write code as readable as possible. That's the reason why I don't want to compare a String to an other empty String object or check its length when I want to know if a String is empty.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-FWLirpvHLAM/UMbfKHp3tUI/AAAAAAAAHCI/NPnjM4Qx5Pk/s1600/isemptyvariants.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-FWLirpvHLAM/UMbfKHp3tUI/AAAAAAAAHCI/NPnjM4Qx5Pk/s1600/isemptyvariants.png" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"></div>In the book "<a href="http://books.google.de/books?id=dwSfGQAACAAJ&amp;dq=isbn:0132350882y">Clean code</a>" by <a href="http://en.wikipedia.org/wiki/Robert_Cecil_Martin">Robert C. Martin</a> you can read&nbsp;<a href="http://en.wikipedia.org/wiki/Grady_Booch">Grady Booch</a> saying: "Clean code reads like well-written prose". So I try to use <a href="http://developer.android.com/reference/java/lang/String.html#isEmpty()">String.isEmpty()</a> for that reason. Internally it may do a length check as well (I stopped my investigation at the <i>native</i> keyword)&nbsp;but when reading the following snippet it is absolutely obvious what I intend to do.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-fPosAzNzRYc/UMbecA_7d3I/AAAAAAAAHB4/K6lPAMAkrIs/s1600/isEmptyMethod.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-fPosAzNzRYc/UMbecA_7d3I/AAAAAAAAHB4/K6lPAMAkrIs/s1600/isEmptyMethod.png" /></a></div><br />Even though <a href="http://developer.android.com/reference/java/lang/String.html#isEmpty()">isEmpty()</a> has been introduced in Java 1.6 it hasn't been available in Android until API level 9 (Android 2.3) so I accidentally caused some crashes on earlier versions of Android. Nowadays <a href="http://tools.android.com/tips/lint">lint</a>&nbsp;thankfully&nbsp;saves me from doing this error.<br /><br />So what to do now? I don't know if someone at Google felt the same but there is a class in the Android framework that solves that problem: <a href="http://developer.android.com/reference/android/text/TextUtils.html">TextUtils</a>. This class also has a lot of other helpful methods like <a href="http://developer.android.com/reference/android/text/TextUtils.html#join(java.lang.CharSequence, java.lang.Object[])">join()</a> to join an array of elements to a String using a&nbsp;delimiter&nbsp;or <a href="http://developer.android.com/reference/android/text/TextUtils.html#getReverse(java.lang.CharSequence, int, int)">getReverse() </a>to reverse a String (Take that interview question!).<br /><br />In addition to that the TextUtils class has a method <a href="http://developer.android.com/reference/android/text/TextUtils.html#isEmpty(java.lang.CharSequence)">isEmpty()</a> that is available since API level 1.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-nzyWV2TAHaM/UMbelfdSHCI/AAAAAAAAHCA/Z2lLIH_YddU/s1600/TextUtils.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-nzyWV2TAHaM/UMbelfdSHCI/AAAAAAAAHCA/Z2lLIH_YddU/s1600/TextUtils.png" /></a></div><br />Phew! By the way: <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/text/TextUtils.java#TextUtils.isEmpty%28java.lang.CharSequence%29">Internally</a> isEmpty() checks if the length of the String is 0 (and does a null check).<img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/jbePXNFlMnA" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com5http://www.androidzeitgeist.com/2012/12/string-is-empty.htmltag:blogger.com,1999:blog-1531829516427013333.post-45102601454214192362012-11-05T20:40:00.000+01:002012-11-05T20:40:10.181+01:00Examining the ViewPager #3<span style="font-size: x-small;">This article is part of a series of articles about the ViewPager component.&nbsp;</span><a href="http://www.androidzeitgeist.com/p/viewpager.html" style="font-size: small;">Click here</a><span style="font-size: x-small;">&nbsp;to see a list of&nbsp;</span><a href="http://www.androidzeitgeist.com/p/viewpager.html" style="font-size: small;">all articles of this series</a><span style="font-size: x-small;">.</span><br /><br /><b><span style="font-size: large;">Horizontal scrolling pages</span></b><br /><br />Have you ever tried putting horizontal scrolling components inside a <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html">ViewPager</a>? Well, since revision 9 of the <a href="http://developer.android.com/tools/extras/support-library.html">support library</a> this is supported by the ViewPager. As long as the inner component can scroll horizontally this component will be scrolled. Whenever the component can't be further scrolled the ViewPager will handle the touch events and you start to switch to the next page. This works out-of-the-box for scrolling view components of Android like the <a href="http://developer.android.com/reference/android/webkit/WebView.html">WebView</a>.<br /><br />Internally the ViewPager uses <a href="http://developer.android.com/reference/android/support/v4/view/ViewCompat.html#canScrollHorizontally(android.view.View, int)">ViewCompat.canScrollHorizontally(View v, int direction)</a>&nbsp;to determine if a child view can be scrolled horizontally and should receive the according touch events. Unfortunately this method is only implemented for Android 4.0 (API level 14) and above. For all earlier versions this method will always return false and therefore never scroll the components inside the ViewPager.<br /><br /><b><span style="font-size: large;">Bezel swipe</span></b><br /><br />Allowing horizontal scrolling components introduces a new problem: What if you want to switch pages but not scroll every component to its horizontal end? When you start the swipe at the phone's bezel (or actually from the edge of the ViewPager) you'll switch pages instead of scrolling the page's content. This gesture is called <i>bezel swipe</i>.<br /><br />For reading more about the bezel swipe gesture from a UI point of view read "<a href="http://www.androiduipatterns.com/2012/02/bezel-swipe-solution-to-pan-and-swipe.html">Bezel swipe, a Solution to Pan and Swipe Confusion?</a>" on <a href="http://www.androiduipatterns.com/">Android UI Patterns</a>.<br /><br />The good news is again: The ViewPager supports bezel swipe out of the box. But as you can't horizontally scroll inside pages on devices running an Android version lower than 4.0 (API level 14) bezel swipe isn't of any use on these as well.<br /><br />The area to start a bezel swipe has a width of either 16dp or a 10th of the total width of the ViewPager depending on which one is smaller.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-dNYV1OuZvdQ/UJgLXTptXHI/AAAAAAAAGS4/Zt0OXlBwbaM/s1600/viewpager_bezel_swipe.png" imageanchor="1"><img border="0" src="http://1.bp.blogspot.com/-dNYV1OuZvdQ/UJgLXTptXHI/AAAAAAAAGS4/Zt0OXlBwbaM/s1600/viewpager_bezel_swipe.png" /></a></div><br /><span style="font-size: large;"><b>Fake dragging</b></span><br /><br />The ViewPager supports fake dragging. Fake dragging can be used to simulate a dragging event/animation, e.g. for detecting drag events on a different component and delegating these to the ViewPager.<br /><br />You have to signal the ViewPager when to start or end a fake drag by calling <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#beginFakeDrag()">beginFakeDrag()</a> and <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#endFakeDrag()">endFakeDrag()</a> on it. After starting a fake drag you can use <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#fakeDragBy(float)">fakeDragBy(float)</a> to drag the ViewPager by the given amount of pixels along the x axis (negative values to the left and positive values to the right).<br /><br />The following example uses a <a href="http://developer.android.com/reference/android/widget/SeekBar.html">SeekBar</a>&nbsp;whose current progress state is used to fake drag a ViewPager by the given percentage.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-SFr1EyEfN4Q/UJgNTawCuSI/AAAAAAAAGTA/Pq_75XpuIes/s1600/SeekBarPagerListener.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://4.bp.blogspot.com/-SFr1EyEfN4Q/UJgNTawCuSI/AAAAAAAAGTA/Pq_75XpuIes/s1600/SeekBarPagerListener.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Zeitgeist-Samples/blob/master/ViewPager/03/SeekBarPagerListener.java">SeekBarPagerListener.java</a></td></tr></tbody></table><br />This video shows the fake drag in action:<br /><br /><iframe allowfullscreen="allowfullscreen" frameborder="0" height="360" src="http://www.youtube.com/embed/us8w2g9YXC4?rel=0" width="480"></iframe><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/GsNXoeK7N6Y" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com1http://www.androidzeitgeist.com/2012/11/examining-viewpager-3.htmltag:blogger.com,1999:blog-1531829516427013333.post-53618283758571209542012-10-30T23:35:00.000+01:002012-10-30T23:35:59.679+01:00Displaying the taken picture – Instant Mustache #7<div><span style="font-size: x-small;">This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection. <a href="http://www.androidzeitgeist.com/p/instant-mustache.html">Click here</a> to get a chronological list of all published <a href="http://www.androidzeitgeist.com/p/instant-mustache.html">articles about Instant Mustache</a>.</span></div><div><span style="font-size: x-small;"><br /></span></div><div><span style="font-size: large;"><b>Writing the PhotoActivity</b></span></div><div><br /></div>In the <a href="http://www.androidzeitgeist.com/2012/10/taking-picture-instant-mustache-6.html">last article</a> we wrote the code to take a camera picture and save it on the external storage. After saving the file the activity will be finished and a Toast will show up. This is not really user-friendly so now we'll write our next activity which will display the taken picture and later offer the option to share this picture.<br /><br />We'll start by creating an empty activity called <a href="https://github.com/pocmo/Instant-Mustache/blob/article-07/src/com/androidzeitgeist/mustache/activity/PhotoActivity.java">PhotoActivity</a> and add it to the <a href="https://github.com/pocmo/Instant-Mustache/blob/article-07/AndroidManifest.xml#L30">manifest</a> of our application. For now the layout will only contain an <a href="http://developer.android.com/reference/android/widget/ImageView.html">ImageView</a> to display the picture:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-KnA5sDjgZds/UJBOSqCkiZI/AAAAAAAAF2k/q3_2TKxMJ8I/s1600/layout_activity_photo.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-KnA5sDjgZds/UJBOSqCkiZI/AAAAAAAAF2k/q3_2TKxMJ8I/s1600/layout_activity_photo.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-07/res/layout/activity_photo.xml">activity_photo.xml</a></td></tr></tbody></table><br />Instead of showing a toast in our <a href="https://github.com/pocmo/Instant-Mustache/blob/article-07/src/com/androidzeitgeist/mustache/activity/CameraActivity.java">CameraActivity</a> we create an Intent to start the PhotoActivity and use <a href="http://developer.android.com/reference/android/content/Intent.html#setData(android.net.Uri)">setData(Uri)</a> on the Intent object to pass a <a href="http://developer.android.com/reference/android/net/Uri.html">Uri</a> pointing to the picture file:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-VSkxvSyGYTU/UJBOjJYq-aI/AAAAAAAAF2s/q1DBQt-Ib9A/s1600/intent_start_photo_activity.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-VSkxvSyGYTU/UJBOjJYq-aI/AAAAAAAAF2s/q1DBQt-Ib9A/s1600/intent_start_photo_activity.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-07/src/com/androidzeitgeist/mustache/activity/CameraActivity.java#L116">onPictureTaken() - CameraActivity.java</a></td></tr></tbody></table><br />In <a href="https://github.com/pocmo/Instant-Mustache/blob/article-07/src/com/androidzeitgeist/mustache/activity/PhotoActivity.java#L19">onCreate(Bundle)</a> of the PhotoActivity we'll retrieve the Uri from the Intent and pass it to the ImageView. The ImageView will take care of loading the picture from the external storage and displaying it.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-tE-1b0nu5Ic/UJBO0nSip_I/AAAAAAAAF20/Thmkq7JwsmM/s1600/photo_activity_on_create.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-tE-1b0nu5Ic/UJBO0nSip_I/AAAAAAAAF20/Thmkq7JwsmM/s1600/photo_activity_on_create.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-07/src/com/androidzeitgeist/mustache/activity/PhotoActivity.java#L19">onCreate() - PhotoActivity.java</a></td></tr></tbody></table><br />And that's already all the code we need for the first version of the <a href="https://github.com/pocmo/Instant-Mustache/blob/article-07/src/com/androidzeitgeist/mustache/activity/PhotoActivity.java">PhotoActivity</a>.<br /><br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-sX-QuJWGZtQ/UJBVljLcABI/AAAAAAAAF3I/XEL1UJHnjiI/s1600/camera_and_photo_screenshot.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-sX-QuJWGZtQ/UJBVljLcABI/AAAAAAAAF3I/XEL1UJHnjiI/s1600/camera_and_photo_screenshot.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">CameraActivity (left) and PhotoActivity (right)</td></tr></tbody></table><br /><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/bA7tWUcBxoc" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com3http://www.androidzeitgeist.com/2012/10/displaying-taken-picture-instant.htmltag:blogger.com,1999:blog-1531829516427013333.post-738290383239656172012-10-26T20:59:00.000+02:002012-10-30T23:17:25.534+01:00Taking a picture – Instant Mustache #6<span style="font-size: x-small;">This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection.&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-size: small;">Click here</a><span style="font-size: x-small;">&nbsp;to get a chronological list of all published&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-size: small;">articles about Instant Mustache</a><span style="font-size: x-small;">.</span><br /><br />After writing the necessary code to display a camera preview in <a href="http://www.androidzeitgeist.com/2012/10/displaying-camera-preview-instant.html">the last article</a> it's now time to actually take a picture and save it on the external storage of the device.<br /><br />We start by extending the layout of the <a href="https://github.com/pocmo/Instant-Mustache/blob/article-06/src/com/androidzeitgeist/mustache/activity/CameraActivity.java">CameraActivity</a> to include a button for taking a picture. We assign a method to it to be called when the user clicks on the button via the attribute <a href="http://developer.android.com/reference/android/view/View.html#attr_android:onClick">android:onClick</a>. Another option would be to assign an <a href="http://developer.android.com/reference/android/view/View.OnClickListener.html">OnClickListener</a> to the view in code. Defining the method in the XML results in less code but has the disadvantage of not being checked by the compiler. Since one of the last releases of the Android SDK the <a href="http://tools.android.com/tips/lint">lint</a> tool is able to check the onClick attributes for correctness. So we will use the XML attribute here.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-hmHriQ9ppUo/UIqjpzAIkZI/AAAAAAAAFpQ/PJZvXOEn5XE/s1600/activity_camera.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-hmHriQ9ppUo/UIqjpzAIkZI/AAAAAAAAFpQ/PJZvXOEn5XE/s1600/activity_camera.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-06/res/layout/activity_camera.xml">activity_camera.xml</a></td></tr></tbody></table><br />As we encapsulated the code handling the <a href="http://developer.android.com/reference/android/hardware/Camera.html">Camera</a> object inside the <a href="https://github.com/pocmo/Instant-Mustache/blob/article-06/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java">CameraFragment</a> class the activity just calls takePicture() on the fragment when the user presses the button.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-FE7ro562XUI/UIqkAHnPvzI/AAAAAAAAFpY/-IZ0ncr7CbU/s1600/CameraActivity_takePicture.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-FE7ro562XUI/UIqkAHnPvzI/AAAAAAAAFpY/-IZ0ncr7CbU/s1600/CameraActivity_takePicture.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-06/src/com/androidzeitgeist/mustache/activity/CameraActivity.java#L64">takePicutre() - CameraActivity.java</a></td></tr></tbody></table><br />The fragment calls <a href="http://developer.android.com/reference/android/hardware/Camera.html#takePicture(android.hardware.Camera.ShutterCallback, android.hardware.Camera.PictureCallback, android.hardware.Camera.PictureCallback, android.hardware.Camera.PictureCallback)">takePicture()</a> on the Camera object. It's possible to pass up to four callbacks to this method: A shutter callback, a raw callback, a postview callback and a jpeg callback. According to the documentation their usage is:<br /><br /><ul><li>The shutter callback occurs after the image is captured. This can be used to trigger a sound to let the user know that image has been captured.</li><li>The raw callback occurs when the raw image data is available.</li><li>The postview callback occurs when a scaled, fully processed postview image is available.</li><li>The jpeg callback occurs when the compressed image is available.</li></ul><br />We are only interested in the JPEG image. The fragment itself is also the callback so we'll implement the Camera.PictureCallback interface.<br /><br />Once the picture is taken <a href="http://developer.android.com/reference/android/hardware/Camera.PictureCallback.html#onPictureTaken(byte[], android.hardware.Camera)">onPictureTaken()</a> will be called with a byte array. We decode the given byte array and create a <a href="http://developer.android.com/reference/android/graphics/Bitmap.html">Bitmap</a> object and pass it via the <a href="https://github.com/pocmo/Instant-Mustache/blob/article-06/src/com/androidzeitgeist/mustache/listener/CameraFragmentListener.java">CameraFragmentListener</a> interface to our CameraActivity. Later we will use this bitmap to draw the mustaches on it.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-HmhBl2pWTlo/UIqkdSoODnI/AAAAAAAAFpg/cJ69yQZOIeg/s1600/CameraFragment_onPictureTaken.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-HmhBl2pWTlo/UIqkdSoODnI/AAAAAAAAFpg/cJ69yQZOIeg/s1600/CameraFragment_onPictureTaken.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-06/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java#L224">onPictureTaken() - CameraFragment.java</a></td></tr></tbody></table><br /><b><span style="font-size: large;">Saving the picture to the external storage</span></b><br /><br />Once the activity receives the bitmap object it needs to do a bunch of things:<br /><ul><li>Determine the directory to save the picture to and create it if necessary</li><li>Create a unique file for the picture inside the directory and save the image data to it</li><li>Notify the MediaScanner that we created a new file</li><li>Show a toast that the picture has been saved successfully (For now until we've written the activity to display the taken picture).</li></ul><br /><span style="font-size: large;">Determining the directory</span><br /><br />We want to save the picture into a directory on the external storage that is visible for all other applications. By calling <a href="http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)">Environment.getExternalStoragePublicDirectory()</a> and passing <a href="http://developer.android.com/reference/android/os/Environment.html#DIRECTORY_PICTURES">Environment.DIRECTORY_PICTURES</a> we get the public directory for pictures (Available since API Level 8). Inside this directory we'll create a directory with the name of our application (if it doesn't exist already).<br /><br /><div class="separator" style="clear: both; text-align: center;"></div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-etMHinejAMU/UIqlvdRKOlI/AAAAAAAAFpo/QlH_Lu4dUOY/s1600/determining_directory.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://4.bp.blogspot.com/-etMHinejAMU/UIqlvdRKOlI/AAAAAAAAFpo/QlH_Lu4dUOY/s1600/determining_directory.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-06/src/com/androidzeitgeist/mustache/activity/CameraActivity.java#L77">onPictureTaken() - CameraActivity.java</a></td></tr></tbody></table><br />&nbsp;<span style="font-size: large;">Saving the file</span><br /><br />We'll create a file with a unique file name containing a timestamp, e.g.: MUSTACHE_20121031_235959.jpg. The <a href="http://developer.android.com/reference/android/graphics/Bitmap.html#compress(android.graphics.Bitmap.CompressFormat, int, java.io.OutputStream)">compress()</a> method of the bitmap object is used to save the picture into the file.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-yNhLaUTQOs8/UIqlxhiP9tI/AAAAAAAAFp0/HlPPxj7_L9w/s1600/saving_picture.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-yNhLaUTQOs8/UIqlxhiP9tI/AAAAAAAAFp0/HlPPxj7_L9w/s1600/saving_picture.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-06/src/com/androidzeitgeist/mustache/activity/CameraActivity.java#L92">onPictureTaken() - CameraActivity.java</a></td></tr></tbody></table><br /><span style="font-size: large;">Notifying the MediaScanner</span><br /><br />Scanning the SD card for changes is costly. Therefore most Android versions only scan the whole card if the card is re-inserted or was mounted by another device. This seems to be different in different vendor versions of Android but nevertheless you can't assume a file to be seen by other applications (for example the gallery) until it has been scanned by the <a href="http://developer.android.com/reference/android/media/MediaScannerConnection.html">MediaScanner</a>. For that reason we'll notify the MediaScanner about the file we've created.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-BKiT4GJmj8s/UIqlw9LsiFI/AAAAAAAAFpw/K1_jEkvhX98/s1600/notify_mediascanner.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://4.bp.blogspot.com/-BKiT4GJmj8s/UIqlw9LsiFI/AAAAAAAAFpw/K1_jEkvhX98/s1600/notify_mediascanner.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-06/src/com/androidzeitgeist/mustache/activity/CameraActivity.java#L107">onPictureTaken() - CameraActivity.java</a></td></tr></tbody></table><br />By now we've already created a simple camera application. We can take pictures and they show up in the gallery of the device. Pretty cool so far, huh?<img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/c-K683UuF5g" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com1http://www.androidzeitgeist.com/2012/10/taking-picture-instant-mustache-6.htmltag:blogger.com,1999:blog-1531829516427013333.post-87275454949960597172012-10-25T21:24:00.000+02:002012-11-05T19:31:06.680+01:00Examining the ViewPager #2<span style="font-size: x-small;">This article is part of a series of articles about the ViewPager component.&nbsp;</span><a href="http://www.androidzeitgeist.com/p/viewpager.html" style="font-size: small;">Click here</a><span style="font-size: x-small;">&nbsp;to see a list of&nbsp;</span><a href="http://www.androidzeitgeist.com/p/viewpager.html" style="font-size: small;">all articles of this series</a><span style="font-size: x-small;">.</span><br /><br /><b><span style="font-size: large;">Offscreen pages</span></b><br /><br />The <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html">ViewPager</a> doesn't create all its pages at once. When using a lot of pages this would be horribly slow and even unnecessary if the user would never swipe through all these pages. By default the ViewPager only creates the current page as well as the offscreen pages to the left and right of the current page.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-HzlJvCZIyQc/UIkzJpr1neI/AAAAAAAAFls/jfMZCwnu30I/s1600/offscreen_pages.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://1.bp.blogspot.com/-HzlJvCZIyQc/UIkzJpr1neI/AAAAAAAAFls/jfMZCwnu30I/s1600/offscreen_pages.png" /></a></div><br /><br />If you only use a small amount of pages you may get a better performance by creating them all at once. You can use <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit(int)">setOffscreenPageLimit(int limit)</a> to set the number of pages that will be created and retained. Note that the limit applies to both sides of the current page. So if you set the offscreen page limit to 2 the ViewPager will retain 5 pages: The current page plus 2 pages to the left and right.<br /><br /><b><span style="font-size: large;">Responding to changing states</span></b><br /><br />You can get notified whenever the displayed page changes or is incrementally scrolled. To listen to these state changes you can implement the <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.OnPageChangeListener.html">OnPageChangeListener</a> interface or extend the <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.SimpleOnPageChangeListener.html">SimpleOnPageChangeListener</a> class if you do not intent to override every method of the interfacce.<br /><br />The following example listener updates the title of the activity according to the title of the currently selected page:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-xgUfOiVWc_g/UIkzQ_OCF8I/AAAAAAAAFl0/Fp_eXNYlt4g/s1600/UpdateTitleListener.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-xgUfOiVWc_g/UIkzQ_OCF8I/AAAAAAAAFl0/Fp_eXNYlt4g/s1600/UpdateTitleListener.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Zeitgeist-Samples/blob/master/ViewPager/02/UpdateTitleListener.java">UpdateTitleListener.java</a></td></tr></tbody></table><br /><b><span style="font-size: large;">Margin between pages</span></b><br /><br />When scrolling through pages they all look like glued together. You can use <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setPageMargin(int)">setPageMargin(int pixels)</a> to define a margin between pages. The gap is filled with the background color of the ViewPager.<br /><br />The following screenshots are showing the same ViewPager during switching pages. The left screenshot shows the ViewPager with no page margin set. In the right screenshot the margin has been set to 20 pixels. Notice that the method expects the margin to be defined in pixels. To use the same physical margin on all kind of screens independent from their pixel density define the margin in density independent pixels (dp) and <a href="http://stackoverflow.com/a/6327095/234908">convert them to the actual number of pixels</a> for the current screen.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-fS9q-7IO-Uc/UIkzWvgeSoI/AAAAAAAAFl8/GESmB7vau7c/s1600/page_margin.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-fS9q-7IO-Uc/UIkzWvgeSoI/AAAAAAAAFl8/GESmB7vau7c/s1600/page_margin.png" /></a></div><br />It's also possible to define a drawable that will be used to fill the margin between two pages using <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setPageMarginDrawable(int)">setPageMarginDrawable(int resId)</a> or <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setPageMarginDrawable(android.graphics.drawable.Drawable)">setPageMarginDrawable(Drawable d)</a>. The best approach is to use a <a href="http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch">Nine-patch</a> that be scaled dynamically by the system to fill the space between the pages.<br /><br /><b><span style="font-size: large;">Switching pages programmatically</span></b><br /><br />You can also switch between pages programmatically. Using <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setCurrentItem(int, boolean)">setCurrentItem(int position, boolean smoothScroll)</a> you can switch to the given position. If the second parameter is <span style="color: #660000;">true</span> a smooth animated transition is being performed. Using <span style="color: #660000;">false</span> the ViewPager will switch to the given page without any animation. If you always want to switch pages with an animation you can also leave the second parameter and use <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setCurrentItem(int)">setCurrentItem(int position)</a>.<img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/EUMG4ssJLOA" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com1http://www.androidzeitgeist.com/2012/10/examining-viewpager-2.htmltag:blogger.com,1999:blog-1531829516427013333.post-16185864477175936152012-10-22T18:30:00.000+02:002012-10-30T23:18:43.358+01:00Examining the ViewPager #1<span style="font-size: x-small;">This article is part of a series of articles about the ViewPager component. <a href="http://www.androidzeitgeist.com/p/viewpager.html">Click here</a> to see a list of <a href="http://www.androidzeitgeist.com/p/viewpager.html">all articles of this series</a>.</span><br /><br />The <a href="http://developer.android.com/tools/extras/support-library.html">Android support library</a> offers a great UI component for horizontal scrolling pages: <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html">The ViewPager</a>. Over the last iterations of the support library more and more functionality has been added to the ViewPager silently. For that reason I decided to study the various features of the ViewPager more closely. This will be a series of articles covering several of these features.<br /><br /><span style="font-size: large;"><b>Disclaimer upfront</b></span><br /><br />According to the <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html">documentation of the ViewPager</a> the implementation and API of the class may change in future releases. Therefore also this blog posting may not be up-to-date if you are reading this a long time after the published date. Check the <a href="http://developer.android.com/reference/android/support/v4/view/ViewPager.html">documentation</a> if some of the examples may not work anymore as I described them here.<br /><br /><span style="font-size: large;"><b>The basics</b></span><br /><br />The ViewPager is a <a href="http://developer.android.com/reference/android/view/ViewGroup.html">ViewGroup</a> that displays by default one page at a time. The user can switch between these pages by swiping horizontally. A <a href="http://developer.android.com/reference/android/support/v4/view/PagerAdapter.html">PagerAdapter</a> dynamically provides these pages which can be just views or fragments. However the ViewPager is not an AdapterView like the ListView or the GridView. Therefore you need to implement a specific adapter class in order to use the ViewPager class.<br /><br />The following video shows a ViewPager with different colored pages:<br /><br /><iframe allowfullscreen="allowfullscreen" frameborder="0" height="360" src="http://www.youtube.com/embed/tcnGyRc9t0M?rel=0" width="480"></iframe> <br /><br /><span style="font-size: large;"><b>Adapter using fragments</b></span><br /><br />The easiest way to write an adapter for a ViewPager is to use fragments and let your adapter implementation extend the <a href="http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html">FragmentPagerAdapter</a> class. You only need to implement <a href="http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html#getItem(int)">getItem(int position)</a> to return a fragment for the page at the given position and <a href="http://developer.android.com/reference/android/support/v4/view/PagerAdapter.html#getCount()">getCount()</a> to return the number of pages to display.<br /><br />The following implementation shows the FragmentPagerAdapter used for the video above:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-CkknYiuF5vQ/UIQMY-pOFOI/AAAAAAAAFjY/es0HrjuPA0U/s1600/SampleFragmentPagerAdapter.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-CkknYiuF5vQ/UIQMY-pOFOI/AAAAAAAAFjY/es0HrjuPA0U/s1600/SampleFragmentPagerAdapter.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Zeitgeist-Samples/blob/master/ViewPager/01/SampleFragmentPagerAdapter.java">SampleFragmentPagerAdapter.java</a></td></tr></tbody></table><br /><span style="font-size: large;"><b>Saving fragment states</b></span><br /><br />When using a <a href="http://developer.android.com/reference/android/support/v13/app/FragmentPagerAdapter.html">FragmentPagerAdapter</a> and swiping through the pages the ViewPager may eventually have created fragments for all the pages. Depending on the number of pages this may need a large amount of memory just for holding all the offscreen pages. To solve this problem the support library offers the <a href="http://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html">FragmentStatePagerAdapter</a> class. This adapter will destroy fragments not visible to the user when needed. Whenever this happens the adapter saves the fragment's current state using <a href="http://developer.android.com/reference/android/app/Fragment.html#onSaveInstanceState(android.os.Bundle)">onSaveInstanceState(Bundle outState) </a>of the fragment class to restore it when the fragment for this page gets recreated.<br /><br />Implementing an adapter extending the FragmentStatePagerAdapter is exactly the same as when using the FragmentPagerAdapter class. Just your fragment needs to take care of saving its state when getting destroyed. Take a look at the <a href="http://developer.android.com/reference/android/app/Fragment.html#onSaveInstanceState(android.os.Bundle)">documentation</a> for an example on how to retain the state of a fragment.<br /><br /><span style="font-size: large;"><b>Adapter using views</b></span><br /><br />You can also use the ViewPager with only View objects as pages if using fragments isn't an option for you. It's a bit more tricky to implement the adapter as you'll have to directly extend the <a href="http://developer.android.com/reference/android/support/v4/view/PagerAdapter.html">PagerAdapter</a> class.<br /><br />The following example creates an adapter that shows a number of different colored pages like the FragmentPagerAdapter implementation above.<br /><br /><div class="separator" style="clear: both; text-align: center;"></div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-mxaO0n1cYhQ/UIQNo43ZszI/AAAAAAAAFjw/FQ5bbhdhrMU/s1600/SamplePagerAdapter.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-mxaO0n1cYhQ/UIQNo43ZszI/AAAAAAAAFjw/FQ5bbhdhrMU/s1600/SamplePagerAdapter.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Zeitgeist-Samples/blob/master/ViewPager/01/SamplePagerAdapter.java">SamplePagerAdaper.java</a></td></tr></tbody></table><br />As you can see you need to write some boilerplate code to add and remove the views to the pager. I published a simple&nbsp;<a href="https://gist.github.com/3927202">ViewPagerAdapter</a> class on GitHub that does all this for you so that you don't need to write much more code than when using fragments:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-RG1Pybe0Qko/UIQNEZ0emlI/AAAAAAAAFjo/wiW86E8k3lY/s1600/SamplePagerAdapter2.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-RG1Pybe0Qko/UIQNEZ0emlI/AAAAAAAAFjo/wiW86E8k3lY/s1600/SamplePagerAdapter2.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Android-Zeitgeist-Samples/blob/master/ViewPager/01/SamplePagerAdapter2.java">SamplePagerAdapter2.java</a></td></tr></tbody></table><br /><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/Xd7oNSltXJE" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com4http://www.androidzeitgeist.com/2012/10/examining-viewpager-14.htmltag:blogger.com,1999:blog-1531829516427013333.post-29351607224188807622012-10-18T19:28:00.003+02:002012-10-30T23:19:15.647+01:00Displaying the camera preview - Instant Mustache #5<span style="font-size: x-small;">This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection.&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-size: small;">Click here</a><span style="font-size: x-small;">&nbsp;to get a chronological list of all published&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-size: small;">articles about Instant Mustache</a><span style="font-size: x-small;">.</span><br /><br />From <a href="http://www.androidzeitgeist.com/2012/10/using-fragment-for-camera-preview.html">the last article</a> we already have three components: A <a href="https://github.com/pocmo/Instant-Mustache/blob/article-04/src/com/androidzeitgeist/mustache/activity/CameraActivity.java">CameraActivity</a> with not much code, an empty <a href="https://github.com/pocmo/Instant-Mustache/blob/article-04/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java">CameraFragment</a> and a <a href="https://github.com/pocmo/Instant-Mustache/blob/article-04/src/com/androidzeitgeist/mustache/listener/CameraFragmentListener.java">CameraFragmentListener</a> interface for the communication between fragment and activity. Now we need to write the actual CameraFragment code to display the camera preview.<br /><br /><span style="font-size: large;"><b>The CameraPreview component</b></span><br /><br />For displaying the preview we need an instance of <a href="http://developer.android.com/reference/android/view/SurfaceView.html">SurfaceView</a> to draw the actual camera picture on. We'll extend the SurfaceView to create our own view component called <a href="https://github.com/pocmo/Instant-Mustache/blob/article-05/src/com/androidzeitgeist/mustache/view/CameraPreview.java">CameraPreview</a>.<br /><div><br /></div><div><a href="http://www.androidzeitgeist.com/2012/08/lets-start-coding-not-instant-mustache-3.html">In the first articles</a> we decided to use a square ratio for the preview. After some testing around it seems the emulator is the only "device" that supports a square sized camera preview and picture size out of the box. To work around this issue we would need to use a widely supported ratio (4:3) and crop the preview picture as well as the taken photo ourselves. To keep the code and the first version of the app small (and to follow the <a href="http://www.androidzeitgeist.com/2012/07/minimal-marketable-app-instant-mustache.html">Minimal Marketable App</a> principle) I decided to change this requirement. We will use the commonly supported ratio of 4:3.<br /><br />We implement onMeasure() to set the dimension of the view to a 4:3 ratio:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-NJ3UtjTFli4/UIA4oX9FTuI/AAAAAAAAFhg/AMivOOGn94Y/s1600/onmeasure.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-NJ3UtjTFli4/UIA4oX9FTuI/AAAAAAAAFhg/AMivOOGn94Y/s1600/onmeasure.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-05/src/com/androidzeitgeist/mustache/view/CameraPreview.java#L32">onMeasure() - CameraPreview.java</a></td></tr></tbody></table><br /><b><span style="font-size: large;">Setting up the camera</span></b><br /><br />Even though we know our desired ratio we can't just set a size via <a href="http://developer.android.com/reference/android/hardware/Camera.html#setParameters(android.hardware.Camera.Parameters)">camera.setParameters(Camera.Parameters)</a>. Instead we have to query the <a href="http://developer.android.com/reference/android/hardware/Camera.Parameters.html">Camera.Parameters</a> object we get from getParameters() to retrieve a list of supported preview and picture sizes. Then we have to scan this list for a size that has our desired ratio. This is what determineBestSize() does:</div><div><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-9EpZpQQQk_g/UH2o5PQn4kI/AAAAAAAAFgk/Ip5ecGrvDSU/s1600/determine_size.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-9EpZpQQQk_g/UH2o5PQn4kI/AAAAAAAAFgk/Ip5ecGrvDSU/s1600/determine_size.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-05/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java#L190">determineBestSize() - CameraFragment.java</a></td></tr></tbody></table>We are using a threshold for the preview and picture size to save some heap space for the bitmap transformations we'll do later. For now these limits are 640x480 for the preview size and 1280x960 for the &nbsp;picture size.</div><div><br />Finally the determined values are used to setup the camera object:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-aeWvWYDnT2s/UH2uJVZkAFI/AAAAAAAAFg4/puouCbK7VOQ/s1600/setup_camera.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-aeWvWYDnT2s/UH2uJVZkAFI/AAAAAAAAFg4/puouCbK7VOQ/s1600/setup_camera.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-05/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java#L166">setupCamera() - CameraFragment.java</a></td></tr></tbody></table><br />The CameraPreview component will be used as view of our CameraFragment by returning it in <a href="http://developer.android.com/reference/android/app/Fragment.html#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)">onCreateView()</a>. In addition to that our CameraFragment needs to implement <a href="http://developer.android.com/reference/android/view/SurfaceHolder.Callback.html">SurfaceHolder.Callback</a> in order to get notified when the surface is created or destroyed.</div><div><br /></div><div><b><span style="font-size: large;">Accessing the camera</span></b></div><div><br /></div><div>To access the camera of the device we need to call <a href="http://developer.android.com/reference/android/hardware/Camera.html#open(int)">Camera.open(int cameraId)</a> to obtain a <a href="http://developer.android.com/reference/android/hardware/Camera.html">Camera</a> object. The camera ids are numbered starting with 0. As we currently don't want to support multiple cameras we will just call Camera.open(0).</div><div><br /></div><div>Unfortunately using the camera can cause undefined exceptions to be thrown. Therefore we need to wrap some code accessing the camera object into try-catch blocks and catch the generic Exception object. This is usually <a href="http://source.android.com/source/code-style.html#dont-catch-generic-exception">considered bad practice</a> but in this case <a href="http://developer.android.com/guide/topics/media/camera.html#access-camera">encouraged to do by the documentation</a>.</div><div><br /><span style="font-size: large;"><b>Sharing the camera resource</b></span><br /><br />The camera can only be used by one application at a time so we need to release the camera every time the activity gets paused. Otherwise the user would not be able to use other camera applications while our activity is in the background. In some cases not releasing the camera can lead to the CameraService crashing. If this happens no camera application can be used until the user reboots his phone. We never want this to happen.<br /><br />To be safe we will open the camera by calling Camera.open() in the <a href="https://github.com/pocmo/Instant-Mustache/blob/article-05/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java#L70">onResume()</a> method of the CameraFragment and releasing it again in <a href="https://github.com/pocmo/Instant-Mustache/blob/article-05/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java#L87">onPause()</a>.<br /><br />Once we have a Camera object and our surface is created we can assign the surface to the camera object and start the preview. We wrap the call to startPreview() in our own method called <a href="https://github.com/pocmo/Instant-Mustache/blob/article-05/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java#L97">startCameraPreview()</a> inside our fragment. This way we can setup the camera object before actually starting the preview.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-KFpfQOjQJY4/UIA567dmV6I/AAAAAAAAFho/fv7wu7wsUYg/s1600/startpreview.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://4.bp.blogspot.com/-KFpfQOjQJY4/UIA567dmV6I/AAAAAAAAFho/fv7wu7wsUYg/s1600/startpreview.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-05/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java#L97">startCameraPreview() - CameraFragment.java</a></td></tr></tbody></table><br /><br /><span style="font-size: large;"><b>Determining the display orientation</b></span><br /><br />The screen can be rotated in four different angles (0°, 90°, 180°, 270°). In addition to that the camera can also be built into the device in four different angles by the manufacturer. Finally the camera can be on the front or on the back of the device. We will need to get all these angles and tell the camera object the display orientation so that the preview will be drawn on the surface using the right rotation.<br /><br />This sounds tricky but fortunately there's a <a href="http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)">code snippet for that in the Android documentation</a>. We'll use <a href="http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)">this code snippet</a> to implement <a href="https://github.com/pocmo/Instant-Mustache/blob/article-05/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java#L126">determineDisplayOrientation()</a>.<br /><br /><b><span style="font-size: large;">Screenshot</span></b><br /><br />And that's how our app looks like so far:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-YuVQvTJ3OU0/UIA00sECLRI/AAAAAAAAFhM/R8mHYZhRnIE/s1600/mustache_screen.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://2.bp.blogspot.com/-YuVQvTJ3OU0/UIA00sECLRI/AAAAAAAAFhM/R8mHYZhRnIE/s1600/mustache_screen.png" /></a></div><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">As always the&nbsp;<a href="https://github.com/pocmo/Instant-Mustache/tree/article-05">source code&nbsp;of the current version</a> of the app is available at Github.</div></div><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/C01oUsX3kSI" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com1http://www.androidzeitgeist.com/2012/10/displaying-camera-preview-instant.htmltag:blogger.com,1999:blog-1531829516427013333.post-77570194732928184942012-10-15T19:28:00.002+02:002012-10-30T23:19:35.663+01:00Using a fragment for the camera preview - Instant Mustache #4<span style="font-size: x-small;">This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection.&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-size: small;">Click here</a><span style="font-size: x-small;">&nbsp;to get a chronological list of all published&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-size: small;">articles about Instant Mustache</a><span style="font-size: x-small;">.</span><br /><br />This article will be the first one about writing the CameraActivity for <a href="http://www.androidzeitgeist.com/p/instant-mustache.html">Instant Mustache</a>. From <a href="http://www.androidzeitgeist.com/2012/08/lets-start-coding-not-instant-mustache-3.html">the last article</a> we already know how the layout of the activity should look like. Now it's time to start the coding part.<br /><br />I won't cover all the lines of code in this and the following blog articles but you can always get the complete <a href="https://github.com/pocmo/Instant-Mustache">source code of Instant Mustache at GitHub</a>.<br /><br /><b>Using a fragment</b><br />We'll move the actual code (and layout) that handles the camera preview to a <a href="http://developer.android.com/guide/components/fragments.html">fragment</a>. Using fragments has several advantages:<br /><br /><ul><li>Fragments can be reused in different activities and layouts. Therefore they are perfect building blocks for composing UIs for different screen sizes.</li><li>They encapsulate the code for a specific component including the layout of the component. This makes the activity code and layout much more simpler and cleaner. By using a bunch of fragments the activity basically only has to handle events and delegate them to the appropriate fragments. This leads to the activity becoming some kind of light meta controller instead of an unreadable dumping ground for handling everything on the current screen.</li><li>Fragments can be dynamically added, removed, replaced, added to the back stack, animated and other cool things that can be painful to do yourself.</li></ul><div><b><br />Activity layout</b></div><div><div style="margin-bottom: 0in;">As said before we are moving the camera preview code and layout to a fragment. Therefore our activity's layout is really quite simple:<br /><br /></div><div style="margin-bottom: 0in;"><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><span style="margin-left: auto; margin-right: auto;"><a href="http://www.blogger.com/goog_154278281"><img border="0" src="http://1.bp.blogspot.com/-9A5F03FauP0/UHxDx3aMDcI/AAAAAAAAFfE/x245XxDRKJk/s1600/camera_activity_layout_2.png" /></a></span></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-04/res/layout/activity_camera.xml">activity_camera.xml</a></td></tr></tbody></table><br /></div><div style="margin-bottom: 0in;"><b>Communication between activity and fragment</b></div><div style="margin-bottom: 0in;"></div><div style="margin-bottom: 0in;">There are situations where the fragment needs to notify the activity about events. In our case the fragment needs to tell the activity when it's unable to instantiate a camera preview so that the activity can handle this error case. Of course we could just access the activity inside the fragment using <a href="http://developer.android.com/reference/android/app/Fragment.html#getActivity()">getActivity()</a> and cast it to a CameraActivity object to get access to a method like onCameraError() but then our fragment would only be usable with this particular activity:</div><div style="margin-bottom: 0in;"><br /></div><div style="margin-bottom: 0in;"></div><div style="margin-bottom: 0in;"><span style="color: #444444; font-family: Courier New, Courier, monospace;">CameraActivity activity = (CameraActivity) getActivity();</span></div><div style="margin-bottom: 0in;"><span style="color: #444444; font-family: Courier New, Courier, monospace;">activity.onCameraError();</span></div><div style="margin-bottom: 0in;"><br /></div><div style="margin-bottom: 0in;"></div><div style="margin-bottom: 0in;">We work around this issue by defining an interface that has to be implemented by the CameraActivity and every other component that wants to use the CameraFragment:</div><div style="margin-bottom: 0in;"><br /></div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/--DMu6Y45ciU/UHxBNXetSII/AAAAAAAAFe0/YrGtXiPkUXE/s1600/fragment_listener.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><span style="color: black;"><img border="0" src="http://2.bp.blogspot.com/--DMu6Y45ciU/UHxBNXetSII/AAAAAAAAFe0/YrGtXiPkUXE/s1600/fragment_listener.png" /></span></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-04/src/com/androidzeitgeist/mustache/listener/CameraFragmentListener.java"><span style="color: black; font-size: small;">CameraFragmentListener.java</span></a></td></tr></tbody></table>Every time our fragment gets attached to an activity <a href="http://developer.android.com/reference/android/app/Fragment.html#onAttach(android.app.Activity)">onAttach()</a> will be called with the activity as parameter. We use this method to enforce that the activity implements our defined interface:<br /><div style="margin-bottom: 0in;"><br /></div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><span style="margin-left: auto; margin-right: auto;"><a href="http://www.blogger.com/goog_154278245"><img border="0" src="http://3.bp.blogspot.com/-hGixG23tyHc/UHxBneeyqOI/AAAAAAAAFe8/VF7FmuzO8Jk/s1600/fragment_on_attach.png" /></a></span></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="https://github.com/pocmo/Instant-Mustache/blob/article-04/src/com/androidzeitgeist/mustache/fragment/CameraFragment.java">CameraFragment.java</a></td></tr></tbody></table><div style="margin-bottom: 0in;"></div><div style="margin-bottom: 0in;">Finally take a look at the <a href="https://github.com/pocmo/Instant-Mustache/blob/article-04/src/com/androidzeitgeist/mustache/activity/CameraActivity.java">CameraActivity source code on GitHub</a>. It just sets the layout in onCreate() and shows a <a href="http://developer.android.com/guide/topics/ui/notifiers/toasts.html">toast</a> in case of the fragment calling onCameraError(). As this method will be called in case of non-recoverable errors we'll also finish the activity.</div></div><br /><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/BCc8E5OcNig" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com2http://www.androidzeitgeist.com/2012/10/using-fragment-for-camera-preview.htmltag:blogger.com,1999:blog-1531829516427013333.post-89785809975449839842012-08-20T19:02:00.001+02:002012-10-30T23:19:51.789+01:00Know your resources: Integers and BooleansAn Android application isn't only code but comes with a bunch of <a href="http://developer.android.com/guide/topics/resources/index.html">resources</a>. Probably the most important resources (besides layouts and drawables) are the string resources. In conjunction with the <a href="http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources">resource qualifiers</a> they are not only perfect to externalize strings for localization but also for defining different internal configurations of your app.<br /><br />However sometimes string resources are overused. Especially when they are used to define boolean or integer values. Let's look at the following example. Code lines like the next ones can be found in several Android projects. For example you can find <a href="https://github.com/pocmo/Yaaic/blob/master/application/src/org/yaaic/model/Settings.java#L74">some of these in Yaaic</a>.<br /><br /><div class="separator" style="clear: both; text-align: center;"></div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-XLbaLF9yRos/UDJrT8HzfaI/AAAAAAAAFMk/6_ctbD-1rQ8/s1600/resources_example01.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-XLbaLF9yRos/UDJrT8HzfaI/AAAAAAAAFMk/6_ctbD-1rQ8/s1600/resources_example01.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Loading string resources and parsing as boolean or integer</td></tr></tbody></table><br />Or even worse in a condition without casting, doing a string comparison:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-IfOUvr3e9og/UDJrri2Gu3I/AAAAAAAAFMs/qB5wMlRTBzI/s1600/resources_example02.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://4.bp.blogspot.com/-IfOUvr3e9og/UDJrri2Gu3I/AAAAAAAAFMs/qB5wMlRTBzI/s1600/resources_example02.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Loading boolean as string resource and doing string comparison</td></tr></tbody></table><br />The code above is not wrong but instead of using string resources and parsing or comparing them it would be easier to use resources of the appropriate type. Fortunately Android allows to&nbsp;define <a href="http://developer.android.com/guide/topics/resources/more-resources.html#Bool">boolean</a> and <a href="http://developer.android.com/guide/topics/resources/more-resources.html#Integer">integer</a> resources too (since API level 1). It's basically the same process as defining a string resource in XML just use the bool and integer tags:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-BIkUDBXNXFU/UDJr4uQMhTI/AAAAAAAAFM0/39d0Vj3jIKo/s1600/xml_resources.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://4.bp.blogspot.com/-BIkUDBXNXFU/UDJr4uQMhTI/AAAAAAAAFM0/39d0Vj3jIKo/s1600/xml_resources.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Defining boolean and integer resources in XML</td></tr></tbody></table><br />After that you can access these resources in code. However there are no <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/content/Context.java#304">alias methods</a> on the <a href="http://developer.android.com/reference/android/content/Context.html">Context</a> object like for string resources. Therefore you need to get a <a href="http://developer.android.com/reference/android/content/res/Resources.html">Resources</a> instance first and then ask it for the defined resources.<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-bLP5ceuA0xY/UDOhAxoQunI/AAAAAAAAFNM/ONwuHscnEDw/s1600/accessing_resources.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-bLP5ceuA0xY/UDOhAxoQunI/AAAAAAAAFNM/ONwuHscnEDw/s1600/accessing_resources.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">Accessing integer and boolean resources from code</td></tr></tbody></table><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/SH5Bn82Meao" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com1http://www.androidzeitgeist.com/2012/08/know-your-resources-integers-and.htmltag:blogger.com,1999:blog-1531829516427013333.post-75676943030018017872012-08-01T21:01:00.002+02:002012-10-30T23:20:51.695+01:00Let's start coding ... NOT! - Instant Mustache #3<span style="font-size: x-small;">This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection.&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-size: small;">Click here</a><span style="font-size: x-small;">&nbsp;to get a chronological list of all published&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-size: small;">articles about Instant Mustache</a><span style="font-size: x-small;">.</span><br /><br />In the <a href="http://www.androidzeitgeist.com/p/instant-mustache.html">last two articles</a> about Instant Mustache we've talked a lot and it's about time to start coding! Yet I’ve to disappoint you for now. There still will be no code in this article. Before we’ll start coding we’ve to define what we actually need or want. From the last article we already know there will be two screens. But what we don’t know yet is how they should look like. So how will we figure out how the (very simple) UI will look like? Of course we can fire up our code editor or visual editor but there’s a much faster way to get results: Good old paper.<br /><br />I won’t talk about paper prototypes or UI development and user testing here. But there’s a better resource for that. The <a href="http://www.androiduipatterns.com/">Android UI Patterns blog</a> has a lot of articles published covering a variety of Android UI topics. Here we are going to just sketch some screens, play around and hopefully come up with an idea of how the app will feel like when it’s finally developed. As said before I'll use paper for that. Other people may like to use software for creating mockups (<a href="http://www.fluidui.com/">Fluid UI</a> seems to be a nice online tool for that). It's up to you what works the best for you. For me paper is the easiest way to try different ideas without the limitations of a software tool. But the important thing is: We won't write a lot of code that we need to throw away again after we realize that our initial idea may not be as good as we thought.<br /><br />The following photo shows a bunch of discarded drawings I came up with during brainstorming the UI:<br /><br /><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/-vLyg3OA870M/UBlqUI8HXhI/AAAAAAAAEeA/E3oDqTCMi9o/s1600/screens.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="176" src="http://2.bp.blogspot.com/-vLyg3OA870M/UBlqUI8HXhI/AAAAAAAAEeA/E3oDqTCMi9o/s400/screens.png" width="400" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"></div><b>The camera screen (CameraActivity)</b><br />The first screen the user will see after launching the app will be the camera screen. There are two main components we need: A camera preview and a button to take a photo. In addition to that we may want to reserve some space for future features like switching between cameras and mustaches.<br /><br />Let's take a look at the the final version of the camera screen as I've drawn it:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-ACfaRYTWXiQ/UBlrUkZlmPI/AAAAAAAAEe4/c5nw7R2I3EM/s1600/final_camera_activity.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://1.bp.blogspot.com/-ACfaRYTWXiQ/UBlrUkZlmPI/AAAAAAAAEe4/c5nw7R2I3EM/s1600/final_camera_activity.jpg" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">CameraActivity</td></tr></tbody></table>The following decisions I've made during drawing and experimenting:<br /><br /><ul><li>I want the app to have an <a href="http://developer.android.com/design/patterns/actionbar.html">ActionBar</a>. To be consistent I also want the ActionBar in the camera screen. I don't know yet if it's useful to show the app title "Instant Mustache" in the ActionBar as I've drawn it. It's quite long and may take up too much space. Furthermore the overflow menu drawn here may not be visible as we have no menu entries defined yet.</li><li>The camera picture will be a square. We'll have to define a picture ratio and a square may fit quite nice into the screen. The darker areas on the screen will grow or shrink depending on the screen size of the device and always center the camera preview.</li><li>There will be a bar at the bottom of the screen which will house the button for taking a picture. Here we will have enough space for adding more functionality in later releases.</li><li>Almost all activities showing a camera preview are fixed in their orientation. While moving the phone around to take a photo you don't want the phone to destroy the current activity, do the rotation and re-create the activity. Especially because the camera picture will be oriented correctly anyways because you are rotating the camera inside the phone as well. To satisfy the previous points we will fixate the orientation to portrait mode.</li></ul><br /><b>The photo screen (PhotoActivity)</b><br />After taking a photo you will see another screen showing the photo you've taken and you'll have the option to share the photo with other apps on your phone.<br /><br />That's how my final version of the photo screen looks like:<br /><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-ZkXDFTYoBTs/UBlv6nT4mRI/AAAAAAAAEfI/RGFW1HHcngE/s1600/final_share_activity.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="http://3.bp.blogspot.com/-ZkXDFTYoBTs/UBlv6nT4mRI/AAAAAAAAEfI/RGFW1HHcngE/s1600/final_share_activity.jpg" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">PhotoActivtiy</td></tr></tbody></table><div class="separator" style="clear: both; text-align: center;"><br /></div><div class="separator" style="clear: both; text-align: left;">The first version of this screen will be really simple:</div><div class="separator" style="clear: both; text-align: left;"></div><ul><li>At the top we'll have the ActionBar again. To share the photo we'll add a <a href="http://developer.android.com/guide/topics/ui/actionbar.html#ActionProvider">ShareActionProvider</a> that shows a list of available share targets as well as the most used app as an icon right beside it.</li><li>Below the ActionBar we'll show the taken photo and that's everything for now.</li></ul><div><b>What's next?</b></div><div>Now we've defined how our two screens will look like. In the next article we are going to launch our IDE and start writing the CameraActivity. I am curious to know what you think about the UI as described here and if you have other ideas. Let me know in the comments or on Google+.</div><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/xRHDRu4wROY" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com2http://www.androidzeitgeist.com/2012/08/lets-start-coding-not-instant-mustache-3.htmltag:blogger.com,1999:blog-1531829516427013333.post-26310402606800882312012-07-03T20:08:00.003+02:002012-10-30T23:21:12.300+01:00Minimal marketable app - Instant Mustache #2<span style="font-size: x-small;">This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection.&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-size: small;">Click here</a><span style="font-size: x-small;">&nbsp;to get a chronological list of all published&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-size: small;">articles about Instant Mustache</a><span style="font-size: x-small;">.</span><br /><b><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></b><b id="internal-source-marker_0.039026354206725955"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">In <a href="http://www.androidzeitgeist.com/2012/06/instant-mustache-1-idea.html">the last article</a> I described roughly the idea behind Instant Mustache. Now it's time to get more concrete. While doing so we try to follow the principle of the minimal marketable feature (MMF).</span></b><br /><br /><b><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Minimal marketable feature</span></b><br /><span id="internal-source-marker_0.039026354206725955"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">The idea behind the minimal marketable feature is to strip all aspects of a feature that are not necessarily needed to end up with a useful (or marketable) feature. After that you'll end up with smaller features that are easier and faster to develop. This is only a very rough explanation of MMF. You can find a way better <a href="http://www.upstarthq.com/2010/04/introduction-to-minimum-marketable-features-mmf/">Introduction to Minimum marketable feature</a> at the upstart blog.</span></span><br /><br /><b style="background-color: white; font-family: Arial; font-size: 15px; white-space: pre-wrap;">Minimal marketable app</b><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">In this case we are slightly modifying this idea to end up with something like a </span><span style="font-family: Arial; font-size: 15px; font-weight: bold; vertical-align: baseline; white-space: pre-wrap;">minimal marketable app</span><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">. This means we are going one level higher and strip all features that are not essentially required for a first releasable app. This does not mean that we won't develop these features at all but our first version will be without them enabling us to ship the app as early as possible. </span><br /><span style="background-color: white; font-family: Arial; font-size: 15px; white-space: pre-wrap;">Let's continue with an example. When you think about the app (<a href="http://www.androidzeitgeist.com/2012/06/instant-mustache-1-idea.html">see first article</a>) you will very fast come up with an idea like: The user should be able to select between a bunch of mustaches - more mustaches = more fun. But do we really need this feature when we launch the app? No, we don't. Our fun app will still be fun with one single mustache. Of course this is one of the first features we should have in the next release after the initial one.</span><br /><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">Another feature that's easy to come up with is switching between the cameras of a device. In most cases this means switching between back and front camera. Again for our basic app it's totally acceptable to strip this feature in the first release. The users of our app won't be able to take pictures of themselves easily and therefore they won't have much fun when there's no mustache-less friend to photograph around. Therefore we should rank this feature high as well to implement it right after the first release.</span><br /><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">In our case the minimal marketable feature set is an app that has two screens: A camera screen - with a camera preview and a button to take a picture - and a second screen that shows the picture you took and has an option to share this picture. The camera preview will show a live preview. Every detected face on the live preview will automatically have a mustache overlayed. If you take a picture the second screen will show the composed picture including the added mustaches. The user will be able to share the picture via the <a href="http://android-developers.blogspot.co.uk/2012/02/share-with-intents.html">Android intent system</a>.</span><br /><br /><b><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Roadmap and Milestones</span></b><br /><b id="internal-source-marker_0.039026354206725955"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">Nothing is more motivating than playing around with what you have created. In contrast nothing is more killing motivation than programming for ages without coming up with something that runs at all.</span><span style="vertical-align: baseline;"> </span><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">This leads us to the goal to always have a running prototype that step by step gets features added until it's ready to ship. So let's break the functionality into parts that can be implemented in order and always leave us with a working prototype that we can deploy on our phone and use at the next party.</span></b><br /><ul><li><span style="font-family: Arial;"><span style="font-size: 15px; white-space: pre-wrap;"><b>Milestone #1</b>: </span></span><b id="internal-source-marker_0.039026354206725955"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">A camera screen that shows the camera preview and has a button to take a photo. The photos will be saved on the SD card. After that we will end up with a basic camera app that we can use to take photos on the go. Goodbye native camera app!</span></b></li><li><b><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Milestone #2</span><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">: </span></b><b id="internal-source-marker_0.039026354206725955"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">We add the second screen. After taking a photo we’ll switch to this second screen which shows the taken photo and has an option to share the photo.</span></b></li><li><b><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Milestone #3</span><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">: </span></b><b id="internal-source-marker_0.039026354206725955"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">It’s time to add the face tracking. We’ll use the face tracking and display mustaches for every face on top of the camera preview.</span></b></li><li><b><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Milestone #4</span><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">: </span></b><b id="internal-source-marker_0.039026354206725955"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">When taking a photo we’ll compose the final photo using the information of the face tracking. The composed photo will contain mustaches like the preview screen before. The composed photo will be saved on the SD card and shown in the second screen. We are ready to release!</span></b></li></ul><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/D7VVl5yQcUE" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com2http://www.androidzeitgeist.com/2012/07/minimal-marketable-app-instant-mustache.htmltag:blogger.com,1999:blog-1531829516427013333.post-25713927705088424512012-06-08T12:14:00.002+02:002012-10-30T23:21:30.173+01:00Creating a MarqueeLayout with the Android Animation SystemWhen I posted the article about <a href="http://www.androidzeitgeist.com/2012/05/curious-blinklayout.html">the hidden BlinkLayout</a> inside Android’s LayoutInflater <a href="https://plus.google.com/105344175486242358933/posts">Thierry-Dimitri Roy</a> wrote on Google+:<br /><br /><a href="http://2.bp.blogspot.com/-kpn1WJrtNRw/T9CZQxI269I/AAAAAAAADnM/Pxbd7NWhWkM/s1600/gpluscomment.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em; text-align: center;"><img border="0" src="http://2.bp.blogspot.com/-kpn1WJrtNRw/T9CZQxI269I/AAAAAAAADnM/Pxbd7NWhWkM/s1600/gpluscomment.png" /></a><br /><br />That’s a challenge I accept! Back in the days when I worked at Jimdo we developed “<a href="http://www.youtube.com/watch?v=RDNhra-6dQo">a lifeboat for GeoCities</a>” which allowed users to migrate their GeoCities website to Jimdo before GeoCities finally shut down in 2009. So I’ve some kind of heart for&nbsp;GeoCities&nbsp;users.<br /><br />The <a href="http://developer.android.com/guide/topics/graphics/view-animation.html">view animation system</a> of Android makes it quite easy to develop something like a MarqueeLayout. All we need to do is to extend an existing ViewGroup and attach a marquee-like animation to every instance.<br /><br />The <a href="http://developer.android.com/reference/android/view/animation/TranslateAnimation.html">TranslateAnimation</a> does already exactly what we need: It moves a view from a starting position to an ending position. The two positions can either be declared absolute (position on the screen) or relative to the view or its parent. After that we only need to define the duration of the animation and Android will do the rest for us.<br /><br />We'll define the start and end positions of the animation by using coordinates relative to the view. When using relative coordinates you can think of our view having a size of 1x1 and it's top left corner placed at (0,0).<br /><br /><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-002il9hIkbs/T9CiYixSw3I/AAAAAAAADnY/-04SitxZqVg/s1600/view.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="http://2.bp.blogspot.com/-002il9hIkbs/T9CiYixSw3I/AAAAAAAADnY/-04SitxZqVg/s1600/view.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">View of size 1x1 at position (0,0)</td></tr></tbody></table><div class="separator" style="clear: both; text-align: left;"><br /></div><div class="separator" style="clear: both; text-align: left;">If our view's width stretches to the whole width of the screen we can consider the screen's size also 1 (relative to the view's width).</div><div class="separator" style="clear: both; text-align: left;"><br /></div><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-a8TAfL-nbQs/T9ClZz9tuxI/AAAAAAAADnk/qwDhuGD7DRU/s1600/view_on_screen.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="http://4.bp.blogspot.com/-a8TAfL-nbQs/T9ClZz9tuxI/AAAAAAAADnk/qwDhuGD7DRU/s1600/view_on_screen.png" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">View (green) filling full width of screen (grey)</td></tr></tbody></table><div class="separator" style="clear: both; text-align: left;"><br /></div><div style="text-align: left;">Assuming a screen size of 1 and a starting position on the right side outside of the screen gives us a relative starting position of (1,0). This will place our view exactly outside the screen (or it's parent).</div><div style="text-align: left;"><br /></div><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody><tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-wuSTX1TEt88/T9Cl3Z4JaxI/AAAAAAAADns/orVD4QJqXMg/s1600/start_at_1_0.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="231" src="http://2.bp.blogspot.com/-wuSTX1TEt88/T9Cl3Z4JaxI/AAAAAAAADns/orVD4QJqXMg/s320/start_at_1_0.png" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">View animation starting at (1,0)</td></tr></tbody></table><div class="separator" style="clear: both; text-align: left;"><br /></div><div style="text-align: left;">The view should move from the starting position to the left until it's outside of the screen at (-1, 0).</div><div style="text-align: left;"><br /></div><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-NOoImxh16nw/T9CmIXQJRqI/AAAAAAAADn0/OF_7nGDw9Pw/s1600/end_-1_0_1.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="231" src="http://4.bp.blogspot.com/-NOoImxh16nw/T9CmIXQJRqI/AAAAAAAADn0/OF_7nGDw9Pw/s320/end_-1_0_1.png" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;">View animation stopping at (-1,0)</td></tr></tbody></table><div class="separator" style="clear: both; text-align: left;"><br /></div><div style="text-align: left;">The animation system will generate all transient positions needed for the animation. Given all the information above we can write a simple MarqueeLayout in a few lines:</div><div style="text-align: left;"><br /></div><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody><tr><td style="text-align: center;"><span style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><a href="http://www.blogger.com/goog_1690609543"><img border="0" src="http://2.bp.blogspot.com/-OaTBb9uyHZ4/T9Cox5IvbMI/AAAAAAAADoA/bD9eXxmXu-Y/s1600/marquee_layout_code.png" /></a></span></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="http://source.androidzeitgeist.com/raw/marquee_layout_code.txt">MarqueeLayout.java</a></td></tr></tbody></table><div class="separator" style="clear: both; text-align: left;"><br /></div><div style="text-align: left;">That's what our MarqueeLayout looks like when adding a TextView to it:</div><div style="text-align: left;"><br /></div><div style="text-align: left;"><div class="separator" style="clear: both; text-align: left;"><iframe allowfullscreen="" frameborder="0" height="360" src="http://www.youtube.com/embed/r1LT2EpIB0s" width="480"></iframe></div><br /></div><div style="text-align: left;">The following code was used to set up an activity using our MarqueeLayout:</div><div style="text-align: left;"><br /></div><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody><tr><td style="text-align: center;"><span style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><a href="http://www.blogger.com/goog_1690609550"><img border="0" src="http://3.bp.blogspot.com/-VzGJqlPup70/T9CpDx20HUI/AAAAAAAADoI/iw61M_02ZuQ/s1600/marquee_activity.png" /></a></span></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="http://source.androidzeitgeist.com/raw/marquee_layout_activity.txt">MarqueeLayoutActivity.java</a></td></tr></tbody></table><div style="text-align: left;"><br /></div><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/5ogW6KCmbFc" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com1http://www.androidzeitgeist.com/2012/06/creating-marqueelayout-with-android.htmltag:blogger.com,1999:blog-1531829516427013333.post-89855408824596290062012-06-05T20:33:00.000+02:002012-10-30T23:21:46.957+01:00Instant Mustache #1 - The idea<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><span style="font-family: 'Times New Roman'; font-size: x-small; white-space: normal;">This article is part of a series of articles about the development process of Instant Mustache, a fun camera app that adds mustaches to all faces using face detection.&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-family: 'Times New Roman'; font-size: small; white-space: normal;">Click here</a><span style="font-family: 'Times New Roman'; font-size: x-small; white-space: normal;">&nbsp;to get a chronological list of all published&nbsp;</span><a href="http://www.androidzeitgeist.com/p/instant-mustache.html" style="font-family: 'Times New Roman'; font-size: small; white-space: normal;">articles about Instant Mustache</a><span style="font-family: 'Times New Roman'; font-size: x-small; white-space: normal;">.</span></span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><b><br /></b></span><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"><b>The idea</b></span><br /><span id="internal-source-marker_0.8338896373752505"><span style="font-family: Arial; vertical-align: baseline;"><span style="font-size: 15px; white-space: pre-wrap;">Instant Mustache is the name of an app that I'm going to develop. The idea is to show the development process of an app starting from a rough idea to a full featured app in the Android market. I'll demonstrate the process of developing the app as well as the thoughts and decisions involved. The source code will be publicly available on </span><a href="http://github.com/pocmo/Instant-Mustache" style="font-size: 15px; font-weight: normal; white-space: pre-wrap;">GitHub</a><span style="font-size: 15px; white-space: pre-wrap;">.</span></span></span><br /><span id="internal-source-marker_0.8338896373752505"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">Later versions of this series of articles are expected to be about topics like <i>refactoring</i>, adding <i>features</i>, <i>testing</i> and maybe <i>monetization</i>. I'll try to make everything as transparent as possible including user statistics of the Android market.</span></span><br /><br /><b><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">The app</span></b><br /><b id="internal-source-marker_0.8338896373752505"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">Instant Mustache is a fun app that utilizes the face tracking feature of Android 4.x to add mustaches to all detected faces currently visible to the camera. Users will be able to take funny pictures and share them with their friends on social networks or other apps on their mobile phone. The user shouldn't need to place the mustaches herself. Instead the placing should be done automatically for every detected face.</span></b><br /><div><span id="internal-source-marker_0.8338896373752505"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">This is a rough idea every developer can come up with. In the following postings we will refine the idea, plan the app with some basic wireframes and develop an elementary version that can be extended to match our planned full-featured app later.</span></span></div><div><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></div><div><span style="font-family: Arial;"><span style="font-size: 15px; white-space: pre-wrap;"><b>Do not forget the napkin</b></span></span></div><div><b id="internal-source-marker_0.8338896373752505"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">Of course as a good entrepreneur we had this world-changing idea on the go and had only time to sketch it on a napkin to not forget it later.</span><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">So here is the napkin we came up with:</span></b></div><div class="separator" style="clear: both; text-align: left;"></div><div><div class="separator" style="clear: both; text-align: left;"><a href="http://1.bp.blogspot.com/-fF1hf6-tlzA/T8ZmAQiTOzI/AAAAAAAADb4/ADS5E1ODlLU/s1600/instant_mustache_tissue.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="200" src="http://1.bp.blogspot.com/-fF1hf6-tlzA/T8ZmAQiTOzI/AAAAAAAADb4/ADS5E1ODlLU/s200/instant_mustache_tissue.jpg" width="200" /></a></div><b><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span></b></div><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/QNOIAC4E51A" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com2http://www.androidzeitgeist.com/2012/06/instant-mustache-1-idea.htmltag:blogger.com,1999:blog-1531829516427013333.post-90650865724884677382012-05-27T19:01:00.002+02:002012-10-30T23:22:02.346+01:00The curious BlinkLayout<span id="internal-source-marker_0.19517051335424185"><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">While reading the source code of Android's <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/view/LayoutInflater.java#LayoutInflater">LayoutInflater class</a> I found a hidden gem that seems to be quite unnoticed yet. Ladies and gentlemen I present you the mighty <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/view/LayoutInflater.java#LayoutInflater.BlinkLayout">BlinkLayout</a>. Views that are placed inside this ViewGroup blink at a rate of 500ms.</span><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">The BlinkLayout is an inner class of the LayoutInflater and can therefore only be used in a XML layout that will be parsed by a LayoutInflater instance. Due to the implementation it's only possible to use it as root node using the &lt;blink&gt; tag inside a XML layout.</span><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">It seems like the BlinkLayout is available since Android 4.0 and isn't used in the Android source code I observed. Maybe it was added for debugging reasons and was forgotten later.</span></span><br /><span style="font-family: Arial;"><span style="font-size: 15px; white-space: pre-wrap;"><br /></span></span><div class="separator" style="clear: both; text-align: center;"><object class="BLOGGER-youtube-video" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" data-thumbnail-src="http://i.ytimg.com/vi/o_EX1mH5ZvM/0.jpg" height="266" width="320"><param name="movie" value="http://www.youtube.com/v/o_EX1mH5ZvM?version=3&f=user_uploads&c=google-webdrive-0&app=youtube_gdata" /> <param name="bgcolor" value="#FFFFFF" /> <embed width="320" height="266" src="http://www.youtube.com/v/o_EX1mH5ZvM?version=3&f=user_uploads&c=google-webdrive-0&app=youtube_gdata" type="application/x-shockwave-flash"></embed></object></div><span style="font-family: Arial;"><span style="font-size: 15px; white-space: pre-wrap;"><br /></span></span><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;">T</span><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">he video above shows the BlinkLayout in action using the following layout XML:</span><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody><tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-2PBd4Bdwjr8/T8I-BukTXnI/AAAAAAAADZs/_z-Ajl7hOlo/s1600/blinklayout_xml.png" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img alt="" border="0" src="http://1.bp.blogspot.com/-2PBd4Bdwjr8/T8I-BukTXnI/AAAAAAAADZs/_z-Ajl7hOlo/s1600/blinklayout_xml.png" title="" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="http://source.androidzeitgeist.com/raw/blinklayout_view_xml.txt">main_layout.xml</a></td></tr></tbody></table><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br /><div class="separator" style="clear: both; text-align: center;"><br /></div><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">T</span><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">he following snippet was used to inflate the layout and pass it to the activity:</span><br /><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody><tr><td style="text-align: center;"><span style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><a href="http://www.blogger.com/goog_899898043"><img border="0" src="http://1.bp.blogspot.com/-zgP0dePQwzw/T8JIp8nqZ0I/AAAAAAAADaY/ZP7LER-JmM0/s1600/blinklayout_code.png" /></a></span></td></tr><tr><td class="tr-caption" style="text-align: center;"><a href="http://source.androidzeitgeist.com/raw/blinklayout_activity_code.txt">BlinkLayoutActivity.java</a><br /><br /></td></tr></tbody></table><div style="text-align: left;"><br /></div><span style="font-family: Arial;"><span style="font-size: 15px; white-space: pre-wrap;"><br /></span></span><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span><span style="font-family: Arial;"><span style="font-size: 15px; white-space: pre-wrap;"><br /></span></span><br /><span style="font-family: Arial;"><span style="font-size: 15px; white-space: pre-wrap;"><br /></span></span><span style="font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"><br /></span><img src="http://feeds.feedburner.com/~r/AndroidZeitgeist/~4/1MleyCfQAow" height="1" width="1" alt=""/>Sebastian Kasparihttps://plus.google.com/112283223674539938062noreply@blogger.com2http://www.androidzeitgeist.com/2012/05/curious-blinklayout.html diff --git a/mobile/android/tests/background/junit4/resources/feed_atom_planetmozilla.xml b/mobile/android/tests/background/junit4/resources/feed_atom_planetmozilla.xml new file mode 100644 index 000000000..1638ed9b1 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_atom_planetmozilla.xml @@ -0,0 +1,4996 @@ + + + + Planet Mozilla + 2016-01-26T19:01:54Z + Venus + + Planet Mozilla Module Team + planet@mozilla.org + + http://planet.mozilla.org/atom.xml + + + + + https://quality.mozilla.org/?p=49454 + + Firefox 45.0 Beta 3 Testday, February 5th +

Hello Mozillians, We are happy to announce that Friday, February 5th, we are organizing Firefox 45.0 Beta 3 Testday. We will be focusing our testing on the following features: Search Refactoring, Synced Tabs Menu, Text to Speech and Grouped Tabs Migration. Check out the … Continue reading
+
+

Hello Mozillians,

+

We are happy to announce that Friday, February 5th, we are organizing Firefox 45.0 Beta 3 Testday. We will be focusing our testing on the following features: Search Refactoring, Synced Tabs Menu, Text to Speech and Grouped Tabs Migration. Check out the detailed instructions via this etherpad.

+

No previous testing experience is required, so feel free to join us on #qa IRC channel where our moderators will offer you guidance and answer your questions.

+

Join us and help us make Firefox better! See you on Friday!

+
+ 2016-01-26T14:40:55Z + + + + + vasilica.mihasca + + + https://quality.mozilla.org + + + Driving quality across Mozilla with data, metrics and a strong community focus + Mozilla Quality Assurance + 2016-01-26T14:46:40Z + + + + + http://dlawrence.wordpress.com/?p=29 + + Happy BMO Push Day! +
the following changes have been pushed to bugzilla.mozilla.org: [1240575] Update form.reps.budget [1226028] API for batching MozReview requests discuss these changes on mozilla.tools.bmo.
+
+

the following changes have been pushed to bugzilla.mozilla.org:

+
    +
  • [1240575] Update form.reps.budget
  • +
  • [1226028] API for batching MozReview requests
  • +
+

discuss these changes on mozilla.tools.bmo.


+
+ 2016-01-26T14:27:50Z + + + dlawrence + + + https://dlawrence.wordpress.com + https://s2.wp.com/i/buttonw-com.png + + + + + Thoughts somehow related to web, linux, mobile and other things I am interested in + Dave's Ramblings + 2016-01-26T14:31:40Z + +
+ + + http://blog.mozilla.org/tanvi/?p=198 + + Updated Firefox Security Indicators +
This article has been coauthored by Aislinn Grigas, Senior Interaction Designer, Firefox Desktop Cross posting with Mozilla’s Security Blog November 3, 2015 Over the past few months, Mozilla has been improving the user experience of our privacy and security features in Firefox. One specific initiative has focused on the feedback shown in our address bar… Read more
+
+

This article has been coauthored by Aislinn Grigas, Senior Interaction Designer, Firefox Desktop
+ Cross posting with Mozilla’s Security Blog

+

November 3, 2015

+

Over the past few months, Mozilla has been improving the user experience of our privacy and security features in Firefox. One specific initiative has focused on the feedback shown in our address bar around a site’s security. The major changes are highlighted below along with the rationale behind each change.

+

+

Change to DV Certificate treatment in the address bar

+

Color and iconography is commonly used today to communicate to users when a site is secure. The most widely used patterns are coloring a lock icon and parts of the address bar green. This treatment has a straightforward rationale given green = good in most cultures. Firefox has historically used two different color treatments for the lock icon – a gray lock for Domain-validated (DV) certificates and a green lock for Extended Validation (EV) certificates. The average user is likely not going to understand this color distinction between EV and DV certificates. The overarching message we want users to take from both certificate states is that their connection to the site is secure. We’re therefore updating the color of the lock when a DV certificate is used to match that of an EV certificate.

+

Although the same green icon will be used, the UI for a site using EV certificates will continue to differ from a site using a DV certificate. Specifically, EV certificates are used when Certificate Authorities (CA) verify the owner of a domain. Hence, we will continue to include the organization name verified by the CA in the address bar.

+

Changes to Mixed Content Blocker UI on HTTPS sites

+

A second change we’re introducing addresses what happens when a page served over a secure connection contains Mixed Content. Firefox’s Mixed Content Blocker proactively blocks Mixed Active Content by default. Users historically saw a shield icon when Mixed Active Content was blocked and were given the option to disable the protection.

+

Since the Mixed Content state is closely tied to site security, the information should be communicated in one place instead of having two separate icons. Moreover, we have seen that the number of times users override mixed content protection is slim, and hence the need for dedicated mixed content iconography is diminishing. Firefox is also using the shield icon for another feature in Private Browsing Mode and we want to avoid making the iconography ambiguous.

+

The updated design that ships with Firefox 42 combines the lock icon with a warning sign which represents Mixed Content. When Firefox blocks Mixed Active Content, we retain the green lock since the HTTP content is blocked and hence the site remains secure.

+

For users who want to learn more about a site’s security state, we have added an informational panel to further explain differences in page security. This panel appears anytime a user clicks on the lock icon in the address bar.

+

Previously users could click on the shield icon in the rare case they needed to override mixed content protection. With this new UI, users can still do this by clicking the arrow icon to expose more information about the site security, along with a disable protection button.

+
mixed active content click and subpanel

Users can click the lock with warning icon and proceed to disable Mixed Content Protection.

+

+

Loading Mixed Passive Content on HTTPS sites

+

There is a second category of Mixed Content called Mixed Passive Content. Firefox does not block Mixed Passive Content by default. However, when it is loaded on an HTTPS page, we let the user know with iconography and text. In previous versions of Firefox, we used a gray warning sign to reflect this case.

+

We have updated this iconography in Firefox 42 to a gray lock with a yellow warning sign. We degrade the lock from green to gray to emphasize that the site is no longer completely secure. In addition, we use a vibrant color for the warning icon to amplify that there is something wrong with the security state of the page.

+

+

We also use this iconography when the certificate or TLS connection used by the website relies on deprecated cryptographic algorithms.

+

The above changes will be rolled out in Firefox 42. Overall, the design improvements make it simpler for our users to understand whether or not their interactions with a site are secure.

+

Firefox Mobile

+

We have made similar changes to the site security indicators in Firefox for Android, which you can learn more about here.

+
+ 2016-01-26T05:58:29Z + + + Tanvi Vyas + + + https://blog.mozilla.org/tanvi + + + Security Engineering - @TanviHacks + Tanvi's Blog + 2016-01-26T06:16:19Z + +
+ + + https://blog.mozilla.org/?p=9166 + + Firefox Can Now Get Push Notifications From Your Favorite Sites +
Firefox for Windows, Mac and Linux now lets you choose to receive push notifications from websites if you give them permission. This is similar to Web notifications, except now you can receive notifications for websites even when they’re not loaded … Continue reading
+
+

Firefox for Windows, Mac and Linux now lets you choose to receive push notifications from websites if you give them permission. This is similar to Web notifications, except now you can receive notifications for websites even when they’re not loaded in a tab. This is super useful for websites like email, weather, social networks and shopping, which you might check frequently for updates.

+

You can manage your notifications in the Control Center by clicking the 'I' Icon icon on the left side of the address bar.

+

Push Notifications for Web Developers
+ To make this functionality possible, Mozilla helped establish the Web Push W3C standard that’s gaining momentum across the Web. We also continue to explore the new design pattern known as Progressive Web Apps. If you’re a developer who wants to implement push notifications on your site, you can learn more in this Hacks blog post.

+

More information:

+
+
+ 2016-01-26T01:56:50Z + + + Mozilla + + + https://blog.mozilla.org + + + News, notes and ramblings from the Mozilla project + The Mozilla Blog + 2016-01-26T16:01:47Z + +
+ + + http://benoitgirard.wordpress.com/?p=651 + + Using RecordReplay to investigate intermittent oranges +
This is a quick write up to summarize my, and Jeff’s, experience, using RR to debug a fairly rare intermittent reftest failure. There’s still a lot of be learned about how to use RR effectively so I’m hoping sharing this will help others. Finding the root of the bad pixel First given a offending pixel […]
+
+

This is a quick write up to summarize my, and Jeff’s, experience, using RR to debug a fairly rare intermittent reftest failure. There’s still a lot of be learned about how to use RR effectively so I’m hoping sharing this will help others.

+

Finding the root of the bad pixel

+

First given a offending pixel I was able to set a breakpoint on it using these instructions. Next using rr-dataflow I was able to step from the offending bad pixel to the display item responsible for this pixel. Let me emphasize this for a second since it’s incredibly impressive. rr + rr-dataflow allows you to go from a buffer, through an intermediate surface, to the compositor on another thread, through another intermediate surface, back to the main thread and eventually back to the relevant display item. All of this was automated except for when the two pixels are blended together which is logically ambiguous. The speed at which rr was able to reverse continue through this execution was very impressive!

+

Here’s the trace of this part: rr-trace-reftest-pixel-origin

+

Understanding the decoding step

+

From here I started comparing a replay of a failing test and a non failing step and it was clear that the DisplayList was different. In one we have a nsDisplayBackgroundColor in the other we don’t. From here I was able to step through the decoder and compare the sequence. This was very useful in ruling out possible theories. It was easy to step forward and backwards in the good and bad replay debugging sessions to test out various theories about race conditions and understanding at which part of the decode process the image was rejected. It turned out that we sent two decodes, one for the metadata that is used to sized the frame tree and the other one for the image data itself.

+

Comparing the frame tree

+

In hindsight, it would have been more effective to start debugging this test by looking at the frame tree (and I imagine for other tests looking at the display list and layer tree) first would have been a quicker start. It works even better if you have a good and a bad trace to compare the difference in the frame tree. From here, I found that the difference in the layer tree came from a change hint that wasn’t guaranteed to come in before the draw.

+

The problem is now well understood: When we do a sync decode on reftest draw, if there’s an image error we wont flush the style hints since we’re already too deep in the painting pipeline.

+

Take away

+
    +
  • Finding the root cause of a bad pixel is very easy, and fast, to do using rr-dataflow.
  • +
  • However it might be better to look for obvious frame tree/display list/layer tree difference(s) first.
  • +
  • Debugging a replay is a lot simpler then debugging against non-determinist re-runs and a lot less frustrating too.
  • +
  • rr is really useful for race conditions, especially rare ones.
  • +

+
+ 2016-01-25T22:16:01Z + + + + benoitgirard + + + https://benoitgirard.wordpress.com + https://s2.wp.com/i/buttonw-com.png + + + + + My Programming Experiences + Benoit Girard's Blog + 2016-01-25T22:30:59Z + +
+ + + http://blog.servo.org/2016/01/25/twis-48/ + + These Weeks In Servo 48 +

In the last two weeks, we landed 130 PRs in the Servo organization’s repositories.

+ +

After months of work by vlad and many others, Windows support landed! Thanks to everyone who contributed fixes, tests, reviews, and even encouragement (or impatience!) to help us make this happen.

+ +

Notable Additions

+ +
    +
  • nikki added tests and support for checking the Fetch redirect count
  • +
  • glennw implemented horizontal scrolling with arrow keys
  • +
  • simon created a script that parses all of the CSS properties parsed by Servo
  • +
  • ms2ger removed the legacy reftest framework
  • +
  • fernando made crowbot able to rejoin IRC after it accidentally floods the channel
  • +
  • jack added testing the geckolib target to our CI
  • +
  • antrik fixed transfer corruption in ipc-channel on 32-bit
  • +
  • valentin added and simon extended IDNA support in rust-url, which is required for both web and Gecko compatibility
  • +
+ +

New Contributors

+ + + +

Screenshot

+ +

Screencast of this post being upvoted on reddit… from Windows!

+ +

(screencast)

+ +

Meetings

+ +

We had a meeting on some CI-related woes, documenting tags and mentoring, and dependencies for the style subsystem.

+
+ 2016-01-25T20:30:00Z + + http://blog.servo.org/ + + The Servo Blog + + + + Servo Blog + 2016-01-26T02:01:45Z + +
+ + + https://air.mozilla.org/mozilla-weekly-project-meeting-20160125/ + + Mozilla Weekly Project Meeting, 25 Jan 2016 +

+ Mozilla Weekly Project Meeting + The Monday Project Meeting +

+
+ 2016-01-25T19:00:00Z + + Air Mozilla + + + https://air.mozilla.org/ + + + Except where otherwise noted, content on this site is licensed under the Creative Commons Attribution Share-Alike License v3.0 or any later version. + Air Mozilla is the Internet multimedia presence of Mozilla, with live and pre-recorded shows, interviews, news snippets, tutorial videos, and features about the Mozilla community. + Air Mozilla + 2016-01-25T20:31:50Z + +
+ + + http://blog.mozilla.org/community/?p=2292 + + Firefox 44 new contributors +
With the release of Firefox 44, we are pleased to welcome the 28 developers who contributed their first code change to Firefox in this release, 23 of whom were brand new volunteers! Please join us in thanking each of these … Continue reading
+
+

With the release of Firefox 44, we are pleased to welcome the 28 developers who contributed their first code change to Firefox in this release, 23 of whom were brand new volunteers! Please join us in thanking each of these diligent and enthusiastic individuals, and take a look at their contributions:

+
+
+ 2016-01-25T16:21:33Z + + + Josh Matthews + + + http://blog.mozilla.org/community + + + News and notes from and for the Mozilla community. + about:community + 2016-01-25T16:31:42Z + +
+ + + tag:literaci.es,2014:Post/digital-skills-curriculum + + 3 things to consider when designing a digital skills framework +

Learning to credential

+ +

The image above was created by Bryan Mathers for our presentation at BETT last week. It shows the way that, in broad brushstrokes, learning design should happen. Before microcredentials such as Open Badges this was a difficult thing to do as both the credential and the assessment are usually given to educators. The flow tends to go backwards from credentials instead of forwards from what we want people to learn.

+ +

But what if you really were starting from scratch? How could you design a digital skills framework that contains knowledge, skills, and behaviours worth learning? Having written my thesis on digital literacies and led Mozilla’s Web Literacy Map for a couple of years, I’ve got some suggestions.

+

+ 1. Define your audience

+

One of the most important things to define is who your audience is for your digital skills framework. Is it for learners to read? Who are they? How old are they? Are you excluding anyone on purpose? Why / why not?

+ +

You might want to do some research and work around user personas as part of a user-centred design approach. This ensures you’re designing for real people instead of figments of your imagination (or, worse still, in line with your prejudices).

+ +

It’s also good practice to make the language used in the skills framework as precise as possible. Jargon is technical language used for the sake of it. There may be times when it’s impossible not to use a word (e.g. ’meme’). If you do this then link to a definition or include a glossary. It’s also useful to check the ‘reading level’ of your framework and, if you really want a challenge, try using Up-Goer Five language.

+

+ 2. Focus on verbs

+

It’s extremely easy, when creating a framework for learning, to fall into the 'knowledge trap’. Our aim when creating the raw materials from which someone can build a curriculum is to focus on action. Knowledge should make a difference in practice.

+ +

One straightforward way to ensure that you’re focusing on action rather than head knowledge is to use verbs when constructing your digital skills framework. If you’re familiar with Bloom’s Taxonomy, then you may find The Differentiator useful. This pairs verbs with the various levels of Bloom’s.

+

+ 3. Add version numbers

+

A framework needs to be a living, breathing thing. It should be subject to revision and updated often. For this reason, you should add version numbers to your documentation. Ideally, the latest version should be at a canonical URL and you should archive previous versions to static URLs.

+ +

I would also advise releasing the first version of your framework not as 'version 1.0’ but as 'v0.1’. This shows that you’re willing for others to provide input, that there will be further versions, and that you know you haven’t got it right first time (and forevermore).

+ +
+ +

Questions? Comments? Ask me on Twitter (@dajbelshaw). I also consult around this kind of thing, so hit me up on hello@dynamicskillset.com

+
+ 2016-01-25T14:46:34Z + 2016-01-25T14:46:34Z + + tag:literaci.es,2014:/feed + + Doug Belshaw + mail@dougbelshaw.com + http://literaci.es + + + + Literacies + 2016-01-25T14:46:34Z + +
+ + + https://fundraising.mozilla.org/?p=800 + + Why did you decide to donate today? +
This year, we asked some of our donors why they decided to donate to our end of year fundraising campaign. The Survey The Audience The survey was shown to a random sample of donors whose browser language was set to … Continue reading
+
+ 2016-01-25T13:31:34Z + + + + Adam Lofting + + + https://fundraising.mozilla.org + + + We work in the open, we fundraise in the open. This site shows you how we work, shares what we know, and challenges you to help us do it better. + Mozilla: View Source Fundraising » mozilla + 2016-01-25T13:31:34Z + +
+ + + http://www.agmweb.ca/robbie-burns + + Robbie Burns +

Tonight is Robbie Burns night, in honour of that great Scottish poet. But tonight had me thinking about another night in my past.

+ +

It was about 5 years ago, maybe less, I struggle to remember now. I was in the UK visiting family and my Dad was sick. Cancer and it's treatment is tough, you have good weeks, you have bad weeks and you have really fucking bad weeks. This was a good week and for some reason I was in the UK.

+ +

Myself, my brother and my sister-in-law went down to see him that night. It was Robbie Burns night and that meant an excuse for haggis, really, truly terrible scotch, Scottish dancing and all that. There are many times when I look back at time with my Dad in those last few years. This was definitely one of those times. He was my Dad at his best, cracking jokes and having fun. Living life to the absolute fullest, while you still have that chance.

+ +

We had a great night. That ended way too soon.

+ +

Not long after that the cancer came back and that was that.

+ +

But suddenly tonight, in a bar in Portland I had these memories of my Dad in a waistcoat cracking jokes and having fun on Robbie Burns night. No-one else in the bar seemed to know what night it was. You'd think Robbie Burns night might get a little bit more appreciation, but hey.

+ +

In the many years I've been running this blog I've never written about my Dad passing away. Here's the first time. I miss him.

+ +

Hey Robbie Burns? Thanks for making me remember that night.

+
+ 2016-01-25T08:00:00Z + + http://www.agmweb.ca/blog/andy + + Andy McKay + andy@clearwind.ca + + + + Andy McKay + 2016-01-26T06:33:30Z + +
+ + + tag:this-week-in-rust.org,2016-01-25:blog/2016/01/25/this-week-in-rust-115/ + + This Week in Rust 115 +

Hello and welcome to another issue of This Week in Rust! + Rust is a systems language pursuing the trifecta: + safety, concurrency, and speed. This is a weekly summary of its progress and + community. Want something mentioned? Tweet us at @ThisWeekInRust or send us an + email! + Want to get involved? We love + contributions.

+

This Week in Rust is openly developed on GitHub. + If you find any errors in this week's issue, please submit a PR.

+

This week's edition was edited by: nasa42, brson, and llogiq.

+

Updates from Rust Community

+

News & Blog Posts

+ +

Notable New Crates & Project Updates

+
    +
  • Are we concurrent yet?
  • +
  • GFX epic rewrite for the Pipeline State Objects paradigm has landed, described on the blog.
  • +
  • Herbie. A rustc plugin to check for numerical instability.
  • +
  • Dynamo. A rusty dynamically typed scripting language.
  • +
  • rust-vnc. An implementation of VNC protocol, client state machine and a client.
  • +
+

Updates from Rust Core

+

129 pull requests were merged in the last week.

+

See the triage digest and subteam reports for more details.

+

Notable changes

+ +

New Contributors

+
    +
  • Adrian Heine
  • +
  • Andrea Bedini
  • +
  • Guillaume Bonnet
  • +
  • Kamal Marhubi
  • +
  • Keith Yeung
  • +
  • Marc Bowes
  • +
  • Martin
  • +
  • mopp
  • +
  • Olaf Buddenhagen
  • +
  • Paul Dicker
  • +
  • Peter Kolloch
  • +
  • Stephen (Ziyun) Li
  • +
+

Approved RFCs

+

Changes to Rust follow the Rust RFC (request for comments) + process. These + are the RFCs that were approved for implementation this week:

+ +

Final Comment Period

+

Every week the team announces the + 'final comment period' for RFCs and key PRs which are reaching a + decision. Express your opinions now. This week's FCPs are:

+ +

New RFCs

+ +

Upcoming Events

+ +

If you are running a Rust event please add it to the calendar to get + it mentioned here. Email Erick Tryzelaar or Brian + Anderson for access.

+

fn work(on: RustProject) -> Money

+ +

Tweet us at @ThisWeekInRust to get your job offers listed here!

+

Crate of the Week

+

This week's Crate of the Week is racer which powers code completion in all Rust development environments.

+

Thanks to Steven Allen for the suggestion.

+

Submit your suggestions for next week!

+

Quote of the Week

+
+

Memory errors are fundamentally state errors, and Rust's move semantics, borrowing, and aliasing XOR mutating help enormously for me to reason about how my program changes state as it executes, to avoid accidental shared state and side effects at a distance. Rust more than any other language I know enables me to do compiler driven design. And internalizing its rules has helped me design better systems, even in other languages.

+
+

desiringmachines on /r/rust.

+

Thanks to dikaiosune for the suggestion.

+

Submit your quotes for next week!

+
+ 2016-01-25T05:00:00Z + + Corey Richardson + + + http://this-week-in-rust.org/ + + + This Week in Rust + 2016-01-25T05:00:00Z + +
+ + + tag:blogger.com,1999:blog-1015214236289077798.post-7056349209464984020 + + 38.6.0 available +
TenFourFox 38.6.0 is available for testing (downloads, hashes, release notes). I'm sorry it's been so quiet around here; I'm in the middle of a backbreaking Master's course, my last one before I'm finally done with the lousy thing, and I haven't had any time to start on 45 so far. 38.6 does have some other fixes in it, though: I think I found the last place where bookmark backups were being mistakenly saved in LZ4 based on Chris Trusch's report, and the problematic fonts on the iCloud login page are now blacklisted, so you should be able to login again. I can't do much more testing than that, however, since I don't use iCloud personally, so other lapses in font functionality will require the font URL and I'll add them to the blacklist in 38.7. The browser will go live Monday Pacific time as usual. (The temporary workaround is to set gfx.downloadable_fonts.enabled to false, and switch the setting back when you don't need it anymore.)

Speaking of, downloadable fonts were exactly the same problem on the Sun Ultra-3 laptop I've been refurbishing; Oracle still provides a free Solaris 10 build of 38ESR, but it crashes on web fonts for reasons I have yet to diagnose, so I just have them turned off. Yes, it really is a SPARC laptop, a rebranded Tadpole Viper, and I think the fastest one ever made in this form factor (a 1.2GHz UltraSPARC IIIi). It's pretty much what I expected the PowerBook G5 would have been -- hot, overthrottled and power-hungry -- but Tadpole actually built the thing and it's not a disaster, relatively speaking. There's no JIT in this Firefox build, the brand new battery gets only 70 minutes of runtime even with the CPU clock-skewed to hell, it stands a very good chance of rendering me sterile and/or medium rare if I actually use it in my lap and it had at least one sudden overtemp shutdown and pooped all over the filesystem, but between Firefox, Star Office and pkgsrc I can actually use it. More on that for laughs in a future post.

It has been pointed out to me that Leopard Webkit has not made an update in over three months, so hopefully Tobias is still doing okay with his port.

+
+ 2016-01-23T06:02:00Z + + ClassicHasClass + noreply@blogger.com + + + tag:blogger.com,1999:blog-1015214236289077798 + + + + + + + + + + + + + + + + + + + + + + + ClassicHasClass + noreply@blogger.com + + + + What's new in TenFourFox, the Mozilla browser for Power Macs. + TenFourFox Development + 2016-01-26T18:31:40Z + +
+ + + https://blog.mozilla.org/netpolicy/?p=907 + + Addressing the Chilling Effect of Patent Damages +
Last year, we unveiled the Mozilla Open Software Patent License as part of our Initiative to help limit the negative impacts that patents have on open source software. While those were an important first step for us, we continue to … Continue reading
+
+

Last year, we unveiled the Mozilla Open Software Patent License as part of our Initiative to help limit the negative impacts that patents have on open source software. While those were an important first step for us, we continue to do more. This past Wednesday, Mozilla joined several other tech and software companies in filing an amicus brief with the Supreme Court of the United States in the Halo and Stryker cases.

+

In the brief, we urge the Court to limit the availability of treble damages. Treble damages are significant because they greatly increase the amount of money owed if a defendant is found to “willfully infringe” a patent. As a result, many open source projects and technology companies will refuse to look into or engage in discussions about patents, in order to avoid even a remote possibility of willful infringement. This makes it very hard to address the chilling effects that patents can have on open source software development, open innovation, and collaborative efforts.

+

We hope that our brief will help the Court see how this legal standard has affected technology companies and persuade the Court to limit treble damages.

+
+ 2016-01-23T00:17:34Z + + + + + Elvin Lee + + + https://blog.mozilla.org/netpolicy + + + Mozilla's official blog on open Internet policy initiatives and developments + Open Policy & Advocacy + 2016-01-25T20:46:35Z + +
+ + + http://blog.mozilla.org/addons/?p=7640 + + Add-on Signing Update +
In Firefox 43, we made it a default requirement for add-ons to be signed. This requirement can be disabled by toggling a preference that was originally scheduled to be removed in Firefox 44 for release and beta versions (this preference … Continue reading
+
+

In Firefox 43, we made it a default requirement for add-ons to be signed. This requirement can be disabled by toggling a preference that was originally scheduled to be removed in Firefox 44 for release and beta versions (this preference will continue to be available in the Nightly, Developer, and ESR Editions of Firefox for the foreseeable future).

+

We are delaying the removal of this preference to Firefox 46 for a couple of reasons: We’re adding a feature in Firefox 45 that allows temporarily loading unsigned restartless add-ons in release, which will allow developers of those add-ons to use Firefox for testing, and we’d like this option to be available when we remove the preference. We also want to ensure that developers have adequate time to finish the transition to signed add-ons.

+

The updated timeline is available on the signing wiki, and you can look up release dates for Firefox versions on the releases wiki. Signing will be mandatory in the beta and release versions of Firefox from 46 onwards, at which point unbranded builds based on beta and release will be provided for testing.

+
+ 2016-01-22T22:40:59Z + + + + + Kev Needham + + + https://blog.mozilla.org/addons + + + Mozilla Add-ons Blog + 2016-01-25T20:46:40Z + +
+ + + http://coopcoopbware.tumblr.com/post/137832199980 + + RelEng & RelOps Weekly Highlights - January 22, 2016 +

wine-and-piesReleng: drinkin’ wine and makin’ pies.
It’s encouraging to see more progress this week on both the build/release promotion and TaskCluster migration fronts, our two major efforts for this quarter.

+ +

Modernize infrastructure:

+

In a continuing effort to enable faster, more reliable, and more easily-run tests for TaskCluster components, Dustin landed support for an in-memory, credential-free mock of Azure Table Storage in the azure-entities package. Together with the fake mock support he added to taskcluster-lib-testing, this allows tests for components like taskcluster-hooks to run without network access and without the need for any credentials, substantially decreasing the barrier to external contributions.

+ +

All release promotion tasks are now signed by default. Thanks to Rail for his work here to help improve verifiability and chain-of-custody in our upcoming release process. (https://bugzil.la/1239682) + Beetmover has been spotted in the wild! Jordan has been working on this new tool as part of our release promotion project. Beetmover helps move build artifacts from one place to another (generally between S3 buckets these days), but can also be extended to perform validation actions inline, e.g. checksums and anti-virus. (https://bugzil.la/1225899)

+ +

Dustin configured the “desktop-test” and “desktop-build” docker images to build automatically on push. That means that you can modify the Dockerfile under `testing/docker`, push to try, and have the try job run in the resulting image, all without pushing any images. This should enable much quicker iteration on tweaks to the docker images. Note, however, that updates to the base OS images (ubuntu1204-build and centos6-build) still require manual pushes.

+ +

Mark landed Puppet code for base windows 10 support including secrets and ssh keys management.

+ +

Improve CI pipeline:

+ +

Vlad and Amy repurposed 10 Windows XP machines as Windows 7 to improve the wait times in that test pool (https://bugzil.la/1239785) + Armen and Joel have been working on porting the Gecko tests to run under TaskCluster, and have narrowed the failures down to the single digits. This puts us on-track to enable Linux debug builds and tests in TaskCluster as the canonical build/test process.

+ +

Release:

+ +

Ben finished up work on enhanced Release Blob validation in Balrog (https://bugzil.la/703040), which makes it much more difficult to enter bad data into our update server.

+ +

You may recall Mihai, our former intern who we just hired back in November. Shortly after joining the team, he jumped into the releaseduty rotation to provide much-needed extra bandwidth. The learning curve here is steep, but over the course of the Firefox 44 release cycle, he’s taken on more and more responsibility. He’s even volunteered to do releaseduty for the Firefox 45 release cycle as well. Perhaps the most impressive thing is that he’s also taken the time to update (or write) the releaseduty docs so that the next person who joins the rotation will be that much further ahead of the game. Thanks for your hard work here, Mihai!

+ +

Operational:

+ +

Hal did some cleanup work to remove unused mozharness configs and directories from the build mercurial repos. These resources have long-since moved into the main mozilla-central tree. Hopefully this will make it easier for contributors to find the canonical copy! (https://bugzil.la/1239003)

+ +

Hiring:

+ +

We’re still hiring for a full-time Build & Release Engineer, and we are still accepting applications for interns for 2016. Come join us!

+ +

Well, I don’t know about you, but all that hard work makes me hungry for pie. See you next week!

+
+ 2016-01-22T20:49:38Z + + + + + http://coopcoopbware.tumblr.com/ + + Chris Cooper + + + + Five different types of fried cheese + 2016-01-22T21:00:12Z + +
+ + + https://air.mozilla.org/foundation-demos-january-22-2016/ + + Foundation Demos January 22 2016 +

+ Foundation Demos January 22 2016 + Mozilla Foundation Demos January 22 2016 +

+
+ 2016-01-22T18:00:00Z + + Air Mozilla + + + https://air.mozilla.org/ + + + Except where otherwise noted, content on this site is licensed under the Creative Commons Attribution Share-Alike License v3.0 or any later version. + Air Mozilla is the Internet multimedia presence of Mozilla, with live and pre-recorded shows, interviews, news snippets, tutorial videos, and features about the Mozilla community. + Air Mozilla + 2016-01-25T20:31:50Z + +
+ + + http://blog.mozilla.org/sumo/?p=3667 + + What’s up with SUMO – 22nd January +
Hello, SUMO Nation! The third week of the new year is already behind us. Time flies when you’re not paying attention… What are you going to do this weekend? Let us know in the comments, if you feel like sharing … Continue reading
+
+

Hello, SUMO Nation!

+

sumo_logoThe third week of the new year is already behind us. Time flies when you’re not paying attention… What are you going to do this weekend? Let us know in the comments, if you feel like sharing :-) I hope to be in the mountains, getting some fresh (bracing) air, and enjoying nature.

+

Welcome, new contributors!
+

+ +
If you just joined us, don’t hesitate – come over and say “hi” in the forums!
+
+
+

Contributors of the week
+

+ +
+

We salute you!

+
+
Don’t forget that if you are new to SUMO and someone helped you get started in a nice way you can nominate them for the Buddy of the Month!
+
+
+

Most recent SUMO Community meeting

+ +

The next SUMO Community meeting…

+
    +
  • is happening on Monday the 25th – join us!
  • +
  • Reminder: if you want to add a discussion topic to the upcoming meeting agenda: +
      +
    • Start a thread in the Community Forums, so that everyone in the community can see what will be discussed and voice their opinion here before Monday (this will make it easier to have an efficient meeting).
    • +
    • Please do so as soon as you can before the meeting, so that people have time to read, think, and reply (and also add it to the agenda).
    • +
    • If you can, please attend the meeting in person (or via IRC), so we can follow up on your discussion topic during the meeting with your feedback.
    • +
    +
  • +
+

Developers

+ +

mission_developers

+

Social

+ +

Community

+ +

hero_support

+
+
+

Localization

+
+
+
+ +
+
+

Firefox
+

+ +
    +
  • for Desktop +
      +
    • Heads up – next week should be release week! Keep your eyes peeled ;-)
    • +
    +
  • +
+
    +
  • for iOS +
    +
      +
    • No news from the world of Firefox for iOS this week.
    • +
    +
    +
  • +
+
+

Thank you for reading all the way down here… More to come next week! You know where to find us, so see you around – keep rocking the open & helpful web!

+ + 2016-01-22T17:43:56Z + + + Michał + + + https://blog.mozilla.org/sumo + + + SUpport MOzilla's official blog - rocking the helpful web since 2008! + SUMO Blog + 2016-01-25T09:31:47Z + + + + + https://air.mozilla.org/bay-area-rust-meetup-january-2016/ + + Bay Area Rust Meetup January 2016 +

+ Bay Area Rust Meetup January 2016 + Bay Area Rust meetup for January 2016. Topics TBD. +

+
+ 2016-01-22T03:00:00Z + + Air Mozilla + + + https://air.mozilla.org/ + + + Except where otherwise noted, content on this site is licensed under the Creative Commons Attribution Share-Alike License v3.0 or any later version. + Air Mozilla is the Internet multimedia presence of Mozilla, with live and pre-recorded shows, interviews, news snippets, tutorial videos, and features about the Mozilla community. + Air Mozilla + 2016-01-25T20:31:49Z + +
+ + + https://blog.lizardwrangler.com/?p=3953 + + Honored to Participate in New UN Panel on Women’s Economic Empowerment + Women’s economic empowerment is necessary for many reasons. It is necessary to bring health, safety and opportunity to half of humanity. It is necessary to bring investment and health to families and communities. It is necessary to unlock economic growth and build more stable societies. Today the UN Secretary General Ban Ki-moon launched the first […] + 2016-01-22T02:45:58Z + + + Mitchell Baker + + + http://blog.lizardwrangler.com + + + Mitchell's Blog + 2016-01-22T03:00:15Z + + + + + https://blog.mozilla.org/webdev/?p=4082 + + Beer and Tell – January 2016 +
Once a month, web developers from across the Mozilla Project get together to talk about our side projects and drink, an occurrence we like to call “Beer and Tell”. There’s a wiki page available with a list of the presenters, … Continue reading
+
+

Once a month, web developers from across the Mozilla Project get together to talk about our side projects and drink, an occurrence we like to call “Beer and Tell”.

+

There’s a wiki page available with a list of the presenters, as well as links to their presentation materials. There’s also a recording available courtesy of Air Mozilla.

+

shobson: CSS-Only Disco Ball

+

First up was shobson with a cool demo of an animated disco ball made entirely with CSS. The demo uses a repeated radial gradient for the background, and linear gradients plus a border radius for the disco ball itself. The demo was made for use in shobson’s WordCamp talk about debugging CSS. A blog post with notes from the talk is available as well.

+

craigcook: Proton – A CSS Framework for Prototyping

+

Next was craigcook, who presented Proton. It’s a CSS framework that is intentionally ugly to encourage use for prototypes only. Unlike other CSS frameworks, the temptation to reuse the classes from the framework in your final page doesn’t occur, which helps avoid the presentational classes that plague sites built using a framework normally.

+

Proton’s website includes an overview of the layout and components provided, as well as examples of prototypes made using the framework.

+
+

If you’re interested in attending the next Beer and Tell, sign up for the dev-webdev@lists.mozilla.org mailing list. An email is sent out a week beforehand with connection details. You could even add yourself to the wiki and show off your side-project!

+

See you next month!

+
+ 2016-01-21T18:56:46Z + + + Michael Kelly + + + https://blog.mozilla.org/webdev + + + For make benefit of glorious tubes + Mozilla Web Development + 2016-01-21T19:01:37Z + +
+ + + http://blog.mozilla.org/community/?p=2287 + + This Month at Mozilla +
A lot of exciting things are happening with Participation at Mozilla this month. Here’s a quick round-up of some of the things that are going on! Mozillians Profiles Got a Facelift: Since the start of this year, the Participation Infrastructure … Continue reading
+
+

A lot of exciting things are happening with Participation at Mozilla this month. Here’s a quick round-up of some of the things that are going on!

+

Mozillians Profiles Got a Facelift:

+

Since the start of this year, the Participation Infrastructure team has had a renewed focus on making mozillians.org a modern community directory to meet Mozilla’s growing needs.

+

Their first target for 2016 was to improve the UX on the profile edit interface.

+

new-profile-768x548
+ ”We chose it due to relatively self-contained nature of it, and cause many people were not happy with the current UX. After research of existing tools and applying latest best practices, we designed, coded and deployed a new profile edit interface (which by the way is renamed to Settings now) that we are happy to deliver to all Mozillians.”

+

Read the full blog here!

+

There are New Ways to Bring Your Design Skills to Mozilla:

+

Are you a passionate designer looking to contribute to Mozilla? You’ll be happy to hear there is a new way to contribute to the many design projects around Mozilla! Submit issues, find collaborators, and work on open source projects by getting involved!

+
    +
  • You can check out the projects looking for help, or submit your own on the GitHub Repo.
  • +
  • Sign-up to the mailing list to be added as a contributor to the Repo, added to the regular meeting list, and to get emails about GitHub trainings and more!
  • +
  • And read a blogpost about the project and its first meeting.
  • +
+

Learn more here.

+

136 Volunteers Are Going to Singapore:

+

This weekend 136 participation leaders from all over the world are heading to Singapore to undergo two days of leadership training to develop the skills, knowledge and attitude to lead Participation in 2016.

+
Photo credit @thephoenixbird on Twitter

Photo credit @thephoenixbird on Twitter

+

If you know someone attending don’t forget to share your questions and goals with them, and follow along over the weekend by watching the hashtag #MozSummit.

+

Stay tuned after the event for a debrief of the weekend!

+

Friday’s Plenary from Mozlando is now public on Air Mozilla:

+

If you’re interested in learning more about all the exciting new features, projects, and plans that were presented at Mozlando look no further! You can now watch the final plenary sessions on Air Mozilla (it’s a lot of fun so I highly recommend it!) here.

+

Share your questions and comments on discourse here.

+

Look forward to more updates like these in the coming months!

+
+ 2016-01-21T17:58:33Z + + + + + + + Lucy Harris + + + http://blog.mozilla.org/community + + + News and notes from and for the Mozilla community. + about:community + 2016-01-25T16:31:42Z + +
+ + + https://blog.mozilla.org/netpolicy/?p=912 + + Prioritizing privacy: Good for business +
This was originally posted at StaySafeOnline.org in advance of Data Privacy Day. Data Privacy Day – which arrives in just a week – is a day designed to raise awareness and promote best practices for privacy and data protection. It … Continue reading
+
+

This was originally posted at StaySafeOnline.org in advance of Data Privacy Day.

+

Data Privacy Day – which arrives in just a week – is a day designed to raise awareness and promote best practices for privacy and data protection. It is a day that looks to the future and recognizes that we can and should do better as an industry. It reminds us that we need to focus on the importance of having the trust of our users.

+

We seek to build trust so we can collectively create the Web our users want – the Web we all want.

+

That Web is based on relationships, the same way that the offline world is. When I log in to a social media account, schedule a grocery delivery online or browse the news, I’m relying on those services to respect my data. While companies are innovating their products and services, they need to be innovating on user trust as well, which means designing to address privacy concerns – and making smart choices (early!) about how to manage data.

+

A recent survey by Pew highlights the thought that each user puts into their choices – and the contextual considerations in various scenarios. They concluded that many participants were annoyed and uncertain by how their information was used, and they are choosing not to interact with those services that they don’t trust. This is a clear call to businesses to foster more trust with their users, which starts by making sure that there are people empowered within your company to ask the right questions: what do your users expect? What data do you need to collect? How can you communicate about that data collection? How should you protect their data? Is holding on to data a risk, or should you delete it?

+

It’s crucial that users are a part of this process – consumers’ data is needed to offer cool, new experiences and a user needs to trust you in order to choose to give you their data. Pro-user innovation can’t happen in a vacuum – the system as it stands today isn’t doing a good job of aligning user interests with business incentives. Good user decisions can be good business decisions, but only if we create thoughtful user-centric products in a way that closes the feedback loop so that positive user experiences are rewarded with better business outcomes.

+

Not prioritizing privacy in product decisions will impact the bottom line. From the many data breaches over the last few years to increasing evidence of eroding trust in online services, data practices are proving to be the dark horse in the online economy. When a company loses user trust, whether on privacy or anything else, it loses customers and the potential for growth.

+

Privacy means different things to different people but what’s clear is that people make decisions about the products and services that they use based on how those companies choose to treat their users. Over this time, the Internet ecosystem has evolved, as has its relationship with users – and some aspects of this evolution threaten the trust that lies at the heart of that relationship. Treating a user as a target – whether for an ad, purchase, or service – undermines the trust and relationship that a business may have with a consumer.

+

The solution is not to abandon the massive value that robust data can bring to users, but rather, to collect and use data leanly, productively and transparently. At Mozilla, we have created a strong set of internal data practices to ensure that data decisions align with our privacy principles. As an industry, we need to keep users at the center of the product vision rather than viewing them as targets of the product – it’s the only way to stay true to consumers and deliver the best, most trusted experiences possible.

+

Want to hear more about how businesses can build relationships with their users by focusing on trust and privacy? We’re holding events in Washington, D.C., and San Francisco with some of our partners to talk about it. Please join us!

+
+ 2016-01-21T17:42:00Z + + + + + Heather West + + + https://blog.mozilla.org/netpolicy + + + Mozilla's official blog on open Internet policy initiatives and developments + Open Policy & Advocacy + 2016-01-25T20:46:35Z + +
+ + + https://tacticalsecret.com/tag/mozilla/rss/9c39ad13-14ae-4456-a84e-13612637d832 + + Issuance Rate for Let's Encrypt +

Gathering data from Certificate Transparency logs, here's a snapshot in time of Let's Encrypt's certificate issuance rate per minute from 7-21 January 2016. On 20 January, DreamHost launched formal support for Let's Encrypt, which coincides with a rate increase.

+ +

Note: This is mostly an experimental post with embedding charts; I've

+
+

Gathering data from Certificate Transparency logs, here's a snapshot in time of Let's Encrypt's certificate issuance rate per minute from 7-21 January 2016. On 20 January, DreamHost launched formal support for Let's Encrypt, which coincides with a rate increase.

+ +

Note: This is mostly an experimental post with embedding charts; I've more data in the queue.

+ +

Let's Encrypt Issuance Rate per Minute

+ +
+ + 2016-01-21T17:07:25Z + + + + + James 'J.C.' Jones + + + https://tacticalsecret.com/ + + + On a mission to solve information security issues for the whole Internet. That, and whatever else comes up. + mozilla - The Internet of Secure Things + 2016-01-21T17:16:43Z + + + + + https://air.mozilla.org/web-qa-weekly-meeting-20160121/ + + Web QA Weekly Meeting, 21 Jan 2016 +

+ Web QA Weekly Meeting + This is our weekly gathering of Mozilla'a Web QA team filled with discussion on our current and future projects, ideas, demos, and fun facts. +

+
+ 2016-01-21T17:00:00Z + + Air Mozilla + + + https://air.mozilla.org/ + + + Except where otherwise noted, content on this site is licensed under the Creative Commons Attribution Share-Alike License v3.0 or any later version. + Air Mozilla is the Internet multimedia presence of Mozilla, with live and pre-recorded shows, interviews, news snippets, tutorial videos, and features about the Mozilla community. + Air Mozilla + 2016-01-25T20:31:49Z + +
+ + + http://soledadpenades.com/?p=6379 + + + No more tap tap tap sounds: yay! +
A few days ago the fantastic Fritz from the Netherlands told me that my Hands On Web Audio slides had stopping working and there was no sound coming out from them in Firefox. @supersole oh noes! I reopened your slides: https://t.co/SO35UfljMI and it doesn't work in @firefox anymore 😱 (works in chrome though.. 😢) — … Continue reading No more tap tap tap sounds: yay!
+
+

A few days ago the fantastic Fritz from the Netherlands told me that my Hands On Web Audio slides had stopping working and there was no sound coming out from them in Firefox.

+ +

+

Which is pretty disappointing for a slide deck that is built to teach you about Web Audio!

+

I noticed that the issue was only on the introductory slide which uses a modified version of Stuart Memo’s fantastic THX sound recreation-the rest of slides did play sound.

+

I built an isolated test case (source) that used a parameter-capable version of the THX sound code, just in case the issue depended on the number of oscillators, and submitted this funnily titled bug to the Web Audio component: Entirely Web Audio generated sound cuts out after a little while, or emits random tap tap tap sounds then silence.

+

I can happily confirm that the bug has been fixed in Nightly and the fix will hopefully be “uplifted” to DevEdition very soon, as it was due to a regression.

+

Paul Adenot (who works in Web Audio and is a Web Audio spec editor, amongst a couple tons of other cool things) was really excited about the bug, saying it was very edge-casey! Yay! And he also explained what did actually happen in lay terms: “you’d have to have a frequency that goes down very very slowly so that the FFT code could not keep up”, which is what the THX sound is doing with the filter frequency automation.

+

I want to thank both Fritz for spotting this out and letting me know and also Stuart for sharing his THX code. It’s amazing what happens when you put stuff on the net and lots of different people use it in different ways and configurations. Together we make everything more robust :-)

+

Of course also sending thanks to Paul and Ben for identifying and fixing the issue so fast! It’s not been even a week! Woohoo!

+

Well done everyone! 👏🏼

+

flattr this!

+
+ 2016-01-21T15:49:05Z + + + + + + + + sole + + + http://soledadpenades.com + + + repeat 4[fd 100 rt 90] + mozilla – soledad penadés + 2016-01-26T02:46:28Z + +
+ + + http://pierros.papadeas.gr/?p=447 + + Mozillians.org Profile Edit refresh +
Since the start of this year, Participation Infrastructure team has a renewed focus on making mozillians.org a modern community directory to meet Mozilla’s growing needs. This will not be an one-time effort. We need to invest technically and programmatically in … Continue reading
+
+

Since the start of this year, Participation Infrastructure team has a renewed focus on making mozillians.org a modern community directory to meet Mozilla’s growing needs. This will not be an one-time effort. We need to invest technically and programmatically in order to deliver a first-class product that will be the foundation for identity management across the Mozilla ecosystem.

+

Mozillians.org is full of functionality as it is today, but is paying the debt of being developed by 5 different teams over the past 5 years. We started simple this time. Updated all core technology pieces, did privacy and security reviews, and started the process of consolidating and modernizing many of the things we do in the site.

+

Our first target was Profile Edit. We chose it due to relatively self-contained nature of it, and cause many people were not happy with the current UX. After research of existing tools and applying latest best practices, we designed, coded and deployed a new profile edit interface (which by the way is renamed to Settings now) that we are happy to deliver to all Mozillians.

+

new-profileHave a look for yourself and don’t miss the chance to update your profile while you do it!

+

Nikos (on the front-end), Tasos and Nemo (on the back-end) worked hard to deliver this in a speedy manner (as they are used to), and the end result is a testament to what is coming next on Mozillians.org.

+

Our next target? Groups. Currently it is obscure and unclear what all those settings in groups are, what is the functionality and how teams within Mozilla will be using it. We will be tackling this soon. After that, search and stats will be our attention, in an ongoing effort to fortify mozillians.org functionality. Stay tuned, and as always feel free to file bugs and contribute in the process.

+
+ 2016-01-21T11:41:39Z + + + + + + + + + + Pierros Papadeas + + + http://pierros.papadeas.gr + + + whereabouts of a life + mozilla – Pierro's Spot + 2016-01-21T11:45:53Z + +
+ + + http://adamlofting.com/?p=1396 + + Blog posts I haven’t written lately +
Last year I joked… Thinking about writing a blog post listing the blog posts I’ve been meaning to write… Maybe that will save some time — Adam Lofting (@adamlofting) November 20, 2015 Now, it has come to this. 9 blog posts I’ve not been writing Working on working on the impact of impact Designing Games … Continue reading Blog posts I haven’t written lately
+
+

Last year I joked…

+ +

+

Now, it has come to this.

+

9 blog posts I’ve not been writing

+
    +
  • Working on working on the impact of impact
  • +
  • Designing Games in my free time
  • +
  • Moving Out (the board game)
  • +
  • Mozilla Foundation 2016 KPIs
  • +
  • Studying Network Science
  • +
  • Learning Analytics plans for 2016
  • +
  • Daily practice / you are what you do every day
  • +
  • Several more A/B tests to write up from the fundraising campaign
  • +
  • CRM Progress in 2015
  • +
+

But my most requested blog by far, is an update on the status of my shed / office that I was tagging on to the end my blog posts at this time last year. Many people at Mozfest wanted to know about the shed… so here it is.

+

This time last year:

+ +

+

Some pictures from this morning:

+

office1

+

office2

+

It’s a pretty nice place to work now and it doubles as useful workshop on the weekends. It needs a few finishing touches, but the law of diminishing returns means those finishing touches are lower priority than work that needs to be done elsewhere in the house and garden. So it’ll stay like this a while longer.

+
+
+ 2016-01-21T09:44:24Z + + + + + + + http://adamlofting.com/1396/blog-posts-i-havent-written-lately/ + + Adam + + + http://adamlofting.com + + + + Thinking out loud about metrics, systems, human experience and the web. + Adam Lofting + 2016-01-21T09:46:30Z + +
+ + + http://blog.ziade.org/2016/01/21/a-pelican-web-editor/ + + A Pelican web editor +

The benefit of being a father again (Freya my 3rd child, was born last week) is + that while on paternity leave & between two baby bottles, I can hack on fun stuff.

+

A few months ago, I've built for my running club a Pelican-based website, check it out + at : http://acr-dijon.org. Nothing's special about it, except that I am not + the one feeding it. The content is added by people from the club that have zero + knowledge about softwares, let alone stuff like vim or command line tools.

+

I set up a github-based flow for them, where they add content through the + github UI and its minimal reStructuredText preview feature - and then a few + of my crons update the website on the server I host. + For images and other media, they are uploading them via FTP using FireSSH in Firefox.

+

For the comments, I've switched from Disqus to ISSO + after I got annoyed by the fact that it was impossible to display a simple Disqus + UI for people to comment without having to log in.

+

I had to make my club friends go through a minimal + reStructuredText syntax training, and things are more of less working now.

+

The system has a few caveats though:

+
    +
  • it's dependent on Github. I'd rather have everything hosted on my server.
  • +
  • the github restTRucturedText preview will not display syntax errors and warnings + and very often, articles get broken
  • +
  • the resulting reST is ugly, and it's a bit hard to force my editors to be stricter + about details like empty lines, not using tabs etc.
  • +
  • adding folders or organizing articles from Github is a pain
  • +
  • editing the metadata tags is prone to many mistakes
  • +
+

So I've decided to build my own web editing tool with the following features:

+
    +
  • resTructuredText cleanup
  • +
  • content browsing
  • +
  • resTructuredText web editor with live preview that shows warnings & errors
  • +
  • a little bit of wsgi glue and a few forms to create articles without + having to worry about metadata syntax.
  • +
+
+

resTructuredText cleanup

+

The first step was to build a reStructuredText parser that would read some + reStructuredText and render it back into a cleaner version.

+

We've imported almost 2000 articles in Pelican from the old blog, so I had + a lot of samples to make my parser work well.

+

I first tried rst2rst but that + parser was built for a very specific use case (text wrapping) and was + incomplete. It was not parsing all of the reStructuredText syntax.

+

Inspired by it, I wrote my own little parser using docutils.

+

Understanding docutils is not a small task. This project is very powerfull + but quite complex. One thing that cruelly misses in docutils parser tools + is the ability to get the source text from any node, including its children, + so you can render back the same source.

+

That's roughly what I had to add in my code. It's ugly but it does the job: + it will parse rst files and render the same content, minus all the extraneous + empty lines, spaces, tabs etc.

+
+
+

Content browsing

+

Content browsing is pretty straightforward: my admin tool let you browse + the Pelican content directory and lists all articles, organized by categories.

+

In our case, each category has a top directory in content. The browser + parses the articles using my parser and displays paginated lists.

+

I had to add a cache system for the parser, because one of the directory + contains over 1000 articles -- and browsing was kind of slow :)

+ http://ziade.org/henet-browsing.png +
+
+

resTructuredText web editor

+

The last big bit was the live editor. I've stumbled on a neat little tool + called rsted, that provides a live preview of the reStructuredText + as you are typing it. And it includes warnings !

+

Check it out: http://rst.ninjs.org/

+

I've stripped it and kept what I needed, and included it in my app.

+ http://ziade.org/henet.png +

I am quite happy with the result so far. I need to add real tests and + a bit of documentation, and I will start to train my club friends on it.

+

The next features I'd like to add are:

+
    +
  • comments management, to replace Isso (working on it now)
  • +
  • smart Pelican builds. e.g. if a comment is added I don't want to rebuild the whole + blog (~1500 articles)
  • +
  • media management
  • +
  • spell checker
  • +
+

The project lives here: https://github.com/AcrDijon/henet

+

I am not going to release it, but if someone finds it useful, I could.

+

It's built with Bottle & Bootstrap as well.

+
+
+ 2016-01-21T09:40:00Z + + + + Tarek Ziade + + + http://blog.ziade.org + + + Tarek Ziadé + Fetchez le Python + 2016-01-24T20:45:46Z + +
+ + + http://www.ncameron.org/blog/rss/631106eb-e7b1-47d5-82f9-cb6ad210ea89 + + Closures and first-class functions +

I wrote a long and probably dull chapter on closures and first-class and higher-order functions in Rust. It goes into some detail on the implementation and some of the subtleties like higher-ranked lifetime bounds.

+ +

I was going to post it here too, but it is really too long. Instead, pop

+
+

I wrote a long and probably dull chapter on closures and first-class and higher-order functions in Rust. It goes into some detail on the implementation and some of the subtleties like higher-ranked lifetime bounds.

+ +

I was going to post it here too, but it is really too long. Instead, pop over to the 'Rust for C++ programmers' repo and read it there.

+
+ 2016-01-21T08:36:21Z + + + + + Nick Cameron + + + http://www.ncameron.org/blog/ + + + I'm a research engineer at Mozilla working on Rust: the language, compiler, and tools. @nick_r_cameron + featherweight musings + 2016-01-21T08:46:17Z + +
+ + + http://nickdesaulniers.github.io/blog/2016/01/20/debugging-x86-64-assembly-with-lldb-and-dtrace + + Intro to Debugging x86-64 Assembly +

I’m hacking on an assembly project, and wanted to document some of the tricks I + was using for figuring out what was going on. This post might seem a little + basic for folks who spend all day heads down in gdb or who do this stuff + professionally, but I just wanted to share a quick intro to some tools that + others may find useful. + (oh god, I’m doing it)

+ +

If your coming from gdb to lldb, there’s a few differences in commands. LLDB + has + great documentation + on some of the differences. Everything in this post about LLDB is pretty much + there.

+ +

The bread and butter commands when working with gdb or lldb are:

+ +
    +
  • r (run the program)
  • +
  • s (step in)
  • +
  • n (step over)
  • +
  • finish (step out)
  • +
  • c (continue)
  • +
  • q (quit the program)
  • +
+ + +

You can hit enter if you want to run the last command again, which is really + useful if you want to keep stepping over statements repeatedly.

+ +

I’ve been using LLDB on OSX. Let’s say I want to debug a program I can build, + but is crashing or something:

+ +
1
+            
$ sudo lldb ./asmttpd web_root
+            
+ + +

Setting a breakpoint on jump to label:

+ +
1
+                2
+            
(lldb) b sys_write
+            Breakpoint 3: where = asmttpd`sys_write, address = 0x00000000000029ae
+            
+ + +

Running the program until breakpoint hit:

+ +
1
+                2
+                3
+                4
+                5
+                6
+                7
+                8
+                9
+                10
+            
(lldb) r
+            Process 32236 launched: './asmttpd' (x86_64)
+            Process 32236 stopped
+            * thread #1: tid = 0xe69b9, 0x00000000000029ae asmttpd`sys_write, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1
+                frame #0: 0x00000000000029ae asmttpd`sys_write
+            asmttpd`sys_write:
+            ->  0x29ae <+0>: pushq  %rdi
+                0x29af <+1>: pushq  %rsi
+                0x29b0 <+2>: pushq  %rdx
+                0x29b1 <+3>: pushq  %r10
+            
+ + +

Seeing more of the current stack frame:

+ +
1
+                2
+                3
+                4
+                5
+                6
+                7
+                8
+                9
+                10
+                11
+                12
+                13
+                14
+                15
+                16
+                17
+                18
+                19
+                20
+                21
+                22
+                23
+                24
+            
(lldb) d
+            asmttpd`sys_write:
+            ->  0x29ae <+0>:  pushq  %rdi
+                0x29af <+1>:  pushq  %rsi
+                0x29b0 <+2>:  pushq  %rdx
+                0x29b1 <+3>:  pushq  %r10
+                0x29b3 <+5>:  pushq  %r8
+                0x29b5 <+7>:  pushq  %r9
+                0x29b7 <+9>:  pushq  %rbx
+                0x29b8 <+10>: pushq  %rcx
+                0x29b9 <+11>: movq   %rsi, %rdx
+                0x29bc <+14>: movq   %rdi, %rsi
+                0x29bf <+17>: movq   $0x1, %rdi
+                0x29c6 <+24>: movq   $0x2000004, %rax
+                0x29cd <+31>: syscall
+                0x29cf <+33>: popq   %rcx
+                0x29d0 <+34>: popq   %rbx
+                0x29d1 <+35>: popq   %r9
+                0x29d3 <+37>: popq   %r8
+                0x29 <+39>: popq   %r10
+                0x29d7 <+41>: popq   %rdx
+                0x29d8 <+42>: popq   %rsi
+                0x29d9 <+43>: popq   %rdi
+                0x29da <+44>: retq
+            
+ + +

Getting a back trace (call stack):

+ +
1
+                2
+                3
+                4
+                5
+                6
+                7
+            
(lldb) bt
+            * thread #1: tid = 0xe69b9, 0x00000000000029ae asmttpd`sys_write, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1
+              * frame #0: 0x00000000000029ae asmttpd`sys_write
+                frame #1: 0x00000000000021b6 asmttpd`print_line + 16
+                frame #2: 0x0000000000002ab3 asmttpd`start + 35
+                frame #3: 0x00007fff9900c5ad libdyld.dylib`start + 1
+                frame #4: 0x00007fff9900c5ad libdyld.dylib`start + 1
+            
+ + +

peeking at the upper stack frame:

+ +
1
+                2
+                3
+                4
+                5
+                6
+                7
+            
(lldb) up
+            frame #1: 0x00000000000021b6 asmttpd`print_line + 16
+            asmttpd`print_line:
+                0x21b6 <+16>: movabsq $0x30cb, %rdi
+                0x21c0 <+26>: movq   $0x1, %rsi
+                0x21c7 <+33>: callq  0x29ae                    ; sys_write
+                0x21cc <+38>: popq   %rcx
+            
+ + +

back down to the breakpoint-halted stack frame:

+ +
1
+                2
+                3
+                4
+                5
+                6
+                7
+            
(lldb) down
+            frame #0: 0x00000000000029ae asmttpd`sys_write
+            asmttpd`sys_write:
+            ->  0x29ae <+0>: pushq  %rdi
+                0x29af <+1>: pushq  %rsi
+                0x29b0 <+2>: pushq  %rdx
+                0x29b1 <+3>: pushq  %r10
+            
+ + +

dumping the values of registers:

+ +
1
+                2
+                3
+                4
+                5
+                6
+                7
+                8
+                9
+                10
+                11
+                12
+                13
+                14
+                15
+                16
+                17
+                18
+                19
+                20
+                21
+                22
+                23
+            
(lldb) register read
+            General Purpose Registers:
+                   rax = 0x0000000000002a90  asmttpd`start
+                   rbx = 0x0000000000000000
+                   rcx = 0x00007fff5fbffaf8
+                   rdx = 0x00007fff5fbffa40
+                   rdi = 0x00000000000030cc  start_text
+                   rsi = 0x000000000000000f
+                   rbp = 0x00007fff5fbffa18
+                   rsp = 0x00007fff5fbff9b8
+                    r8 = 0x0000000000000000
+                    r9 = 0x00007fff7b1670c8  atexit_mutex + 24
+                   r10 = 0x00000000ffffffff
+                   r11 = 0xffffffff00000000
+                   r12 = 0x0000000000000000
+                   r13 = 0x0000000000000000
+                   r14 = 0x0000000000000000
+                   r15 = 0x0000000000000000
+                   rip = 0x00000000000029ae  asmttpd`sys_write
+                rflags = 0x0000000000000246
+                    cs = 0x000000000000002b
+                    fs = 0x0000000000000000
+                    gs = 0x0000000000000000
+            
+ + +

read just one register:

+ +
1
+                2
+            
(lldb) register read rdi
+                 rdi = 0x00000000000030cc  start_text
+            
+ + +

When you’re trying to figure out what system calls are made by some C code, + using dtruss is very helpful. dtruss is available on OSX and seems to be some + kind of wrapper around DTrace.

+ +
1
+                2
+                3
+                4
+                5
+                6
+                7
+                8
+                9
+                10
+                11
+                12
+                13
+                14
+                15
+                16
+            
$ cat sleep.c
+            #include <time.h>
+            int main () {
+              struct timespec rqtp = {
+                2,
+                0
+              };
+            
+              nanosleep(&rqtp, NULL);
+            }
+            
+            $ clang sleep.c
+            
+            $ sudo dtruss ./a.out
+            ...all kinds of fun stuff
+            __semwait_signal(0xB03, 0x0, 0x1)    = -1 Err#60
+            
+ + +

If you compile with -g to emit debug symbols, you can use lldb’s disassemble + command to get the equivalent assembly:

+ +
1
+                2
+                3
+                4
+                5
+                6
+                7
+                8
+                9
+                10
+                11
+                12
+                13
+                14
+                15
+                16
+                17
+                18
+                19
+                20
+                21
+                22
+                23
+                24
+                25
+                26
+                27
+                28
+                29
+                30
+                31
+                32
+                33
+                34
+                35
+                36
+                37
+            
$ clang sleep.c -g
+            $ lldb a.out
+            (lldb) target create "a.out"
+            Current executable set to 'a.out' (x86_64).
+            (lldb) b main
+            Breakpoint 1: where = a.out`main + 16 at sleep.c:3, address = 0x0000000100000f40
+            (lldb) r
+            Process 33213 launched: '/Users/Nicholas/code/assembly/asmttpd/a.out' (x86_64)
+            Process 33213 stopped
+            * thread #1: tid = 0xeca04, 0x0000000100000f40 a.out`main + 16 at sleep.c:3, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
+                frame #0: 0x0000000100000f40 a.out`main + 16 at sleep.c:3
+               1    #include <time.h>
+               2    int main () {
+            -> 3      struct timespec rqtp = {
+               4        2,
+               5        0
+               6      };
+               7
+            (lldb) disassemble
+            a.out`main:
+                0x100000f30 <+0>:  pushq  %rbp
+                0x100000f31 <+1>:  movq   %rsp, %rbp
+                0x100000f34 <+4>:  subq   $0x20, %rsp
+                0x100000f38 <+8>:  leaq   -0x10(%rbp), %rdi
+                0x100000f3c <+12>: xorl   %eax, %eax
+                0x100000f3e <+14>: movl   %eax, %esi
+            ->  0x100000f40 <+16>: movq   0x49(%rip), %rcx
+                0x100000f47 <+23>: movq   %rcx, -0x10(%rbp)
+                0x100000f4b <+27>: movq   0x46(%rip), %rcx
+                0x100000f52 <+34>: movq   %rcx, -0x8(%rbp)
+                0x100000f56 <+38>: callq  0x100000f68               ; symbol stub for: nanosleep
+                0x100000f5b <+43>: xorl   %edx, %edx
+                0x100000f5d <+45>: movl   %eax, -0x14(%rbp)
+                0x100000f60 <+48>: movl   %edx, %eax
+                0x100000f62 <+50>: addq   $0x20, %rsp
+                0x100000f66 <+54>: popq   %rbp
+                0x100000f67 <+55>: retq
+            
+ + +

Anyways, I’ve been learning some interesting things about OSX that I’ll be + sharing soon. If you’d like to learn more about x86-64 assembly programming, + you should read my other posts about + writing x86-64 + and a toy + JIT for Brainfuck + (the creator of Brainfuck liked it).

+ +

I should also do a post on + Mozilla’s rr, + because it can do amazing things like step backwards. Another day…

+
+ 2016-01-21T04:04:00Z + + http://nickdesaulniers.github.io/ + + Nick Desaulniers + + + + Nick Desaulniers + 2016-01-21T05:07:32Z + +
+ + + https://rail.merail.ca/posts/rebooting-productivity.html + + Rebooting productivity +

Every new year gives you an opportunity to sit back, relax, + have some scotch and re-think the passed year. Holidays give + you enough free time. Even if you decide to not take a vacation around + the holidays, it's usually calm and peaceful.

+

This time, I found myself thinking mostly about productivity, being + effective, feeling busy, overwhelmed with work and other related topics.

+

When I started at Mozilla (almost 6 years ago!), I tried to apply all my + GTD and time management knowledge and techniques. Working remotely and + in a different time zone was an advantage - I had close to zero + interruptions. It worked perfect.

+

Last year I realized that my productivity skills had faded away somehow. + 40h+ workweeks, working on weekends, delivering goals in the last week + of quarter don't sound like good signs. Instead of being productive I + felt busy.

+

"Every crisis is an opportunity". Time to make a step back and reboot + myself. Burning out at work is not a good idea. :)

+

Here are some ideas/tips that I wrote down for myself you may found + useful.

+ +
+

Concentration

+
    +
  • Task #1: make a daily plan. No plan - no work.
  • +
  • Don't start your day by reading emails. Get one (little) thing done + first - THEN check your email.
  • +
  • Try to define outcomes, not tasks. "Ship XYZ" instead of "Work on XYZ".
  • +
  • Meetings are time consuming, so "Set a goal for each meeting". + Consider skipping a meeting if you don't have any goal set, unless it's a + beer-and-tell meeting! :)
  • +
  • Constantly ask yourself if what you're working on is important.
  • +
  • 3-4 times a day ask yourself whether you are doing something towards + your goal or just finding something else to keep you busy. If you want + to look busy, take your phone and walk around the office with some + papers in your hand. Everybody will think that you are a busy person! + This way you can take a break and look busy at the same time!
  • +
  • Take breaks! Pomodoro technique has this option + built-in. Taking breaks helps not only to avoid RSI, but also + keeps your brain sane and gives you time to ask yourself the questions + mentioned above. I use Workrave on my + laptop, but you can use a real kitchen timer instead.
  • +
  • Wear headphones, especially at office. Noise cancelling ones are even + better. White noise, nature sounds, or instrumental music are your + friends.
  • +
+
+
+

(Home) Office

+
    +
  • Make sure you enjoy your work environment. Why on the earth would you + spend your valuable time working without joy?!
  • +
  • De-clutter and organize your desk. Less things around - less + distractions.
  • +
  • Desk, chair, monitor, keyboard, mouse, etc - don't cheap out on them. + Your health is more important and expensive. Thanks to mhoye for this advice!
  • +
+
+
+

Other

+
    +
  • Don't check email every 30 seconds. If there is an emergency, they + will call you! :)
  • +
  • Reward yourself at a certain time. "I'm going to have a chocolate at + 11am", or "MFBT at 4pm sharp!" are good examples. Don't forget, you + are Pavlov's dog too!
  • +
  • Don't try to read everything NOW. Save it for later and read in a + batch.
  • +
  • Capture all creative ideas. You can delete them later. ;)
  • +
  • Prepare for next task before break. Make sure you know what's next, so + you can think about it during the break.
  • +
+

This is my list of things that I try to use everyday. Looking forward to + see improvements!

+

I would appreciate your thoughts this topic. Feel free to comment or + send a private email.

+

Happy Productive New Year!

+
+
+ 2016-01-21T02:06:37Z + + + + Rail Aliiev + + + https://rail.merail.ca/ + + + Rail's Blog (mozilla) + 2016-01-21T02:31:38Z + +
+ + + http://blog.rust-lang.org/2016/01/21/Rust-1.6.html + + Announcing Rust 1.6 +

Hello 2016! We’re happy to announce the first Rust release of the year, 1.6. + Rust is a systems programming language focused on safety, speed, and + concurrency.

+ +

As always, you can install Rust 1.6 from the appropriate page on our + website, and check out the detailed release notes for 1.6 on GitHub. + About 1100 patches were landed in this release.

+ +

What’s in 1.6 stable

+ +

This release contains a number of small refinements, one major feature, and + a change to Crates.io.

+ +

libcore stabilization

+ +

The largest new feature in 1.6 is that libcore is now stable! Rust’s + standard library is two-tiered: there’s a small core library, libcore, and + the full standard library, libstd, that builds on top of it. libcore is + completely platform agnostic, and requires only a handful of external symbols + to be defined. Rust’s libstd builds on top of libcore, adding support for + memory allocation, I/O, and concurrency. Applications using Rust in the + embedded space, as well as those writing operating systems, often eschew + libstd, using only libcore.

+ +

libcore being stabilized is a major step towards being able to write the + lowest levels of software using stable Rust. There’s still future work to be + done, however. This will allow for a library ecosystem to develop around + libcore, but applications are not fully supported yet. Expect to hear more + about this in future release notes.

+ +

Library stabilizations

+ +

About 30 library functions and methods are now stable in 1.6. Notable + improvements include:

+ +

The drain() family of functions on collections. These methods let you move + elements out of a collection while allowing them to retain their backing + memory, reducing allocation in certain situations.

+ +

A number of implementations of From for converting between standard library + types, mainly between various integral and floating-point types.

+ +

Finally, Vec::extend_from_slice(), which was previously known as + push_all(). This method has a significantly faster implementation than the + more general extend().

+ +

See the detailed release notes for more.

+ +

Crates.io disallows wildcards

+ +

If you maintain a crate on Crates.io, you might have seen + a warning: newly uploaded crates are no longer allowed to use a wildcard when + describing their dependencies. In other words, this is not allowed:

+
[dependencies]
+                regex = "*"
+            
+

Instead, you must actually specify a specific version or range of + versions, using one of the semver crate’s various options: ^, + ~, or =.

+ +

A wildcard dependency means that you work with any possible version of your + dependency. This is highly unlikely to be true, and causes unnecessary breakage + in the ecosystem. We’ve been advertising this change as a warning for some time; + now it’s time to turn it into an error.

+ +

Contributors to 1.6

+ +

We had 132 individuals contribute to 1.6. Thank you so much!

+ +
    +
  • Aaron Turon
  • +
  • Adam Badawy
  • +
  • Aleksey Kladov
  • +
  • Alexander Bulaev
  • +
  • Alex Burka
  • +
  • Alex Crichton
  • +
  • Alex Gaynor
  • +
  • Alexis Beingessner
  • +
  • Amanieu d'Antras
  • +
  • Amit Saha
  • +
  • Andrea Canciani
  • +
  • Andrew Paseltiner
  • +
  • androm3da
  • +
  • angelsl
  • +
  • Angus Lees
  • +
  • Antti Keränen
  • +
  • arcnmx
  • +
  • Ariel Ben-Yehuda
  • +
  • Ashkan Kiani
  • +
  • Barosl Lee
  • +
  • Benjamin Herr
  • +
  • Ben Striegel
  • +
  • Bhargav Patel
  • +
  • Björn Steinbrink
  • +
  • Boris Egorov
  • +
  • bors
  • +
  • Brian Anderson
  • +
  • Bruno Tavares
  • +
  • Bryce Van Dyk
  • +
  • Cameron Sun
  • +
  • Christopher Sumnicht
  • +
  • Cole Reynolds
  • +
  • corentih
  • +
  • Daniel Campbell
  • +
  • Daniel Keep
  • +
  • Daniel Rollins
  • +
  • Daniel Trebbien
  • +
  • Danilo Bargen
  • +
  • Devon Hollowood
  • +
  • Doug Goldstein
  • +
  • Dylan McKay
  • +
  • ebadf
  • +
  • Eli Friedman
  • +
  • Eric Findlay
  • +
  • Erik Davidson
  • +
  • Felix S. Klock II
  • +
  • Florian Hahn
  • +
  • Florian Hartwig
  • +
  • Gleb Kozyrev
  • +
  • Guillaume Gomez
  • +
  • Huon Wilson
  • +
  • Igor Shuvalov
  • +
  • Ivan Ivaschenko
  • +
  • Ivan Kozik
  • +
  • Ivan Stankovic
  • +
  • Jack Fransham
  • +
  • Jake Goulding
  • +
  • Jake Worth
  • +
  • James Miller
  • +
  • Jan Likar
  • +
  • Jean Maillard
  • +
  • Jeffrey Seyfried
  • +
  • Jethro Beekman
  • +
  • John Kåre Alsaker
  • +
  • John Talling
  • +
  • Jonas Schievink
  • +
  • Jonathan S
  • +
  • Jose Narvaez
  • +
  • Josh Austin
  • +
  • Josh Stone
  • +
  • Joshua Holmer
  • +
  • JP Sugarbroad
  • +
  • jrburke
  • +
  • Kevin Butler
  • +
  • Kevin Yeh
  • +
  • Kohei Hasegawa
  • +
  • Kyle Mayes
  • +
  • Lee Jeffery
  • +
  • Manish Goregaokar
  • +
  • Marcell Pardavi
  • +
  • Markus Unterwaditzer
  • +
  • Martin Pool
  • +
  • Marvin Löbel
  • +
  • Matt Brubeck
  • +
  • Matthias Bussonnier
  • +
  • Matthias Kauer
  • +
  • mdinger
  • +
  • Michael Layzell
  • +
  • Michael Neumann
  • +
  • Michael Sproul
  • +
  • Michael Woerister
  • +
  • Mihaly Barasz
  • +
  • Mika Attila
  • +
  • mitaa
  • +
  • Ms2ger
  • +
  • Nicholas Mazzuca
  • +
  • Nick Cameron
  • +
  • Niko Matsakis
  • +
  • Ole Krüger
  • +
  • Oliver Middleton
  • +
  • Oliver Schneider
  • +
  • Ori Avtalion
  • +
  • Paul A. Jungwirth
  • +
  • Peter Atashian
  • +
  • Philipp Matthias Schäfer
  • +
  • pierzchalski
  • +
  • Ravi Shankar
  • +
  • Ricardo Martins
  • +
  • Ricardo Signes
  • +
  • Richard Diamond
  • +
  • Rizky Luthfianto
  • +
  • Ryan Scheel
  • +
  • Scott Olson
  • +
  • Sean Griffin
  • +
  • Sebastian Hahn
  • +
  • Sébastien Marie
  • +
  • Seo Sanghyeon
  • +
  • Simonas Kazlauskas
  • +
  • Simon Sapin
  • +
  • Stepan Koltsov
  • +
  • Steve Klabnik
  • +
  • Steven Fackler
  • +
  • Tamir Duberstein
  • +
  • Tobias Bucher
  • +
  • Toby Scrace
  • +
  • Tshepang Lekhonkhobe
  • +
  • Ulrik Sverdrup
  • +
  • Vadim Chugunov
  • +
  • Vadim Petrochenkov
  • +
  • William Throwe
  • +
  • xd1le
  • +
  • Xmasreturns
  • +
+
+ 2016-01-21T00:00:00Z + + http://blog.rust-lang.org/ + + The Rust Programming Language Blog + + + + Words from the Rust team + The Rust Programming Language Blog + 2016-01-21T21:36:56Z + +
+ + + http://blog.mozilla.org/addons/?p=7644 + + Archiving AMO Stats +
One of the advantages of listing an add-on or theme on addons.mozilla.org (AMO) is that you’ll get statistics on your add-on’s usage. These stats, which are covered by the Mozilla privacy policy, provide add-on developers with information such as the … Continue reading
+
+

One of the advantages of listing an add-on or theme on addons.mozilla.org (AMO) is that you’ll get statistics on your add-on’s usage. These stats, which are covered by the Mozilla privacy policy, provide add-on developers with information such as the number of downloads and daily users, among other insights.

+

Currently, the data that generates these statistics can go back as far as 2007, as we haven’t had an archiving policy. As a result, statistics take up the vast majority of disk space in our database and require a significant amount of processing and operations time. Statistics over a year old are very rarely accessed, and the value of their generation is very low, while the costs are increasing.

+

To reduce our operating and development costs, and increase the site’s reliability for developers, we are introducing an archiving policy.

+

In the coming weeks, statistics data over one year old will no longer be stored in the AMO database, and reports generated from them will no longer be accessible through AMO’s add-on statistics pages. Instead, the data will be archived and maintained as plain text files, which developers can download. We will write a follow-up post when these archives become available.

+

If you’ve chosen to keep your add-on’s statistics private, they will remain private when stats are archived. You can check your privacy settings by going to your add-on in the Developer Hub, clicking on Edit Listing, and then Technical Details.

+

editlisting

+

The total number of users and other cumulative counts on add-ons and themes will not be affected and these will continue to function.

+

If you have feedback or concerns, please head to our forum post on this topic.

+
+ 2016-01-20T23:54:09Z + + + + Andy McKay + + + https://blog.mozilla.org/addons + + + Mozilla Add-ons Blog + 2016-01-25T20:46:40Z + +
+ + + https://air.mozilla.org/the-joy-of-coding-episode-41/ + + The Joy of Coding - Episode 41 +

+ The Joy of Coding - Episode 41 + mconley livehacks on real Firefox bugs while thinking aloud. +

+
+ 2016-01-20T18:00:00Z + + Air Mozilla + + + https://air.mozilla.org/ + + + Except where otherwise noted, content on this site is licensed under the Creative Commons Attribution Share-Alike License v3.0 or any later version. + Air Mozilla is the Internet multimedia presence of Mozilla, with live and pre-recorded shows, interviews, news snippets, tutorial videos, and features about the Mozilla community. + Air Mozilla + 2016-01-25T20:31:50Z + +
+ + + http://blog.mozilla.org/nfroyd/?p=452 + + gecko and c++ onboarding presentation + One of the things the Firefox team has been doing recently is having onboarding sessions for new hires. This onboarding currently covers: 1st day setup Bugzilla Building Firefox Desktop Firefox Architecture / Product Communication and Community Javascript and the DOM C++ and Gecko Shipping Software Telemetry Org structure and career development My first day consisted […] +

One of the things the Firefox team has been doing recently is having onboarding sessions for new hires. This onboarding currently covers:

+
    +
  • 1st day setup
  • +
  • Bugzilla
  • +
  • Building Firefox
  • +
  • Desktop Firefox Architecture / Product
  • +
  • Communication and Community
  • +
  • Javascript and the DOM
  • +
  • C++ and Gecko
  • +
  • Shipping Software
  • +
  • Telemetry
  • +
  • Org structure and career development
  • +
+

My first day consisted of some useful HR presentations and then I was given my laptop and a pointer to a wiki page on building Firefox. Needless to say, it took me a while to get started! It would have been super convenient to have an introduction to all the stuff above.

+

I’ve been asked to do the C++ and Gecko session three times. All of the sessions are open to whoever wants to come, not just the new hires, and I think yesterday’s session was easily the most well-attended yet: somewhere between 10 and 20 people showed up. Yesterday’s session was the first session where I made the slides available to attendees (should have been doing that from the start…) and it seemed equally useful to make the slides available to a broader audience as well. The Gecko and C++ Onboarding slides are up now!

+

This presentation is a “living” presentation; it will get updated for future sessions with feedback and as I think of things that should have been in the presentation or better ways to set things up (some diagrams would be nice…). If you have feedback (good, bad, or ugly) on particular things in the slides or you have suggestions on what other things should be covered, please contact me! Next time I do this I’ll try to record the presentation so folks can watch that if they prefer.

+
+ 2016-01-20T16:48:29Z + + + + + + + Nathan Froyd + + + https://blog.mozilla.org/nfroyd + + + writing code to help other people write code + Nathan's Blog + 2016-01-20T17:01:01Z + +
+ + + http://andreasgal.com/?p=573 + + Brendan is back to save the Web +
Brendan is back, and he has a plan to save the Web. Its a big and bold plan, and it may just work. I am pretty excited about this. If you have 5 minutes to read along I’ll explain why I think you should be as well. The Web is broken Lets face it, the Web […]
+
+

Brendan is back, and he has a plan to save the Web. Its a big and bold plan, and it may just work. I am pretty excited about this. If you have 5 minutes to read along I’ll explain why I think you should be as well.

+

The Web is broken

+

Lets face it, the Web today is a mess. Everywhere we go online we are constantly inundated with annoying ads. Often pages are more ads than content, and the more ads the industry throws at us, the more we ignore them, the more obnoxious ads get, trying to catch our attention. As Brendan explains in his blog post, the browser used to be on the user’s side—we call browsers the user agent for a reason. Part of the early success of Firefox was that it blocked popup ads. But somewhere over the last 10 years of modern Web browsers, browsers lost their way and stopped being the user’s agent alone. Why?

+

Browsers aren’t free

+

Making a modern Web browser is not free. It takes hundreds of engineers to make a competitive modern browser engine. Someone has to pay for that, and that someone needs to have a reason to pay for it. Google doesn’t make Chrome for the good of mankind. Google makes Chrome so you can consume more Web and along with it, more Google ads. Each time you click on one, Google makes more money. Chrome is a billion dollar business for Google. And the same is true for pretty much every other browser. Every major browser out there is funded through advertisement. No browser maker can escape this dilemma. Maybe now you understand why no major browser ships with a builtin enabled by default ad-blocker, even though ad-blockers are by far the most popular add-ons.

+

Our privacy is at stake

+

It’s not just the unregulated flood of advertisement that needs a solution. Every ad you see is often selected based on sensitive private information advertisement networks have extracted from your browsing behavior through tracking. Remember how the FBI used to track what books Americans read at the library, and it was a big scandal? Today the Googles and Facebooks of the world know almost every site you visit, everything you buy online, and they use this data to target you with advertisement. I am often puzzled why people are so afraid of the NSA spying on us but show so little concern about all the deeply personal data Google and Facebook are amassing about everyone.

+

Blocking alone doesn’t scale

+

I wish the solution was as easy as just blocking all ads. There is a lot of great Web content out there: news, entertainment, educational content. It’s not free to make all this content, but we have gotten used to consuming it “for free”. Banning all ads without an alternative mechanism would break the economic backbone of the Web. This dilemma has existed for many years, and the big browser vendors seem to have given up on it. It’s hard to blame them. How do you disrupt the status quo without sawing off the (ad revenue) branch you are sitting on?

+

It takes an newcomer to fix this mess

+

I think its unlikely that the incumbent browser vendors will make any bold moves to solve this mess. There is too much money at stake. I am excited to see a startup take a swipe at this problem, because they have little to lose (seed money aside). Brave is getting the user agent back into the game. Browsers have intentionally remained silent onlookers to the ad industry invading users’ privacy. With Brave, Brendan makes the user agent step up and fight for the user as it was always intended to do.

+

Brave basically consists of two parts: part one blocks third party ad content and tracking signals. Instead of these Brave inserts alternative ad content. Sites can sign up to get a fair share of any ads that Brave displays for them. The big change in comparison to the status quo is that the Brave user agent is in control and can regulate what you see. It’s like a speed limit for advertisement on the Web, with the goal to restore balance and give sites a fair way to monetize while giving the user control through the user agent.

+

Making money with a better Web

+

The ironic part of Brave is that its for-profit. Brave can make money by reducing obnoxious ads and protecting your privacy at the same time. If Brave succeeds, it’s going to drain money away from the crappy privacy-invasive obnoxious advertisement world we have today, and publishers and sites will start transacting in the new Brave world that is regulated by the user agent. Brave will take a cut of these transactions. And I think this is key. It aligns the incentives right. The current funding structure of major browsers encourages them to keep things as they are. Brave’s incentive is to bring down the whole diseased temple and usher in a better Web. Exciting.

+

Quick update: I had a chance to look over the Brave GitHub repo. It looks like the Brave Desktop browser is based on Chromium, not Gecko. Yes, you read that right. Brave is using Google’s rendering engine, not Mozilla’s. Much to write about this one, but it will definitely help Brave “hide” better in the large volume of Chrome users, making it harder for sites to identify and block Brave users. Brave for iOS seems to be a fork of Firefox for iOS, but it manages to block ads (Mozilla says they can’t).


Filed under: Mozilla
+
+ 2016-01-20T16:00:00Z + + + Andreas + + + http://andreasgal.com + http://s2.wp.com/i/buttonw-com.png + + + + + Entrepreneur. Technologist. Former CTO Mozilla + Andreas Gal + 2016-01-22T11:45:34Z + +
+ + + https://miketaylr.com/posts/2016/01/at-media-webkit-transform-three-dee.html + + 🙅 @media (-webkit-transform-3d) +

@media (-webkit-transform-3d) is a funny thing that exists on the web.

+ +

It's like, a media query feature in the form of a prefixed CSS property, which should tell you if your (once upon a time probably Safari-only) browser supports 3D transforms, invented back in the day before we had @supports.

+ +

(According to Apple docs it first appeared in Safari 4, along side the other -webkit-transition and -webkit-transform-2d hybrid-media-query-feature-prefixed-css-properties-things that you should immediately forget exist.)

+ +

Older versions of Modernizr used this (and only this) to detect support for 3D transforms, and that seemed pretty OK. (They also did the polite thing and tested @media (transform-3d), but no browser has ever actually supported that, as it turns out). And because they're so consistently polite, they've since updated the test to prefer @supports too (via a pull request from Edge developer Jacob Rossi).

+ +

As it turns out other browsers have been updated to support 3D CSS transforms, but sites didn't go back and update their version of Modernizr. So unless you support @media (-webkit-transform-3d) these sites break. Niche websites like yahoo.com and about.com.

+ +

So, anyways. I added @media (-webkit-transform-3d) to the Compat Standard and we added support for it Firefox so websites stop breaking.

+ +

But you shouldn't ever use it—use @supports. In fact, don't even share this blog post. Maybe delete it from your browser history just in case.

+
+ 2016-01-20T08:00:00Z + + Mike Taylor + + + https://miketaylr.com/posts + + + 3000 + Erotic web browser fan-fiction. + Mike Taylr Dot Com Web Log + 2016-01-20T19:46:39Z + +
+ + + http://globau.wordpress.com/?p=881 + + happy bmo push day! +
the following changes have been pushed to bugzilla.mozilla.org: [1236161] when converting a BMP attachment to PNG fails a zero byte attachment is created [1231918] error handler doesn’t close multi-part responses discuss these changes on mozilla.tools.bmo.Filed under: bmo, mozilla
+
+

the following changes have been pushed to bugzilla.mozilla.org:

+
    +
  • [1236161] when converting a BMP attachment to PNG fails a zero byte attachment is created
  • +
  • [1231918] error handler doesn’t close multi-part responses
  • +
+

discuss these changes on mozilla.tools.bmo.


Filed under: bmo, mozilla
+
+ 2016-01-20T07:33:46Z + + + + glob + + + https://globau.wordpress.com + https://s2.wp.com/i/buttonw-com.png + + + + + mozilla – glob blog + 2016-01-26T19:01:06Z + +
+ + + https://www.alex-johnson.net/tag/mozilla/rss/85d84c54-ed0c-4ee5-beb3-8823edb3c074 + + Removing Honeycomb Code +

As an effort to reduce the APK size of Firefox for Android and to remove unnecessary code, I will be helping remove the Honeycomb code throughout the Fennec project. Honeycomb will not be supported since Firefox 46, so this code is not necessary.
+ Bug 1217675 will keep track of the

+
+

As an effort to reduce the APK size of Firefox for Android and to remove unnecessary code, I will be helping remove the Honeycomb code throughout the Fennec project. Honeycomb will not be supported since Firefox 46, so this code is not necessary.
+ Bug 1217675 will keep track of the progress.
+ Hopefully this will help reduce the APK size some and clean up the road for killing Gingerbread hopefully sometime in the near future.

+
+ 2016-01-20T04:59:34Z + + + + + Alex Johnson + + + https://www.alex-johnson.net/ + + + Open source evangelist; lover of technology and video games. + Mozilla - Alex Johnson + 2016-01-26T19:01:53Z + +
+ + + http://www.brianbondy.com/blog/id/172 + + Brave Software +

Since June of last year, I’ve been co-founding a new startup called Brave Software with Brendan Eich. + With our amazing team, we're developing something pretty epic.

+

We're building the next-generation of browsers for smartphones and laptops as part of our new ad-tech platform. + Our terms of use give our users control over their personal data by blocking ad trackers and third party cookies. + We re-integrate fewer and better ads directly into programmatic ad positions, paying revenue shares to users and publishers to support both of these essential parties in the web ecosystem.

+

Coming built in, we have new faster engines for tracking protection, ad block, HTTPS Everywhere, safe ads with rev-share, and more. + We're seeing massive web page load time speedups.

+ + +

We're starting to bring people in for early developer build access on all platforms.

+

I’m happy to share that the browsers we’re developing were made fully open sourced. + We welcome contributors, and would love your help.

+

Some of the repositories include:

+

    +
  • Brave OSX and Windows x64 browsers: Prototyped as a Gecko based browser, but now replaced with a powerful new browser built on top of the electron framework. The electron framework is the same one in use by Slack and the Atom editor. It uses the latest libchromiumcontent and Node.
  • +
  • Brave for Android: Formerly Link Bubble, working as a background service so you can use other apps as your pages load.
  • +
  • Brave for iOS: Originally forked from Firefox for iOS but with all of the built-in greatness described above.
  • +
  • And many others: Website, updater code, vault, electron fork, and others.
  • +
+
+ 2016-01-20T00:00:00Z + + + + + + + + + Brian R. Bondy + + + http://www.brianbondy.com/blog/tagged/mozilla + http://www.brianbondy.com/img/logo.png + + + Blog posts tagged mozilla by Brian R. Bondy + Brian R. Bondy's feed for tag mozilla + 2016-01-26T19:01:09Z + +
+ + + http://coffeeonthekeyboard.com/rss/0388d8a6-fc86-477e-a161-1b356e01fe77 + + PIEfection Slides Up +

I put the slides for my ManhattanJS talk, "PIEfection" up on GitHub the other day (sans images, but there are links in the source for all of those).

+ +

I completely neglected to talk about the Maillard reaction, which is responsible for food tasting good, and specifically for browning pie crusts.

+
+

I put the slides for my ManhattanJS talk, "PIEfection" up on GitHub the other day (sans images, but there are links in the source for all of those).

+ +

I completely neglected to talk about the Maillard reaction, which is responsible for food tasting good, and specifically for browning pie crusts. tl;dr: Amino acid (protein) + sugar + ~300°F (~150°C) = delicious. There are innumerable and poorly understood combinations of amino acids and sugars, but this class of reaction is responsible for everything from searing stakes to browning crusts to toasting marshmallows.

+ +

Above ~330°F, you get caramelization, which is also a delicious part of the pie and crust, but you don't want to overdo it. Starting around ~400°F, you get pyrolysis (burning, charring, carbonization) and below 285°F the reaction won't occur (at least not quickly) so you won't get the delicious compounds.

+ +

(All of these are, of course, temperatures measured in the material, not in the air of the oven.)

+ +

So, instead of an egg wash on your top crust, try whole milk, which has more sugar to react with the gluten in the crust.

+ +

I also didn't get a chance to mention a rolling technique I use, that I learned from a cousin of mine, in whose baking shadow I happily live.

+ +

When rolling out a crust after it's been in the fridge, first roll it out in a long stretch, then fold it in thirds; do it again; then start rolling it out into a round. Not only do you add more layer structure (mmm, flaky, delicious layers) but it'll fill in the cracks that often form if you try to roll it out directly, resulting in a stronger crust.

+ +

Those pepper flake shakers, filled with flour, are a great way to keep adding flour to the workspace without worrying about your buttery hands.

+ +

For transferring the crust to the pie plate, try rolling it up onto your rolling pin and unrolling it on the plate. Tapered (or "French") rolling pins (or wine bottle) are particularly good at this since they don't have moving parts.

+ +

Finally, thanks again to Jenn for helping me get pies from one island to another. It would not have been possible without her!

+
+ 2016-01-19T20:45:34Z + + James Socol + + + http://coffeeonthekeyboard.com/ + + + Coffee on the Keyboard + Coffee on the Keyboard + 2016-01-25T18:00:43Z + +
+ + + https://air.mozilla.org/reprendre-le-controle-de-sa-vie-privee-sur-internet/ + + Reprendre le contrôle de sa vie privée sur Internet +

+ Reprendre le contrôle de sa vie privée sur Internet + L'omniprésence des réseaux sociaux, des moteurs de recherches et de la publicité est-elle compatible avec notre droit à la vie privée ? +

+
+ 2016-01-19T18:00:00Z + + Air Mozilla + + + https://air.mozilla.org/ + + + Except where otherwise noted, content on this site is licensed under the Creative Commons Attribution Share-Alike License v3.0 or any later version. + Air Mozilla is the Internet multimedia presence of Mozilla, with live and pre-recorded shows, interviews, news snippets, tutorial videos, and features about the Mozilla community. + Air Mozilla + 2016-01-25T20:31:50Z + +
+ + + https://mykzilla.org/?p=245 + + New Year, New Blogware + Four score and many moons ago, I decided to move this blog from Blogger to WordPress. The transition took longer than expected, but it’s finally done. If you’ve been following along at the old address, https://mykzilla.blogspot.com/, now’s the time to update your address book! If you’ve been going to https://mykzilla.org/, however, or you read the […] +

Four score and many moons ago, I decided to move this blog from Blogger to WordPress. The transition took longer than expected, but it’s finally done.

+

If you’ve been following along at the old address, https://mykzilla.blogspot.com/, now’s the time to update your address book! If you’ve been going to https://mykzilla.org/, however, or you read the blog on Planet Mozilla, then there’s nothing to do, as that’s the new address, and Planet Mozilla has been updated to syndicate posts from it.

+
+ 2016-01-19T16:56:05Z + + + Myk Melez + + + https://mykzilla.org + https://mykzilla.org/wp-content/uploads/2016/01/cropped-headshot-2014-32x32.jpg + + + Mozilla – Mykzilla + 2016-01-19T17:30:17Z + +
+ + + http://michaelkohler.info/?p=348 + + Mozillas strategische Leitlinien für 2016 und danach +
Dieser Beitrag wurde zuerst im Blog auf https://blog.mozilla.org/community veröffentlicht. Herzlichen Dank an Aryx und Coce für die Übersetzung! Auf der ganzen Welt arbeiten leidenschaftliche Mozillianer am Fortschritt für Mozillas Mission. Aber fragt man fünf verschiedene Mozillianer, was die Mission ist, erhält man womöglich sieben verschiedene Antworten. Am Ende des letzten Jahres legte Mozillas CEO Chris Beard klare Vorstellungen über Mozillas Mission, Vision und Rolle dar und zeigte auf, wie unsere Produkte uns diesem Ziel in den nächsten fünf Jahren näher bringen. Das Ziel dieser strategischen Leitlinien besteht darin, für Mozilla...read more
+
+

Dieser Beitrag wurde zuerst im Blog auf https://blog.mozilla.org/community veröffentlicht. Herzlichen Dank an Aryx und Coce für die Übersetzung!

+

Auf der ganzen Welt arbeiten leidenschaftliche Mozillianer am Fortschritt für Mozillas Mission. Aber fragt man fünf verschiedene Mozillianer, was die Mission ist, erhält man womöglich sieben verschiedene Antworten.

+

Am Ende des letzten Jahres legte Mozillas CEO Chris Beard klare Vorstellungen über Mozillas Mission, Vision und Rolle dar und zeigte auf, wie unsere Produkte uns diesem Ziel in den nächsten fünf Jahren näher bringen. Das Ziel dieser strategischen Leitlinien besteht darin, für Mozilla insgesamt ein prägnantes, gemeinsames Verständnis unserer Ziele zu entwickeln, die uns als Individuen das Treffen von Entscheidungen und Erkennen von Möglichkeiten erleichtert, mit denen wir Mozilla voranbringen.

+

Mozillas Mission können wir nicht alleine erreichen. Die Tausenden von Mozillianern auf der ganzen Welt müssen dahinter stehen, damit wir zügig und mit lauterer Stimme als je zuvor Unglaubliches erreichen können.

+

Deswegen ist eine der sechs strategischen Initiativen des Participation Teams für die erste Jahreshälfte, möglichst viele Mozillianer über diese Leitlinien aufzuklären, damit wir 2016 den bisher wesentlichsten Einfluss erzielen können. Wir werden einen weiteren Beitrag veröffentlichen, der sich näher mit der Strategie des Participation Teams für das Jahr 2016 befassen wird.

+

+

Das Verstehen dieser Strategie wird unabdingbar sein für jeden, der bei Mozilla in diesem Jahr etwas bewirken möchte, denn sie wird bestimmen, wofür wir eintreten, wo wir unsere Ressourcen einsetzen und auf welche Projekte wir uns 2016 konzentrieren werden.

+

Zu Jahresbeginn werden wir näher auf diese Strategie eingehen und weitere Details dazu bekanntgeben, wie die diversen Teams und Projekte bei Mozilla auf diese Ziele hinarbeiten.

+

Der aktuelle Aufruf zum Handeln besteht darin, im Kontext Ihrer Arbeit über diese Ziele nachzudenken und darüber, wie Sie im kommenden Jahr bei Mozilla mitwirken möchten. Dies hilft, Ihre Innovationen, Ambitionen und Ihren Einfluss im Jahr 2016 zu gestalten.

+

Wir hoffen, dass Sie mitdiskutieren und Ihre Fragen, Kommentare und Pläne für das Vorantreiben der strategischen Leitlinien im Jahr 2016 hier auf Discourse teilen und Ihre Gedanken auf Twitter mit dem Hashtag #Mozilla2016Strategy mitteilen.

+

+

Mission, Vision & Strategie

+

Unsere Mission

+

Dafür zu sorgen, dass das Internet eine weltweite öffentliche Ressource ist, die allen zugänglich ist.

+

Unsere Vision

+

Ein Internet, für das Menschen tatsächlich an erster Stelle stehen. Ein Internet, in dem Menschen ihr eigenes Erlebnis gestalten können. Ein Internet, in dem die Menschen selbst entscheiden können sowie sicher und unabhängig sind.

+

Unsere Rolle

+

Mozilla setzt sich im wahrsten Sinne des Wortes in Ihrem Online-Leben für Sie ein. Wir setzen uns für Sie ein, sowohl in Ihrem Online-Erlebnis als auch für Ihre Interessen beim Zustand des Internets.

+

Unsere Arbeit

+

Unsere Säulen

+
    +
  1. Produkte: Wir entwickeln Produkte mit Menschen im Mittelpunkt sowie Bildungsprogramme, mit deren Hilfe Menschen online ihr gesamtes Potential ausschöpfen können.
  2. +
  3. Technologie: Wir entwickeln robuste technische Lösungen, die das Internet über verschiedene Plattformen hinweg zum Leben erwecken.
  4. +
  5. Menschen: Wir entwickeln Führungspersonen und Mitwirkende in der Gemeinschaft, die das Internet erfinden, gestalten und verteidigen.
  6. +
+

Wir wir positive Veränderungen in Zukunft anpacken wollen

+

Die Arbeitsweise ist ebensowichtig wie das Ziel. Unsere Gesundheit und bleibender Einfluss hängen davon ab, wie sehr unsere Produkte und Aktivitäten:

+
    +
  1. Interoperabilität, Open Source und offene Standards fördern,
  2. +
  3. Gemeinschaften aufbauen und fördern,
  4. +
  5. Für politische Veränderungen und rechtlichen Schutz eintreten sowie
  6. +
  7. Netzbürger bilden und einbeziehen.
  8. +
+

+
+
+ 2016-01-19T15:27:24Z + + + + Michael Kohler + + + https://michaelkohler.info + + + Mozilla – Michael Kohler + 2016-01-19T15:31:45Z + +
+ + + http://dlawrence.wordpress.com/?p=27 + + happy bmo push day! +
the following changes have been pushed to bugzilla.mozilla.org: [1238573] Change label of “New Bug” menu to “New/Clone Bug” [1239065] Project Kickoff Form: Adjustments needed to Mozilla Infosec review portion [1240157] Fix a typo in bug.rst [1236461] Mass update mozilla-reps group discuss these changes on mozilla.tools.bmo.
+
+

the following changes have been pushed to bugzilla.mozilla.org:

+
    +
  • [1238573] Change label of “New Bug” menu to “New/Clone Bug”
  • +
  • [1239065] Project Kickoff Form: Adjustments needed to Mozilla Infosec review portion
  • +
  • [1240157] Fix a typo in bug.rst
  • +
  • [1236461] Mass update mozilla-reps group
  • +
+

discuss these changes on mozilla.tools.bmo.


+
+ 2016-01-19T14:49:59Z + + + dlawrence + + + https://dlawrence.wordpress.com + https://s2.wp.com/i/buttonw-com.png + + + + + Thoughts somehow related to web, linux, mobile and other things I am interested in + Dave's Ramblings + 2016-01-26T14:31:39Z + +
+ + + http://soledadpenades.com/?p=6335 + + + Hardware Hack Day @ MozLDN, 1 +
Last week we ran an internal “hack day” here at the Mozilla space in London. It was just a bunch of software engineers looking at various hardware boards and things and learning about them Here’s what we did! Sole I essentially kind of bricked my Arduino Duemilanove trying to get it working with Johnny Five, … Continue reading Hardware Hack Day @ MozLDN, 1
+
+

Last week we ran an internal “hack day” here at the Mozilla space in London. It was just a bunch of software engineers looking at various hardware boards and things and learning about them :-)

+

Here’s what we did!

+

Sole

+

I essentially kind of bricked my Arduino Duemilanove trying to get it working with Johnny Five, but it was fine–apparently there’s a way to recover it using another Arduino, and someone offered to help with that in the next NodeBots London, which I’m going to attend.

+

Francisco

+

Thinks he’s having issues with cables. It seems like the boards are not reset automatically by the Arduino IDE nowadays? He found the button in the board actually resets the board when pressed i.e. it’s the RESET button.

+

On the Raspberry Pi side of things, he was very happy to put all his old-school Linux skills in action configuring network interfaces without GUIs!

+

Guillaume

+

Played with mDNS advertising and listening to services on Raspberry Pi.

+

(He was very quiet)

+

(He also built a very nice LEGO case for the Raspberry Pi, but I do not have a picture, so just imagine it).

+

Wilson

+

+ Wilson: “I got my Raspberry Pi on the Wi-Fi”

+

Francisco: “Sorry?”

+

Wilson: “I mean, you got my Raspberry Pi on the network. And now I’m trying to build a web app on the Pi…”

+

Chris

+

Exploring the Pebble with Linux. There’s a libpebble, and he managed to connect…

+

(sorry, I had to leave early so I do not know what else did Chris do!)

+

Updated, 20 January: Chris told me he just managed to successfully connect to the Pebble watch using the bluetooth WebAPI. It requires two Gecko patches (one regression patch and one obvious logic error that he hasn’t filed yet). PROGRESS!

+

~~~

+

So as you can see we didn’t really get super far in just a day, and I even ended up with unusable hardware. BUT! we all learned something, and next time we know what NOT to do (or at least I DO KNOW what NOT to do!).

+

flattr this!

+
+ 2016-01-19T13:31:55Z + + + + + + + + + + sole + + + http://soledadpenades.com + + + repeat 4[fd 100 rt 90] + mozilla – soledad penadés + 2016-01-26T02:46:29Z + +
+ + + http://daniel.haxx.se/blog/?p=8544 + + “Subject: Urgent Warning” +
Back in December I got a desperate email from this person. A woman who said her Instagram had been hacked and since she found my contact info in the app she mailed me and asked for help. I of course replied and said that I have nothing to do with her being hacked but I … Continue reading “Subject: Urgent Warning”
+
+

Back in December I got a desperate email from this person. A woman who said her Instagram had been hacked and since she found my contact info in the app she mailed me and asked for help. I of course replied and said that I have nothing to do with her being hacked but I also have nothing to do with Instagram other than that they use software I’ve written.

+

Today she writes back. Clearly not convinced I told the truth before, and now she strikes back with more “evidence” of my wrongdoings.

+

Dear Daniel,

+

I had emailed you a couple months ago about my “screen dumps” aka screenshots and asked for your help with restoring my Instagram account since it had been hacked, my photos changed, and your name was included in the coding. You claimed to have no involvement whatsoever in developing a third party app for Instagram and could not help me salvage my original Instagram photos, pre-hacked, despite Instagram serving as my Photography portfolio and my career is a Photographer.

+

Since you weren’t aware that your name was attached to Instagram related hacking code, I thought you might want to know, in case you weren’t already aware, that your name is also included in Spotify terms and conditions. I came across this information using my Spotify which has also been hacked into and would love your help hacking out of Spotify. Also, I have yet to figure out how to unhack the hackers from my Instagram so if you change your mind and want to restore my Instagram to its original form as well as help me secure my account from future privacy breaches, I’d be extremely grateful. As you know, changing my passwords did nothing to resolve the problem. Please keep in mind that Facebook owns Instagram and these are big companies that you likely don’t want to have a trail of evidence that you are a part of an Instagram and Spotify hacking ring. Also, Spotify is a major partner of Spotify so you are likely familiar with the coding for all of these illegally developed third party apps. I’d be grateful for your help fixing this error immediately.

+

Thank you,

+

[name redacted]

+

P.S. Please see attached screen dump for a screen shot of your contact info included in Spotify (or what more likely seems to be a hacked Spotify developed illegally by a third party).

+

Spotify credits screenshot

+

Here’s the Instagram screenshot she sent me in a previous email:

+

Instagram credits screenshot

+

I’ve tried to respond with calm and clear reasonable logic and technical details on why she’s seeing my name there. That clearly failed. What do I try next?

+
+ 2016-01-19T08:37:32Z + + + + + + + Daniel Stenberg + + + http://daniel.haxx.se/blog + http://daniel.haxx.se/blog/wp-content/uploads/2015/08/cropped-Daniel-head-greenshirt-32x32.jpg + + + tech, open source and networking + daniel.haxx.se + 2016-01-26T07:16:26Z + +
+ + + http://edunham.net/2016/01/19/how_much_knowledge_do_you_need_to_give_a_conference_talk.html + + How much knowledge do you need to give a conference talk? +

How much knowledge do you need to give a conference talk?

+

I was recently asked an excellent question when I promoted the LFNW CFP on + IRC:

+
+
As someone who has never done a talk, but wants to, what kind of knowledge + do you need about a subject to give a talk on it?
+

If you answer “yes” to any of the following questions, you know enough to + propose a talk:

+
    +
  • Do you have a hobby that most tech people aren’t experts on? Talk + about applying a lesson or skill from that hobby to tech! For instance, I + turned a habit of reading about psychology into my Human Hacking talk.
  • +
  • Have you ever spent a bunch of hours forcing two tools to work with each + other, because the documentation wasn’t very helpful and Googling didn’t get + you very far, and built something useful? “How to build ___ with ___” makes + a catchy talk title, if the thing you built solves a common problem.
  • +
  • Have you ever had a mentor sit down with you and explain a tool or + technique, and the new understanding improved the quality of your work or + code? Passing along useful lessons from your mentors is a valuable talk, + because it allows others to benefit from the knowledge without taking as + much of your mentor’s time.
  • +
  • Have you seen a dozen newbies ask the same question over the course of a few + months? When your answer to a common question starts to feel like a + broken record, it’s time to compose it into a talk then link the newbies to + your slides or recording!
  • +
  • Have you taken a really interesting class lately? Can you distill part of it + into a 1-hour lesson that would appeal to nerds who don’t have the time or + resources to take the class themselves? (thanks lucyw for adding this to + the list!)
  • +
  • Have you built a cool thing that over a dozen other people use? A tutorial + talk can not only expand your community, but its recording can augment your + documentation and make the project more accessible for those who prefer to + learn directly from humans!
  • +
  • Did you benefit from a really great introductory talk when you were learning + a tool? Consider doing your own tutorial! Any conference with beginners in + their target audience needs at least one Git lesson, an IRC talk, and some + discussions of how to use basic Unix utilities. These introductory talks + are actually better when given by someone who learned the technology + relatively recently, because newer users remember what it’s like not to know + how to use it. Just remember to have a more expert user look over your slides + before you present, in case you made an incorrect assumption about the tool’s + more advanced functionality.
  • +
+

I personally try to propose talks I want to hear, because the dealine of a + CFP or conference is great motivation to prioritize a cool project over + ordinary chores.

+
+ 2016-01-19T08:00:00Z + + http://edunham.net/ + + Emily Dunham + + + + is a "DevOps" Engineer at Mozilla Research + edunham + 2016-01-19T08:00:00Z + +
+ + + https://quality.mozilla.org/?p=49441 + + Aurora 45.0 Testday Results +
Howdy mozillians! Last week – on Friday, January 15th – we held Aurora 45.0 Testday; and, of course, it was another outstanding event! Thank you all – Mahmoudi Dris, Iryna Thompson, Chandrakant Dhutadmal, Preethi Dhinesh, Moin Shaikh, Ilse Macías, Hossain Al Ikram, Rezaul Huque Nayeem, Tahsan Chowdhury Akash, Kazi Nuzhat Tasnem, Fahmida … Continue reading
+
+

Howdy mozillians!

+

Last week – on Friday, January 15th – we held Aurora 45.0 Testday; and, of course, it was another outstanding event!

+

Thank you all – Mahmoudi Dris, Iryna Thompson, Chandrakant Dhutadmal, Preethi Dhinesh, Moin Shaikh, Ilse Macías, Hossain Al Ikram, Rezaul Huque Nayeem, Tahsan Chowdhury Akash, Kazi Nuzhat Tasnem, Fahmida Noor, Tazin Ahmed, Md. Ehsanul Hassan, Mohammad Maruf Islam, Kazi Sakib Ahmad, Khalid Syfullah Zaman, Asiful Kabir, Tabassum Mehnaz, Hasibul Hasan, Saddam Hossain, Mohammad Kamran Hossain, Amlan Biswas, Fazle Rabbi, Mohammed Jawad Ibne Ishaque, Asif Mahmud Shuvo, Nazir Ahmed Sabbir, Md. Raihan Ali, Md. Almas Hossain, Sadik Khan, Md. Faysal Alam Riyad, Faisal Mahmud, Md. Oliullah Sizan, Asif Mahmud Rony, Forhad Hossain and Tanvir Rahman – for the participation!

+

A big thank you to all our active moderators too!

+

Results:

+ +

I strongly advise everyone of you to reach out to us, the moderators, via #qa during the events when you encountered any kind of failures. Keep up the great work! \o/

+

And keep an eye on QMO for upcoming events! 😉

+
+ 2016-01-19T07:51:57Z + + + + + Alexandra Lucinet + + + https://quality.mozilla.org + + + Driving quality across Mozilla with data, metrics and a strong community focus + Mozilla Quality Assurance + 2016-01-26T14:46:39Z + +
+ + + http://blog.monotonous.org/?p=678 + + + + It’s MLK Day and It’s Not Too Late to Do Something About It +
For the last three years I have had the opportunity to send out a reminder to Mozilla staff that Martin Luther King Jr. Day is coming up, and that U.S. employees get the day off. It has turned into my MLK Day eve ritual. I read his letters, listen to speeches, and then I compose […]
+
+

For the last three years I have had the opportunity to send out a reminder to Mozilla staff that Martin Luther King Jr. Day is coming up, and that U.S. employees get the day off. It has turned into my MLK Day eve ritual. I read his letters, listen to speeches, and then I compose a belabored paragraph about Dr. King with some choice quotes.

+

If you didn’t get a chance to celebrate Dr. King’s legacy and the movements he was a part of, you still have a chance:

+
+
+ 2016-01-18T23:35:19Z + 2016-01-18T23:34:26Z + + + + + Eitan + http://mememe82.wordpress.com/ + + + http://blog.monotonous.org/feed/atom/ + + + + + + Eitan's Pitch + Monotonous.org + 2016-01-18T23:45:54Z + +
+ + + http://www.ncameron.org/blog/rss/0e4d587c-380c-40ce-954a-7206f69bc1dd + + Libmacro +

As I outlined in an earlier post, libmacro is a new crate designed to be used by procedural macro authors. It provides the basic API for procedural macros to interact with the compiler. I expect higher level functionality to be provided by library crates. In this post I'll go into

+
+

As I outlined in an earlier post, libmacro is a new crate designed to be used by procedural macro authors. It provides the basic API for procedural macros to interact with the compiler. I expect higher level functionality to be provided by library crates. In this post I'll go into a bit more detail about the API I think should be exposed here.

+ +

This is a lot of stuff. I've probably missed something. If you use syntax extensions today and do something with libsyntax that would not be possible with libmacro, please let me know!

+ +

I previously introduced MacroContext as one of the gateways to libmacro. All procedural macros will have access to a &mut MacroContext.

+ +

Tokens

+ +

I described the tokens module in the last post, I won't repeat that here.

+ +

There are a few more things I thought of. I mentioned a TokenStream which is a sequence of tokens. We should also have TokenSlice which is a borrowed slice of tokens (the slice to TokenStream's Vec). These should implement the standard methods for sequences, in particular they support iteration, so can be maped, etc.

+ +

In the earlier blog post, I talked about a token kind called Delimited which contains a delimited sequence of tokens. I would like to rename that to Sequence and add a None variant to the Delimiter enum. The None option is so that we can have blocks of tokens without using delimiters. It will be used for noting unsafety and other properties of tokens. Furthermore, it is useful for macro expansion (replacing the interpolated AST tokens currently present). Although None blocks do not affect scoping, they do affect precedence and parsing.

+ +

We should provide API for creating tokens. By default these have no hygiene information and come with a span which has no place in the source code, but shows the source of the token to be the procedural macro itself (see below for how this interacts with expansion of the current macro). I expect a make_ function for each kind of token. We should also have API for creating macros in a given scope (which do the same thing but with provided hygiene information). This could be considered an over-rich API, since the hygiene information could be set after construction. However, since hygiene is fiddly and annoying to get right, we should make it as easy as possible to work with.

+ +

There should also be a function for creating a token which is just a fresh name. This is useful for creating new identifiers. Although this can be done by interning a string and then creating a token around it, it is used frequently enough to deserve a helper function.

+ +

Emitting errors and warnings

+ +

Procedural macros should report errors, warnings, etc. via the MacroContext. They should avoid panicking as much as possible since this will crash the compiler (once catch_panic is available, we should use it to catch such panics and exit gracefully, however, they will certainly still meaning aborting compilation).

+ +

Libmacro will 're-export' DiagnosticBuilder from syntax::errors. I don't actually expect this to be a literal re-export. We will use libmacro's version of Span, for example.

+ +
impl MacroContext {
+                pub fn struct_error(&self, &str) -> DiagnosticBuilder;
+                pub fn error(&self, Option<Span>, &str);
+                }
+
+                pub mod errors {
+                pub struct DiagnosticBuilder { ... }
+                impl DiagnosticBuilder { ... }
+                pub enum ErrorLevel { ... }
+                }
+            
+ +

There should be a macro try_emit!, which reduces a Result<T, ErrStruct> to a T or calls emit() and then calls unreachable!() (if the error is not fatal, then it should be upgraded to a fatal error).

+ +

Tokenising and quasi-quoting

+ +

The simplest function here is tokenize which takes a string (&str) and returns a Result<TokenStream, ErrStruct>. The string is treated like source text. The success option is the tokenised version of the string. I expect this function must take a MacroContext argument.

+ +

We will offer a quasi-quoting macro. This will return a TokenStream (in contrast to today's quasi-quoting which returns AST nodes), to be precise a Result<TokenStream, ErrStruct>. The string which is quoted may include metavariables ($x), and these are filled in with variables from the environment. The type of the variables should be either a TokenStream, a TokenTree, or a Result<TokenStream, ErrStruct> (in this last case, if the variable is an error, then it is just returned by the macro). For example,

+ +
fn foo(cx: &mut MacroContext, tokens: TokenStream) -> TokenStream {
+                quote!(cx, fn foo() { $tokens }).unwrap()
+                }
+            
+ +

The quote! macro can also handle multiple tokens when the variable corresponding with the metavariable has type [TokenStream] (or is dereferencable to it). In this case, the same syntax as used in macros-by-example can be used. For example, if x: Vec<TokenStream> then quote!(cx, ($x),*) will produce a TokenStream of a comma-separated list of tokens from the elements of x.

+ +

Since the tokenize function is a degenerate case of quasi-quoting, an alternative would be to always use quote! and remove tokenize. I believe there is utility in the simple function, and it must be used internally in any case.

+ +

These functions and macros should create tokens with spans and hygiene information set as described above for making new tokens. We might also offer versions which takes a scope and uses that as the context for tokenising.

+ +

Parsing helper functions

+ +

There are some common patterns for tokens to follow in macros. In particular those used as arguments for attribute-like macros. We will offer some functions which attempt to parse tokens into these patterns. I expect there will be more of these in time; to start with:

+ +
pub mod parsing {
+                // Expects `(foo = "bar"),*`
+                pub fn parse_keyed_values(&TokenSlice, &mut MacroContext) -> Result<Vec<(InternedString, String)>, ErrStruct>;
+                // Expects `"bar"`
+                pub fn parse_string(&TokenSlice, &mut MacroContext) -> Result<String, ErrStruct>;
+                }
+            
+ +

To be honest, given the token design in the last post, I think parse_string is unnecessary, but I wanted to give more than one example of this kind of function. If parse_keyed_values is the only one we end up with, then that is fine.

+ +

Pattern matching

+ +

The goal with the pattern matching API is to allow procedural macros to operate on tokens in the same way as macros-by-example. The pattern language is thus the same as that for macros-by-example.

+ +

There is a single macro, which I propose calling matches. Its first argument is the name of a MacroContext. Its second argument is the input, which must be a TokenSlice (or dereferencable to one). The third argument is a pattern definition. The macro produces a Result<T, ErrStruct> where T is the type produced by the pattern arms. If the pattern has multiple arms, then each arm must have the same type. An error is produced if none of the arms in the pattern are matched.

+ +

The pattern language follows the language for defining macros-by-example (but is slightly stricter). There are two forms, a single pattern form and a multiple pattern form. If the first character is a { then the pattern is treated as a multiple pattern form, if it starts with ( then as a single pattern form, otherwise an error (causes a panic with a Bug error, as opposed to returning an Err).

+ +

The single pattern form is (pattern) => { code }. The multiple pattern form is {(pattern) => { code } (pattern) => { code } ... (pattern) => { code }}. code is any old Rust code which is executed when the corresponding pattern is matched. The pattern follows from macros-by-example - it is a series of characters treated as literals, meta-variables indicated with $, and the syntax for matching multiple variables. Any meta-variables are available as variables in the righthand side, e.g., $x becomes available as x. These variables have type TokenStream if they appear singly or Vec<TokenStream> if they appear multiply (or Vec<Vec<TokenStream>> and so forth).

+ +

Examples:

+ +
matches!(cx, input, (foo($x:expr) bar) => {quote(cx, foo_bar($x).unwrap()}).unwrap()
+
+                matches!(cx, input, {
+                () => {
+                cx.err("No input?");
+                }
+                (foo($($x:ident),+ bar) => {
+                println!("found {} idents", x.len());
+                quote!(($x);*).unwrap()
+                }
+                }
+                })
+            
+ +

Note that since we match AST items here, our backwards compatibility story is a bit complicated (though hopefully not much more so than with current macros).

+ +

Hygiene

+ +

The intention of the design is that the actual hygiene algorithm applied is irrelevant. Procedural macros should be able to use the same API if the hygiene algorithm changes (of course the result of applying the API might change). To this end, all hygiene objects are opaque and cannot be directly manipulated by macros.

+ +

I propose one module (hygiene) and two types: Context and Scope.

+ +

A Context is attached to each token and contains all hygiene information about that token. If two tokens have the same Context, then they may be compared syntactically. The reverse is not true - two tokens can have different Contexts and still be equal. Contexts can only be created by applying the hygiene algorithm and cannot be manipulated, only moved and stored.

+ +

MacroContext has a method fresh_hygiene_context for creating a new, fresh Context (i.e., a Context not shared with any other tokens).

+ +

MacroContext has a method expansion_hygiene_context for getting the Context where the macro is defined. This is equivalent to .expansion_scope().direct_context(), but might be more efficient (and I expect it to be used a lot).

+ +

A Scope provides information about a position within an AST at a certain point during macro expansion. For example,

+ +
fn foo() {
+                a
+                {
+                b
+                c
+                }
+                }
+            
+ +

a and b will have different Scopes. b and c will have the same Scopes, even if b was written in this position and c is due to macro expansion. However, a Scope may contain more information than just the syntactic scopes, for example, it may contain information about pending scopes yet to be applied by the hygiene algorithm (i.e., information about let expressions which are in scope).

+ +

Note that a Scope means a scope in the macro hygiene sense, not the commonly used sense of a scope declared with {}. In particular, each let statement starts a new scope and the items and statements in a function body are in different scopes.

+ +

The functions lookup_item_scope and lookup_statement_scope take a MacroContext and a path, represented as a TokenSlice, and return the Scope which that item defines or an error if the path does not refer to an item, or the item does not define a scope of the right kind.

+ +

The function lookup_scope_for is similar, but returns the Scope in which an item is declared.

+ +

MacroContext has a method expansion_scope for getting the scope in which the current macro is being expanded.

+ +

Scope has a method direct_context which returns a Context for items declared directly (c.f., via macro expansion) in that Scope.

+ +

Scope has a method nested which creates a fresh Scope nested within the receiver scope.

+ +

Scope has a static method empty for creating an empty scope, that is one with no scope information at all (note that this is different from a top-level scope).

+ +

I expect the exact API around Scopes and Contexts will need some work. Scope seems halfway between an intuitive, algorithm-neutral abstraction, and the scopes from the sets of scopes hygiene algorithm. I would prefer a Scope should be more abstract, on the other hand, macro authors may want fine-grained control over hygiene application.

+ +

Manipulating hygiene information on tokens,

+ +
pub mod hygiene {
+                pub fn add(cx: &mut MacroContext, t: &Token, scope: &Scope) -> Token;
+                // Maybe unnecessary if we have direct access to Tokens.
+                pub fn set(t: &Token, cx: &Context) -> Token;
+                // Maybe unnecessary - can use set with cx.expansion_hygiene_context().
+                // Also, bad name.
+                pub fn current(cx: &MacroContext, t: &Token) -> Token;
+                }
+            
+ +

add adds scope to any context already on t (Context should have a similar method). Note that the implementation is a bit complex - the nature of the Scope might mean we replace the old context completely, or add to it.

+ +

Applying hygiene when expanding the current macro

+ +

By default, the current macro will be expanded in the standard way, having hygiene applied as expected. Mechanically, hygiene information is added to tokens when the macro is expanded. Assuming the sets of scopes algorithm, scopes (for example, for the macro's definition, and for the introduction) are added to any scopes already present on the token. A token with no hygiene information will thus behave like a token in a macro-by-example macro. Hygiene due to nested scopes created by the macro do not need to be taken into account by the macro author, this is handled at expansion time.

+ +

Procedural macro authors may want to customise hygiene application (it is common in Racket), for example, to introduce items that can be referred to by code in the call-site scope.

+ +

We must provide an option to expand the current macro without applying hygiene; the macro author must then handle hygiene. For this to work, the macro must be able to access information about the scope in which it is applied (see MacroContext::expansion_scope, above) and to supply a Scope indicating scopes that should be added to tokens following the macro expansion.

+ +
pub mod hygiene {
+                pub enum ExpansionMode {
+                Automatic,
+                Manual(Scope),
+                }
+                }
+
+                impl MacroContext {
+                pub fn set_hygienic_expansion(hygiene::ExpansionMode);
+                }
+            
+ +

We may wish to offer other modes for expansion which allow for tweaking hygiene application without requiring full manual application. One possible mode is where the author provides a Scope for the macro definition (rather than using the scope where the macro is actually defined), but hygiene is otherwise applied automatically. We might wish to give the author the option of applying scopes due to the macro definition, but not the introduction scopes.

+ +

On a related note, might we want to affect how spans are applied when the current macro is expanded? I can't think of a use case right now, but it seems like something that might be wanted.

+ +

Blocks of tokens (that is a Sequence token) may be marked (not sure how, exactly, perhaps using a distinguished context) such that it is expanded without any hygiene being applied or spans changed. There should be a function for creating such a Sequence from a TokenSlice in the tokens module. The primary motivation for this is to handle the tokens representing the body on which an annotation-like macro is present. For a 'decorator' macro, these tokens will be untouched (passed through by the macro), and since they are not touched by the macro, they should appear untouched by it (in terms of hygiene and spans).

+ +

Applying macros

+ +

We provide functionality to expand a provided macro or to lookup and expand a macro.

+ +
pub mod apply {
+                pub fn expand_macro(cx: &mut MacroContext,
+                expansion_scope: Scope,
+                macro: &TokenSlice,
+                macro_scope: Scope,
+                input: &TokenSlice)
+                -> Result<(TokenStream, Scope), ErrStruct>;
+                pub fn lookup_and_expand_macro(cx: &mut MacroContext,
+                expansion_scope: Scope,
+                macro: &TokenSlice,
+                input: &TokenSlice)
+                -> Result<(TokenStream, Scope), ErrStruct>;
+                }
+            
+ +

These functions apply macro hygiene in the usual way, with expansion_scope dictating the scope into which the macro is expanded. Other spans and hygiene information is taken from the tokens. expand_macro takes pending scopes from macro_scope, lookup_and_expand_macro uses the proper pending scopes. In order to apply the hygiene algorithm, the result of the macro must be parsable. The returned scope will contain pending scopes that can be applied by the macro to subsequent tokens.

+ +

We could provide versions that don't take an expansion_scope and use cx.expansion_scope(). Probably unnecessary.

+ +
pub mod apply {
+                pub fn expand_macro_unhygienic(cx: &mut MacroContext,
+                macro: &TokenSlice,
+                input: &TokenSlice)
+                -> Result<TokenStream, ErrStruct>;
+                pub fn lookup_and_expand_macro_unhygienic(cx: &mut MacroContext,
+                macro: &TokenSlice,
+                input: &TokenSlice)
+                -> Result<TokenStream, ErrStruct>;
+                }
+            
+ +

The _unhygienic variants expand a macro as in the first functions, but do not apply the hygiene algorithm or change any hygiene information. Any hygiene information on tokens is preserved. I'm not sure if _unhygienic are the right names - using these is not necessarily unhygienic, just that we are automatically applying the hygiene algorithm.

+ +

Note that all these functions are doing an eager expansion of macros, or in Scheme terms they are local-expand functions.

+ +

Looking up items

+ +

The function lookup_item takes a MacroContext and a path represented as a TokenSlice and returns a TokenStream for the item referred to by the path, or an error if name resolution failed. I'm not sure where this function should live.

+ +

Interned strings

+ +
pub mod strings {
+                pub struct InternedString;
+
+                impl InternedString {
+                pub fn get(&self) -> String;
+                }
+
+                pub fn intern(cx: &mut MacroContext, s: &str) -> Result<InternedString, ErrStruct>;
+                pub fn find(cx: &mut MacroContext, s: &str) -> Result<InternedString, ErrStruct>;
+                pub fn find_or_intern(cx: &mut MacroContext, s: &str) -> Result<InternedString, ErrStruct>;
+                }
+            
+ +

intern interns a string and returns a fresh InternedString. find tries to find an existing InternedString.

+ +

Spans

+ +

A span gives information about where in the source code a token is defined. It also gives information about where the token came from (how it was generated, if it was generated code).

+ +

There should be a spans module in libmacro, which will include a Span type which can be easily inter-converted with the Span defined in libsyntax. Libsyntax spans currently include information about stability, this will not be present in libmacro spans.

+ +

If the programmer does nothing special with spans, then they will be 'correct' by default. There are two important cases: tokens passed to the macro and tokens made fresh by the macro. The former will have the source span indicating where they were written and will include their history. The latter will have no source span and indicate they were created by the current macro. All tokens will have the history relating to expansion of the current macro added when the macro is expanded. At macro expansion, tokens with no source span will be given the macro use-site as their source.

+ +

Spans can be freely copied between tokens.

+ +

It will probably useful to make it easy to manipulate spans. For example, rather than point at the macro's defining function, point at a helper function where the token is made. Or to set the origin to the current macro when the token was produced by another which should an implementation detail. I'm not sure what such an interface should look like (and is probably not necessary in an initial library).

+ +

Feature gates

+ +
pub mod features {
+                pub enum FeatureStatus {
+                // The feature gate is allowed.
+                Allowed,
+                // The feature gate has not been enabled.
+                Disallowed,
+                // Use of the feature is forbidden by the compiler.
+                Forbidden,
+                }
+
+                pub fn query_feature(cx: &MacroContext, feature: Token) -> Result<FeatureStatus, ErrStruct>;
+                pub fn query_feature_by_str(cx: &MacroContext, feature: &str) -> Result<FeatureStatus, ErrStruct>;
+                pub fn query_feature_unused(cx: &MacroContext, feature: Token) -> Result<FeatureStatus, ErrStruct>;
+                pub fn query_feature_by_str_unused(cx: &MacroContext, feature: &str) -> Result<FeatureStatus, ErrStruct>;
+
+                pub fn used_feature_gate(cx: &MacroContext, feature: Token) -> Result<(), ErrStruct>;
+                pub fn used_feature_by_str(cx: &MacroContext, feature: &str) -> Result<(), ErrStruct>;
+
+                pub fn allow_feature_gate(cx: &MacroContext, feature: Token) -> Result<(), ErrStruct>;
+                pub fn allow_feature_by_str(cx: &MacroContext, feature: &str) -> Result<(), ErrStruct>;
+                pub fn disallow_feature_gate(cx: &MacroContext, feature: Token) -> Result<(), ErrStruct>;
+                pub fn disallow_feature_by_str(cx: &MacroContext, feature: &str) -> Result<(), ErrStruct>;
+                }
+            
+ +

The query_* functions query if a feature gate has been set. They return an error if the feature gate does not exist. The _unused variants do not mark the feature gate as used. The used_ functions mark a feature gate as used, or return an error if it does not exist.

+ +

The allow_ and disallow_ functions set a feature gate as allowed or disallowed for the current crate. These functions will only affect feature gates which take affect after parsing and expansion are complete. They do not affect feature gates which are checked during parsing or expansion.

+ +

Question: do we need the used_ functions? Could just call query_ and ignore the result.

+ +

Attributes

+ +

We need some mechanism for setting attributes as used. I don't actually know how the unused attribute checking in the compiler works, so I can't spec this area. But, I expect MacroContext to make available some interface for reading attributes on a macro use and marking them as used.

+
+ 2016-01-18T21:40:42Z + + + + Nick Cameron + + + http://www.ncameron.org/blog/ + + + I'm a research engineer at Mozilla working on Rust: the language, compiler, and tools. @nick_r_cameron + featherweight musings + 2016-01-21T08:46:18Z + +
+ + + http://geekyogre.com/rss/63eb682d-66b4-447d-8fb6-f4ed448019df + + Skizze progress and REPL +


+

+ Over the last 3 weeks, based on feedback we proceeded fledging out the concepts and the code behind Skizze.
+ Neil Patel suggested the following:

+ +
+ +

So I've been thinking about the server API. I think we want to choose one thing and do it as well as possible, instead of having

+
+


+

+ Over the last 3 weeks, based on feedback we proceeded fledging out the concepts and the code behind Skizze.
+ Neil Patel suggested the following:

+ +
+ +

So I've been thinking about the server API. I think we want to choose one thing and do it as well as possible, instead of having six ways to talk to the server. I think that helps to keep things sane and simple overall.

+ +

Thinking about usage, I can only really imagine Skizze in an environment like ours, which is high-throughput. I think that is it's 'home' and we should be optimising for that all day long.

+ +

Taking that into account, I believe we have two options:

+ +
    +
  1. We go the gRPC route, provide .proto files and let people use the existing gRPC tooling to build support for their favourite language. That means we can happily give Ruby/Node/C#/etc devs a real way to get started up with Skizze almost immediately, piggy-backing on the gRPC docs etc.

  2. +
  3. We absorb the Redis Protocol. It does everything we need, is very lean, and we can (mostly) easily adapt it for what we need to do. The downside is that to get support from other libs, there will have to be actual libraries for every language. This could slow adoption, or it might be easy enough if people can reuse existing REDIS code. It's hard to tell how that would end up.

  4. +
+ +

gRPC is interesting because it's built already for distributed systems, across bad networks, and obviously is bi-directional etc. Without us having to spend time on the protocol, gRPC let's us easily add features that require streaming. Like, imagine a client being able to listen for changes in count/size and be notified instantly. That's something that gRPC is built for right now.

+ +

I think gRPC is a bit verbose, but I think it'll pay off for ease of third-party lib support and as things grow.

+ +

The CLI could easily be built to work with gRPC, including adding support for streaming stuff etc. Which could be pretty exciting.

+ +
+ +

That being said, we gave Skizze a new home, where based on feedback we developed .proto files and started rewriting big chunks of the code.

+ +

We added a new wrapper called "domain" which represents a stream. It wraps around Count-Min-Log, Bloom Filter, Top-K and HyperLogLog++, so when feeding it values it feeds all the sketches. Later we intend to allow attaching and detaching sketches from "domains" (We need a better name).

+ +

We also implemented a gRPC API which should allow easy wrapper creation in other languages.

+ +

Special thanks go to Martin Pinto for helping out with unit tests and Soren Macbeth for thorough feedback and ideas about the "domain" concept.
+ Take a look at our initial REPL work there:

+ +

Link to this page
+ click for GIF

+
+ 2016-01-18T17:41:43Z + + + + Seif Lotfy + + + http://geekyogre.com/ + + + The geekiest ogre alive + Geeky Ogre + 2016-01-18T18:16:25Z + +
+ + + http://dougbelshaw.com/blog/?p=39986 + + What a post-Persona landscape means for Open Badges + Why you shouldn't worry about Mozilla's recent announcement. +

Note: I don’t work for Mozilla any more, so (like Adele) these are my thoughts ‘from the outside’…

+
+

Introduction

+

Open Badges is no longer a Mozilla project. In fact, it hasn’t been for a while — the Badge Alliance was set up a couple of years ago to promote the specification on a both a technical and community basis. As I stated in a recent post, this is a good thing and means that the future is bright for Open Badges.

+

However, Mozilla is still involved with the Open Badges project: Mark Surman, Executive Director of the Mozilla Foundation, sits on the board of the Badge Alliance. Mozilla also pays for contractors to work on the Open Badges backpack and there were badges earned at the Mozilla Festival a few months ago.

+

Although it may seem strange for those used to corporates interested purely in profit, Mozilla creates what the open web needs at any given time. Like any organisation, sometimes it gets these wrong, either because the concept was flawed, or because the execution was poor. Other times, I’d argue, Mozilla doesn’t give ideas and concepts enough time to gain traction.

+

The end of Persona at Mozilla

+

Open Badges, at its very essence, is a technical specification. It allows credentials with metadata hard-coded into them to be issued, exchanged, and displayed. This is done in a secure, standardised manner.

+

OBI diagram

+

For users to be able to access their ‘backpack’ (i.e. the place they store badges) they needed a secure login system.Back in 2011 at the start of the Open Badges project it made sense to make use of Mozilla’s nascent Persona project. This aimed to provide a way for users to easily sign into sites around the web without using their Facebook/Google logins. These ‘social’ sign-in methods mean that users are tracked around the web — something that Mozilla was obviously against.

+

By 2014, Persona wasn’t seen to be having the kind of ‘growth trajectory’ that Mozilla wanted. The project was transferred to community ownership and most of the team left Mozilla in 2015. It was announced that Persona would be shutting down as a Mozilla service in November 2016. While Persona will exist as an open source project, it won’t be hosted by Mozilla.

+

What this means for Open Badges

+

Although I’m not aware of an official announcement from the Badge Alliance, I think it’s worth making three points here.

+
1. You can still use Persona
+

If you’re a developer, you can still use Persona. It’s open source. It works.

+
2. Persona is not central to the Open Badges Infrastructure
+

The Open Badges backpack is one place where users can store their badges. There are others, including the Open Badge Passport and Open Badge Academy. MacArthur, who seed-funded the Open Badges ecosystem, have a new platform launching through LRNG.

+

It is up to the organisations behind these various solutions as to how they allow users to authenticate. They may choose to allow social logins. They may force users to create logins based on their email address. They may decide to use an open source version of Persona. It’s entirely up to them.

+
3. A post-Persona badges system has its advantages
+

The Persona authentication system runs off email addresses. This means that transitioning from Persona to another system is relatively straightforward. It has, however, meant that for the past few years we’ve had a recurrent problem: what do you do with people being issued badges to multiple email addresses?

+

Tying badges to emails seemed like the easiest and fastest way to get to a critical mass in terms of Open Badge adoption. Now that’s worked, we need to think in a more nuanced way about allowing users to tie multiple identities to a single badge.

+

Conclusion

+

Persona was always a slightly awkward fit for Open Badges. Although, for a time, it made sense to use Persona for authentication to the Open Badges backpack, we’re now in a post-Persona landscape. This brings with it certain advantages.

+

As Nate Otto wrote in his post Open Badges in 2016: A Look Ahead, the project is growing up. It’s time to move beyond what was expedient at the dawn of Open Badges and look to the future. I’m sad to see the decline of Persona, but I’m excited what the future holds!

+

Header image CC BY-NC-SA Barbara

+
+ 2016-01-18T11:34:19Z + + + + + + + Doug Belshaw + + + http://dougbelshaw.com/blog + http://dougbelshaw.com/blog/wp-content/plugins/podpress/images/powered_by_podpress_large.jpg + + + + + + + + + + + + Doug Belshaw + dajbelshaw@gmail.com + + + + Copyright © Open Educational Thinkering 2013 + Doug Belshaw's blog + Mozilla – Doug Belshaw’s blog + 2016-01-23T07:46:17Z + +
+ + + tag:this-week-in-rust.org,2016-01-18:blog/2016/01/18/this-week-in-rust-114/ + + This Week in Rust 114 +

Hello and welcome to another issue of This Week in Rust! + Rust is a systems language pursuing the trifecta: + safety, concurrency, and speed. This is a weekly summary of its progress and + community. Want something mentioned? Tweet us at @ThisWeekInRust or send us an + email! + Want to get involved? We love + contributions.

+

This Week in Rust is openly developed on GitHub. + If you find any errors in this week's issue, please submit a PR.

+

This week's edition was edited by: nasa42, brson, and llogiq.

+

Updates from Rust Community

+

News & Blog Posts

+ +

Notable New Crates & Project Updates

+ +

Updates from Rust Core

+

164 pull requests were merged in the last week.

+

See the triage digest and subteam reports for more details.

+

Notable changes

+ +

New Contributors

+
    +
  • Anton Blanchard
  • +
  • Jonas Tepe
  • +
  • Jörg Krause
  • +
  • Joshua Olson
  • +
  • kalita.alexey
  • +
  • Pierre Krieger
  • +
  • Sergey Veselkov
  • +
  • Simon Martin
  • +
  • Steffen
  • +
  • tomaka
  • +
+

Approved RFCs

+

Changes to Rust follow the Rust RFC (request for comments) + process. These + are the RFCs that were approved for implementation this week:

+ +

Final Comment Period

+

Every week the team announces the + 'final comment period' for RFCs and key PRs which are reaching a + decision. Express your opinions now. This week's FCPs are:

+ +

New RFCs

+ +

Upcoming Events

+ +

If you are running a Rust event please add it to the calendar to get + it mentioned here. Email Erick Tryzelaar or Brian + Anderson for access.

+

fn work(on: RustProject) -> Money

+ +

Tweet us at @ThisWeekInRust to get your job offers listed here!

+

Crate of the Week

+

This week's Crate of the Week is toml, a crate for all our configuration needs, simple yet effective.

+

Thanks to Steven Allen for the suggestion.

+

Submit your suggestions for next week!

+

Quote of the Week

+
+

Borrow/lifetime errors are usually Rust compiler bugs. + Typically, I will spend 20 minutes detailing the precise conditions of + the bug, using language that understates my immense knowledge, while + demonstrating sympathetic understanding of the pressures placed on a + Rust compiler developer, who is also probably studying for several exams + at the moment. The developer reading my bug report may not understand + this stuff as well as I do, so I will carefully trace the lifetimes of + each variable, where memory is allocated on the stack vs the heap, which + struct or function owns a value at any point in time, where borrows + begin and where they... oh yeah, actually that variable really doesn't + live long enough.

+
+

peterjoel on /r/rust.

+

Thanks to Wa Delma for the suggestion.

+

Submit your quotes for next week!

+
+ 2016-01-18T05:00:00Z + + Corey Richardson + + + http://this-week-in-rust.org/ + + + This Week in Rust + 2016-01-25T05:00:00Z + +
+ + + http://nikkisquared.github.io/2016/01/17/what-does-your-work-mean-part-2.html + + Okay, But What Does Your Work Actually Mean, Nikki? Part 2: The Fetch Standard and Servo +

In my previous post, I started discussing in more detail what my internship entails, by talking about my first contribution to Servo. As a refresher, my first contribution was as part of my application to Outreachy, which I later revisited during my internship after a change I introduced to the HTML Standard it relied on. I’m going to expand on that last point today- specifically, how easy it is to introduce changes in WHATWG’s various standards. I’m also going to talk about how this accessibility to changing web standards affects how I can understand it, how I can help improve it, and my work on Servo.

+ +

Two Ways To Change

+ +

There are many ways to get involved with WHATWG, but there are two that I’ve become the most familiar with: firstly, by opening a discussion about a perceived issue and asking how it should be resolved; secondly, by taking on an issue approved as needing change and making the desired change. I’ve almost entirely only done the former, and the latter only for some minor typos. Any changes that relate directly to my work, however minor, are significant for me though! Like I discussed in my previous post, I brought attention to an inconsistency that was resolved, giving me a new task of updating my first contribution to Servo to reflect the change in the HTML Standard. I’ve done that several times since, for the Fetch Standard.

+ +

Understanding Fetch

+ +

My first two weeks of my internship were spent on reading through the majority of the Fetch Standard, primarily the various Fetch functions. I took many notes describing the steps to myself, annotated with questions I had and the answers I got from either other people on the Servo team who had worked with Fetch (including my internship mentor, of course!) or people from WHATWG who were involved in the Fetch Standard. Getting so familiar with Fetch meant a few things: I would notice minor errors (such as an out of date link) that I could submit a simple fix for, or a bigger issue that I couldn’t resolve myself.

+ +

Discussions & Resolutions

+ +

I’m going to go into more detail about some of those bigger issues. From my perspective, when I start a discussion about a piece of documentation (such as the Fetch Standard, or reading about a programming library Servo uses), I go into it thinking “Either this documentation is incorrect, or my understanding is incorrect”. Whichever the answer is, it doesn’t mean that the documentation is bad, or that I’m bad at reading comprehension. I understand best by building up a model of something in my head, putting that to practice, and asking a lot of questions along the way. I learn by getting things wrong and figuring out why I was wrong, and sometimes in the process I uncover a point that could be made more clear, or an inconsistency! I have good examples of both of the different outcomes I listed, which I’ll cover over the next two sections.

+ +
Looking For The Big Picture
+ +

Early on in my initial review of the Fetch Standard’s several protocols, I found a major step that seemed to have no use. I understood that since I was learning Fetch on a step-by-step basis, I did not have a view of the bigger picture, so I asked around what I was missing that would help me understand this. One of the people I work with on implementing Fetch agreed with me that the step seemed to have no purpose, and so we decided to open an issue asking about removing it from the standard. It turned out that I had actually missed the meaning of it, as we learned. However, instead of leaving it there, I shifted the issue into asking for some explanatory notes on why this step is needed, which was fulfilled. This meant that I would have a reference to go back to should I forget the significance of the step, and that people reading the Fetch Standard in the future would be much less likely to come to the same incorrect conclusion I had.

+ +
A Confusing Order
+ +

Shortly after I had first discovered that apparent issue, I found myself struggling to comprehend a sequence of actions in another Fetch protocol. The specification seemed to say that part of an early step was meant to only be done after the final step. I unfortunately don’t remember details of the discussion I had about this- if there was a reason for why it was organized like this, I forget what it was. Regardless, it was agreed that moving those sub-steps to be actually listed after the step they’re supposed to run after would be a good change. This meant that I would need to re-organize my notes to reflect the re-arranged sequence of actions, as well as have an easier time being able to follow this part of the Fetch Standard.

+ +

A Living Standard

+ +

Like I said at the start of this post, I’m going to talk about how changes in the Fetch Standard affects my work on Servo itself. What I’ve covered so far has mostly been how changes affect my understanding of the standard itself. A key aspect in understanding the Fetch protocols is reviewing them for updates that impact me. WHATWG labels every standard they author as a “Living Standard” for good reason. It was one thing for me to learn how easy it is to introduce changes, while knowing exactly what’s going on, but it’s another for me to understand that anybody else can, and often does, make changes to the Fetch Standard!

+ +
Changes Over Time
+ +

When an update is made to the Fetch Standard, it’s not so difficult to deal with as one might imagine. The Fetch Standard always notes the last day it was updated at the top of the document, I follow a Twitter account that posts about updates, and all the history can be seen on GitHub which will show me exactly what has been changed as well as some discussion on what the change does. All of these together alert me to the fact that the Fetch Standard has been modified, and I can quickly see what was revised. If it’s relevant to what I’m going to be implementing, I update my notes to match it. Occasionally, I need to change existing code to reflect the new Standard, which is also easily done by comparing my new notes to the Fetch implementation in Servo!

+ +
Snapshots
+ +

From all of this, it might sound like the Fetch Standard is unfinished, or unreliable/inconsistent. I don’t mean to misrepresent it- the many small improvements help make the Fetch Standard, like all of WHATWG’s standards, better and more reliable. You can think of the status of the Fetch Standard at any point in time as a single, working snapshot. If somebody implemented all of Fetch as it is now, they’d have something that works by itself correctly. A different snapshot of Fetch is just that- different. It will have an improvement or two, but that doesn’t obsolete anybody who implemented it previously. It just means if they revisit the implementation, they’ll have things to update.

+ +

Third post over.

+
+ 2016-01-17T20:20:27Z + + + + http://nikkisquared.github.io/ + + Nikki Bee + + + + Hi! I'm currently doing an internship for Outreachy. Wow! + Nikki Bee Blog + 2016-01-18T05:28:11Z + +
+ + + http://ngokevin.com/blog/aframe-component/ + + How to Write an A-Frame VR Component +
Abstract representation of components by @rubenmueller of thevrjump.com. + +

A-Frame is a WebVR framework that introduces the + entity-component system (docs) to the DOM. The + entity-component system treats every entity in the scene as a placeholder + object which we apply and mix components to in order to add appearance, + behavior, and functionality. A-Frame comes with some standard components out of + the box like camera, geometry, material, light, or sound. However, people can + write, publish, and register their own components to do whatever they want + like have entities collide/explode/spawn, be controlled by + physics, or follow a path. Today, we'll be going through + how we can write our own A-Frame components.

+
+

Note that this tutorial will be covering the upcoming release of A-Frame + 0.2.0 which vastly improves the component API.

+
+

Table of Contents

+ +

What a Component Looks Like

+

A component contains a bucket of data in the form of component properties. This + data is used to modify the entity. For example, we might have an engine + component. Possible properties might be horsepower or cylinders.

+

+

+ Abstract representation of a component by @rubenmueller of thevrjump.com. +

+

From the DOM

+

Let's first see what a component looks like from the DOM.

+

For example, the light component has properties such as type, color, + and intensity. In A-Frame, we register and configure a component to an entity + using an HTML attribute and a style-like syntax:

+
<a-entity light="type: point; color: crimson; intensity: 2.5"></a-entity>
+            
+ + +

This would give us a light in the scene. To demonstrate composability, we could + give the light a spherical representation by mixing in the geometry + component.

+
<a-entity geometry="primitive: sphere; radius: 5"
+                light="type: point; color: crimson; intensity: 2.5"></a-entity>
+            
+ + +

Or we can configure the position component to move the light sphere a bit to the right.

+
<a-entity geometry="primitive: sphere; radius: 5"
+                light="type: point; color: crimson; intensity: 2.5"
+                position="5 0 0"></a-entity>
+            
+ + +

Given the style-like syntax and that it modifies the appearance and behavior of + DOM nodes, component properties can be thought of as a rough analog to CSS. In + the near future, I can imagine component property stylesheets.

+

Under the Hood

+

Now let's see what a component looks like under the hood. A-Frame's most + basic component is the position component:

+
AFRAME.registerComponent('position', {
+                schema: { type: 'vec3' },
+
+                update: function () {
+                var object3D = this.el.object3D;
+                var data = this.data;
+                object3D.position.set(data.x, data.y, data.z);
+                }
+                });
+            
+ + +

The position component uses only a tiny subset of the component API, but what + this does is register the component with the name "position", define a schema + where the component's value with be parsed to an {x, y, z} object, and when + the component initializes or the component's data updates, set the position of + the entity with the update callback. this.el is a reference from the + component to the DOM element, or entity, and object3D is the entity's + three.js. Note that A-Frame is built on top of three.js so many + components will be using the three.js API.

+

So we see that components consist of a name and a definition, and then they can + be registered to A-Frame. We saw the the position component definition defined + a schema and an update handler. Components simply consist of the schema, + which defines the shape of the data, and several handlers for the component to + modify the entity in reaction to different types of events.

+

Here is the current list of properties and methods of a component definition:

+ + + + + + + + + + + + + + + + + +
PropertyDescription
dataData of the component derived from the schema default values, mixins, and the entity's attributes.
elReference to the entity element.
schemaNames, types, and default values of the component property value(s)
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
MethodDescription
initCalled once when the component is initialized.
updateCalled both when the component is initialized and whenever the component's data changes (e.g, via setAttribute).
removeCalled when the component detaches from the element (e.g., via removeAttribute).
tickCalled on each render loop or tick of the scene.
playCalled whenever the scene or entity plays to add any background or dynamic behavior.
pauseCalled whenever the scene or entity pauses to remove any background or dynamic behavior.
+ +

Defining the Schema

+

The component's schema defines what type of data it takes. A component can + either be single-property or consist of multiple properties. And properties + have property types. Note that single-property schemas and property types are + being released in A-Frame v0.2.0.

+

A property might look like:

+
{ type: 'int', default: 5 }
+            
+ + +

And a schema consisting of multiple properties might look like:

+
{
+                color: { default: '#FFF' },
+                target: { type: 'selector' },
+                uv: {
+                default: '1 1',
+                parse: function (value) {
+                return value.split(' ').map(parseFloat);
+                }
+                },
+                }
+            
+ + +

Since components in the entity-component system are just buckets of data that + are used to affect the appearance or behavior of the entity, the schema plays a + crucial role in the definition of the component.

+

Property Types

+

A-Frame comes with several built-in property types such as boolean, int, + number, selector, string, or vec3. Every single property is assigned a + type, whether explicitly through the type key or implictly via inferring the + value. And each type is used to assign parse and stringify functions. The + parser deserializes the incoming string value from the DOM to be put into the + component's data object. The stringifier is used when using setAttribute to + serialize back to the DOM.

+

We can actually define and register our own property types:

+
AFRAME.registerPropertyType('radians', {
+                parse: function () {
+
+                }
+
+                // Default stringify is .toString().
+                });
+            
+ + +

Single-Property Schemas

+

If a component has only one property, then it must either have a type or a + default value. If the type is defined, then the type is used to parse and + coerce the string retrieved from the DOM (e.g., getAttribute). Or if the + default value is defined, the default value is used to infer the type.

+

Take for instance the visible component. The schema property + definition implicitly defines it as a boolean:

+
AFRAME.registerComponent('visible', {
+                schema: {
+                // Type will be inferred to be boolean.
+                default: true
+                },
+
+                // ...
+                });
+            
+ + +

Or the rotation component which explicitly defines the value as a vec3:

+
AFRAME.registerComponent('rotation', {
+                schema: {
+                // Default value will be 0, 0, 0 as defined by the vec3 property type.
+                type: 'vec3'
+                }
+
+                // ...
+                });
+            
+ + +

Using these defined property types, schemas are processed by + registerComponent to inject default values, parsers, and stringifiers for + each property. So if a default value is not defined, the default value will be + whatever the property type defines as the "default default value".

+

Multiple-Property Schemas

+

If a component has multiple properties (or one named property), then it consists of + one or more property definitions, in the form described above, in an object keyed by + property name. For instance, a physics body component might define a schema:

+
AFRAME.registerComponent('physics-body', {
+                schema: {
+                boundingBox: {
+                type: 'vec3',
+                default: { x: 1, y: 1, z: 1 }
+                },
+                mass: {
+                default: 0
+                },
+                velocity: {
+                type: 'vec3'
+                }
+                }
+                }
+            
+ + +

Having multiple properties is what makes the component take the syntax in the + form of physics="mass: 2; velocity: 1 1 1".

+

With the schema defined, all data coming into the component will be passed + through the schema for parsing. Then in the lifecycle methods, the component + has access to this.data which in a single-property schema is a value and in a + multiple-propery schema is an object.

+

Defining the Lifecycle Methods

+

Component.init() - Set Up

+

init is called once in the component's lifecycle when it is mounted to the + entity. init is generally used to set up variables or members that may used + throughout the component or to set up state. Though not every component will + need to define an init handler. Sort of like the component-equivalent method + to createdCallback or React.ComponentDidMount.

+

For example, the look-at component's init handler sets up some variables:

+
init: function () {
+                this.target3D = null;
+                this.vector = new THREE.Vector3();
+                },
+
+                // ...
+            
+ + +

Component.update(oldData) - Do the Magic

+

The update handler is called both at the beginning of the component's + lifecycle with the initial this.data and every time the component's data + changes (generally during the entity's attributeChangedCallback like with a + setAttribute). The update handler gets access to the previous state of the + component data passed in through oldData. The previous state of the component + can be used to tell exactly which properties changed to do more granular + updates.

+

The update handler uses this.data to modify the entity, usually interacting + with three.js APIs. One of the simplest update handlers is the + visible component's:

+
update: function () {
+                this.el.object3D.visible = this.data;
+                }
+            
+ + +

A slightly more complex update handler might be the light component's, + which we'll show via abbreviated code:

+
update: function (oldData) {
+                var diffData = diff(data, oldData || {});
+
+                if (this.light && !('type' in diffData)) {
+                // If there is an existing light and the type hasn't changed, update light.
+                Object.keys(diffData).forEach(function (property) {
+                light[property] = diffData[property];
+                });
+                } else {
+                // No light exists yet or the type of light has changed, create a new light.
+                this.light = this.getLight(this.data));
+
+                // Register the object3D of type `light` to the entity.
+                this.el.setObject3D('light', this.light);
+                }
+                }
+            
+ + +

The entity's object3D is a plain THREE.Object3D. Other three.js object types + such as meshes, lights, and cameras can be set with setObject3D where they + will be appeneded to the entity's object3D.

+

Component.remove() - Tear Down

+

The remove handler is called when the component detaches from the entity such + as with removeAttribute. This is generally used to remove all modifications, + listeners, and behaviors to the entity that the component added.

+

For example, when the light component detaches, it removes the light + it previously attached from the entity and thus the scene:

+
remove: function () {
+                this.el.removeObject3D('light');
+                }
+            
+ + +

Component.tick(time) - Background Behavior

+

The tick handler is called on every single tick or render loop of the scene. + So expect it to run on the order of 60-120 times for second. The global uptime of + the scene in seconds is passed into the tick handler.

+

For example, the look-at component, which instructs an entity to + look at another target entity, uses the tick handler to update the rotation in + case the target entity changes its position:

+
tick: function (t) {
+                // target3D and vector are set from the update handler.
+                if (this.target3D) {
+                this.el.object3D.lookAt(this.vector.setFromMatrixPosition(target3D.matrixWorld));
+                }
+                }
+            
+ + +

Component.pause() and Component.play() - Stop and Go

+

To support pause and play, just as with a video game or to toggle entities for + performance, components can implement play and pause handlers. These are + invoked when the component's entity runs its play or pause method. When an + entity plays or pauses, all of its child entities are also played or paused.

+

Components should implement play or pause handlers if they register any + dynamic, asynchronous, or background behavior such as animations, event + listeners, or tick handlers.

+

For example, the look-controls component simply removes its event listeners + such that the camera does not move when the scene is paused, and it adds its + event listeners when the scene starts playing or is resumed:

+
pause: function () {
+                this.removeEventListeners()
+                },
+
+                play: function () {
+                this.addEventListeners()
+                }
+            
+ + +

Boilerplate

+

I suggest that people start off with my component boilerplate, + even hardcore tool junkies. This will get you straight into building a + component and comes with everything you will need to publish your component + into the wild. The boilerplate handles creating a stubbed component, build + steps for both NPM and browser distribution files, and publishing to Github + Pages.

+

Generally with boilerplates, it is better to start from scratch and build your + own boilerplate, but the A-Frame component boilerplate contains a lot of tribal + inside knowledge about A-Frame and is updated frequently to reflect new things + landing on A-Frame. The only possibly opinionated pieces about the boilerplate + is the development tools it internally uses that are hidden away by NPM + scripts.

+

Examples

+

Under construction. Stay tuned!

+

Text Component

+

Text component

+

Physics Components

+

Physics components

+

Layout Component

+

Layout component

+
+ 2016-01-17T00:00:00Z + + http://ngokevin.com/rss + + Kevin Ngo + + + + 2016-01-26T18:09:34Z + +
+ + + http://blog.gerv.net/?p=3527 + + + + Convenient… and Creepy +
The last Mozilla All-Hands was at one of the hotels in the Walt Disney World Resort in Florida. Every attendee was issued with one of these (although their use was optional): It’s called a “Magic Band”. You register it online … Continue reading
+
+

The last Mozilla All-Hands was at one of the hotels in the Walt Disney World Resort in Florida. Every attendee was issued with one of these (although their use was optional):
+

+

It’s called a “Magic Band”. You register it online and connect it to your Disney account, and then it can be used for park entry, entry to pre-booked rides so you don’t have to queue (called “FastPass+”), payment, picking up photos, as your room key, and all sorts of other convenient features. Note that it has no UI whatsoever – no lights, no buttons. Not even a battery compartment. (It does contain a battery, but it’s not replaceable.) These are specific design decisions – the aim is for ultra-simple convenience.

+

One of the talks we had at the All Hands was from one of the Magic Band team. The audience reactions to some of the things he said was really interesting. He gave the example of Cinderella wishing you a Happy Birthday as you walk round the park. “Cinderella just knows”, he said. Of course, in fact, her costume’s tech prompts her when it silently reads your Magic Band from a distance. This got some initial impressed applause, but it was noticeable that after a few moments, it wavered – people were thinking “Cool… er, but creepy?”

+

The Magic Band also has range sufficient that Disney can track you around the park. This enables some features which are good for both customers and Disney – for example, they can use it for load balancing. If one area of the park seems to be getting overcrowded, have some characters pop up in a neighbouring area to try and draw people away. But it means that they always know where you are and where you’ve been.

+

My take-away from learning about the Magic Band is that it’s really hard to have a technical solution to this kind of requirement which allows all the Convenient features but not the Creepy features. Disney does offer an RFID-card-based solution for the privacy-conscious which does some of these things, but not all of them. And it’s easier to lose. It seems to me that the only way to distinguish the two types of feature, and get one and not the other, is policy – either the policy of the organization, or external restrictions on them (e.g. from a watchdog body’s code of conduct they sign up to, or from law). And it’s often not in the organization’s interest to limit themselves in this way.

+
+
+ 2016-01-16T12:18:38Z + 2016-01-16T12:18:38Z + + http://blog.gerv.net/2016/01/convenient-and-creepy/ + + gerv + + + http://blog.gerv.net/feed/atom/ + + + + Gervase Markham + Syndicate – Hacking for Christ + 2016-01-16T12:18:38Z + +
+ + + https://www.christianheilmann.com/?p=4957 + + Don’t tell me what my browser can’t do! + Chances are, your guess is wrong! Arrogance towards possible customers never pays out – as shown in “Pretty Woman” There is nothing more frustrating than being capable of something and not getting a chance to do it. The same goes for being blocked out from something although you are capable of consuming it. Or you’re […] +

Chances are, your guess is wrong!

+ +

you are obviously in the wrong placeArrogance towards possible customers never pays out – as shown in “Pretty Woman”

+ +

There is nothing more frustrating than being capable of something and not getting a chance to do it. The same goes for being blocked out from something although you are capable of consuming it. Or you’re even willing to put some extra effort or even money in and you still don’t get to consume it.

+ +

For example, I’d happily pay $50 a month to get access to Netflix’s world-wide library from any country I’m in. But the companies Netflix get their content from won’t go for that. Movies and TV show are budgeted by predicted revenue in different geographical markets with month-long breaks in between the releases. A world-wide network capable of delivering content in real time? Preposterous — let’s shut that down.

+ +

On a less “let’s break a 100 year old monopoly” scale of annoyance, I tweeted yesterday something glib and apparently cruel:

+ +

“Sorry, but your browser does not support WebGL!” – sorry, you are a shit coder.

+ +

And I stand by this. I went to a web site that promised me some cute, pointless animation and technological demo. I was using Firefox Nightly — a WebGL capable browser. I also went there with Microsoft Edge — another WebGL capable browser. Finally, using Chrome, I was able to delight in seeing an animation.

+ +

I’m not saying the creators of that thing lack in development capabilities. The demo was slick, beautiful and well coded. They still do lack in two things developers of web products (and I count apps into that) should have: empathy for the end user and an understanding that they are not in control.

+ +

Now, I am a pretty capable technical person. When you tell me that I might be lacking WebGL, I know what you mean. I don’t lack WebGL. I was blocked out because the web site did browser sniffing instead of capability testing. But I know what could be the problem.

+ +

A normal user of the web has no idea what WebGL is and — if you’re lucky — will try to find it on an app store. If you’re not lucky all you did is confuse a person. A person who went through the effort to click a link, open a browser and wait for your thing to load. A person that feels stupid for using your product as they have no clue what WebGL is and won’t ask. Humans hate feeling stupid and we do anything not to appear it or show it.

+ +

This is what I mean by empathy for the end user. Our problems should never become theirs.

+ +

A cryptic error message telling the user that they lack some technology helps nobody and is sloppy development at best, sheer arrogance at worst.

+ +

The web is, sadly enough, littered with unhelpful error messages and assumptions that it is the user’s fault when they can’t consume the thing we built.

+ +

Here’s a reality check — this is what our users should have to do to consume the things we build:

+ +

+ +

That’s right. Nothing. This is the web. Everybody is invited to consume, contribute and create. This is what made it the success it is. This is what will make it outlive whatever other platform threatens it with shiny impressive interactions. Interactions at that time impossible to achieve with web technologies.

+ +

Whenever I mention this, the knee-jerk reaction is the same:

+ +

How can you expect us to build delightful experiences close to magic (and whatever other soundbites were in the last Apple keynote) if we keep having to support old browsers and users with terrible setups?

+ +

You don’t have to support old browsers and terrible setups. But you are not allowed to block them out. It is a simple matter of giving a usable interface to end users. A button that does nothing when you click it is not a good experience. Test if the functionality is available, then create or show the button. This is as simple as it is.

+ +

If you really have to rely on some technology then show people what they are missing out on and tell them how to upgrade. A screenshot or a video of a WebGL animation is still lovely to see. A message telling me I have no WebGL less so.

+ +

Even more on the black and white scale, what the discussion boils down to is in essence:

+ +

But it is 2016 — surely we can expect people to have JavaScript enabled — it is after all “the assembly language of the web”

+ +

Despite the cringe-worthy misquote of the assembly language thing, here is a harsh truth:

+ +

You can absolutely expect JavaScript to be available on your end users computers in 2016. At the same time it is painfully naive to expect it to work under all circumstances.

+ +

JavaScript is brittle. HTML and CSS both are fault tolerant. If something goes wrong in HTML, browsers either display the content of the element or try to fix minor issues like unclosed elements for you. CSS skips lines of code it can’t understand and merrily goes on its way to show the rest of it. JavaScript breaks on errors and tells you that something went wrong. It will not execute the rest of the script, but throws in the towel and tells you to get your house in order first.

+ +

There are many outside influences that will interfere with the execution of your JavaScript. That’s why a non-naive and non-arrogant — a dedicated and seasoned web developer — will never rely on it. Instead, you treat it as an enhancement and in an almost paranoid fashion test for the availability of everything before you access it.

+ +

Sorry (not sorry) — this will never go away. This is the nature of JavaScript. And it is a good thing. It means we can access new features of the language as they come along instead of getting stuck in a certain state. It means we have to think about using it every time instead of relying on libraries to do the work for us. It means that we need to keep evolving with the web — a living and constantly changing medium, and not a software platform. That’s just part of it.

+ +

This is why the whole discussion about JavaScript enabled or disabled is a massive waste of time. It is not the availability of JavaScript we need to worry about. It is our products breaking in perfectly capable environments because we rely on perfect execution instead of writing defensive code. A tumblr like Sigh, JavaScript is fun, but is pithy finger-pointing.

+ +

There is nothing wrong with using JavaScript to build things. Just be aware that the error handling is your responsibility.

+ +

Any message telling the user that they have to turn on JavaScript to use a certain product is a proof that you care more about your developer convenience than your users.

+ +

It is damn hard these days to turn off JavaScript – you are complaining about a almost non-existent issue and tell the confused user to do something they don’t know how to.

+ +

The chance that something in the JavaScript execution of any of your dozens of dependencies went wrong is much higher – and this is your job to fix. This is why advice like using noscript to provide alternative content is terrible. It means you double your workload instead of enhancing what works. Who knows? If you start with something not JavaScript dependent (or running it server side) you might find that you don’t need the complex solution you started with in the first place. Faster, smaller, easier. Sounds good, right?

+ +

So, please, stop sniffing my browser, you will fail and tell me lies. Stop pretending that working with a brittle technology is the user’s fault when something goes wrong.

+ +

As web developers we work in the service industry. We deliver products to people. And keeping these people happy and non-worried is our job. Nothing more, nothing less.

+ +

Without users, your product is nothing. Sure, we are better paid and well educated and we are not flipping burgers. But we have no right whatsoever to be arrogant and not understanding that our mistakes are not the fault of our end users.

+ +

Our demeanor when complaining about how stupid our end users and their terrible setups are reminds me of this Mitchell and Webb sketch.

+ +

+ +

Don’t be that person. Our job is to enable people to consume, participate and create the web. This is magic. This is beautiful. This is incredibly rewarding. The next markets we should care about are ready to be as excited about the web as we were when we first encountered it. Browsers are good these days. Use what they offer after testing for it and enjoy what you can achieve. Don’t tell the user when things go wrong – they can not fix what you messed up.

+ + +
+
+ 2016-01-16T11:28:10Z + + + Chris Heilmann + + + https://www.christianheilmann.com + + + + For a better web with more professional jobs - can talk, will travel + Christian Heilmann + 2016-01-16T11:46:15Z + +
+ + + http://glandium.org/blog/?p=3510 + + Announcing git-cinnabar 0.3.1 + This is a brown paper bag release. It turns out I managed to break the upgrade path only 10 commits before the release. What’s new since 0.3.0? git cinnabar fsck doesn’t fail to upgrade metadata. The remote.$remote.cinnabar-draft config works again. Don’t fail to clone an empty repository. Allow to specify mercurial configuration items in a […] +

This is a brown paper bag release. It turns out I managed to break the upgrade
+ path only 10 commits before the release.

+

What’s new since 0.3.0?

+
    +
  • git cinnabar fsck doesn’t fail to upgrade metadata.
  • +
  • The remote.$remote.cinnabar-draft config works again.
  • +
  • Don’t fail to clone an empty repository.
  • +
  • Allow to specify mercurial configuration items in a .git/hgrc file.
  • +
+
+ 2016-01-16T11:26:45Z + + + + + glandium + + + http://glandium.org/blog + + + glandium.org + p.m.o – glandium.org + 2016-01-16T11:30:43Z + +
+ + + http://edunham.net/2016/01/16/buildbot_and_eoferror.html + + Buildbot and EOFError +

Buildbot and EOFError

+

More SEO-bait, after tracking down an poorly documented problem:

+
# buildbot start master
+                Following twistd.log until startup finished..
+                2016-01-17 04:35:49+0000 [-] Log opened.
+                2016-01-17 04:35:49+0000 [-] twistd 14.0.2 (/usr/bin/python 2.7.6) starting up.
+                2016-01-17 04:35:49+0000 [-] reactor class: twisted.internet.epollreactor.EPollReactor.
+                2016-01-17 04:35:49+0000 [-] Starting BuildMaster -- buildbot.version: 0.8.12
+                2016-01-17 04:35:49+0000 [-] Loading configuration from '/home/user/buildbot/master/master.cfg'
+                2016-01-17 04:35:53+0000 [-] error while parsing config file:
+                Traceback (most recent call last):
+                File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 577, in _runCallbacks
+                current.result = callback(current.result, *args, **kw)
+                File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1155, in gotResult
+                _inlineCallbacks(r, g, deferred)
+                File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1099, in _inlineCallbacks
+                result = g.send(result)
+                File "/usr/local/lib/python2.7/dist-packages/buildbot/master.py", line 189, in startService
+                self.configFileName)
+                --- <exception caught here> ---
+                File "/usr/local/lib/python2.7/dist-packages/buildbot/config.py", line 156, in loadConfig
+                exec f in localDict
+                File "/home/user/buildbot/master/master.cfg", line 415, in <module>
+                extra_post_params={'secret': HOMU_BUILDBOT_SECRET},
+                File "/usr/local/lib/python2.7/dist-packages/buildbot/status/status_push.py", line 404, in __init__
+                secondaryQueue=DiskQueue(path, maxItems=maxDiskItems))
+                File "/usr/local/lib/python2.7/dist-packages/buildbot/status/persistent_queue.py", line 286, in __init__
+                self.secondaryQueue.popChunk(self.primaryQueue.maxItems()))
+                File "/usr/local/lib/python2.7/dist-packages/buildbot/status/persistent_queue.py", line 208, in popChunk
+                ret.append(self.unpickleFn(ReadFile(path)))
+                exceptions.EOFError:
+
+                2016-01-17 04:35:53+0000 [-] Configuration Errors:
+                2016-01-17 04:35:53+0000 [-]   error while parsing config file:  (traceback in logfile)
+                2016-01-17 04:35:53+0000 [-] Halting master.
+                2016-01-17 04:35:53+0000 [-] Main loop terminated.
+                2016-01-17 04:35:53+0000 [-] Server Shut Down.
+            
+
+

This happened after the buildmaster’s disk filled up and a bunch of stuff was + manually deleted. There were no changes to master.cfg since it worked + perfectly.

+

The fix was to examine master.cfg to see where the HttpStatusPush was + created, + of the form:

+
c['status'].append(HttpStatusPush(
+                serverUrl='http://build.servo.org:54856/buildbot',
+                extra_post_params={'secret': HOMU_BUILDBOT_SECRET},
+                ))
+            
+
+

Digging in the Buildbot source reveals that persistent_queue.py wants to + unpickle a cache file from /events_build.servo.org/-1 if there was nothing + in /events_build.servo.org/. To fix this the right way, create that file + and make sure Buildbot has +rwx on it.

+

Alternately, you can give up on writing your status push cache to disk + entirely by adding the line maxDiskItems=0 to the creation of the + HttpStatusPush, giving you:

+
c['status'].append(HttpStatusPush(
+                serverUrl='http://build.servo.org:54856/buildbot',
+                maxDiskItems=0,
+                extra_post_params={'secret': HOMU_BUILDBOT_SECRET},
+                ))
+            
+
+

The real moral of the story is “remember to use logrotate.

+
+ 2016-01-16T08:00:00Z + + http://edunham.net/ + + Emily Dunham + + + + is a "DevOps" Engineer at Mozilla Research + edunham + 2016-01-19T08:00:00Z + +
+ + + urn:md5:41d039bb28fb15c761578cba0b1454fa + + Ebook pagination and CSS +

Let's suppose you have a rather long document, for instance a book chapter, and you want to render it in your browser à la iBooks/Kindle. That's rather easy with just a dash of CSS:

+
body {
+                height: calc(100vh - 24px);
+                column-width: 45vw;
+                overflow: hidden;
+                margin-left: calc(-50vw * attr(currentpage integer));
+                }
+

Yes, yes, I know that no browser implements that attr()extended syntax. So put an inline style on your body for margin-left: calc(-50vw * <n>) where <n> is the page number you want minus 1.

+

Then add the fixed positioned controls you need to let user change page, plus gesture detection. Add a transition on margin-left to make it nicer. Done. Works perfectly in Firefox, Safari, Chrome and Opera. I don't have a Windows box handy so I can't test on Edge.

+
+ 2016-01-16T03:43:00Z + + + glazou + + + http://www.glazman.org/weblog/dotclear/index.php + + + Un Glazman, un blog, un Glazblog + <Glazblog/> + 2016-01-25T16:34:47Z + +
+ + + https://repeer.org/?p=48 + + Mozilla cultural revolution: from ‘radical participation’ to ‘radical user-centric’ +
This post has been written about the Mozilla Foundation (MoFo) 2020 strategy. The ideas developed in this post are in different levels: some are global, some focus on particular points of the proposed draft. But in my point of view, they all carry a transversal meaning: articulation (as piece connected to a structure allowing movement) […]
+
+

This post has been written about the Mozilla Foundation (MoFo) 2020 strategy.

+

The ideas developed in this post are in different levels: some are global, some focus on particular points of the proposed draft. But in my point of view, they all carry a transversal meaning: articulation (as piece connected to a structure allowing movement) with others and consistency with our mission.

+

Summary

+

On the way to radical participation, Mozilla should be radical 1 user-centric. Mozilla should not go against the social understanding of the (tech and whole society) situation because it’s what is massively shared and what polarizes the prism of understanding of the society. We should built solutions for it and transform (develop and change) it on the way. Our responsibility is to build inclusivity (inclusion strengths) everywhere, to gather for multiplying our impact. We must build (progressive) victories instead of battles (of static positions and postures).
+ If we don’t do it, we go against users self-perceived need: use. We value our differences more than our commonalities and consider ethic more as an absolute objective than a concrete process: we divide, separate, compete. Our solutions get irrelevant, we get rejected and marginalized, we reject compromises that improve the current situation for the ideal, we loose influence and therefore impact on the definition of the present and future. We already done it for the good and the bad in the past (H.264+Daala, pocket integration, Hello login, no Firefox for iOS, Google fishing vs Disconnect, FxOS Notes app which sync is evernote only, …).
+ To get a consistent and impactful ability to integrate and transform the social understanding, there are four domains where we can take and articulate (connected structure allowing movement) action:

+
    +
  • People: identity is the key to grow consciousness, understanding, skills, voice, representation and to articulate global/local, personal/common. [Activate]
  • +
  • Technology: universality is key for a platform (for resilience) with interfaces (for modularity) where services, features and front-ends can plug-in and communicate to provide (inter)active support ; Decouple conditions of fulfillment with execution (content/appearance/policy ; material/immaterial) to support remix (policy continuity, consistency thought providers, …). [Unlock]
  • +
  • Product: persona and (current and emerging) use via user-agents are the keys. Be on all major platforms depending on use, ethical alignment and opportunities, emerging newness to provide continuity (task, device) to users and leading on new practices. Features should be about products parity and opening new possibilities carrying our values to the action at a massive scale. [Build]
  • +
  • Organizations/institutions: sociological innovation for participation is the key. Research on historical (evolution) and sociological (human organizations, social institutions and social behaviors) analysis based on social networks (link as social interactions), in the perspective of producing commons. [Drive]
  • +
+

Our front has two sides: propose and protect. But each of them are connected and can have different strategic expressions, if our actions generate improving (progressive) curves:

+
    +
  • For the action taking: consciousness, understanding, symbolic actions, behavior change, behavior advocacy (evangelism)
  • +
  • For the action mode: promotion (spreading the idea), incitement (giving a competitive advantage to people involved), collaboration (open interactions to make a win-win exchange; process-centric), contractualization (formalize domains where a win-win exchange is made; object-centric), coercion (giving a competitive disadvantage to people not involved).
  • +
+

Social history is a history of social values. The way we understand and tell the problem determine the solution we can create: we need, all the way long, a shared understanding. Tools and technologies are not tied, bound forever to their social value, which depends on people’s social representations that evolve over time.

+
    +
  • The social behavior is a first key. It is the narrative, and therefore its inclusion in the social history that we make, which converges the product with the values that it stands for. Here is the articulation of product with people and technology, of product with leadership network and advocacy engine (it could be less persistent and inclusive: marketing).
  • +
  • The social organization is a second key. It is about how the process, the tools, the architecture, the governance and the opportunities/constraints have changed for Mozilla (org) and Mozillians (people). Here comes the question of being open. It is not enough because it is about availability (passive) and not inclusivity (active). The high level of automation coming is a challenge. We should level-up the meaning to differentiate from others: Mozilla should activate and unlock societal progress to build fair technical progress. Mozilla need to identify its resilient backbone (not only a technology, the web, but something that articulate people, technology and products) and make it more universal (through people and products). But our goals can’t be absolutely achieved because they have to be considered in a dynamic context. However, the brand engagement is persistent, if it’s included in the product, visible, and centered on easing the user’s action.
    + Linked to the ‘being open’ question, the advocacy engine could be a thing to unlock societal progress. People are satisfied of narrow hills of choice until they understand it’s not socially neutral. It’s the case with technology: they accept things about technology to be build top-down. A successful advocacy, even one about technology, is always built bottom-up, as its function is to give back the voice to the people, to get them involved, not to make them fulfill our predefined aims. The top-down method is too organization centric and administrative content centric: it can’t massively drive people that are not already committed to the org. It’s usually named advertisement or propaganda. If we want to have an impact, we should listen to people needs, not tell them to listen to ours. People want (first) to be empowered, not to empower an org. We need to have content and user centric (not org and it’s process) tools/platform for advocates and leaders: let’s build the technology advocacy plan together. Yes it’s slower, but much more massive, inclusive and persistent. The impact will be higher because it will carry a meaning for people and it wont be too org centric. So it will be qualitatively better: not just an amount, accumulation is not our goal, but impact, that comes from articulation. Likewise we should be careful to not use best practice as absolute solutions, but as solutions in a context, if we want to transpose them massively: when we unify we should avoid to homogenize. On the narrative side, our preoccupation should be about building short, medium and long term narrative to get action.
  • +
  • The social institutions are the third key. Here is the articulation of the leadership network with the advocacy engine. Leaders build new solutions (products) and Advocates new voices (rallying), they are both about personal development and empower commons. Leadership=learn+create and advocacy=teach+spread commons. Leaders are projects/orgs leaders, the ones that traduce DNA (values) in products (concrete ability and availability). Advocates are values advocates, the ones that traduce DNA (values) in actions (behavior). As they are both targeting commons, they both produce the same social organization (collaboration instead of competition). They are both involved in creating (different) representations (institutions) and organizations (foundation/firms) but with a different DNA (values) processing: from public good to personal benefit or from personal interest to public benefit. If Mozilla cares about public good resilience, the articulation of their domains of values is critical. So, on the social organization side, their articulation’s expression and the revision process must be said and clear: from hierarchy or contract or different autonomy levels (internal incubation and external advocacy), or … to criteria to start a revision. About the narrative, and hence about the social behavior side, leaders carry a lot of legitimacy and avoid the stay-experimental or non-massive (unique) thoughts. And we need legitimacy to get impact. But this legitimacy is already present if we make clear that our actions are about commons. We should name them creators (compositors or managers) to make it clear that the creative process is a collaboration, made by a team and that the public good do not have the same role in the process and outcome. Full circle.
  • +
  • The social networks are the keystone. Let’s shortly take an example based on social networks (link as social interactions) with the perspective of producing people, technological and product commons. We need better tools for collaboration and participation: tools that merge discussion channels, capitalize on the discussion and preview the results to build a plan. From evolving the wiki discussion page to feature document production into peer-to-peer discussion.
  • +
+

An analysis of the creation process is another way to the articulation of product with people and technology.
+ Platforms move closer to strict ‘walled garden’ ecosystems. We need bridges from lab to home that carry different mix of customization and reliability to support the emancipation curve. We need to build pathways thought audiences and thought IT layers (content, software, hardware, distant service). We should find a convergence between customization (dev code patch to users add-ons) and reliability (self made to mass product), between first time experience, support and add-ons thought all our users’ persona by building bridges, pathways. Mozilla should find ways to integrate learning in its products, in-content, as we have code comment on code: on-boarding levels, progression from simple to high level techniques, reproducible/universal next task/skill building.

+

Detailed discussion content

+

Here are the developed ideas, with more reference to our allies and detractors’ products.

+

People, the sociological side

+
From focused to systemic action
+

First of all, I think the strategy move Mozilla is doing is the right one as it embraces more our real life. People are not defined by one characteristic, we are complex: ex. we can be pedestrian, car driver, biker, Public Transport user… we think and do simultaneously. So why Mozilla should restrict its strategy by targeting people on skills, through education, thought better material only (the Mozilla Academy program). Education, even popular education, can’t do everything for the people to build change. We need a plan that balance intellectual and practical (abstraction/action, think/do) integrating progressive paths to massively scale so we get an impact: build change.

+
Real life: Social history, individuals and institutions as an articulation founding the action.
+

Let’s start by some definitions based on my understanding of some Wikipedia articles. Sociology is the study of the evolution of societies: human organizations and social institutions. It is about the impact of the social dimension on humans representations (ways of thinking) and behaviors (ways of acting). It allows to study the conceptions of social relations according to fundamental criteria (structuralism, functionalism, conventionalism, etc.) and the hooks to reality (interactionism, institutionalism, regulationisme, actionism, etc.), to think and shape the modernity. Currently (and this is key for Mozilla’s positioning), the combination of models replace the models’ unity, which aims to assume the multidimensionality. There are three major sociological paradigms, including one emerging:

+
    +
  • The holistic paradigm: Society is a whole that is greater than the sum of its parts, it exists before the individual and individuals are governed by it. In this context, the Society includes the individual and the individual consciousness is seen only as a fragment of the collective consciousness. The emphasis is on the social fact, whose cause must be sought in earlier social facts. The social fact is part of a system of interlocking institutions that govern individuals. It is external to the individual and constraint it. Sociology is then the science of institutional invariants in which are the observable phenomenas.
  • +
  • The atomistic paradigm: each individual is a social atom. The atoms act according to self motives, interests, emotions and are linked to other atoms. A system of constant interaction between atoms produces and reproduces Society. The emphasis is on the cause of social actions and the meaning given by individuals to their actions. A horizon of meanings serve as reference instead of the arrangements of institutions. The institution is there but it serves the motives and interests of agents. Sociology is then the study of the social action.
  • +
  • The recent emergence of a sociological analysis based on social networks (which are a collection of individuals or organizations connected by regular social interactions) suggest lines of research beyond the opposition between the holistic and the atomistic approaches. The theory of social networks conceives social relationships in terms of nodes and links. The nodes are usually social actors in the network but can also represent institutions, and links are the relationships between these nodes. There may be several kinds of links between nodes and their analysis determines social capital of the social actors.
  • +
+

Consequently, Mozilla should build its strategy on historical (evolution) and sociological (human organizations, social institutions and social behaviors) analysis based on social networks (links as social interactions), in the perspective of producing commons. That is to say as an engine of transition from a model of value on its last leg (rarity capitalism) to the emerging one (new articulation of the individual and the collective: commons).
+ It is important and strategic to propose a sociological articulation supporting our mission and its purpose (commons) since the sociological concept (the paradigm) reveals an ideological characteristic: because it participates in societal movements made in the Society, it serves an ideal. The societal domain, what’s making society, a political object, should be a stake for Mozilla.

+
Build on a basement: current tech challenge articulated with current social meaning/perception
+

We should articulate ‘our real life’ with the nowadays tech challenge: how to get back control over our data at the time of IoT, cloud, big data, convergence (multi-devices/form factor)? From a user point of view, we have devices and want them convenient, easy and nice. The big moves in the tech industry (IoT, cloud, big data, convergence) free us for somethings and lock us for others. The lock key is that our devices don’t compute anymore our data that are in silos. From a developer point of view, the innovation is going very fast and it’s hard to have a complete open source toolbox that we can share, mostly because we don’t lead: Open has turn to be more open-releasing.
+ We should articulate our new strategy with the tech industry moves: for example, as a user, how can I get (email) encryption on all my devices? Should I follow (fragmented) different kind of howtos/tools/apps to achieve that? How do I know these are consistent together? How can I be sure it won’t brake my continuous workflow? (app silo? social silo? level of trust and reliability?)
+ Mozilla have the skills to answer this as we already faced and solved some of these issues on particular points: like how to ease the installation of Firefox for Android for Firefox desktop users, open and discoverable choice of search engines, synchronization across devices, …
+ Mozilla’s challenge is to not be marginalized by the change of practices. Having an impact is embracing the new practice and give it an alternative. Mozilla already made that move by saying « Firefox will go where users are« , by trying to balance the advertisement practice between adds companies and users, by integrating H.264 and developing Daala. But Mozilla never stated that clearly as a strategy.

+
A backbone to make our mission resilient in it expressions
+

If we think about the Facebook’s strategy, they first built a network of people whiling to share (no matter what they share) and then use this transversal backbone to power vertical business segments (search, donation, local market selling, …). Google with its search engine and its open source policy have a similar (in a way) strategy. The difference here is that the backbone is people’s data and control over digital formats. In both cases, the level of use (of the social network, search engine, mobile OS, …) is the key (with fast innovation) to have an impact. And that’s a major obstacle to build successful alternatives.
+ The proposed Mozilla’s strategy is built in the opposite way, and that’s questioning. We try to build people network depending on some shared matters. Then, is our strategy able to scale enough to compete against GAFAM, or are we trying to build a third way ?
+ For the products, the Mozilla’s strategy is still (and has always been) inclusive: everybody can use the product and then benefit of its open web values. A good product that answer people needs, plus giving people back/new power (allow new use) build a big community. For the network, should we build our global force of people based on concentric circles (of shared matters) or based on a (Mozilla own) transversal backbone (matter agnostic)? It seems to me the actual presentation of the strategy do not answer clearly enough this big question: which inclusivity (inclusion strengths) mechanism in the strategy?
+ And that call back to our product strategy: build a community that shares values, that is used to spread outcomes (product) OR build a community that shares a product, that is used to spread values. This is not a question on what matters more (product VS values) but on the strategy to get to a point, an objective (many web citizens). Shouldn’t we use our product to built a people network backbone ? Back to GAFAM: what can we learn from the Google try with Google+?
+ If our core is not enough transversal (the backbone), more new web/tech market there will be, more we will be marginalized, because focused on our circles center not taking in account that the war front (the context) have changed. Mozilla have to be resilient: mutability of the means, stability in the objectives.
+ The document is the MoFo strategy, and so it doesn’t say anything about ‘build Firefox’ (aka the product strategy) and so don’t articulate our main product (Firefox) with our main people network building effort and values sharing engine. We should do it: at a strategic scale and a particular scale (articulating the agenda-setting with main product features).

+
Brand engagement, a psychological backbone on the user side ?
+

It seems that our GAFAM challengers get big and have impact by not educating (that much) people, and that’s what makes them not involved in the web citizenship. Or only when they are pushed by their customers. At the opposite, making people aware about web citizenship at first, makes it hard to have that much people involved and so to have impact. However, there is an other prism that drive people: the brand perceived values. Google is seen as a tech pioneer innovator and doing the good because of its open policy, free model, fast innovation… Facebook is seen as really cool firm trying to help people by connecting them…
+ Is the increase of marketing of Mozilla doing good enough to gains back users ? Is this resilient compared to the next-tech-thing coming ?
+ Most of the time when I meet Goggle Chrome users and ask then why they use it and don’t switch to Firefox, they answer about use allowed (sync thought devices, apps everywhere that run only on GC, …). Sometimes, they argue that they make effort on other areas, and that they want to keep they digital life simple. They experience is not centered in a product/brand, but more on the person: on that Google Chrome with its Person (with one click ‘auto-login’ to all Google services) is far superior than Firefox.

+
User-agent or products ?
+

A user-agent is an intermediary acting on behalf of a supplier. As a representative, it is the contact point with customers; It’s role is to manage, to administer the affairs; it is entrusted with a mission by one or more persons; it both acts and produce an effect.
+ So, the user-agent can be describe with three criteria. It is: an intermediate (user/technology) ; a tool (used to manage and administrate depending on the user’s skills) ; a representative (mission bearer, values vector, for a group of people). It exceeds partly the contradiction between being active and passive.
+ A user-agent articulate personal-identity with technology-identity and give informations about available skills over these domains. It’s much more universal than a product that is about featuring a user-agent. If we target resilience, user-agent should be the target.

+

Social history, marketing: how we understand things to make choices

+
History of the social value
+

The way we look at the past and current facts shape our understanding and determine if we open new ways to solve the issues identified. That’s the way to understand the challenges that come on the way and to agree on an adaptation of the strategy instead of splitting things. The way we understand and tell the problem determine the solution we can create: we need, all the way long, a shared understanding.
+ Tools and technologies are not necessarily tied to their social value, which depends on social representations. The social value can be built upstream and evolve downstream. It also depends on the perspective in which we look at it, on the understanding of the action and therefore on past or current history. Example: the social value of a weapon can be a potential danger or defense, creative (liberating) or destructive. The nuclear bomb is a weapon of mass destruction (negative), whose social value was (ingeniously built as) freedom (positive).

+
Impact in our strategy: a missing root
+

To engage the public, before to « Focus on creative campaigns that use media + software to engage the public. » we need to step back, in our speeding world, for understanding together the big picture and the big movement.
+ Mozilla want to fuel a movement and propose a strong and consistent strategy. However, I think this plan miss a key point, a root point: build a common (hi)story. This should be an objective, not just an action.
+ Also, that’s maybe a missing root for the State of the web report: how do we understand what we want to evaluate? But it’s not only a missing root for an (annual?) report (a ‘Reporters without borders’ Press-Freedom like?), it’s a missing root for a new grow of our products’ market share.
+ For example, I do think that most users don’t know and understand that Mozilla is a foundation, Firefox build by a community as a product to keep the web healthy: they don’t imagine any meaning about technology, because they see it as a neutral tool at its root, so as a tool that should just fit they producing needs.
+ Firefox, its technologies and its features are not bound for ever. It is the narrative, and therefore their inclusion in the social history that we make, which converges Firefox with the values that it stand for. Stoping or changing the deep narrative means cutting the source of common understanding and making stronger other consistencies captured by other objects, turning as centrifugal forces for Firefox.
+ Marketing is a way to change what we socially say about things: that’s why Google Chrome marketing campaign (and consistent features maturity) has been the decreasing starting point of Firefox. Our message has been scrambled.

+

From participation to emancipation: values, people and org relationships

+

How to emancipate people in the digital world ?

+
Keeping the open open
+

Being open is not a thing we can achieve, it’s a constant process. « Mozilla needs to engage on both fronts, tackling the big problems but also fuelling the next wave of open. » Yes, but Mozilla should say too how the next wave of open can stay under people’s control and rally new people. Not only open code, but open participation, open governance, open organization. Being open is not a releasing policy about objects, it’s a mutation to participation process: a metamorphosis. It’s not reached by expanding, but by shifting. It’s not only about an amount, but about values: it’s qualitative.
+ Maybe open is not enough, because it doesn’t say enough about who control and how, about the governance, and says too much about availability (passive) and not enough about inclusivity (active ; inclusion strengths). It doesn’t say how the power is organized and articulated to the people (ex. think about how closed is the open Android). We may need to change the wording: indie web, the web that fuel autonomy, is a try, but it doesn’t say enough about inclusivity compared to openness & opportunity. Emancipation is the concept. It’s strategic because it says what is aligned to what, especially how to articulate values and uses. It’s important because it tells what are the sufficient conditions of realization to ‘open/indie’. That’s key to get ‘open/indie at small and large scales, from Internet people to Internet institutions, thought all ‘open/indie’ detractors in the always-current situation: a resilient ecosystem.
+ My intuition is that the leadership network and advocacy engine promoting open will be efficient if we clarify ‘open’ while keeping it universal. We can do it by looking back at the raw material that we have worked for years, our DNA in action. Because after all, we are experts about it and wish others to become experts too. It does not mean to essentialize it (opposing its nature and its culture), but to define its conditions of continuous achievement in our social context.

+
Starting point: exemplary projects that tell a lot about the evolution of our DNA in action
+

Clarifying the idea of ‘open’ is strategic to our action because it outlines the constitution of ‘open’, its high ‘rules’, like with laws in political regimes. It clarifies for all, if you are part of it or not, and it tells you what to change to get in. It can reinforce the brand by differentiating from the big players that are the GAFAM: it’s a way to drive, not to be driven by others lowering the meaning to catch the social impact. We should say that ‘open’ at Mozilla means more than ‘open’ at GAFAM. I wish Mozilla to speak about its openness, not as an ‘equal in opportunity’ but as an ‘equal in participation’, because it fits openness not only for a moment (on boarding) or for a person, but during the whole process of people’s interaction.
+ Rust and Servo or Firefox OS (since the Mozilla’s shift to radical participation) seem to be very good examples of projects with participation & impact centric rules, tools, process (RFC, new team and owners, …). Think about how Rust and Dart emerged and are evolving. Think about how stronger has been the locked-open Android with partnership than the open-locked FxOS. We should tell those stories, not as recipes that can be reproduced, but as process based on a Constitution (inclusive rules) that make a political regime (open) and define a mode of government (participation). That’s key to social understanding and therefore to transpose and advocate for it.
+ As projects compared to ‘original Mozilla’, Rust, Servo and FxOS could say a lot about how different they implemented learning/interaction/participation at the roots of the project. How the process, the tools, the architecture, the governance and the opportunities/constraints have changed for Mozilla and participants. This could definitely help to setup our curriculum resources, database and workshop at a personal (e.g., “How to teach / facilitate / organize / lead in the open like Mozilla.”) and orgs levels, with personal and orgs policies.

+
Spreading the high meanings in our strategy to consolidate it consistency
+

Clarifying the constitution of ‘open’ calls to clarify other related wordings.
+ I’m satisfied to read back (social) ‘movement’ instead of ‘community’, because it means that our goal can’t be achieve forever (is static), but we should protect it by acting. And it seems more inclusive, less ‘folds on itself’ and less ‘build the alternative beside’ than ‘community’: the alternative can be everywhere the actual system is. It can make a system. It can get global, convergent, continuous, … all at the same time. Because it’s roots are decentralized _and_ consistent, collaborating, …

+

About participation, we should think too (again) about engagement VS contribute VS participate: how much am I engaged ? Free about defining and receiving cost/gains? What is the impact of my actions ? … These different words carry different ideas about how we connect the ‘open’: spread is not enough because it diffuses, _be_ everywhere is more permanent. Applied to Mozilla’s own actions, funding open projects and leaders, is maybe not enough and there should be others areas where we can connect inside products, technology, people and organizations that build emancipation. So that say something about getting control (who, how, …).

+
IA: a challenge for ‘open’
+

IA is first developed to help us by improving our interactions. However, this seems to start to shift into taking decisions instead of us. This is problematic because these are indirect and direct ways for us to loose control, to be locked. And that can be as far as computers smarter than humans. The problem is that technical progress is made without any consideration of the societal progress it should made.
+ That’s an other point, why open is not enough: automation should be build-in with superior humanization. Mozilla should activate and unlock societal progress to build fair technical progress.

+
Digital integration & democracy
+

The digital (& virtual) world is gaining control over the physical world in many domains of our society (economy to finance, mail to email, automatic car, voting machine, …). It’s getting more and more integrated to our lives without getting back our (imperfect) democracy integrated into them. Public benefit and public good are turning ‘self benefit’ and ‘own sake’ because citizens don’t have control over private companies. We should build a digital democracy if we don’t want to loose at all the democratic governing of society. We must overcome the poses and postures battles about private and public. We need to build.

+

‘Leader’ & ‘Leadership’ need a clarification

+
Why a clarification?
+

At some level, I’m not the only one to ask this question:

+

How do CRM requirements for Leadership and Advocacy overlap / differ? What’s our email management / communications platform for Leadership?

+

Connect leaders to lead what ? How ? To whose benefit ? Do we want to connect leaders or initiatives (people or orgs) ? Will the leaders be emerging ones (building new networks) or established ones (use they influence to rally more people)? Are Leaders leaders of something part of Mozilla (like can be Reps) or outside of Mozilla (leaders of project, companies, newspaper: tech leaders, news leaders, …) ? This is especially important depending on what is the desire for the leaders to become in the future. The MoFo’s document should be more precise about this and go forward than « Mozilla must attract, develop, and support a global network of diverse leaders who use their expertise to collaboratively advance points-of-view, policies and practices that maintain the overall health of the Internet. »
+ We should do it because the confusion about the leadership impact the advocacy engine: « The shared themes also provide explicit opportunities for our Leadership and Advocacy efforts to work together. » Regarding Mozilla, is the leaders role to be advocacy leaders ? It seems as they share themes and key initiatives (even if not worded the same sometimes). Or in other words, who Drives the Advocacy engine?

+
Iterations with the actual definition: creators
+

Here are my iterations on the definition of ‘Leaders’:

+
    +
  • The Leaders could be the people platform (the community) and the advocacy engine the tool/themes/actions platform (the product).
  • +
  • Leaders could build at the end new solutions (products) and Advocates new voices (rallying), that could be translated in a learning area divided like Leadership=learn+create and advocacy=teach+spread.
  • +
  • Leadership: personal development to produce (turn into) new commons or add new facets to commons. Advocacy: personal development to protect established/identified commons.
  • +
+

With these definitions, then Leaders are maybe more a Lab, R&D place, incubation tool (if we think about start-up incubators, then it shows a tool-set that we will need to inspire for the future). But if we want to keep the emphasis on people, we could name them ‘creators’ (compositors or managers ; not commoners, because leaders and advocates are commoners ; yes, traditionally creators are craftspersons and intellectual designers). This make sens with the examples given in the MoFo 2020 strategy 0.8 document, where all persona are involved in a building-something-new process.

+

However, it’s interesting to understand why we choose at first ‘Leaders’. Leaders build new solutions (products) and Advocates new voices (rallying), they are both about personal development and empower commons. Leadership=learn+create and advocacy=teach+spread commons. Leaders are projects/orgs leaders, the ones that traduce DNA (values) in products (concrete ability and availability). Advocates are values advocates, the ones that traduce DNA (values) in actions (behavior). As they are both targeting commons, they both produce the same social organization (collaboration instead of competition). They are both involved to create (different) representation (institutions) and organization (foundation/firms) but with a different DNA (values) processing: from public good to personal interest or the opposite. If Mozilla cares about public good resilience, the articulation of they domains of values is critical. So their articulation’s expression and the revision process must be said and clear: from hierarchy vs contract vs different autonomy levels (internal incubation and external advocacy), vs … to criteria to start a revision.

+
The network effect
+

Another argument for the switch from Leader to Creator is that the Leader word it too much tight to a single-person-made innovation. Creator make more clear that the innovation is possible not because of one genius, but because of a team, a group, a collective: personS (where there could also be genius). The value is made by the collaboration of people (especially in an open project, especially in a network).
+ That’s important because that could impact how well we do the convening part: not self-promoting, not-advertising, but sharing skills and knowledge for people and catalysing projects.
+ The same for the wording ‘talent’: alone, a talent can do nothing that has an impact. At least, we need two talents, a team (plus some assistants at some point).

+
The cultural prism
+

Again, this seems to be an open question:

+

Define and articulate “leadership.” Hone our story, ethos and definition for what we mean by “leadership development” (including cultural / localization aspects).

+

In my culture, Leader carry positive (take action) and negative (dominate) meanings. That’s another reason why I prefer another naming.
+ I understand too that it carries a lot of legitimacy (ex. market leader) in our societies and it avoids the stay-experimental or non-massive (unique) thoughts. And we need legitimacy to get impact.
+ But the way Mozilla has an impact thought all cultures, its legitimacy, is by creating or expanding a common. To do this, depending on the maturity, Mozilla could follow the market proposing an alternative with superior usability OR opening a new market by adding a vertical segment.

+
Existing tool-set opportunities
+

If Leadership is « a year-round MozFest + Lab« , so it’s a social network + an incubation place. Then, we already have a social network for people involved with Mozilla: Which kind of link should have the leadership network with mozillians.org ? What can we learn from this project and other specialized social network projects (linkedin, viadeo, …) to build the leadership network ?

+

Advocacy engine: make it clear

+
What it is & how it works
+

Mozilla is doing a great effort to build its advocacy engine on collaboration (« Develop new partnerships and build on current partnerships« , « begin collaboration« , « build alliances with similar orgs« ) but at the same time affirms that Mozilla should be « Part of a broader movement, be the boldest, loudest and most effective advocates » that could be seen as too centralized, too exclusive.
+ While this can be consistent (or contradictory), the consistency has to be explained looking at orgs and people, global and local, abstract and real, with a complementarity/competitive grid.
+ First, the articulation with other orgs has to be explained. What about others orgs doing things global (EFF, FSF, …) and local (Quadrature du net, CCC, …) ? What about the value they give and that Mozilla doesn’t have (juridic expertise for example) ? What about other advocate engines (change.org, Avaaz…) ? That should not be at an administrative level only like « Develop an affiliate policy. Defining what MoFo does / does not offer to effectively govern relationships w. affiliated partners and networks (e.g., for issues like branding, fundraising, incentives, participation guidelines, in-kind resources.) »
+ Second, this is key for users to understand and articulate the global level of the brand engagement and their local preoccupations and engagement. How the engine will be used for local (non-US) battles ? In the past Mozilla totally involved against PIPA, SOPA by taking action, and hesitate a lot to take position and just published a blog post (and too late to gain traction and get impact) against French spying law for example.
+ Third, the articulation ‘action(own agenda)/reaction’ should be clarified in the objectives and functioning of the advocacy engine. Especially because other orgs, allies or detractors, try to to setup the social agenda. It’s important because it can change the social perception of our narrative (alternative promotion/issue fighting) and therefore people’s contributions.
+ People think the technology is socially neutral. People are satisfied of narrow hills of choice (not the meaning, the aim, but only the ability to show your favorite avatar). People don’t want to feel guilty or oppressed, they don’t want new constraints, they are looking for solution only: they want to use, not to do more, they want they things to be done. Part of the problem is about understanding (literacy, education), part of it is about the personal/common duality, part of it is about being hopeless about having an impact, part of it is about expressing change as a positive goal and a new possible way (alternative), not a fight against an issue. About the advocacy engine, I think our preoccupation should be people-centric and the aim to give them a short, medium and long term narrative to get action without being individuals-centric.

+
How we build it ?
+

How to build a social movement ? How it has been built in the past ? Is it the same today ? Can it be transposed to the digital domain from others social domains ? How strong are the cultural differences between nations? These are the main questions we should answer, and our pivot era gives us many examples in diverse domains (climate change advocates, Syriza & Podemos, NSA & surveillance services in Europe, empowered syndicates in Venezuela, Valve corp. internal organization…) to set a search terrain. However, I will go strait to my intuitive understanding below.
+ I’m kind of worried that it’s imagined to build the advocacy engine themes by a top-down method. I think a successful advocacy is always built bottom-up, as its function is to give back the voice to the people, to get them involved, not to make them fulfill our predefined aims. The top-down method is too organization centric: it can’t massively drive people that are not already committed to the org. It’s usually named advertisement or propaganda. If we want to have impact, we should listen to people needs, not tell them to listen to ours. People want (first) to be empowered, not to empower an org. So let’s organize the infrastructure, set the agenda and draw the horizon (strategic understanding) participative: make people fill them with content of their experience. It seems to me it is the only way, the only successful method, if we want to build a movement, and not just a shifting moment (that could be built by the top, with a good press campaign locally relayed for example ; that’s what happen in old style politics: the aim is short term, to cleave).
+ Isn’t the advocacy engine a new Drumbeat ? We shifted from Drumbeat to Webmaker+web literacy to Mozilla Academy and now to Leadership plus advocacy: it could be good to tell that story now that we are shifting again and learn from it.
+ Mozilla should support, behave as a platform, not define, not focus. Letting the people set the agenda makes them more involved and is a good way to build a network of shared aims with other orgs, that is not invasive or alienating, but a support relationship in a win-win move. The strength comes from the all agendas sewed. So at an org level, let’s on-board allies organizations as soon as plan building-time (now), to build it together. Yes it’s slower, but much more massive, inclusive and persistent.

+
How we evaluate it: cultural bias & qualitative analysis
+

First, about the agenda-setting KPI for 2016, should these KPI be an evaluation of the inclusion and rank in others strategic agendas, governance systems and productions (outcome/products) ? Others org could be from different domains: political, social, economy orgs.
+ Then, as a wide size audience KPI, Mozilla wants « celebration of our campaigns with ‘headline KPIs’ including number of actions, and number of advocates.« . While doing this could be the right thing to do for some cultures, it could be the worst for others. I think that these KPI don’t carry a meaning for people and are too org centric. In a way, they are to generic: it’s just an amount. Accumulation is not our goal: we want impact that is the grow of articulated actions made by diverse people toward the same aim. We need our massive KPI to be more qualitative, or at least find a way to present them in a more qualitative way: interactive map ? a global to local prism that engages people for the next step ?

+
Best practices & massive impact
+

Selecting best practices are an appealing method when we want to have a fast and strong impact in a wide area. However, when we unify we should avoid to homogenize. The gain in area by scaling-up is always at the cost of loosing local impact because it is not corresponding to local specificities, hence to local expectations. Federating instead of scaling-up is a way to solve this challenge. So we should be careful to not use best practice as absolute solutions, but as solutions in a context if we want to transpose them massively.

+
Tools & platform balanced between user-centric and org-centric outcomes
+

It’s good to hear that we will build a advocacy platform. As we ‘had’ bugzilla+svn then mercurial (hg)+… and are going to the integrated, pluggable and content-centric (but non-free; admin tools are closed source) github (targeting more coder than users, but with a lower entry price for users still), we need to be able to have the same kind of tool for advocates and leaders. Something inspired maybe at some levels by the remixing tools we built in Webmakers for web users.

+

From experiment to production: support (self made to mass product) + modularity (dev code patch to users add-ons).

+

We need pathways from lab to home that carry different mix of customization and reliability to support the emancipation curve.
+ Users want things to work, because they want to use it. Geeks want to be able to modify a lot and accept to put their hands in the engine to build growing reliability. Advanced users want to customize their experience and keep control and understanding on working status. They want to be able to fix the reliability at a medium/low technical cost. They are OK to gain more control at these prices. Users want to use things to do what they need and want to trust a reliability maintained for them. They are OK to gain control at a no technical cost. Depending on the matter we all have different skill levels, so we are all geeks, advanced users and users depending on our position or on the moment. And depending on our aspirations, we all want to be able to move from one category to an other. That’s what we need to build: we don’t just need to « better articulate the value to our audiences« , we need to build pathways thought audiences and thought IT layers (content, software, hardware, distant service). We should find a convergence between customization and reliability, between first time experience, support and add-ons thought all our users’ persona by building bridges, pathways. So, « better articulate the value to our audiences » should not be restrained in our minds to the Mozilla Leadership Network.
+ Part of this is being done in other projects outside of Mozilla in the commons movement. There are many, but let’s take just one example, the Fairphone project: modularity, howtos, … all this help to break the product-to-use walls and drive appropriation/emancipation. Products are less product and brand centric and more people/user centric.
+ Part of this has been done inside Mozilla, like integrating learning in our products, in-content, as we have code comment on code. I think the Spark project on Firefox OS is on a promising path, even if maybe immature: it maybe has not been released mainstream because it misses bridges/pathways (on-boarding levels, progression from simple to high level techniques, and no or not enough reproducible/universal next task/skill building).
+ So some solutions start to emerge, the direction is here, but has never been conceived and implemented that globally, as there isn’t integrated pathways with choice and opportunity and a strategy embracing all products and technologies (platform, tools, …).

+

Better tools for collaboration and participation: task-centric to process-centric (use) infrastructure

+

The open community should definitely improve the collaboration tools and infrastructure to ease participation.
+ Discourse ‘merged’ discussion channels: email+forum(+instant, messaging, … and others peer-to-peer discussion?). Stack exchange merged the questioning/solving process and added a vote mechanism to rank answers: it eased the collaboration on editing the statement and the results while staying synchronous with the discussion and keeping the discussion history. We need such kind of possibilities with discourse: capitalize on the discussion and preview the results to build a plan.
+ This exist in document oriented software (that added collaboration editing tools), but not that much in collaboration software (that don’t produce documents). For example, while discussing the future plan for Fx/FxOS be supported to keep track on a doc about the proposals plans + criteria & dependencies. In action, it is from this plus all the discussion taking place to that.
+ This is maybe something like integrating Discourse+Wiki, maybe with the need to have competing and ranked (both for content and underlaying meaning of content=strategy?) plan/page proposals. From evolving the wiki discussion page to featuring document production into peer-to-peer discussion.

+

A recovering strategy: from fail to win

+

There is maybe one thing that is in the shadow in this plan: what do we do when/if we (partially) fail ?
+ I think at least we should say that we document (keep research going on) to be able to outline and spread the outcomes of what we tried to fight against. So we still try to built consciousness to be ready for the next round.

+

+

If you see some contradiction in my thoughts, let’s say it’s my state of thinking right now: please voice them so we can go forward.
+ The same for thoughts that are voiced definitive (like users are): take it as a first attempt with my bias: let’s state these bias to go forward.

+
+
+
    +
  1. Radical‘ can be in some cultures an euphemism to ‘violent‘. Let’s be clear that the change by increasing violence is done to make a popular uprising of some part against others. While it does not help the majority to magically understand that the minority is right, it stigmatize the radical-violent-changers and in the way it discredits the alternative proposed.
  2. +
+
+ + 2016-01-16T00:27:13Z + + + + + + + + + + Nicolas + + + https://repeer.org + + + Reprenez le pouvoir ! + Repeer » Mozilla + 2016-01-16T00:46:46Z + + + + + http://bluesock.org/%7Ewillkg/blog/pyvideo/status_20160115.html + + pyvideo status: January 15th, 2016 +
+

What is pyvideo.org

+

pyvideo.org is an index of Python-related conference and user-group videos on + the Internet. Saw a session you liked and want to share it? It's likely you can + find it, watch it, and share it with pyvideo.org.

+

This is the latest status report for all things happening on the site.

+

It's also an announcement about the end.

+

Read more… (5 mins to read)

+
+ 2016-01-15T23:30:00Z + + + + + + Will Kahn-Greene + + + http://bluesock.org/%7Ewillkg/blog/ + + + Will Kahn-Greene's blog of Python, Mozilla, GNU/Linux, random content, dennis, Input, SUMO, and other projects mixed in there ad hoc, half-baked and with a twist of lemon + Will's blog + 2016-01-16T16:31:16Z + +
+ + + http://coopcoopbware.tumblr.com/post/137371863755 + + RelEng & RelOps Weekly Highlights - January 15, 2016 +

One of releng’s big goals for Q1 is to deliver a beta via build promotion. It was great to have some tangible progress there this week with bouncer submission.

+ +

Lots of other stuff in-flight, more details below! +

Modernize infrastructure:

+ +

Dustin worked with Armen and Joel Maher to run Firefox tests in TaskCluster on an older EC2 instance type where the tests seem to fail less often, perhaps because they are single-CPU or slower.

+ +

Improve CI pipeline:

+ +

We turned off automation for b2g 2.2 builds this week, which allowed us to remove some code, reduce some complexity, and regain some small amount of capacity. Thanks to Vlad and Alin on buildduty for helping to land those patches. (https://bugzil.la/1236835 and https://bugzil.la/1237985)

+ +

In a similar vein, Callek landed code to disable all b2g desktop builds and tests on all trees. Another win for increased capacity and reduced complexity! (https://bugzil.la/1236835)

+ +

Release:

+ +

Kim finished integrating bouncer submission with our release promotion project. That’s one more blocker out of the way! (https://bugzil.la/1215204)

+ +

Ben landed several enhancements to our update server: adding aliases to update rules (https://bugzil.la/1067402), and allowing fallbacks for rules with whitelists (https://bugzil.la/1235073).

+ +

Operational:

+

There was some excitement last Sunday when all the trees were closed due to timeouts connectivity issues between our SCL3 datacentre and AWS. (https://bugzil.la/238369)

+ +

Build config:

+ +

Mike released v0.7.4 of tup, and is working on generating the tup backend from moz.build. We hope to offer tup as an alternative build backend sometime soon.

+ +

See you all next week!

+
+ 2016-01-15T22:44:13Z + + + + + http://coopcoopbware.tumblr.com/ + + Chris Cooper + + + + Five different types of fried cheese + 2016-01-22T21:00:12Z + +
+ + + https://air.mozilla.org/webdev-beer-and-tell-january-2016/ + + Webdev Beer and Tell: January 2016 +

+ Webdev Beer and Tell: January 2016 + Once a month web developers across the Mozilla community get together (in person and virtually) to share what cool stuff we've been working on in... +

+
+ 2016-01-15T22:00:00Z + + Air Mozilla + + + https://air.mozilla.org/ + + + Except where otherwise noted, content on this site is licensed under the Creative Commons Attribution Share-Alike License v3.0 or any later version. + Air Mozilla is the Internet multimedia presence of Mozilla, with live and pre-recorded shows, interviews, news snippets, tutorial videos, and features about the Mozilla community. + Air Mozilla + 2016-01-25T20:31:50Z + +
+ + + http://blog.mozilla.org/sumo/?p=3665 + + What’s up with SUMO – 15th January +
Hello, SUMO Nation! The second post of the year is here. Have you had a good time in 2016 so far? Let us know in the comments! Now, let’s get going with the updates and activity summaries. It will be … Continue reading
+
+

Hello, SUMO Nation!

+

The second post of the year is here. Have you had a good time in 2016 so far? Let us know in the comments!

+

Now, let’s get going with the updates and activity summaries. It will be brief today, I promise.

+

Welcome, new contributors!
+

+ +
After the massive influx over the last few weeks, we only had Andy introducing himself recently – the warmer the welcome for him!
+
+
If you just joined us, don’t hesitate – come over and say “hi” in the forums!
+
+
+

Contributors of the week
+

+ +
+

We salute you!

+
+
Don’t forget that if you are new to SUMO and someone helped you get started in a nice way you can nominate them for the Buddy of the Month!
+
+
+

Most recent SUMO Community meeting

+ +

The next SUMO Community meeting…

+
    +
  • is happening on Monday the 18th – join us!
  • +
  • Reminder: if you want to add a discussion topic to the upcoming meeting agenda: +
      +
    • Start a thread in the Community Forums, so that everyone in the community can see what will be discussed and voice their opinion here before Monday (this will make it easier to have an efficient meeting).
    • +
    • Please do so as soon as you can before the meeting, so that people have time to read, think, and reply (and also add it to the agenda).
    • +
    • If you can, please attend the meeting in person (or via IRC), so we can follow up on your discussion topic during the meeting with your feedback.
    • +
    +
  • +
+

Developers

+ +

Community

+ +

Support Forum

+ + +
+
    +
  • Thanks to everyone writing in with problems, ideas, reports of bugs – all your feedback matters!
  • +
+
+ +

Not that many updates this week, since we’re coming out of our winter slumber (even though winter will be here for a while, still) and plotting an awesome 2016 with you and for you. Take it easy, have a great weekend and see you around SUMO.

+ + 2016-01-15T19:38:51Z + + + Michał + + + https://blog.mozilla.org/sumo + + + SUpport MOzilla's official blog - rocking the helpful web since 2008! + SUMO Blog + 2016-01-25T09:31:47Z + + + + + https://air.mozilla.org/paris-firefox-os-hackathon-presentations/ + + Paris Firefox OS Hackathon Presentations +

+ Paris Firefox OS Hackathon Presentations + As an introduction to this weekend's Firefox OS Hackathon in Paris we'll have two presentations: - Guillaume Marty will talk about the current state of... +

+
+ 2016-01-15T18:00:00Z + + Air Mozilla + + + https://air.mozilla.org/ + + + Except where otherwise noted, content on this site is licensed under the Creative Commons Attribution Share-Alike License v3.0 or any later version. + Air Mozilla is the Internet multimedia presence of Mozilla, with live and pre-recorded shows, interviews, news snippets, tutorial videos, and features about the Mozilla community. + Air Mozilla + 2016-01-25T20:31:49Z + +
+ + + https://tacticalsecret.com/tag/mozilla/rss/db7fec0c-34d3-4633-9904-79b98aab34e7 + + Renewing Let's Encrypt Certs (Nginx) +

All the first Let's Encrypt certs for my websites from the LE private beta began expiring last week, so it was time to work through the renewal tooling. I wanted a script that:

+ +
    +
  1. Would be okay to run daily, so there'd be plenty of retries if something went wrong,
  2. +
  3. Wouldn't
+
+

All the first Let's Encrypt certs for my websites from the LE private beta began expiring last week, so it was time to work through the renewal tooling. I wanted a script that:

+ +
    +
  1. Would be okay to run daily, so there'd be plenty of retries if something went wrong,
  2. +
  3. Wouldn't require extra config for me to forget about if I add a new site,
  4. +
  5. Would only renew certificates expiring in the next few weeks.
  6. +
+ +

The official Let's Encrypt client team is hard at work producing a great renew tool to handle all this, but it's not released yet. Of course I could use Caddy Server that just handles all this, but I have a lot invested in Nginx here.

+ +

So I wrote a short script and put it up in a Gist.

+ +

The script is designed to run daily, with a random start between 00:00 and 02:00 to protect against load spikes at Let's Encrypt's infrastructure. It doesn't do any real reporting, though, except to maintain /var/log/letsencrypt/renew.log as the most-recent failure if one fails.

+ +

It's written to handle Nginx with Upstart's service command. It's pretty modular though; you could make this operate any webserver, or use the webroot method quite easily. Feel free to use the OpenSSL SubjectAlternativeName processing code for whatever purposes you have.

+ +

Happy renewing!

+
+ 2016-01-15T16:01:19Z + + + + James 'J.C.' Jones + + + https://tacticalsecret.com/ + + + On a mission to solve information security issues for the whole Internet. That, and whatever else comes up. + mozilla - The Internet of Secure Things + 2016-01-21T17:31:50Z + +
+ + + http://firefoxmania.uci.cu/?p=15521 + + Conoce los complementos destacados para enero + Comenzó un nuevo año y con él, te traemos nuevos e interesantes complementos para tu navegador preferido que mejoran con creces tu experiencia de navegación. Durante los próximos 6 meses estará trabajando nuevos miembros en el Add-ons Board Team, en la próxima selección desde Firefoxmanía te avisaremos. +

Comenzó un nuevo año y con él, te traemos nuevos e interesantes complementos para tu navegador preferido que mejoran con creces tu experiencia de navegación. Durante los próximos 6 meses estará trabajando nuevos miembros en el Add-ons Board Team, en la próxima selección desde Firefoxmanía te avisaremos.

+

Elección del mes: uMatrix

+

uMatrix es muy parecido a un firewall y desde una ventana fácilmente podrás controlar todos los lugares a donde tu navegador tiene permitido conectarse, qué tipo de datos pueden descargarse y cual puede ejecutar.

+

Esta puede ser la extensión perfecta para el control avanzado de los usuarios.

+

+ + Interfaz principal de uMatrix + Opciones de configuración de uMatrix + +

Instalar uMatrix »

+

También te recomendamos

+

⇒ HTTPS Everywhere por EFF Technologists

+

Protege tus comunicaciones habilitando la encriptación HTTPS automáticamente en los sitios conocidos que la soportan, incluso cuando navegas mediante sitios que no incluyen el prefijo “https” en la URL.

+

⇒ Add to Search Bar por Dr. Evil

+

Hace posible que cualquier página con un formulario de búsqueda disponible pueda ser añadido fácilmente a la barra de búsqueda de Firefox.

+
add_to_search_bar

Añadiendo la búsqueda de un sitio web a la barra de búsqueda

+

⇒ Duplicate Tabs Closer por Peuj

+

Detecta las pestañas duplicadas en tu navegador y automáticamente las cierra.

+

Nomina tus complementos favoritos

+

A nosotros nos encantaría que fueras parte del proceso de seleccionar los mejores complementos para Firefox y nos gustaría escucharte. ¿No sabes cómo? Sólo tienes que enviar un correo electrónico a la dirección amo-featured@mozilla.org con el nombre del complemento o el archivo de instalación y los miembros evaluarán tu recomendación.

+

Fuente: Mozilla Add-ons Blog

+
+ 2016-01-15T15:10:26Z + + + + + Yunier J + + + http://firefoxmania.uci.cu + + + Comunidad Mozilla Firefox de Cuba + Yunier J – Firefoxmanía + 2016-01-23T12:16:22Z + +
+ + + https://timtaubert.de/blog/2016/01/build-your-own-signal-desktop + + Build Your Own Signal Desktop +

The Signal Private Messenger is great. Use it. It’s probably the best secure + messenger on the market. When recently a desktop app was announced people were + eager to join the beta and even happier when an invite finally showed up in + their inbox. So was I, it’s a great app and works surprisingly well for an early + version.

+ +

The only problem is that it’s a Chrome App. Apart from excluding folks with + other browsers it’s also a shitty user experience. If you too want your + messaging app not tied to a browser then let’s just build our own standalone + variant of Signal Desktop.

+ +

NW.js beta with Chrome App support

+ +

Signal Desktop is a Chrome App, so the easiest way to turn it into a standalone + app is to use NW.js. Conveniently, their next release v0.13 + will ship with Chrome App support and is available for download as a beta + version.

+ +

First, make sure you have git and npm installed. Then open a terminal and + prepare a temporary build directory to which we can download a few things and + where we can build the app:

+ +
$ mkdir signal-build
+                $ cd signal-build
+            
+ + +

[OS X] Packaging Signal and NW.js

+ +

Download the latest beta of NW.js and unzip it. We’ll extract the application + and use it as a template for our Signal clone. The NW.js project does + unfortunately not seem to provide a secure source (or at least hashes) + for their downloads.

+ +
$ wget http://dl.nwjs.io/v0.13.0-beta3/nwjs-sdk-v0.13.0-beta3-osx-x64.zip
+                $ unzip nwjs-sdk-v0.13.0-beta3-osx-x64.zip
+                $ cp -r nwjs-sdk-v0.13.0-beta3-osx-x64/nwjs.app SignalPrivateMessenger.app
+            
+ + +

Next, clone the Signal repository and use NPM to install the necessary modules. + Run the grunt automation tool to build the application.

+ +
$ git clone https://github.com/WhisperSystems/Signal-Desktop.git
+                $ cd Signal-Desktop/
+                $ npm install
+                $ node_modules/grunt-cli/bin/grunt
+            
+ + +

Finally, simply to copy the dist folder containing all the juicy Signal files + into the application template we created a few moments ago.

+ +
$ cp -r dist ../SignalPrivateMessenger.app/Contents/Resources/app.nw
+                $ open ..
+            
+ + +

The last command opens a Finder window. Move SignalPrivateMessenger.app to + your Applications folder and launch it as usual. You should now see a welcome + page!

+ +

[Linux] Packaging Signal and NW.js

+ +

The build instructions for Linux aren’t too different but I’ll write them down, + if just for convenience. Start by cloning the Signal Desktop repository and + build.

+ +
$ git clone https://github.com/WhisperSystems/Signal-Desktop.git
+                $ cd Signal-Desktop/
+                $ npm install
+                $ node_modules/grunt-cli/bin/grunt
+            
+ + +

The dist folder contains the app, ready to be launched. zip it and place + the resulting package somewhere handy.

+ +
$ cd dist
+                $ zip -r ../../package.nw *
+            
+ + +

Back to the top. Download the NW.js binary, extract it, and change into the + newly created directory. Move the package.nw file we created earlier next to + the nw binary and we’re done. The nwjs-sdk-v0.13.0-beta3-linux-x64 folder + does now contain the standalone Signal app.

+ +
$ cd ../..
+                $ wget http://dl.nwjs.io/v0.13.0-beta3/nwjs-sdk-v0.13.0-beta3-linux-x64.tar.gz
+                $ tar xfz nwjs-sdk-v0.13.0-beta3-linux-x64.tar.gz
+                $ cd nwjs-sdk-v0.13.0-beta3-linux-x64
+                $ mv ../package.nw .
+            
+ + +

Finally, launch NW.js. You should see a welcome page!

+ +
$ ./nw
+            
+ + +

If you see something, file something

+ +

Our standalone Signal clone mostly works, but it’s far from perfect. We’re + pulling from master and that might bring breaking changes that weren’t + sufficiently tested.

+ +

We don’t have the right icons. The app crashes when you click a media message. + It opens a blank popup when you click a link. It’s quite big because also NW.js + has bugs and so we have to use the SDK build for now. In the future it would be + great to have automatic updates, and maybe even signed builds.

+ +

Remember, Signal Desktop is beta, and completely untested with NW.js. If you + want to help file bugs, but only after checking that those affect the Chrome + App too. If you want to fix a bug only occurring in the standalone version + it’s probably best to file a pull request and cross fingers.

+ +

Is this secure?

+ +

Great question! I don’t know. I would love to get some more insights from people + that know more about the NW.js security model and whether it comes with all the + protections Chromium can offer. Another interesting question is whether bundling + Signal Desktop with NW.js is in any way worse (from a security perspective) than + installing it as a Chrome extension. If you happen to have an opinion about + that, I would love to hear it.

+ +

Another important thing to keep in mind is that when building Signal on your + own you will possibly miss automatic and signed security updates from the + Chrome Web Store. Keep an eye on the repository and rebuild your app from + time to time to not fall behind too much.

+
+ 2016-01-15T14:00:00Z + + https://timtaubert.de/ + + Tim Taubert + + + + Tim Taubert + 2016-01-15T15:04:09Z + +
+ + + http://glandium.org/blog/?p=3579 + + Announcing git-cinnabar 0.3.0 + Git-cinnabar is a git remote helper to interact with mercurial repositories. It allows to clone, pull and push from/to mercurial remote repositories, using git. Get it on github. These release notes are also available on the git-cinnabar wiki. Development had been stalled for a few months, with many improvements in the next branch without any […] +

Git-cinnabar is a git remote helper to interact with mercurial repositories. It allows to clone, pull and push from/to mercurial remote repositories, using git.

+

Get it on github.

+

These release notes are also available on the git-cinnabar wiki.

+

Development had been stalled for a few months, with many improvements in the
+ next branch without any new release. I used some time during the new year
+ break and after in order to straighten things up in order to create a new
+ release, delaying many of the originally planned changes to a future 0.4.0
+ release.

+

What’s new since 0.2.2?

+
    +
  • Speed and memory usage were improved when doing git push.
  • +
  • Now works on Windows, at least to some extent. See details.
  • +
  • Support for pre-0.1.0 git-cinnabar repositories was removed. You must first
    + use a git-cinnabar version between 0.1.0 and 0.2.2 to upgrade its metadata.
  • +
  • It is now possible to attach/graft git-cinnabar metadata to existing commits
    + matching mercurial changesets. This allows to migrate from some other
    + hg-to-git tool to git-cinnabar while preserving the existing git commits.
    + See an example of how this works with the git clone of the Gecko mercurial
    + repository
    +
  • +
  • Avoid mercurial printing its progress bar, messing up with git-cinnabar’s
    + output.
  • +
  • It is now possible to fetch from an incremental mercurial bundle (without
    + a root changeset).
  • +
  • It is now possible to push to a new mercurial repository without -f.
  • +
  • By default, reject pushing a new root to a mercurial repository.
  • +
  • Make the connection to a mercurial repository through ssh respect the
    + GIT_SSH and GIT_SSH_COMMAND environment variables.
  • +
  • + git cinnabar now has a proper argument parser for all its subcommands.
  • +
  • +
  • +
  • A new git cinnabar python command allows to run python scripts or open a
    + python shell with the right sys.path to import the cinnabar module.
  • +
  • All git-cinnabar metadata is now kept under a single ref (although for
    + convenience, other refs are created, but they can be derived if necessary).
  • +
  • Consequently, a new git cinnabar rollback command allows to roll back to
    + previous metadata states.
  • +
  • git-cinnabar metadata now tracks the manifests DAG.
  • +
  • A new git cinnabar bundle command allows to create mercurial bundles,
    + mostly for debugging purposes, without requiring to hit a mercurial server.
  • +
  • Updated git to 2.7.0 for the native helper.
  • +
+

Development process changes

+

Up to before this release closing in, the master branch was dedicated to
+ releases, and development was happening on the next branch, until a new
+ release happens.

+

From now on, the release branch will take dot-release fixes and new
+ releases, while the master branch will receive all changes that are
+ validated through testing (currently semi-automatically tested with
+ out-of-tree tests based on four real-life mercurial repositories, with
+ some automated CI based on in-tree tests used in the future).

+

The next branch will receive changes to be tested in CI when things
+ will be hooked up, and may have rewritten history as a consequence of
+ wanting passing tests on every commit on master.

+
+ 2016-01-15T08:56:40Z + + + + + glandium + + + http://glandium.org/blog + + + glandium.org + p.m.o – glandium.org + 2016-01-16T11:30:44Z + +
+ + + https://air.mozilla.org/web-qa-weekly-meeting-20160114/ + + Web QA Weekly Meeting, 14 Jan 2016 +

+ Web QA Weekly Meeting + This is our weekly gathering of Mozilla'a Web QA team filled with discussion on our current and future projects, ideas, demos, and fun facts. +

+
+ 2016-01-14T17:00:00Z + + Air Mozilla + + + https://air.mozilla.org/ + + + Except where otherwise noted, content on this site is licensed under the Creative Commons Attribution Share-Alike License v3.0 or any later version. + Air Mozilla is the Internet multimedia presence of Mozilla, with live and pre-recorded shows, interviews, news snippets, tutorial videos, and features about the Mozilla community. + Air Mozilla + 2016-01-25T20:31:49Z + +
+ + + https://air.mozilla.org/reps-weekly-20160114/ + + Reps weekly, 14 Jan 2016 +

+ Reps weekly + This is a weekly call with some of the Reps to discuss all matters about/affecting Reps and invite Reps to share their work with everyone. +

+
+ 2016-01-14T16:00:00Z + + Air Mozilla + + + https://air.mozilla.org/ + + + Except where otherwise noted, content on this site is licensed under the Creative Commons Attribution Share-Alike License v3.0 or any later version. + Air Mozilla is the Internet multimedia presence of Mozilla, with live and pre-recorded shows, interviews, news snippets, tutorial videos, and features about the Mozilla community. + Air Mozilla + 2016-01-25T20:31:50Z + +
+ + + http://blog.mozilla.org/community/?p=2281 + + 32C3 Report – Chaos Time Zone +
Written by Valentin Schmitt. Entering the CCH (Congress Center Hamburg) between Christmas and new year brings you somewhere else than Hamburg on Central European Time. Most people you’ll meet will say they are from Internet (or the Internets, if they … Continue reading
+
+

Written by Valentin Schmitt.

+

Entering the CCH (Congress Center Hamburg) between Christmas and new year brings you somewhere else than Hamburg on Central European Time.

+

Most people you’ll meet will say they are from Internet (or the Internets, if they are funny), and for a few days you’ll live in -what a friend of mine called- Chaos Time Zone: a blurry mix of everyone’s time difference. Days are pretty shorts anyway and you’ll probably spend a lot of time under artificial light, so it won’t help your internal clock keeping on track. The organizers will gently remind you the 6,2,1 rule: 6 hours of sleep, 2 meals and 1 shower per day, that should keep you safe. You’ll probably meet a lot of great people, and will often have a hard time to decide which talk or workshop to go to.
+ This is the 32nd Chaos Communication Congress. Welcome, and have fun!

+
32C3 Chaos Communication Congress

32C3 Chaos Communication Congress – Photo: Mario Behling

+

FxOS is not dead.

+

I looked for a screen printer, or anything to do myself a t-shirt with the message “Firefox OS is not dead!” on it, but very surprisingly regarding the variety of machines there, I couldn’t find any on site. I really wanted to do that, because most of the people I talked to about
+ Firefox OS answered me “But isn’t Firefox OS dead?”. I bet it won’t come as a surprise for you, as there was a lot of feedback from the community regarding what some might call “a PR disaster”. It just made it very clear to me that we (still) have to communicate a lot on this topic, and very loudly, because the tech news websites will be less likely to spread the word this time.

+

Once this detail (*cough*) was clarified, almost everybody I had the chance to talk to showed a lot of interested for the project, the only ones who didn’t were the hardcore Free Software enthusiasts, whom have been disappointed by Mozilla recent policy choices (like the tiles with
+ advertisement, or the DRM support in Firefox desktop), or the people who care less about software freedom and prefer an iPhone to a free (as in freedom) mobile OS.

+
Mozilla and Firefox at 32C3 with friends

Mozilla and Firefox at 32C3 with friends – Photo: Mario Behling

+

“Well, it’s Mozilla.”

+

Mozilla has a pretty good image in the Free Software community, and the main reason why people never tried a Firefox OS device is only because they never had the chance to do so (not many devices marketed in Europe or the US, not many ports on mainstream phones). Fortunately enough, I had some foxfooding devices to hand out. The foxfooding program had a very positive reception, most people were happy to have the chance to try the OS, participate in sending data to Mozilla, file bugs, some were eager to develop apps, and try port the OS on their favorite phone or device (the RasPi got a bunch of them very excited).

+

More importantly, they really asked me how to flash a device, where to find the documentation to get started, how to file a bug. The people I handed a device to planned to show it to their colleagues, friends and fellow hacktivists, and were very excited to have phone with a hardware good enough to provide a responsive experience.

+

Questions?

+

“Is there a Signal app or any secure messaging app?”
+ “Can I use Tor?”
+ “Can I keep OSM maps in cache?”
+ “Is there an app for WhatsApp?”
+ These were the questions I was asked the most. It’s pretty expected that the hackers community is looking for reliable privacy tools, but I was a bit surprised by the last question that still came up several times. :)

+

Mozillians, assemble!

+

An assembly is the name the Chaos Communication Congress gives to the physical place (typically a bunch of tables with a power outlet) within the CCH where people can gather to hack, share ideas and have self organized-sessions on a particular topic, or around a particular project, there were 277 registered this year.

+
Assembling Under The Lights

Assembling Under The Lights – Photo: Hong Phuc FOSSASIA

+

With the Mozilla Assembly, we had several sessions (directly at the Assembly or in dedicated rooms) over these 4 days:

+
    +
  • Several Nightly Firefox OS workshops, combining more than 50 participants;
  • +
  • The Mozilla community meetup that gathered 20 participants;
  • +
  • a Thunderbird session with 42 participants;
  • +
  • an IoT and Firefox OS workshop, in a dedicated room that was packed with 90 participants;
  • +
+

On average, there were around 15 Mozillians at the Assembly and a continuous flow of people from different community.

+

Other projects where Mozilla is involved were represented, like Let’s Encrypt, with a talk so successful that the conference room was full, and New Palmyra, for which Mozillians organized a session for 25 participants.

+

The hackers and makers communities have a real ethical and practical interest in a mobile or embedded OS that’s trustworthy and hackable, we bear similar values and Firefox OS is a great opportunity to strengthen the ties between us.

+
+ 2016-01-13T22:55:23Z + + + + + + + + + + + + + Brian King + + + http://blog.mozilla.org/community + + + News and notes from and for the Mozilla community. + about:community + 2016-01-25T16:31:43Z + +
+ diff --git a/mobile/android/tests/background/junit4/resources/feed_atom_wikipedia.xml b/mobile/android/tests/background/junit4/resources/feed_atom_wikipedia.xml new file mode 100644 index 000000000..8b0344c59 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_atom_wikipedia.xml @@ -0,0 +1,34 @@ + + + + + Example Feed + A subtitle. + + + urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6 + 2003-12-13T18:30:02Z + + + + Atom-Powered Robots Run Amok + + + + urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a + 2003-12-13T18:30:02Z + Some text. + +
+

This is the entry content.

+
+
+ + John Doe + johndoe@example.com + +
+ +
\ No newline at end of file diff --git a/mobile/android/tests/background/junit4/resources/feed_rss10_planetmozilla.xml b/mobile/android/tests/background/junit4/resources/feed_rss10_planetmozilla.xml new file mode 100644 index 000000000..2cfd93d3c --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_rss10_planetmozilla.xml @@ -0,0 +1,3860 @@ + + + + Planet Mozilla + http://planet.mozilla.org/ + Planet Mozilla - http://planet.mozilla.org/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Aaron Klotz: Announcing Mozdbgext + http://dblohm7.ca/blog/2016/01/26/announcing-mozdbgext/ + <p>A well-known problem at Mozilla is that, while most of our desktop users run + Windows, most of Mozilla’s developers do not. There are a lot of problems that + result from that, but one of the most frustrating to me is that sometimes + those of us that actually use Windows for development find ourselves at a + disadvantage when it comes to tooling or other productivity enhancers.</p> + + <p>In many ways this problem is also a Catch-22: People don’t want to use Windows + for many reasons, but tooling is big part of the problem. OTOH, nobody is + motivated to improve the tooling situation if nobody is actually going to + use them.</p> + + <p>A couple of weeks ago my frustrations with the situation boiled over when I + learned that our <code>Cpp</code> unit test suite could not log symbolicated call stacks, + resulting in my filing of <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1238305" title="cppunittests do not look up breakpad symbols for logged stack traces">bug 1238305</a> and <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1240605" title="Set _NT_SYMBOL_PATH on Windows test machines">bug 1240605</a>. Not only could we + not log those stacks, in many situations we could not view them in a debugger + either.</p> + + <p>Due to the fact that PDB files consume a large amount of disk space, we don’t + keep those when building from integration or try repositories. Unfortunately + they are be quite useful to have when there is a build failure. Most of our + integration builds, however, do include breakpad symbols. Developers may also + explicitly <a href="https://wiki.mozilla.org/ReleaseEngineering/TryServer#Getting_debug_symbols">request symbols</a> + for their try builds.</p> + + <p>A couple of years ago I had begun working on a WinDbg debugger extension that + was tailored to Mozilla development. It had mostly bitrotted over time, but I + decided to resurrect it for a new purpose: to help WinDbg<sup><a href="http://dblohm7.ca/atom.xml#fn1" id="r1">*</a></sup> + grok breakpad.</p> + + <h3>Enter mozdbgext</h3> + + <p><a href="https://github.com/dblohm7/mozdbgext"><code>mozdbgext</code></a> is the result. This extension + adds a few commands that makes Win32 debugging with breakpad a little bit easier.</p> + + <p>The original plan was that I wanted <code>mozdbgext</code> to load breakpad symbols and then + insert them into the debugger’s symbol table via the <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff537943%28v=vs.85%29.aspx"><code>IDebugSymbols3::AddSyntheticSymbol</code></a> + API. Unfortunately the design of this API is not well equipped for bulk loading + of synthetic symbols: each individual symbol insertion causes the debugger to + re-sort its entire symbol table. Since <code>xul.dll</code>’s quantity of symbols is in the + six-figure range, using this API to load that quantity of symbols is + prohibitively expensive. I tweeted a Microsoft PM who works on Debugging Tools + for Windows, asking if there would be any improvements there, but it sounds like + this is not going to be happening any time soon.</p> + + <p>My original plan would have been ideal from a UX perspective: the breakpad + symbols would look just like any other symbols in the debugger and could be + accessed and manipulated using the same set of commands. Since synthetic symbols + would not work for me in this case, I went for “Plan B:” Extension commands that + are separate from, but analagous to, regular WinDbg commands.</p> + + <p>I plan to continuously improve the commands that are available. Until I have a + proper README checked in, I’ll introduce the commands here.</p> + + <h4>Loading the Extension</h4> + + <ol> + <li>Use the <code>.load</code> command: <code>.load &lt;path_to_mozdbgext_dll&gt;</code></li> + </ol> + + + <h4>Loading the Breakpad Symbols</h4> + + <ol> + <li>Extract the breakpad symbols into a directory.</li> + <li>In the debugger, enter <code>!bploadsyms &lt;path_to_breakpad_symbol_directory&gt;</code></li> + <li>Note that this command will take some time to load all the relevant symbols.</li> + </ol> + + + <h4>Working with Breakpad Symbols</h4> + + <p><strong>Note: You must have successfully run the <code>!bploadsyms</code> command first!</strong></p> + + <p>As a general guide, I am attempting to name each breakpad command similarly to + the native WinDbg command, except that the command name is prefixed by <code>!bp</code>.</p> + + <ul> + <li>Stack trace: <code>!bpk</code></li> + <li>Find nearest symbol to address: <code>!bpln &lt;address&gt;</code> where <em>address</em> is specified + as a hexadecimal value.</li> + </ul> + + + <h4>Downloading windbgext</h4> + + <p>I have pre-built a <a href="https://github.com/dblohm7/mozdbgext/blob/master/bin/mozdbgext.dll?raw=true">32-bit binary</a> + (which obviously requires 32-bit WinDbg). I have not built a 64-bit binary yet, + but the code should be source compatible.</p> + + <p>Note that there are several other commands that are “roughed-in” at this point + and do not work correctly yet. Please stick to the documented commands at this + time.</p> + + <hr /> + + <p><sup><a href="http://dblohm7.ca/atom.xml#r1" id="fn1">*</a></sup> When I write “WinDbg”, I am really + referring to any debugger in the <em>Debugging Tools for Windows</em> package, + including <code>cdb</code>.</p> + 2016-01-26T19:45:00+00:00 + + + Yunier José Sosa Vázquez: Soporte para WebM/VP9, más seguridad y nuevas herramientas para desarrolladores en el nuevo Firefox + http://firefoxmania.uci.cu/soporte-para-webmvp9-mas-seguridad-y-nuevas-herramientas-para-desarrolladores-en-el-nuevo-firefox/ + <p style="text-align: left;">¡Como pasa el tiempo amigos! Casi sin darnos cuenta han transcurrido 6 semanas y hasta hemos comenzado un año nuevo, un año en el que Mozilla prepara nuevas funcionalidades que harán de Firefox un mejor como por ejemplo: la <a href="http://firefoxmania.uci.cu/como-se-hace-activar-electrolysis-en-firefox/" target="_blank">separación de procesos</a>, el uso de vías alternas para <a href="http://firefoxmania.uci.cu/el-futuro-de-los-plugins-npapi-en-firefox/" target="_blank">ejecutar plugins</a> y la nueva API para desarrollar <a href="http://firefoxmania.uci.cu/el-futuro-de-los-complementos-en-firefox/" target="_blank">complementos “multi navegador”</a>.</p> + <p style="text-align: left;">Desde el anuncio en 2010 del formato de video WebM, <a href="https://blog.mozilla.org/blog/2010/05/19/open-web-open-video-and-webm/" target="_blank">Mozilla ha mostrado un especial interés</a> al ser una alternativa potente frente a los formatos propietarios del mercado que existían en aquel momento y de esta forma mejorar la experiencia de los usuarios al reproducir videos en la web. Con esta liberación se ha habilitado el <strong>soporte para WebM/VP9 en aquellos sistemas que no soportan MP4/H.264</strong>.</p> + <p style="text-align: left;">Desde algunas versiones atrás, Firefox incluye el plugin <a href="http://andreasgal.com/2014/10/14/openh264-now-in-firefox/" target="_blank">OpenH264 proveído por Cisco</a> para cumplir las especificaciones de WebRTC y habilitar las llamadas con dispositivos que lo requieran. Ahora, si el <strong>decodificador de H.264 está disponible</strong> en el sistema, entonces se habilita este codec de video.<span id="more-15548"></span></p> + <h3 style="text-align: left;"><em>Novedades para desarrolladores</em></h3> + <p style="text-align: left;">En esta oportunidad, los desarrolladores podrán contar con herramientas de animación y filtros CSS, informes sobre consumo de memoria, depuración de WebSocket y más. Todo esto puedes leerlo en <a href="https://www.mozilla-hispano.org/edicion-para-desarrolladores-44-editor-visual-manejo-de-memoria/" target="_blank">el blog de Labs</a> de Mozilla Hispano.</p> + <h3 style="text-align: left;"><em>Novedades en Android</em></h3> + <ul> + <li>Los usuarios pueden elegir la página de inicio a mostrar, en vez de los sitios más visitados.</li> + <li>El servicio de impresión de Android permite activar la impresión en la nube.</li> + <li>Al <a href="https://developer.chrome.com/multidevice/android/intents" target="_blank">intentar abrir una URIs</a>, se le pregunta al usuario si desea abrirla en una pestaña privada.</li> + <li>Adicionado el soporte para ejecutar URIs con el protocolo mms.</li> + <li>Fácil acceso a la configuración de la búsqueda mientras buscamos en Internet.</li> + <li>Ahora se muestran las sugerencias del historial de búsqueda.</li> + <li>La página Cuentas Firefox ahora está basada en la web.</li> + </ul> + <h3><em>Otras novedades</em></h3> + <ul> + <li>El soporte para el algoritmo criptográfico RC4 ha sido removido.</li> + <li>Soporte para el formato de compresión brotli cuando se usa HTTPS.</li> + <li>Uso de un certificado de firmado SHA256 para las versiones de Windows en aras de adaptarse a los nuevos requerimientos.</li> + <li>Para soportar el descriptor unicode-range de las fuentes web, el algoritmo de concordancia en Linux usa el mismo código como en las demás plataformas.</li> + <li>Firefox no confiará más en la autoridad de certificación Equifax Secure Certificate Authority 1024-bit root o UTN – DATACorp SGC para validar <a href="https://support.mozilla.org/ta/kb/secure-website-certificate" target="_blank">certificados web seguros</a>.</li> + <li>El soporte para el teclado en pantalla ha sido temporalmente desactivado en Windows 8 y 8.1.</li> + </ul> + <p>Si deseas conocer más, puedes leer las <a href="http://www.mozilla.org/en-US/firefox/44.0/releasenotes/" target="_blank">notas de lanzamiento</a> (en inglés) para conocer más novedades.</p> + <p><strong>Aclaración para la versión móvil.</strong></p> + <p>En las descargas se pueden encontrar 3 versiones para Android. El archivo que contiene <strong>i386</strong> es para los dispositivos que tengan la <strong>arquitectura de Intel</strong>. Mientras que en los nombrados <strong>arm</strong>, el que dice <strong>api11 funciona con Honeycomb (3.0) o superior</strong> y el de <strong>api9 es para Gingerbread (2.3)</strong>.</p> + <p>Puedes obtener esta versión desde nuestra <a href="http://firefoxmania.uci.cu/download/" target="_blank">zona de Descargas</a> en español e inglés para Linux, Mac, Windows y Android. Recuerda que para navegar a través de servidores proxy debes modificar la preferencia <strong>network.auth.force-generic-ntlm</strong> a <code>true</code> desde <a target="_blank">about:config</a>.</p> + <p>Si te ha gustado, por favor comparte con tus amigos esta noticia en las redes sociales. No dudes en dejarnos un comentario.</p> + 2016-01-26T18:56:54+00:00 + Yunier J + + + QMO: Firefox 45.0 Beta 3 Testday, February 5th + https://quality.mozilla.org/2016/01/firefox-45-0-beta-3-testday-february-5th/ + <p>Hello Mozillians,</p> + <p>We are happy to announce that <strong>Friday, February 5th</strong>, we are organizing <strong>Firefox 45.0 Beta 3 Testday</strong>. We will be focusing our testing on the following features: <em>Search Refactoring, Synced Tabs Menu, Text to Speech and Grouped Tabs Migration</em>. Check out the detailed instructions via <a href="https://public.etherpad-mozilla.org/p/testday-20160205" target="_blank">this etherpad</a>.</p> + <p>No previous testing experience is required, so feel free to join us on <strong><a href="http://widget01.mibbit.com/?server=irc.mozilla.org&amp;channel=%23qa">#qa IRC channel</a></strong> where our moderators will offer you guidance and answer your questions.</p> + <p>Join us and help us make Firefox better! See you on <strong>Friday</strong>!</p> + 2016-01-26T14:40:55+00:00 + vasilica.mihasca + + + David Lawrence: Happy BMO Push Day! + https://dlawrence.wordpress.com/2016/01/26/happy-bmo-push-day-4/ + <p>the following changes have been pushed to bugzilla.mozilla.org:</p> + <ul> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1240575" target="_blank">1240575</a>] Update form.reps.budget</li> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1226028" target="_blank">1226028</a>] API for batching MozReview requests</li> + </ul> + <p>discuss these changes on <a href="https://lists.mozilla.org/listinfo/tools-bmo" target="_blank">mozilla.tools.bmo</a>.</p><br /> <a href="http://feeds.wordpress.com/1.0/gocomments/dlawrence.wordpress.com/29/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dlawrence.wordpress.com/29/" /></a> <img alt="" border="0" height="1" src="https://pixel.wp.com/b.gif?host=dlawrence.wordpress.com&amp;blog=58816&amp;post=29&amp;subd=dlawrence&amp;ref=&amp;feed=1" width="1" /> + 2016-01-26T14:27:50+00:00 + dlawrence + + + Tanvi Vyas: Updated Firefox Security Indicators + https://blog.mozilla.org/tanvi/2016/01/26/updated-firefox-security-indicators/ + <p><em>This article has been coauthored by Aislinn Grigas, Senior Interaction Designer, Firefox Desktop</em><br /> + <em>Cross posting with <a href="https://blog.mozilla.org/security/2015/11/03/updated-firefox-security-indicators-2/">Mozilla’s Security Blog</a></em></p> + <p>November 3, 2015</p> + <p>Over the past few months, Mozilla has been improving the user experience of our privacy and security features in Firefox. One specific initiative has focused on the feedback shown in our address bar around a site’s security. The major changes are highlighted below along with the rationale behind each change.</p> + <p><a href="https://blog.mozilla.org/security/files/2015/10/combo-graph21.png"><img alt="" class="alignnone wp-image-2045 size-full" height="914" src="https://blog.mozilla.org/security/files/2015/10/combo-graph21.png" width="1518" /></a></p> + <h3>Change to DV Certificate treatment in the address bar</h3> + <p>Color and iconography is commonly used today to communicate to users when a site is secure. The most widely used patterns are coloring a lock icon and parts of the address bar green. This treatment has a straightforward rationale given green = good in most cultures. Firefox has historically used two different color treatments for the lock icon – a gray lock for <a href="https://en.wikipedia.org/wiki/Domain-validated_certificate">Domain-validated (DV) certificates</a> and a green lock for <a href="https://en.wikipedia.org/wiki/Extended_Validation_Certificate">Extended Validation (EV) certificates</a>. The average user is likely not going to understand this color distinction between EV and DV certificates. The overarching message we want users to take from both certificate states is that their connection to the site is secure. We’re therefore updating the color of the lock when a DV certificate is used to match that of an EV certificate.</p> + <p>Although the same green icon will be used, the UI for a site using EV certificates will continue to differ from a site using a DV certificate. Specifically, EV certificates are used when <a href="https://en.wikipedia.org/wiki/Certificate_authority">Certificate Authorities (CA)</a> verify the owner of a domain. Hence, we will continue to include the organization name verified by the CA in the address bar.</p> + <h3>Changes to Mixed Content Blocker UI on HTTPS sites</h3> + <p>A second change we’re introducing addresses what happens when a page served over a secure connection contains <a href="https://developer.mozilla.org/en-US/docs/Security/MixedContent">Mixed Content</a>. Firefox’s Mixed Content Blocker proactively blocks <a href="https://developer.mozilla.org/en-US/docs/Security/MixedContent#Mixed_active_content">Mixed Active Content</a> by default. Users historically saw a <a href="https://people.mozilla.org/~tvyas/FigureA.jpg">shield icon</a> when Mixed Active Content was blocked and were given the option to disable the protection.</p> + <p>Since the Mixed Content state is closely tied to site security, the information should be communicated in one place instead of having two separate icons. Moreover, we have seen that the <a href="https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&amp;end_date=2015-09-17&amp;keys=__none__!__none__!__none__&amp;max_channel_version=beta%252F41&amp;measure=MIXED_CONTENT_UNBLOCK_COUNTER&amp;min_channel_version=null&amp;product=Firefox&amp;sanitize=1&amp;sort_keys=submissions&amp;start_date=2015-08-11&amp;table=0&amp;trim=1&amp;use_submission_date=0">number of times users override mixed content protection</a> is slim, and hence the need for dedicated mixed content iconography is diminishing. Firefox is also using the shield icon for another feature in <a href="https://support.mozilla.org/en-US/kb/private-browsing-use-firefox-without-history">Private Browsing Mode</a> and we want to avoid making the iconography ambiguous.</p> + <p>The updated design that ships with Firefox 42 combines the lock icon with a warning sign which represents Mixed Content. When Firefox blocks Mixed Active Content, we retain the green lock since the HTTP content is blocked and hence the site remains secure.</p> + <p>For users who want to learn more about a site’s security state, we have added an informational panel to further explain differences in page security. This panel appears anytime a user clicks on the lock icon in the address bar.</p> + <p>Previously users could <a href="https://people.mozilla.org/~tvyas/FigureB.jpg">click on the shield icon</a> in the rare case they needed to override mixed content protection. With this new UI, users can still do this by clicking the arrow icon to expose more information about the site security, along with a disable protection button.</p> + <div class="wp-caption alignnone" id="attachment_2034" style="width: 557px;"><a href="https://blog.mozilla.org/security/files/2015/10/mixed-active-content-click-and-subpanel.png"><img alt="mixed active content click and subpanel" class="wp-image-2034 " height="176" src="https://blog.mozilla.org/security/files/2015/10/mixed-active-content-click-and-subpanel.png" width="547" /></a><p class="wp-caption-text">Users can click the lock with warning icon and proceed to disable Mixed Content Protection.</p></div> + <h3></h3> + <h3>Loading Mixed Passive Content on HTTPS sites</h3> + <p>There is a second category of Mixed Content called <a href="https://developer.mozilla.org/en-US/docs/Security/MixedContent#Mixed_passivedisplay_content">Mixed Passive Content</a>. Firefox does not block Mixed Passive Content by default. However, when it is loaded on an HTTPS page, we let the user know with iconography and text. In previous versions of Firefox, we used a gray warning sign to reflect this case.</p> + <p>We have updated this iconography in Firefox 42 to a gray lock with a yellow warning sign. We degrade the lock from green to gray to emphasize that the site is no longer completely secure. In addition, we use a vibrant color for the warning icon to amplify that there is something wrong with the security state of the page.</p> + <p><a href="https://blog.mozilla.org/security/files/2015/10/mixed-passive-click1.png"><img alt="" class="alignnone wp-image-2042 " height="100" src="https://blog.mozilla.org/security/files/2015/10/mixed-passive-click1-600x221.png" width="268" /></a></p> + <p>We also use this iconography when the certificate or TLS connection used by the website relies on deprecated cryptographic algorithms.</p> + <p>The above changes will be rolled out in Firefox 42. Overall, the design improvements make it simpler for our users to understand whether or not their interactions with a site are secure.</p> + <h3>Firefox Mobile</h3> + <p>We have made similar changes to the site security indicators in Firefox for Android, which you can learn more about <a href="https://support.mozilla.org/en-US/kb/mixed-content-blocker-firefox-android#w_how-do-i-know-if-a-page-has-mixed-content">here</a>.</p> + 2016-01-26T05:58:29+00:00 + Tanvi Vyas + + + The Mozilla Blog: Firefox Can Now Get Push Notifications From Your Favorite Sites + https://blog.mozilla.org/blog/2016/01/25/firefox-can-now-get-push-notifications-from-your-favorite-sites/ + <p>UPDATED TO CLARIFY HOW TO MANAGE PUSH NOTIFICATIONS</p> + <p>Firefox for Windows, Mac and Linux now lets you choose to receive push notifications from websites if you give them permission. This is similar to Web notifications, except now you can receive notifications for websites even when they’re not loaded in a tab. This is super useful for websites like email, weather, social networks and shopping, which you might check frequently for updates.</p> + <p>You can manage your notifications in the Control Center by clicking the green lock icon on the left side of the address bar. You can learn more about how to manage push notifications<a href="https://support.mozilla.org/en-US/kb/push-notifications-firefox?as=u&amp;utm_source=inproduct#w_upgraded-notifications"> here</a>.</p> + <p><b>Push Notifications for Web Developers</b><br /> + To make this functionality possible, Mozilla helped establish the Web Push W3C standard that’s gaining momentum across the Web. We also continue to explore the new design pattern known as<a href="https://blog.mozilla.org/futurereleases/2015/11/17/extending-the-webs-capabilities-in-firefox-and-beyond/"> Progressive Web Apps</a>. If you’re a developer who wants to implement push notifications on your site, you can learn more in this<a href="https://hacks.mozilla.org/2016/01/web-push-arrives-in-firefox-44/"> Hacks blog post</a>.</p> + <p><b>More information:</b></p> + <ul> + <li>Download<a href="https://www.mozilla.org/firefox/new/"> Firefox for Windows, Mac, Linux</a></li> + <li>Release Notes for<a href="https://www.mozilla.org/firefox/44.0/releasenotes/"> Firefox for Windows, Mac, Linux</a></li> + <li>Download<a href="https://play.google.com/store/apps/details?id=org.mozilla.firefox&amp;referrer=utm_source%3Dmozilla%26utm_medium"> Firefox for Android</a></li> + <li>Release Notes for<a href="https://www.mozilla.org/firefox/android/44.0/releasenotes/"> Firefox for Android</a></li> + </ul> + 2016-01-26T01:56:50+00:00 + Mozilla + + + Benoit Girard: Using RecordReplay to investigate intermittent oranges + https://benoitgirard.wordpress.com/2016/01/25/using-recordreplay-to-investigate-intermittent-oranges/ + <p>This is a quick write up to summarize my, and Jeff’s, experience, using RR to debug a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1226748">fairly rare intermittent reftest failure</a>. There’s still a lot of be learned about how to use RR effectively so I’m hoping sharing this will help others.</p> + <h3>Finding the root of the bad pixel</h3> + <p>First given a offending pixel I was able to set a breakpoint on it using <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Hacking_Tips#rr_with_reftest">these instructions</a>. Next using <a href="https://github.com/jrmuizel/rr-dataflow">rr-dataflow</a> I was able to step from the offending bad pixel to the display item responsible for this pixel. Let me emphasize this for a second since it’s incredibly impressive. rr + rr-dataflow allows you to go from a buffer, through an intermediate surface, to the compositor on another thread, through another intermediate surface, back to the main thread and eventually back to the relevant display item. All of this was automated except for when the two pixels are blended together which is logically ambiguous. The speed at which rr was able to reverse continue through this execution was very impressive!</p> + <p>Here’s the trace of this part: <a href="https://gist.github.com/bgirard/e707e9b97556b500d9ae">rr-trace-reftest-pixel-origin</a></p> + <h3>Understanding the decoding step</h3> + <p>From here I started comparing a replay of a failing test and a non failing step and it was clear that the DisplayList was different. In one we have a nsDisplayBackgroundColor in the other we don’t. From here I was able to step through the decoder and compare the sequence. This was very useful in ruling out possible theories. It was easy to step forward and backwards in the good and bad replay debugging sessions to test out various theories about race conditions and understanding at which part of the decode process the image was rejected. It turned out that we sent two decodes, one for the metadata that is used to sized the frame tree and the other one for the image data itself.</p> + <h3>Comparing the frame tree</h3> + <p>In hindsight, it would have been more effective to start debugging this test by looking at the frame tree (and I imagine for other tests looking at the display list and layer tree) first would have been a quicker start. It works even better if you have a good and a bad trace to compare the difference in the frame tree. From here, I found that the difference in the layer tree came from a change hint that wasn’t guaranteed to come in before the draw.</p> + <p>The problem is now well understood: When we do a sync decode on reftest draw, if there’s an image error we wont flush the style hints since we’re already too deep in the painting pipeline.</p> + <h3>Take away</h3> + <ul> + <li>Finding the root cause of a bad pixel is very easy, and fast, to do using rr-dataflow.</li> + <li>However it might be better to look for obvious frame tree/display list/layer tree difference(s) first.</li> + <li>Debugging a replay is a lot simpler then debugging against non-determinist re-runs and a lot less frustrating too.</li> + <li>rr is really useful for race conditions, especially rare ones.</li> + </ul><br /> <a href="http://feeds.wordpress.com/1.0/gocomments/benoitgirard.wordpress.com/651/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benoitgirard.wordpress.com/651/" /></a> <img alt="" border="0" height="1" src="https://pixel.wp.com/b.gif?host=benoitgirard.wordpress.com&amp;blog=12112851&amp;post=651&amp;subd=benoitgirard&amp;ref=&amp;feed=1" width="1" /> + 2016-01-25T22:16:01+00:00 + benoitgirard + + + The Servo Blog: These Weeks In Servo 48 + http://blog.servo.org/2016/01/25/twis-48/ + <p>In the <a href="https://github.com/pulls?page=1&amp;q=is%3Apr+is%3Amerged+closed%3A2016-01-11..2016-01-25+user%3Aservo">last two weeks</a>, we landed 130 PRs in the Servo organization’s repositories.</p> + + <p>After months of work by vlad and many others, Windows support <a href="https://github.com/servo/servo/pull/9385">landed</a>! Thanks to everyone who contributed fixes, tests, reviews, and even encouragement (or impatience!) to help us make this happen.</p> + + <h3 id="notable-additions">Notable Additions</h3> + + <ul> + <li>nikki <a href="https://github.com/servo/servo/pull/9391">added</a> tests and support for checking the Fetch redirect count</li> + <li>glennw <a href="https://github.com/servo/servo/pull/9359">implemented</a> horizontal scrolling with arrow keys</li> + <li>simon <a href="https://github.com/servo/servo/pull/9333">created</a> a script that parses all of the CSS properties parsed by Servo</li> + <li>ms2ger <a href="https://github.com/servo/servo/pull/9293">removed</a> the legacy reftest framework</li> + <li>fernando <a href="https://github.com/servo/crowbot/pull/33">made</a> crowbot able to rejoin IRC after it accidentally floods the channel</li> + <li>jack <a href="https://github.com/servo/saltfs/pull/193">added</a> testing the <code>geckolib</code> target to our CI</li> + <li>antrik <a href="https://github.com/servo/ipc-channel/pull/25">fixed</a> transfer corruption in ipc-channel on 32-bit</li> + <li>valentin <a href="https://github.com/servo/rust-url/pull/119">added</a> and simon <a href="https://github.com/servo/rust-url/pull/152">extended</a> IDNA support in rust-url, which is required for both web and Gecko compatibility</li> + </ul> + + <h3 id="new-contributors">New Contributors</h3> + + <ul> + <li><a href="https://github.com/Chandler">Chandler Abraham</a></li> + <li><a href="https://github.com/DarinM223">Darin Minamoto</a></li> + <li><a href="https://github.com/coder543">Josh Leverette</a></li> + <li><a href="https://github.com/shssoichiro">Joshua Holmer</a></li> + <li><a href="https://github.com/therealkbhat">Kishor Bhat</a></li> + <li><a href="https://github.com/MonsieurLanza">Lanza</a></li> + <li><a href="https://github.com/mattkuo">Matthew Kuo</a></li> + <li><a href="https://github.com/waterlink">Oleksii Fedorov</a></li> + <li><a href="https://github.com/stspyder">St.Spyder</a></li> + <li><a href="https://github.com/vvuk">Vladimir Vukicevic</a></li> + <li><a href="https://github.com/apopiak">apopiak</a></li> + <li><a href="https://github.com/askalski">askalski</a></li> + </ul> + + <h3 id="screenshot">Screenshot</h3> + + <p>Screencast of this post being upvoted on reddit… from Windows!</p> + + <p><img alt="(screencast)" src="http://blog.servo.org/images/upvote-windows.gif" title="Screencast of upvoting on Reddit on Windows." /></p> + + <h3 id="meetings">Meetings</h3> + + <p>We had a <a href="https://github.com/servo/servo/wiki/Meeting-2016-01-11">meeting</a> on some CI-related woes, documenting tags and mentoring, and dependencies for the style subsystem.</p> + 2016-01-25T20:30:00+00:00 + + + Air Mozilla: Mozilla Weekly Project Meeting, 25 Jan 2016 + https://air.mozilla.org/mozilla-weekly-project-meeting-20160125/ + <p> + <img alt="Mozilla Weekly Project Meeting" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/e9/4f/e94fbd7f8df916c75a60e63a85b9168c.png" width="160" /> + The Monday Project Meeting + </p> + 2016-01-25T19:00:00+00:00 + Air Mozilla + + + About:Community: Firefox 44 new contributors + http://blog.mozilla.org/community/2016/01/25/firefox-44-new-contributors/ + <p>With the release of Firefox 44, we are pleased to welcome the <strong>28 developers</strong> who contributed their first code change to Firefox in this release, <strong>23</strong> of whom were brand new volunteers! Please join us in thanking each of these diligent and enthusiastic individuals, and take a look at their contributions:</p> + <ul> + <li>mkm: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208124">1208124</a></li> + <li>Aditya Motwani: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1209087">1209087</a></li> + <li>Aniket Vyas: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1197309">1197309</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1197315">1197315</a></li> + <li>Chirath R: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1216941">1216941</a></li> + <li>Christiane Ruetten: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1209091">1209091</a></li> + <li>Fernando Campo: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1199815">1199815</a></li> + <li>Grisha Pushkov: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=994555">994555</a></li> + <li>Guang-De Lin: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1150305">1150305</a></li> + <li>Hassen ben tanfous: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1074804">1074804</a></li> + <li>Helen V. Holmes: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1205046">1205046</a></li> + <li>Henrik Tjäder: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1161698">1161698</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1209912">1209912</a></li> + <li>Johann Hofmann: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1192432">1192432</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1198405">1198405</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1204072">1204072</a></li> + <li>Kapeel Sable: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1212171">1212171</a></li> + <li>Manav Batra: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1202618">1202618</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1212280">1212280</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1214626">1214626</a></li> + <li>Manuel Casas Barrado: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1172662">1172662</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1193674">1193674</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1200693">1200693</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1203298">1203298</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1205684">1205684</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1212331">1212331</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1212338">1212338</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1214582">1214582</a></li> + <li>Matt Howell: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208626">1208626</a></li> + <li>Matthew Turnbull: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1213620">1213620</a></li> + <li>Olivier Yiptong: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1210936">1210936</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1210940">1210940</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1213078">1213078</a></li> + <li>Piotr Tworek: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1209446">1209446</a></li> + <li>Rocik: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1070719">1070719</a></li> + <li>Roland Sako: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1207733">1207733</a></li> + <li>Ronald Claveau: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1207266">1207266</a></li> + <li>Sanchit Nevgi: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1205181">1205181</a></li> + <li>Shaif Chowdhury: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1185606">1185606</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208121">1208121</a></li> + <li>Shubham Jain: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208470">1208470</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208705">1208705</a></li> + <li>Stanislas Daniel Claude Dolcini: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1147197">1147197</a></li> + <li>Stephanie Ouillon: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1178533">1178533</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1201626">1201626</a></li> + <li>Tim Huang: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1181489">1181489</a></li> + <li>simplyblue24: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1218204">1218204</a></li> + </ul> + 2016-01-25T16:21:33+00:00 + Josh Matthews + + + Doug Belshaw: 3 things to consider when designing a digital skills framework + http://literaci.es/digital-skills-curriculum + <p><img alt="Learning to credential" src="http://bryanmmathers.com/wp-content/uploads/2016/01/learning-to-credential.png" /></p> + + <p>The image above was created by <a href="http://bryanmmathers.com/learning-to-credential" rel="nofollow">Bryan Mathers</a> for our <a href="https://goo.gl/QqwUKP" rel="nofollow">presentation</a> at <a href="http://bettshow.com" rel="nofollow">BETT</a> last week. It shows the way that, in broad brushstrokes, learning design <em>should</em> happen. Before microcredentials such as <a href="http://openbadges.org" rel="nofollow">Open Badges</a> this was a difficult thing to do as both the credential and the assessment are usually given to educators. The flow tends to go <em>backwards</em> from credentials instead of forwards from what we want people to learn.</p> + + <p>But what if you really <em>were</em> starting from scratch? How could you design a digital skills framework that contains knowledge, skills, and behaviours worth learning? Having written my <a href="http://neverendingthesis.com" rel="nofollow">thesis</a> on digital literacies and led Mozilla’s <a href="https://teach.mozilla.org/activities/web-literacy/" rel="nofollow">Web Literacy Map</a> for a couple of years, I’ve got some suggestions. </p> + <h3> + <a class="head_anchor" href="http://literaci.es/feed#1-define-your-audience" name="1-define-your-audience" rel="nofollow"> </a>1. Define your audience</h3> + <p>One of the most important things to define is who your audience is for your digital skills framework. Is it for learners to read? Who are they? How old are they? Are you excluding anyone on purpose? Why / why not?</p> + + <p>You might want to do some research and work around <a href="https://en.wikipedia.org/wiki/Persona_(user_experience)" rel="nofollow">user personas</a> as part of a user-centred design approach. This ensures you’re designing for real people instead of figments of your imagination (or, worse still, in line with your prejudices).</p> + + <p>It’s also good practice to make the language used in the skills framework as precise as possible. Jargon is technical language used for the sake of it. There may be times when it’s impossible not to use a word (e.g. ’<a href="https://en.wikipedia.org/wiki/Meme" rel="nofollow">meme</a>’). If you do this then link to a definition or include a glossary. It’s also useful to check the ‘reading level’ of your framework and, if you really want a challenge, try using <a href="http://splasho.com/upgoer5/" rel="nofollow">Up-Goer Five</a> language.</p> + <h3> + <a class="head_anchor" href="http://literaci.es/feed#2-focus-on-verbs" name="2-focus-on-verbs" rel="nofollow"> </a>2. Focus on verbs</h3> + <p>It’s extremely easy, when creating a framework for learning, to fall into the 'knowledge trap’. Our aim when creating the raw materials from which someone can build a curriculum is to focus on <em>action</em>. Knowledge should make a difference in practice.</p> + + <p>One straightforward way to ensure that you’re focusing on action rather than head knowledge is to use <strong>verbs</strong> when constructing your digital skills framework. If you’re familiar with <a href="https://en.wikipedia.org/wiki/Bloom%27s_taxonomy" rel="nofollow">Bloom’s Taxonomy</a>, then you may find <a href="http://byrdseed.com/differentiator/" rel="nofollow">The Differentiator</a> useful. This pairs verbs with the various levels of Bloom’s.</p> + <h3> + <a class="head_anchor" href="http://literaci.es/feed#3-add-version-numbers" name="3-add-version-numbers" rel="nofollow"> </a>3. Add version numbers</h3> + <p>A framework needs to be a living, breathing thing. It should be subject to revision and updated often. For this reason, you should add version numbers to your documentation. Ideally, the latest version should be at a canonical URL and you should archive previous versions to static URLs. </p> + + <p>I would also advise releasing the first version of your framework not as 'version 1.0’ but as 'v0.1’. This shows that you’re willing for others to provide input, that there will be further versions, and that you know you haven’t got it right first time (and forevermore). </p> + + <hr /> + + <p><strong>Questions? Comments?</strong> Ask me on Twitter (<a href="http://twitter.com/dajbelshaw" rel="nofollow">@dajbelshaw</a>). I also consult around this kind of thing, so hit me up on <a href="http://literaci.es/hello@dynamicskillset.com" rel="nofollow">hello@dynamicskillset.com</a></p> + 2016-01-25T14:46:34+00:00 + + + Mozilla Fundraising: Why did you decide to donate today? + https://fundraising.mozilla.org/why-did-you-decide-to-donate-today/ + This year, we asked some of our donors why they decided to donate to our end of year fundraising campaign. The Survey The Audience The survey was shown to a random sample of donors whose browser language was set to … <a class="go" href="https://fundraising.mozilla.org/why-did-you-decide-to-donate-today/">Continue reading</a> + 2016-01-25T13:31:34+00:00 + Adam Lofting + + + Andy McKay: Robbie Burns + http://www.agmweb.ca/2016-01-25-robbie-burns/ + <p>Tonight is Robbie Burns night, in honour of that great Scottish poet. But tonight had me thinking about another night in my past.</p> + + <p>It was about 5 years ago, maybe less, I struggle to remember now. I was in the UK visiting family and my Dad was sick. Cancer and it's treatment is tough, you have good weeks, you have bad weeks and you have really fucking bad weeks. This was a good week and for some reason I was in the UK.</p> + + <p>Myself, my brother and my sister-in-law went down to see him that night. It was Robbie Burns night and that meant an excuse for haggis, really, truly terrible scotch, Scottish dancing and all that. There are many times when I look back at time with my Dad in those last few years. This was definitely one of those times. He was my Dad at his best, cracking jokes and having fun. Living life to the absolute fullest, while you still have that chance.</p> + + <p>We had a great night. That ended way too soon.</p> + + <p>Not long after that the cancer came back and that was that.</p> + + <p>But suddenly tonight, in a bar in Portland I had these memories of my Dad in a waistcoat cracking jokes and having fun on Robbie Burns night. No-one else in the bar seemed to know what night it was. You'd think Robbie Burns night might get a little bit more appreciation, but hey.</p> + + <p>In the many years I've been running this blog I've never written about my Dad passing away. Here's the first time. I miss him.</p> + + <p>Hey Robbie Burns? Thanks for making me remember that night.</p> + 2016-01-25T08:00:00+00:00 + + + This Week In Rust: This Week in Rust 115 + http://this-week-in-rust.org/blog/2016/01/25/this-week-in-rust-115/ + <p>Hello and welcome to another issue of <em>This Week in Rust</em>! + <a href="http://rust-lang.org">Rust</a> is a systems language pursuing the trifecta: + safety, concurrency, and speed. This is a weekly summary of its progress and + community. Want something mentioned? Tweet us at <a href="https://twitter.com/ThisWeekInRust">@ThisWeekInRust</a> or <a href="mailto:corey@octayn.net?subject=This%20Week%20in%20Rust%20Suggestion">send us an + email</a>! + Want to get involved? <a href="https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md">We love + contributions</a>.</p> + <p><em>This Week in Rust</em> is openly developed <a href="https://github.com/cmr/this-week-in-rust">on GitHub</a>. + If you find any errors in this week's issue, <a href="https://github.com/cmr/this-week-in-rust/pulls">please submit a PR</a>.</p> + <p>This week's edition was edited by: <a href="https://github.com/nasa42">nasa42</a>, <a href="https://github.com/brson">brson</a>, and <a href="https://github.com/llogiq">llogiq</a>.</p> + <h3>Updates from Rust Community</h3> + <h4>News &amp; Blog Posts</h4> + <ul> + <li><img alt="balloon" class="emoji" src="https://cdn.discourse.org/business/images/emoji/emoji_one/balloon.png?v=0" title=":balloon:" /><img alt="tada" class="emoji" src="https://cdn.discourse.org/business/images/emoji/emoji_one/tada.png?v=0" title=":tada:" /> <a href="http://blog.rust-lang.org/2016/01/21/Rust-1.6.html">Announcing Rust 1.6</a>. <img alt="tada" class="emoji" src="https://cdn.discourse.org/business/images/emoji/emoji_one/tada.png?v=0" title=":tada:" /><img alt="balloon" class="emoji" src="https://cdn.discourse.org/business/images/emoji/emoji_one/balloon.png?v=0" title=":balloon:" /></li> + <li><a href="http://www.poumeyrol.fr/2016/01/15/Awkward-zone/">Rust, BigData and my laptop</a>.</li> + <li>[pdf]<a href="https://cdn.rawgit.com/Gankro/thesis/master/thesis.pdf">You can't spell trust without Rust</a>. Analysis of the semantics and expressiveness of Rust’s type system.</li> + <li><a href="http://www.ncameron.org/blog/libmacro/">Libmacro - an API for procedural macros to interact with the compiler</a>.</li> + <li><a href="http://www.jonathanturner.org/2016/01/rust-and-blub-paradox.html">Rust and the Blub Paradox</a>. And the <a href="http://www.jonathanturner.org/2016/01/rethinking-the-blub-paradox.html">follow-up</a>.</li> + <li>[video] <a href="https://www.youtube.com/channel/UC4mpLlHn0FOekNg05yCnkzQ/videos">Ferris Makes Emulators</a>. Live stream of Ferris developing a N64 emulator in Rust (also on <a href="http://www.twitch.tv/ferrisstreamsstuff/profile">Twitch</a>).</li> + </ul> + <h4>Notable New Crates &amp; Project Updates</h4> + <ul> + <li><a href="http://areweconcurrentyet.com/">Are we concurrent yet</a>?</li> + <li><a href="https://github.com/gfx-rs/gfx">GFX</a> epic rewrite for the Pipeline State Objects paradigm has <a href="https://github.com/gfx-rs/gfx/pull/828">landed</a>, described <a href="http://gfx-rs.github.io/2016/01/22/pso.html">on the blog</a>.</li> + <li><a href="https://github.com/mcarton/rust-herbie-lint">Herbie</a>. A rustc plugin to check for numerical instability.</li> + <li><a href="http://blog.piston.rs/2016/01/23/dynamo/">Dynamo</a>. A rusty dynamically typed scripting language.</li> + <li><a href="https://github.com/whitequark/rust-vnc">rust-vnc</a>. An implementation of VNC protocol, client state machine and a client.</li> + </ul> + <h3>Updates from Rust Core</h3> + <p>129 pull requests were <a href="https://github.com/issues?q=is%3Apr+org%3Arust-lang+is%3Amerged+merged%3A2016-01-18..2016-01-25">merged in the last week</a>.</p> + <p>See the <a href="https://internals.rust-lang.org/t/triage-digest-mon-jan-25-2016/3111">triage digest</a> and <a href="https://internals.rust-lang.org/t/subteam-reports-2016-01-22/3106">subteam reports</a> for more details.</p> + <h4>Notable changes</h4> + <ul> + <li><a href="https://github.com/rust-lang/rust/pull/30872">Implement RFC 1252 expanding the OpenOptions structure</a>.</li> + <li><a href="https://github.com/rust-lang/book/pull/58">Book: First draft of 'ownership'</a>.</li> + <li><a href="https://github.com/rust-lang/cargo/pull/2205">Cargo: Add convenience syntax to install current crate</a>.</li> + <li><a href="https://github.com/rust-lang/cargo/pull/2196">Cargo: Introduce cargo metadata subcommand</a>.</li> + <li><a href="https://github.com/rust-lang/cargo/pull/2081">Cargo: Implement <code>cargo init</code></a>.</li> + <li><a href="https://github.com/rust-lang/cargo/pull/2270">Cargo: Emit a warning when manifest specifies empty dependency constraints</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/29520">Change name when outputting staticlibs on Windows</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30998">Make <code>btree_set::{IntoIter, Iter, Range}</code> covariant</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30917">Avoid bounds checking at <code>slice::binary_search</code></a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30894"><code>std::sync::mpsc</code>: Add <code>fmt::Debug</code> stubs</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30882">resolve: Fix variant namespacing</a>.</li> + </ul> + <h4>New Contributors</h4> + <ul> + <li>Adrian Heine</li> + <li>Andrea Bedini</li> + <li>Guillaume Bonnet</li> + <li>Kamal Marhubi</li> + <li>Keith Yeung</li> + <li>Marc Bowes</li> + <li>Martin</li> + <li>mopp</li> + <li>Olaf Buddenhagen</li> + <li>Paul Dicker</li> + <li>Peter Kolloch</li> + <li>Stephen (Ziyun) Li</li> + </ul> + <h4>Approved RFCs</h4> + <p>Changes to Rust follow the Rust <a href="https://github.com/rust-lang/rfcs#rust-rfcs">RFC (request for comments) + process</a>. These + are the RFCs that were approved for implementation this week:</p> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/1462">Amendment to RFC 550: Add <code>[</code> to the FOLLOW(ty) in macro future-proofing rules</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1320">Amendment to RFC 1192: Amend <code>RangeInclusive</code> to use an enum</a>.</li> + </ul> + <h4>Final Comment Period</h4> + <p>Every week <a href="https://rust-lang.org/team.html">the team</a> announces the + 'final comment period' for RFCs and key PRs which are reaching a + decision. Express your opinions now. <a href="https://github.com/rust-lang/rfcs/labels/final-comment-period">This week's FCPs</a> are:</p> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/243">Trait-based exception handling</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1361">Improve Cargo target-specific dependencies</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1129">Add a <code>IndexAssign</code> trait that allows overloading "indexed assignment" expressions like <code>a[b] = c</code></a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1196">Allow eliding more type parameters</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1296">Add an <code>alias</code> attribute to <code>#[link]</code> and <code>-l</code></a>.</li> + </ul> + <h4>New RFCs</h4> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/1477">Add compiler support for generic atomic operations</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1478">Translate undefined generic intrinsics to an LLVM <code>unreachable</code> and a lint</a>.</li> + </ul> + <h3>Upcoming Events</h3> + <ul> + <li><a href="http://www.meetup.com/opentechschool-berlin/">1/27. OpenTechSchool Berlin: Rust Hack and Learn</a>.</li> + <li><a href="http://www.meetup.com/Tokyo-Rust-Meetup/events/227871840/">1/28. Tokyo Rust Meetup #2</a>.</li> + <li><a href="http://www.meetup.com/Rust-Berlin/events/227321071/">2/3. Rust Berlin: Leaf and Collenchyma</a>.</li> + <li><a href="http://www.meetup.com/de/Rust-Cologne-Bonn/events/227534456/">2/3. Rust Meetup in Cologne / Germany</a>.</li> + <li><a href="https://www.eventbrite.com/e/mozilla-rust-seattle-meetup-tickets-12222326307?aff=erelexporg">2/8. Seattle Rust Meetup</a>.</li> + <li><a href="http://www.meetup.com/de-DE/Rust-Rhein-Main/events/228170051/">2/12. Embedded Rust Workshop Frankfurt</a>.</li> + </ul> + <p>If you are running a Rust event please add it to the <a href="https://www.google.com/calendar/embed?src=apd9vmbc22egenmtu5l6c5jbfc%40group.calendar.google.com">calendar</a> to get + it mentioned here. Email <a href="mailto:erick.tryzelaar@gmail.com">Erick Tryzelaar</a> or <a href="mailto:banderson@mozilla.com">Brian + Anderson</a> for access.</p> + <h3>fn work(on: RustProject) -&gt; Money</h3> + <ul> + <li><a href="http://maidsafe.net/rust_engineer.html">Rust Engineer</a> at MaidSafe.</li> + <li><a href="https://careers.mozilla.org/en-US/position/ozy21fwU">Research Engineer - Servo</a> at Mozilla.</li> + <li><a href="https://careers.mozilla.org/en-US/position/o0H41fww">Senior Research Engineer - Rust</a> at Mozilla.</li> + <li><a href="http://plv.mpi-sws.org/rustbelt/">PhD and postdoc positions</a> at MPI-SWS.</li> + </ul> + <p><em>Tweet us at <a href="https://twitter.com/ThisWeekInRust">@ThisWeekInRust</a> to get your job offers listed here!</em></p> + <h3>Crate of the Week</h3> + <p>This week's Crate of the Week is <a href="https://github.com/phildawes/racer">racer</a> which powers code completion in all Rust development environments.</p> + <p>Thanks to <a href="https://users.rust-lang.org/users/stebalien">Steven Allen</a> for the suggestion.</p> + <p><a href="https://users.rust-lang.org/t/crate-of-the-week/2704">Submit your suggestions for next week</a>!</p> + <h3>Quote of the Week</h3> + <blockquote> + <p>Memory errors are fundamentally state errors, and Rust's move semantics, borrowing, and aliasing XOR mutating help enormously for me to reason about how my program changes state as it executes, to avoid accidental shared state and side effects at a distance. Rust more than any other language I know enables me to do compiler driven design. And internalizing its rules has helped me design better systems, even in other languages.</p> + </blockquote> + <p>— <a href="https://www.reddit.com/r/rust/comments/4275gz/rust_and_the_blub_paradox/cz8akv9">desiringmachines on /r/rust</a>.</p> + <p>Thanks to <a href="https://users.rust-lang.org/users/dikaiosune">dikaiosune</a> for the suggestion.</p> + <p><a href="http://users.rust-lang.org/t/twir-quote-of-the-week/328">Submit your quotes for next week</a>!</p> + 2016-01-25T05:00:00+00:00 + Corey Richardson + + + Cameron Kaiser: 38.6.0 available + http://tenfourfox.blogspot.com/2016/01/3860-available.html + TenFourFox 38.6.0 is available for testing (<a href="https://sourceforge.net/projects/tenfourfox/files/38.6.0/">downloads</a>, <a href="https://github.com/classilla/tenfourfox/wiki/Hashes">hashes</a>, <a href="https://github.com/classilla/tenfourfox/wiki/ZZReleaseNotes3860">release notes</a>). I'm sorry it's been so quiet around here; I'm in the middle of a backbreaking Master's course, my last one before I'm finally done with the lousy thing, and I haven't had any time to start on 45 so far. 38.6 does have some other fixes in it, though: I think I found the last place where bookmark backups were being mistakenly saved in LZ4 based on Chris Trusch's report, and the problematic fonts on the iCloud login page are now blacklisted, so you should be able to login again. I can't do much more testing than that, however, since I don't use iCloud personally, so other lapses in font functionality will require the font URL and I'll add them to the blacklist in 38.7. The browser will go live Monday Pacific time as usual. (The temporary workaround is to set <tt>gfx.downloadable_fonts.enabled</tt> to <tt>false</tt>, and switch the setting back when you don't need it anymore.) <p>Speaking of, downloadable fonts were exactly the same problem on the Sun Ultra-3 laptop I've been refurbishing; Oracle still provides a free Solaris 10 build of 38ESR, but it crashes on web fonts for reasons I have yet to diagnose, so I just have them turned off. Yes, it really is a SPARC laptop, a rebranded Tadpole Viper, and I think the fastest one ever made in this form factor (a 1.2GHz UltraSPARC IIIi). It's pretty much what I expected the PowerBook G5 would have been -- hot, overthrottled and power-hungry -- but Tadpole actually built the thing and it's not a disaster, relatively speaking. There's no JIT in this Firefox build, the brand new battery gets only 70 minutes of runtime even with the CPU clock-skewed to hell, it stands a very good chance of rendering me sterile and/or medium rare if I actually use it in my lap and it had at least one sudden overtemp shutdown and pooped all over the filesystem, but between Firefox, Star Office and <tt>pkgsrc</tt> I can actually use it. More on that for laughs in a future post. </p><p>It has been pointed out to me that Leopard Webkit has not made an update in over three months, so hopefully Tobias is still doing okay with his port.</p> + 2016-01-23T06:02:00+00:00 + ClassicHasClass + + + Mozilla Privacy Blog: Addressing the Chilling Effect of Patent Damages + https://blog.mozilla.org/netpolicy/2016/01/22/addressing-the-chilling-effect-of-patent-damages/ + <p>Last year, we unveiled the <a href="https://www.mozilla.org/about/patents/license/">Mozilla Open Software Patent License</a> as part of our <a href="https://www.mozilla.org/about/patents/">Initiative</a> to help limit the negative impacts that patents have on open source software. While those were an important first step for us, we continue to do more. This past Wednesday, Mozilla joined several other tech and software companies in filing an <a href="https://blog.mozilla.org/netpolicy/files/2016/01/Halo-Stryker-Internet-Companies-brief.pdf">amicus brief</a> with the Supreme Court of the United States in the <i>Halo</i> and <i>Stryker</i> cases.</p> + <p>In the brief, we urge the Court to limit the availability of treble damages. Treble damages are significant because they greatly increase the amount of money owed if a defendant is found to “willfully infringe” a patent. As a result, many open source projects and technology companies will refuse to look into or engage in discussions about patents, in order to avoid even a remote possibility of willful infringement. This makes it very hard to address the chilling effects that patents can have on open source software development, open innovation, and collaborative efforts.</p> + <p>We hope that our brief will help the Court see how this legal standard has affected technology companies and persuade the Court to limit treble damages.</p> + 2016-01-23T00:17:34+00:00 + Elvin Lee + + + Mozilla Addons Blog: Add-on Signing Update + https://blog.mozilla.org/addons/2016/01/22/add-on-signing-update/ + <p>In Firefox 43, we made it a default requirement for add-ons to be signed. This requirement can be disabled by <a href="https://wiki.mozilla.org/Addons/Extension_Signing#FAQ">toggling a preference</a> that was originally scheduled to be removed in Firefox 44 for release and beta versions (this preference will continue to be available in the Nightly, Developer, and ESR Editions of Firefox for the foreseeable future). </p> + <p>We are delaying the removal of this preference to Firefox 46 for a couple of reasons: We’re adding a feature in Firefox 45 that allows <a href="https://blog.mozilla.org/addons/2015/12/23/loading-temporary-add-ons/">temporarily loading unsigned restartless add-ons</a> in release, which will allow developers of those add-ons to use Firefox for testing, and we’d like this option to be available when we remove the preference. We also want to ensure that developers have adequate time to finish the transition to signed add-ons. </p> + <p>The <a href="https://wiki.mozilla.org/Addons/Extension_Signing#Timeline">updated timeline</a> is available on the signing wiki, and you can look up <a href="https://wiki.mozilla.org/RapidRelease/Calendar">release dates for Firefox versions</a> on the releases wiki. Signing will be mandatory in the beta and release versions of Firefox from 46 onwards, at which point unbranded builds based on beta and release will be provided for testing.</p> + 2016-01-22T22:40:59+00:00 + Kev Needham + + + Chris Cooper: RelEng & RelOps Weekly Highlights - January 22, 2016 + http://coopcoopbware.tumblr.com/post/137832199980 + <p></p><figure class="alignright"><a href="https://www.flickr.com/photos/proud2bcan8dn/1150097247/in/faves-19934681@N00/" target="_blank" title="wine-and-pies"><img alt="wine-and-pies" src="https://farm2.staticflickr.com/1216/1150097247_2f11cb4c2d_z.jpg?zz=1" width="200px" /></a>Releng: drinkin’ wine and makin’ pies.</figure>It’s encouraging to see more progress this week on both the build/release promotion and TaskCluster migration fronts, our two major efforts for this quarter.<p></p> + + <p><b>Modernize infrastructure:</b></p> + <p>In a continuing effort to enable faster, more reliable, and more easily-run tests for TaskCluster components, Dustin landed support for an in-memory, credential-free mock of Azure Table Storage in the <a href="https://www.npmjs.com/package/azure-entities" target="_blank">azure-entities</a> package. Together with the fake mock support he added to <a href="https://github.com/djmitche/taskcluster-lib-testing" target="_blank">taskcluster-lib-testing</a>, this allows tests for components like taskcluster-hooks to run without network access and without the need for any credentials, substantially decreasing the barrier to external contributions.</p> + + <p>All release promotion tasks are now signed by default. Thanks to Rail for his work here to help improve verifiability and chain-of-custody in our upcoming release process. (<a href="https://bugzil.la/1239682" target="_blank">https://bugzil.la/1239682</a>) + Beetmover has been spotted in the wild! Jordan has been working on this new tool as part of our release promotion project. Beetmover helps move build artifacts from one place to another (generally between S3 buckets these days), but can also be extended to perform validation actions inline, e.g. checksums and anti-virus. (<a href="https://bugzil.la/1225899" target="_blank">https://bugzil.la/1225899</a>)</p> + + <p>Dustin configured the “desktop-test” and “desktop-build” docker images to build automatically on push. That means that you can modify the Dockerfile under `testing/docker`, push to try, and have the try job run in the resulting image, all without pushing any images. This should enable much quicker iteration on tweaks to the docker images. Note, however, that updates to the base OS images (ubuntu1204-build and centos6-build) still require manual pushes.</p> + + <p>Mark landed Puppet code for base windows 10 support including secrets and ssh keys management.</p> + + <p><b>Improve CI pipeline:</b></p> + + <p>Vlad and Amy repurposed 10 Windows XP machines as Windows 7 to improve the wait times in that test pool (<a href="https://bugzil.la/1239785" target="_blank">https://bugzil.la/1239785</a>) + Armen and Joel have been working on porting the Gecko tests to run under TaskCluster, and have narrowed the failures down to the single digits. This puts us on-track to enable Linux debug builds and tests in TaskCluster as the canonical build/test process.</p> + + <p><b>Release:</b></p> + + <p>Ben finished up work on enhanced Release Blob validation in Balrog (<a href="https://bugzil.la/703040" target="_blank">https://bugzil.la/703040</a>), which makes it much more difficult to enter bad data into our update server.</p> + + <p>You may recall Mihai, our former intern who <a href="http://coopcoopbware.tumblr.com/post/133490693210/welcome-back-mihai" target="_blank">we just hired back in November</a>. Shortly after joining the team, he jumped into the <a href="https://wiki.mozilla.org/ReleaseEngineering/Releaseduty" target="_blank">releaseduty</a> rotation to provide much-needed extra bandwidth. The learning curve here is steep, but over the course of the Firefox 44 release cycle, he’s taken on more and more responsibility. He’s even volunteered to do releaseduty for the Firefox 45 release cycle as well. Perhaps the most impressive thing is that he’s also taken the time to update (or write) the releaseduty docs so that the next person who joins the rotation will be that much further ahead of the game. Thanks for your hard work here, Mihai!</p> + + <p><b>Operational:</b></p> + + <p>Hal did some cleanup work to remove unused mozharness configs and directories from the build mercurial repos. These resources have long-since moved into the main mozilla-central tree. Hopefully this will make it easier for contributors to find the canonical copy! (<a href="https://bugzil.la/1239003" target="_blank">https://bugzil.la/1239003</a>)</p> + + <p><b>Hiring:</b></p> + + <p>We’re still hiring for a full-time <a href="https://careers.mozilla.org/position/oi8b2fwn" target="_blank">Build &amp; Release Engineer</a>, and we are still accepting applications for <a href="https://careers.mozilla.org/position/ofA51fwF" target="_blank">interns for 2016</a>. Come join us!</p> + + <p>Well, I don’t know about you, but all that hard work makes me hungry for pie. See you next week!</p> + 2016-01-22T20:49:38+00:00 + + + Air Mozilla: Foundation Demos January 22 2016 + https://air.mozilla.org/foundation-demos-january-22-2016/ + <p> + <img alt="Foundation Demos January 22 2016" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/1c/a0/1ca0b9b2609cdd4e6e3577a8c3df8cfc.jpg" width="160" /> + Mozilla Foundation Demos January 22 2016 + </p> + 2016-01-22T18:00:00+00:00 + Air Mozilla + + + Support.Mozilla.Org: What’s up with SUMO – 22nd January + https://blog.mozilla.org/sumo/2016/01/22/whats-up-with-sumo-22nd-january/ + <p><strong>Hello, SUMO Nation!</strong></p> + <p><a href="http://blog.mozilla.org/sumo/files/2016/01/sumo_logo.png"><img alt="sumo_logo" class="aligncenter size-full wp-image-3670" height="387" src="http://blog.mozilla.org/sumo/files/2016/01/sumo_logo.png" width="383" /></a>The third week of the new year is already behind us. Time flies when you’re not paying attention… What are you going to do this weekend? Let us know in the comments, if you feel like sharing :-) I hope to be in the mountains, getting some fresh (bracing) air, and enjoying nature.</p> + <h3><strong class="username">Welcome, new contributors!<br /> + </strong></h3> + <ul> + <li class="author"> + <div class="author"><a class="username" href="https://support.mozilla.org/user/johnmwc2" target="_blank">johnmwc2</a></div> + </li> + <li class="author"><a class="author-name" href="https://support.mozilla.org/user/myanesp" target="_blank">myanesp</a></li> + <li class="author"><a class="author-name" href="https://support.mozilla.org/user/Harish.A" target="_blank">Harish.A</a></li> + <li class="author"><a class="author-name" href="https://support.mozilla.org/user/hoolibob" target="_blank">hoolibob</a></li> + <li class="author"><a class="author-name" href="https://support.mozilla.org/user/Meteoro890" target="_blank">Meteoro890</a></li> + </ul> + <div class="author">If you just joined us, don’t hesitate – come over and <a href="https://support.mozilla.org/forums/buddies" target="_blank">say “hi” in the forums!</a></div> + <div class="author"></div> + <div class="author"> + <h3><strong>Contributors of the week<br /> + </strong></h3> + <ul> + <li><span class="author-a-z74z1rz89z69z76zbz72zz69zz67z9z82zniz71z"><a href="https://support.mozilla.org/user/safwan.rahman" target="_blank">Safwan</a> for his work on the <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=619284" target="_blank">draft feature for l10n / KB editing</a> – rock on!</span></li> + <li><a href="https://support.mozilla.org/user/artist" target="_blank">Artist</a> and <a href="https://support.mozilla.org/user/pollti" target="_blank">Pollti</a> for their the work on updating important articles for Focus with limited time – woot!</li> + </ul> + <div class="" id="magicdomid64"> + <p><strong><span style="text-decoration: underline;">We salute you!</span></strong></p> + </div> + <div class="author">Don’t forget that if you are new to SUMO and someone helped you get started in a nice way you can <a href="https://support.mozilla.org/forums/buddies/711364?last=65670" target="_blank">nominate them for the Buddy of the Month!</a></div> + <div class="author"></div> + </div> + <h3><strong>Most recent SUMO Community meeting</strong></h3> + <ul> + <li><a href="https://public.etherpad-mozilla.org/p/sumo-2016-01-18" target="_blank">You can read the notes here</a> (most of the staff members were AFK due to MLK Day in the US) and see the video on our <a href="https://www.youtube.com/channel/UCaiposaIhA7HfMqH2NIciyA/videos" target="_blank">YouTube channel</a> and <a href="https://air.mozilla.org/search/?q=sumo" target="_blank">at AirMozilla</a>.<del> </del><del><br /> + </del></li> + <li><strong>IMPORTANT: We are considering changing the way the meetings work. Help us figure out what’s best for you – join the discussion on the forums in this thread: <a href="https://support.mozilla.org/en-US/forums/contributors/711752?last=67873">(Monday) Community Meetings in 2016</a>.</strong></li> + </ul> + <h3><strong>The next SUMO Community meeting… </strong></h3> + <ul> + <li style="text-align: left;">is happening on <a href="https://public.etherpad-mozilla.org/p/sumo-2016-01-25" target="_blank">Monday the 25th – join us</a>!</li> + <li style="text-align: left;"><strong>Reminder: if you want to add a discussion topic to the upcoming meeting agenda:</strong> + <ul> + <li style="text-align: left;">Start a thread in the <a href="https://support.mozilla.org/forums/contributors" target="_blank">Community Forums</a>, so that everyone in the community can see what will be discussed and voice their opinion here before Monday (this will make it easier to have an efficient meeting).</li> + <li style="text-align: left;">Please do so as soon as you can before the meeting, so that people have time to read, think, and reply (and also add it to the agenda).</li> + <li style="text-align: left;">If you can, please attend the meeting in person (or via IRC), so we can follow up on your discussion topic during the meeting with your feedback.</li> + </ul> + </li> + </ul> + <h3><strong class="author-g-ivsra51ph44x461i">Developers</strong></h3> + <ul> + <li><a href="http://edwin.mozilla.io/t/sumo" target="_blank">You can see the current state of the backlog our developers are working on here</a>.</li> + <li><a href="https://public.etherpad-mozilla.org/p/sumo-p-2016-01-21" target="_blank">The latest SUMO Platform meeting notes can be found here</a>.</li> + <li>Interested in learning how Kitsune (the engine behind SUMO) works? <a href="http://kitsune.readthedocs.org/" target="_blank">Read more about it here</a> and <a href="https://github.com/mozilla/kitsune/" target="_blank">fork it on GitHub</a>!</li> + <li>We have a new link for promoting contributions to Kitsune’s code. Please use <strong>http://mzl.la/SUMOdev</strong> whenever you want to show interested people to see what Kitsune is all about – thanks!</li> + </ul> + <p><a href="http://blog.mozilla.org/sumo/files/2016/01/mission_developers.png"><img alt="mission_developers" class="aligncenter size-full wp-image-3668" height="406" src="http://blog.mozilla.org/sumo/files/2016/01/mission_developers.png" width="437" /></a></p> + <h3><strong>Social</strong></h3> + <ul> + <li>Next week, there will be a kick-off meeting for the rethinking of Mozilla’s general support strategy through social networks. <a href="https://support.mozilla.org/user/Madasan" target="_blank">Are you interested in taking part? Let Madalina know!</a></li> + </ul> + <h3><strong>Community</strong></h3> + <ul> + <li>The NDA process and list is currently being reworked under the leadership of the Participation Team. Expect to see messaging on this subject in the coming days.</li> + <li> + <div class="title"><strong><a href="https://support.mozilla.org/forums/contributors/711729?last=67763">IMPORTANT: take a look at our Work Week Summary for Mozlando. We need your feedback for a few things there.</a></strong></div> + </li> + <li>Are you going to FOSDEM next week? Would you like to have a small SUMO-meetup? <a href="https://support.mozilla.org/user/vesper" target="_blank">Let me know</a>!</li> + <li> + <div class="title">Ongoing reminder: if you think you can benefit from getting <a href="https://wiki.mozilla.org/Community_Hardware" target="_blank">a second-hand device</a> to help you with contributing to SUMO, you know where to find us.</div> + </li> + </ul> + <p><a href="http://blog.mozilla.org/sumo/files/2016/01/hero_support.png"><img alt="hero_support" class="aligncenter size-full wp-image-3669" height="383" src="http://blog.mozilla.org/sumo/files/2016/01/hero_support.png" width="367" /></a></p> + <div class=""> + <div class="" id="magicdomid83"> + <h3><strong class="author-g-ivsra51ph44x461i">Localization</strong></h3> + </div> + </div> + <div class="" id="magicdomid95"> + <ul> + <li>You can <a href="https://support.mozilla.org/forums/l10n-forum/711781" target="_blank">read more about the recent “infrequent contributor survey” in this thread</a>. In short: the good news is that we’re doing a good job at making it easy enough for everyone to contribute. The bad news – we’re not doing enough to make sure they know what to do after their first contribution. Expect some changes in the messaging for first-time contributors to the KB :-)</li> + <li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1012384" target="_blank">Our magical l10n dashboards keep being magical</a> ;-) Thank you for your patience. If you see any discrepancies between the number of localized articles and the percentage shown in the bar, file a bug!</li> + </ul> + </div> + <div class="" id="magicdomid75"> + <h3><strong>Firefox<br /> + </strong></h3> + <ul> + <li><strong>for Android</strong> + <ul> + <li><a href="https://support.mozilla.org/forums/contributors/711712?last=67653">Learn more about Firefox 43 for Android from the official thread with release notes / issues / discussions</a>.</li> + <li> + <div class="title"><a href="https://support.mozilla.org/forums/contributors/711718?last=67822">Reminder: Roland is sharing Firefox 44 for Android release notes / issues / discussions</a> with everyone in the forum.</div> + </li> + </ul> + </li> + </ul> + <ul> + <li><strong>for Desktop</strong> + <ul> + <li>Heads up – next week should be release week! Keep your eyes peeled ;-)</li> + </ul> + </li> + </ul> + <ul> + <li><strong>for iOS</strong> + <div class="" id="magicdomid85"> + <ul class="list-bullet1"> + <li><span class="author-a-107uz69zz81zhz78z0z78zz84zz66zz76zz82zz77zj">No news from the world of Firefox for iOS this week.</span></li> + </ul> + </div> + </li> + </ul> + </div> + <p>Thank you for reading all the way down here… More to come next week! You know where to find us, so see you around – keep rocking the open &amp; helpful web!</p> + 2016-01-22T17:43:56+00:00 + Michał + + + Air Mozilla: Bay Area Rust Meetup January 2016 + https://air.mozilla.org/bay-area-rust-meetup-january-2016/ + <p> + <img alt="Bay Area Rust Meetup January 2016" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/87/4f/874f4abef76f55213d50e43d6417ed99.png" width="160" /> + Bay Area Rust meetup for January 2016. Topics TBD. + </p> + 2016-01-22T03:00:00+00:00 + Air Mozilla + + + Mitchell Baker: Honored to Participate in New UN Panel on Women’s Economic Empowerment + http://blog.lizardwrangler.com/2016/01/22/honored-to-participate-in-new-un-panel-on-womens-economic-empowerment/ + Women’s economic empowerment is necessary for many reasons. It is necessary to bring health, safety and opportunity to half of humanity. It is necessary to bring investment and health to families and communities. It is necessary to unlock economic growth and build more stable societies. Today the UN Secretary General Ban Ki-moon launched the first […] + 2016-01-22T02:45:58+00:00 + Mitchell Baker + + + Mozilla WebDev Community: Beer and Tell – January 2016 + https://blog.mozilla.org/webdev/2016/01/21/beer-and-tell-january-2016/ + <p>Once a month, web developers from across the Mozilla Project get together to talk about our side projects and drink, an occurrence we like to call “Beer and Tell”.</p> + <p>There’s a <a href="https://wiki.mozilla.org/Webdev/Beer_And_Tell/January_2016">wiki page available</a> with a list of the presenters, as well as links to their presentation materials. There’s also a <a href="https://air.mozilla.org/webdev-beer-and-tell-january-2016/">recording available</a> courtesy of Air Mozilla.</p> + <h3>shobson: CSS-Only Disco Ball</h3> + <p>First up was <a href="https://mozillians.org/en-US/u/stephaniehobson/">shobson</a> with a cool demo of an <a href="http://codepen.io/stephaniehobson/pen/ZGZBVW?editors=110">animated disco ball made entirely with CSS</a>. The demo uses a repeated radial gradient for the background, and linear gradients plus a border radius for the disco ball itself. The demo was made for use in shobson’s <a href="https://www.youtube.com/watch?v=7poVasAQjos">WordCamp talk</a> about debugging CSS. A <a href="http://stephaniehobson.ca/wordpress/2015/08/15/how-to-debug-css/">blog post</a> with notes from the talk is available as well.</p> + <h3>craigcook: Proton – A CSS Framework for Prototyping</h3> + <p>Next was <a href="https://mozillians.org/en-US/u/craigcook/">craigcook</a>, who presented <a href="http://craigcook.github.io/proton/">Proton</a>. It’s a CSS framework that is intentionally ugly to encourage use for prototypes only. Unlike other CSS frameworks, the temptation to reuse the classes from the framework in your final page doesn’t occur, which helps avoid the presentational classes that plague sites built using a framework normally.</p> + <p>Proton’s website includes an overview of the layout and components provided, as well as examples of prototypes made using the framework.</p> + <hr /> + <p>If you’re interested in attending the next Beer and Tell, sign up for the <a href="https://lists.mozilla.org/listinfo/dev-webdev">dev-webdev@lists.mozilla.org mailing list</a>. An email is sent out a week beforehand with connection details. You could even add yourself to the wiki and show off your side-project!</p> + <p>See you next month!</p> + 2016-01-21T18:56:46+00:00 + Michael Kelly + + + About:Community: This Month at Mozilla + http://blog.mozilla.org/community/2016/01/21/this-month-at-mozilla/ + <p style="text-align: center;"><em>A lot of exciting things are happening with Participation at Mozilla this month. Here’s a quick round-up of some of the things that are going on!</em></p> + <h3><b>Mozillians Profiles Got a Facelift: </b></h3> + <p>Since the start of this year, the Participation Infrastructure team has had a renewed focus on making mozillians.org a modern community directory to meet Mozilla’s growing needs.</p> + <p>Their first target for 2016 was to improve the UX on the profile edit interface.</p> + <p><a href="https://blog.mozilla.org/community/files/2016/01/new-profile-768x548.png"><img alt="new-profile-768x548" class="aligncenter wp-image-2288 size-large" height="428" src="https://blog.mozilla.org/community/files/2016/01/new-profile-768x548-600x428.png" width="600" /></a><br /> + ”We chose it due to relatively self-contained nature of it, and cause many people were not happy with the current UX. After research of existing tools and applying latest best practices, we designed, coded and deployed a new profile edit interface (which by the way is renamed to Settings now) that we are happy to deliver to all Mozillians.”</p> + <p>Read the full blog <a href="http://pierros.papadeas.gr/?p=447">here</a>!</p> + <h3><b>There are New Ways to Bring Your Design Skills to Mozilla: </b></h3> + <p>Are you a passionate designer looking to contribute to Mozilla? You’ll be happy to hear there is a new way to contribute to the many design projects around Mozilla! Submit issues, find collaborators, and work on open source projects by getting involved!</p> + <ul> + <li>You can check out the projects looking for help, or submit your own on the <a href="https://github.com/mozilla/Community-Design/issues">GitHub Repo</a>.</li> + <li><a href="https://docs.google.com/a/mozilla.com/forms/d/1Tw3Mw_CMiqcIQrJF7TB1yIETGYec__NiVhaSz0CAaE8/viewform">Sign-up to the mailing list</a> to be added as a contributor to the Repo, added to the regular meeting list, and to get emails about GitHub trainings and more!</li> + <li>And read<a href="http://elioqoshi.me/en/2016/01/mozilla-community-design-kickoff/"> a blogpost</a> about the project and its first meeting.</li> + </ul> + <p>Learn more <a href="https://discourse.mozilla-community.org/c/community-design">here</a>.</p> + <h3><b>136 Volunteers Are Going to Singapore: </b></h3> + <p>This weekend 136 participation leaders from all over the world are<a href="https://twitter.com/thephoenixbird/status/690181985222926336"> heading to Singapore</a> to undergo two days of<a href="https://wiki.mozilla.org/Participation/Global_Gatherings_2015"> leadership training</a> to develop the skills, knowledge and attitude to lead Participation in 2016.</p> + <div class="wp-caption aligncenter" id="attachment_2289" style="width: 609px;"><a href="https://blog.mozilla.org/community/files/2016/01/CZQE241WIAA6R2J.jpg"><img alt="Photo credit @thephoenixbird on Twitter" class="wp-image-2289 size-full" height="337" src="https://blog.mozilla.org/community/files/2016/01/CZQE241WIAA6R2J.jpg" width="599" /></a><p class="wp-caption-text">Photo credit @<a href="https://twitter.com/thephoenixbird/status/690181985222926336" target="_blank">thephoenixbird</a> on Twitter</p></div> + <p>If you know someone attending don’t forget to share your questions and goals with them, and follow along over the weekend by watching the hashtag<a href="https://twitter.com/search?q=%23mozsummit"> #MozSummit</a>.</p> + <p>Stay tuned after the event for a debrief of the weekend!</p> + <h3><b>Friday’s Plenary from Mozlando is now public on Air Mozilla: </b></h3> + <p>If you’re interested in learning more about all the exciting new features, projects, and plans that were presented at Mozlando look no further! You can now watch the final plenary sessions on Air Mozilla (it’s a lot of fun so I highly recommend it!) <a href="https://air.mozilla.org/channels/mozlando/">here</a>.</p> + <p>Share your questions and comments on discourse <a href="https://discourse.mozilla-community.org/t/friday-plenary-from-mozlando-now-public-on-air-mozilla/6659">here</a>.</p> + <p><em>Look forward to more updates like these in the coming months!</em></p> + 2016-01-21T17:58:33+00:00 + Lucy Harris + + + Mozilla Privacy Blog: Prioritizing privacy: Good for business + https://blog.mozilla.org/netpolicy/2016/01/21/prioritizing-privacy-good-for-business/ + <p><em>This was originally posted at <a href="http://staysafeonline.org/blog/prioritizing-privacy-good-for-business/">StaySafeOnline.org</a> in advance of <a href="http://www.staysafeonline.org/data-privacy-day/events/">Data Privacy Day</a>.</em></p> + <p>Data Privacy Day – which arrives in just a week – is a day designed to raise awareness and promote best practices for privacy and data protection. It is a day that looks to the future and recognizes that we can and should do better as an industry. It reminds us that we need to focus on the importance of having the trust of our users.</p> + <p>We seek to build trust so we can collectively create the Web our users want – the Web we all want.</p> + <p>That Web is based on relationships, the same way that the offline world is. When I log in to a social media account, schedule a grocery delivery online or browse the news, I’m relying on those services to respect my data. While companies are innovating their products and services, they need to be innovating on user trust as well, which means designing to address privacy concerns – and making smart choices (early!) about how to manage data.</p> + <p>A <a href="http://www.pewinternet.org/2016/01/14/privacy-and-information-sharing/">recent survey by Pew</a> highlights the thought that each user puts into their choices – and the contextual considerations in various scenarios. They concluded that many participants were annoyed and uncertain by how their information was used, and they are choosing not to interact with those services that they don’t trust. This is a clear call to businesses to foster more trust with their users, which starts by making sure that there are people empowered within your company to ask the right questions: what do your users expect? What data do you need to collect? How can you communicate about that data collection? How should you protect their data? Is holding on to data a risk, or should you delete it?</p> + <p>It’s crucial that users are a part of this process – consumers’ data is needed to offer cool, new experiences and a user needs to trust you in order to choose to give you their data. Pro-user innovation can’t happen in a vacuum – the system as it stands today isn’t doing a good job of aligning user interests with business incentives. Good user decisions can be good business decisions, but only if we create thoughtful user-centric products in a way that closes the feedback loop so that positive user experiences are rewarded with better business outcomes.</p> + <p>Not prioritizing privacy in product decisions will impact the bottom line. From the many data breaches over the last few years to increasing evidence of eroding trust in online services, data practices are proving to be the dark horse in the online economy. When a company loses user trust, whether on privacy or <a href="https://medium.com/@davidamerland/the-cost-of-losing-trust-97d764a1e696">anything else</a>, it loses customers and the potential for growth.</p> + <p>Privacy means different things to different people but what’s clear is that people make decisions about the products and services that they use based on how those companies choose to treat their users. Over this time, the Internet ecosystem has evolved, as has its relationship with users – and some aspects of this evolution threaten the trust that lies at the heart of that relationship. Treating a user as a target – whether for an ad, purchase, or service – undermines the trust and relationship that a business may have with a consumer.</p> + <p>The solution is not to abandon the massive value that robust data can bring to users, but rather, to collect and use data leanly, productively and transparently. At Mozilla, we have created a strong set of internal data practices to ensure that data decisions align with our <a href="https://www.mozilla.org/en-US/privacy/principles/">privacy principles</a>. As an industry, we need to keep users at the center of the product vision rather than viewing them as targets of the product – it’s the only way to stay true to consumers and deliver the best, most trusted experiences possible.</p> + <p>Want to hear more about how businesses can build relationships with their users by focusing on trust and privacy? We’re holding events in Washington, D.C., and <a href="https://www.eventbrite.com/e/january-privacy-lab-privacy-for-startups-tickets-19849219550?aff=es2">San Francisco</a> with some of our partners to talk about it. Please join us!</p> + 2016-01-21T17:42:00+00:00 + Heather West + + + J.C. Jones: Issuance Rate for Let's Encrypt + https://tacticalsecret.com/issuance-rate-for-lets-encrypt/ + <p>Gathering data from <a href="https://github.com/jcjones/letsencrypt_statistics">Certificate Transparency logs</a>, here's a snapshot in time of Let's Encrypt's certificate issuance rate per minute from 7-21 January 2016. On 20 January, DreamHost launched formal support for Let's Encrypt, which coincides with a rate increase.</p> + + <p>Note: This is mostly an experimental post with embedding charts; I've more data in the queue.</p> + + <h3>Let's Encrypt Issuance Rate per Minute</h3> + + <div id="rate_hours"></div> + 2016-01-21T17:07:25+00:00 + James 'J.C.' Jones + + + Air Mozilla: Web QA Weekly Meeting, 21 Jan 2016 + https://air.mozilla.org/web-qa-weekly-meeting-20160121/ + <p> + <img alt="Web QA Weekly Meeting" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/f5/13/f5137857516694df0458e837c2d3a4be.png" width="160" /> + This is our weekly gathering of Mozilla'a Web QA team filled with discussion on our current and future projects, ideas, demos, and fun facts. + </p> + 2016-01-21T17:00:00+00:00 + Air Mozilla + + + Soledad Penades: No more tap tap tap sounds: yay! + http://soledadpenades.com/2016/01/21/no-more-tap-tap-tap-sounds-yay/ + <p>A few days ago the fantastic Fritz from the Netherlands told me that my <a href="http://soledadpenades.com/files/t/2015_howa/">Hands On Web Audio slides</a> had stopping working and there was no sound coming out from them in Firefox.</p> + <blockquote class="twitter-tweet" width="550"><p dir="ltr" lang="en"><a href="https://twitter.com/supersole">@supersole</a> oh noes! I reopened your slides: <a href="https://t.co/SO35UfljMI">https://t.co/SO35UfljMI</a> and it doesn't work in <a href="https://twitter.com/firefox">@firefox</a> anymore <img alt="😱" class="wp-smiley" src="http://s.w.org/images/core/emoji/72x72/1f631.png" style="height: 1em;" /> (works in chrome though.. <img alt="😢" class="wp-smiley" src="http://s.w.org/images/core/emoji/72x72/1f622.png" style="height: 1em;" />)</p> + <p>— Boring Stranger (@fritzvd) <a href="https://twitter.com/fritzvd/status/686481500611735552">January 11, 2016</a></p></blockquote> + <p></p> + <p>Which is pretty disappointing for a slide deck that is built to teach you about Web Audio!</p> + <p>I noticed that the issue was only on the introductory slide which uses a modified version of Stuart Memo’s <a href="https://blog.stuartmemo.com/thx-deep-note-in-javascript/">fantastic THX sound recreation</a>-the rest of slides did play sound.</p> + <p>I built <a href="http://sole.github.io/test_cases/web_audio/thx_cutting_out/">an isolated test case</a> <small><a href="https://github.com/sole/test_cases/tree/gh-pages/web_audio/thx_cutting_out">(source)</a></small> that used a parameter-capable version of the THX sound code, just in case the issue depended on the number of oscillators, and submitted this funnily titled bug to the Web Audio component: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1240054">Entirely Web Audio generated sound cuts out after a little while, or emits random tap tap tap sounds then silence</a>.</p> + <p>I can happily confirm that the bug has been fixed in Nightly and the fix will hopefully be “uplifted” to DevEdition very soon, as it was due to a regression.</p> + <p><a href="https://paul.cx/">Paul Adenot</a> (who works in Web Audio and is a Web Audio spec editor, amongst a couple tons of other cool things) was really excited about the bug, saying it was very edge-casey! Yay! And he also explained what did actually happen in lay terms: “you’d have to have a frequency that goes down very very slowly so that the FFT code could not keep up”, which is what the THX sound is doing with the filter frequency automation.</p> + <p>I want to thank both Fritz for spotting this out and letting me know and also Stuart for sharing his THX code. It’s amazing what happens when you put stuff on the net and lots of different people use it in different ways and configurations. Together we make everything more robust <img alt=":-)" class="wp-smiley" src="http://soledadpenades.com/wp-includes/images/smilies/simple-smile.png" style="height: 1em;" /></p> + <p>Of course also sending thanks to Paul and Ben for identifying and fixing the issue so fast! It’s not been even a week! Woohoo!</p> + <p>Well done everyone! <img alt="👏" class="wp-smiley" src="http://s.w.org/images/core/emoji/72x72/1f44f.png" style="height: 1em;" /><img alt="🏼" class="wp-smiley" src="http://s.w.org/images/core/emoji/72x72/1f3fc.png" style="height: 1em;" /></p> + <p><a href="http://soledadpenades.com/?flattrss_redirect&amp;id=6379&amp;md5=57babe624711830f95e4b8fbd6e52c91" target="_blank" title="Flattr"><img alt="flattr this!" src="http://soledadpenades.com/wp-content/plugins/flattr/img/flattr-badge-large.png" /></a></p> + 2016-01-21T15:49:05+00:00 + sole + + + Pierros Papadeas: Mozillians.org Profile Edit refresh + http://pierros.papadeas.gr/?p=447 + <p>Since the start of this year, Participation Infrastructure team has a renewed focus on making mozillians.org a modern community directory to meet Mozilla’s growing needs. This will not be an one-time effort. We need to invest technically and programmatically in order to deliver a first-class product that will be the foundation for identity management across the Mozilla ecosystem.</p> + <p>Mozillians.org is full of functionality as it is today, but is paying the debt of being developed by 5 different teams over the past 5 years. We started simple this time. Updated all core technology pieces, did privacy and security reviews, and started the process of consolidating and modernizing many of the things we do in the site.</p> + <p>Our first target was Profile Edit. We chose it due to relatively self-contained nature of it, and cause many people were not happy with the current UX. After research of existing tools and applying latest best practices, we designed, coded and deployed a new profile edit interface (which by the way is renamed to Settings now) that we are happy to deliver to all Mozillians.</p> + <p><a href="http://pierros.papadeas.gr/wp-content/uploads/2016/01/new-profile.png" rel="attachment wp-att-448"><img alt="new-profile" class="aligncenter size-large wp-image-448" height="417" src="http://pierros.papadeas.gr/wp-content/uploads/2016/01/new-profile-1024x731.png" width="584" /></a>Have a<a href="https://mozillians.org/en-US/user/edit/"> look for yourself </a>and don’t miss the chance to update your profile while you do it!</p> + <p><a href="https://mozillians.org/en-US/u/comzeradd/">Nikos</a> (on the front-end), <a href="https://mozillians.org/en-US/u/akatsoulas/">Tasos</a> and <a href="https://mozillians.org/en-US/u/jgiannelos/">Nemo</a> (on the back-end) worked hard to deliver this in a speedy manner (as they are used to), and the end result is a testament to what is coming next on Mozillians.org.</p> + <p>Our next target? Groups. Currently it is obscure and unclear what all those settings in groups are, what is the functionality and how teams within Mozilla will be using it. We will be tackling this soon. After that, search and stats will be our attention, in an ongoing effort to fortify mozillians.org functionality. Stay tuned, and as always feel free to <a href="https://bugzilla.mozilla.org/enter_bug.cgi?product=Participation%20Infrastructure&amp;component=Phonebook">file bugs</a> and <a href="https://github.com/mozilla/mozillians">contribute </a>in the process.</p> + 2016-01-21T11:41:39+00:00 + Pierros Papadeas + + + Adam Lofting: Blog posts I haven’t written lately + http://feedproxy.google.com/~r/adamlofting/blog/~3/DoEWpBapwiw/ + <p>Last year I joked…</p> + <blockquote class="twitter-tweet" lang="en"> + <p dir="ltr" lang="en">Thinking about writing a blog post listing the blog posts I’ve been meaning to write… Maybe that will save some time</p> + <p>— Adam Lofting (@adamlofting) <a href="https://twitter.com/adamlofting/status/667657889817956352">November 20, 2015</a></p></blockquote> + <p></p> + <p>Now, it has come to this.</p> + <h4>9 blog posts I’ve not been writing</h4> + <ul> + <li>Working on working on the impact of impact</li> + <li>Designing Games in <a href="https://en.wikipedia.org/wiki/Amateur" target="_blank">my free time</a></li> + <li>Moving Out (the board game)</li> + <li>Mozilla Foundation 2016 KPIs</li> + <li>Studying Network Science</li> + <li>Learning Analytics plans for 2016</li> + <li>Daily practice / you are what you do every day</li> + <li>Several more A/B tests to write up from <a href="http://fundraising.mozilla.org/">the fundraising campaign</a></li> + <li>CRM Progress in 2015</li> + </ul> + <p>But my most requested blog by far, is an update on the status of my shed / office that I was tagging on to the end my blog posts at this time last year. Many people at Mozfest wanted to know about the shed… so here it is.</p> + <p>This time last year:</p> + <blockquote class="twitter-tweet" lang="en"><p> + Starting in the new office today. It will take time to make it *nice* but it works for now. <a href="http://t.co/sWoC4kFNLc">pic.twitter.com/sWoC4kFNLc</a></p> + <p>— Adam Lofting (@adamlofting) <a href="https://twitter.com/adamlofting/status/560361913339899904">January 28, 2015</a> + </p></blockquote> + <p></p> + <p>Some pictures from this morning:</p> + <p><img alt="office1" class="alignright size-large wp-image-1398" height="282" src="http://adamlofting.com/wp-content/uploads/2016/01/office1-750x320.jpg" width="660" /></p> + <p><img alt="office2" class="aligncenter size-large wp-image-1399" height="237" src="http://adamlofting.com/wp-content/uploads/2016/01/office2-750x269.jpg" width="660" /></p> + <p>It’s a pretty nice place to work now and it doubles as useful workshop on the weekends. It needs a few finishing touches, but the law of diminishing returns means those finishing touches are lower priority than work that needs to be done elsewhere in the house and garden. So it’ll stay like this a while longer.</p> + <div class="feedflare"> + <a href="http://feeds.feedburner.com/~ff/adamlofting/blog?a=DoEWpBapwiw:VxTJGXwqhlI:yIl2AUoC8zA"><img border="0" src="http://feeds.feedburner.com/~ff/adamlofting/blog?d=yIl2AUoC8zA" /></a> <a href="http://feeds.feedburner.com/~ff/adamlofting/blog?a=DoEWpBapwiw:VxTJGXwqhlI:qj6IDK7rITs"><img border="0" src="http://feeds.feedburner.com/~ff/adamlofting/blog?d=qj6IDK7rITs" /></a> + </div><img alt="" height="1" src="http://feeds.feedburner.com/~r/adamlofting/blog/~4/DoEWpBapwiw" width="1" /> + 2016-01-21T09:44:24+00:00 + Adam + + + Tarek Ziadé: A Pelican web editor + http://blog.ziade.org/2016/01/21/a-pelican-web-editor/ + <p>The benefit of being a father again (Freya my 3rd child, was born last week) is + that while on paternity leave &amp; between two baby bottles, I can hack on fun stuff.</p> + <p>A few months ago, I've built for my running club a Pelican-based website, check it out + at : <a class="reference external" href="http://acr-dijon.org">http://acr-dijon.org</a>. Nothing's special about it, except that I am not + the one feeding it. The content is added by people from the club that have zero + knowledge about softwares, let alone stuff like vim or command line tools.</p> + <p>I set up a github-based flow for them, where they add content through the + github UI and its minimal reStructuredText preview feature - and then a few + of my crons update the website on the server I host. + For images and other media, they are uploading them via FTP using FireSSH in Firefox.</p> + <p>For the comments, I've switched from Disqus to <a class="reference external" href="https://posativ.org/isso/">ISSO</a> + after I got annoyed by the fact that it was impossible to display a simple Disqus + UI for people to comment without having to log in.</p> + <p>I had to make my club friends go through a minimal + reStructuredText syntax training, and things are more of less working now.</p> + <p>The system has a few caveats though:</p> + <ul class="simple"> + <li>it's dependent on Github. I'd rather have everything hosted on my server.</li> + <li>the github restTRucturedText preview will not display syntax errors and warnings + and very often, articles get broken</li> + <li>the resulting reST is ugly, and it's a bit hard to force my editors to be stricter + about details like empty lines, not using tabs etc.</li> + <li>adding folders or organizing articles from Github is a pain</li> + <li>editing the metadata tags is prone to many mistakes</li> + </ul> + <p>So I've decided to build my own web editing tool with the following features:</p> + <ul class="simple"> + <li>resTructuredText cleanup</li> + <li>content browsing</li> + <li>resTructuredText web editor with live preview that shows warnings &amp; errors</li> + <li>a little bit of wsgi glue and a few forms to create articles without + having to worry about metadata syntax.</li> + </ul> + <div class="section" id="restructuredtext-cleanup"> + <h3>resTructuredText cleanup</h3> + <p>The first step was to build a reStructuredText parser that would read some + reStructuredText and render it back into a cleaner version.</p> + <p>We've imported almost 2000 articles in Pelican from the old blog, so I had + a <strong>lot</strong> of samples to make my parser work well.</p> + <p>I first tried <a class="reference external" href="https://github.com/benoitbryon/rst2rst">rst2rst</a> but that + parser was built for a very specific use case (text wrapping) and was + incomplete. It was not parsing all of the reStructuredText syntax.</p> + <p>Inspired by it, I wrote my own little parser using <strong>docutils</strong>.</p> + <p>Understanding docutils is not a small task. This project is very powerfull + but quite complex. One thing that cruelly misses in docutils parser tools + is the ability to get the source text from any node, including its children, + so you can render back the same source.</p> + <p>That's roughly what I had to add in my code. It's ugly but it does the job: + it will parse rst files and render the same content, minus all the extraneous + empty lines, spaces, tabs etc.</p> + </div> + <div class="section" id="content-browsing"> + <h3>Content browsing</h3> + <p>Content browsing is pretty straightforward: my admin tool let you browse + the Pelican <em>content</em> directory and lists all articles, organized by categories.</p> + <p>In our case, each category has a top directory in <em>content</em>. The browser + parses the articles using my parser and displays paginated lists.</p> + <p>I had to add a cache system for the parser, because one of the directory + contains over 1000 articles -- and browsing was kind of slow :)</p> + <img alt="http://ziade.org/henet-browsing.png" src="http://ziade.org/henet-browsing.png" /> + </div> + <div class="section" id="restructuredtext-web-editor"> + <h3>resTructuredText web editor</h3> + <p>The last big bit was the live editor. I've stumbled on a neat little tool + called <strong>rsted</strong>, that provides a live preview of the reStructuredText + as you are typing it. And it includes warnings !</p> + <p>Check it out: <a class="reference external" href="http://rst.ninjs.org/">http://rst.ninjs.org/</a></p> + <p>I've stripped it and kept what I needed, and included it in my app.</p> + <img alt="http://ziade.org/henet.png" src="http://ziade.org/henet.png" /> + <p>I am quite happy with the result so far. I need to add real tests and + a bit of documentation, and I will start to train my club friends on it.</p> + <p>The next features I'd like to add are:</p> + <ul class="simple"> + <li>comments management, to replace Isso (working on it now)</li> + <li>smart Pelican builds. e.g. if a comment is added I don't want to rebuild the whole + blog (~1500 articles)</li> + <li>media management</li> + <li>spell checker</li> + </ul> + <p>The project lives here: <a class="reference external" href="https://github.com/AcrDijon/henet">https://github.com/AcrDijon/henet</a></p> + <p>I am not going to release it, but if someone finds it useful, I could.</p> + <p>It's built with Bottle &amp; Bootstrap as well.</p> + </div> + 2016-01-21T09:40:00+00:00 + Tarek Ziade + + + Nick Cameron: Closures and first-class functions + http://www.ncameron.org/blog/closures-and-first-class-functions/ + <p>I wrote a long and probably dull chapter on closures and first-class and higher-order functions in Rust. It goes into some detail on the implementation and some of the subtleties like higher-ranked lifetime bounds.</p> + + <p>I was going to post it here too, but it is really too long. Instead, pop over to the 'Rust for C++ programmers' repo and read it <a href="https://github.com/nrc/r4cppp/blob/master/closures.md">there</a>.</p> + 2016-01-21T08:36:21+00:00 + Nick Cameron + + + Nick Desaulniers: Intro to Debugging x86-64 Assembly + http://nickdesaulniers.github.io/blog/2016/01/20/debugging-x86-64-assembly-with-lldb-and-dtrace/ + <p>I’m hacking on an assembly project, and wanted to document some of the tricks I + was using for figuring out what was going on. This post might seem a little + basic for folks who spend all day heads down in gdb or who do this stuff + professionally, but I just wanted to share a quick intro to some tools that + others may find useful. + (<a href="https://pchiusano.github.io/2014-10-11/defensive-writing.html">oh god, I’m doing it</a>)</p> + + <p>If your coming from gdb to lldb, there’s a few differences in commands. LLDB + has + <a href="http://lldb.llvm.org/lldb-gdb.html">great documentation</a> + on some of the differences. Everything in this post about LLDB is pretty much + there.</p> + + <p>The bread and butter commands when working with gdb or lldb are:</p> + + <ul> + <li>r (run the program)</li> + <li>s (step in)</li> + <li>n (step over)</li> + <li>finish (step out)</li> + <li>c (continue)</li> + <li>q (quit the program)</li> + </ul> + + + <p>You can hit enter if you want to run the last command again, which is really + useful if you want to keep stepping over statements repeatedly.</p> + + <p>I’ve been using LLDB on OSX. Let’s say I want to debug a program I can build, + but is crashing or something:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="nv">$ </span>sudo lldb ./asmttpd web_root + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>Setting a breakpoint on jump to label:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> b sys_write + </span><span class="line">Breakpoint 3: <span class="nv">where</span> <span class="o">=</span> asmttpd<span class="sb">`</span>sys_write, <span class="nv">address</span> <span class="o">=</span> 0x00000000000029ae + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>Running the program until breakpoint hit:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + <span class="line-number">8</span> + <span class="line-number">9</span> + <span class="line-number">10</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> r + </span><span class="line">Process 32236 launched: <span class="s1">'./asmttpd'</span> <span class="o">(</span>x86_64<span class="o">)</span> + </span><span class="line">Process 32236 stopped + </span><span class="line">* thread <span class="c">#1: tid = 0xe69b9, 0x00000000000029ae asmttpd`sys_write, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1</span> + </span><span class="line"> frame <span class="c">#0: 0x00000000000029ae asmttpd`sys_write</span> + </span><span class="line">asmttpd<span class="sb">`</span>sys_write: + </span><span class="line">-&gt; 0x29ae &lt;+0&gt;: pushq %rdi + </span><span class="line"> 0x29af &lt;+1&gt;: pushq %rsi + </span><span class="line"> 0x29b0 &lt;+2&gt;: pushq %rdx + </span><span class="line"> 0x29b1 &lt;+3&gt;: pushq %r10 + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>Seeing more of the current stack frame:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + <span class="line-number">8</span> + <span class="line-number">9</span> + <span class="line-number">10</span> + <span class="line-number">11</span> + <span class="line-number">12</span> + <span class="line-number">13</span> + <span class="line-number">14</span> + <span class="line-number">15</span> + <span class="line-number">16</span> + <span class="line-number">17</span> + <span class="line-number">18</span> + <span class="line-number">19</span> + <span class="line-number">20</span> + <span class="line-number">21</span> + <span class="line-number">22</span> + <span class="line-number">23</span> + <span class="line-number">24</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> d + </span><span class="line">asmttpd<span class="sb">`</span>sys_write: + </span><span class="line">-&gt; 0x29ae &lt;+0&gt;: pushq %rdi + </span><span class="line"> 0x29af &lt;+1&gt;: pushq %rsi + </span><span class="line"> 0x29b0 &lt;+2&gt;: pushq %rdx + </span><span class="line"> 0x29b1 &lt;+3&gt;: pushq %r10 + </span><span class="line"> 0x29b3 &lt;+5&gt;: pushq %r8 + </span><span class="line"> 0x29b5 &lt;+7&gt;: pushq %r9 + </span><span class="line"> 0x29b7 &lt;+9&gt;: pushq %rbx + </span><span class="line"> 0x29b8 &lt;+10&gt;: pushq %rcx + </span><span class="line"> 0x29b9 &lt;+11&gt;: movq %rsi, %rdx + </span><span class="line"> 0x29bc &lt;+14&gt;: movq %rdi, %rsi + </span><span class="line"> 0x29bf &lt;+17&gt;: movq <span class="nv">$0x1</span>, %rdi + </span><span class="line"> 0x29c6 &lt;+24&gt;: movq <span class="nv">$0x2000004</span>, %rax + </span><span class="line"> 0x29cd &lt;+31&gt;: syscall + </span><span class="line"> 0x29cf &lt;+33&gt;: popq %rcx + </span><span class="line"> 0x29d0 &lt;+34&gt;: popq %rbx + </span><span class="line"> 0x29d1 &lt;+35&gt;: popq %r9 + </span><span class="line"> 0x29d3 &lt;+37&gt;: popq %r8 + </span><span class="line"> 0x29 &lt;+39&gt;: popq %r10 + </span><span class="line"> 0x29d7 &lt;+41&gt;: popq %rdx + </span><span class="line"> 0x29d8 &lt;+42&gt;: popq %rsi + </span><span class="line"> 0x29d9 &lt;+43&gt;: popq %rdi + </span><span class="line"> 0x29da &lt;+44&gt;: retq + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>Getting a back trace (call stack):</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> bt + </span><span class="line">* thread <span class="c">#1: tid = 0xe69b9, 0x00000000000029ae asmttpd`sys_write, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1</span> + </span><span class="line"> * frame <span class="c">#0: 0x00000000000029ae asmttpd`sys_write</span> + </span><span class="line"> frame <span class="c">#1: 0x00000000000021b6 asmttpd`print_line + 16</span> + </span><span class="line"> frame <span class="c">#2: 0x0000000000002ab3 asmttpd`start + 35</span> + </span><span class="line"> frame <span class="c">#3: 0x00007fff9900c5ad libdyld.dylib`start + 1</span> + </span><span class="line"> frame <span class="c">#4: 0x00007fff9900c5ad libdyld.dylib`start + 1</span> + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>peeking at the upper stack frame:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> up + </span><span class="line">frame <span class="c">#1: 0x00000000000021b6 asmttpd`print_line + 16</span> + </span><span class="line">asmttpd<span class="sb">`</span>print_line: + </span><span class="line"> 0x21b6 &lt;+16&gt;: movabsq <span class="nv">$0x30cb</span>, %rdi + </span><span class="line"> 0x21c0 &lt;+26&gt;: movq <span class="nv">$0x1</span>, %rsi + </span><span class="line"> 0x21c7 &lt;+33&gt;: callq 0x29ae ; sys_write + </span><span class="line"> 0x21cc &lt;+38&gt;: popq %rcx + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>back down to the breakpoint-halted stack frame:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> down + </span><span class="line">frame <span class="c">#0: 0x00000000000029ae asmttpd`sys_write</span> + </span><span class="line">asmttpd<span class="sb">`</span>sys_write: + </span><span class="line">-&gt; 0x29ae &lt;+0&gt;: pushq %rdi + </span><span class="line"> 0x29af &lt;+1&gt;: pushq %rsi + </span><span class="line"> 0x29b0 &lt;+2&gt;: pushq %rdx + </span><span class="line"> 0x29b1 &lt;+3&gt;: pushq %r10 + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>dumping the values of registers:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + <span class="line-number">8</span> + <span class="line-number">9</span> + <span class="line-number">10</span> + <span class="line-number">11</span> + <span class="line-number">12</span> + <span class="line-number">13</span> + <span class="line-number">14</span> + <span class="line-number">15</span> + <span class="line-number">16</span> + <span class="line-number">17</span> + <span class="line-number">18</span> + <span class="line-number">19</span> + <span class="line-number">20</span> + <span class="line-number">21</span> + <span class="line-number">22</span> + <span class="line-number">23</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> register <span class="nb">read</span> + </span><span class="line">General Purpose Registers: + </span><span class="line"> <span class="nv">rax</span> <span class="o">=</span> 0x0000000000002a90 asmttpd<span class="sb">`</span>start + </span><span class="line"> <span class="nv">rbx</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">rcx</span> <span class="o">=</span> 0x00007fff5fbffaf8 + </span><span class="line"> <span class="nv">rdx</span> <span class="o">=</span> 0x00007fff5fbffa40 + </span><span class="line"> <span class="nv">rdi</span> <span class="o">=</span> 0x00000000000030cc start_text + </span><span class="line"> <span class="nv">rsi</span> <span class="o">=</span> 0x000000000000000f + </span><span class="line"> <span class="nv">rbp</span> <span class="o">=</span> 0x00007fff5fbffa18 + </span><span class="line"> <span class="nv">rsp</span> <span class="o">=</span> 0x00007fff5fbff9b8 + </span><span class="line"> <span class="nv">r8</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">r9</span> <span class="o">=</span> 0x00007fff7b1670c8 atexit_mutex + 24 + </span><span class="line"> <span class="nv">r10</span> <span class="o">=</span> 0x00000000ffffffff + </span><span class="line"> <span class="nv">r11</span> <span class="o">=</span> 0xffffffff00000000 + </span><span class="line"> <span class="nv">r12</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">r13</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">r14</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">r15</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">rip</span> <span class="o">=</span> 0x00000000000029ae asmttpd<span class="sb">`</span>sys_write + </span><span class="line"> <span class="nv">rflags</span> <span class="o">=</span> 0x0000000000000246 + </span><span class="line"> <span class="nv">cs</span> <span class="o">=</span> 0x000000000000002b + </span><span class="line"> <span class="nv">fs</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">gs</span> <span class="o">=</span> 0x0000000000000000 + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>read just one register:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> register <span class="nb">read </span>rdi + </span><span class="line"> <span class="nv">rdi</span> <span class="o">=</span> 0x00000000000030cc start_text + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>When you’re trying to figure out what system calls are made by some C code, + using dtruss is very helpful. dtruss is available on OSX and seems to be some + kind of wrapper around DTrace.</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + <span class="line-number">8</span> + <span class="line-number">9</span> + <span class="line-number">10</span> + <span class="line-number">11</span> + <span class="line-number">12</span> + <span class="line-number">13</span> + <span class="line-number">14</span> + <span class="line-number">15</span> + <span class="line-number">16</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="nv">$ </span>cat sleep.c + </span><span class="line"><span class="c">#include &lt;time.h&gt;</span> + </span><span class="line">int main <span class="o">()</span> <span class="o">{</span> + </span><span class="line"> struct timespec <span class="nv">rqtp</span> <span class="o">=</span> <span class="o">{</span> + </span><span class="line"> 2, + </span><span class="line"> 0 + </span><span class="line"> <span class="o">}</span>; + </span><span class="line"> + </span><span class="line"> nanosleep<span class="o">(</span>&amp;rqtp, NULL<span class="o">)</span>; + </span><span class="line"><span class="o">}</span> + </span><span class="line"> + </span><span class="line"><span class="nv">$ </span>clang sleep.c + </span><span class="line"> + </span><span class="line"><span class="nv">$ </span>sudo dtruss ./a.out + </span><span class="line">...all kinds of fun stuff + </span><span class="line">__semwait_signal<span class="o">(</span>0xB03, 0x0, 0x1<span class="o">)</span> <span class="o">=</span> -1 Err#60 + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>If you compile with <code>-g</code> to emit debug symbols, you can use lldb’s disassemble + command to get the equivalent assembly:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + <span class="line-number">8</span> + <span class="line-number">9</span> + <span class="line-number">10</span> + <span class="line-number">11</span> + <span class="line-number">12</span> + <span class="line-number">13</span> + <span class="line-number">14</span> + <span class="line-number">15</span> + <span class="line-number">16</span> + <span class="line-number">17</span> + <span class="line-number">18</span> + <span class="line-number">19</span> + <span class="line-number">20</span> + <span class="line-number">21</span> + <span class="line-number">22</span> + <span class="line-number">23</span> + <span class="line-number">24</span> + <span class="line-number">25</span> + <span class="line-number">26</span> + <span class="line-number">27</span> + <span class="line-number">28</span> + <span class="line-number">29</span> + <span class="line-number">30</span> + <span class="line-number">31</span> + <span class="line-number">32</span> + <span class="line-number">33</span> + <span class="line-number">34</span> + <span class="line-number">35</span> + <span class="line-number">36</span> + <span class="line-number">37</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="nv">$ </span>clang sleep.c -g + </span><span class="line"><span class="nv">$ </span>lldb a.out + </span><span class="line"><span class="o">(</span>lldb<span class="o">)</span> target create <span class="s2">"a.out"</span> + </span><span class="line">Current executable <span class="nb">set </span>to <span class="s1">'a.out'</span> <span class="o">(</span>x86_64<span class="o">)</span>. + </span><span class="line"><span class="o">(</span>lldb<span class="o">)</span> b main + </span><span class="line">Breakpoint 1: <span class="nv">where</span> <span class="o">=</span> a.out<span class="sb">`</span>main + 16 at sleep.c:3, <span class="nv">address</span> <span class="o">=</span> 0x0000000100000f40 + </span><span class="line"><span class="o">(</span>lldb<span class="o">)</span> r + </span><span class="line">Process 33213 launched: <span class="s1">'/Users/Nicholas/code/assembly/asmttpd/a.out'</span> <span class="o">(</span>x86_64<span class="o">)</span> + </span><span class="line">Process 33213 stopped + </span><span class="line">* thread <span class="c">#1: tid = 0xeca04, 0x0000000100000f40 a.out`main + 16 at sleep.c:3, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1</span> + </span><span class="line"> frame <span class="c">#0: 0x0000000100000f40 a.out`main + 16 at sleep.c:3</span> + </span><span class="line"> 1 <span class="c">#include &lt;time.h&gt;</span> + </span><span class="line"> 2 int main <span class="o">()</span> <span class="o">{</span> + </span><span class="line">-&gt; 3 struct timespec <span class="nv">rqtp</span> <span class="o">=</span> <span class="o">{</span> + </span><span class="line"> 4 2, + </span><span class="line"> 5 0 + </span><span class="line"> 6 <span class="o">}</span>; + </span><span class="line"> 7 + </span><span class="line"><span class="o">(</span>lldb<span class="o">)</span> disassemble + </span><span class="line">a.out<span class="sb">`</span>main: + </span><span class="line"> 0x100000f30 &lt;+0&gt;: pushq %rbp + </span><span class="line"> 0x100000f31 &lt;+1&gt;: movq %rsp, %rbp + </span><span class="line"> 0x100000f34 &lt;+4&gt;: subq <span class="nv">$0x20</span>, %rsp + </span><span class="line"> 0x100000f38 &lt;+8&gt;: leaq -0x10<span class="o">(</span>%rbp<span class="o">)</span>, %rdi + </span><span class="line"> 0x100000f3c &lt;+12&gt;: xorl %eax, %eax + </span><span class="line"> 0x100000f3e &lt;+14&gt;: movl %eax, %esi + </span><span class="line">-&gt; 0x100000f40 &lt;+16&gt;: movq 0x49<span class="o">(</span>%rip<span class="o">)</span>, %rcx + </span><span class="line"> 0x100000f47 &lt;+23&gt;: movq %rcx, -0x10<span class="o">(</span>%rbp<span class="o">)</span> + </span><span class="line"> 0x100000f4b &lt;+27&gt;: movq 0x46<span class="o">(</span>%rip<span class="o">)</span>, %rcx + </span><span class="line"> 0x100000f52 &lt;+34&gt;: movq %rcx, -0x8<span class="o">(</span>%rbp<span class="o">)</span> + </span><span class="line"> 0x100000f56 &lt;+38&gt;: callq 0x100000f68 ; symbol stub <span class="k">for</span>: nanosleep + </span><span class="line"> 0x100000f5b &lt;+43&gt;: xorl %edx, %edx + </span><span class="line"> 0x100000f5d &lt;+45&gt;: movl %eax, -0x14<span class="o">(</span>%rbp<span class="o">)</span> + </span><span class="line"> 0x100000f60 &lt;+48&gt;: movl %edx, %eax + </span><span class="line"> 0x100000f62 &lt;+50&gt;: addq <span class="nv">$0x20</span>, %rsp + </span><span class="line"> 0x100000f66 &lt;+54&gt;: popq %rbp + </span><span class="line"> 0x100000f67 &lt;+55&gt;: retq + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>Anyways, I’ve been learning some interesting things about OSX that I’ll be + sharing soon. If you’d like to learn more about x86-64 assembly programming, + you should read my other posts about + <a href="http://nickdesaulniers.github.io/blog/2014/04/18/lets-write-some-x86-64/">writing x86-64</a> + and a toy + <a href="http://nickdesaulniers.github.io/blog/2015/05/25/interpreter-compiler-jit/">JIT for Brainfuck</a> + (<a href="https://www.reddit.com/r/programming/comments/377ov9/interpreter_compiler_jit/crkkrz4">the creator of Brainfuck liked it</a>).</p> + + <p>I should also do a post on + <a href="http://rr-project.org/">Mozilla’s rr</a>, + because it can do amazing things like step backwards. Another day…</p> + 2016-01-21T04:04:00+00:00 + + + Rail Aliiev: Rebooting productivity + https://rail.merail.ca/posts/rebooting-productivity.html + <div><p>Every new year gives you an opportunity to sit back, relax, + <span class="strike">have some scotch</span> and re-think the passed year. Holidays give + you enough free time. Even if you decide to not take a vacation around + the holidays, it's usually calm and peaceful.</p> + <p>This time, I found myself thinking mostly about productivity, being + effective, feeling busy, overwhelmed with work and other related topics.</p> + <p>When I started at Mozilla (almost 6 years ago!), I tried to apply all my + GTD and time management knowledge and techniques. Working remotely and + in a different time zone was an advantage - I had close to zero + interruptions. It worked perfect.</p> + <p>Last year I realized that my productivity skills had faded away somehow. + 40h+ workweeks, working on weekends, delivering goals in the last week + of quarter don't sound like good signs. Instead of being productive I + felt busy.</p> + <p>"Every crisis is an opportunity". Time to make a step back and reboot + myself. Burning out at work is not a good idea. :)</p> + <p>Here are some ideas/tips that I wrote down for myself you may found + useful.</p> + <div class="section" id="health-related"> + <h3>Health related</h3> + <ul class="simple"> + <li>Morning exercises. A 20-minute walk will wake your brain up and + generate enough endorphins for the first half of the day.</li> + <li>Meditation. 2x20min a day is ideal; 2x10min would work too. Something + like <a class="reference external" href="http://www.calm.com/">calm.com</a> makes this a peace of cake.</li> + </ul> + </div> + <div class="section" id="concentration"> + <h3>Concentration</h3> + <ul class="simple"> + <li>Task #1: make a daily plan. No plan - no work.</li> + <li>Don't start your day by reading emails. Get one (little) thing done + first - THEN check your email.</li> + <li>Try to define outcomes, not tasks. "Ship XYZ" instead of "Work on XYZ".</li> + <li>Meetings are time consuming, so "Set a goal for each meeting". + Consider skipping a meeting if you don't have any goal set, unless it's a + beer-and-tell meeting! :)</li> + <li>Constantly ask yourself if what you're working on is important.</li> + <li>3-4 times a day ask yourself whether you are doing something towards + your goal or just finding something else to keep you busy. If you want + to look busy, take your phone and walk around the office with some + papers in your hand. Everybody will think that you are a busy person! + This way you can take a break and look busy at the same time!</li> + <li>Take breaks! <a class="reference external" href="https://en.wikipedia.org/wiki/Pomodoro_Technique">Pomodoro technique</a> has this option + built-in. Taking breaks helps not only to avoid <a class="reference external" href="https://en.wikipedia.org/wiki/Repetitive_strain_injury">RSI</a>, but also + keeps your brain sane and gives you time to ask yourself the questions + mentioned above. I use <a class="reference external" href="http://www.workrave.org/">Workrave</a> on my + laptop, but you can use a real kitchen timer instead.</li> + <li>Wear headphones, especially at office. Noise cancelling ones are even + better. White noise, nature sounds, or instrumental music are your + friends.</li> + </ul> + </div> + <div class="section" id="home-office"> + <h3>(Home) Office</h3> + <ul class="simple"> + <li>Make sure you enjoy your work environment. Why on the earth would you + spend your valuable time working without joy?!</li> + <li>De-clutter and organize your desk. Less things around - less + distractions.</li> + <li>Desk, chair, monitor, keyboard, mouse, etc - don't cheap out on them. + Your health is more important and expensive. Thanks to <a class="reference external" href="https://twitter.com/mhoye">mhoye</a> for this advice!</li> + </ul> + </div> + <div class="section" id="other"> + <h3>Other</h3> + <ul class="simple"> + <li>Don't check email every 30 seconds. If there is an emergency, they + will call you! :)</li> + <li>Reward yourself at a certain time. "I'm going to have a chocolate at + 11am", or "MFBT at 4pm sharp!" are good examples. Don't forget, you + are <a class="reference external" href="https://en.wikipedia.org/wiki/Classical_conditioning">Pavlov's dog</a> too!</li> + <li>Don't try to read everything NOW. Save it for later and read in a + batch.</li> + <li>Capture all creative ideas. You can delete them later. ;)</li> + <li>Prepare for next task before break. Make sure you know what's next, so + you can think about it during the break.</li> + </ul> + <p>This is my list of things that I try to use everyday. Looking forward to + see improvements!</p> + <p>I would appreciate your thoughts this topic. Feel free to comment or + send a private email.</p> + <p>Happy Productive New Year!</p> + </div></div> + 2016-01-21T02:06:37+00:00 + Rail Aliiev + + + The Rust Programming Language Blog: Announcing Rust 1.6 + http://blog.rust-lang.org/2016/01/21/Rust-1.6.html + <p>Hello 2016! We’re happy to announce the first Rust release of the year, 1.6. + Rust is a systems programming language focused on safety, speed, and + concurrency.</p> + + <p>As always, you can <a href="http://www.rust-lang.org/install.html">install Rust 1.6</a> from the appropriate page on our + website, and check out the <a href="https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-160-2016-01-21">detailed release notes for 1.6</a> on GitHub. + About 1100 patches were landed in this release.</p> + + <h3 id="what-39-s-in-1-6-stable">What’s in 1.6 stable</h3> + + <p>This release contains a number of small refinements, one major feature, and + a change to <a href="https://crates.io">Crates.io</a>.</p> + + <h4 id="libcore-stabilization">libcore stabilization</h4> + + <p>The largest new feature in 1.6 is that <a href="http://doc.rust-lang.org/nightly/core/"><code>libcore</code></a> is now stable! Rust’s + standard library is two-tiered: there’s a small core library, <code>libcore</code>, and + the full standard library, <code>libstd</code>, that builds on top of it. <code>libcore</code> is + completely platform agnostic, and requires only a handful of external symbols + to be defined. Rust’s <code>libstd</code> builds on top of <code>libcore</code>, adding support for + memory allocation, I/O, and concurrency. Applications using Rust in the + embedded space, as well as those writing operating systems, often eschew + <code>libstd</code>, using only <code>libcore</code>.</p> + + <p><code>libcore</code> being stabilized is a major step towards being able to write the + lowest levels of software using stable Rust. There’s still future work to be + done, however. This will allow for a library ecosystem to develop around + <code>libcore</code>, but <em>applications</em> are not fully supported yet. Expect to hear more + about this in future release notes.</p> + + <h4 id="library-stabilizations">Library stabilizations</h4> + + <p>About 30 library functions and methods are now stable in 1.6. Notable + improvements include:</p> + + <p>The <code>drain()</code> family of functions on collections. These methods let you move + elements out of a collection while allowing them to retain their backing + memory, reducing allocation in certain situations.</p> + + <p>A number of implementations of <code>From</code> for converting between standard library + types, mainly between various integral and floating-point types.</p> + + <p>Finally, <code>Vec::extend_from_slice()</code>, which was previously known as + <code>push_all()</code>. This method has a significantly faster implementation than the + more general <code>extend()</code>.</p> + + <p>See the <a href="https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-160-2016-01-21">detailed release notes</a> for more.</p> + + <h4 id="crates-io-disallows-wildcards">Crates.io disallows wildcards</h4> + + <p>If you maintain a crate on <a href="https://crates.io">Crates.io</a>, you might have seen + a warning: newly uploaded crates are no longer allowed to use a wildcard when + describing their dependencies. In other words, this is not allowed:</p> + <div class="highlight"><pre><code class="language-toml"><span class="p">[</span><span class="n">dependencies</span><span class="p">]</span> + <span class="n">regex</span> <span class="o">=</span> <span class="s">"*"</span> + </code></pre></div> + <p>Instead, you must actually specify <a href="http://doc.crates.io/crates-io.html#using-cratesio-based-crates">a specific version or range of + versions</a>, using one of the <code>semver</code> crate’s various options: <code>^</code>, + <code>~</code>, or <code>=</code>.</p> + + <p>A wildcard dependency means that you work with any possible version of your + dependency. This is highly unlikely to be true, and causes unnecessary breakage + in the ecosystem. We’ve been advertising this change as a warning for some time; + now it’s time to turn it into an error.</p> + + <h3 id="contributors-to-1-6">Contributors to 1.6</h3> + + <p>We had 132 individuals contribute to 1.6. Thank you so much!</p> + + <ul> + <li>Aaron Turon</li> + <li>Adam Badawy</li> + <li>Aleksey Kladov</li> + <li>Alexander Bulaev</li> + <li>Alex Burka</li> + <li>Alex Crichton</li> + <li>Alex Gaynor</li> + <li>Alexis Beingessner</li> + <li>Amanieu d'Antras</li> + <li>Amit Saha</li> + <li>Andrea Canciani</li> + <li>Andrew Paseltiner</li> + <li>androm3da</li> + <li>angelsl</li> + <li>Angus Lees</li> + <li>Antti Keränen</li> + <li>arcnmx</li> + <li>Ariel Ben-Yehuda</li> + <li>Ashkan Kiani</li> + <li>Barosl Lee</li> + <li>Benjamin Herr</li> + <li>Ben Striegel</li> + <li>Bhargav Patel</li> + <li>Björn Steinbrink</li> + <li>Boris Egorov</li> + <li>bors</li> + <li>Brian Anderson</li> + <li>Bruno Tavares</li> + <li>Bryce Van Dyk</li> + <li>Cameron Sun</li> + <li>Christopher Sumnicht</li> + <li>Cole Reynolds</li> + <li>corentih</li> + <li>Daniel Campbell</li> + <li>Daniel Keep</li> + <li>Daniel Rollins</li> + <li>Daniel Trebbien</li> + <li>Danilo Bargen</li> + <li>Devon Hollowood</li> + <li>Doug Goldstein</li> + <li>Dylan McKay</li> + <li>ebadf</li> + <li>Eli Friedman</li> + <li>Eric Findlay</li> + <li>Erik Davidson</li> + <li>Felix S. Klock II</li> + <li>Florian Hahn</li> + <li>Florian Hartwig</li> + <li>Gleb Kozyrev</li> + <li>Guillaume Gomez</li> + <li>Huon Wilson</li> + <li>Igor Shuvalov</li> + <li>Ivan Ivaschenko</li> + <li>Ivan Kozik</li> + <li>Ivan Stankovic</li> + <li>Jack Fransham</li> + <li>Jake Goulding</li> + <li>Jake Worth</li> + <li>James Miller</li> + <li>Jan Likar</li> + <li>Jean Maillard</li> + <li>Jeffrey Seyfried</li> + <li>Jethro Beekman</li> + <li>John Kåre Alsaker</li> + <li>John Talling</li> + <li>Jonas Schievink</li> + <li>Jonathan S</li> + <li>Jose Narvaez</li> + <li>Josh Austin</li> + <li>Josh Stone</li> + <li>Joshua Holmer</li> + <li>JP Sugarbroad</li> + <li>jrburke</li> + <li>Kevin Butler</li> + <li>Kevin Yeh</li> + <li>Kohei Hasegawa</li> + <li>Kyle Mayes</li> + <li>Lee Jeffery</li> + <li>Manish Goregaokar</li> + <li>Marcell Pardavi</li> + <li>Markus Unterwaditzer</li> + <li>Martin Pool</li> + <li>Marvin Löbel</li> + <li>Matt Brubeck</li> + <li>Matthias Bussonnier</li> + <li>Matthias Kauer</li> + <li>mdinger</li> + <li>Michael Layzell</li> + <li>Michael Neumann</li> + <li>Michael Sproul</li> + <li>Michael Woerister</li> + <li>Mihaly Barasz</li> + <li>Mika Attila</li> + <li>mitaa</li> + <li>Ms2ger</li> + <li>Nicholas Mazzuca</li> + <li>Nick Cameron</li> + <li>Niko Matsakis</li> + <li>Ole Krüger</li> + <li>Oliver Middleton</li> + <li>Oliver Schneider</li> + <li>Ori Avtalion</li> + <li>Paul A. Jungwirth</li> + <li>Peter Atashian</li> + <li>Philipp Matthias Schäfer</li> + <li>pierzchalski</li> + <li>Ravi Shankar</li> + <li>Ricardo Martins</li> + <li>Ricardo Signes</li> + <li>Richard Diamond</li> + <li>Rizky Luthfianto</li> + <li>Ryan Scheel</li> + <li>Scott Olson</li> + <li>Sean Griffin</li> + <li>Sebastian Hahn</li> + <li>Sébastien Marie</li> + <li>Seo Sanghyeon</li> + <li>Simonas Kazlauskas</li> + <li>Simon Sapin</li> + <li>Stepan Koltsov</li> + <li>Steve Klabnik</li> + <li>Steven Fackler</li> + <li>Tamir Duberstein</li> + <li>Tobias Bucher</li> + <li>Toby Scrace</li> + <li>Tshepang Lekhonkhobe</li> + <li>Ulrik Sverdrup</li> + <li>Vadim Chugunov</li> + <li>Vadim Petrochenkov</li> + <li>William Throwe</li> + <li>xd1le</li> + <li>Xmasreturns</li> + </ul> + 2016-01-21T00:00:00+00:00 + + + Mozilla Addons Blog: Archiving AMO Stats + https://blog.mozilla.org/addons/2016/01/20/archiving-amo-stats/ + <p>One of the advantages of listing an add-on or theme on <a href="https://addons.mozilla.org" target="_blank">addons.mozilla.org</a> (AMO) is that you’ll get statistics on your add-on’s usage. These stats, which are covered by the <a href="https://www.mozilla.org/privacy/" target="_blank">Mozilla privacy policy</a>, provide add-on developers with information such as the number of downloads and daily users, among other insights.</p> + <p>Currently, the data that generates these statistics can go back as far as 2007, as we haven’t had an archiving policy. As a result, statistics take up the vast majority of disk space in our database and require a significant amount of processing and operations time. Statistics over a year old are very rarely accessed, and the value of their generation is very low, while the costs are increasing.</p> + <p>To reduce our operating and development costs, and increase the site’s reliability for developers, we are introducing an archiving policy.</p> + <p>In the coming weeks, statistics data <strong>over one year old</strong> will no longer be stored in the AMO database, and reports generated from them will no longer be accessible through AMO’s add-on statistics pages. Instead, the data will be archived and maintained as plain text files, which developers can download. We will write a follow-up post when these archives become available.</p> + <p>If you’ve chosen to keep your add-on’s statistics private, they will remain private when stats are archived. You can check your privacy settings by going to your add-on in the <a href="https://addons.mozilla.org/developers/addons" target="_blank">Developer Hub</a>, clicking on <strong>Edit Listing</strong>, and then <strong>Technical Details</strong>.</p> + <p><a href="https://blog.mozilla.org/addons/files/2016/01/Screenshot-2016-01-20-14.52.33.png"><img alt="editlisting" class="alignnone size-large wp-image-7645" height="389" src="https://blog.mozilla.org/addons/files/2016/01/Screenshot-2016-01-20-14.52.33-600x389.png" width="600" /></a></p> + <p>The total number of users and other cumulative counts on add-ons and themes will not be affected and these will continue to function.</p> + <p>If you have feedback or concerns, please head to our <a href="https://discourse.mozilla-community.org/t/archiving-of-add-on-statistics/6573" target="_blank">forum post</a> on this topic.</p> + 2016-01-20T23:54:09+00:00 + Andy McKay + + + Air Mozilla: The Joy of Coding - Episode 41 + https://air.mozilla.org/the-joy-of-coding-episode-41/ + <p> + <img alt="The Joy of Coding - Episode 41" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/cb/68/cb68b6ac48452be7e7f25ddc7b63c959.png" width="160" /> + mconley livehacks on real Firefox bugs while thinking aloud. + </p> + 2016-01-20T18:00:00+00:00 + Air Mozilla + + + Nathan Froyd: gecko and c++ onboarding presentation + https://blog.mozilla.org/nfroyd/2016/01/20/gecko-and-c-onboarding-presentation/ + <p>One of the things the Firefox team has been doing recently is having onboarding sessions for new hires. This onboarding currently covers:</p> + <ul> + <li>1st day setup</li> + <li>Bugzilla</li> + <li>Building Firefox</li> + <li>Desktop Firefox Architecture / Product</li> + <li>Communication and Community</li> + <li>Javascript and the DOM</li> + <li>C++ and Gecko</li> + <li>Shipping Software</li> + <li>Telemetry</li> + <li>Org structure and career development</li> + </ul> + <p>My first day consisted of some useful HR presentations and then I was given my laptop and a pointer to a wiki page on building Firefox. Needless to say, it took me a while to get started! It would have been super convenient to have an introduction to all the stuff above.</p> + <p>I’ve been asked to do the C++ and Gecko session three times. All of the sessions are open to whoever wants to come, not just the new hires, and I think yesterday’s session was easily the most well-attended yet: somewhere between 10 and 20 people showed up. Yesterday’s session was the first session where I made the slides available to attendees (should have been doing that from the start…) and it seemed equally useful to make the slides available to a broader audience as well. The <a href="https://docs.google.com/presentation/d/1ZHUkNzZK2TrF5_4MWd_lqEq7Ph5B6CDbNsizIkBxbnQ/edit?usp=sharing">Gecko and C++ Onboarding slides</a> are up now!</p> + <p>This presentation is a “living” presentation; it will get updated for future sessions with feedback and as I think of things that should have been in the presentation or better ways to set things up (some diagrams would be nice…). If you have feedback (good, bad, or ugly) on particular things in the slides or you have suggestions on what other things should be covered, please contact me! Next time I do this I’ll try to record the presentation so folks can watch that if they prefer.</p> + 2016-01-20T16:48:29+00:00 + Nathan Froyd + + + Andreas Gal: Brendan is back to save the Web + http://andreasgal.com/2016/01/20/brendan-is-back-to-save-the-web/ + <p class="p1">Brendan is <a href="https://github.com/brave">back</a>, and he has a <a href="http://brave.com/">plan</a> to save the Web. Its a big and bold plan, and it may just work. I am pretty excited about this. If you have 5 minutes to read along I’ll explain why I think you should be as well.</p> + <p class="p1"><strong>The Web is broken</strong></p> + <p class="p1">Lets face it, the Web today is a mess. Everywhere we go online we are constantly inundated with annoying ads. Often pages are more ads than content, and the more ads the industry throws at us, the more we ignore them, the more obnoxious ads get, trying to catch our attention. As Brendan explains in his blog post, the browser used to be on the user’s side—we call browsers the user agent for a reason. Part of the early success of Firefox was that it blocked popup ads. But somewhere over the last 10 years of modern Web browsers, browsers lost their way and stopped being the user’s agent alone. Why?</p> + <p class="p1"><strong>Browsers aren’t free</strong></p> + <p class="p1">Making a modern Web browser is not free. It takes hundreds of engineers to make a competitive modern browser engine. Someone has to pay for that, and that someone needs to have a reason to pay for it. Google doesn’t make Chrome for the good of mankind. Google makes Chrome so you can consume more Web and along with it, more Google ads. Each time you click on one, Google makes more money. Chrome is a billion dollar business for Google. And the same is true for pretty much every other browser. Every major browser out there is funded through advertisement. No browser maker can escape this dilemma. Maybe now you understand why no major browser ships with a builtin enabled by default ad-blocker, even though ad-blockers are by far the most popular add-ons.</p> + <p class="p1"><strong>Our privacy is at stake</strong></p> + <p class="p1">It’s not just the unregulated flood of advertisement that needs a solution. Every ad you see is often selected based on sensitive private information advertisement networks have extracted from your browsing behavior through tracking. Remember how the FBI used to track what books Americans read at the library, and it was a big scandal? Today the Googles and Facebooks of the world know almost every site you visit, everything you buy online, and they use this data to target you with advertisement. I am often puzzled why people are so afraid of the NSA spying on us but show so little concern about all the deeply personal data Google and Facebook are amassing about everyone.</p> + <p class="p1"><strong>Blocking alone doesn’t scale</strong></p> + <p class="p1">I wish the solution was as easy as just blocking all ads. There is a lot of great Web content out there: news, entertainment, educational content. It’s not free to make all this content, but we have gotten used to consuming it “for free”. Banning all ads without an alternative mechanism would break the economic backbone of the Web. This dilemma has existed for many years, and the big browser vendors seem to have given up on it. It’s hard to blame them. How do you disrupt the status quo without sawing off the (ad revenue) branch you are sitting on?</p> + <p class="p1"><strong>It takes an newcomer to fix this mess</strong></p> + <p class="p1">I think its unlikely that the incumbent browser vendors will make any bold moves to solve this mess. There is too much money at stake. I am excited to see a startup take a swipe at this problem, because they have little to lose (seed money aside). Brave is getting the user agent back into the game. Browsers have intentionally remained silent onlookers to the ad industry invading users’ privacy. With Brave, Brendan makes the user agent step up and fight for the user as it was always intended to do.</p> + <p class="p1">Brave basically consists of two parts: part one blocks third party ad content and tracking signals. Instead of these Brave inserts alternative ad content. Sites can sign up to get a fair share of any ads that Brave displays for them. The big change in comparison to the status quo is that the Brave user agent is in control and can regulate what you see. It’s like a speed limit for advertisement on the Web, with the goal to restore balance and give sites a fair way to monetize while giving the user control through the user agent.</p> + <p class="p1"><strong>Making money with a better Web</strong></p> + <p class="p1">The ironic part of Brave is that its for-profit. Brave can make money by reducing obnoxious ads and protecting your privacy at the same time. If Brave succeeds, it’s going to drain money away from the crappy privacy-invasive obnoxious advertisement world we have today, and publishers and sites will start transacting in the new Brave world that is regulated by the user agent. Brave will take a cut of these transactions. And I think this is key. It aligns the incentives right. The current funding structure of major browsers encourages them to keep things as they are. Brave’s incentive is to bring down the whole diseased temple and usher in a better Web. Exciting.</p> + <p class="p1"><strong>Quick update:</strong> I had a chance to look over the Brave GitHub repo. It looks like the Brave Desktop browser is based on Chromium, not Gecko. Yes, you read that right. <span style="text-decoration: underline;">Brave is using Google’s rendering engine, not Mozilla’s.</span> Much to write about this one, but it will definitely help Brave “hide” better in the large volume of Chrome users, making it harder for sites to identify and block Brave users. Brave for iOS seems to be a <span style="text-decoration: underline;">fork of Firefox for iOS, but it manages to block ads</span> (Mozilla says they can’t).</p><br />Filed under: <a href="http://andreasgal.com/category/mozilla/">Mozilla</a> <a href="http://feeds.wordpress.com/1.0/gocomments/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/godelicious/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/gofacebook/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/gotwitter/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/gostumble/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/godigg/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/goreddit/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andreasgal.wordpress.com/573/" /></a> <img alt="" border="0" height="1" src="http://pixel.wp.com/b.gif?host=andreasgal.com&amp;blog=891661&amp;post=573&amp;subd=andreasgal&amp;ref=&amp;feed=1" width="1" /> + 2016-01-20T16:00:00+00:00 + Andreas + + + Mike Taylor: 🙅 @media (-webkit-transform-3d) + https://miketaylr.com/posts/2016/01/at-media-webkit-transform-three-dee.html + <p><code>@media (-webkit-transform-3d)</code> is a funny thing that exists on the web.</p> + + <p>It's like, a <a href="https://drafts.csswg.org/mediaqueries-4/#mq-features">media query feature</a> in the form of a prefixed CSS property, which should tell you if your (once upon a time probably Safari-only) browser supports 3D transforms, invented back in the day before we had <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@supports"><code>@supports</code></a>.</p> + + <p>(According to <a href="https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariCSSRef/Articles/OtherStandardCSS3Features.html#//apple_ref/doc/uid/TP40007601-SW3">Apple docs</a> it first appeared in Safari 4, along side the other <code>-webkit-transition</code> and <code>-webkit-transform-2d</code> hybrid-media-query-feature-prefixed-css-properties-things that you should immediately forget exist.)</p> + + <p>Older versions of Modernizr <a href="https://github.com/Modernizr/Modernizr/blob/66c694d136241d356e0d24fcbaa5c068b0b0cdae/feature-detects/css/transforms3d.js#L26-L27">used this (and only this)</a> to detect support for 3D transforms, and that seemed pretty OK. (They also did the polite thing and tested <code>@media (transform-3d)</code>, but no browser has ever actually supported that, as it turns out). And because they're so consistently polite, they've since <a href="https://github.com/patrickkettner/Modernizr/commit/a54308e47e269a058472854b1ef417bd54f4e616">updated the test</a> to prefer <code>@supports</code> too (via a pull request from Edge developer Jacob Rossi).</p> + + <p>As it turns out other browsers have been <a href="http://caniuse.com/#feat=transforms3d">updated to support 3D CSS transforms</a>, but sites didn't go back and update their version of Modernizr. So unless you support <code>@media (-webkit-transform-3d)</code> these sites break. Niche websites like <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1239136">yahoo.com</a> and <a href="https://github.com/webcompat/web-bugs/issues/2151">about.com</a>.</p> + + <p>So, anyways. I added <a href="https://compat.spec.whatwg.org/#css-media-queries-webkit-transform-3d"><code>@media (-webkit-transform-3d)</code> to the Compat Standard</a> and we <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1239799">added support for it Firefox</a> so websites stop breaking.</p> + + <p>But you shouldn't ever use it—use <code>@supports</code>. In fact, don't even share this blog post. Maybe delete it from your browser history just in case.</p> + 2016-01-20T08:00:00+00:00 + Mike Taylor + + + Byron Jones: happy bmo push day! + https://globau.wordpress.com/2016/01/20/happy-bmo-push-day-166/ + <p>the following changes have been pushed to bugzilla.mozilla.org:</p> + <ul> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1236161" target="_blank">1236161</a>] when converting a BMP attachment to PNG fails a zero byte attachment is created</li> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1231918" target="_blank">1231918</a>] error handler doesn’t close multi-part responses</li> + </ul> + <p>discuss these changes on <a href="https://lists.mozilla.org/listinfo/tools-bmo" target="_blank">mozilla.tools.bmo</a>.</p><br />Filed under: <a href="https://globau.wordpress.com/category/mozilla/bmo/">bmo</a>, <a href="https://globau.wordpress.com/category/mozilla/">mozilla</a> <img alt="" border="0" height="1" src="https://pixel.wp.com/b.gif?host=globau.wordpress.com&amp;blog=25718030&amp;post=881&amp;subd=globau&amp;ref=&amp;feed=1" width="1" /> + 2016-01-20T07:33:46+00:00 + glob + + + Alex Johnson: Removing Honeycomb Code + https://www.alex-johnson.net/removing-honeycomb-code/ + <p>As an effort to reduce the APK size of Firefox for Android and to remove unnecessary code, I will be helping remove the Honeycomb code throughout the Fennec project. Honeycomb will not be supported since Firefox 46, so this code is not necessary. <br /> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1217675">Bug 1217675</a> will keep track of the progress. <br /> + Hopefully this will help reduce the APK size some and clean up the road for <a href="https://www.youtube.com/watch?v=NJ6kzW5t02Y">killing Gingerbread</a> hopefully sometime in the near future.</p> + 2016-01-20T04:59:34+00:00 + Alex Johnson + + + Brian R. Bondy: Brave Software + http://www.brianbondy.com/blog/172/brave-software + <p></p><p>Since June of last year, I’ve been co-founding a new startup called <a href="https://brave.com/">Brave Software</a> with <a href="https://en.wikipedia.org/wiki/Brendan_Eich">Brendan Eich</a>. + With our amazing team, we're developing something pretty epic.</p><p></p> + <p></p><p>We're building the next-generation of browsers for smartphones and laptops as part of our new ad-tech platform. + Our terms of use give our users control over their personal data by blocking ad trackers and third party cookies. + We re-integrate fewer and better ads directly into programmatic ad positions, paying revenue shares to users and publishers to support both of these essential parties in the web ecosystem.</p><p></p> + <p></p><p>Coming built in, we have new faster engines for tracking protection, ad block, HTTPS Everywhere, safe ads with rev-share, and more. + We're seeing massive web page load time speedups.</p><p></p> + + + <p></p><p>We're starting to bring people in for early developer build access on all platforms.</p><p></p> + <p></p><p>I’m happy to share that the browsers we’re developing were made fully open sourced. + We welcome contributors, and would love your help.</p><p></p> + <p></p><p>Some of the repositories include:</p><p></p> + <ul> + <li><a href="https://github.com/brave/browser-laptop">Brave OSX and Windows x64 browsers</a>: Prototyped as a Gecko based browser, but now replaced with a powerful new browser built on top of the electron framework. The electron framework is the same one in use by Slack and the Atom editor. It uses the latest libchromiumcontent and Node.</li> + <li><a href="https://github.com/brave/link-bubble">Brave for Android</a>: Formerly Link Bubble, working as a background service so you can use other apps as your pages load.</li> + <li><a href="https://github.com/brave/browser-ios">Brave for iOS</a>: Originally forked from Firefox for iOS but with all of the built-in greatness described above.</li> + <li>And many others: Website, updater code, vault, electron fork, and others.</li> + </ul> + 2016-01-20T00:00:00+00:00 + Brian R. Bondy + + + James Socol: PIEfection Slides Up + http://coffeeonthekeyboard.com/piefection-slides-up/ + <p>I put <a href="https://github.com/jsocol/talks/tree/master/2016-01-13-manhattanjs-pie">the slides for my ManhattanJS talk, "PIEfection"</a> up on GitHub the other day (sans images, but there are links in the source for all of those).</p> + + <p>I completely neglected to talk about the <a href="https://en.wikipedia.org/wiki/Maillard_reaction">Maillard reaction</a>, which is responsible for food tasting good, and specifically for browning pie crusts. tl;dr: Amino acid (protein) + sugar + ~300°F (~150°C) = delicious. There are innumerable and poorly understood combinations of amino acids and sugars, but this class of reaction is responsible for everything from searing stakes to browning crusts to toasting marshmallows.</p> + + <p>Above ~330°F, you get caramelization, which is also a delicious part of the pie and crust, but you don't want to overdo it. Starting around ~400°F, you get pyrolysis (burning, charring, carbonization) and below 285°F the reaction won't occur (at least not quickly) so you won't get the delicious compounds.</p> + + <p>(All of these are, of course, temperatures measured in the material, not in the air of the oven.)</p> + + <p>So, instead of an egg wash on your top crust, try whole milk, which has more sugar to react with the gluten in the crust.</p> + + <p>I also didn't get a chance to mention a rolling technique I use, that I learned from a <a href="https://www.facebook.com/ellenspirerstaffing">cousin of mine</a>, in whose baking shadow I happily live.</p> + + <p>When rolling out a crust after it's been in the fridge, first roll it out in a long stretch, then fold it in thirds; do it again; then start rolling it out into a round. Not only do you add more layer structure (mmm, flaky, delicious layers) but it'll fill in the cracks that often form if you try to roll it out directly, resulting in a stronger crust.</p> + + <p>Those <a href="http://www.amazon.com/Cheese-Shaker-Pepper-Perforated-Stainless/dp/B007T40P28/ref=sr_1_1?ie=UTF8&amp;qid=1453236391&amp;sr=8-1&amp;keywords=pizza+shaker">pepper flake shakers</a>, filled with flour, are a great way to keep adding flour to the workspace without worrying about your buttery hands.</p> + + <p>For transferring the crust to the pie plate, try rolling it up onto your rolling pin and unrolling it on the plate. <a href="http://www.amazon.com/Ateco-20-Inch-Length-French-Rolling/dp/B000KESQ1G">Tapered (or "French") rolling pins</a> (or wine bottle) are particularly good at this since they don't have moving parts.</p> + + <p>Finally, thanks again to <a href="https://twitter.com/renrutnnej">Jenn</a> for helping me get pies from one island to another. It would not have been possible without her!</p> + 2016-01-19T20:45:34+00:00 + James Socol + + + Air Mozilla: Reprendre le contrôle de sa vie privée sur Internet + https://air.mozilla.org/reprendre-le-controle-de-sa-vie-privee-sur-internet/ + <p> + <img alt="Reprendre le contrôle de sa vie privée sur Internet" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/be/f6/bef62897fb87e08dc8392fe61d10bcfa.png" width="160" /> + L'omniprésence des réseaux sociaux, des moteurs de recherches et de la publicité est-elle compatible avec notre droit à la vie privée ? + </p> + 2016-01-19T18:00:00+00:00 + Air Mozilla + + + Myk Melez: New Year, New Blogware + https://mykzilla.org/2016/01/19/new-year-new-blogware/ + <p>Four score and many moons ago, I decided to move this blog from Blogger to WordPress. The transition took longer than expected, but it’s finally done.</p> + <p>If you’ve been following along at the old address, <a href="https://mykzilla.blogspot.com/">https://mykzilla.blogspot.com/</a>, now’s the time to update your address book! If you’ve been going to <a href="https://mykzilla.org/">https://mykzilla.org/</a>, however, or you read the blog on <a href="http://planet.mozilla.org/">Planet Mozilla</a>, then there’s nothing to do, as that’s the new address, and Planet Mozilla has been updated to syndicate posts from it.</p> + 2016-01-19T16:56:05+00:00 + Myk Melez + + + Michael Kohler: Mozillas strategische Leitlinien für 2016 und danach + https://michaelkohler.info/2016/mozillas-strategische-leitlinien-fur-2016-und-danach + <p>Dieser Beitrag wurde zuerst im Blog auf<a href="https://blog.mozilla.org/community"> https://blog.mozilla.org/community</a> veröffentlicht. Herzlichen Dank an Aryx und Coce für die Übersetzung!</p> + <p>Auf der ganzen Welt arbeiten leidenschaftliche Mozillianer am Fortschritt für Mozillas Mission. Aber fragt man fünf verschiedene Mozillianer, was die Mission ist, erhält man womöglich sieben verschiedene Antworten.</p> + <p>Am Ende des letzten Jahres legte Mozillas CEO Chris Beard klare Vorstellungen über Mozillas Mission, Vision und Rolle dar und zeigte auf, wie unsere Produkte uns diesem Ziel in den nächsten fünf Jahren näher bringen. Das Ziel dieser strategischen Leitlinien besteht darin, für Mozilla insgesamt ein prägnantes, gemeinsames Verständnis unserer Ziele zu entwickeln, die uns als Individuen das Treffen von Entscheidungen und Erkennen von Möglichkeiten erleichtert, mit denen wir Mozilla voranbringen.</p> + <p>Mozillas Mission können wir nicht alleine erreichen. Die Tausenden von Mozillianern auf der ganzen Welt müssen dahinter stehen, damit wir zügig und mit lauterer Stimme als je zuvor Unglaubliches erreichen können.</p> + <p>Deswegen ist eine der sechs<a href="https://docs.google.com/presentation/d/1A3Ma9gNawAYYGbYC2bUW0wUwcpHuvyMiZvHNiMLriw0/edit#slide=id.gdaa7a0bd0_1_0"> strategischen Initiativen</a> des Participation Teams für die erste Jahreshälfte, möglichst viele Mozillianer über diese Leitlinien aufzuklären, damit wir 2016 den bisher wesentlichsten Einfluss erzielen können. Wir werden einen weiteren Beitrag veröffentlichen, der sich näher mit der Strategie des Participation Teams für das Jahr 2016 befassen wird.</p> + <p><img alt="" class="alignnone" height="335" src="https://ffp4g1ylyit3jdyti1hqcvtb-wpengine.netdna-ssl.com/community/files/2016/01/Screen-Shot-2015-12-18-at-2.02.07-PM-600x335.png" width="600" /></p> + <p>Das Verstehen dieser Strategie wird unabdingbar sein für jeden, der bei Mozilla in diesem Jahr etwas bewirken möchte, denn sie wird bestimmen, wofür wir eintreten, wo wir unsere Ressourcen einsetzen und auf welche Projekte wir uns 2016 konzentrieren werden.</p> + <p>Zu Jahresbeginn werden wir näher auf diese Strategie eingehen und weitere Details dazu bekanntgeben, wie die diversen Teams und Projekte bei Mozilla auf diese Ziele hinarbeiten.</p> + <p>Der aktuelle Aufruf zum Handeln besteht darin, im Kontext Ihrer Arbeit über diese Ziele nachzudenken und darüber, wie Sie im kommenden Jahr bei Mozilla mitwirken möchten. Dies hilft, Ihre Innovationen, Ambitionen und Ihren Einfluss im Jahr 2016 zu gestalten.</p> + <p>Wir hoffen, dass Sie mitdiskutieren und Ihre Fragen, Kommentare und Pläne für das Vorantreiben der strategischen Leitlinien im Jahr 2016<a href="https://discourse.mozilla-community.org/t/mozillas-strategic-narrative-2016/6397"> hier</a> auf Discourse teilen und Ihre Gedanken auf Twitter mit dem Hashtag <a href="https://twitter.com/search?q=%23mozilla2016strategy&amp;src=typd">#Mozilla2016Strategy</a> mitteilen.</p> + <p> </p> + <h3>Mission, Vision &amp; Strategie</h3> + <p><b>Unsere Mission</b></p> + <p>Dafür zu sorgen, dass das Internet eine weltweite öffentliche Ressource ist, die allen zugänglich ist.</p> + <p><b>Unsere Vision</b></p> + <p>Ein Internet, für das Menschen tatsächlich an erster Stelle stehen. Ein Internet, in dem Menschen ihr eigenes Erlebnis gestalten können. Ein Internet, in dem die Menschen selbst entscheiden können sowie sicher und unabhängig sind.</p> + <p><b>Unsere Rolle</b></p> + <p>Mozilla setzt sich im wahrsten Sinne des Wortes in Ihrem Online-Leben für Sie ein. Wir setzen uns für Sie ein, sowohl in Ihrem Online-Erlebnis als auch für Ihre Interessen beim Zustand des Internets.</p> + <p><b>Unsere Arbeit</b></p> + <p>Unsere Säulen</p> + <ol> + <li><b>Produkte:</b> Wir entwickeln Produkte mit Menschen im Mittelpunkt sowie Bildungsprogramme, mit deren Hilfe Menschen online ihr gesamtes Potential ausschöpfen können.</li> + <li><b>Technologie:</b> Wir entwickeln robuste technische Lösungen, die das Internet über verschiedene Plattformen hinweg zum Leben erwecken.</li> + <li><b>Menschen:</b> Wir entwickeln Führungspersonen und Mitwirkende in der Gemeinschaft, die das Internet erfinden, gestalten und verteidigen.</li> + </ol> + <p>Wir wir positive Veränderungen in Zukunft anpacken wollen</p> + <p>Die Arbeitsweise ist ebensowichtig wie das Ziel. Unsere Gesundheit und bleibender Einfluss hängen davon ab, wie sehr unsere Produkte und Aktivitäten:</p> + <ol> + <li>Interoperabilität, Open Source und offene Standards fördern,</li> + <li>Gemeinschaften aufbauen und fördern,</li> + <li>Für politische Veränderungen und rechtlichen Schutz eintreten sowie</li> + <li>Netzbürger bilden und einbeziehen.</li> + </ol> + <p> </p> + <img alt="" height="0" src="http://piwik.michaelkohler.info/piwik.php?idsite=1&amp;rec=1&amp;url=https%3A%2F%2Fmichaelkohler.info%2F2016%2Fmozillas-strategische-leitlinien-fur-2016-und-danach&amp;action_name=Mozillas+strategische+Leitlinien+f%C3%BCr+2016+und+danach&amp;urlref=https%3A%2F%2Fmichaelkohler.info%2Ffeed" style="border: 0; width: 0; height: 0;" width="0" /> + 2016-01-19T15:27:24+00:00 + Michael Kohler + + + David Lawrence: happy bmo push day! + https://dlawrence.wordpress.com/2016/01/19/happy-bmo-push-day-3/ + <p>the following changes have been pushed to bugzilla.mozilla.org:</p> + <ul> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1238573" target="_blank">1238573</a>] Change label of “New Bug” menu to “New/Clone Bug”</li> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1239065" target="_blank">1239065</a>] Project Kickoff Form: Adjustments needed to Mozilla Infosec review portion</li> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1240157" target="_blank">1240157</a>] Fix a typo in bug.rst</li> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1236461" target="_blank">1236461</a>] Mass update mozilla-reps group</li> + </ul> + <p>discuss these changes on <a href="https://lists.mozilla.org/listinfo/tools-bmo" target="_blank">mozilla.tools.bmo</a>.</p><br /> <a href="http://feeds.wordpress.com/1.0/gocomments/dlawrence.wordpress.com/27/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dlawrence.wordpress.com/27/" /></a> <img alt="" border="0" height="1" src="https://pixel.wp.com/b.gif?host=dlawrence.wordpress.com&amp;blog=58816&amp;post=27&amp;subd=dlawrence&amp;ref=&amp;feed=1" width="1" /> + 2016-01-19T14:49:59+00:00 + dlawrence + + + Soledad Penades: Hardware Hack Day @ MozLDN, 1 + http://soledadpenades.com/2016/01/19/hardware-hack-day-mozldn-1/ + <p>Last week we ran an internal “hack day” here at the Mozilla space in London. It was just a bunch of <em>software</em> engineers looking at various <em>hardware</em> boards and things and learning about them <img alt=":-)" class="wp-smiley" src="http://soledadpenades.com/wp-includes/images/smilies/simple-smile.png" style="height: 1em;" /></p> + <p>Here’s what we did!</p> + <h3><a href="http://soledadpenades.com/">Sole</a></h3> + <p>I essentially <a href="http://soledadpenades.com/2016/01/19/kind-of-bricking-an-arduino-duemilanove-by-exhausting-its-memory/">kind of bricked my Arduino Duemilanove</a> trying to get it working with Johnny Five, but it was fine–apparently there’s a way to recover it using another Arduino, and someone offered to help with that in the next <a href="http://www.meetup.com/NodeBots-of-London/events/227890374/">NodeBots</a> London, which I’m going to attend.</p> + <h3><a href="http://ardeenelinfierno.com/">Francisco</a></h3> + <p>Thinks he’s having issues with cables. It seems like the boards are not reset automatically by the Arduino IDE nowadays? He found the button in the board actually resets the board when pressed i.e. it’s the RESET button.</p> + <p>On the Raspberry Pi side of things, he was very happy to put all his old-school Linux skills in action configuring network interfaces without GUIs!</p> + <h3><a href="http://gu.illau.me/">Guillaume</a></h3> + <p>Played with mDNS advertising and listening to services on Raspberry Pi.</p> + <p>(He was very quiet)</p> + <p>(He also built a very nice LEGO case for the Raspberry Pi, but I do not have a picture, so just imagine it).</p> + <h3><a href="http://wilsonpage.co.uk/">Wilson</a></h3> + <blockquote><p> + Wilson: “I got my Raspberry Pi on the Wi-Fi”</p> + <p>Francisco: “Sorry?”</p> + <p>Wilson: “I mean, you got my Raspberry Pi on the network. And now I’m trying to build a web app on the Pi…”</p></blockquote> + <h3><a href="http://chrislord.net/">Chris</a></h3> + <p>Exploring the Pebble with Linux. There’s a libpebble, and he managed to connect…</p> + <p><del datetime="2016-01-20T11:22:33+00:00"><em><small>(sorry, I had to leave early so I do not know what else did Chris do!)</small></em></del></p> + <p>Updated, 20 January: Chris told me he just managed to successfully connect to the Pebble watch using the bluetooth WebAPI. It requires two Gecko patches (one regression patch and one obvious logic error that he hasn’t filed yet). PROGRESS!</p> + <p>~~~</p> + <p>So as you can see we didn’t really get super far in just a day, and I even ended up with unusable hardware. BUT! we all learned something, and next time we know what NOT to do (or at least I DO KNOW what NOT to do!).</p> + <p><a href="http://soledadpenades.com/?flattrss_redirect&amp;id=6335&amp;md5=40427d69faa3b9c2d1530732fd78e66d" target="_blank" title="Flattr"><img alt="flattr this!" src="http://soledadpenades.com/wp-content/plugins/flattr/img/flattr-badge-large.png" /></a></p> + 2016-01-19T13:31:55+00:00 + sole + + + Daniel Stenberg: “Subject: Urgent Warning” + http://daniel.haxx.se/blog/2016/01/19/subject-urgent-warning/ + <p>Back in December I got a desperate email from this person. A woman who said her Instagram had been hacked and since she found my contact info in the app she mailed me and asked for help. I of course replied and said that I have nothing to do with her being hacked but I also have nothing to do with Instagram other than that they use software I’ve written.</p> + <p>Today she writes back. Clearly not convinced I told the truth before, and now she strikes back with more “evidence” of my wrongdoings.</p> + <p><em>Dear Daniel,</em></p> + <p><em>I had emailed you a couple months ago about my “screen dumps” aka screenshots and asked for your help with restoring my Instagram account since it had been hacked, my photos changed, and your name was included in the coding. You claimed to have no involvement whatsoever in developing a third party app for Instagram and could not help me salvage my original Instagram photos, pre-hacked, despite Instagram serving as my Photography portfolio and my career is a Photographer.</em></p> + <p><em>Since you weren’t aware that your name was attached to Instagram related hacking code, I thought you might want to know, in case you weren’t already aware, that your name is also included in Spotify terms and conditions. I came across this information using my Spotify which has also been hacked into and would love your help hacking out of Spotify. Also, I have yet to figure out how to unhack the hackers from my Instagram so if you change your mind and want to restore my Instagram to its original form as well as help me secure my account from future privacy breaches, I’d be extremely grateful. As you know, changing my passwords did nothing to resolve the problem. Please keep in mind that Facebook owns Instagram and these are big companies that you likely don’t want to have a trail of evidence that you are a part of an Instagram and Spotify hacking ring. Also, Spotify is a major partner of Spotify so you are likely familiar with the coding for all of these illegally developed third party apps. I’d be grateful for your help fixing this error immediately.</em></p> + <p><em>Thank you,</em></p> + <p>[name redacted]</p> + <p><em>P.S. Please see attached screen dump for a screen shot of your contact info included in Spotify (or what more likely seems to be a hacked Spotify developed illegally by a third party).</em></p> + <p><a href="http://daniel.haxx.se/blog/wp-content/uploads/2016/01/IMG_7393.png" rel="attachment wp-att-8545"><img alt="Spotify credits screenshot" class="aligncenter size-medium wp-image-8545" height="450" src="http://daniel.haxx.se/blog/wp-content/uploads/2016/01/IMG_7393-253x450.png" width="253" /></a></p> + <p>Here’s the Instagram screenshot she sent me in a previous email:</p> + <p><a href="http://daniel.haxx.se/blog/wp-content/uploads/2016/01/IMG_2156.jpg" rel="attachment wp-att-8546"><img alt="Instagram credits screenshot" class="aligncenter size-medium wp-image-8546" height="450" src="http://daniel.haxx.se/blog/wp-content/uploads/2016/01/IMG_2156-253x450.jpg" width="253" /></a></p> + <p>I’ve tried to respond with calm and clear reasonable logic and technical details on why she’s seeing my name there. That clearly failed. What do I try next?</p> + 2016-01-19T08:37:32+00:00 + Daniel Stenberg + + + Emily Dunham: How much knowledge do you need to give a conference talk? + http://edunham.net/2016/01/19/how_much_knowledge_do_you_need_to_give_a_conference_talk.html + <h3>How much knowledge do you need to give a conference talk?</h3> + <p>I was recently asked an excellent question when I promoted the <a class="reference external" href="http://www.linuxfestnorthwest.org/2016/present">LFNW CFP</a> on + IRC:</p> + <blockquote> + <div>As someone who has never done a talk, but wants to, what kind of knowledge + do you need about a subject to give a talk on it?</div></blockquote> + <p>If you answer “yes” to any of the following questions, you know enough to + propose a talk:</p> + <ul class="simple"> + <li>Do you have a <strong>hobby</strong> that most tech people aren’t experts on? Talk + about applying a lesson or skill from that hobby to tech! For instance, I + turned a habit of reading about psychology into my <a class="reference external" href="http://talks.edunham.net/scale13x/#1">Human Hacking</a> talk.</li> + <li>Have you ever spent a bunch of hours forcing two tools to work with each + other, because the documentation wasn’t very helpful and Googling didn’t get + you very far, and built something useful? “How to build ___ with ___” makes + a catchy talk title, if the <strong>thing you built</strong> solves a common problem.</li> + <li>Have you ever had a mentor sit down with you and explain a tool or + technique, and the new understanding improved the quality of your work or + code? Passing along useful <strong>lessons from your mentors</strong> is a valuable talk, + because it allows others to benefit from the knowledge without taking as + much of your mentor’s time.</li> + <li>Have you seen a dozen newbies ask the same question over the course of a few + months? When your <strong>answer to a common question</strong> starts to feel like a + broken record, it’s time to compose it into a talk then link the newbies to + your slides or recording!</li> + <li>Have you taken a really <strong>interesting class</strong> lately? Can you distill part of it + into a 1-hour lesson that would appeal to nerds who don’t have the time or + resources to take the class themselves? (thanks <a class="reference external" href="http://lucywyman.me/">lucyw</a> for adding this to + the list!)</li> + <li>Have you built a cool thing that over a dozen other people use? A <strong>tutorial + talk</strong> can not only expand your community, but its recording can augment your + documentation and make the project more accessible for those who prefer to + learn directly from humans!</li> + <li>Did you benefit from a really great introductory talk when you were learning + a tool? Consider doing your own tutorial! Any conference with beginners in + their target audience needs at least one Git lesson, an IRC talk, and some + discussions of how to use basic Unix utilities. These <strong>introductory talks</strong> + are actually better when given by someone who learned the technology + relatively recently, because newer users remember what it’s like not to know + how to use it. Just remember to have a more expert user look over your slides + before you present, in case you made an incorrect assumption about the tool’s + more advanced functionality.</li> + </ul> + <p>I personally try to propose talks I want to hear, because the dealine of a + CFP or conference is great motivation to prioritize a cool project over + ordinary chores.</p> + 2016-01-19T08:00:00+00:00 + + + QMO: Aurora 45.0 Testday Results + https://quality.mozilla.org/2016/01/aurora-45-0-testday-results/ + <p>Howdy mozillians!</p> + <p>Last week – on <em>Friday, January 15th</em> – we held <a href="https://quality.mozilla.org/2016/01/firefox-45-0-aurora-testday-january-15th/">Aurora 45.0 Testday</a>; and, of course, it was another outstanding event!</p> + <p><strong>Thank you</strong> all – <span class="author-a-oz90z4z89zz89za7qfz70zda5z87zxz85z i"><i>Mahmoudi Dris, Iryna Thompson, Chandrakant Dhutadmal, Preethi Dhinesh, Moin Shaikh, Ilse Macías, Hossain Al Ikram, Rezaul Huque Nayeem, Tahsan Chowdhury Akash, Kazi Nuzhat Tasnem, Fahmida Noor, Tazin Ahmed, Md. Ehsanul Hassan, Mohammad Maruf Islam, Kazi Sakib Ahmad, Khalid Syfullah Zaman, Asiful Kabir, Tabassum Mehnaz, Hasibul Hasan, Saddam Hossain, Mohammad Kamran Hossain, Amlan Biswas, Fazle Rabbi, Mohammed Jawad Ibne Ishaque, Asif Mahmud Shuvo, Nazir Ahmed Sabbir, Md. Raihan Ali, Md. Almas Hossain, Sadik Khan, Md. Faysal Alam Riyad, Faisal Mahmud, Md. Oliullah Sizan, Asif Mahmud Rony, Forhad Hossain </i>and<i> Tanvir Rahman </i></span>– for the participation!</p> + <p>A big <strong>thank you</strong> to all our active moderators too!</p> + <p><span style="color: #333333;"><span style="font-family: 'Open Sans', sans-serif;"><span style="font-size: medium;"><u>Results:</u></span></span></span></p> + <ul> + <li><span style="color: #333333;"><span style="font-family: 'Open Sans', sans-serif;"><span style="font-size: medium;"><strong>15</strong> issues were verified: </span></span></span><span style="color: #333333;"><span style="font-family: 'Open Sans', sans-serif;"><span style="font-size: medium;"> <span style="font-weight: 400;"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1235821">1235821</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1228518">1228518</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1165637">1165637</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1232647">1232647</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1235379">1235379</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=842356">842356</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1222971">1222971</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=915962">915962</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1180761">1180761</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1218455">1218455</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1222747">1222747</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1210752">1210752</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1198450">1198450</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1222820">1222820</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1225514">1225514</a></span></span></span></span></li> + <li><strong>1</strong> bug was triaged: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1230789"><span style="font-weight: 400;">1230789</span></a></li> + <li>some failures were mentioned for <i>Search Refactoring </i>feature in the etherpads (<a href="https://public.etherpad-mozilla.org/p/testday-20160115">link 1</a> and <a href="https://public.etherpad-mozilla.org/p/bangladesh.testday-15012016">link 2</a>); please feel free to add the requested details in the etherpads or, even better, join us on <a href="http://widget01.mibbit.com/?server=irc.mozilla.org&amp;channel=%23qa" target="_blank">#qa IRC channel</a> and let’s figure them out</li> + </ul> + <p>I <strong>strongly</strong> advise everyone of you to reach out to us, the moderators, via <a href="http://widget01.mibbit.com/?server=irc.mozilla.org&amp;channel=%23qa">#qa</a> during the events when you encountered any kind of failures. Keep up the great work! \o/</p> + <p>And keep an eye on QMO for upcoming events! <img alt="😉" class="wp-smiley" src="https://s.w.org/images/core/emoji/72x72/1f609.png" style="height: 1em;" /></p> + 2016-01-19T07:51:57+00:00 + Alexandra Lucinet + + + Eitan Isaacson: It’s MLK Day and It’s Not Too Late to Do Something About It + http://blog.monotonous.org/2016/01/18/its-mlk-day-and-its-not-too-late-to-do-something-about-it/ + <p>For the last three years I have had the opportunity to send out a reminder to Mozilla staff that Martin Luther King Jr. Day is coming up, and that U.S. employees get the day off. It has turned into my MLK Day eve ritual. I read his letters, listen to speeches, and then I compose a belabored paragraph about Dr. King with some choice quotes.</p> + <p>If you didn’t get a chance to celebrate Dr. King’s legacy and the movements he was a part of, you still have a chance:</p> + <ul> + <li>Watch <a href="http://www.imdb.com/title/tt1020072/" target="_blank">Selma.</a></li> + <li>Watch <a href="http://www.imdb.com/title/tt1592527/" target="_blank">The Black Power Mixtape</a> (it’s on Netflix).</li> + <li>Read <a href="http://www.africa.upenn.edu/Articles_Gen/Letter_Birmingham.html" target="_blank">A Letter from a Birmingham Jail</a> (it’s really really good).</li> + <li>Listen to his speech <a href="https://www.youtube.com/watch?v=3Qf6x9_MLD0" target="_blank">Beyond Vietnam</a>.</li> + <li>Listen to his last speech <a href="https://www.youtube.com/watch?v=IDl84vusXos" target="_blank">I Have Been To The Mountaintop</a>.</li> + </ul><br /> <a href="http://feeds.wordpress.com/1.0/gocomments/blogdotmonotonousdotorg.wordpress.com/678/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogdotmonotonousdotorg.wordpress.com/678/" /></a> <img alt="" border="0" height="1" src="http://pixel.wp.com/b.gif?host=blog.monotonous.org&amp;blog=34885741&amp;post=678&amp;subd=blogdotmonotonousdotorg&amp;ref=&amp;feed=1" width="1" /> + 2016-01-18T23:35:19+00:00 + Eitan + + + Nick Cameron: Libmacro + http://www.ncameron.org/blog/libmacro/ + <p>As I outlined in an <a href="http://ncameron.org/blog/procedural-macros-framework/">earlier post</a>, libmacro is a new crate designed to be used by procedural macro authors. It provides the basic API for procedural macros to interact with the compiler. I expect higher level functionality to be provided by library crates. In this post I'll go into a bit more detail about the API I think should be exposed here.</p> + + <p>This is a lot of stuff. I've probably missed something. If you use syntax extensions today and do something with libsyntax that would not be possible with libmacro, please let me know!</p> + + <p>I previously introduced <code>MacroContext</code> as one of the gateways to libmacro. All procedural macros will have access to a <code>&amp;mut MacroContext</code>.</p> + + <h3>Tokens</h3> + + <p>I described the <code>tokens</code> module in the last post, I won't repeat that here.</p> + + <p>There are a few more things I thought of. I mentioned a <code>TokenStream</code> which is a sequence of tokens. We should also have <code>TokenSlice</code> which is a borrowed slice of tokens (the slice to <code>TokenStream</code>'s <code>Vec</code>). These should implement the standard methods for sequences, in particular they support iteration, so can be <code>map</code>ed, etc.</p> + + <p>In the earlier blog post, I talked about a token kind called <code>Delimited</code> which contains a delimited sequence of tokens. I would like to rename that to <code>Sequence</code> and add a <code>None</code> variant to the <code>Delimiter</code> enum. The <code>None</code> option is so that we can have blocks of tokens without using delimiters. It will be used for noting unsafety and other properties of tokens. Furthermore, it is useful for macro expansion (replacing the interpolated AST tokens currently present). Although <code>None</code> blocks do not affect scoping, they do affect precedence and parsing.</p> + + <p>We should provide API for creating tokens. By default these have no hygiene information and come with a span which has no place in the source code, but shows the source of the token to be the procedural macro itself (see below for how this interacts with expansion of the current macro). I expect a <code>make_</code> function for each kind of token. We should also have API for creating macros in a given scope (which do the same thing but with provided hygiene information). This could be considered an over-rich API, since the hygiene information could be set after construction. However, since hygiene is fiddly and annoying to get right, we should make it as easy as possible to work with.</p> + + <p>There should also be a function for creating a token which is just a fresh name. This is useful for creating new identifiers. Although this can be done by interning a string and then creating a token around it, it is used frequently enough to deserve a helper function.</p> + + <h3>Emitting errors and warnings</h3> + + <p>Procedural macros should report errors, warnings, etc. via the <code>MacroContext</code>. They should avoid panicking as much as possible since this will crash the compiler (once <code>catch_panic</code> is available, we should use it to catch such panics and exit gracefully, however, they will certainly still meaning aborting compilation).</p> + + <p>Libmacro will 're-export' <code>DiagnosticBuilder</code> from <a href="https://dxr.mozilla.org/rust/source/src/libsyntax/errors/mod.rs">syntax::errors</a>. I don't actually expect this to be a literal re-export. We will use libmacro's version of <code>Span</code>, for example.</p> + + <pre><code>impl MacroContext { + pub fn struct_error(&amp;self, &amp;str) -&gt; DiagnosticBuilder; + pub fn error(&amp;self, Option&lt;Span&gt;, &amp;str); + } + + pub mod errors { + pub struct DiagnosticBuilder { ... } + impl DiagnosticBuilder { ... } + pub enum ErrorLevel { ... } + } + </code></pre> + + <p>There should be a macro <code>try_emit!</code>, which reduces a <code>Result&lt;T, ErrStruct&gt;</code> to a T or calls <code>emit()</code> and then calls <code>unreachable!()</code> (if the error is not fatal, then it should be upgraded to a fatal error).</p> + + <h3>Tokenising and quasi-quoting</h3> + + <p>The simplest function here is <code>tokenize</code> which takes a string (<code>&amp;str</code>) and returns a <code>Result&lt;TokenStream, ErrStruct&gt;</code>. The string is treated like source text. The success option is the tokenised version of the string. I expect this function must take a <code>MacroContext</code> argument.</p> + + <p>We will offer a quasi-quoting macro. This will return a <code>TokenStream</code> (in contrast to today's quasi-quoting which returns AST nodes), to be precise a <code>Result&lt;TokenStream, ErrStruct&gt;</code>. The string which is quoted may include metavariables (<code>$x</code>), and these are filled in with variables from the environment. The type of the variables should be either a <code>TokenStream</code>, a <code>TokenTree</code>, or a <code>Result&lt;TokenStream, ErrStruct&gt;</code> (in this last case, if the variable is an error, then it is just returned by the macro). For example,</p> + + <pre><code>fn foo(cx: &amp;mut MacroContext, tokens: TokenStream) -&gt; TokenStream { + quote!(cx, fn foo() { $tokens }).unwrap() + } + </code></pre> + + <p>The <code>quote!</code> macro can also handle multiple tokens when the variable corresponding with the metavariable has type <code>[TokenStream]</code> (or is dereferencable to it). In this case, the same syntax as used in macros-by-example can be used. For example, if <code>x: Vec&lt;TokenStream&gt;</code> then <code>quote!(cx, ($x),*)</code> will produce a <code>TokenStream</code> of a comma-separated list of tokens from the elements of <code>x</code>.</p> + + <p>Since the <code>tokenize</code> function is a degenerate case of quasi-quoting, an alternative would be to always use <code>quote!</code> and remove <code>tokenize</code>. I believe there is utility in the simple function, and it must be used internally in any case.</p> + + <p>These functions and macros should create tokens with spans and hygiene information set as described above for making new tokens. We might also offer versions which takes a scope and uses that as the context for tokenising.</p> + + <h3>Parsing helper functions</h3> + + <p>There are some common patterns for tokens to follow in macros. In particular those used as arguments for attribute-like macros. We will offer some functions which attempt to parse tokens into these patterns. I expect there will be more of these in time; to start with:</p> + + <pre><code>pub mod parsing { + // Expects `(foo = "bar"),*` + pub fn parse_keyed_values(&amp;TokenSlice, &amp;mut MacroContext) -&gt; Result&lt;Vec&lt;(InternedString, String)&gt;, ErrStruct&gt;; + // Expects `"bar"` + pub fn parse_string(&amp;TokenSlice, &amp;mut MacroContext) -&gt; Result&lt;String, ErrStruct&gt;; + } + </code></pre> + + <p>To be honest, given the token design in the last post, I think <code>parse_string</code> is unnecessary, but I wanted to give more than one example of this kind of function. If <code>parse_keyed_values</code> is the only one we end up with, then that is fine.</p> + + <h3>Pattern matching</h3> + + <p>The goal with the pattern matching API is to allow procedural macros to operate on tokens in the same way as macros-by-example. The pattern language is thus the same as that for macros-by-example.</p> + + <p>There is a single macro, which I propose calling <code>matches</code>. Its first argument is the name of a <code>MacroContext</code>. Its second argument is the input, which must be a <code>TokenSlice</code> (or dereferencable to one). The third argument is a pattern definition. The macro produces a <code>Result&lt;T, ErrStruct&gt;</code> where <code>T</code> is the type produced by the pattern arms. If the pattern has multiple arms, then each arm must have the same type. An error is produced if none of the arms in the pattern are matched.</p> + + <p>The pattern language follows the language for defining macros-by-example (but is slightly stricter). There are two forms, a single pattern form and a multiple pattern form. If the first character is a <code>{</code> then the pattern is treated as a multiple pattern form, if it starts with <code>(</code> then as a single pattern form, otherwise an error (causes a panic with a <code>Bug</code> error, as opposed to returning an <code>Err</code>).</p> + + <p>The single pattern form is <code>(pattern) =&gt; { code }</code>. The multiple pattern form is <code>{(pattern) =&gt; { code } (pattern) =&gt; { code } ... (pattern) =&gt; { code }}</code>. <code>code</code> is any old Rust code which is executed when the corresponding pattern is matched. The pattern follows from macros-by-example - it is a series of characters treated as literals, meta-variables indicated with <code>$</code>, and the syntax for matching multiple variables. Any meta-variables are available as variables in the righthand side, e.g., <code>$x</code> becomes available as <code>x</code>. These variables have type <code>TokenStream</code> if they appear singly or <code>Vec&lt;TokenStream&gt;</code> if they appear multiply (or <code>Vec&lt;Vec&lt;TokenStream&gt;&gt;</code> and so forth).</p> + + <p>Examples:</p> + + <pre><code>matches!(cx, input, (foo($x:expr) bar) =&gt; {quote(cx, foo_bar($x).unwrap()}).unwrap() + + matches!(cx, input, { + () =&gt; { + cx.err("No input?"); + } + (foo($($x:ident),+ bar) =&gt; { + println!("found {} idents", x.len()); + quote!(($x);*).unwrap() + } + } + }) + </code></pre> + + <p>Note that since we match AST items here, our backwards compatibility story is a bit complicated (though hopefully not much more so than with current macros).</p> + + <h3>Hygiene</h3> + + <p>The intention of the design is that the actual hygiene algorithm applied is irrelevant. Procedural macros should be able to use the same API if the hygiene algorithm changes (of course the result of applying the API might change). To this end, all hygiene objects are opaque and cannot be directly manipulated by macros.</p> + + <p>I propose one module (<code>hygiene</code>) and two types: <code>Context</code> and <code>Scope</code>.</p> + + <p>A <code>Context</code> is attached to each token and contains all hygiene information about that token. If two tokens have the same <code>Context</code>, then they may be compared syntactically. The reverse is not true - two tokens can have different <code>Context</code>s and still be equal. <code>Context</code>s can only be created by applying the hygiene algorithm and cannot be manipulated, only moved and stored.</p> + + <p><code>MacroContext</code> has a method <code>fresh_hygiene_context</code> for creating a new, fresh <code>Context</code> (i.e., a <code>Context</code> not shared with any other tokens).</p> + + <p><code>MacroContext</code> has a method <code>expansion_hygiene_context</code> for getting the <code>Context</code> where the macro is defined. This is equivalent to <code>.expansion_scope().direct_context()</code>, but might be more efficient (and I expect it to be used a lot).</p> + + <p>A <code>Scope</code> provides information about a position within an AST at a certain point during macro expansion. For example,</p> + + <pre><code>fn foo() { + a + { + b + c + } + } + </code></pre> + + <p><code>a</code> and <code>b</code> will have different <code>Scope</code>s. <code>b</code> and <code>c</code> will have the same <code>Scope</code>s, even if <code>b</code> was written in this position and <code>c</code> is due to macro expansion. However, a <code>Scope</code> may contain more information than just the syntactic scopes, for example, it may contain information about pending scopes yet to be applied by the hygiene algorithm (i.e., information about <code>let</code> expressions which are in scope).</p> + + <p>Note that a <code>Scope</code> means a scope in the macro hygiene sense, not the commonly used sense of a scope declared with <code>{}</code>. In particular, each <code>let</code> statement starts a new scope and the items and statements in a function body are in different scopes.</p> + + <p>The functions <code>lookup_item_scope</code> and <code>lookup_statement_scope</code> take a <code>MacroContext</code> and a path, represented as a <code>TokenSlice</code>, and return the <code>Scope</code> which that item defines or an error if the path does not refer to an item, or the item does not define a scope of the right kind.</p> + + <p>The function <code>lookup_scope_for</code> is similar, but returns the <code>Scope</code> in which an item is declared.</p> + + <p><code>MacroContext</code> has a method <code>expansion_scope</code> for getting the scope in which the current macro is being expanded.</p> + + <p><code>Scope</code> has a method <code>direct_context</code> which returns a <code>Context</code> for items declared directly (c.f., via macro expansion) in that <code>Scope</code>.</p> + + <p><code>Scope</code> has a method <code>nested</code> which creates a fresh <code>Scope</code> nested within the receiver scope.</p> + + <p><code>Scope</code> has a static method <code>empty</code> for creating an empty scope, that is one with no scope information at all (note that this is different from a top-level scope).</p> + + <p>I expect the exact API around <code>Scope</code>s and <code>Context</code>s will need some work. <code>Scope</code> seems halfway between an intuitive, algorithm-neutral abstraction, and the scopes from the sets of scopes hygiene algorithm. I would prefer a <code>Scope</code> should be more abstract, on the other hand, macro authors may want fine-grained control over hygiene application.</p> + + <h4>Manipulating hygiene information on tokens,</h4> + + <pre><code>pub mod hygiene { + pub fn add(cx: &amp;mut MacroContext, t: &amp;Token, scope: &amp;Scope) -&gt; Token; + // Maybe unnecessary if we have direct access to Tokens. + pub fn set(t: &amp;Token, cx: &amp;Context) -&gt; Token; + // Maybe unnecessary - can use set with cx.expansion_hygiene_context(). + // Also, bad name. + pub fn current(cx: &amp;MacroContext, t: &amp;Token) -&gt; Token; + } + </code></pre> + + <p><code>add</code> adds <code>scope</code> to any context already on <code>t</code> (<code>Context</code> should have a similar method). Note that the implementation is a bit complex - the nature of the <code>Scope</code> might mean we replace the old context completely, or add to it.</p> + + <h4>Applying hygiene when expanding the current macro</h4> + + <p>By default, the current macro will be expanded in the standard way, having hygiene applied as expected. Mechanically, hygiene information is added to tokens when the macro is expanded. Assuming the sets of scopes algorithm, scopes (for example, for the macro's definition, and for the introduction) are added to any scopes already present on the token. A token with no hygiene information will thus behave like a token in a macro-by-example macro. Hygiene due to nested scopes created by the macro do not need to be taken into account by the macro author, this is handled at expansion time.</p> + + <p>Procedural macro authors may want to customise hygiene application (it is common in Racket), for example, to introduce items that can be referred to by code in the call-site scope.</p> + + <p>We must provide an option to expand the current macro without applying hygiene; the macro author must then handle hygiene. For this to work, the macro must be able to access information about the scope in which it is applied (see <code>MacroContext::expansion_scope</code>, above) and to supply a <code>Scope</code> indicating scopes that should be added to tokens following the macro expansion.</p> + + <pre><code>pub mod hygiene { + pub enum ExpansionMode { + Automatic, + Manual(Scope), + } + } + + impl MacroContext { + pub fn set_hygienic_expansion(hygiene::ExpansionMode); + } + </code></pre> + + <p>We may wish to offer other modes for expansion which allow for tweaking hygiene application without requiring full manual application. One possible mode is where the author provides a <code>Scope</code> for the macro definition (rather than using the scope where the macro is actually defined), but hygiene is otherwise applied automatically. We might wish to give the author the option of applying scopes due to the macro definition, but not the introduction scopes.</p> + + <p>On a related note, might we want to affect how spans are applied when the current macro is expanded? I can't think of a use case right now, but it seems like something that might be wanted.</p> + + <p>Blocks of tokens (that is a <code>Sequence</code> token) may be marked (not sure how, exactly, perhaps using a distinguished context) such that it is expanded without any hygiene being applied or spans changed. There should be a function for creating such a <code>Sequence</code> from a <code>TokenSlice</code> in the <code>tokens</code> module. The primary motivation for this is to handle the tokens representing the body on which an annotation-like macro is present. For a 'decorator' macro, these tokens will be untouched (passed through by the macro), and since they are not touched by the macro, they should appear untouched by it (in terms of hygiene and spans).</p> + + <h3>Applying macros</h3> + + <p>We provide functionality to expand a provided macro or to lookup and expand a macro.</p> + + <pre><code>pub mod apply { + pub fn expand_macro(cx: &amp;mut MacroContext, + expansion_scope: Scope, + macro: &amp;TokenSlice, + macro_scope: Scope, + input: &amp;TokenSlice) + -&gt; Result&lt;(TokenStream, Scope), ErrStruct&gt;; + pub fn lookup_and_expand_macro(cx: &amp;mut MacroContext, + expansion_scope: Scope, + macro: &amp;TokenSlice, + input: &amp;TokenSlice) + -&gt; Result&lt;(TokenStream, Scope), ErrStruct&gt;; + } + </code></pre> + + <p>These functions apply macro hygiene in the usual way, with <code>expansion_scope</code> dictating the scope into which the macro is expanded. Other spans and hygiene information is taken from the tokens. <code>expand_macro</code> takes pending scopes from <code>macro_scope</code>, <code>lookup_and_expand_macro</code> uses the proper pending scopes. In order to apply the hygiene algorithm, the result of the macro must be parsable. The returned scope will contain pending scopes that can be applied by the macro to subsequent tokens.</p> + + <p>We could provide versions that don't take an <code>expansion_scope</code> and use <code>cx.expansion_scope()</code>. Probably unnecessary.</p> + + <pre><code>pub mod apply { + pub fn expand_macro_unhygienic(cx: &amp;mut MacroContext, + macro: &amp;TokenSlice, + input: &amp;TokenSlice) + -&gt; Result&lt;TokenStream, ErrStruct&gt;; + pub fn lookup_and_expand_macro_unhygienic(cx: &amp;mut MacroContext, + macro: &amp;TokenSlice, + input: &amp;TokenSlice) + -&gt; Result&lt;TokenStream, ErrStruct&gt;; + } + </code></pre> + + <p>The <code>_unhygienic</code> variants expand a macro as in the first functions, but do not apply the hygiene algorithm or change any hygiene information. Any hygiene information on tokens is preserved. I'm not sure if <code>_unhygienic</code> are the right names - using these is not necessarily unhygienic, just that we are automatically applying the hygiene algorithm.</p> + + <p>Note that all these functions are doing an eager expansion of macros, or in Scheme terms they are <code>local-expand</code> functions. </p> + + <h3>Looking up items</h3> + + <p>The function <code>lookup_item</code> takes a <code>MacroContext</code> and a path represented as a <code>TokenSlice</code> and returns a <code>TokenStream</code> for the item referred to by the path, or an error if name resolution failed. I'm not sure where this function should live.</p> + + <h3>Interned strings</h3> + + <pre><code>pub mod strings { + pub struct InternedString; + + impl InternedString { + pub fn get(&amp;self) -&gt; String; + } + + pub fn intern(cx: &amp;mut MacroContext, s: &amp;str) -&gt; Result&lt;InternedString, ErrStruct&gt;; + pub fn find(cx: &amp;mut MacroContext, s: &amp;str) -&gt; Result&lt;InternedString, ErrStruct&gt;; + pub fn find_or_intern(cx: &amp;mut MacroContext, s: &amp;str) -&gt; Result&lt;InternedString, ErrStruct&gt;; + } + </code></pre> + + <p><code>intern</code> interns a string and returns a fresh <code>InternedString</code>. <code>find</code> tries to find <em>an</em> existing <code>InternedString</code>.</p> + + <h3>Spans</h3> + + <p>A span gives information about where in the source code a token is defined. It also gives information about where the token came from (how it was generated, if it was generated code).</p> + + <p>There should be a <code>spans</code> module in libmacro, which will include a <code>Span</code> type which can be easily inter-converted with the <code>Span</code> defined in libsyntax. Libsyntax spans currently include information about stability, this will not be present in libmacro spans.</p> + + <p>If the programmer does nothing special with spans, then they will be 'correct' by default. There are two important cases: tokens passed to the macro and tokens made fresh by the macro. The former will have the source span indicating where they were written and will include their history. The latter will have no source span and indicate they were created by the current macro. All tokens will have the history relating to expansion of the current macro added when the macro is expanded. At macro expansion, tokens with no source span will be given the macro use-site as their source.</p> + + <p><code>Span</code>s can be freely copied between tokens.</p> + + <p>It will probably useful to make it easy to manipulate spans. For example, rather than point at the macro's defining function, point at a helper function where the token is made. Or to set the origin to the current macro when the token was produced by another which should an implementation detail. I'm not sure what such an interface should look like (and is probably not necessary in an initial library).</p> + + <h3>Feature gates</h3> + + <pre><code>pub mod features { + pub enum FeatureStatus { + // The feature gate is allowed. + Allowed, + // The feature gate has not been enabled. + Disallowed, + // Use of the feature is forbidden by the compiler. + Forbidden, + } + + pub fn query_feature(cx: &amp;MacroContext, feature: Token) -&gt; Result&lt;FeatureStatus, ErrStruct&gt;; + pub fn query_feature_by_str(cx: &amp;MacroContext, feature: &amp;str) -&gt; Result&lt;FeatureStatus, ErrStruct&gt;; + pub fn query_feature_unused(cx: &amp;MacroContext, feature: Token) -&gt; Result&lt;FeatureStatus, ErrStruct&gt;; + pub fn query_feature_by_str_unused(cx: &amp;MacroContext, feature: &amp;str) -&gt; Result&lt;FeatureStatus, ErrStruct&gt;; + + pub fn used_feature_gate(cx: &amp;MacroContext, feature: Token) -&gt; Result&lt;(), ErrStruct&gt;; + pub fn used_feature_by_str(cx: &amp;MacroContext, feature: &amp;str) -&gt; Result&lt;(), ErrStruct&gt;; + + pub fn allow_feature_gate(cx: &amp;MacroContext, feature: Token) -&gt; Result&lt;(), ErrStruct&gt;; + pub fn allow_feature_by_str(cx: &amp;MacroContext, feature: &amp;str) -&gt; Result&lt;(), ErrStruct&gt;; + pub fn disallow_feature_gate(cx: &amp;MacroContext, feature: Token) -&gt; Result&lt;(), ErrStruct&gt;; + pub fn disallow_feature_by_str(cx: &amp;MacroContext, feature: &amp;str) -&gt; Result&lt;(), ErrStruct&gt;; + } + </code></pre> + + <p>The <code>query_*</code> functions query if a feature gate has been set. They return an error if the feature gate does not exist. The <code>_unused</code> variants do not mark the feature gate as used. The <code>used_</code> functions mark a feature gate as used, or return an error if it does not exist.</p> + + <p>The <code>allow_</code> and <code>disallow_</code> functions set a feature gate as allowed or disallowed for the current crate. These functions will only affect feature gates which take affect after parsing and expansion are complete. They do not affect feature gates which are checked during parsing or expansion.</p> + + <p>Question: do we need the <code>used_</code> functions? Could just call <code>query_</code> and ignore the result.</p> + + <h3>Attributes</h3> + + <p>We need some mechanism for setting attributes as used. I don't actually know how the unused attribute checking in the compiler works, so I can't spec this area. But, I expect <code>MacroContext</code> to make available some interface for reading attributes on a macro use and marking them as used.</p> + 2016-01-18T21:40:42+00:00 + Nick Cameron + + + Seif Lotfy: Skizze progress and REPL + http://geekyogre.com/skizze-progress-and-repl/ + <p><img align="center" height="190" src="http://i.imgur.com/9z47NdA.png" width="600" /> <br /> + <br /> <br /> + Over the last 3 weeks, based on feedback we proceeded fledging out the concepts and the code behind <a href="https://github.com/skizzehq/skizze">Skizze</a>. <br /> + <a href="https://medium.com/@njpatel/">Neil Patel</a> suggested the following:</p> + + <hr /> + + <p><em>So I've been thinking about the server API. I think we want to choose one thing and do it as well as possible, instead of having six ways to talk to the server. I think that helps to keep things sane and simple overall.</em></p> + + <p><em>Thinking about usage, I can only really imagine Skizze in an environment like <a href="https://xamarin.com/insights">ours</a>, which is high-throughput. I think that is it's 'home' and we should be optimising for that all day long.</em></p> + + <p><em>Taking that into account, I believe we have two options:</em></p> + + <ol> + <li><p><em>We go the gRPC route, provide .proto files and let people use the existing gRPC tooling to build support for their favourite language. That means we can happily give Ruby/Node/C#/etc devs a real way to get started up with Skizze almost immediately, piggy-backing on the gRPC docs etc.</em></p></li> + <li><p><em>We absorb the Redis Protocol. It does everything we need, is very lean, and we can (mostly) easily adapt it for what we need to do. The downside is that to get support from other libs, there will have to be actual libraries for every language. This could slow adoption, or it might be easy enough if people can reuse existing REDIS code. It's hard to tell how that would end up.</em></p></li> + </ol> + + <p><em>gRPC is interesting because it's built already for distributed systems, across bad networks, and obviously is bi-directional etc. Without us having to spend time on the protocol, gRPC let's us easily add features that require streaming. Like, imagine a client being able to listen for changes in count/size and be notified instantly. That's something that gRPC is built for right now.</em></p> + + <p><em>I think gRPC is a bit verbose, but I think it'll pay off for ease of third-party lib support and as things grow.</em></p> + + <p><em>The CLI could easily be built to work with gRPC, including adding support for streaming stuff etc. Which could be pretty exciting.</em></p> + + <hr /> + + <p>That being said, we gave Skizze <a href="https://github.com/skizzehq/">a new home</a>, where based on feedback we developed .proto files and started rewriting big chunks of the code.</p> + + <p>We added a new wrapper called "domain" which represents a stream. It wraps around Count-Min-Log, Bloom Filter, Top-K and HyperLogLog++, so when feeding it values it feeds all the sketches. Later we intend to allow attaching and detaching sketches from "domains" (We need a better name).</p> + + <p>We also implemented a gRPC API which should allow easy wrapper creation in other languages.</p> + + <p>Special thanks go to <a href="https://twitter.com/martinpintob">Martin Pinto</a> for helping out with unit tests and <a href="http://dopeness.org">Soren Macbeth</a> for thorough feedback and ideas about the "domain" concept. <br /> + Take a look at our initial REPL work there:</p> + + <p><a href="http://geekyogre.com/content/images/2016/01/MBCY64aaKL.gif"><img alt="Link to this page" border="0" src="http://geekyogre.com/content/images/2016/01/skizze-1.png" /></a> <br /> + <a href="http://geekyogre.com/content/images/2016/01/MBCY64aaKL.gif">click for GIF</a></p> + 2016-01-18T17:41:43+00:00 + Seif Lotfy + + + Doug Belshaw: What a post-Persona landscape means for Open Badges + http://dougbelshaw.com/blog/2016/01/18/open-badges-persona/ + <p><em><strong>Note:</strong> I don’t work for Mozilla any more, so (like <a href="https://www.youtube.com/watch?v=YQHsXMglC9A">Adele</a>) these are my thoughts ‘from the outside’…</em></p> + <hr /> + <h3>Introduction</h3> + <p><a href="http://openbadges.org">Open Badges</a> is no longer a <a href="http://mozilla.org">Mozilla</a> project. In fact, it hasn’t been for a while — the <a href="http://badgealliance.org">Badge Alliance</a> was set up a couple of years ago to promote the specification on a both a technical and community basis. As I stated in a recent post, this is a <strong>good</strong> thing and means that <a href="http://dougbelshaw.com/blog/2015/11/08/bright-future-badges/">the future is bright for Open Badges</a>.</p> + <p>However, Mozilla <em>is</em> still involved with the Open Badges project: Mark Surman, Executive Director of the Mozilla Foundation, sits on the board of the Badge Alliance. Mozilla also pays for contractors to work on the <a href="http://backpack.openbadges.org">Open Badges backpack</a> and there were badges earned at the <a href="http://mozillafestival.org">Mozilla Festival</a> a few months ago.</p> + <p>Although it may seem strange for those used to corporates interested purely in profit, Mozilla creates what the open web needs at any given time. Like any organisation, sometimes it gets these wrong, either because the concept was flawed, or because the execution was poor. Other times, I’d argue, Mozilla doesn’t give ideas and concepts enough time to gain traction.</p> + <h3>The end of Persona at Mozilla</h3> + <p>Open Badges, at its very essence, is a technical specification. It allows credentials with metadata hard-coded into them to be issued, exchanged, and displayed. This is done in a secure, standardised manner.</p> + <p><img alt="OBI diagram" class="alignnone wp-image-39987 size-full" src="http://i1.wp.com/dougbelshaw.com/blog/wp-content/uploads/2016/01/obi-diagram.png?w=100%25" /></p> + <p>For users to be able to access their ‘backpack’ (i.e. the place they store badges) they needed a secure login system.Back in 2011 at the start of the Open Badges project it made sense to make use of Mozilla’s nascent <a href="https://www.mozilla.org/en-US/persona/">Persona</a> project. This aimed to provide a way for users to easily sign into sites around the web without using their Facebook/Google logins. These ‘social’ sign-in methods mean that users are tracked around the web — something that Mozilla was obviously against.</p> + <p>By 2014, Persona wasn’t seen to be having the kind of ‘growth trajectory’ that Mozilla wanted. The project was transferred to <a href="http://identity.mozilla.com/post/78873831485/transitioning-persona-to-community-ownership">community ownership</a> and most of the team left Mozilla in 2015. It was <a href="https://groups.google.com/forum/#!msg/mozilla.dev.identity/mibOQrD6K0c/kt0NdMWbEQAJ">announced</a> that Persona would be shutting down as a Mozilla service in November 2016. While Persona will exist as an open source project, it won’t be hosted by Mozilla.</p> + <h3>What this means for Open Badges</h3> + <p>Although I’m not aware of an official announcement from the Badge Alliance, I think it’s worth making three points here.</p> + <h5>1. You can still use Persona</h5> + <p>If you’re a developer, you can still use Persona. It’s open source. It works.</p> + <h5>2. Persona is not central to the Open Badges Infrastructure</h5> + <p>The Open Badges backpack is <em>one</em> place where users can store their badges. There are others, including the <a href="https://openbadgepassport.com/">Open Badge Passport</a> and <a href="https://www.openbadgeacademy.com/">Open Badge Academy</a>. MacArthur, who seed-funded the Open Badges ecosystem, have a new platform launching through <a href="https://www.lrng.org/">LRNG</a>.</p> + <p>It is up to the organisations behind these various solutions as to how they allow users to authenticate. They may choose to allow social logins. They may force users to create logins based on their email address. They may decide to use an open source version of Persona. It’s entirely up to them.</p> + <h5>3. A post-Persona badges system has its advantages</h5> + <p>The Persona authentication system runs off email addresses. This means that transitioning <em>from</em> Persona to another system is relatively straightforward. It has, however, meant that for the past few years we’ve had a recurrent problem: what do you do with people being issued badges to multiple email addresses?</p> + <p>Tying badges to emails seemed like the easiest and fastest way to get to a critical mass in terms of Open Badge adoption. Now that’s worked, we need to think in a more nuanced way about allowing users to tie multiple identities to a single badge.</p> + <h4>Conclusion</h4> + <p>Persona was always a slightly awkward fit for Open Badges. Although, for a time, it made sense to use Persona for authentication to the Open Badges backpack, we’re now in a post-Persona landscape. This brings with it certain advantages.</p> + <p>As Nate Otto wrote in his post <a href="https://medium.com/badge-alliance/open-badges-in-2016-a-look-ahead-3cfe5c3c9878#.l5mhiztwx">Open Badges in 2016: A Look Ahead</a>, the project is growing up. It’s time to move beyond what was expedient at the dawn of Open Badges and look to the future. I’m sad to see the decline of Persona, but I’m excited what the future holds!</p> + <p style="text-align: right;"><em>Header image CC BY-NC-SA <a href="https://www.flickr.com/photos/blmiers2/6904758951/">Barbara</a></em></p> + 2016-01-18T11:34:19+00:00 + Doug Belshaw + + + This Week In Rust: This Week in Rust 114 + http://this-week-in-rust.org/blog/2016/01/18/this-week-in-rust-114/ + <p>Hello and welcome to another issue of <em>This Week in Rust</em>! + <a href="http://rust-lang.org">Rust</a> is a systems language pursuing the trifecta: + safety, concurrency, and speed. This is a weekly summary of its progress and + community. Want something mentioned? Tweet us at <a href="https://twitter.com/ThisWeekInRust">@ThisWeekInRust</a> or <a href="mailto:corey@octayn.net?subject=This%20Week%20in%20Rust%20Suggestion">send us an + email</a>! + Want to get involved? <a href="https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md">We love + contributions</a>.</p> + <p><em>This Week in Rust</em> is openly developed <a href="https://github.com/cmr/this-week-in-rust">on GitHub</a>. + If you find any errors in this week's issue, <a href="https://github.com/cmr/this-week-in-rust/pulls">please submit a PR</a>.</p> + <p>This week's edition was edited by: <a href="https://github.com/nasa42">nasa42</a>, <a href="https://github.com/brson">brson</a>, and <a href="https://github.com/llogiq">llogiq</a>.</p> + <h3>Updates from Rust Community</h3> + <h4>News &amp; Blog Posts</h4> + <ul> + <li><a href="http://gregchapple.com/contributing-to-the-rust-compiler/">Guide: Contributing to the Rust compiler</a>.</li> + <li><a href="http://www.ncameron.org/blog/a-type-safe-and-zero-allocation-library-for-reading-and-navigating-elf-files/">A type-safe and zero-allocation library for reading and navigating ELF files</a>.</li> + <li>[podcast] <a href="http://www.newrustacean.com/show_notes/e009/">New Rustacean podcast episode 09</a>. Getting into the nitty-gritty with Rust's traits.</li> + <li><a href="https://jadpole.github.io/arcaders/arcaders-1-12/">ArcadeRS 1.12: Brawl, at last</a>! Part of the series <a href="https://jadpole.github.io/arcaders/arcaders-1-0/">ArcadeRS 1.0: The project</a> - a series whose objective is to explore the Rust programming language and ecosystem through the development of a simple, old-school shooter.</li> + <li><a href="https://blog.thiago.me/raspberry-pi-bare-metal-programming-with-rust/">Raspberry Pi bare metal programming with Rust</a>.</li> + <li><a href="http://blog.servo.org/2016/01/11/twis-47/">This week in Servo 47</a>.</li> + <li><a href="http://www.redox-os.org/news/this-week-in-redox-10/">This week in Redox OS 10</a>.</li> + </ul> + <h4>Notable New Crates &amp; Project Updates</h4> + <ul> + <li><a href="https://github.com/ebkalderon/amethyst">Amethyst</a>. Data-oriented game engine written in Rust.</li> + <li><a href="https://www.rust-lang.org/">Rust website</a> has received some <a href="https://www.reddit.com/r/rust/comments/40zxey/major_website_updates/">major updates</a>.</li> + <li><a href="https://packages.debian.org/stretch/rustc">Rust</a> and <a href="https://packages.debian.org/stretch/cargo">Cargo</a> are now available in Debian stretch.</li> + <li><a href="https://community.particle.io/t/rust-on-particle-call-for-contributors/19090">Rust on Particle: Call for contributors</a>.</li> + <li><a href="https://dwrensha.github.io/capnproto-rust/2016/01/11/async-rpc.html">capnp-rpc-rust rewritten to use async I/O</a>.</li> + <li><a href="https://github.com/Ogeon/palette">Palette</a>. A Rust library for linear color calculations and conversion.</li> + </ul> + <h3>Updates from Rust Core</h3> + <p>164 pull requests were <a href="https://github.com/issues?q=is%3Apr+org%3Arust-lang+is%3Amerged+merged%3A2016-01-11..2016-01-18">merged in the last week</a>.</p> + <p>See the <a href="https://internals.rust-lang.org/t/triage-digest-tue-jan-05-2016/3052">triage digest</a> and <a href="https://internals.rust-lang.org/t/subteam-reports-2016-01-08/3067">subteam reports</a> for more details.</p> + <h4>Notable changes</h4> + <ul> + <li><a href="https://github.com/rust-lang/rust/pull/30943">std: Stabilize APIs for the 1.7 release</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/27807">Refactor and improve: Arena, TypedArena</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/29498">Let <code>str::replace</code> take a pattern</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30295">rustc_resolve: Fix bug in duplicate checking for extern crates</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30426">Rewrite BTreeMap to use parent pointers</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30446">Support generic associated consts</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30509">Add an <code>impl</code> for <code>Box&lt;Error&gt;</code> from String</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30533">Introduce "obligation forest" data structure into fulfillment to track backtraces</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30538">Remove negate_unsigned feature gate</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30567">llvm: Add support for vectorcall (X86_VectorCall) convention</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30676">Make coherence more tolerant of error types</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30740">Add fast path for ASCII in UTF-8 validation</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30753">Downgrade unit struct match via S(..) warnings to errors</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30930">Move const block checks before lowering step</a>.</li> + </ul> + <h4>New Contributors</h4> + <ul> + <li>Anton Blanchard</li> + <li>Jonas Tepe</li> + <li>Jörg Krause</li> + <li>Joshua Olson</li> + <li>kalita.alexey</li> + <li>Pierre Krieger</li> + <li>Sergey Veselkov</li> + <li>Simon Martin</li> + <li>Steffen</li> + <li>tomaka</li> + </ul> + <h4>Approved RFCs</h4> + <p>Changes to Rust follow the Rust <a href="https://github.com/rust-lang/rfcs#rust-rfcs">RFC (request for comments) + process</a>. These + are the RFCs that were approved for implementation this week:</p> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/1331">RFC 1331: <code>src/grammar</code> for the canonical grammar of the Rust language</a>.</li> + </ul> + <h4>Final Comment Period</h4> + <p>Every week <a href="https://rust-lang.org/team.html">the team</a> announces the + 'final comment period' for RFCs and key PRs which are reaching a + decision. Express your opinions now. <a href="https://github.com/rust-lang/rfcs/labels/final-comment-period">This week's FCPs</a> are:</p> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/1462">Add <code>[</code> to the FOLLOW(ty) in macro future-proofing rules</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1457">Rewrite <code>for</code> loop desugaring to use language items</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1320">Amend 1192 (RangeInclusive) to use an enum</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/243">Trait-based exception handling</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1361">Improve Cargo target-specific dependencies</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1129">Add a <code>IndexAssign</code> trait that allows overloading "indexed assignment" expressions like <code>a[b] = c</code></a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1196">Allow eliding more type parameters</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1296">Add an <code>alias</code> attribute to <code>#[link]</code> and <code>-l</code></a>.</li> + </ul> + <h4>New RFCs</h4> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/1459">Add a used attribute to prevent symbols from being discarded</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1461">Move some net2 functionality into libstd</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1465">Add <code>some!</code> macro for unwrapping Option more safely</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1467">Stabilize the <code>volatile_load</code> and <code>volatile_store</code> intrinsics as <code>ptr::volatile_read</code> and <code>ptr::volatile_write</code></a>.</li> + </ul> + <h3>Upcoming Events</h3> + <ul> + <li><a href="http://www.meetup.com/Rust-Meetup-Hamburg/events/227838367/">1/19. Rust Hack and Learn Hamburg @ Ponton</a>.</li> + <li><a href="http://www.meetup.com/Rust-Bay-Area/events/227841778/">1/21. SF Bay Area: Rust Concurrency and Parallelism</a>.</li> + <li><a href="http://www.meetup.com/opentechschool-berlin/">1/27. OpenTechSchool Berlin: Rust Hack and Learn</a>.</li> + </ul> + <p>If you are running a Rust event please add it to the <a href="https://www.google.com/calendar/embed?src=apd9vmbc22egenmtu5l6c5jbfc%40group.calendar.google.com">calendar</a> to get + it mentioned here. Email <a href="mailto:erick.tryzelaar@gmail.com">Erick Tryzelaar</a> or <a href="mailto:banderson@mozilla.com">Brian + Anderson</a> for access.</p> + <h3>fn work(on: RustProject) -&gt; Money</h3> + <ul> + <li><a href="http://maidsafe.net/rust_engineer.html">Rust Engineer</a> at MaidSafe.</li> + <li><a href="https://careers.mozilla.org/en-US/position/ozy21fwU">Research Engineer - Servo</a> at Mozilla.</li> + <li><a href="https://careers.mozilla.org/en-US/position/o0H41fww">Senior Research Engineer - Rust</a> at Mozilla.</li> + <li><a href="http://plv.mpi-sws.org/rustbelt/">PhD and postdoc positions</a> at MPI-SWS.</li> + </ul> + <p><em>Tweet us at <a href="https://twitter.com/ThisWeekInRust">@ThisWeekInRust</a> to get your job offers listed here!</em></p> + <h3>Crate of the Week</h3> + <p>This week's Crate of the Week is <a href="https://github.com/alexcrichton/toml-rs">toml</a>, a crate for all our configuration needs, simple yet effective.</p> + <p>Thanks to <a href="https://users.rust-lang.org/users/stebalien">Steven Allen</a> for the suggestion.</p> + <p><a href="https://users.rust-lang.org/t/crate-of-the-week/2704">Submit your suggestions for next week</a>!</p> + <h3>Quote of the Week</h3> + <blockquote> + <p>Borrow/lifetime errors are usually Rust compiler bugs. + Typically, I will spend 20 minutes detailing the precise conditions of + the bug, using language that understates my immense knowledge, while + demonstrating sympathetic understanding of the pressures placed on a + Rust compiler developer, who is also probably studying for several exams + at the moment. The developer reading my bug report may not understand + this stuff as well as I do, so I will carefully trace the lifetimes of + each variable, where memory is allocated on the stack vs the heap, which + struct or function owns a value at any point in time, where borrows + begin and where they... oh yeah, actually that variable really doesn't + live long enough.</p> + </blockquote> + <p>— <a href="https://www.reddit.com/r/rust/comments/4084yx/my_trick_when_i_get_stuck_as_a_beginner/cysqz3s">peterjoel on /r/rust</a>.</p> + <p>Thanks to <a href="https://users.rust-lang.org/users/WaDelma">Wa Delma</a> for the suggestion.</p> + <p><a href="http://users.rust-lang.org/t/twir-quote-of-the-week/328">Submit your quotes for next week</a>!</p> + 2016-01-18T05:00:00+00:00 + Corey Richardson + + + Nikki Bee: Okay, But What Does Your Work Actually Mean, Nikki? Part 2: The Fetch Standard and Servo + http://nikkisquared.github.io/2016/01/17/what-does-your-work-mean-part-2.html + <p>In my previous post, I started discussing in more detail what my internship entails, by talking about my first contribution to Servo. As a refresher, my first contribution was as part of my application to Outreachy, which I later revisited during my internship after a change I introduced to the HTML Standard it relied on. I’m going to expand on that last point today- specifically, how easy it is to introduce changes in <a href="https://wiki.whatwg.org/wiki/FAQ#What_is_the_WHATWG.3F">WHATWG</a>’s various standards. I’m also going to talk about how this accessibility to changing web standards affects how I can understand it, how I can help improve it, and my work on Servo.</p> + + <h3>Two Ways To Change</h3> + + <p>There are many ways to <a href="https://wiki.whatwg.org/wiki/What_you_can_do">get involved with WHATWG</a>, but there are two that I’ve become the most familiar with: firstly, by opening a discussion about a perceived issue and asking how it should be resolved; secondly, by taking on an issue approved as needing change and making the desired change. I’ve almost entirely only done the former, and the latter only for some minor typos. Any changes that relate directly to my work, however minor, are significant for me though! Like I discussed in my previous post, I brought attention to <a href="https://github.com/whatwg/html/issues/296">an inconsistency</a> that was resolved, giving me a new task of updating my first contribution to Servo to reflect the change in the HTML Standard. I’ve done that several times since, for the Fetch Standard.</p> + + <h3>Understanding Fetch</h3> + + <p>My first two weeks of my internship were spent on reading through the majority of the <a href="https://fetch.spec.whatwg.org/">Fetch Standard</a>, primarily the various Fetch functions. I took many notes describing the steps to myself, annotated with questions I had and the answers I got from either other people on the Servo team who had worked with Fetch (including my internship mentor, of course!) or people from WHATWG who were involved in the Fetch Standard. Getting so familiar with Fetch meant a few things: I would notice minor errors (such as an out of date link) that I could submit a <a href="https://github.com/whatwg/fetch/pull/173">simple fix for</a>, or a bigger issue that I couldn’t resolve myself.</p> + + <h3>Discussions &amp; Resolutions</h3> + + <p>I’m going to go into more detail about some of those bigger issues. From my perspective, when I start a discussion about a piece of documentation (such as the Fetch Standard, or reading about a programming library Servo uses), I go into it thinking “Either this documentation is incorrect, or my understanding is incorrect”. Whichever the answer is, it doesn’t mean that the documentation is bad, or that I’m bad at reading comprehension. I understand best by building up a model of something in my head, putting that to practice, and asking a lot of questions along the way. I learn by getting things wrong and figuring out why I was wrong, and sometimes in the process I uncover a point that could be made more clear, or an inconsistency! I have good examples of both of the different outcomes I listed, which I’ll cover over the next two sections.</p> + + <h5>Looking For The Big Picture</h5> + + <p>Early on in my initial review of the Fetch Standard’s several protocols, I found a major step that seemed to have no use. I understood that since I was learning Fetch on a step-by-step basis, I did not have a view of the bigger picture, so I asked around what I was missing that would help me understand this. One of the people I work with on implementing Fetch agreed with me that the step seemed to have no purpose, and so we decided to <a href="https://github.com/whatwg/fetch/issues/174">open an issue</a> asking about removing it from the standard. It turned out that I had actually missed the meaning of it, as we learned. However, instead of leaving it there, I shifted the issue into asking for some explanatory notes on why this step is needed, which was fulfilled. This meant that I would have a reference to go back to should I forget the significance of the step, and that people reading the Fetch Standard in the future would be much less likely to come to the same incorrect conclusion I had.</p> + + <h5>A Confusing Order</h5> + + <p>Shortly after I had first discovered that apparent issue, I found myself struggling to comprehend a sequence of actions in another Fetch protocol. The specification seemed to say that part of an early step was meant to only be done after the final step. I unfortunately don’t remember details of the discussion I had about this- if there was a reason for why it was organized like this, I forget what it was. Regardless, it was agreed that <a href="https://github.com/whatwg/fetch/issues/176">moving those sub-steps</a> to be actually listed after the step they’re supposed to run after would be a good change. This meant that I would need to re-organize my notes to reflect the re-arranged sequence of actions, as well as have an easier time being able to follow this part of the Fetch Standard.</p> + + <h3>A Living Standard</h3> + + <p>Like I said at the start of this post, I’m going to talk about how changes in the Fetch Standard affects my work on Servo itself. What I’ve covered so far has mostly been how changes affect my understanding of the standard itself. A key aspect in understanding the Fetch protocols is reviewing them for updates that impact me. WHATWG labels every standard they author as a “<a href="https://wiki.whatwg.org/wiki/FAQ#What_does_.22Living_Standard.22_mean.3F">Living Standard</a>” for good reason. It was one thing for me to learn how easy it is to introduce changes, while knowing exactly what’s going on, but it’s another for me to understand that anybody else can, and often does, make changes to the Fetch Standard!</p> + + <h5>Changes Over Time</h5> + + <p>When an update is made to the Fetch Standard, it’s not so difficult to deal with as one might imagine. The Fetch Standard always notes the last day it was updated at the top of the document, I follow a Twitter account that <a href="https://twitter.com/fetchstandard">posts about updates</a>, and all the history can be <a href="https://github.com/whatwg/fetch/commits">seen on GitHub</a> which will show me exactly what has been changed as well as some discussion on what the change does. All of these together alert me to the fact that the Fetch Standard has been modified, and I can quickly see what was revised. If it’s relevant to what I’m going to be implementing, I update my notes to match it. Occasionally, I need to change existing code to reflect the new Standard, which is also easily done by comparing my new notes to the Fetch implementation in Servo!</p> + + <h5>Snapshots</h5> + + <p>From all of this, it might sound like the Fetch Standard is unfinished, or unreliable/inconsistent. I don’t mean to misrepresent it- the many small improvements help make the Fetch Standard, like all of WHATWG’s standards, better and more reliable. You can think of the status of the Fetch Standard at any point in time as a single, working snapshot. If somebody implemented all of Fetch as it is now, they’d have something that works by itself correctly. A different snapshot of Fetch is just that- different. It will have an improvement or two, but that doesn’t obsolete anybody who implemented it previously. It just means if they revisit the implementation, they’ll have things to update.</p> + + <p>Third post over.</p> + 2016-01-17T20:20:27+00:00 + + + Kevin Ngo: How to Write an A-Frame VR Component + http://ngokevin.com/blog/aframe-component/ + <img align="left" hspace="5" src="http://thevrjump.com/assets/img/articles/aframe-system/aframe-example.jpg" width="320" />Abstract representation of components by @rubenmueller of thevrjump.com. + + <p><a href="http://ngokevin.com/blog/aframe">A-Frame</a> is a WebVR framework that introduces the + <a href="http://ngokevin.com/blog/aframe-vs-3dml">entity-component system</a> (<a href="http://ngokevin.com/rss/docs">docs</a>) to the DOM. The + entity-component system treats every <strong>entity</strong> in the scene as a placeholder + object which we apply and mix <strong>components</strong> to in order to add appearance, + behavior, and functionality. A-Frame comes with some standard components out of + the box like camera, geometry, material, light, or sound. However, people can + write, publish, and register their own components to do <strong>whatever</strong> they want + like have entities <a href="https://github.com/dmarcos/a-invaders/tree/master/js/components">collide/explode/spawn</a>, be controlled by + <a href="https://github.com/ngokevin/aframe-physics-components">physics</a>, or <a href="https://jsbin.com/dasefeh/edit?html,output">follow a path</a>. Today, we'll be going through + how we can write our own A-Frame components.</p> + <blockquote> + <p>Note that this tutorial will be covering the upcoming release of <a href="https://github.com/aframevr/aframe/blob/dev/CHANGELOG.md#dev">A-Frame + 0.2.0</a> which vastly improves the component API.</p> + </blockquote> + <h3>Table of Contents</h3> + <ul> + <li><a href="http://ngokevin.com/rss/index.xml#what-a-component-looks-like">What a Component Looks Like</a><ul> + <li><a href="http://ngokevin.com/rss/index.xml#from-the-dom">From the DOM</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#under-the-hood">Under the Hood</a></li> + </ul> + </li> + <li><a href="http://ngokevin.com/rss/index.xml#defining-the-schema">Defining the Schema</a><ul> + <li><a href="http://ngokevin.com/rss/index.xml#property-types">Property Types</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#single-property-schemas">Single-Property Schemas</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#multiple-property-schemas">Multiple-Property Schemas</a></li> + </ul> + </li> + <li><a href="http://ngokevin.com/rss/index.xml#defining-the-lifecycle-methods">Defining the Lifecycle Methods</a><ul> + <li><a href="http://ngokevin.com/rss/index.xml#component-init-set-up">Component.init() - Set Up</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#component-update-olddata-do-the-magic">Component.update(oldData) - Do the Magic</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#component-remove-tear-down">Component.remove() - Tear Down</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#component-tick-time-background-behavior">Component.tick() - Background Behavior</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#component-pause-and-component-play-stop-and-go">Component.pause() and Component.play() - Stop and Go</a></li> + </ul> + </li> + <li><a href="http://ngokevin.com/rss/index.xml#boilerplate">Boilerplate</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#examples">Examples</a><ul> + <li><a href="http://ngokevin.com/rss/index.xml#text-component">Text Component</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#physics-components">Physics Components</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#layout-component">Layout Component</a></li> + </ul> + </li> + </ul> + <h3>What a Component Looks Like</h3> + <p>A component contains a bucket of data in the form of component properties. This + data is used to modify the entity. For example, we might have an <em>engine</em> + component. Possible properties might be <em>horsepower</em> or <em>cylinders</em>.</p> + <p><img alt="" src="http://thevrjump.com/assets/img/articles/aframe-system/aframe-system.jpg" /> + </p><div class="page-caption"><span> + Abstract representation of a component by @rubenmueller of thevrjump.com. + </span></div><p></p> + <h4>From the DOM</h4> + <p>Let's first see what a component looks like from the DOM.</p> + <p>For example, the <a href="https://aframe.io/docs/components/light.html">light component</a> has properties such as type, color, + and intensity. In A-Frame, we register and configure a component to an entity + using an HTML attribute and a style-like syntax:</p> + <div class="highlight"><pre><span class="p">&lt;</span><span class="nt">a-entity</span> <span class="na">light</span><span class="o">=</span><span class="s">"type: point; color: crimson; intensity: 2.5"</span><span class="p">&gt;&lt;/</span><span class="nt">a-entity</span><span class="p">&gt;</span> + </pre></div> + + + <p>This would give us a light in the scene. To demonstrate composability, we could + give the light a spherical representation by mixing in the <a href="https://aframe.io/docs/components/geometry.html">geometry + component</a>.</p> + <div class="highlight"><pre><span class="p">&lt;</span><span class="nt">a-entity</span> <span class="na">geometry</span><span class="o">=</span><span class="s">"primitive: sphere; radius: 5"</span> + <span class="na">light</span><span class="o">=</span><span class="s">"type: point; color: crimson; intensity: 2.5"</span><span class="p">&gt;&lt;/</span><span class="nt">a-entity</span><span class="p">&gt;</span> + </pre></div> + + + <p>Or we can configure the position component to move the light sphere a bit to the right.</p> + <div class="highlight"><pre><span class="p">&lt;</span><span class="nt">a-entity</span> <span class="na">geometry</span><span class="o">=</span><span class="s">"primitive: sphere; radius: 5"</span> + <span class="na">light</span><span class="o">=</span><span class="s">"type: point; color: crimson; intensity: 2.5"</span> + <span class="na">position</span><span class="o">=</span><span class="s">"5 0 0"</span><span class="p">&gt;&lt;/</span><span class="nt">a-entity</span><span class="p">&gt;</span> + </pre></div> + + + <p>Given the style-like syntax and that it modifies the appearance and behavior of + DOM nodes, component properties can be thought of as a rough analog to CSS. In + the near future, I can imagine component property stylesheets.</p> + <h4>Under the Hood</h4> + <p>Now let's see what a component looks like <strong>under the hood</strong>. A-Frame's most + basic component is the <a href="https://aframe.io/docs/components/position.html">position component</a>:</p> + <div class="highlight"><pre><span class="nx">AFRAME</span><span class="p">.</span><span class="nx">registerComponent</span><span class="p">(</span><span class="s1">'position'</span><span class="p">,</span> <span class="p">{</span> + <span class="nx">schema</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">'vec3'</span> <span class="p">},</span> + + <span class="nx">update</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="kd">var</span> <span class="nx">object3D</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">object3D</span><span class="p">;</span> + <span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">;</span> + <span class="nx">object3D</span><span class="p">.</span><span class="nx">position</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">x</span><span class="p">,</span> <span class="nx">data</span><span class="p">.</span><span class="nx">y</span><span class="p">,</span> <span class="nx">data</span><span class="p">.</span><span class="nx">z</span><span class="p">);</span> + <span class="p">}</span> + <span class="p">});</span> + </pre></div> + + + <p>The position component uses only a tiny subset of the component API, but what + this does is register the component with the name "position", define a <code>schema</code> + where the component's value with be parsed to an <code>{x, y, z}</code> object, and when + the component initializes or the component's data updates, set the position of + the entity with the <code>update</code> callback. <code>this.el</code> is a reference from the + component to the DOM element, or entity, and <code>object3D</code> is the entity's + <a href="http://threejs.org/">three.js</a>. Note that A-Frame is built on top of three.js so many + components will be using the three.js API.</p> + <p>So we see that components consist of a name and a definition, and then they can + be registered to A-Frame. We saw the the position component definition defined + a <code>schema</code> and an <code>update</code> handler. Components simply consist of the <code>schema</code>, + which defines the shape of the data, and several handlers for the component to + modify the entity in reaction to different types of events.</p> + <p>Here is the current list of properties and methods of a component definition:</p> + <table class="pure-table-striped"> + <tbody><tr> + <th>Property</th> + <th>Description</th> + </tr> + <tr> + <td>data</td> + <td>Data of the component derived from the schema default values, mixins, and the entity's attributes.</td> + </tr> + <tr> + <td>el</td> + <td>Reference to the <a href="https://aframe.io/docs/core/entity.html">entity</a> element.</td> + </tr> + <tr> + <td>schema</td> + <td>Names, types, and default values of the component property value(s)</td> + </tr> + </tbody></table> + + <table class="pure-table-striped"> + <tbody><tr><th>Method</th><th>Description</th></tr> + <tr> + <td>init</td> + <td>Called once when the component is initialized.</td> + </tr> + <tr> + <td>update</td> + <td>Called both when the component is initialized and whenever the component's data changes (e.g, via <i>setAttribute</i>).</td> + </tr> + <tr> + <td>remove</td> + <td>Called when the component detaches from the element (e.g., via <i>removeAttribute</i>).</td> + </tr> + <tr> + <td>tick</td> + <td>Called on each render loop or tick of the scene.</td> + </tr> + <tr> + <td>play</td> + <td>Called whenever the scene or entity plays to add any background or dynamic behavior.</td> + </tr> + <tr> + <td>pause</td> + <td>Called whenever the scene or entity pauses to remove any background or dynamic behavior.</td> + </tr> + </tbody></table> + + <h3>Defining the Schema</h3> + <p>The component's schema defines what type of data it takes. A component can + either be single-property or consist of multiple properties. And properties + have <em>property types</em>. Note that single-property schemas and property types are + being released in A-Frame <code>v0.2.0</code>.</p> + <p>A property might look like:</p> + <div class="highlight"><pre><span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">'int'</span><span class="p">,</span> <span class="k">default</span><span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> + </pre></div> + + + <p>And a schema consisting of multiple properties might look like:</p> + <div class="highlight"><pre><span class="p">{</span> + <span class="nx">color</span><span class="o">:</span> <span class="p">{</span> <span class="k">default</span><span class="o">:</span> <span class="s1">'#FFF'</span> <span class="p">},</span> + <span class="nx">target</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">'selector'</span> <span class="p">},</span> + <span class="nx">uv</span><span class="o">:</span> <span class="p">{</span> + <span class="k">default</span><span class="o">:</span> <span class="s1">'1 1'</span><span class="p">,</span> + <span class="nx">parse</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="p">{</span> + <span class="k">return</span> <span class="nx">value</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">' '</span><span class="p">).</span><span class="nx">map</span><span class="p">(</span><span class="nb">parseFloat</span><span class="p">);</span> + <span class="p">}</span> + <span class="p">},</span> + <span class="p">}</span> + </pre></div> + + + <p>Since components in the entity-component system are just buckets of data that + are used to affect the appearance or behavior of the entity, the schema plays a + crucial role in the definition of the component.</p> + <h4>Property Types</h4> + <p>A-Frame comes with several built-in property types such as <code>boolean</code>, <code>int</code>, + <code>number</code>, <code>selector</code>, <code>string</code>, or <code>vec3</code>. Every single property is assigned a + type, whether explicitly through the <code>type</code> key or implictly via inferring the + value. And each type is used to assign <code>parse</code> and <code>stringify</code> functions. The + parser deserializes the incoming string value from the DOM to be put into the + component's data object. The stringifier is used when using <code>setAttribute</code> to + serialize back to the DOM.</p> + <p>We can actually define and register our own property types:</p> + <div class="highlight"><pre><span class="nx">AFRAME</span><span class="p">.</span><span class="nx">registerPropertyType</span><span class="p">(</span><span class="s1">'radians'</span><span class="p">,</span> <span class="p">{</span> + <span class="nx">parse</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + + <span class="p">}</span> + + <span class="c1">// Default stringify is .toString().</span> + <span class="p">});</span> + </pre></div> + + + <h4>Single-Property Schemas</h4> + <p>If a component has only one property, then it must either have a <code>type</code> or a + <code>default</code> value. If the type is defined, then the type is used to parse and + coerce the string retrieved from the DOM (e.g., <code>getAttribute</code>). Or if the + default value is defined, the default value is used to infer the type.</p> + <p>Take for instance the <a href="https://aframe.io/docs/components/visible.html">visible component</a>. The schema property + definition implicitly defines it as a boolean:</p> + <div class="highlight"><pre><span class="nx">AFRAME</span><span class="p">.</span><span class="nx">registerComponent</span><span class="p">(</span><span class="s1">'visible'</span><span class="p">,</span> <span class="p">{</span> + <span class="nx">schema</span><span class="o">:</span> <span class="p">{</span> + <span class="c1">// Type will be inferred to be boolean.</span> + <span class="k">default</span><span class="o">:</span> <span class="kc">true</span> + <span class="p">},</span> + + <span class="c1">// ...</span> + <span class="p">});</span> + </pre></div> + + + <p>Or the <a href="https://aframe.io/docs/components/rotation.html">rotation component</a> which explicitly defines the value as a <code>vec3</code>:</p> + <div class="highlight"><pre><span class="nx">AFRAME</span><span class="p">.</span><span class="nx">registerComponent</span><span class="p">(</span><span class="s1">'rotation'</span><span class="p">,</span> <span class="p">{</span> + <span class="nx">schema</span><span class="o">:</span> <span class="p">{</span> + <span class="c1">// Default value will be 0, 0, 0 as defined by the vec3 property type.</span> + <span class="nx">type</span><span class="o">:</span> <span class="s1">'vec3'</span> + <span class="p">}</span> + + <span class="c1">// ...</span> + <span class="p">});</span> + </pre></div> + + + <p>Using these defined property types, schemas are processed by + <code>registerComponent</code> to inject default values, parsers, and stringifiers for + each property. So if a default value is not defined, the default value will be + whatever the property type defines as the "default default value".</p> + <h4>Multiple-Property Schemas</h4> + <p>If a component has multiple properties (or one named property), then it consists of + one or more property definitions, in the form described above, in an object keyed by + property name. For instance, a physics body component might define a schema:</p> + <div class="highlight"><pre><span class="nx">AFRAME</span><span class="p">.</span><span class="nx">registerComponent</span><span class="p">(</span><span class="s1">'physics-body'</span><span class="p">,</span> <span class="p">{</span> + <span class="nx">schema</span><span class="o">:</span> <span class="p">{</span> + <span class="nx">boundingBox</span><span class="o">:</span> <span class="p">{</span> + <span class="nx">type</span><span class="o">:</span> <span class="s1">'vec3'</span><span class="p">,</span> + <span class="k">default</span><span class="o">:</span> <span class="p">{</span> <span class="nx">x</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">y</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">z</span><span class="o">:</span> <span class="mi">1</span> <span class="p">}</span> + <span class="p">},</span> + <span class="nx">mass</span><span class="o">:</span> <span class="p">{</span> + <span class="k">default</span><span class="o">:</span> <span class="mi">0</span> + <span class="p">},</span> + <span class="nx">velocity</span><span class="o">:</span> <span class="p">{</span> + <span class="nx">type</span><span class="o">:</span> <span class="s1">'vec3'</span> + <span class="p">}</span> + <span class="p">}</span> + <span class="p">}</span> + </pre></div> + + + <p>Having multiple properties is what makes the component take the syntax in the + form of <code>physics="mass: 2; velocity: 1 1 1"</code>.</p> + <p>With the schema defined, all data coming into the component will be passed + through the schema for parsing. Then in the lifecycle methods, the component + has access to <code>this.data</code> which in a single-property schema is a value and in a + multiple-propery schema is an object.</p> + <h3>Defining the Lifecycle Methods</h3> + <h4>Component.init() - Set Up</h4> + <p><code>init</code> is called once in the component's lifecycle when it is mounted to the + entity. <code>init</code> is generally used to set up variables or members that may used + throughout the component or to set up state. Though not every component will + need to define an <code>init</code> handler. Sort of like the component-equivalent method + to <code>createdCallback</code> or <code>React.ComponentDidMount</code>.</p> + <p>For example, the <code>look-at</code> component's <code>init</code> handler sets up some variables:</p> + <div class="highlight"><pre><span class="nx">init</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">target3D</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span> + <span class="k">this</span><span class="p">.</span><span class="nx">vector</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">THREE</span><span class="p">.</span><span class="nx">Vector3</span><span class="p">();</span> + <span class="p">},</span> + + <span class="c1">// ...</span> + </pre></div> + + + <h4>Component.update(oldData) - Do the Magic</h4> + <p>The <code>update</code> handler is called both at the beginning of the component's + lifecycle with the initial <code>this.data</code> <em>and</em> every time the component's data + changes (generally during the entity's <code>attributeChangedCallback</code> like with a + <code>setAttribute</code>). The update handler gets access to the previous state of the + component data passed in through <code>oldData</code>. The previous state of the component + can be used to tell exactly which properties changed to do more granular + updates.</p> + <p>The update handler uses <code>this.data</code> to modify the entity, usually interacting + with three.js APIs. One of the simplest update handlers is the + <a href="https://aframe.io/docs/components/visible.html">visible</a> component's:</p> + <div class="highlight"><pre><span class="nx">update</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">object3D</span><span class="p">.</span><span class="nx">visible</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">;</span> + <span class="p">}</span> + </pre></div> + + + <p>A slightly more complex update handler might be the <a href="https://aframe.io/docs/components/light.html">light</a> component's, + which we'll show via abbreviated code:</p> + <div class="highlight"><pre><span class="nx">update</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">oldData</span><span class="p">)</span> <span class="p">{</span> + <span class="kd">var</span> <span class="nx">diffData</span> <span class="o">=</span> <span class="nx">diff</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="nx">oldData</span> <span class="o">||</span> <span class="p">{});</span> + + <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">light</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="p">(</span><span class="s1">'type'</span> <span class="k">in</span> <span class="nx">diffData</span><span class="p">))</span> <span class="p">{</span> + <span class="c1">// If there is an existing light and the type hasn't changed, update light.</span> + <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">diffData</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">property</span><span class="p">)</span> <span class="p">{</span> + <span class="nx">light</span><span class="p">[</span><span class="nx">property</span><span class="p">]</span> <span class="o">=</span> <span class="nx">diffData</span><span class="p">[</span><span class="nx">property</span><span class="p">];</span> + <span class="p">});</span> + <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> + <span class="c1">// No light exists yet or the type of light has changed, create a new light.</span> + <span class="k">this</span><span class="p">.</span><span class="nx">light</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">getLight</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">));</span> + + <span class="c1">// Register the object3D of type `light` to the entity.</span> + <span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">setObject3D</span><span class="p">(</span><span class="s1">'light'</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">light</span><span class="p">);</span> + <span class="p">}</span> + <span class="p">}</span> + </pre></div> + + + <p>The entity's <code>object3D</code> is a plain THREE.Object3D. Other three.js object types + such as meshes, lights, and cameras can be set with <code>setObject3D</code> where they + will be appeneded to the entity's <code>object3D</code>.</p> + <h4>Component.remove() - Tear Down</h4> + <p>The <code>remove</code> handler is called when the component detaches from the entity such + as with <code>removeAttribute</code>. This is generally used to remove all modifications, + listeners, and behaviors to the entity that the component added.</p> + <p>For example, when the <a href="https://aframe.io/docs/components/light.html">light component</a> detaches, it removes the light + it previously attached from the entity and thus the scene:</p> + <div class="highlight"><pre><span class="nx">remove</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">removeObject3D</span><span class="p">(</span><span class="s1">'light'</span><span class="p">);</span> + <span class="p">}</span> + </pre></div> + + + <h4>Component.tick(time) - Background Behavior</h4> + <p>The <code>tick</code> handler is called on every single tick or render loop of the scene. + So expect it to run on the order of 60-120 times for second. The global uptime of + the scene in seconds is passed into the tick handler.</p> + <p>For example, the <a href="https://aframe.io/docs/components/look-at.html">look-at</a> component, which instructs an entity to + look at another target entity, uses the tick handler to update the rotation in + case the target entity changes its position:</p> + <div class="highlight"><pre><span class="nx">tick</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">t</span><span class="p">)</span> <span class="p">{</span> + <span class="c1">// target3D and vector are set from the update handler.</span> + <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">target3D</span><span class="p">)</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">object3D</span><span class="p">.</span><span class="nx">lookAt</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">vector</span><span class="p">.</span><span class="nx">setFromMatrixPosition</span><span class="p">(</span><span class="nx">target3D</span><span class="p">.</span><span class="nx">matrixWorld</span><span class="p">));</span> + <span class="p">}</span> + <span class="p">}</span> + </pre></div> + + + <h4>Component.pause() and Component.play() - Stop and Go</h4> + <p>To support pause and play, just as with a video game or to toggle entities for + performance, components can implement <code>play</code> and <code>pause</code> handlers. These are + invoked when the component's entity runs its <code>play</code> or <code>pause</code> method. When an + entity plays or pauses, all of its child entities are also played or paused.</p> + <p>Components should implement play or pause handlers if they register any + dynamic, asynchronous, or background behavior such as animations, event + listeners, or tick handlers.</p> + <p>For example, the <code>look-controls</code> component simply removes its event listeners + such that the camera does not move when the scene is paused, and it adds its + event listeners when the scene starts playing or is resumed:</p> + <div class="highlight"><pre><span class="nx">pause</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">removeEventListeners</span><span class="p">()</span> + <span class="p">},</span> + + <span class="nx">play</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">addEventListeners</span><span class="p">()</span> + <span class="p">}</span> + </pre></div> + + + <h3>Boilerplate</h3> + <p>I suggest that people start off with my <a href="https://github.com/ngokevin/aframe-component-boilerplate">component boilerplate</a>, + even hardcore tool junkies. This will get you straight into building a + component and comes with everything you will need to publish your component + into the wild. The boilerplate handles creating a stubbed component, build + steps for both NPM and browser distribution files, and publishing to Github + Pages.</p> + <p>Generally with boilerplates, it is better to start from scratch and build your + own boilerplate, but the A-Frame component boilerplate contains a lot of tribal + inside knowledge about A-Frame and is updated frequently to reflect new things + landing on A-Frame. The only possibly opinionated pieces about the boilerplate + is the development tools it internally uses that are hidden away by NPM + scripts.</p> + <h3>Examples</h3> + <p>Under construction. Stay tuned!</p> + <h4>Text Component</h4> + <p><a href="https://github.com/ngokevin/aframe-text-component">Text component</a></p> + <h4>Physics Components</h4> + <p><a href="https://github.com/ngokevin/aframe-physics-components">Physics components</a></p> + <h4>Layout Component</h4> + <p><a href="https://github.com/ngokevin/aframe-layout-component">Layout component</a></p> + 2016-01-17T00:00:00+00:00 + + + Gervase Markham: Convenient… and Creepy + http://feedproxy.google.com/~r/HackingForChrist/~3/DN054t04_dE/ + <p>The last Mozilla All-Hands was at one of the hotels in the Walt Disney World Resort in Florida. Every attendee was issued with one of these (although their use was optional):<br /> + <a href="http://blog.gerv.net/files/2016/01/Disneys_MagicBand.jpg"><img class="alignnone size-large wp-image-3530" src="http://blog.gerv.net/files/2016/01/Disneys_MagicBand-1024x832.jpg" width="292" /></a></p> + <p>It’s called a “Magic Band”. You register it online and connect it to your Disney account, and then it can be used for park entry, entry to pre-booked rides so you don’t have to queue (called “FastPass+”), payment, picking up photos, as your room key, and all sorts of other convenient features. Note that it has no UI whatsoever – no lights, no buttons. Not even a battery compartment. (It does contain a battery, but it’s not replaceable.) These are specific design decisions – the aim is for ultra-simple convenience.</p> + <p>One of the talks we had at the All Hands was from one of the Magic Band team. The audience reactions to some of the things he said was really interesting. He gave the example of Cinderella wishing you a Happy Birthday as you walk round the park. “Cinderella just knows”, he said. Of course, in fact, her costume’s tech prompts her when it silently reads your Magic Band from a distance. This got some initial impressed applause, but it was noticeable that after a few moments, it wavered – people were thinking “Cool… er, but creepy?”</p> + <p>The Magic Band also has range sufficient that Disney can track you around the park. This enables some features which are good for both customers and Disney – for example, they can use it for load balancing. If one area of the park seems to be getting overcrowded, have some characters pop up in a neighbouring area to try and draw people away. But it means that they always know where you are and where you’ve been.</p> + <p>My take-away from learning about the Magic Band is that it’s really hard to have a technical solution to this kind of requirement which allows all the Convenient features but not the Creepy features. Disney does offer an RFID-card-based solution for the privacy-conscious which does some of these things, but not all of them. And it’s easier to lose. It seems to me that the only way to distinguish the two types of feature, and get one and not the other, is policy – either the policy of the organization, or external restrictions on them (e.g. from a watchdog body’s code of conduct they sign up to, or from law). And it’s often not in the organization’s interest to limit themselves in this way.</p> + <img alt="" height="1" src="http://feeds.feedburner.com/~r/HackingForChrist/~4/DN054t04_dE" width="1" /> + 2016-01-16T12:18:38+00:00 + gerv + + + Christian Heilmann: Don’t tell me what my browser can’t do! + https://www.christianheilmann.com/2016/01/16/dont-tell-me-what-my-browser-cant-do/ + <p><em class="markup--em markup--p-em">Chances are, your guess is wrong!</em></p> + + <p></p><figure><img alt="you are obviously in the wrong place" src="https://d262ilb51hltx0.cloudfront.net/max/800/1*l9jPbOyAl00kjPhyNYA-IQ.jpeg" width="100%" />Arrogance towards possible customers never pays out – as shown in “Pretty Woman”</figure><p></p> + + <p>There is nothing more frustrating than being capable of something and not getting a chance to do it. The same goes for being blocked out from something although you are capable of consuming it. Or you’re even willing to put some extra effort or even money in and you still don’t get to consume it.</p> + + <p>For example, I’d happily pay $50 a month to get access to Netflix’s world-wide library from any country I’m in. But the companies Netflix get their content from won’t go for that. Movies and TV show are budgeted by predicted revenue in different geographical markets with month-long breaks in between the releases. A world-wide network capable of delivering content in real time? Preposterous — let’s shut that down.</p> + + <p>On a less “let’s break a 100 year old monopoly” scale of annoyance, <a href="https://twitter.com/codepo8/status/687616620529844224">I tweeted yesterday something glib and apparently cruel</a>:</p> + + <p></p><blockquote>“Sorry, but your browser does not support WebGL!” – sorry, you are a shit coder.</blockquote><p></p> + + <p><strong>And I stand by this</strong>. I went to a web site that promised me some cute, pointless animation and technological demo. I was using Firefox Nightly — a WebGL capable browser. I also went there with Microsoft Edge — another WebGL capable browser. Finally, using Chrome, I was able to delight in seeing an animation.</p> + + <p><strong>I’m not saying the creators of that thing lack in development capabilities</strong>. The demo was slick, beautiful and well coded. They still do lack in two things developers of <em>web products </em>(and I count apps into that) should have: empathy for the end user and an understanding that they are not in control.</p> + + <p>Now, I am a pretty capable technical person. When you tell me that I might be lacking WebGL, I know what you mean. I don’t lack WebGL. I was blocked out because the web site did browser sniffing instead of capability testing. But I know what could be the problem.</p> + + <p>A normal user of the web has no idea what WebGL is and — if you’re lucky — will try to find it on an app store. If you’re not lucky all you did is confuse a person. A person who went through the effort to click a link, open a browser and wait for your thing to load. A person that feels stupid for using your product as they have no clue what WebGL is and won’t ask. Humans hate feeling stupid and we do anything not to appear it or show it.</p> + + <p>This is what I mean by empathy for the end user. Our problems should never become theirs.</p> + + <p></p><blockquote>A cryptic error message telling the user that they lack some technology helps nobody and is sloppy development at best, sheer arrogance at worst.</blockquote><p></p> + + <p>The web is, sadly enough, littered with unhelpful error messages and assumptions that it is the user’s fault when they can’t consume the thing we built.</p> + + <p>Here’s a reality check — this is what our users should have to do to consume the things we build:</p> + + <p><img alt="" height="600" src="https://d262ilb51hltx0.cloudfront.net/max/800/1*DXtRIWTu-UzRb0YB-h8SmA.png" width="10" /></p> + + <p><strong>That’s right. Nothing</strong>. This is the web. Everybody is invited to consume, contribute and create. This is what made it the success it is. This is what will make it outlive whatever other platform threatens it with shiny impressive interactions. Interactions at that time impossible to achieve with web technologies.</p> + + <p>Whenever I mention this, the knee-jerk reaction is the same:</p> + + <p></p><blockquote class="graf--blockquote graf-after--p" id="79d6" name="79d6">How can you expect us to build delightful experiences close to magic (and whatever other soundbites were in the last Apple keynote) if we keep having to support old browsers and users with terrible setups?</blockquote><p></p> + + <p>You don’t have to support old browsers and terrible setups. But you are not allowed to block them out. It is a simple matter of giving a usable interface to end users. A button that does nothing when you click it is not a good experience. Test if the functionality is available, then create or show the button. <strong class="markup--strong markup--p-strong">This is as simple as it is.</strong></p> + + <p>If you really have to rely on some technology then show people what they are missing out on and tell them how to upgrade. A screenshot or a video of a WebGL animation is still lovely to see. A message telling me I have no WebGL less so.</p> + + <p>Even more on the black and white scale, what the discussion boils down to is in essence:</p> + + <p></p><blockquote class="graf--blockquote graf-after--p" id="a775" name="a775">But it is 2016 — surely we can expect people to have JavaScript enabled — it is after all “the assembly language of the web”</blockquote><p></p> + + <p>Despite the cringe-worthy <a href="http://www.hanselman.com/blog/JavaScriptIsAssemblyLanguageForTheWebSematicMarkupIsDeadCleanVsMachinecodedHTML.aspx">misquote of the assembly language</a> thing, here is a harsh truth:</p> + + <p></p><blockquote>You can absolutely expect JavaScript to be available on your end users computers in 2016. At the same time it is painfully <strong>naive</strong> to expect it to work under all circumstances.</blockquote><p></p> + + <p><strong>JavaScript is brittle</strong>. <span class="caps">HTML</span> and <span class="caps">CSS</span> both are <em>fault tolerant</em>. If something goes wrong in <span class="caps">HTML</span>, browsers either display the content of the element or try to fix minor issues like unclosed elements for you. <span class="caps">CSS</span> skips lines of code it can’t understand and merrily goes on its way to show the rest of it. JavaScript breaks on errors and tells you that something went wrong. It will not execute the rest of the script, but throws in the towel and tells you to get your house in order first.</p> + + <p>There <a href="http://kryogenix.org/code/browser/everyonehasjs.html">are many outside influences</a> that will interfere with the execution of your JavaScript. That’s why a non-naive and non-arrogant — a dedicated and seasoned web developer — will never rely on it. Instead, you treat it as an enhancement and in an almost paranoid fashion test for the availability of everything before you access it.</p> + + <p><strong>Sorry (not sorry) — this will never go away</strong>. This is the nature of JavaScript. And it is a good thing. It means we can access new features of the language as they come along instead of getting stuck in a certain state. It means we have to think about using it every time instead of relying on libraries to do the work for us. It means that we need to keep evolving with the web — a living and constantly changing medium, and not a software platform. That’s just part of it.</p> + + <p>This is why the whole discussion about JavaScript enabled or disabled is a massive waste of time. It is not the availability of JavaScript we need to worry about. It is our products breaking in perfectly capable environments because we rely on perfect execution instead of writing defensive code. A tumblr like <a class="markup--anchor markup--p-anchor" href="http://sighjavascript.tumblr.com/" rel="nofollow">Sigh, JavaScript</a> is fun, but is pithy finger-pointing.</p> + + <p></p><blockquote>There is nothing wrong with using JavaScript to build things. Just be aware that the error handling is your responsibility.</blockquote><p></p> + + <p>Any message telling the user that they have to turn on JavaScript to use a certain product is a proof that you care more about your developer convenience than your users.</p> + + <p></p><blockquote>It is damn hard these days to turn off JavaScript – you are complaining about a almost non-existent issue and tell the confused user to do something they don’t know how to.</blockquote><p></p> + + <p>The chance that something in the JavaScript execution of any of your dozens of dependencies went wrong is much higher – and this is your job to fix. This is why advice like <a href="http://webdesign.tutsplus.com/tutorials/quick-tip-dont-forget-the-noscript-element--cms-25498">using noscript to provide alternative content</a> is terrible. It means you double your workload instead of enhancing what works. Who knows? If you start with something not JavaScript dependent (or running it server side) you might find that you don’t need the complex solution you started with in the first place. Faster, smaller, easier. Sounds good, right?</p> + + <p>So, please, stop sniffing my browser, you will fail and tell me lies. Stop pretending that working with a brittle technology is the user’s fault when something goes wrong.</p> + + <p></p><blockquote>As web developers we work in the service industry. We deliver products to people. And keeping these people happy and non-worried is our job. Nothing more, nothing less.</blockquote><p></p> + + <p>Without users, your product is nothing. Sure, we are better paid and well educated and we are not flipping burgers. But we have no right whatsoever to be arrogant and not understanding that our mistakes are not the fault of our end users.</p> + + <p>Our demeanor when complaining about how stupid our end users and their terrible setups are reminds me of <a href="https://www.youtube.com/watch?v=CSj5stmFkQ0">this Mitchell and Webb sketch</a>.</p> + + <p></p> + + <p><strong class="markup--strong markup--p-strong">Don’t be that person. </strong>Our job is to enable people to consume, participate and create the web. This is magic. This is beautiful. This is incredibly rewarding. The next markets we should care about are ready to be as excited about the web as we were when we first encountered it. Browsers are good these days. Use what they offer after testing for it and enjoy what you can achieve. Don’t tell the user when things go wrong – they can not fix what you messed up.</p> + + + <img alt="" height="1" src="http://feeds.feedburner.com/~r/chrisheilmann/~4/vqtqgcNQXy8" width="1" /> + 2016-01-16T11:28:10+00:00 + Chris Heilmann + + + Mike Hommey: Announcing git-cinnabar 0.3.1 + http://glandium.org/blog/?p=3510 + <p>This is a brown paper bag release. It turns out I managed to break the upgrade<br /> + path only 10 commits before the release.</p> + <h3>What’s new since 0.3.0?</h3> + <ul> + <li><code>git cinnabar fsck</code> doesn’t fail to upgrade metadata.</li> + <li>The <code>remote.$remote.cinnabar-draft</code> config works again.</li> + <li>Don’t fail to clone an empty repository.</li> + <li>Allow to specify mercurial configuration items in a .git/hgrc file.</li> + </ul> + 2016-01-16T11:26:45+00:00 + glandium + + + Emily Dunham: Buildbot and EOFError + http://edunham.net/2016/01/16/buildbot_and_eoferror.html + <h3>Buildbot and EOFError</h3> + <p>More SEO-bait, after tracking down an poorly documented problem:</p> + <div class="highlight-python"><div class="highlight"><pre># buildbot start master + Following twistd.log until startup finished.. + 2016-01-17 04:35:49+0000 [-] Log opened. + 2016-01-17 04:35:49+0000 [-] twistd 14.0.2 (/usr/bin/python 2.7.6) starting up. + 2016-01-17 04:35:49+0000 [-] reactor class: twisted.internet.epollreactor.EPollReactor. + 2016-01-17 04:35:49+0000 [-] Starting BuildMaster -- buildbot.version: 0.8.12 + 2016-01-17 04:35:49+0000 [-] Loading configuration from '/home/user/buildbot/master/master.cfg' + 2016-01-17 04:35:53+0000 [-] error while parsing config file: + Traceback (most recent call last): + File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 577, in _runCallbacks + current.result = callback(current.result, *args, **kw) + File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1155, in gotResult + _inlineCallbacks(r, g, deferred) + File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1099, in _inlineCallbacks + result = g.send(result) + File "/usr/local/lib/python2.7/dist-packages/buildbot/master.py", line 189, in startService + self.configFileName) + --- &lt;exception caught here&gt; --- + File "/usr/local/lib/python2.7/dist-packages/buildbot/config.py", line 156, in loadConfig + exec f in localDict + File "/home/user/buildbot/master/master.cfg", line 415, in &lt;module&gt; + extra_post_params={'secret': HOMU_BUILDBOT_SECRET}, + File "/usr/local/lib/python2.7/dist-packages/buildbot/status/status_push.py", line 404, in __init__ + secondaryQueue=DiskQueue(path, maxItems=maxDiskItems)) + File "/usr/local/lib/python2.7/dist-packages/buildbot/status/persistent_queue.py", line 286, in __init__ + self.secondaryQueue.popChunk(self.primaryQueue.maxItems())) + File "/usr/local/lib/python2.7/dist-packages/buildbot/status/persistent_queue.py", line 208, in popChunk + ret.append(self.unpickleFn(ReadFile(path))) + exceptions.EOFError: + + 2016-01-17 04:35:53+0000 [-] Configuration Errors: + 2016-01-17 04:35:53+0000 [-] error while parsing config file: (traceback in logfile) + 2016-01-17 04:35:53+0000 [-] Halting master. + 2016-01-17 04:35:53+0000 [-] Main loop terminated. + 2016-01-17 04:35:53+0000 [-] Server Shut Down. + </pre></div> + </div> + <p>This happened after the buildmaster’s disk filled up and a bunch of stuff was + manually deleted. There were no changes to master.cfg since it worked + perfectly.</p> + <p>The fix was to examine <span class="docutils literal"><span class="pre">master.cfg</span></span> to see <a class="reference external" href="https://github.com/servo/saltfs/blob/master/buildbot/master/master.cfg#L413">where the HttpStatusPush was + created</a>, + of the form:</p> + <div class="highlight-python"><div class="highlight"><pre><span class="n">c</span><span class="p">[</span><span class="s">'status'</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">HttpStatusPush</span><span class="p">(</span> + <span class="n">serverUrl</span><span class="o">=</span><span class="s">'http://build.servo.org:54856/buildbot'</span><span class="p">,</span> + <span class="n">extra_post_params</span><span class="o">=</span><span class="p">{</span><span class="s">'secret'</span><span class="p">:</span> <span class="n">HOMU_BUILDBOT_SECRET</span><span class="p">},</span> + <span class="p">))</span> + </pre></div> + </div> + <p>Digging in the Buildbot source reveals that <span class="docutils literal"><span class="pre">persistent_queue.py</span></span> wants to + unpickle a cache file from <span class="docutils literal"><span class="pre">/events_build.servo.org/-1</span></span> if there was nothing + in <span class="docutils literal"><span class="pre">/events_build.servo.org/</span></span>. To fix this the right way, create that file + and make sure Buildbot has <span class="docutils literal"><span class="pre">+rwx</span></span> on it.</p> + <p>Alternately, you can give up on writing your status push cache to disk + entirely by adding the line <span class="docutils literal"><span class="pre">maxDiskItems=0</span></span> to the creation of the + HttpStatusPush, giving you:</p> + <div class="highlight-python"><div class="highlight"><pre><span class="n">c</span><span class="p">[</span><span class="s">'status'</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">HttpStatusPush</span><span class="p">(</span> + <span class="n">serverUrl</span><span class="o">=</span><span class="s">'http://build.servo.org:54856/buildbot'</span><span class="p">,</span> + <span class="n">maxDiskItems</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> + <span class="n">extra_post_params</span><span class="o">=</span><span class="p">{</span><span class="s">'secret'</span><span class="p">:</span> <span class="n">HOMU_BUILDBOT_SECRET</span><span class="p">},</span> + <span class="p">))</span> + </pre></div> + </div> + <p>The real moral of the story is “remember to use <a class="reference external" href="http://www.linuxcommand.org/man_pages/logrotate8.html">logrotate</a>.</p> + 2016-01-16T08:00:00+00:00 + + + Daniel Glazman: Ebook pagination and CSS + http://www.glazman.org/weblog/dotclear/index.php?post/2016/01/16/Ebook-pagination-and-CSS + <p>Let's suppose you have a rather long document, for instance a book chapter, and you want to render it in your browser <em>à la</em> iBooks/Kindle. That's rather easy with just a dash of CSS:</p> + <pre>body { + height: calc(100vh - 24px); + column-width: 45vw; + overflow: hidden; + margin-left: calc(-50vw * attr(currentpage integer)); + }</pre> + <p>Yes, yes, I know that no browser implements that <code>attr()</code>extended syntax. So put an inline style on your body for <code>margin-left: calc(-50vw * <em>&lt;n&gt;</em>)</code> where <em><code>&lt;n&gt;</code></em> is the page number you want minus 1.</p> + <p>Then add the fixed positioned controls you need to let user change page, plus gesture detection. Add a transition on margin-left to make it nicer. Done. Works perfectly in Firefox, Safari, Chrome and Opera. I don't have a Windows box handy so I can't test on Edge.</p> + 2016-01-16T03:43:00+00:00 + glazou + + + Nicolas Mandil: Mozilla cultural revolution: from ‘radical participation’ to ‘radical user-centric’ + https://repeer.org/2016/01/16/mozilla-cultural-revolution-from-radical-participation-to-radical-user-centric/ + <p>This post has been written about the <a href="http://marksurman.commons.ca/2015/12/21/mofo2020/">Mozilla Foundation (MoFo) 2020 strategy</a>.</p> + <p>The ideas developed in this post are in different levels: some are global, some focus on particular points of the proposed draft. But in my point of view, they all carry a transversal meaning: articulation (as piece connected to a structure allowing movement) with others and consistency with our mission.</p> + <h3>Summary</h3> + <p>On the way to <a href="http://marksurman.commons.ca/2015/01/09/what-is-radical-participation/">radical participation</a>, Mozilla should be radical <sup class="footnote"><a href="https://repeer.org/tag/mozilla/feed/#fn-48-1" id="fnref-48-1">1</a></sup> user-centric. Mozilla should not go against the social understanding of the (tech and whole society) situation because it’s what is massively shared and what polarizes the prism of understanding of the society. <strong>We should built solutions for it and transform (develop and change) it on the way. Our responsibility is to build <em>inclusivity</em> (inclusion strengths) everywhere, to gather for multiplying our impact.</strong> We must build (progressive) victories instead of battles (of static positions and postures).<br /> + If we don’t do it, we go against users self-perceived need: use. We value our differences more than our commonalities and <strong>consider ethic more as an absolute objective than a concrete process</strong>: we divide, separate, compete. Our solutions get irrelevant, we get rejected and marginalized, we reject compromises that improve the current situation for the ideal, we loose influence and therefore impact on the definition of the present and future. We already done it for the good and the bad in the past (H.264+Daala, pocket integration, Hello login, no Firefox for iOS, Google fishing vs Disconnect, FxOS Notes app which sync is evernote only, …).<br /> + To get a consistent and impactful ability to integrate and transform the social understanding, there are four domains where we can take and articulate (connected structure allowing movement) action:</p> + <ul> + <li><strong>People</strong>: identity is the key to grow consciousness, understanding, skills, voice, representation and to articulate global/local, personal/common. <strong>[Activate]</strong></li> + <li><strong>Technology</strong>: universality is key for a platform (for resilience) with interfaces (for modularity) where services, features and front-ends can plug-in and communicate to provide (inter)active support ; Decouple conditions of fulfillment with execution (content/appearance/policy ; material/immaterial) to support remix (policy continuity, consistency thought providers, …). <strong>[Unlock]</strong></li> + <li><strong>Product</strong>: persona and (current and emerging) use via user-agents are the keys. Be on all major platforms depending on use, ethical alignment and opportunities, emerging newness to provide continuity (task, device) to users and leading on new practices. Features should be about products parity and opening new possibilities carrying our values to the action at a massive scale. <strong>[Build]</strong></li> + <li><strong>Organizations/institutions</strong>: sociological innovation for participation is the key. Research on historical (evolution) and sociological (human organizations, social institutions and social behaviors) analysis based on social networks (link as social interactions), in the perspective of producing commons. <strong>[Drive]</strong></li> + </ul> + <p>Our front has two sides: <strong>propose and protect</strong>. But each of them are connected and can have different strategic expressions, if our actions generate improving (progressive) curves:</p> + <ul> + <li>For the <strong>action taking</strong>: consciousness, understanding, symbolic actions, behavior change, behavior advocacy (evangelism)</li> + <li>For the <strong>action mode</strong>: promotion (spreading the idea), incitement (giving a competitive advantage to people involved), collaboration (open interactions to make a win-win exchange; process-centric), contractualization (formalize domains where a win-win exchange is made; object-centric), coercion (giving a competitive disadvantage to people not involved).</li> + </ul> + <p>Social history is a history of social values.<strong> The way we understand and tell the problem determine the solution we can create</strong>: we need, all the way long, a shared understanding. Tools and technologies are not tied, bound forever to their social value, which depends on people’s social representations that evolve over time.</p> + <ul> + <li><strong>The social behavior</strong> is a first key. It is the narrative, and therefore its <strong>inclusion in the social history that we make, which converges the product with the values that it stands for</strong>. Here is the articulation of product with people and technology, of product with leadership network and advocacy engine (it could be less persistent and inclusive: marketing).</li> + <li><strong>The social organization</strong> is a second key. It is about how the process, the tools, the architecture, the governance and the opportunities/constraints have changed for Mozilla (org) and Mozillians (people). <strong>Here comes the question of being open</strong>. It is not enough because it is about availability (passive) and not inclusivity (active). The high level of automation coming is a challenge. We should level-up the meaning to differentiate from others: <strong>Mozilla should activate and unlock societal progress to build fair technical progress</strong>. Mozilla need to <strong>identify its resilient backbone</strong> (not only a technology, the web, but something that articulate people, technology and products) and make it more universal (through people and products). But our goals can’t be absolutely achieved because they have to be considered in a dynamic context. However, the brand engagement is persistent, if it’s included in the product, visible, and centered on easing the user’s action.<br /> + Linked to the ‘being open’ question, the advocacy engine could be a thing to unlock societal progress. People are satisfied of narrow hills of choice until they understand it’s not socially neutral. It’s the case with technology: they accept things about technology to be build top-down. <strong>A successful advocacy, even one about technology, is always built bottom-up</strong>, as its function is to give back the voice to the people, to get them involved, not to make them fulfill our predefined aims. The top-down method is too organization centric and administrative content centric: it can’t massively drive people that are not already committed to the org. It’s usually named advertisement or propaganda. <strong>If we want to have an impact, we should listen to people needs, not tell them to listen to ours</strong>. People want (first) to be empowered, not to empower an org. We need to have content and user centric (not org and it’s process) tools/platform for advocates and leaders: let’s build the technology advocacy plan together. Yes it’s slower, but much more massive, inclusive and persistent. The impact will be higher because it will carry a meaning for people and it wont be too org centric. So it will be qualitatively better: not just an amount, <strong>accumulation is not our goal, but impact, that comes from articulation</strong>. Likewise we should be careful to not use best practice as absolute solutions, but as solutions in a context, if we want to transpose them massively: when we unify we should avoid to homogenize. On the narrative side, our preoccupation should be about building short, medium and long term narrative to get action.</li> + <li><strong>The social institutions</strong> are the third key. Here is the articulation of the leadership network with the advocacy engine. <strong>Leaders build new solutions (products) and Advocates new voices (rallying), they are both about personal development and empower commons.</strong> Leadership=learn+create and advocacy=teach+spread commons. Leaders are projects/orgs leaders, the ones that traduce DNA (values) in products (concrete ability and availability). Advocates are values advocates, the ones that traduce DNA (values) in actions (behavior). As they are both targeting commons, they both produce the same social organization (collaboration instead of competition). They are both involved in creating (different) representations (institutions) and organizations (foundation/firms) but <strong>with a different DNA (values) processing</strong>: from public good to personal benefit or from personal interest to public benefit. If Mozilla cares about public good resilience, <strong>the articulation of their domains of values is critical</strong>. So, on the social organization side, their articulation’s expression and the revision process must be said and clear: from hierarchy or contract or different autonomy levels (internal incubation and external advocacy), or … to criteria to start a revision. About the narrative, and hence about the social behavior side, leaders carry a lot of legitimacy and avoid the stay-experimental or non-massive (unique) thoughts. And we need legitimacy to get impact. But this legitimacy is already present if we<strong> make clear that our actions are about commons</strong>. We should name them creators (compositors or managers) to make it clear that the creative process is a collaboration, made by a team and that the public good do not have the same role in the process and outcome. Full circle.</li> + <li><strong>The social networks</strong> are the keystone. Let’s shortly take an example based on social networks (link as social interactions) with the perspective of producing people, technological and product commons. <strong>We need better tools for collaboration and participation</strong>: tools that merge discussion channels, capitalize on the discussion and preview the results to build a plan. From evolving the wiki discussion page to feature document production into peer-to-peer discussion.</li> + </ul> + <p>An analysis of the creation process is another way to the articulation of product with people and technology.<br /> + Platforms move closer to strict ‘walled garden’ ecosystems. We need bridges from lab to home that carry different mix of customization and reliability to support the emancipation curve. We need to build pathways thought audiences and thought IT layers (content, software, hardware, distant service). <strong>We should find a convergence between customization</strong> (dev code patch to users add-ons) <strong>and reliability</strong> (self made to mass product), <strong>between first time experience, support and add-ons thought all our users’ persona by building bridges, pathways</strong>. Mozilla should find ways to <strong>integrate learning</strong> in its products, in-content, as we have code comment on code: on-boarding levels, progression from simple to high level techniques, reproducible/universal next task/skill building.</p> + <h3>Detailed discussion content</h3> + <p>Here are the developed ideas, with more reference to our allies and detractors’ products.</p> + <h4>People, the sociological side</h4> + <h5>From focused to systemic action</h5> + <p>First of all, I think <strong>the strategy move Mozilla is doing is the right one</strong> as it embraces more our real life. People are not defined by one characteristic, we are complex: ex. we can be pedestrian, car driver, biker, Public Transport user… we think and do simultaneously. So why Mozilla should restrict its strategy by targeting people on skills, through education, thought better material only (the Mozilla Academy program). Education, even popular education, can’t do everything for the people to build change. <strong>We need a plan that balance intellectual and practical (abstraction/action, think/do) integrating progressive paths to massively scale so we get an impact: build change.</strong></p> + <h5>Real life: Social history, individuals and institutions as an articulation founding the action.</h5> + <p>Let’s start by some definitions based on my understanding of some <a href="https://fr.wikipedia.org/wiki/Sociologie">Wikipedia articles</a>. Sociology is the study of the evolution of societies: human organizations and social institutions. It is about <strong>the impact of the social dimension on humans representations (ways of thinking) and behaviors (ways of acting)</strong>. It allows to study the conceptions of social relations according to fundamental criteria (structuralism, functionalism, conventionalism, etc.) and the hooks to reality (interactionism, institutionalism, regulationisme, actionism, etc.), to think and shape the modernity. Currently (and this is key for Mozilla’s positioning), the combination of models replace the models’ unity, which aims to assume the multidimensionality. There are three major sociological paradigms, including one emerging:</p> + <ul> + <li><strong>The holistic paradigm</strong>: Society is a whole that is greater than the sum of its parts, it exists before the individual and individuals are governed by it. In this context, the Society includes the individual and the individual consciousness is seen only as a fragment of the collective consciousness. The emphasis is on the social fact, whose cause must be sought in earlier social facts. The social fact is part of a system of interlocking institutions that govern individuals. It is external to the individual and constraint it. Sociology is then the science of institutional invariants in which are the observable phenomenas.</li> + <li><strong>The atomistic paradigm</strong>: each individual is a social atom. The atoms act according to self motives, interests, emotions and are linked to other atoms. A system of constant interaction between atoms produces and reproduces Society. The emphasis is on the cause of social actions and the meaning given by individuals to their actions. A horizon of meanings serve as reference instead of the arrangements of institutions. The institution is there but it serves the motives and interests of agents. Sociology is then the study of the social action.</li> + <li>The recent emergence of a sociological analysis based on <strong>social networks</strong> (which are a collection of individuals or organizations connected by regular social interactions) suggest lines of research <strong>beyond the opposition between the holistic and the atomistic approaches</strong>. The theory of social networks conceives social relationships in terms of nodes and links. The nodes are usually social actors in the network but can also represent institutions, and links are the relationships between these nodes. There may be several kinds of links between nodes and their analysis determines social capital of the social actors.</li> + </ul> + <p>Consequently, Mozilla should build its strategy on <strong>historical</strong> (evolution) and <strong>sociological</strong> (human organizations, social institutions and social behaviors) analysis based on <strong>social networks</strong> (links as social interactions), in the perspective of producing <strong>commons</strong>. That is to say as an <strong>engine of transition from a model of value</strong> on its last leg (rarity capitalism) to the emerging one (new articulation of the individual and the collective: commons).<br /> + It is important and strategic to propose a sociological articulation supporting our mission and its purpose (commons) since <strong>the sociological concept (the paradigm) reveals an ideological characteristic</strong>: because it participates in societal movements made in the Society, it serves an ideal. The societal domain, what’s making society, a political object, should be a stake for Mozilla.</p> + <h5>Build on a basement: current tech challenge articulated with current social meaning/perception</h5> + <p><strong>We should articulate ‘our real life’ with the nowadays tech challenge</strong>: how to get back control over our data at the time of IoT, cloud, big data, convergence (multi-devices/form factor)? From a user point of view, we have devices and want them convenient, easy and nice. The big moves in the tech industry (IoT, cloud, big data, convergence) free us for somethings and lock us for others. The lock key is that our devices don’t compute anymore our data that are in silos. From a developer point of view, the innovation is going very fast and it’s hard to have a complete open source toolbox that we can share, mostly because we don’t lead: Open has turn to be more open-releasing.<br /> + We should articulate our new strategy with the tech industry moves: for example, <strong>as a user, how can I get (email) encryption on all my devices?</strong> Should I follow (fragmented) different kind of howtos/tools/apps to achieve that? How do I know these are consistent together? How can I be sure it won’t brake my continuous workflow? (app silo? social silo? level of trust and reliability?)<br /> + Mozilla have the skills to answer this as we already faced and solved some of these issues on particular points: like how to ease the installation of Firefox for Android for Firefox desktop users, open and discoverable choice of search engines, synchronization across devices, …<br /> + <strong>Mozilla’s challenge is to not be marginalized by the change of practices. Having an impact is embracing the new practice and give it an alternative.</strong> Mozilla already made that move by saying « <em>Firefox will go where users are</em>« , by trying to balance the advertisement practice between adds companies and users, by integrating H.264 and developing Daala. But <strong>Mozilla never stated that clearly as a strategy</strong>.</p> + <h5>A backbone to make our mission resilient in it expressions</h5> + <p>If we think about the <strong>Facebook’s strategy, they first built a network of people whiling to share</strong> (no matter what they share) and then use this <strong>transversal backbone to power vertical business segments</strong> (search, donation, local market selling, …). Google with its search engine and its open source policy have a similar (in a way) strategy. The difference here is that the backbone is people’s data and control over digital formats. In both cases, the level of use (of the social network, search engine, mobile OS, …) is the key (with fast innovation) to have an impact. And that’s a major obstacle to build successful alternatives.<br /> + The proposed Mozilla’s strategy is built in the opposite way, and that’s questioning. <strong>We try to build people network depending on some shared matters</strong>. Then, is our strategy able to scale enough to compete against GAFAM, or are we trying to build a third way ?<br /> + For the products, the Mozilla’s strategy is still (and has always been) inclusive: everybody can use the product and then benefit of its open web values. A good product that answer people needs, plus giving people back/new power (allow new use) build a big community. For the network, should we build our global force of people based on concentric circles (of shared matters) or based on a (Mozilla own) transversal backbone (matter agnostic)? It seems to me the actual presentation of the strategy do not answer clearly enough this big question: <strong>which <em>inclusivity</em> (inclusion strengths) mechanism in the strategy?</strong><br /> + And that <strong>call back to our product strategy</strong>: build a community that shares values, that is used to spread outcomes (product) OR build a community that shares a product, that is used to spread values. This is not a question on what matters more (product VS values) but on the strategy to get to a point, an objective (many web citizens). Shouldn’t we use our product to built a people network backbone ? Back to GAFAM: what can we learn from the Google try with Google+?<br /> + If our core is not enough transversal (the backbone), more new web/tech market there will be, more we will be marginalized, because focused on our circles center not taking in account that the war front (the context) have changed. <strong>Mozilla have to be resilient: mutability of the means, stability in the objectives.</strong><br /> + The document is the MoFo strategy, and so it doesn’t say anything about ‘build Firefox’ (aka the product strategy) and so don’t articulate our main product (Firefox) with our main people network building effort and values sharing engine. We should do it: at a strategic scale and a particular scale (articulating the agenda-setting with main product features).</p> + <h5>Brand engagement, a psychological backbone on the user side ?</h5> + <p>It seems that our GAFAM challengers get big and have impact by not educating (that much) people, and that’s what makes them not involved in the web citizenship. Or only when they are pushed by their customers. At the opposite, making people aware about web citizenship at first, makes it hard to have that much people involved and so to have impact. However, there is <strong>an other prism that drive people: the brand perceived values</strong>. Google is seen as a tech pioneer innovator and doing the good because of its open policy, free model, fast innovation… Facebook is seen as really cool firm trying to help people by connecting them…<br /> + Is the increase of marketing of Mozilla doing good enough to gains back users ? Is this resilient compared to the next-tech-thing coming ?<br /> + Most of the time when I meet Goggle Chrome users and ask then why they use it and don’t switch to Firefox, they answer about use allowed (sync thought devices, apps everywhere that run only on GC, …). Sometimes, they argue that they make effort on other areas, and that they want to keep they digital life simple. They <strong>experience is not centered in a product/brand, but more on the person</strong>: on that Google Chrome with its Person (with one click ‘auto-login’ to all Google services) is far superior than Firefox.</p> + <h5>User-agent or products ?</h5> + <p>A user-agent is an intermediary acting on behalf of a supplier. As a representative, it is the contact point with customers; It’s role is to manage, to administer the affairs; it is entrusted with a mission by one or more persons; it both acts and produce an effect.<br /> + So, the user-agent can be describe with three criteria. It is: an intermediate (user/technology) ; a tool (used to manage and administrate depending on the user’s skills) ; a representative (mission bearer, values vector, for a group of people). It exceeds partly the contradiction between being active and passive.<br /> + A <strong>user-agent articulate personal-identity with technology-identity</strong> and give informations about available skills over these domains. It’s much more universal than a product that is about featuring a user-agent. <strong>If we target resilience, user-agent should be the target</strong>.</p> + <h4>Social history, marketing: how we understand things to make choices</h4> + <h5>History of the social value</h5> + <p>The way we look at the past and current facts shape our understanding and determine if we open new ways to solve the issues identified. That’s the way to understand the challenges that come on the way and to agree on an adaptation of the strategy instead of splitting things. The way we understand and tell the problem determine the solution we can create: we need, all the way long, <strong>a shared understanding.</strong><br /> + <strong>Tools and technologies are not necessarily tied to their social value, which depends on social representations. The social value can be built upstream and evolve downstream.</strong> It also depends on the perspective in which we look at it, on the understanding of the action and therefore on past or current history. Example: the social value of a weapon can be a potential danger or defense, creative (liberating) or destructive. The nuclear bomb is a weapon of mass destruction (negative), whose social value was (ingeniously built as) freedom (positive).</p> + <h5>Impact in our strategy: a missing root</h5> + <p>To engage the public, before to « <em>Focus on creative campaigns that use media + software to engage the public.</em> » we need to step back, in our speeding world, for understanding together the big picture and the big movement.<br /> + Mozilla want to fuel a movement and propose a strong and consistent strategy. However, I think <strong>this plan miss a key point, a root point: build a common (hi)story.</strong> This should be an objective, not just an action.<br /> + Also, that’s maybe a missing root for the State of the web report: how do we understand what we want to evaluate? But it’s not only a missing root for an (annual?) report (a ‘Reporters without borders’ Press-Freedom like?), it’s a missing root for a new grow of our products’ market share.<br /> + For example, I do think that most users don’t know and understand that Mozilla is a foundation, Firefox build by a community as a product to keep the web healthy: <strong>they don’t imagine any meaning about technology</strong>, because they see it as a neutral tool at its root, so as a tool that should just fit they producing needs.<br /> + Firefox, its technologies and its features are not bound for ever. It is the narrative, and therefore their inclusion in the social history that we make, which converges Firefox with the values that it stand for. <strong>Stoping or changing the deep narrative means cutting the source of common understanding and making stronger other consistencies captured by other objects, turning as centrifugal forces for Firefox.</strong><br /> + Marketing is a way to change what we socially say about things: that’s why Google Chrome marketing campaign (and consistent features maturity) has been the decreasing starting point of Firefox. <strong>Our message has been scrambled.</strong></p> + <h4>From participation to emancipation: values, people and org relationships</h4> + <p>How to emancipate people in the digital world ?</p> + <h5>Keeping the open open</h5> + <p>Being open is not a thing we can achieve, it’s a constant process. « <em>Mozilla needs to engage on both fronts, tackling the big problems but also fuelling the next wave of open.</em> » Yes, but <strong>Mozilla should say too how the next wave of open can stay under people’s control and rally new people</strong>. Not only open code, but open participation, open governance, open organization. Being open is not a releasing policy about objects, it’s a mutation to participation process: a metamorphosis. It’s not reached by expanding, but by shifting. It’s not only about an amount, but about values: it’s qualitative.<br /> + Maybe <strong>open is not enough</strong>, because it doesn’t say enough about who control and how, about the governance, and says too much about <strong>availability (passive)</strong> and not enough <strong>about <em>inclusivity</em> (active ; inclusion strengths)</strong>. It doesn’t say how the power is organized and articulated to the people (ex. think about how closed is the open Android). We may need to change the wording: indie web, the web that fuel autonomy, is a try, but it doesn’t say enough about <em>inclusivity</em> compared to openness &amp; opportunity. Emancipation is the concept. It’s strategic because it says what is aligned to what, especially how to articulate values and uses. It’s important because it tells what are the sufficient conditions of realization to ‘open/indie’. That’s key to get ‘open/indie at small and large scales, from Internet people to Internet institutions, thought all ‘open/indie’ detractors in the always-current situation: a resilient ecosystem.<br /> + My intuition is that <strong>the leadership network and advocacy engine promoting open will be efficient if we clarify ‘open’ while keeping it universal</strong>. We can do it by looking back at the raw material that we have worked for years, our DNA in action. Because after all, we are experts about it and wish others to become experts too. It does not mean to essentialize it (opposing its nature and its culture), <strong>but to define its conditions of continuous achievement in our social context</strong>.</p> + <h5>Starting point: exemplary projects that tell a lot about the evolution of our DNA in action</h5> + <p>Clarifying the idea of ‘open’ is strategic to our action because it outlines the constitution of ‘open’, its high ‘rules’, like with laws in political regimes. It clarifies for all, if you are part of it or not, and it tells you what to change to get in. It can reinforce the brand by differentiating from the big players that are the GAFAM: <strong>it’s a way to drive, not to be driven by others lowering the meaning to catch the social impact. We should say that ‘open’ at Mozilla means more than ‘open’ at GAFAM</strong>. I wish Mozilla to speak about its openness, not as an ‘equal in opportunity’ but as an ‘equal in participation’, because it fits openness not only for a moment (on boarding) or for a person, but during the whole process of people’s interaction.<br /> + <a href="https://www.rust-lang.org/">Rust</a> and <a href="https://servo.org/">Servo</a> or <a href="https://firefoxos.mozilla.community/">Firefox OS</a> (since the Mozilla’s shift to radical participation) seem to be very good examples of projects with participation &amp; impact centric rules, tools, process (RFC, new team and owners, …). Think about how Rust and <a href="http://arc.applause.com/2015/03/27/google-dart-virtual-machine-chrome/">Dart emerged and are evolving</a>. Think about how stronger has been the locked-open Android with partnership than the open-locked FxOS. We should tell those stories, not as recipes that can be reproduced, but as process based on a Constitution (inclusive rules) that make a political regime (open) and define a mode of government (participation). That’s key to social understanding and therefore to transpose and advocate for it.<br /> + As projects<strong> compared to ‘original Mozilla’, Rust, Servo and FxOS could say a lot</strong> about how different they implemented learning/interaction/participation at the roots of the project. How the process, the tools, the architecture, the governance and the opportunities/constraints have changed for Mozilla and participants. This could definitely help to setup our curriculum resources, database and workshop at a personal (e.g., “How to teach / facilitate / organize / lead in the open like Mozilla.”) and orgs levels, with personal and orgs policies.</p> + <h5>Spreading the high meanings in our strategy to consolidate it consistency</h5> + <p>Clarifying the constitution of ‘open’ calls to clarify other related wordings.<br /> + I’m satisfied to read back (social) ‘movement’ instead of ‘community’, because it means that our goal can’t be achieve forever (is static), but we should protect it by acting. And it seems more inclusive, less ‘folds on itself’ and less ‘build the alternative beside’ than ‘community’: the alternative can be everywhere the actual system is. It can make a system. It can get global, convergent, continuous, … all at the same time. Because it’s roots are decentralized _and_ consistent, collaborating, …</p> + <p>About participation, we should think too (again) about engagement VS contribute VS participate: how much am I engaged ? Free about defining and receiving cost/gains? What is the impact of my actions ? … <strong>These different words carry different ideas about how we connect the ‘open’</strong>: spread is not enough because it diffuses, _be_ everywhere is more permanent. Applied to Mozilla’s own actions, <strong>funding open projects and leaders, is maybe not enough and there should be others areas where we can connect</strong> inside products, technology, people and organizations that build emancipation. So that say something about getting control (who, how, …).</p> + <h5>IA: a challenge for ‘open’</h5> + <p>IA is first developed to help us by improving our interactions. However, this seems to start to shift into taking decisions instead of us. This is problematic because these are indirect and direct ways for us to loose control, to be locked. And that can be as far as computers smarter than humans. The problem is that technical progress is made without any consideration of the societal progress it should made.<br /> + That’s an other point, why open is not enough: automation should be build-in with superior humanization. <strong>Mozilla should activate and unlock societal progress to build fair technical progress.</strong></p> + <h5>Digital integration &amp; democracy</h5> + <p>The digital (&amp; virtual) world is gaining control over the physical world in many domains of our society (economy to finance, mail to email, automatic car, voting machine, …). It’s getting more and more integrated to our lives without getting back our (imperfect) democracy integrated into them. Public benefit and public good are turning ‘self benefit’ and ‘own sake’ because citizens don’t have control over private companies. <strong>We should build a digital democracy if we don’t want to loose at all the democratic governing of society.</strong> We must overcome the poses and postures battles about private and public. We need to build.</p> + <h4>‘Leader’ &amp; ‘Leadership’ need a clarification</h4> + <h5>Why a clarification?</h5> + <p>At some level, I’m not the only one to ask this question:</p> + <blockquote><p>How do CRM requirements for Leadership and Advocacy overlap / differ? What’s our email management / communications platform for Leadership?</p></blockquote> + <p>Connect leaders to lead what ? How ? To whose benefit ? Do we want to connect leaders or initiatives (people or orgs) ? Will the leaders be emerging ones (building new networks) or established ones (use they influence to rally more people)? Are Leaders leaders of something part of Mozilla (like can be Reps) or outside of Mozilla (leaders of project, companies, newspaper: tech leaders, news leaders, …) ? This is especially important depending on what is the desire for the leaders to become in the future. <strong>The MoFo’s document should be more precise</strong> about this and go forward than « <em>Mozilla must attract, develop, and support a global network of diverse leaders who use their expertise to collaboratively advance points-of-view, policies and practices that maintain the overall health of the Internet.</em> »<br /> + We should do it because <strong>the confusion about the leadership impact the advocacy engine</strong>: « <em>The shared themes also provide explicit opportunities for our Leadership and Advocacy efforts to work together.</em> » Regarding Mozilla, is the leaders role to be advocacy leaders ? It seems as they share themes and key initiatives (even if not worded the same sometimes). Or in other words, who Drives the Advocacy engine?</p> + <h5>Iterations with the actual definition: creators</h5> + <p>Here are my iterations on the definition of ‘Leaders’:</p> + <ul> + <li>The Leaders could be the people platform (the community) and the advocacy engine the tool/themes/actions platform (the product).</li> + <li>Leaders could build at the end new solutions (products) and Advocates new voices (rallying), that could be translated in a learning area divided like Leadership=learn+create and advocacy=teach+spread.</li> + <li>Leadership: personal development to produce (turn into) new commons or add new facets to commons. Advocacy: personal development to protect established/identified commons.</li> + </ul> + <p>With these definitions, then Leaders are maybe more a Lab, R&amp;D place, incubation tool (if we think about start-up incubators, then it shows a tool-set that we will need to inspire for the future). But if we want to keep the emphasis on people, <strong>we could name them ‘creators’</strong> (compositors or managers ; not commoners, because leaders and advocates are commoners ; yes, traditionally creators are craftspersons and intellectual designers). This make sens with the examples given in the MoFo 2020 strategy 0.8 document, where all persona are involved in a building-something-new process.</p> + <p>However, it’s interesting to understand why we choose at first ‘Leaders’. <strong>Leaders build new solutions (products) and Advocates new voices (rallying), they are both about personal development and empower commons.</strong> Leadership=learn+create and advocacy=teach+spread commons. Leaders are projects/orgs leaders, the ones that traduce DNA (values) in products (concrete ability and availability). Advocates are values advocates, the ones that traduce DNA (values) in actions (behavior). As they are both targeting commons, they both produce the same social organization (collaboration instead of competition). They are both involved to create (different) representation (institutions) and organization (foundation/firms) but <strong>with a different DNA (values) processing</strong>: from public good to personal interest or the opposite. If Mozilla cares about public good resilience, <strong>the articulation of they domains of values is critical. So their articulation’s expression and the revision process must be said and clear</strong>: from hierarchy vs contract vs different autonomy levels (internal incubation and external advocacy), vs … to criteria to start a revision.</p> + <h5>The network effect</h5> + <p>Another argument for the switch from Leader to Creator is that the Leader word it too much tight to a single-person-made innovation. <strong>Creator make more clear that the innovation is possible not because of one genius, but because of a team</strong>, a group, a collective: personS (where there could also be genius). The value is made by the collaboration of people (especially in an open project, especially in a network).<br /> + That’s important because that could impact how well we do the convening part: not self-promoting, not-advertising, but sharing skills and knowledge for people and catalysing projects.<br /> + <strong>The same for the wording ‘talent’</strong>: alone, a talent can do nothing that has an impact. At least, we need two talents, a team (plus some assistants at some point).</p> + <h5>The cultural prism</h5> + <p>Again, this seems to be an open question:</p> + <blockquote><p>Define and articulate “leadership.” Hone our story, ethos and definition for what we mean by “leadership development” (including cultural / localization aspects).</p></blockquote> + <p>In my culture, Leader carry positive (take action) and negative (dominate) meanings. That’s another reason why I prefer another naming.<br /> + I understand too that it carries a lot of legitimacy (ex. market leader) in our societies and it avoids the stay-experimental or non-massive (unique) thoughts. And we need legitimacy to get impact.<br /> + But the way Mozilla has an impact thought all cultures, its <strong>legitimacy, is by creating or expanding a common</strong>. To do this, depending on the maturity, Mozilla could follow the market proposing an alternative with superior usability OR opening a new market by adding a vertical segment.</p> + <h5>Existing tool-set opportunities</h5> + <p>If Leadership is « <em>a year-round MozFest + Lab</em>« , so it’s a social network + an incubation place. Then, we already have a social network for people involved with Mozilla: Which kind of link should have the leadership network with <strong>mozillians.org</strong> ? What can we learn from this project and other specialized social network projects (linkedin, viadeo, …) to build the leadership network ?</p> + <h4>Advocacy engine: make it clear</h4> + <h5>What it is &amp; how it works</h5> + <p>Mozilla is doing a great effort to build its advocacy engine on collaboration (« <em>Develop new partnerships and build on current partnerships</em>« , « <em>begin collaboration</em>« , « <em>build alliances with similar orgs</em>« ) but at the same time affirms that Mozilla should be « <em>Part of a broader movement, be the boldest, loudest and most effective advocates</em> » that could be seen as too centralized, too exclusive.<br /> + While this can be consistent (or contradictory), <strong>the consistency has to be explained</strong> looking at orgs and people, global and local, abstract and real, with a complementarity/competitive grid.<br /> + First, <strong>the articulation with other orgs has to be explained</strong>. What about others orgs doing things global (<a href="https://eff.org/">EFF</a>, <a href="https://fsf.org/">FSF</a>, …) and local (<a href="http://www.laquadrature.net/">Quadrature du net</a>, CCC, …) ? What about the value they give and that Mozilla doesn’t have (juridic expertise for example) ? What about other advocate engines (<a href="https://change.org/">change.org</a>, <a href="https://secure.avaaz.org/">Avaaz</a>…) ? That should not be at an administrative level only like « <em>Develop an affiliate policy. Defining what MoFo does / does not offer to effectively govern relationships w. affiliated partners and networks (e.g., for issues like branding, fundraising, incentives, participation guidelines, in-kind resources.)</em> »<br /> + Second, this is key for users to understand and <strong>articulate the global level of the brand engagement and their local preoccupations and engagement</strong>. How the engine will be used for local (non-US) battles ? In the past Mozilla totally involved against PIPA, SOPA by taking action, and hesitate a lot to take position and just published a blog post (and too late to gain traction and get impact) against French spying law for example.<br /> + Third, <strong>the articulation ‘action(own agenda)/reaction’ should be clarified</strong> in the objectives and functioning of the advocacy engine. Especially because other orgs, allies or detractors, try to to setup the social agenda. It’s important because it can change the social perception of our narrative (alternative promotion/issue fighting) and therefore people’s contributions.<br /> + People think the technology is socially neutral. People are satisfied of narrow hills of choice (not the meaning, the aim, but only the ability to show your favorite avatar). <strong>People don’t want to feel guilty or oppressed</strong>, they don’t want new constraints, they are looking for solution only: they want to use, not to do more, they want they things to be done. Part of the problem is about understanding (literacy, education), part of it is about the personal/common duality, part of it is about being hopeless about having an impact, part of it is about expressing change as a positive goal and a new possible way (alternative), not a fight against an issue. About the advocacy engine, I think <strong>our preoccupation should be people-centric and the aim to give them a short, medium and long term narrative to get action without being individuals-centric</strong>.</p> + <h5>How we build it ?</h5> + <p>How to build a social movement ? How it has been built in the past ? Is it the same today ? Can it be transposed to the digital domain from others social domains ? How strong are the cultural differences between nations? These are the main questions we should answer, and our pivot era gives us many examples in diverse domains (climate change advocates, Syriza &amp; Podemos, NSA &amp; surveillance services in Europe, empowered syndicates in Venezuela, <a href="http://blogs.valvesoftware.com/economics/why-valve-or-what-do-we-need-corporations-for-and-how-does-valves-management-structure-fit-into-todays-corporate-world/#more-252">Valve corp. internal organization</a>…) to set a search terrain. However, I will go strait to my intuitive understanding below.<br /> + I’m kind of worried that it’s imagined to build the advocacy engine themes by a top-down method. <strong>I think a successful advocacy is always built bottom-up</strong>, as its function is to give back the voice to the people, to get them involved, not to make them fulfill our predefined aims. The top-down method is too organization centric: it can’t massively drive people that are not already committed to the org. It’s usually named advertisement or propaganda. If we want to have impact, <strong>we should listen to people needs, not tell them to listen to ours. People want (first) to be empowered, not to empower an org</strong>. So let’s organize the infrastructure, set the agenda and draw the horizon (strategic understanding) participative: make people fill them with content of their experience. It seems to me it is the only way, the only successful method, if we want to build a movement, and not just a shifting moment (that could be built by the top, with a good press campaign locally relayed for example ; that’s what happen in old style politics: the aim is short term, to cleave).<br /> + <strong>Isn’t the advocacy engine a new Drumbeat ?</strong> We shifted from Drumbeat to Webmaker+web literacy to Mozilla Academy and now to Leadership plus advocacy: it could be good to tell that story now that we are shifting again and learn from it.<br /> + <strong>Mozilla should support, behave as a platform</strong>, not define, not focus. Letting the people set the agenda makes them more involved and is a good way to build a network of shared aims with other orgs, that is not invasive or alienating, but a support relationship in a win-win move. The strength comes from the all agendas sewed. So at an org level, let’s on-board allies organizations as soon as plan building-time (now), to build it together. Yes it’s slower, but much more massive, inclusive and persistent.</p> + <h5>How we evaluate it: cultural bias &amp; qualitative analysis</h5> + <p>First, about the agenda-setting KPI for 2016, should these KPI be an evaluation of the inclusion and rank in others strategic agendas, governance systems and productions (outcome/products) ? Others org could be from different domains: political, social, economy orgs.<br /> + Then, as a wide size audience KPI, Mozilla wants « <em>celebration of our campaigns with ‘headline KPIs’ including number of actions, and number of advocates.</em>« . While doing this could be the right thing to do for some cultures, it could be the worst for others. I think that these KPI don’t carry a meaning for people and are too org centric. In a way, they are to generic: it’s just an amount. <strong>Accumulation is not our goal: we want impact that is the grow of articulated actions</strong> made by diverse people toward the same aim. <strong>We need our massive KPI to be more qualitative</strong>, or at least find a way to present them in a more qualitative way: interactive map ? a global to local prism that engages people for the next step ?</p> + <h5>Best practices &amp; massive impact</h5> + <p>Selecting best practices are an appealing method when we want to have a fast and strong impact in a wide area. However, <strong>when we unify we should avoid to homogenize</strong>. The gain in area by scaling-up is always at the cost of loosing local impact because it is not corresponding to local specificities, hence to local expectations. Federating instead of scaling-up is a way to solve this challenge. So we should be careful to not <strong>use best practice as absolute solutions, but as solutions in a context</strong> if we want to transpose them massively.</p> + <h5>Tools &amp; platform balanced between user-centric and org-centric outcomes</h5> + <p>It’s good to hear that we will build a advocacy platform. As we ‘had’ bugzilla+svn then mercurial (hg)+… and are going to the <strong>integrated</strong>, <strong>pluggable</strong> and <strong>content-centric</strong> (but non-free; admin tools are closed source) github (targeting more coder than users, but with a lower entry price for users still), we need to be able to have the same kind of tool for advocates and leaders. Something inspired maybe at some levels by the remixing tools we built in Webmakers for web users.</p> + <h4>From experiment to production: support (self made to mass product) + modularity (dev code patch to users add-ons).</h4> + <p><strong>We need pathways from lab to home that carry different mix of customization and reliability to support the emancipation curve.</strong><br /> + Users want things to work, because they want to use it. Geeks want to be able to modify a lot and accept to put their hands in the engine to build growing reliability. Advanced users want to customize their experience and keep control and understanding on working status. They want to be able to fix the reliability at a medium/low technical cost. They are OK to gain more control at these prices. Users want to use things to do what they need and want to trust a reliability maintained for them. They are OK to gain control at a no technical cost. Depending on the matter we all have different skill levels, so we are all geeks, advanced users and users depending on our position or on the moment. And depending on our aspirations, we all want to be able to move from one category to an other. That’s what we need to build: we don’t just need to « <em>better articulate the value to our audiences</em>« , <strong>we need to build pathways thought audiences and thought IT layers</strong> (content, software, hardware, distant service). <strong>We should find a convergence between customization and reliability, between first time experience, support and add-ons thought all our users’ persona by building bridges, pathways</strong>. So, « <em>better articulate the value to our audiences</em> » should not be restrained in our minds to the Mozilla Leadership Network.<br /> + <strong>Part of this is being done in other projects outside of Mozilla in the commons movement.</strong> There are many, but let’s take just one example, the <a href="https://www.fairphone.com/">Fairphone</a> project: modularity, howtos, … all this help to break the product-to-use walls and drive appropriation/emancipation. <strong>Products are less product and brand centric and more people/user centric</strong>.<br /> + Part of this has been done inside Mozilla, like integrating learning in our products, in-content, as we have code comment on code. I think <strong>the <a href="https://wiki.mozilla.org/Firefox_OS/Spark">Spark</a> project on Firefox OS is on a promising path</strong>, even if maybe immature: it maybe has not been released mainstream because it misses bridges/pathways (on-boarding levels, progression from simple to high level techniques, and no or not enough reproducible/universal next task/skill building).<br /> + So some solutions start to emerge, the direction is here, but has never been conceived and implemented that globally, as there isn’t integrated pathways with choice and opportunity and a strategy embracing all products and technologies (platform, tools, …).</p> + <h4>Better tools for collaboration and participation: task-centric to process-centric (use) infrastructure</h4> + <p><strong>The open community should definitely improve the collaboration tools and infrastructure to ease participation.</strong><br /> + <strong><a href="http://www.discourse.org">Discourse</a> ‘merged’ discussion channels</strong>: email+forum(+instant, messaging, … and others peer-to-peer discussion?). <strong><a href="http://stackexchange.com">Stack exchange</a> merged the questioning/solving process</strong> and added a vote mechanism to rank answers: it eased the collaboration on editing the statement and the results while staying synchronous with the discussion and keeping the discussion history. We need such kind of possibilities with discourse: <strong>capitalize on the discussion and preview the results to build a plan.</strong><br /> + This exist in document oriented software (that added collaboration editing tools), but not that much in collaboration software (that don’t produce documents). For example, while discussing the future plan for Fx/FxOS be supported to keep track on a doc about the proposals plans + criteria &amp; dependencies. In action, it is from <a href="https://mail.mozilla.org/pipermail/firefox-dev/2015-July/003063.html">this</a> plus all the discussion taking place to <a href="https://mail.mozilla.org/pipermail/firefox-dev/2015-July/003119.html">that</a>.<br /> + This is maybe something like integrating Discourse+Wiki, maybe with the need to have competing and ranked (both for content and underlaying meaning of content=strategy?) plan/page proposals. <strong>From evolving the wiki discussion page to featuring document production into peer-to-peer discussion.</strong></p> + <h4>A recovering strategy: from fail to win</h4> + <p>There is maybe one thing that is in the shadow in this plan: <strong>what do we do when/if we (partially) fail ?</strong><br /> + I think at least we should say that <strong>we document</strong> (keep research going on) to be able to outline and spread the outcomes of what we tried to fight against. So we still try to built consciousness to be ready for the next round.</p> + <p> </p> + <p><em>If you see some contradiction in my thoughts, let’s say it’s my state of thinking right now: please voice them so we can go forward.</em><br /> + <em> The same for thoughts that are voiced definitive (like users are): take it as a first attempt with my bias: let’s state these bias to go forward.</em></p> + <div class="footnotes" id="footnotes-48"> + <div class="footnotedivider"></div> + <ol> + <li id="fn-48-1"> ‘<em>Radical</em>‘ can be in some cultures an euphemism to ‘<em>violent</em>‘. Let’s be clear that the change by increasing violence is done to make a popular uprising of some part against others. While it does not help the majority to magically understand that the minority is right, it stigmatize the radical-violent-changers and in the way it discredits the alternative proposed. <span class="footnotereverse"><a href="https://repeer.org/tag/mozilla/feed/#fnref-48-1">↩</a></span></li> + </ol> + </div> + 2016-01-16T00:27:13+00:00 + Nicolas + + + Will Kahn-Greene: pyvideo status: January 15th, 2016 + http://bluesock.org/%7Ewillkg/blog/pyvideo/status_20160115.html + <div class="section" id="what-is-pyvideo-org"> + <h3>What is pyvideo.org</h3> + <p><a class="reference external" href="http://pyvideo.org/">pyvideo.org</a> is an index of Python-related conference and user-group videos on + the Internet. Saw a session you liked and want to share it? It's likely you can + find it, watch it, and share it with pyvideo.org.</p> + <p>This is the latest status report for all things happening on the site.</p> + <p>It's also an announcement about the end.</p> + <p><a href="http://bluesock.org/~willkg/blog/pyvideo/status_20160115.html">Read more…</a> (5 mins to read)</p></div> + 2016-01-15T23:30:00+00:00 + Will Kahn-Greene + + + Chris Cooper: RelEng & RelOps Weekly Highlights - January 15, 2016 + http://coopcoopbware.tumblr.com/post/137371863755 + <p>One of releng’s big goals for Q1 is to deliver a beta via <a href="https://bugzil.la/release-promotion" target="_blank">build promotion</a>. It was great to have some tangible progress there this week with bouncer submission.</p> + + <p>Lots of other stuff in-flight, more details below! + </p><p><b>Modernize infrastructure</b>:</p> + + <p>Dustin worked with Armen and Joel Maher to run Firefox tests in TaskCluster on an older EC2 instance type where the tests seem to fail less often, perhaps because they are single-CPU or slower.</p> + + <p><b>Improve CI pipeline</b>:</p> + + <p>We turned off automation for b2g 2.2 builds this week, which allowed us to remove some code, reduce some complexity, and regain some small amount of capacity. Thanks to Vlad and Alin on buildduty for helping to land those patches. (<a href="https://bugzil.la/1236835" target="_blank">https://bugzil.la/1236835</a> and <a href="https://bugzil.la/1237985" target="_blank">https://bugzil.la/1237985</a>)</p> + + <p>In a similar vein, Callek landed code to disable all b2g desktop builds and tests on all trees. Another win for increased capacity and reduced complexity! (<a href="https://bugzil.la/1236835" target="_blank">https://bugzil.la/1236835</a>)</p> + + <p><b>Release</b>:</p> + + <p>Kim finished integrating bouncer submission with our release promotion project. That’s one more blocker out of the way! (<a href="https://bugzil.la/1215204" target="_blank">https://bugzil.la/1215204</a>)</p> + + <p>Ben landed several enhancements to our update server: adding aliases to update rules (<a href="https://bugzil.la/1067402" target="_blank">https://bugzil.la/1067402</a>), and allowing fallbacks for rules with whitelists (<a href="https://bugzil.la/1235073" target="_blank">https://bugzil.la/1235073</a>).</p> + + <p><b>Operational</b>:</p> + <p>There was some excitement last Sunday when all the trees were closed due to timeouts connectivity issues between our SCL3 datacentre and AWS. (<a href="https://bugzil.la/238369" target="_blank">https://bugzil.la/238369</a>)</p> + + <p><b>Build config</b>:</p> + + <p>Mike released v0.7.4 of <a href="http://gittup.org/tup/" target="_blank">tup</a>, and is working on generating the tup backend from moz.build. We hope to offer tup as an alternative build backend sometime soon.</p> + + <p>See you all next week!</p> + 2016-01-15T22:44:13+00:00 + + + Air Mozilla: Webdev Beer and Tell: January 2016 + https://air.mozilla.org/webdev-beer-and-tell-january-2016/ + <p> + <img alt="Webdev Beer and Tell: January 2016" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/35/0f/350f246037ead3bab95fdbd4c2b77484.png" width="160" /> + Once a month web developers across the Mozilla community get together (in person and virtually) to share what cool stuff we've been working on in... + </p> + 2016-01-15T22:00:00+00:00 + Air Mozilla + + + Support.Mozilla.Org: What’s up with SUMO – 15th January + https://blog.mozilla.org/sumo/2016/01/15/whats-up-with-sumo-15th-january/ + <p><strong>Hello, SUMO Nation!</strong></p> + <p>The second post of the year is here. Have you had a good time in 2016 so far? Let us know in the comments!</p> + <p>Now, let’s get going with the updates and activity summaries. It will be brief today, I promise.</p> + <h3><strong class="author-name">Welcome, new contributors!<br /> + </strong></h3> + <ul> + <li class="author"> + <div class="author"><a class="username" href="https://support.mozilla.org/en-US/user/Andy.Yang">Andy.Yang</a></div> + </li> + </ul> + <div class="author">After the massive influx over the last few weeks, we only had Andy introducing himself recently – the warmer the welcome for him!</div> + <div class="author"></div> + <div class="author">If you just joined us, don’t hesitate – come over and <a href="https://support.mozilla.org/forums/buddies" target="_blank">say “hi” in the forums!</a></div> + <div class="author"></div> + <div class="author"> + <h3><strong>Contributors of the week<br /> + </strong></h3> + <ul> + <li><a href="https://blog.mozilla.org/sumo/2016/01/08/whats-up-with-sumo-8th-january/" target="_blank">All the people who joined us in the winter season so far!</a></li> + </ul> + <div class="" id="magicdomid64"> + <p><strong><span style="text-decoration: underline;">We salute you!</span></strong></p> + </div> + <div class="author">Don’t forget that if you are new to SUMO and someone helped you get started in a nice way you can <a href="https://support.mozilla.org/forums/buddies/711364?last=65670" target="_blank">nominate them for the Buddy of the Month!</a></div> + <div class="author"></div> + </div> + <h3><strong>Most recent SUMO Community meeting</strong></h3> + <ul> + <li><a href="https://public.etherpad-mozilla.org/p/sumo-2016-01-11" target="_blank">You can read the notes here</a> and see the video on our <a href="https://www.youtube.com/channel/UCaiposaIhA7HfMqH2NIciyA/videos" target="_blank">YouTube channel</a> and <a href="https://air.mozilla.org/search/?q=sumo" target="_blank">at AirMozilla</a>.<del> </del><del><br /> + </del></li> + <li><strong>IMPORTANT: We are considering changing the way the meetings work. Help us figure out what’s best for you – join the discussion on the forums in this thread: <a href="https://support.mozilla.org/en-US/forums/contributors/711752?last=67873">(Monday) Community Meetings in 2016</a>.</strong></li> + </ul> + <h3><strong>The next SUMO Community meeting… </strong></h3> + <ul> + <li style="text-align: left;">is happening on <a href="https://public.etherpad-mozilla.org/p/sumo-2016-01-18" target="_blank">Monday the 18th – join us</a>!</li> + <li style="text-align: left;"><strong>Reminder: if you want to add a discussion topic to the upcoming meeting agenda:</strong> + <ul> + <li style="text-align: left;">Start a thread in the <a href="https://support.mozilla.org/forums/contributors" target="_blank">Community Forums</a>, so that everyone in the community can see what will be discussed and voice their opinion here before Monday (this will make it easier to have an efficient meeting).</li> + <li style="text-align: left;">Please do so as soon as you can before the meeting, so that people have time to read, think, and reply (and also add it to the agenda).</li> + <li style="text-align: left;">If you can, please attend the meeting in person (or via IRC), so we can follow up on your discussion topic during the meeting with your feedback.</li> + </ul> + </li> + </ul> + <h3><strong class="author-g-ivsra51ph44x461i">Developers</strong></h3> + <ul> + <li>The new version of the Ask A Question page is here!</li> + <li>The 2.0 version of the KPI dashboard is in the works.</li> + <li><a href="http://edwin.mozilla.io/t/sumo" target="_blank">You can see the current state of the backlog our developers are working on here</a>.</li> + <li><a href="https://public.etherpad-mozilla.org/p/sumo-p-2016-01-14" target="_blank">The latest SUMO Platform meeting notes can be found here</a>.</li> + <li>Interested in learning how Kitsune (the engine behind SUMO) works? <a href="http://kitsune.readthedocs.org/" target="_blank">Read more about it here</a> and <a href="https://github.com/mozilla/kitsune/" target="_blank">fork it on GitHub</a>!</li> + </ul> + <h3><strong>Community</strong></h3> + <ul> + <li>Our awesome Bangladesh SUMO Warriors are on the road again! Follow their adventures on Twitter under this tag: <a href="https://twitter.com/search?q=%23sumotourctg" target="_blank">#sumotourctg</a></li> + <li> + <div class="title"><a href="https://support.mozilla.org/forums/contributors/711729?last=67763">Reminder: take a look at our Work Week Summary for Mozlando. We need your feedback for a few things there.</a></div> + </li> + <li> + <div class="title">Ongoing reminder: if you think you can benefit from getting <a href="https://wiki.mozilla.org/Community_Hardware" target="_blank">a second-hand device</a> to help you with contributing to SUMO, you know where to find us.</div> + </li> + </ul> + <h3><strong class="user-chip" title="adriel0415">Support Forum</strong></h3> + <ul> + <li>Say hello to the new people on the forums! + <ul> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/Tomi55" target="_blank">Tomi55</a> (Hungarian)</span></li> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/jdc20181" target="_blank">jdc20181</a> (English)</span></li> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/andexi" target="_blank">andexi</a> (Spanish)</span></li> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/Qantas94Heavy" target="_blank">Qantas94Heavy</a> (English)</span></li> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/samuelms79" target="_blank">samuelms79</a> (Brazilian-PT)</span></li> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/jorgecomun" target="_blank">jorgecomun</a> (Spanish)</span></li> + </ul> + </li> + </ul> + <div class=""> + <h3><strong class="author-g-ivsra51ph44x461i">Knowledge Base</strong></h3> + <div class="" id="magicdomid90"> + <div class="" id="magicdomid82"> + <ul class="list-bullet1"> + <li><span class="author-a-z87zjz80zxwjz85z4z65zytdpz68zoz69z"><a href="https://support.mozilla.org/forums/knowledge-base-articles/711304#post-65289" target="_blank">Thanks to everyone who took part in the most recent KB Day!</a></span></li> + <li>Version 44 updates should be live now.</li> + <li><span class="author-a-w2dz70zaz70z7z89zqz78ziz69zz78zz85zz90zj"><a href="https://docs.google.com/spreadsheets/d/1lkpRPJp9P1P5MRU-c9dwbDC0w5bMmrMdu-BNMp1xe8w/edit#gid=6" target="_blank">Ongoing reminder: learn more about upcoming English article updates by clicking here</a></span>.</li> + <li><span style="text-decoration: underline;">Ongoing reminder #2:<a href="https://support.mozilla.org/forums/knowledge-base-articles/" target="_blank"> do you have ideas about improving the KB guidelines and training materials? Let us know in the forums</a>!</span></li> + </ul> + </div> + <div class="" id="magicdomid83"> + <h3><strong class="author-g-ivsra51ph44x461i">Localization</strong></h3> + </div> + </div> + </div> + <div class="" id="magicdomid95"> + <ul> + <li>Thanks to everyone writing in with problems, ideas, reports of bugs – all your feedback matters!</li> + </ul> + </div> + <div class="" id="magicdomid75"> + <h3><strong>Firefox<br /> + </strong></h3> + <ul> + <li><strong>for Android</strong> + <ul> + <li><a href="https://support.mozilla.org/forums/contributors/711712?last=67653">Learn more about Firefox 43 for Android from the official thread with release notes / issues / discussions</a>.</li> + <li> + <div class="title"><a href="https://support.mozilla.org/forums/contributors/711718?last=67822">Reminder: Roland is sharing Firefox 44 for Android release notes / issues / discussions</a> with everyone in the forum.</div> + </li> + </ul> + </li> + </ul> + <ul> + <li><strong>for Desktop</strong> + <ul> + <li>The <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1238620" target="_blank">uploading issues reported by many users are being tracked here.</a></li> + <li><a href="https://support.mozilla.org/questions/firefox?tagged=bug1208145&amp;show=all" target="_blank">The “show passwords” button has been removed from the password manager for the Beta of Version 44</a>. The developers are looking into <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208145" target="_blank">last minute fixes for that in this bug</a>.</li> + <li>Also in Version 44, the <span class="author-a-kz88zz80zhz89z6hlz81znytez70zz66zz68z"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=606655" target="_blank">“ask me everytime” option for cookies will be removed from the privacy panel.</a></span></li> + </ul> + </li> + </ul> + <ul> + <li><strong>for iOS</strong> + <div class="" id="magicdomid85"> + <ul class="list-bullet1"> + <li><span class="author-a-107uz69zz81zhz78z0z78zz84zz66zz76zz82zz77zj"><a href="https://www.mozilla.org/en-US/firefox/ios/1.4/releasenotes/" target="_blank">Firefox for iOS 1.4 primarily with features for China is here</a>.<br /> + </span></li> + </ul> + </div> + <div class="" id="magicdomid86"> + <ul class="list-bullet1"> + <li><span class="author-a-107uz69zz81zhz78z0z78zz84zz66zz76zz82zz77zj">Firefox for iOS 2.0 is after 1.4 and hopefully sometime this quarter!</span></li> + </ul> + </div> + </li> + </ul> + </div> + <p>Not that many updates this week, since we’re coming out of our winter slumber (even though winter will be here for a while, still) and plotting an awesome 2016 with you and for you. Take it easy, have a great weekend and see you around SUMO.</p> + 2016-01-15T19:38:51+00:00 + Michał + + + Air Mozilla: Paris Firefox OS Hackathon Presentations + https://air.mozilla.org/paris-firefox-os-hackathon-presentations/ + <p> + <img alt="Paris Firefox OS Hackathon Presentations" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/35/83/358305bfa246fff07d707061082134aa.png" width="160" /> + As an introduction to this weekend's Firefox OS Hackathon in Paris we'll have two presentations: - Guillaume Marty will talk about the current state of... + </p> + 2016-01-15T18:00:00+00:00 + Air Mozilla + + + J.C. Jones: Renewing Let's Encrypt Certs (Nginx) + https://tacticalsecret.com/renewing-lets-encrypt-certs-nginx/ + <p>All the first <a href="https://crt.sh/?id=10172479">Let's Encrypt certs for my websites</a> from the LE private beta began expiring last week, so it was time to work through the renewal tooling. I wanted a script that:</p> + + <ol> + <li>Would be okay to run daily, so there'd be plenty of retries if something went wrong, </li> + <li>Wouldn't require extra config for me to forget about if I add a new site, </li> + <li>Would only renew certificates expiring in the next few weeks.</li> + </ol> + + <p>The official Let's Encrypt client team is hard at work producing a great renew tool to handle all this, but it's not released yet. Of course I could use <a href="https://caddyserver.com/">Caddy Server</a> that <a href="https://www.youtube.com/watch?v=nk4EWHvvZtI">just handles all this</a>, but I have a lot invested in Nginx here.</p> + + <p>So I wrote a short script and <a href="https://gist.github.com/jcjones/432eeaa6a2bf25e2c746">put it up in a Gist</a>. </p> + + <p>The script is designed to run daily, with a random start between 00:00 and 02:00 to protect against load spikes at Let's Encrypt's infrastructure. It doesn't do any real reporting, though, except to maintain <code>/var/log/letsencrypt/renew.log</code> as the most-recent failure if one fails.</p> + + <p>It's written to handle Nginx with Upstart's <code>service</code> command. It's pretty modular though; you could make this operate any webserver, or use the webroot method quite easily. Feel free to use the OpenSSL SubjectAlternativeName processing code for whatever purposes you have.</p> + + <p>Happy renewing!</p> + 2016-01-15T16:01:19+00:00 + James 'J.C.' Jones + + + Yunier José Sosa Vázquez: Conoce los complementos destacados para enero + http://firefoxmania.uci.cu/conoce-los-complementos-destacados-para-enero-2016/ + <p style="text-align: left;">Comenzó un nuevo año y con él, te traemos nuevos e interesantes complementos para tu navegador preferido que mejoran con creces tu experiencia de navegación. Durante los próximos 6 meses estará trabajando nuevos miembros en el Add-ons Board Team, en la próxima selección desde Firefoxmanía te avisaremos.</p> + <h3 style="text-align: left;">Elección del mes: uMatrix</h3> + <p>uMatrix es muy parecido a un <em>firewall</em> y desde una ventana fácilmente podrás controlar todos los lugares a donde tu navegador tiene permitido conectarse, qué tipo de datos pueden descargarse y cual puede ejecutar.</p> + <blockquote><p>Esta puede ser la extensión perfecta para el control avanzado de los usuarios.</p></blockquote> + <p><span id="more-15521"></span></p> + + <a href="http://firefoxmania.uci.cu/conoce-los-complementos-destacados-para-enero-2016/umatrix/"><img alt="Interfaz principal de uMatrix" class="attachment-thumbnail size-thumbnail" height="160" src="http://firefoxmania.uci.cu/wp-content/uploads/2016/01/uMatrix-160x160.png" width="160" /></a> + <a href="http://firefoxmania.uci.cu/conoce-los-complementos-destacados-para-enero-2016/umatrix2/"><img alt="Opciones de configuración de uMatrix" class="attachment-thumbnail size-thumbnail" height="160" src="http://firefoxmania.uci.cu/wp-content/uploads/2016/01/uMatrix2-160x160.png" width="160" /></a> + + <p><em><a href="http://addons.firefoxmania.uci.cu/umatrix/" target="_blank">Instalar uMatrix »</a></em></p> + <h3>También te recomendamos</h3> + <p style="text-align: left;"><a href="http://addons.firefoxmania.uci.cu/https-everywhere/" target="_blank">⇒ HTTPS Everywhere</a> por <a href="https://addons.mozilla.org/en-US/firefox/user/eff-technologists/" title="EFF Technologists">EFF Technologists</a></p> + <p style="text-align: left;">Protege tus comunicaciones habilitando la encriptación HTTPS automáticamente en los sitios conocidos que la soportan, incluso cuando navegas mediante sitios que no incluyen el prefijo “https” en la URL.</p> + <p style="text-align: left;"><a href="http://addons.firefoxmania.uci.cu/add-to-search-bar/" target="_blank">⇒ Add to Search Bar</a> por <a href="https://addons.mozilla.org/firefox/user/dr-evil/" target="_blank" title="AdblockLite">Dr. Evil</a></p> + <p style="text-align: left;">Hace posible que cualquier página con un formulario de búsqueda disponible pueda ser añadido fácilmente a la barra de búsqueda de Firefox.</p> + <div class="wp-caption aligncenter" id="attachment_15528" style="width: 262px;"><a href="http://firefoxmania.uci.cu/wp-content/uploads/2016/01/add_to_search_bar.png" rel="attachment wp-att-15528"><img alt="add_to_search_bar" class="wp-image-15528 size-medium" height="226" src="http://firefoxmania.uci.cu/wp-content/uploads/2016/01/add_to_search_bar-252x226.png" width="252" /></a><p class="wp-caption-text">Añadiendo la búsqueda de un sitio web a la barra de búsqueda</p></div> + <p style="text-align: left;"><a href="http://addons.firefoxmania.uci.cu/duplicate-tabs-closer/" target="_blank">⇒ Duplicate Tabs Closer</a> por <a href="https://addons.mozilla.org/firefox/user/peuj/" target="_blank" title="The 1-Click YouTube Video Download Team">Peuj</a></p> + <p style="text-align: left;">Detecta las pestañas duplicadas en tu navegador y automáticamente las cierra.</p> + <h3 style="text-align: left;">Nomina tus complementos favoritos</h3> + <p style="text-align: left;">A nosotros nos encantaría que <strong>fueras parte del proceso</strong> de seleccionar los mejores complementos para Firefox y nos gustaría escucharte. <em>¿No sabes cómo?</em> Sólo tienes que <em>enviar un correo electrónico</em> a la dirección <strong>amo-featured@mozilla.org</strong> con el nombre del complemento o el archivo de instalación y los miembros evaluarán tu recomendación.</p> + <p style="text-align: left;"><strong>Fuente:</strong> <a href="https://blog.mozilla.org/addons/2016/01/01/january-2016-featured-add-ons/" target="_blank">Mozilla Add-ons Blog</a></p> + 2016-01-15T15:10:26+00:00 + Yunier J + + + Tim Taubert: Build Your Own Signal Desktop + https://timtaubert.de/blog/2016/01/build-your-own-signal-desktop/ + <p>The Signal Private Messenger is great. <strong>Use it.</strong> It’s probably the best secure + messenger on the market. When recently a desktop app was announced people were + eager to join the beta and even happier when an invite finally showed up in + their inbox. So was I, it’s a great app and works surprisingly well for an early + version.</p> + + <p>The only problem is that it’s a Chrome App. Apart from excluding folks with + other browsers it’s also a shitty user experience. If you too want your + messaging app not tied to a browser then let’s just build our own standalone + variant of Signal Desktop.</p> + + <h3>NW.js beta with Chrome App support</h3> + + <p>Signal Desktop is a Chrome App, so the easiest way to turn it into a standalone + app is to use <a href="http://nwjs.io/">NW.js</a>. Conveniently, their next release v0.13 + will ship with Chrome App support and is available for download as a beta + version.</p> + + <p>First, make sure you have <code>git</code> and <code>npm</code> installed. Then open a terminal and + prepare a temporary build directory to which we can download a few things and + where we can build the app:</p> + + <figure class="code"><div class="highlight"><pre>$ mkdir signal-build + $ cd signal-build + </pre></div></figure> + + + <h3>[OS X] Packaging Signal and NW.js</h3> + + <p>Download the latest beta of NW.js and <code>unzip</code> it. We’ll extract the application + and use it as a template for our Signal clone. The NW.js project does + unfortunately not seem to provide a secure source (or at least hashes) + for their downloads.</p> + + <figure class="code"><div class="highlight"><pre>$ wget http://dl.nwjs.io/v0.13.0-beta3/nwjs-sdk-v0.13.0-beta3-osx-x64.zip + $ unzip nwjs-sdk-v0.13.0-beta3-osx-x64.zip + $ cp -r nwjs-sdk-v0.13.0-beta3-osx-x64/nwjs.app SignalPrivateMessenger.app + </pre></div></figure> + + + <p>Next, clone the Signal repository and use NPM to install the necessary modules. + Run the <code>grunt</code> automation tool to build the application.</p> + + <figure class="code"><div class="highlight"><pre>$ git clone https://github.com/WhisperSystems/Signal-Desktop.git + $ cd Signal-Desktop/ + $ npm install + $ node_modules/grunt-cli/bin/grunt + </pre></div></figure> + + + <p>Finally, simply to copy the <code>dist</code> folder containing all the juicy Signal files + into the application template we created a few moments ago.</p> + + <figure class="code"><div class="highlight"><pre>$ cp -r dist ../SignalPrivateMessenger.app/Contents/Resources/app.nw + $ open .. + </pre></div></figure> + + + <p>The last command opens a Finder window. Move <code>SignalPrivateMessenger.app</code> to + your Applications folder and launch it as usual. You should now see a welcome + page!</p> + + <h3>[Linux] Packaging Signal and NW.js</h3> + + <p>The build instructions for Linux aren’t too different but I’ll write them down, + if just for convenience. Start by cloning the Signal Desktop repository and + build.</p> + + <figure class="code"><div class="highlight"><pre>$ git clone https://github.com/WhisperSystems/Signal-Desktop.git + $ cd Signal-Desktop/ + $ npm install + $ node_modules/grunt-cli/bin/grunt + </pre></div></figure> + + + <p>The <code>dist</code> folder contains the app, ready to be launched. <code>zip</code> it and place + the resulting package somewhere handy.</p> + + <figure class="code"><div class="highlight"><pre>$ cd dist + $ zip -r ../../package.nw * + </pre></div></figure> + + + <p>Back to the top. Download the NW.js binary, extract it, and change into the + newly created directory. Move the <code>package.nw</code> file we created earlier next to + the <code>nw</code> binary and we’re done. The <code>nwjs-sdk-v0.13.0-beta3-linux-x64</code> folder + does now contain the standalone Signal app.</p> + + <figure class="code"><div class="highlight"><pre>$ cd ../.. + $ wget http://dl.nwjs.io/v0.13.0-beta3/nwjs-sdk-v0.13.0-beta3-linux-x64.tar.gz + $ tar xfz nwjs-sdk-v0.13.0-beta3-linux-x64.tar.gz + $ cd nwjs-sdk-v0.13.0-beta3-linux-x64 + $ mv ../package.nw . + </pre></div></figure> + + + <p>Finally, launch NW.js. You should see a welcome page!</p> + + <figure class="code"><div class="highlight"><pre>$ ./nw + </pre></div></figure> + + + <h3>If you see something, file something</h3> + + <p>Our standalone Signal clone mostly works, but it’s far from perfect. We’re + pulling from master and that might bring breaking changes that weren’t + sufficiently tested.</p> + + <p>We don’t have the right icons. The app crashes when you click a media message. + It opens a blank popup when you click a link. It’s quite big because also NW.js + has bugs and so we have to use the SDK build for now. In the future it would be + great to have automatic updates, and maybe even signed builds.</p> + + <p>Remember, Signal Desktop is beta, and completely untested with NW.js. If you + want to help file bugs, but only after checking that those affect the Chrome + App too. If you want to fix a bug only occurring in the standalone version + it’s probably best to file a pull request and cross fingers.</p> + + <h3>Is this secure?</h3> + + <p>Great question! I don’t know. I would love to get some more insights from people + that know more about the NW.js security model and whether it comes with all the + protections Chromium can offer. Another interesting question is whether bundling + Signal Desktop with NW.js is in any way worse (from a security perspective) than + installing it as a Chrome extension. If you happen to have an opinion about + that, I would love to hear it.</p> + + <p>Another important thing to keep in mind is that when building Signal on your + own you will possibly miss automatic and signed security updates from the + Chrome Web Store. Keep an eye on the repository and rebuild your app from + time to time to not fall behind too much.</p> + 2016-01-15T14:00:00+00:00 + + + Mike Hommey: Announcing git-cinnabar 0.3.0 + http://glandium.org/blog/?p=3579 + <p>Git-cinnabar is a git remote helper to interact with mercurial repositories. It allows to clone, pull and push from/to mercurial remote repositories, using git.</p> + <p><a href="https://github.com/glandium/git-cinnabar">Get it on github</a>.</p> + <p>These release notes are also <a href="https://github.com/glandium/git-cinnabar/wiki/Release-Notes:-0.3.0">available on the git-cinnabar wiki</a>.</p> + <p>Development had been stalled for a few months, with many improvements in the<br /> + <code>next</code> branch without any new release. I used some time during the new year<br /> + break and after in order to straighten things up in order to create a new<br /> + release, delaying many of the originally planned changes to a future 0.4.0<br /> + release.</p> + <h3>What’s new since 0.2.2?</h3> + <ul> + <li>Speed and memory usage were improved when doing <code>git push</code>.</li> + <li>Now works on Windows, at least to some extent. See <a href="http://glandium.org/blog/Windows-Support">details</a>.</li> + <li>Support for pre-0.1.0 git-cinnabar repositories was removed. You must first<br /> + use a git-cinnabar version between 0.1.0 and 0.2.2 to upgrade its metadata.</li> + <li>It is now possible to attach/graft git-cinnabar metadata to existing commits<br /> + matching mercurial changesets. This allows to migrate from some other<br /> + hg-to-git tool to git-cinnabar while preserving the existing git commits.<br /> + See <a href="http://glandium.org/blog/Mozilla%3A-Using-a-git-clone-of-gecko%E2%80%90dev-to-push-to-mercurial">an example of how this works with the git clone of the Gecko mercurial<br /> + repository</a> + </li> + <li>Avoid mercurial printing its progress bar, messing up with git-cinnabar’s<br /> + output.</li> + <li>It is now possible to fetch from an incremental mercurial bundle (without<br /> + a root changeset).</li> + <li>It is now possible to push to a new mercurial repository without <code>-f</code>.</li> + <li>By default, reject pushing a new root to a mercurial repository.</li> + <li>Make the connection to a mercurial repository through ssh respect the<br /> + <code>GIT_SSH</code> and <code>GIT_SSH_COMMAND</code> environment variables.</li> + <li> + <code>git cinnabar</code> now has a proper argument parser for all its subcommands.</li> + <li> + </li> + <li>A new <code>git cinnabar python</code> command allows to run python scripts or open a<br /> + python shell with the right sys.path to import the cinnabar module.</li> + <li>All git-cinnabar metadata is now kept under a single ref (although for<br /> + convenience, other refs are created, but they can be derived if necessary).</li> + <li>Consequently, a new <code>git cinnabar rollback</code> command allows to roll back to<br /> + previous metadata states.</li> + <li>git-cinnabar metadata now tracks the manifests DAG.</li> + <li>A new <code>git cinnabar bundle</code> command allows to create mercurial bundles,<br /> + mostly for debugging purposes, without requiring to hit a mercurial server.</li> + <li>Updated git to 2.7.0 for the native helper.</li> + </ul> + <h3>Development process changes</h3> + <p>Up to before this release closing in, the <code>master</code> branch was dedicated to<br /> + releases, and development was happening on the <code>next</code> branch, until a new<br /> + release happens.</p> + <p>From now on, the <code>release</code> branch will take dot-release fixes and new<br /> + releases, while the <code>master</code> branch will receive all changes that are<br /> + validated through testing (currently semi-automatically tested with<br /> + out-of-tree tests based on four real-life mercurial repositories, with<br /> + some automated CI based on in-tree tests used in the future).</p> + <p>The <code>next</code> branch will receive changes to be tested in CI when things<br /> + will be hooked up, and may have rewritten history as a consequence of<br /> + wanting passing tests on every commit on <code>master</code>.</p> + 2016-01-15T08:56:40+00:00 + glandium + + + Air Mozilla: Web QA Weekly Meeting, 14 Jan 2016 + https://air.mozilla.org/web-qa-weekly-meeting-20160114/ + <p> + <img alt="Web QA Weekly Meeting" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/f5/13/f5137857516694df0458e837c2d3a4be.png" width="160" /> + This is our weekly gathering of Mozilla'a Web QA team filled with discussion on our current and future projects, ideas, demos, and fun facts. + </p> + 2016-01-14T17:00:00+00:00 + Air Mozilla + + + diff --git a/mobile/android/tests/background/junit4/resources/feed_rss20_planetmozilla.xml b/mobile/android/tests/background/junit4/resources/feed_rss20_planetmozilla.xml new file mode 100644 index 000000000..a3447ab8a --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_rss20_planetmozilla.xml @@ -0,0 +1,3853 @@ + + + + + Planet Mozilla + http://planet.mozilla.org/ + en + Planet Mozilla - http://planet.mozilla.org/ + + + + Aaron Klotz: Announcing Mozdbgext + http://dblohm7.ca/blog/2016/01/26/announcing-mozdbgext + http://dblohm7.ca/blog/2016/01/26/announcing-mozdbgext/ + <p>A well-known problem at Mozilla is that, while most of our desktop users run + Windows, most of Mozilla’s developers do not. There are a lot of problems that + result from that, but one of the most frustrating to me is that sometimes + those of us that actually use Windows for development find ourselves at a + disadvantage when it comes to tooling or other productivity enhancers.</p> + + <p>In many ways this problem is also a Catch-22: People don’t want to use Windows + for many reasons, but tooling is big part of the problem. OTOH, nobody is + motivated to improve the tooling situation if nobody is actually going to + use them.</p> + + <p>A couple of weeks ago my frustrations with the situation boiled over when I + learned that our <code>Cpp</code> unit test suite could not log symbolicated call stacks, + resulting in my filing of <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1238305" title="cppunittests do not look up breakpad symbols for logged stack traces">bug 1238305</a> and <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1240605" title="Set _NT_SYMBOL_PATH on Windows test machines">bug 1240605</a>. Not only could we + not log those stacks, in many situations we could not view them in a debugger + either.</p> + + <p>Due to the fact that PDB files consume a large amount of disk space, we don’t + keep those when building from integration or try repositories. Unfortunately + they are be quite useful to have when there is a build failure. Most of our + integration builds, however, do include breakpad symbols. Developers may also + explicitly <a href="https://wiki.mozilla.org/ReleaseEngineering/TryServer#Getting_debug_symbols">request symbols</a> + for their try builds.</p> + + <p>A couple of years ago I had begun working on a WinDbg debugger extension that + was tailored to Mozilla development. It had mostly bitrotted over time, but I + decided to resurrect it for a new purpose: to help WinDbg<sup><a href="http://dblohm7.ca/atom.xml#fn1" id="r1">*</a></sup> + grok breakpad.</p> + + <h3>Enter mozdbgext</h3> + + <p><a href="https://github.com/dblohm7/mozdbgext"><code>mozdbgext</code></a> is the result. This extension + adds a few commands that makes Win32 debugging with breakpad a little bit easier.</p> + + <p>The original plan was that I wanted <code>mozdbgext</code> to load breakpad symbols and then + insert them into the debugger’s symbol table via the <a href="https://msdn.microsoft.com/en-us/library/windows/hardware/ff537943%28v=vs.85%29.aspx"><code>IDebugSymbols3::AddSyntheticSymbol</code></a> + API. Unfortunately the design of this API is not well equipped for bulk loading + of synthetic symbols: each individual symbol insertion causes the debugger to + re-sort its entire symbol table. Since <code>xul.dll</code>’s quantity of symbols is in the + six-figure range, using this API to load that quantity of symbols is + prohibitively expensive. I tweeted a Microsoft PM who works on Debugging Tools + for Windows, asking if there would be any improvements there, but it sounds like + this is not going to be happening any time soon.</p> + + <p>My original plan would have been ideal from a UX perspective: the breakpad + symbols would look just like any other symbols in the debugger and could be + accessed and manipulated using the same set of commands. Since synthetic symbols + would not work for me in this case, I went for “Plan B:” Extension commands that + are separate from, but analagous to, regular WinDbg commands.</p> + + <p>I plan to continuously improve the commands that are available. Until I have a + proper README checked in, I’ll introduce the commands here.</p> + + <h4>Loading the Extension</h4> + + <ol> + <li>Use the <code>.load</code> command: <code>.load &lt;path_to_mozdbgext_dll&gt;</code></li> + </ol> + + + <h4>Loading the Breakpad Symbols</h4> + + <ol> + <li>Extract the breakpad symbols into a directory.</li> + <li>In the debugger, enter <code>!bploadsyms &lt;path_to_breakpad_symbol_directory&gt;</code></li> + <li>Note that this command will take some time to load all the relevant symbols.</li> + </ol> + + + <h4>Working with Breakpad Symbols</h4> + + <p><strong>Note: You must have successfully run the <code>!bploadsyms</code> command first!</strong></p> + + <p>As a general guide, I am attempting to name each breakpad command similarly to + the native WinDbg command, except that the command name is prefixed by <code>!bp</code>.</p> + + <ul> + <li>Stack trace: <code>!bpk</code></li> + <li>Find nearest symbol to address: <code>!bpln &lt;address&gt;</code> where <em>address</em> is specified + as a hexadecimal value.</li> + </ul> + + + <h4>Downloading windbgext</h4> + + <p>I have pre-built a <a href="https://github.com/dblohm7/mozdbgext/blob/master/bin/mozdbgext.dll?raw=true">32-bit binary</a> + (which obviously requires 32-bit WinDbg). I have not built a 64-bit binary yet, + but the code should be source compatible.</p> + + <p>Note that there are several other commands that are “roughed-in” at this point + and do not work correctly yet. Please stick to the documented commands at this + time.</p> + + <hr /> + + <p><sup><a href="http://dblohm7.ca/atom.xml#r1" id="fn1">*</a></sup> When I write “WinDbg”, I am really + referring to any debugger in the <em>Debugging Tools for Windows</em> package, + including <code>cdb</code>.</p> + Tue, 26 Jan 2016 19:45:00 +0000 + + + Yunier José Sosa Vázquez: Soporte para WebM/VP9, más seguridad y nuevas herramientas para desarrolladores en el nuevo Firefox + http://firefoxmania.uci.cu/?p=15548 + http://firefoxmania.uci.cu/soporte-para-webmvp9-mas-seguridad-y-nuevas-herramientas-para-desarrolladores-en-el-nuevo-firefox/ + <p style="text-align: left;">¡Como pasa el tiempo amigos! Casi sin darnos cuenta han transcurrido 6 semanas y hasta hemos comenzado un año nuevo, un año en el que Mozilla prepara nuevas funcionalidades que harán de Firefox un mejor como por ejemplo: la <a href="http://firefoxmania.uci.cu/como-se-hace-activar-electrolysis-en-firefox/" target="_blank">separación de procesos</a>, el uso de vías alternas para <a href="http://firefoxmania.uci.cu/el-futuro-de-los-plugins-npapi-en-firefox/" target="_blank">ejecutar plugins</a> y la nueva API para desarrollar <a href="http://firefoxmania.uci.cu/el-futuro-de-los-complementos-en-firefox/" target="_blank">complementos “multi navegador”</a>.</p> + <p style="text-align: left;">Desde el anuncio en 2010 del formato de video WebM, <a href="https://blog.mozilla.org/blog/2010/05/19/open-web-open-video-and-webm/" target="_blank">Mozilla ha mostrado un especial interés</a> al ser una alternativa potente frente a los formatos propietarios del mercado que existían en aquel momento y de esta forma mejorar la experiencia de los usuarios al reproducir videos en la web. Con esta liberación se ha habilitado el <strong>soporte para WebM/VP9 en aquellos sistemas que no soportan MP4/H.264</strong>.</p> + <p style="text-align: left;">Desde algunas versiones atrás, Firefox incluye el plugin <a href="http://andreasgal.com/2014/10/14/openh264-now-in-firefox/" target="_blank">OpenH264 proveído por Cisco</a> para cumplir las especificaciones de WebRTC y habilitar las llamadas con dispositivos que lo requieran. Ahora, si el <strong>decodificador de H.264 está disponible</strong> en el sistema, entonces se habilita este codec de video.<span id="more-15548"></span></p> + <h3 style="text-align: left;"><em>Novedades para desarrolladores</em></h3> + <p style="text-align: left;">En esta oportunidad, los desarrolladores podrán contar con herramientas de animación y filtros CSS, informes sobre consumo de memoria, depuración de WebSocket y más. Todo esto puedes leerlo en <a href="https://www.mozilla-hispano.org/edicion-para-desarrolladores-44-editor-visual-manejo-de-memoria/" target="_blank">el blog de Labs</a> de Mozilla Hispano.</p> + <h3 style="text-align: left;"><em>Novedades en Android</em></h3> + <ul> + <li>Los usuarios pueden elegir la página de inicio a mostrar, en vez de los sitios más visitados.</li> + <li>El servicio de impresión de Android permite activar la impresión en la nube.</li> + <li>Al <a href="https://developer.chrome.com/multidevice/android/intents" target="_blank">intentar abrir una URIs</a>, se le pregunta al usuario si desea abrirla en una pestaña privada.</li> + <li>Adicionado el soporte para ejecutar URIs con el protocolo mms.</li> + <li>Fácil acceso a la configuración de la búsqueda mientras buscamos en Internet.</li> + <li>Ahora se muestran las sugerencias del historial de búsqueda.</li> + <li>La página Cuentas Firefox ahora está basada en la web.</li> + </ul> + <h3><em>Otras novedades</em></h3> + <ul> + <li>El soporte para el algoritmo criptográfico RC4 ha sido removido.</li> + <li>Soporte para el formato de compresión brotli cuando se usa HTTPS.</li> + <li>Uso de un certificado de firmado SHA256 para las versiones de Windows en aras de adaptarse a los nuevos requerimientos.</li> + <li>Para soportar el descriptor unicode-range de las fuentes web, el algoritmo de concordancia en Linux usa el mismo código como en las demás plataformas.</li> + <li>Firefox no confiará más en la autoridad de certificación Equifax Secure Certificate Authority 1024-bit root o UTN – DATACorp SGC para validar <a href="https://support.mozilla.org/ta/kb/secure-website-certificate" target="_blank">certificados web seguros</a>.</li> + <li>El soporte para el teclado en pantalla ha sido temporalmente desactivado en Windows 8 y 8.1.</li> + </ul> + <p>Si deseas conocer más, puedes leer las <a href="http://www.mozilla.org/en-US/firefox/44.0/releasenotes/" target="_blank">notas de lanzamiento</a> (en inglés) para conocer más novedades.</p> + <p><strong>Aclaración para la versión móvil.</strong></p> + <p>En las descargas se pueden encontrar 3 versiones para Android. El archivo que contiene <strong>i386</strong> es para los dispositivos que tengan la <strong>arquitectura de Intel</strong>. Mientras que en los nombrados <strong>arm</strong>, el que dice <strong>api11 funciona con Honeycomb (3.0) o superior</strong> y el de <strong>api9 es para Gingerbread (2.3)</strong>.</p> + <p>Puedes obtener esta versión desde nuestra <a href="http://firefoxmania.uci.cu/download/" target="_blank">zona de Descargas</a> en español e inglés para Linux, Mac, Windows y Android. Recuerda que para navegar a través de servidores proxy debes modificar la preferencia <strong>network.auth.force-generic-ntlm</strong> a <code>true</code> desde <a target="_blank">about:config</a>.</p> + <p>Si te ha gustado, por favor comparte con tus amigos esta noticia en las redes sociales. No dudes en dejarnos un comentario.</p> + Tue, 26 Jan 2016 18:56:54 +0000 + Yunier J + + + QMO: Firefox 45.0 Beta 3 Testday, February 5th + https://quality.mozilla.org/?p=49454 + https://quality.mozilla.org/2016/01/firefox-45-0-beta-3-testday-february-5th/ + <p>Hello Mozillians,</p> + <p>We are happy to announce that <strong>Friday, February 5th</strong>, we are organizing <strong>Firefox 45.0 Beta 3 Testday</strong>. We will be focusing our testing on the following features: <em>Search Refactoring, Synced Tabs Menu, Text to Speech and Grouped Tabs Migration</em>. Check out the detailed instructions via <a href="https://public.etherpad-mozilla.org/p/testday-20160205" target="_blank">this etherpad</a>.</p> + <p>No previous testing experience is required, so feel free to join us on <strong><a href="http://widget01.mibbit.com/?server=irc.mozilla.org&amp;channel=%23qa">#qa IRC channel</a></strong> where our moderators will offer you guidance and answer your questions.</p> + <p>Join us and help us make Firefox better! See you on <strong>Friday</strong>!</p> + Tue, 26 Jan 2016 14:40:55 +0000 + vasilica.mihasca + + + David Lawrence: Happy BMO Push Day! + http://dlawrence.wordpress.com/?p=29 + https://dlawrence.wordpress.com/2016/01/26/happy-bmo-push-day-4/ + <p>the following changes have been pushed to bugzilla.mozilla.org:</p> + <ul> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1240575" target="_blank">1240575</a>] Update form.reps.budget</li> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1226028" target="_blank">1226028</a>] API for batching MozReview requests</li> + </ul> + <p>discuss these changes on <a href="https://lists.mozilla.org/listinfo/tools-bmo" target="_blank">mozilla.tools.bmo</a>.</p><br /> <a href="http://feeds.wordpress.com/1.0/gocomments/dlawrence.wordpress.com/29/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dlawrence.wordpress.com/29/" /></a> <img alt="" border="0" height="1" src="https://pixel.wp.com/b.gif?host=dlawrence.wordpress.com&amp;blog=58816&amp;post=29&amp;subd=dlawrence&amp;ref=&amp;feed=1" width="1" /> + Tue, 26 Jan 2016 14:27:50 +0000 + dlawrence + + + Tanvi Vyas: Updated Firefox Security Indicators + http://blog.mozilla.org/tanvi/?p=198 + https://blog.mozilla.org/tanvi/2016/01/26/updated-firefox-security-indicators/ + <p><em>This article has been coauthored by Aislinn Grigas, Senior Interaction Designer, Firefox Desktop</em><br /> + <em>Cross posting with <a href="https://blog.mozilla.org/security/2015/11/03/updated-firefox-security-indicators-2/">Mozilla’s Security Blog</a></em></p> + <p>November 3, 2015</p> + <p>Over the past few months, Mozilla has been improving the user experience of our privacy and security features in Firefox. One specific initiative has focused on the feedback shown in our address bar around a site’s security. The major changes are highlighted below along with the rationale behind each change.</p> + <p><a href="https://blog.mozilla.org/security/files/2015/10/combo-graph21.png"><img alt="" class="alignnone wp-image-2045 size-full" height="914" src="https://blog.mozilla.org/security/files/2015/10/combo-graph21.png" width="1518" /></a></p> + <h3>Change to DV Certificate treatment in the address bar</h3> + <p>Color and iconography is commonly used today to communicate to users when a site is secure. The most widely used patterns are coloring a lock icon and parts of the address bar green. This treatment has a straightforward rationale given green = good in most cultures. Firefox has historically used two different color treatments for the lock icon – a gray lock for <a href="https://en.wikipedia.org/wiki/Domain-validated_certificate">Domain-validated (DV) certificates</a> and a green lock for <a href="https://en.wikipedia.org/wiki/Extended_Validation_Certificate">Extended Validation (EV) certificates</a>. The average user is likely not going to understand this color distinction between EV and DV certificates. The overarching message we want users to take from both certificate states is that their connection to the site is secure. We’re therefore updating the color of the lock when a DV certificate is used to match that of an EV certificate.</p> + <p>Although the same green icon will be used, the UI for a site using EV certificates will continue to differ from a site using a DV certificate. Specifically, EV certificates are used when <a href="https://en.wikipedia.org/wiki/Certificate_authority">Certificate Authorities (CA)</a> verify the owner of a domain. Hence, we will continue to include the organization name verified by the CA in the address bar.</p> + <h3>Changes to Mixed Content Blocker UI on HTTPS sites</h3> + <p>A second change we’re introducing addresses what happens when a page served over a secure connection contains <a href="https://developer.mozilla.org/en-US/docs/Security/MixedContent">Mixed Content</a>. Firefox’s Mixed Content Blocker proactively blocks <a href="https://developer.mozilla.org/en-US/docs/Security/MixedContent#Mixed_active_content">Mixed Active Content</a> by default. Users historically saw a <a href="https://people.mozilla.org/~tvyas/FigureA.jpg">shield icon</a> when Mixed Active Content was blocked and were given the option to disable the protection.</p> + <p>Since the Mixed Content state is closely tied to site security, the information should be communicated in one place instead of having two separate icons. Moreover, we have seen that the <a href="https://telemetry.mozilla.org/new-pipeline/dist.html#!cumulative=0&amp;end_date=2015-09-17&amp;keys=__none__!__none__!__none__&amp;max_channel_version=beta%252F41&amp;measure=MIXED_CONTENT_UNBLOCK_COUNTER&amp;min_channel_version=null&amp;product=Firefox&amp;sanitize=1&amp;sort_keys=submissions&amp;start_date=2015-08-11&amp;table=0&amp;trim=1&amp;use_submission_date=0">number of times users override mixed content protection</a> is slim, and hence the need for dedicated mixed content iconography is diminishing. Firefox is also using the shield icon for another feature in <a href="https://support.mozilla.org/en-US/kb/private-browsing-use-firefox-without-history">Private Browsing Mode</a> and we want to avoid making the iconography ambiguous.</p> + <p>The updated design that ships with Firefox 42 combines the lock icon with a warning sign which represents Mixed Content. When Firefox blocks Mixed Active Content, we retain the green lock since the HTTP content is blocked and hence the site remains secure.</p> + <p>For users who want to learn more about a site’s security state, we have added an informational panel to further explain differences in page security. This panel appears anytime a user clicks on the lock icon in the address bar.</p> + <p>Previously users could <a href="https://people.mozilla.org/~tvyas/FigureB.jpg">click on the shield icon</a> in the rare case they needed to override mixed content protection. With this new UI, users can still do this by clicking the arrow icon to expose more information about the site security, along with a disable protection button.</p> + <div class="wp-caption alignnone" id="attachment_2034" style="width: 557px;"><a href="https://blog.mozilla.org/security/files/2015/10/mixed-active-content-click-and-subpanel.png"><img alt="mixed active content click and subpanel" class="wp-image-2034 " height="176" src="https://blog.mozilla.org/security/files/2015/10/mixed-active-content-click-and-subpanel.png" width="547" /></a><p class="wp-caption-text">Users can click the lock with warning icon and proceed to disable Mixed Content Protection.</p></div> + <h3></h3> + <h3>Loading Mixed Passive Content on HTTPS sites</h3> + <p>There is a second category of Mixed Content called <a href="https://developer.mozilla.org/en-US/docs/Security/MixedContent#Mixed_passivedisplay_content">Mixed Passive Content</a>. Firefox does not block Mixed Passive Content by default. However, when it is loaded on an HTTPS page, we let the user know with iconography and text. In previous versions of Firefox, we used a gray warning sign to reflect this case.</p> + <p>We have updated this iconography in Firefox 42 to a gray lock with a yellow warning sign. We degrade the lock from green to gray to emphasize that the site is no longer completely secure. In addition, we use a vibrant color for the warning icon to amplify that there is something wrong with the security state of the page.</p> + <p><a href="https://blog.mozilla.org/security/files/2015/10/mixed-passive-click1.png"><img alt="" class="alignnone wp-image-2042 " height="100" src="https://blog.mozilla.org/security/files/2015/10/mixed-passive-click1-600x221.png" width="268" /></a></p> + <p>We also use this iconography when the certificate or TLS connection used by the website relies on deprecated cryptographic algorithms.</p> + <p>The above changes will be rolled out in Firefox 42. Overall, the design improvements make it simpler for our users to understand whether or not their interactions with a site are secure.</p> + <h3>Firefox Mobile</h3> + <p>We have made similar changes to the site security indicators in Firefox for Android, which you can learn more about <a href="https://support.mozilla.org/en-US/kb/mixed-content-blocker-firefox-android#w_how-do-i-know-if-a-page-has-mixed-content">here</a>.</p> + Tue, 26 Jan 2016 05:58:29 +0000 + Tanvi Vyas + + + The Mozilla Blog: Firefox Can Now Get Push Notifications From Your Favorite Sites + https://blog.mozilla.org/?p=9166 + https://blog.mozilla.org/blog/2016/01/25/firefox-can-now-get-push-notifications-from-your-favorite-sites/ + <p>UPDATED TO CLARIFY HOW TO MANAGE PUSH NOTIFICATIONS</p> + <p>Firefox for Windows, Mac and Linux now lets you choose to receive push notifications from websites if you give them permission. This is similar to Web notifications, except now you can receive notifications for websites even when they’re not loaded in a tab. This is super useful for websites like email, weather, social networks and shopping, which you might check frequently for updates.</p> + <p>You can manage your notifications in the Control Center by clicking the green lock icon on the left side of the address bar. You can learn more about how to manage push notifications<a href="https://support.mozilla.org/en-US/kb/push-notifications-firefox?as=u&amp;utm_source=inproduct#w_upgraded-notifications"> here</a>.</p> + <p><b>Push Notifications for Web Developers</b><br /> + To make this functionality possible, Mozilla helped establish the Web Push W3C standard that’s gaining momentum across the Web. We also continue to explore the new design pattern known as<a href="https://blog.mozilla.org/futurereleases/2015/11/17/extending-the-webs-capabilities-in-firefox-and-beyond/"> Progressive Web Apps</a>. If you’re a developer who wants to implement push notifications on your site, you can learn more in this<a href="https://hacks.mozilla.org/2016/01/web-push-arrives-in-firefox-44/"> Hacks blog post</a>.</p> + <p><b>More information:</b></p> + <ul> + <li>Download<a href="https://www.mozilla.org/firefox/new/"> Firefox for Windows, Mac, Linux</a></li> + <li>Release Notes for<a href="https://www.mozilla.org/firefox/44.0/releasenotes/"> Firefox for Windows, Mac, Linux</a></li> + <li>Download<a href="https://play.google.com/store/apps/details?id=org.mozilla.firefox&amp;referrer=utm_source%3Dmozilla%26utm_medium"> Firefox for Android</a></li> + <li>Release Notes for<a href="https://www.mozilla.org/firefox/android/44.0/releasenotes/"> Firefox for Android</a></li> + </ul> + Tue, 26 Jan 2016 01:56:50 +0000 + Mozilla + + + Benoit Girard: Using RecordReplay to investigate intermittent oranges + http://benoitgirard.wordpress.com/?p=651 + https://benoitgirard.wordpress.com/2016/01/25/using-recordreplay-to-investigate-intermittent-oranges/ + <p>This is a quick write up to summarize my, and Jeff’s, experience, using RR to debug a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1226748">fairly rare intermittent reftest failure</a>. There’s still a lot of be learned about how to use RR effectively so I’m hoping sharing this will help others.</p> + <h3>Finding the root of the bad pixel</h3> + <p>First given a offending pixel I was able to set a breakpoint on it using <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Hacking_Tips#rr_with_reftest">these instructions</a>. Next using <a href="https://github.com/jrmuizel/rr-dataflow">rr-dataflow</a> I was able to step from the offending bad pixel to the display item responsible for this pixel. Let me emphasize this for a second since it’s incredibly impressive. rr + rr-dataflow allows you to go from a buffer, through an intermediate surface, to the compositor on another thread, through another intermediate surface, back to the main thread and eventually back to the relevant display item. All of this was automated except for when the two pixels are blended together which is logically ambiguous. The speed at which rr was able to reverse continue through this execution was very impressive!</p> + <p>Here’s the trace of this part: <a href="https://gist.github.com/bgirard/e707e9b97556b500d9ae">rr-trace-reftest-pixel-origin</a></p> + <h3>Understanding the decoding step</h3> + <p>From here I started comparing a replay of a failing test and a non failing step and it was clear that the DisplayList was different. In one we have a nsDisplayBackgroundColor in the other we don’t. From here I was able to step through the decoder and compare the sequence. This was very useful in ruling out possible theories. It was easy to step forward and backwards in the good and bad replay debugging sessions to test out various theories about race conditions and understanding at which part of the decode process the image was rejected. It turned out that we sent two decodes, one for the metadata that is used to sized the frame tree and the other one for the image data itself.</p> + <h3>Comparing the frame tree</h3> + <p>In hindsight, it would have been more effective to start debugging this test by looking at the frame tree (and I imagine for other tests looking at the display list and layer tree) first would have been a quicker start. It works even better if you have a good and a bad trace to compare the difference in the frame tree. From here, I found that the difference in the layer tree came from a change hint that wasn’t guaranteed to come in before the draw.</p> + <p>The problem is now well understood: When we do a sync decode on reftest draw, if there’s an image error we wont flush the style hints since we’re already too deep in the painting pipeline.</p> + <h3>Take away</h3> + <ul> + <li>Finding the root cause of a bad pixel is very easy, and fast, to do using rr-dataflow.</li> + <li>However it might be better to look for obvious frame tree/display list/layer tree difference(s) first.</li> + <li>Debugging a replay is a lot simpler then debugging against non-determinist re-runs and a lot less frustrating too.</li> + <li>rr is really useful for race conditions, especially rare ones.</li> + </ul><br /> <a href="http://feeds.wordpress.com/1.0/gocomments/benoitgirard.wordpress.com/651/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/benoitgirard.wordpress.com/651/" /></a> <img alt="" border="0" height="1" src="https://pixel.wp.com/b.gif?host=benoitgirard.wordpress.com&amp;blog=12112851&amp;post=651&amp;subd=benoitgirard&amp;ref=&amp;feed=1" width="1" /> + Mon, 25 Jan 2016 22:16:01 +0000 + benoitgirard + + + The Servo Blog: These Weeks In Servo 48 + http://blog.servo.org/2016/01/25/twis-48/ + http://blog.servo.org/2016/01/25/twis-48/ + <p>In the <a href="https://github.com/pulls?page=1&amp;q=is%3Apr+is%3Amerged+closed%3A2016-01-11..2016-01-25+user%3Aservo">last two weeks</a>, we landed 130 PRs in the Servo organization’s repositories.</p> + + <p>After months of work by vlad and many others, Windows support <a href="https://github.com/servo/servo/pull/9385">landed</a>! Thanks to everyone who contributed fixes, tests, reviews, and even encouragement (or impatience!) to help us make this happen.</p> + + <h3 id="notable-additions">Notable Additions</h3> + + <ul> + <li>nikki <a href="https://github.com/servo/servo/pull/9391">added</a> tests and support for checking the Fetch redirect count</li> + <li>glennw <a href="https://github.com/servo/servo/pull/9359">implemented</a> horizontal scrolling with arrow keys</li> + <li>simon <a href="https://github.com/servo/servo/pull/9333">created</a> a script that parses all of the CSS properties parsed by Servo</li> + <li>ms2ger <a href="https://github.com/servo/servo/pull/9293">removed</a> the legacy reftest framework</li> + <li>fernando <a href="https://github.com/servo/crowbot/pull/33">made</a> crowbot able to rejoin IRC after it accidentally floods the channel</li> + <li>jack <a href="https://github.com/servo/saltfs/pull/193">added</a> testing the <code>geckolib</code> target to our CI</li> + <li>antrik <a href="https://github.com/servo/ipc-channel/pull/25">fixed</a> transfer corruption in ipc-channel on 32-bit</li> + <li>valentin <a href="https://github.com/servo/rust-url/pull/119">added</a> and simon <a href="https://github.com/servo/rust-url/pull/152">extended</a> IDNA support in rust-url, which is required for both web and Gecko compatibility</li> + </ul> + + <h3 id="new-contributors">New Contributors</h3> + + <ul> + <li><a href="https://github.com/Chandler">Chandler Abraham</a></li> + <li><a href="https://github.com/DarinM223">Darin Minamoto</a></li> + <li><a href="https://github.com/coder543">Josh Leverette</a></li> + <li><a href="https://github.com/shssoichiro">Joshua Holmer</a></li> + <li><a href="https://github.com/therealkbhat">Kishor Bhat</a></li> + <li><a href="https://github.com/MonsieurLanza">Lanza</a></li> + <li><a href="https://github.com/mattkuo">Matthew Kuo</a></li> + <li><a href="https://github.com/waterlink">Oleksii Fedorov</a></li> + <li><a href="https://github.com/stspyder">St.Spyder</a></li> + <li><a href="https://github.com/vvuk">Vladimir Vukicevic</a></li> + <li><a href="https://github.com/apopiak">apopiak</a></li> + <li><a href="https://github.com/askalski">askalski</a></li> + </ul> + + <h3 id="screenshot">Screenshot</h3> + + <p>Screencast of this post being upvoted on reddit… from Windows!</p> + + <p><img alt="(screencast)" src="http://blog.servo.org/images/upvote-windows.gif" title="Screencast of upvoting on Reddit on Windows." /></p> + + <h3 id="meetings">Meetings</h3> + + <p>We had a <a href="https://github.com/servo/servo/wiki/Meeting-2016-01-11">meeting</a> on some CI-related woes, documenting tags and mentoring, and dependencies for the style subsystem.</p> + Mon, 25 Jan 2016 20:30:00 +0000 + + + Air Mozilla: Mozilla Weekly Project Meeting, 25 Jan 2016 + https://air.mozilla.org/mozilla-weekly-project-meeting-20160125/ + https://air.mozilla.org/mozilla-weekly-project-meeting-20160125/ + <p> + <img alt="Mozilla Weekly Project Meeting" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/e9/4f/e94fbd7f8df916c75a60e63a85b9168c.png" width="160" /> + The Monday Project Meeting + </p> + Mon, 25 Jan 2016 19:00:00 +0000 + Air Mozilla + + + About:Community: Firefox 44 new contributors + http://blog.mozilla.org/community/?p=2292 + http://blog.mozilla.org/community/2016/01/25/firefox-44-new-contributors/ + <p>With the release of Firefox 44, we are pleased to welcome the <strong>28 developers</strong> who contributed their first code change to Firefox in this release, <strong>23</strong> of whom were brand new volunteers! Please join us in thanking each of these diligent and enthusiastic individuals, and take a look at their contributions:</p> + <ul> + <li>mkm: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208124">1208124</a></li> + <li>Aditya Motwani: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1209087">1209087</a></li> + <li>Aniket Vyas: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1197309">1197309</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1197315">1197315</a></li> + <li>Chirath R: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1216941">1216941</a></li> + <li>Christiane Ruetten: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1209091">1209091</a></li> + <li>Fernando Campo: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1199815">1199815</a></li> + <li>Grisha Pushkov: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=994555">994555</a></li> + <li>Guang-De Lin: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1150305">1150305</a></li> + <li>Hassen ben tanfous: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1074804">1074804</a></li> + <li>Helen V. Holmes: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1205046">1205046</a></li> + <li>Henrik Tjäder: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1161698">1161698</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1209912">1209912</a></li> + <li>Johann Hofmann: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1192432">1192432</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1198405">1198405</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1204072">1204072</a></li> + <li>Kapeel Sable: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1212171">1212171</a></li> + <li>Manav Batra: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1202618">1202618</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1212280">1212280</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1214626">1214626</a></li> + <li>Manuel Casas Barrado: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1172662">1172662</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1193674">1193674</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1200693">1200693</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1203298">1203298</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1205684">1205684</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1212331">1212331</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1212338">1212338</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1214582">1214582</a></li> + <li>Matt Howell: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208626">1208626</a></li> + <li>Matthew Turnbull: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1213620">1213620</a></li> + <li>Olivier Yiptong: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1210936">1210936</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1210940">1210940</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1213078">1213078</a></li> + <li>Piotr Tworek: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1209446">1209446</a></li> + <li>Rocik: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1070719">1070719</a></li> + <li>Roland Sako: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1207733">1207733</a></li> + <li>Ronald Claveau: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1207266">1207266</a></li> + <li>Sanchit Nevgi: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1205181">1205181</a></li> + <li>Shaif Chowdhury: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1185606">1185606</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208121">1208121</a></li> + <li>Shubham Jain: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208470">1208470</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208705">1208705</a></li> + <li>Stanislas Daniel Claude Dolcini: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1147197">1147197</a></li> + <li>Stephanie Ouillon: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1178533">1178533</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1201626">1201626</a></li> + <li>Tim Huang: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1181489">1181489</a></li> + <li>simplyblue24: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1218204">1218204</a></li> + </ul> + Mon, 25 Jan 2016 16:21:33 +0000 + Josh Matthews + + + Doug Belshaw: 3 things to consider when designing a digital skills framework + tag:literaci.es,2014:Post/digital-skills-curriculum + http://literaci.es/digital-skills-curriculum + <p><img alt="Learning to credential" src="http://bryanmmathers.com/wp-content/uploads/2016/01/learning-to-credential.png" /></p> + + <p>The image above was created by <a href="http://bryanmmathers.com/learning-to-credential" rel="nofollow">Bryan Mathers</a> for our <a href="https://goo.gl/QqwUKP" rel="nofollow">presentation</a> at <a href="http://bettshow.com" rel="nofollow">BETT</a> last week. It shows the way that, in broad brushstrokes, learning design <em>should</em> happen. Before microcredentials such as <a href="http://openbadges.org" rel="nofollow">Open Badges</a> this was a difficult thing to do as both the credential and the assessment are usually given to educators. The flow tends to go <em>backwards</em> from credentials instead of forwards from what we want people to learn.</p> + + <p>But what if you really <em>were</em> starting from scratch? How could you design a digital skills framework that contains knowledge, skills, and behaviours worth learning? Having written my <a href="http://neverendingthesis.com" rel="nofollow">thesis</a> on digital literacies and led Mozilla’s <a href="https://teach.mozilla.org/activities/web-literacy/" rel="nofollow">Web Literacy Map</a> for a couple of years, I’ve got some suggestions. </p> + <h3> + <a class="head_anchor" href="http://literaci.es/feed#1-define-your-audience" name="1-define-your-audience" rel="nofollow"> </a>1. Define your audience</h3> + <p>One of the most important things to define is who your audience is for your digital skills framework. Is it for learners to read? Who are they? How old are they? Are you excluding anyone on purpose? Why / why not?</p> + + <p>You might want to do some research and work around <a href="https://en.wikipedia.org/wiki/Persona_(user_experience)" rel="nofollow">user personas</a> as part of a user-centred design approach. This ensures you’re designing for real people instead of figments of your imagination (or, worse still, in line with your prejudices).</p> + + <p>It’s also good practice to make the language used in the skills framework as precise as possible. Jargon is technical language used for the sake of it. There may be times when it’s impossible not to use a word (e.g. ’<a href="https://en.wikipedia.org/wiki/Meme" rel="nofollow">meme</a>’). If you do this then link to a definition or include a glossary. It’s also useful to check the ‘reading level’ of your framework and, if you really want a challenge, try using <a href="http://splasho.com/upgoer5/" rel="nofollow">Up-Goer Five</a> language.</p> + <h3> + <a class="head_anchor" href="http://literaci.es/feed#2-focus-on-verbs" name="2-focus-on-verbs" rel="nofollow"> </a>2. Focus on verbs</h3> + <p>It’s extremely easy, when creating a framework for learning, to fall into the 'knowledge trap’. Our aim when creating the raw materials from which someone can build a curriculum is to focus on <em>action</em>. Knowledge should make a difference in practice.</p> + + <p>One straightforward way to ensure that you’re focusing on action rather than head knowledge is to use <strong>verbs</strong> when constructing your digital skills framework. If you’re familiar with <a href="https://en.wikipedia.org/wiki/Bloom%27s_taxonomy" rel="nofollow">Bloom’s Taxonomy</a>, then you may find <a href="http://byrdseed.com/differentiator/" rel="nofollow">The Differentiator</a> useful. This pairs verbs with the various levels of Bloom’s.</p> + <h3> + <a class="head_anchor" href="http://literaci.es/feed#3-add-version-numbers" name="3-add-version-numbers" rel="nofollow"> </a>3. Add version numbers</h3> + <p>A framework needs to be a living, breathing thing. It should be subject to revision and updated often. For this reason, you should add version numbers to your documentation. Ideally, the latest version should be at a canonical URL and you should archive previous versions to static URLs. </p> + + <p>I would also advise releasing the first version of your framework not as 'version 1.0’ but as 'v0.1’. This shows that you’re willing for others to provide input, that there will be further versions, and that you know you haven’t got it right first time (and forevermore). </p> + + <hr /> + + <p><strong>Questions? Comments?</strong> Ask me on Twitter (<a href="http://twitter.com/dajbelshaw" rel="nofollow">@dajbelshaw</a>). I also consult around this kind of thing, so hit me up on <a href="http://literaci.es/hello@dynamicskillset.com" rel="nofollow">hello@dynamicskillset.com</a></p> + Mon, 25 Jan 2016 14:46:34 +0000 + + + Mozilla Fundraising: Why did you decide to donate today? + https://fundraising.mozilla.org/?p=800 + https://fundraising.mozilla.org/why-did-you-decide-to-donate-today/ + This year, we asked some of our donors why they decided to donate to our end of year fundraising campaign. The Survey The Audience The survey was shown to a random sample of donors whose browser language was set to … <a class="go" href="https://fundraising.mozilla.org/why-did-you-decide-to-donate-today/">Continue reading</a> + Mon, 25 Jan 2016 13:31:34 +0000 + Adam Lofting + + + Andy McKay: Robbie Burns + http://www.agmweb.ca/robbie-burns + http://www.agmweb.ca/2016-01-25-robbie-burns/ + <p>Tonight is Robbie Burns night, in honour of that great Scottish poet. But tonight had me thinking about another night in my past.</p> + + <p>It was about 5 years ago, maybe less, I struggle to remember now. I was in the UK visiting family and my Dad was sick. Cancer and it's treatment is tough, you have good weeks, you have bad weeks and you have really fucking bad weeks. This was a good week and for some reason I was in the UK.</p> + + <p>Myself, my brother and my sister-in-law went down to see him that night. It was Robbie Burns night and that meant an excuse for haggis, really, truly terrible scotch, Scottish dancing and all that. There are many times when I look back at time with my Dad in those last few years. This was definitely one of those times. He was my Dad at his best, cracking jokes and having fun. Living life to the absolute fullest, while you still have that chance.</p> + + <p>We had a great night. That ended way too soon.</p> + + <p>Not long after that the cancer came back and that was that.</p> + + <p>But suddenly tonight, in a bar in Portland I had these memories of my Dad in a waistcoat cracking jokes and having fun on Robbie Burns night. No-one else in the bar seemed to know what night it was. You'd think Robbie Burns night might get a little bit more appreciation, but hey.</p> + + <p>In the many years I've been running this blog I've never written about my Dad passing away. Here's the first time. I miss him.</p> + + <p>Hey Robbie Burns? Thanks for making me remember that night.</p> + Mon, 25 Jan 2016 08:00:00 +0000 + + + This Week In Rust: This Week in Rust 115 + tag:this-week-in-rust.org,2016-01-25:blog/2016/01/25/this-week-in-rust-115/ + http://this-week-in-rust.org/blog/2016/01/25/this-week-in-rust-115/ + <p>Hello and welcome to another issue of <em>This Week in Rust</em>! + <a href="http://rust-lang.org">Rust</a> is a systems language pursuing the trifecta: + safety, concurrency, and speed. This is a weekly summary of its progress and + community. Want something mentioned? Tweet us at <a href="https://twitter.com/ThisWeekInRust">@ThisWeekInRust</a> or <a href="mailto:corey@octayn.net?subject=This%20Week%20in%20Rust%20Suggestion">send us an + email</a>! + Want to get involved? <a href="https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md">We love + contributions</a>.</p> + <p><em>This Week in Rust</em> is openly developed <a href="https://github.com/cmr/this-week-in-rust">on GitHub</a>. + If you find any errors in this week's issue, <a href="https://github.com/cmr/this-week-in-rust/pulls">please submit a PR</a>.</p> + <p>This week's edition was edited by: <a href="https://github.com/nasa42">nasa42</a>, <a href="https://github.com/brson">brson</a>, and <a href="https://github.com/llogiq">llogiq</a>.</p> + <h3>Updates from Rust Community</h3> + <h4>News &amp; Blog Posts</h4> + <ul> + <li><img alt="balloon" class="emoji" src="https://cdn.discourse.org/business/images/emoji/emoji_one/balloon.png?v=0" title=":balloon:" /><img alt="tada" class="emoji" src="https://cdn.discourse.org/business/images/emoji/emoji_one/tada.png?v=0" title=":tada:" /> <a href="http://blog.rust-lang.org/2016/01/21/Rust-1.6.html">Announcing Rust 1.6</a>. <img alt="tada" class="emoji" src="https://cdn.discourse.org/business/images/emoji/emoji_one/tada.png?v=0" title=":tada:" /><img alt="balloon" class="emoji" src="https://cdn.discourse.org/business/images/emoji/emoji_one/balloon.png?v=0" title=":balloon:" /></li> + <li><a href="http://www.poumeyrol.fr/2016/01/15/Awkward-zone/">Rust, BigData and my laptop</a>.</li> + <li>[pdf]<a href="https://cdn.rawgit.com/Gankro/thesis/master/thesis.pdf">You can't spell trust without Rust</a>. Analysis of the semantics and expressiveness of Rust’s type system.</li> + <li><a href="http://www.ncameron.org/blog/libmacro/">Libmacro - an API for procedural macros to interact with the compiler</a>.</li> + <li><a href="http://www.jonathanturner.org/2016/01/rust-and-blub-paradox.html">Rust and the Blub Paradox</a>. And the <a href="http://www.jonathanturner.org/2016/01/rethinking-the-blub-paradox.html">follow-up</a>.</li> + <li>[video] <a href="https://www.youtube.com/channel/UC4mpLlHn0FOekNg05yCnkzQ/videos">Ferris Makes Emulators</a>. Live stream of Ferris developing a N64 emulator in Rust (also on <a href="http://www.twitch.tv/ferrisstreamsstuff/profile">Twitch</a>).</li> + </ul> + <h4>Notable New Crates &amp; Project Updates</h4> + <ul> + <li><a href="http://areweconcurrentyet.com/">Are we concurrent yet</a>?</li> + <li><a href="https://github.com/gfx-rs/gfx">GFX</a> epic rewrite for the Pipeline State Objects paradigm has <a href="https://github.com/gfx-rs/gfx/pull/828">landed</a>, described <a href="http://gfx-rs.github.io/2016/01/22/pso.html">on the blog</a>.</li> + <li><a href="https://github.com/mcarton/rust-herbie-lint">Herbie</a>. A rustc plugin to check for numerical instability.</li> + <li><a href="http://blog.piston.rs/2016/01/23/dynamo/">Dynamo</a>. A rusty dynamically typed scripting language.</li> + <li><a href="https://github.com/whitequark/rust-vnc">rust-vnc</a>. An implementation of VNC protocol, client state machine and a client.</li> + </ul> + <h3>Updates from Rust Core</h3> + <p>129 pull requests were <a href="https://github.com/issues?q=is%3Apr+org%3Arust-lang+is%3Amerged+merged%3A2016-01-18..2016-01-25">merged in the last week</a>.</p> + <p>See the <a href="https://internals.rust-lang.org/t/triage-digest-mon-jan-25-2016/3111">triage digest</a> and <a href="https://internals.rust-lang.org/t/subteam-reports-2016-01-22/3106">subteam reports</a> for more details.</p> + <h4>Notable changes</h4> + <ul> + <li><a href="https://github.com/rust-lang/rust/pull/30872">Implement RFC 1252 expanding the OpenOptions structure</a>.</li> + <li><a href="https://github.com/rust-lang/book/pull/58">Book: First draft of 'ownership'</a>.</li> + <li><a href="https://github.com/rust-lang/cargo/pull/2205">Cargo: Add convenience syntax to install current crate</a>.</li> + <li><a href="https://github.com/rust-lang/cargo/pull/2196">Cargo: Introduce cargo metadata subcommand</a>.</li> + <li><a href="https://github.com/rust-lang/cargo/pull/2081">Cargo: Implement <code>cargo init</code></a>.</li> + <li><a href="https://github.com/rust-lang/cargo/pull/2270">Cargo: Emit a warning when manifest specifies empty dependency constraints</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/29520">Change name when outputting staticlibs on Windows</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30998">Make <code>btree_set::{IntoIter, Iter, Range}</code> covariant</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30917">Avoid bounds checking at <code>slice::binary_search</code></a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30894"><code>std::sync::mpsc</code>: Add <code>fmt::Debug</code> stubs</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30882">resolve: Fix variant namespacing</a>.</li> + </ul> + <h4>New Contributors</h4> + <ul> + <li>Adrian Heine</li> + <li>Andrea Bedini</li> + <li>Guillaume Bonnet</li> + <li>Kamal Marhubi</li> + <li>Keith Yeung</li> + <li>Marc Bowes</li> + <li>Martin</li> + <li>mopp</li> + <li>Olaf Buddenhagen</li> + <li>Paul Dicker</li> + <li>Peter Kolloch</li> + <li>Stephen (Ziyun) Li</li> + </ul> + <h4>Approved RFCs</h4> + <p>Changes to Rust follow the Rust <a href="https://github.com/rust-lang/rfcs#rust-rfcs">RFC (request for comments) + process</a>. These + are the RFCs that were approved for implementation this week:</p> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/1462">Amendment to RFC 550: Add <code>[</code> to the FOLLOW(ty) in macro future-proofing rules</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1320">Amendment to RFC 1192: Amend <code>RangeInclusive</code> to use an enum</a>.</li> + </ul> + <h4>Final Comment Period</h4> + <p>Every week <a href="https://rust-lang.org/team.html">the team</a> announces the + 'final comment period' for RFCs and key PRs which are reaching a + decision. Express your opinions now. <a href="https://github.com/rust-lang/rfcs/labels/final-comment-period">This week's FCPs</a> are:</p> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/243">Trait-based exception handling</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1361">Improve Cargo target-specific dependencies</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1129">Add a <code>IndexAssign</code> trait that allows overloading "indexed assignment" expressions like <code>a[b] = c</code></a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1196">Allow eliding more type parameters</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1296">Add an <code>alias</code> attribute to <code>#[link]</code> and <code>-l</code></a>.</li> + </ul> + <h4>New RFCs</h4> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/1477">Add compiler support for generic atomic operations</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1478">Translate undefined generic intrinsics to an LLVM <code>unreachable</code> and a lint</a>.</li> + </ul> + <h3>Upcoming Events</h3> + <ul> + <li><a href="http://www.meetup.com/opentechschool-berlin/">1/27. OpenTechSchool Berlin: Rust Hack and Learn</a>.</li> + <li><a href="http://www.meetup.com/Tokyo-Rust-Meetup/events/227871840/">1/28. Tokyo Rust Meetup #2</a>.</li> + <li><a href="http://www.meetup.com/Rust-Berlin/events/227321071/">2/3. Rust Berlin: Leaf and Collenchyma</a>.</li> + <li><a href="http://www.meetup.com/de/Rust-Cologne-Bonn/events/227534456/">2/3. Rust Meetup in Cologne / Germany</a>.</li> + <li><a href="https://www.eventbrite.com/e/mozilla-rust-seattle-meetup-tickets-12222326307?aff=erelexporg">2/8. Seattle Rust Meetup</a>.</li> + <li><a href="http://www.meetup.com/de-DE/Rust-Rhein-Main/events/228170051/">2/12. Embedded Rust Workshop Frankfurt</a>.</li> + </ul> + <p>If you are running a Rust event please add it to the <a href="https://www.google.com/calendar/embed?src=apd9vmbc22egenmtu5l6c5jbfc%40group.calendar.google.com">calendar</a> to get + it mentioned here. Email <a href="mailto:erick.tryzelaar@gmail.com">Erick Tryzelaar</a> or <a href="mailto:banderson@mozilla.com">Brian + Anderson</a> for access.</p> + <h3>fn work(on: RustProject) -&gt; Money</h3> + <ul> + <li><a href="http://maidsafe.net/rust_engineer.html">Rust Engineer</a> at MaidSafe.</li> + <li><a href="https://careers.mozilla.org/en-US/position/ozy21fwU">Research Engineer - Servo</a> at Mozilla.</li> + <li><a href="https://careers.mozilla.org/en-US/position/o0H41fww">Senior Research Engineer - Rust</a> at Mozilla.</li> + <li><a href="http://plv.mpi-sws.org/rustbelt/">PhD and postdoc positions</a> at MPI-SWS.</li> + </ul> + <p><em>Tweet us at <a href="https://twitter.com/ThisWeekInRust">@ThisWeekInRust</a> to get your job offers listed here!</em></p> + <h3>Crate of the Week</h3> + <p>This week's Crate of the Week is <a href="https://github.com/phildawes/racer">racer</a> which powers code completion in all Rust development environments.</p> + <p>Thanks to <a href="https://users.rust-lang.org/users/stebalien">Steven Allen</a> for the suggestion.</p> + <p><a href="https://users.rust-lang.org/t/crate-of-the-week/2704">Submit your suggestions for next week</a>!</p> + <h3>Quote of the Week</h3> + <blockquote> + <p>Memory errors are fundamentally state errors, and Rust's move semantics, borrowing, and aliasing XOR mutating help enormously for me to reason about how my program changes state as it executes, to avoid accidental shared state and side effects at a distance. Rust more than any other language I know enables me to do compiler driven design. And internalizing its rules has helped me design better systems, even in other languages.</p> + </blockquote> + <p>— <a href="https://www.reddit.com/r/rust/comments/4275gz/rust_and_the_blub_paradox/cz8akv9">desiringmachines on /r/rust</a>.</p> + <p>Thanks to <a href="https://users.rust-lang.org/users/dikaiosune">dikaiosune</a> for the suggestion.</p> + <p><a href="http://users.rust-lang.org/t/twir-quote-of-the-week/328">Submit your quotes for next week</a>!</p> + Mon, 25 Jan 2016 05:00:00 +0000 + Corey Richardson + + + Cameron Kaiser: 38.6.0 available + tag:blogger.com,1999:blog-1015214236289077798.post-7056349209464984020 + http://tenfourfox.blogspot.com/2016/01/3860-available.html + TenFourFox 38.6.0 is available for testing (<a href="https://sourceforge.net/projects/tenfourfox/files/38.6.0/">downloads</a>, <a href="https://github.com/classilla/tenfourfox/wiki/Hashes">hashes</a>, <a href="https://github.com/classilla/tenfourfox/wiki/ZZReleaseNotes3860">release notes</a>). I'm sorry it's been so quiet around here; I'm in the middle of a backbreaking Master's course, my last one before I'm finally done with the lousy thing, and I haven't had any time to start on 45 so far. 38.6 does have some other fixes in it, though: I think I found the last place where bookmark backups were being mistakenly saved in LZ4 based on Chris Trusch's report, and the problematic fonts on the iCloud login page are now blacklisted, so you should be able to login again. I can't do much more testing than that, however, since I don't use iCloud personally, so other lapses in font functionality will require the font URL and I'll add them to the blacklist in 38.7. The browser will go live Monday Pacific time as usual. (The temporary workaround is to set <tt>gfx.downloadable_fonts.enabled</tt> to <tt>false</tt>, and switch the setting back when you don't need it anymore.) <p>Speaking of, downloadable fonts were exactly the same problem on the Sun Ultra-3 laptop I've been refurbishing; Oracle still provides a free Solaris 10 build of 38ESR, but it crashes on web fonts for reasons I have yet to diagnose, so I just have them turned off. Yes, it really is a SPARC laptop, a rebranded Tadpole Viper, and I think the fastest one ever made in this form factor (a 1.2GHz UltraSPARC IIIi). It's pretty much what I expected the PowerBook G5 would have been -- hot, overthrottled and power-hungry -- but Tadpole actually built the thing and it's not a disaster, relatively speaking. There's no JIT in this Firefox build, the brand new battery gets only 70 minutes of runtime even with the CPU clock-skewed to hell, it stands a very good chance of rendering me sterile and/or medium rare if I actually use it in my lap and it had at least one sudden overtemp shutdown and pooped all over the filesystem, but between Firefox, Star Office and <tt>pkgsrc</tt> I can actually use it. More on that for laughs in a future post. </p><p>It has been pointed out to me that Leopard Webkit has not made an update in over three months, so hopefully Tobias is still doing okay with his port.</p> + Sat, 23 Jan 2016 06:02:00 +0000 + noreply@blogger.com (ClassicHasClass) + + + Mozilla Privacy Blog: Addressing the Chilling Effect of Patent Damages + https://blog.mozilla.org/netpolicy/?p=907 + https://blog.mozilla.org/netpolicy/2016/01/22/addressing-the-chilling-effect-of-patent-damages/ + <p>Last year, we unveiled the <a href="https://www.mozilla.org/about/patents/license/">Mozilla Open Software Patent License</a> as part of our <a href="https://www.mozilla.org/about/patents/">Initiative</a> to help limit the negative impacts that patents have on open source software. While those were an important first step for us, we continue to do more. This past Wednesday, Mozilla joined several other tech and software companies in filing an <a href="https://blog.mozilla.org/netpolicy/files/2016/01/Halo-Stryker-Internet-Companies-brief.pdf">amicus brief</a> with the Supreme Court of the United States in the <i>Halo</i> and <i>Stryker</i> cases.</p> + <p>In the brief, we urge the Court to limit the availability of treble damages. Treble damages are significant because they greatly increase the amount of money owed if a defendant is found to “willfully infringe” a patent. As a result, many open source projects and technology companies will refuse to look into or engage in discussions about patents, in order to avoid even a remote possibility of willful infringement. This makes it very hard to address the chilling effects that patents can have on open source software development, open innovation, and collaborative efforts.</p> + <p>We hope that our brief will help the Court see how this legal standard has affected technology companies and persuade the Court to limit treble damages.</p> + Sat, 23 Jan 2016 00:17:34 +0000 + Elvin Lee + + + Mozilla Addons Blog: Add-on Signing Update + http://blog.mozilla.org/addons/?p=7640 + https://blog.mozilla.org/addons/2016/01/22/add-on-signing-update/ + <p>In Firefox 43, we made it a default requirement for add-ons to be signed. This requirement can be disabled by <a href="https://wiki.mozilla.org/Addons/Extension_Signing#FAQ">toggling a preference</a> that was originally scheduled to be removed in Firefox 44 for release and beta versions (this preference will continue to be available in the Nightly, Developer, and ESR Editions of Firefox for the foreseeable future). </p> + <p>We are delaying the removal of this preference to Firefox 46 for a couple of reasons: We’re adding a feature in Firefox 45 that allows <a href="https://blog.mozilla.org/addons/2015/12/23/loading-temporary-add-ons/">temporarily loading unsigned restartless add-ons</a> in release, which will allow developers of those add-ons to use Firefox for testing, and we’d like this option to be available when we remove the preference. We also want to ensure that developers have adequate time to finish the transition to signed add-ons. </p> + <p>The <a href="https://wiki.mozilla.org/Addons/Extension_Signing#Timeline">updated timeline</a> is available on the signing wiki, and you can look up <a href="https://wiki.mozilla.org/RapidRelease/Calendar">release dates for Firefox versions</a> on the releases wiki. Signing will be mandatory in the beta and release versions of Firefox from 46 onwards, at which point unbranded builds based on beta and release will be provided for testing.</p> + Fri, 22 Jan 2016 22:40:59 +0000 + Kev Needham + + + Chris Cooper: RelEng & RelOps Weekly Highlights - January 22, 2016 + http://coopcoopbware.tumblr.com/post/137832199980 + http://coopcoopbware.tumblr.com/post/137832199980 + <p></p><figure class="alignright"><a href="https://www.flickr.com/photos/proud2bcan8dn/1150097247/in/faves-19934681@N00/" target="_blank" title="wine-and-pies"><img alt="wine-and-pies" src="https://farm2.staticflickr.com/1216/1150097247_2f11cb4c2d_z.jpg?zz=1" width="200px" /></a>Releng: drinkin’ wine and makin’ pies.</figure>It’s encouraging to see more progress this week on both the build/release promotion and TaskCluster migration fronts, our two major efforts for this quarter.<p></p> + + <p><b>Modernize infrastructure:</b></p> + <p>In a continuing effort to enable faster, more reliable, and more easily-run tests for TaskCluster components, Dustin landed support for an in-memory, credential-free mock of Azure Table Storage in the <a href="https://www.npmjs.com/package/azure-entities" target="_blank">azure-entities</a> package. Together with the fake mock support he added to <a href="https://github.com/djmitche/taskcluster-lib-testing" target="_blank">taskcluster-lib-testing</a>, this allows tests for components like taskcluster-hooks to run without network access and without the need for any credentials, substantially decreasing the barrier to external contributions.</p> + + <p>All release promotion tasks are now signed by default. Thanks to Rail for his work here to help improve verifiability and chain-of-custody in our upcoming release process. (<a href="https://bugzil.la/1239682" target="_blank">https://bugzil.la/1239682</a>) + Beetmover has been spotted in the wild! Jordan has been working on this new tool as part of our release promotion project. Beetmover helps move build artifacts from one place to another (generally between S3 buckets these days), but can also be extended to perform validation actions inline, e.g. checksums and anti-virus. (<a href="https://bugzil.la/1225899" target="_blank">https://bugzil.la/1225899</a>)</p> + + <p>Dustin configured the “desktop-test” and “desktop-build” docker images to build automatically on push. That means that you can modify the Dockerfile under `testing/docker`, push to try, and have the try job run in the resulting image, all without pushing any images. This should enable much quicker iteration on tweaks to the docker images. Note, however, that updates to the base OS images (ubuntu1204-build and centos6-build) still require manual pushes.</p> + + <p>Mark landed Puppet code for base windows 10 support including secrets and ssh keys management.</p> + + <p><b>Improve CI pipeline:</b></p> + + <p>Vlad and Amy repurposed 10 Windows XP machines as Windows 7 to improve the wait times in that test pool (<a href="https://bugzil.la/1239785" target="_blank">https://bugzil.la/1239785</a>) + Armen and Joel have been working on porting the Gecko tests to run under TaskCluster, and have narrowed the failures down to the single digits. This puts us on-track to enable Linux debug builds and tests in TaskCluster as the canonical build/test process.</p> + + <p><b>Release:</b></p> + + <p>Ben finished up work on enhanced Release Blob validation in Balrog (<a href="https://bugzil.la/703040" target="_blank">https://bugzil.la/703040</a>), which makes it much more difficult to enter bad data into our update server.</p> + + <p>You may recall Mihai, our former intern who <a href="http://coopcoopbware.tumblr.com/post/133490693210/welcome-back-mihai" target="_blank">we just hired back in November</a>. Shortly after joining the team, he jumped into the <a href="https://wiki.mozilla.org/ReleaseEngineering/Releaseduty" target="_blank">releaseduty</a> rotation to provide much-needed extra bandwidth. The learning curve here is steep, but over the course of the Firefox 44 release cycle, he’s taken on more and more responsibility. He’s even volunteered to do releaseduty for the Firefox 45 release cycle as well. Perhaps the most impressive thing is that he’s also taken the time to update (or write) the releaseduty docs so that the next person who joins the rotation will be that much further ahead of the game. Thanks for your hard work here, Mihai!</p> + + <p><b>Operational:</b></p> + + <p>Hal did some cleanup work to remove unused mozharness configs and directories from the build mercurial repos. These resources have long-since moved into the main mozilla-central tree. Hopefully this will make it easier for contributors to find the canonical copy! (<a href="https://bugzil.la/1239003" target="_blank">https://bugzil.la/1239003</a>)</p> + + <p><b>Hiring:</b></p> + + <p>We’re still hiring for a full-time <a href="https://careers.mozilla.org/position/oi8b2fwn" target="_blank">Build &amp; Release Engineer</a>, and we are still accepting applications for <a href="https://careers.mozilla.org/position/ofA51fwF" target="_blank">interns for 2016</a>. Come join us!</p> + + <p>Well, I don’t know about you, but all that hard work makes me hungry for pie. See you next week!</p> + Fri, 22 Jan 2016 20:49:38 +0000 + + + Air Mozilla: Foundation Demos January 22 2016 + https://air.mozilla.org/foundation-demos-january-22-2016/ + https://air.mozilla.org/foundation-demos-january-22-2016/ + <p> + <img alt="Foundation Demos January 22 2016" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/1c/a0/1ca0b9b2609cdd4e6e3577a8c3df8cfc.jpg" width="160" /> + Mozilla Foundation Demos January 22 2016 + </p> + Fri, 22 Jan 2016 18:00:00 +0000 + Air Mozilla + + + Support.Mozilla.Org: What’s up with SUMO – 22nd January + http://blog.mozilla.org/sumo/?p=3667 + https://blog.mozilla.org/sumo/2016/01/22/whats-up-with-sumo-22nd-january/ + <p><strong>Hello, SUMO Nation!</strong></p> + <p><a href="http://blog.mozilla.org/sumo/files/2016/01/sumo_logo.png"><img alt="sumo_logo" class="aligncenter size-full wp-image-3670" height="387" src="http://blog.mozilla.org/sumo/files/2016/01/sumo_logo.png" width="383" /></a>The third week of the new year is already behind us. Time flies when you’re not paying attention… What are you going to do this weekend? Let us know in the comments, if you feel like sharing :-) I hope to be in the mountains, getting some fresh (bracing) air, and enjoying nature.</p> + <h3><strong class="username">Welcome, new contributors!<br /> + </strong></h3> + <ul> + <li class="author"> + <div class="author"><a class="username" href="https://support.mozilla.org/user/johnmwc2" target="_blank">johnmwc2</a></div> + </li> + <li class="author"><a class="author-name" href="https://support.mozilla.org/user/myanesp" target="_blank">myanesp</a></li> + <li class="author"><a class="author-name" href="https://support.mozilla.org/user/Harish.A" target="_blank">Harish.A</a></li> + <li class="author"><a class="author-name" href="https://support.mozilla.org/user/hoolibob" target="_blank">hoolibob</a></li> + <li class="author"><a class="author-name" href="https://support.mozilla.org/user/Meteoro890" target="_blank">Meteoro890</a></li> + </ul> + <div class="author">If you just joined us, don’t hesitate – come over and <a href="https://support.mozilla.org/forums/buddies" target="_blank">say “hi” in the forums!</a></div> + <div class="author"></div> + <div class="author"> + <h3><strong>Contributors of the week<br /> + </strong></h3> + <ul> + <li><span class="author-a-z74z1rz89z69z76zbz72zz69zz67z9z82zniz71z"><a href="https://support.mozilla.org/user/safwan.rahman" target="_blank">Safwan</a> for his work on the <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=619284" target="_blank">draft feature for l10n / KB editing</a> – rock on!</span></li> + <li><a href="https://support.mozilla.org/user/artist" target="_blank">Artist</a> and <a href="https://support.mozilla.org/user/pollti" target="_blank">Pollti</a> for their the work on updating important articles for Focus with limited time – woot!</li> + </ul> + <div class="" id="magicdomid64"> + <p><strong><span style="text-decoration: underline;">We salute you!</span></strong></p> + </div> + <div class="author">Don’t forget that if you are new to SUMO and someone helped you get started in a nice way you can <a href="https://support.mozilla.org/forums/buddies/711364?last=65670" target="_blank">nominate them for the Buddy of the Month!</a></div> + <div class="author"></div> + </div> + <h3><strong>Most recent SUMO Community meeting</strong></h3> + <ul> + <li><a href="https://public.etherpad-mozilla.org/p/sumo-2016-01-18" target="_blank">You can read the notes here</a> (most of the staff members were AFK due to MLK Day in the US) and see the video on our <a href="https://www.youtube.com/channel/UCaiposaIhA7HfMqH2NIciyA/videos" target="_blank">YouTube channel</a> and <a href="https://air.mozilla.org/search/?q=sumo" target="_blank">at AirMozilla</a>.<del> </del><del><br /> + </del></li> + <li><strong>IMPORTANT: We are considering changing the way the meetings work. Help us figure out what’s best for you – join the discussion on the forums in this thread: <a href="https://support.mozilla.org/en-US/forums/contributors/711752?last=67873">(Monday) Community Meetings in 2016</a>.</strong></li> + </ul> + <h3><strong>The next SUMO Community meeting… </strong></h3> + <ul> + <li style="text-align: left;">is happening on <a href="https://public.etherpad-mozilla.org/p/sumo-2016-01-25" target="_blank">Monday the 25th – join us</a>!</li> + <li style="text-align: left;"><strong>Reminder: if you want to add a discussion topic to the upcoming meeting agenda:</strong> + <ul> + <li style="text-align: left;">Start a thread in the <a href="https://support.mozilla.org/forums/contributors" target="_blank">Community Forums</a>, so that everyone in the community can see what will be discussed and voice their opinion here before Monday (this will make it easier to have an efficient meeting).</li> + <li style="text-align: left;">Please do so as soon as you can before the meeting, so that people have time to read, think, and reply (and also add it to the agenda).</li> + <li style="text-align: left;">If you can, please attend the meeting in person (or via IRC), so we can follow up on your discussion topic during the meeting with your feedback.</li> + </ul> + </li> + </ul> + <h3><strong class="author-g-ivsra51ph44x461i">Developers</strong></h3> + <ul> + <li><a href="http://edwin.mozilla.io/t/sumo" target="_blank">You can see the current state of the backlog our developers are working on here</a>.</li> + <li><a href="https://public.etherpad-mozilla.org/p/sumo-p-2016-01-21" target="_blank">The latest SUMO Platform meeting notes can be found here</a>.</li> + <li>Interested in learning how Kitsune (the engine behind SUMO) works? <a href="http://kitsune.readthedocs.org/" target="_blank">Read more about it here</a> and <a href="https://github.com/mozilla/kitsune/" target="_blank">fork it on GitHub</a>!</li> + <li>We have a new link for promoting contributions to Kitsune’s code. Please use <strong>http://mzl.la/SUMOdev</strong> whenever you want to show interested people to see what Kitsune is all about – thanks!</li> + </ul> + <p><a href="http://blog.mozilla.org/sumo/files/2016/01/mission_developers.png"><img alt="mission_developers" class="aligncenter size-full wp-image-3668" height="406" src="http://blog.mozilla.org/sumo/files/2016/01/mission_developers.png" width="437" /></a></p> + <h3><strong>Social</strong></h3> + <ul> + <li>Next week, there will be a kick-off meeting for the rethinking of Mozilla’s general support strategy through social networks. <a href="https://support.mozilla.org/user/Madasan" target="_blank">Are you interested in taking part? Let Madalina know!</a></li> + </ul> + <h3><strong>Community</strong></h3> + <ul> + <li>The NDA process and list is currently being reworked under the leadership of the Participation Team. Expect to see messaging on this subject in the coming days.</li> + <li> + <div class="title"><strong><a href="https://support.mozilla.org/forums/contributors/711729?last=67763">IMPORTANT: take a look at our Work Week Summary for Mozlando. We need your feedback for a few things there.</a></strong></div> + </li> + <li>Are you going to FOSDEM next week? Would you like to have a small SUMO-meetup? <a href="https://support.mozilla.org/user/vesper" target="_blank">Let me know</a>!</li> + <li> + <div class="title">Ongoing reminder: if you think you can benefit from getting <a href="https://wiki.mozilla.org/Community_Hardware" target="_blank">a second-hand device</a> to help you with contributing to SUMO, you know where to find us.</div> + </li> + </ul> + <p><a href="http://blog.mozilla.org/sumo/files/2016/01/hero_support.png"><img alt="hero_support" class="aligncenter size-full wp-image-3669" height="383" src="http://blog.mozilla.org/sumo/files/2016/01/hero_support.png" width="367" /></a></p> + <div class=""> + <div class="" id="magicdomid83"> + <h3><strong class="author-g-ivsra51ph44x461i">Localization</strong></h3> + </div> + </div> + <div class="" id="magicdomid95"> + <ul> + <li>You can <a href="https://support.mozilla.org/forums/l10n-forum/711781" target="_blank">read more about the recent “infrequent contributor survey” in this thread</a>. In short: the good news is that we’re doing a good job at making it easy enough for everyone to contribute. The bad news – we’re not doing enough to make sure they know what to do after their first contribution. Expect some changes in the messaging for first-time contributors to the KB :-)</li> + <li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1012384" target="_blank">Our magical l10n dashboards keep being magical</a> ;-) Thank you for your patience. If you see any discrepancies between the number of localized articles and the percentage shown in the bar, file a bug!</li> + </ul> + </div> + <div class="" id="magicdomid75"> + <h3><strong>Firefox<br /> + </strong></h3> + <ul> + <li><strong>for Android</strong> + <ul> + <li><a href="https://support.mozilla.org/forums/contributors/711712?last=67653">Learn more about Firefox 43 for Android from the official thread with release notes / issues / discussions</a>.</li> + <li> + <div class="title"><a href="https://support.mozilla.org/forums/contributors/711718?last=67822">Reminder: Roland is sharing Firefox 44 for Android release notes / issues / discussions</a> with everyone in the forum.</div> + </li> + </ul> + </li> + </ul> + <ul> + <li><strong>for Desktop</strong> + <ul> + <li>Heads up – next week should be release week! Keep your eyes peeled ;-)</li> + </ul> + </li> + </ul> + <ul> + <li><strong>for iOS</strong> + <div class="" id="magicdomid85"> + <ul class="list-bullet1"> + <li><span class="author-a-107uz69zz81zhz78z0z78zz84zz66zz76zz82zz77zj">No news from the world of Firefox for iOS this week.</span></li> + </ul> + </div> + </li> + </ul> + </div> + <p>Thank you for reading all the way down here… More to come next week! You know where to find us, so see you around – keep rocking the open &amp; helpful web!</p> + Fri, 22 Jan 2016 17:43:56 +0000 + Michał + + + Air Mozilla: Bay Area Rust Meetup January 2016 + https://air.mozilla.org/bay-area-rust-meetup-january-2016/ + https://air.mozilla.org/bay-area-rust-meetup-january-2016/ + <p> + <img alt="Bay Area Rust Meetup January 2016" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/87/4f/874f4abef76f55213d50e43d6417ed99.png" width="160" /> + Bay Area Rust meetup for January 2016. Topics TBD. + </p> + Fri, 22 Jan 2016 03:00:00 +0000 + Air Mozilla + + + Mitchell Baker: Honored to Participate in New UN Panel on Women’s Economic Empowerment + https://blog.lizardwrangler.com/?p=3953 + http://blog.lizardwrangler.com/2016/01/22/honored-to-participate-in-new-un-panel-on-womens-economic-empowerment/ + Women’s economic empowerment is necessary for many reasons. It is necessary to bring health, safety and opportunity to half of humanity. It is necessary to bring investment and health to families and communities. It is necessary to unlock economic growth and build more stable societies. Today the UN Secretary General Ban Ki-moon launched the first […] + Fri, 22 Jan 2016 02:45:58 +0000 + Mitchell Baker + + + Mozilla WebDev Community: Beer and Tell – January 2016 + https://blog.mozilla.org/webdev/?p=4082 + https://blog.mozilla.org/webdev/2016/01/21/beer-and-tell-january-2016/ + <p>Once a month, web developers from across the Mozilla Project get together to talk about our side projects and drink, an occurrence we like to call “Beer and Tell”.</p> + <p>There’s a <a href="https://wiki.mozilla.org/Webdev/Beer_And_Tell/January_2016">wiki page available</a> with a list of the presenters, as well as links to their presentation materials. There’s also a <a href="https://air.mozilla.org/webdev-beer-and-tell-january-2016/">recording available</a> courtesy of Air Mozilla.</p> + <h3>shobson: CSS-Only Disco Ball</h3> + <p>First up was <a href="https://mozillians.org/en-US/u/stephaniehobson/">shobson</a> with a cool demo of an <a href="http://codepen.io/stephaniehobson/pen/ZGZBVW?editors=110">animated disco ball made entirely with CSS</a>. The demo uses a repeated radial gradient for the background, and linear gradients plus a border radius for the disco ball itself. The demo was made for use in shobson’s <a href="https://www.youtube.com/watch?v=7poVasAQjos">WordCamp talk</a> about debugging CSS. A <a href="http://stephaniehobson.ca/wordpress/2015/08/15/how-to-debug-css/">blog post</a> with notes from the talk is available as well.</p> + <h3>craigcook: Proton – A CSS Framework for Prototyping</h3> + <p>Next was <a href="https://mozillians.org/en-US/u/craigcook/">craigcook</a>, who presented <a href="http://craigcook.github.io/proton/">Proton</a>. It’s a CSS framework that is intentionally ugly to encourage use for prototypes only. Unlike other CSS frameworks, the temptation to reuse the classes from the framework in your final page doesn’t occur, which helps avoid the presentational classes that plague sites built using a framework normally.</p> + <p>Proton’s website includes an overview of the layout and components provided, as well as examples of prototypes made using the framework.</p> + <hr /> + <p>If you’re interested in attending the next Beer and Tell, sign up for the <a href="https://lists.mozilla.org/listinfo/dev-webdev">dev-webdev@lists.mozilla.org mailing list</a>. An email is sent out a week beforehand with connection details. You could even add yourself to the wiki and show off your side-project!</p> + <p>See you next month!</p> + Thu, 21 Jan 2016 18:56:46 +0000 + Michael Kelly + + + About:Community: This Month at Mozilla + http://blog.mozilla.org/community/?p=2287 + http://blog.mozilla.org/community/2016/01/21/this-month-at-mozilla/ + <p style="text-align: center;"><em>A lot of exciting things are happening with Participation at Mozilla this month. Here’s a quick round-up of some of the things that are going on!</em></p> + <h3><b>Mozillians Profiles Got a Facelift: </b></h3> + <p>Since the start of this year, the Participation Infrastructure team has had a renewed focus on making mozillians.org a modern community directory to meet Mozilla’s growing needs.</p> + <p>Their first target for 2016 was to improve the UX on the profile edit interface.</p> + <p><a href="https://blog.mozilla.org/community/files/2016/01/new-profile-768x548.png"><img alt="new-profile-768x548" class="aligncenter wp-image-2288 size-large" height="428" src="https://blog.mozilla.org/community/files/2016/01/new-profile-768x548-600x428.png" width="600" /></a><br /> + ”We chose it due to relatively self-contained nature of it, and cause many people were not happy with the current UX. After research of existing tools and applying latest best practices, we designed, coded and deployed a new profile edit interface (which by the way is renamed to Settings now) that we are happy to deliver to all Mozillians.”</p> + <p>Read the full blog <a href="http://pierros.papadeas.gr/?p=447">here</a>!</p> + <h3><b>There are New Ways to Bring Your Design Skills to Mozilla: </b></h3> + <p>Are you a passionate designer looking to contribute to Mozilla? You’ll be happy to hear there is a new way to contribute to the many design projects around Mozilla! Submit issues, find collaborators, and work on open source projects by getting involved!</p> + <ul> + <li>You can check out the projects looking for help, or submit your own on the <a href="https://github.com/mozilla/Community-Design/issues">GitHub Repo</a>.</li> + <li><a href="https://docs.google.com/a/mozilla.com/forms/d/1Tw3Mw_CMiqcIQrJF7TB1yIETGYec__NiVhaSz0CAaE8/viewform">Sign-up to the mailing list</a> to be added as a contributor to the Repo, added to the regular meeting list, and to get emails about GitHub trainings and more!</li> + <li>And read<a href="http://elioqoshi.me/en/2016/01/mozilla-community-design-kickoff/"> a blogpost</a> about the project and its first meeting.</li> + </ul> + <p>Learn more <a href="https://discourse.mozilla-community.org/c/community-design">here</a>.</p> + <h3><b>136 Volunteers Are Going to Singapore: </b></h3> + <p>This weekend 136 participation leaders from all over the world are<a href="https://twitter.com/thephoenixbird/status/690181985222926336"> heading to Singapore</a> to undergo two days of<a href="https://wiki.mozilla.org/Participation/Global_Gatherings_2015"> leadership training</a> to develop the skills, knowledge and attitude to lead Participation in 2016.</p> + <div class="wp-caption aligncenter" id="attachment_2289" style="width: 609px;"><a href="https://blog.mozilla.org/community/files/2016/01/CZQE241WIAA6R2J.jpg"><img alt="Photo credit @thephoenixbird on Twitter" class="wp-image-2289 size-full" height="337" src="https://blog.mozilla.org/community/files/2016/01/CZQE241WIAA6R2J.jpg" width="599" /></a><p class="wp-caption-text">Photo credit @<a href="https://twitter.com/thephoenixbird/status/690181985222926336" target="_blank">thephoenixbird</a> on Twitter</p></div> + <p>If you know someone attending don’t forget to share your questions and goals with them, and follow along over the weekend by watching the hashtag<a href="https://twitter.com/search?q=%23mozsummit"> #MozSummit</a>.</p> + <p>Stay tuned after the event for a debrief of the weekend!</p> + <h3><b>Friday’s Plenary from Mozlando is now public on Air Mozilla: </b></h3> + <p>If you’re interested in learning more about all the exciting new features, projects, and plans that were presented at Mozlando look no further! You can now watch the final plenary sessions on Air Mozilla (it’s a lot of fun so I highly recommend it!) <a href="https://air.mozilla.org/channels/mozlando/">here</a>.</p> + <p>Share your questions and comments on discourse <a href="https://discourse.mozilla-community.org/t/friday-plenary-from-mozlando-now-public-on-air-mozilla/6659">here</a>.</p> + <p><em>Look forward to more updates like these in the coming months!</em></p> + Thu, 21 Jan 2016 17:58:33 +0000 + Lucy Harris + + + Mozilla Privacy Blog: Prioritizing privacy: Good for business + https://blog.mozilla.org/netpolicy/?p=912 + https://blog.mozilla.org/netpolicy/2016/01/21/prioritizing-privacy-good-for-business/ + <p><em>This was originally posted at <a href="http://staysafeonline.org/blog/prioritizing-privacy-good-for-business/">StaySafeOnline.org</a> in advance of <a href="http://www.staysafeonline.org/data-privacy-day/events/">Data Privacy Day</a>.</em></p> + <p>Data Privacy Day – which arrives in just a week – is a day designed to raise awareness and promote best practices for privacy and data protection. It is a day that looks to the future and recognizes that we can and should do better as an industry. It reminds us that we need to focus on the importance of having the trust of our users.</p> + <p>We seek to build trust so we can collectively create the Web our users want – the Web we all want.</p> + <p>That Web is based on relationships, the same way that the offline world is. When I log in to a social media account, schedule a grocery delivery online or browse the news, I’m relying on those services to respect my data. While companies are innovating their products and services, they need to be innovating on user trust as well, which means designing to address privacy concerns – and making smart choices (early!) about how to manage data.</p> + <p>A <a href="http://www.pewinternet.org/2016/01/14/privacy-and-information-sharing/">recent survey by Pew</a> highlights the thought that each user puts into their choices – and the contextual considerations in various scenarios. They concluded that many participants were annoyed and uncertain by how their information was used, and they are choosing not to interact with those services that they don’t trust. This is a clear call to businesses to foster more trust with their users, which starts by making sure that there are people empowered within your company to ask the right questions: what do your users expect? What data do you need to collect? How can you communicate about that data collection? How should you protect their data? Is holding on to data a risk, or should you delete it?</p> + <p>It’s crucial that users are a part of this process – consumers’ data is needed to offer cool, new experiences and a user needs to trust you in order to choose to give you their data. Pro-user innovation can’t happen in a vacuum – the system as it stands today isn’t doing a good job of aligning user interests with business incentives. Good user decisions can be good business decisions, but only if we create thoughtful user-centric products in a way that closes the feedback loop so that positive user experiences are rewarded with better business outcomes.</p> + <p>Not prioritizing privacy in product decisions will impact the bottom line. From the many data breaches over the last few years to increasing evidence of eroding trust in online services, data practices are proving to be the dark horse in the online economy. When a company loses user trust, whether on privacy or <a href="https://medium.com/@davidamerland/the-cost-of-losing-trust-97d764a1e696">anything else</a>, it loses customers and the potential for growth.</p> + <p>Privacy means different things to different people but what’s clear is that people make decisions about the products and services that they use based on how those companies choose to treat their users. Over this time, the Internet ecosystem has evolved, as has its relationship with users – and some aspects of this evolution threaten the trust that lies at the heart of that relationship. Treating a user as a target – whether for an ad, purchase, or service – undermines the trust and relationship that a business may have with a consumer.</p> + <p>The solution is not to abandon the massive value that robust data can bring to users, but rather, to collect and use data leanly, productively and transparently. At Mozilla, we have created a strong set of internal data practices to ensure that data decisions align with our <a href="https://www.mozilla.org/en-US/privacy/principles/">privacy principles</a>. As an industry, we need to keep users at the center of the product vision rather than viewing them as targets of the product – it’s the only way to stay true to consumers and deliver the best, most trusted experiences possible.</p> + <p>Want to hear more about how businesses can build relationships with their users by focusing on trust and privacy? We’re holding events in Washington, D.C., and <a href="https://www.eventbrite.com/e/january-privacy-lab-privacy-for-startups-tickets-19849219550?aff=es2">San Francisco</a> with some of our partners to talk about it. Please join us!</p> + Thu, 21 Jan 2016 17:42:00 +0000 + Heather West + + + J.C. Jones: Issuance Rate for Let's Encrypt + https://tacticalsecret.com/tag/mozilla/rss/9c39ad13-14ae-4456-a84e-13612637d832 + https://tacticalsecret.com/issuance-rate-for-lets-encrypt/ + <p>Gathering data from <a href="https://github.com/jcjones/letsencrypt_statistics">Certificate Transparency logs</a>, here's a snapshot in time of Let's Encrypt's certificate issuance rate per minute from 7-21 January 2016. On 20 January, DreamHost launched formal support for Let's Encrypt, which coincides with a rate increase.</p> + + <p>Note: This is mostly an experimental post with embedding charts; I've more data in the queue.</p> + + <h3>Let's Encrypt Issuance Rate per Minute</h3> + + <div id="rate_hours"></div> + Thu, 21 Jan 2016 17:07:25 +0000 + James 'J.C.' Jones + + + Air Mozilla: Web QA Weekly Meeting, 21 Jan 2016 + https://air.mozilla.org/web-qa-weekly-meeting-20160121/ + https://air.mozilla.org/web-qa-weekly-meeting-20160121/ + <p> + <img alt="Web QA Weekly Meeting" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/f5/13/f5137857516694df0458e837c2d3a4be.png" width="160" /> + This is our weekly gathering of Mozilla'a Web QA team filled with discussion on our current and future projects, ideas, demos, and fun facts. + </p> + Thu, 21 Jan 2016 17:00:00 +0000 + Air Mozilla + + + Soledad Penades: No more tap tap tap sounds: yay! + http://soledadpenades.com/?p=6379 + http://soledadpenades.com/2016/01/21/no-more-tap-tap-tap-sounds-yay/ + <p>A few days ago the fantastic Fritz from the Netherlands told me that my <a href="http://soledadpenades.com/files/t/2015_howa/">Hands On Web Audio slides</a> had stopping working and there was no sound coming out from them in Firefox.</p> + <blockquote class="twitter-tweet" width="550"><p dir="ltr" lang="en"><a href="https://twitter.com/supersole">@supersole</a> oh noes! I reopened your slides: <a href="https://t.co/SO35UfljMI">https://t.co/SO35UfljMI</a> and it doesn't work in <a href="https://twitter.com/firefox">@firefox</a> anymore <img alt="😱" class="wp-smiley" src="http://s.w.org/images/core/emoji/72x72/1f631.png" style="height: 1em;" /> (works in chrome though.. <img alt="😢" class="wp-smiley" src="http://s.w.org/images/core/emoji/72x72/1f622.png" style="height: 1em;" />)</p> + <p>— Boring Stranger (@fritzvd) <a href="https://twitter.com/fritzvd/status/686481500611735552">January 11, 2016</a></p></blockquote> + <p></p> + <p>Which is pretty disappointing for a slide deck that is built to teach you about Web Audio!</p> + <p>I noticed that the issue was only on the introductory slide which uses a modified version of Stuart Memo’s <a href="https://blog.stuartmemo.com/thx-deep-note-in-javascript/">fantastic THX sound recreation</a>-the rest of slides did play sound.</p> + <p>I built <a href="http://sole.github.io/test_cases/web_audio/thx_cutting_out/">an isolated test case</a> <small><a href="https://github.com/sole/test_cases/tree/gh-pages/web_audio/thx_cutting_out">(source)</a></small> that used a parameter-capable version of the THX sound code, just in case the issue depended on the number of oscillators, and submitted this funnily titled bug to the Web Audio component: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1240054">Entirely Web Audio generated sound cuts out after a little while, or emits random tap tap tap sounds then silence</a>.</p> + <p>I can happily confirm that the bug has been fixed in Nightly and the fix will hopefully be “uplifted” to DevEdition very soon, as it was due to a regression.</p> + <p><a href="https://paul.cx/">Paul Adenot</a> (who works in Web Audio and is a Web Audio spec editor, amongst a couple tons of other cool things) was really excited about the bug, saying it was very edge-casey! Yay! And he also explained what did actually happen in lay terms: “you’d have to have a frequency that goes down very very slowly so that the FFT code could not keep up”, which is what the THX sound is doing with the filter frequency automation.</p> + <p>I want to thank both Fritz for spotting this out and letting me know and also Stuart for sharing his THX code. It’s amazing what happens when you put stuff on the net and lots of different people use it in different ways and configurations. Together we make everything more robust <img alt=":-)" class="wp-smiley" src="http://soledadpenades.com/wp-includes/images/smilies/simple-smile.png" style="height: 1em;" /></p> + <p>Of course also sending thanks to Paul and Ben for identifying and fixing the issue so fast! It’s not been even a week! Woohoo!</p> + <p>Well done everyone! <img alt="👏" class="wp-smiley" src="http://s.w.org/images/core/emoji/72x72/1f44f.png" style="height: 1em;" /><img alt="🏼" class="wp-smiley" src="http://s.w.org/images/core/emoji/72x72/1f3fc.png" style="height: 1em;" /></p> + <p><a href="http://soledadpenades.com/?flattrss_redirect&amp;id=6379&amp;md5=57babe624711830f95e4b8fbd6e52c91" target="_blank" title="Flattr"><img alt="flattr this!" src="http://soledadpenades.com/wp-content/plugins/flattr/img/flattr-badge-large.png" /></a></p> + Thu, 21 Jan 2016 15:49:05 +0000 + sole + + + Pierros Papadeas: Mozillians.org Profile Edit refresh + http://pierros.papadeas.gr/?p=447 + http://pierros.papadeas.gr/?p=447 + <p>Since the start of this year, Participation Infrastructure team has a renewed focus on making mozillians.org a modern community directory to meet Mozilla’s growing needs. This will not be an one-time effort. We need to invest technically and programmatically in order to deliver a first-class product that will be the foundation for identity management across the Mozilla ecosystem.</p> + <p>Mozillians.org is full of functionality as it is today, but is paying the debt of being developed by 5 different teams over the past 5 years. We started simple this time. Updated all core technology pieces, did privacy and security reviews, and started the process of consolidating and modernizing many of the things we do in the site.</p> + <p>Our first target was Profile Edit. We chose it due to relatively self-contained nature of it, and cause many people were not happy with the current UX. After research of existing tools and applying latest best practices, we designed, coded and deployed a new profile edit interface (which by the way is renamed to Settings now) that we are happy to deliver to all Mozillians.</p> + <p><a href="http://pierros.papadeas.gr/wp-content/uploads/2016/01/new-profile.png" rel="attachment wp-att-448"><img alt="new-profile" class="aligncenter size-large wp-image-448" height="417" src="http://pierros.papadeas.gr/wp-content/uploads/2016/01/new-profile-1024x731.png" width="584" /></a>Have a<a href="https://mozillians.org/en-US/user/edit/"> look for yourself </a>and don’t miss the chance to update your profile while you do it!</p> + <p><a href="https://mozillians.org/en-US/u/comzeradd/">Nikos</a> (on the front-end), <a href="https://mozillians.org/en-US/u/akatsoulas/">Tasos</a> and <a href="https://mozillians.org/en-US/u/jgiannelos/">Nemo</a> (on the back-end) worked hard to deliver this in a speedy manner (as they are used to), and the end result is a testament to what is coming next on Mozillians.org.</p> + <p>Our next target? Groups. Currently it is obscure and unclear what all those settings in groups are, what is the functionality and how teams within Mozilla will be using it. We will be tackling this soon. After that, search and stats will be our attention, in an ongoing effort to fortify mozillians.org functionality. Stay tuned, and as always feel free to <a href="https://bugzilla.mozilla.org/enter_bug.cgi?product=Participation%20Infrastructure&amp;component=Phonebook">file bugs</a> and <a href="https://github.com/mozilla/mozillians">contribute </a>in the process.</p> + Thu, 21 Jan 2016 11:41:39 +0000 + Pierros Papadeas + + + Adam Lofting: Blog posts I haven’t written lately + http://adamlofting.com/?p=1396 + http://feedproxy.google.com/~r/adamlofting/blog/~3/DoEWpBapwiw/ + <p>Last year I joked…</p> + <blockquote class="twitter-tweet" lang="en"> + <p dir="ltr" lang="en">Thinking about writing a blog post listing the blog posts I’ve been meaning to write… Maybe that will save some time</p> + <p>— Adam Lofting (@adamlofting) <a href="https://twitter.com/adamlofting/status/667657889817956352">November 20, 2015</a></p></blockquote> + <p></p> + <p>Now, it has come to this.</p> + <h4>9 blog posts I’ve not been writing</h4> + <ul> + <li>Working on working on the impact of impact</li> + <li>Designing Games in <a href="https://en.wikipedia.org/wiki/Amateur" target="_blank">my free time</a></li> + <li>Moving Out (the board game)</li> + <li>Mozilla Foundation 2016 KPIs</li> + <li>Studying Network Science</li> + <li>Learning Analytics plans for 2016</li> + <li>Daily practice / you are what you do every day</li> + <li>Several more A/B tests to write up from <a href="http://fundraising.mozilla.org/">the fundraising campaign</a></li> + <li>CRM Progress in 2015</li> + </ul> + <p>But my most requested blog by far, is an update on the status of my shed / office that I was tagging on to the end my blog posts at this time last year. Many people at Mozfest wanted to know about the shed… so here it is.</p> + <p>This time last year:</p> + <blockquote class="twitter-tweet" lang="en"><p> + Starting in the new office today. It will take time to make it *nice* but it works for now. <a href="http://t.co/sWoC4kFNLc">pic.twitter.com/sWoC4kFNLc</a></p> + <p>— Adam Lofting (@adamlofting) <a href="https://twitter.com/adamlofting/status/560361913339899904">January 28, 2015</a> + </p></blockquote> + <p></p> + <p>Some pictures from this morning:</p> + <p><img alt="office1" class="alignright size-large wp-image-1398" height="282" src="http://adamlofting.com/wp-content/uploads/2016/01/office1-750x320.jpg" width="660" /></p> + <p><img alt="office2" class="aligncenter size-large wp-image-1399" height="237" src="http://adamlofting.com/wp-content/uploads/2016/01/office2-750x269.jpg" width="660" /></p> + <p>It’s a pretty nice place to work now and it doubles as useful workshop on the weekends. It needs a few finishing touches, but the law of diminishing returns means those finishing touches are lower priority than work that needs to be done elsewhere in the house and garden. So it’ll stay like this a while longer.</p> + <div class="feedflare"> + <a href="http://feeds.feedburner.com/~ff/adamlofting/blog?a=DoEWpBapwiw:VxTJGXwqhlI:yIl2AUoC8zA"><img border="0" src="http://feeds.feedburner.com/~ff/adamlofting/blog?d=yIl2AUoC8zA" /></a> <a href="http://feeds.feedburner.com/~ff/adamlofting/blog?a=DoEWpBapwiw:VxTJGXwqhlI:qj6IDK7rITs"><img border="0" src="http://feeds.feedburner.com/~ff/adamlofting/blog?d=qj6IDK7rITs" /></a> + </div><img alt="" height="1" src="http://feeds.feedburner.com/~r/adamlofting/blog/~4/DoEWpBapwiw" width="1" /> + Thu, 21 Jan 2016 09:44:24 +0000 + Adam + + + Tarek Ziadé: A Pelican web editor + http://blog.ziade.org/2016/01/21/a-pelican-web-editor/ + http://blog.ziade.org/2016/01/21/a-pelican-web-editor/ + <p>The benefit of being a father again (Freya my 3rd child, was born last week) is + that while on paternity leave &amp; between two baby bottles, I can hack on fun stuff.</p> + <p>A few months ago, I've built for my running club a Pelican-based website, check it out + at : <a class="reference external" href="http://acr-dijon.org">http://acr-dijon.org</a>. Nothing's special about it, except that I am not + the one feeding it. The content is added by people from the club that have zero + knowledge about softwares, let alone stuff like vim or command line tools.</p> + <p>I set up a github-based flow for them, where they add content through the + github UI and its minimal reStructuredText preview feature - and then a few + of my crons update the website on the server I host. + For images and other media, they are uploading them via FTP using FireSSH in Firefox.</p> + <p>For the comments, I've switched from Disqus to <a class="reference external" href="https://posativ.org/isso/">ISSO</a> + after I got annoyed by the fact that it was impossible to display a simple Disqus + UI for people to comment without having to log in.</p> + <p>I had to make my club friends go through a minimal + reStructuredText syntax training, and things are more of less working now.</p> + <p>The system has a few caveats though:</p> + <ul class="simple"> + <li>it's dependent on Github. I'd rather have everything hosted on my server.</li> + <li>the github restTRucturedText preview will not display syntax errors and warnings + and very often, articles get broken</li> + <li>the resulting reST is ugly, and it's a bit hard to force my editors to be stricter + about details like empty lines, not using tabs etc.</li> + <li>adding folders or organizing articles from Github is a pain</li> + <li>editing the metadata tags is prone to many mistakes</li> + </ul> + <p>So I've decided to build my own web editing tool with the following features:</p> + <ul class="simple"> + <li>resTructuredText cleanup</li> + <li>content browsing</li> + <li>resTructuredText web editor with live preview that shows warnings &amp; errors</li> + <li>a little bit of wsgi glue and a few forms to create articles without + having to worry about metadata syntax.</li> + </ul> + <div class="section" id="restructuredtext-cleanup"> + <h3>resTructuredText cleanup</h3> + <p>The first step was to build a reStructuredText parser that would read some + reStructuredText and render it back into a cleaner version.</p> + <p>We've imported almost 2000 articles in Pelican from the old blog, so I had + a <strong>lot</strong> of samples to make my parser work well.</p> + <p>I first tried <a class="reference external" href="https://github.com/benoitbryon/rst2rst">rst2rst</a> but that + parser was built for a very specific use case (text wrapping) and was + incomplete. It was not parsing all of the reStructuredText syntax.</p> + <p>Inspired by it, I wrote my own little parser using <strong>docutils</strong>.</p> + <p>Understanding docutils is not a small task. This project is very powerfull + but quite complex. One thing that cruelly misses in docutils parser tools + is the ability to get the source text from any node, including its children, + so you can render back the same source.</p> + <p>That's roughly what I had to add in my code. It's ugly but it does the job: + it will parse rst files and render the same content, minus all the extraneous + empty lines, spaces, tabs etc.</p> + </div> + <div class="section" id="content-browsing"> + <h3>Content browsing</h3> + <p>Content browsing is pretty straightforward: my admin tool let you browse + the Pelican <em>content</em> directory and lists all articles, organized by categories.</p> + <p>In our case, each category has a top directory in <em>content</em>. The browser + parses the articles using my parser and displays paginated lists.</p> + <p>I had to add a cache system for the parser, because one of the directory + contains over 1000 articles -- and browsing was kind of slow :)</p> + <img alt="http://ziade.org/henet-browsing.png" src="http://ziade.org/henet-browsing.png" /> + </div> + <div class="section" id="restructuredtext-web-editor"> + <h3>resTructuredText web editor</h3> + <p>The last big bit was the live editor. I've stumbled on a neat little tool + called <strong>rsted</strong>, that provides a live preview of the reStructuredText + as you are typing it. And it includes warnings !</p> + <p>Check it out: <a class="reference external" href="http://rst.ninjs.org/">http://rst.ninjs.org/</a></p> + <p>I've stripped it and kept what I needed, and included it in my app.</p> + <img alt="http://ziade.org/henet.png" src="http://ziade.org/henet.png" /> + <p>I am quite happy with the result so far. I need to add real tests and + a bit of documentation, and I will start to train my club friends on it.</p> + <p>The next features I'd like to add are:</p> + <ul class="simple"> + <li>comments management, to replace Isso (working on it now)</li> + <li>smart Pelican builds. e.g. if a comment is added I don't want to rebuild the whole + blog (~1500 articles)</li> + <li>media management</li> + <li>spell checker</li> + </ul> + <p>The project lives here: <a class="reference external" href="https://github.com/AcrDijon/henet">https://github.com/AcrDijon/henet</a></p> + <p>I am not going to release it, but if someone finds it useful, I could.</p> + <p>It's built with Bottle &amp; Bootstrap as well.</p> + </div> + Thu, 21 Jan 2016 09:40:00 +0000 + Tarek Ziade + + + Nick Cameron: Closures and first-class functions + http://www.ncameron.org/blog/rss/631106eb-e7b1-47d5-82f9-cb6ad210ea89 + http://www.ncameron.org/blog/closures-and-first-class-functions/ + <p>I wrote a long and probably dull chapter on closures and first-class and higher-order functions in Rust. It goes into some detail on the implementation and some of the subtleties like higher-ranked lifetime bounds.</p> + + <p>I was going to post it here too, but it is really too long. Instead, pop over to the 'Rust for C++ programmers' repo and read it <a href="https://github.com/nrc/r4cppp/blob/master/closures.md">there</a>.</p> + Thu, 21 Jan 2016 08:36:21 +0000 + Nick Cameron + + + Nick Desaulniers: Intro to Debugging x86-64 Assembly + http://nickdesaulniers.github.io/blog/2016/01/20/debugging-x86-64-assembly-with-lldb-and-dtrace + http://nickdesaulniers.github.io/blog/2016/01/20/debugging-x86-64-assembly-with-lldb-and-dtrace/ + <p>I’m hacking on an assembly project, and wanted to document some of the tricks I + was using for figuring out what was going on. This post might seem a little + basic for folks who spend all day heads down in gdb or who do this stuff + professionally, but I just wanted to share a quick intro to some tools that + others may find useful. + (<a href="https://pchiusano.github.io/2014-10-11/defensive-writing.html">oh god, I’m doing it</a>)</p> + + <p>If your coming from gdb to lldb, there’s a few differences in commands. LLDB + has + <a href="http://lldb.llvm.org/lldb-gdb.html">great documentation</a> + on some of the differences. Everything in this post about LLDB is pretty much + there.</p> + + <p>The bread and butter commands when working with gdb or lldb are:</p> + + <ul> + <li>r (run the program)</li> + <li>s (step in)</li> + <li>n (step over)</li> + <li>finish (step out)</li> + <li>c (continue)</li> + <li>q (quit the program)</li> + </ul> + + + <p>You can hit enter if you want to run the last command again, which is really + useful if you want to keep stepping over statements repeatedly.</p> + + <p>I’ve been using LLDB on OSX. Let’s say I want to debug a program I can build, + but is crashing or something:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="nv">$ </span>sudo lldb ./asmttpd web_root + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>Setting a breakpoint on jump to label:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> b sys_write + </span><span class="line">Breakpoint 3: <span class="nv">where</span> <span class="o">=</span> asmttpd<span class="sb">`</span>sys_write, <span class="nv">address</span> <span class="o">=</span> 0x00000000000029ae + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>Running the program until breakpoint hit:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + <span class="line-number">8</span> + <span class="line-number">9</span> + <span class="line-number">10</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> r + </span><span class="line">Process 32236 launched: <span class="s1">'./asmttpd'</span> <span class="o">(</span>x86_64<span class="o">)</span> + </span><span class="line">Process 32236 stopped + </span><span class="line">* thread <span class="c">#1: tid = 0xe69b9, 0x00000000000029ae asmttpd`sys_write, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1</span> + </span><span class="line"> frame <span class="c">#0: 0x00000000000029ae asmttpd`sys_write</span> + </span><span class="line">asmttpd<span class="sb">`</span>sys_write: + </span><span class="line">-&gt; 0x29ae &lt;+0&gt;: pushq %rdi + </span><span class="line"> 0x29af &lt;+1&gt;: pushq %rsi + </span><span class="line"> 0x29b0 &lt;+2&gt;: pushq %rdx + </span><span class="line"> 0x29b1 &lt;+3&gt;: pushq %r10 + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>Seeing more of the current stack frame:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + <span class="line-number">8</span> + <span class="line-number">9</span> + <span class="line-number">10</span> + <span class="line-number">11</span> + <span class="line-number">12</span> + <span class="line-number">13</span> + <span class="line-number">14</span> + <span class="line-number">15</span> + <span class="line-number">16</span> + <span class="line-number">17</span> + <span class="line-number">18</span> + <span class="line-number">19</span> + <span class="line-number">20</span> + <span class="line-number">21</span> + <span class="line-number">22</span> + <span class="line-number">23</span> + <span class="line-number">24</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> d + </span><span class="line">asmttpd<span class="sb">`</span>sys_write: + </span><span class="line">-&gt; 0x29ae &lt;+0&gt;: pushq %rdi + </span><span class="line"> 0x29af &lt;+1&gt;: pushq %rsi + </span><span class="line"> 0x29b0 &lt;+2&gt;: pushq %rdx + </span><span class="line"> 0x29b1 &lt;+3&gt;: pushq %r10 + </span><span class="line"> 0x29b3 &lt;+5&gt;: pushq %r8 + </span><span class="line"> 0x29b5 &lt;+7&gt;: pushq %r9 + </span><span class="line"> 0x29b7 &lt;+9&gt;: pushq %rbx + </span><span class="line"> 0x29b8 &lt;+10&gt;: pushq %rcx + </span><span class="line"> 0x29b9 &lt;+11&gt;: movq %rsi, %rdx + </span><span class="line"> 0x29bc &lt;+14&gt;: movq %rdi, %rsi + </span><span class="line"> 0x29bf &lt;+17&gt;: movq <span class="nv">$0x1</span>, %rdi + </span><span class="line"> 0x29c6 &lt;+24&gt;: movq <span class="nv">$0x2000004</span>, %rax + </span><span class="line"> 0x29cd &lt;+31&gt;: syscall + </span><span class="line"> 0x29cf &lt;+33&gt;: popq %rcx + </span><span class="line"> 0x29d0 &lt;+34&gt;: popq %rbx + </span><span class="line"> 0x29d1 &lt;+35&gt;: popq %r9 + </span><span class="line"> 0x29d3 &lt;+37&gt;: popq %r8 + </span><span class="line"> 0x29 &lt;+39&gt;: popq %r10 + </span><span class="line"> 0x29d7 &lt;+41&gt;: popq %rdx + </span><span class="line"> 0x29d8 &lt;+42&gt;: popq %rsi + </span><span class="line"> 0x29d9 &lt;+43&gt;: popq %rdi + </span><span class="line"> 0x29da &lt;+44&gt;: retq + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>Getting a back trace (call stack):</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> bt + </span><span class="line">* thread <span class="c">#1: tid = 0xe69b9, 0x00000000000029ae asmttpd`sys_write, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1</span> + </span><span class="line"> * frame <span class="c">#0: 0x00000000000029ae asmttpd`sys_write</span> + </span><span class="line"> frame <span class="c">#1: 0x00000000000021b6 asmttpd`print_line + 16</span> + </span><span class="line"> frame <span class="c">#2: 0x0000000000002ab3 asmttpd`start + 35</span> + </span><span class="line"> frame <span class="c">#3: 0x00007fff9900c5ad libdyld.dylib`start + 1</span> + </span><span class="line"> frame <span class="c">#4: 0x00007fff9900c5ad libdyld.dylib`start + 1</span> + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>peeking at the upper stack frame:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> up + </span><span class="line">frame <span class="c">#1: 0x00000000000021b6 asmttpd`print_line + 16</span> + </span><span class="line">asmttpd<span class="sb">`</span>print_line: + </span><span class="line"> 0x21b6 &lt;+16&gt;: movabsq <span class="nv">$0x30cb</span>, %rdi + </span><span class="line"> 0x21c0 &lt;+26&gt;: movq <span class="nv">$0x1</span>, %rsi + </span><span class="line"> 0x21c7 &lt;+33&gt;: callq 0x29ae ; sys_write + </span><span class="line"> 0x21cc &lt;+38&gt;: popq %rcx + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>back down to the breakpoint-halted stack frame:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> down + </span><span class="line">frame <span class="c">#0: 0x00000000000029ae asmttpd`sys_write</span> + </span><span class="line">asmttpd<span class="sb">`</span>sys_write: + </span><span class="line">-&gt; 0x29ae &lt;+0&gt;: pushq %rdi + </span><span class="line"> 0x29af &lt;+1&gt;: pushq %rsi + </span><span class="line"> 0x29b0 &lt;+2&gt;: pushq %rdx + </span><span class="line"> 0x29b1 &lt;+3&gt;: pushq %r10 + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>dumping the values of registers:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + <span class="line-number">8</span> + <span class="line-number">9</span> + <span class="line-number">10</span> + <span class="line-number">11</span> + <span class="line-number">12</span> + <span class="line-number">13</span> + <span class="line-number">14</span> + <span class="line-number">15</span> + <span class="line-number">16</span> + <span class="line-number">17</span> + <span class="line-number">18</span> + <span class="line-number">19</span> + <span class="line-number">20</span> + <span class="line-number">21</span> + <span class="line-number">22</span> + <span class="line-number">23</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> register <span class="nb">read</span> + </span><span class="line">General Purpose Registers: + </span><span class="line"> <span class="nv">rax</span> <span class="o">=</span> 0x0000000000002a90 asmttpd<span class="sb">`</span>start + </span><span class="line"> <span class="nv">rbx</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">rcx</span> <span class="o">=</span> 0x00007fff5fbffaf8 + </span><span class="line"> <span class="nv">rdx</span> <span class="o">=</span> 0x00007fff5fbffa40 + </span><span class="line"> <span class="nv">rdi</span> <span class="o">=</span> 0x00000000000030cc start_text + </span><span class="line"> <span class="nv">rsi</span> <span class="o">=</span> 0x000000000000000f + </span><span class="line"> <span class="nv">rbp</span> <span class="o">=</span> 0x00007fff5fbffa18 + </span><span class="line"> <span class="nv">rsp</span> <span class="o">=</span> 0x00007fff5fbff9b8 + </span><span class="line"> <span class="nv">r8</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">r9</span> <span class="o">=</span> 0x00007fff7b1670c8 atexit_mutex + 24 + </span><span class="line"> <span class="nv">r10</span> <span class="o">=</span> 0x00000000ffffffff + </span><span class="line"> <span class="nv">r11</span> <span class="o">=</span> 0xffffffff00000000 + </span><span class="line"> <span class="nv">r12</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">r13</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">r14</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">r15</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">rip</span> <span class="o">=</span> 0x00000000000029ae asmttpd<span class="sb">`</span>sys_write + </span><span class="line"> <span class="nv">rflags</span> <span class="o">=</span> 0x0000000000000246 + </span><span class="line"> <span class="nv">cs</span> <span class="o">=</span> 0x000000000000002b + </span><span class="line"> <span class="nv">fs</span> <span class="o">=</span> 0x0000000000000000 + </span><span class="line"> <span class="nv">gs</span> <span class="o">=</span> 0x0000000000000000 + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>read just one register:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="o">(</span>lldb<span class="o">)</span> register <span class="nb">read </span>rdi + </span><span class="line"> <span class="nv">rdi</span> <span class="o">=</span> 0x00000000000030cc start_text + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>When you’re trying to figure out what system calls are made by some C code, + using dtruss is very helpful. dtruss is available on OSX and seems to be some + kind of wrapper around DTrace.</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + <span class="line-number">8</span> + <span class="line-number">9</span> + <span class="line-number">10</span> + <span class="line-number">11</span> + <span class="line-number">12</span> + <span class="line-number">13</span> + <span class="line-number">14</span> + <span class="line-number">15</span> + <span class="line-number">16</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="nv">$ </span>cat sleep.c + </span><span class="line"><span class="c">#include &lt;time.h&gt;</span> + </span><span class="line">int main <span class="o">()</span> <span class="o">{</span> + </span><span class="line"> struct timespec <span class="nv">rqtp</span> <span class="o">=</span> <span class="o">{</span> + </span><span class="line"> 2, + </span><span class="line"> 0 + </span><span class="line"> <span class="o">}</span>; + </span><span class="line"> + </span><span class="line"> nanosleep<span class="o">(</span>&amp;rqtp, NULL<span class="o">)</span>; + </span><span class="line"><span class="o">}</span> + </span><span class="line"> + </span><span class="line"><span class="nv">$ </span>clang sleep.c + </span><span class="line"> + </span><span class="line"><span class="nv">$ </span>sudo dtruss ./a.out + </span><span class="line">...all kinds of fun stuff + </span><span class="line">__semwait_signal<span class="o">(</span>0xB03, 0x0, 0x1<span class="o">)</span> <span class="o">=</span> -1 Err#60 + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>If you compile with <code>-g</code> to emit debug symbols, you can use lldb’s disassemble + command to get the equivalent assembly:</p> + + <figure class="code"><span></span><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span> + <span class="line-number">2</span> + <span class="line-number">3</span> + <span class="line-number">4</span> + <span class="line-number">5</span> + <span class="line-number">6</span> + <span class="line-number">7</span> + <span class="line-number">8</span> + <span class="line-number">9</span> + <span class="line-number">10</span> + <span class="line-number">11</span> + <span class="line-number">12</span> + <span class="line-number">13</span> + <span class="line-number">14</span> + <span class="line-number">15</span> + <span class="line-number">16</span> + <span class="line-number">17</span> + <span class="line-number">18</span> + <span class="line-number">19</span> + <span class="line-number">20</span> + <span class="line-number">21</span> + <span class="line-number">22</span> + <span class="line-number">23</span> + <span class="line-number">24</span> + <span class="line-number">25</span> + <span class="line-number">26</span> + <span class="line-number">27</span> + <span class="line-number">28</span> + <span class="line-number">29</span> + <span class="line-number">30</span> + <span class="line-number">31</span> + <span class="line-number">32</span> + <span class="line-number">33</span> + <span class="line-number">34</span> + <span class="line-number">35</span> + <span class="line-number">36</span> + <span class="line-number">37</span> + </pre></td><td class="code"><pre><code class="sh"><span class="line"><span class="nv">$ </span>clang sleep.c -g + </span><span class="line"><span class="nv">$ </span>lldb a.out + </span><span class="line"><span class="o">(</span>lldb<span class="o">)</span> target create <span class="s2">"a.out"</span> + </span><span class="line">Current executable <span class="nb">set </span>to <span class="s1">'a.out'</span> <span class="o">(</span>x86_64<span class="o">)</span>. + </span><span class="line"><span class="o">(</span>lldb<span class="o">)</span> b main + </span><span class="line">Breakpoint 1: <span class="nv">where</span> <span class="o">=</span> a.out<span class="sb">`</span>main + 16 at sleep.c:3, <span class="nv">address</span> <span class="o">=</span> 0x0000000100000f40 + </span><span class="line"><span class="o">(</span>lldb<span class="o">)</span> r + </span><span class="line">Process 33213 launched: <span class="s1">'/Users/Nicholas/code/assembly/asmttpd/a.out'</span> <span class="o">(</span>x86_64<span class="o">)</span> + </span><span class="line">Process 33213 stopped + </span><span class="line">* thread <span class="c">#1: tid = 0xeca04, 0x0000000100000f40 a.out`main + 16 at sleep.c:3, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1</span> + </span><span class="line"> frame <span class="c">#0: 0x0000000100000f40 a.out`main + 16 at sleep.c:3</span> + </span><span class="line"> 1 <span class="c">#include &lt;time.h&gt;</span> + </span><span class="line"> 2 int main <span class="o">()</span> <span class="o">{</span> + </span><span class="line">-&gt; 3 struct timespec <span class="nv">rqtp</span> <span class="o">=</span> <span class="o">{</span> + </span><span class="line"> 4 2, + </span><span class="line"> 5 0 + </span><span class="line"> 6 <span class="o">}</span>; + </span><span class="line"> 7 + </span><span class="line"><span class="o">(</span>lldb<span class="o">)</span> disassemble + </span><span class="line">a.out<span class="sb">`</span>main: + </span><span class="line"> 0x100000f30 &lt;+0&gt;: pushq %rbp + </span><span class="line"> 0x100000f31 &lt;+1&gt;: movq %rsp, %rbp + </span><span class="line"> 0x100000f34 &lt;+4&gt;: subq <span class="nv">$0x20</span>, %rsp + </span><span class="line"> 0x100000f38 &lt;+8&gt;: leaq -0x10<span class="o">(</span>%rbp<span class="o">)</span>, %rdi + </span><span class="line"> 0x100000f3c &lt;+12&gt;: xorl %eax, %eax + </span><span class="line"> 0x100000f3e &lt;+14&gt;: movl %eax, %esi + </span><span class="line">-&gt; 0x100000f40 &lt;+16&gt;: movq 0x49<span class="o">(</span>%rip<span class="o">)</span>, %rcx + </span><span class="line"> 0x100000f47 &lt;+23&gt;: movq %rcx, -0x10<span class="o">(</span>%rbp<span class="o">)</span> + </span><span class="line"> 0x100000f4b &lt;+27&gt;: movq 0x46<span class="o">(</span>%rip<span class="o">)</span>, %rcx + </span><span class="line"> 0x100000f52 &lt;+34&gt;: movq %rcx, -0x8<span class="o">(</span>%rbp<span class="o">)</span> + </span><span class="line"> 0x100000f56 &lt;+38&gt;: callq 0x100000f68 ; symbol stub <span class="k">for</span>: nanosleep + </span><span class="line"> 0x100000f5b &lt;+43&gt;: xorl %edx, %edx + </span><span class="line"> 0x100000f5d &lt;+45&gt;: movl %eax, -0x14<span class="o">(</span>%rbp<span class="o">)</span> + </span><span class="line"> 0x100000f60 &lt;+48&gt;: movl %edx, %eax + </span><span class="line"> 0x100000f62 &lt;+50&gt;: addq <span class="nv">$0x20</span>, %rsp + </span><span class="line"> 0x100000f66 &lt;+54&gt;: popq %rbp + </span><span class="line"> 0x100000f67 &lt;+55&gt;: retq + </span></code></pre></td></tr></tbody></table></div></figure> + + + <p>Anyways, I’ve been learning some interesting things about OSX that I’ll be + sharing soon. If you’d like to learn more about x86-64 assembly programming, + you should read my other posts about + <a href="http://nickdesaulniers.github.io/blog/2014/04/18/lets-write-some-x86-64/">writing x86-64</a> + and a toy + <a href="http://nickdesaulniers.github.io/blog/2015/05/25/interpreter-compiler-jit/">JIT for Brainfuck</a> + (<a href="https://www.reddit.com/r/programming/comments/377ov9/interpreter_compiler_jit/crkkrz4">the creator of Brainfuck liked it</a>).</p> + + <p>I should also do a post on + <a href="http://rr-project.org/">Mozilla’s rr</a>, + because it can do amazing things like step backwards. Another day…</p> + Thu, 21 Jan 2016 04:04:00 +0000 + + + Rail Aliiev: Rebooting productivity + https://rail.merail.ca/posts/rebooting-productivity.html + https://rail.merail.ca/posts/rebooting-productivity.html + <div><p>Every new year gives you an opportunity to sit back, relax, + <span class="strike">have some scotch</span> and re-think the passed year. Holidays give + you enough free time. Even if you decide to not take a vacation around + the holidays, it's usually calm and peaceful.</p> + <p>This time, I found myself thinking mostly about productivity, being + effective, feeling busy, overwhelmed with work and other related topics.</p> + <p>When I started at Mozilla (almost 6 years ago!), I tried to apply all my + GTD and time management knowledge and techniques. Working remotely and + in a different time zone was an advantage - I had close to zero + interruptions. It worked perfect.</p> + <p>Last year I realized that my productivity skills had faded away somehow. + 40h+ workweeks, working on weekends, delivering goals in the last week + of quarter don't sound like good signs. Instead of being productive I + felt busy.</p> + <p>"Every crisis is an opportunity". Time to make a step back and reboot + myself. Burning out at work is not a good idea. :)</p> + <p>Here are some ideas/tips that I wrote down for myself you may found + useful.</p> + <div class="section" id="health-related"> + <h3>Health related</h3> + <ul class="simple"> + <li>Morning exercises. A 20-minute walk will wake your brain up and + generate enough endorphins for the first half of the day.</li> + <li>Meditation. 2x20min a day is ideal; 2x10min would work too. Something + like <a class="reference external" href="http://www.calm.com/">calm.com</a> makes this a peace of cake.</li> + </ul> + </div> + <div class="section" id="concentration"> + <h3>Concentration</h3> + <ul class="simple"> + <li>Task #1: make a daily plan. No plan - no work.</li> + <li>Don't start your day by reading emails. Get one (little) thing done + first - THEN check your email.</li> + <li>Try to define outcomes, not tasks. "Ship XYZ" instead of "Work on XYZ".</li> + <li>Meetings are time consuming, so "Set a goal for each meeting". + Consider skipping a meeting if you don't have any goal set, unless it's a + beer-and-tell meeting! :)</li> + <li>Constantly ask yourself if what you're working on is important.</li> + <li>3-4 times a day ask yourself whether you are doing something towards + your goal or just finding something else to keep you busy. If you want + to look busy, take your phone and walk around the office with some + papers in your hand. Everybody will think that you are a busy person! + This way you can take a break and look busy at the same time!</li> + <li>Take breaks! <a class="reference external" href="https://en.wikipedia.org/wiki/Pomodoro_Technique">Pomodoro technique</a> has this option + built-in. Taking breaks helps not only to avoid <a class="reference external" href="https://en.wikipedia.org/wiki/Repetitive_strain_injury">RSI</a>, but also + keeps your brain sane and gives you time to ask yourself the questions + mentioned above. I use <a class="reference external" href="http://www.workrave.org/">Workrave</a> on my + laptop, but you can use a real kitchen timer instead.</li> + <li>Wear headphones, especially at office. Noise cancelling ones are even + better. White noise, nature sounds, or instrumental music are your + friends.</li> + </ul> + </div> + <div class="section" id="home-office"> + <h3>(Home) Office</h3> + <ul class="simple"> + <li>Make sure you enjoy your work environment. Why on the earth would you + spend your valuable time working without joy?!</li> + <li>De-clutter and organize your desk. Less things around - less + distractions.</li> + <li>Desk, chair, monitor, keyboard, mouse, etc - don't cheap out on them. + Your health is more important and expensive. Thanks to <a class="reference external" href="https://twitter.com/mhoye">mhoye</a> for this advice!</li> + </ul> + </div> + <div class="section" id="other"> + <h3>Other</h3> + <ul class="simple"> + <li>Don't check email every 30 seconds. If there is an emergency, they + will call you! :)</li> + <li>Reward yourself at a certain time. "I'm going to have a chocolate at + 11am", or "MFBT at 4pm sharp!" are good examples. Don't forget, you + are <a class="reference external" href="https://en.wikipedia.org/wiki/Classical_conditioning">Pavlov's dog</a> too!</li> + <li>Don't try to read everything NOW. Save it for later and read in a + batch.</li> + <li>Capture all creative ideas. You can delete them later. ;)</li> + <li>Prepare for next task before break. Make sure you know what's next, so + you can think about it during the break.</li> + </ul> + <p>This is my list of things that I try to use everyday. Looking forward to + see improvements!</p> + <p>I would appreciate your thoughts this topic. Feel free to comment or + send a private email.</p> + <p>Happy Productive New Year!</p> + </div></div> + Thu, 21 Jan 2016 02:06:37 +0000 + Rail Aliiev + + + The Rust Programming Language Blog: Announcing Rust 1.6 + http://blog.rust-lang.org/2016/01/21/Rust-1.6.html + http://blog.rust-lang.org/2016/01/21/Rust-1.6.html + <p>Hello 2016! We’re happy to announce the first Rust release of the year, 1.6. + Rust is a systems programming language focused on safety, speed, and + concurrency.</p> + + <p>As always, you can <a href="http://www.rust-lang.org/install.html">install Rust 1.6</a> from the appropriate page on our + website, and check out the <a href="https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-160-2016-01-21">detailed release notes for 1.6</a> on GitHub. + About 1100 patches were landed in this release.</p> + + <h3 id="what-39-s-in-1-6-stable">What’s in 1.6 stable</h3> + + <p>This release contains a number of small refinements, one major feature, and + a change to <a href="https://crates.io">Crates.io</a>.</p> + + <h4 id="libcore-stabilization">libcore stabilization</h4> + + <p>The largest new feature in 1.6 is that <a href="http://doc.rust-lang.org/nightly/core/"><code>libcore</code></a> is now stable! Rust’s + standard library is two-tiered: there’s a small core library, <code>libcore</code>, and + the full standard library, <code>libstd</code>, that builds on top of it. <code>libcore</code> is + completely platform agnostic, and requires only a handful of external symbols + to be defined. Rust’s <code>libstd</code> builds on top of <code>libcore</code>, adding support for + memory allocation, I/O, and concurrency. Applications using Rust in the + embedded space, as well as those writing operating systems, often eschew + <code>libstd</code>, using only <code>libcore</code>.</p> + + <p><code>libcore</code> being stabilized is a major step towards being able to write the + lowest levels of software using stable Rust. There’s still future work to be + done, however. This will allow for a library ecosystem to develop around + <code>libcore</code>, but <em>applications</em> are not fully supported yet. Expect to hear more + about this in future release notes.</p> + + <h4 id="library-stabilizations">Library stabilizations</h4> + + <p>About 30 library functions and methods are now stable in 1.6. Notable + improvements include:</p> + + <p>The <code>drain()</code> family of functions on collections. These methods let you move + elements out of a collection while allowing them to retain their backing + memory, reducing allocation in certain situations.</p> + + <p>A number of implementations of <code>From</code> for converting between standard library + types, mainly between various integral and floating-point types.</p> + + <p>Finally, <code>Vec::extend_from_slice()</code>, which was previously known as + <code>push_all()</code>. This method has a significantly faster implementation than the + more general <code>extend()</code>.</p> + + <p>See the <a href="https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-160-2016-01-21">detailed release notes</a> for more.</p> + + <h4 id="crates-io-disallows-wildcards">Crates.io disallows wildcards</h4> + + <p>If you maintain a crate on <a href="https://crates.io">Crates.io</a>, you might have seen + a warning: newly uploaded crates are no longer allowed to use a wildcard when + describing their dependencies. In other words, this is not allowed:</p> + <div class="highlight"><pre><code class="language-toml"><span class="p">[</span><span class="n">dependencies</span><span class="p">]</span> + <span class="n">regex</span> <span class="o">=</span> <span class="s">"*"</span> + </code></pre></div> + <p>Instead, you must actually specify <a href="http://doc.crates.io/crates-io.html#using-cratesio-based-crates">a specific version or range of + versions</a>, using one of the <code>semver</code> crate’s various options: <code>^</code>, + <code>~</code>, or <code>=</code>.</p> + + <p>A wildcard dependency means that you work with any possible version of your + dependency. This is highly unlikely to be true, and causes unnecessary breakage + in the ecosystem. We’ve been advertising this change as a warning for some time; + now it’s time to turn it into an error.</p> + + <h3 id="contributors-to-1-6">Contributors to 1.6</h3> + + <p>We had 132 individuals contribute to 1.6. Thank you so much!</p> + + <ul> + <li>Aaron Turon</li> + <li>Adam Badawy</li> + <li>Aleksey Kladov</li> + <li>Alexander Bulaev</li> + <li>Alex Burka</li> + <li>Alex Crichton</li> + <li>Alex Gaynor</li> + <li>Alexis Beingessner</li> + <li>Amanieu d'Antras</li> + <li>Amit Saha</li> + <li>Andrea Canciani</li> + <li>Andrew Paseltiner</li> + <li>androm3da</li> + <li>angelsl</li> + <li>Angus Lees</li> + <li>Antti Keränen</li> + <li>arcnmx</li> + <li>Ariel Ben-Yehuda</li> + <li>Ashkan Kiani</li> + <li>Barosl Lee</li> + <li>Benjamin Herr</li> + <li>Ben Striegel</li> + <li>Bhargav Patel</li> + <li>Björn Steinbrink</li> + <li>Boris Egorov</li> + <li>bors</li> + <li>Brian Anderson</li> + <li>Bruno Tavares</li> + <li>Bryce Van Dyk</li> + <li>Cameron Sun</li> + <li>Christopher Sumnicht</li> + <li>Cole Reynolds</li> + <li>corentih</li> + <li>Daniel Campbell</li> + <li>Daniel Keep</li> + <li>Daniel Rollins</li> + <li>Daniel Trebbien</li> + <li>Danilo Bargen</li> + <li>Devon Hollowood</li> + <li>Doug Goldstein</li> + <li>Dylan McKay</li> + <li>ebadf</li> + <li>Eli Friedman</li> + <li>Eric Findlay</li> + <li>Erik Davidson</li> + <li>Felix S. Klock II</li> + <li>Florian Hahn</li> + <li>Florian Hartwig</li> + <li>Gleb Kozyrev</li> + <li>Guillaume Gomez</li> + <li>Huon Wilson</li> + <li>Igor Shuvalov</li> + <li>Ivan Ivaschenko</li> + <li>Ivan Kozik</li> + <li>Ivan Stankovic</li> + <li>Jack Fransham</li> + <li>Jake Goulding</li> + <li>Jake Worth</li> + <li>James Miller</li> + <li>Jan Likar</li> + <li>Jean Maillard</li> + <li>Jeffrey Seyfried</li> + <li>Jethro Beekman</li> + <li>John Kåre Alsaker</li> + <li>John Talling</li> + <li>Jonas Schievink</li> + <li>Jonathan S</li> + <li>Jose Narvaez</li> + <li>Josh Austin</li> + <li>Josh Stone</li> + <li>Joshua Holmer</li> + <li>JP Sugarbroad</li> + <li>jrburke</li> + <li>Kevin Butler</li> + <li>Kevin Yeh</li> + <li>Kohei Hasegawa</li> + <li>Kyle Mayes</li> + <li>Lee Jeffery</li> + <li>Manish Goregaokar</li> + <li>Marcell Pardavi</li> + <li>Markus Unterwaditzer</li> + <li>Martin Pool</li> + <li>Marvin Löbel</li> + <li>Matt Brubeck</li> + <li>Matthias Bussonnier</li> + <li>Matthias Kauer</li> + <li>mdinger</li> + <li>Michael Layzell</li> + <li>Michael Neumann</li> + <li>Michael Sproul</li> + <li>Michael Woerister</li> + <li>Mihaly Barasz</li> + <li>Mika Attila</li> + <li>mitaa</li> + <li>Ms2ger</li> + <li>Nicholas Mazzuca</li> + <li>Nick Cameron</li> + <li>Niko Matsakis</li> + <li>Ole Krüger</li> + <li>Oliver Middleton</li> + <li>Oliver Schneider</li> + <li>Ori Avtalion</li> + <li>Paul A. Jungwirth</li> + <li>Peter Atashian</li> + <li>Philipp Matthias Schäfer</li> + <li>pierzchalski</li> + <li>Ravi Shankar</li> + <li>Ricardo Martins</li> + <li>Ricardo Signes</li> + <li>Richard Diamond</li> + <li>Rizky Luthfianto</li> + <li>Ryan Scheel</li> + <li>Scott Olson</li> + <li>Sean Griffin</li> + <li>Sebastian Hahn</li> + <li>Sébastien Marie</li> + <li>Seo Sanghyeon</li> + <li>Simonas Kazlauskas</li> + <li>Simon Sapin</li> + <li>Stepan Koltsov</li> + <li>Steve Klabnik</li> + <li>Steven Fackler</li> + <li>Tamir Duberstein</li> + <li>Tobias Bucher</li> + <li>Toby Scrace</li> + <li>Tshepang Lekhonkhobe</li> + <li>Ulrik Sverdrup</li> + <li>Vadim Chugunov</li> + <li>Vadim Petrochenkov</li> + <li>William Throwe</li> + <li>xd1le</li> + <li>Xmasreturns</li> + </ul> + Thu, 21 Jan 2016 00:00:00 +0000 + + + Mozilla Addons Blog: Archiving AMO Stats + http://blog.mozilla.org/addons/?p=7644 + https://blog.mozilla.org/addons/2016/01/20/archiving-amo-stats/ + <p>One of the advantages of listing an add-on or theme on <a href="https://addons.mozilla.org" target="_blank">addons.mozilla.org</a> (AMO) is that you’ll get statistics on your add-on’s usage. These stats, which are covered by the <a href="https://www.mozilla.org/privacy/" target="_blank">Mozilla privacy policy</a>, provide add-on developers with information such as the number of downloads and daily users, among other insights.</p> + <p>Currently, the data that generates these statistics can go back as far as 2007, as we haven’t had an archiving policy. As a result, statistics take up the vast majority of disk space in our database and require a significant amount of processing and operations time. Statistics over a year old are very rarely accessed, and the value of their generation is very low, while the costs are increasing.</p> + <p>To reduce our operating and development costs, and increase the site’s reliability for developers, we are introducing an archiving policy.</p> + <p>In the coming weeks, statistics data <strong>over one year old</strong> will no longer be stored in the AMO database, and reports generated from them will no longer be accessible through AMO’s add-on statistics pages. Instead, the data will be archived and maintained as plain text files, which developers can download. We will write a follow-up post when these archives become available.</p> + <p>If you’ve chosen to keep your add-on’s statistics private, they will remain private when stats are archived. You can check your privacy settings by going to your add-on in the <a href="https://addons.mozilla.org/developers/addons" target="_blank">Developer Hub</a>, clicking on <strong>Edit Listing</strong>, and then <strong>Technical Details</strong>.</p> + <p><a href="https://blog.mozilla.org/addons/files/2016/01/Screenshot-2016-01-20-14.52.33.png"><img alt="editlisting" class="alignnone size-large wp-image-7645" height="389" src="https://blog.mozilla.org/addons/files/2016/01/Screenshot-2016-01-20-14.52.33-600x389.png" width="600" /></a></p> + <p>The total number of users and other cumulative counts on add-ons and themes will not be affected and these will continue to function.</p> + <p>If you have feedback or concerns, please head to our <a href="https://discourse.mozilla-community.org/t/archiving-of-add-on-statistics/6573" target="_blank">forum post</a> on this topic.</p> + Wed, 20 Jan 2016 23:54:09 +0000 + Andy McKay + + + Air Mozilla: The Joy of Coding - Episode 41 + https://air.mozilla.org/the-joy-of-coding-episode-41/ + https://air.mozilla.org/the-joy-of-coding-episode-41/ + <p> + <img alt="The Joy of Coding - Episode 41" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/cb/68/cb68b6ac48452be7e7f25ddc7b63c959.png" width="160" /> + mconley livehacks on real Firefox bugs while thinking aloud. + </p> + Wed, 20 Jan 2016 18:00:00 +0000 + Air Mozilla + + + Nathan Froyd: gecko and c++ onboarding presentation + http://blog.mozilla.org/nfroyd/?p=452 + https://blog.mozilla.org/nfroyd/2016/01/20/gecko-and-c-onboarding-presentation/ + <p>One of the things the Firefox team has been doing recently is having onboarding sessions for new hires. This onboarding currently covers:</p> + <ul> + <li>1st day setup</li> + <li>Bugzilla</li> + <li>Building Firefox</li> + <li>Desktop Firefox Architecture / Product</li> + <li>Communication and Community</li> + <li>Javascript and the DOM</li> + <li>C++ and Gecko</li> + <li>Shipping Software</li> + <li>Telemetry</li> + <li>Org structure and career development</li> + </ul> + <p>My first day consisted of some useful HR presentations and then I was given my laptop and a pointer to a wiki page on building Firefox. Needless to say, it took me a while to get started! It would have been super convenient to have an introduction to all the stuff above.</p> + <p>I’ve been asked to do the C++ and Gecko session three times. All of the sessions are open to whoever wants to come, not just the new hires, and I think yesterday’s session was easily the most well-attended yet: somewhere between 10 and 20 people showed up. Yesterday’s session was the first session where I made the slides available to attendees (should have been doing that from the start…) and it seemed equally useful to make the slides available to a broader audience as well. The <a href="https://docs.google.com/presentation/d/1ZHUkNzZK2TrF5_4MWd_lqEq7Ph5B6CDbNsizIkBxbnQ/edit?usp=sharing">Gecko and C++ Onboarding slides</a> are up now!</p> + <p>This presentation is a “living” presentation; it will get updated for future sessions with feedback and as I think of things that should have been in the presentation or better ways to set things up (some diagrams would be nice…). If you have feedback (good, bad, or ugly) on particular things in the slides or you have suggestions on what other things should be covered, please contact me! Next time I do this I’ll try to record the presentation so folks can watch that if they prefer.</p> + Wed, 20 Jan 2016 16:48:29 +0000 + Nathan Froyd + + + Andreas Gal: Brendan is back to save the Web + http://andreasgal.com/?p=573 + http://andreasgal.com/2016/01/20/brendan-is-back-to-save-the-web/ + <p class="p1">Brendan is <a href="https://github.com/brave">back</a>, and he has a <a href="http://brave.com/">plan</a> to save the Web. Its a big and bold plan, and it may just work. I am pretty excited about this. If you have 5 minutes to read along I’ll explain why I think you should be as well.</p> + <p class="p1"><strong>The Web is broken</strong></p> + <p class="p1">Lets face it, the Web today is a mess. Everywhere we go online we are constantly inundated with annoying ads. Often pages are more ads than content, and the more ads the industry throws at us, the more we ignore them, the more obnoxious ads get, trying to catch our attention. As Brendan explains in his blog post, the browser used to be on the user’s side—we call browsers the user agent for a reason. Part of the early success of Firefox was that it blocked popup ads. But somewhere over the last 10 years of modern Web browsers, browsers lost their way and stopped being the user’s agent alone. Why?</p> + <p class="p1"><strong>Browsers aren’t free</strong></p> + <p class="p1">Making a modern Web browser is not free. It takes hundreds of engineers to make a competitive modern browser engine. Someone has to pay for that, and that someone needs to have a reason to pay for it. Google doesn’t make Chrome for the good of mankind. Google makes Chrome so you can consume more Web and along with it, more Google ads. Each time you click on one, Google makes more money. Chrome is a billion dollar business for Google. And the same is true for pretty much every other browser. Every major browser out there is funded through advertisement. No browser maker can escape this dilemma. Maybe now you understand why no major browser ships with a builtin enabled by default ad-blocker, even though ad-blockers are by far the most popular add-ons.</p> + <p class="p1"><strong>Our privacy is at stake</strong></p> + <p class="p1">It’s not just the unregulated flood of advertisement that needs a solution. Every ad you see is often selected based on sensitive private information advertisement networks have extracted from your browsing behavior through tracking. Remember how the FBI used to track what books Americans read at the library, and it was a big scandal? Today the Googles and Facebooks of the world know almost every site you visit, everything you buy online, and they use this data to target you with advertisement. I am often puzzled why people are so afraid of the NSA spying on us but show so little concern about all the deeply personal data Google and Facebook are amassing about everyone.</p> + <p class="p1"><strong>Blocking alone doesn’t scale</strong></p> + <p class="p1">I wish the solution was as easy as just blocking all ads. There is a lot of great Web content out there: news, entertainment, educational content. It’s not free to make all this content, but we have gotten used to consuming it “for free”. Banning all ads without an alternative mechanism would break the economic backbone of the Web. This dilemma has existed for many years, and the big browser vendors seem to have given up on it. It’s hard to blame them. How do you disrupt the status quo without sawing off the (ad revenue) branch you are sitting on?</p> + <p class="p1"><strong>It takes an newcomer to fix this mess</strong></p> + <p class="p1">I think its unlikely that the incumbent browser vendors will make any bold moves to solve this mess. There is too much money at stake. I am excited to see a startup take a swipe at this problem, because they have little to lose (seed money aside). Brave is getting the user agent back into the game. Browsers have intentionally remained silent onlookers to the ad industry invading users’ privacy. With Brave, Brendan makes the user agent step up and fight for the user as it was always intended to do.</p> + <p class="p1">Brave basically consists of two parts: part one blocks third party ad content and tracking signals. Instead of these Brave inserts alternative ad content. Sites can sign up to get a fair share of any ads that Brave displays for them. The big change in comparison to the status quo is that the Brave user agent is in control and can regulate what you see. It’s like a speed limit for advertisement on the Web, with the goal to restore balance and give sites a fair way to monetize while giving the user control through the user agent.</p> + <p class="p1"><strong>Making money with a better Web</strong></p> + <p class="p1">The ironic part of Brave is that its for-profit. Brave can make money by reducing obnoxious ads and protecting your privacy at the same time. If Brave succeeds, it’s going to drain money away from the crappy privacy-invasive obnoxious advertisement world we have today, and publishers and sites will start transacting in the new Brave world that is regulated by the user agent. Brave will take a cut of these transactions. And I think this is key. It aligns the incentives right. The current funding structure of major browsers encourages them to keep things as they are. Brave’s incentive is to bring down the whole diseased temple and usher in a better Web. Exciting.</p> + <p class="p1"><strong>Quick update:</strong> I had a chance to look over the Brave GitHub repo. It looks like the Brave Desktop browser is based on Chromium, not Gecko. Yes, you read that right. <span style="text-decoration: underline;">Brave is using Google’s rendering engine, not Mozilla’s.</span> Much to write about this one, but it will definitely help Brave “hide” better in the large volume of Chrome users, making it harder for sites to identify and block Brave users. Brave for iOS seems to be a <span style="text-decoration: underline;">fork of Firefox for iOS, but it manages to block ads</span> (Mozilla says they can’t).</p><br />Filed under: <a href="http://andreasgal.com/category/mozilla/">Mozilla</a> <a href="http://feeds.wordpress.com/1.0/gocomments/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/godelicious/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/gofacebook/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/gotwitter/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/gostumble/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/godigg/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/andreasgal.wordpress.com/573/" /></a> <a href="http://feeds.wordpress.com/1.0/goreddit/andreasgal.wordpress.com/573/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/andreasgal.wordpress.com/573/" /></a> <img alt="" border="0" height="1" src="http://pixel.wp.com/b.gif?host=andreasgal.com&amp;blog=891661&amp;post=573&amp;subd=andreasgal&amp;ref=&amp;feed=1" width="1" /> + Wed, 20 Jan 2016 16:00:00 +0000 + Andreas + + + Mike Taylor: 🙅 @media (-webkit-transform-3d) + https://miketaylr.com/posts/2016/01/at-media-webkit-transform-three-dee.html + https://miketaylr.com/posts/2016/01/at-media-webkit-transform-three-dee.html + <p><code>@media (-webkit-transform-3d)</code> is a funny thing that exists on the web.</p> + + <p>It's like, a <a href="https://drafts.csswg.org/mediaqueries-4/#mq-features">media query feature</a> in the form of a prefixed CSS property, which should tell you if your (once upon a time probably Safari-only) browser supports 3D transforms, invented back in the day before we had <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@supports"><code>@supports</code></a>.</p> + + <p>(According to <a href="https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariCSSRef/Articles/OtherStandardCSS3Features.html#//apple_ref/doc/uid/TP40007601-SW3">Apple docs</a> it first appeared in Safari 4, along side the other <code>-webkit-transition</code> and <code>-webkit-transform-2d</code> hybrid-media-query-feature-prefixed-css-properties-things that you should immediately forget exist.)</p> + + <p>Older versions of Modernizr <a href="https://github.com/Modernizr/Modernizr/blob/66c694d136241d356e0d24fcbaa5c068b0b0cdae/feature-detects/css/transforms3d.js#L26-L27">used this (and only this)</a> to detect support for 3D transforms, and that seemed pretty OK. (They also did the polite thing and tested <code>@media (transform-3d)</code>, but no browser has ever actually supported that, as it turns out). And because they're so consistently polite, they've since <a href="https://github.com/patrickkettner/Modernizr/commit/a54308e47e269a058472854b1ef417bd54f4e616">updated the test</a> to prefer <code>@supports</code> too (via a pull request from Edge developer Jacob Rossi).</p> + + <p>As it turns out other browsers have been <a href="http://caniuse.com/#feat=transforms3d">updated to support 3D CSS transforms</a>, but sites didn't go back and update their version of Modernizr. So unless you support <code>@media (-webkit-transform-3d)</code> these sites break. Niche websites like <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1239136">yahoo.com</a> and <a href="https://github.com/webcompat/web-bugs/issues/2151">about.com</a>.</p> + + <p>So, anyways. I added <a href="https://compat.spec.whatwg.org/#css-media-queries-webkit-transform-3d"><code>@media (-webkit-transform-3d)</code> to the Compat Standard</a> and we <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1239799">added support for it Firefox</a> so websites stop breaking.</p> + + <p>But you shouldn't ever use it—use <code>@supports</code>. In fact, don't even share this blog post. Maybe delete it from your browser history just in case.</p> + Wed, 20 Jan 2016 08:00:00 +0000 + Mike Taylor + + + Byron Jones: happy bmo push day! + http://globau.wordpress.com/?p=881 + https://globau.wordpress.com/2016/01/20/happy-bmo-push-day-166/ + <p>the following changes have been pushed to bugzilla.mozilla.org:</p> + <ul> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1236161" target="_blank">1236161</a>] when converting a BMP attachment to PNG fails a zero byte attachment is created</li> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1231918" target="_blank">1231918</a>] error handler doesn’t close multi-part responses</li> + </ul> + <p>discuss these changes on <a href="https://lists.mozilla.org/listinfo/tools-bmo" target="_blank">mozilla.tools.bmo</a>.</p><br />Filed under: <a href="https://globau.wordpress.com/category/mozilla/bmo/">bmo</a>, <a href="https://globau.wordpress.com/category/mozilla/">mozilla</a> <img alt="" border="0" height="1" src="https://pixel.wp.com/b.gif?host=globau.wordpress.com&amp;blog=25718030&amp;post=881&amp;subd=globau&amp;ref=&amp;feed=1" width="1" /> + Wed, 20 Jan 2016 07:33:46 +0000 + glob + + + Alex Johnson: Removing Honeycomb Code + https://www.alex-johnson.net/tag/mozilla/rss/85d84c54-ed0c-4ee5-beb3-8823edb3c074 + https://www.alex-johnson.net/removing-honeycomb-code/ + <p>As an effort to reduce the APK size of Firefox for Android and to remove unnecessary code, I will be helping remove the Honeycomb code throughout the Fennec project. Honeycomb will not be supported since Firefox 46, so this code is not necessary. <br /> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1217675">Bug 1217675</a> will keep track of the progress. <br /> + Hopefully this will help reduce the APK size some and clean up the road for <a href="https://www.youtube.com/watch?v=NJ6kzW5t02Y">killing Gingerbread</a> hopefully sometime in the near future.</p> + Wed, 20 Jan 2016 04:59:34 +0000 + Alex Johnson + + + Brian R. Bondy: Brave Software + http://www.brianbondy.com/blog/id/172 + http://www.brianbondy.com/blog/172/brave-software + <p></p><p>Since June of last year, I’ve been co-founding a new startup called <a href="https://brave.com/">Brave Software</a> with <a href="https://en.wikipedia.org/wiki/Brendan_Eich">Brendan Eich</a>. + With our amazing team, we're developing something pretty epic.</p><p></p> + <p></p><p>We're building the next-generation of browsers for smartphones and laptops as part of our new ad-tech platform. + Our terms of use give our users control over their personal data by blocking ad trackers and third party cookies. + We re-integrate fewer and better ads directly into programmatic ad positions, paying revenue shares to users and publishers to support both of these essential parties in the web ecosystem.</p><p></p> + <p></p><p>Coming built in, we have new faster engines for tracking protection, ad block, HTTPS Everywhere, safe ads with rev-share, and more. + We're seeing massive web page load time speedups.</p><p></p> + + + <p></p><p>We're starting to bring people in for early developer build access on all platforms.</p><p></p> + <p></p><p>I’m happy to share that the browsers we’re developing were made fully open sourced. + We welcome contributors, and would love your help.</p><p></p> + <p></p><p>Some of the repositories include:</p><p></p> + <ul> + <li><a href="https://github.com/brave/browser-laptop">Brave OSX and Windows x64 browsers</a>: Prototyped as a Gecko based browser, but now replaced with a powerful new browser built on top of the electron framework. The electron framework is the same one in use by Slack and the Atom editor. It uses the latest libchromiumcontent and Node.</li> + <li><a href="https://github.com/brave/link-bubble">Brave for Android</a>: Formerly Link Bubble, working as a background service so you can use other apps as your pages load.</li> + <li><a href="https://github.com/brave/browser-ios">Brave for iOS</a>: Originally forked from Firefox for iOS but with all of the built-in greatness described above.</li> + <li>And many others: Website, updater code, vault, electron fork, and others.</li> + </ul> + Wed, 20 Jan 2016 00:00:00 +0000 + Brian R. Bondy + + + James Socol: PIEfection Slides Up + http://coffeeonthekeyboard.com/rss/0388d8a6-fc86-477e-a161-1b356e01fe77 + http://coffeeonthekeyboard.com/piefection-slides-up/ + <p>I put <a href="https://github.com/jsocol/talks/tree/master/2016-01-13-manhattanjs-pie">the slides for my ManhattanJS talk, "PIEfection"</a> up on GitHub the other day (sans images, but there are links in the source for all of those).</p> + + <p>I completely neglected to talk about the <a href="https://en.wikipedia.org/wiki/Maillard_reaction">Maillard reaction</a>, which is responsible for food tasting good, and specifically for browning pie crusts. tl;dr: Amino acid (protein) + sugar + ~300°F (~150°C) = delicious. There are innumerable and poorly understood combinations of amino acids and sugars, but this class of reaction is responsible for everything from searing stakes to browning crusts to toasting marshmallows.</p> + + <p>Above ~330°F, you get caramelization, which is also a delicious part of the pie and crust, but you don't want to overdo it. Starting around ~400°F, you get pyrolysis (burning, charring, carbonization) and below 285°F the reaction won't occur (at least not quickly) so you won't get the delicious compounds.</p> + + <p>(All of these are, of course, temperatures measured in the material, not in the air of the oven.)</p> + + <p>So, instead of an egg wash on your top crust, try whole milk, which has more sugar to react with the gluten in the crust.</p> + + <p>I also didn't get a chance to mention a rolling technique I use, that I learned from a <a href="https://www.facebook.com/ellenspirerstaffing">cousin of mine</a>, in whose baking shadow I happily live.</p> + + <p>When rolling out a crust after it's been in the fridge, first roll it out in a long stretch, then fold it in thirds; do it again; then start rolling it out into a round. Not only do you add more layer structure (mmm, flaky, delicious layers) but it'll fill in the cracks that often form if you try to roll it out directly, resulting in a stronger crust.</p> + + <p>Those <a href="http://www.amazon.com/Cheese-Shaker-Pepper-Perforated-Stainless/dp/B007T40P28/ref=sr_1_1?ie=UTF8&amp;qid=1453236391&amp;sr=8-1&amp;keywords=pizza+shaker">pepper flake shakers</a>, filled with flour, are a great way to keep adding flour to the workspace without worrying about your buttery hands.</p> + + <p>For transferring the crust to the pie plate, try rolling it up onto your rolling pin and unrolling it on the plate. <a href="http://www.amazon.com/Ateco-20-Inch-Length-French-Rolling/dp/B000KESQ1G">Tapered (or "French") rolling pins</a> (or wine bottle) are particularly good at this since they don't have moving parts.</p> + + <p>Finally, thanks again to <a href="https://twitter.com/renrutnnej">Jenn</a> for helping me get pies from one island to another. It would not have been possible without her!</p> + Tue, 19 Jan 2016 20:45:34 +0000 + James Socol + + + Air Mozilla: Reprendre le contrôle de sa vie privée sur Internet + https://air.mozilla.org/reprendre-le-controle-de-sa-vie-privee-sur-internet/ + https://air.mozilla.org/reprendre-le-controle-de-sa-vie-privee-sur-internet/ + <p> + <img alt="Reprendre le contrôle de sa vie privée sur Internet" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/be/f6/bef62897fb87e08dc8392fe61d10bcfa.png" width="160" /> + L'omniprésence des réseaux sociaux, des moteurs de recherches et de la publicité est-elle compatible avec notre droit à la vie privée ? + </p> + Tue, 19 Jan 2016 18:00:00 +0000 + Air Mozilla + + + Myk Melez: New Year, New Blogware + https://mykzilla.org/?p=245 + https://mykzilla.org/2016/01/19/new-year-new-blogware/ + <p>Four score and many moons ago, I decided to move this blog from Blogger to WordPress. The transition took longer than expected, but it’s finally done.</p> + <p>If you’ve been following along at the old address, <a href="https://mykzilla.blogspot.com/">https://mykzilla.blogspot.com/</a>, now’s the time to update your address book! If you’ve been going to <a href="https://mykzilla.org/">https://mykzilla.org/</a>, however, or you read the blog on <a href="http://planet.mozilla.org/">Planet Mozilla</a>, then there’s nothing to do, as that’s the new address, and Planet Mozilla has been updated to syndicate posts from it.</p> + Tue, 19 Jan 2016 16:56:05 +0000 + Myk Melez + + + Michael Kohler: Mozillas strategische Leitlinien für 2016 und danach + http://michaelkohler.info/?p=348 + https://michaelkohler.info/2016/mozillas-strategische-leitlinien-fur-2016-und-danach + <p>Dieser Beitrag wurde zuerst im Blog auf<a href="https://blog.mozilla.org/community"> https://blog.mozilla.org/community</a> veröffentlicht. Herzlichen Dank an Aryx und Coce für die Übersetzung!</p> + <p>Auf der ganzen Welt arbeiten leidenschaftliche Mozillianer am Fortschritt für Mozillas Mission. Aber fragt man fünf verschiedene Mozillianer, was die Mission ist, erhält man womöglich sieben verschiedene Antworten.</p> + <p>Am Ende des letzten Jahres legte Mozillas CEO Chris Beard klare Vorstellungen über Mozillas Mission, Vision und Rolle dar und zeigte auf, wie unsere Produkte uns diesem Ziel in den nächsten fünf Jahren näher bringen. Das Ziel dieser strategischen Leitlinien besteht darin, für Mozilla insgesamt ein prägnantes, gemeinsames Verständnis unserer Ziele zu entwickeln, die uns als Individuen das Treffen von Entscheidungen und Erkennen von Möglichkeiten erleichtert, mit denen wir Mozilla voranbringen.</p> + <p>Mozillas Mission können wir nicht alleine erreichen. Die Tausenden von Mozillianern auf der ganzen Welt müssen dahinter stehen, damit wir zügig und mit lauterer Stimme als je zuvor Unglaubliches erreichen können.</p> + <p>Deswegen ist eine der sechs<a href="https://docs.google.com/presentation/d/1A3Ma9gNawAYYGbYC2bUW0wUwcpHuvyMiZvHNiMLriw0/edit#slide=id.gdaa7a0bd0_1_0"> strategischen Initiativen</a> des Participation Teams für die erste Jahreshälfte, möglichst viele Mozillianer über diese Leitlinien aufzuklären, damit wir 2016 den bisher wesentlichsten Einfluss erzielen können. Wir werden einen weiteren Beitrag veröffentlichen, der sich näher mit der Strategie des Participation Teams für das Jahr 2016 befassen wird.</p> + <p><img alt="" class="alignnone" height="335" src="https://ffp4g1ylyit3jdyti1hqcvtb-wpengine.netdna-ssl.com/community/files/2016/01/Screen-Shot-2015-12-18-at-2.02.07-PM-600x335.png" width="600" /></p> + <p>Das Verstehen dieser Strategie wird unabdingbar sein für jeden, der bei Mozilla in diesem Jahr etwas bewirken möchte, denn sie wird bestimmen, wofür wir eintreten, wo wir unsere Ressourcen einsetzen und auf welche Projekte wir uns 2016 konzentrieren werden.</p> + <p>Zu Jahresbeginn werden wir näher auf diese Strategie eingehen und weitere Details dazu bekanntgeben, wie die diversen Teams und Projekte bei Mozilla auf diese Ziele hinarbeiten.</p> + <p>Der aktuelle Aufruf zum Handeln besteht darin, im Kontext Ihrer Arbeit über diese Ziele nachzudenken und darüber, wie Sie im kommenden Jahr bei Mozilla mitwirken möchten. Dies hilft, Ihre Innovationen, Ambitionen und Ihren Einfluss im Jahr 2016 zu gestalten.</p> + <p>Wir hoffen, dass Sie mitdiskutieren und Ihre Fragen, Kommentare und Pläne für das Vorantreiben der strategischen Leitlinien im Jahr 2016<a href="https://discourse.mozilla-community.org/t/mozillas-strategic-narrative-2016/6397"> hier</a> auf Discourse teilen und Ihre Gedanken auf Twitter mit dem Hashtag <a href="https://twitter.com/search?q=%23mozilla2016strategy&amp;src=typd">#Mozilla2016Strategy</a> mitteilen.</p> + <p> </p> + <h3>Mission, Vision &amp; Strategie</h3> + <p><b>Unsere Mission</b></p> + <p>Dafür zu sorgen, dass das Internet eine weltweite öffentliche Ressource ist, die allen zugänglich ist.</p> + <p><b>Unsere Vision</b></p> + <p>Ein Internet, für das Menschen tatsächlich an erster Stelle stehen. Ein Internet, in dem Menschen ihr eigenes Erlebnis gestalten können. Ein Internet, in dem die Menschen selbst entscheiden können sowie sicher und unabhängig sind.</p> + <p><b>Unsere Rolle</b></p> + <p>Mozilla setzt sich im wahrsten Sinne des Wortes in Ihrem Online-Leben für Sie ein. Wir setzen uns für Sie ein, sowohl in Ihrem Online-Erlebnis als auch für Ihre Interessen beim Zustand des Internets.</p> + <p><b>Unsere Arbeit</b></p> + <p>Unsere Säulen</p> + <ol> + <li><b>Produkte:</b> Wir entwickeln Produkte mit Menschen im Mittelpunkt sowie Bildungsprogramme, mit deren Hilfe Menschen online ihr gesamtes Potential ausschöpfen können.</li> + <li><b>Technologie:</b> Wir entwickeln robuste technische Lösungen, die das Internet über verschiedene Plattformen hinweg zum Leben erwecken.</li> + <li><b>Menschen:</b> Wir entwickeln Führungspersonen und Mitwirkende in der Gemeinschaft, die das Internet erfinden, gestalten und verteidigen.</li> + </ol> + <p>Wir wir positive Veränderungen in Zukunft anpacken wollen</p> + <p>Die Arbeitsweise ist ebensowichtig wie das Ziel. Unsere Gesundheit und bleibender Einfluss hängen davon ab, wie sehr unsere Produkte und Aktivitäten:</p> + <ol> + <li>Interoperabilität, Open Source und offene Standards fördern,</li> + <li>Gemeinschaften aufbauen und fördern,</li> + <li>Für politische Veränderungen und rechtlichen Schutz eintreten sowie</li> + <li>Netzbürger bilden und einbeziehen.</li> + </ol> + <p> </p> + <img alt="" height="0" src="http://piwik.michaelkohler.info/piwik.php?idsite=1&amp;rec=1&amp;url=https%3A%2F%2Fmichaelkohler.info%2F2016%2Fmozillas-strategische-leitlinien-fur-2016-und-danach&amp;action_name=Mozillas+strategische+Leitlinien+f%C3%BCr+2016+und+danach&amp;urlref=https%3A%2F%2Fmichaelkohler.info%2Ffeed" style="border: 0; width: 0; height: 0;" width="0" /> + Tue, 19 Jan 2016 15:27:24 +0000 + Michael Kohler + + + David Lawrence: happy bmo push day! + http://dlawrence.wordpress.com/?p=27 + https://dlawrence.wordpress.com/2016/01/19/happy-bmo-push-day-3/ + <p>the following changes have been pushed to bugzilla.mozilla.org:</p> + <ul> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1238573" target="_blank">1238573</a>] Change label of “New Bug” menu to “New/Clone Bug”</li> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1239065" target="_blank">1239065</a>] Project Kickoff Form: Adjustments needed to Mozilla Infosec review portion</li> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1240157" target="_blank">1240157</a>] Fix a typo in bug.rst</li> + <li>[<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1236461" target="_blank">1236461</a>] Mass update mozilla-reps group</li> + </ul> + <p>discuss these changes on <a href="https://lists.mozilla.org/listinfo/tools-bmo" target="_blank">mozilla.tools.bmo</a>.</p><br /> <a href="http://feeds.wordpress.com/1.0/gocomments/dlawrence.wordpress.com/27/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/dlawrence.wordpress.com/27/" /></a> <img alt="" border="0" height="1" src="https://pixel.wp.com/b.gif?host=dlawrence.wordpress.com&amp;blog=58816&amp;post=27&amp;subd=dlawrence&amp;ref=&amp;feed=1" width="1" /> + Tue, 19 Jan 2016 14:49:59 +0000 + dlawrence + + + Soledad Penades: Hardware Hack Day @ MozLDN, 1 + http://soledadpenades.com/?p=6335 + http://soledadpenades.com/2016/01/19/hardware-hack-day-mozldn-1/ + <p>Last week we ran an internal “hack day” here at the Mozilla space in London. It was just a bunch of <em>software</em> engineers looking at various <em>hardware</em> boards and things and learning about them <img alt=":-)" class="wp-smiley" src="http://soledadpenades.com/wp-includes/images/smilies/simple-smile.png" style="height: 1em;" /></p> + <p>Here’s what we did!</p> + <h3><a href="http://soledadpenades.com/">Sole</a></h3> + <p>I essentially <a href="http://soledadpenades.com/2016/01/19/kind-of-bricking-an-arduino-duemilanove-by-exhausting-its-memory/">kind of bricked my Arduino Duemilanove</a> trying to get it working with Johnny Five, but it was fine–apparently there’s a way to recover it using another Arduino, and someone offered to help with that in the next <a href="http://www.meetup.com/NodeBots-of-London/events/227890374/">NodeBots</a> London, which I’m going to attend.</p> + <h3><a href="http://ardeenelinfierno.com/">Francisco</a></h3> + <p>Thinks he’s having issues with cables. It seems like the boards are not reset automatically by the Arduino IDE nowadays? He found the button in the board actually resets the board when pressed i.e. it’s the RESET button.</p> + <p>On the Raspberry Pi side of things, he was very happy to put all his old-school Linux skills in action configuring network interfaces without GUIs!</p> + <h3><a href="http://gu.illau.me/">Guillaume</a></h3> + <p>Played with mDNS advertising and listening to services on Raspberry Pi.</p> + <p>(He was very quiet)</p> + <p>(He also built a very nice LEGO case for the Raspberry Pi, but I do not have a picture, so just imagine it).</p> + <h3><a href="http://wilsonpage.co.uk/">Wilson</a></h3> + <blockquote><p> + Wilson: “I got my Raspberry Pi on the Wi-Fi”</p> + <p>Francisco: “Sorry?”</p> + <p>Wilson: “I mean, you got my Raspberry Pi on the network. And now I’m trying to build a web app on the Pi…”</p></blockquote> + <h3><a href="http://chrislord.net/">Chris</a></h3> + <p>Exploring the Pebble with Linux. There’s a libpebble, and he managed to connect…</p> + <p><del datetime="2016-01-20T11:22:33+00:00"><em><small>(sorry, I had to leave early so I do not know what else did Chris do!)</small></em></del></p> + <p>Updated, 20 January: Chris told me he just managed to successfully connect to the Pebble watch using the bluetooth WebAPI. It requires two Gecko patches (one regression patch and one obvious logic error that he hasn’t filed yet). PROGRESS!</p> + <p>~~~</p> + <p>So as you can see we didn’t really get super far in just a day, and I even ended up with unusable hardware. BUT! we all learned something, and next time we know what NOT to do (or at least I DO KNOW what NOT to do!).</p> + <p><a href="http://soledadpenades.com/?flattrss_redirect&amp;id=6335&amp;md5=40427d69faa3b9c2d1530732fd78e66d" target="_blank" title="Flattr"><img alt="flattr this!" src="http://soledadpenades.com/wp-content/plugins/flattr/img/flattr-badge-large.png" /></a></p> + Tue, 19 Jan 2016 13:31:55 +0000 + sole + + + Daniel Stenberg: “Subject: Urgent Warning” + http://daniel.haxx.se/blog/?p=8544 + http://daniel.haxx.se/blog/2016/01/19/subject-urgent-warning/ + <p>Back in December I got a desperate email from this person. A woman who said her Instagram had been hacked and since she found my contact info in the app she mailed me and asked for help. I of course replied and said that I have nothing to do with her being hacked but I also have nothing to do with Instagram other than that they use software I’ve written.</p> + <p>Today she writes back. Clearly not convinced I told the truth before, and now she strikes back with more “evidence” of my wrongdoings.</p> + <p><em>Dear Daniel,</em></p> + <p><em>I had emailed you a couple months ago about my “screen dumps” aka screenshots and asked for your help with restoring my Instagram account since it had been hacked, my photos changed, and your name was included in the coding. You claimed to have no involvement whatsoever in developing a third party app for Instagram and could not help me salvage my original Instagram photos, pre-hacked, despite Instagram serving as my Photography portfolio and my career is a Photographer.</em></p> + <p><em>Since you weren’t aware that your name was attached to Instagram related hacking code, I thought you might want to know, in case you weren’t already aware, that your name is also included in Spotify terms and conditions. I came across this information using my Spotify which has also been hacked into and would love your help hacking out of Spotify. Also, I have yet to figure out how to unhack the hackers from my Instagram so if you change your mind and want to restore my Instagram to its original form as well as help me secure my account from future privacy breaches, I’d be extremely grateful. As you know, changing my passwords did nothing to resolve the problem. Please keep in mind that Facebook owns Instagram and these are big companies that you likely don’t want to have a trail of evidence that you are a part of an Instagram and Spotify hacking ring. Also, Spotify is a major partner of Spotify so you are likely familiar with the coding for all of these illegally developed third party apps. I’d be grateful for your help fixing this error immediately.</em></p> + <p><em>Thank you,</em></p> + <p>[name redacted]</p> + <p><em>P.S. Please see attached screen dump for a screen shot of your contact info included in Spotify (or what more likely seems to be a hacked Spotify developed illegally by a third party).</em></p> + <p><a href="http://daniel.haxx.se/blog/wp-content/uploads/2016/01/IMG_7393.png" rel="attachment wp-att-8545"><img alt="Spotify credits screenshot" class="aligncenter size-medium wp-image-8545" height="450" src="http://daniel.haxx.se/blog/wp-content/uploads/2016/01/IMG_7393-253x450.png" width="253" /></a></p> + <p>Here’s the Instagram screenshot she sent me in a previous email:</p> + <p><a href="http://daniel.haxx.se/blog/wp-content/uploads/2016/01/IMG_2156.jpg" rel="attachment wp-att-8546"><img alt="Instagram credits screenshot" class="aligncenter size-medium wp-image-8546" height="450" src="http://daniel.haxx.se/blog/wp-content/uploads/2016/01/IMG_2156-253x450.jpg" width="253" /></a></p> + <p>I’ve tried to respond with calm and clear reasonable logic and technical details on why she’s seeing my name there. That clearly failed. What do I try next?</p> + Tue, 19 Jan 2016 08:37:32 +0000 + Daniel Stenberg + + + Emily Dunham: How much knowledge do you need to give a conference talk? + http://edunham.net/2016/01/19/how_much_knowledge_do_you_need_to_give_a_conference_talk.html + http://edunham.net/2016/01/19/how_much_knowledge_do_you_need_to_give_a_conference_talk.html + <h3>How much knowledge do you need to give a conference talk?</h3> + <p>I was recently asked an excellent question when I promoted the <a class="reference external" href="http://www.linuxfestnorthwest.org/2016/present">LFNW CFP</a> on + IRC:</p> + <blockquote> + <div>As someone who has never done a talk, but wants to, what kind of knowledge + do you need about a subject to give a talk on it?</div></blockquote> + <p>If you answer “yes” to any of the following questions, you know enough to + propose a talk:</p> + <ul class="simple"> + <li>Do you have a <strong>hobby</strong> that most tech people aren’t experts on? Talk + about applying a lesson or skill from that hobby to tech! For instance, I + turned a habit of reading about psychology into my <a class="reference external" href="http://talks.edunham.net/scale13x/#1">Human Hacking</a> talk.</li> + <li>Have you ever spent a bunch of hours forcing two tools to work with each + other, because the documentation wasn’t very helpful and Googling didn’t get + you very far, and built something useful? “How to build ___ with ___” makes + a catchy talk title, if the <strong>thing you built</strong> solves a common problem.</li> + <li>Have you ever had a mentor sit down with you and explain a tool or + technique, and the new understanding improved the quality of your work or + code? Passing along useful <strong>lessons from your mentors</strong> is a valuable talk, + because it allows others to benefit from the knowledge without taking as + much of your mentor’s time.</li> + <li>Have you seen a dozen newbies ask the same question over the course of a few + months? When your <strong>answer to a common question</strong> starts to feel like a + broken record, it’s time to compose it into a talk then link the newbies to + your slides or recording!</li> + <li>Have you taken a really <strong>interesting class</strong> lately? Can you distill part of it + into a 1-hour lesson that would appeal to nerds who don’t have the time or + resources to take the class themselves? (thanks <a class="reference external" href="http://lucywyman.me/">lucyw</a> for adding this to + the list!)</li> + <li>Have you built a cool thing that over a dozen other people use? A <strong>tutorial + talk</strong> can not only expand your community, but its recording can augment your + documentation and make the project more accessible for those who prefer to + learn directly from humans!</li> + <li>Did you benefit from a really great introductory talk when you were learning + a tool? Consider doing your own tutorial! Any conference with beginners in + their target audience needs at least one Git lesson, an IRC talk, and some + discussions of how to use basic Unix utilities. These <strong>introductory talks</strong> + are actually better when given by someone who learned the technology + relatively recently, because newer users remember what it’s like not to know + how to use it. Just remember to have a more expert user look over your slides + before you present, in case you made an incorrect assumption about the tool’s + more advanced functionality.</li> + </ul> + <p>I personally try to propose talks I want to hear, because the dealine of a + CFP or conference is great motivation to prioritize a cool project over + ordinary chores.</p> + Tue, 19 Jan 2016 08:00:00 +0000 + + + QMO: Aurora 45.0 Testday Results + https://quality.mozilla.org/?p=49441 + https://quality.mozilla.org/2016/01/aurora-45-0-testday-results/ + <p>Howdy mozillians!</p> + <p>Last week – on <em>Friday, January 15th</em> – we held <a href="https://quality.mozilla.org/2016/01/firefox-45-0-aurora-testday-january-15th/">Aurora 45.0 Testday</a>; and, of course, it was another outstanding event!</p> + <p><strong>Thank you</strong> all – <span class="author-a-oz90z4z89zz89za7qfz70zda5z87zxz85z i"><i>Mahmoudi Dris, Iryna Thompson, Chandrakant Dhutadmal, Preethi Dhinesh, Moin Shaikh, Ilse Macías, Hossain Al Ikram, Rezaul Huque Nayeem, Tahsan Chowdhury Akash, Kazi Nuzhat Tasnem, Fahmida Noor, Tazin Ahmed, Md. Ehsanul Hassan, Mohammad Maruf Islam, Kazi Sakib Ahmad, Khalid Syfullah Zaman, Asiful Kabir, Tabassum Mehnaz, Hasibul Hasan, Saddam Hossain, Mohammad Kamran Hossain, Amlan Biswas, Fazle Rabbi, Mohammed Jawad Ibne Ishaque, Asif Mahmud Shuvo, Nazir Ahmed Sabbir, Md. Raihan Ali, Md. Almas Hossain, Sadik Khan, Md. Faysal Alam Riyad, Faisal Mahmud, Md. Oliullah Sizan, Asif Mahmud Rony, Forhad Hossain </i>and<i> Tanvir Rahman </i></span>– for the participation!</p> + <p>A big <strong>thank you</strong> to all our active moderators too!</p> + <p><span style="color: #333333;"><span style="font-family: 'Open Sans', sans-serif;"><span style="font-size: medium;"><u>Results:</u></span></span></span></p> + <ul> + <li><span style="color: #333333;"><span style="font-family: 'Open Sans', sans-serif;"><span style="font-size: medium;"><strong>15</strong> issues were verified: </span></span></span><span style="color: #333333;"><span style="font-family: 'Open Sans', sans-serif;"><span style="font-size: medium;"> <span style="font-weight: 400;"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1235821">1235821</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1228518">1228518</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1165637">1165637</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1232647">1232647</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1235379">1235379</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=842356">842356</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1222971">1222971</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=915962">915962</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1180761">1180761</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1218455">1218455</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1222747">1222747</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1210752">1210752</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1198450">1198450</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1222820">1222820</a>, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1225514">1225514</a></span></span></span></span></li> + <li><strong>1</strong> bug was triaged: <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1230789"><span style="font-weight: 400;">1230789</span></a></li> + <li>some failures were mentioned for <i>Search Refactoring </i>feature in the etherpads (<a href="https://public.etherpad-mozilla.org/p/testday-20160115">link 1</a> and <a href="https://public.etherpad-mozilla.org/p/bangladesh.testday-15012016">link 2</a>); please feel free to add the requested details in the etherpads or, even better, join us on <a href="http://widget01.mibbit.com/?server=irc.mozilla.org&amp;channel=%23qa" target="_blank">#qa IRC channel</a> and let’s figure them out</li> + </ul> + <p>I <strong>strongly</strong> advise everyone of you to reach out to us, the moderators, via <a href="http://widget01.mibbit.com/?server=irc.mozilla.org&amp;channel=%23qa">#qa</a> during the events when you encountered any kind of failures. Keep up the great work! \o/</p> + <p>And keep an eye on QMO for upcoming events! <img alt="😉" class="wp-smiley" src="https://s.w.org/images/core/emoji/72x72/1f609.png" style="height: 1em;" /></p> + Tue, 19 Jan 2016 07:51:57 +0000 + Alexandra Lucinet + + + Eitan Isaacson: It’s MLK Day and It’s Not Too Late to Do Something About It + http://blog.monotonous.org/?p=678 + http://blog.monotonous.org/2016/01/18/its-mlk-day-and-its-not-too-late-to-do-something-about-it/ + <p>For the last three years I have had the opportunity to send out a reminder to Mozilla staff that Martin Luther King Jr. Day is coming up, and that U.S. employees get the day off. It has turned into my MLK Day eve ritual. I read his letters, listen to speeches, and then I compose a belabored paragraph about Dr. King with some choice quotes.</p> + <p>If you didn’t get a chance to celebrate Dr. King’s legacy and the movements he was a part of, you still have a chance:</p> + <ul> + <li>Watch <a href="http://www.imdb.com/title/tt1020072/" target="_blank">Selma.</a></li> + <li>Watch <a href="http://www.imdb.com/title/tt1592527/" target="_blank">The Black Power Mixtape</a> (it’s on Netflix).</li> + <li>Read <a href="http://www.africa.upenn.edu/Articles_Gen/Letter_Birmingham.html" target="_blank">A Letter from a Birmingham Jail</a> (it’s really really good).</li> + <li>Listen to his speech <a href="https://www.youtube.com/watch?v=3Qf6x9_MLD0" target="_blank">Beyond Vietnam</a>.</li> + <li>Listen to his last speech <a href="https://www.youtube.com/watch?v=IDl84vusXos" target="_blank">I Have Been To The Mountaintop</a>.</li> + </ul><br /> <a href="http://feeds.wordpress.com/1.0/gocomments/blogdotmonotonousdotorg.wordpress.com/678/" rel="nofollow"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogdotmonotonousdotorg.wordpress.com/678/" /></a> <img alt="" border="0" height="1" src="http://pixel.wp.com/b.gif?host=blog.monotonous.org&amp;blog=34885741&amp;post=678&amp;subd=blogdotmonotonousdotorg&amp;ref=&amp;feed=1" width="1" /> + Mon, 18 Jan 2016 23:35:19 +0000 + Eitan + + + Nick Cameron: Libmacro + http://www.ncameron.org/blog/rss/0e4d587c-380c-40ce-954a-7206f69bc1dd + http://www.ncameron.org/blog/libmacro/ + <p>As I outlined in an <a href="http://ncameron.org/blog/procedural-macros-framework/">earlier post</a>, libmacro is a new crate designed to be used by procedural macro authors. It provides the basic API for procedural macros to interact with the compiler. I expect higher level functionality to be provided by library crates. In this post I'll go into a bit more detail about the API I think should be exposed here.</p> + + <p>This is a lot of stuff. I've probably missed something. If you use syntax extensions today and do something with libsyntax that would not be possible with libmacro, please let me know!</p> + + <p>I previously introduced <code>MacroContext</code> as one of the gateways to libmacro. All procedural macros will have access to a <code>&amp;mut MacroContext</code>.</p> + + <h3>Tokens</h3> + + <p>I described the <code>tokens</code> module in the last post, I won't repeat that here.</p> + + <p>There are a few more things I thought of. I mentioned a <code>TokenStream</code> which is a sequence of tokens. We should also have <code>TokenSlice</code> which is a borrowed slice of tokens (the slice to <code>TokenStream</code>'s <code>Vec</code>). These should implement the standard methods for sequences, in particular they support iteration, so can be <code>map</code>ed, etc.</p> + + <p>In the earlier blog post, I talked about a token kind called <code>Delimited</code> which contains a delimited sequence of tokens. I would like to rename that to <code>Sequence</code> and add a <code>None</code> variant to the <code>Delimiter</code> enum. The <code>None</code> option is so that we can have blocks of tokens without using delimiters. It will be used for noting unsafety and other properties of tokens. Furthermore, it is useful for macro expansion (replacing the interpolated AST tokens currently present). Although <code>None</code> blocks do not affect scoping, they do affect precedence and parsing.</p> + + <p>We should provide API for creating tokens. By default these have no hygiene information and come with a span which has no place in the source code, but shows the source of the token to be the procedural macro itself (see below for how this interacts with expansion of the current macro). I expect a <code>make_</code> function for each kind of token. We should also have API for creating macros in a given scope (which do the same thing but with provided hygiene information). This could be considered an over-rich API, since the hygiene information could be set after construction. However, since hygiene is fiddly and annoying to get right, we should make it as easy as possible to work with.</p> + + <p>There should also be a function for creating a token which is just a fresh name. This is useful for creating new identifiers. Although this can be done by interning a string and then creating a token around it, it is used frequently enough to deserve a helper function.</p> + + <h3>Emitting errors and warnings</h3> + + <p>Procedural macros should report errors, warnings, etc. via the <code>MacroContext</code>. They should avoid panicking as much as possible since this will crash the compiler (once <code>catch_panic</code> is available, we should use it to catch such panics and exit gracefully, however, they will certainly still meaning aborting compilation).</p> + + <p>Libmacro will 're-export' <code>DiagnosticBuilder</code> from <a href="https://dxr.mozilla.org/rust/source/src/libsyntax/errors/mod.rs">syntax::errors</a>. I don't actually expect this to be a literal re-export. We will use libmacro's version of <code>Span</code>, for example.</p> + + <pre><code>impl MacroContext { + pub fn struct_error(&amp;self, &amp;str) -&gt; DiagnosticBuilder; + pub fn error(&amp;self, Option&lt;Span&gt;, &amp;str); + } + + pub mod errors { + pub struct DiagnosticBuilder { ... } + impl DiagnosticBuilder { ... } + pub enum ErrorLevel { ... } + } + </code></pre> + + <p>There should be a macro <code>try_emit!</code>, which reduces a <code>Result&lt;T, ErrStruct&gt;</code> to a T or calls <code>emit()</code> and then calls <code>unreachable!()</code> (if the error is not fatal, then it should be upgraded to a fatal error).</p> + + <h3>Tokenising and quasi-quoting</h3> + + <p>The simplest function here is <code>tokenize</code> which takes a string (<code>&amp;str</code>) and returns a <code>Result&lt;TokenStream, ErrStruct&gt;</code>. The string is treated like source text. The success option is the tokenised version of the string. I expect this function must take a <code>MacroContext</code> argument.</p> + + <p>We will offer a quasi-quoting macro. This will return a <code>TokenStream</code> (in contrast to today's quasi-quoting which returns AST nodes), to be precise a <code>Result&lt;TokenStream, ErrStruct&gt;</code>. The string which is quoted may include metavariables (<code>$x</code>), and these are filled in with variables from the environment. The type of the variables should be either a <code>TokenStream</code>, a <code>TokenTree</code>, or a <code>Result&lt;TokenStream, ErrStruct&gt;</code> (in this last case, if the variable is an error, then it is just returned by the macro). For example,</p> + + <pre><code>fn foo(cx: &amp;mut MacroContext, tokens: TokenStream) -&gt; TokenStream { + quote!(cx, fn foo() { $tokens }).unwrap() + } + </code></pre> + + <p>The <code>quote!</code> macro can also handle multiple tokens when the variable corresponding with the metavariable has type <code>[TokenStream]</code> (or is dereferencable to it). In this case, the same syntax as used in macros-by-example can be used. For example, if <code>x: Vec&lt;TokenStream&gt;</code> then <code>quote!(cx, ($x),*)</code> will produce a <code>TokenStream</code> of a comma-separated list of tokens from the elements of <code>x</code>.</p> + + <p>Since the <code>tokenize</code> function is a degenerate case of quasi-quoting, an alternative would be to always use <code>quote!</code> and remove <code>tokenize</code>. I believe there is utility in the simple function, and it must be used internally in any case.</p> + + <p>These functions and macros should create tokens with spans and hygiene information set as described above for making new tokens. We might also offer versions which takes a scope and uses that as the context for tokenising.</p> + + <h3>Parsing helper functions</h3> + + <p>There are some common patterns for tokens to follow in macros. In particular those used as arguments for attribute-like macros. We will offer some functions which attempt to parse tokens into these patterns. I expect there will be more of these in time; to start with:</p> + + <pre><code>pub mod parsing { + // Expects `(foo = "bar"),*` + pub fn parse_keyed_values(&amp;TokenSlice, &amp;mut MacroContext) -&gt; Result&lt;Vec&lt;(InternedString, String)&gt;, ErrStruct&gt;; + // Expects `"bar"` + pub fn parse_string(&amp;TokenSlice, &amp;mut MacroContext) -&gt; Result&lt;String, ErrStruct&gt;; + } + </code></pre> + + <p>To be honest, given the token design in the last post, I think <code>parse_string</code> is unnecessary, but I wanted to give more than one example of this kind of function. If <code>parse_keyed_values</code> is the only one we end up with, then that is fine.</p> + + <h3>Pattern matching</h3> + + <p>The goal with the pattern matching API is to allow procedural macros to operate on tokens in the same way as macros-by-example. The pattern language is thus the same as that for macros-by-example.</p> + + <p>There is a single macro, which I propose calling <code>matches</code>. Its first argument is the name of a <code>MacroContext</code>. Its second argument is the input, which must be a <code>TokenSlice</code> (or dereferencable to one). The third argument is a pattern definition. The macro produces a <code>Result&lt;T, ErrStruct&gt;</code> where <code>T</code> is the type produced by the pattern arms. If the pattern has multiple arms, then each arm must have the same type. An error is produced if none of the arms in the pattern are matched.</p> + + <p>The pattern language follows the language for defining macros-by-example (but is slightly stricter). There are two forms, a single pattern form and a multiple pattern form. If the first character is a <code>{</code> then the pattern is treated as a multiple pattern form, if it starts with <code>(</code> then as a single pattern form, otherwise an error (causes a panic with a <code>Bug</code> error, as opposed to returning an <code>Err</code>).</p> + + <p>The single pattern form is <code>(pattern) =&gt; { code }</code>. The multiple pattern form is <code>{(pattern) =&gt; { code } (pattern) =&gt; { code } ... (pattern) =&gt; { code }}</code>. <code>code</code> is any old Rust code which is executed when the corresponding pattern is matched. The pattern follows from macros-by-example - it is a series of characters treated as literals, meta-variables indicated with <code>$</code>, and the syntax for matching multiple variables. Any meta-variables are available as variables in the righthand side, e.g., <code>$x</code> becomes available as <code>x</code>. These variables have type <code>TokenStream</code> if they appear singly or <code>Vec&lt;TokenStream&gt;</code> if they appear multiply (or <code>Vec&lt;Vec&lt;TokenStream&gt;&gt;</code> and so forth).</p> + + <p>Examples:</p> + + <pre><code>matches!(cx, input, (foo($x:expr) bar) =&gt; {quote(cx, foo_bar($x).unwrap()}).unwrap() + + matches!(cx, input, { + () =&gt; { + cx.err("No input?"); + } + (foo($($x:ident),+ bar) =&gt; { + println!("found {} idents", x.len()); + quote!(($x);*).unwrap() + } + } + }) + </code></pre> + + <p>Note that since we match AST items here, our backwards compatibility story is a bit complicated (though hopefully not much more so than with current macros).</p> + + <h3>Hygiene</h3> + + <p>The intention of the design is that the actual hygiene algorithm applied is irrelevant. Procedural macros should be able to use the same API if the hygiene algorithm changes (of course the result of applying the API might change). To this end, all hygiene objects are opaque and cannot be directly manipulated by macros.</p> + + <p>I propose one module (<code>hygiene</code>) and two types: <code>Context</code> and <code>Scope</code>.</p> + + <p>A <code>Context</code> is attached to each token and contains all hygiene information about that token. If two tokens have the same <code>Context</code>, then they may be compared syntactically. The reverse is not true - two tokens can have different <code>Context</code>s and still be equal. <code>Context</code>s can only be created by applying the hygiene algorithm and cannot be manipulated, only moved and stored.</p> + + <p><code>MacroContext</code> has a method <code>fresh_hygiene_context</code> for creating a new, fresh <code>Context</code> (i.e., a <code>Context</code> not shared with any other tokens).</p> + + <p><code>MacroContext</code> has a method <code>expansion_hygiene_context</code> for getting the <code>Context</code> where the macro is defined. This is equivalent to <code>.expansion_scope().direct_context()</code>, but might be more efficient (and I expect it to be used a lot).</p> + + <p>A <code>Scope</code> provides information about a position within an AST at a certain point during macro expansion. For example,</p> + + <pre><code>fn foo() { + a + { + b + c + } + } + </code></pre> + + <p><code>a</code> and <code>b</code> will have different <code>Scope</code>s. <code>b</code> and <code>c</code> will have the same <code>Scope</code>s, even if <code>b</code> was written in this position and <code>c</code> is due to macro expansion. However, a <code>Scope</code> may contain more information than just the syntactic scopes, for example, it may contain information about pending scopes yet to be applied by the hygiene algorithm (i.e., information about <code>let</code> expressions which are in scope).</p> + + <p>Note that a <code>Scope</code> means a scope in the macro hygiene sense, not the commonly used sense of a scope declared with <code>{}</code>. In particular, each <code>let</code> statement starts a new scope and the items and statements in a function body are in different scopes.</p> + + <p>The functions <code>lookup_item_scope</code> and <code>lookup_statement_scope</code> take a <code>MacroContext</code> and a path, represented as a <code>TokenSlice</code>, and return the <code>Scope</code> which that item defines or an error if the path does not refer to an item, or the item does not define a scope of the right kind.</p> + + <p>The function <code>lookup_scope_for</code> is similar, but returns the <code>Scope</code> in which an item is declared.</p> + + <p><code>MacroContext</code> has a method <code>expansion_scope</code> for getting the scope in which the current macro is being expanded.</p> + + <p><code>Scope</code> has a method <code>direct_context</code> which returns a <code>Context</code> for items declared directly (c.f., via macro expansion) in that <code>Scope</code>.</p> + + <p><code>Scope</code> has a method <code>nested</code> which creates a fresh <code>Scope</code> nested within the receiver scope.</p> + + <p><code>Scope</code> has a static method <code>empty</code> for creating an empty scope, that is one with no scope information at all (note that this is different from a top-level scope).</p> + + <p>I expect the exact API around <code>Scope</code>s and <code>Context</code>s will need some work. <code>Scope</code> seems halfway between an intuitive, algorithm-neutral abstraction, and the scopes from the sets of scopes hygiene algorithm. I would prefer a <code>Scope</code> should be more abstract, on the other hand, macro authors may want fine-grained control over hygiene application.</p> + + <h4>Manipulating hygiene information on tokens,</h4> + + <pre><code>pub mod hygiene { + pub fn add(cx: &amp;mut MacroContext, t: &amp;Token, scope: &amp;Scope) -&gt; Token; + // Maybe unnecessary if we have direct access to Tokens. + pub fn set(t: &amp;Token, cx: &amp;Context) -&gt; Token; + // Maybe unnecessary - can use set with cx.expansion_hygiene_context(). + // Also, bad name. + pub fn current(cx: &amp;MacroContext, t: &amp;Token) -&gt; Token; + } + </code></pre> + + <p><code>add</code> adds <code>scope</code> to any context already on <code>t</code> (<code>Context</code> should have a similar method). Note that the implementation is a bit complex - the nature of the <code>Scope</code> might mean we replace the old context completely, or add to it.</p> + + <h4>Applying hygiene when expanding the current macro</h4> + + <p>By default, the current macro will be expanded in the standard way, having hygiene applied as expected. Mechanically, hygiene information is added to tokens when the macro is expanded. Assuming the sets of scopes algorithm, scopes (for example, for the macro's definition, and for the introduction) are added to any scopes already present on the token. A token with no hygiene information will thus behave like a token in a macro-by-example macro. Hygiene due to nested scopes created by the macro do not need to be taken into account by the macro author, this is handled at expansion time.</p> + + <p>Procedural macro authors may want to customise hygiene application (it is common in Racket), for example, to introduce items that can be referred to by code in the call-site scope.</p> + + <p>We must provide an option to expand the current macro without applying hygiene; the macro author must then handle hygiene. For this to work, the macro must be able to access information about the scope in which it is applied (see <code>MacroContext::expansion_scope</code>, above) and to supply a <code>Scope</code> indicating scopes that should be added to tokens following the macro expansion.</p> + + <pre><code>pub mod hygiene { + pub enum ExpansionMode { + Automatic, + Manual(Scope), + } + } + + impl MacroContext { + pub fn set_hygienic_expansion(hygiene::ExpansionMode); + } + </code></pre> + + <p>We may wish to offer other modes for expansion which allow for tweaking hygiene application without requiring full manual application. One possible mode is where the author provides a <code>Scope</code> for the macro definition (rather than using the scope where the macro is actually defined), but hygiene is otherwise applied automatically. We might wish to give the author the option of applying scopes due to the macro definition, but not the introduction scopes.</p> + + <p>On a related note, might we want to affect how spans are applied when the current macro is expanded? I can't think of a use case right now, but it seems like something that might be wanted.</p> + + <p>Blocks of tokens (that is a <code>Sequence</code> token) may be marked (not sure how, exactly, perhaps using a distinguished context) such that it is expanded without any hygiene being applied or spans changed. There should be a function for creating such a <code>Sequence</code> from a <code>TokenSlice</code> in the <code>tokens</code> module. The primary motivation for this is to handle the tokens representing the body on which an annotation-like macro is present. For a 'decorator' macro, these tokens will be untouched (passed through by the macro), and since they are not touched by the macro, they should appear untouched by it (in terms of hygiene and spans).</p> + + <h3>Applying macros</h3> + + <p>We provide functionality to expand a provided macro or to lookup and expand a macro.</p> + + <pre><code>pub mod apply { + pub fn expand_macro(cx: &amp;mut MacroContext, + expansion_scope: Scope, + macro: &amp;TokenSlice, + macro_scope: Scope, + input: &amp;TokenSlice) + -&gt; Result&lt;(TokenStream, Scope), ErrStruct&gt;; + pub fn lookup_and_expand_macro(cx: &amp;mut MacroContext, + expansion_scope: Scope, + macro: &amp;TokenSlice, + input: &amp;TokenSlice) + -&gt; Result&lt;(TokenStream, Scope), ErrStruct&gt;; + } + </code></pre> + + <p>These functions apply macro hygiene in the usual way, with <code>expansion_scope</code> dictating the scope into which the macro is expanded. Other spans and hygiene information is taken from the tokens. <code>expand_macro</code> takes pending scopes from <code>macro_scope</code>, <code>lookup_and_expand_macro</code> uses the proper pending scopes. In order to apply the hygiene algorithm, the result of the macro must be parsable. The returned scope will contain pending scopes that can be applied by the macro to subsequent tokens.</p> + + <p>We could provide versions that don't take an <code>expansion_scope</code> and use <code>cx.expansion_scope()</code>. Probably unnecessary.</p> + + <pre><code>pub mod apply { + pub fn expand_macro_unhygienic(cx: &amp;mut MacroContext, + macro: &amp;TokenSlice, + input: &amp;TokenSlice) + -&gt; Result&lt;TokenStream, ErrStruct&gt;; + pub fn lookup_and_expand_macro_unhygienic(cx: &amp;mut MacroContext, + macro: &amp;TokenSlice, + input: &amp;TokenSlice) + -&gt; Result&lt;TokenStream, ErrStruct&gt;; + } + </code></pre> + + <p>The <code>_unhygienic</code> variants expand a macro as in the first functions, but do not apply the hygiene algorithm or change any hygiene information. Any hygiene information on tokens is preserved. I'm not sure if <code>_unhygienic</code> are the right names - using these is not necessarily unhygienic, just that we are automatically applying the hygiene algorithm.</p> + + <p>Note that all these functions are doing an eager expansion of macros, or in Scheme terms they are <code>local-expand</code> functions. </p> + + <h3>Looking up items</h3> + + <p>The function <code>lookup_item</code> takes a <code>MacroContext</code> and a path represented as a <code>TokenSlice</code> and returns a <code>TokenStream</code> for the item referred to by the path, or an error if name resolution failed. I'm not sure where this function should live.</p> + + <h3>Interned strings</h3> + + <pre><code>pub mod strings { + pub struct InternedString; + + impl InternedString { + pub fn get(&amp;self) -&gt; String; + } + + pub fn intern(cx: &amp;mut MacroContext, s: &amp;str) -&gt; Result&lt;InternedString, ErrStruct&gt;; + pub fn find(cx: &amp;mut MacroContext, s: &amp;str) -&gt; Result&lt;InternedString, ErrStruct&gt;; + pub fn find_or_intern(cx: &amp;mut MacroContext, s: &amp;str) -&gt; Result&lt;InternedString, ErrStruct&gt;; + } + </code></pre> + + <p><code>intern</code> interns a string and returns a fresh <code>InternedString</code>. <code>find</code> tries to find <em>an</em> existing <code>InternedString</code>.</p> + + <h3>Spans</h3> + + <p>A span gives information about where in the source code a token is defined. It also gives information about where the token came from (how it was generated, if it was generated code).</p> + + <p>There should be a <code>spans</code> module in libmacro, which will include a <code>Span</code> type which can be easily inter-converted with the <code>Span</code> defined in libsyntax. Libsyntax spans currently include information about stability, this will not be present in libmacro spans.</p> + + <p>If the programmer does nothing special with spans, then they will be 'correct' by default. There are two important cases: tokens passed to the macro and tokens made fresh by the macro. The former will have the source span indicating where they were written and will include their history. The latter will have no source span and indicate they were created by the current macro. All tokens will have the history relating to expansion of the current macro added when the macro is expanded. At macro expansion, tokens with no source span will be given the macro use-site as their source.</p> + + <p><code>Span</code>s can be freely copied between tokens.</p> + + <p>It will probably useful to make it easy to manipulate spans. For example, rather than point at the macro's defining function, point at a helper function where the token is made. Or to set the origin to the current macro when the token was produced by another which should an implementation detail. I'm not sure what such an interface should look like (and is probably not necessary in an initial library).</p> + + <h3>Feature gates</h3> + + <pre><code>pub mod features { + pub enum FeatureStatus { + // The feature gate is allowed. + Allowed, + // The feature gate has not been enabled. + Disallowed, + // Use of the feature is forbidden by the compiler. + Forbidden, + } + + pub fn query_feature(cx: &amp;MacroContext, feature: Token) -&gt; Result&lt;FeatureStatus, ErrStruct&gt;; + pub fn query_feature_by_str(cx: &amp;MacroContext, feature: &amp;str) -&gt; Result&lt;FeatureStatus, ErrStruct&gt;; + pub fn query_feature_unused(cx: &amp;MacroContext, feature: Token) -&gt; Result&lt;FeatureStatus, ErrStruct&gt;; + pub fn query_feature_by_str_unused(cx: &amp;MacroContext, feature: &amp;str) -&gt; Result&lt;FeatureStatus, ErrStruct&gt;; + + pub fn used_feature_gate(cx: &amp;MacroContext, feature: Token) -&gt; Result&lt;(), ErrStruct&gt;; + pub fn used_feature_by_str(cx: &amp;MacroContext, feature: &amp;str) -&gt; Result&lt;(), ErrStruct&gt;; + + pub fn allow_feature_gate(cx: &amp;MacroContext, feature: Token) -&gt; Result&lt;(), ErrStruct&gt;; + pub fn allow_feature_by_str(cx: &amp;MacroContext, feature: &amp;str) -&gt; Result&lt;(), ErrStruct&gt;; + pub fn disallow_feature_gate(cx: &amp;MacroContext, feature: Token) -&gt; Result&lt;(), ErrStruct&gt;; + pub fn disallow_feature_by_str(cx: &amp;MacroContext, feature: &amp;str) -&gt; Result&lt;(), ErrStruct&gt;; + } + </code></pre> + + <p>The <code>query_*</code> functions query if a feature gate has been set. They return an error if the feature gate does not exist. The <code>_unused</code> variants do not mark the feature gate as used. The <code>used_</code> functions mark a feature gate as used, or return an error if it does not exist.</p> + + <p>The <code>allow_</code> and <code>disallow_</code> functions set a feature gate as allowed or disallowed for the current crate. These functions will only affect feature gates which take affect after parsing and expansion are complete. They do not affect feature gates which are checked during parsing or expansion.</p> + + <p>Question: do we need the <code>used_</code> functions? Could just call <code>query_</code> and ignore the result.</p> + + <h3>Attributes</h3> + + <p>We need some mechanism for setting attributes as used. I don't actually know how the unused attribute checking in the compiler works, so I can't spec this area. But, I expect <code>MacroContext</code> to make available some interface for reading attributes on a macro use and marking them as used.</p> + Mon, 18 Jan 2016 21:40:42 +0000 + Nick Cameron + + + Seif Lotfy: Skizze progress and REPL + http://geekyogre.com/rss/63eb682d-66b4-447d-8fb6-f4ed448019df + http://geekyogre.com/skizze-progress-and-repl/ + <p><img align="center" height="190" src="http://i.imgur.com/9z47NdA.png" width="600" /> <br /> + <br /> <br /> + Over the last 3 weeks, based on feedback we proceeded fledging out the concepts and the code behind <a href="https://github.com/skizzehq/skizze">Skizze</a>. <br /> + <a href="https://medium.com/@njpatel/">Neil Patel</a> suggested the following:</p> + + <hr /> + + <p><em>So I've been thinking about the server API. I think we want to choose one thing and do it as well as possible, instead of having six ways to talk to the server. I think that helps to keep things sane and simple overall.</em></p> + + <p><em>Thinking about usage, I can only really imagine Skizze in an environment like <a href="https://xamarin.com/insights">ours</a>, which is high-throughput. I think that is it's 'home' and we should be optimising for that all day long.</em></p> + + <p><em>Taking that into account, I believe we have two options:</em></p> + + <ol> + <li><p><em>We go the gRPC route, provide .proto files and let people use the existing gRPC tooling to build support for their favourite language. That means we can happily give Ruby/Node/C#/etc devs a real way to get started up with Skizze almost immediately, piggy-backing on the gRPC docs etc.</em></p></li> + <li><p><em>We absorb the Redis Protocol. It does everything we need, is very lean, and we can (mostly) easily adapt it for what we need to do. The downside is that to get support from other libs, there will have to be actual libraries for every language. This could slow adoption, or it might be easy enough if people can reuse existing REDIS code. It's hard to tell how that would end up.</em></p></li> + </ol> + + <p><em>gRPC is interesting because it's built already for distributed systems, across bad networks, and obviously is bi-directional etc. Without us having to spend time on the protocol, gRPC let's us easily add features that require streaming. Like, imagine a client being able to listen for changes in count/size and be notified instantly. That's something that gRPC is built for right now.</em></p> + + <p><em>I think gRPC is a bit verbose, but I think it'll pay off for ease of third-party lib support and as things grow.</em></p> + + <p><em>The CLI could easily be built to work with gRPC, including adding support for streaming stuff etc. Which could be pretty exciting.</em></p> + + <hr /> + + <p>That being said, we gave Skizze <a href="https://github.com/skizzehq/">a new home</a>, where based on feedback we developed .proto files and started rewriting big chunks of the code.</p> + + <p>We added a new wrapper called "domain" which represents a stream. It wraps around Count-Min-Log, Bloom Filter, Top-K and HyperLogLog++, so when feeding it values it feeds all the sketches. Later we intend to allow attaching and detaching sketches from "domains" (We need a better name).</p> + + <p>We also implemented a gRPC API which should allow easy wrapper creation in other languages.</p> + + <p>Special thanks go to <a href="https://twitter.com/martinpintob">Martin Pinto</a> for helping out with unit tests and <a href="http://dopeness.org">Soren Macbeth</a> for thorough feedback and ideas about the "domain" concept. <br /> + Take a look at our initial REPL work there:</p> + + <p><a href="http://geekyogre.com/content/images/2016/01/MBCY64aaKL.gif"><img alt="Link to this page" border="0" src="http://geekyogre.com/content/images/2016/01/skizze-1.png" /></a> <br /> + <a href="http://geekyogre.com/content/images/2016/01/MBCY64aaKL.gif">click for GIF</a></p> + Mon, 18 Jan 2016 17:41:43 +0000 + Seif Lotfy + + + Doug Belshaw: What a post-Persona landscape means for Open Badges + http://dougbelshaw.com/blog/?p=39986 + http://dougbelshaw.com/blog/2016/01/18/open-badges-persona/ + <p><em><strong>Note:</strong> I don’t work for Mozilla any more, so (like <a href="https://www.youtube.com/watch?v=YQHsXMglC9A">Adele</a>) these are my thoughts ‘from the outside’…</em></p> + <hr /> + <h3>Introduction</h3> + <p><a href="http://openbadges.org">Open Badges</a> is no longer a <a href="http://mozilla.org">Mozilla</a> project. In fact, it hasn’t been for a while — the <a href="http://badgealliance.org">Badge Alliance</a> was set up a couple of years ago to promote the specification on a both a technical and community basis. As I stated in a recent post, this is a <strong>good</strong> thing and means that <a href="http://dougbelshaw.com/blog/2015/11/08/bright-future-badges/">the future is bright for Open Badges</a>.</p> + <p>However, Mozilla <em>is</em> still involved with the Open Badges project: Mark Surman, Executive Director of the Mozilla Foundation, sits on the board of the Badge Alliance. Mozilla also pays for contractors to work on the <a href="http://backpack.openbadges.org">Open Badges backpack</a> and there were badges earned at the <a href="http://mozillafestival.org">Mozilla Festival</a> a few months ago.</p> + <p>Although it may seem strange for those used to corporates interested purely in profit, Mozilla creates what the open web needs at any given time. Like any organisation, sometimes it gets these wrong, either because the concept was flawed, or because the execution was poor. Other times, I’d argue, Mozilla doesn’t give ideas and concepts enough time to gain traction.</p> + <h3>The end of Persona at Mozilla</h3> + <p>Open Badges, at its very essence, is a technical specification. It allows credentials with metadata hard-coded into them to be issued, exchanged, and displayed. This is done in a secure, standardised manner.</p> + <p><img alt="OBI diagram" class="alignnone wp-image-39987 size-full" src="http://i1.wp.com/dougbelshaw.com/blog/wp-content/uploads/2016/01/obi-diagram.png?w=100%25" /></p> + <p>For users to be able to access their ‘backpack’ (i.e. the place they store badges) they needed a secure login system.Back in 2011 at the start of the Open Badges project it made sense to make use of Mozilla’s nascent <a href="https://www.mozilla.org/en-US/persona/">Persona</a> project. This aimed to provide a way for users to easily sign into sites around the web without using their Facebook/Google logins. These ‘social’ sign-in methods mean that users are tracked around the web — something that Mozilla was obviously against.</p> + <p>By 2014, Persona wasn’t seen to be having the kind of ‘growth trajectory’ that Mozilla wanted. The project was transferred to <a href="http://identity.mozilla.com/post/78873831485/transitioning-persona-to-community-ownership">community ownership</a> and most of the team left Mozilla in 2015. It was <a href="https://groups.google.com/forum/#!msg/mozilla.dev.identity/mibOQrD6K0c/kt0NdMWbEQAJ">announced</a> that Persona would be shutting down as a Mozilla service in November 2016. While Persona will exist as an open source project, it won’t be hosted by Mozilla.</p> + <h3>What this means for Open Badges</h3> + <p>Although I’m not aware of an official announcement from the Badge Alliance, I think it’s worth making three points here.</p> + <h5>1. You can still use Persona</h5> + <p>If you’re a developer, you can still use Persona. It’s open source. It works.</p> + <h5>2. Persona is not central to the Open Badges Infrastructure</h5> + <p>The Open Badges backpack is <em>one</em> place where users can store their badges. There are others, including the <a href="https://openbadgepassport.com/">Open Badge Passport</a> and <a href="https://www.openbadgeacademy.com/">Open Badge Academy</a>. MacArthur, who seed-funded the Open Badges ecosystem, have a new platform launching through <a href="https://www.lrng.org/">LRNG</a>.</p> + <p>It is up to the organisations behind these various solutions as to how they allow users to authenticate. They may choose to allow social logins. They may force users to create logins based on their email address. They may decide to use an open source version of Persona. It’s entirely up to them.</p> + <h5>3. A post-Persona badges system has its advantages</h5> + <p>The Persona authentication system runs off email addresses. This means that transitioning <em>from</em> Persona to another system is relatively straightforward. It has, however, meant that for the past few years we’ve had a recurrent problem: what do you do with people being issued badges to multiple email addresses?</p> + <p>Tying badges to emails seemed like the easiest and fastest way to get to a critical mass in terms of Open Badge adoption. Now that’s worked, we need to think in a more nuanced way about allowing users to tie multiple identities to a single badge.</p> + <h4>Conclusion</h4> + <p>Persona was always a slightly awkward fit for Open Badges. Although, for a time, it made sense to use Persona for authentication to the Open Badges backpack, we’re now in a post-Persona landscape. This brings with it certain advantages.</p> + <p>As Nate Otto wrote in his post <a href="https://medium.com/badge-alliance/open-badges-in-2016-a-look-ahead-3cfe5c3c9878#.l5mhiztwx">Open Badges in 2016: A Look Ahead</a>, the project is growing up. It’s time to move beyond what was expedient at the dawn of Open Badges and look to the future. I’m sad to see the decline of Persona, but I’m excited what the future holds!</p> + <p style="text-align: right;"><em>Header image CC BY-NC-SA <a href="https://www.flickr.com/photos/blmiers2/6904758951/">Barbara</a></em></p> + Mon, 18 Jan 2016 11:34:19 +0000 + Doug Belshaw + + + This Week In Rust: This Week in Rust 114 + tag:this-week-in-rust.org,2016-01-18:blog/2016/01/18/this-week-in-rust-114/ + http://this-week-in-rust.org/blog/2016/01/18/this-week-in-rust-114/ + <p>Hello and welcome to another issue of <em>This Week in Rust</em>! + <a href="http://rust-lang.org">Rust</a> is a systems language pursuing the trifecta: + safety, concurrency, and speed. This is a weekly summary of its progress and + community. Want something mentioned? Tweet us at <a href="https://twitter.com/ThisWeekInRust">@ThisWeekInRust</a> or <a href="mailto:corey@octayn.net?subject=This%20Week%20in%20Rust%20Suggestion">send us an + email</a>! + Want to get involved? <a href="https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md">We love + contributions</a>.</p> + <p><em>This Week in Rust</em> is openly developed <a href="https://github.com/cmr/this-week-in-rust">on GitHub</a>. + If you find any errors in this week's issue, <a href="https://github.com/cmr/this-week-in-rust/pulls">please submit a PR</a>.</p> + <p>This week's edition was edited by: <a href="https://github.com/nasa42">nasa42</a>, <a href="https://github.com/brson">brson</a>, and <a href="https://github.com/llogiq">llogiq</a>.</p> + <h3>Updates from Rust Community</h3> + <h4>News &amp; Blog Posts</h4> + <ul> + <li><a href="http://gregchapple.com/contributing-to-the-rust-compiler/">Guide: Contributing to the Rust compiler</a>.</li> + <li><a href="http://www.ncameron.org/blog/a-type-safe-and-zero-allocation-library-for-reading-and-navigating-elf-files/">A type-safe and zero-allocation library for reading and navigating ELF files</a>.</li> + <li>[podcast] <a href="http://www.newrustacean.com/show_notes/e009/">New Rustacean podcast episode 09</a>. Getting into the nitty-gritty with Rust's traits.</li> + <li><a href="https://jadpole.github.io/arcaders/arcaders-1-12/">ArcadeRS 1.12: Brawl, at last</a>! Part of the series <a href="https://jadpole.github.io/arcaders/arcaders-1-0/">ArcadeRS 1.0: The project</a> - a series whose objective is to explore the Rust programming language and ecosystem through the development of a simple, old-school shooter.</li> + <li><a href="https://blog.thiago.me/raspberry-pi-bare-metal-programming-with-rust/">Raspberry Pi bare metal programming with Rust</a>.</li> + <li><a href="http://blog.servo.org/2016/01/11/twis-47/">This week in Servo 47</a>.</li> + <li><a href="http://www.redox-os.org/news/this-week-in-redox-10/">This week in Redox OS 10</a>.</li> + </ul> + <h4>Notable New Crates &amp; Project Updates</h4> + <ul> + <li><a href="https://github.com/ebkalderon/amethyst">Amethyst</a>. Data-oriented game engine written in Rust.</li> + <li><a href="https://www.rust-lang.org/">Rust website</a> has received some <a href="https://www.reddit.com/r/rust/comments/40zxey/major_website_updates/">major updates</a>.</li> + <li><a href="https://packages.debian.org/stretch/rustc">Rust</a> and <a href="https://packages.debian.org/stretch/cargo">Cargo</a> are now available in Debian stretch.</li> + <li><a href="https://community.particle.io/t/rust-on-particle-call-for-contributors/19090">Rust on Particle: Call for contributors</a>.</li> + <li><a href="https://dwrensha.github.io/capnproto-rust/2016/01/11/async-rpc.html">capnp-rpc-rust rewritten to use async I/O</a>.</li> + <li><a href="https://github.com/Ogeon/palette">Palette</a>. A Rust library for linear color calculations and conversion.</li> + </ul> + <h3>Updates from Rust Core</h3> + <p>164 pull requests were <a href="https://github.com/issues?q=is%3Apr+org%3Arust-lang+is%3Amerged+merged%3A2016-01-11..2016-01-18">merged in the last week</a>.</p> + <p>See the <a href="https://internals.rust-lang.org/t/triage-digest-tue-jan-05-2016/3052">triage digest</a> and <a href="https://internals.rust-lang.org/t/subteam-reports-2016-01-08/3067">subteam reports</a> for more details.</p> + <h4>Notable changes</h4> + <ul> + <li><a href="https://github.com/rust-lang/rust/pull/30943">std: Stabilize APIs for the 1.7 release</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/27807">Refactor and improve: Arena, TypedArena</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/29498">Let <code>str::replace</code> take a pattern</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30295">rustc_resolve: Fix bug in duplicate checking for extern crates</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30426">Rewrite BTreeMap to use parent pointers</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30446">Support generic associated consts</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30509">Add an <code>impl</code> for <code>Box&lt;Error&gt;</code> from String</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30533">Introduce "obligation forest" data structure into fulfillment to track backtraces</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30538">Remove negate_unsigned feature gate</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30567">llvm: Add support for vectorcall (X86_VectorCall) convention</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30676">Make coherence more tolerant of error types</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30740">Add fast path for ASCII in UTF-8 validation</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30753">Downgrade unit struct match via S(..) warnings to errors</a>.</li> + <li><a href="https://github.com/rust-lang/rust/pull/30930">Move const block checks before lowering step</a>.</li> + </ul> + <h4>New Contributors</h4> + <ul> + <li>Anton Blanchard</li> + <li>Jonas Tepe</li> + <li>Jörg Krause</li> + <li>Joshua Olson</li> + <li>kalita.alexey</li> + <li>Pierre Krieger</li> + <li>Sergey Veselkov</li> + <li>Simon Martin</li> + <li>Steffen</li> + <li>tomaka</li> + </ul> + <h4>Approved RFCs</h4> + <p>Changes to Rust follow the Rust <a href="https://github.com/rust-lang/rfcs#rust-rfcs">RFC (request for comments) + process</a>. These + are the RFCs that were approved for implementation this week:</p> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/1331">RFC 1331: <code>src/grammar</code> for the canonical grammar of the Rust language</a>.</li> + </ul> + <h4>Final Comment Period</h4> + <p>Every week <a href="https://rust-lang.org/team.html">the team</a> announces the + 'final comment period' for RFCs and key PRs which are reaching a + decision. Express your opinions now. <a href="https://github.com/rust-lang/rfcs/labels/final-comment-period">This week's FCPs</a> are:</p> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/1462">Add <code>[</code> to the FOLLOW(ty) in macro future-proofing rules</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1457">Rewrite <code>for</code> loop desugaring to use language items</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1320">Amend 1192 (RangeInclusive) to use an enum</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/243">Trait-based exception handling</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1361">Improve Cargo target-specific dependencies</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1129">Add a <code>IndexAssign</code> trait that allows overloading "indexed assignment" expressions like <code>a[b] = c</code></a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1196">Allow eliding more type parameters</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1296">Add an <code>alias</code> attribute to <code>#[link]</code> and <code>-l</code></a>.</li> + </ul> + <h4>New RFCs</h4> + <ul> + <li><a href="https://github.com/rust-lang/rfcs/pull/1459">Add a used attribute to prevent symbols from being discarded</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1461">Move some net2 functionality into libstd</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1465">Add <code>some!</code> macro for unwrapping Option more safely</a>.</li> + <li><a href="https://github.com/rust-lang/rfcs/pull/1467">Stabilize the <code>volatile_load</code> and <code>volatile_store</code> intrinsics as <code>ptr::volatile_read</code> and <code>ptr::volatile_write</code></a>.</li> + </ul> + <h3>Upcoming Events</h3> + <ul> + <li><a href="http://www.meetup.com/Rust-Meetup-Hamburg/events/227838367/">1/19. Rust Hack and Learn Hamburg @ Ponton</a>.</li> + <li><a href="http://www.meetup.com/Rust-Bay-Area/events/227841778/">1/21. SF Bay Area: Rust Concurrency and Parallelism</a>.</li> + <li><a href="http://www.meetup.com/opentechschool-berlin/">1/27. OpenTechSchool Berlin: Rust Hack and Learn</a>.</li> + </ul> + <p>If you are running a Rust event please add it to the <a href="https://www.google.com/calendar/embed?src=apd9vmbc22egenmtu5l6c5jbfc%40group.calendar.google.com">calendar</a> to get + it mentioned here. Email <a href="mailto:erick.tryzelaar@gmail.com">Erick Tryzelaar</a> or <a href="mailto:banderson@mozilla.com">Brian + Anderson</a> for access.</p> + <h3>fn work(on: RustProject) -&gt; Money</h3> + <ul> + <li><a href="http://maidsafe.net/rust_engineer.html">Rust Engineer</a> at MaidSafe.</li> + <li><a href="https://careers.mozilla.org/en-US/position/ozy21fwU">Research Engineer - Servo</a> at Mozilla.</li> + <li><a href="https://careers.mozilla.org/en-US/position/o0H41fww">Senior Research Engineer - Rust</a> at Mozilla.</li> + <li><a href="http://plv.mpi-sws.org/rustbelt/">PhD and postdoc positions</a> at MPI-SWS.</li> + </ul> + <p><em>Tweet us at <a href="https://twitter.com/ThisWeekInRust">@ThisWeekInRust</a> to get your job offers listed here!</em></p> + <h3>Crate of the Week</h3> + <p>This week's Crate of the Week is <a href="https://github.com/alexcrichton/toml-rs">toml</a>, a crate for all our configuration needs, simple yet effective.</p> + <p>Thanks to <a href="https://users.rust-lang.org/users/stebalien">Steven Allen</a> for the suggestion.</p> + <p><a href="https://users.rust-lang.org/t/crate-of-the-week/2704">Submit your suggestions for next week</a>!</p> + <h3>Quote of the Week</h3> + <blockquote> + <p>Borrow/lifetime errors are usually Rust compiler bugs. + Typically, I will spend 20 minutes detailing the precise conditions of + the bug, using language that understates my immense knowledge, while + demonstrating sympathetic understanding of the pressures placed on a + Rust compiler developer, who is also probably studying for several exams + at the moment. The developer reading my bug report may not understand + this stuff as well as I do, so I will carefully trace the lifetimes of + each variable, where memory is allocated on the stack vs the heap, which + struct or function owns a value at any point in time, where borrows + begin and where they... oh yeah, actually that variable really doesn't + live long enough.</p> + </blockquote> + <p>— <a href="https://www.reddit.com/r/rust/comments/4084yx/my_trick_when_i_get_stuck_as_a_beginner/cysqz3s">peterjoel on /r/rust</a>.</p> + <p>Thanks to <a href="https://users.rust-lang.org/users/WaDelma">Wa Delma</a> for the suggestion.</p> + <p><a href="http://users.rust-lang.org/t/twir-quote-of-the-week/328">Submit your quotes for next week</a>!</p> + Mon, 18 Jan 2016 05:00:00 +0000 + Corey Richardson + + + Nikki Bee: Okay, But What Does Your Work Actually Mean, Nikki? Part 2: The Fetch Standard and Servo + http://nikkisquared.github.io/2016/01/17/what-does-your-work-mean-part-2.html + http://nikkisquared.github.io/2016/01/17/what-does-your-work-mean-part-2.html + <p>In my previous post, I started discussing in more detail what my internship entails, by talking about my first contribution to Servo. As a refresher, my first contribution was as part of my application to Outreachy, which I later revisited during my internship after a change I introduced to the HTML Standard it relied on. I’m going to expand on that last point today- specifically, how easy it is to introduce changes in <a href="https://wiki.whatwg.org/wiki/FAQ#What_is_the_WHATWG.3F">WHATWG</a>’s various standards. I’m also going to talk about how this accessibility to changing web standards affects how I can understand it, how I can help improve it, and my work on Servo.</p> + + <h3>Two Ways To Change</h3> + + <p>There are many ways to <a href="https://wiki.whatwg.org/wiki/What_you_can_do">get involved with WHATWG</a>, but there are two that I’ve become the most familiar with: firstly, by opening a discussion about a perceived issue and asking how it should be resolved; secondly, by taking on an issue approved as needing change and making the desired change. I’ve almost entirely only done the former, and the latter only for some minor typos. Any changes that relate directly to my work, however minor, are significant for me though! Like I discussed in my previous post, I brought attention to <a href="https://github.com/whatwg/html/issues/296">an inconsistency</a> that was resolved, giving me a new task of updating my first contribution to Servo to reflect the change in the HTML Standard. I’ve done that several times since, for the Fetch Standard.</p> + + <h3>Understanding Fetch</h3> + + <p>My first two weeks of my internship were spent on reading through the majority of the <a href="https://fetch.spec.whatwg.org/">Fetch Standard</a>, primarily the various Fetch functions. I took many notes describing the steps to myself, annotated with questions I had and the answers I got from either other people on the Servo team who had worked with Fetch (including my internship mentor, of course!) or people from WHATWG who were involved in the Fetch Standard. Getting so familiar with Fetch meant a few things: I would notice minor errors (such as an out of date link) that I could submit a <a href="https://github.com/whatwg/fetch/pull/173">simple fix for</a>, or a bigger issue that I couldn’t resolve myself.</p> + + <h3>Discussions &amp; Resolutions</h3> + + <p>I’m going to go into more detail about some of those bigger issues. From my perspective, when I start a discussion about a piece of documentation (such as the Fetch Standard, or reading about a programming library Servo uses), I go into it thinking “Either this documentation is incorrect, or my understanding is incorrect”. Whichever the answer is, it doesn’t mean that the documentation is bad, or that I’m bad at reading comprehension. I understand best by building up a model of something in my head, putting that to practice, and asking a lot of questions along the way. I learn by getting things wrong and figuring out why I was wrong, and sometimes in the process I uncover a point that could be made more clear, or an inconsistency! I have good examples of both of the different outcomes I listed, which I’ll cover over the next two sections.</p> + + <h5>Looking For The Big Picture</h5> + + <p>Early on in my initial review of the Fetch Standard’s several protocols, I found a major step that seemed to have no use. I understood that since I was learning Fetch on a step-by-step basis, I did not have a view of the bigger picture, so I asked around what I was missing that would help me understand this. One of the people I work with on implementing Fetch agreed with me that the step seemed to have no purpose, and so we decided to <a href="https://github.com/whatwg/fetch/issues/174">open an issue</a> asking about removing it from the standard. It turned out that I had actually missed the meaning of it, as we learned. However, instead of leaving it there, I shifted the issue into asking for some explanatory notes on why this step is needed, which was fulfilled. This meant that I would have a reference to go back to should I forget the significance of the step, and that people reading the Fetch Standard in the future would be much less likely to come to the same incorrect conclusion I had.</p> + + <h5>A Confusing Order</h5> + + <p>Shortly after I had first discovered that apparent issue, I found myself struggling to comprehend a sequence of actions in another Fetch protocol. The specification seemed to say that part of an early step was meant to only be done after the final step. I unfortunately don’t remember details of the discussion I had about this- if there was a reason for why it was organized like this, I forget what it was. Regardless, it was agreed that <a href="https://github.com/whatwg/fetch/issues/176">moving those sub-steps</a> to be actually listed after the step they’re supposed to run after would be a good change. This meant that I would need to re-organize my notes to reflect the re-arranged sequence of actions, as well as have an easier time being able to follow this part of the Fetch Standard.</p> + + <h3>A Living Standard</h3> + + <p>Like I said at the start of this post, I’m going to talk about how changes in the Fetch Standard affects my work on Servo itself. What I’ve covered so far has mostly been how changes affect my understanding of the standard itself. A key aspect in understanding the Fetch protocols is reviewing them for updates that impact me. WHATWG labels every standard they author as a “<a href="https://wiki.whatwg.org/wiki/FAQ#What_does_.22Living_Standard.22_mean.3F">Living Standard</a>” for good reason. It was one thing for me to learn how easy it is to introduce changes, while knowing exactly what’s going on, but it’s another for me to understand that anybody else can, and often does, make changes to the Fetch Standard!</p> + + <h5>Changes Over Time</h5> + + <p>When an update is made to the Fetch Standard, it’s not so difficult to deal with as one might imagine. The Fetch Standard always notes the last day it was updated at the top of the document, I follow a Twitter account that <a href="https://twitter.com/fetchstandard">posts about updates</a>, and all the history can be <a href="https://github.com/whatwg/fetch/commits">seen on GitHub</a> which will show me exactly what has been changed as well as some discussion on what the change does. All of these together alert me to the fact that the Fetch Standard has been modified, and I can quickly see what was revised. If it’s relevant to what I’m going to be implementing, I update my notes to match it. Occasionally, I need to change existing code to reflect the new Standard, which is also easily done by comparing my new notes to the Fetch implementation in Servo!</p> + + <h5>Snapshots</h5> + + <p>From all of this, it might sound like the Fetch Standard is unfinished, or unreliable/inconsistent. I don’t mean to misrepresent it- the many small improvements help make the Fetch Standard, like all of WHATWG’s standards, better and more reliable. You can think of the status of the Fetch Standard at any point in time as a single, working snapshot. If somebody implemented all of Fetch as it is now, they’d have something that works by itself correctly. A different snapshot of Fetch is just that- different. It will have an improvement or two, but that doesn’t obsolete anybody who implemented it previously. It just means if they revisit the implementation, they’ll have things to update.</p> + + <p>Third post over.</p> + Sun, 17 Jan 2016 20:20:27 +0000 + + + Kevin Ngo: How to Write an A-Frame VR Component + http://ngokevin.com/blog/aframe-component/ + http://ngokevin.com/blog/aframe-component/ + <img align="left" hspace="5" src="http://thevrjump.com/assets/img/articles/aframe-system/aframe-example.jpg" width="320" />Abstract representation of components by @rubenmueller of thevrjump.com. + + <p><a href="http://ngokevin.com/blog/aframe">A-Frame</a> is a WebVR framework that introduces the + <a href="http://ngokevin.com/blog/aframe-vs-3dml">entity-component system</a> (<a href="http://ngokevin.com/rss/docs">docs</a>) to the DOM. The + entity-component system treats every <strong>entity</strong> in the scene as a placeholder + object which we apply and mix <strong>components</strong> to in order to add appearance, + behavior, and functionality. A-Frame comes with some standard components out of + the box like camera, geometry, material, light, or sound. However, people can + write, publish, and register their own components to do <strong>whatever</strong> they want + like have entities <a href="https://github.com/dmarcos/a-invaders/tree/master/js/components">collide/explode/spawn</a>, be controlled by + <a href="https://github.com/ngokevin/aframe-physics-components">physics</a>, or <a href="https://jsbin.com/dasefeh/edit?html,output">follow a path</a>. Today, we'll be going through + how we can write our own A-Frame components.</p> + <blockquote> + <p>Note that this tutorial will be covering the upcoming release of <a href="https://github.com/aframevr/aframe/blob/dev/CHANGELOG.md#dev">A-Frame + 0.2.0</a> which vastly improves the component API.</p> + </blockquote> + <h3>Table of Contents</h3> + <ul> + <li><a href="http://ngokevin.com/rss/index.xml#what-a-component-looks-like">What a Component Looks Like</a><ul> + <li><a href="http://ngokevin.com/rss/index.xml#from-the-dom">From the DOM</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#under-the-hood">Under the Hood</a></li> + </ul> + </li> + <li><a href="http://ngokevin.com/rss/index.xml#defining-the-schema">Defining the Schema</a><ul> + <li><a href="http://ngokevin.com/rss/index.xml#property-types">Property Types</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#single-property-schemas">Single-Property Schemas</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#multiple-property-schemas">Multiple-Property Schemas</a></li> + </ul> + </li> + <li><a href="http://ngokevin.com/rss/index.xml#defining-the-lifecycle-methods">Defining the Lifecycle Methods</a><ul> + <li><a href="http://ngokevin.com/rss/index.xml#component-init-set-up">Component.init() - Set Up</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#component-update-olddata-do-the-magic">Component.update(oldData) - Do the Magic</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#component-remove-tear-down">Component.remove() - Tear Down</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#component-tick-time-background-behavior">Component.tick() - Background Behavior</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#component-pause-and-component-play-stop-and-go">Component.pause() and Component.play() - Stop and Go</a></li> + </ul> + </li> + <li><a href="http://ngokevin.com/rss/index.xml#boilerplate">Boilerplate</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#examples">Examples</a><ul> + <li><a href="http://ngokevin.com/rss/index.xml#text-component">Text Component</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#physics-components">Physics Components</a></li> + <li><a href="http://ngokevin.com/rss/index.xml#layout-component">Layout Component</a></li> + </ul> + </li> + </ul> + <h3>What a Component Looks Like</h3> + <p>A component contains a bucket of data in the form of component properties. This + data is used to modify the entity. For example, we might have an <em>engine</em> + component. Possible properties might be <em>horsepower</em> or <em>cylinders</em>.</p> + <p><img alt="" src="http://thevrjump.com/assets/img/articles/aframe-system/aframe-system.jpg" /> + </p><div class="page-caption"><span> + Abstract representation of a component by @rubenmueller of thevrjump.com. + </span></div><p></p> + <h4>From the DOM</h4> + <p>Let's first see what a component looks like from the DOM.</p> + <p>For example, the <a href="https://aframe.io/docs/components/light.html">light component</a> has properties such as type, color, + and intensity. In A-Frame, we register and configure a component to an entity + using an HTML attribute and a style-like syntax:</p> + <div class="highlight"><pre><span class="p">&lt;</span><span class="nt">a-entity</span> <span class="na">light</span><span class="o">=</span><span class="s">"type: point; color: crimson; intensity: 2.5"</span><span class="p">&gt;&lt;/</span><span class="nt">a-entity</span><span class="p">&gt;</span> + </pre></div> + + + <p>This would give us a light in the scene. To demonstrate composability, we could + give the light a spherical representation by mixing in the <a href="https://aframe.io/docs/components/geometry.html">geometry + component</a>.</p> + <div class="highlight"><pre><span class="p">&lt;</span><span class="nt">a-entity</span> <span class="na">geometry</span><span class="o">=</span><span class="s">"primitive: sphere; radius: 5"</span> + <span class="na">light</span><span class="o">=</span><span class="s">"type: point; color: crimson; intensity: 2.5"</span><span class="p">&gt;&lt;/</span><span class="nt">a-entity</span><span class="p">&gt;</span> + </pre></div> + + + <p>Or we can configure the position component to move the light sphere a bit to the right.</p> + <div class="highlight"><pre><span class="p">&lt;</span><span class="nt">a-entity</span> <span class="na">geometry</span><span class="o">=</span><span class="s">"primitive: sphere; radius: 5"</span> + <span class="na">light</span><span class="o">=</span><span class="s">"type: point; color: crimson; intensity: 2.5"</span> + <span class="na">position</span><span class="o">=</span><span class="s">"5 0 0"</span><span class="p">&gt;&lt;/</span><span class="nt">a-entity</span><span class="p">&gt;</span> + </pre></div> + + + <p>Given the style-like syntax and that it modifies the appearance and behavior of + DOM nodes, component properties can be thought of as a rough analog to CSS. In + the near future, I can imagine component property stylesheets.</p> + <h4>Under the Hood</h4> + <p>Now let's see what a component looks like <strong>under the hood</strong>. A-Frame's most + basic component is the <a href="https://aframe.io/docs/components/position.html">position component</a>:</p> + <div class="highlight"><pre><span class="nx">AFRAME</span><span class="p">.</span><span class="nx">registerComponent</span><span class="p">(</span><span class="s1">'position'</span><span class="p">,</span> <span class="p">{</span> + <span class="nx">schema</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">'vec3'</span> <span class="p">},</span> + + <span class="nx">update</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="kd">var</span> <span class="nx">object3D</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">object3D</span><span class="p">;</span> + <span class="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">;</span> + <span class="nx">object3D</span><span class="p">.</span><span class="nx">position</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="nx">data</span><span class="p">.</span><span class="nx">x</span><span class="p">,</span> <span class="nx">data</span><span class="p">.</span><span class="nx">y</span><span class="p">,</span> <span class="nx">data</span><span class="p">.</span><span class="nx">z</span><span class="p">);</span> + <span class="p">}</span> + <span class="p">});</span> + </pre></div> + + + <p>The position component uses only a tiny subset of the component API, but what + this does is register the component with the name "position", define a <code>schema</code> + where the component's value with be parsed to an <code>{x, y, z}</code> object, and when + the component initializes or the component's data updates, set the position of + the entity with the <code>update</code> callback. <code>this.el</code> is a reference from the + component to the DOM element, or entity, and <code>object3D</code> is the entity's + <a href="http://threejs.org/">three.js</a>. Note that A-Frame is built on top of three.js so many + components will be using the three.js API.</p> + <p>So we see that components consist of a name and a definition, and then they can + be registered to A-Frame. We saw the the position component definition defined + a <code>schema</code> and an <code>update</code> handler. Components simply consist of the <code>schema</code>, + which defines the shape of the data, and several handlers for the component to + modify the entity in reaction to different types of events.</p> + <p>Here is the current list of properties and methods of a component definition:</p> + <table class="pure-table-striped"> + <tbody><tr> + <th>Property</th> + <th>Description</th> + </tr> + <tr> + <td>data</td> + <td>Data of the component derived from the schema default values, mixins, and the entity's attributes.</td> + </tr> + <tr> + <td>el</td> + <td>Reference to the <a href="https://aframe.io/docs/core/entity.html">entity</a> element.</td> + </tr> + <tr> + <td>schema</td> + <td>Names, types, and default values of the component property value(s)</td> + </tr> + </tbody></table> + + <table class="pure-table-striped"> + <tbody><tr><th>Method</th><th>Description</th></tr> + <tr> + <td>init</td> + <td>Called once when the component is initialized.</td> + </tr> + <tr> + <td>update</td> + <td>Called both when the component is initialized and whenever the component's data changes (e.g, via <i>setAttribute</i>).</td> + </tr> + <tr> + <td>remove</td> + <td>Called when the component detaches from the element (e.g., via <i>removeAttribute</i>).</td> + </tr> + <tr> + <td>tick</td> + <td>Called on each render loop or tick of the scene.</td> + </tr> + <tr> + <td>play</td> + <td>Called whenever the scene or entity plays to add any background or dynamic behavior.</td> + </tr> + <tr> + <td>pause</td> + <td>Called whenever the scene or entity pauses to remove any background or dynamic behavior.</td> + </tr> + </tbody></table> + + <h3>Defining the Schema</h3> + <p>The component's schema defines what type of data it takes. A component can + either be single-property or consist of multiple properties. And properties + have <em>property types</em>. Note that single-property schemas and property types are + being released in A-Frame <code>v0.2.0</code>.</p> + <p>A property might look like:</p> + <div class="highlight"><pre><span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">'int'</span><span class="p">,</span> <span class="k">default</span><span class="o">:</span> <span class="mi">5</span> <span class="p">}</span> + </pre></div> + + + <p>And a schema consisting of multiple properties might look like:</p> + <div class="highlight"><pre><span class="p">{</span> + <span class="nx">color</span><span class="o">:</span> <span class="p">{</span> <span class="k">default</span><span class="o">:</span> <span class="s1">'#FFF'</span> <span class="p">},</span> + <span class="nx">target</span><span class="o">:</span> <span class="p">{</span> <span class="nx">type</span><span class="o">:</span> <span class="s1">'selector'</span> <span class="p">},</span> + <span class="nx">uv</span><span class="o">:</span> <span class="p">{</span> + <span class="k">default</span><span class="o">:</span> <span class="s1">'1 1'</span><span class="p">,</span> + <span class="nx">parse</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="p">{</span> + <span class="k">return</span> <span class="nx">value</span><span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s1">' '</span><span class="p">).</span><span class="nx">map</span><span class="p">(</span><span class="nb">parseFloat</span><span class="p">);</span> + <span class="p">}</span> + <span class="p">},</span> + <span class="p">}</span> + </pre></div> + + + <p>Since components in the entity-component system are just buckets of data that + are used to affect the appearance or behavior of the entity, the schema plays a + crucial role in the definition of the component.</p> + <h4>Property Types</h4> + <p>A-Frame comes with several built-in property types such as <code>boolean</code>, <code>int</code>, + <code>number</code>, <code>selector</code>, <code>string</code>, or <code>vec3</code>. Every single property is assigned a + type, whether explicitly through the <code>type</code> key or implictly via inferring the + value. And each type is used to assign <code>parse</code> and <code>stringify</code> functions. The + parser deserializes the incoming string value from the DOM to be put into the + component's data object. The stringifier is used when using <code>setAttribute</code> to + serialize back to the DOM.</p> + <p>We can actually define and register our own property types:</p> + <div class="highlight"><pre><span class="nx">AFRAME</span><span class="p">.</span><span class="nx">registerPropertyType</span><span class="p">(</span><span class="s1">'radians'</span><span class="p">,</span> <span class="p">{</span> + <span class="nx">parse</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + + <span class="p">}</span> + + <span class="c1">// Default stringify is .toString().</span> + <span class="p">});</span> + </pre></div> + + + <h4>Single-Property Schemas</h4> + <p>If a component has only one property, then it must either have a <code>type</code> or a + <code>default</code> value. If the type is defined, then the type is used to parse and + coerce the string retrieved from the DOM (e.g., <code>getAttribute</code>). Or if the + default value is defined, the default value is used to infer the type.</p> + <p>Take for instance the <a href="https://aframe.io/docs/components/visible.html">visible component</a>. The schema property + definition implicitly defines it as a boolean:</p> + <div class="highlight"><pre><span class="nx">AFRAME</span><span class="p">.</span><span class="nx">registerComponent</span><span class="p">(</span><span class="s1">'visible'</span><span class="p">,</span> <span class="p">{</span> + <span class="nx">schema</span><span class="o">:</span> <span class="p">{</span> + <span class="c1">// Type will be inferred to be boolean.</span> + <span class="k">default</span><span class="o">:</span> <span class="kc">true</span> + <span class="p">},</span> + + <span class="c1">// ...</span> + <span class="p">});</span> + </pre></div> + + + <p>Or the <a href="https://aframe.io/docs/components/rotation.html">rotation component</a> which explicitly defines the value as a <code>vec3</code>:</p> + <div class="highlight"><pre><span class="nx">AFRAME</span><span class="p">.</span><span class="nx">registerComponent</span><span class="p">(</span><span class="s1">'rotation'</span><span class="p">,</span> <span class="p">{</span> + <span class="nx">schema</span><span class="o">:</span> <span class="p">{</span> + <span class="c1">// Default value will be 0, 0, 0 as defined by the vec3 property type.</span> + <span class="nx">type</span><span class="o">:</span> <span class="s1">'vec3'</span> + <span class="p">}</span> + + <span class="c1">// ...</span> + <span class="p">});</span> + </pre></div> + + + <p>Using these defined property types, schemas are processed by + <code>registerComponent</code> to inject default values, parsers, and stringifiers for + each property. So if a default value is not defined, the default value will be + whatever the property type defines as the "default default value".</p> + <h4>Multiple-Property Schemas</h4> + <p>If a component has multiple properties (or one named property), then it consists of + one or more property definitions, in the form described above, in an object keyed by + property name. For instance, a physics body component might define a schema:</p> + <div class="highlight"><pre><span class="nx">AFRAME</span><span class="p">.</span><span class="nx">registerComponent</span><span class="p">(</span><span class="s1">'physics-body'</span><span class="p">,</span> <span class="p">{</span> + <span class="nx">schema</span><span class="o">:</span> <span class="p">{</span> + <span class="nx">boundingBox</span><span class="o">:</span> <span class="p">{</span> + <span class="nx">type</span><span class="o">:</span> <span class="s1">'vec3'</span><span class="p">,</span> + <span class="k">default</span><span class="o">:</span> <span class="p">{</span> <span class="nx">x</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">y</span><span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">z</span><span class="o">:</span> <span class="mi">1</span> <span class="p">}</span> + <span class="p">},</span> + <span class="nx">mass</span><span class="o">:</span> <span class="p">{</span> + <span class="k">default</span><span class="o">:</span> <span class="mi">0</span> + <span class="p">},</span> + <span class="nx">velocity</span><span class="o">:</span> <span class="p">{</span> + <span class="nx">type</span><span class="o">:</span> <span class="s1">'vec3'</span> + <span class="p">}</span> + <span class="p">}</span> + <span class="p">}</span> + </pre></div> + + + <p>Having multiple properties is what makes the component take the syntax in the + form of <code>physics="mass: 2; velocity: 1 1 1"</code>.</p> + <p>With the schema defined, all data coming into the component will be passed + through the schema for parsing. Then in the lifecycle methods, the component + has access to <code>this.data</code> which in a single-property schema is a value and in a + multiple-propery schema is an object.</p> + <h3>Defining the Lifecycle Methods</h3> + <h4>Component.init() - Set Up</h4> + <p><code>init</code> is called once in the component's lifecycle when it is mounted to the + entity. <code>init</code> is generally used to set up variables or members that may used + throughout the component or to set up state. Though not every component will + need to define an <code>init</code> handler. Sort of like the component-equivalent method + to <code>createdCallback</code> or <code>React.ComponentDidMount</code>.</p> + <p>For example, the <code>look-at</code> component's <code>init</code> handler sets up some variables:</p> + <div class="highlight"><pre><span class="nx">init</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">target3D</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span> + <span class="k">this</span><span class="p">.</span><span class="nx">vector</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">THREE</span><span class="p">.</span><span class="nx">Vector3</span><span class="p">();</span> + <span class="p">},</span> + + <span class="c1">// ...</span> + </pre></div> + + + <h4>Component.update(oldData) - Do the Magic</h4> + <p>The <code>update</code> handler is called both at the beginning of the component's + lifecycle with the initial <code>this.data</code> <em>and</em> every time the component's data + changes (generally during the entity's <code>attributeChangedCallback</code> like with a + <code>setAttribute</code>). The update handler gets access to the previous state of the + component data passed in through <code>oldData</code>. The previous state of the component + can be used to tell exactly which properties changed to do more granular + updates.</p> + <p>The update handler uses <code>this.data</code> to modify the entity, usually interacting + with three.js APIs. One of the simplest update handlers is the + <a href="https://aframe.io/docs/components/visible.html">visible</a> component's:</p> + <div class="highlight"><pre><span class="nx">update</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">object3D</span><span class="p">.</span><span class="nx">visible</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">;</span> + <span class="p">}</span> + </pre></div> + + + <p>A slightly more complex update handler might be the <a href="https://aframe.io/docs/components/light.html">light</a> component's, + which we'll show via abbreviated code:</p> + <div class="highlight"><pre><span class="nx">update</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">oldData</span><span class="p">)</span> <span class="p">{</span> + <span class="kd">var</span> <span class="nx">diffData</span> <span class="o">=</span> <span class="nx">diff</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="nx">oldData</span> <span class="o">||</span> <span class="p">{});</span> + + <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">light</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="p">(</span><span class="s1">'type'</span> <span class="k">in</span> <span class="nx">diffData</span><span class="p">))</span> <span class="p">{</span> + <span class="c1">// If there is an existing light and the type hasn't changed, update light.</span> + <span class="nb">Object</span><span class="p">.</span><span class="nx">keys</span><span class="p">(</span><span class="nx">diffData</span><span class="p">).</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span> <span class="p">(</span><span class="nx">property</span><span class="p">)</span> <span class="p">{</span> + <span class="nx">light</span><span class="p">[</span><span class="nx">property</span><span class="p">]</span> <span class="o">=</span> <span class="nx">diffData</span><span class="p">[</span><span class="nx">property</span><span class="p">];</span> + <span class="p">});</span> + <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> + <span class="c1">// No light exists yet or the type of light has changed, create a new light.</span> + <span class="k">this</span><span class="p">.</span><span class="nx">light</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="nx">getLight</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">data</span><span class="p">));</span> + + <span class="c1">// Register the object3D of type `light` to the entity.</span> + <span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">setObject3D</span><span class="p">(</span><span class="s1">'light'</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">light</span><span class="p">);</span> + <span class="p">}</span> + <span class="p">}</span> + </pre></div> + + + <p>The entity's <code>object3D</code> is a plain THREE.Object3D. Other three.js object types + such as meshes, lights, and cameras can be set with <code>setObject3D</code> where they + will be appeneded to the entity's <code>object3D</code>.</p> + <h4>Component.remove() - Tear Down</h4> + <p>The <code>remove</code> handler is called when the component detaches from the entity such + as with <code>removeAttribute</code>. This is generally used to remove all modifications, + listeners, and behaviors to the entity that the component added.</p> + <p>For example, when the <a href="https://aframe.io/docs/components/light.html">light component</a> detaches, it removes the light + it previously attached from the entity and thus the scene:</p> + <div class="highlight"><pre><span class="nx">remove</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">removeObject3D</span><span class="p">(</span><span class="s1">'light'</span><span class="p">);</span> + <span class="p">}</span> + </pre></div> + + + <h4>Component.tick(time) - Background Behavior</h4> + <p>The <code>tick</code> handler is called on every single tick or render loop of the scene. + So expect it to run on the order of 60-120 times for second. The global uptime of + the scene in seconds is passed into the tick handler.</p> + <p>For example, the <a href="https://aframe.io/docs/components/look-at.html">look-at</a> component, which instructs an entity to + look at another target entity, uses the tick handler to update the rotation in + case the target entity changes its position:</p> + <div class="highlight"><pre><span class="nx">tick</span><span class="o">:</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">t</span><span class="p">)</span> <span class="p">{</span> + <span class="c1">// target3D and vector are set from the update handler.</span> + <span class="k">if</span> <span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">target3D</span><span class="p">)</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">el</span><span class="p">.</span><span class="nx">object3D</span><span class="p">.</span><span class="nx">lookAt</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">vector</span><span class="p">.</span><span class="nx">setFromMatrixPosition</span><span class="p">(</span><span class="nx">target3D</span><span class="p">.</span><span class="nx">matrixWorld</span><span class="p">));</span> + <span class="p">}</span> + <span class="p">}</span> + </pre></div> + + + <h4>Component.pause() and Component.play() - Stop and Go</h4> + <p>To support pause and play, just as with a video game or to toggle entities for + performance, components can implement <code>play</code> and <code>pause</code> handlers. These are + invoked when the component's entity runs its <code>play</code> or <code>pause</code> method. When an + entity plays or pauses, all of its child entities are also played or paused.</p> + <p>Components should implement play or pause handlers if they register any + dynamic, asynchronous, or background behavior such as animations, event + listeners, or tick handlers.</p> + <p>For example, the <code>look-controls</code> component simply removes its event listeners + such that the camera does not move when the scene is paused, and it adds its + event listeners when the scene starts playing or is resumed:</p> + <div class="highlight"><pre><span class="nx">pause</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">removeEventListeners</span><span class="p">()</span> + <span class="p">},</span> + + <span class="nx">play</span><span class="o">:</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span> + <span class="k">this</span><span class="p">.</span><span class="nx">addEventListeners</span><span class="p">()</span> + <span class="p">}</span> + </pre></div> + + + <h3>Boilerplate</h3> + <p>I suggest that people start off with my <a href="https://github.com/ngokevin/aframe-component-boilerplate">component boilerplate</a>, + even hardcore tool junkies. This will get you straight into building a + component and comes with everything you will need to publish your component + into the wild. The boilerplate handles creating a stubbed component, build + steps for both NPM and browser distribution files, and publishing to Github + Pages.</p> + <p>Generally with boilerplates, it is better to start from scratch and build your + own boilerplate, but the A-Frame component boilerplate contains a lot of tribal + inside knowledge about A-Frame and is updated frequently to reflect new things + landing on A-Frame. The only possibly opinionated pieces about the boilerplate + is the development tools it internally uses that are hidden away by NPM + scripts.</p> + <h3>Examples</h3> + <p>Under construction. Stay tuned!</p> + <h4>Text Component</h4> + <p><a href="https://github.com/ngokevin/aframe-text-component">Text component</a></p> + <h4>Physics Components</h4> + <p><a href="https://github.com/ngokevin/aframe-physics-components">Physics components</a></p> + <h4>Layout Component</h4> + <p><a href="https://github.com/ngokevin/aframe-layout-component">Layout component</a></p> + Sun, 17 Jan 2016 00:00:00 +0000 + + + Gervase Markham: Convenient… and Creepy + http://blog.gerv.net/?p=3527 + http://feedproxy.google.com/~r/HackingForChrist/~3/DN054t04_dE/ + <p>The last Mozilla All-Hands was at one of the hotels in the Walt Disney World Resort in Florida. Every attendee was issued with one of these (although their use was optional):<br /> + <a href="http://blog.gerv.net/files/2016/01/Disneys_MagicBand.jpg"><img class="alignnone size-large wp-image-3530" src="http://blog.gerv.net/files/2016/01/Disneys_MagicBand-1024x832.jpg" width="292" /></a></p> + <p>It’s called a “Magic Band”. You register it online and connect it to your Disney account, and then it can be used for park entry, entry to pre-booked rides so you don’t have to queue (called “FastPass+”), payment, picking up photos, as your room key, and all sorts of other convenient features. Note that it has no UI whatsoever – no lights, no buttons. Not even a battery compartment. (It does contain a battery, but it’s not replaceable.) These are specific design decisions – the aim is for ultra-simple convenience.</p> + <p>One of the talks we had at the All Hands was from one of the Magic Band team. The audience reactions to some of the things he said was really interesting. He gave the example of Cinderella wishing you a Happy Birthday as you walk round the park. “Cinderella just knows”, he said. Of course, in fact, her costume’s tech prompts her when it silently reads your Magic Band from a distance. This got some initial impressed applause, but it was noticeable that after a few moments, it wavered – people were thinking “Cool… er, but creepy?”</p> + <p>The Magic Band also has range sufficient that Disney can track you around the park. This enables some features which are good for both customers and Disney – for example, they can use it for load balancing. If one area of the park seems to be getting overcrowded, have some characters pop up in a neighbouring area to try and draw people away. But it means that they always know where you are and where you’ve been.</p> + <p>My take-away from learning about the Magic Band is that it’s really hard to have a technical solution to this kind of requirement which allows all the Convenient features but not the Creepy features. Disney does offer an RFID-card-based solution for the privacy-conscious which does some of these things, but not all of them. And it’s easier to lose. It seems to me that the only way to distinguish the two types of feature, and get one and not the other, is policy – either the policy of the organization, or external restrictions on them (e.g. from a watchdog body’s code of conduct they sign up to, or from law). And it’s often not in the organization’s interest to limit themselves in this way.</p> + <img alt="" height="1" src="http://feeds.feedburner.com/~r/HackingForChrist/~4/DN054t04_dE" width="1" /> + Sat, 16 Jan 2016 12:18:38 +0000 + gerv + + + Christian Heilmann: Don’t tell me what my browser can’t do! + https://www.christianheilmann.com/?p=4957 + https://www.christianheilmann.com/2016/01/16/dont-tell-me-what-my-browser-cant-do/ + <p><em class="markup--em markup--p-em">Chances are, your guess is wrong!</em></p> + + <p></p><figure><img alt="you are obviously in the wrong place" src="https://d262ilb51hltx0.cloudfront.net/max/800/1*l9jPbOyAl00kjPhyNYA-IQ.jpeg" width="100%" />Arrogance towards possible customers never pays out – as shown in “Pretty Woman”</figure><p></p> + + <p>There is nothing more frustrating than being capable of something and not getting a chance to do it. The same goes for being blocked out from something although you are capable of consuming it. Or you’re even willing to put some extra effort or even money in and you still don’t get to consume it.</p> + + <p>For example, I’d happily pay $50 a month to get access to Netflix’s world-wide library from any country I’m in. But the companies Netflix get their content from won’t go for that. Movies and TV show are budgeted by predicted revenue in different geographical markets with month-long breaks in between the releases. A world-wide network capable of delivering content in real time? Preposterous — let’s shut that down.</p> + + <p>On a less “let’s break a 100 year old monopoly” scale of annoyance, <a href="https://twitter.com/codepo8/status/687616620529844224">I tweeted yesterday something glib and apparently cruel</a>:</p> + + <p></p><blockquote>“Sorry, but your browser does not support WebGL!” – sorry, you are a shit coder.</blockquote><p></p> + + <p><strong>And I stand by this</strong>. I went to a web site that promised me some cute, pointless animation and technological demo. I was using Firefox Nightly — a WebGL capable browser. I also went there with Microsoft Edge — another WebGL capable browser. Finally, using Chrome, I was able to delight in seeing an animation.</p> + + <p><strong>I’m not saying the creators of that thing lack in development capabilities</strong>. The demo was slick, beautiful and well coded. They still do lack in two things developers of <em>web products </em>(and I count apps into that) should have: empathy for the end user and an understanding that they are not in control.</p> + + <p>Now, I am a pretty capable technical person. When you tell me that I might be lacking WebGL, I know what you mean. I don’t lack WebGL. I was blocked out because the web site did browser sniffing instead of capability testing. But I know what could be the problem.</p> + + <p>A normal user of the web has no idea what WebGL is and — if you’re lucky — will try to find it on an app store. If you’re not lucky all you did is confuse a person. A person who went through the effort to click a link, open a browser and wait for your thing to load. A person that feels stupid for using your product as they have no clue what WebGL is and won’t ask. Humans hate feeling stupid and we do anything not to appear it or show it.</p> + + <p>This is what I mean by empathy for the end user. Our problems should never become theirs.</p> + + <p></p><blockquote>A cryptic error message telling the user that they lack some technology helps nobody and is sloppy development at best, sheer arrogance at worst.</blockquote><p></p> + + <p>The web is, sadly enough, littered with unhelpful error messages and assumptions that it is the user’s fault when they can’t consume the thing we built.</p> + + <p>Here’s a reality check — this is what our users should have to do to consume the things we build:</p> + + <p><img alt="" height="600" src="https://d262ilb51hltx0.cloudfront.net/max/800/1*DXtRIWTu-UzRb0YB-h8SmA.png" width="10" /></p> + + <p><strong>That’s right. Nothing</strong>. This is the web. Everybody is invited to consume, contribute and create. This is what made it the success it is. This is what will make it outlive whatever other platform threatens it with shiny impressive interactions. Interactions at that time impossible to achieve with web technologies.</p> + + <p>Whenever I mention this, the knee-jerk reaction is the same:</p> + + <p></p><blockquote class="graf--blockquote graf-after--p" id="79d6" name="79d6">How can you expect us to build delightful experiences close to magic (and whatever other soundbites were in the last Apple keynote) if we keep having to support old browsers and users with terrible setups?</blockquote><p></p> + + <p>You don’t have to support old browsers and terrible setups. But you are not allowed to block them out. It is a simple matter of giving a usable interface to end users. A button that does nothing when you click it is not a good experience. Test if the functionality is available, then create or show the button. <strong class="markup--strong markup--p-strong">This is as simple as it is.</strong></p> + + <p>If you really have to rely on some technology then show people what they are missing out on and tell them how to upgrade. A screenshot or a video of a WebGL animation is still lovely to see. A message telling me I have no WebGL less so.</p> + + <p>Even more on the black and white scale, what the discussion boils down to is in essence:</p> + + <p></p><blockquote class="graf--blockquote graf-after--p" id="a775" name="a775">But it is 2016 — surely we can expect people to have JavaScript enabled — it is after all “the assembly language of the web”</blockquote><p></p> + + <p>Despite the cringe-worthy <a href="http://www.hanselman.com/blog/JavaScriptIsAssemblyLanguageForTheWebSematicMarkupIsDeadCleanVsMachinecodedHTML.aspx">misquote of the assembly language</a> thing, here is a harsh truth:</p> + + <p></p><blockquote>You can absolutely expect JavaScript to be available on your end users computers in 2016. At the same time it is painfully <strong>naive</strong> to expect it to work under all circumstances.</blockquote><p></p> + + <p><strong>JavaScript is brittle</strong>. <span class="caps">HTML</span> and <span class="caps">CSS</span> both are <em>fault tolerant</em>. If something goes wrong in <span class="caps">HTML</span>, browsers either display the content of the element or try to fix minor issues like unclosed elements for you. <span class="caps">CSS</span> skips lines of code it can’t understand and merrily goes on its way to show the rest of it. JavaScript breaks on errors and tells you that something went wrong. It will not execute the rest of the script, but throws in the towel and tells you to get your house in order first.</p> + + <p>There <a href="http://kryogenix.org/code/browser/everyonehasjs.html">are many outside influences</a> that will interfere with the execution of your JavaScript. That’s why a non-naive and non-arrogant — a dedicated and seasoned web developer — will never rely on it. Instead, you treat it as an enhancement and in an almost paranoid fashion test for the availability of everything before you access it.</p> + + <p><strong>Sorry (not sorry) — this will never go away</strong>. This is the nature of JavaScript. And it is a good thing. It means we can access new features of the language as they come along instead of getting stuck in a certain state. It means we have to think about using it every time instead of relying on libraries to do the work for us. It means that we need to keep evolving with the web — a living and constantly changing medium, and not a software platform. That’s just part of it.</p> + + <p>This is why the whole discussion about JavaScript enabled or disabled is a massive waste of time. It is not the availability of JavaScript we need to worry about. It is our products breaking in perfectly capable environments because we rely on perfect execution instead of writing defensive code. A tumblr like <a class="markup--anchor markup--p-anchor" href="http://sighjavascript.tumblr.com/" rel="nofollow">Sigh, JavaScript</a> is fun, but is pithy finger-pointing.</p> + + <p></p><blockquote>There is nothing wrong with using JavaScript to build things. Just be aware that the error handling is your responsibility.</blockquote><p></p> + + <p>Any message telling the user that they have to turn on JavaScript to use a certain product is a proof that you care more about your developer convenience than your users.</p> + + <p></p><blockquote>It is damn hard these days to turn off JavaScript – you are complaining about a almost non-existent issue and tell the confused user to do something they don’t know how to.</blockquote><p></p> + + <p>The chance that something in the JavaScript execution of any of your dozens of dependencies went wrong is much higher – and this is your job to fix. This is why advice like <a href="http://webdesign.tutsplus.com/tutorials/quick-tip-dont-forget-the-noscript-element--cms-25498">using noscript to provide alternative content</a> is terrible. It means you double your workload instead of enhancing what works. Who knows? If you start with something not JavaScript dependent (or running it server side) you might find that you don’t need the complex solution you started with in the first place. Faster, smaller, easier. Sounds good, right?</p> + + <p>So, please, stop sniffing my browser, you will fail and tell me lies. Stop pretending that working with a brittle technology is the user’s fault when something goes wrong.</p> + + <p></p><blockquote>As web developers we work in the service industry. We deliver products to people. And keeping these people happy and non-worried is our job. Nothing more, nothing less.</blockquote><p></p> + + <p>Without users, your product is nothing. Sure, we are better paid and well educated and we are not flipping burgers. But we have no right whatsoever to be arrogant and not understanding that our mistakes are not the fault of our end users.</p> + + <p>Our demeanor when complaining about how stupid our end users and their terrible setups are reminds me of <a href="https://www.youtube.com/watch?v=CSj5stmFkQ0">this Mitchell and Webb sketch</a>.</p> + + <p></p> + + <p><strong class="markup--strong markup--p-strong">Don’t be that person. </strong>Our job is to enable people to consume, participate and create the web. This is magic. This is beautiful. This is incredibly rewarding. The next markets we should care about are ready to be as excited about the web as we were when we first encountered it. Browsers are good these days. Use what they offer after testing for it and enjoy what you can achieve. Don’t tell the user when things go wrong – they can not fix what you messed up.</p> + + + <img alt="" height="1" src="http://feeds.feedburner.com/~r/chrisheilmann/~4/vqtqgcNQXy8" width="1" /> + Sat, 16 Jan 2016 11:28:10 +0000 + Chris Heilmann + + + Mike Hommey: Announcing git-cinnabar 0.3.1 + http://glandium.org/blog/?p=3510 + http://glandium.org/blog/?p=3510 + <p>This is a brown paper bag release. It turns out I managed to break the upgrade<br /> + path only 10 commits before the release.</p> + <h3>What’s new since 0.3.0?</h3> + <ul> + <li><code>git cinnabar fsck</code> doesn’t fail to upgrade metadata.</li> + <li>The <code>remote.$remote.cinnabar-draft</code> config works again.</li> + <li>Don’t fail to clone an empty repository.</li> + <li>Allow to specify mercurial configuration items in a .git/hgrc file.</li> + </ul> + Sat, 16 Jan 2016 11:26:45 +0000 + glandium + + + Emily Dunham: Buildbot and EOFError + http://edunham.net/2016/01/16/buildbot_and_eoferror.html + http://edunham.net/2016/01/16/buildbot_and_eoferror.html + <h3>Buildbot and EOFError</h3> + <p>More SEO-bait, after tracking down an poorly documented problem:</p> + <div class="highlight-python"><div class="highlight"><pre># buildbot start master + Following twistd.log until startup finished.. + 2016-01-17 04:35:49+0000 [-] Log opened. + 2016-01-17 04:35:49+0000 [-] twistd 14.0.2 (/usr/bin/python 2.7.6) starting up. + 2016-01-17 04:35:49+0000 [-] reactor class: twisted.internet.epollreactor.EPollReactor. + 2016-01-17 04:35:49+0000 [-] Starting BuildMaster -- buildbot.version: 0.8.12 + 2016-01-17 04:35:49+0000 [-] Loading configuration from '/home/user/buildbot/master/master.cfg' + 2016-01-17 04:35:53+0000 [-] error while parsing config file: + Traceback (most recent call last): + File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 577, in _runCallbacks + current.result = callback(current.result, *args, **kw) + File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1155, in gotResult + _inlineCallbacks(r, g, deferred) + File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1099, in _inlineCallbacks + result = g.send(result) + File "/usr/local/lib/python2.7/dist-packages/buildbot/master.py", line 189, in startService + self.configFileName) + --- &lt;exception caught here&gt; --- + File "/usr/local/lib/python2.7/dist-packages/buildbot/config.py", line 156, in loadConfig + exec f in localDict + File "/home/user/buildbot/master/master.cfg", line 415, in &lt;module&gt; + extra_post_params={'secret': HOMU_BUILDBOT_SECRET}, + File "/usr/local/lib/python2.7/dist-packages/buildbot/status/status_push.py", line 404, in __init__ + secondaryQueue=DiskQueue(path, maxItems=maxDiskItems)) + File "/usr/local/lib/python2.7/dist-packages/buildbot/status/persistent_queue.py", line 286, in __init__ + self.secondaryQueue.popChunk(self.primaryQueue.maxItems())) + File "/usr/local/lib/python2.7/dist-packages/buildbot/status/persistent_queue.py", line 208, in popChunk + ret.append(self.unpickleFn(ReadFile(path))) + exceptions.EOFError: + + 2016-01-17 04:35:53+0000 [-] Configuration Errors: + 2016-01-17 04:35:53+0000 [-] error while parsing config file: (traceback in logfile) + 2016-01-17 04:35:53+0000 [-] Halting master. + 2016-01-17 04:35:53+0000 [-] Main loop terminated. + 2016-01-17 04:35:53+0000 [-] Server Shut Down. + </pre></div> + </div> + <p>This happened after the buildmaster’s disk filled up and a bunch of stuff was + manually deleted. There were no changes to master.cfg since it worked + perfectly.</p> + <p>The fix was to examine <span class="docutils literal"><span class="pre">master.cfg</span></span> to see <a class="reference external" href="https://github.com/servo/saltfs/blob/master/buildbot/master/master.cfg#L413">where the HttpStatusPush was + created</a>, + of the form:</p> + <div class="highlight-python"><div class="highlight"><pre><span class="n">c</span><span class="p">[</span><span class="s">'status'</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">HttpStatusPush</span><span class="p">(</span> + <span class="n">serverUrl</span><span class="o">=</span><span class="s">'http://build.servo.org:54856/buildbot'</span><span class="p">,</span> + <span class="n">extra_post_params</span><span class="o">=</span><span class="p">{</span><span class="s">'secret'</span><span class="p">:</span> <span class="n">HOMU_BUILDBOT_SECRET</span><span class="p">},</span> + <span class="p">))</span> + </pre></div> + </div> + <p>Digging in the Buildbot source reveals that <span class="docutils literal"><span class="pre">persistent_queue.py</span></span> wants to + unpickle a cache file from <span class="docutils literal"><span class="pre">/events_build.servo.org/-1</span></span> if there was nothing + in <span class="docutils literal"><span class="pre">/events_build.servo.org/</span></span>. To fix this the right way, create that file + and make sure Buildbot has <span class="docutils literal"><span class="pre">+rwx</span></span> on it.</p> + <p>Alternately, you can give up on writing your status push cache to disk + entirely by adding the line <span class="docutils literal"><span class="pre">maxDiskItems=0</span></span> to the creation of the + HttpStatusPush, giving you:</p> + <div class="highlight-python"><div class="highlight"><pre><span class="n">c</span><span class="p">[</span><span class="s">'status'</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">HttpStatusPush</span><span class="p">(</span> + <span class="n">serverUrl</span><span class="o">=</span><span class="s">'http://build.servo.org:54856/buildbot'</span><span class="p">,</span> + <span class="n">maxDiskItems</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> + <span class="n">extra_post_params</span><span class="o">=</span><span class="p">{</span><span class="s">'secret'</span><span class="p">:</span> <span class="n">HOMU_BUILDBOT_SECRET</span><span class="p">},</span> + <span class="p">))</span> + </pre></div> + </div> + <p>The real moral of the story is “remember to use <a class="reference external" href="http://www.linuxcommand.org/man_pages/logrotate8.html">logrotate</a>.</p> + Sat, 16 Jan 2016 08:00:00 +0000 + + + Daniel Glazman: Ebook pagination and CSS + urn:md5:41d039bb28fb15c761578cba0b1454fa + http://www.glazman.org/weblog/dotclear/index.php?post/2016/01/16/Ebook-pagination-and-CSS + <p>Let's suppose you have a rather long document, for instance a book chapter, and you want to render it in your browser <em>à la</em> iBooks/Kindle. That's rather easy with just a dash of CSS:</p> + <pre>body { + height: calc(100vh - 24px); + column-width: 45vw; + overflow: hidden; + margin-left: calc(-50vw * attr(currentpage integer)); + }</pre> + <p>Yes, yes, I know that no browser implements that <code>attr()</code>extended syntax. So put an inline style on your body for <code>margin-left: calc(-50vw * <em>&lt;n&gt;</em>)</code> where <em><code>&lt;n&gt;</code></em> is the page number you want minus 1.</p> + <p>Then add the fixed positioned controls you need to let user change page, plus gesture detection. Add a transition on margin-left to make it nicer. Done. Works perfectly in Firefox, Safari, Chrome and Opera. I don't have a Windows box handy so I can't test on Edge.</p> + Sat, 16 Jan 2016 03:43:00 +0000 + glazou + + + Nicolas Mandil: Mozilla cultural revolution: from ‘radical participation’ to ‘radical user-centric’ + https://repeer.org/?p=48 + https://repeer.org/2016/01/16/mozilla-cultural-revolution-from-radical-participation-to-radical-user-centric/ + <p>This post has been written about the <a href="http://marksurman.commons.ca/2015/12/21/mofo2020/">Mozilla Foundation (MoFo) 2020 strategy</a>.</p> + <p>The ideas developed in this post are in different levels: some are global, some focus on particular points of the proposed draft. But in my point of view, they all carry a transversal meaning: articulation (as piece connected to a structure allowing movement) with others and consistency with our mission.</p> + <h3>Summary</h3> + <p>On the way to <a href="http://marksurman.commons.ca/2015/01/09/what-is-radical-participation/">radical participation</a>, Mozilla should be radical <sup class="footnote"><a href="https://repeer.org/tag/mozilla/feed/#fn-48-1" id="fnref-48-1">1</a></sup> user-centric. Mozilla should not go against the social understanding of the (tech and whole society) situation because it’s what is massively shared and what polarizes the prism of understanding of the society. <strong>We should built solutions for it and transform (develop and change) it on the way. Our responsibility is to build <em>inclusivity</em> (inclusion strengths) everywhere, to gather for multiplying our impact.</strong> We must build (progressive) victories instead of battles (of static positions and postures).<br /> + If we don’t do it, we go against users self-perceived need: use. We value our differences more than our commonalities and <strong>consider ethic more as an absolute objective than a concrete process</strong>: we divide, separate, compete. Our solutions get irrelevant, we get rejected and marginalized, we reject compromises that improve the current situation for the ideal, we loose influence and therefore impact on the definition of the present and future. We already done it for the good and the bad in the past (H.264+Daala, pocket integration, Hello login, no Firefox for iOS, Google fishing vs Disconnect, FxOS Notes app which sync is evernote only, …).<br /> + To get a consistent and impactful ability to integrate and transform the social understanding, there are four domains where we can take and articulate (connected structure allowing movement) action:</p> + <ul> + <li><strong>People</strong>: identity is the key to grow consciousness, understanding, skills, voice, representation and to articulate global/local, personal/common. <strong>[Activate]</strong></li> + <li><strong>Technology</strong>: universality is key for a platform (for resilience) with interfaces (for modularity) where services, features and front-ends can plug-in and communicate to provide (inter)active support ; Decouple conditions of fulfillment with execution (content/appearance/policy ; material/immaterial) to support remix (policy continuity, consistency thought providers, …). <strong>[Unlock]</strong></li> + <li><strong>Product</strong>: persona and (current and emerging) use via user-agents are the keys. Be on all major platforms depending on use, ethical alignment and opportunities, emerging newness to provide continuity (task, device) to users and leading on new practices. Features should be about products parity and opening new possibilities carrying our values to the action at a massive scale. <strong>[Build]</strong></li> + <li><strong>Organizations/institutions</strong>: sociological innovation for participation is the key. Research on historical (evolution) and sociological (human organizations, social institutions and social behaviors) analysis based on social networks (link as social interactions), in the perspective of producing commons. <strong>[Drive]</strong></li> + </ul> + <p>Our front has two sides: <strong>propose and protect</strong>. But each of them are connected and can have different strategic expressions, if our actions generate improving (progressive) curves:</p> + <ul> + <li>For the <strong>action taking</strong>: consciousness, understanding, symbolic actions, behavior change, behavior advocacy (evangelism)</li> + <li>For the <strong>action mode</strong>: promotion (spreading the idea), incitement (giving a competitive advantage to people involved), collaboration (open interactions to make a win-win exchange; process-centric), contractualization (formalize domains where a win-win exchange is made; object-centric), coercion (giving a competitive disadvantage to people not involved).</li> + </ul> + <p>Social history is a history of social values.<strong> The way we understand and tell the problem determine the solution we can create</strong>: we need, all the way long, a shared understanding. Tools and technologies are not tied, bound forever to their social value, which depends on people’s social representations that evolve over time.</p> + <ul> + <li><strong>The social behavior</strong> is a first key. It is the narrative, and therefore its <strong>inclusion in the social history that we make, which converges the product with the values that it stands for</strong>. Here is the articulation of product with people and technology, of product with leadership network and advocacy engine (it could be less persistent and inclusive: marketing).</li> + <li><strong>The social organization</strong> is a second key. It is about how the process, the tools, the architecture, the governance and the opportunities/constraints have changed for Mozilla (org) and Mozillians (people). <strong>Here comes the question of being open</strong>. It is not enough because it is about availability (passive) and not inclusivity (active). The high level of automation coming is a challenge. We should level-up the meaning to differentiate from others: <strong>Mozilla should activate and unlock societal progress to build fair technical progress</strong>. Mozilla need to <strong>identify its resilient backbone</strong> (not only a technology, the web, but something that articulate people, technology and products) and make it more universal (through people and products). But our goals can’t be absolutely achieved because they have to be considered in a dynamic context. However, the brand engagement is persistent, if it’s included in the product, visible, and centered on easing the user’s action.<br /> + Linked to the ‘being open’ question, the advocacy engine could be a thing to unlock societal progress. People are satisfied of narrow hills of choice until they understand it’s not socially neutral. It’s the case with technology: they accept things about technology to be build top-down. <strong>A successful advocacy, even one about technology, is always built bottom-up</strong>, as its function is to give back the voice to the people, to get them involved, not to make them fulfill our predefined aims. The top-down method is too organization centric and administrative content centric: it can’t massively drive people that are not already committed to the org. It’s usually named advertisement or propaganda. <strong>If we want to have an impact, we should listen to people needs, not tell them to listen to ours</strong>. People want (first) to be empowered, not to empower an org. We need to have content and user centric (not org and it’s process) tools/platform for advocates and leaders: let’s build the technology advocacy plan together. Yes it’s slower, but much more massive, inclusive and persistent. The impact will be higher because it will carry a meaning for people and it wont be too org centric. So it will be qualitatively better: not just an amount, <strong>accumulation is not our goal, but impact, that comes from articulation</strong>. Likewise we should be careful to not use best practice as absolute solutions, but as solutions in a context, if we want to transpose them massively: when we unify we should avoid to homogenize. On the narrative side, our preoccupation should be about building short, medium and long term narrative to get action.</li> + <li><strong>The social institutions</strong> are the third key. Here is the articulation of the leadership network with the advocacy engine. <strong>Leaders build new solutions (products) and Advocates new voices (rallying), they are both about personal development and empower commons.</strong> Leadership=learn+create and advocacy=teach+spread commons. Leaders are projects/orgs leaders, the ones that traduce DNA (values) in products (concrete ability and availability). Advocates are values advocates, the ones that traduce DNA (values) in actions (behavior). As they are both targeting commons, they both produce the same social organization (collaboration instead of competition). They are both involved in creating (different) representations (institutions) and organizations (foundation/firms) but <strong>with a different DNA (values) processing</strong>: from public good to personal benefit or from personal interest to public benefit. If Mozilla cares about public good resilience, <strong>the articulation of their domains of values is critical</strong>. So, on the social organization side, their articulation’s expression and the revision process must be said and clear: from hierarchy or contract or different autonomy levels (internal incubation and external advocacy), or … to criteria to start a revision. About the narrative, and hence about the social behavior side, leaders carry a lot of legitimacy and avoid the stay-experimental or non-massive (unique) thoughts. And we need legitimacy to get impact. But this legitimacy is already present if we<strong> make clear that our actions are about commons</strong>. We should name them creators (compositors or managers) to make it clear that the creative process is a collaboration, made by a team and that the public good do not have the same role in the process and outcome. Full circle.</li> + <li><strong>The social networks</strong> are the keystone. Let’s shortly take an example based on social networks (link as social interactions) with the perspective of producing people, technological and product commons. <strong>We need better tools for collaboration and participation</strong>: tools that merge discussion channels, capitalize on the discussion and preview the results to build a plan. From evolving the wiki discussion page to feature document production into peer-to-peer discussion.</li> + </ul> + <p>An analysis of the creation process is another way to the articulation of product with people and technology.<br /> + Platforms move closer to strict ‘walled garden’ ecosystems. We need bridges from lab to home that carry different mix of customization and reliability to support the emancipation curve. We need to build pathways thought audiences and thought IT layers (content, software, hardware, distant service). <strong>We should find a convergence between customization</strong> (dev code patch to users add-ons) <strong>and reliability</strong> (self made to mass product), <strong>between first time experience, support and add-ons thought all our users’ persona by building bridges, pathways</strong>. Mozilla should find ways to <strong>integrate learning</strong> in its products, in-content, as we have code comment on code: on-boarding levels, progression from simple to high level techniques, reproducible/universal next task/skill building.</p> + <h3>Detailed discussion content</h3> + <p>Here are the developed ideas, with more reference to our allies and detractors’ products.</p> + <h4>People, the sociological side</h4> + <h5>From focused to systemic action</h5> + <p>First of all, I think <strong>the strategy move Mozilla is doing is the right one</strong> as it embraces more our real life. People are not defined by one characteristic, we are complex: ex. we can be pedestrian, car driver, biker, Public Transport user… we think and do simultaneously. So why Mozilla should restrict its strategy by targeting people on skills, through education, thought better material only (the Mozilla Academy program). Education, even popular education, can’t do everything for the people to build change. <strong>We need a plan that balance intellectual and practical (abstraction/action, think/do) integrating progressive paths to massively scale so we get an impact: build change.</strong></p> + <h5>Real life: Social history, individuals and institutions as an articulation founding the action.</h5> + <p>Let’s start by some definitions based on my understanding of some <a href="https://fr.wikipedia.org/wiki/Sociologie">Wikipedia articles</a>. Sociology is the study of the evolution of societies: human organizations and social institutions. It is about <strong>the impact of the social dimension on humans representations (ways of thinking) and behaviors (ways of acting)</strong>. It allows to study the conceptions of social relations according to fundamental criteria (structuralism, functionalism, conventionalism, etc.) and the hooks to reality (interactionism, institutionalism, regulationisme, actionism, etc.), to think and shape the modernity. Currently (and this is key for Mozilla’s positioning), the combination of models replace the models’ unity, which aims to assume the multidimensionality. There are three major sociological paradigms, including one emerging:</p> + <ul> + <li><strong>The holistic paradigm</strong>: Society is a whole that is greater than the sum of its parts, it exists before the individual and individuals are governed by it. In this context, the Society includes the individual and the individual consciousness is seen only as a fragment of the collective consciousness. The emphasis is on the social fact, whose cause must be sought in earlier social facts. The social fact is part of a system of interlocking institutions that govern individuals. It is external to the individual and constraint it. Sociology is then the science of institutional invariants in which are the observable phenomenas.</li> + <li><strong>The atomistic paradigm</strong>: each individual is a social atom. The atoms act according to self motives, interests, emotions and are linked to other atoms. A system of constant interaction between atoms produces and reproduces Society. The emphasis is on the cause of social actions and the meaning given by individuals to their actions. A horizon of meanings serve as reference instead of the arrangements of institutions. The institution is there but it serves the motives and interests of agents. Sociology is then the study of the social action.</li> + <li>The recent emergence of a sociological analysis based on <strong>social networks</strong> (which are a collection of individuals or organizations connected by regular social interactions) suggest lines of research <strong>beyond the opposition between the holistic and the atomistic approaches</strong>. The theory of social networks conceives social relationships in terms of nodes and links. The nodes are usually social actors in the network but can also represent institutions, and links are the relationships between these nodes. There may be several kinds of links between nodes and their analysis determines social capital of the social actors.</li> + </ul> + <p>Consequently, Mozilla should build its strategy on <strong>historical</strong> (evolution) and <strong>sociological</strong> (human organizations, social institutions and social behaviors) analysis based on <strong>social networks</strong> (links as social interactions), in the perspective of producing <strong>commons</strong>. That is to say as an <strong>engine of transition from a model of value</strong> on its last leg (rarity capitalism) to the emerging one (new articulation of the individual and the collective: commons).<br /> + It is important and strategic to propose a sociological articulation supporting our mission and its purpose (commons) since <strong>the sociological concept (the paradigm) reveals an ideological characteristic</strong>: because it participates in societal movements made in the Society, it serves an ideal. The societal domain, what’s making society, a political object, should be a stake for Mozilla.</p> + <h5>Build on a basement: current tech challenge articulated with current social meaning/perception</h5> + <p><strong>We should articulate ‘our real life’ with the nowadays tech challenge</strong>: how to get back control over our data at the time of IoT, cloud, big data, convergence (multi-devices/form factor)? From a user point of view, we have devices and want them convenient, easy and nice. The big moves in the tech industry (IoT, cloud, big data, convergence) free us for somethings and lock us for others. The lock key is that our devices don’t compute anymore our data that are in silos. From a developer point of view, the innovation is going very fast and it’s hard to have a complete open source toolbox that we can share, mostly because we don’t lead: Open has turn to be more open-releasing.<br /> + We should articulate our new strategy with the tech industry moves: for example, <strong>as a user, how can I get (email) encryption on all my devices?</strong> Should I follow (fragmented) different kind of howtos/tools/apps to achieve that? How do I know these are consistent together? How can I be sure it won’t brake my continuous workflow? (app silo? social silo? level of trust and reliability?)<br /> + Mozilla have the skills to answer this as we already faced and solved some of these issues on particular points: like how to ease the installation of Firefox for Android for Firefox desktop users, open and discoverable choice of search engines, synchronization across devices, …<br /> + <strong>Mozilla’s challenge is to not be marginalized by the change of practices. Having an impact is embracing the new practice and give it an alternative.</strong> Mozilla already made that move by saying « <em>Firefox will go where users are</em>« , by trying to balance the advertisement practice between adds companies and users, by integrating H.264 and developing Daala. But <strong>Mozilla never stated that clearly as a strategy</strong>.</p> + <h5>A backbone to make our mission resilient in it expressions</h5> + <p>If we think about the <strong>Facebook’s strategy, they first built a network of people whiling to share</strong> (no matter what they share) and then use this <strong>transversal backbone to power vertical business segments</strong> (search, donation, local market selling, …). Google with its search engine and its open source policy have a similar (in a way) strategy. The difference here is that the backbone is people’s data and control over digital formats. In both cases, the level of use (of the social network, search engine, mobile OS, …) is the key (with fast innovation) to have an impact. And that’s a major obstacle to build successful alternatives.<br /> + The proposed Mozilla’s strategy is built in the opposite way, and that’s questioning. <strong>We try to build people network depending on some shared matters</strong>. Then, is our strategy able to scale enough to compete against GAFAM, or are we trying to build a third way ?<br /> + For the products, the Mozilla’s strategy is still (and has always been) inclusive: everybody can use the product and then benefit of its open web values. A good product that answer people needs, plus giving people back/new power (allow new use) build a big community. For the network, should we build our global force of people based on concentric circles (of shared matters) or based on a (Mozilla own) transversal backbone (matter agnostic)? It seems to me the actual presentation of the strategy do not answer clearly enough this big question: <strong>which <em>inclusivity</em> (inclusion strengths) mechanism in the strategy?</strong><br /> + And that <strong>call back to our product strategy</strong>: build a community that shares values, that is used to spread outcomes (product) OR build a community that shares a product, that is used to spread values. This is not a question on what matters more (product VS values) but on the strategy to get to a point, an objective (many web citizens). Shouldn’t we use our product to built a people network backbone ? Back to GAFAM: what can we learn from the Google try with Google+?<br /> + If our core is not enough transversal (the backbone), more new web/tech market there will be, more we will be marginalized, because focused on our circles center not taking in account that the war front (the context) have changed. <strong>Mozilla have to be resilient: mutability of the means, stability in the objectives.</strong><br /> + The document is the MoFo strategy, and so it doesn’t say anything about ‘build Firefox’ (aka the product strategy) and so don’t articulate our main product (Firefox) with our main people network building effort and values sharing engine. We should do it: at a strategic scale and a particular scale (articulating the agenda-setting with main product features).</p> + <h5>Brand engagement, a psychological backbone on the user side ?</h5> + <p>It seems that our GAFAM challengers get big and have impact by not educating (that much) people, and that’s what makes them not involved in the web citizenship. Or only when they are pushed by their customers. At the opposite, making people aware about web citizenship at first, makes it hard to have that much people involved and so to have impact. However, there is <strong>an other prism that drive people: the brand perceived values</strong>. Google is seen as a tech pioneer innovator and doing the good because of its open policy, free model, fast innovation… Facebook is seen as really cool firm trying to help people by connecting them…<br /> + Is the increase of marketing of Mozilla doing good enough to gains back users ? Is this resilient compared to the next-tech-thing coming ?<br /> + Most of the time when I meet Goggle Chrome users and ask then why they use it and don’t switch to Firefox, they answer about use allowed (sync thought devices, apps everywhere that run only on GC, …). Sometimes, they argue that they make effort on other areas, and that they want to keep they digital life simple. They <strong>experience is not centered in a product/brand, but more on the person</strong>: on that Google Chrome with its Person (with one click ‘auto-login’ to all Google services) is far superior than Firefox.</p> + <h5>User-agent or products ?</h5> + <p>A user-agent is an intermediary acting on behalf of a supplier. As a representative, it is the contact point with customers; It’s role is to manage, to administer the affairs; it is entrusted with a mission by one or more persons; it both acts and produce an effect.<br /> + So, the user-agent can be describe with three criteria. It is: an intermediate (user/technology) ; a tool (used to manage and administrate depending on the user’s skills) ; a representative (mission bearer, values vector, for a group of people). It exceeds partly the contradiction between being active and passive.<br /> + A <strong>user-agent articulate personal-identity with technology-identity</strong> and give informations about available skills over these domains. It’s much more universal than a product that is about featuring a user-agent. <strong>If we target resilience, user-agent should be the target</strong>.</p> + <h4>Social history, marketing: how we understand things to make choices</h4> + <h5>History of the social value</h5> + <p>The way we look at the past and current facts shape our understanding and determine if we open new ways to solve the issues identified. That’s the way to understand the challenges that come on the way and to agree on an adaptation of the strategy instead of splitting things. The way we understand and tell the problem determine the solution we can create: we need, all the way long, <strong>a shared understanding.</strong><br /> + <strong>Tools and technologies are not necessarily tied to their social value, which depends on social representations. The social value can be built upstream and evolve downstream.</strong> It also depends on the perspective in which we look at it, on the understanding of the action and therefore on past or current history. Example: the social value of a weapon can be a potential danger or defense, creative (liberating) or destructive. The nuclear bomb is a weapon of mass destruction (negative), whose social value was (ingeniously built as) freedom (positive).</p> + <h5>Impact in our strategy: a missing root</h5> + <p>To engage the public, before to « <em>Focus on creative campaigns that use media + software to engage the public.</em> » we need to step back, in our speeding world, for understanding together the big picture and the big movement.<br /> + Mozilla want to fuel a movement and propose a strong and consistent strategy. However, I think <strong>this plan miss a key point, a root point: build a common (hi)story.</strong> This should be an objective, not just an action.<br /> + Also, that’s maybe a missing root for the State of the web report: how do we understand what we want to evaluate? But it’s not only a missing root for an (annual?) report (a ‘Reporters without borders’ Press-Freedom like?), it’s a missing root for a new grow of our products’ market share.<br /> + For example, I do think that most users don’t know and understand that Mozilla is a foundation, Firefox build by a community as a product to keep the web healthy: <strong>they don’t imagine any meaning about technology</strong>, because they see it as a neutral tool at its root, so as a tool that should just fit they producing needs.<br /> + Firefox, its technologies and its features are not bound for ever. It is the narrative, and therefore their inclusion in the social history that we make, which converges Firefox with the values that it stand for. <strong>Stoping or changing the deep narrative means cutting the source of common understanding and making stronger other consistencies captured by other objects, turning as centrifugal forces for Firefox.</strong><br /> + Marketing is a way to change what we socially say about things: that’s why Google Chrome marketing campaign (and consistent features maturity) has been the decreasing starting point of Firefox. <strong>Our message has been scrambled.</strong></p> + <h4>From participation to emancipation: values, people and org relationships</h4> + <p>How to emancipate people in the digital world ?</p> + <h5>Keeping the open open</h5> + <p>Being open is not a thing we can achieve, it’s a constant process. « <em>Mozilla needs to engage on both fronts, tackling the big problems but also fuelling the next wave of open.</em> » Yes, but <strong>Mozilla should say too how the next wave of open can stay under people’s control and rally new people</strong>. Not only open code, but open participation, open governance, open organization. Being open is not a releasing policy about objects, it’s a mutation to participation process: a metamorphosis. It’s not reached by expanding, but by shifting. It’s not only about an amount, but about values: it’s qualitative.<br /> + Maybe <strong>open is not enough</strong>, because it doesn’t say enough about who control and how, about the governance, and says too much about <strong>availability (passive)</strong> and not enough <strong>about <em>inclusivity</em> (active ; inclusion strengths)</strong>. It doesn’t say how the power is organized and articulated to the people (ex. think about how closed is the open Android). We may need to change the wording: indie web, the web that fuel autonomy, is a try, but it doesn’t say enough about <em>inclusivity</em> compared to openness &amp; opportunity. Emancipation is the concept. It’s strategic because it says what is aligned to what, especially how to articulate values and uses. It’s important because it tells what are the sufficient conditions of realization to ‘open/indie’. That’s key to get ‘open/indie at small and large scales, from Internet people to Internet institutions, thought all ‘open/indie’ detractors in the always-current situation: a resilient ecosystem.<br /> + My intuition is that <strong>the leadership network and advocacy engine promoting open will be efficient if we clarify ‘open’ while keeping it universal</strong>. We can do it by looking back at the raw material that we have worked for years, our DNA in action. Because after all, we are experts about it and wish others to become experts too. It does not mean to essentialize it (opposing its nature and its culture), <strong>but to define its conditions of continuous achievement in our social context</strong>.</p> + <h5>Starting point: exemplary projects that tell a lot about the evolution of our DNA in action</h5> + <p>Clarifying the idea of ‘open’ is strategic to our action because it outlines the constitution of ‘open’, its high ‘rules’, like with laws in political regimes. It clarifies for all, if you are part of it or not, and it tells you what to change to get in. It can reinforce the brand by differentiating from the big players that are the GAFAM: <strong>it’s a way to drive, not to be driven by others lowering the meaning to catch the social impact. We should say that ‘open’ at Mozilla means more than ‘open’ at GAFAM</strong>. I wish Mozilla to speak about its openness, not as an ‘equal in opportunity’ but as an ‘equal in participation’, because it fits openness not only for a moment (on boarding) or for a person, but during the whole process of people’s interaction.<br /> + <a href="https://www.rust-lang.org/">Rust</a> and <a href="https://servo.org/">Servo</a> or <a href="https://firefoxos.mozilla.community/">Firefox OS</a> (since the Mozilla’s shift to radical participation) seem to be very good examples of projects with participation &amp; impact centric rules, tools, process (RFC, new team and owners, …). Think about how Rust and <a href="http://arc.applause.com/2015/03/27/google-dart-virtual-machine-chrome/">Dart emerged and are evolving</a>. Think about how stronger has been the locked-open Android with partnership than the open-locked FxOS. We should tell those stories, not as recipes that can be reproduced, but as process based on a Constitution (inclusive rules) that make a political regime (open) and define a mode of government (participation). That’s key to social understanding and therefore to transpose and advocate for it.<br /> + As projects<strong> compared to ‘original Mozilla’, Rust, Servo and FxOS could say a lot</strong> about how different they implemented learning/interaction/participation at the roots of the project. How the process, the tools, the architecture, the governance and the opportunities/constraints have changed for Mozilla and participants. This could definitely help to setup our curriculum resources, database and workshop at a personal (e.g., “How to teach / facilitate / organize / lead in the open like Mozilla.”) and orgs levels, with personal and orgs policies.</p> + <h5>Spreading the high meanings in our strategy to consolidate it consistency</h5> + <p>Clarifying the constitution of ‘open’ calls to clarify other related wordings.<br /> + I’m satisfied to read back (social) ‘movement’ instead of ‘community’, because it means that our goal can’t be achieve forever (is static), but we should protect it by acting. And it seems more inclusive, less ‘folds on itself’ and less ‘build the alternative beside’ than ‘community’: the alternative can be everywhere the actual system is. It can make a system. It can get global, convergent, continuous, … all at the same time. Because it’s roots are decentralized _and_ consistent, collaborating, …</p> + <p>About participation, we should think too (again) about engagement VS contribute VS participate: how much am I engaged ? Free about defining and receiving cost/gains? What is the impact of my actions ? … <strong>These different words carry different ideas about how we connect the ‘open’</strong>: spread is not enough because it diffuses, _be_ everywhere is more permanent. Applied to Mozilla’s own actions, <strong>funding open projects and leaders, is maybe not enough and there should be others areas where we can connect</strong> inside products, technology, people and organizations that build emancipation. So that say something about getting control (who, how, …).</p> + <h5>IA: a challenge for ‘open’</h5> + <p>IA is first developed to help us by improving our interactions. However, this seems to start to shift into taking decisions instead of us. This is problematic because these are indirect and direct ways for us to loose control, to be locked. And that can be as far as computers smarter than humans. The problem is that technical progress is made without any consideration of the societal progress it should made.<br /> + That’s an other point, why open is not enough: automation should be build-in with superior humanization. <strong>Mozilla should activate and unlock societal progress to build fair technical progress.</strong></p> + <h5>Digital integration &amp; democracy</h5> + <p>The digital (&amp; virtual) world is gaining control over the physical world in many domains of our society (economy to finance, mail to email, automatic car, voting machine, …). It’s getting more and more integrated to our lives without getting back our (imperfect) democracy integrated into them. Public benefit and public good are turning ‘self benefit’ and ‘own sake’ because citizens don’t have control over private companies. <strong>We should build a digital democracy if we don’t want to loose at all the democratic governing of society.</strong> We must overcome the poses and postures battles about private and public. We need to build.</p> + <h4>‘Leader’ &amp; ‘Leadership’ need a clarification</h4> + <h5>Why a clarification?</h5> + <p>At some level, I’m not the only one to ask this question:</p> + <blockquote><p>How do CRM requirements for Leadership and Advocacy overlap / differ? What’s our email management / communications platform for Leadership?</p></blockquote> + <p>Connect leaders to lead what ? How ? To whose benefit ? Do we want to connect leaders or initiatives (people or orgs) ? Will the leaders be emerging ones (building new networks) or established ones (use they influence to rally more people)? Are Leaders leaders of something part of Mozilla (like can be Reps) or outside of Mozilla (leaders of project, companies, newspaper: tech leaders, news leaders, …) ? This is especially important depending on what is the desire for the leaders to become in the future. <strong>The MoFo’s document should be more precise</strong> about this and go forward than « <em>Mozilla must attract, develop, and support a global network of diverse leaders who use their expertise to collaboratively advance points-of-view, policies and practices that maintain the overall health of the Internet.</em> »<br /> + We should do it because <strong>the confusion about the leadership impact the advocacy engine</strong>: « <em>The shared themes also provide explicit opportunities for our Leadership and Advocacy efforts to work together.</em> » Regarding Mozilla, is the leaders role to be advocacy leaders ? It seems as they share themes and key initiatives (even if not worded the same sometimes). Or in other words, who Drives the Advocacy engine?</p> + <h5>Iterations with the actual definition: creators</h5> + <p>Here are my iterations on the definition of ‘Leaders’:</p> + <ul> + <li>The Leaders could be the people platform (the community) and the advocacy engine the tool/themes/actions platform (the product).</li> + <li>Leaders could build at the end new solutions (products) and Advocates new voices (rallying), that could be translated in a learning area divided like Leadership=learn+create and advocacy=teach+spread.</li> + <li>Leadership: personal development to produce (turn into) new commons or add new facets to commons. Advocacy: personal development to protect established/identified commons.</li> + </ul> + <p>With these definitions, then Leaders are maybe more a Lab, R&amp;D place, incubation tool (if we think about start-up incubators, then it shows a tool-set that we will need to inspire for the future). But if we want to keep the emphasis on people, <strong>we could name them ‘creators’</strong> (compositors or managers ; not commoners, because leaders and advocates are commoners ; yes, traditionally creators are craftspersons and intellectual designers). This make sens with the examples given in the MoFo 2020 strategy 0.8 document, where all persona are involved in a building-something-new process.</p> + <p>However, it’s interesting to understand why we choose at first ‘Leaders’. <strong>Leaders build new solutions (products) and Advocates new voices (rallying), they are both about personal development and empower commons.</strong> Leadership=learn+create and advocacy=teach+spread commons. Leaders are projects/orgs leaders, the ones that traduce DNA (values) in products (concrete ability and availability). Advocates are values advocates, the ones that traduce DNA (values) in actions (behavior). As they are both targeting commons, they both produce the same social organization (collaboration instead of competition). They are both involved to create (different) representation (institutions) and organization (foundation/firms) but <strong>with a different DNA (values) processing</strong>: from public good to personal interest or the opposite. If Mozilla cares about public good resilience, <strong>the articulation of they domains of values is critical. So their articulation’s expression and the revision process must be said and clear</strong>: from hierarchy vs contract vs different autonomy levels (internal incubation and external advocacy), vs … to criteria to start a revision.</p> + <h5>The network effect</h5> + <p>Another argument for the switch from Leader to Creator is that the Leader word it too much tight to a single-person-made innovation. <strong>Creator make more clear that the innovation is possible not because of one genius, but because of a team</strong>, a group, a collective: personS (where there could also be genius). The value is made by the collaboration of people (especially in an open project, especially in a network).<br /> + That’s important because that could impact how well we do the convening part: not self-promoting, not-advertising, but sharing skills and knowledge for people and catalysing projects.<br /> + <strong>The same for the wording ‘talent’</strong>: alone, a talent can do nothing that has an impact. At least, we need two talents, a team (plus some assistants at some point).</p> + <h5>The cultural prism</h5> + <p>Again, this seems to be an open question:</p> + <blockquote><p>Define and articulate “leadership.” Hone our story, ethos and definition for what we mean by “leadership development” (including cultural / localization aspects).</p></blockquote> + <p>In my culture, Leader carry positive (take action) and negative (dominate) meanings. That’s another reason why I prefer another naming.<br /> + I understand too that it carries a lot of legitimacy (ex. market leader) in our societies and it avoids the stay-experimental or non-massive (unique) thoughts. And we need legitimacy to get impact.<br /> + But the way Mozilla has an impact thought all cultures, its <strong>legitimacy, is by creating or expanding a common</strong>. To do this, depending on the maturity, Mozilla could follow the market proposing an alternative with superior usability OR opening a new market by adding a vertical segment.</p> + <h5>Existing tool-set opportunities</h5> + <p>If Leadership is « <em>a year-round MozFest + Lab</em>« , so it’s a social network + an incubation place. Then, we already have a social network for people involved with Mozilla: Which kind of link should have the leadership network with <strong>mozillians.org</strong> ? What can we learn from this project and other specialized social network projects (linkedin, viadeo, …) to build the leadership network ?</p> + <h4>Advocacy engine: make it clear</h4> + <h5>What it is &amp; how it works</h5> + <p>Mozilla is doing a great effort to build its advocacy engine on collaboration (« <em>Develop new partnerships and build on current partnerships</em>« , « <em>begin collaboration</em>« , « <em>build alliances with similar orgs</em>« ) but at the same time affirms that Mozilla should be « <em>Part of a broader movement, be the boldest, loudest and most effective advocates</em> » that could be seen as too centralized, too exclusive.<br /> + While this can be consistent (or contradictory), <strong>the consistency has to be explained</strong> looking at orgs and people, global and local, abstract and real, with a complementarity/competitive grid.<br /> + First, <strong>the articulation with other orgs has to be explained</strong>. What about others orgs doing things global (<a href="https://eff.org/">EFF</a>, <a href="https://fsf.org/">FSF</a>, …) and local (<a href="http://www.laquadrature.net/">Quadrature du net</a>, CCC, …) ? What about the value they give and that Mozilla doesn’t have (juridic expertise for example) ? What about other advocate engines (<a href="https://change.org/">change.org</a>, <a href="https://secure.avaaz.org/">Avaaz</a>…) ? That should not be at an administrative level only like « <em>Develop an affiliate policy. Defining what MoFo does / does not offer to effectively govern relationships w. affiliated partners and networks (e.g., for issues like branding, fundraising, incentives, participation guidelines, in-kind resources.)</em> »<br /> + Second, this is key for users to understand and <strong>articulate the global level of the brand engagement and their local preoccupations and engagement</strong>. How the engine will be used for local (non-US) battles ? In the past Mozilla totally involved against PIPA, SOPA by taking action, and hesitate a lot to take position and just published a blog post (and too late to gain traction and get impact) against French spying law for example.<br /> + Third, <strong>the articulation ‘action(own agenda)/reaction’ should be clarified</strong> in the objectives and functioning of the advocacy engine. Especially because other orgs, allies or detractors, try to to setup the social agenda. It’s important because it can change the social perception of our narrative (alternative promotion/issue fighting) and therefore people’s contributions.<br /> + People think the technology is socially neutral. People are satisfied of narrow hills of choice (not the meaning, the aim, but only the ability to show your favorite avatar). <strong>People don’t want to feel guilty or oppressed</strong>, they don’t want new constraints, they are looking for solution only: they want to use, not to do more, they want they things to be done. Part of the problem is about understanding (literacy, education), part of it is about the personal/common duality, part of it is about being hopeless about having an impact, part of it is about expressing change as a positive goal and a new possible way (alternative), not a fight against an issue. About the advocacy engine, I think <strong>our preoccupation should be people-centric and the aim to give them a short, medium and long term narrative to get action without being individuals-centric</strong>.</p> + <h5>How we build it ?</h5> + <p>How to build a social movement ? How it has been built in the past ? Is it the same today ? Can it be transposed to the digital domain from others social domains ? How strong are the cultural differences between nations? These are the main questions we should answer, and our pivot era gives us many examples in diverse domains (climate change advocates, Syriza &amp; Podemos, NSA &amp; surveillance services in Europe, empowered syndicates in Venezuela, <a href="http://blogs.valvesoftware.com/economics/why-valve-or-what-do-we-need-corporations-for-and-how-does-valves-management-structure-fit-into-todays-corporate-world/#more-252">Valve corp. internal organization</a>…) to set a search terrain. However, I will go strait to my intuitive understanding below.<br /> + I’m kind of worried that it’s imagined to build the advocacy engine themes by a top-down method. <strong>I think a successful advocacy is always built bottom-up</strong>, as its function is to give back the voice to the people, to get them involved, not to make them fulfill our predefined aims. The top-down method is too organization centric: it can’t massively drive people that are not already committed to the org. It’s usually named advertisement or propaganda. If we want to have impact, <strong>we should listen to people needs, not tell them to listen to ours. People want (first) to be empowered, not to empower an org</strong>. So let’s organize the infrastructure, set the agenda and draw the horizon (strategic understanding) participative: make people fill them with content of their experience. It seems to me it is the only way, the only successful method, if we want to build a movement, and not just a shifting moment (that could be built by the top, with a good press campaign locally relayed for example ; that’s what happen in old style politics: the aim is short term, to cleave).<br /> + <strong>Isn’t the advocacy engine a new Drumbeat ?</strong> We shifted from Drumbeat to Webmaker+web literacy to Mozilla Academy and now to Leadership plus advocacy: it could be good to tell that story now that we are shifting again and learn from it.<br /> + <strong>Mozilla should support, behave as a platform</strong>, not define, not focus. Letting the people set the agenda makes them more involved and is a good way to build a network of shared aims with other orgs, that is not invasive or alienating, but a support relationship in a win-win move. The strength comes from the all agendas sewed. So at an org level, let’s on-board allies organizations as soon as plan building-time (now), to build it together. Yes it’s slower, but much more massive, inclusive and persistent.</p> + <h5>How we evaluate it: cultural bias &amp; qualitative analysis</h5> + <p>First, about the agenda-setting KPI for 2016, should these KPI be an evaluation of the inclusion and rank in others strategic agendas, governance systems and productions (outcome/products) ? Others org could be from different domains: political, social, economy orgs.<br /> + Then, as a wide size audience KPI, Mozilla wants « <em>celebration of our campaigns with ‘headline KPIs’ including number of actions, and number of advocates.</em>« . While doing this could be the right thing to do for some cultures, it could be the worst for others. I think that these KPI don’t carry a meaning for people and are too org centric. In a way, they are to generic: it’s just an amount. <strong>Accumulation is not our goal: we want impact that is the grow of articulated actions</strong> made by diverse people toward the same aim. <strong>We need our massive KPI to be more qualitative</strong>, or at least find a way to present them in a more qualitative way: interactive map ? a global to local prism that engages people for the next step ?</p> + <h5>Best practices &amp; massive impact</h5> + <p>Selecting best practices are an appealing method when we want to have a fast and strong impact in a wide area. However, <strong>when we unify we should avoid to homogenize</strong>. The gain in area by scaling-up is always at the cost of loosing local impact because it is not corresponding to local specificities, hence to local expectations. Federating instead of scaling-up is a way to solve this challenge. So we should be careful to not <strong>use best practice as absolute solutions, but as solutions in a context</strong> if we want to transpose them massively.</p> + <h5>Tools &amp; platform balanced between user-centric and org-centric outcomes</h5> + <p>It’s good to hear that we will build a advocacy platform. As we ‘had’ bugzilla+svn then mercurial (hg)+… and are going to the <strong>integrated</strong>, <strong>pluggable</strong> and <strong>content-centric</strong> (but non-free; admin tools are closed source) github (targeting more coder than users, but with a lower entry price for users still), we need to be able to have the same kind of tool for advocates and leaders. Something inspired maybe at some levels by the remixing tools we built in Webmakers for web users.</p> + <h4>From experiment to production: support (self made to mass product) + modularity (dev code patch to users add-ons).</h4> + <p><strong>We need pathways from lab to home that carry different mix of customization and reliability to support the emancipation curve.</strong><br /> + Users want things to work, because they want to use it. Geeks want to be able to modify a lot and accept to put their hands in the engine to build growing reliability. Advanced users want to customize their experience and keep control and understanding on working status. They want to be able to fix the reliability at a medium/low technical cost. They are OK to gain more control at these prices. Users want to use things to do what they need and want to trust a reliability maintained for them. They are OK to gain control at a no technical cost. Depending on the matter we all have different skill levels, so we are all geeks, advanced users and users depending on our position or on the moment. And depending on our aspirations, we all want to be able to move from one category to an other. That’s what we need to build: we don’t just need to « <em>better articulate the value to our audiences</em>« , <strong>we need to build pathways thought audiences and thought IT layers</strong> (content, software, hardware, distant service). <strong>We should find a convergence between customization and reliability, between first time experience, support and add-ons thought all our users’ persona by building bridges, pathways</strong>. So, « <em>better articulate the value to our audiences</em> » should not be restrained in our minds to the Mozilla Leadership Network.<br /> + <strong>Part of this is being done in other projects outside of Mozilla in the commons movement.</strong> There are many, but let’s take just one example, the <a href="https://www.fairphone.com/">Fairphone</a> project: modularity, howtos, … all this help to break the product-to-use walls and drive appropriation/emancipation. <strong>Products are less product and brand centric and more people/user centric</strong>.<br /> + Part of this has been done inside Mozilla, like integrating learning in our products, in-content, as we have code comment on code. I think <strong>the <a href="https://wiki.mozilla.org/Firefox_OS/Spark">Spark</a> project on Firefox OS is on a promising path</strong>, even if maybe immature: it maybe has not been released mainstream because it misses bridges/pathways (on-boarding levels, progression from simple to high level techniques, and no or not enough reproducible/universal next task/skill building).<br /> + So some solutions start to emerge, the direction is here, but has never been conceived and implemented that globally, as there isn’t integrated pathways with choice and opportunity and a strategy embracing all products and technologies (platform, tools, …).</p> + <h4>Better tools for collaboration and participation: task-centric to process-centric (use) infrastructure</h4> + <p><strong>The open community should definitely improve the collaboration tools and infrastructure to ease participation.</strong><br /> + <strong><a href="http://www.discourse.org">Discourse</a> ‘merged’ discussion channels</strong>: email+forum(+instant, messaging, … and others peer-to-peer discussion?). <strong><a href="http://stackexchange.com">Stack exchange</a> merged the questioning/solving process</strong> and added a vote mechanism to rank answers: it eased the collaboration on editing the statement and the results while staying synchronous with the discussion and keeping the discussion history. We need such kind of possibilities with discourse: <strong>capitalize on the discussion and preview the results to build a plan.</strong><br /> + This exist in document oriented software (that added collaboration editing tools), but not that much in collaboration software (that don’t produce documents). For example, while discussing the future plan for Fx/FxOS be supported to keep track on a doc about the proposals plans + criteria &amp; dependencies. In action, it is from <a href="https://mail.mozilla.org/pipermail/firefox-dev/2015-July/003063.html">this</a> plus all the discussion taking place to <a href="https://mail.mozilla.org/pipermail/firefox-dev/2015-July/003119.html">that</a>.<br /> + This is maybe something like integrating Discourse+Wiki, maybe with the need to have competing and ranked (both for content and underlaying meaning of content=strategy?) plan/page proposals. <strong>From evolving the wiki discussion page to featuring document production into peer-to-peer discussion.</strong></p> + <h4>A recovering strategy: from fail to win</h4> + <p>There is maybe one thing that is in the shadow in this plan: <strong>what do we do when/if we (partially) fail ?</strong><br /> + I think at least we should say that <strong>we document</strong> (keep research going on) to be able to outline and spread the outcomes of what we tried to fight against. So we still try to built consciousness to be ready for the next round.</p> + <p> </p> + <p><em>If you see some contradiction in my thoughts, let’s say it’s my state of thinking right now: please voice them so we can go forward.</em><br /> + <em> The same for thoughts that are voiced definitive (like users are): take it as a first attempt with my bias: let’s state these bias to go forward.</em></p> + <div class="footnotes" id="footnotes-48"> + <div class="footnotedivider"></div> + <ol> + <li id="fn-48-1"> ‘<em>Radical</em>‘ can be in some cultures an euphemism to ‘<em>violent</em>‘. Let’s be clear that the change by increasing violence is done to make a popular uprising of some part against others. While it does not help the majority to magically understand that the minority is right, it stigmatize the radical-violent-changers and in the way it discredits the alternative proposed. <span class="footnotereverse"><a href="https://repeer.org/tag/mozilla/feed/#fnref-48-1">↩</a></span></li> + </ol> + </div> + Sat, 16 Jan 2016 00:27:13 +0000 + Nicolas + + + Will Kahn-Greene: pyvideo status: January 15th, 2016 + http://bluesock.org/%7Ewillkg/blog/pyvideo/status_20160115.html + http://bluesock.org/%7Ewillkg/blog/pyvideo/status_20160115.html + <div class="section" id="what-is-pyvideo-org"> + <h3>What is pyvideo.org</h3> + <p><a class="reference external" href="http://pyvideo.org/">pyvideo.org</a> is an index of Python-related conference and user-group videos on + the Internet. Saw a session you liked and want to share it? It's likely you can + find it, watch it, and share it with pyvideo.org.</p> + <p>This is the latest status report for all things happening on the site.</p> + <p>It's also an announcement about the end.</p> + <p><a href="http://bluesock.org/~willkg/blog/pyvideo/status_20160115.html">Read more…</a> (5 mins to read)</p></div> + Fri, 15 Jan 2016 23:30:00 +0000 + Will Kahn-Greene + + + Chris Cooper: RelEng & RelOps Weekly Highlights - January 15, 2016 + http://coopcoopbware.tumblr.com/post/137371863755 + http://coopcoopbware.tumblr.com/post/137371863755 + <p>One of releng’s big goals for Q1 is to deliver a beta via <a href="https://bugzil.la/release-promotion" target="_blank">build promotion</a>. It was great to have some tangible progress there this week with bouncer submission.</p> + + <p>Lots of other stuff in-flight, more details below! + </p><p><b>Modernize infrastructure</b>:</p> + + <p>Dustin worked with Armen and Joel Maher to run Firefox tests in TaskCluster on an older EC2 instance type where the tests seem to fail less often, perhaps because they are single-CPU or slower.</p> + + <p><b>Improve CI pipeline</b>:</p> + + <p>We turned off automation for b2g 2.2 builds this week, which allowed us to remove some code, reduce some complexity, and regain some small amount of capacity. Thanks to Vlad and Alin on buildduty for helping to land those patches. (<a href="https://bugzil.la/1236835" target="_blank">https://bugzil.la/1236835</a> and <a href="https://bugzil.la/1237985" target="_blank">https://bugzil.la/1237985</a>)</p> + + <p>In a similar vein, Callek landed code to disable all b2g desktop builds and tests on all trees. Another win for increased capacity and reduced complexity! (<a href="https://bugzil.la/1236835" target="_blank">https://bugzil.la/1236835</a>)</p> + + <p><b>Release</b>:</p> + + <p>Kim finished integrating bouncer submission with our release promotion project. That’s one more blocker out of the way! (<a href="https://bugzil.la/1215204" target="_blank">https://bugzil.la/1215204</a>)</p> + + <p>Ben landed several enhancements to our update server: adding aliases to update rules (<a href="https://bugzil.la/1067402" target="_blank">https://bugzil.la/1067402</a>), and allowing fallbacks for rules with whitelists (<a href="https://bugzil.la/1235073" target="_blank">https://bugzil.la/1235073</a>).</p> + + <p><b>Operational</b>:</p> + <p>There was some excitement last Sunday when all the trees were closed due to timeouts connectivity issues between our SCL3 datacentre and AWS. (<a href="https://bugzil.la/238369" target="_blank">https://bugzil.la/238369</a>)</p> + + <p><b>Build config</b>:</p> + + <p>Mike released v0.7.4 of <a href="http://gittup.org/tup/" target="_blank">tup</a>, and is working on generating the tup backend from moz.build. We hope to offer tup as an alternative build backend sometime soon.</p> + + <p>See you all next week!</p> + Fri, 15 Jan 2016 22:44:13 +0000 + + + Air Mozilla: Webdev Beer and Tell: January 2016 + https://air.mozilla.org/webdev-beer-and-tell-january-2016/ + https://air.mozilla.org/webdev-beer-and-tell-january-2016/ + <p> + <img alt="Webdev Beer and Tell: January 2016" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/35/0f/350f246037ead3bab95fdbd4c2b77484.png" width="160" /> + Once a month web developers across the Mozilla community get together (in person and virtually) to share what cool stuff we've been working on in... + </p> + Fri, 15 Jan 2016 22:00:00 +0000 + Air Mozilla + + + Support.Mozilla.Org: What’s up with SUMO – 15th January + http://blog.mozilla.org/sumo/?p=3665 + https://blog.mozilla.org/sumo/2016/01/15/whats-up-with-sumo-15th-january/ + <p><strong>Hello, SUMO Nation!</strong></p> + <p>The second post of the year is here. Have you had a good time in 2016 so far? Let us know in the comments!</p> + <p>Now, let’s get going with the updates and activity summaries. It will be brief today, I promise.</p> + <h3><strong class="author-name">Welcome, new contributors!<br /> + </strong></h3> + <ul> + <li class="author"> + <div class="author"><a class="username" href="https://support.mozilla.org/en-US/user/Andy.Yang">Andy.Yang</a></div> + </li> + </ul> + <div class="author">After the massive influx over the last few weeks, we only had Andy introducing himself recently – the warmer the welcome for him!</div> + <div class="author"></div> + <div class="author">If you just joined us, don’t hesitate – come over and <a href="https://support.mozilla.org/forums/buddies" target="_blank">say “hi” in the forums!</a></div> + <div class="author"></div> + <div class="author"> + <h3><strong>Contributors of the week<br /> + </strong></h3> + <ul> + <li><a href="https://blog.mozilla.org/sumo/2016/01/08/whats-up-with-sumo-8th-january/" target="_blank">All the people who joined us in the winter season so far!</a></li> + </ul> + <div class="" id="magicdomid64"> + <p><strong><span style="text-decoration: underline;">We salute you!</span></strong></p> + </div> + <div class="author">Don’t forget that if you are new to SUMO and someone helped you get started in a nice way you can <a href="https://support.mozilla.org/forums/buddies/711364?last=65670" target="_blank">nominate them for the Buddy of the Month!</a></div> + <div class="author"></div> + </div> + <h3><strong>Most recent SUMO Community meeting</strong></h3> + <ul> + <li><a href="https://public.etherpad-mozilla.org/p/sumo-2016-01-11" target="_blank">You can read the notes here</a> and see the video on our <a href="https://www.youtube.com/channel/UCaiposaIhA7HfMqH2NIciyA/videos" target="_blank">YouTube channel</a> and <a href="https://air.mozilla.org/search/?q=sumo" target="_blank">at AirMozilla</a>.<del> </del><del><br /> + </del></li> + <li><strong>IMPORTANT: We are considering changing the way the meetings work. Help us figure out what’s best for you – join the discussion on the forums in this thread: <a href="https://support.mozilla.org/en-US/forums/contributors/711752?last=67873">(Monday) Community Meetings in 2016</a>.</strong></li> + </ul> + <h3><strong>The next SUMO Community meeting… </strong></h3> + <ul> + <li style="text-align: left;">is happening on <a href="https://public.etherpad-mozilla.org/p/sumo-2016-01-18" target="_blank">Monday the 18th – join us</a>!</li> + <li style="text-align: left;"><strong>Reminder: if you want to add a discussion topic to the upcoming meeting agenda:</strong> + <ul> + <li style="text-align: left;">Start a thread in the <a href="https://support.mozilla.org/forums/contributors" target="_blank">Community Forums</a>, so that everyone in the community can see what will be discussed and voice their opinion here before Monday (this will make it easier to have an efficient meeting).</li> + <li style="text-align: left;">Please do so as soon as you can before the meeting, so that people have time to read, think, and reply (and also add it to the agenda).</li> + <li style="text-align: left;">If you can, please attend the meeting in person (or via IRC), so we can follow up on your discussion topic during the meeting with your feedback.</li> + </ul> + </li> + </ul> + <h3><strong class="author-g-ivsra51ph44x461i">Developers</strong></h3> + <ul> + <li>The new version of the Ask A Question page is here!</li> + <li>The 2.0 version of the KPI dashboard is in the works.</li> + <li><a href="http://edwin.mozilla.io/t/sumo" target="_blank">You can see the current state of the backlog our developers are working on here</a>.</li> + <li><a href="https://public.etherpad-mozilla.org/p/sumo-p-2016-01-14" target="_blank">The latest SUMO Platform meeting notes can be found here</a>.</li> + <li>Interested in learning how Kitsune (the engine behind SUMO) works? <a href="http://kitsune.readthedocs.org/" target="_blank">Read more about it here</a> and <a href="https://github.com/mozilla/kitsune/" target="_blank">fork it on GitHub</a>!</li> + </ul> + <h3><strong>Community</strong></h3> + <ul> + <li>Our awesome Bangladesh SUMO Warriors are on the road again! Follow their adventures on Twitter under this tag: <a href="https://twitter.com/search?q=%23sumotourctg" target="_blank">#sumotourctg</a></li> + <li> + <div class="title"><a href="https://support.mozilla.org/forums/contributors/711729?last=67763">Reminder: take a look at our Work Week Summary for Mozlando. We need your feedback for a few things there.</a></div> + </li> + <li> + <div class="title">Ongoing reminder: if you think you can benefit from getting <a href="https://wiki.mozilla.org/Community_Hardware" target="_blank">a second-hand device</a> to help you with contributing to SUMO, you know where to find us.</div> + </li> + </ul> + <h3><strong class="user-chip" title="adriel0415">Support Forum</strong></h3> + <ul> + <li>Say hello to the new people on the forums! + <ul> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/Tomi55" target="_blank">Tomi55</a> (Hungarian)</span></li> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/jdc20181" target="_blank">jdc20181</a> (English)</span></li> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/andexi" target="_blank">andexi</a> (Spanish)</span></li> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/Qantas94Heavy" target="_blank">Qantas94Heavy</a> (English)</span></li> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/samuelms79" target="_blank">samuelms79</a> (Brazilian-PT)</span></li> + <li><span class="author-a-z87zkz70z39yz83zw7ykz89z3gz82zt"><a href="https://support.mozilla.org/user/jorgecomun" target="_blank">jorgecomun</a> (Spanish)</span></li> + </ul> + </li> + </ul> + <div class=""> + <h3><strong class="author-g-ivsra51ph44x461i">Knowledge Base</strong></h3> + <div class="" id="magicdomid90"> + <div class="" id="magicdomid82"> + <ul class="list-bullet1"> + <li><span class="author-a-z87zjz80zxwjz85z4z65zytdpz68zoz69z"><a href="https://support.mozilla.org/forums/knowledge-base-articles/711304#post-65289" target="_blank">Thanks to everyone who took part in the most recent KB Day!</a></span></li> + <li>Version 44 updates should be live now.</li> + <li><span class="author-a-w2dz70zaz70z7z89zqz78ziz69zz78zz85zz90zj"><a href="https://docs.google.com/spreadsheets/d/1lkpRPJp9P1P5MRU-c9dwbDC0w5bMmrMdu-BNMp1xe8w/edit#gid=6" target="_blank">Ongoing reminder: learn more about upcoming English article updates by clicking here</a></span>.</li> + <li><span style="text-decoration: underline;">Ongoing reminder #2:<a href="https://support.mozilla.org/forums/knowledge-base-articles/" target="_blank"> do you have ideas about improving the KB guidelines and training materials? Let us know in the forums</a>!</span></li> + </ul> + </div> + <div class="" id="magicdomid83"> + <h3><strong class="author-g-ivsra51ph44x461i">Localization</strong></h3> + </div> + </div> + </div> + <div class="" id="magicdomid95"> + <ul> + <li>Thanks to everyone writing in with problems, ideas, reports of bugs – all your feedback matters!</li> + </ul> + </div> + <div class="" id="magicdomid75"> + <h3><strong>Firefox<br /> + </strong></h3> + <ul> + <li><strong>for Android</strong> + <ul> + <li><a href="https://support.mozilla.org/forums/contributors/711712?last=67653">Learn more about Firefox 43 for Android from the official thread with release notes / issues / discussions</a>.</li> + <li> + <div class="title"><a href="https://support.mozilla.org/forums/contributors/711718?last=67822">Reminder: Roland is sharing Firefox 44 for Android release notes / issues / discussions</a> with everyone in the forum.</div> + </li> + </ul> + </li> + </ul> + <ul> + <li><strong>for Desktop</strong> + <ul> + <li>The <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1238620" target="_blank">uploading issues reported by many users are being tracked here.</a></li> + <li><a href="https://support.mozilla.org/questions/firefox?tagged=bug1208145&amp;show=all" target="_blank">The “show passwords” button has been removed from the password manager for the Beta of Version 44</a>. The developers are looking into <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208145" target="_blank">last minute fixes for that in this bug</a>.</li> + <li>Also in Version 44, the <span class="author-a-kz88zz80zhz89z6hlz81znytez70zz66zz68z"><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=606655" target="_blank">“ask me everytime” option for cookies will be removed from the privacy panel.</a></span></li> + </ul> + </li> + </ul> + <ul> + <li><strong>for iOS</strong> + <div class="" id="magicdomid85"> + <ul class="list-bullet1"> + <li><span class="author-a-107uz69zz81zhz78z0z78zz84zz66zz76zz82zz77zj"><a href="https://www.mozilla.org/en-US/firefox/ios/1.4/releasenotes/" target="_blank">Firefox for iOS 1.4 primarily with features for China is here</a>.<br /> + </span></li> + </ul> + </div> + <div class="" id="magicdomid86"> + <ul class="list-bullet1"> + <li><span class="author-a-107uz69zz81zhz78z0z78zz84zz66zz76zz82zz77zj">Firefox for iOS 2.0 is after 1.4 and hopefully sometime this quarter!</span></li> + </ul> + </div> + </li> + </ul> + </div> + <p>Not that many updates this week, since we’re coming out of our winter slumber (even though winter will be here for a while, still) and plotting an awesome 2016 with you and for you. Take it easy, have a great weekend and see you around SUMO.</p> + Fri, 15 Jan 2016 19:38:51 +0000 + Michał + + + Air Mozilla: Paris Firefox OS Hackathon Presentations + https://air.mozilla.org/paris-firefox-os-hackathon-presentations/ + https://air.mozilla.org/paris-firefox-os-hackathon-presentations/ + <p> + <img alt="Paris Firefox OS Hackathon Presentations" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/35/83/358305bfa246fff07d707061082134aa.png" width="160" /> + As an introduction to this weekend's Firefox OS Hackathon in Paris we'll have two presentations: - Guillaume Marty will talk about the current state of... + </p> + Fri, 15 Jan 2016 18:00:00 +0000 + Air Mozilla + + + J.C. Jones: Renewing Let's Encrypt Certs (Nginx) + https://tacticalsecret.com/tag/mozilla/rss/db7fec0c-34d3-4633-9904-79b98aab34e7 + https://tacticalsecret.com/renewing-lets-encrypt-certs-nginx/ + <p>All the first <a href="https://crt.sh/?id=10172479">Let's Encrypt certs for my websites</a> from the LE private beta began expiring last week, so it was time to work through the renewal tooling. I wanted a script that:</p> + + <ol> + <li>Would be okay to run daily, so there'd be plenty of retries if something went wrong, </li> + <li>Wouldn't require extra config for me to forget about if I add a new site, </li> + <li>Would only renew certificates expiring in the next few weeks.</li> + </ol> + + <p>The official Let's Encrypt client team is hard at work producing a great renew tool to handle all this, but it's not released yet. Of course I could use <a href="https://caddyserver.com/">Caddy Server</a> that <a href="https://www.youtube.com/watch?v=nk4EWHvvZtI">just handles all this</a>, but I have a lot invested in Nginx here.</p> + + <p>So I wrote a short script and <a href="https://gist.github.com/jcjones/432eeaa6a2bf25e2c746">put it up in a Gist</a>. </p> + + <p>The script is designed to run daily, with a random start between 00:00 and 02:00 to protect against load spikes at Let's Encrypt's infrastructure. It doesn't do any real reporting, though, except to maintain <code>/var/log/letsencrypt/renew.log</code> as the most-recent failure if one fails.</p> + + <p>It's written to handle Nginx with Upstart's <code>service</code> command. It's pretty modular though; you could make this operate any webserver, or use the webroot method quite easily. Feel free to use the OpenSSL SubjectAlternativeName processing code for whatever purposes you have.</p> + + <p>Happy renewing!</p> + Fri, 15 Jan 2016 16:01:19 +0000 + James 'J.C.' Jones + + + Yunier José Sosa Vázquez: Conoce los complementos destacados para enero + http://firefoxmania.uci.cu/?p=15521 + http://firefoxmania.uci.cu/conoce-los-complementos-destacados-para-enero-2016/ + <p style="text-align: left;">Comenzó un nuevo año y con él, te traemos nuevos e interesantes complementos para tu navegador preferido que mejoran con creces tu experiencia de navegación. Durante los próximos 6 meses estará trabajando nuevos miembros en el Add-ons Board Team, en la próxima selección desde Firefoxmanía te avisaremos.</p> + <h3 style="text-align: left;">Elección del mes: uMatrix</h3> + <p>uMatrix es muy parecido a un <em>firewall</em> y desde una ventana fácilmente podrás controlar todos los lugares a donde tu navegador tiene permitido conectarse, qué tipo de datos pueden descargarse y cual puede ejecutar.</p> + <blockquote><p>Esta puede ser la extensión perfecta para el control avanzado de los usuarios.</p></blockquote> + <p><span id="more-15521"></span></p> + + <a href="http://firefoxmania.uci.cu/conoce-los-complementos-destacados-para-enero-2016/umatrix/"><img alt="Interfaz principal de uMatrix" class="attachment-thumbnail size-thumbnail" height="160" src="http://firefoxmania.uci.cu/wp-content/uploads/2016/01/uMatrix-160x160.png" width="160" /></a> + <a href="http://firefoxmania.uci.cu/conoce-los-complementos-destacados-para-enero-2016/umatrix2/"><img alt="Opciones de configuración de uMatrix" class="attachment-thumbnail size-thumbnail" height="160" src="http://firefoxmania.uci.cu/wp-content/uploads/2016/01/uMatrix2-160x160.png" width="160" /></a> + + <p><em><a href="http://addons.firefoxmania.uci.cu/umatrix/" target="_blank">Instalar uMatrix »</a></em></p> + <h3>También te recomendamos</h3> + <p style="text-align: left;"><a href="http://addons.firefoxmania.uci.cu/https-everywhere/" target="_blank">⇒ HTTPS Everywhere</a> por <a href="https://addons.mozilla.org/en-US/firefox/user/eff-technologists/" title="EFF Technologists">EFF Technologists</a></p> + <p style="text-align: left;">Protege tus comunicaciones habilitando la encriptación HTTPS automáticamente en los sitios conocidos que la soportan, incluso cuando navegas mediante sitios que no incluyen el prefijo “https” en la URL.</p> + <p style="text-align: left;"><a href="http://addons.firefoxmania.uci.cu/add-to-search-bar/" target="_blank">⇒ Add to Search Bar</a> por <a href="https://addons.mozilla.org/firefox/user/dr-evil/" target="_blank" title="AdblockLite">Dr. Evil</a></p> + <p style="text-align: left;">Hace posible que cualquier página con un formulario de búsqueda disponible pueda ser añadido fácilmente a la barra de búsqueda de Firefox.</p> + <div class="wp-caption aligncenter" id="attachment_15528" style="width: 262px;"><a href="http://firefoxmania.uci.cu/wp-content/uploads/2016/01/add_to_search_bar.png" rel="attachment wp-att-15528"><img alt="add_to_search_bar" class="wp-image-15528 size-medium" height="226" src="http://firefoxmania.uci.cu/wp-content/uploads/2016/01/add_to_search_bar-252x226.png" width="252" /></a><p class="wp-caption-text">Añadiendo la búsqueda de un sitio web a la barra de búsqueda</p></div> + <p style="text-align: left;"><a href="http://addons.firefoxmania.uci.cu/duplicate-tabs-closer/" target="_blank">⇒ Duplicate Tabs Closer</a> por <a href="https://addons.mozilla.org/firefox/user/peuj/" target="_blank" title="The 1-Click YouTube Video Download Team">Peuj</a></p> + <p style="text-align: left;">Detecta las pestañas duplicadas en tu navegador y automáticamente las cierra.</p> + <h3 style="text-align: left;">Nomina tus complementos favoritos</h3> + <p style="text-align: left;">A nosotros nos encantaría que <strong>fueras parte del proceso</strong> de seleccionar los mejores complementos para Firefox y nos gustaría escucharte. <em>¿No sabes cómo?</em> Sólo tienes que <em>enviar un correo electrónico</em> a la dirección <strong>amo-featured@mozilla.org</strong> con el nombre del complemento o el archivo de instalación y los miembros evaluarán tu recomendación.</p> + <p style="text-align: left;"><strong>Fuente:</strong> <a href="https://blog.mozilla.org/addons/2016/01/01/january-2016-featured-add-ons/" target="_blank">Mozilla Add-ons Blog</a></p> + Fri, 15 Jan 2016 15:10:26 +0000 + Yunier J + + + Tim Taubert: Build Your Own Signal Desktop + https://timtaubert.de/blog/2016/01/build-your-own-signal-desktop + https://timtaubert.de/blog/2016/01/build-your-own-signal-desktop/ + <p>The Signal Private Messenger is great. <strong>Use it.</strong> It’s probably the best secure + messenger on the market. When recently a desktop app was announced people were + eager to join the beta and even happier when an invite finally showed up in + their inbox. So was I, it’s a great app and works surprisingly well for an early + version.</p> + + <p>The only problem is that it’s a Chrome App. Apart from excluding folks with + other browsers it’s also a shitty user experience. If you too want your + messaging app not tied to a browser then let’s just build our own standalone + variant of Signal Desktop.</p> + + <h3>NW.js beta with Chrome App support</h3> + + <p>Signal Desktop is a Chrome App, so the easiest way to turn it into a standalone + app is to use <a href="http://nwjs.io/">NW.js</a>. Conveniently, their next release v0.13 + will ship with Chrome App support and is available for download as a beta + version.</p> + + <p>First, make sure you have <code>git</code> and <code>npm</code> installed. Then open a terminal and + prepare a temporary build directory to which we can download a few things and + where we can build the app:</p> + + <figure class="code"><div class="highlight"><pre>$ mkdir signal-build + $ cd signal-build + </pre></div></figure> + + + <h3>[OS X] Packaging Signal and NW.js</h3> + + <p>Download the latest beta of NW.js and <code>unzip</code> it. We’ll extract the application + and use it as a template for our Signal clone. The NW.js project does + unfortunately not seem to provide a secure source (or at least hashes) + for their downloads.</p> + + <figure class="code"><div class="highlight"><pre>$ wget http://dl.nwjs.io/v0.13.0-beta3/nwjs-sdk-v0.13.0-beta3-osx-x64.zip + $ unzip nwjs-sdk-v0.13.0-beta3-osx-x64.zip + $ cp -r nwjs-sdk-v0.13.0-beta3-osx-x64/nwjs.app SignalPrivateMessenger.app + </pre></div></figure> + + + <p>Next, clone the Signal repository and use NPM to install the necessary modules. + Run the <code>grunt</code> automation tool to build the application.</p> + + <figure class="code"><div class="highlight"><pre>$ git clone https://github.com/WhisperSystems/Signal-Desktop.git + $ cd Signal-Desktop/ + $ npm install + $ node_modules/grunt-cli/bin/grunt + </pre></div></figure> + + + <p>Finally, simply to copy the <code>dist</code> folder containing all the juicy Signal files + into the application template we created a few moments ago.</p> + + <figure class="code"><div class="highlight"><pre>$ cp -r dist ../SignalPrivateMessenger.app/Contents/Resources/app.nw + $ open .. + </pre></div></figure> + + + <p>The last command opens a Finder window. Move <code>SignalPrivateMessenger.app</code> to + your Applications folder and launch it as usual. You should now see a welcome + page!</p> + + <h3>[Linux] Packaging Signal and NW.js</h3> + + <p>The build instructions for Linux aren’t too different but I’ll write them down, + if just for convenience. Start by cloning the Signal Desktop repository and + build.</p> + + <figure class="code"><div class="highlight"><pre>$ git clone https://github.com/WhisperSystems/Signal-Desktop.git + $ cd Signal-Desktop/ + $ npm install + $ node_modules/grunt-cli/bin/grunt + </pre></div></figure> + + + <p>The <code>dist</code> folder contains the app, ready to be launched. <code>zip</code> it and place + the resulting package somewhere handy.</p> + + <figure class="code"><div class="highlight"><pre>$ cd dist + $ zip -r ../../package.nw * + </pre></div></figure> + + + <p>Back to the top. Download the NW.js binary, extract it, and change into the + newly created directory. Move the <code>package.nw</code> file we created earlier next to + the <code>nw</code> binary and we’re done. The <code>nwjs-sdk-v0.13.0-beta3-linux-x64</code> folder + does now contain the standalone Signal app.</p> + + <figure class="code"><div class="highlight"><pre>$ cd ../.. + $ wget http://dl.nwjs.io/v0.13.0-beta3/nwjs-sdk-v0.13.0-beta3-linux-x64.tar.gz + $ tar xfz nwjs-sdk-v0.13.0-beta3-linux-x64.tar.gz + $ cd nwjs-sdk-v0.13.0-beta3-linux-x64 + $ mv ../package.nw . + </pre></div></figure> + + + <p>Finally, launch NW.js. You should see a welcome page!</p> + + <figure class="code"><div class="highlight"><pre>$ ./nw + </pre></div></figure> + + + <h3>If you see something, file something</h3> + + <p>Our standalone Signal clone mostly works, but it’s far from perfect. We’re + pulling from master and that might bring breaking changes that weren’t + sufficiently tested.</p> + + <p>We don’t have the right icons. The app crashes when you click a media message. + It opens a blank popup when you click a link. It’s quite big because also NW.js + has bugs and so we have to use the SDK build for now. In the future it would be + great to have automatic updates, and maybe even signed builds.</p> + + <p>Remember, Signal Desktop is beta, and completely untested with NW.js. If you + want to help file bugs, but only after checking that those affect the Chrome + App too. If you want to fix a bug only occurring in the standalone version + it’s probably best to file a pull request and cross fingers.</p> + + <h3>Is this secure?</h3> + + <p>Great question! I don’t know. I would love to get some more insights from people + that know more about the NW.js security model and whether it comes with all the + protections Chromium can offer. Another interesting question is whether bundling + Signal Desktop with NW.js is in any way worse (from a security perspective) than + installing it as a Chrome extension. If you happen to have an opinion about + that, I would love to hear it.</p> + + <p>Another important thing to keep in mind is that when building Signal on your + own you will possibly miss automatic and signed security updates from the + Chrome Web Store. Keep an eye on the repository and rebuild your app from + time to time to not fall behind too much.</p> + Fri, 15 Jan 2016 14:00:00 +0000 + + + Mike Hommey: Announcing git-cinnabar 0.3.0 + http://glandium.org/blog/?p=3579 + http://glandium.org/blog/?p=3579 + <p>Git-cinnabar is a git remote helper to interact with mercurial repositories. It allows to clone, pull and push from/to mercurial remote repositories, using git.</p> + <p><a href="https://github.com/glandium/git-cinnabar">Get it on github</a>.</p> + <p>These release notes are also <a href="https://github.com/glandium/git-cinnabar/wiki/Release-Notes:-0.3.0">available on the git-cinnabar wiki</a>.</p> + <p>Development had been stalled for a few months, with many improvements in the<br /> + <code>next</code> branch without any new release. I used some time during the new year<br /> + break and after in order to straighten things up in order to create a new<br /> + release, delaying many of the originally planned changes to a future 0.4.0<br /> + release.</p> + <h3>What’s new since 0.2.2?</h3> + <ul> + <li>Speed and memory usage were improved when doing <code>git push</code>.</li> + <li>Now works on Windows, at least to some extent. See <a href="http://glandium.org/blog/Windows-Support">details</a>.</li> + <li>Support for pre-0.1.0 git-cinnabar repositories was removed. You must first<br /> + use a git-cinnabar version between 0.1.0 and 0.2.2 to upgrade its metadata.</li> + <li>It is now possible to attach/graft git-cinnabar metadata to existing commits<br /> + matching mercurial changesets. This allows to migrate from some other<br /> + hg-to-git tool to git-cinnabar while preserving the existing git commits.<br /> + See <a href="http://glandium.org/blog/Mozilla%3A-Using-a-git-clone-of-gecko%E2%80%90dev-to-push-to-mercurial">an example of how this works with the git clone of the Gecko mercurial<br /> + repository</a> + </li> + <li>Avoid mercurial printing its progress bar, messing up with git-cinnabar’s<br /> + output.</li> + <li>It is now possible to fetch from an incremental mercurial bundle (without<br /> + a root changeset).</li> + <li>It is now possible to push to a new mercurial repository without <code>-f</code>.</li> + <li>By default, reject pushing a new root to a mercurial repository.</li> + <li>Make the connection to a mercurial repository through ssh respect the<br /> + <code>GIT_SSH</code> and <code>GIT_SSH_COMMAND</code> environment variables.</li> + <li> + <code>git cinnabar</code> now has a proper argument parser for all its subcommands.</li> + <li> + </li> + <li>A new <code>git cinnabar python</code> command allows to run python scripts or open a<br /> + python shell with the right sys.path to import the cinnabar module.</li> + <li>All git-cinnabar metadata is now kept under a single ref (although for<br /> + convenience, other refs are created, but they can be derived if necessary).</li> + <li>Consequently, a new <code>git cinnabar rollback</code> command allows to roll back to<br /> + previous metadata states.</li> + <li>git-cinnabar metadata now tracks the manifests DAG.</li> + <li>A new <code>git cinnabar bundle</code> command allows to create mercurial bundles,<br /> + mostly for debugging purposes, without requiring to hit a mercurial server.</li> + <li>Updated git to 2.7.0 for the native helper.</li> + </ul> + <h3>Development process changes</h3> + <p>Up to before this release closing in, the <code>master</code> branch was dedicated to<br /> + releases, and development was happening on the <code>next</code> branch, until a new<br /> + release happens.</p> + <p>From now on, the <code>release</code> branch will take dot-release fixes and new<br /> + releases, while the <code>master</code> branch will receive all changes that are<br /> + validated through testing (currently semi-automatically tested with<br /> + out-of-tree tests based on four real-life mercurial repositories, with<br /> + some automated CI based on in-tree tests used in the future).</p> + <p>The <code>next</code> branch will receive changes to be tested in CI when things<br /> + will be hooked up, and may have rewritten history as a consequence of<br /> + wanting passing tests on every commit on <code>master</code>.</p> + Fri, 15 Jan 2016 08:56:40 +0000 + glandium + + + Air Mozilla: Web QA Weekly Meeting, 14 Jan 2016 + https://air.mozilla.org/web-qa-weekly-meeting-20160114/ + https://air.mozilla.org/web-qa-weekly-meeting-20160114/ + <p> + <img alt="Web QA Weekly Meeting" class="wp-post-image" height="90" src="https://air.cdn.mozilla.net/media/cache/f5/13/f5137857516694df0458e837c2d3a4be.png" width="160" /> + This is our weekly gathering of Mozilla'a Web QA team filled with discussion on our current and future projects, ideas, demos, and fun facts. + </p> + Thu, 14 Jan 2016 17:00:00 +0000 + Air Mozilla + + + + diff --git a/mobile/android/tests/background/junit4/resources/feed_rss_heise.xml b/mobile/android/tests/background/junit4/resources/feed_rss_heise.xml new file mode 100644 index 000000000..a23399bb8 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_rss_heise.xml @@ -0,0 +1,1965 @@ + + + + heise online News + http://www.heise.de/newsticker/ + Nachrichten nicht nur aus der Welt der Computer + en + Copyright (c) 2016 Heise Medien + Wed, 28 Jan 2016 17:36:00 GMT + Wed, 27 Jan 2016 17:32:00 GMT + 5 + + Google: “Dramatische Verbesserungen” für Chrome in iOS + + http://www.heise.de/newsticker/meldung/Google-Dramatische-Verbesserungen-fuer-Chrome-in-iOS-3085808.html?wt_mc=rss.ho.beitrag.atom + + Als Unterbau von iOS-Chrome kommt nun eine neuere, von Apple + bereitgestellte Rendering-Engine zum Einsatz, die ohne Leistungseinschränkungen + läuft. Manche Funktionen fallen dadurch allerdings weg.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389546558/u/0/f/653902/c/35207/s/4d2c8260/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389546558/u/0/f/653902/c/35207/s/4d2c8260/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389546558/u/0/f/653902/c/35207/s/4d2c8260/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389546558/u/0/f/653902/c/35207/s/4d2c8260/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389546558/u/0/f/653902/c/35207/s/4d2c8260/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389546558/u/0/f/653902/c/35207/s/4d2c8260/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389546558/u/0/f/653902/c/35207/s/4d2c8260/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389546558/u/0/f/653902/c/35207/s/4d2c8260/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389546558/u/0/f/653902/c/35207/s/4d2c8260/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2c8260/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 17:32:00 GMT + http://heise.de/-3085808 + + Google Chrome für iOS

Als Unterbau von iOS-Chrome kommt nun eine neuere, von Apple bereitgestellte Rendering-Engine zum Einsatz, die ohne Leistungseinschränkungen läuft. Manche Funktionen fallen dadurch allerdings weg.










]]> + + + IBM holt Ford-Chef in seinen Verwaltungsrat + + http://www.heise.de/newsticker/meldung/IBM-holt-Ford-Chef-in-seinen-Verwaltungsrat-3085806.html?wt_mc=rss.ho.beitrag.atom + + Mark Fields, der seit 2014 den zweitgrößten US-amerikanischen + Autohersteller leitet, gehört nun dem IBM-Verwaltungsrat an.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389544988/u/0/f/653902/c/35207/s/4d2c54c4/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389544988/u/0/f/653902/c/35207/s/4d2c54c4/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389544988/u/0/f/653902/c/35207/s/4d2c54c4/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389544988/u/0/f/653902/c/35207/s/4d2c54c4/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389544988/u/0/f/653902/c/35207/s/4d2c54c4/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389544988/u/0/f/653902/c/35207/s/4d2c54c4/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389544988/u/0/f/653902/c/35207/s/4d2c54c4/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389544988/u/0/f/653902/c/35207/s/4d2c54c4/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389544988/u/0/f/653902/c/35207/s/4d2c54c4/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2c54c4/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 17:19:00 GMT + http://heise.de/-3085806 + + IBM holt Ford-Chef in seinen Verwaltungsrat

Mark Fields, der seit 2014 den zweitgrößten US-amerikanischen Autohersteller leitet, gehört nun dem IBM-Verwaltungsrat an.










]]> + + + News Pro: Microsoft bringt Nachrichten-App fürs iPhone + + http://www.heise.de/newsticker/meldung/News-Pro-Microsoft-bringt-Nachrichten-App-fuers-iPhone-3085776.html?wt_mc=rss.ho.beitrag.atom + + Microsoft setzt besonders auf geschäftliche Nachrichten, die nach Branchen + sortiert sind. News Pro soll außerdem interessenbasierte Vorschläge unterbreiten. + Noch läuft die App als experimentelles Projekt.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389583008/u/0/f/653902/c/35207/s/4d2c039d/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389583008/u/0/f/653902/c/35207/s/4d2c039d/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389583008/u/0/f/653902/c/35207/s/4d2c039d/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389583008/u/0/f/653902/c/35207/s/4d2c039d/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389583008/u/0/f/653902/c/35207/s/4d2c039d/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389583008/u/0/f/653902/c/35207/s/4d2c039d/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389583008/u/0/f/653902/c/35207/s/4d2c039d/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389583008/u/0/f/653902/c/35207/s/4d2c039d/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389583008/u/0/f/653902/c/35207/s/4d2c039d/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2c039d/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 16:20:00 GMT + http://heise.de/-3085776 + + News Pro

Microsoft setzt besonders auf geschäftliche Nachrichten, die nach Branchen sortiert sind. News Pro soll außerdem interessenbasierte Vorschläge unterbreiten. Noch läuft die App als experimentelles Projekt.










]]> + + + Supercomputer mit Xeon Phi Knights Landing wird im Frühsommer ausgeliefert + + + http://www.heise.de/newsticker/meldung/Supercomputer-mit-Xeon-Phi-Knights-Landing-wird-im-Fruehsommer-ausgeliefert-3085672.html?wt_mc=rss.ho.beitrag.atom + + Im Juni soll Cray XC40-Systeme mit Xeon-E5 und Xeon Phi Knight Landing an + den britischen Wetterdienst liefern.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389581460/u/0/f/653902/c/35207/s/4d2bfd33/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389581460/u/0/f/653902/c/35207/s/4d2bfd33/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389581460/u/0/f/653902/c/35207/s/4d2bfd33/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389581460/u/0/f/653902/c/35207/s/4d2bfd33/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389581460/u/0/f/653902/c/35207/s/4d2bfd33/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389581460/u/0/f/653902/c/35207/s/4d2bfd33/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389581460/u/0/f/653902/c/35207/s/4d2bfd33/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389581460/u/0/f/653902/c/35207/s/4d2bfd33/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389581460/u/0/f/653902/c/35207/s/4d2bfd33/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2bfd33/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 15:58:00 GMT + http://heise.de/-3085672 + + Supercomputer mit Xeon Phi Knights Landing im Frühsommer

Im Juni soll Cray XC40-Systeme mit Xeon-E5 und Xeon Phi Knight Landing an den britischen Wetterdienst liefern.










]]> + + + FDP reicht Verfassungsklage gegen Vorratsdatenspeicherung ein + + http://www.heise.de/newsticker/meldung/FDP-reicht-Verfassungsklage-gegen-Vorratsdatenspeicherung-ein-3085660.html?wt_mc=rss.ho.beitrag.atom + + &quot;Dieser Angriff auf die Bürgerrechte darf nicht akzeptiert werden&quot;, + kommentierte der FDP-Bundesvize Wolfgang Kubicki seinen Gang nach Karlsruhe.<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389571260/u/0/f/653902/c/35207/s/4d2bee54/sc/7/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389571260/u/0/f/653902/c/35207/s/4d2bee54/sc/7/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389571260/u/0/f/653902/c/35207/s/4d2bee54/sc/7/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389571260/u/0/f/653902/c/35207/s/4d2bee54/sc/7/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389571260/u/0/f/653902/c/35207/s/4d2bee54/sc/7/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389571260/u/0/f/653902/c/35207/s/4d2bee54/sc/7/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389571260/u/0/f/653902/c/35207/s/4d2bee54/sc/7/a2.htm"><img + src="http://da.feedsportal.com/r/247389571260/u/0/f/653902/c/35207/s/4d2bee54/sc/7/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389571260/u/0/f/653902/c/35207/s/4d2bee54/sc/7/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2bee54/sc/7/mf.gif' + border='0'/> + Wed, 27 Jan 2016 15:51:00 GMT + http://heise.de/-3085660 + + FDP reicht Verfassungsklage gegen Vorratsdatenspeicherung ein

"Dieser Angriff auf die Bürgerrechte darf nicht akzeptiert werden", kommentierte der FDP-Bundesvize Wolfgang Kubicki seinen Gang nach Karlsruhe.










]]> + + + Adblocker werden immer populärer + + http://www.heise.de/newsticker/meldung/Adblocker-werden-immer-populaerer-3085744.html?wt_mc=rss.ho.beitrag.atom + + Zwei aktuelle Studien zeigen: Werbeblocker werden immer populärer. Gerade + mobil wollen Nutzer weniger Werbung sehen. Ausgerechnet ein Anbieter von + Videowerbung sieht sich als Musterbeispiel.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389571259/u/0/f/653902/c/35207/s/4d2bee52/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389571259/u/0/f/653902/c/35207/s/4d2bee52/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389571259/u/0/f/653902/c/35207/s/4d2bee52/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389571259/u/0/f/653902/c/35207/s/4d2bee52/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389571259/u/0/f/653902/c/35207/s/4d2bee52/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389571259/u/0/f/653902/c/35207/s/4d2bee52/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389571259/u/0/f/653902/c/35207/s/4d2bee52/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389571259/u/0/f/653902/c/35207/s/4d2bee52/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389571259/u/0/f/653902/c/35207/s/4d2bee52/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2bee52/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 15:49:00 GMT + http://heise.de/-3085744 + + Adblocker immer populärer

Zwei aktuelle Studien zeigen: Werbeblocker werden immer populärer. Gerade mobil wollen Nutzer weniger Werbung sehen. Ausgerechnet ein Anbieter von Videowerbung sieht sich als Musterbeispiel.










]]> + + + Steuererklärung: Bundesfinanzhof bleibt beim häuslichen Arbeitszimmer hart + + + http://www.heise.de/newsticker/meldung/Steuererklaerung-Bundesfinanzhof-bleibt-beim-haeuslichen-Arbeitszimmer-hart-3085652.html?wt_mc=rss.ho.beitrag.atom + + Der Bundesfinanzhof hält in einem Grundsatzurteil an den strengen Vorgaben + für die Absetzbarkeit des häuslichen Arbeitszimmers fest. Ein nur zeitweise für die + Arbeit genutzter Raum wird nicht anerkannt.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389578312/u/0/f/653902/c/35207/s/4d2bb5a4/sc/17/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389578312/u/0/f/653902/c/35207/s/4d2bb5a4/sc/17/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389578312/u/0/f/653902/c/35207/s/4d2bb5a4/sc/17/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389578312/u/0/f/653902/c/35207/s/4d2bb5a4/sc/17/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389578312/u/0/f/653902/c/35207/s/4d2bb5a4/sc/17/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389578312/u/0/f/653902/c/35207/s/4d2bb5a4/sc/17/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389578312/u/0/f/653902/c/35207/s/4d2bb5a4/sc/17/a2.htm"><img + src="http://da.feedsportal.com/r/247389578312/u/0/f/653902/c/35207/s/4d2bb5a4/sc/17/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389578312/u/0/f/653902/c/35207/s/4d2bb5a4/sc/17/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2bb5a4/sc/17/mf.gif' + border='0'/> + Wed, 27 Jan 2016 15:37:00 GMT + http://heise.de/-3085652 + + Steuererklärung: Bundesfinanzhof bleibt beim Arbeitszimmer hart

Der Bundesfinanzhof hält in einem Grundsatzurteil an den strengen Vorgaben für die Absetzbarkeit des häuslichen Arbeitszimmers fest. Ein nur zeitweise für die Arbeit genutzter Raum wird nicht anerkannt.










]]> + + + Olympus Pen F: Erster Eindruck von der spiegellosen Edel-Systemkamera + + http://www.heise.de/newsticker/meldung/Olympus-Pen-F-Erster-Eindruck-von-der-spiegellosen-Edel-Systemkamera-3085217.html?wt_mc=rss.ho.beitrag.atom + + Olympus möchte seine neue Pen F über das Lebensgefühl der 60er Jahre + verkaufen. Die spiegellose Systemkamera wirkt extrem durchgestylt und will + gleichzeitig ein mächtiges Werkzeug sein.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389561062/u/0/f/653902/c/35207/s/4d2b625e/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389561062/u/0/f/653902/c/35207/s/4d2b625e/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389561062/u/0/f/653902/c/35207/s/4d2b625e/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389561062/u/0/f/653902/c/35207/s/4d2b625e/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389561062/u/0/f/653902/c/35207/s/4d2b625e/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389561062/u/0/f/653902/c/35207/s/4d2b625e/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389561062/u/0/f/653902/c/35207/s/4d2b625e/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389561062/u/0/f/653902/c/35207/s/4d2b625e/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389561062/u/0/f/653902/c/35207/s/4d2b625e/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2b625e/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 14:18:00 GMT + http://heise.de/-3085217 + + Olympus Pen F

Olympus möchte seine neue Pen F über das Lebensgefühl der 60er Jahre verkaufen. Die spiegellose Systemkamera wirkt extrem durchgestylt und will gleichzeitig ein mächtiges Werkzeug sein.










]]>
+
+ + VW-Skandal: EU-Kommission verschärft Kfz-Aufsicht und Abgaskontrolle + + http://www.heise.de/newsticker/meldung/VW-Skandal-EU-Kommission-verschaerft-Kfz-Aufsicht-und-Abgaskontrolle-3085529.html?wt_mc=rss.ho.beitrag.atom + + Per Verordnung will die EU-Kommission erreichen, dass sich + Automobilhersteller streng an die geltenden Sicherheits-, Umwelt- und + Fertigungsanforderungen halten. Softwareprotokolle für Kfz sollen zugänglich werden.<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389561061/u/0/f/653902/c/35207/s/4d2b625d/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389561061/u/0/f/653902/c/35207/s/4d2b625d/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389561061/u/0/f/653902/c/35207/s/4d2b625d/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389561061/u/0/f/653902/c/35207/s/4d2b625d/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389561061/u/0/f/653902/c/35207/s/4d2b625d/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389561061/u/0/f/653902/c/35207/s/4d2b625d/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389561061/u/0/f/653902/c/35207/s/4d2b625d/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389561061/u/0/f/653902/c/35207/s/4d2b625d/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389561061/u/0/f/653902/c/35207/s/4d2b625d/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2b625d/sc/3/mf.gif' + border='0'/> + Wed, 27 Jan 2016 14:13:00 GMT + http://heise.de/-3085529 + + VW-Skandal: EU-Kommission verschärft Kfz-Aufsicht und Abgaskontrolle

Per Verordnung will die EU-Kommission erreichen, dass sich Automobilhersteller streng an die geltenden Sicherheits-, Umwelt- und Fertigungsanforderungen halten. Softwareprotokolle für Kfz sollen zugänglich werden.










]]>
+
+ + PC-Version von Rise of the Tomb Raider: Die schärfste Lara Croft + + http://www.heise.de/newsticker/meldung/PC-Version-von-Rise-of-the-Tomb-Raider-Die-schaerfste-Lara-Croft-3084870.html?wt_mc=rss.ho.beitrag.atom + + Am 28. Januar erscheint die PC-Version von Rise of the Tomb Raider. Sie + besticht durch tolle Grafik und flüssige Bildraten. Allerdings gibt es auch ein paar + Probleme. heise online hat die PC-Version angetestet.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389561060/u/0/f/653902/c/35207/s/4d2b625c/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389561060/u/0/f/653902/c/35207/s/4d2b625c/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389561060/u/0/f/653902/c/35207/s/4d2b625c/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389561060/u/0/f/653902/c/35207/s/4d2b625c/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389561060/u/0/f/653902/c/35207/s/4d2b625c/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389561060/u/0/f/653902/c/35207/s/4d2b625c/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389561060/u/0/f/653902/c/35207/s/4d2b625c/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389561060/u/0/f/653902/c/35207/s/4d2b625c/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389561060/u/0/f/653902/c/35207/s/4d2b625c/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2b625c/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 14:09:00 GMT + http://heise.de/-3084870 + + Lara Croft

Am 28. Januar erscheint die PC-Version von Rise of the Tomb Raider. Sie besticht durch tolle Grafik und flüssige Bildraten. Allerdings gibt es auch ein paar Probleme. heise online hat die PC-Version angetestet.










]]>
+
+ + TP-Link-Router mit vorhersehbarem Standard-WLAN-Passwort + + http://www.heise.de/newsticker/meldung/TP-Link-Router-mit-vorhersehbarem-Standard-WLAN-Passwort-3085482.html?wt_mc=rss.ho.beitrag.atom + + Angreifer können das werkseitige WLAN-Passwort von einer + TP-Link-Router-Serie vergleichsweise einfach herausfinden und sich so Zugang zum + Netzwerk verschaffen. Weitere Serien könnten ebenfalls betroffen sein.<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389559600/u/0/f/653902/c/35207/s/4d2b5c3d/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389559600/u/0/f/653902/c/35207/s/4d2b5c3d/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389559600/u/0/f/653902/c/35207/s/4d2b5c3d/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389559600/u/0/f/653902/c/35207/s/4d2b5c3d/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389559600/u/0/f/653902/c/35207/s/4d2b5c3d/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389559600/u/0/f/653902/c/35207/s/4d2b5c3d/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389559600/u/0/f/653902/c/35207/s/4d2b5c3d/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389559600/u/0/f/653902/c/35207/s/4d2b5c3d/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389559600/u/0/f/653902/c/35207/s/4d2b5c3d/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2b5c3d/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 14:06:00 GMT + http://heise.de/-3085482 + + Hacker

Angreifer können das werkseitige WLAN-Passwort von einer TP-Link-Router-Serie vergleichsweise einfach herausfinden und sich so Zugang zum Netzwerk verschaffen. Weitere Serien könnten ebenfalls betroffen sein.










]]>
+
+ + Tails 2.0: Das Anonymisierungs-OS im neuen Look + + http://www.heise.de/newsticker/meldung/Tails-2-0-Das-Anonymisierungs-OS-im-neuen-Look-3085312.html?wt_mc=rss.ho.beitrag.atom + + Die neueste Version der spezialisierten Linux-Distribution basiert auf + Debian Jessie und bringt Gnome Shell als neuen Desktop mit.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389521976/u/0/f/653902/c/35207/s/4d2b0a56/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389521976/u/0/f/653902/c/35207/s/4d2b0a56/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389521976/u/0/f/653902/c/35207/s/4d2b0a56/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389521976/u/0/f/653902/c/35207/s/4d2b0a56/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389521976/u/0/f/653902/c/35207/s/4d2b0a56/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389521976/u/0/f/653902/c/35207/s/4d2b0a56/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389521976/u/0/f/653902/c/35207/s/4d2b0a56/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389521976/u/0/f/653902/c/35207/s/4d2b0a56/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389521976/u/0/f/653902/c/35207/s/4d2b0a56/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2b0a56/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 13:47:00 GMT + http://heise.de/-3085312 + + Tails 2.0

Die neueste Version der spezialisierten Linux-Distribution basiert auf Debian Jessie und bringt Gnome Shell als neuen Desktop mit.










]]>
+
+ + US-Fotograf Steve McCurry: "Die Selfie-Generation ist cool" + + http://www.heise.de/newsticker/meldung/US-Fotograf-Steve-McCurry-Die-Selfie-Generation-ist-cool-3085412.html?wt_mc=rss.ho.beitrag.atom + + Der amerikanische Fotograf Steve McCurry ist für seine Aufnahme des &quot;afghanischen + Mädchens&quot;, welches auf dem Cover der National Geographic um die Welt ging, + bekannt. Nun sprach der 65-Jährige mit der Zeitung &quot;Times of India&quot; + unter anderem über Selfies.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389521975/u/0/f/653902/c/35207/s/4d2b0a54/sc/17/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389521975/u/0/f/653902/c/35207/s/4d2b0a54/sc/17/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389521975/u/0/f/653902/c/35207/s/4d2b0a54/sc/17/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389521975/u/0/f/653902/c/35207/s/4d2b0a54/sc/17/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389521975/u/0/f/653902/c/35207/s/4d2b0a54/sc/17/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389521975/u/0/f/653902/c/35207/s/4d2b0a54/sc/17/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389521975/u/0/f/653902/c/35207/s/4d2b0a54/sc/17/a2.htm"><img + src="http://da.feedsportal.com/r/247389521975/u/0/f/653902/c/35207/s/4d2b0a54/sc/17/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389521975/u/0/f/653902/c/35207/s/4d2b0a54/sc/17/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2b0a54/sc/17/mf.gif' + border='0'/> + Wed, 27 Jan 2016 13:38:00 GMT + http://heise.de/-3085412 + + Selfie

Der amerikanische Fotograf Steve McCurry ist für seine Aufnahme des "afghanischen Mädchens", welches auf dem Cover der National Geographic um die Welt ging, bekannt. Nun sprach der 65-Jährige mit der Zeitung "Times of India" unter anderem über Selfies.










]]>
+
+ + AMDs GPUOpen: Zahlreiche SDKs und Tools auf GitHub im Source verfügbar + + http://www.heise.de/newsticker/meldung/AMDs-GPUOpen-Zahlreiche-SDKs-und-Tools-auf-GitHub-im-Source-verfuegbar-3085309.html?wt_mc=rss.ho.beitrag.atom + + AMDs Open-Source-Initiative spricht zum einen Spieleentwickler und zum + anderen Entwickler von HPC-Anwendungen an. Der Chiphersteller veröffentlicht nun + zahlreiche SDKs und Werkzeuge auf GitHub.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389556077/u/0/f/653902/c/35207/s/4d2b26a0/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389556077/u/0/f/653902/c/35207/s/4d2b26a0/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389556077/u/0/f/653902/c/35207/s/4d2b26a0/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389556077/u/0/f/653902/c/35207/s/4d2b26a0/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389556077/u/0/f/653902/c/35207/s/4d2b26a0/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389556077/u/0/f/653902/c/35207/s/4d2b26a0/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389556077/u/0/f/653902/c/35207/s/4d2b26a0/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389556077/u/0/f/653902/c/35207/s/4d2b26a0/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389556077/u/0/f/653902/c/35207/s/4d2b26a0/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2b26a0/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 13:36:00 GMT + http://heise.de/-3085309 + + AMDs GPUOpen: Zahlreiche SDKs und Tools auf GitHub im Source verfügbar

AMDs Open-Source-Initiative spricht zum einen Spieleentwickler und zum anderen Entwickler von HPC-Anwendungen an. Der Chiphersteller veröffentlicht nun zahlreiche SDKs und Werkzeuge auf GitHub.










]]>
+
+ + ZTE Axon Mini: Erstes Android-Smartphone mit Force Touch kommt nach Deutschland + + + http://www.heise.de/newsticker/meldung/ZTE-Axon-Mini-Erstes-Android-Smartphone-mit-Force-Touch-kommt-nach-Deutschland-3085296.html?wt_mc=rss.ho.beitrag.atom + + ZTE bringt ein Smartphone auf den deutschen Markt, das je nach Fingerdruck + anders reagiert. Davon abgesehen ist das Axon Mini ein 5,2-Zöller mit guter + Ausstattung in gewöhnungsbedürftiger Farbe.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389556076/u/0/f/653902/c/35207/s/4d2b269f/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389556076/u/0/f/653902/c/35207/s/4d2b269f/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389556076/u/0/f/653902/c/35207/s/4d2b269f/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389556076/u/0/f/653902/c/35207/s/4d2b269f/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389556076/u/0/f/653902/c/35207/s/4d2b269f/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389556076/u/0/f/653902/c/35207/s/4d2b269f/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389556076/u/0/f/653902/c/35207/s/4d2b269f/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389556076/u/0/f/653902/c/35207/s/4d2b269f/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389556076/u/0/f/653902/c/35207/s/4d2b269f/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2b269f/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 13:34:00 GMT + http://heise.de/-3085296 + + ZTE Axon Mini: Erstes Android-Smartphone mit Force Touch kommt nach Deutschland

ZTE bringt ein Smartphone auf den deutschen Markt, das je nach Fingerdruck anders reagiert. Davon abgesehen ist das Axon Mini ein 5,2-Zöller mit guter Ausstattung in gewöhnungsbedürftiger Farbe.










]]>
+
+ + #heiseshow: Die wöchentliche Dosis Technik-News und Netzpolitik + + http://www.heise.de/newsticker/meldung/heiseshow-Die-woechentliche-Dosis-Technik-News-und-Netzpolitik-3085429.html?wt_mc=rss.ho.beitrag.atom + + Am Donnerstag um 16 Uhr starten wir ein neues Live-Videoformat: Mit Gästen + diskutiert das Team von heise online über aktuelle Ereignisse in der Hightech-Welt + und der Netzpolitik.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389554329/u/0/f/653902/c/35207/s/4d2ae4d2/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389554329/u/0/f/653902/c/35207/s/4d2ae4d2/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389554329/u/0/f/653902/c/35207/s/4d2ae4d2/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389554329/u/0/f/653902/c/35207/s/4d2ae4d2/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389554329/u/0/f/653902/c/35207/s/4d2ae4d2/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389554329/u/0/f/653902/c/35207/s/4d2ae4d2/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389554329/u/0/f/653902/c/35207/s/4d2ae4d2/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389554329/u/0/f/653902/c/35207/s/4d2ae4d2/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389554329/u/0/f/653902/c/35207/s/4d2ae4d2/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2ae4d2/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 13:21:00 GMT + http://heise.de/-3085429 + + #heiseshow: Die wöchentliche Dosis Technik-News und Netzpolitik

Am Donnerstag um 16 Uhr starten wir ein neues Live-Videoformat: Mit Gästen diskutiert das Team von heise online über aktuelle Ereignisse in der Hightech-Welt und der Netzpolitik.










]]>
+
+ + Wikipedianer lehnen sich gegen Wikimedia-Vorstand auf + + http://www.heise.de/newsticker/meldung/Wikipedianer-lehnen-sich-gegen-Wikimedia-Vorstand-auf-3085399.html?wt_mc=rss.ho.beitrag.atom + + Mit einem inoffiziellen Misstrauensvotum wollen Wikipedianer ein + Vorstandsmitglied zum Rücktritt drängen. Der ehemalige Google-Manager will jedoch + nicht gehen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389550223/u/0/f/653902/c/35207/s/4d2ad413/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389550223/u/0/f/653902/c/35207/s/4d2ad413/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389550223/u/0/f/653902/c/35207/s/4d2ad413/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389550223/u/0/f/653902/c/35207/s/4d2ad413/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389550223/u/0/f/653902/c/35207/s/4d2ad413/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389550223/u/0/f/653902/c/35207/s/4d2ad413/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389550223/u/0/f/653902/c/35207/s/4d2ad413/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389550223/u/0/f/653902/c/35207/s/4d2ad413/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389550223/u/0/f/653902/c/35207/s/4d2ad413/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2ad413/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 12:29:00 GMT + http://heise.de/-3085399 + + Arnnon Geshuri

Mit einem inoffiziellen Misstrauensvotum wollen Wikipedianer ein Vorstandsmitglied zum Rücktritt drängen. Der ehemalige Google-Manager will jedoch nicht gehen.










]]>
+
+ + Google senkt Preise für Smartphones Nexus 5X und 6P + + http://www.heise.de/newsticker/meldung/Google-senkt-Preise-fuer-Smartphones-Nexus-5X-und-6P-3085276.html?wt_mc=rss.ho.beitrag.atom + + Bis Mitte Februar verkauft Google seine Nexus-Smartphones günstiger: Das + Nexus 5X startet bei 349 Euro, das Nexus 6P bei 549 Euro.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389510599/u/0/f/653902/c/35207/s/4d2a8d5f/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389510599/u/0/f/653902/c/35207/s/4d2a8d5f/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389510599/u/0/f/653902/c/35207/s/4d2a8d5f/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389510599/u/0/f/653902/c/35207/s/4d2a8d5f/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389510599/u/0/f/653902/c/35207/s/4d2a8d5f/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389510599/u/0/f/653902/c/35207/s/4d2a8d5f/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389510599/u/0/f/653902/c/35207/s/4d2a8d5f/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389510599/u/0/f/653902/c/35207/s/4d2a8d5f/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389510599/u/0/f/653902/c/35207/s/4d2a8d5f/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2a8d5f/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 12:15:00 GMT + http://heise.de/-3085276 + + Google senkt Preise für Nexus 5X und 6P

Bis Mitte Februar verkauft Google seine Nexus-Smartphones günstiger: Das Nexus 5X startet bei 349 Euro, das Nexus 6P bei 549 Euro.










]]>
+
+ + Bundesregierung verlangt Glasfaserkabel entlang von Fernstraßen und anderer + Infrastruktur + + + http://www.heise.de/newsticker/meldung/Bundesregierung-verlangt-Glasfaserkabel-entlang-von-Fernstrassen-und-anderer-Infrastruktur-3085354.html?wt_mc=rss.ho.beitrag.atom + + Das Bundeskabinett will &quot;Voraussetzungen für die + Gigabit-Gesellschaft&quot; schaffen und hat dafür ein Gesetz vorgelegt: + Öffentliche Versorgungsnetzbetreiber sollen ihre Infrastruktur für Breitband öffnen.<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389552422/u/0/f/653902/c/35207/s/4d2a7435/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389552422/u/0/f/653902/c/35207/s/4d2a7435/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389552422/u/0/f/653902/c/35207/s/4d2a7435/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389552422/u/0/f/653902/c/35207/s/4d2a7435/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389552422/u/0/f/653902/c/35207/s/4d2a7435/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389552422/u/0/f/653902/c/35207/s/4d2a7435/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389552422/u/0/f/653902/c/35207/s/4d2a7435/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389552422/u/0/f/653902/c/35207/s/4d2a7435/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389552422/u/0/f/653902/c/35207/s/4d2a7435/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2a7435/sc/3/mf.gif' + border='0'/> + Wed, 27 Jan 2016 11:58:00 GMT + http://heise.de/-3085354 + + Bundesregierung verlangt Glasfaserkabel entlang von Fernstraßen und anderer Infrastruktur

Das Bundeskabinett will "Voraussetzungen für die Gigabit-Gesellschaft" schaffen und hat dafür ein Gesetz vorgelegt: Öffentliche Versorgungsnetzbetreiber sollen ihre Infrastruktur für Breitband öffnen.










]]>
+
+ + iOS und OS X: Safari-Vorschläge legen Apples Webbrowser lahm + + http://www.heise.de/newsticker/meldung/iOS-und-OS-X-Safari-Vorschlaege-legen-Apples-Webbrowser-lahm-3085337.html?wt_mc=rss.ho.beitrag.atom + + Eine Fehlkonfiguration bei Apples Suchhilfe scheint aktuell der Grund für + einen sofortigen Absturz von Safari, wenn Nutzer auf iPhone oder iPad die + Adresszeile auswählen oder eine Eingabe starten. Das Problem lässt sich umgehen.<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389542680/u/0/f/653902/c/35207/s/4d2a66f7/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389542680/u/0/f/653902/c/35207/s/4d2a66f7/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389542680/u/0/f/653902/c/35207/s/4d2a66f7/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389542680/u/0/f/653902/c/35207/s/4d2a66f7/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389542680/u/0/f/653902/c/35207/s/4d2a66f7/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389542680/u/0/f/653902/c/35207/s/4d2a66f7/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389542680/u/0/f/653902/c/35207/s/4d2a66f7/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389542680/u/0/f/653902/c/35207/s/4d2a66f7/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389542680/u/0/f/653902/c/35207/s/4d2a66f7/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2a66f7/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 11:38:00 GMT + http://heise.de/-3085337 + + Apple

Eine Fehlkonfiguration bei Apples Suchhilfe scheint aktuell der Grund für einen sofortigen Absturz von Safari, wenn Nutzer auf iPhone oder iPad die Adresszeile auswählen oder eine Eingabe starten. Das Problem lässt sich umgehen.










]]>
+
+ + VMware baut 800 Arbeitsplätze ab + + http://www.heise.de/newsticker/meldung/VMware-baut-800-Arbeitsplaetze-ab-3085308.html?wt_mc=rss.ho.beitrag.atom + + Der Hersteller von Virtualisierungssoftware will sich umstrukturieren. + Dafür müssen zunächst 800 Mitarbeiter gehen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389542679/u/0/f/653902/c/35207/s/4d2a66f6/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389542679/u/0/f/653902/c/35207/s/4d2a66f6/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389542679/u/0/f/653902/c/35207/s/4d2a66f6/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389542679/u/0/f/653902/c/35207/s/4d2a66f6/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389542679/u/0/f/653902/c/35207/s/4d2a66f6/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389542679/u/0/f/653902/c/35207/s/4d2a66f6/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389542679/u/0/f/653902/c/35207/s/4d2a66f6/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389542679/u/0/f/653902/c/35207/s/4d2a66f6/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389542679/u/0/f/653902/c/35207/s/4d2a66f6/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2a66f6/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 11:34:00 GMT + http://heise.de/-3085308 + + VMware baut 800 Arbeitsplätze ab

Der Hersteller von Virtualisierungssoftware will sich umstrukturieren. Dafür müssen zunächst 800 Mitarbeiter gehen.










]]>
+
+ + Menschen-Rohrpost Hyperloop: Elon Musk lässt Aecom Teststrecke bauen + + http://www.heise.de/newsticker/meldung/Menschen-Rohrpost-Hyperloop-Elon-Musk-laesst-Aecom-Teststrecke-bauen-3085245.html?wt_mc=rss.ho.beitrag.atom + + Die Firma Aecom will noch im Frühling mit dem Bau einer + Hyperloop-Teststecke starten. Elon Musks Firma SpaceX hat das + Fortune-500-Unternehmen damit beauftragt. Studierende sollen helfen, + Kapsel-Prototypen zu bauen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389503052/u/0/f/653902/c/35207/s/4d2a0cbe/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389503052/u/0/f/653902/c/35207/s/4d2a0cbe/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389503052/u/0/f/653902/c/35207/s/4d2a0cbe/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389503052/u/0/f/653902/c/35207/s/4d2a0cbe/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389503052/u/0/f/653902/c/35207/s/4d2a0cbe/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389503052/u/0/f/653902/c/35207/s/4d2a0cbe/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389503052/u/0/f/653902/c/35207/s/4d2a0cbe/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389503052/u/0/f/653902/c/35207/s/4d2a0cbe/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389503052/u/0/f/653902/c/35207/s/4d2a0cbe/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2a0cbe/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 11:13:00 GMT + http://heise.de/-3085245 + + Hyperloop

Die Firma Aecom will noch im Frühling mit dem Bau einer Hyperloop-Teststecke starten. Elon Musks Firma SpaceX hat das Fortune-500-Unternehmen damit beauftragt. Studierende sollen helfen, Kapsel-Prototypen zu bauen.










]]>
+
+ + Lenovos Datentausch-App Shareit: 12345678 als Standardpasswort + + http://www.heise.de/newsticker/meldung/Lenovos-Datentausch-App-Shareit-12345678-als-Standardpasswort-3085250.html?wt_mc=rss.ho.beitrag.atom + + In der Shareit-Anwendung von Lenovo klaffen mehrere Schwachstellen, über + die Angreifer Nutzern unter anderem Schadcode unterjubeln können. Gefixte Version + sollen das unterbinden.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389501134/u/0/f/653902/c/35207/s/4d2a0506/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389501134/u/0/f/653902/c/35207/s/4d2a0506/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389501134/u/0/f/653902/c/35207/s/4d2a0506/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389501134/u/0/f/653902/c/35207/s/4d2a0506/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389501134/u/0/f/653902/c/35207/s/4d2a0506/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389501134/u/0/f/653902/c/35207/s/4d2a0506/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389501134/u/0/f/653902/c/35207/s/4d2a0506/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389501134/u/0/f/653902/c/35207/s/4d2a0506/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389501134/u/0/f/653902/c/35207/s/4d2a0506/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2a0506/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 10:54:00 GMT + http://heise.de/-3085250 + + Lenovos Datentausch-App Shareit mit 12345678 als Standardpasswort

In der Shareit-Anwendung von Lenovo klaffen mehrere Schwachstellen, über die Angreifer Nutzern unter anderem Schadcode unterjubeln können. Gefixte Version sollen das unterbinden.










]]>
+
+ + Paketdrohne: Google lässt sich beweglichen Paketempfangsbehälter patentieren + + + http://www.heise.de/newsticker/meldung/Paketdrohne-Google-laesst-sich-beweglichen-Paketempfangsbehaelter-patentieren-3085263.html?wt_mc=rss.ho.beitrag.atom + + Manche Orte können von unbemannten Fluggeräten nicht ohne Sicherheitsrisiko + angeflogen werden. Dafür haben sich Google-Entwickler eine Lösung ausgedacht.<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389501131/u/0/f/653902/c/35207/s/4d2a0504/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389501131/u/0/f/653902/c/35207/s/4d2a0504/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389501131/u/0/f/653902/c/35207/s/4d2a0504/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389501131/u/0/f/653902/c/35207/s/4d2a0504/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389501131/u/0/f/653902/c/35207/s/4d2a0504/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389501131/u/0/f/653902/c/35207/s/4d2a0504/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389501131/u/0/f/653902/c/35207/s/4d2a0504/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389501131/u/0/f/653902/c/35207/s/4d2a0504/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389501131/u/0/f/653902/c/35207/s/4d2a0504/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2a0504/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 10:53:00 GMT + http://heise.de/-3085263 + + Paketdrohne: Google lässt sich beweglichen Paketempfangsbehälter patentieren

Manche Orte können von unbemannten Fluggeräten nicht ohne Sicherheitsrisiko angeflogen werden. Dafür haben sich Google-Entwickler eine Lösung ausgedacht.










]]>
+
+ + Webbrowser Firefox 44 mit verbesserten Push-Nachrichten + + http://www.heise.de/newsticker/meldung/Webbrowser-Firefox-44-mit-verbesserten-Push-Nachrichten-3085193.html?wt_mc=rss.ho.beitrag.atom + + Version 44 des Firefox-Browsers verschickt nun auch Push-Nachrichten von + Websites, die nicht geöffnet sind. Zudem haben die Entwickler die Fehlerseiten + verbessert und die RC4-Unterstützung entfernt.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389543121/u/0/f/653902/c/35207/s/4d29ec71/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389543121/u/0/f/653902/c/35207/s/4d29ec71/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389543121/u/0/f/653902/c/35207/s/4d29ec71/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389543121/u/0/f/653902/c/35207/s/4d29ec71/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389543121/u/0/f/653902/c/35207/s/4d29ec71/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389543121/u/0/f/653902/c/35207/s/4d29ec71/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389543121/u/0/f/653902/c/35207/s/4d29ec71/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389543121/u/0/f/653902/c/35207/s/4d29ec71/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389543121/u/0/f/653902/c/35207/s/4d29ec71/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d29ec71/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 10:42:00 GMT + http://heise.de/-3085193 + + Firefox

Version 44 des Firefox-Browsers verschickt nun auch Push-Nachrichten von Websites, die nicht geöffnet sind. Zudem haben die Entwickler die Fehlerseiten verbessert und die RC4-Unterstützung entfernt.










]]>
+
+ + BMW steuert via IFTTT das Smart Home + + http://www.heise.de/newsticker/meldung/BMW-steuert-via-IFTTT-das-Smart-Home-3085257.html?wt_mc=rss.ho.beitrag.atom + + Wer einen BMW mit ConnectedDrive Services fährt, kann jetzt mit einem + Widget für den Automatisierungsdienst IFTTT zum Beispiel das Garagentor hochfahren + lassen, wenn er auf dem Weg nach Hause ist.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389543120/u/0/f/653902/c/35207/s/4d29ec70/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389543120/u/0/f/653902/c/35207/s/4d29ec70/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389543120/u/0/f/653902/c/35207/s/4d29ec70/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389543120/u/0/f/653902/c/35207/s/4d29ec70/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389543120/u/0/f/653902/c/35207/s/4d29ec70/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389543120/u/0/f/653902/c/35207/s/4d29ec70/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389543120/u/0/f/653902/c/35207/s/4d29ec70/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389543120/u/0/f/653902/c/35207/s/4d29ec70/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389543120/u/0/f/653902/c/35207/s/4d29ec70/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d29ec70/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 10:38:00 GMT + http://heise.de/-3085257 + + BMW steuert via IFTTT das Smart Home

Wer einen BMW mit ConnectedDrive Services fährt, kann jetzt mit einem Widget für den Automatisierungsdienst IFTTT zum Beispiel das Garagentor hochfahren lassen, wenn er auf dem Weg nach Hause ist.










]]>
+
+ + Eine Million Petenten protestieren gegen Elfenbeinhandel auf Yahoo Japan + + http://www.heise.de/newsticker/meldung/Eine-Million-Petenten-protestieren-gegen-Elfenbeinhandel-auf-Yahoo-Japan-3085214.html?wt_mc=rss.ho.beitrag.atom + + Jeden Tag werden auf der Welt hundert Elefanten wegen ihrer Stoßzähne + getötet. Die Nichtregierungsorganisation Avaaz will erreichen, dass Elfenbein nicht + mehr über Yahoo Japan verkauft werden kann.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389543119/u/0/f/653902/c/35207/s/4d29ec6e/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389543119/u/0/f/653902/c/35207/s/4d29ec6e/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389543119/u/0/f/653902/c/35207/s/4d29ec6e/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389543119/u/0/f/653902/c/35207/s/4d29ec6e/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389543119/u/0/f/653902/c/35207/s/4d29ec6e/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389543119/u/0/f/653902/c/35207/s/4d29ec6e/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389543119/u/0/f/653902/c/35207/s/4d29ec6e/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389543119/u/0/f/653902/c/35207/s/4d29ec6e/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389543119/u/0/f/653902/c/35207/s/4d29ec6e/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d29ec6e/sc/3/mf.gif' + border='0'/> + Wed, 27 Jan 2016 10:21:00 GMT + http://heise.de/-3085214 + + Eine Million Petitenten protestieren gegen Elfenbeinhandel auf Yahoo Japan

Jeden Tag werden auf der Welt hundert Elefanten wegen ihrer Stoßzähne getötet. Die Nichtregierungsorganisation Avaaz will erreichen, dass Elfenbein nicht mehr über Yahoo Japan verkauft werden kann.










]]>
+
+ + Eine Million Petitenten protestieren gegen Elfenbeinhandel auf Yahoo Japan + + + http://www.heise.de/newsticker/meldung/Eine-Million-Petitenten-protestieren-gegen-Elfenbeinhandel-auf-Yahoo-Japan-3085214.html?wt_mc=rss.ho.beitrag.atom + + Jeden Tag werden auf der Welt hundert Elefanten wegen ihrer Stoßzähne + getötet. Die Nichtregierungsorganisation Avaaz will erreichen, dass Elfenbein nicht + mehr über Yahoo Japan verkauft werden kann.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389541116/u/0/f/653902/c/35207/s/4d29bd45/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389541116/u/0/f/653902/c/35207/s/4d29bd45/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389541116/u/0/f/653902/c/35207/s/4d29bd45/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389541116/u/0/f/653902/c/35207/s/4d29bd45/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389541116/u/0/f/653902/c/35207/s/4d29bd45/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389541116/u/0/f/653902/c/35207/s/4d29bd45/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389541116/u/0/f/653902/c/35207/s/4d29bd45/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389541116/u/0/f/653902/c/35207/s/4d29bd45/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389541116/u/0/f/653902/c/35207/s/4d29bd45/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d29bd45/sc/3/mf.gif' + border='0'/> + Wed, 27 Jan 2016 10:21:00 GMT + http://heise.de/-3085214 + + Eine Million Petitenten protestieren gegen Elfenbeinhandel auf Yahoo Japan

Jeden Tag werden auf der Welt hundert Elefanten wegen ihrer Stoßzähne getötet. Die Nichtregierungsorganisation Avaaz will erreichen, dass Elfenbein nicht mehr über Yahoo Japan verkauft werden kann.










]]>
+
+ + China überholt die USA als größter Markt für Elektroautos + + http://www.heise.de/newsticker/meldung/China-ueberholt-die-USA-als-groesster-Markt-fuer-Elektroautos-3085152.html?wt_mc=rss.ho.beitrag.atom + + Die Zahl der Neuzulassungen von E-Autos steigt – auch in Deutschland. Von + einem Leitmarkt ist die Bundesrepublik aber weit entfernt.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389529191/u/0/f/653902/c/35207/s/4d29a77c/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389529191/u/0/f/653902/c/35207/s/4d29a77c/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389529191/u/0/f/653902/c/35207/s/4d29a77c/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389529191/u/0/f/653902/c/35207/s/4d29a77c/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389529191/u/0/f/653902/c/35207/s/4d29a77c/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389529191/u/0/f/653902/c/35207/s/4d29a77c/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389529191/u/0/f/653902/c/35207/s/4d29a77c/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389529191/u/0/f/653902/c/35207/s/4d29a77c/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389529191/u/0/f/653902/c/35207/s/4d29a77c/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d29a77c/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 09:54:00 GMT + http://heise.de/-3085152 + + Elektroauto

Die Zahl der Neuzulassungen von E-Autos steigt – auch in Deutschland. Von einem Leitmarkt ist die Bundesrepublik aber weit entfernt.










]]>
+
+ + Altermedia: Deutschlandweite Razzia gegen rechtsextreme Internetplattform – zwei + Festnahmen + + + http://www.heise.de/newsticker/meldung/Altermedia-Deutschlandweite-Razzia-gegen-rechtsextreme-Internetplattform-zwei-Festnahmen-3085140.html?wt_mc=rss.ho.beitrag.atom + + In einer bundesweiten Aktion gehen Ermittler der Bundesanwaltschaft gegen + führende Betreiber des rechtsextremen Internetportals &quot;Altermedia&quot; + vor. Ihnen wird die Gründung einer kriminellen Vereinigung vorgeworfen. Inzwischen + wurde die Vereinigung verboten.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389487846/u/0/f/653902/c/35207/s/4d293258/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389487846/u/0/f/653902/c/35207/s/4d293258/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389487846/u/0/f/653902/c/35207/s/4d293258/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389487846/u/0/f/653902/c/35207/s/4d293258/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389487846/u/0/f/653902/c/35207/s/4d293258/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389487846/u/0/f/653902/c/35207/s/4d293258/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389487846/u/0/f/653902/c/35207/s/4d293258/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389487846/u/0/f/653902/c/35207/s/4d293258/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389487846/u/0/f/653902/c/35207/s/4d293258/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d293258/sc/3/mf.gif' + border='0'/> + Wed, 27 Jan 2016 09:10:00 GMT + http://heise.de/-3085140 + + Hacker

In einer bundesweiten Aktion gehen Ermittler der Bundesanwaltschaft gegen führende Betreiber des rechtsextremen Internetportals "Altermedia" vor. Ihnen wird die Gründung einer kriminellen Vereinigung vorgeworfen. Inzwischen wurde die Vereinigung verboten.










]]>
+
+ + Bundesdatenschutzbeauftragte warnt vor Dashcams + + http://www.heise.de/newsticker/meldung/Bundesdatenschutzbeauftragte-warnt-vor-Dashcams-3085120.html?wt_mc=rss.ho.beitrag.atom + + Im Ausland setzen Autofahrer vermehrt Videokameras ein, die hinter der + Windschutzscheibe postiert werden und das Geschehen vor dem Auto kontinuierlich + aufzeichnen. In Deutschland ist das aus Datenschutzgründen unzulässig, meint Andrea + Voßhoff.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389528982/u/0/f/653902/c/35207/s/4d293d2a/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389528982/u/0/f/653902/c/35207/s/4d293d2a/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389528982/u/0/f/653902/c/35207/s/4d293d2a/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389528982/u/0/f/653902/c/35207/s/4d293d2a/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389528982/u/0/f/653902/c/35207/s/4d293d2a/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389528982/u/0/f/653902/c/35207/s/4d293d2a/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389528982/u/0/f/653902/c/35207/s/4d293d2a/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389528982/u/0/f/653902/c/35207/s/4d293d2a/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389528982/u/0/f/653902/c/35207/s/4d293d2a/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d293d2a/sc/3/mf.gif' + border='0'/> + Wed, 27 Jan 2016 08:52:00 GMT + http://heise.de/-3085120 + + Dashcam

Im Ausland setzen Autofahrer vermehrt Videokameras ein, die hinter der Windschutzscheibe postiert werden und das Geschehen vor dem Auto kontinuierlich aufzeichnen. In Deutschland ist das aus Datenschutzgründen unzulässig, meint Andrea Voßhoff.










]]>
+
+ + Unitymedia bietet Kabelanschlüsse mit 400 MBit/s an + + http://www.heise.de/newsticker/meldung/Unitymedia-bietet-Kabelanschluesse-mit-400-MBit-s-an-3084956.html?wt_mc=rss.ho.beitrag.atom + + Der Kabelriese dreht an der Speed-Schraube: Rund 40 Prozent der Haushalte + im Verbreitungsgebiet in Nordrhein-Westfalen, Hessen und Baden-Württemberg können in + Kürze Anschlüsse mit bis zu 400 MBit/s buchen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389519640/u/0/f/653902/c/35207/s/4d291cc3/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389519640/u/0/f/653902/c/35207/s/4d291cc3/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389519640/u/0/f/653902/c/35207/s/4d291cc3/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389519640/u/0/f/653902/c/35207/s/4d291cc3/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389519640/u/0/f/653902/c/35207/s/4d291cc3/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389519640/u/0/f/653902/c/35207/s/4d291cc3/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389519640/u/0/f/653902/c/35207/s/4d291cc3/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389519640/u/0/f/653902/c/35207/s/4d291cc3/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389519640/u/0/f/653902/c/35207/s/4d291cc3/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d291cc3/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 08:30:00 GMT + http://heise.de/-3084956 + + Unitymedia

Der Kabelriese dreht an der Speed-Schraube: Rund 40 Prozent der Haushalte im Verbreitungsgebiet in Nordrhein-Westfalen, Hessen und Baden-Württemberg können in Kürze Anschlüsse mit bis zu 400 MBit/s buchen.










]]>
+
+ + Tim Cook zu den Apple-Quartalszahlen: Weiterhin kein Billig-iPhone + + http://www.heise.de/newsticker/meldung/Tim-Cook-zu-den-Apple-Quartalszahlen-Weiterhin-kein-Billig-iPhone-3085095.html?wt_mc=rss.ho.beitrag.atom + + Der Apple-Chef hat sich im Gespräch mit Analysten zur künftigen + Geschäftsstrategie geäußert, da das geringe Wachstum beim iPhone der Börse Sorge + bereitet. Auch zum für Cupertino zunehmend bedeutenden Wachstumsmarkt China nannte + er Details.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389519639/u/0/f/653902/c/35207/s/4d291cc2/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389519639/u/0/f/653902/c/35207/s/4d291cc2/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389519639/u/0/f/653902/c/35207/s/4d291cc2/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389519639/u/0/f/653902/c/35207/s/4d291cc2/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389519639/u/0/f/653902/c/35207/s/4d291cc2/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389519639/u/0/f/653902/c/35207/s/4d291cc2/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389519639/u/0/f/653902/c/35207/s/4d291cc2/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389519639/u/0/f/653902/c/35207/s/4d291cc2/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389519639/u/0/f/653902/c/35207/s/4d291cc2/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d291cc2/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 08:12:00 GMT + http://heise.de/-3085095 + + Tim Cook

Der Apple-Chef hat sich im Gespräch mit Analysten zur künftigen Geschäftsstrategie geäußert, da das geringe Wachstum beim iPhone der Börse Sorge bereitet. Auch zum für Cupertino zunehmend bedeutenden Wachstumsmarkt China nannte er Details.










]]>
+
+ + Lufthansa und Drohnenhersteller DJI werden Partner + + http://www.heise.de/newsticker/meldung/Lufthansa-und-Drohnenhersteller-DJI-werden-Partner-3085067.html?wt_mc=rss.ho.beitrag.atom + + Die Lufthansa möchte neue Geschäftsfelder erobern. Zusammen mit dem + Drohnenhersteller DJI sollen Drohnen für Großkunden gefertigt werden. Diese könnten + mit den fliegenden Helfern etwa einfacher Windkraftanlagen überwachen oder + Baufortschritte verfolgen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389516237/u/0/f/653902/c/35207/s/4d28e6a3/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389516237/u/0/f/653902/c/35207/s/4d28e6a3/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389516237/u/0/f/653902/c/35207/s/4d28e6a3/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389516237/u/0/f/653902/c/35207/s/4d28e6a3/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389516237/u/0/f/653902/c/35207/s/4d28e6a3/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389516237/u/0/f/653902/c/35207/s/4d28e6a3/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389516237/u/0/f/653902/c/35207/s/4d28e6a3/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389516237/u/0/f/653902/c/35207/s/4d28e6a3/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389516237/u/0/f/653902/c/35207/s/4d28e6a3/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d28e6a3/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 08:11:00 GMT + http://heise.de/-3085067 + + Drohne

Die Lufthansa möchte neue Geschäftsfelder erobern. Zusammen mit dem Drohnenhersteller DJI sollen Drohnen für Großkunden gefertigt werden. Diese könnten mit den fliegenden Helfern etwa einfacher Windkraftanlagen überwachen oder Baufortschritte verfolgen.










]]>
+
+ + Wasserknappheit bedroht Stromproduktion + + http://www.heise.de/newsticker/meldung/Wasserknappheit-bedroht-Stromproduktion-3084350.html?wt_mc=rss.ho.beitrag.atom + + Forscher fürchten, dass die globale Stromproduktion aufgrund des + Klimawandels in den nächsten 35 Jahren deutlich zurückgehen könnte. Der Grund: Dürre + macht Kühlung unmöglich.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389516745/u/0/f/653902/c/35207/s/4d2893ec/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389516745/u/0/f/653902/c/35207/s/4d2893ec/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389516745/u/0/f/653902/c/35207/s/4d2893ec/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389516745/u/0/f/653902/c/35207/s/4d2893ec/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389516745/u/0/f/653902/c/35207/s/4d2893ec/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389516745/u/0/f/653902/c/35207/s/4d2893ec/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389516745/u/0/f/653902/c/35207/s/4d2893ec/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389516745/u/0/f/653902/c/35207/s/4d2893ec/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389516745/u/0/f/653902/c/35207/s/4d2893ec/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2893ec/sc/3/mf.gif' + border='0'/> + Wed, 27 Jan 2016 07:07:00 GMT + http://heise.de/-3084350 + + Kraftwerk

Forscher fürchten, dass die globale Stromproduktion aufgrund des Klimawandels in den nächsten 35 Jahren deutlich zurückgehen könnte. Der Grund: Dürre macht Kühlung unmöglich.










]]>
+
+ + Studie: Soziale Netzwerke und schlechter Schlaf gehören zusammen + + http://www.heise.de/newsticker/meldung/Studie-Soziale-Netzwerke-und-schlechter-Schlaf-gehoeren-zusammen-3085003.html?wt_mc=rss.ho.beitrag.atom + + Verbringen junge Erwachsene Zeit in sozialen Netzwerken und greifen häufig + auf ihre Konten zu, leiden sie auch öfter unter Schlafstörungen. So lautet das + Ergebnis einer Studie von Forschern der University of Pittsburgh.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389514741/u/0/f/653902/c/35207/s/4d288bd0/sc/17/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389514741/u/0/f/653902/c/35207/s/4d288bd0/sc/17/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389514741/u/0/f/653902/c/35207/s/4d288bd0/sc/17/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389514741/u/0/f/653902/c/35207/s/4d288bd0/sc/17/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389514741/u/0/f/653902/c/35207/s/4d288bd0/sc/17/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389514741/u/0/f/653902/c/35207/s/4d288bd0/sc/17/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389514741/u/0/f/653902/c/35207/s/4d288bd0/sc/17/a2.htm"><img + src="http://da.feedsportal.com/r/247389514741/u/0/f/653902/c/35207/s/4d288bd0/sc/17/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389514741/u/0/f/653902/c/35207/s/4d288bd0/sc/17/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d288bd0/sc/17/mf.gif' + border='0'/> + Wed, 27 Jan 2016 06:48:00 GMT + http://heise.de/-3085003 + + Kind mit Tablet

Verbringen junge Erwachsene Zeit in sozialen Netzwerken und greifen häufig auf ihre Konten zu, leiden sie auch öfter unter Schlafstörungen. So lautet das Ergebnis einer Studie von Forschern der University of Pittsburgh.










]]>
+
+ + 136 Jahre nach Edisons Patent: Forscher arbeiten an einer Renaissance der + Glühbirne + + + http://www.heise.de/newsticker/meldung/136-Jahre-nach-Edisons-Patent-Forscher-arbeiten-an-einer-Renaissance-der-Gluehbirne-3084807.html?wt_mc=rss.ho.beitrag.atom + + Am 27. Januar 1880 erhielt Thomas A. Edison das Patent Nr. 223.898 für die + &quot;Elektrische Lampe&quot;. Heute wollen Forscher des MIT und der Purdue + University der totgesagten Glühbirne mit Nano-Beschichtung wieder eine Renaissance + bescheren.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389470313/u/0/f/653902/c/35207/s/4d28388a/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389470313/u/0/f/653902/c/35207/s/4d28388a/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389470313/u/0/f/653902/c/35207/s/4d28388a/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389470313/u/0/f/653902/c/35207/s/4d28388a/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389470313/u/0/f/653902/c/35207/s/4d28388a/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389470313/u/0/f/653902/c/35207/s/4d28388a/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389470313/u/0/f/653902/c/35207/s/4d28388a/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389470313/u/0/f/653902/c/35207/s/4d28388a/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389470313/u/0/f/653902/c/35207/s/4d28388a/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d28388a/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 06:30:00 GMT + http://heise.de/-3084807 + + Glühbirne

Am 27. Januar 1880 erhielt Thomas A. Edison das Patent Nr. 223.898 für die "Elektrische Lampe". Heute wollen Forscher des MIT und der Purdue University der totgesagten Glühbirne mit Nano-Beschichtung wieder eine Renaissance bescheren.










]]>
+
+ + Verschlüsselung: IETF standardisiert zwei weitere elliptische Kurven + + http://www.heise.de/newsticker/meldung/Verschluesselung-IETF-standardisiert-zwei-weitere-elliptische-Kurven-3084830.html?wt_mc=rss.ho.beitrag.atom + + Die IETF hat die beiden elliptischen Kurven Curve25519 und Curve448 als RFC + für Krypto-Funktionen offiziell abgesegnet. Eine Standardisierung der Kurven für den + Schlüsselaustausch bei TLS wird ebenfalls erwartet.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389510249/u/0/f/653902/c/35207/s/4d283e99/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389510249/u/0/f/653902/c/35207/s/4d283e99/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389510249/u/0/f/653902/c/35207/s/4d283e99/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389510249/u/0/f/653902/c/35207/s/4d283e99/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389510249/u/0/f/653902/c/35207/s/4d283e99/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389510249/u/0/f/653902/c/35207/s/4d283e99/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389510249/u/0/f/653902/c/35207/s/4d283e99/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389510249/u/0/f/653902/c/35207/s/4d283e99/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389510249/u/0/f/653902/c/35207/s/4d283e99/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d283e99/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 06:01:00 GMT + http://heise.de/-3084830 + + IETF verabschiedet zwei elliptische Kurven

Die IETF hat die beiden elliptischen Kurven Curve25519 und Curve448 als RFC für Krypto-Funktionen offiziell abgesegnet. Eine Standardisierung der Kurven für den Schlüsselaustausch bei TLS wird ebenfalls erwartet.










]]>
+
+ + Rekordgewinn: Apple trotzt dem starken Dollar + + http://www.heise.de/newsticker/meldung/Rekordgewinn-Apple-trotzt-dem-starken-Dollar-3085026.html?wt_mc=rss.ho.beitrag.atom + + Höchster Umsatz, höchster Reingewinn und eine Marge von 40 Prozent erzielte + Apple im Weihnachtsquartal. Weil frühere Weihnachtsquartale aber mehr Zuwachs + gebracht hatten, reagierte der Aktienmarkt leicht pikiert.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389507720/u/0/f/653902/c/35207/s/4d280d10/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389507720/u/0/f/653902/c/35207/s/4d280d10/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389507720/u/0/f/653902/c/35207/s/4d280d10/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389507720/u/0/f/653902/c/35207/s/4d280d10/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389507720/u/0/f/653902/c/35207/s/4d280d10/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389507720/u/0/f/653902/c/35207/s/4d280d10/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389507720/u/0/f/653902/c/35207/s/4d280d10/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389507720/u/0/f/653902/c/35207/s/4d280d10/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389507720/u/0/f/653902/c/35207/s/4d280d10/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d280d10/sc/3/mf.gif' + border='0'/> + Wed, 27 Jan 2016 05:34:00 GMT + http://heise.de/-3085026 + + Abfallende Kurve

Höchster Umsatz, höchster Reingewinn und eine Marge von 40 Prozent erzielte Apple im Weihnachtsquartal. Weil frühere Weihnachtsquartale aber mehr Zuwachs gebracht hatten, reagierte der Aktienmarkt leicht pikiert.










]]>
+
+ + Dank Eigenbau-Exoskelett: Der menschliche Wagenheber + + http://www.heise.de/newsticker/meldung/Dank-Eigenbau-Exoskelett-Der-menschliche-Wagenheber-3084868.html?wt_mc=rss.ho.beitrag.atom + + Wie viel Krafttraining braucht man, um die Hinterachse eines Mini Coopers + vom Boden zu heben? Keines, jedenfalls wenn man das pneumatische Exoskelett benutzt, + das James Hobson selbst gebaut hat.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389498069/u/0/f/653902/c/35207/s/4d281348/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389498069/u/0/f/653902/c/35207/s/4d281348/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389498069/u/0/f/653902/c/35207/s/4d281348/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389498069/u/0/f/653902/c/35207/s/4d281348/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389498069/u/0/f/653902/c/35207/s/4d281348/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389498069/u/0/f/653902/c/35207/s/4d281348/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389498069/u/0/f/653902/c/35207/s/4d281348/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389498069/u/0/f/653902/c/35207/s/4d281348/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389498069/u/0/f/653902/c/35207/s/4d281348/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d281348/sc/21/mf.gif' + border='0'/> + Wed, 27 Jan 2016 05:00:00 GMT + http://heise.de/-3084868 + + DIY Exoskelett hebt Auto

Wie viel Krafttraining braucht man, um die Hinterachse eines Mini Coopers vom Boden zu heben? Keines, jedenfalls wenn man das pneumatische Exoskelett benutzt, das James Hobson selbst gebaut hat.










]]>
+
+ + "Online-Kriminellen nicht hinterherlaufen" – Mehr EU-Kooperation gegen + Cyberkriminalität + + + http://www.heise.de/newsticker/meldung/Online-Kriminellen-nicht-hinterherlaufen-Mehr-EU-Kooperation-gegen-Cyberkriminalitaet-3084940.html?wt_mc=rss.ho.beitrag.atom + + Wer ein Verbrechen begeht, hinterlässt oft Spuren – das gilt auch im + Internet. Doch in der virtuellen Welt ist die Strafverfolgung schwierig. Was wenn + der Täter von einem weit entfernten Erdteil agiert oder Daten dort gespeichert sind?<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389422225/u/0/f/653902/c/35207/s/4d25a88b/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389422225/u/0/f/653902/c/35207/s/4d25a88b/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389422225/u/0/f/653902/c/35207/s/4d25a88b/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389422225/u/0/f/653902/c/35207/s/4d25a88b/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389422225/u/0/f/653902/c/35207/s/4d25a88b/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389422225/u/0/f/653902/c/35207/s/4d25a88b/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389422225/u/0/f/653902/c/35207/s/4d25a88b/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389422225/u/0/f/653902/c/35207/s/4d25a88b/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389422225/u/0/f/653902/c/35207/s/4d25a88b/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d25a88b/sc/3/mf.gif' + border='0'/> + Tue, 26 Jan 2016 18:08:00 GMT + http://heise.de/-3084940 + + "Enter Password"

Wer ein Verbrechen begeht, hinterlässt oft Spuren – das gilt auch im Internet. Doch in der virtuellen Welt ist die Strafverfolgung schwierig. Was wenn der Täter von einem weit entfernten Erdteil agiert oder Daten dort gespeichert sind?










]]>
+
+ + Jolla: Update für Sailfish OS, Tablet-Abwicklung ungeklärt + + http://www.heise.de/newsticker/meldung/Jolla-Update-fuer-Sailfish-OS-Tablet-Abwicklung-ungeklaert-3084918.html?wt_mc=rss.ho.beitrag.atom + + Die Abwicklung des gescheiterten Tablet-Projekts verzögert sich bei Jolla + weiter. Dafür stellt das Start-up ein Update für sein Betriebssystem Sailfish OS + bereit und Partner Intex kündigt für den MWC ein Smartphone mit Sailfish OS an.<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389460756/u/0/f/653902/c/35207/s/4d256c68/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389460756/u/0/f/653902/c/35207/s/4d256c68/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389460756/u/0/f/653902/c/35207/s/4d256c68/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389460756/u/0/f/653902/c/35207/s/4d256c68/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389460756/u/0/f/653902/c/35207/s/4d256c68/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389460756/u/0/f/653902/c/35207/s/4d256c68/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389460756/u/0/f/653902/c/35207/s/4d256c68/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389460756/u/0/f/653902/c/35207/s/4d256c68/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389460756/u/0/f/653902/c/35207/s/4d256c68/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d256c68/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 17:41:00 GMT + http://heise.de/-3084918 + + Jolla: Update für Sailfish OS, Tablet-Abwicklung ungeklärt

Die Abwicklung des gescheiterten Tablet-Projekts verzögert sich bei Jolla weiter. Dafür stellt das Start-up ein Update für sein Betriebssystem Sailfish OS bereit und Partner Intex kündigt für den MWC ein Smartphone mit Sailfish OS an.










]]>
+
+ + Periscope ermöglicht Livestreaming mit GoPro-Kamera + + http://www.heise.de/newsticker/meldung/Periscope-ermoeglicht-Livestreaming-mit-GoPro-Kamera-3084901.html?wt_mc=rss.ho.beitrag.atom + + Die iPhone-App von Twitters Livestreaming-Dienstes unterstützt nun GoPro: + Die Aufnahme der Action-Cam lässt sich so unmittelbar ausstrahlen – im Wechsel mit + der iPhone-Kamera<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389416151/u/0/f/653902/c/35207/s/4d252b88/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389416151/u/0/f/653902/c/35207/s/4d252b88/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389416151/u/0/f/653902/c/35207/s/4d252b88/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389416151/u/0/f/653902/c/35207/s/4d252b88/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389416151/u/0/f/653902/c/35207/s/4d252b88/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389416151/u/0/f/653902/c/35207/s/4d252b88/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389416151/u/0/f/653902/c/35207/s/4d252b88/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389416151/u/0/f/653902/c/35207/s/4d252b88/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389416151/u/0/f/653902/c/35207/s/4d252b88/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d252b88/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 17:11:00 GMT + http://heise.de/-3084901 + + Periscope GoPro

Die iPhone-App von Twitters Livestreaming-Dienstes unterstützt nun GoPro: Die Aufnahme der Action-Cam lässt sich so unmittelbar ausstrahlen – im Wechsel mit der iPhone-Kamera










]]>
+
+ + Globales Satelliten-Internet: Airbus gründet Joint Venture mit OneWeb + + http://www.heise.de/newsticker/meldung/Globales-Satelliten-Internet-Airbus-gruendet-Joint-Venture-mit-OneWeb-3084840.html?wt_mc=rss.ho.beitrag.atom + + Der europäische Rüstungs- und Weltraumkonzern Airbus arbeitet jetzt noch + enger mit OneWeb zusammen bei dem Vorhaben, Hunderte Satelliten ins All zu schießen, + die die ganze Erde mit Internet versorgen sollen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389454758/u/0/f/653902/c/35207/s/4d252c8b/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389454758/u/0/f/653902/c/35207/s/4d252c8b/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389454758/u/0/f/653902/c/35207/s/4d252c8b/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389454758/u/0/f/653902/c/35207/s/4d252c8b/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389454758/u/0/f/653902/c/35207/s/4d252c8b/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389454758/u/0/f/653902/c/35207/s/4d252c8b/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389454758/u/0/f/653902/c/35207/s/4d252c8b/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389454758/u/0/f/653902/c/35207/s/4d252c8b/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389454758/u/0/f/653902/c/35207/s/4d252c8b/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d252c8b/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 16:38:00 GMT + http://heise.de/-3084840 + + Globales Satelliten-Internet: Airbus gründet Joint Venture mit OneWeb

Der europäische Rüstungs- und Weltraumkonzern Airbus arbeitet jetzt noch enger mit OneWeb zusammen bei dem Vorhaben, Hunderte Satelliten ins All zu schießen, die die ganze Erde mit Internet versorgen sollen.










]]>
+
+ + Verfassungsgericht stoppt Vorratsdatenspeicherung vorerst nicht + + http://www.heise.de/newsticker/meldung/Verfassungsgericht-stoppt-Vorratsdatenspeicherung-vorerst-nicht-3084879.html?wt_mc=rss.ho.beitrag.atom + + Das Bundesverfassungsgericht hat einen Antrag aus einer + Verfassungsbeschwerde abgelehnt, wonach die neue Speicherpflicht für elektronische + Nutzerspuren zunächst gar nicht greifen sollte. In der Sache ist damit aber noch + nichts entschieden.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389454757/u/0/f/653902/c/35207/s/4d252c8a/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389454757/u/0/f/653902/c/35207/s/4d252c8a/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389454757/u/0/f/653902/c/35207/s/4d252c8a/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389454757/u/0/f/653902/c/35207/s/4d252c8a/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389454757/u/0/f/653902/c/35207/s/4d252c8a/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389454757/u/0/f/653902/c/35207/s/4d252c8a/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389454757/u/0/f/653902/c/35207/s/4d252c8a/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389454757/u/0/f/653902/c/35207/s/4d252c8a/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389454757/u/0/f/653902/c/35207/s/4d252c8a/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d252c8a/sc/3/mf.gif' + border='0'/> + Tue, 26 Jan 2016 16:37:00 GMT + http://heise.de/-3084879 + + Verfassungsgericht stoppt Vorratsdatenspeicherung vorerst nicht

Das Bundesverfassungsgericht hat einen Antrag aus einer Verfassungsbeschwerde abgelehnt, wonach die neue Speicherpflicht für elektronische Nutzerspuren zunächst gar nicht greifen sollte. In der Sache ist damit aber noch nichts entschieden.










]]>
+
+ + Intel enthüllt erste Skylake-Prozessoren mit Iris-Pro-Grafik + + http://www.heise.de/newsticker/meldung/Intel-enthuellt-erste-Skylake-Prozessoren-mit-Iris-Pro-Grafik-3084686.html?wt_mc=rss.ho.beitrag.atom + + In Intels neustem Preislisten-Update finden sich etliche neue + Skylake-Modelle für Notebooks, darunter das neue Flaggschiff: der rund 1200 + US-Dollar teure Xeon E3-1575M v5 mit Iris Pro P580.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389453021/u/0/f/653902/c/35207/s/4d24fe5f/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389453021/u/0/f/653902/c/35207/s/4d24fe5f/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389453021/u/0/f/653902/c/35207/s/4d24fe5f/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389453021/u/0/f/653902/c/35207/s/4d24fe5f/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389453021/u/0/f/653902/c/35207/s/4d24fe5f/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389453021/u/0/f/653902/c/35207/s/4d24fe5f/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389453021/u/0/f/653902/c/35207/s/4d24fe5f/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389453021/u/0/f/653902/c/35207/s/4d24fe5f/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389453021/u/0/f/653902/c/35207/s/4d24fe5f/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d24fe5f/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 16:27:00 GMT + http://heise.de/-3084686 + + Intel

In Intels neustem Preislisten-Update finden sich etliche neue Skylake-Modelle für Notebooks, darunter das neue Flaggschiff: der rund 1200 US-Dollar teure Xeon E3-1575M v5 mit Iris Pro P580.










]]>
+
+ + Pornografie-Vorwurf: Pakistan sperrt mehr als 400.000 Webseiten + + http://www.heise.de/newsticker/meldung/Pornografie-Vorwurf-Pakistan-sperrt-mehr-als-400-000-Webseiten-3084805.html?wt_mc=rss.ho.beitrag.atom + + Eine Woche nach der Wiederzulassung von YouTube hat Pakistans + Telekommunikationsbehörde angekündigt, eine halbe Million Webseiten wegen + angeblicher Pornografie zu löschen. Welche Seiten es letztlich trifft, ist noch + nicht abzusehen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389441451/u/0/f/653902/c/35207/s/4d24d43d/sc/17/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389441451/u/0/f/653902/c/35207/s/4d24d43d/sc/17/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389441451/u/0/f/653902/c/35207/s/4d24d43d/sc/17/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389441451/u/0/f/653902/c/35207/s/4d24d43d/sc/17/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389441451/u/0/f/653902/c/35207/s/4d24d43d/sc/17/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389441451/u/0/f/653902/c/35207/s/4d24d43d/sc/17/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389441451/u/0/f/653902/c/35207/s/4d24d43d/sc/17/a2.htm"><img + src="http://da.feedsportal.com/r/247389441451/u/0/f/653902/c/35207/s/4d24d43d/sc/17/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389441451/u/0/f/653902/c/35207/s/4d24d43d/sc/17/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d24d43d/sc/17/mf.gif' + border='0'/> + Tue, 26 Jan 2016 15:50:00 GMT + http://heise.de/-3084805 + + Surfen im Internet

Eine Woche nach der Wiederzulassung von YouTube hat Pakistans Telekommunikationsbehörde angekündigt, eine halbe Million Webseiten wegen angeblicher Pornografie zu löschen. Welche Seiten es letztlich trifft, ist noch nicht abzusehen.










]]>
+
+ + Phishing-SMS: Identitätsdiebstahl bei Car2go-Kunden + + http://www.heise.de/newsticker/meldung/Phishing-SMS-Identitaetsdiebstahl-bei-Car2go-Kunden-3084730.html?wt_mc=rss.ho.beitrag.atom + + Über eine SMS wollen Betrüger Car2go-Nutzer auf eine Phishing-Webseite + locken und persönliche Daten abziehen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389439795/u/0/f/653902/c/35207/s/4d24cd38/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389439795/u/0/f/653902/c/35207/s/4d24cd38/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389439795/u/0/f/653902/c/35207/s/4d24cd38/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389439795/u/0/f/653902/c/35207/s/4d24cd38/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389439795/u/0/f/653902/c/35207/s/4d24cd38/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389439795/u/0/f/653902/c/35207/s/4d24cd38/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389439795/u/0/f/653902/c/35207/s/4d24cd38/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389439795/u/0/f/653902/c/35207/s/4d24cd38/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389439795/u/0/f/653902/c/35207/s/4d24cd38/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d24cd38/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 15:39:00 GMT + http://heise.de/-3084730 + + SMS

Über eine SMS wollen Betrüger Car2go-Nutzer auf eine Phishing-Webseite locken und persönliche Daten abziehen.










]]>
+
+ + Studie: Vernetzung von Autos schafft mehr Sicherheit – aber auch Skepsis + + http://www.heise.de/newsticker/meldung/Studie-Vernetzung-von-Autos-schafft-mehr-Sicherheit-aber-auch-Skepsis-3084679.html?wt_mc=rss.ho.beitrag.atom + + Analysten im Auftrag des Wirtschaftsministeriums kommen zu dem Ergebnis, + dass die Vernetzung von Fahrzeugen und Straßen Sicherheit und Komfort verbessert. + Die Angst vorm gläsernen Fahrer müsse aber bewältigt werden.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389446423/u/0/f/653902/c/35207/s/4d24bc09/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389446423/u/0/f/653902/c/35207/s/4d24bc09/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389446423/u/0/f/653902/c/35207/s/4d24bc09/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389446423/u/0/f/653902/c/35207/s/4d24bc09/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389446423/u/0/f/653902/c/35207/s/4d24bc09/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389446423/u/0/f/653902/c/35207/s/4d24bc09/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389446423/u/0/f/653902/c/35207/s/4d24bc09/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389446423/u/0/f/653902/c/35207/s/4d24bc09/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389446423/u/0/f/653902/c/35207/s/4d24bc09/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d24bc09/sc/3/mf.gif' + border='0'/> + Tue, 26 Jan 2016 15:18:00 GMT + http://heise.de/-3084679 + + Vernetzte Autos

Analysten im Auftrag des Wirtschaftsministeriums kommen zu dem Ergebnis, dass die Vernetzung von Fahrzeugen und Straßen Sicherheit und Komfort verbessert. Die Angst vorm gläsernen Fahrer müsse aber bewältigt werden.










]]>
+
+ + Spezieller Einhandmodus für Microsofts iPhone-Tastatur + + http://www.heise.de/newsticker/meldung/Spezieller-Einhandmodus-fuer-Microsofts-iPhone-Tastatur-3084738.html?wt_mc=rss.ho.beitrag.atom + + Die geplante iOS-Version von Microsofts Word-Flow-Keyboard erhält einem + Bericht zufolge einen besonderen Modus für die einhändige Bedienung. Der öffentliche + Beta-Test der Tastatur soll bald beginnen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389403553/u/0/f/653902/c/35207/s/4d2495f5/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389403553/u/0/f/653902/c/35207/s/4d2495f5/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389403553/u/0/f/653902/c/35207/s/4d2495f5/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389403553/u/0/f/653902/c/35207/s/4d2495f5/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389403553/u/0/f/653902/c/35207/s/4d2495f5/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389403553/u/0/f/653902/c/35207/s/4d2495f5/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389403553/u/0/f/653902/c/35207/s/4d2495f5/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389403553/u/0/f/653902/c/35207/s/4d2495f5/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389403553/u/0/f/653902/c/35207/s/4d2495f5/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2495f5/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 15:10:00 GMT + http://heise.de/-3084738 + + Word Flow Microsoft

Die geplante iOS-Version von Microsofts Word-Flow-Keyboard erhält einem Bericht zufolge einen besonderen Modus für die einhändige Bedienung. Der öffentliche Beta-Test der Tastatur soll bald beginnen.










]]>
+
+ + Groupon schließt in der Schweiz und in Österreich + + http://www.heise.de/newsticker/meldung/Groupon-schliesst-in-der-Schweiz-und-in-Oesterreich-3084595.html?wt_mc=rss.ho.beitrag.atom + + Das Rabatt-Portal Groupon reduziert sein internationales Angebot: Zum 25. + Januar hat das Unternehmen seine Geschäfte in Österreich und in der Schweiz + eingestellt.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389398598/u/0/f/653902/c/35207/s/4d245ae7/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389398598/u/0/f/653902/c/35207/s/4d245ae7/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389398598/u/0/f/653902/c/35207/s/4d245ae7/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389398598/u/0/f/653902/c/35207/s/4d245ae7/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389398598/u/0/f/653902/c/35207/s/4d245ae7/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389398598/u/0/f/653902/c/35207/s/4d245ae7/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389398598/u/0/f/653902/c/35207/s/4d245ae7/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389398598/u/0/f/653902/c/35207/s/4d245ae7/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389398598/u/0/f/653902/c/35207/s/4d245ae7/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d245ae7/sc/3/mf.gif' + border='0'/> + Tue, 26 Jan 2016 14:30:00 GMT + http://heise.de/-3084595 + + Groupon

Das Rabatt-Portal Groupon reduziert sein internationales Angebot: Zum 25. Januar hat das Unternehmen seine Geschäfte in Österreich und in der Schweiz eingestellt.










]]>
+
+ + Bilderkennung: Algorithmen aus Jena sollen Tiere auch in Bewegung bestimmen + können + + + http://www.heise.de/newsticker/meldung/Bilderkennung-Algorithmen-aus-Jena-sollen-Tiere-auch-in-Bewegung-bestimmen-koennen-3084658.html?wt_mc=rss.ho.beitrag.atom + + So manches Elternteil wird stutzen, wenn das Kind auf dem Waldspaziergang + nach dem Namen einer Pflanze oder eines Tieres fragt. Forscher der Uni Jena könnten + mit einem von ihnen entwickelten Verfahren vielleicht bald Apphilfe schaffen.<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389398597/u/0/f/653902/c/35207/s/4d245ae6/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389398597/u/0/f/653902/c/35207/s/4d245ae6/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389398597/u/0/f/653902/c/35207/s/4d245ae6/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389398597/u/0/f/653902/c/35207/s/4d245ae6/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389398597/u/0/f/653902/c/35207/s/4d245ae6/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389398597/u/0/f/653902/c/35207/s/4d245ae6/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389398597/u/0/f/653902/c/35207/s/4d245ae6/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389398597/u/0/f/653902/c/35207/s/4d245ae6/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389398597/u/0/f/653902/c/35207/s/4d245ae6/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d245ae6/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 14:20:00 GMT + http://heise.de/-3084658 + + Bilderkennung: Algorithmen aus Jena sollen Tiere auch in Bewegung bestimmen können

So manches Elternteil wird stutzen, wenn das Kind auf dem Waldspaziergang nach dem Namen einer Pflanze oder eines Tieres fragt. Forscher der Uni Jena könnten mit einem von ihnen entwickelten Verfahren vielleicht bald Apphilfe schaffen.










]]>
+
+ + Neue Folgen von Akte X: "Ich will es immer noch glauben" + + http://www.heise.de/newsticker/meldung/Neue-Folgen-von-Akte-X-Ich-will-es-immer-noch-glauben-3084426.html?wt_mc=rss.ho.beitrag.atom + + 13 Jahre nach ihrem Ende geht die US-Serie &quot;Akte X&quot; + weiter, als Fortsetzung des Klassikers in modernem Gewand und unserer Zeit. + Inhaltlich bleibt sie sich treu: An allem sind geheime Verschwörer schuld – eine + Einschätzung, die seltsam bekannt klingt.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389434588/u/0/f/653902/c/35207/s/4d240285/sc/17/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389434588/u/0/f/653902/c/35207/s/4d240285/sc/17/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389434588/u/0/f/653902/c/35207/s/4d240285/sc/17/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389434588/u/0/f/653902/c/35207/s/4d240285/sc/17/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389434588/u/0/f/653902/c/35207/s/4d240285/sc/17/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389434588/u/0/f/653902/c/35207/s/4d240285/sc/17/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389434588/u/0/f/653902/c/35207/s/4d240285/sc/17/a2.htm"><img + src="http://da.feedsportal.com/r/247389434588/u/0/f/653902/c/35207/s/4d240285/sc/17/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389434588/u/0/f/653902/c/35207/s/4d240285/sc/17/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d240285/sc/17/mf.gif' + border='0'/> + Tue, 26 Jan 2016 13:35:00 GMT + http://heise.de/-3084426 + + Neue Folgen von Akte X: "Ich will es nur glauben"

13 Jahre nach ihrem Ende geht die US-Serie "Akte X" weiter, als Fortsetzung des Klassikers in modernem Gewand und unserer Zeit. Inhaltlich bleibt sie sich treu: An allem sind geheime Verschwörer schuld – eine Einschätzung, die seltsam bekannt klingt.










]]>
+
+ + Frag den Bundestag: Parlamentsgutachten sollen öffentlich werden + + http://www.heise.de/newsticker/meldung/Frag-den-Bundestag-Parlamentsgutachten-sollen-oeffentlich-werden-3084481.html?wt_mc=rss.ho.beitrag.atom + + Über das neue Portal &quot;Frag den Bundestag&quot; können Nutzer + per Knopfdruck Studien des Wissenschaftlichen Dienstes des Bundestags beantragen. So + soll es möglich werden, alle herausgegebenen Untersuchungen in einer + Online-Bibliothek zu veröffentlichen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389434587/u/0/f/653902/c/35207/s/4d240284/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389434587/u/0/f/653902/c/35207/s/4d240284/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389434587/u/0/f/653902/c/35207/s/4d240284/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389434587/u/0/f/653902/c/35207/s/4d240284/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389434587/u/0/f/653902/c/35207/s/4d240284/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389434587/u/0/f/653902/c/35207/s/4d240284/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389434587/u/0/f/653902/c/35207/s/4d240284/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389434587/u/0/f/653902/c/35207/s/4d240284/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389434587/u/0/f/653902/c/35207/s/4d240284/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d240284/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 13:32:00 GMT + http://heise.de/-3084481 + + Frag den Bundestag: Parlamentsgutachten sollen öffentlich werden

Über das neue Portal "Frag den Bundestag" können Nutzer per Knopfdruck Studien des Wissenschaftlichen Dienstes des Bundestags beantragen. So soll es möglich werden, alle herausgegebenen Untersuchungen in einer Online-Bibliothek zu veröffentlichen.










]]>
+
+ + USA: 300.000 Hobbypiloten registrieren ihre Drohnen + + http://www.heise.de/newsticker/meldung/USA-300-000-Hobbypiloten-registrieren-ihre-Drohnen-3084403.html?wt_mc=rss.ho.beitrag.atom + + Seit dem 21. Dezember 2015 müssen Hobbypiloten in den USA ihre kleinen + unbemannten Flugobjekte registrieren. Nun hat die Luftfahrtbehörde erste Zahlen + veröffentlicht. Bei einer Registrierung bis zum 20. Januar konnten Piloten mit einer + Belohnung rechnen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389390571/u/0/f/653902/c/35207/s/4d23ebcb/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389390571/u/0/f/653902/c/35207/s/4d23ebcb/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389390571/u/0/f/653902/c/35207/s/4d23ebcb/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389390571/u/0/f/653902/c/35207/s/4d23ebcb/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389390571/u/0/f/653902/c/35207/s/4d23ebcb/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389390571/u/0/f/653902/c/35207/s/4d23ebcb/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389390571/u/0/f/653902/c/35207/s/4d23ebcb/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389390571/u/0/f/653902/c/35207/s/4d23ebcb/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389390571/u/0/f/653902/c/35207/s/4d23ebcb/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d23ebcb/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 13:06:00 GMT + http://heise.de/-3084403 + + Drohne

Seit dem 21. Dezember 2015 müssen Hobbypiloten in den USA ihre kleinen unbemannten Flugobjekte registrieren. Nun hat die Luftfahrtbehörde erste Zahlen veröffentlicht. Bei einer Registrierung bis zum 20. Januar konnten Piloten mit einer Belohnung rechnen.










]]>
+
+ + Autoindustrie und Datenschützer: KfZ-Daten unterliegen dem Datenschutz + + http://www.heise.de/newsticker/meldung/Autoindustrie-und-Datenschuetzer-KfZ-Daten-unterliegen-dem-Datenschutz-3084253.html?wt_mc=rss.ho.beitrag.atom + + Alle Daten, die in einem Fahrzeug anfallen, gelten als personenbezogen, + sobald sie mit der Fahrzeugidentifikationsnummer oder dem Kfz-Kennzeichen verknüpft + sind. Darauf und auf mehr haben sich Industrie und Datenschutzbeauftragte geeinigt.<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389411781/u/0/f/653902/c/35207/s/4d2348fb/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389411781/u/0/f/653902/c/35207/s/4d2348fb/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389411781/u/0/f/653902/c/35207/s/4d2348fb/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389411781/u/0/f/653902/c/35207/s/4d2348fb/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389411781/u/0/f/653902/c/35207/s/4d2348fb/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389411781/u/0/f/653902/c/35207/s/4d2348fb/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389411781/u/0/f/653902/c/35207/s/4d2348fb/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389411781/u/0/f/653902/c/35207/s/4d2348fb/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389411781/u/0/f/653902/c/35207/s/4d2348fb/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2348fb/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 11:37:00 GMT + http://heise.de/-3084253 + + Auto

Alle Daten, die in einem Fahrzeug anfallen, gelten als personenbezogen, sobald sie mit der Fahrzeugidentifikationsnummer oder dem Kfz-Kennzeichen verknüpft sind. Darauf und auf mehr haben sich Industrie und Datenschutzbeauftragte geeinigt.










]]>
+
+ + Wirtschaftsministerium richtet Leseraum für TTIP-Dokumente ein + + http://www.heise.de/newsticker/meldung/Wirtschaftsministerium-richtet-Leseraum-fuer-TTIP-Dokumente-ein-3084344.html?wt_mc=rss.ho.beitrag.atom + + Die Bundesregierung kommt einer Forderung des Bundestags nach und gewährt + Abgeordneten und Ländervertretern Zugang zu vertraulichen Verhandlungspapieren rund + um das umstrittene Handelsabkommen TTIP.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389411780/u/0/f/653902/c/35207/s/4d2348fa/sc/3/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389411780/u/0/f/653902/c/35207/s/4d2348fa/sc/3/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389411780/u/0/f/653902/c/35207/s/4d2348fa/sc/3/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389411780/u/0/f/653902/c/35207/s/4d2348fa/sc/3/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389411780/u/0/f/653902/c/35207/s/4d2348fa/sc/3/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389411780/u/0/f/653902/c/35207/s/4d2348fa/sc/3/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389411780/u/0/f/653902/c/35207/s/4d2348fa/sc/3/a2.htm"><img + src="http://da.feedsportal.com/r/247389411780/u/0/f/653902/c/35207/s/4d2348fa/sc/3/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389411780/u/0/f/653902/c/35207/s/4d2348fa/sc/3/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d2348fa/sc/3/mf.gif' + border='0'/> + Tue, 26 Jan 2016 11:27:00 GMT + http://heise.de/-3084344 + + Wirtschaftsministerium richtet Leseraum für TTIP-Dokumente ein

Die Bundesregierung kommt einer Forderung des Bundestags nach und gewährt Abgeordneten und Ländervertretern Zugang zu vertraulichen Verhandlungspapieren rund um das umstrittene Handelsabkommen TTIP.










]]>
+
+ + Sony verlegt seine Playstation-Zentrale von Japan in die USA + + http://www.heise.de/newsticker/meldung/Sony-verlegt-seine-Playstation-Zentrale-von-Japan-in-die-USA-3084235.html?wt_mc=rss.ho.beitrag.atom + + Unter dem Dach der Sony Interactive Entertainment (SIE) sollen die + Geschäfte mit Hard- und Software sowie Inhalten und Netzwerkservices zusammengeführt + werden – und zwar in Kalifornien.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389402157/u/0/f/653902/c/35207/s/4d22c030/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389402157/u/0/f/653902/c/35207/s/4d22c030/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389402157/u/0/f/653902/c/35207/s/4d22c030/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389402157/u/0/f/653902/c/35207/s/4d22c030/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389402157/u/0/f/653902/c/35207/s/4d22c030/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389402157/u/0/f/653902/c/35207/s/4d22c030/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389402157/u/0/f/653902/c/35207/s/4d22c030/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389402157/u/0/f/653902/c/35207/s/4d22c030/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389402157/u/0/f/653902/c/35207/s/4d22c030/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d22c030/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 10:13:00 GMT + http://heise.de/-3084235 + + Playstation

Unter dem Dach der Sony Interactive Entertainment (SIE) sollen die Geschäfte mit Hard- und Software sowie Inhalten und Netzwerkservices zusammengeführt werden – und zwar in Kalifornien.










]]>
+
+ + Sicherheitsupdate für OpenSSL steht an + + http://www.heise.de/newsticker/meldung/Sicherheitsupdate-fuer-OpenSSL-steht-an-3084227.html?wt_mc=rss.ho.beitrag.atom + + Neue OpenSSL-Versionen sollen zwei Sicherheitslücken schließen. Den + Schweregrad einer Schwachstelle stuft das OpenSSL-Team mit hoch ein.<br + clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389402156/u/0/f/653902/c/35207/s/4d22c02f/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389402156/u/0/f/653902/c/35207/s/4d22c02f/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389402156/u/0/f/653902/c/35207/s/4d22c02f/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389402156/u/0/f/653902/c/35207/s/4d22c02f/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389402156/u/0/f/653902/c/35207/s/4d22c02f/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389402156/u/0/f/653902/c/35207/s/4d22c02f/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389402156/u/0/f/653902/c/35207/s/4d22c02f/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389402156/u/0/f/653902/c/35207/s/4d22c02f/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389402156/u/0/f/653902/c/35207/s/4d22c02f/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d22c02f/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 10:10:00 GMT + http://heise.de/-3084227 + + Schlüssel

Neue OpenSSL-Versionen sollen zwei Sicherheitslücken schließen. Den Schweregrad einer Schwachstelle stuft das OpenSSL-Team mit hoch ein.










]]>
+
+ + PDF-Reader Foxit Reader für Schadcode anfällig + + http://www.heise.de/newsticker/meldung/PDF-Reader-Foxit-Reader-fuer-Schadcode-anfaellig-3084161.html?wt_mc=rss.ho.beitrag.atom + + Neue Versionen sichern Foxit PhantomPDF und Foxit Reader ab. Beide + Anwendungen lassen sich aus der Ferne attackieren und Angreifer können eigenen Code + auf Computer schleusen.<br clear='all'/><br/><br/><a + href="http://rc.feedsportal.com/r/247389406045/u/0/f/653902/c/35207/s/4d227a5f/sc/21/rc/1/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389406045/u/0/f/653902/c/35207/s/4d227a5f/sc/21/rc/1/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389406045/u/0/f/653902/c/35207/s/4d227a5f/sc/21/rc/2/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389406045/u/0/f/653902/c/35207/s/4d227a5f/sc/21/rc/2/rc.img" + border="0"/></a><br/><br/><a + href="http://rc.feedsportal.com/r/247389406045/u/0/f/653902/c/35207/s/4d227a5f/sc/21/rc/3/rc.htm" + rel="nofollow"><img + src="http://rc.feedsportal.com/r/247389406045/u/0/f/653902/c/35207/s/4d227a5f/sc/21/rc/3/rc.img" + border="0"/></a><br/><br/><a + href="http://da.feedsportal.com/r/247389406045/u/0/f/653902/c/35207/s/4d227a5f/sc/21/a2.htm"><img + src="http://da.feedsportal.com/r/247389406045/u/0/f/653902/c/35207/s/4d227a5f/sc/21/a2.img" + border="0"/></a><img width="1" height="1" + src="http://pi.feedsportal.com/r/247389406045/u/0/f/653902/c/35207/s/4d227a5f/sc/21/a2t.img" + border="0"/><img width='1' height='1' + src='http://heise.de.feedsportal.com/c/35207/f/653902/s/4d227a5f/sc/21/mf.gif' + border='0'/> + Tue, 26 Jan 2016 09:53:00 GMT + http://heise.de/-3084161 + + Foxit Reader für Schadcode anfällig

Neue Versionen sichern Foxit PhantomPDF und Foxit Reader ab. Beide Anwendungen lassen sich aus der Ferne attackieren und Angreifer können eigenen Code auf Computer schleusen.










]]>
+
+ + diff --git a/mobile/android/tests/background/junit4/resources/feed_rss_medium.xml b/mobile/android/tests/background/junit4/resources/feed_rss_medium.xml new file mode 100644 index 000000000..0f5a20ab6 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_rss_medium.xml @@ -0,0 +1,100 @@ + + + + + <![CDATA[Anthony Lam on Medium]]> + + https://medium.com/@antlam?source=rss-59f49b9e4b19------2 + + https://d262ilb51hltx0.cloudfront.net/fit/c/150/150/1*BNfAhhQ8TybWsu_gMMixWw.jpeg + Anthony Lam on Medium + https://medium.com/@antlam?source=rss-59f49b9e4b19------2 + + RSS for Node + Tue, 26 Jan 2016 17:06:09 GMT + + + + + <![CDATA[UX thoughts for 2016]]> +

And just like that, another year.

]]>
+ https://medium.com/@antlam/ux-thoughts-for-2016-1fc1d6e515e8?source=rss-59f49b9e4b19------2 + https://medium.com/p/1fc1d6e515e8 + + Mon, 11 Jan 2016 18:43:58 GMT +
+ + <![CDATA[A New Mobile Tabs tray]]> +

Why we’re giving it an update in Firefox for Android

]]>
+ https://medium.com/@antlam/a-new-mobile-tabs-tray-327ac262eacb?source=rss-59f49b9e4b19------2 + https://medium.com/p/327ac262eacb + + Fri, 06 Nov 2015 17:30:55 GMT +
+ + <![CDATA[Quick search]]> +

Instantly search with any of your search providers

]]>
+ https://medium.com/@antlam/quick-search-bdd374257e75?source=rss-59f49b9e4b19------2 + https://medium.com/p/bdd374257e75 + + Tue, 01 Sep 2015 17:36:32 GMT +
+ + <![CDATA[Designing helpfulness]]> +

Being there, without being annoying

]]>
+ https://medium.com/@antlam/designing-helpfulness-c1777727faf?source=rss-59f49b9e4b19------2 + https://medium.com/p/c1777727faf + + Tue, 11 Aug 2015 20:59:13 GMT +
+ + <![CDATA[Share to… Firefox?]]> +

You may remember this from such share intents as “Add to Firefox”

]]>
+ https://medium.com/@antlam/share-to-firefox-245984b2da33?source=rss-59f49b9e4b19------2 + https://medium.com/p/245984b2da33 + + Fri, 08 May 2015 20:18:18 GMT +
+ + <![CDATA[Open multiple links]]> +

Queue links in Firefox instead of switching applications each time.

]]>
+ https://medium.com/@antlam/open-multiple-links-1ce475c47de3?source=rss-59f49b9e4b19------2 + https://medium.com/p/1ce475c47de3 + + Tue, 14 Apr 2015 18:44:59 GMT +
+ + <![CDATA[Firefox for Android on Tablets]]> +

Redesigning the browser interface — Part two

]]>
+ https://medium.com/@antlam/firefox-for-android-on-tablets-f67edc83dd46?source=rss-59f49b9e4b19------2 + https://medium.com/p/f67edc83dd46 + + Tue, 03 Feb 2015 20:29:18 GMT +
+ + <![CDATA[Are big phones back?]]> +

Some thoughts and impressions

]]>
+ https://medium.com/@antlam/are-big-phones-back-59550ba0f24e?source=rss-59f49b9e4b19------2 + https://medium.com/p/59550ba0f24e + + Tue, 23 Dec 2014 20:05:36 GMT +
+ + <![CDATA[Firefox for Android looks a bit different]]> +

Redesigning the browser interface

]]>
+ https://medium.com/@antlam/firefox-for-android-looks-a-bit-different-8ae8eba41b1f?source=rss-59f49b9e4b19------2 + https://medium.com/p/8ae8eba41b1f + + Fri, 29 Aug 2014 23:38:07 GMT +
+ + <![CDATA[My fancy new watch]]> +

Early thoughts

]]>
+ https://medium.com/@antlam/my-fancy-new-watch-4856162890a3?source=rss-59f49b9e4b19------2 + https://medium.com/p/4856162890a3 + + Tue, 22 Jul 2014 01:36:52 GMT +
+
\ No newline at end of file diff --git a/mobile/android/tests/background/junit4/resources/feed_rss_spon.xml b/mobile/android/tests/background/junit4/resources/feed_rss_spon.xml new file mode 100644 index 000000000..e5a81d514 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_rss_spon.xml @@ -0,0 +1,314 @@ + + + + SPIEGEL ONLINE - Schlagzeilen + http://www.spiegel.de + Deutschlands fhrende Nachrichtenseite. Alles Wichtige aus Politik, Wirtschaft, Sport, Kultur, Wissenschaft, Technik und mehr. + de + Wed, 27 Jan 2016 18:20:31 +0100 + Wed, 27 Jan 2016 18:20:31 +0100 + + SPIEGEL ONLINE + http://www.spiegel.de + http://www.spiegel.de/static/sys/logo_120x61.gif + + + Angebliche Vergewaltigung einer 13-Jhrigen: Steinmeier kanzelt russischen Minister Lawrow ab + http://www.spiegel.de/politik/ausland/steinmeier-kanzelt-lawrow-ab-aerger-um-angebliche-vergewaltigung-a-1074292.html#ref=rss + Der Ton wird scharf zwischen Berlin und Moskau: Frank-Walter Steinmeier wirft dem russischen Auenminister Lawrow politische Propaganda vor - es geht um die angebliche Vergewaltigung einer 13-Jhrigen in Berlin. + Politik + Wed, 27 Jan 2016 18:16:16 +0100 + http://www.spiegel.de/politik/ausland/steinmeier-kanzelt-lawrow-ab-aerger-um-angebliche-vergewaltigung-a-1074292.html + Der Ton wird scharf zwischen Berlin und Moskau: Frank-Walter Steinmeier wirft dem russischen Auenminister Lawrow politische Propaganda vor - es geht um die angebliche Vergewaltigung einer 13-Jhrigen in Berlin.]]> + + + + Grafischer berblick: Hier gibt es die wenigsten Herzinfarkte in Deutschland + http://www.spiegel.de/gesundheit/diagnose/ostdeutsche-sterben-deutlich-haeufiger-an-einem-herzinfarkt-a-1074231.html#ref=rss + Nirgendwo arbeiten mehr Kardiologen als in Hamburg - auch deshalb gibt es dort weniger Herzinfarkte als in anderen Bundeslndern. Wie sieht es in Ihrer Gegend aus, wo ist die Sterblichkeit am hchsten? Der berblick. + Gesundheit + Wed, 27 Jan 2016 18:08:00 +0100 + http://www.spiegel.de/gesundheit/diagnose/ostdeutsche-sterben-deutlich-haeufiger-an-einem-herzinfarkt-a-1074231.html + Nirgendwo arbeiten mehr Kardiologen als in Hamburg - auch deshalb gibt es dort weniger Herzinfarkte als in anderen Bundeslndern. Wie sieht es in Ihrer Gegend aus, wo ist die Sterblichkeit am hchsten? Der berblick.]]> + + + + Nachhilfe fr gute Schler: Lasst Eure Kinder auch das Scheitern lernen + http://www.spiegel.de/schulspiegel/nachhilfe-entspannte-schueler-brauchen-entspannte-eltern-a-1074197.html#ref=rss + Selbst gute Schler werden von ihren Eltern zur Nachhilfe geschickt. Das schadet mehr, als es ntzt - denn die Kinder lernen dabei vor allem eines: Dass sie nicht scheitern drfen. + SchulSPIEGEL + Wed, 27 Jan 2016 18:02:00 +0100 + http://www.spiegel.de/schulspiegel/nachhilfe-entspannte-schueler-brauchen-entspannte-eltern-a-1074197.html + Selbst gute Schler werden von ihren Eltern zur Nachhilfe geschickt. Das schadet mehr, als es ntzt - denn die Kinder lernen dabei vor allem eines: Dass sie nicht scheitern drfen.]]> + + + + Germanwings-Katastrophe: Arbeitsgruppe regt Schleuse zwischen Kabine und Cockpit an + http://www.spiegel.de/panorama/germanwings-katastrophe-arbeitsgruppe-legt-abschlussbericht-vor-a-1074294.html#ref=rss + Wie sicher muss ein Flugzeugcockpit sein? Nach dem Germanwings-Absturz mit 150 Toten hat sich eine Arbeitsgruppe mit dieser Frage befasst - und nun ihren Abschlussbericht vorgelegt. + Panorama + Wed, 27 Jan 2016 17:52:00 +0100 + http://www.spiegel.de/panorama/germanwings-katastrophe-arbeitsgruppe-legt-abschlussbericht-vor-a-1074294.html + Wie sicher muss ein Flugzeugcockpit sein? Nach dem Germanwings-Absturz mit 150 Toten hat sich eine Arbeitsgruppe mit dieser Frage befasst - und nun ihren Abschlussbericht vorgelegt.]]> + + + + Polen: Hndler wehren sich gegen Supermarktsteuer + http://www.spiegel.de/wirtschaft/soziales/polen-will-internationale-einzelhaendler-hoeher-besteuern-a-1074101.html#ref=rss + Polens Regierung plant, Einzelhndler hher zu besteuern - und will mit den Einnahmen soziale Wohltaten finanzieren. Besonders trifft es auslndische Unternehmen wie Kaufland und Metro. + Wirtschaft + Wed, 27 Jan 2016 17:46:10 +0100 + http://www.spiegel.de/wirtschaft/soziales/polen-will-internationale-einzelhaendler-hoeher-besteuern-a-1074101.html + Polens Regierung plant, Einzelhndler hher zu besteuern - und will mit den Einnahmen soziale Wohltaten finanzieren. Besonders trifft es auslndische Unternehmen wie Kaufland und Metro.]]> + + + + bergriffe in Kln: Polizei erteilt Silvester-Verdchtigen Karnevalverbot + http://www.spiegel.de/panorama/justiz/koeln-polizei-erteilt-silvester-verdaechtigen-verbote-fuer-karneval-a-1074274.html#ref=rss + Klns Polizei bereitet sich auf die Karnevalstage vor: Tatverdchtige aus der Silvesternacht sollen mit Zutrittsverboten von bestimmten Orten ferngehalten werden. Der Polizeiprsident forderte die Narren zudem auf, keine Spielzeugwaffen zu tragen. + Panorama + Wed, 27 Jan 2016 17:23:00 +0100 + http://www.spiegel.de/panorama/justiz/koeln-polizei-erteilt-silvester-verdaechtigen-verbote-fuer-karneval-a-1074274.html + Klns Polizei bereitet sich auf die Karnevalstage vor: Tatverdchtige aus der Silvesternacht sollen mit Zutrittsverboten von bestimmten Orten ferngehalten werden. Der Polizeiprsident forderte die Narren zudem auf, keine Spielzeugwaffen zu tragen.]]> + + + + "The Hateful 8"-Stars im Interview: "Wahnsinn, was da alles passiert!" + http://www.spiegel.de/kultur/kino/the-hateful-8-quentin-tarantino-und-jennifer-jason-leigh-im-interview-a-1074202.html#ref=rss + Sieben Mnner und eine Frau - in seinem Western "The Hateful 8" entwirft Quentin Tarantino ein brutales Abbild der US-Gesellschaft. Hier erklren der Regisseur und seine Hauptdarstellerin, warum es sich lohnt, den Film gleich mehrmals anzusehen. + Kultur + Wed, 27 Jan 2016 17:08:00 +0100 + http://www.spiegel.de/kultur/kino/the-hateful-8-quentin-tarantino-und-jennifer-jason-leigh-im-interview-a-1074202.html + Sieben Mnner und eine Frau - in seinem Western "The Hateful 8" entwirft Quentin Tarantino ein brutales Abbild der US-Gesellschaft. Hier erklren der Regisseur und seine Hauptdarstellerin, warum es sich lohnt, den Film gleich mehrmals anzusehen.]]> + + + + Drama auf zugefrorenem Teich: Baby in akuter Lebensgefahr - Messer gefunden + http://www.spiegel.de/panorama/justiz/hamburg-vater-mit-baby-in-zugefrorenem-teich-eingebrochen-messer-gefunden-a-1074258.html#ref=rss + Der Fall gibt Rtsel auf: In Hamburg wird ein Vater mit seinem Baby aus einem zugefrorenen Teich gerettet - zwei Mnner htten ihn berfallen, sagt der 24-Jhrige. Nun haben Ermittler in der Nhe des Gewssers ein Messer gefunden. + Panorama + Wed, 27 Jan 2016 16:32:00 +0100 + http://www.spiegel.de/panorama/justiz/hamburg-vater-mit-baby-in-zugefrorenem-teich-eingebrochen-messer-gefunden-a-1074258.html + Der Fall gibt Rtsel auf: In Hamburg wird ein Vater mit seinem Baby aus einem zugefrorenen Teich gerettet - zwei Mnner htten ihn berfallen, sagt der 24-Jhrige. Nun haben Ermittler in der Nhe des Gewssers ein Messer gefunden.]]> + + + + Rheinland-Pfalz: Elefantenrunde soll mit sechs Parteien stattfinden + http://www.spiegel.de/politik/deutschland/swr-fernsehdebatte-jetzt-mit-sechs-parteien-a-1074262.html#ref=rss + Erst drei, dann eine, jetzt sechs Parteien: Die TV-Diskussion im Sdwestrundfunk zur rheinland-pflzischen Landtagswahl findet nun in ganz groer Runde statt. + Politik + Wed, 27 Jan 2016 16:29:00 +0100 + http://www.spiegel.de/politik/deutschland/swr-fernsehdebatte-jetzt-mit-sechs-parteien-a-1074262.html + Erst drei, dann eine, jetzt sechs Parteien: Die TV-Diskussion im Sdwestrundfunk zur rheinland-pflzischen Landtagswahl findet nun in ganz groer Runde statt.]]> + + + + Blauer Brief: Britische Schulleiterin mahnt Pyjama-Eltern ab + http://www.spiegel.de/schulspiegel/direktorin-appelliert-an-eltern-bringt-eure-kinder-nicht-im-schlafanzug-zur-schule-a-1074167.html#ref=rss + Rektorin Kate Chisholm hat genug: Stndig beobachtet sie Eltern, die noch im Schlafanzug stecken, wenn sie ihre Kinder an der Schule absetzen. Nun schrieb sie einen Brandbrief, die Elternschaft reagiert gespalten. + SchulSPIEGEL + Wed, 27 Jan 2016 16:26:00 +0100 + http://www.spiegel.de/schulspiegel/direktorin-appelliert-an-eltern-bringt-eure-kinder-nicht-im-schlafanzug-zur-schule-a-1074167.html + + + + Zwischenruf bei Merkel-Besuch: Hochschule verwirft juristische Schritte gegen Str-Professor + http://www.spiegel.de/unispiegel/studium/zwischenruf-bei-merkel-besuch-hochschule-verwirft-juristische-schritte-gegen-professor-a-1074208.html#ref=rss + Seine politische Str-Aktion whrend einer Rede von Kanzlerin Merkel ist fr einen Merseburger Professor glimpflich ausgegangen. Die Hochschule sieht von juristischen Schritten ab. + UniSPIEGEL + Wed, 27 Jan 2016 16:08:00 +0100 + http://www.spiegel.de/unispiegel/studium/zwischenruf-bei-merkel-besuch-hochschule-verwirft-juristische-schritte-gegen-professor-a-1074208.html + Seine politische Str-Aktion whrend einer Rede von Kanzlerin Merkel ist fr einen Merseburger Professor glimpflich ausgegangen. Die Hochschule sieht von juristischen Schritten ab. ]]> + + + + Bundesautobahngesellschaft: Verkehrsminister wehren sich gegen "Mammutbehrde" + http://www.spiegel.de/auto/aktuell/bundesautobahngesellschaft-widerstand-der-verkehrsminister-a-1074198.html#ref=rss + Der Bund knnte die Grndung einer Bundesautobahngesellschaft vorantreiben. Mehrere Verkehrsminister der Lnder stellen sich dagegen - auch aus Furcht vor privaten Investoren beim Fernstraenbau. + Auto + Wed, 27 Jan 2016 15:54:00 +0100 + http://www.spiegel.de/auto/aktuell/bundesautobahngesellschaft-widerstand-der-verkehrsminister-a-1074198.html + Der Bund knnte die Grndung einer Bundesautobahngesellschaft vorantreiben. Mehrere Verkehrsminister der Lnder stellen sich dagegen - auch aus Furcht vor privaten Investoren beim Fernstraenbau. ]]> + + + + Glasfaser-Ausbau: Dobrindt will schnelles Netz unter die Autobahnen legen + http://www.spiegel.de/netzwelt/netzpolitik/alexander-dobrindt-will-schnelles-netz-unter-die-autobahnen-legen-a-1074151.html#ref=rss + Jede Baustelle soll Bandbreite bringen: Die Bundesregierung beschliet, dass knftig beim Straenbau automatisch Glasfaserkabel verlegt werden mssen. Kommt Deutschland so schneller ins Netz? + Netzwelt + Wed, 27 Jan 2016 15:52:00 +0100 + http://www.spiegel.de/netzwelt/netzpolitik/alexander-dobrindt-will-schnelles-netz-unter-die-autobahnen-legen-a-1074151.html + Jede Baustelle soll Bandbreite bringen: Die Bundesregierung beschliet, dass knftig beim Straenbau automatisch Glasfaserkabel verlegt werden mssen. Kommt Deutschland so schneller ins Netz?]]> + + + + Handball-Insolvenz: Flensburg will den HSV verklagen + http://www.spiegel.de/sport/sonst/handball-bundesliga-sg-flensburg-handewitt-klagt-gegen-hsv-a-1074260.html#ref=rss + Einem nackten Mann kann man nicht in die Tasche greifen? Die SG Flensburg-Handewitt will den insolventen HSV Handball verklagen. Der Traditionsverein will Schadenersatz aus Hamburg haben. + Sport + Wed, 27 Jan 2016 15:49:00 +0100 + http://www.spiegel.de/sport/sonst/handball-bundesliga-sg-flensburg-handewitt-klagt-gegen-hsv-a-1074260.html + Einem nackten Mann kann man nicht in die Tasche greifen? Die SG Flensburg-Handewitt will den insolventen HSV Handball verklagen. Der Traditionsverein will Schadenersatz aus Hamburg haben.]]> + + + + Lage am Lageso: Berliner Senatsverwaltung bestreitet Tod eines Flchtlings + http://www.spiegel.de/politik/deutschland/berlin-fluechtling-vom-lageso-tot-senat-widerspricht-a-1074255.html#ref=rss + Ist in Berlin ein syrischer Flchtling gestorben, nachdem er lange vor dem Lageso warten musste? Der Helfer, der darber berichtete, ist abgetaucht - die Senatsverwaltung widerspricht der Darstellung ber den Todesfall. + Politik + Wed, 27 Jan 2016 15:45:00 +0100 + http://www.spiegel.de/politik/deutschland/berlin-fluechtling-vom-lageso-tot-senat-widerspricht-a-1074255.html + Ist in Berlin ein syrischer Flchtling gestorben, nachdem er lange vor dem Lageso warten musste? Der Helfer, der darber berichtete, ist abgetaucht - die Senatsverwaltung widerspricht der Darstellung ber den Todesfall.]]> + + + + Tierarzt-Ikone: Evan Antin, der "heieste Veterinr der Welt" + http://www.spiegel.de/panorama/leute/tierarzt-evan-antin-ist-der-sexiest-veterinaer-ever-laut-people-a-1074229.html#ref=rss + Evan Antin ist Tierarzt, Model und Personal Trainer. So irritierend gutaussehend, dass er zum "Sexiest Tierbetrer" avancierte. Trotz seiner Vorliebe fr blutiges Gedrm und anatomische Anomalien. + Panorama + Wed, 27 Jan 2016 15:31:00 +0100 + http://www.spiegel.de/panorama/leute/tierarzt-evan-antin-ist-der-sexiest-veterinaer-ever-laut-people-a-1074229.html + + + + Verteidigungshaushalt: Schuble will mehr Geld fr Bundeswehr ausgeben + http://www.spiegel.de/politik/deutschland/wolfgang-schaeuble-einverstanden-mit-mehr-geld-fuer-ruestung-a-1074242.html#ref=rss + Drei Milliarden Euro mehr pro Jahr fr Waffen: Finanzminister Schuble sieht die Aufrstungsplne der Verteidigungsministerin von der Leyen positiv. + Politik + Wed, 27 Jan 2016 15:29:00 +0100 + http://www.spiegel.de/politik/deutschland/wolfgang-schaeuble-einverstanden-mit-mehr-geld-fuer-ruestung-a-1074242.html + Drei Milliarden Euro mehr pro Jahr fr Waffen: Finanzminister Schuble sieht die Aufrstungsplne der Verteidigungsministerin von der Leyen positiv.]]> + + + + Doping-Vorwrfe: NFL leitet Untersuchung gegen Manning ein + http://www.spiegel.de/sport/sonst/nfl-peyton-manning-unter-doping-verdacht-a-1074230.html#ref=rss + Die NFL prft Vorwrfe gegen einen Superstar: Die Football-Liga geht jetzt offiziell den Doping-Gerchten um Peyton Manning nach. Der Quarterback soll ber seine Frau Hormone geordert haben. + Sport + Wed, 27 Jan 2016 15:23:00 +0100 + http://www.spiegel.de/sport/sonst/nfl-peyton-manning-unter-doping-verdacht-a-1074230.html + Die NFL prft Vorwrfe gegen einen Superstar: Die Football-Liga geht jetzt offiziell den Doping-Gerchten um Peyton Manning nach. Der Quarterback soll ber seine Frau Hormone geordert haben.]]> + + + + Posse um SWR-Elefantenrunde: Feigheit vor dem Feind + http://www.spiegel.de/politik/deutschland/spd-und-swr-posse-um-tv-auftritt-in-rheinland-pfalz-kommentar-a-1074235.html#ref=rss + Die Sozialdemokraten weigern sich, an einer TV-Debatte mit der AfD teilzunehmen, jetzt geht das Spektakel in eine neue Runde. Statt der Ministerprsidentin soll der SPD-Landeschef ran. Wie absurd ist das denn? + Politik + Wed, 27 Jan 2016 15:23:00 +0100 + http://www.spiegel.de/politik/deutschland/spd-und-swr-posse-um-tv-auftritt-in-rheinland-pfalz-kommentar-a-1074235.html + Die Sozialdemokraten weigern sich, an einer TV-Debatte mit der AfD teilzunehmen, jetzt geht das Spektakel in eine neue Runde. Statt der Ministerprsidentin soll der SPD-Landeschef ran. Wie absurd ist das denn? ]]> + + + + Apple-Browser: Und pltzlich strzt Safari ab + http://www.spiegel.de/netzwelt/apps/apple-safari-browser-stuerzt-ploetzlich-ab-a-1074217.html#ref=rss + Seit einigen Stunden haben Apple-Nutzer Probleme mit dem Safari-Browser. Wodurch die Abstrze ausgelst werden, ist unklar. Doch mit einem kleinen Trick kann man sich helfen. + Netzwelt + Wed, 27 Jan 2016 15:18:00 +0100 + http://www.spiegel.de/netzwelt/apps/apple-safari-browser-stuerzt-ploetzlich-ab-a-1074217.html + Seit einigen Stunden haben Apple-Nutzer Probleme mit dem Safari-Browser. Wodurch die Abstrze ausgelst werden, ist unklar. Doch mit einem kleinen Trick kann man sich helfen.]]> + + + + EU-Bericht zu Grenzsicherung: Griechenland droht Schengen-Rauswurf + http://www.spiegel.de/politik/ausland/griechenland-eu-kommission-droht-mit-schengen-rauswurf-a-1074201.html#ref=rss + Griechenland gert in der Flchtlingskrise unter massiven Druck der EU: Die Kommission will Athen Forderungen zum Grenzschutz schicken. Werden die nicht binnen drei Monaten erfllt, droht der Ausschluss aus dem Schengen-Raum. + Politik + Wed, 27 Jan 2016 15:04:00 +0100 + http://www.spiegel.de/politik/ausland/griechenland-eu-kommission-droht-mit-schengen-rauswurf-a-1074201.html + Griechenland gert in der Flchtlingskrise unter massiven Druck der EU: Die Kommission will Athen Forderungen zum Grenzschutz schicken. Werden die nicht binnen drei Monaten erfllt, droht der Ausschluss aus dem Schengen-Raum.]]> + + + + Protest gegen dnisches Asylrecht: Ai Weiwei schliet Ausstellung in Kopenhagen + http://www.spiegel.de/kultur/gesellschaft/protest-gegen-daenisches-asylrecht-ai-weiwei-schliesst-ausstellung-a-1074241.html#ref=rss + Ai Weiwei, Chinas wohl bekanntester Knstler, beendet seine Ausstellung in Kopenhagen vorzeitig. Grund ist eine Verschrfung der Asylregeln in Dnemark. + Kultur + Wed, 27 Jan 2016 15:01:00 +0100 + http://www.spiegel.de/kultur/gesellschaft/protest-gegen-daenisches-asylrecht-ai-weiwei-schliesst-ausstellung-a-1074241.html + Ai Weiwei, Chinas wohl bekanntester Knstler, beendet seine Ausstellung in Kopenhagen vorzeitig. Grund ist eine Verschrfung der Asylregeln in Dnemark.]]> + + + + Deutsche Handballer gegen Dnemark: Jetzt muss es schmutzig werden + http://www.spiegel.de/sport/sonst/handball-em-2016-jetzt-muss-es-schmutzig-werden-a-1074123.html#ref=rss + Noch ein Sieg bis zum Halbfinale: Die deutsche Handball-Nationalmannschaft hat bei der EM einen Lauf, sie ist gierig auf den Titel. Jetzt geht es gegen einen groen Favoriten - und Dnemark wirkt angeschlagen. + Sport + Wed, 27 Jan 2016 14:59:00 +0100 + http://www.spiegel.de/sport/sonst/handball-em-2016-jetzt-muss-es-schmutzig-werden-a-1074123.html + Noch ein Sieg bis zum Halbfinale: Die deutsche Handball-Nationalmannschaft hat bei der EM einen Lauf, sie ist gierig auf den Titel. Jetzt geht es gegen einen groen Favoriten - und Dnemark wirkt angeschlagen. ]]> + + + + Sicherheitslage nach Anschlag: Russland spricht Reisewarnung fr Trkei aus + http://www.spiegel.de/reise/aktuell/russland-spricht-reisewarnung-fuer-tuerkei-aus-a-1074225.html#ref=rss + Die russische Regierung warnt ihre Brger vor Reisen in die Trkei. Damit schrnkt sie den Tourismus in das Land weiter ein. Nach dem Anschlag in Istanbul sind auch die Buchungen von deutschen Urlaubern eingebrochen. + Reise + Wed, 27 Jan 2016 14:58:00 +0100 + http://www.spiegel.de/reise/aktuell/russland-spricht-reisewarnung-fuer-tuerkei-aus-a-1074225.html + Die russische Regierung warnt ihre Brger vor Reisen in die Trkei. Damit schrnkt sie den Tourismus in das Land weiter ein. Nach dem Anschlag in Istanbul sind auch die Buchungen von deutschen Urlaubern eingebrochen.]]> + + + + Bayern-Deal mit Katar: Scheich Di! + http://www.spiegel.de/sport/fussball/fc-bayern-muenchen-und-der-katar-deal-in-der-pflicht-kommentar-a-1074187.html#ref=rss + Der FC Bayern schliet einen Sponsoren-Deal mit Katar ab, die Kritik darber ist ebenso berechtigt wie vorhersehbar. Dabei darf es nicht bleiben. Nehmen wir den Rekordmeister doch beim Wort. + Sport + Wed, 27 Jan 2016 14:52:00 +0100 + http://www.spiegel.de/sport/fussball/fc-bayern-muenchen-und-der-katar-deal-in-der-pflicht-kommentar-a-1074187.html + Der FC Bayern schliet einen Sponsoren-Deal mit Katar ab, die Kritik darber ist ebenso berechtigt wie vorhersehbar. Dabei darf es nicht bleiben. Nehmen wir den Rekordmeister doch beim Wort.]]> + + + + Flchtlingskrise: EU wirft Griechenland schwere Mngel bei Grenzkontrolle vor + http://www.spiegel.de/politik/ausland/fluechtlinge-eu-wirft-griechenland-maengel-bei-grenzkontrolle-vor-a-1074219.html#ref=rss + Die griechische Regierung verletzt ihre Pflichten bei der Grenzsicherung - zu diesem Schluss kommt ein Untersuchungsbericht der EU-Kommission. Brssel spricht nun eine klare Drohung gegen Athen aus. + Politik + Wed, 27 Jan 2016 14:47:00 +0100 + http://www.spiegel.de/politik/ausland/fluechtlinge-eu-wirft-griechenland-maengel-bei-grenzkontrolle-vor-a-1074219.html + Die griechische Regierung verletzt ihre Pflichten bei der Grenzsicherung - zu diesem Schluss kommt ein Untersuchungsbericht der EU-Kommission. Brssel spricht nun eine klare Drohung gegen Athen aus.]]> + + + + Abgasaffre: Brssel will Autokonzerne bestrafen knnen + http://www.spiegel.de/wirtschaft/soziales/abgasaffaere-bruessel-will-autokonzerne-bestrafen-koennen-a-1074228.html#ref=rss + Im Abgas-Skandal ist der VW-Konzern Schuldiger - aber auch die Aufseher in Brssel sind blamiert. Denn US-Behrden enthllten, was ihnen jahrelang durch die Lappen ging. Die EU-Kommission will jetzt dafr sorgen, dass sich das nicht wiederholt. + Wirtschaft + Wed, 27 Jan 2016 14:46:00 +0100 + http://www.spiegel.de/wirtschaft/soziales/abgasaffaere-bruessel-will-autokonzerne-bestrafen-koennen-a-1074228.html + Im Abgas-Skandal ist der VW-Konzern Schuldiger - aber auch die Aufseher in Brssel sind blamiert. Denn US-Behrden enthllten, was ihnen jahrelang durch die Lappen ging. Die EU-Kommission will jetzt dafr sorgen, dass sich das nicht wiederholt.]]> + + + + Bundesverfassungsgericht: Wer alles gegen die Vorratsdatenspeicherung klagt + http://www.spiegel.de/netzwelt/netzpolitik/vorratsdatenspeicherung-wer-klagt-vor-dem-bundesverfassungsgericht-a-1074152.html#ref=rss + Widerstand gegen Vorratsdatenspeicherung: Die FDP hat Klage in Karlsruhe eingereicht, und auch weitere Gegner versuchen, das Gesetz vor Gericht noch zu kippen. Der berblick. + Netzwelt + Wed, 27 Jan 2016 14:42:00 +0100 + http://www.spiegel.de/netzwelt/netzpolitik/vorratsdatenspeicherung-wer-klagt-vor-dem-bundesverfassungsgericht-a-1074152.html + Widerstand gegen Vorratsdatenspeicherung: Die FDP hat Klage in Karlsruhe eingereicht, und auch weitere Gegner versuchen, das Gesetz vor Gericht noch zu kippen. Der berblick. ]]> + + + + Berliner Flchtlingsamt: Das Scheitern des Lageso - das Protokoll + http://www.spiegel.de/politik/deutschland/berlin-das-scheitern-des-lageso-eine-chronik-a-1074186.html#ref=rss + Tagelanges Warten, keine Auszahlung von Essensgeld, Gewalt - jetzt angeblich ein Toter: Seit Monaten steht das Berliner Flchtlingsamt Lageso in den Schlagzeilen. Die Chronologie des Scheiterns. + Politik + Wed, 27 Jan 2016 14:22:00 +0100 + http://www.spiegel.de/politik/deutschland/berlin-das-scheitern-des-lageso-eine-chronik-a-1074186.html + Tagelanges Warten, keine Auszahlung von Essensgeld, Gewalt - jetzt angeblich ein Toter: Seit Monaten steht das Berliner Flchtlingsamt Lageso in den Schlagzeilen. Die Chronologie des Scheiterns. ]]> + + + + Apple-Gerchte: So knnte das neue iPhone aussehen. Aber was wnschen Sie sich? + http://www.spiegel.de/netzwelt/gadgets/apple-so-gut-muss-das-iphone-7-sein-a-1074158.html#ref=rss + Ist der iPhone-Boom vorbei? Nicht unbedingt - das nchste Gert knnte starke neue Features haben. Hier der Stand der Gerchte. Und Sie knnen abstimmen: Was brauchen Sie wirklich? + Netzwelt + Wed, 27 Jan 2016 14:17:00 +0100 + http://www.spiegel.de/netzwelt/gadgets/apple-so-gut-muss-das-iphone-7-sein-a-1074158.html + Ist der iPhone-Boom vorbei? Nicht unbedingt - das nchste Gert knnte starke neue Features haben. Hier der Stand der Gerchte. Und Sie knnen abstimmen: Was brauchen Sie wirklich?]]> + + + + \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/resources/feed_rss_tumblr.xml b/mobile/android/tests/background/junit4/resources/feed_rss_tumblr.xml new file mode 100644 index 000000000..15b20b652 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_rss_tumblr.xml @@ -0,0 +1,95 @@ + +Your reliable source for up-to-the-minute commodities pricing.Tumblr StaffTumblr (3.0; @staff)http://staff.tumblr.com/hardyboyscovers: + + Can Nancy Drew see things through and solve...<img src="http://41.media.tumblr.com/6dcceee090b2eef840cf694b205e1551/tumblr_o0r7mqDr5P1ug9yhzo1_400.jpg"/><br/><br/><p><a class="tumblr_blog" href="http://hardyboyscovers.tumblr.com/post/137036714181">hardyboyscovers</a>:</p> + <blockquote> + <p>Can Nancy Drew see things through and solve the case?<br/><br/></p> + </blockquote> + + <p>Please horse, no</p>http://staff.tumblr.com/post/138124026275http://staff.tumblr.com/post/138124026275Tue, 26 Jan 2016 21:30:12 -0500good blogbad horsebook coversbook cover weekChasing Storms at 17,500mph<p><a class="tumblr_blog" href="http://stationcdrkelly.tumblr.com/post/138047038357">stationcdrkelly</a>:</p> + <blockquote> + <p>Flying 250 miles above the Earth aboard the International Space Station has given me the unique vantage point from which to view our planet. Spending a year in space has given me the unique opportunity to see a wide range of spectacular storm systems in space and on Earth. <br/></p> + <p>The recent blizzard was remarkably visible from space. I took several photos of the first big storm system on Earth of year 2016 as it moved across the East Coast, Chicago and Washington D.C. Since my time here on the space station began in March 2015, I’ve been able to capture an array of storms on Earth and in space, ranging from hurricanes and dust storms to solar storms and most recently a rare thunder snowstorm. </p> + <figure class="tmblr-full" data-orig-height="1065" data-orig-width="1600"><img src="http://41.media.tumblr.com/ba62a8f18ceef5a20f60b700d14b39fe/tumblr_inline_o1hmtucs6o1tmec5e_540.jpg" data-orig-height="1065" data-orig-width="1600"/></figure><p>Blizzard 2016</p> + <figure class="tmblr-full" data-orig-height="1065" data-orig-width="1600"><img src="http://40.media.tumblr.com/371eedcc0adf48ed07c5d1bd3f326ef1/tumblr_inline_o1hmuyAVw01tmec5e_540.jpg" data-orig-height="1065" data-orig-width="1600"/></figure><p>Hurricane Patricia 2015</p> + <figure class="tmblr-full" data-orig-height="1065" data-orig-width="1600"><img src="http://40.media.tumblr.com/07cc92970eea9607b20264f589a94f59/tumblr_inline_o1hmwd9dIE1tmec5e_540.jpg" data-orig-height="1065" data-orig-width="1600"/></figure><p>Hurricane Joaquin 2015</p> + <figure class="tmblr-full" data-orig-height="682" data-orig-width="1024"><img src="http://41.media.tumblr.com/ee5232cbf15d24b23932e0af0384f922/tumblr_inline_o1hmyeCO2I1tmec5e_540.jpg" data-orig-height="682" data-orig-width="1024"/></figure><p>Dust Storm in the Red Sea 2015</p> + <figure class="tmblr-full" data-orig-height="1065" data-orig-width="1600"><img src="http://41.media.tumblr.com/e1c72c1a9be6394db409f0ffd0db31f8/tumblr_inline_o1hmzrMkBF1tmec5e_540.jpg" data-orig-height="1065" data-orig-width="1600"/></figure><p>Dust Storm of Gobi Desert 2015</p> + <figure class="tmblr-full" data-orig-height="1065" data-orig-width="1600"><img src="http://40.media.tumblr.com/aa3a6d80dc603a9cc2cd5ceeb528ca55/tumblr_inline_o1hn1cI5xt1tmec5e_540.jpg" data-orig-height="1065" data-orig-width="1600"/></figure><p>Aurora Solar Storm 2015</p> + <figure class="tmblr-full" data-orig-height="1065" data-orig-width="1600"><img src="http://40.media.tumblr.com/6d5c5715f629aa0a37908cc7ddc9e9a4/tumblr_inline_o1hn2ewElf1tmec5e_540.jpg" data-orig-height="1065" data-orig-width="1600"/></figure><p>Aurora Solar Storm 2016</p> + <figure class="tmblr-full" data-orig-height="1065" data-orig-width="1600"><img src="http://41.media.tumblr.com/ec251e592ad4132c3141d3289344f6b0/tumblr_inline_o1hn7eMqGD1tmec5e_540.jpg" data-orig-height="1065" data-orig-width="1600"/></figure><p>Thunderstorm over Italy 2015</p> + <figure class="tmblr-full" data-orig-height="1067" data-orig-width="1600"><img src="http://36.media.tumblr.com/d15b6033547c0e5c465a35614cdd753e/tumblr_inline_o1hnaxgi6r1tmec5e_540.jpg" data-orig-height="1067" data-orig-width="1600"/></figure><p>Lightning and Aurora 2016</p> + <figure class="tmblr-full" data-orig-height="1065" data-orig-width="1600"><img src="http://36.media.tumblr.com/96f14b994bba66b9f690a6e086657333/tumblr_inline_o1hnc4GTCi1tmec5e_540.jpg" data-orig-height="1065" data-orig-width="1600"/></figure><p>Rare Thunder Snowstorm 2016</p> + <p>Follow my Year In Space on Twitter, Facebook and Instagram. </p> + </blockquote> + + <p>Astronaut Scott Kelly just signed up for Tumblr all the way from space. <i>Outer</i> space. So far, this the coolest weather blog of all time. </p>http://staff.tumblr.com/post/138053124065http://staff.tumblr.com/post/138053124065Mon, 25 Jan 2016 19:48:40 -0500digg: + + first it starts out like a little spinning hexagonthen it spins more and gets biggermore...<p><a href="http://digg.tumblr.com/post/137842908963/first-it-starts-out-like-a-little-spinning-hexagon" class="tumblr_blog">digg</a>:</p> + + <blockquote><figure data-orig-width="473" data-orig-height="52" class="tmblr-full"><img src="http://40.media.tumblr.com/0ec3a49eb7143dc50e7d3a7252bb707f/tumblr_inline_o1dnci9q4j1ro8h5m_540.png" data-orig-width="473" data-orig-height="52"/></figure><p><br/>first it starts out like a little spinning hexagon</p><figure data-orig-width="400" data-orig-height="396" class="tmblr-full"><img src="http://38.media.tumblr.com/fb369bd707e311591f85de1d10b94bc6/tumblr_inline_o1dnbpkqXI1ro8h5m_500.gif" data-orig-width="400" data-orig-height="396"/></figure><p>then it spins more and gets bigger<br/></p><figure data-orig-width="400" data-orig-height="396" class="tmblr-full"><img src="http://33.media.tumblr.com/5d5e6abd203bda735f5b798bd7d100cb/tumblr_inline_o1dnbnbv6r1ro8h5m_500.gif" data-orig-width="400" data-orig-height="396"/></figure><p>more spinning, the background gets red</p><figure data-orig-width="400" data-orig-height="396" class="tmblr-full"><img src="http://38.media.tumblr.com/7b11f8f9abec6211440880cee0c94a89/tumblr_inline_o1dnbnn1IM1ro8h5m_500.gif" data-orig-width="400" data-orig-height="396"/></figure><p>then it goes all over your driveway like this</p><figure class="tmblr-full" data-orig-height="225" data-orig-width="400"><img src="http://38.media.tumblr.com/6e3d06c9a97f3acc05c20d2e37f3f730/tumblr_inline_o1dney205v1ro8h5m_500.gif" data-orig-height="225" data-orig-width="400"/></figure></blockquote>http://staff.tumblr.com/post/137845368600http://staff.tumblr.com/post/137845368600Fri, 22 Jan 2016 19:47:00 -0500have a good weekend tumblrstay safe stay beautifulThis week in drama clubHigh School Musical: Bopped to the top 10...<img src="http://40.media.tumblr.com/9c69a850eece63c29d913b6e83dd49a7/tumblr_o1dcfztyzk1qz8q0ho1_500.png"/><br/><br/><h2>This week in drama club</h2><ul><li><b><a href="http://tumblr.com/search/golden%20disk%20awards"></a></b><a href="http://tumblr.com/search/hsm"><i><b>High School Musical</b></i></a>: Bopped to the top 10 years ago this week.<br/></li><li><a href="http://tumblr.com/search/golden%20disk%20awards"><i><b>Golden Disk Awards</b></i></a>: Baked to perfection. Thanks, Zeke!<br/></li><li><a href="http://tumblr.com/search/miraculous%20ladybug"><b><i>Miraculous Ladybug</i></b></a>: The Gabriella to Cat Noir’s Troy.<br/></li><li><a href="http://tumblr.com/search/agent%20carter"><b><i>Agent Carter</i></b></a>: The start of something new (season two).<br/></li></ul><figure data-orig-width="160" data-orig-height="180" data-tumblr-attribution="hunting-the-grievers:cPVhQbqjjwjt3Hpa2i0A3Q:ZDFbbm1f4dbEu" class="tmblr-full"><img src="http://38.media.tumblr.com/d6c281341a84fd1367682d598b008af9/tumblr_nkrg1eqpXu1tl1wyoo1_250.gif" alt="image" data-orig-width="160" data-orig-height="180"/></figure><h2>Student government elections</h2><ul><li><a href="http://tumblr.com/search/sarah%20palin"><b>Sarah Palin</b></a>: Song singin’, bitter clingin’, proud clingers of West Side Knights.<br/></li><li><a href="http://tumblr.com/search/democratic%20debate"><b>Democratic debate</b></a>: A political decathlon.</li></ul><h2>Wildcat co-captains</h2><ul><li><a href="http://tumblr.com/search/matt%20the%20radar%20technician"><b>Matt the Radar Technician</b></a>: Secretly Coach Bolton.<br/></li><li><a href="http://tumblr.com/search/jada%20pinkett%20smith"><b>Jada Pinkett Smith</b></a>: Owns more hats than Ryan Evans.<br/></li></ul><figure data-orig-width="480" data-orig-height="270" data-tumblr-attribution="nbcsnl:B-Wm_cenWtc03w62FRwf1A:ZpdRYu201JEGk" class="tmblr-full"><img src="http://31.media.tumblr.com/acd5b9d1d6ef051d12fabbedeb1bc023/tumblr_o13140hUBg1rdzuduo1_500.gif" alt="image" data-orig-width="480" data-orig-height="270"/></figure><h2>Get’cha head in the game</h2><ul><li><a href="http://tumblr.com/search/wwe"><b>WWE</b></a>: We’re all in this Royal Rumble together.<br/></li><li><a href="http://tumblr.com/search/australian%20open"><b>Australian Open</b></a>: Go Wildcats!<br/></li></ul><h2>Sticking to the status quo: Check out these Tumblrs</h2><ul><li><b>Creative Capital</b> (<a href="http://tmblr.co/mcSeD8C3uF_aHrmt0C6VpUw">@creative-cap</a>): Patron of the arts.<br/></li><li><b>Broadway Con</b> (<a href="http://tmblr.co/miT9FBjVCw7YfioPNppjryw">@bwaycon</a>): What you’ve been looking for.<br/></li><li><b>Mall Goth Phase</b> (<a href="http://tmblr.co/mUHclMBjOwpJBi4M1bucs5Q">@mallgothphase</a>): Hot, topical blog.<br/></li></ul><figure data-orig-width="367" data-orig-height="245" data-tumblr-attribution="wrestling-giffer:V0IfEVup_dIDxzIYMr5R0A:Z1UX8r1yd0krY" class="tmblr-full"><img src="http://38.media.tumblr.com/5685bb235ec944c5084939da16c24958/tumblr_ny9xzoSQ5K1sbzhteo1_400.gif" alt="image" data-orig-width="367" data-orig-height="245"/></figure>http://staff.tumblr.com/post/137833222680http://staff.tumblr.com/post/137833222680Fri, 22 Jan 2016 16:07:26 -0500trendsnationwideexposure: + + I’M CRYING...<img src="http://40.media.tumblr.com/7ba6d036bd5939f087f8feee424dc337/tumblr_n1aawcsEOd1rr31p0o1_400.jpg"/><br/> <br/><img src="http://41.media.tumblr.com/8bfce3018cf868734dc73f11c9c84cce/tumblr_n1aawcsEOd1rr31p0o2_500.jpg"/><br/> <br/><img src="http://41.media.tumblr.com/68275fc41a5879e03f6b67401d21b9c6/tumblr_n1aawcsEOd1rr31p0o3_500.jpg"/><br/> <br/><img src="http://40.media.tumblr.com/4d987c36b13dc78ec66d9f7311f23ed8/tumblr_n1aawcsEOd1rr31p0o4_500.jpg"/><br/> <br/><img src="http://40.media.tumblr.com/052fb3ff421e40865f517b60e7a00af4/tumblr_n1aawcsEOd1rr31p0o5_500.jpg"/><br/> <br/><img src="http://40.media.tumblr.com/b4d65c50fed46518eef6091575171247/tumblr_n1aawcsEOd1rr31p0o6_250.jpg"/><br/> <br/><img src="http://41.media.tumblr.com/e989c0771b588d4b8e4068caa71c7764/tumblr_n1aawcsEOd1rr31p0o7_500.jpg"/><br/> <br/><img src="http://41.media.tumblr.com/3a9ca6beb713678743987b830ce2a5a6/tumblr_n1aawcsEOd1rr31p0o8_500.jpg"/><br/> <br/><img src="http://41.media.tumblr.com/72daba4a9a2598dcbc18f6d5b7c1ecaa/tumblr_n1aawcsEOd1rr31p0o9_500.jpg"/><br/> <br/><img src="http://40.media.tumblr.com/a9db431bf354b42fd035d44c9910bfe6/tumblr_n1aawcsEOd1rr31p0o10_500.jpg"/><br/> <br/><p><a class="tumblr_blog" href="http://nationwideexposure.tumblr.com/post/77260363328">nationwideexposure</a>:</p> + <blockquote> + <p>I’M CRYING 😂😭😂😭😂</p> + </blockquote> + <p>——<br/>——<br/>——<br/>——</p><p> 👀<br/>——<br/>——<br/>——<br/>——</p>http://staff.tumblr.com/post/137788176890http://staff.tumblr.com/post/137788176890Thu, 21 Jan 2016 22:00:16 -0500stock photostock photo weekrisingfunk: + + hey creationists, + if evolution isn’t real… explain...<img src="http://41.media.tumblr.com/9dd0ed0e50f1963930b55002f22d2569/tumblr_njt97mInHy1rz419eo3_500.jpg"/><br/> <br/><img src="http://41.media.tumblr.com/39362963e0d3bab55f84c7b9e7acc1b1/tumblr_njt97mInHy1rz419eo4_500.jpg"/><br/> <br/><img src="http://36.media.tumblr.com/f2e4d58b37bebdd48c0593b66c2fa910/tumblr_njt97mInHy1rz419eo2_500.jpg"/><br/> <br/><img src="http://40.media.tumblr.com/0e0fb52c15c625d46ee1fa108c102e41/tumblr_njt97mInHy1rz419eo1_500.jpg"/><br/> <br/><p><a class="tumblr_blog" href="http://risingfunk.tumblr.com/post/111068384527">risingfunk</a>:</p> + <blockquote> + <p>hey creationists,</p> + <p>if evolution isn’t real… explain <b>THIS</b><br/></p> + </blockquote> + + <p>We’d like anyone to explain this.</p>http://staff.tumblr.com/post/137724564137http://staff.tumblr.com/post/137724564137Wed, 20 Jan 2016 22:00:29 -0500stock photostock photo weekI’ll Be There For You (Theme from…)<p><a class="tumblr_blog" href="http://thefandometrics.tumblr.com/post/137713318764">thefandometrics</a>:</p> + <blockquote> + <p><figure class="tmblr-full" data-orig-height="100" data-orig-width="500"><img src="http://36.media.tumblr.com/b528045dbfddacd8dcb1789ae1aabad8/tumblr_inline_o19xl51Nx51qz7tc0_540.png" data-orig-height="100" data-orig-width="500"/></figure></p><h2> + <a href="http://thefandometrics.tumblr.com/post/137583618255/tv-shows-week-ending-january-18th-2016-steven">Television</a>: So no one told you life was gonna be this way.</h2> + <blockquote><p>☆ <b><i><a href="https://www.tumblr.com/search/Saturday+Night+Live">Saturday Night Live</a></i></b> returns to No. 11 with a little help from Kyl–uh, Matt the Radar Technician.<br/> ⬆ <b><i><a href="https://www.tumblr.com/search/Pretty%20Little%20Liars">Pretty Little Liars</a></i></b> (No. 7) jumped five years in the future and eleven spots on our list.<br/>☆ <b><i><a href="https://www.tumblr.com/search/Rick%20and%20Morty">Rick and Morty</a></i></b> came back at a solid No. 18 while all of you played <i>Pocket Mortys</i>. </p></blockquote> + <figure class="tmblr-full" data-orig-height="271" data-orig-width="480" data-tumblr-attribution="ren-rey-lo:3VGJxt125Qzd9mCpO3SEBg:ZZ1ZMi202CMhl"><img src="http://38.media.tumblr.com/fd91b6634cfd45862f50b955a4dcecd6/tumblr_o13kbrUuy51v4pr6ko4_500.gif" data-orig-height="271" data-orig-width="480"/></figure><h2> + <a href="http://thefandometrics.tumblr.com/post/137583047944/movies-week-ending-january-18th-2016-star-wars">Movies</a>: 👏👏👏👏.</h2> + <blockquote><p>⬆ <b><i><a href="https://www.tumblr.com/search/Deadpool">Deadpool</a></i></b>’s (No. 2) <a href="http://www.herochan.com/post/137155502690/deadpool-movie-promotion-done-right">marketing</a> team deserves a raise. <br/>☆ <b><i><a href="https://www.tumblr.com/search/Labyrinth">Labyrinth</a></i></b> debuted at No. 6. All hail The Goblin King. </p></blockquote> + <h2> + <a href="http://thefandometrics.tumblr.com/post/137582487533/musical-acts-week-ending-january-18th-2016-david">Music</a>: Your life’s a joke, you’re broke.</h2> + <blockquote><p>☆ <b><a href="https://www.tumblr.com/search/David%20Bowie">David Bowie</a></b> is No. 1, as he should be.<br/>⬆ <b><a href="https://www.tumblr.com/search/Panic%20at%20the%20Disco">Panic! at the Disco</a></b> did the hustle up to No. 4.</p></blockquote> + <h2> + <a href="http://thefandometrics.tumblr.com/post/137581921455/celebrities-week-ending-january-18th-2016-alan">Celebrities</a>: Your love life’s D.O.A.</h2> + <blockquote><p>☆ <b><a href="https://www.tumblr.com/search/Alan%20Rickman">Alan Rickman</a></b> is No. 1, as he should be.<br/> ⬆ <b><a href="https://www.tumblr.com/search/Leonardo%20DiCaprio">Leonardo DiCaprio</a></b> continues his climb, moves up to No. 5. A true revenant.<br/> ☆ <b><a href="https://www.tumblr.com/search/Gillian%20Anderson">Gillian Anderson</a></b> debuted at No. 14. We want to believe in the reboot. </p></blockquote> + <figure class="tmblr-full" data-orig-height="211" data-orig-width="500" data-tumblr-attribution="szabcsiify:6F9QwBM8is-j-q9KKvjFOQ:Z5xAar1qg38kJ"><img src="http://33.media.tumblr.com/ea080946a865dd802c098792fc303649/tumblr_ns7chfYxeU1sxov47o1_500.gif" data-orig-height="211" data-orig-width="500"/></figure><h2> + <a href="http://thefandometrics.tumblr.com/post/137581349025/video-games-week-ending-january-18th-2016">Games</a>: It’s like you’re always stuck in second gear. </h2> + <blockquote><p>⬆ <b><i><a href="https://www.tumblr.com/search/Pok%C3%A9mon">Pokémon</a></i></b> (No. 2) is twenty years old. Like, human earth years. Twenty of them.<br/> ⬆ <b><i><a href="https://www.tumblr.com/search/Splatoon">Splatoon</a></i></b>’s Splatfest was an inky success, propelling it to No. 10.</p></blockquote> + <h2> + <a href="http://thefandometrics.tumblr.com/post/137580830792/web-stuff-week-ending-january-18th-2016">Web stuff</a>: When it hasn’t been your day, your week, your month, or even your year.</h2> + <blockquote><p>⬆ Vlogging savant <b><a href="https://www.tumblr.com/search/Troye%20Sivan">Troye Sivan</a></b> moves up to No. 4.<br/> ⬇︎ Story time! <b><a href="https://www.tumblr.com/search/Thomas%20Sanders">Thomas Sanders</a></b> fell seven spots to No. 19.</p></blockquote> + </blockquote>http://staff.tumblr.com/post/137714050360http://staff.tumblr.com/post/137714050360Wed, 20 Jan 2016 18:42:44 -0500week in reviewPhoto<img src="http://36.media.tumblr.com/9886e52dcd701c004da445cecd89e7a7/tumblr_ne2u5i2aWI1sq05vko1_400.png"/><br/><br/>http://staff.tumblr.com/post/137656822367http://staff.tumblr.com/post/137656822367Tue, 19 Jan 2016 21:00:09 -0500stockstock photo weekbusinessingbusinessvedranmisic: + + Happy Birthday, Dr. Martin Luther King Jr.“I HAVE...<img src="http://40.media.tumblr.com/01e16942f7f596872c5e7d73d41f989b/tumblr_o0z9nswYMm1re26ajo1_500.jpg"/><br/><br/><p><a href="http://vedranmisic.tumblr.com/post/137328304708/happy-birthday-dr-martin-luther-king-jr-i-have" class="tumblr_blog">vedranmisic</a>:</p> + + <blockquote><p>Happy Birthday, Dr. Martin Luther King Jr.<br/>“I HAVE A DREAM” (ink on paper, 11x14 inches)<br/></p></blockquote>http://staff.tumblr.com/post/137556640935http://staff.tumblr.com/post/137556640935Mon, 18 Jan 2016 11:20:27 -0500martin luther king jrfruitsoftheweb: + + Elastic and non-linear plastic effects are...<img src="http://45.media.tumblr.com/525d91fe69a7815bc84438e4dab4e8e0/tumblr_n7lvudTrkx1skn1oxo1_400.gif"/><br/><br/><p><a class="tumblr_blog" href="http://fruitsoftheweb.tumblr.com/post/89724820207">fruitsoftheweb</a>:</p> + <blockquote> + <p class="p1"><a href="https://www.youtube.com/watch?v=1Q_zb65SXt0"><em>Elastic and non-linear plastic effects are obtained by adding springs with varying rest length between particles.</em></a></p> + </blockquote> + + <p>You can dress this description up any way you want, but this here link is a video about straight-up slime.</p>http://staff.tumblr.com/post/137382144100http://staff.tumblr.com/post/137382144100Fri, 15 Jan 2016 21:00:30 -0500slimeslime weekVideo + <video id='embed-56a8a4909ac31729864247' class='crt-video crt-skin-default' width='400' height='225' poster='http://media.tumblr.com/tumblr_o10q0s4lQw1qz8q0h_frame1.jpg' preload='none' data-crt-video data-crt-options='{"autoheight":null,"duration":299,"hdUrl":false,"filmstrip":{"url":"http:\/\/38.media.tumblr.com\/previews\/tumblr_o10q0s4lQw1qz8q0h_filmstrip.jpg","width":"200","height":"112"}}' > + <source src="http://staff.tumblr.com/video_file/137376306290/tumblr_o10q0s4lQw1qz8q0h" type="video/mp4"> + </video> + <br/><br/>http://staff.tumblr.com/post/137376306290http://staff.tumblr.com/post/137376306290Fri, 15 Jan 2016 19:06:25 -0500have a relaxing weekend tumblrLosing one was hard enough… David Bowie said his goodbye, we’re...<img src="http://40.media.tumblr.com/9c69a850eece63c29d913b6e83dd49a7/tumblr_o10jfzocXP1qz8q0ho1_500.png"/><br/><br/><h2>Losing one was hard enough… </h2><ul><li><a href="http://tumblr.com/search/david%20bowie"><b>David Bowie</b></a> said his goodbye, we’re all thinking of his love. <br/></li><li><a href="http://tumblr.com/search/alan%20rickman"><b>Alan Rickman</b></a> is survived by his wife and his magic.<br/></li></ul><p>Losing <a href="http://tumblr.com/search/powerball"><b>POWERBALL</b></a> didn’t help anything.</p><figure data-orig-width="500" data-orig-height="278" data-tumblr-attribution="rustbeltjessie:Z20sTdCnR6V5dULG-Pk5FA:ZyRL1u1-svswa" class="tmblr-full"><img src="http://33.media.tumblr.com/896e5f5e4ea77f08a930d01a39723805/tumblr_o0y90c1KPr1rift8jo1_500.gif" alt="image" data-orig-width="500" data-orig-height="278"/></figure><h2>It’s award season (again)</h2><ul><li><a href="http://tumblr.com/search/golden%20globes"><b>Golden Globes</b></a> got a little loose with the juice.</li><li><a href="http://tumblr.com/search/leonardo%20dicaprio"><b>Leo DiCaprio</b></a> got on Lady Gaga’s shit list.</li><li>And <a href="http://tumblr.com/search/oscars%202016"><b>Oscars 2016</b></a>: got heat for an all-white nomination slate.</li></ul><h2>Trends gonna trend</h2><ul><li><a href="http://tumblr.com/search/coming%20out"><b>Coming out</b></a>: It’s all part of growing up.</li><li><a href="http://tumblr.com/search/the%20shannara%20chronicles"><b><i>The Shannara Chronicles</i></b></a>: A shoo be doo wop / bop bop doo wop.</li><li><a href="http://tumblr.com/search/shadowhunters"><b><i>Shadowhunters</i></b></a>: Best played on a sunny day.</li></ul><figure data-orig-width="500" data-orig-height="281" data-tumblr-attribution="katiecouric:bvFuZWnCzpG75MylRNwCUA:ZPcBQw1-hna98" class="tmblr-full"><img src="http://33.media.tumblr.com/1da9dfe557532a71323d45749dd6ea3c/tumblr_o0swib9HUI1r7kaf3o1_500.gif" alt="image" data-orig-width="500" data-orig-height="281"/></figure><h2>And these dynamite Tumblrs: </h2><ul><li><b>Plus Size Never Looked So Good</b> (<a href="http://tmblr.co/mpKfpxC4WXhPT0bbAU74L0w">@plussizeneverlookedsogood</a>): Big girl swag.<br/></li><li><b>Amandla</b> (<a href="http://tmblr.co/mfy9cYbpNQiEgZnaWyfwSRg">@amandla</a>): You know her as Rue, but you should see her graphic novels.<br/></li><li><b>Black Shop, White Writing </b>(<a href="http://tmblr.co/myTgmVRoFyIoi0hhKlWr0vw">@blackshopswhitewriting</a>): Shades of gentrification<br/></li></ul><figure data-orig-width="500" data-orig-height="190" data-tumblr-attribution="ziggyreturns:LA35rxFHUTbzeMrpzP2h-w:ZfoOZm1mAh7Bv" class="tmblr-full"><img src="http://33.media.tumblr.com/6bb8b39e6a9cd2c981fee71de1a281a6/tumblr_noi61wxvz31tlqitmo1_500.gif" alt="image" data-orig-width="500" data-orig-height="190"/></figure>http://staff.tumblr.com/post/137369118080http://staff.tumblr.com/post/137369118080Fri, 15 Jan 2016 16:55:09 -0500trendsIs this satisfying or enraging? We can’t decide. <img src="http://49.media.tumblr.com/d022b6caad3f1b5ae988b94d7113b434/tumblr_nyv2d24zYP1v0kd8mo1_500.gif"/><br/><br/><p>Is this satisfying or enraging? We can’t decide. </p>http://staff.tumblr.com/post/137318516024http://staff.tumblr.com/post/137318516024Thu, 14 Jan 2016 21:00:04 -0500slimeslime weekyou decide⬆ This great GIF button is now on iOS This button turns your...<img src="http://49.media.tumblr.com/8342edc0521edf0edcfabeed522825c9/tumblr_o0st80ul691qz8q0ho1_500.gif"/><br/><br/><h2>⬆ This great GIF button is now on iOS </h2><p>This button turns your feelings into GIFs, then inserts those GIFs into your posts. <a href="http://staff.tumblr.com/post/120720833005/since-gifs-have-replaced-written-language-were">Web</a> and <a href="http://staff.tumblr.com/post/135263390205/a-treat-for-android-users-now-you-can-add-gifs-to">Android</a> users have had it for a little while, and now the triumvirate is complete. </p><p>First, get the <a href="https://itunes.apple.com/us/app/tumblr/id305343404?mt=8">latest version of the app</a>. Next, open up a new post (or reblog!) and tap the GIF button. Search for something you want to express. Something like “potato.” Pick one, and into your post it goes:</p><figure data-orig-width="500" data-orig-height="367" data-orig-src="http://38.media.tumblr.com/801919ec41dfc2f1c5ec1b5d62482ba4/tumblr_inline_o0yfc3XE0y1qzpzhj_500.gif" data-tumblr-attribution="addyisabutler:Hr9auQKKX-zyrYFX_K4zIQ:ZClLCj1wTXFo4" class="tmblr-full"><img src="http://38.media.tumblr.com/801919ec41dfc2f1c5ec1b5d62482ba4/tumblr_inline_o0zac6myJV1qzpzhj_500.gif" alt="image" data-orig-width="500" data-orig-height="367" data-orig-src="http://38.media.tumblr.com/801919ec41dfc2f1c5ec1b5d62482ba4/tumblr_inline_o0yfc3XE0y1qzpzhj_500.gif"/></figure><p>What a marvelous potato! It communicates a passion that words cannot. Very nice. <i>Very nice indeed</i>. </p>http://staff.tumblr.com/post/137292522640http://staff.tumblr.com/post/137292522640Thu, 14 Jan 2016 13:00:03 -0500featuresjellygummies: + Iridescent goo! (and the guy doesn’t even...<img src="http://45.media.tumblr.com/5c93c21e43e0e672a5ae97d7e93d34e7/tumblr_n3je4jy7zk1syjt2wo1_400.gif"/><br/><br/><p><a class="tumblr_blog" href="http://jellygummies.tumblr.com/post/81738200024">jellygummies</a>:</p><blockquote> + <p>Iridescent goo! (and the guy doesn’t even flinch) </p> + </blockquote>http://staff.tumblr.com/post/137259011190http://staff.tumblr.com/post/137259011190Wed, 13 Jan 2016 22:15:43 -0500slime weeksorrywe hate this tooin a real appreciative wayHeavens to Betsy, it’s…<p><a href="http://thefandometrics.tumblr.com/post/137250140754/heavens-to-betsy-its" class="tumblr_blog">thefandometrics</a>:</p> + + <blockquote><figure data-orig-width="500" data-orig-height="100" class="tmblr-full"><img src="http://41.media.tumblr.com/b528045dbfddacd8dcb1789ae1aabad8/tumblr_inline_o0wy2ln5Md1qz7tc0_540.png" alt="image" data-orig-width="500" data-orig-height="100"/></figure><h2><a href="http://thefandometrics.tumblr.com/post/137118390340/tv-shows-week-ending-january-11th-2016-steven">Television</a>: This section adjusted to fit your screen.</h2><blockquote><p>⬆ <b><i><a href="https://www.tumblr.com/search/Teen+Wolf">Teen Wolf</a></i></b> makes a hair-raising leap to No. 2.<br/>☆ <b><i><a href="https://www.tumblr.com/search/The%20Golden%20Globes">The Golden Globes</a></i></b> debuted at No. 3. Shoulda been an award for <a href="http://mtv.tumblr.com/post/137063593090/leo">best grimace</a>.<br/>☆ Some elves cannot be shelved. <b><i><a href="https://www.tumblr.com/search/The%20Shannara%20Chronicles">The Shannara Chronicles</a></i></b> debuted at No. 16.</p></blockquote><figure data-orig-width="500" data-orig-height="281" data-tumblr-attribution="darkvoidpack:I6_HYH3Z998B28zTSV1YSQ:ZnIIfj1slKySo" class="tmblr-full"><img src="http://38.media.tumblr.com/05b727c83aace22632b2d8474b2d112b/tumblr_ntlpl06Z3f1uesvvmo1_500.gif" alt="image" data-orig-width="500" data-orig-height="281"/></figure><h2><a href="http://thefandometrics.tumblr.com/post/137117810802/movies-week-ending-january-11th-2016-star-wars">Movies</a>: Don’t forget to put on your 3D glasses for the next two sentences. </h2><blockquote><p>⬆ Was <b><i><a href="https://www.tumblr.com/search/Mad%20Max">Mad Max</a></i></b> snubbed at the awards? Your passionate cries lifted it to No. 10.<br/>☆ <b><i><a href="https://www.tumblr.com/search/Ghostbusters">Ghostbusters</a></i></b>, a revamp of the breathtaking documentary <i>Ghostbusters</i>, returns at No. 14.</p></blockquote><h2><a href="http://thefandometrics.tumblr.com/post/137117244608/musical-acts-week-ending-january-11th-2016-5">Music</a>: Musicians without music.</h2><blockquote><p>⬆ <b><a href="https://www.tumblr.com/search/Beyonce">Beyonce</a></b> moved up to No. 8 without making a peep on <i>Lip Sync Battle</i>.<br/>⬆ <b><a href="https://www.tumblr.com/search/Lady%20Gaga">Lady Gaga</a></b> won best actress and the equally impressive rank of No. 9.</p></blockquote><h2><a href="http://thefandometrics.tumblr.com/post/137116652699/celebrities-week-ending-january-11th-2016-adam">Celebrities</a>: Please don’t let a rich person win the Powerball.</h2><blockquote><p>☆ <b><a href="https://www.tumblr.com/search/Leonardo%20DiCaprio">Leonardo DiCaprio</a></b> battled a bear, won a Golden Globe, landed at No. 17. What a night.<br/>☆ Teen Queen <b><a href="https://www.tumblr.com/search/Amandla%20Stenberg">Amandla Stenberg</a></b> debuted at No 18 after a <a href="http://tmblr.co/mJ7SklFRPVSBBt8ifjeqy2w">@teenvogue</a> Snapchat takeover.<br/>☆ OTP alert. <b><a href="https://www.tumblr.com/search/Rami%20Malek">Rami Malek</a></b> cabooses our list at No. 20 after Christian Slater sang his praises.</p></blockquote><figure class="tmblr-full" data-orig-height="250" data-orig-width="500" data-tumblr-attribution="tvwatercooler:lbxG1rwZpwLHmhy8rIunCQ:Z7loFw1tgtiVe"><img src="http://38.media.tumblr.com/5f5e8438f58442fb65cee706a1631608/tumblr_nu9i5x036O1r9x12go1_500.gif" data-orig-height="250" data-orig-width="500"/></figure><h2><a href="http://thefandometrics.tumblr.com/post/137116069969/video-games-week-ending-january-11th-2016">Games</a>: Don’t Wake Daddy.</h2><blockquote><p>⬆ LOL, <b><i><a href="https://www.tumblr.com/search/League%20of%20Legends">League of Legends</a></i></b><b></b> moved up to No. 7.<br/>⬆ Neither Hell Nohr high water could keep <b><i><a href="https://www.tumblr.com/search/Fire%20Emblem%20Fates">Fire Emblem Fates</a> </i></b>(No. 19) off our list.</p></blockquote><h2><a href="http://thefandometrics.tumblr.com/post/137115545596/web-stuff-week-ending-january-11th-2016">Web stuff</a>: The internet is cool, good bye. </h2><blockquote><p>⬆ <b><a href="https://www.tumblr.com/search/Jacksepticeye">Jacksepticeye</a></b> (No. 4) reached 8 million subscribers. Is that even a real number?<br/>⬇︎ Animator, voice actor, rapper, human male <b><a href="https://www.tumblr.com/search/Arin%20Hanson">Arin Hanson</a></b> falls to No. 16.</p></blockquote></blockquote>http://staff.tumblr.com/post/137250668505http://staff.tumblr.com/post/137250668505Wed, 13 Jan 2016 19:39:47 -0500week in reviewPhoto<img src="http://49.media.tumblr.com/2edae122171f1a99abd1ce4dc40fe2d1/tumblr_o0aokm7F9s1v1xodyo1_500.gif"/><br/><br/>http://staff.tumblr.com/post/137191044499http://staff.tumblr.com/post/137191044499Tue, 12 Jan 2016 21:00:05 -0500welcome to the slime zoneslime weekdollychops: + + ‘Time may change me’ + + + Thank you, David Bowie, for...<img src="http://36.media.tumblr.com/6d3af2caaf3a1e444d8f22489e54fcf7/tumblr_nhuzifiESR1qaetdco1_500.png"/><br/><br/><p><a class="tumblr_blog" href="http://dollychops.tumblr.com/post/107623338570">dollychops</a>:</p> + <blockquote> + <p>‘Time may change me’</p> + </blockquote> + + <p>Thank you, David Bowie, for everything you left on this planet.</p>http://staff.tumblr.com/post/137108708620http://staff.tumblr.com/post/137108708620Mon, 11 Jan 2016 16:08:34 -0500⚡️Photo<img src="http://41.media.tumblr.com/967aba4d63cfa34fb00ed3edbc2ef27e/tumblr_nxky79R9Xz1sflxizo1_500.png"/><br/><br/>http://staff.tumblr.com/post/136905518945http://staff.tumblr.com/post/136905518945Fri, 08 Jan 2016 17:44:31 -0500have a good weekend tumblrNew year, new trends, new youBlowing up now: Graphic novelist...<img src="http://41.media.tumblr.com/9c69a850eece63c29d913b6e83dd49a7/tumblr_o0ne9sk7yG1qz8q0ho1_500.png"/><br/><br/><h2>New year, new trends, new you</h2><ul><li>Blowing up now: Graphic novelist <b><a href="http://tumblr.com/search/amandla%20stenberg">Amandla Stenberg’s</a></b> (alias: Rue) <a href="http://amandla.tumblr.com/post/136866720678/so-i-took-over-the-teen-vogue-snapchat-today">inspiring message</a>. </li><li>It took Sherlock Holmes to figure out the <a href="http://tumblr.com/search/sherlock"><b><i>Sherlock</i></b></a> special.</li><li><a href="http://tumblr.com/search/teen%20wolf"><b><i>Teen Wolf</i></b></a> and friends chased Taylor Swift <a href="http://tumblr.com/search/out%20of%20the%20woods"><b><i>Out of the Woods</i></b></a>.</li><li><a href="http://tumblr.com/search/oregon"><b>Oregon</b></a> is hosting everyone’s drunk uncles.</li><li>POTUS announced new <a href="http://tumblr.com/search/gun%20control"><b>gun control</b></a> policies.</li><li><a href="http://tumblr.com/search/ces%202016"><b>CES 2016</b></a>: for people who don’t get invited to <a href="http://tumblr.com/search/pca%202016"><b>PCA 2016</b></a>.</li></ul><figure data-orig-width="500" data-orig-height="333" data-tumblr-attribution="qualcomm:w-2kl3XPK9VC_h4I30lZQQ:ZAN2in1-NvniN" class="tmblr-full"><img src="http://33.media.tumblr.com/86405300020cd161baa702cf983c6189/tumblr_o0juioRm5j1ta1bw6o1_500.gif" alt="image" data-orig-width="500" data-orig-height="333"/></figure><ul><li><a href="http://tumblr.com/search/pvris"><b>PVRIS</b></a>: untrilled as in “Morris.”</li><li>And it’s definitely <a href="http://tumblr.com/search/jailey"><b>Jailey</b></a>. Bieldwin slays orcs in Enedwaith.</li></ul><h2>Once-around-the-sun Tumblrs</h2><ul><li><b>Daily Overview </b>(<a href="http://tmblr.co/mfB7_qm9Di9WXyvW2jkKcDA">@dailyoverview</a>): Cool stuff from above ground.</li><li><b>Earth Blingg </b>(<a href="http://tmblr.co/mMwXAkW_6d4ddLGw7VhfWaQ">@earthblingg</a>): Cool stuff from underground</li></ul>http://staff.tumblr.com/post/136898076525http://staff.tumblr.com/post/136898076525Fri, 08 Jan 2016 15:36:23 -0500trends diff --git a/mobile/android/tests/background/junit4/resources/feed_rss_wikipedia.xml b/mobile/android/tests/background/junit4/resources/feed_rss_wikipedia.xml new file mode 100644 index 000000000..a20082231 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_rss_wikipedia.xml @@ -0,0 +1,21 @@ + + + + + RSS Title + This is an example of an RSS feed + http://www.example.com/main.html + Mon, 06 Sep 2010 00:01:00 +0000 + Sun, 06 Sep 2009 16:20:00 +0000 + 1800 + + Example entry + Here is some text containing an interesting description. + http://www.example.com/blog/post/1 + 7bd204c6-1655-4c27-aeee-53f933c5395f + Sun, 06 Sep 2009 16:20:00 +0000 + + + diff --git a/mobile/android/tests/background/junit4/resources/feed_rss_wordpress.xml b/mobile/android/tests/background/junit4/resources/feed_rss_wordpress.xml new file mode 100644 index 000000000..7981eb173 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/feed_rss_wordpress.xml @@ -0,0 +1,84 @@ + + + + justasimpletest2016 + + https://justasimpletest2016.wordpress.com + + Fri, 26 Feb 2016 22:08:00 +0000 + en + hourly + 1 + http://wordpress.com/ + + + https://s2.wp.com/i/buttonw-com.png + justasimpletest2016 + https://justasimpletest2016.wordpress.com + + + diff --git a/mobile/android/tests/background/junit4/resources/robolectric.properties b/mobile/android/tests/background/junit4/resources/robolectric.properties new file mode 100644 index 000000000..a809da730 --- /dev/null +++ b/mobile/android/tests/background/junit4/resources/robolectric.properties @@ -0,0 +1,3 @@ +sdk=21 +constants=org.mozilla.gecko.BuildConfig +packageName=org.mozilla.gecko diff --git a/mobile/android/tests/background/junit4/src/com/keepsafe/switchboard/TestSwitchboard.java b/mobile/android/tests/background/junit4/src/com/keepsafe/switchboard/TestSwitchboard.java new file mode 100644 index 000000000..5726f12db --- /dev/null +++ b/mobile/android/tests/background/junit4/src/com/keepsafe/switchboard/TestSwitchboard.java @@ -0,0 +1,142 @@ +package com.keepsafe.switchboard; + +import android.content.Context; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.Experiments; +import org.mozilla.gecko.util.IOUtils; +import org.robolectric.RuntimeEnvironment; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.List; +import java.util.UUID; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class TestSwitchboard { + + /** + * Create a JSON response from a JSON file. + */ + private String readFromFile(String fileName) throws IOException { + URL url = getClass().getResource("/" + fileName); + if (url == null) { + throw new FileNotFoundException(fileName); + } + + InputStream inputStream = null; + ByteArrayOutputStream outputStream = null; + + try { + inputStream = new BufferedInputStream(new FileInputStream(url.getPath())); + InputStreamReader inputStreamReader = new InputStreamReader(inputStream); + BufferedReader bufferReader = new BufferedReader(inputStreamReader, 8192); + String line; + StringBuilder resultContent = new StringBuilder(); + while ((line = bufferReader.readLine()) != null) { + resultContent.append(line); + } + bufferReader.close(); + + return resultContent.toString(); + + } finally { + IOUtils.safeStreamClose(inputStream); + } + } + + @Before + public void setUp() throws IOException { + final Context c = RuntimeEnvironment.application; + Preferences.setDynamicConfigJson(c, readFromFile("experiments.json")); + } + + @Test + public void testDeviceUuidFactory() { + final Context c = RuntimeEnvironment.application; + final DeviceUuidFactory df = new DeviceUuidFactory(c); + final UUID uuid = df.getDeviceUuid(); + assertNotNull("UUID is not null", uuid); + assertEquals("DeviceUuidFactory always returns the same UUID", df.getDeviceUuid(), uuid); + } + + @Test + public void testIsInExperiment() { + final Context c = RuntimeEnvironment.application; + assertTrue("active-experiment is active", SwitchBoard.isInExperiment(c, "active-experiment")); + assertFalse("inactive-experiment is inactive", SwitchBoard.isInExperiment(c, "inactive-experiment")); + } + + @Test + public void testExperimentValues() throws JSONException { + final Context c = RuntimeEnvironment.application; + assertTrue("active-experiment has values", SwitchBoard.hasExperimentValues(c, "active-experiment")); + assertFalse("inactive-experiment doesn't have values", SwitchBoard.hasExperimentValues(c, "inactive-experiment")); + + final JSONObject values = SwitchBoard.getExperimentValuesFromJson(c, "active-experiment"); + assertNotNull("active-experiment values are not null", values); + assertTrue("\"foo\" extra value is true", values.getBoolean("foo")); + } + + @Test + public void testGetActiveExperiments() { + final Context c = RuntimeEnvironment.application; + final List experiments = SwitchBoard.getActiveExperiments(c); + assertNotNull("List of active experiments is not null", experiments); + + assertTrue("List of active experiments contains active-experiment", experiments.contains("active-experiment")); + assertFalse("List of active experiments does not contain inactive-experiment", experiments.contains("inactive-experiment")); + } + + @Test + public void testOverride() { + final Context c = RuntimeEnvironment.application; + + Experiments.setOverride(c, "active-experiment", false); + assertFalse("active-experiment is not active because of override", SwitchBoard.isInExperiment(c, "active-experiment")); + assertFalse("List of active experiments does not contain active-experiment", SwitchBoard.getActiveExperiments(c).contains("active-experiment")); + + Experiments.clearOverride(c, "active-experiment"); + assertTrue("active-experiment is active after override is cleared", SwitchBoard.isInExperiment(c, "active-experiment")); + assertTrue("List of active experiments contains active-experiment again", SwitchBoard.getActiveExperiments(c).contains("active-experiment")); + + Experiments.setOverride(c, "inactive-experiment", true); + assertTrue("inactive-experiment is active because of override", SwitchBoard.isInExperiment(c, "inactive-experiment")); + assertTrue("List of active experiments contains inactive-experiment", SwitchBoard.getActiveExperiments(c).contains("inactive-experiment")); + + Experiments.clearOverride(c, "inactive-experiment"); + assertFalse("inactive-experiment is inactive after override is cleared", SwitchBoard.isInExperiment(c, "inactive-experiment")); + assertFalse("List of active experiments does not contain inactive-experiment again", SwitchBoard.getActiveExperiments(c).contains("inactive-experiment")); + } + + @Test + public void testMatching() { + final Context c = RuntimeEnvironment.application; + assertTrue("is-experiment is matching", SwitchBoard.isInExperiment(c, "is-matching")); + assertFalse("is-not-matching is not matching", SwitchBoard.isInExperiment(c, "is-not-matching")); + } + + @Test + public void testNotExisting() { + final Context c = RuntimeEnvironment.application; + assertFalse("F0O does not exists", SwitchBoard.isInExperiment(c, "F0O")); + assertFalse("BaAaz does not exists", SwitchBoard.hasExperimentValues(c, "BaAaz")); + } + + + +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestBackoff.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestBackoff.java new file mode 100644 index 000000000..8e8152e36 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestBackoff.java @@ -0,0 +1,114 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import ch.boye.httpclientandroidlib.HttpResponse; +import ch.boye.httpclientandroidlib.ProtocolVersion; +import ch.boye.httpclientandroidlib.message.BasicHttpResponse; +import ch.boye.httpclientandroidlib.message.BasicStatusLine; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.MockGlobalSessionCallback; +import org.mozilla.gecko.background.testhelpers.MockGlobalSession; +import org.mozilla.gecko.background.testhelpers.MockSharedPreferences; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.SyncConfiguration; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestBackoff { + private final String TEST_USERNAME = "johndoe"; + private final String TEST_PASSWORD = "password"; + private final String TEST_SYNC_KEY = "abcdeabcdeabcdeabcdeabcdea"; + private final long TEST_BACKOFF_IN_SECONDS = 1201; + + /** + * Test that interpretHTTPFailure calls requestBackoff if + * X-Weave-Backoff is present. + */ + @Test + public void testBackoffCalledIfBackoffHeaderPresent() { + try { + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), new MockSharedPreferences(), new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY)); + final GlobalSession session = new MockGlobalSession(config, callback); + + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); + response.addHeader("X-Weave-Backoff", Long.toString(TEST_BACKOFF_IN_SECONDS)); // Backoff given in seconds. + + session.interpretHTTPFailure(response); // This is synchronous... + + assertEquals(false, callback.calledSuccess); // ... so we can test immediately. + assertEquals(false, callback.calledError); + assertEquals(false, callback.calledAborted); + assertEquals(true, callback.calledRequestBackoff); + assertEquals(TEST_BACKOFF_IN_SECONDS * 1000, callback.weaveBackoff); // Backoff returned in milliseconds. + } catch (Exception e) { + e.printStackTrace(); + fail("Got exception."); + } + } + + /** + * Test that interpretHTTPFailure does not call requestBackoff if + * X-Weave-Backoff is not present. + */ + @Test + public void testBackoffNotCalledIfBackoffHeaderNotPresent() { + try { + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), new MockSharedPreferences(), new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY)); + final GlobalSession session = new MockGlobalSession(config, callback); + + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); + + session.interpretHTTPFailure(response); // This is synchronous... + + assertEquals(false, callback.calledSuccess); // ... so we can test immediately. + assertEquals(false, callback.calledError); + assertEquals(false, callback.calledAborted); + assertEquals(false, callback.calledRequestBackoff); + } catch (Exception e) { + e.printStackTrace(); + fail("Got exception."); + } + } + + /** + * Test that interpretHTTPFailure calls requestBackoff with the + * largest specified value if X-Weave-Backoff and Retry-After are + * present. + */ + @Test + public void testBackoffCalledIfMultipleBackoffHeadersPresent() { + try { + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), new MockSharedPreferences(), new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY)); + final GlobalSession session = new MockGlobalSession(config, callback); + + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); + response.addHeader("Retry-After", Long.toString(TEST_BACKOFF_IN_SECONDS)); // Backoff given in seconds. + response.addHeader("X-Weave-Backoff", Long.toString(TEST_BACKOFF_IN_SECONDS + 1)); // If we now add a second header, the larger should be returned. + + session.interpretHTTPFailure(response); // This is synchronous... + + assertEquals(false, callback.calledSuccess); // ... so we can test immediately. + assertEquals(false, callback.calledError); + assertEquals(false, callback.calledAborted); + assertEquals(true, callback.calledRequestBackoff); + assertEquals((TEST_BACKOFF_IN_SECONDS + 1) * 1000, callback.weaveBackoff); // Backoff returned in milliseconds. + } catch (Exception e) { + e.printStackTrace(); + fail("Got exception."); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestBrowserIDAuthHeaderProvider.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestBrowserIDAuthHeaderProvider.java new file mode 100644 index 000000000..6a14c6d29 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestBrowserIDAuthHeaderProvider.java @@ -0,0 +1,23 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import ch.boye.httpclientandroidlib.Header; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.net.BrowserIDAuthHeaderProvider; + +import static org.junit.Assert.assertEquals; + +@RunWith(TestRunner.class) +public class TestBrowserIDAuthHeaderProvider { + @Test + public void testHeader() { + Header header = new BrowserIDAuthHeaderProvider("assertion").getAuthHeader(null, null, null); + + assertEquals("authorization", header.getName().toLowerCase()); + assertEquals("BrowserID assertion", header.getValue()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestClientsEngineStage.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestClientsEngineStage.java new file mode 100644 index 000000000..920cafb35 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestClientsEngineStage.java @@ -0,0 +1,806 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import ch.boye.httpclientandroidlib.HttpStatus; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockGlobalSessionCallback; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.android.sync.test.helpers.MockSyncClientsEngineStage; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.testhelpers.CommandHelpers; +import org.mozilla.gecko.background.testhelpers.MockClientsDataDelegate; +import org.mozilla.gecko.background.testhelpers.MockClientsDatabaseAccessor; +import org.mozilla.gecko.background.testhelpers.MockGlobalSession; +import org.mozilla.gecko.background.testhelpers.MockSharedPreferences; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.CollectionKeys; +import org.mozilla.gecko.sync.CommandProcessor.Command; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.SyncConfiguration; +import org.mozilla.gecko.sync.SyncConfigurationException; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.mozilla.gecko.sync.repositories.NullCursorException; +import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor; +import org.mozilla.gecko.sync.repositories.domain.ClientRecord; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.io.IOException; +import java.io.PrintStream; +import java.math.BigDecimal; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Some tests in this class run client/server multi-threaded code but JUnit assertions triggered + * from background threads do not fail the test. If you see unexplained connection-related test failures, + * an assertion on the server may have been thrown. Unfortunately, it is non-trivial to get the background + * threads to transfer failures back to the test thread so we leave the tests in this state for now. + * + * One reason the server might throw an assertion is if you have not installed the crypto policies. See + * https://wiki.mozilla.org/Mobile/Fennec/Android/Testing#JUnit4_tests for more information. + */ +@RunWith(TestRunner.class) +public class TestClientsEngineStage extends MockSyncClientsEngineStage { + public final static String LOG_TAG = "TestClientsEngSta"; + + public TestClientsEngineStage() throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, CryptoException, URISyntaxException { + super(); + session = initializeSession(); + } + + // Static so we can set it during the constructor. This is so evil. + private static MockGlobalSessionCallback callback; + private static GlobalSession initializeSession() throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, CryptoException, URISyntaxException { + callback = new MockGlobalSessionCallback(); + SyncConfiguration config = new SyncConfiguration(USERNAME, new BasicAuthHeaderProvider(USERNAME, PASSWORD), new MockSharedPreferences()); + config.syncKeyBundle = new KeyBundle(USERNAME, SYNC_KEY); + GlobalSession session = new MockClientsGlobalSession(config, callback); + session.config.setClusterURL(new URI(TEST_SERVER)); + session.config.setCollectionKeys(CollectionKeys.generateCollectionKeys()); + return session; + } + + private static final int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private static final String TEST_SERVER = "http://localhost:" + TEST_PORT; + + private static final String USERNAME = "john"; + private static final String PASSWORD = "password"; + private static final String SYNC_KEY = "abcdeabcdeabcdeabcdeabcdea"; + + private HTTPServerTestHelper data = new HTTPServerTestHelper(); + private int numRecordsFromGetRequest = 0; + + private ArrayList expectedClients = new ArrayList(); + private ArrayList downloadedClients = new ArrayList(); + + // For test purposes. + private ClientRecord lastComputedLocalClientRecord; + private ClientRecord uploadedRecord; + private String uploadBodyTimestamp; + private long uploadHeaderTimestamp; + private MockServer currentUploadMockServer; + private MockServer currentDownloadMockServer; + + private boolean stubUpload = false; + + protected static WaitHelper testWaiter() { + return WaitHelper.getTestWaiter(); + } + + @Override + protected ClientRecord newLocalClientRecord(ClientsDataDelegate delegate) { + lastComputedLocalClientRecord = super.newLocalClientRecord(delegate); + return lastComputedLocalClientRecord; + } + + @After + public void teardown() { + stubUpload = false; + getMockDataAccessor().resetVars(); + } + + @Override + public synchronized ClientsDatabaseAccessor getClientsDatabaseAccessor() { + if (db == null) { + db = new MockClientsDatabaseAccessor(); + } + return db; + } + + // For test use. + private MockClientsDatabaseAccessor getMockDataAccessor() { + return (MockClientsDatabaseAccessor) getClientsDatabaseAccessor(); + } + + private synchronized boolean mockDataAccessorIsClosed() { + if (db == null) { + return true; + } + return ((MockClientsDatabaseAccessor) db).closed; + } + + @Override + protected ClientDownloadDelegate makeClientDownloadDelegate() { + return clientDownloadDelegate; + } + + @Override + protected void downloadClientRecords() { + BaseResource.rewriteLocalhost = false; + data.startHTTPServer(currentDownloadMockServer); + super.downloadClientRecords(); + } + + @Override + protected void uploadClientRecord(CryptoRecord record) { + BaseResource.rewriteLocalhost = false; + if (stubUpload) { + session.advance(); + return; + } + data.startHTTPServer(currentUploadMockServer); + super.uploadClientRecord(record); + } + + @Override + protected void uploadClientRecords(JSONArray records) { + BaseResource.rewriteLocalhost = false; + if (stubUpload) { + return; + } + data.startHTTPServer(currentUploadMockServer); + super.uploadClientRecords(records); + } + + public static class MockClientsGlobalSession extends MockGlobalSession { + private ClientsDataDelegate clientsDataDelegate = new MockClientsDataDelegate(); + + public MockClientsGlobalSession(SyncConfiguration config, + GlobalSessionCallback callback) + throws SyncConfigurationException, + IllegalArgumentException, + IOException, + NonObjectJSONException { + super(config, callback); + } + + @Override + public ClientsDataDelegate getClientsDelegate() { + return clientsDataDelegate; + } + } + + public class TestSuccessClientDownloadDelegate extends TestClientDownloadDelegate { + public TestSuccessClientDownloadDelegate(HTTPServerTestHelper data) { + super(data); + } + + @Override + public void handleRequestFailure(SyncStorageResponse response) { + super.handleRequestFailure(response); + assertTrue(getMockDataAccessor().closed); + fail("Should not error."); + } + + @Override + public void handleRequestError(Exception ex) { + super.handleRequestError(ex); + assertTrue(getMockDataAccessor().closed); + fail("Should not fail."); + } + + @Override + public void handleWBO(CryptoRecord record) { + ClientRecord r; + try { + r = (ClientRecord) factory.createRecord(record.decrypt()); + downloadedClients.add(r); + numRecordsFromGetRequest++; + } catch (Exception e) { + fail("handleWBO failed."); + } + } + } + + public class TestHandleWBODownloadDelegate extends TestClientDownloadDelegate { + public TestHandleWBODownloadDelegate(HTTPServerTestHelper data) { + super(data); + } + + @Override + public void handleRequestFailure(SyncStorageResponse response) { + super.handleRequestFailure(response); + assertTrue(getMockDataAccessor().closed); + fail("Should not error."); + } + + @Override + public void handleRequestError(Exception ex) { + super.handleRequestError(ex); + assertTrue(getMockDataAccessor().closed); + ex.printStackTrace(); + fail("Should not fail."); + } + } + + public class MockSuccessClientUploadDelegate extends MockClientUploadDelegate { + public MockSuccessClientUploadDelegate(HTTPServerTestHelper data) { + super(data); + } + + @Override + public void handleRequestSuccess(SyncStorageResponse response) { + uploadHeaderTimestamp = response.normalizedWeaveTimestamp(); + super.handleRequestSuccess(response); + } + + @Override + public void handleRequestFailure(SyncStorageResponse response) { + super.handleRequestFailure(response); + fail("Should not fail."); + } + + @Override + public void handleRequestError(Exception ex) { + super.handleRequestError(ex); + ex.printStackTrace(); + fail("Should not error."); + } + } + + public class MockFailureClientUploadDelegate extends MockClientUploadDelegate { + public MockFailureClientUploadDelegate(HTTPServerTestHelper data) { + super(data); + } + + @Override + public void handleRequestSuccess(SyncStorageResponse response) { + super.handleRequestSuccess(response); + fail("Should not succeed."); + } + + @Override + public void handleRequestError(Exception ex) { + super.handleRequestError(ex); + fail("Should not fail."); + } + } + + public class UploadMockServer extends MockServer { + @SuppressWarnings("unchecked") + private String postBodyForRecord(ClientRecord cr) { + final long now = cr.lastModified; + final BigDecimal modified = Utils.millisecondsToDecimalSeconds(now); + + Logger.debug(LOG_TAG, "Now is " + now + " (" + modified + ")"); + final JSONArray idArray = new JSONArray(); + idArray.add(cr.guid); + + final JSONObject result = new JSONObject(); + result.put("modified", modified); + result.put("success", idArray); + result.put("failed", new JSONObject()); + + uploadBodyTimestamp = modified.toString(); + return result.toJSONString(); + } + + private String putBodyForRecord(ClientRecord cr) { + final String modified = Utils.millisecondsToDecimalSecondsString(cr.lastModified); + uploadBodyTimestamp = modified; + return modified; + } + + protected void handleUploadPUT(Request request, Response response) throws Exception { + Logger.debug(LOG_TAG, "Handling PUT: " + request.getPath()); + + // Save uploadedRecord to test against. + CryptoRecord cryptoRecord = CryptoRecord.fromJSONRecord(request.getContent()); + cryptoRecord.keyBundle = session.keyBundleForCollection(COLLECTION_NAME); + uploadedRecord = (ClientRecord) factory.createRecord(cryptoRecord.decrypt()); + + // Note: collection is not saved in CryptoRecord.toJSONObject() upon upload. + // So its value is null and is set here so ClientRecord.equals() may be used. + uploadedRecord.collection = lastComputedLocalClientRecord.collection; + + // Create response body containing current timestamp. + long now = System.currentTimeMillis(); + PrintStream bodyStream = this.handleBasicHeaders(request, response, 200, "application/json", now); + uploadedRecord.lastModified = now; + + bodyStream.println(putBodyForRecord(uploadedRecord)); + bodyStream.close(); + } + + protected void handleUploadPOST(Request request, Response response) throws Exception { + Logger.debug(LOG_TAG, "Handling POST: " + request.getPath()); + String content = request.getContent(); + Logger.debug(LOG_TAG, "Content is " + content); + JSONArray array = ExtendedJSONObject.parseJSONArray(content); + + Logger.debug(LOG_TAG, "Content is " + array); + + KeyBundle keyBundle = session.keyBundleForCollection(COLLECTION_NAME); + if (array.size() != 1) { + Logger.debug(LOG_TAG, "Expecting only one record! Fail!"); + PrintStream bodyStream = this.handleBasicHeaders(request, response, 400, "text/plain"); + bodyStream.println("Expecting only one record! Fail!"); + bodyStream.close(); + return; + } + + CryptoRecord r = CryptoRecord.fromJSONRecord(new ExtendedJSONObject((JSONObject) array.get(0))); + r.keyBundle = keyBundle; + ClientRecord cr = (ClientRecord) factory.createRecord(r.decrypt()); + cr.collection = lastComputedLocalClientRecord.collection; + uploadedRecord = cr; + + Logger.debug(LOG_TAG, "Record is " + cr); + long now = System.currentTimeMillis(); + PrintStream bodyStream = this.handleBasicHeaders(request, response, 200, "application/json", now); + cr.lastModified = now; + final String responseBody = postBodyForRecord(cr); + Logger.debug(LOG_TAG, "Response is " + responseBody); + bodyStream.println(responseBody); + bodyStream.close(); + } + + @Override + public void handle(Request request, Response response) { + try { + String method = request.getMethod(); + Logger.debug(LOG_TAG, "Handling " + method); + if (method.equalsIgnoreCase("post")) { + handleUploadPOST(request, response); + } else if (method.equalsIgnoreCase("put")) { + handleUploadPUT(request, response); + } else { + PrintStream bodyStream = this.handleBasicHeaders(request, response, 404, "text/plain"); + bodyStream.close(); + } + } catch (Exception e) { + fail("Error handling uploaded client record in UploadMockServer."); + } + } + } + + public class DownloadMockServer extends MockServer { + @Override + public void handle(Request request, Response response) { + try { + PrintStream bodyStream = this.handleBasicHeaders(request, response, 200, "application/newlines"); + for (int i = 0; i < 5; i++) { + ClientRecord record = new ClientRecord(); + if (i != 2) { // So we test null version. + record.version = Integer.toString(28 + i); + } + expectedClients.add(record); + CryptoRecord cryptoRecord = cryptoFromClient(record); + bodyStream.print(cryptoRecord.toJSONString() + "\n"); + } + bodyStream.close(); + } catch (IOException e) { + fail("Error handling downloaded client records in DownloadMockServer."); + } + } + } + + public class DownloadLocalRecordMockServer extends MockServer { + @SuppressWarnings("unchecked") + @Override + public void handle(Request request, Response response) { + try { + PrintStream bodyStream = this.handleBasicHeaders(request, response, 200, "application/newlines"); + ClientRecord record = new ClientRecord(session.getClientsDelegate().getAccountGUID()); + + // Timestamp on server is 10 seconds after local timestamp + // (would trigger 412 if upload was attempted). + CryptoRecord cryptoRecord = cryptoFromClient(record); + JSONObject object = cryptoRecord.toJSONObject(); + final long modified = (setRecentClientRecordTimestamp() + 10000) / 1000; + Logger.debug(LOG_TAG, "Setting modified to " + modified); + object.put("modified", modified); + bodyStream.print(object.toJSONString() + "\n"); + bodyStream.close(); + } catch (IOException e) { + fail("Error handling downloaded client records in DownloadLocalRecordMockServer."); + } + } + } + + private CryptoRecord cryptoFromClient(ClientRecord record) { + CryptoRecord cryptoRecord = record.getEnvelope(); + cryptoRecord.keyBundle = clientDownloadDelegate.keyBundle(); + try { + cryptoRecord.encrypt(); + } catch (Exception e) { + fail("Cannot encrypt client record."); + } + return cryptoRecord; + } + + private long setRecentClientRecordTimestamp() { + long timestamp = System.currentTimeMillis() - (CLIENTS_TTL_REFRESH - 1000); + session.config.persistServerClientRecordTimestamp(timestamp); + return timestamp; + } + + private void performFailingUpload() { + // performNotify() occurs in MockGlobalSessionCallback. + testWaiter().performWait(new Runnable() { + @Override + public void run() { + clientUploadDelegate = new MockFailureClientUploadDelegate(data); + checkAndUpload(); + } + }); + } + + @SuppressWarnings("unchecked") + @Test + public void testShouldUploadNoCommandsToProcess() throws NullCursorException { + // shouldUpload() returns true. + assertEquals(0, session.config.getPersistedServerClientRecordTimestamp()); + assertFalse(shouldUploadLocalRecord); + assertTrue(shouldUpload()); + + // Set the timestamp to be a little earlier than refresh time, + // so shouldUpload() returns false. + setRecentClientRecordTimestamp(); + assertFalse(0 == session.config.getPersistedServerClientRecordTimestamp()); + assertFalse(shouldUploadLocalRecord); + assertFalse(shouldUpload()); + + // Now simulate observing a client record with the incorrect version. + + ClientRecord outdatedRecord = new ClientRecord("dontmatter12", "clients", System.currentTimeMillis(), false); + + outdatedRecord.version = getLocalClientVersion(); + outdatedRecord.protocols = getLocalClientProtocols(); + handleDownloadedLocalRecord(outdatedRecord); + + assertEquals(outdatedRecord.lastModified, session.config.getPersistedServerClientRecordTimestamp()); + assertFalse(shouldUploadLocalRecord); + assertFalse(shouldUpload()); + + outdatedRecord.version = outdatedRecord.version + "a1"; + handleDownloadedLocalRecord(outdatedRecord); + + // Now we think we need to upload because the version is outdated. + assertTrue(shouldUploadLocalRecord); + assertTrue(shouldUpload()); + + shouldUploadLocalRecord = false; + assertFalse(shouldUpload()); + + // If the protocol list is missing or wrong, we should reupload. + outdatedRecord.protocols = new JSONArray(); + handleDownloadedLocalRecord(outdatedRecord); + assertTrue(shouldUpload()); + + shouldUploadLocalRecord = false; + assertFalse(shouldUpload()); + + outdatedRecord.protocols.add("1.0"); + handleDownloadedLocalRecord(outdatedRecord); + assertTrue(shouldUpload()); + } + + @SuppressWarnings("unchecked") + @Test + public void testShouldUploadProcessCommands() throws NullCursorException { + // shouldUpload() returns false since array is size 0 and + // it has not been long enough yet to require an upload. + processCommands(new JSONArray()); + setRecentClientRecordTimestamp(); + assertFalse(shouldUploadLocalRecord); + assertFalse(shouldUpload()); + + // shouldUpload() returns true since array is size 1 even though + // it has not been long enough yet to require an upload. + JSONArray commands = new JSONArray(); + commands.add(new JSONObject()); + processCommands(commands); + setRecentClientRecordTimestamp(); + assertEquals(1, commands.size()); + assertTrue(shouldUploadLocalRecord); + assertTrue(shouldUpload()); + } + + @Test + public void testWipeAndStoreShouldNotWipe() { + assertFalse(shouldWipe); + wipeAndStore(new ClientRecord()); + assertFalse(shouldWipe); + assertFalse(getMockDataAccessor().clientsTableWiped); + assertTrue(getMockDataAccessor().storedRecord); + } + + @Test + public void testWipeAndStoreShouldWipe() { + assertFalse(shouldWipe); + shouldWipe = true; + wipeAndStore(new ClientRecord()); + assertFalse(shouldWipe); + assertTrue(getMockDataAccessor().clientsTableWiped); + assertTrue(getMockDataAccessor().storedRecord); + } + + @Test + public void testDownloadClientRecord() { + // Make sure no upload occurs after a download so we can + // test download in isolation. + stubUpload = true; + + currentDownloadMockServer = new DownloadMockServer(); + // performNotify() occurs in MockGlobalSessionCallback. + testWaiter().performWait(new Runnable() { + @Override + public void run() { + clientDownloadDelegate = new TestSuccessClientDownloadDelegate(data); + downloadClientRecords(); + } + }); + + assertEquals(expectedClients.size(), numRecordsFromGetRequest); + for (int i = 0; i < downloadedClients.size(); i++) { + final ClientRecord downloaded = downloadedClients.get(i); + final ClientRecord expected = expectedClients.get(i); + assertTrue(expected.guid.equals(downloaded.guid)); + assertEquals(expected.version, downloaded.version); + } + assertTrue(mockDataAccessorIsClosed()); + } + + @Test + public void testCheckAndUploadClientRecord() { + uploadAttemptsCount.set(MAX_UPLOAD_FAILURE_COUNT); + assertFalse(shouldUploadLocalRecord); + assertEquals(0, session.config.getPersistedServerClientRecordTimestamp()); + currentUploadMockServer = new UploadMockServer(); + // performNotify() occurs in MockGlobalSessionCallback. + testWaiter().performWait(new Runnable() { + @Override + public void run() { + clientUploadDelegate = new MockSuccessClientUploadDelegate(data); + checkAndUpload(); + } + }); + + // Test ClientUploadDelegate.handleRequestSuccess(). + Logger.debug(LOG_TAG, "Last computed local client record: " + lastComputedLocalClientRecord.guid); + Logger.debug(LOG_TAG, "Uploaded client record: " + uploadedRecord.guid); + assertTrue(lastComputedLocalClientRecord.equalPayloads(uploadedRecord)); + assertEquals(0, uploadAttemptsCount.get()); + assertTrue(callback.calledSuccess); + + assertFalse(0 == session.config.getPersistedServerClientRecordTimestamp()); + + // Body and header are the same. + assertEquals(Utils.decimalSecondsToMilliseconds(uploadBodyTimestamp), + session.config.getPersistedServerClientsTimestamp()); + assertEquals(uploadedRecord.lastModified, + session.config.getPersistedServerClientRecordTimestamp()); + assertEquals(uploadHeaderTimestamp, session.config.getPersistedServerClientsTimestamp()); + } + + @Test // client/server multi-threaded + public void testDownloadHasOurRecord() { + // Make sure no upload occurs after a download so we can + // test download in isolation. + stubUpload = true; + + // We've uploaded our local record recently. + long initialTimestamp = setRecentClientRecordTimestamp(); + + currentDownloadMockServer = new DownloadLocalRecordMockServer(); + // performNotify() occurs in MockGlobalSessionCallback. + testWaiter().performWait(new Runnable() { + @Override + public void run() { + clientDownloadDelegate = new TestHandleWBODownloadDelegate(data); + downloadClientRecords(); + } + }); + + // Timestamp got updated (but not reset) since we downloaded our record + assertFalse(0 == session.config.getPersistedServerClientRecordTimestamp()); + assertTrue(initialTimestamp < session.config.getPersistedServerClientRecordTimestamp()); + assertTrue(mockDataAccessorIsClosed()); + } + + @Test + public void testResetTimestampOnDownload() { + // Make sure no upload occurs after a download so we can + // test download in isolation. + stubUpload = true; + + currentDownloadMockServer = new DownloadMockServer(); + // performNotify() occurs in MockGlobalSessionCallback. + testWaiter().performWait(new Runnable() { + @Override + public void run() { + clientDownloadDelegate = new TestHandleWBODownloadDelegate(data); + downloadClientRecords(); + } + }); + + // Timestamp got reset since our record wasn't downloaded. + assertEquals(0, session.config.getPersistedServerClientRecordTimestamp()); + assertTrue(mockDataAccessorIsClosed()); + } + + /** + * The following 8 tests are for ClientUploadDelegate.handleRequestFailure(). + * for the varying values of uploadAttemptsCount, shouldUploadLocalRecord, + * and the type of server error. + * + * The first 4 are for 412 Precondition Failures. + * The second 4 represent the functionality given any other type of variable. + */ + @Test + public void testHandle412UploadFailureLowCount() { + assertFalse(shouldUploadLocalRecord); + currentUploadMockServer = new MockServer(HttpStatus.SC_PRECONDITION_FAILED, null); + assertEquals(0, uploadAttemptsCount.get()); + performFailingUpload(); + assertEquals(0, uploadAttemptsCount.get()); + assertTrue(callback.calledError); + } + + @Test + public void testHandle412UploadFailureHighCount() { + assertFalse(shouldUploadLocalRecord); + currentUploadMockServer = new MockServer(HttpStatus.SC_PRECONDITION_FAILED, null); + uploadAttemptsCount.set(MAX_UPLOAD_FAILURE_COUNT); + performFailingUpload(); + assertEquals(MAX_UPLOAD_FAILURE_COUNT, uploadAttemptsCount.get()); + assertTrue(callback.calledError); + } + + @Test + public void testHandle412UploadFailureLowCountWithCommand() { + shouldUploadLocalRecord = true; + currentUploadMockServer = new MockServer(HttpStatus.SC_PRECONDITION_FAILED, null); + assertEquals(0, uploadAttemptsCount.get()); + performFailingUpload(); + assertEquals(0, uploadAttemptsCount.get()); + assertTrue(callback.calledError); + } + + @Test + public void testHandle412UploadFailureHighCountWithCommand() { + shouldUploadLocalRecord = true; + currentUploadMockServer = new MockServer(HttpStatus.SC_PRECONDITION_FAILED, null); + uploadAttemptsCount.set(MAX_UPLOAD_FAILURE_COUNT); + performFailingUpload(); + assertEquals(MAX_UPLOAD_FAILURE_COUNT, uploadAttemptsCount.get()); + assertTrue(callback.calledError); + } + + @Test + public void testHandleMiscUploadFailureLowCount() { + currentUploadMockServer = new MockServer(HttpStatus.SC_BAD_REQUEST, null); + assertFalse(shouldUploadLocalRecord); + assertEquals(0, uploadAttemptsCount.get()); + performFailingUpload(); + assertEquals(0, uploadAttemptsCount.get()); + assertTrue(callback.calledError); + } + + @Test + public void testHandleMiscUploadFailureHighCount() { + currentUploadMockServer = new MockServer(HttpStatus.SC_BAD_REQUEST, null); + assertFalse(shouldUploadLocalRecord); + uploadAttemptsCount.set(MAX_UPLOAD_FAILURE_COUNT); + performFailingUpload(); + assertEquals(MAX_UPLOAD_FAILURE_COUNT, uploadAttemptsCount.get()); + assertTrue(callback.calledError); + } + + @Test + public void testHandleMiscUploadFailureHighCountWithCommands() { + currentUploadMockServer = new MockServer(HttpStatus.SC_BAD_REQUEST, null); + shouldUploadLocalRecord = true; + uploadAttemptsCount.set(MAX_UPLOAD_FAILURE_COUNT); + performFailingUpload(); + assertEquals(MAX_UPLOAD_FAILURE_COUNT + 1, uploadAttemptsCount.get()); + assertTrue(callback.calledError); + } + + @Test + public void testHandleMiscUploadFailureMaxAttempts() { + currentUploadMockServer = new MockServer(HttpStatus.SC_BAD_REQUEST, null); + shouldUploadLocalRecord = true; + assertEquals(0, uploadAttemptsCount.get()); + performFailingUpload(); + assertEquals(MAX_UPLOAD_FAILURE_COUNT + 1, uploadAttemptsCount.get()); + assertTrue(callback.calledError); + } + + class TestAddCommandsMockClientsDatabaseAccessor extends MockClientsDatabaseAccessor { + @Override + public List fetchCommandsForClient(String accountGUID) throws NullCursorException { + List commands = new ArrayList(); + commands.add(CommandHelpers.getCommand1()); + commands.add(CommandHelpers.getCommand2()); + commands.add(CommandHelpers.getCommand3()); + commands.add(CommandHelpers.getCommand4()); + return commands; + } + } + + @Test + public void testAddCommandsToUnversionedClient() throws NullCursorException { + db = new TestAddCommandsMockClientsDatabaseAccessor(); + + final ClientRecord remoteRecord = new ClientRecord(); + remoteRecord.version = null; + final String expectedGUID = remoteRecord.guid; + + this.addCommands(remoteRecord); + assertEquals(1, modifiedClientsToUpload.size()); + + final ClientRecord recordToUpload = modifiedClientsToUpload.get(0); + assertEquals(4, recordToUpload.commands.size()); + assertEquals(expectedGUID, recordToUpload.guid); + assertEquals(null, recordToUpload.version); + } + + @Test + public void testAddCommandsToVersionedClient() throws NullCursorException { + db = new TestAddCommandsMockClientsDatabaseAccessor(); + + final ClientRecord remoteRecord = new ClientRecord(); + remoteRecord.version = "12a1"; + final String expectedGUID = remoteRecord.guid; + + this.addCommands(remoteRecord); + assertEquals(1, modifiedClientsToUpload.size()); + + final ClientRecord recordToUpload = modifiedClientsToUpload.get(0); + assertEquals(4, recordToUpload.commands.size()); + assertEquals(expectedGUID, recordToUpload.guid); + assertEquals("12a1", recordToUpload.version); + } + + @Test + public void testLastModifiedTimestamp() throws NullCursorException { + // If we uploaded a record a moment ago, we shouldn't upload another. + final long now = System.currentTimeMillis() - 1; + session.config.persistServerClientRecordTimestamp(now); + assertEquals(now, session.config.getPersistedServerClientRecordTimestamp()); + assertFalse(shouldUploadLocalRecord); + assertFalse(shouldUpload()); + + // But if we change our client data, we should upload. + session.getClientsDelegate().setClientName("new name", System.currentTimeMillis()); + assertTrue(shouldUpload()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestCredentialsEndToEnd.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestCredentialsEndToEnd.java new file mode 100644 index 000000000..0f568a81e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestCredentialsEndToEnd.java @@ -0,0 +1,72 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +import ch.boye.httpclientandroidlib.Header; + +import static org.junit.Assert.assertEquals; + +/** + * Test the transfer of a UTF-8 string from desktop, and ensure that it results in the + * correct hashed Basic Auth header. + */ +@RunWith(TestRunner.class) +public class TestCredentialsEndToEnd { + + public static final String REAL_PASSWORD = "pïgéons1"; + public static final String USERNAME = "utvm3mk6hnngiir2sp4jsxf2uvoycrv6"; + public static final String DESKTOP_PASSWORD_JSON = "{\"password\":\"pïgéons1\"}"; + public static final String BTOA_PASSWORD = "cMOvZ8Opb25zMQ=="; + public static final int DESKTOP_ASSERTED_SIZE = 10; + public static final String DESKTOP_BASIC_AUTH = "Basic dXR2bTNtazZobm5naWlyMnNwNGpzeGYydXZveWNydjY6cMOvZ8Opb25zMQ=="; + + private String getCreds(String password) { + Header authenticate = new BasicAuthHeaderProvider(USERNAME, password).getAuthHeader(null, null, null); + return authenticate.getValue(); + } + + @SuppressWarnings("static-method") + @Test + public void testUTF8() throws UnsupportedEncodingException { + final String in = "pïgéons1"; + final String out = "pïgéons1"; + assertEquals(out, Utils.decodeUTF8(in)); + } + + @Test + public void testAuthHeaderFromPassword() throws NonObjectJSONException, IOException { + final ExtendedJSONObject parsed = new ExtendedJSONObject(DESKTOP_PASSWORD_JSON); + + final String password = parsed.getString("password"); + final String decoded = Utils.decodeUTF8(password); + + final byte[] expectedBytes = Utils.decodeBase64(BTOA_PASSWORD); + final String expected = new String(expectedBytes, "UTF-8"); + + assertEquals(DESKTOP_ASSERTED_SIZE, password.length()); + assertEquals(expected, decoded); + + System.out.println("Retrieved password: " + password); + System.out.println("Expected password: " + expected); + System.out.println("Rescued password: " + decoded); + + assertEquals(getCreds(expected), getCreds(decoded)); + assertEquals(getCreds(decoded), DESKTOP_BASIC_AUTH); + } + + // Note that we do *not* have a test for the J-PAKE setup process + // (SetupSyncActivity) that actually stores credentials and requires + // decodeUTF8. This will have to suffice. +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestGlobalSession.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestGlobalSession.java new file mode 100644 index 000000000..c00da9b26 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestGlobalSession.java @@ -0,0 +1,436 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import ch.boye.httpclientandroidlib.HttpResponse; +import ch.boye.httpclientandroidlib.ProtocolVersion; +import ch.boye.httpclientandroidlib.message.BasicHttpResponse; +import ch.boye.httpclientandroidlib.message.BasicStatusLine; +import junit.framework.AssertionFailedError; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockGlobalSessionCallback; +import org.mozilla.android.sync.test.helpers.MockResourceDelegate; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.testhelpers.MockAbstractNonRepositorySyncStage; +import org.mozilla.gecko.background.testhelpers.MockGlobalSession; +import org.mozilla.gecko.background.testhelpers.MockPrefsGlobalSession; +import org.mozilla.gecko.background.testhelpers.MockServerSyncStage; +import org.mozilla.gecko.background.testhelpers.MockSharedPreferences; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.EngineSettings; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.MetaGlobal; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.SyncConfiguration; +import org.mozilla.gecko.sync.SyncConfigurationException; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.mozilla.gecko.sync.repositories.domain.VersionConstants; +import org.mozilla.gecko.sync.stage.AndroidBrowserBookmarksServerSyncStage; +import org.mozilla.gecko.sync.stage.GlobalSyncStage; +import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; +import org.mozilla.gecko.sync.stage.NoSuchStageException; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestGlobalSession { + private int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private final String TEST_CLUSTER_URL = "http://localhost:" + TEST_PORT; + private final String TEST_USERNAME = "johndoe"; + private final String TEST_PASSWORD = "password"; + private final String TEST_SYNC_KEY = "abcdeabcdeabcdeabcdeabcdea"; + private final long TEST_BACKOFF_IN_SECONDS = 2401; + + public static WaitHelper getTestWaiter() { + return WaitHelper.getTestWaiter(); + } + + @Test + public void testGetSyncStagesBy() throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, CryptoException, NoSuchStageException { + + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + GlobalSession s = MockPrefsGlobalSession.getSession(TEST_USERNAME, TEST_PASSWORD, + new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY), + callback, /* context */ null, null); + + assertTrue(s.getSyncStageByName(Stage.syncBookmarks) instanceof AndroidBrowserBookmarksServerSyncStage); + + final Set empty = new HashSet(); + + final Set bookmarksAndTabsNames = new HashSet(); + bookmarksAndTabsNames.add("bookmarks"); + bookmarksAndTabsNames.add("tabs"); + + final Set bookmarksAndTabsSyncStages = new HashSet(); + GlobalSyncStage bookmarksStage = s.getSyncStageByName("bookmarks"); + GlobalSyncStage tabsStage = s.getSyncStageByName(Stage.syncTabs); + bookmarksAndTabsSyncStages.add(bookmarksStage); + bookmarksAndTabsSyncStages.add(tabsStage); + + final Set bookmarksAndTabsEnums = new HashSet(); + bookmarksAndTabsEnums.add(Stage.syncBookmarks); + bookmarksAndTabsEnums.add(Stage.syncTabs); + + assertTrue(s.getSyncStagesByName(empty).isEmpty()); + assertEquals(bookmarksAndTabsSyncStages, new HashSet(s.getSyncStagesByName(bookmarksAndTabsNames))); + assertEquals(bookmarksAndTabsSyncStages, new HashSet(s.getSyncStagesByEnum(bookmarksAndTabsEnums))); + } + + /** + * Test that handleHTTPError does in fact backoff. + */ + @Test + public void testBackoffCalledByHandleHTTPError() { + try { + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), new MockSharedPreferences(), new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY)); + final GlobalSession session = new MockGlobalSession(config, callback); + + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 503, "Illegal method/protocol")); + response.setHeader("X-Weave-Backoff", Long.toString(TEST_BACKOFF_IN_SECONDS)); // Backoff given in seconds. + + getTestWaiter().performWait(WaitHelper.onThreadRunnable(new Runnable() { + @Override + public void run() { + session.handleHTTPError(new SyncStorageResponse(response), "Illegal method/protocol"); + } + })); + + assertEquals(false, callback.calledSuccess); + assertEquals(true, callback.calledError); + assertEquals(false, callback.calledAborted); + assertEquals(true, callback.calledRequestBackoff); + assertEquals(TEST_BACKOFF_IN_SECONDS * 1000, callback.weaveBackoff); // Backoff returned in milliseconds. + } catch (Exception e) { + e.printStackTrace(); + fail("Got exception."); + } + } + + /** + * Test that a trivially successful GlobalSession does not fail or backoff. + */ + @Test + public void testSuccessCalledAfterStages() { + try { + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), new MockSharedPreferences(), new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY)); + final GlobalSession session = new MockGlobalSession(config, callback); + + getTestWaiter().performWait(WaitHelper.onThreadRunnable(new Runnable() { + @Override + public void run() { + try { + session.start(); + } catch (Exception e) { + final AssertionFailedError error = new AssertionFailedError(); + error.initCause(e); + getTestWaiter().performNotify(error); + } + } + })); + + assertEquals(true, callback.calledSuccess); + assertEquals(false, callback.calledError); + assertEquals(false, callback.calledAborted); + assertEquals(false, callback.calledRequestBackoff); + } catch (Exception e) { + e.printStackTrace(); + fail("Got exception."); + } + } + + /** + * Test that a failing GlobalSession does in fact fail and back off. + */ + @Test + public void testBackoffCalledInStages() { + try { + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + + // Stage fakes a 503 and sets X-Weave-Backoff header to the given seconds. + final GlobalSyncStage stage = new MockAbstractNonRepositorySyncStage() { + @Override + public void execute() { + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 503, "Illegal method/protocol")); + + response.addHeader("X-Weave-Backoff", Long.toString(TEST_BACKOFF_IN_SECONDS)); // Backoff given in seconds. + session.handleHTTPError(new SyncStorageResponse(response), "Failure fetching info/collections."); + } + }; + + // Session installs fake stage to fetch info/collections. + SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), new MockSharedPreferences(), new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY)); + final GlobalSession session = new MockGlobalSession(config, callback) + .withStage(Stage.fetchInfoCollections, stage); + + getTestWaiter().performWait(WaitHelper.onThreadRunnable(new Runnable() { + @Override + public void run() { + try { + session.start(); + } catch (Exception e) { + final AssertionFailedError error = new AssertionFailedError(); + error.initCause(e); + getTestWaiter().performNotify(error); + } + } + })); + + assertEquals(false, callback.calledSuccess); + assertEquals(true, callback.calledError); + assertEquals(false, callback.calledAborted); + assertEquals(true, callback.calledRequestBackoff); + assertEquals(TEST_BACKOFF_IN_SECONDS * 1000, callback.weaveBackoff); // Backoff returned in milliseconds. + } catch (Exception e) { + e.printStackTrace(); + fail("Got exception."); + } + } + + private HTTPServerTestHelper data = new HTTPServerTestHelper(); + + @SuppressWarnings("static-method") + @Before + public void setUp() { + BaseResource.rewriteLocalhost = false; + } + + public void doRequest() { + final WaitHelper innerWaitHelper = new WaitHelper(); + innerWaitHelper.performWait(new Runnable() { + @Override + public void run() { + try { + final BaseResource r = new BaseResource(TEST_CLUSTER_URL); + r.delegate = new MockResourceDelegate(innerWaitHelper); + r.get(); + } catch (URISyntaxException e) { + innerWaitHelper.performNotify(e); + } + } + }); + } + + public MockGlobalSessionCallback doTestSuccess(final boolean stageShouldBackoff, final boolean stageShouldAdvance) throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, CryptoException { + MockServer server = new MockServer() { + @Override + public void handle(Request request, Response response) { + if (stageShouldBackoff) { + response.addValue("X-Weave-Backoff", Long.toString(TEST_BACKOFF_IN_SECONDS)); + } + super.handle(request, response); + } + }; + + final MockServerSyncStage stage = new MockServerSyncStage() { + @Override + public void execute() { + // We should have installed our HTTP response observer before starting the sync. + assertTrue(BaseResource.isHttpResponseObserver(session)); + + doRequest(); + if (stageShouldAdvance) { + session.advance(); + return; + } + session.abort(null, "Stage intentionally failed."); + } + }; + + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), new MockSharedPreferences(), new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY)); + final GlobalSession session = new MockGlobalSession(config, callback) + .withStage(Stage.syncBookmarks, stage); + + data.startHTTPServer(server); + WaitHelper.getTestWaiter().performWait(WaitHelper.onThreadRunnable(new Runnable() { + @Override + public void run() { + try { + session.start(); + } catch (Exception e) { + final AssertionFailedError error = new AssertionFailedError(); + error.initCause(e); + WaitHelper.getTestWaiter().performNotify(error); + } + } + })); + data.stopHTTPServer(); + + // We should have uninstalled our HTTP response observer when the session is terminated. + assertFalse(BaseResource.isHttpResponseObserver(session)); + + return callback; + } + + @Test + public void testOnSuccessBackoffAdvanced() throws SyncConfigurationException, + IllegalArgumentException, NonObjectJSONException, IOException, + CryptoException { + MockGlobalSessionCallback callback = doTestSuccess(true, true); + + assertTrue(callback.calledError); // TODO: this should be calledAborted. + assertTrue(callback.calledRequestBackoff); + assertEquals(1000 * TEST_BACKOFF_IN_SECONDS, callback.weaveBackoff); + } + + @Test + public void testOnSuccessBackoffAborted() throws SyncConfigurationException, + IllegalArgumentException, NonObjectJSONException, IOException, + CryptoException { + MockGlobalSessionCallback callback = doTestSuccess(true, false); + + assertTrue(callback.calledError); // TODO: this should be calledAborted. + assertTrue(callback.calledRequestBackoff); + assertEquals(1000 * TEST_BACKOFF_IN_SECONDS, callback.weaveBackoff); + } + + @Test + public void testOnSuccessNoBackoffAdvanced() throws SyncConfigurationException, + IllegalArgumentException, NonObjectJSONException, IOException, + CryptoException { + MockGlobalSessionCallback callback = doTestSuccess(false, true); + + assertTrue(callback.calledSuccess); + assertFalse(callback.calledRequestBackoff); + } + + @Test + public void testOnSuccessNoBackoffAborted() throws SyncConfigurationException, + IllegalArgumentException, NonObjectJSONException, IOException, + CryptoException { + MockGlobalSessionCallback callback = doTestSuccess(false, false); + + assertTrue(callback.calledError); // TODO: this should be calledAborted. + assertFalse(callback.calledRequestBackoff); + } + + @Test + public void testGenerateNewMetaGlobalNonePersisted() throws Exception { + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + final GlobalSession session = MockPrefsGlobalSession.getSession(TEST_USERNAME, TEST_PASSWORD, + new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY), callback, null, null); + + // Verify we fill in all of our known engines when none are persisted. + session.config.enabledEngineNames = null; + MetaGlobal mg = session.generateNewMetaGlobal(); + assertEquals(Long.valueOf(GlobalSession.STORAGE_VERSION), mg.getStorageVersion()); + assertEquals(VersionConstants.BOOKMARKS_ENGINE_VERSION, mg.getEngines().getObject("bookmarks").getIntegerSafely("version").intValue()); + assertEquals(VersionConstants.CLIENTS_ENGINE_VERSION, mg.getEngines().getObject("clients").getIntegerSafely("version").intValue()); + + List namesList = new ArrayList(mg.getEnabledEngineNames()); + Collections.sort(namesList); + String[] names = namesList.toArray(new String[namesList.size()]); + String[] expected = new String[] { "bookmarks", "clients", "forms", "history", "passwords", "tabs" }; + assertArrayEquals(expected, names); + } + + @Test + public void testGenerateNewMetaGlobalSomePersisted() throws Exception { + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + final GlobalSession session = MockPrefsGlobalSession.getSession(TEST_USERNAME, TEST_PASSWORD, + new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY), callback, null, null); + + // Verify we preserve engines with version 0 if some are persisted. + session.config.enabledEngineNames = new HashSet(); + session.config.enabledEngineNames.add("bookmarks"); + session.config.enabledEngineNames.add("clients"); + session.config.enabledEngineNames.add("addons"); + session.config.enabledEngineNames.add("prefs"); + + MetaGlobal mg = session.generateNewMetaGlobal(); + assertEquals(Long.valueOf(GlobalSession.STORAGE_VERSION), mg.getStorageVersion()); + assertEquals(VersionConstants.BOOKMARKS_ENGINE_VERSION, mg.getEngines().getObject("bookmarks").getIntegerSafely("version").intValue()); + assertEquals(VersionConstants.CLIENTS_ENGINE_VERSION, mg.getEngines().getObject("clients").getIntegerSafely("version").intValue()); + assertEquals(0, mg.getEngines().getObject("addons").getIntegerSafely("version").intValue()); + assertEquals(0, mg.getEngines().getObject("prefs").getIntegerSafely("version").intValue()); + + List namesList = new ArrayList(mg.getEnabledEngineNames()); + Collections.sort(namesList); + String[] names = namesList.toArray(new String[namesList.size()]); + String[] expected = new String[] { "addons", "bookmarks", "clients", "prefs" }; + assertArrayEquals(expected, names); + } + + @Test + public void testUploadUpdatedMetaGlobal() throws Exception { + // Set up session with meta/global. + final MockGlobalSessionCallback callback = new MockGlobalSessionCallback(); + final GlobalSession session = MockPrefsGlobalSession.getSession(TEST_USERNAME, TEST_PASSWORD, + new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY), callback, null, null); + session.config.metaGlobal = session.generateNewMetaGlobal(); + session.enginesToUpdate.clear(); + + // Set enabledEngines in meta/global, including a "new engine." + String[] origEngines = new String[] { "bookmarks", "clients", "forms", "history", "tabs", "new-engine" }; + + ExtendedJSONObject origEnginesJSONObject = new ExtendedJSONObject(); + for (String engineName : origEngines) { + EngineSettings mockEngineSettings = new EngineSettings(Utils.generateGuid(), Integer.valueOf(0)); + origEnginesJSONObject.put(engineName, mockEngineSettings.toJSONObject()); + } + session.config.metaGlobal.setEngines(origEnginesJSONObject); + + // Engines to remove. + String[] toRemove = new String[] { "bookmarks", "tabs" }; + for (String name : toRemove) { + session.removeEngineFromMetaGlobal(name); + } + + // Engines to add. + String[] toAdd = new String[] { "passwords" }; + for (String name : toAdd) { + String syncId = Utils.generateGuid(); + session.recordForMetaGlobalUpdate(name, new EngineSettings(syncId, Integer.valueOf(1))); + } + + // Update engines. + session.uploadUpdatedMetaGlobal(); + + // Check resulting enabledEngines. + Set expected = new HashSet(); + for (String name : origEngines) { + expected.add(name); + } + for (String name : toRemove) { + expected.remove(name); + } + for (String name : toAdd) { + expected.add(name); + } + assertEquals(expected, session.config.metaGlobal.getEnabledEngineNames()); + } + + public void testStageAdvance() { + assertEquals(GlobalSession.nextStage(Stage.idle), Stage.checkPreconditions); + assertEquals(GlobalSession.nextStage(Stage.completed), Stage.idle); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestHeaderParsing.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestHeaderParsing.java new file mode 100644 index 000000000..532d60d13 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestHeaderParsing.java @@ -0,0 +1,29 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.Utils; + +import static org.junit.Assert.assertEquals; + +@RunWith(TestRunner.class) +public class TestHeaderParsing { + + @SuppressWarnings("static-method") + @Test + public void testDecimalSecondsToMilliseconds() { + assertEquals(Utils.decimalSecondsToMilliseconds(""), -1); + assertEquals(Utils.decimalSecondsToMilliseconds("1234.1.1"), -1); + assertEquals(Utils.decimalSecondsToMilliseconds("1234"), 1234000); + assertEquals(Utils.decimalSecondsToMilliseconds("1234.123"), 1234123); + assertEquals(Utils.decimalSecondsToMilliseconds("1234.12"), 1234120); + + assertEquals("1234.000", Utils.millisecondsToDecimalSecondsString(1234000)); + assertEquals("1234.123", Utils.millisecondsToDecimalSecondsString(1234123)); + assertEquals("1234.120", Utils.millisecondsToDecimalSecondsString(1234120)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestLineByLineHandling.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestLineByLineHandling.java new file mode 100644 index 000000000..b7f11adbf --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestLineByLineHandling.java @@ -0,0 +1,115 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.SyncStorageCollectionRequest; +import org.mozilla.gecko.sync.net.SyncStorageCollectionRequestDelegate; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.io.IOException; +import java.io.PrintStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestLineByLineHandling { + private static final int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private static final String TEST_SERVER = "http://localhost:" + TEST_PORT; + private static final String LOG_TAG = "TestLineByLineHandling"; + static String STORAGE_URL = TEST_SERVER + "/1.1/c6o7dvmr2c4ud2fyv6woz2u4zi22bcyd/storage/lines"; + private HTTPServerTestHelper data = new HTTPServerTestHelper(); + + public ArrayList lines = new ArrayList(); + + public class LineByLineMockServer extends MockServer { + public void handle(Request request, Response response) { + try { + System.out.println("Handling line-by-line request..."); + PrintStream bodyStream = this.handleBasicHeaders(request, response, 200, "application/newlines"); + + bodyStream.print("First line.\n"); + bodyStream.print("Second line.\n"); + bodyStream.print("Third line.\n"); + bodyStream.print("Fourth line.\n"); + bodyStream.close(); + } catch (IOException e) { + System.err.println("Oops."); + } + } + } + + public class BaseLineByLineDelegate extends + SyncStorageCollectionRequestDelegate { + + @Override + public void handleRequestProgress(String progress) { + lines.add(progress); + } + + @Override + public AuthHeaderProvider getAuthHeaderProvider() { + return null; + } + + @Override + public String ifUnmodifiedSince() { + return null; + } + + @Override + public void handleRequestSuccess(SyncStorageResponse res) { + Logger.info(LOG_TAG, "Request success."); + assertTrue(res.wasSuccessful()); + assertTrue(res.httpResponse().containsHeader("X-Weave-Timestamp")); + + assertEquals(lines.size(), 4); + assertEquals(lines.get(0), "First line."); + assertEquals(lines.get(1), "Second line."); + assertEquals(lines.get(2), "Third line."); + assertEquals(lines.get(3), "Fourth line."); + data.stopHTTPServer(); + } + + @Override + public void handleRequestFailure(SyncStorageResponse response) { + Logger.info(LOG_TAG, "Got request failure: " + response); + BaseResource.consumeEntity(response); + fail("Should not be called."); + } + + @Override + public void handleRequestError(Exception ex) { + Logger.error(LOG_TAG, "Got request error: ", ex); + fail("Should not be called."); + } + } + + @Test + public void testLineByLine() throws URISyntaxException { + BaseResource.rewriteLocalhost = false; + + data.startHTTPServer(new LineByLineMockServer()); + Logger.info(LOG_TAG, "Server started."); + SyncStorageCollectionRequest r = new SyncStorageCollectionRequest(new URI(STORAGE_URL)); + SyncStorageCollectionRequestDelegate delegate = new BaseLineByLineDelegate(); + r.delegate = delegate; + r.get(); + // Server is stopped in the callback. + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestMetaGlobal.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestMetaGlobal.java new file mode 100644 index 000000000..ec4c03859 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestMetaGlobal.java @@ -0,0 +1,347 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.MetaGlobal; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.delegates.MetaGlobalDelegate; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestMetaGlobal { + private static final int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private static final String TEST_SERVER = "http://localhost:" + TEST_PORT; + private static final String TEST_SYNC_ID = "foobar"; + + public static final String USER_PASS = "c6o7dvmr2c4ud2fyv6woz2u4zi22bcyd:password"; + public static final String META_URL = TEST_SERVER + "/1.1/c6o7dvmr2c4ud2fyv6woz2u4zi22bcyd/storage/meta/global"; + private HTTPServerTestHelper data = new HTTPServerTestHelper(); + + + public static final String TEST_DECLINED_META_GLOBAL_RESPONSE = + "{\"id\":\"global\"," + + "\"payload\":" + + "\"{\\\"syncID\\\":\\\"zPSQTm7WBVWB\\\"," + + "\\\"declined\\\":[\\\"bookmarks\\\"]," + + "\\\"storageVersion\\\":5," + + "\\\"engines\\\":{" + + "\\\"clients\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"fDg0MS5bDtV7\\\"}," + + "\\\"forms\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"GXF29AFprnvc\\\"}," + + "\\\"history\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"av75g4vm-_rp\\\"}," + + "\\\"passwords\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"LT_ACGpuKZ6a\\\"}," + + "\\\"prefs\\\":{\\\"version\\\":2,\\\"syncID\\\":\\\"-3nsksP9wSAs\\\"}," + + "\\\"tabs\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"W4H5lOMChkYA\\\"}}}\"," + + "\"username\":\"5817483\"," + + "\"modified\":1.32046073744E9}"; + + public static final String TEST_META_GLOBAL_RESPONSE = + "{\"id\":\"global\"," + + "\"payload\":" + + "\"{\\\"syncID\\\":\\\"zPSQTm7WBVWB\\\"," + + "\\\"storageVersion\\\":5," + + "\\\"engines\\\":{" + + "\\\"clients\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"fDg0MS5bDtV7\\\"}," + + "\\\"bookmarks\\\":{\\\"version\\\":2,\\\"syncID\\\":\\\"NNaQr6_F-9dm\\\"}," + + "\\\"forms\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"GXF29AFprnvc\\\"}," + + "\\\"history\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"av75g4vm-_rp\\\"}," + + "\\\"passwords\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"LT_ACGpuKZ6a\\\"}," + + "\\\"prefs\\\":{\\\"version\\\":2,\\\"syncID\\\":\\\"-3nsksP9wSAs\\\"}," + + "\\\"tabs\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"W4H5lOMChkYA\\\"}}}\"," + + "\"username\":\"5817483\"," + + "\"modified\":1.32046073744E9}"; + public static final String TEST_META_GLOBAL_NO_PAYLOAD_RESPONSE = "{\"id\":\"global\"," + + "\"username\":\"5817483\",\"modified\":1.32046073744E9}"; + public static final String TEST_META_GLOBAL_MALFORMED_PAYLOAD_RESPONSE = "{\"id\":\"global\"," + + "\"payload\":\"{!!!}\"," + + "\"username\":\"5817483\",\"modified\":1.32046073744E9}"; + public static final String TEST_META_GLOBAL_EMPTY_PAYLOAD_RESPONSE = "{\"id\":\"global\"," + + "\"payload\":\"{}\"," + + "\"username\":\"5817483\",\"modified\":1.32046073744E9}"; + + public MetaGlobal global; + + @SuppressWarnings("static-method") + @Before + public void setUp() { + BaseResource.rewriteLocalhost = false; + global = new MetaGlobal(META_URL, new BasicAuthHeaderProvider(USER_PASS)); + } + + @SuppressWarnings("static-method") + @Test + public void testSyncID() { + global.setSyncID("foobar"); + assertEquals(global.getSyncID(), "foobar"); + } + + public class MockMetaGlobalFetchDelegate implements MetaGlobalDelegate { + boolean successCalled = false; + MetaGlobal successGlobal = null; + SyncStorageResponse successResponse = null; + boolean failureCalled = false; + SyncStorageResponse failureResponse = null; + boolean errorCalled = false; + Exception errorException = null; + boolean missingCalled = false; + MetaGlobal missingGlobal = null; + SyncStorageResponse missingResponse = null; + + public void handleSuccess(MetaGlobal global, SyncStorageResponse response) { + successCalled = true; + successGlobal = global; + successResponse = response; + WaitHelper.getTestWaiter().performNotify(); + } + + public void handleFailure(SyncStorageResponse response) { + failureCalled = true; + failureResponse = response; + WaitHelper.getTestWaiter().performNotify(); + } + + public void handleError(Exception e) { + errorCalled = true; + errorException = e; + WaitHelper.getTestWaiter().performNotify(); + } + + public void handleMissing(MetaGlobal global, SyncStorageResponse response) { + missingCalled = true; + missingGlobal = global; + missingResponse = response; + WaitHelper.getTestWaiter().performNotify(); + } + } + + public MockMetaGlobalFetchDelegate doFetch(final MetaGlobal global) { + final MockMetaGlobalFetchDelegate delegate = new MockMetaGlobalFetchDelegate(); + WaitHelper.getTestWaiter().performWait(WaitHelper.onThreadRunnable(new Runnable() { + @Override + public void run() { + global.fetch(delegate); + } + })); + + return delegate; + } + + @Test + public void testFetchMissing() { + MockServer missingMetaGlobalServer = new MockServer(404, "{}"); + global.setSyncID(TEST_SYNC_ID); + assertEquals(TEST_SYNC_ID, global.getSyncID()); + + data.startHTTPServer(missingMetaGlobalServer); + final MockMetaGlobalFetchDelegate delegate = doFetch(global); + data.stopHTTPServer(); + + assertTrue(delegate.missingCalled); + assertEquals(404, delegate.missingResponse.getStatusCode()); + assertEquals(TEST_SYNC_ID, delegate.missingGlobal.getSyncID()); + } + + @Test + public void testFetchExisting() { + MockServer existingMetaGlobalServer = new MockServer(200, TEST_META_GLOBAL_RESPONSE); + assertNull(global.getSyncID()); + assertNull(global.getEngines()); + assertNull(global.getStorageVersion()); + + data.startHTTPServer(existingMetaGlobalServer); + final MockMetaGlobalFetchDelegate delegate = doFetch(global); + data.stopHTTPServer(); + + assertTrue(delegate.successCalled); + assertEquals(200, delegate.successResponse.getStatusCode()); + assertEquals("zPSQTm7WBVWB", global.getSyncID()); + assertTrue(global.getEngines() instanceof ExtendedJSONObject); + assertEquals(Long.valueOf(5), global.getStorageVersion()); + } + + /** + * A record that is valid JSON but invalid as a meta/global record will be + * downloaded successfully, but will fail later. + */ + @Test + public void testFetchNoPayload() { + MockServer existingMetaGlobalServer = new MockServer(200, TEST_META_GLOBAL_NO_PAYLOAD_RESPONSE); + + data.startHTTPServer(existingMetaGlobalServer); + final MockMetaGlobalFetchDelegate delegate = doFetch(global); + data.stopHTTPServer(); + + assertTrue(delegate.successCalled); + } + + @Test + public void testFetchEmptyPayload() { + MockServer existingMetaGlobalServer = new MockServer(200, TEST_META_GLOBAL_EMPTY_PAYLOAD_RESPONSE); + + data.startHTTPServer(existingMetaGlobalServer); + final MockMetaGlobalFetchDelegate delegate = doFetch(global); + data.stopHTTPServer(); + + assertTrue(delegate.successCalled); + } + + /** + * A record that is invalid JSON will fail to download at all. + */ + @Test + public void testFetchMalformedPayload() { + MockServer existingMetaGlobalServer = new MockServer(200, TEST_META_GLOBAL_MALFORMED_PAYLOAD_RESPONSE); + + data.startHTTPServer(existingMetaGlobalServer); + final MockMetaGlobalFetchDelegate delegate = doFetch(global); + data.stopHTTPServer(); + + assertTrue(delegate.errorCalled); + assertNotNull(delegate.errorException); + assertEquals(NonObjectJSONException.class, delegate.errorException.getClass()); + } + + @SuppressWarnings("static-method") + @Test + public void testSetFromRecord() throws Exception { + MetaGlobal mg = new MetaGlobal(null, null); + mg.setFromRecord(CryptoRecord.fromJSONRecord(TEST_META_GLOBAL_RESPONSE)); + assertEquals("zPSQTm7WBVWB", mg.getSyncID()); + assertTrue(mg.getEngines() instanceof ExtendedJSONObject); + assertEquals(Long.valueOf(5), mg.getStorageVersion()); + } + + @SuppressWarnings("static-method") + @Test + public void testAsCryptoRecord() throws Exception { + MetaGlobal mg = new MetaGlobal(null, null); + mg.setFromRecord(CryptoRecord.fromJSONRecord(TEST_META_GLOBAL_RESPONSE)); + CryptoRecord rec = mg.asCryptoRecord(); + assertEquals("global", rec.guid); + mg.setFromRecord(rec); + assertEquals("zPSQTm7WBVWB", mg.getSyncID()); + assertTrue(mg.getEngines() instanceof ExtendedJSONObject); + assertEquals(Long.valueOf(5), mg.getStorageVersion()); + } + + @SuppressWarnings("static-method") + @Test + public void testGetEnabledEngineNames() throws Exception { + MetaGlobal mg = new MetaGlobal(null, null); + mg.setFromRecord(CryptoRecord.fromJSONRecord(TEST_META_GLOBAL_RESPONSE)); + assertEquals("zPSQTm7WBVWB", mg.getSyncID()); + final Set actual = mg.getEnabledEngineNames(); + final Set expected = new HashSet(); + for (String name : new String[] { "bookmarks", "clients", "forms", "history", "passwords", "prefs", "tabs" }) { + expected.add(name); + } + assertEquals(expected, actual); + } + + @SuppressWarnings("static-method") + @Test + public void testGetEmptyDeclinedEngineNames() throws Exception { + MetaGlobal mg = new MetaGlobal(null, null); + mg.setFromRecord(CryptoRecord.fromJSONRecord(TEST_META_GLOBAL_RESPONSE)); + assertEquals(0, mg.getDeclinedEngineNames().size()); + } + + @SuppressWarnings("static-method") + @Test + public void testGetDeclinedEngineNames() throws Exception { + MetaGlobal mg = new MetaGlobal(null, null); + mg.setFromRecord(CryptoRecord.fromJSONRecord(TEST_DECLINED_META_GLOBAL_RESPONSE)); + assertEquals(1, mg.getDeclinedEngineNames().size()); + assertEquals("bookmarks", mg.getDeclinedEngineNames().iterator().next()); + } + + @SuppressWarnings("static-method") + @Test + public void testRoundtripDeclinedEngineNames() throws Exception { + MetaGlobal mg = new MetaGlobal(null, null); + mg.setFromRecord(CryptoRecord.fromJSONRecord(TEST_DECLINED_META_GLOBAL_RESPONSE)); + assertEquals("bookmarks", mg.getDeclinedEngineNames().iterator().next()); + assertEquals("bookmarks", mg.asCryptoRecord().payload.getArray("declined").get(0)); + MetaGlobal again = new MetaGlobal(null, null); + again.setFromRecord(mg.asCryptoRecord()); + assertEquals("bookmarks", again.getDeclinedEngineNames().iterator().next()); + } + + + public MockMetaGlobalFetchDelegate doUpload(final MetaGlobal global) { + final MockMetaGlobalFetchDelegate delegate = new MockMetaGlobalFetchDelegate(); + WaitHelper.getTestWaiter().performWait(WaitHelper.onThreadRunnable(new Runnable() { + @Override + public void run() { + global.upload(delegate); + } + })); + + return delegate; + } + + @Test + public void testUpload() { + long TEST_STORAGE_VERSION = 111; + String TEST_SYNC_ID = "testSyncID"; + global.setSyncID(TEST_SYNC_ID); + global.setStorageVersion(Long.valueOf(TEST_STORAGE_VERSION)); + + final AtomicBoolean mgUploaded = new AtomicBoolean(false); + final MetaGlobal uploadedMg = new MetaGlobal(null, null); + + MockServer server = new MockServer() { + public void handle(Request request, Response response) { + if (request.getMethod().equals("PUT")) { + try { + ExtendedJSONObject body = new ExtendedJSONObject(request.getContent()); + System.out.println(body.toJSONString()); + assertTrue(body.containsKey("payload")); + assertFalse(body.containsKey("default")); + + CryptoRecord rec = CryptoRecord.fromJSONRecord(body); + uploadedMg.setFromRecord(rec); + mgUploaded.set(true); + } catch (Exception e) { + throw new RuntimeException(e); + } + this.handle(request, response, 200, "success"); + return; + } + this.handle(request, response, 404, "missing"); + } + }; + + data.startHTTPServer(server); + final MockMetaGlobalFetchDelegate delegate = doUpload(global); + data.stopHTTPServer(); + + assertTrue(delegate.successCalled); + assertTrue(mgUploaded.get()); + assertEquals(TEST_SYNC_ID, uploadedMg.getSyncID()); + assertEquals(TEST_STORAGE_VERSION, uploadedMg.getStorageVersion().longValue()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestResource.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestResource.java new file mode 100644 index 000000000..e53d02d33 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestResource.java @@ -0,0 +1,102 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import ch.boye.httpclientandroidlib.HttpResponse; +import ch.boye.httpclientandroidlib.client.methods.HttpUriRequest; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockResourceDelegate; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.HttpResponseObserver; + +import java.net.URISyntaxException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestResource { + private static final int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private static final String TEST_SERVER = "http://localhost:" + TEST_PORT; + + private HTTPServerTestHelper data = new HTTPServerTestHelper(); + + @SuppressWarnings("static-method") + @Before + public void setUp() { + BaseResource.rewriteLocalhost = false; + } + + @SuppressWarnings("static-method") + @Test + public void testLocalhostRewriting() throws URISyntaxException { + BaseResource r = new BaseResource("http://localhost:5000/foo/bar", true); + assertEquals("http://10.0.2.2:5000/foo/bar", r.getURI().toASCIIString()); + } + + @SuppressWarnings("static-method") + public MockResourceDelegate doGet() throws URISyntaxException { + final BaseResource r = new BaseResource(TEST_SERVER + "/foo/bar"); + MockResourceDelegate delegate = new MockResourceDelegate(); + r.delegate = delegate; + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + r.get(); + } + }); + return delegate; + } + + @Test + public void testTrivialFetch() throws URISyntaxException { + MockServer server = data.startHTTPServer(); + server.expectedBasicAuthHeader = MockResourceDelegate.EXPECT_BASIC; + MockResourceDelegate delegate = doGet(); + assertTrue(delegate.handledHttpResponse); + data.stopHTTPServer(); + } + + public static class MockHttpResponseObserver implements HttpResponseObserver { + public HttpResponse response = null; + + @Override + public void observeHttpResponse(HttpUriRequest request, HttpResponse response) { + this.response = response; + } + } + + @Test + public void testObservers() throws URISyntaxException { + data.startHTTPServer(); + // Check that null observer doesn't fail. + BaseResource.addHttpResponseObserver(null); + doGet(); // HTTP server stopped in callback. + + // Check that multiple non-null observers gets called with reasonable HttpResponse. + MockHttpResponseObserver observers[] = { new MockHttpResponseObserver(), new MockHttpResponseObserver() }; + for (MockHttpResponseObserver observer : observers) { + BaseResource.addHttpResponseObserver(observer); + assertTrue(BaseResource.isHttpResponseObserver(observer)); + assertNull(observer.response); + } + + doGet(); // HTTP server stopped in callback. + + for (MockHttpResponseObserver observer : observers) { + assertNotNull(observer.response); + assertEquals(200, observer.response.getStatusLine().getStatusCode()); + } + + data.stopHTTPServer(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestRetryAfter.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestRetryAfter.java new file mode 100644 index 000000000..429ad29d4 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestRetryAfter.java @@ -0,0 +1,87 @@ +package org.mozilla.android.sync.net.test; + +import ch.boye.httpclientandroidlib.HttpResponse; +import ch.boye.httpclientandroidlib.ProtocolVersion; +import ch.boye.httpclientandroidlib.impl.cookie.DateUtils; +import ch.boye.httpclientandroidlib.message.BasicHttpResponse; +import ch.boye.httpclientandroidlib.message.BasicStatusLine; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.net.SyncResponse; + +import java.util.Date; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestRetryAfter { + private int TEST_SECONDS = 120; + + @Test + public void testRetryAfterParsesSeconds() { + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 503, "Illegal method/protocol")); + response.addHeader("Retry-After", Long.toString(TEST_SECONDS)); // Retry-After given in seconds. + + final SyncResponse syncResponse = new SyncResponse(response); + assertEquals(TEST_SECONDS, syncResponse.retryAfterInSeconds()); + } + + @Test + public void testRetryAfterParsesHTTPDate() { + Date future = new Date(System.currentTimeMillis() + TEST_SECONDS * 1000); + + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 503, "Illegal method/protocol")); + response.addHeader("Retry-After", DateUtils.formatDate(future)); + + final SyncResponse syncResponse = new SyncResponse(response); + assertTrue(syncResponse.retryAfterInSeconds() > TEST_SECONDS - 15); + assertTrue(syncResponse.retryAfterInSeconds() < TEST_SECONDS + 15); + } + + @SuppressWarnings("static-method") + @Test + public void testRetryAfterParsesMalformed() { + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 503, "Illegal method/protocol")); + response.addHeader("Retry-After", "10X"); + + final SyncResponse syncResponse = new SyncResponse(response); + assertEquals(-1, syncResponse.retryAfterInSeconds()); + } + + @SuppressWarnings("static-method") + @Test + public void testRetryAfterParsesNeither() { + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 503, "Illegal method/protocol")); + + final SyncResponse syncResponse = new SyncResponse(response); + assertEquals(-1, syncResponse.retryAfterInSeconds()); + } + + @Test + public void testRetryAfterParsesLargerRetryAfter() { + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 503, "Illegal method/protocol")); + response.addHeader("Retry-After", Long.toString(TEST_SECONDS + 1)); + response.addHeader("X-Weave-Backoff", Long.toString(TEST_SECONDS)); + + final SyncResponse syncResponse = new SyncResponse(response); + assertEquals(1000 * (TEST_SECONDS + 1), syncResponse.totalBackoffInMilliseconds()); + } + + @Test + public void testRetryAfterParsesLargerXWeaveBackoff() { + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 503, "Illegal method/protocol")); + response.addHeader("Retry-After", Long.toString(TEST_SECONDS)); + response.addHeader("X-Weave-Backoff", Long.toString(TEST_SECONDS + 1)); + + final SyncResponse syncResponse = new SyncResponse(response); + assertEquals(1000 * (TEST_SECONDS + 1), syncResponse.totalBackoffInMilliseconds()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestServer11Repository.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestServer11Repository.java new file mode 100644 index 000000000..3aa0a91ec --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestServer11Repository.java @@ -0,0 +1,48 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.InfoCollections; +import org.mozilla.gecko.sync.InfoConfiguration; +import org.mozilla.gecko.sync.repositories.Server11Repository; + +import java.net.URI; +import java.net.URISyntaxException; + +@RunWith(TestRunner.class) +public class TestServer11Repository { + + private static final String COLLECTION = "bookmarks"; + private static final String COLLECTION_URL = "http://foo.com/1.1/n6ec3u5bee3tixzp2asys7bs6fve4jfw/storage"; + + protected final InfoCollections infoCollections = new InfoCollections(); + protected final InfoConfiguration infoConfiguration = new InfoConfiguration(); + + public static void assertQueryEquals(String expected, URI u) { + Assert.assertEquals(expected, u.getRawQuery()); + } + + @SuppressWarnings("static-method") + @Test + public void testCollectionURIFull() throws URISyntaxException { + Server11Repository r = new Server11Repository(COLLECTION, COLLECTION_URL, null, infoCollections, infoConfiguration); + assertQueryEquals("full=1&newer=5000.000", r.collectionURI(true, 5000000L, -1, null, null, null)); + assertQueryEquals("newer=1230.000", r.collectionURI(false, 1230000L, -1, null, null, null)); + assertQueryEquals("newer=5000.000&limit=10", r.collectionURI(false, 5000000L, 10, null, null, null)); + assertQueryEquals("full=1&newer=5000.000&sort=index", r.collectionURI(true, 5000000L, 0, "index", null, null)); + assertQueryEquals("full=1&ids=123,abc", r.collectionURI(true, -1L, -1, null, "123,abc", null)); + } + + @Test + public void testCollectionURI() throws URISyntaxException { + Server11Repository noTrailingSlash = new Server11Repository(COLLECTION, COLLECTION_URL, null, infoCollections, infoConfiguration); + Server11Repository trailingSlash = new Server11Repository(COLLECTION, COLLECTION_URL + "/", null, infoCollections, infoConfiguration); + Assert.assertEquals("http://foo.com/1.1/n6ec3u5bee3tixzp2asys7bs6fve4jfw/storage/bookmarks", noTrailingSlash.collectionURI().toASCIIString()); + Assert.assertEquals("http://foo.com/1.1/n6ec3u5bee3tixzp2asys7bs6fve4jfw/storage/bookmarks", trailingSlash.collectionURI().toASCIIString()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestSyncStorageRequest.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestSyncStorageRequest.java new file mode 100644 index 000000000..0e6447c27 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/net/test/TestSyncStorageRequest.java @@ -0,0 +1,269 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.net.test; + +import org.json.simple.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.BaseTestStorageRequestDelegate; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.net.SyncStorageRecordRequest; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestSyncStorageRequest { + private static final int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private static final String TEST_SERVER = "http://localhost:" + TEST_PORT; + + private static final String LOCAL_META_URL = TEST_SERVER + "/1.1/c6o7dvmr2c4ud2fyv6woz2u4zi22bcyd/storage/meta/global"; + private static final String LOCAL_BAD_REQUEST_URL = TEST_SERVER + "/1.1/c6o7dvmr2c4ud2fyv6woz2u4zi22bcyd/storage/bad"; + + private static final String EXPECTED_ERROR_CODE = "12"; + private static final String EXPECTED_RETRY_AFTER_ERROR_MESSAGE = "{error:'informative error message'}"; + + // Corresponds to rnewman+testandroid@mozilla.com. + private static final String TEST_USERNAME = "c6o7dvmr2c4ud2fyv6woz2u4zi22bcyd"; + private static final String TEST_PASSWORD = "password"; + private final AuthHeaderProvider authHeaderProvider = new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD); + + private HTTPServerTestHelper data = new HTTPServerTestHelper(); + + public class TestSyncStorageRequestDelegate extends + BaseTestStorageRequestDelegate { + public TestSyncStorageRequestDelegate(AuthHeaderProvider authHeaderProvider) { + super(authHeaderProvider); + } + + @Override + public void handleRequestSuccess(SyncStorageResponse res) { + assertTrue(res.wasSuccessful()); + assertTrue(res.httpResponse().containsHeader("X-Weave-Timestamp")); + + // Make sure we consume the rest of the body, so we can reuse the + // connection. Even test code has to be correct in this regard! + try { + System.out.println("Success body: " + res.body()); + } catch (Exception e) { + e.printStackTrace(); + } + BaseResource.consumeEntity(res); + data.stopHTTPServer(); + } + } + + public class TestBadSyncStorageRequestDelegate extends + BaseTestStorageRequestDelegate { + + public TestBadSyncStorageRequestDelegate(AuthHeaderProvider authHeaderProvider) { + super(authHeaderProvider); + } + + @Override + public void handleRequestFailure(SyncStorageResponse res) { + assertTrue(!res.wasSuccessful()); + assertTrue(res.httpResponse().containsHeader("X-Weave-Timestamp")); + try { + String responseMessage = res.getErrorMessage(); + String expectedMessage = SyncStorageResponse.SERVER_ERROR_MESSAGES.get(EXPECTED_ERROR_CODE); + assertEquals(expectedMessage, responseMessage); + } catch (Exception e) { + fail("Got exception fetching error message."); + } + BaseResource.consumeEntity(res); + data.stopHTTPServer(); + } + } + + + @Test + public void testSyncStorageRequest() throws URISyntaxException, IOException { + BaseResource.rewriteLocalhost = false; + data.startHTTPServer(); + SyncStorageRecordRequest r = new SyncStorageRecordRequest(new URI(LOCAL_META_URL)); + TestSyncStorageRequestDelegate delegate = new TestSyncStorageRequestDelegate(authHeaderProvider); + r.delegate = delegate; + r.get(); + // Server is stopped in the callback. + } + + public class ErrorMockServer extends MockServer { + @Override + public void handle(Request request, Response response) { + super.handle(request, response, 400, EXPECTED_ERROR_CODE); + } + } + + @Test + public void testErrorResponse() throws URISyntaxException { + BaseResource.rewriteLocalhost = false; + data.startHTTPServer(new ErrorMockServer()); + SyncStorageRecordRequest r = new SyncStorageRecordRequest(new URI(LOCAL_BAD_REQUEST_URL)); + TestBadSyncStorageRequestDelegate delegate = new TestBadSyncStorageRequestDelegate(authHeaderProvider); + r.delegate = delegate; + r.post(new JSONObject()); + // Server is stopped in the callback. + } + + // Test that the Retry-After header is correctly parsed and that handleRequestFailure + // is being called. + public class TestRetryAfterSyncStorageRequestDelegate extends BaseTestStorageRequestDelegate { + + public TestRetryAfterSyncStorageRequestDelegate(AuthHeaderProvider authHeaderProvider) { + super(authHeaderProvider); + } + + @Override + public void handleRequestFailure(SyncStorageResponse res) { + assertTrue(!res.wasSuccessful()); + assertTrue(res.httpResponse().containsHeader("Retry-After")); + assertEquals(res.retryAfterInSeconds(), 3001); + try { + String responseMessage = res.getErrorMessage(); + String expectedMessage = EXPECTED_RETRY_AFTER_ERROR_MESSAGE; + assertEquals(expectedMessage, responseMessage); + } catch (Exception e) { + fail("Got exception fetching error message."); + } + BaseResource.consumeEntity(res); + data.stopHTTPServer(); + } + } + + public class RetryAfterMockServer extends MockServer { + @Override + public void handle(Request request, Response response) { + String errorBody = EXPECTED_RETRY_AFTER_ERROR_MESSAGE; + response.setValue("Retry-After", "3001"); + super.handle(request, response, 503, errorBody); + } + } + + @Test + public void testRetryAfterResponse() throws URISyntaxException { + BaseResource.rewriteLocalhost = false; + data.startHTTPServer(new RetryAfterMockServer()); + SyncStorageRecordRequest r = new SyncStorageRecordRequest(new URI(LOCAL_BAD_REQUEST_URL)); // URL not used -- we 503 every response + TestRetryAfterSyncStorageRequestDelegate delegate = new TestRetryAfterSyncStorageRequestDelegate(authHeaderProvider); + r.delegate = delegate; + r.post(new JSONObject()); + // Server is stopped in the callback. + } + + // Test that the X-Weave-Backoff header is correctly parsed and that handleRequestSuccess + // is still being called. + public class TestWeaveBackoffSyncStorageRequestDelegate extends + TestSyncStorageRequestDelegate { + + public TestWeaveBackoffSyncStorageRequestDelegate(AuthHeaderProvider authHeaderProvider) { + super(authHeaderProvider); + } + + @Override + public void handleRequestSuccess(SyncStorageResponse res) { + assertTrue(res.httpResponse().containsHeader("X-Weave-Backoff")); + assertEquals(res.weaveBackoffInSeconds(), 1801); + super.handleRequestSuccess(res); + } + } + + public class WeaveBackoffMockServer extends MockServer { + @Override + public void handle(Request request, Response response) { + response.setValue("X-Weave-Backoff", "1801"); + super.handle(request, response); + } + } + + @Test + public void testWeaveBackoffResponse() throws URISyntaxException { + BaseResource.rewriteLocalhost = false; + data.startHTTPServer(new WeaveBackoffMockServer()); + SyncStorageRecordRequest r = new SyncStorageRecordRequest(new URI(LOCAL_META_URL)); // URL re-used -- we need any successful response + TestWeaveBackoffSyncStorageRequestDelegate delegate = new TestWeaveBackoffSyncStorageRequestDelegate(new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD)); + r.delegate = delegate; + r.post(new JSONObject()); + // Server is stopped in the callback. + } + + // Test that the X-Weave-{Quota-Remaining, Alert, Records} headers are correctly parsed and + // that handleRequestSuccess is still being called. + public class TestHeadersSyncStorageRequestDelegate extends + TestSyncStorageRequestDelegate { + + public TestHeadersSyncStorageRequestDelegate(AuthHeaderProvider authHeaderProvider) { + super(authHeaderProvider); + } + + @Override + public void handleRequestSuccess(SyncStorageResponse res) { + assertTrue(res.httpResponse().containsHeader("X-Weave-Quota-Remaining")); + assertTrue(res.httpResponse().containsHeader("X-Weave-Alert")); + assertTrue(res.httpResponse().containsHeader("X-Weave-Records")); + assertEquals(65536, res.weaveQuotaRemaining()); + assertEquals("First weave alert string", res.weaveAlert()); + assertEquals(50, res.weaveRecords()); + + super.handleRequestSuccess(res); + } + } + + public class HeadersMockServer extends MockServer { + @Override + public void handle(Request request, Response response) { + response.setValue("X-Weave-Quota-Remaining", "65536"); + response.setValue("X-Weave-Alert", "First weave alert string"); + response.addValue("X-Weave-Alert", "Second weave alert string"); + response.setValue("X-Weave-Records", "50"); + + super.handle(request, response); + } + } + + @Test + public void testHeadersResponse() throws URISyntaxException { + BaseResource.rewriteLocalhost = false; + data.startHTTPServer(new HeadersMockServer()); + SyncStorageRecordRequest r = new SyncStorageRecordRequest(new URI(LOCAL_META_URL)); // URL re-used -- we need any successful response + TestHeadersSyncStorageRequestDelegate delegate = new TestHeadersSyncStorageRequestDelegate(authHeaderProvider); + r.delegate = delegate; + r.post(new JSONObject()); + // Server is stopped in the callback. + } + + public class DeleteMockServer extends MockServer { + @Override + public void handle(Request request, Response response) { + assertNotNull(request.getValue("x-confirm-delete")); + assertEquals("1", request.getValue("x-confirm-delete")); + super.handle(request, response); + } + } + + @Test + public void testDelete() throws URISyntaxException { + BaseResource.rewriteLocalhost = false; + data.startHTTPServer(new DeleteMockServer()); + SyncStorageRecordRequest r = new SyncStorageRecordRequest(new URI(LOCAL_META_URL)); // URL re-used -- we need any successful response + TestSyncStorageRequestDelegate delegate = new TestSyncStorageRequestDelegate(authHeaderProvider); + r.delegate = delegate; + r.delete(); + // Server is stopped in the callback. + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java new file mode 100644 index 000000000..f67f7e334 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/SynchronizerHelpers.java @@ -0,0 +1,282 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import android.content.Context; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.testhelpers.WBORepository; +import org.mozilla.gecko.sync.repositories.FetchFailedException; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; +import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; +import org.mozilla.gecko.sync.repositories.StoreFailedException; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import java.util.ArrayList; +import java.util.concurrent.ExecutorService; + +public class SynchronizerHelpers { + public static final String FAIL_SENTINEL = "Fail"; + + /** + * Store one at a time, failing if the guid contains FAIL_SENTINEL. + */ + public static class FailFetchWBORepository extends WBORepository { + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this) { + @Override + public void fetchSince(long timestamp, + final RepositorySessionFetchRecordsDelegate delegate) { + super.fetchSince(timestamp, new RepositorySessionFetchRecordsDelegate() { + @Override + public void onFetchedRecord(Record record) { + if (record.guid.contains(FAIL_SENTINEL)) { + delegate.onFetchFailed(new FetchFailedException(), record); + } else { + delegate.onFetchedRecord(record); + } + } + + @Override + public void onFetchFailed(Exception ex, Record record) { + delegate.onFetchFailed(ex, record); + } + + @Override + public void onFetchCompleted(long fetchEnd) { + delegate.onFetchCompleted(fetchEnd); + } + + @Override + public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) { + return this; + } + }); + } + }); + } + } + + /** + * Store one at a time, failing if the guid contains FAIL_SENTINEL. + */ + public static class SerialFailStoreWBORepository extends WBORepository { + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this) { + @Override + public void store(final Record record) throws NoStoreDelegateException { + if (delegate == null) { + throw new NoStoreDelegateException(); + } + if (record.guid.contains(FAIL_SENTINEL)) { + delegate.onRecordStoreFailed(new StoreFailedException(), record.guid); + } else { + super.store(record); + } + } + }); + } + } + + /** + * Store in batches, failing if any of the batch guids contains "Fail". + *

+ * This will drop the final batch. + */ + public static class BatchFailStoreWBORepository extends WBORepository { + public final int batchSize; + public ArrayList batch = new ArrayList(); + public boolean batchShouldFail = false; + + public class BatchFailStoreWBORepositorySession extends WBORepositorySession { + public BatchFailStoreWBORepositorySession(WBORepository repository) { + super(repository); + } + + public void superStore(final Record record) throws NoStoreDelegateException { + super.store(record); + } + + @Override + public void store(final Record record) throws NoStoreDelegateException { + if (delegate == null) { + throw new NoStoreDelegateException(); + } + synchronized (batch) { + batch.add(record); + if (record.guid.contains("Fail")) { + batchShouldFail = true; + } + + if (batch.size() >= batchSize) { + flush(); + } + } + } + + public void flush() { + final ArrayList thisBatch = new ArrayList(batch); + final boolean thisBatchShouldFail = batchShouldFail; + batchShouldFail = false; + batch.clear(); + storeWorkQueue.execute(new Runnable() { + @Override + public void run() { + Logger.trace("XXX", "Notifying about batch. Failure? " + thisBatchShouldFail); + for (Record batchRecord : thisBatch) { + if (thisBatchShouldFail) { + delegate.onRecordStoreFailed(new StoreFailedException(), batchRecord.guid); + } else { + try { + superStore(batchRecord); + } catch (NoStoreDelegateException e) { + delegate.onRecordStoreFailed(e, batchRecord.guid); + } + } + } + } + }); + } + + @Override + public void storeDone() { + synchronized (batch) { + flush(); + // Do this in a Runnable so that the timestamp is grabbed after any upload. + final Runnable r = new Runnable() { + @Override + public void run() { + synchronized (batch) { + Logger.trace("XXX", "Calling storeDone."); + storeDone(now()); + } + } + }; + storeWorkQueue.execute(r); + } + } + } + public BatchFailStoreWBORepository(int batchSize) { + super(); + this.batchSize = batchSize; + } + + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + delegate.deferredCreationDelegate().onSessionCreated(new BatchFailStoreWBORepositorySession(this)); + } + } + + public static class TrackingWBORepository extends WBORepository { + @Override + public synchronized boolean shouldTrack() { + return true; + } + } + + public static class BeginFailedException extends Exception { + private static final long serialVersionUID = -2349459755976915096L; + } + + public static class FinishFailedException extends Exception { + private static final long serialVersionUID = -4644528423867070934L; + } + + public static class BeginErrorWBORepository extends TrackingWBORepository { + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + delegate.deferredCreationDelegate().onSessionCreated(new BeginErrorWBORepositorySession(this)); + } + + public class BeginErrorWBORepositorySession extends WBORepositorySession { + public BeginErrorWBORepositorySession(WBORepository repository) { + super(repository); + } + + @Override + public void begin(RepositorySessionBeginDelegate delegate) throws InvalidSessionTransitionException { + delegate.onBeginFailed(new BeginFailedException()); + } + } + } + + public static class FinishErrorWBORepository extends TrackingWBORepository { + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + delegate.deferredCreationDelegate().onSessionCreated(new FinishErrorWBORepositorySession(this)); + } + + public class FinishErrorWBORepositorySession extends WBORepositorySession { + public FinishErrorWBORepositorySession(WBORepository repository) { + super(repository); + } + + @Override + public void finish(final RepositorySessionFinishDelegate delegate) throws InactiveSessionException { + delegate.onFinishFailed(new FinishFailedException()); + } + } + } + + public static class DataAvailableWBORepository extends TrackingWBORepository { + public boolean dataAvailable = true; + + public DataAvailableWBORepository(boolean dataAvailable) { + this.dataAvailable = dataAvailable; + } + + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + delegate.deferredCreationDelegate().onSessionCreated(new DataAvailableWBORepositorySession(this)); + } + + public class DataAvailableWBORepositorySession extends WBORepositorySession { + public DataAvailableWBORepositorySession(WBORepository repository) { + super(repository); + } + + @Override + public boolean dataAvailable() { + return dataAvailable; + } + } + } + + public static class ShouldSkipWBORepository extends TrackingWBORepository { + public boolean shouldSkip = true; + + public ShouldSkipWBORepository(boolean shouldSkip) { + this.shouldSkip = shouldSkip; + } + + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + delegate.deferredCreationDelegate().onSessionCreated(new ShouldSkipWBORepositorySession(this)); + } + + public class ShouldSkipWBORepositorySession extends WBORepositorySession { + public ShouldSkipWBORepositorySession(WBORepository repository) { + super(repository); + } + + @Override + public boolean shouldSkip() { + return shouldSkip; + } + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCollectionKeys.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCollectionKeys.java new file mode 100644 index 000000000..76791a6ed --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCollectionKeys.java @@ -0,0 +1,197 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import org.json.simple.JSONArray; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.apache.commons.codec.binary.Base64; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.CollectionKeys; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.NoCollectionKeysSetException; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.crypto.KeyBundle; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Set; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestCollectionKeys { + + @Test + public void testDefaultKeys() throws CryptoException, NoCollectionKeysSetException { + CollectionKeys ck = new CollectionKeys(); + try { + ck.defaultKeyBundle(); + fail("defaultKeys should throw."); + } catch (NoCollectionKeysSetException ex) { + // Good. + } + KeyBundle testKeys = KeyBundle.withRandomKeys(); + ck.setDefaultKeyBundle(testKeys); + assertEquals(testKeys, ck.defaultKeyBundle()); + } + + @Test + public void testKeyForCollection() throws CryptoException, NoCollectionKeysSetException { + CollectionKeys ck = new CollectionKeys(); + try { + ck.keyBundleForCollection("test"); + fail("keyForCollection should throw."); + } catch (NoCollectionKeysSetException ex) { + // Good. + } + KeyBundle testKeys = KeyBundle.withRandomKeys(); + KeyBundle otherKeys = KeyBundle.withRandomKeys(); + + ck.setDefaultKeyBundle(testKeys); + assertEquals(testKeys, ck.defaultKeyBundle()); + assertEquals(testKeys, ck.keyBundleForCollection("test")); // Returns default. + + ck.setKeyBundleForCollection("test", otherKeys); + assertEquals(otherKeys, ck.keyBundleForCollection("test")); // Returns default. + + } + + public static void assertSame(byte[] arrayOne, byte[] arrayTwo) { + assertTrue(Arrays.equals(arrayOne, arrayTwo)); + } + + + @Test + public void testSetKeysFromWBO() throws IOException, NonObjectJSONException, CryptoException, NoCollectionKeysSetException { + String json = "{\"default\":[\"3fI6k1exImMgAKjilmMaAWxGqEIzFX/9K5EjEgH99vc=\",\"/AMaoCX4hzic28WY94XtokNi7N4T0nv+moS1y5wlbug=\"],\"collections\":{},\"collection\":\"crypto\",\"id\":\"keys\"}"; + CryptoRecord rec = new CryptoRecord(json); + + KeyBundle syncKeyBundle = new KeyBundle("slyjcrjednxd6rf4cr63vqilmkus6zbe", "6m8mv8ex2brqnrmsb9fjuvfg7y"); + rec.keyBundle = syncKeyBundle; + + rec.encrypt(); + CollectionKeys ck = new CollectionKeys(); + ck.setKeyPairsFromWBO(rec, syncKeyBundle); + byte[] input = "3fI6k1exImMgAKjilmMaAWxGqEIzFX/9K5EjEgH99vc=".getBytes("UTF-8"); + byte[] expected = Base64.decodeBase64(input); + assertSame(expected, ck.defaultKeyBundle().getEncryptionKey()); + } + + @Test + public void testCryptoRecordFromCollectionKeys() throws CryptoException, NoCollectionKeysSetException, IOException, NonObjectJSONException { + CollectionKeys ck1 = CollectionKeys.generateCollectionKeys(); + assertNotNull(ck1.defaultKeyBundle()); + assertEquals(ck1.keyBundleForCollection("foobar"), ck1.defaultKeyBundle()); + CryptoRecord rec = ck1.asCryptoRecord(); + assertEquals(rec.collection, "crypto"); + assertEquals(rec.guid, "keys"); + JSONArray defaultKey = (JSONArray) rec.payload.get("default"); + + assertSame(Base64.decodeBase64((String) (defaultKey.get(0))), ck1.defaultKeyBundle().getEncryptionKey()); + CollectionKeys ck2 = new CollectionKeys(); + ck2.setKeyPairsFromWBO(rec, null); + assertSame(ck1.defaultKeyBundle().getEncryptionKey(), ck2.defaultKeyBundle().getEncryptionKey()); + } + + @Test + public void testCreateKeysBundle() throws CryptoException, NonObjectJSONException, IOException, NoCollectionKeysSetException { + String username = "b6evr62dptbxz7fvebek7btljyu322wp"; + String friendlyBase32SyncKey = "basuxv2426eqj7frhvpcwkavdi"; + + KeyBundle syncKeyBundle = new KeyBundle(username, friendlyBase32SyncKey); + + CollectionKeys ck = CollectionKeys.generateCollectionKeys(); + CryptoRecord unencrypted = ck.asCryptoRecord(); + unencrypted.keyBundle = syncKeyBundle; + CryptoRecord encrypted = unencrypted.encrypt(); + + CollectionKeys ckDecrypted = new CollectionKeys(); + ckDecrypted.setKeyPairsFromWBO(encrypted, syncKeyBundle); + + // Compare decrypted keys to the keys that were set upon creation + assertArrayEquals(ck.defaultKeyBundle().getEncryptionKey(), ckDecrypted.defaultKeyBundle().getEncryptionKey()); + assertArrayEquals(ck.defaultKeyBundle().getHMACKey(), ckDecrypted.defaultKeyBundle().getHMACKey()); + } + + @Test + public void testDifferences() throws Exception { + KeyBundle kb1 = KeyBundle.withRandomKeys(); + KeyBundle kb2 = KeyBundle.withRandomKeys(); + KeyBundle kb3 = KeyBundle.withRandomKeys(); + CollectionKeys a = CollectionKeys.generateCollectionKeys(); + CollectionKeys b = CollectionKeys.generateCollectionKeys(); + Set diffs; + + a.setKeyBundleForCollection("1", kb1); + b.setKeyBundleForCollection("1", kb1); + diffs = CollectionKeys.differences(a, b); + assertTrue(diffs.isEmpty()); + + a.setKeyBundleForCollection("2", kb2); + diffs = CollectionKeys.differences(a, b); + assertArrayEquals(new String[] { "2" }, diffs.toArray(new String[diffs.size()])); + + b.setKeyBundleForCollection("3", kb3); + diffs = CollectionKeys.differences(a, b); + assertEquals(2, diffs.size()); + assertTrue(diffs.contains("2")); + assertTrue(diffs.contains("3")); + + b.setKeyBundleForCollection("1", KeyBundle.withRandomKeys()); + diffs = CollectionKeys.differences(a, b); + assertEquals(3, diffs.size()); + + // This tests that explicitly setting a default key works. + a = CollectionKeys.generateCollectionKeys(); + b = CollectionKeys.generateCollectionKeys(); + b.setDefaultKeyBundle(a.defaultKeyBundle()); + a.setKeyBundleForCollection("a", a.defaultKeyBundle()); + b.setKeyBundleForCollection("b", b.defaultKeyBundle()); + assertTrue(CollectionKeys.differences(a, b).isEmpty()); + assertTrue(CollectionKeys.differences(b, a).isEmpty()); + } + + @Test + public void testEquals() throws Exception { + KeyBundle kb1 = KeyBundle.withRandomKeys(); + KeyBundle kb2 = KeyBundle.withRandomKeys(); + CollectionKeys a = CollectionKeys.generateCollectionKeys(); + CollectionKeys b = CollectionKeys.generateCollectionKeys(); + + // Random keys are different. + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); + + // keys with unset default key bundles are different. + b.setDefaultKeyBundle(null); + assertFalse(a.equals(b)); + + // keys with equal default key bundles and no other collections are the same. + b.setDefaultKeyBundle(a.defaultKeyBundle()); + assertTrue(a.equals(b)); + + // keys with equal defaults and equal collections are the same. + a.setKeyBundleForCollection("1", kb1); + b.setKeyBundleForCollection("1", kb1); + assertTrue(a.equals(b)); + + // keys with equal defaults but some collection missing are different. + a.setKeyBundleForCollection("2", kb2); + assertFalse(a.equals(b)); + assertFalse(b.equals(a)); + + // keys with equal defaults and some collection set to the default are the same. + a.setKeyBundleForCollection("2", a.defaultKeyBundle()); + b.setKeyBundleForCollection("3", b.defaultKeyBundle()); + assertTrue(a.equals(b)); + assertTrue(b.equals(a)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCommandProcessor.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCommandProcessor.java new file mode 100644 index 000000000..adab2d738 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCommandProcessor.java @@ -0,0 +1,117 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.CommandProcessor; +import org.mozilla.gecko.sync.CommandRunner; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.NonObjectJSONException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestCommandProcessor extends CommandProcessor { + + public static final String commandType = "displayURI"; + public static final String commandWithNoArgs = "{\"command\":\"displayURI\"}"; + public static final String commandWithNoType = "{\"args\":[\"https://bugzilla.mozilla.org/show_bug.cgi?id=731341\",\"PKsljsuqYbGg\"]}"; + public static final String wellFormedCommand = "{\"args\":[\"https://bugzilla.mozilla.org/show_bug.cgi?id=731341\",\"PKsljsuqYbGg\"],\"command\":\"displayURI\"}"; + public static final String wellFormedCommandWithNullArgs = "{\"args\":[\"https://bugzilla.mozilla.org/show_bug.cgi?id=731341\",null,\"PKsljsuqYbGg\",null],\"command\":\"displayURI\"}"; + + private boolean commandExecuted; + + // Session is not used in these tests. + protected final GlobalSession session = null; + + public class MockCommandRunner extends CommandRunner { + public MockCommandRunner(int argCount) { + super(argCount); + } + + @Override + public void executeCommand(final GlobalSession session, List args) { + commandExecuted = true; + } + } + + @Test + public void testRegisterCommand() throws NonObjectJSONException, IOException { + assertNull(commands.get(commandType)); + this.registerCommand(commandType, new MockCommandRunner(1)); + assertNotNull(commands.get(commandType)); + } + + @Test + public void testProcessRegisteredCommand() throws NonObjectJSONException, IOException { + commandExecuted = false; + ExtendedJSONObject unparsedCommand = new ExtendedJSONObject(wellFormedCommand); + this.registerCommand(commandType, new MockCommandRunner(1)); + this.processCommand(session, unparsedCommand); + assertTrue(commandExecuted); + } + + @Test + public void testProcessUnregisteredCommand() throws NonObjectJSONException, IOException { + commandExecuted = false; + ExtendedJSONObject unparsedCommand = new ExtendedJSONObject(wellFormedCommand); + this.processCommand(session, unparsedCommand); + assertFalse(commandExecuted); + } + + @Test + public void testProcessInvalidCommand() throws NonObjectJSONException, IOException { + ExtendedJSONObject unparsedCommand = new ExtendedJSONObject(commandWithNoType); + this.registerCommand(commandType, new MockCommandRunner(1)); + this.processCommand(session, unparsedCommand); + assertFalse(commandExecuted); + } + + @Test + public void testParseCommandNoType() throws NonObjectJSONException, IOException { + ExtendedJSONObject unparsedCommand = new ExtendedJSONObject(commandWithNoType); + assertNull(CommandProcessor.parseCommand(unparsedCommand)); + } + + @Test + public void testParseCommandNoArgs() throws NonObjectJSONException, IOException { + ExtendedJSONObject unparsedCommand = new ExtendedJSONObject(commandWithNoArgs); + assertNull(CommandProcessor.parseCommand(unparsedCommand)); + } + + @Test + public void testParseWellFormedCommand() throws NonObjectJSONException, IOException { + ExtendedJSONObject unparsedCommand = new ExtendedJSONObject(wellFormedCommand); + Command parsedCommand = CommandProcessor.parseCommand(unparsedCommand); + assertNotNull(parsedCommand); + assertEquals(2, parsedCommand.args.size()); + assertEquals(commandType, parsedCommand.commandType); + } + + @Test + public void testParseCommandNullArg() throws NonObjectJSONException, IOException { + ExtendedJSONObject unparsedCommand = new ExtendedJSONObject(wellFormedCommandWithNullArgs); + Command parsedCommand = CommandProcessor.parseCommand(unparsedCommand); + assertNotNull(parsedCommand); + assertEquals(4, parsedCommand.args.size()); + assertEquals(commandType, parsedCommand.commandType); + final List expectedArgs = new ArrayList(); + expectedArgs.add("https://bugzilla.mozilla.org/show_bug.cgi?id=731341"); + expectedArgs.add(null); + expectedArgs.add("PKsljsuqYbGg"); + expectedArgs.add(null); + assertEquals(expectedArgs, parsedCommand.getArgsList()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCryptoRecord.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCryptoRecord.java new file mode 100644 index 000000000..a6b91eaf8 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestCryptoRecord.java @@ -0,0 +1,302 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.apache.commons.codec.binary.Base64; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.repositories.domain.ClientRecord; +import org.mozilla.gecko.sync.repositories.domain.HistoryRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestCryptoRecord { + String base64EncryptionKey = "9K/wLdXdw+nrTtXo4ZpECyHFNr4d7aYHqeg3KW9+m6Q="; + String base64HmacKey = "MMntEfutgLTc8FlTLQFms8/xMPmCldqPlq/QQXEjx70="; + + @Test + public void testBaseCryptoRecordEncrypt() throws IOException, NonObjectJSONException, CryptoException { + + ExtendedJSONObject clearPayload = new ExtendedJSONObject("{\"id\":\"5qRsgXWRJZXr\"," + + "\"title\":\"Index of file:///Users/jason/Library/Application " + + "Support/Firefox/Profiles/ksgd7wpk.LocalSyncServer/weave/logs/\"," + + "\"histUri\":\"file:///Users/jason/Library/Application%20Support/Firefox/Profiles" + + "/ksgd7wpk.LocalSyncServer/weave/logs/\",\"visits\":[{\"type\":1," + + "\"date\":1319149012372425}]}"); + + CryptoRecord record = new CryptoRecord(); + record.payload = clearPayload; + String expectedGUID = "5qRsgXWRJZXr"; + record.guid = expectedGUID; + record.keyBundle = KeyBundle.fromBase64EncodedKeys(base64EncryptionKey, base64HmacKey); + record.encrypt(); + assertTrue(record.payload.get("title") == null); + assertTrue(record.payload.get("ciphertext") != null); + assertEquals(expectedGUID, record.guid); + assertEquals(expectedGUID, record.toJSONObject().get("id")); + record.decrypt(); + assertEquals(expectedGUID, record.toJSONObject().get("id")); + } + + @Test + public void testEntireRecord() throws Exception { + // Check a raw JSON blob from a real Sync account. + String inputString = "{\"sortindex\": 131, \"payload\": \"{\\\"ciphertext\\\":\\\"YJB4dr0vZEIWPirfU2FCJvfzeSLiOP5QWasol2R6ILUxdHsJWuUuvTZVhxYQfTVNou6hVV67jfAvi5Cs+bqhhQsv7icZTiZhPTiTdVGt+uuMotxauVA5OryNGVEZgCCTvT3upzhDFdDbJzVd9O3/gU/b7r/CmAHykX8bTlthlbWeZ8oz6gwHJB5tPRU15nM/m/qW1vyKIw5pw/ZwtAy630AieRehGIGDk+33PWqsfyuT4EUFY9/Ly+8JlnqzxfiBCunIfuXGdLuqTjJOxgrK8mI4wccRFEdFEnmHvh5x7fjl1ID52qumFNQl8zkB75C8XK25alXqwvRR6/AQSP+BgQ==\\\",\\\"IV\\\":\\\"v/0BFgicqYQsd70T39rraA==\\\",\\\"hmac\\\":\\\"59605ed696f6e0e6e062a03510cff742bf6b50d695c042e8372a93f4c2d37dac\\\"}\", \"id\": \"0-P9fabp9vJD\", \"modified\": 1326254123.65}"; + CryptoRecord record = CryptoRecord.fromJSONRecord(inputString); + assertEquals("0-P9fabp9vJD", record.guid); + assertEquals(1326254123650L, record.lastModified); + assertEquals(131, record.sortIndex); + + String b64E = "0A7mU5SZ/tu7ZqwXW1og4qHVHN+zgEi4Xwfwjw+vEJw="; + String b64H = "11GN34O9QWXkjR06g8t0gWE1sGgQeWL0qxxWwl8Dmxs="; + record.keyBundle = KeyBundle.fromBase64EncodedKeys(b64E, b64H); + record.decrypt(); + + assertEquals("0-P9fabp9vJD", record.guid); + assertEquals(1326254123650L, record.lastModified); + assertEquals(131, record.sortIndex); + + assertEquals("Customize Firefox", record.payload.get("title")); + assertEquals("0-P9fabp9vJD", record.payload.get("id")); + assertTrue(record.payload.get("tags") instanceof JSONArray); + } + + @Test + public void testBaseCryptoRecordDecrypt() throws Exception { + String base64CipherText = + "NMsdnRulLwQsVcwxKW9XwaUe7ouJk5Wn" + + "80QhbD80l0HEcZGCynh45qIbeYBik0lg" + + "cHbKmlIxTJNwU+OeqipN+/j7MqhjKOGI" + + "lvbpiPQQLC6/ffF2vbzL0nzMUuSyvaQz" + + "yGGkSYM2xUFt06aNivoQTvU2GgGmUK6M" + + "vadoY38hhW2LCMkoZcNfgCqJ26lO1O0s" + + "EO6zHsk3IVz6vsKiJ2Hq6VCo7hu123wN" + + "egmujHWQSGyf8JeudZjKzfi0OFRRvvm4" + + "QAKyBWf0MgrW1F8SFDnVfkq8amCB7Nhd" + + "whgLWbN+21NitNwWYknoEWe1m6hmGZDg" + + "DT32uxzWxCV8QqqrpH/ZggViEr9uMgoy" + + "4lYaWqP7G5WKvvechc62aqnsNEYhH26A" + + "5QgzmlNyvB+KPFvPsYzxDnSCjOoRSLx7" + + "GG86wT59QZw="; + String base64IV = "GX8L37AAb2FZJMzIoXlX8w=="; + String base16Hmac = + "b1e6c18ac30deb70236bc0d65a46f7a4" + + "dce3b8b0e02cf92182b914e3afa5eebc"; + + ExtendedJSONObject body = new ExtendedJSONObject(); + ExtendedJSONObject payload = new ExtendedJSONObject(); + payload.put("ciphertext", base64CipherText); + payload.put("IV", base64IV); + payload.put("hmac", base16Hmac); + body.put("payload", payload.toJSONString()); + CryptoRecord record = CryptoRecord.fromJSONRecord(body); + byte[] decodedKey = Base64.decodeBase64(base64EncryptionKey.getBytes("UTF-8")); + byte[] decodedHMAC = Base64.decodeBase64(base64HmacKey.getBytes("UTF-8")); + record.keyBundle = new KeyBundle(decodedKey, decodedHMAC); + + record.decrypt(); + String id = (String) record.payload.get("id"); + assertTrue(id.equals("5qRsgXWRJZXr")); + } + + @Test + public void testBaseCryptoRecordSyncKeyBundle() throws UnsupportedEncodingException, CryptoException { + // These values pulled straight out of Firefox. + String key = "6m8mv8ex2brqnrmsb9fjuvfg7y"; + String user = "c6o7dvmr2c4ud2fyv6woz2u4zi22bcyd"; + + // Check our friendly base32 decoding. + assertTrue(Arrays.equals(Utils.decodeFriendlyBase32(key), Base64.decodeBase64("8xbKrJfQYwbFkguKmlSm/g==".getBytes("UTF-8")))); + KeyBundle bundle = new KeyBundle(user, key); + String expectedEncryptKeyBase64 = "/8RzbFT396htpZu5rwgIg2WKfyARgm7dLzsF5pwrVz8="; + String expectedHMACKeyBase64 = "NChGjrqoXYyw8vIYP2334cvmMtsjAMUZNqFwV2LGNkM="; + byte[] computedEncryptKey = bundle.getEncryptionKey(); + byte[] computedHMACKey = bundle.getHMACKey(); + assertTrue(Arrays.equals(computedEncryptKey, Base64.decodeBase64(expectedEncryptKeyBase64.getBytes("UTF-8")))); + assertTrue(Arrays.equals(computedHMACKey, Base64.decodeBase64(expectedHMACKeyBase64.getBytes("UTF-8")))); + } + + @Test + public void testDecrypt() throws Exception { + String jsonInput = "{\"sortindex\": 90, \"payload\":" + + "\"{\\\"ciphertext\\\":\\\"F4ukf0" + + "LM+vhffiKyjaANXeUhfmOPPmQYX1XBoG" + + "Rh1LiHeKHB5rqjhzd7yAoxqgmFnkIgQF" + + "YPSqRAoCxWiAeGULTX+KM4MU5drbNyR/" + + "690JBWSyE1vQSiMGwNIbTKnOLGHKkQVY" + + "HDpajg5BNFfvHNQ5Jx7uM9uJcmuEjCI6" + + "GRMDKyKjhsTqCd99MONkY5rISutaWQ0e" + + "EXFgpA9RZPv4jgWlQhe+YrVnpcrTi20b" + + "NgKp3IfIeqEelrZ5FJd2WGZOA021d3e7" + + "P3Z4qptefH4Q9/hySrWsELWngBaydyn/" + + "IjsheZuKra3kJSST/4SvRZ7qXn\\\",\\" + + "\"IV\\\":\\\"GadPajeXhpk75K2YH+L" + + "y4w==\\\",\\\"hmac\\\":\\\"71442" + + "d946502e3ca475c70a633d3d37f4b4e9" + + "313a6d1041d0c0550cd354e7605\\\"}" + + "\", \"id\": \"hkZYpC-BH4Xi\", \"" + + "modified\": 1320183464.21}"; + String base64EncryptionKey = "K8fV6PHG8RgugfHexGesbzTeOs2o12cr" + + "N/G3bz0Bx1M="; + String base64HmacKey = "nbceuI6w1RJbBzh+iCJHEs8p4lElsOma" + + "yUhx+OztVgM="; + String expectedDecryptedText = "{\"id\":\"hkZYpC-BH4Xi\",\"histU" + + "ri\":\"http://hathology.com/2008" + + "/06/how-to-edit-your-path-enviro" + + "nment-variables-on-mac-os-x/\",\"" + + "title\":\"How To Edit Your PATH " + + "Environment Variables On Mac OS " + + "X\",\"visits\":[{\"date\":131898" + + "2074310889,\"type\":1}]}"; + + KeyBundle keyBundle = KeyBundle.fromBase64EncodedKeys(base64EncryptionKey, base64HmacKey); + + CryptoRecord encrypted = CryptoRecord.fromJSONRecord(jsonInput); + encrypted.keyBundle = keyBundle; + CryptoRecord decrypted = encrypted.decrypt(); + + // We don't necessarily produce exactly the same JSON but we do have the same values. + ExtendedJSONObject expectedJson = new ExtendedJSONObject(expectedDecryptedText); + assertEquals(expectedJson.get("id"), decrypted.payload.get("id")); + assertEquals(expectedJson.get("title"), decrypted.payload.get("title")); + assertEquals(expectedJson.get("histUri"), decrypted.payload.get("histUri")); + } + + @Test + public void testEncryptDecrypt() throws Exception { + String originalText = "{\"id\":\"hkZYpC-BH4Xi\",\"histU" + + "ri\":\"http://hathology.com/2008" + + "/06/how-to-edit-your-path-enviro" + + "nment-variables-on-mac-os-x/\",\"" + + "title\":\"How To Edit Your PATH " + + "Environment Variables On Mac OS " + + "X\",\"visits\":[{\"date\":131898" + + "2074310889,\"type\":1}]}"; + String base64EncryptionKey = "K8fV6PHG8RgugfHexGesbzTeOs2o12cr" + + "N/G3bz0Bx1M="; + String base64HmacKey = "nbceuI6w1RJbBzh+iCJHEs8p4lElsOma" + + "yUhx+OztVgM="; + + KeyBundle keyBundle = KeyBundle.fromBase64EncodedKeys(base64EncryptionKey, base64HmacKey); + + // Encrypt. + CryptoRecord unencrypted = new CryptoRecord(originalText); + unencrypted.keyBundle = keyBundle; + CryptoRecord encrypted = unencrypted.encrypt(); + + // Decrypt after round-trip through JSON. + CryptoRecord undecrypted = CryptoRecord.fromJSONRecord(encrypted.toJSONString()); + undecrypted.keyBundle = keyBundle; + CryptoRecord decrypted = undecrypted.decrypt(); + + // We don't necessarily produce exactly the same JSON but we do have the same values. + ExtendedJSONObject expectedJson = new ExtendedJSONObject(originalText); + assertEquals(expectedJson.get("id"), decrypted.payload.get("id")); + assertEquals(expectedJson.get("title"), decrypted.payload.get("title")); + assertEquals(expectedJson.get("histUri"), decrypted.payload.get("histUri")); + } + + @Test + public void testDecryptKeysBundle() throws Exception { + String jsonInput = "{\"payload\": \"{\\\"ciphertext\\" + + "\":\\\"L1yRyZBkVYKXC1cTpeUqqfmKg" + + "CinYV9YntGiG0PfYZSTLQ2s86WPI0VBb" + + "QbLZfx7udk6sf6CFE4w5EgiPx0XP3Fbj" + + "L7r4qIT0vjbAOrLKedZwA3cgiquc+PXM" + + "Etml8B4Dfm0crJK0iROlRkb+lePAYkzI" + + "iQn5Ba8mSWQEFoLy3zAcfCYXumA7E0Fj" + + "XYD+TqTG5bqYJY4zvPaB9mn9y3WHw==\\" + + "\",\\\"IV\\\":\\\"Jjb2oVI5uvvFfm" + + "ZYRY4GaA==\\\",\\\"hmac\\\":\\\"" + + "0b59731cb1aaedc85f54917b7058f361" + + "60826b70050b0d70cd42b0b609b1d717" + + "\\\"}\", \"id\": \"keys\", \"mod" + + "ified\": 1320183463.91}"; + String username = "b6evr62dptbxz7fvebek7btljyu322wp"; + String friendlyBase32SyncKey = "basuxv2426eqj7frhvpcwkavdi"; + String expectedDecryptedText = "{\"default\":[\"K8fV6PHG8RgugfHe" + + "xGesbzTeOs2o12crN/G3bz0Bx1M=\",\"" + + "nbceuI6w1RJbBzh+iCJHEs8p4lElsOma" + + "yUhx+OztVgM=\"],\"collections\":" + + "{},\"collection\":\"crypto\",\"i" + + "d\":\"keys\"}"; + String expectedBase64EncryptionKey = "K8fV6PHG8RgugfHexGesbzTeOs2o12cr" + + "N/G3bz0Bx1M="; + String expectedBase64HmacKey = "nbceuI6w1RJbBzh+iCJHEs8p4lElsOma" + + "yUhx+OztVgM="; + + KeyBundle syncKeyBundle = new KeyBundle(username, friendlyBase32SyncKey); + + ExtendedJSONObject json = new ExtendedJSONObject(jsonInput); + assertEquals("keys", json.get("id")); + + CryptoRecord encrypted = CryptoRecord.fromJSONRecord(jsonInput); + encrypted.keyBundle = syncKeyBundle; + CryptoRecord decrypted = encrypted.decrypt(); + + // We don't necessarily produce exactly the same JSON but we do have the same values. + ExtendedJSONObject expectedJson = new ExtendedJSONObject(expectedDecryptedText); + assertEquals(expectedJson.get("id"), decrypted.payload.get("id")); + assertEquals(expectedJson.get("default"), decrypted.payload.get("default")); + assertEquals(expectedJson.get("collection"), decrypted.payload.get("collection")); + assertEquals(expectedJson.get("collections"), decrypted.payload.get("collections")); + + // Check that the extracted keys were as expected. + JSONArray keys = new ExtendedJSONObject(decrypted.payload.toJSONString()).getArray("default"); + KeyBundle keyBundle = KeyBundle.fromBase64EncodedKeys((String)keys.get(0), (String)keys.get(1)); + + assertArrayEquals(Base64.decodeBase64(expectedBase64EncryptionKey.getBytes("UTF-8")), keyBundle.getEncryptionKey()); + assertArrayEquals(Base64.decodeBase64(expectedBase64HmacKey.getBytes("UTF-8")), keyBundle.getHMACKey()); + } + + @Test + public void testTTL() throws UnsupportedEncodingException, CryptoException { + Record historyRecord = new HistoryRecord(); + CryptoRecord cryptoRecord = historyRecord.getEnvelope(); + assertEquals(historyRecord.ttl, cryptoRecord.ttl); + + // Very important that ttls are set in outbound envelopes. + JSONObject o = cryptoRecord.toJSONObject(); + assertEquals(cryptoRecord.ttl, o.get("ttl")); + + // Most important of all, outbound encrypted record envelopes. + KeyBundle keyBundle = KeyBundle.withRandomKeys(); + cryptoRecord.keyBundle = keyBundle; + cryptoRecord.encrypt(); + assertEquals(historyRecord.ttl, cryptoRecord.ttl); // Should be preserved. + o = cryptoRecord.toJSONObject(); + assertEquals(cryptoRecord.ttl, o.get("ttl")); + + // But we should ignore negative ttls. + Record clientRecord = new ClientRecord(); + clientRecord.ttl = -1; // Don't ttl this record. + o = clientRecord.getEnvelope().toJSONObject(); + assertNull(o.get("ttl")); + + // But we should ignore negative ttls in outbound encrypted record envelopes. + cryptoRecord = clientRecord.getEnvelope(); + cryptoRecord.keyBundle = keyBundle; + cryptoRecord.encrypt(); + o = cryptoRecord.toJSONObject(); + assertNull(o.get("ttl")); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestRecord.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestRecord.java new file mode 100644 index 000000000..473534aac --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestRecord.java @@ -0,0 +1,330 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.db.Tab; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; +import org.mozilla.gecko.sync.repositories.domain.ClientRecord; +import org.mozilla.gecko.sync.repositories.domain.HistoryRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; +import org.mozilla.gecko.sync.repositories.domain.RecordParseException; +import org.mozilla.gecko.sync.repositories.domain.TabsRecord; + +import java.io.IOException; +import java.util.ArrayList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestRecord { + + @SuppressWarnings("static-method") + @Test + public void testQueryRecord() throws NonObjectJSONException, IOException { + final String expectedGUID = "Bl3n3gpKag3s"; + final String testRecord = + "{\"id\":\"" + expectedGUID + "\"," + + " \"type\":\"query\"," + + " \"title\":\"Downloads\"," + + " \"parentName\":\"\"," + + " \"bmkUri\":\"place:transition=7&sort=4\"," + + " \"tags\":[]," + + " \"keyword\":null," + + " \"description\":null," + + " \"loadInSidebar\":false," + + " \"parentid\":\"BxfRgGiNeITG\"}"; + + final ExtendedJSONObject o = new ExtendedJSONObject(testRecord); + final CryptoRecord cr = new CryptoRecord(o); + cr.guid = expectedGUID; + cr.lastModified = System.currentTimeMillis(); + cr.collection = "bookmarks"; + + final BookmarkRecord r = new BookmarkRecord("Bl3n3gpKag3s", "bookmarks"); + r.initFromEnvelope(cr); + assertEquals(expectedGUID, r.guid); + assertEquals("query", r.type); + assertEquals("places:uri=place%3Atransition%3D7%26sort%3D4", r.bookmarkURI); + + // Check that we get the same bookmark URI out the other end, + // once we've parsed it into a CryptoRecord, a BookmarkRecord, then + // back into a CryptoRecord. + assertEquals("place:transition=7&sort=4", r.getEnvelope().payload.getString("bmkUri")); + } + + @SuppressWarnings("static-method") + @Test + public void testRecordGUIDs() { + for (int i = 0; i < 50; ++i) { + CryptoRecord cryptoRecord = new HistoryRecord().getEnvelope(); + assertEquals(12, cryptoRecord.guid.length()); + } + } + + @Test + public void testRecordEquality() { + long now = System.currentTimeMillis(); + BookmarkRecord bOne = new BookmarkRecord("abcdefghijkl", "bookmarks", now , false); + BookmarkRecord bTwo = new BookmarkRecord("abcdefghijkl", "bookmarks", now , false); + HistoryRecord hOne = new HistoryRecord("mbcdefghijkm", "history", now , false); + HistoryRecord hTwo = new HistoryRecord("mbcdefghijkm", "history", now , false); + + // Identical records. + assertFalse(bOne == bTwo); + assertTrue(bOne.equals(bTwo)); + assertTrue(bOne.equalPayloads(bTwo)); + assertTrue(bOne.congruentWith(bTwo)); + assertTrue(bTwo.equals(bOne)); + assertTrue(bTwo.equalPayloads(bOne)); + assertTrue(bTwo.congruentWith(bOne)); + + // Null checking. + assertFalse(bOne.equals(null)); + assertFalse(bOne.equalPayloads(null)); + assertFalse(bOne.congruentWith(null)); + + // Different types. + hOne.guid = bOne.guid; + assertFalse(bOne.equals(hOne)); + assertFalse(bOne.equalPayloads(hOne)); + assertFalse(bOne.congruentWith(hOne)); + hOne.guid = hTwo.guid; + + // Congruent androidID. + bOne.androidID = 1; + assertFalse(bOne.equals(bTwo)); + assertTrue(bOne.equalPayloads(bTwo)); + assertTrue(bOne.congruentWith(bTwo)); + assertFalse(bTwo.equals(bOne)); + assertTrue(bTwo.equalPayloads(bOne)); + assertTrue(bTwo.congruentWith(bOne)); + + // Non-congruent androidID. + bTwo.androidID = 2; + assertFalse(bOne.equals(bTwo)); + assertTrue(bOne.equalPayloads(bTwo)); + assertFalse(bOne.congruentWith(bTwo)); + assertFalse(bTwo.equals(bOne)); + assertTrue(bTwo.equalPayloads(bOne)); + assertFalse(bTwo.congruentWith(bOne)); + + // Identical androidID. + bOne.androidID = 2; + assertTrue(bOne.equals(bTwo)); + assertTrue(bOne.equalPayloads(bTwo)); + assertTrue(bOne.congruentWith(bTwo)); + assertTrue(bTwo.equals(bOne)); + assertTrue(bTwo.equalPayloads(bOne)); + assertTrue(bTwo.congruentWith(bOne)); + + // Different times. + bTwo.lastModified += 1000; + assertFalse(bOne.equals(bTwo)); + assertTrue(bOne.equalPayloads(bTwo)); + assertTrue(bOne.congruentWith(bTwo)); + assertFalse(bTwo.equals(bOne)); + assertTrue(bTwo.equalPayloads(bOne)); + assertTrue(bTwo.congruentWith(bOne)); + + // Add some visits. + JSONObject v1 = fakeVisit(now - 1000); + JSONObject v2 = fakeVisit(now - 500); + + hOne.fennecDateVisited = now + 2000; + hOne.fennecVisitCount = 1; + assertFalse(hOne.equals(hTwo)); + assertTrue(hOne.equalPayloads(hTwo)); + assertTrue(hOne.congruentWith(hTwo)); + addVisit(hOne, v1); + assertFalse(hOne.equals(hTwo)); + assertFalse(hOne.equalPayloads(hTwo)); + assertTrue(hOne.congruentWith(hTwo)); + addVisit(hTwo, v2); + assertFalse(hOne.equals(hTwo)); + assertFalse(hOne.equalPayloads(hTwo)); + assertTrue(hOne.congruentWith(hTwo)); + + // Now merge the visits. + addVisit(hTwo, v1); + addVisit(hOne, v2); + assertFalse(hOne.equals(hTwo)); + assertTrue(hOne.equalPayloads(hTwo)); + assertTrue(hOne.congruentWith(hTwo)); + hTwo.fennecDateVisited = hOne.fennecDateVisited; + hTwo.fennecVisitCount = hOne.fennecVisitCount = 2; + assertTrue(hOne.equals(hTwo)); + assertTrue(hOne.equalPayloads(hTwo)); + assertTrue(hOne.congruentWith(hTwo)); + } + + @SuppressWarnings("unchecked") + private void addVisit(HistoryRecord r, JSONObject visit) { + if (r.visits == null) { + r.visits = new JSONArray(); + } + r.visits.add(visit); + } + + @SuppressWarnings("unchecked") + private JSONObject fakeVisit(long time) { + JSONObject object = new JSONObject(); + object.put("type", 1L); + object.put("date", time * 1000); + return object; + } + + @SuppressWarnings("static-method") + @Test + public void testTabParsing() throws Exception { + String json = "{\"title\":\"mozilla-central mozilla/browser/base/content/syncSetup.js\"," + + " \"urlHistory\":[\"http://mxr.mozilla.org/mozilla-central/source/browser/base/content/syncSetup.js#72\"]," + + " \"icon\":\"http://mxr.mozilla.org/mxr.png\"," + + " \"lastUsed\":\"1306374531\"}"; + Tab tab = TabsRecord.tabFromJSONObject(new ExtendedJSONObject(json).object); + + assertEquals("mozilla-central mozilla/browser/base/content/syncSetup.js", tab.title); + assertEquals("http://mxr.mozilla.org/mxr.png", tab.icon); + assertEquals("http://mxr.mozilla.org/mozilla-central/source/browser/base/content/syncSetup.js#72", tab.history.get(0)); + assertEquals(1306374531000L, tab.lastUsed); + + String zeroJSON = "{\"title\":\"a\"," + + " \"urlHistory\":[\"http://example.com\"]," + + " \"icon\":\"\"," + + " \"lastUsed\":0}"; + Tab zero = TabsRecord.tabFromJSONObject(new ExtendedJSONObject(zeroJSON).object); + + assertEquals("a", zero.title); + assertEquals("", zero.icon); + assertEquals("http://example.com", zero.history.get(0)); + assertEquals(0L, zero.lastUsed); + } + + @SuppressWarnings({ "unchecked", "static-method" }) + @Test + public void testTabsRecordCreation() throws Exception { + final TabsRecord record = new TabsRecord("testGuid"); + record.clientName = "test client name"; + + final JSONArray history1 = new JSONArray(); + history1.add("http://test.com/test1.html"); + final Tab tab1 = new Tab("test title 1", "http://test.com/test1.png", history1, 1000); + + final JSONArray history2 = new JSONArray(); + history2.add("http://test.com/test2.html#1"); + history2.add("http://test.com/test2.html#2"); + history2.add("http://test.com/test2.html#3"); + final Tab tab2 = new Tab("test title 2", "http://test.com/test2.png", history2, 2000); + + record.tabs = new ArrayList(); + record.tabs.add(tab1); + record.tabs.add(tab2); + + final TabsRecord parsed = new TabsRecord(); + parsed.initFromEnvelope(CryptoRecord.fromJSONRecord(record.getEnvelope().toJSONString())); + + assertEquals(record.guid, parsed.guid); + assertEquals(record.clientName, parsed.clientName); + assertEquals(record.tabs, parsed.tabs); + + // Verify that equality test doesn't always return true. + parsed.tabs.get(0).history.add("http://test.com/different.html"); + assertFalse(record.tabs.equals(parsed.tabs)); + } + + public static class URITestBookmarkRecord extends BookmarkRecord { + public static void doTest() { + assertEquals("places:uri=abc%26def+baz&p1=123&p2=bar+baz", + encodeUnsupportedTypeURI("abc&def baz", "p1", "123", "p2", "bar baz")); + assertEquals("places:uri=abc%26def+baz&p1=123", + encodeUnsupportedTypeURI("abc&def baz", "p1", "123", null, "bar baz")); + assertEquals("places:p1=123", + encodeUnsupportedTypeURI(null, "p1", "123", "p2", null)); + } + } + + @SuppressWarnings("static-method") + @Test + public void testEncodeURI() { + URITestBookmarkRecord.doTest(); + } + + private static final String payload = + "{\"id\":\"M5bwUKK8hPyF\"," + + "\"type\":\"livemark\"," + + "\"siteUri\":\"http://www.bbc.co.uk/go/rss/int/news/-/news/\"," + + "\"feedUri\":\"http://fxfeeds.mozilla.com/en-US/firefox/headlines.xml\"," + + "\"parentName\":\"Bookmarks Toolbar\"," + + "\"parentid\":\"toolbar\"," + + "\"title\":\"Latest Headlines\"," + + "\"description\":\"\"," + + "\"children\":" + + "[\"7oBdEZB-8BMO\", \"SUd1wktMNCTB\", \"eZe4QWzo1BcY\", \"YNBhGwhVnQsN\"," + + "\"mNTdpgoRZMbW\", \"-L8Vci6CbkJY\", \"bVzudKSQERc1\", \"Gxl9lb4DXsmL\"," + + "\"3Qr13GucOtEh\"]}"; + + public class PayloadBookmarkRecord extends BookmarkRecord { + public PayloadBookmarkRecord() { + super("abcdefghijkl", "bookmarks", 1234, false); + } + + public void doTest() throws NonObjectJSONException, IOException { + this.initFromPayload(new ExtendedJSONObject(payload)); + assertEquals("abcdefghijkl", this.guid); // Ignores payload. + assertEquals("livemark", this.type); + assertEquals("Bookmarks Toolbar", this.parentName); + assertEquals("toolbar", this.parentID); + assertEquals("", this.description); + assertEquals(null, this.children); + + final String encodedSite = "http%3A%2F%2Fwww.bbc.co.uk%2Fgo%2Frss%2Fint%2Fnews%2F-%2Fnews%2F"; + final String encodedFeed = "http%3A%2F%2Ffxfeeds.mozilla.com%2Fen-US%2Ffirefox%2Fheadlines.xml"; + final String expectedURI = "places:siteUri=" + encodedSite + "&feedUri=" + encodedFeed; + assertEquals(expectedURI, this.bookmarkURI); + } + } + + @Test + public void testUnusualBookmarkRecords() throws NonObjectJSONException, IOException { + PayloadBookmarkRecord record = new PayloadBookmarkRecord(); + record.doTest(); + } + + @SuppressWarnings("static-method") + @Test + public void testTTL() { + Record record = new HistoryRecord(); + assertEquals(HistoryRecord.HISTORY_TTL, record.ttl); + + // ClientRecords are transient, HistoryRecords are not. + Record clientRecord = new ClientRecord(); + assertTrue(clientRecord.ttl < record.ttl); + + CryptoRecord cryptoRecord = record.getEnvelope(); + assertEquals(record.ttl, cryptoRecord.ttl); + } + + @Test + public void testStringModified() throws Exception { + // modified member is a string, expected a floating point number with 2 + // decimal digits. + String badJson = "{\"sortindex\":\"0\",\"payload\":\"{\\\"syncID\\\":\\\"ZJOqMBjhBthH\\\",\\\"storageVersion\\\":5,\\\"engines\\\":{\\\"clients\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"4oTBXG20rJH5\\\"},\\\"bookmarks\\\":{\\\"version\\\":2,\\\"syncID\\\":\\\"JiMJXy8xI3fr\\\"},\\\"forms\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"J17vSloroXBU\\\"},\\\"history\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"y1HgpbSc3LJT\\\"},\\\"passwords\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"v3y-RidcCuT5\\\"},\\\"prefs\\\":{\\\"version\\\":2,\\\"syncID\\\":\\\"LvfqmT7cUUm4\\\"},\\\"tabs\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"MKMRlBah2d9D\\\"},\\\"addons\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"Ih2hhRrcGjh4\\\"}}}\",\"id\":\"global\",\"modified\":\"1370689360.28\"}"; + try { + CryptoRecord.fromJSONRecord(badJson); + fail("Expected exception."); + } catch (Exception e) { + assertTrue(e instanceof RecordParseException); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestRecordsChannel.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestRecordsChannel.java new file mode 100644 index 000000000..69d3c32e7 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestRecordsChannel.java @@ -0,0 +1,229 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.SynchronizerHelpers.FailFetchWBORepository; +import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionCreationDelegate; +import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFinishDelegate; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WBORepository; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; +import org.mozilla.gecko.sync.synchronizer.RecordsChannel; +import org.mozilla.gecko.sync.synchronizer.RecordsChannelDelegate; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestRecordsChannel { + + protected WBORepository remote; + protected WBORepository local; + + protected RepositorySession source; + protected RepositorySession sink; + protected RecordsChannelDelegate rcDelegate; + + protected AtomicInteger numFlowFetchFailed; + protected AtomicInteger numFlowStoreFailed; + protected AtomicInteger numFlowCompleted; + protected AtomicBoolean flowBeginFailed; + protected AtomicBoolean flowFinishFailed; + + public void doFlow(final Repository remote, final Repository local) throws Exception { + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + remote.createSession(new ExpectSuccessRepositorySessionCreationDelegate(WaitHelper.getTestWaiter()) { + @Override + public void onSessionCreated(RepositorySession session) { + source = session; + local.createSession(new ExpectSuccessRepositorySessionCreationDelegate(WaitHelper.getTestWaiter()) { + @Override + public void onSessionCreated(RepositorySession session) { + sink = session; + WaitHelper.getTestWaiter().performNotify(); + } + }, null); + } + }, null); + } + }); + + assertNotNull(source); + assertNotNull(sink); + + numFlowFetchFailed = new AtomicInteger(0); + numFlowStoreFailed = new AtomicInteger(0); + numFlowCompleted = new AtomicInteger(0); + flowBeginFailed = new AtomicBoolean(false); + flowFinishFailed = new AtomicBoolean(false); + + rcDelegate = new RecordsChannelDelegate() { + @Override + public void onFlowFetchFailed(RecordsChannel recordsChannel, Exception ex) { + numFlowFetchFailed.incrementAndGet(); + } + + @Override + public void onFlowStoreFailed(RecordsChannel recordsChannel, Exception ex, String recordGuid) { + numFlowStoreFailed.incrementAndGet(); + } + + @Override + public void onFlowFinishFailed(RecordsChannel recordsChannel, Exception ex) { + flowFinishFailed.set(true); + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void onFlowCompleted(RecordsChannel recordsChannel, long fetchEnd, long storeEnd) { + numFlowCompleted.incrementAndGet(); + try { + sink.finish(new ExpectSuccessRepositorySessionFinishDelegate(WaitHelper.getTestWaiter()) { + @Override + public void onFinishSucceeded(RepositorySession session, RepositorySessionBundle bundle) { + try { + source.finish(new ExpectSuccessRepositorySessionFinishDelegate(WaitHelper.getTestWaiter()) { + @Override + public void onFinishSucceeded(RepositorySession session, RepositorySessionBundle bundle) { + performNotify(); + } + }); + } catch (InactiveSessionException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + }); + } catch (InactiveSessionException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + + @Override + public void onFlowBeginFailed(RecordsChannel recordsChannel, Exception ex) { + flowBeginFailed.set(true); + WaitHelper.getTestWaiter().performNotify(); + } + }; + + final RecordsChannel rc = new RecordsChannel(source, sink, rcDelegate); + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + try { + rc.beginAndFlow(); + } catch (InvalidSessionTransitionException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + }); + } + + public static final BookmarkRecord[] inbounds = new BookmarkRecord[] { + new BookmarkRecord("inboundSucc1", "bookmarks", 1, false), + new BookmarkRecord("inboundSucc2", "bookmarks", 1, false), + new BookmarkRecord("inboundFail1", "bookmarks", 1, false), + new BookmarkRecord("inboundSucc3", "bookmarks", 1, false), + new BookmarkRecord("inboundSucc4", "bookmarks", 1, false), + new BookmarkRecord("inboundFail2", "bookmarks", 1, false), + }; + public static final BookmarkRecord[] outbounds = new BookmarkRecord[] { + new BookmarkRecord("outboundSucc1", "bookmarks", 1, false), + new BookmarkRecord("outboundSucc2", "bookmarks", 1, false), + new BookmarkRecord("outboundSucc3", "bookmarks", 1, false), + new BookmarkRecord("outboundSucc4", "bookmarks", 1, false), + new BookmarkRecord("outboundSucc5", "bookmarks", 1, false), + new BookmarkRecord("outboundFail6", "bookmarks", 1, false), + }; + + protected WBORepository empty() { + WBORepository repo = new SynchronizerHelpers.TrackingWBORepository(); + return repo; + } + + protected WBORepository full() { + WBORepository repo = new SynchronizerHelpers.TrackingWBORepository(); + for (BookmarkRecord outbound : outbounds) { + repo.wbos.put(outbound.guid, outbound); + } + return repo; + } + + protected WBORepository failingFetch() { + WBORepository repo = new FailFetchWBORepository(); + for (BookmarkRecord outbound : outbounds) { + repo.wbos.put(outbound.guid, outbound); + } + return repo; + } + + @Test + public void testSuccess() throws Exception { + WBORepository source = full(); + WBORepository sink = empty(); + doFlow(source, sink); + assertEquals(1, numFlowCompleted.get()); + assertEquals(0, numFlowFetchFailed.get()); + assertEquals(0, numFlowStoreFailed.get()); + assertEquals(source.wbos, sink.wbos); + } + + @Test + public void testFetchFail() throws Exception { + WBORepository source = failingFetch(); + WBORepository sink = empty(); + doFlow(source, sink); + assertEquals(1, numFlowCompleted.get()); + assertTrue(numFlowFetchFailed.get() > 0); + assertEquals(0, numFlowStoreFailed.get()); + assertTrue(sink.wbos.size() < 6); + } + + @Test + public void testStoreSerialFail() throws Exception { + WBORepository source = full(); + WBORepository sink = new SynchronizerHelpers.SerialFailStoreWBORepository(); + doFlow(source, sink); + assertEquals(1, numFlowCompleted.get()); + assertEquals(0, numFlowFetchFailed.get()); + assertEquals(1, numFlowStoreFailed.get()); + assertEquals(5, sink.wbos.size()); + } + + @Test + public void testStoreBatchesFail() throws Exception { + WBORepository source = full(); + WBORepository sink = new SynchronizerHelpers.BatchFailStoreWBORepository(3); + doFlow(source, sink); + assertEquals(1, numFlowCompleted.get()); + assertEquals(0, numFlowFetchFailed.get()); + assertEquals(3, numFlowStoreFailed.get()); // One batch fails. + assertEquals(3, sink.wbos.size()); // One batch succeeds. + } + + + @Test + public void testStoreOneBigBatchFail() throws Exception { + WBORepository source = full(); + WBORepository sink = new SynchronizerHelpers.BatchFailStoreWBORepository(50); + doFlow(source, sink); + assertEquals(1, numFlowCompleted.get()); + assertEquals(0, numFlowFetchFailed.get()); + assertEquals(6, numFlowStoreFailed.get()); // One (big) batch fails. + assertEquals(0, sink.wbos.size()); // No batches succeed. + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestResetCommands.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestResetCommands.java new file mode 100644 index 000000000..22bcc5093 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestResetCommands.java @@ -0,0 +1,153 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import android.content.SharedPreferences; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.DefaultGlobalSessionCallback; +import org.mozilla.gecko.background.testhelpers.MockPrefsGlobalSession; +import org.mozilla.gecko.background.testhelpers.MockServerSyncStage; +import org.mozilla.gecko.background.testhelpers.MockSharedPreferences; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.CommandProcessor; +import org.mozilla.gecko.sync.EngineSettings; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.MetaGlobalException; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.SyncConfiguration; +import org.mozilla.gecko.sync.SyncConfigurationException; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.stage.GlobalSyncStage; +import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; + +import java.io.IOException; +import java.util.HashMap; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Test that reset commands properly invoke the reset methods on the correct stage. + */ +@RunWith(TestRunner.class) +public class TestResetCommands { + private static final String TEST_USERNAME = "johndoe"; + private static final String TEST_PASSWORD = "password"; + private static final String TEST_SYNC_KEY = "abcdeabcdeabcdeabcdeabcdea"; + + public static void performNotify() { + WaitHelper.getTestWaiter().performNotify(); + } + + public static void performNotify(Throwable e) { + WaitHelper.getTestWaiter().performNotify(e); + } + + public static void performWait(Runnable runnable) { + WaitHelper.getTestWaiter().performWait(runnable); + } + + @Before + public void setUp() { + assertTrue(WaitHelper.getTestWaiter().isIdle()); + } + + @Test + public void testHandleResetCommand() throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, CryptoException { + // Create a global session. + // Set up stage mappings for a real stage name (because they're looked up by name + // in an enumeration) pointing to our fake stage. + // Send a reset command. + // Verify that reset is called on our stage. + + class Result { + public boolean called = false; + } + + final Result yes = new Result(); + final Result no = new Result(); + final GlobalSessionCallback callback = createGlobalSessionCallback(); + + // So we can poke at stages separately. + final HashMap stagesToRun = new HashMap(); + + // Side-effect: modifies global command processor. + final SharedPreferences prefs = new MockSharedPreferences(); + final SyncConfiguration config = new SyncConfiguration(TEST_USERNAME, new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD), prefs); + config.syncKeyBundle = new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY); + final GlobalSession session = new MockPrefsGlobalSession(config, callback, null, null) { + @Override + public boolean isEngineRemotelyEnabled(String engineName, + EngineSettings engineSettings) + throws MetaGlobalException { + return true; + } + + @Override + public void advance() { + // So we don't proceed and run other stages. + } + + @Override + public void prepareStages() { + this.stages = stagesToRun; + } + }; + + final MockServerSyncStage stageGetsReset = new MockServerSyncStage() { + @Override + public void resetLocal() { + yes.called = true; + } + }; + + final MockServerSyncStage stageNotReset = new MockServerSyncStage() { + @Override + public void resetLocal() { + no.called = true; + } + }; + + stagesToRun.put(Stage.syncBookmarks, stageGetsReset); + stagesToRun.put(Stage.syncHistory, stageNotReset); + + final String resetBookmarks = "{\"args\":[\"bookmarks\"],\"command\":\"resetEngine\"}"; + ExtendedJSONObject unparsedCommand = new ExtendedJSONObject(resetBookmarks); + CommandProcessor processor = CommandProcessor.getProcessor(); + processor.processCommand(session, unparsedCommand); + + assertTrue(yes.called); + assertFalse(no.called); + } + + public void testHandleWipeCommand() { + // TODO + } + + private static GlobalSessionCallback createGlobalSessionCallback() { + return new DefaultGlobalSessionCallback() { + + @Override + public void handleAborted(GlobalSession globalSession, String reason) { + performNotify(new Exception("Aborted")); + } + + @Override + public void handleError(GlobalSession globalSession, Exception ex) { + performNotify(ex); + } + + @Override + public void handleSuccess(GlobalSession globalSession) { + } + }; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestServer11RepositorySession.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestServer11RepositorySession.java new file mode 100644 index 000000000..96a366c2d --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestServer11RepositorySession.java @@ -0,0 +1,231 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.SynchronizerHelpers.TrackingWBORepository; +import org.mozilla.android.sync.test.helpers.BaseTestStorageRequestDelegate; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.InfoCollections; +import org.mozilla.gecko.sync.InfoConfiguration; +import org.mozilla.gecko.sync.JSONRecordFetcher; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepository; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.mozilla.gecko.sync.repositories.FetchFailedException; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.Server11Repository; +import org.mozilla.gecko.sync.repositories.StoreFailedException; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecordFactory; +import org.mozilla.gecko.sync.stage.SafeConstrainedServer11Repository; +import org.mozilla.gecko.sync.synchronizer.ServerLocalSynchronizer; +import org.mozilla.gecko.sync.synchronizer.Synchronizer; +import org.simpleframework.http.ContentType; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestServer11RepositorySession { + + public class POSTMockServer extends MockServer { + @Override + public void handle(Request request, Response response) { + try { + String content = request.getContent(); + System.out.println("Content:" + content); + } catch (IOException e) { + e.printStackTrace(); + } + ContentType contentType = request.getContentType(); + System.out.println("Content-Type:" + contentType); + super.handle(request, response, 200, "{success:[]}"); + } + } + + private static final int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private static final String TEST_SERVER = "http://localhost:" + TEST_PORT + "/"; + static final String LOCAL_BASE_URL = TEST_SERVER + "1.1/n6ec3u5bee3tixzp2asys7bs6fve4jfw/"; + static final String LOCAL_INFO_BASE_URL = LOCAL_BASE_URL + "info/"; + static final String LOCAL_COUNTS_URL = LOCAL_INFO_BASE_URL + "collection_counts"; + + // Corresponds to rnewman+atest1@mozilla.com, local. + static final String TEST_USERNAME = "n6ec3u5bee3tixzp2asys7bs6fve4jfw"; + static final String TEST_PASSWORD = "passowrd"; + static final String SYNC_KEY = "eh7ppnb82iwr5kt3z3uyi5vr44"; + + public final AuthHeaderProvider authHeaderProvider = new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD); + protected final InfoCollections infoCollections = new InfoCollections(); + protected final InfoConfiguration infoConfiguration = new InfoConfiguration(); + + // Few-second timeout so that our longer operations don't time out and cause spurious error-handling results. + private static final int SHORT_TIMEOUT = 10000; + + public AuthHeaderProvider getAuthHeaderProvider() { + return new BasicAuthHeaderProvider(TEST_USERNAME, TEST_PASSWORD); + } + + private HTTPServerTestHelper data = new HTTPServerTestHelper(); + + public class TestSyncStorageRequestDelegate extends + BaseTestStorageRequestDelegate { + public TestSyncStorageRequestDelegate(String username, String password) { + super(username, password); + } + + @Override + public void handleRequestSuccess(SyncStorageResponse res) { + assertTrue(res.wasSuccessful()); + assertTrue(res.httpResponse().containsHeader("X-Weave-Timestamp")); + BaseResource.consumeEntity(res); + data.stopHTTPServer(); + } + } + + @SuppressWarnings("static-method") + protected TrackingWBORepository getLocal(int numRecords) { + final TrackingWBORepository local = new TrackingWBORepository(); + for (int i = 0; i < numRecords; i++) { + BookmarkRecord outbound = new BookmarkRecord("outboundFail" + i, "bookmarks", 1, false); + local.wbos.put(outbound.guid, outbound); + } + return local; + } + + protected Exception doSynchronize(MockServer server) throws Exception { + final String COLLECTION = "test"; + + final TrackingWBORepository local = getLocal(100); + final Server11Repository remote = new Server11Repository(COLLECTION, getCollectionURL(COLLECTION), authHeaderProvider, infoCollections, infoConfiguration); + KeyBundle collectionKey = new KeyBundle(TEST_USERNAME, SYNC_KEY); + Crypto5MiddlewareRepository cryptoRepo = new Crypto5MiddlewareRepository(remote, collectionKey); + cryptoRepo.recordFactory = new BookmarkRecordFactory(); + + final Synchronizer synchronizer = new ServerLocalSynchronizer(); + synchronizer.repositoryA = cryptoRepo; + synchronizer.repositoryB = local; + + data.startHTTPServer(server); + try { + Exception e = TestServerLocalSynchronizer.doSynchronize(synchronizer); + return e; + } finally { + data.stopHTTPServer(); + } + } + + protected String getCollectionURL(String collection) { + return LOCAL_BASE_URL + "/storage/" + collection; + } + + @Test + public void testFetchFailure() throws Exception { + MockServer server = new MockServer(404, "error"); + Exception e = doSynchronize(server); + assertNotNull(e); + assertEquals(FetchFailedException.class, e.getClass()); + } + + @Test + public void testStorePostSuccessWithFailingRecords() throws Exception { + MockServer server = new MockServer(200, "{ modified: \" + " + Utils.millisecondsToDecimalSeconds(System.currentTimeMillis()) + ", " + + "success: []," + + "failed: { outboundFail2: [] } }"); + Exception e = doSynchronize(server); + assertNotNull(e); + assertEquals(StoreFailedException.class, e.getClass()); + } + + @Test + public void testStorePostFailure() throws Exception { + MockServer server = new MockServer() { + @Override + public void handle(Request request, Response response) { + if (request.getMethod().equals("POST")) { + this.handle(request, response, 404, "missing"); + } + this.handle(request, response, 200, "success"); + return; + } + }; + + Exception e = doSynchronize(server); + assertNotNull(e); + assertEquals(StoreFailedException.class, e.getClass()); + } + + @Test + public void testConstraints() throws Exception { + MockServer server = new MockServer() { + @Override + public void handle(Request request, Response response) { + if (request.getMethod().equals("GET")) { + if (request.getPath().getPath().endsWith("/info/collection_counts")) { + this.handle(request, response, 200, "{\"bookmarks\": 5001}"); + } + } + this.handle(request, response, 400, "NOOOO"); + } + }; + final JSONRecordFetcher countsFetcher = new JSONRecordFetcher(LOCAL_COUNTS_URL, getAuthHeaderProvider()); + String collection = "bookmarks"; + final SafeConstrainedServer11Repository remote = new SafeConstrainedServer11Repository(collection, + getCollectionURL(collection), + getAuthHeaderProvider(), + infoCollections, + infoConfiguration, + 5000, 5000, "sortindex", countsFetcher); + + data.startHTTPServer(server); + final AtomicBoolean out = new AtomicBoolean(false); + + // Verify that shouldSkip returns true due to a fetch of too large counts, + // rather than due to a timeout failure waiting to fetch counts. + try { + WaitHelper.getTestWaiter().performWait( + SHORT_TIMEOUT, + new Runnable() { + @Override + public void run() { + remote.createSession(new RepositorySessionCreationDelegate() { + @Override + public void onSessionCreated(RepositorySession session) { + out.set(session.shouldSkip()); + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void onSessionCreateFailed(Exception ex) { + WaitHelper.getTestWaiter().performNotify(ex); + } + + @Override + public RepositorySessionCreationDelegate deferredCreationDelegate() { + return this; + } + }, null); + } + }); + assertTrue(out.get()); + } finally { + data.stopHTTPServer(); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestServerLocalSynchronizer.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestServerLocalSynchronizer.java new file mode 100644 index 000000000..267798672 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestServerLocalSynchronizer.java @@ -0,0 +1,237 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.SynchronizerHelpers.BatchFailStoreWBORepository; +import org.mozilla.android.sync.test.SynchronizerHelpers.BeginErrorWBORepository; +import org.mozilla.android.sync.test.SynchronizerHelpers.BeginFailedException; +import org.mozilla.android.sync.test.SynchronizerHelpers.FailFetchWBORepository; +import org.mozilla.android.sync.test.SynchronizerHelpers.FinishErrorWBORepository; +import org.mozilla.android.sync.test.SynchronizerHelpers.FinishFailedException; +import org.mozilla.android.sync.test.SynchronizerHelpers.SerialFailStoreWBORepository; +import org.mozilla.android.sync.test.SynchronizerHelpers.TrackingWBORepository; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WBORepository; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.repositories.FetchFailedException; +import org.mozilla.gecko.sync.repositories.StoreFailedException; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; +import org.mozilla.gecko.sync.synchronizer.ServerLocalSynchronizer; +import org.mozilla.gecko.sync.synchronizer.Synchronizer; +import org.mozilla.gecko.sync.synchronizer.SynchronizerDelegate; + +import java.util.ArrayList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +@RunWith(TestRunner.class) +public class TestServerLocalSynchronizer { + public static final String LOG_TAG = "TestServLocSync"; + + protected Synchronizer getSynchronizer(WBORepository remote, WBORepository local) { + BookmarkRecord[] inbounds = new BookmarkRecord[] { + new BookmarkRecord("inboundSucc1", "bookmarks", 1, false), + new BookmarkRecord("inboundSucc2", "bookmarks", 1, false), + new BookmarkRecord("inboundFail1", "bookmarks", 1, false), + new BookmarkRecord("inboundSucc3", "bookmarks", 1, false), + new BookmarkRecord("inboundFail2", "bookmarks", 1, false), + new BookmarkRecord("inboundFail3", "bookmarks", 1, false), + }; + BookmarkRecord[] outbounds = new BookmarkRecord[] { + new BookmarkRecord("outboundFail1", "bookmarks", 1, false), + new BookmarkRecord("outboundFail2", "bookmarks", 1, false), + new BookmarkRecord("outboundFail3", "bookmarks", 1, false), + new BookmarkRecord("outboundFail4", "bookmarks", 1, false), + new BookmarkRecord("outboundFail5", "bookmarks", 1, false), + new BookmarkRecord("outboundFail6", "bookmarks", 1, false), + }; + for (BookmarkRecord inbound : inbounds) { + remote.wbos.put(inbound.guid, inbound); + } + for (BookmarkRecord outbound : outbounds) { + local.wbos.put(outbound.guid, outbound); + } + + final Synchronizer synchronizer = new ServerLocalSynchronizer(); + synchronizer.repositoryA = remote; + synchronizer.repositoryB = local; + return synchronizer; + } + + protected static Exception doSynchronize(final Synchronizer synchronizer) { + final ArrayList a = new ArrayList(); + + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + synchronizer.synchronize(null, new SynchronizerDelegate() { + @Override + public void onSynchronized(Synchronizer synchronizer) { + Logger.trace(LOG_TAG, "Got onSynchronized."); + a.add(null); + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void onSynchronizeFailed(Synchronizer synchronizer, Exception lastException, String reason) { + Logger.trace(LOG_TAG, "Got onSynchronizedFailed."); + a.add(lastException); + WaitHelper.getTestWaiter().performNotify(); + } + }); + } + }); + + assertEquals(1, a.size()); // Should not be called multiple times! + return a.get(0); + } + + @Test + public void testNoErrors() { + WBORepository remote = new TrackingWBORepository(); + WBORepository local = new TrackingWBORepository(); + + Synchronizer synchronizer = getSynchronizer(remote, local); + assertNull(doSynchronize(synchronizer)); + + assertEquals(12, local.wbos.size()); + assertEquals(12, remote.wbos.size()); + } + + @Test + public void testLocalFetchErrors() { + WBORepository remote = new TrackingWBORepository(); + WBORepository local = new FailFetchWBORepository(); + + Synchronizer synchronizer = getSynchronizer(remote, local); + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(FetchFailedException.class, e.getClass()); + + // Neither session gets finished successfully, so all records are dropped. + assertEquals(6, local.wbos.size()); + assertEquals(6, remote.wbos.size()); + } + + @Test + public void testRemoteFetchErrors() { + WBORepository remote = new FailFetchWBORepository(); + WBORepository local = new TrackingWBORepository(); + + Synchronizer synchronizer = getSynchronizer(remote, local); + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(FetchFailedException.class, e.getClass()); + + // Neither session gets finished successfully, so all records are dropped. + assertEquals(6, local.wbos.size()); + assertEquals(6, remote.wbos.size()); + } + + @Test + public void testLocalSerialStoreErrorsAreIgnored() { + WBORepository remote = new TrackingWBORepository(); + WBORepository local = new SerialFailStoreWBORepository(); + + Synchronizer synchronizer = getSynchronizer(remote, local); + assertNull(doSynchronize(synchronizer)); + + assertEquals(9, local.wbos.size()); + assertEquals(12, remote.wbos.size()); + } + + @Test + public void testLocalBatchStoreErrorsAreIgnored() { + final int BATCH_SIZE = 3; + + Synchronizer synchronizer = getSynchronizer(new TrackingWBORepository(), new BatchFailStoreWBORepository(BATCH_SIZE)); + + Exception e = doSynchronize(synchronizer); + assertNull(e); + } + + @Test + public void testRemoteSerialStoreErrorsAreNotIgnored() throws Exception { + Synchronizer synchronizer = getSynchronizer(new SerialFailStoreWBORepository(), new TrackingWBORepository()); // Tracking so we don't send incoming records back. + + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(StoreFailedException.class, e.getClass()); + } + + @Test + public void testRemoteBatchStoreErrorsAreNotIgnoredManyBatches() throws Exception { + final int BATCH_SIZE = 3; + + Synchronizer synchronizer = getSynchronizer(new BatchFailStoreWBORepository(BATCH_SIZE), new TrackingWBORepository()); // Tracking so we don't send incoming records back. + + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(StoreFailedException.class, e.getClass()); + } + + @Test + public void testRemoteBatchStoreErrorsAreNotIgnoredOneBigBatch() throws Exception { + final int BATCH_SIZE = 20; + + Synchronizer synchronizer = getSynchronizer(new BatchFailStoreWBORepository(BATCH_SIZE), new TrackingWBORepository()); // Tracking so we don't send incoming records back. + + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(StoreFailedException.class, e.getClass()); + } + + @Test + public void testSessionRemoteBeginError() { + Synchronizer synchronizer = getSynchronizer(new BeginErrorWBORepository(), new TrackingWBORepository()); + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(BeginFailedException.class, e.getClass()); + } + + @Test + public void testSessionLocalBeginError() { + Synchronizer synchronizer = getSynchronizer(new TrackingWBORepository(), new BeginErrorWBORepository()); + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(BeginFailedException.class, e.getClass()); + } + + @Test + public void testSessionRemoteFinishError() { + Synchronizer synchronizer = getSynchronizer(new FinishErrorWBORepository(), new TrackingWBORepository()); + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(FinishFailedException.class, e.getClass()); + } + + @Test + public void testSessionLocalFinishError() { + Synchronizer synchronizer = getSynchronizer(new TrackingWBORepository(), new FinishErrorWBORepository()); + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(FinishFailedException.class, e.getClass()); + } + + @Test + public void testSessionBothBeginError() { + Synchronizer synchronizer = getSynchronizer(new BeginErrorWBORepository(), new BeginErrorWBORepository()); + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(BeginFailedException.class, e.getClass()); + } + + @Test + public void testSessionBothFinishError() { + Synchronizer synchronizer = getSynchronizer(new FinishErrorWBORepository(), new FinishErrorWBORepository()); + Exception e = doSynchronize(synchronizer); + assertNotNull(e); + assertEquals(FinishFailedException.class, e.getClass()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSyncConfiguration.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSyncConfiguration.java new file mode 100644 index 000000000..974d799de --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSyncConfiguration.java @@ -0,0 +1,39 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.MockSharedPreferences; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.Sync11Configuration; +import org.mozilla.gecko.sync.SyncConfiguration; + +import java.net.URI; + +@RunWith(TestRunner.class) +public class TestSyncConfiguration { + @Test + public void testURLs() throws Exception { + final MockSharedPreferences prefs = new MockSharedPreferences(); + + // N.B., the username isn't used in the cluster path. + SyncConfiguration fxaConfig = new SyncConfiguration("username", null, prefs); + fxaConfig.clusterURL = new URI("http://db1.oldsync.dev.lcip.org/1.1/174"); + Assert.assertEquals("http://db1.oldsync.dev.lcip.org/1.1/174/info/collections", fxaConfig.infoCollectionsURL()); + Assert.assertEquals("http://db1.oldsync.dev.lcip.org/1.1/174/info/collection_counts", fxaConfig.infoCollectionCountsURL()); + Assert.assertEquals("http://db1.oldsync.dev.lcip.org/1.1/174/storage/meta/global", fxaConfig.metaURL()); + Assert.assertEquals("http://db1.oldsync.dev.lcip.org/1.1/174/storage", fxaConfig.storageURL()); + Assert.assertEquals("http://db1.oldsync.dev.lcip.org/1.1/174/storage/collection", fxaConfig.collectionURI("collection").toASCIIString()); + + SyncConfiguration oldConfig = new Sync11Configuration("username", null, prefs); + oldConfig.clusterURL = new URI("https://db.com/internal/"); + Assert.assertEquals("https://db.com/internal/1.1/username/info/collections", oldConfig.infoCollectionsURL()); + Assert.assertEquals("https://db.com/internal/1.1/username/info/collection_counts", oldConfig.infoCollectionCountsURL()); + Assert.assertEquals("https://db.com/internal/1.1/username/storage/meta/global", oldConfig.metaURL()); + Assert.assertEquals("https://db.com/internal/1.1/username/storage", oldConfig.storageURL()); + Assert.assertEquals("https://db.com/internal/1.1/username/storage/collection", oldConfig.collectionURI("collection").toASCIIString()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSynchronizer.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSynchronizer.java new file mode 100644 index 000000000..65157beee --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSynchronizer.java @@ -0,0 +1,398 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import android.content.Context; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.SynchronizerHelpers.TrackingWBORepository; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WBORepository; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; +import org.mozilla.gecko.sync.synchronizer.Synchronizer; +import org.mozilla.gecko.sync.synchronizer.SynchronizerDelegate; +import org.mozilla.gecko.sync.synchronizer.SynchronizerSession; +import org.mozilla.gecko.sync.synchronizer.SynchronizerSessionDelegate; + +import java.util.Date; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestSynchronizer { + public static final String LOG_TAG = "TestSynchronizer"; + + public static void assertInRangeInclusive(long earliest, long value, long latest) { + assertTrue(earliest <= value); + assertTrue(latest >= value); + } + + public static void recordEquals(BookmarkRecord r, String guid, long lastModified, boolean deleted, String collection) { + assertEquals(r.guid, guid); + assertEquals(r.lastModified, lastModified); + assertEquals(r.deleted, deleted); + assertEquals(r.collection, collection); + } + + public static void recordEquals(BookmarkRecord a, BookmarkRecord b) { + assertEquals(a.guid, b.guid); + assertEquals(a.lastModified, b.lastModified); + assertEquals(a.deleted, b.deleted); + assertEquals(a.collection, b.collection); + } + + @Before + public void setUp() { + WaitHelper.resetTestWaiter(); + } + + @After + public void tearDown() { + WaitHelper.resetTestWaiter(); + } + + @Test + public void testSynchronizerSession() { + final Context context = null; + final WBORepository repoA = new TrackingWBORepository(); + final WBORepository repoB = new TrackingWBORepository(); + + final String collection = "bookmarks"; + final boolean deleted = false; + final String guidA = "abcdabcdabcd"; + final String guidB = "ffffffffffff"; + final String guidC = "xxxxxxxxxxxx"; + final long lastModifiedA = 312345; + final long lastModifiedB = 412340; + final long lastModifiedC = 412345; + BookmarkRecord bookmarkRecordA = new BookmarkRecord(guidA, collection, lastModifiedA, deleted); + BookmarkRecord bookmarkRecordB = new BookmarkRecord(guidB, collection, lastModifiedB, deleted); + BookmarkRecord bookmarkRecordC = new BookmarkRecord(guidC, collection, lastModifiedC, deleted); + + repoA.wbos.put(guidA, bookmarkRecordA); + repoB.wbos.put(guidB, bookmarkRecordB); + repoB.wbos.put(guidC, bookmarkRecordC); + Synchronizer synchronizer = new Synchronizer(); + synchronizer.repositoryA = repoA; + synchronizer.repositoryB = repoB; + final SynchronizerSession syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() { + + @Override + public void onInitialized(SynchronizerSession session) { + assertFalse(repoA.wbos.containsKey(guidB)); + assertFalse(repoA.wbos.containsKey(guidC)); + assertFalse(repoB.wbos.containsKey(guidA)); + assertTrue(repoA.wbos.containsKey(guidA)); + assertTrue(repoB.wbos.containsKey(guidB)); + assertTrue(repoB.wbos.containsKey(guidC)); + session.synchronize(); + } + + @Override + public void onSynchronized(SynchronizerSession session) { + try { + assertEquals(1, session.getInboundCount()); + assertEquals(2, session.getOutboundCount()); + WaitHelper.getTestWaiter().performNotify(); + } catch (Throwable e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + + @Override + public void onSynchronizeFailed(SynchronizerSession session, + Exception lastException, String reason) { + WaitHelper.getTestWaiter().performNotify(lastException); + } + + @Override + public void onSynchronizeSkipped(SynchronizerSession synchronizerSession) { + WaitHelper.getTestWaiter().performNotify(new RuntimeException()); + } + }); + + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + syncSession.init(context, new RepositorySessionBundle(0), new RepositorySessionBundle(0)); + } + }); + + // Verify contents. + assertTrue(repoA.wbos.containsKey(guidA)); + assertTrue(repoA.wbos.containsKey(guidB)); + assertTrue(repoA.wbos.containsKey(guidC)); + assertTrue(repoB.wbos.containsKey(guidA)); + assertTrue(repoB.wbos.containsKey(guidB)); + assertTrue(repoB.wbos.containsKey(guidC)); + BookmarkRecord aa = (BookmarkRecord) repoA.wbos.get(guidA); + BookmarkRecord ab = (BookmarkRecord) repoA.wbos.get(guidB); + BookmarkRecord ac = (BookmarkRecord) repoA.wbos.get(guidC); + BookmarkRecord ba = (BookmarkRecord) repoB.wbos.get(guidA); + BookmarkRecord bb = (BookmarkRecord) repoB.wbos.get(guidB); + BookmarkRecord bc = (BookmarkRecord) repoB.wbos.get(guidC); + recordEquals(aa, guidA, lastModifiedA, deleted, collection); + recordEquals(ab, guidB, lastModifiedB, deleted, collection); + recordEquals(ac, guidC, lastModifiedC, deleted, collection); + recordEquals(ba, guidA, lastModifiedA, deleted, collection); + recordEquals(bb, guidB, lastModifiedB, deleted, collection); + recordEquals(bc, guidC, lastModifiedC, deleted, collection); + recordEquals(aa, ba); + recordEquals(ab, bb); + recordEquals(ac, bc); + } + + public abstract class SuccessfulSynchronizerDelegate implements SynchronizerDelegate { + public long syncAOne = 0; + public long syncBOne = 0; + + @Override + public void onSynchronizeFailed(Synchronizer synchronizer, + Exception lastException, String reason) { + fail("Should not fail."); + } + } + + @Test + public void testSynchronizerPersists() { + final Object monitor = new Object(); + final long earliest = new Date().getTime(); + + Context context = null; + final WBORepository repoA = new WBORepository(); + final WBORepository repoB = new WBORepository(); + Synchronizer synchronizer = new Synchronizer(); + synchronizer.bundleA = new RepositorySessionBundle(0); + synchronizer.bundleB = new RepositorySessionBundle(0); + synchronizer.repositoryA = repoA; + synchronizer.repositoryB = repoB; + + final SuccessfulSynchronizerDelegate delegateOne = new SuccessfulSynchronizerDelegate() { + @Override + public void onSynchronized(Synchronizer synchronizer) { + Logger.trace(LOG_TAG, "onSynchronized. Success!"); + syncAOne = synchronizer.bundleA.getTimestamp(); + syncBOne = synchronizer.bundleB.getTimestamp(); + synchronized (monitor) { + monitor.notify(); + } + } + }; + final SuccessfulSynchronizerDelegate delegateTwo = new SuccessfulSynchronizerDelegate() { + @Override + public void onSynchronized(Synchronizer synchronizer) { + Logger.trace(LOG_TAG, "onSynchronized. Success!"); + syncAOne = synchronizer.bundleA.getTimestamp(); + syncBOne = synchronizer.bundleB.getTimestamp(); + synchronized (monitor) { + monitor.notify(); + } + } + }; + synchronized (monitor) { + synchronizer.synchronize(context, delegateOne); + try { + monitor.wait(); + } catch (InterruptedException e) { + fail("Interrupted."); + } + } + long now = new Date().getTime(); + Logger.trace(LOG_TAG, "Earliest is " + earliest); + Logger.trace(LOG_TAG, "syncAOne is " + delegateOne.syncAOne); + Logger.trace(LOG_TAG, "syncBOne is " + delegateOne.syncBOne); + Logger.trace(LOG_TAG, "Now: " + now); + assertInRangeInclusive(earliest, delegateOne.syncAOne, now); + assertInRangeInclusive(earliest, delegateOne.syncBOne, now); + try { + Thread.sleep(10); + } catch (InterruptedException e) { + fail("Thread interrupted!"); + } + synchronized (monitor) { + synchronizer.synchronize(context, delegateTwo); + try { + monitor.wait(); + } catch (InterruptedException e) { + fail("Interrupted."); + } + } + now = new Date().getTime(); + Logger.trace(LOG_TAG, "Earliest is " + earliest); + Logger.trace(LOG_TAG, "syncAOne is " + delegateTwo.syncAOne); + Logger.trace(LOG_TAG, "syncBOne is " + delegateTwo.syncBOne); + Logger.trace(LOG_TAG, "Now: " + now); + assertInRangeInclusive(earliest, delegateTwo.syncAOne, now); + assertInRangeInclusive(earliest, delegateTwo.syncBOne, now); + assertTrue(delegateTwo.syncAOne > delegateOne.syncAOne); + assertTrue(delegateTwo.syncBOne > delegateOne.syncBOne); + Logger.trace(LOG_TAG, "Reached end of test."); + } + + private Synchronizer getTestSynchronizer(long tsA, long tsB) { + WBORepository repoA = new TrackingWBORepository(); + WBORepository repoB = new TrackingWBORepository(); + Synchronizer synchronizer = new Synchronizer(); + synchronizer.bundleA = new RepositorySessionBundle(tsA); + synchronizer.bundleB = new RepositorySessionBundle(tsB); + synchronizer.repositoryA = repoA; + synchronizer.repositoryB = repoB; + return synchronizer; + } + + /** + * Let's put data in two repos and synchronize them with last sync + * timestamps later than all of the records. Verify that no records + * are exchanged. + */ + @Test + public void testSynchronizerFakeTimestamps() { + final Context context = null; + + final String collection = "bookmarks"; + final boolean deleted = false; + final String guidA = "abcdabcdabcd"; + final String guidB = "ffffffffffff"; + final long lastModifiedA = 312345; + final long lastModifiedB = 412345; + BookmarkRecord bookmarkRecordA = new BookmarkRecord(guidA, collection, lastModifiedA, deleted); + BookmarkRecord bookmarkRecordB = new BookmarkRecord(guidB, collection, lastModifiedB, deleted); + + final Synchronizer synchronizer = getTestSynchronizer(lastModifiedA + 10, lastModifiedB + 10); + final WBORepository repoA = (WBORepository) synchronizer.repositoryA; + final WBORepository repoB = (WBORepository) synchronizer.repositoryB; + + repoA.wbos.put(guidA, bookmarkRecordA); + repoB.wbos.put(guidB, bookmarkRecordB); + + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + synchronizer.synchronize(context, new SynchronizerDelegate() { + + @Override + public void onSynchronized(Synchronizer synchronizer) { + try { + // No records get sent either way. + final SynchronizerSession synchronizerSession = synchronizer.getSynchronizerSession(); + assertNotNull(synchronizerSession); + assertEquals(0, synchronizerSession.getInboundCount()); + assertEquals(0, synchronizerSession.getOutboundCount()); + WaitHelper.getTestWaiter().performNotify(); + } catch (Throwable e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + + @Override + public void onSynchronizeFailed(Synchronizer synchronizer, + Exception lastException, String reason) { + WaitHelper.getTestWaiter().performNotify(lastException); + } + }); + } + }); + + // Verify contents. + assertTrue(repoA.wbos.containsKey(guidA)); + assertTrue(repoB.wbos.containsKey(guidB)); + assertFalse(repoB.wbos.containsKey(guidA)); + assertFalse(repoA.wbos.containsKey(guidB)); + BookmarkRecord aa = (BookmarkRecord) repoA.wbos.get(guidA); + BookmarkRecord ab = (BookmarkRecord) repoA.wbos.get(guidB); + BookmarkRecord ba = (BookmarkRecord) repoB.wbos.get(guidA); + BookmarkRecord bb = (BookmarkRecord) repoB.wbos.get(guidB); + assertNull(ab); + assertNull(ba); + recordEquals(aa, guidA, lastModifiedA, deleted, collection); + recordEquals(bb, guidB, lastModifiedB, deleted, collection); + } + + + @Test + public void testSynchronizer() { + final Context context = null; + + final String collection = "bookmarks"; + final boolean deleted = false; + final String guidA = "abcdabcdabcd"; + final String guidB = "ffffffffffff"; + final String guidC = "gggggggggggg"; + final long lastModifiedA = 312345; + final long lastModifiedB = 412340; + final long lastModifiedC = 412345; + BookmarkRecord bookmarkRecordA = new BookmarkRecord(guidA, collection, lastModifiedA, deleted); + BookmarkRecord bookmarkRecordB = new BookmarkRecord(guidB, collection, lastModifiedB, deleted); + BookmarkRecord bookmarkRecordC = new BookmarkRecord(guidC, collection, lastModifiedC, deleted); + + final Synchronizer synchronizer = getTestSynchronizer(0, 0); + final WBORepository repoA = (WBORepository) synchronizer.repositoryA; + final WBORepository repoB = (WBORepository) synchronizer.repositoryB; + + repoA.wbos.put(guidA, bookmarkRecordA); + repoB.wbos.put(guidB, bookmarkRecordB); + repoB.wbos.put(guidC, bookmarkRecordC); + + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + synchronizer.synchronize(context, new SynchronizerDelegate() { + + @Override + public void onSynchronized(Synchronizer synchronizer) { + try { + // No records get sent either way. + final SynchronizerSession synchronizerSession = synchronizer.getSynchronizerSession(); + assertNotNull(synchronizerSession); + assertEquals(1, synchronizerSession.getInboundCount()); + assertEquals(2, synchronizerSession.getOutboundCount()); + WaitHelper.getTestWaiter().performNotify(); + } catch (Throwable e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + + @Override + public void onSynchronizeFailed(Synchronizer synchronizer, + Exception lastException, String reason) { + WaitHelper.getTestWaiter().performNotify(lastException); + } + }); + } + }); + + // Verify contents. + assertTrue(repoA.wbos.containsKey(guidA)); + assertTrue(repoA.wbos.containsKey(guidB)); + assertTrue(repoA.wbos.containsKey(guidC)); + assertTrue(repoB.wbos.containsKey(guidA)); + assertTrue(repoB.wbos.containsKey(guidB)); + assertTrue(repoB.wbos.containsKey(guidC)); + BookmarkRecord aa = (BookmarkRecord) repoA.wbos.get(guidA); + BookmarkRecord ab = (BookmarkRecord) repoA.wbos.get(guidB); + BookmarkRecord ac = (BookmarkRecord) repoA.wbos.get(guidC); + BookmarkRecord ba = (BookmarkRecord) repoB.wbos.get(guidA); + BookmarkRecord bb = (BookmarkRecord) repoB.wbos.get(guidB); + BookmarkRecord bc = (BookmarkRecord) repoB.wbos.get(guidC); + recordEquals(aa, guidA, lastModifiedA, deleted, collection); + recordEquals(ab, guidB, lastModifiedB, deleted, collection); + recordEquals(ac, guidC, lastModifiedC, deleted, collection); + recordEquals(ba, guidA, lastModifiedA, deleted, collection); + recordEquals(bb, guidB, lastModifiedB, deleted, collection); + recordEquals(bc, guidC, lastModifiedC, deleted, collection); + recordEquals(aa, ba); + recordEquals(ab, bb); + recordEquals(ac, bc); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSynchronizerSession.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSynchronizerSession.java new file mode 100644 index 000000000..ddc3ae68e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestSynchronizerSession.java @@ -0,0 +1,306 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import android.content.Context; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.SynchronizerHelpers.DataAvailableWBORepository; +import org.mozilla.android.sync.test.SynchronizerHelpers.ShouldSkipWBORepository; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WBORepository; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.SynchronizerConfiguration; +import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; +import org.mozilla.gecko.sync.synchronizer.Synchronizer; +import org.mozilla.gecko.sync.synchronizer.SynchronizerSession; +import org.mozilla.gecko.sync.synchronizer.SynchronizerSessionDelegate; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestSynchronizerSession { + public static final String LOG_TAG = TestSynchronizerSession.class.getSimpleName(); + + protected static void assertFirstContainsSecond(Map first, Map second) { + for (Entry entry : second.entrySet()) { + assertTrue("Expected key " + entry.getKey(), first.containsKey(entry.getKey())); + Record record = first.get(entry.getKey()); + assertEquals(entry.getValue(), record); + } + } + + protected static void assertFirstDoesNotContainSecond(Map first, Map second) { + for (Entry entry : second.entrySet()) { + assertFalse("Unexpected key " + entry.getKey(), first.containsKey(entry.getKey())); + } + } + + protected WBORepository repoA = null; + protected WBORepository repoB = null; + protected SynchronizerSession syncSession = null; + protected Map originalWbosA = null; + protected Map originalWbosB = null; + + @Before + public void setUp() { + repoA = new DataAvailableWBORepository(false); + repoB = new DataAvailableWBORepository(false); + + final String collection = "bookmarks"; + final boolean deleted = false; + final String guidA = "abcdabcdabcd"; + final String guidB = "ffffffffffff"; + final String guidC = "xxxxxxxxxxxx"; + final long lastModifiedA = 312345; + final long lastModifiedB = 412340; + final long lastModifiedC = 412345; + final BookmarkRecord bookmarkRecordA = new BookmarkRecord(guidA, collection, lastModifiedA, deleted); + final BookmarkRecord bookmarkRecordB = new BookmarkRecord(guidB, collection, lastModifiedB, deleted); + final BookmarkRecord bookmarkRecordC = new BookmarkRecord(guidC, collection, lastModifiedC, deleted); + + repoA.wbos.put(guidA, bookmarkRecordA); + repoB.wbos.put(guidB, bookmarkRecordB); + repoB.wbos.put(guidC, bookmarkRecordC); + + originalWbosA = new HashMap(repoA.wbos); + originalWbosB = new HashMap(repoB.wbos); + + Synchronizer synchronizer = new Synchronizer(); + synchronizer.repositoryA = repoA; + synchronizer.repositoryB = repoB; + syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() { + @Override + public void onInitialized(SynchronizerSession session) { + session.synchronize(); + } + + @Override + public void onSynchronized(SynchronizerSession session) { + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void onSynchronizeFailed(SynchronizerSession session, Exception lastException, String reason) { + WaitHelper.getTestWaiter().performNotify(lastException); + } + + @Override + public void onSynchronizeSkipped(SynchronizerSession synchronizerSession) { + WaitHelper.getTestWaiter().performNotify(new RuntimeException("Not expecting onSynchronizeSkipped")); + } + }); + } + + protected void logStats() { + // Uncomment this line to print stats to console: + // Logger.startLoggingTo(new PrintLogWriter(new PrintWriter(System.out, true))); + + Logger.debug(LOG_TAG, "Repo A fetch done: " + repoA.stats.fetchCompleted); + Logger.debug(LOG_TAG, "Repo B store done: " + repoB.stats.storeCompleted); + Logger.debug(LOG_TAG, "Repo B fetch done: " + repoB.stats.fetchCompleted); + Logger.debug(LOG_TAG, "Repo A store done: " + repoA.stats.storeCompleted); + + SynchronizerConfiguration sc = syncSession.getSynchronizer().save(); + Logger.debug(LOG_TAG, "Repo A timestamp: " + sc.remoteBundle.getTimestamp()); + Logger.debug(LOG_TAG, "Repo B timestamp: " + sc.localBundle.getTimestamp()); + } + + protected void doTest(boolean remoteDataAvailable, boolean localDataAvailable) { + ((DataAvailableWBORepository) repoA).dataAvailable = remoteDataAvailable; + ((DataAvailableWBORepository) repoB).dataAvailable = localDataAvailable; + + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + final Context context = null; + syncSession.init(context, + new RepositorySessionBundle(0), + new RepositorySessionBundle(0)); + } + }); + + logStats(); + } + + @Test + public void testSynchronizerSessionBothHaveData() { + long before = System.currentTimeMillis(); + boolean remoteDataAvailable = true; + boolean localDataAvailable = true; + doTest(remoteDataAvailable, localDataAvailable); + long after = System.currentTimeMillis(); + + assertEquals(1, syncSession.getInboundCount()); + assertEquals(2, syncSession.getOutboundCount()); + + // Didn't lose any records. + assertFirstContainsSecond(repoA.wbos, originalWbosA); + assertFirstContainsSecond(repoB.wbos, originalWbosB); + // Got new records. + assertFirstContainsSecond(repoA.wbos, originalWbosB); + assertFirstContainsSecond(repoB.wbos, originalWbosA); + + // Timestamps updated. + SynchronizerConfiguration sc = syncSession.getSynchronizer().save(); + TestSynchronizer.assertInRangeInclusive(before, sc.localBundle.getTimestamp(), after); + TestSynchronizer.assertInRangeInclusive(before, sc.remoteBundle.getTimestamp(), after); + } + + @Test + public void testSynchronizerSessionOnlyLocalHasData() { + long before = System.currentTimeMillis(); + boolean remoteDataAvailable = false; + boolean localDataAvailable = true; + doTest(remoteDataAvailable, localDataAvailable); + long after = System.currentTimeMillis(); + + // Record counts updated. + assertEquals(0, syncSession.getInboundCount()); + assertEquals(2, syncSession.getOutboundCount()); + + // Didn't lose any records. + assertFirstContainsSecond(repoA.wbos, originalWbosA); + assertFirstContainsSecond(repoB.wbos, originalWbosB); + // Got new records. + assertFirstContainsSecond(repoA.wbos, originalWbosB); + // Didn't get records we shouldn't have fetched. + assertFirstDoesNotContainSecond(repoB.wbos, originalWbosA); + + // Timestamps updated. + SynchronizerConfiguration sc = syncSession.getSynchronizer().save(); + TestSynchronizer.assertInRangeInclusive(before, sc.localBundle.getTimestamp(), after); + TestSynchronizer.assertInRangeInclusive(before, sc.remoteBundle.getTimestamp(), after); + } + + @Test + public void testSynchronizerSessionOnlyRemoteHasData() { + long before = System.currentTimeMillis(); + boolean remoteDataAvailable = true; + boolean localDataAvailable = false; + doTest(remoteDataAvailable, localDataAvailable); + long after = System.currentTimeMillis(); + + // Record counts updated. + assertEquals(1, syncSession.getInboundCount()); + assertEquals(0, syncSession.getOutboundCount()); + + // Didn't lose any records. + assertFirstContainsSecond(repoA.wbos, originalWbosA); + assertFirstContainsSecond(repoB.wbos, originalWbosB); + // Got new records. + assertFirstContainsSecond(repoB.wbos, originalWbosA); + // Didn't get records we shouldn't have fetched. + assertFirstDoesNotContainSecond(repoA.wbos, originalWbosB); + + // Timestamps updated. + SynchronizerConfiguration sc = syncSession.getSynchronizer().save(); + TestSynchronizer.assertInRangeInclusive(before, sc.localBundle.getTimestamp(), after); + TestSynchronizer.assertInRangeInclusive(before, sc.remoteBundle.getTimestamp(), after); + } + + @Test + public void testSynchronizerSessionNeitherHaveData() { + long before = System.currentTimeMillis(); + boolean remoteDataAvailable = false; + boolean localDataAvailable = false; + doTest(remoteDataAvailable, localDataAvailable); + long after = System.currentTimeMillis(); + + // Record counts updated. + assertEquals(0, syncSession.getInboundCount()); + assertEquals(0, syncSession.getOutboundCount()); + + // Didn't lose any records. + assertFirstContainsSecond(repoA.wbos, originalWbosA); + assertFirstContainsSecond(repoB.wbos, originalWbosB); + // Didn't get records we shouldn't have fetched. + assertFirstDoesNotContainSecond(repoA.wbos, originalWbosB); + assertFirstDoesNotContainSecond(repoB.wbos, originalWbosA); + + // Timestamps updated. + SynchronizerConfiguration sc = syncSession.getSynchronizer().save(); + TestSynchronizer.assertInRangeInclusive(before, sc.localBundle.getTimestamp(), after); + TestSynchronizer.assertInRangeInclusive(before, sc.remoteBundle.getTimestamp(), after); + } + + protected void doSkipTest(boolean remoteShouldSkip, boolean localShouldSkip) { + repoA = new ShouldSkipWBORepository(remoteShouldSkip); + repoB = new ShouldSkipWBORepository(localShouldSkip); + + Synchronizer synchronizer = new Synchronizer(); + synchronizer.repositoryA = repoA; + synchronizer.repositoryB = repoB; + + syncSession = new SynchronizerSession(synchronizer, new SynchronizerSessionDelegate() { + @Override + public void onInitialized(SynchronizerSession session) { + session.synchronize(); + } + + @Override + public void onSynchronized(SynchronizerSession session) { + WaitHelper.getTestWaiter().performNotify(new RuntimeException("Not expecting onSynchronized")); + } + + @Override + public void onSynchronizeFailed(SynchronizerSession session, Exception lastException, String reason) { + WaitHelper.getTestWaiter().performNotify(lastException); + } + + @Override + public void onSynchronizeSkipped(SynchronizerSession synchronizerSession) { + WaitHelper.getTestWaiter().performNotify(); + } + }); + + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + final Context context = null; + syncSession.init(context, + new RepositorySessionBundle(100), + new RepositorySessionBundle(200)); + } + }); + + // If we skip, we don't update timestamps or even un-bundle. + SynchronizerConfiguration sc = syncSession.getSynchronizer().save(); + assertNotNull(sc); + assertNull(sc.localBundle); + assertNull(sc.remoteBundle); + assertEquals(-1, syncSession.getInboundCount()); + assertEquals(-1, syncSession.getOutboundCount()); + } + + @Test + public void testSynchronizerSessionShouldSkip() { + // These combinations should all skip. + doSkipTest(true, false); + + doSkipTest(false, true); + doSkipTest(true, true); + + try { + doSkipTest(false, false); + fail("Expected exception."); + } catch (WaitHelper.InnerError e) { + assertTrue(e.innerError instanceof RuntimeException); + assertEquals("Not expecting onSynchronized", e.innerError.getMessage()); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestUtils.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestUtils.java new file mode 100644 index 000000000..bc9a99dae --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/TestUtils.java @@ -0,0 +1,154 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.SyncConstants; +import org.mozilla.gecko.sync.Utils; + +import java.io.UnsupportedEncodingException; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestUtils extends Utils { + + @Test + public void testGenerateGUID() { + for (int i = 0; i < 1000; ++i) { + assertEquals(12, Utils.generateGuid().length()); + } + } + + public static final byte[][] BYTE_ARRS = { + new byte[] {' '}, // Tab. + new byte[] {'0'}, + new byte[] {'A'}, + new byte[] {'a'}, + new byte[] {'I', 'U'}, + new byte[] {'`', 'h', 'g', ' ', 's', '`'}, + new byte[] {} + }; + // Indices correspond with the above array. + public static final String[] STRING_ARR = { + "09", + "30", + "41", + "61", + "4955", + "606867207360", + "" + }; + + @Test + public void testByte2Hex() throws Exception { + for (int i = 0; i < BYTE_ARRS.length; ++i) { + final byte[] b = BYTE_ARRS[i]; + final String expected = STRING_ARR[i]; + assertEquals(expected, Utils.byte2Hex(b)); + } + } + + @Test + public void testHex2Byte() throws Exception { + for (int i = 0; i < STRING_ARR.length; ++i) { + final String s = STRING_ARR[i]; + final byte[] expected = BYTE_ARRS[i]; + assertTrue(Arrays.equals(expected, Utils.hex2Byte(s))); + } + } + + @Test + public void testByte2Hex2ByteAndViceVersa() throws Exception { // There and back again! + for (int i = 0; i < BYTE_ARRS.length; ++i) { + // byte2Hex2Byte + final byte[] b = BYTE_ARRS[i]; + final String s = Utils.byte2Hex(b); + assertTrue(Arrays.equals(b, Utils.hex2Byte(s))); + } + + // hex2Byte2Hex + for (int i = 0; i < STRING_ARR.length; ++i) { + final String s = STRING_ARR[i]; + final byte[] b = Utils.hex2Byte(s); + assertEquals(s, Utils.byte2Hex(b)); + } + } + + @Test + public void testByte2HexLength() throws Exception { + for (int i = 0; i < BYTE_ARRS.length; ++i) { + final byte[] b = BYTE_ARRS[i]; + final String expected = STRING_ARR[i]; + assertEquals(expected, Utils.byte2Hex(b, b.length)); + assertEquals("0" + expected, Utils.byte2Hex(b, 2 * b.length + 1)); + assertEquals("00" + expected, Utils.byte2Hex(b, 2 * b.length + 2)); + } + } + + @Test + public void testHex2ByteLength() throws Exception { + for (int i = 0; i < STRING_ARR.length; ++i) { + final String s = STRING_ARR[i]; + final byte[] expected = BYTE_ARRS[i]; + assertTrue(Arrays.equals(expected, Utils.hex2Byte(s))); + final byte[] expected1 = new byte[expected.length + 1]; + System.arraycopy(expected, 0, expected1, 1, expected.length); + assertTrue(Arrays.equals(expected1, Utils.hex2Byte("00" + s))); + final byte[] expected2 = new byte[expected.length + 2]; + System.arraycopy(expected, 0, expected2, 2, expected.length); + assertTrue(Arrays.equals(expected2, Utils.hex2Byte("0000" + s))); + } + } + + @Test + public void testToCommaSeparatedString() { + ArrayList xs = new ArrayList(); + assertEquals("", Utils.toCommaSeparatedString(null)); + assertEquals("", Utils.toCommaSeparatedString(xs)); + xs.add("test1"); + assertEquals("test1", Utils.toCommaSeparatedString(xs)); + xs.add("test2"); + assertEquals("test1, test2", Utils.toCommaSeparatedString(xs)); + xs.add("test3"); + assertEquals("test1, test2, test3", Utils.toCommaSeparatedString(xs)); + } + + @Test + public void testUsernameFromAccount() throws NoSuchAlgorithmException, UnsupportedEncodingException { + assertEquals("xee7ffonluzpdp66l6xgpyh2v2w6ojkc", Utils.sha1Base32("foobar@baz.com")); + assertEquals("xee7ffonluzpdp66l6xgpyh2v2w6ojkc", Utils.usernameFromAccount("foobar@baz.com")); + assertEquals("xee7ffonluzpdp66l6xgpyh2v2w6ojkc", Utils.usernameFromAccount("FooBar@Baz.com")); + assertEquals("xee7ffonluzpdp66l6xgpyh2v2w6ojkc", Utils.usernameFromAccount("xee7ffonluzpdp66l6xgpyh2v2w6ojkc")); + assertEquals("foobar", Utils.usernameFromAccount("foobar")); + assertEquals("foobar", Utils.usernameFromAccount("FOOBAr")); + } + + @Test + public void testGetPrefsPath() throws NoSuchAlgorithmException, UnsupportedEncodingException { + assertEquals("ore7dlrwqi6xr7honxdtpvmh6tly4r7k", Utils.sha1Base32("test.url.com:xee7ffonluzpdp66l6xgpyh2v2w6ojkc")); + + assertEquals("sync.prefs.ore7dlrwqi6xr7honxdtpvmh6tly4r7k", Utils.getPrefsPath("product", "foobar@baz.com", "test.url.com", "default", 0)); + assertEquals("sync.prefs.ore7dlrwqi6xr7honxdtpvmh6tly4r7k", Utils.getPrefsPath("org.mozilla.firefox_beta", "FooBar@Baz.com", "test.url.com", "default", 0)); + assertEquals("sync.prefs.ore7dlrwqi6xr7honxdtpvmh6tly4r7k", Utils.getPrefsPath("org.mozilla.firefox", "xee7ffonluzpdp66l6xgpyh2v2w6ojkc", "test.url.com", "profile", 0)); + + assertEquals("sync.prefs.product.ore7dlrwqi6xr7honxdtpvmh6tly4r7k.default.1", Utils.getPrefsPath("product", "foobar@baz.com", "test.url.com", "default", 1)); + assertEquals("sync.prefs.with!spaces_underbars!periods.ore7dlrwqi6xr7honxdtpvmh6tly4r7k.default.1", Utils.getPrefsPath("with spaces_underbars.periods", "foobar@baz.com", "test.url.com", "default", 1)); + assertEquals("sync.prefs.org!mozilla!firefox_beta.ore7dlrwqi6xr7honxdtpvmh6tly4r7k.default.2", Utils.getPrefsPath("org.mozilla.firefox_beta", "FooBar@Baz.com", "test.url.com", "default", 2)); + assertEquals("sync.prefs.org!mozilla!firefox.ore7dlrwqi6xr7honxdtpvmh6tly4r7k.profile.3", Utils.getPrefsPath("org.mozilla.firefox", "xee7ffonluzpdp66l6xgpyh2v2w6ojkc", "test.url.com", "profile", 3)); + } + + @Test + public void testObfuscateEmail() { + assertEquals("XXX@XXX.XXX", Utils.obfuscateEmail("foo@bar.com")); + assertEquals("XXXX@XXX.XXXX.XX", Utils.obfuscateEmail("foot@bar.test.ca")); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/BaseTestStorageRequestDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/BaseTestStorageRequestDelegate.java new file mode 100644 index 000000000..a87925608 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/BaseTestStorageRequestDelegate.java @@ -0,0 +1,61 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate; +import org.mozilla.gecko.sync.net.SyncStorageResponse; + +import java.io.IOException; + +import static org.junit.Assert.fail; + +public class BaseTestStorageRequestDelegate implements + SyncStorageRequestDelegate { + + protected final AuthHeaderProvider authHeaderProvider; + + public BaseTestStorageRequestDelegate(AuthHeaderProvider authHeaderProvider) { + this.authHeaderProvider = authHeaderProvider; + } + + public BaseTestStorageRequestDelegate(String username, String password) { + this(new BasicAuthHeaderProvider(username, password)); + } + + @Override + public AuthHeaderProvider getAuthHeaderProvider() { + return authHeaderProvider; + } + + @Override + public String ifUnmodifiedSince() { + return null; + } + + @Override + public void handleRequestSuccess(SyncStorageResponse response) { + BaseResource.consumeEntity(response); + fail("Should not be called."); + } + + @Override + public void handleRequestFailure(SyncStorageResponse response) { + System.out.println("Response: " + response.httpResponse().getStatusLine().getStatusCode()); + BaseResource.consumeEntity(response); + fail("Should not be called."); + } + + @Override + public void handleRequestError(Exception e) { + if (e instanceof IOException) { + System.out.println("WARNING: TEST FAILURE IGNORED!"); + // Assume that this is because Jenkins doesn't have network access. + return; + } + fail("Should not error."); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessDelegate.java new file mode 100644 index 000000000..cf3545c1e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessDelegate.java @@ -0,0 +1,35 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.testhelpers.WaitHelper; + +public class ExpectSuccessDelegate { + public WaitHelper waitHelper; + + public ExpectSuccessDelegate(WaitHelper waitHelper) { + this.waitHelper = waitHelper; + } + + public void performNotify() { + this.waitHelper.performNotify(); + } + + public void performNotify(Throwable e) { + this.waitHelper.performNotify(e); + } + + public String logTag() { + return this.getClass().getSimpleName(); + } + + public void log(String message) { + Logger.info(logTag(), message); + } + + public void log(String message, Throwable throwable) { + Logger.warn(logTag(), message, throwable); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionBeginDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionBeginDelegate.java new file mode 100644 index 000000000..d7cb186f8 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionBeginDelegate.java @@ -0,0 +1,38 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import junit.framework.AssertionFailedError; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate; + +import java.util.concurrent.ExecutorService; + +public class ExpectSuccessRepositorySessionBeginDelegate +extends ExpectSuccessDelegate +implements RepositorySessionBeginDelegate { + + public ExpectSuccessRepositorySessionBeginDelegate(WaitHelper waitHelper) { + super(waitHelper); + } + + @Override + public void onBeginFailed(Exception ex) { + log("Session begin failed.", ex); + performNotify(new AssertionFailedError("Session begin failed: " + ex.getMessage())); + } + + @Override + public void onBeginSucceeded(RepositorySession session) { + log("Session begin succeeded."); + performNotify(); + } + + @Override + public RepositorySessionBeginDelegate deferredBeginDelegate(ExecutorService executor) { + log("Session begin delegate deferred."); + return this; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionCreationDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionCreationDelegate.java new file mode 100644 index 000000000..8860baf77 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionCreationDelegate.java @@ -0,0 +1,36 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import junit.framework.AssertionFailedError; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; + +public class ExpectSuccessRepositorySessionCreationDelegate extends + ExpectSuccessDelegate implements RepositorySessionCreationDelegate { + + public ExpectSuccessRepositorySessionCreationDelegate(WaitHelper waitHelper) { + super(waitHelper); + } + + @Override + public void onSessionCreateFailed(Exception ex) { + log("Session creation failed.", ex); + performNotify(new AssertionFailedError("onSessionCreateFailed: session creation should not have failed.")); + } + + @Override + public void onSessionCreated(RepositorySession session) { + log("Session creation succeeded."); + performNotify(); + } + + @Override + public RepositorySessionCreationDelegate deferredCreationDelegate() { + log("Session creation deferred."); + return this; + } + +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java new file mode 100644 index 000000000..5f5cf8995 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFetchRecordsDelegate.java @@ -0,0 +1,44 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import junit.framework.AssertionFailedError; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import java.util.ArrayList; +import java.util.concurrent.ExecutorService; + +public class ExpectSuccessRepositorySessionFetchRecordsDelegate extends + ExpectSuccessDelegate implements RepositorySessionFetchRecordsDelegate { + public ArrayList fetchedRecords = new ArrayList(); + + public ExpectSuccessRepositorySessionFetchRecordsDelegate(WaitHelper waitHelper) { + super(waitHelper); + } + + @Override + public void onFetchFailed(Exception ex, Record record) { + log("Fetch failed.", ex); + performNotify(new AssertionFailedError("onFetchFailed: fetch should not have failed.")); + } + + @Override + public void onFetchedRecord(Record record) { + fetchedRecords.add(record); + log("Fetched record with guid '" + record.guid + "'."); + } + + @Override + public void onFetchCompleted(long end) { + log("Fetch completed."); + performNotify(); + } + + @Override + public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) { + return this; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFinishDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFinishDelegate.java new file mode 100644 index 000000000..4435d5fa2 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionFinishDelegate.java @@ -0,0 +1,37 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import junit.framework.AssertionFailedError; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; + +import java.util.concurrent.ExecutorService; + +public class ExpectSuccessRepositorySessionFinishDelegate extends + ExpectSuccessDelegate implements RepositorySessionFinishDelegate { + + public ExpectSuccessRepositorySessionFinishDelegate(WaitHelper waitHelper) { + super(waitHelper); + } + + @Override + public void onFinishFailed(Exception ex) { + log("Finish failed.", ex); + performNotify(new AssertionFailedError("onFinishFailed: finish should not have failed.")); + } + + @Override + public void onFinishSucceeded(RepositorySession session, RepositorySessionBundle bundle) { + log("Finish succeeded."); + performNotify(); + } + + @Override + public RepositorySessionFinishDelegate deferredFinishDelegate(ExecutorService executor) { + return this; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionStoreDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionStoreDelegate.java new file mode 100644 index 000000000..cfca180fa --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositorySessionStoreDelegate.java @@ -0,0 +1,39 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import junit.framework.AssertionFailedError; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; + +import java.util.concurrent.ExecutorService; + +public class ExpectSuccessRepositorySessionStoreDelegate extends + ExpectSuccessDelegate implements RepositorySessionStoreDelegate { + + public ExpectSuccessRepositorySessionStoreDelegate(WaitHelper waitHelper) { + super(waitHelper); + } + + @Override + public void onRecordStoreFailed(Exception ex, String guid) { + log("Record store failed.", ex); + performNotify(new AssertionFailedError("onRecordStoreFailed: record store should not have failed.")); + } + + @Override + public void onRecordStoreSucceeded(String guid) { + log("Record store succeeded."); + } + + @Override + public void onStoreCompleted(long storeEnd) { + log("Record store completed at " + storeEnd); + } + + @Override + public RepositorySessionStoreDelegate deferredStoreDelegate(ExecutorService executor) { + return this; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositoryWipeDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositoryWipeDelegate.java new file mode 100644 index 000000000..0f248dda7 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/ExpectSuccessRepositoryWipeDelegate.java @@ -0,0 +1,36 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import junit.framework.AssertionFailedError; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; + +import java.util.concurrent.ExecutorService; + +public class ExpectSuccessRepositoryWipeDelegate extends ExpectSuccessDelegate + implements RepositorySessionWipeDelegate { + + public ExpectSuccessRepositoryWipeDelegate(WaitHelper waitHelper) { + super(waitHelper); + } + + @Override + public void onWipeSucceeded() { + log("Wipe succeeded."); + performNotify(); + } + + @Override + public void onWipeFailed(Exception ex) { + log("Wipe failed.", ex); + performNotify(new AssertionFailedError("onWipeFailed: wipe should not have failed.")); + } + + @Override + public RepositorySessionWipeDelegate deferredWipeDelegate(ExecutorService executor) { + log("Wipe deferred."); + return this; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/HTTPServerTestHelper.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/HTTPServerTestHelper.java new file mode 100644 index 000000000..1829bdd12 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/HTTPServerTestHelper.java @@ -0,0 +1,226 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.BaseResourceDelegate; +import org.simpleframework.http.core.ContainerSocketProcessor; +import org.simpleframework.transport.connect.Connection; +import org.simpleframework.transport.connect.SocketConnection; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.util.IdentityHashMap; +import java.util.Map; + +import static org.junit.Assert.fail; + +/** + * Test helper code to bind MockServer instances to ports. + *

+ * Maintains a collection of running servers and (by default) throws helpful + * errors if two servers are started "on top" of each other. The + * unchecked exception thrown contains a stack trace pointing to where + * the new server is being created and where the pre-existing server was + * created. + *

+ * Parses a system property to determine current test port, which is fixed for + * the duration of a test execution. + */ +public class HTTPServerTestHelper { + private static final String LOG_TAG = "HTTPServerTestHelper"; + + /** + * Port to run HTTP servers on during this test execution. + *

+ * Lazily initialized on first call to {@link #getTestPort}. + */ + public static Integer testPort = null; + + public static final String LOCAL_HTTP_PORT_PROPERTY = "android.sync.local.http.port"; + public static final int LOCAL_HTTP_PORT_DEFAULT = 15125; + + public final int port; + + public Connection connection; + public MockServer server; + + /** + * Create a helper to bind MockServer instances. + *

+ * Use {@link #getTestPort} to determine the port this helper will bind to. + */ + public HTTPServerTestHelper() { + this.port = getTestPort(); + } + + // For testing only. + protected HTTPServerTestHelper(int port) { + this.port = port; + } + + /** + * Lazily initialize test port for this test execution. + *

+ * Only called from {@link #getTestPort}. + *

+ * If the test port has not been determined, we try to parse it from a system + * property; if that fails, we return the default test port. + */ + protected synchronized static void ensureTestPort() { + if (testPort != null) { + return; + } + + String value = System.getProperty(LOCAL_HTTP_PORT_PROPERTY); + if (value != null) { + try { + testPort = Integer.valueOf(value); + } catch (NumberFormatException e) { + Logger.warn(LOG_TAG, "Got exception parsing local test port; ignoring. ", e); + } + } + + if (testPort == null) { + testPort = Integer.valueOf(LOCAL_HTTP_PORT_DEFAULT); + } + } + + /** + * The port to which all HTTP servers will be found for the duration of this + * test execution. + *

+ * We try to parse the port from a system property; if that fails, we return + * the default test port. + * + * @return port number. + */ + public synchronized static int getTestPort() { + if (testPort == null) { + ensureTestPort(); + } + + return testPort.intValue(); + } + + /** + * Used to maintain a stack trace pointing to where a server was started. + */ + public static class HTTPServerStartedError extends Error { + private static final long serialVersionUID = -6778447718799087274L; + + public final HTTPServerTestHelper httpServer; + + public HTTPServerStartedError(HTTPServerTestHelper httpServer) { + this.httpServer = httpServer; + } + } + + /** + * Thrown when a server is started "on top" of another server. The cause error + * will be an HTTPServerStartedError with a stack trace pointing + * to where the pre-existing server was started. + */ + public static class HTTPServerAlreadyRunningError extends Error { + private static final long serialVersionUID = -6778447718799087275L; + + public HTTPServerAlreadyRunningError(Throwable e) { + super(e); + } + } + + /** + * Maintain a hash of running servers. Each value is an error with a stack + * traces pointing to where that server was started. + *

+ * We don't key on the server itself because each server is a helper + * that may be started many times with different MockServer + * instances. + *

+ * Synchronize access on the class. + */ + protected static Map runningServers = + new IdentityHashMap(); + + protected synchronized static void throwIfServerAlreadyRunning() { + for (HTTPServerStartedError value : runningServers.values()) { + throw new HTTPServerAlreadyRunningError(value); + } + } + + protected synchronized static void registerServerAsRunning(HTTPServerTestHelper httpServer) { + if (httpServer == null || httpServer.connection == null) { + throw new IllegalArgumentException("HTTPServerTestHelper or connection was null; perhaps server has not been started?"); + } + + HTTPServerStartedError old = runningServers.put(httpServer.connection, new HTTPServerStartedError(httpServer)); + if (old != null) { + // Should never happen. + throw old; + } + } + + protected synchronized static void unregisterServerAsRunning(HTTPServerTestHelper httpServer) { + if (httpServer == null || httpServer.connection == null) { + throw new IllegalArgumentException("HTTPServerTestHelper or connection was null; perhaps server has not been started?"); + } + + runningServers.remove(httpServer.connection); + } + + public MockServer startHTTPServer(MockServer server, boolean allowMultipleServers) { + BaseResource.rewriteLocalhost = false; // No sense rewriting when we're running the unit tests. + BaseResourceDelegate.connectionTimeoutInMillis = 1000; // No sense waiting a long time for a local connection. + + if (!allowMultipleServers) { + throwIfServerAlreadyRunning(); + } + + try { + this.server = server; + connection = new SocketConnection(new ContainerSocketProcessor(server)); + SocketAddress address = new InetSocketAddress(port); + connection.connect(address); + + registerServerAsRunning(this); + + Logger.info(LOG_TAG, "Started HTTP server on port " + port + "."); + } catch (IOException ex) { + Logger.error(LOG_TAG, "Error starting HTTP server on port " + port + ".", ex); + fail(ex.toString()); + } + + return server; + } + + public MockServer startHTTPServer(MockServer server) { + return startHTTPServer(server, false); + } + + public MockServer startHTTPServer() { + return startHTTPServer(new MockServer()); + } + + public void stopHTTPServer() { + try { + if (connection != null) { + unregisterServerAsRunning(this); + + connection.close(); + } + server = null; + connection = null; + + Logger.info(LOG_TAG, "Stopped HTTP server on port " + port + "."); + + Logger.debug(LOG_TAG, "Closing connection pool..."); + BaseResource.shutdownConnectionManager(); + } catch (IOException ex) { + Logger.error(LOG_TAG, "Error stopping HTTP server on port " + port + ".", ex); + fail(ex.toString()); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockGlobalSessionCallback.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockGlobalSessionCallback.java new file mode 100644 index 000000000..5d7e8edd1 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockGlobalSessionCallback.java @@ -0,0 +1,91 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; + +import java.net.URI; + +import static org.junit.Assert.assertEquals; + +/** + * A callback for use with a GlobalSession that records what happens for later + * inspection. + * + * This callback is expected to be used from within the friendly confines of a + * WaitHelper performWait. + */ +public class MockGlobalSessionCallback implements GlobalSessionCallback { + protected WaitHelper testWaiter() { + return WaitHelper.getTestWaiter(); + } + + public int stageCounter = Stage.values().length - 1; // Exclude starting state. + public boolean calledSuccess = false; + public boolean calledError = false; + public Exception calledErrorException = null; + public boolean calledAborted = false; + public boolean calledRequestBackoff = false; + public boolean calledInformUnauthorizedResponse = false; + public boolean calledInformUpgradeRequiredResponse = false; + public boolean calledInformMigrated = false; + public URI calledInformUnauthorizedResponseClusterURL = null; + public long weaveBackoff = -1; + + @Override + public void handleSuccess(GlobalSession globalSession) { + this.calledSuccess = true; + assertEquals(0, this.stageCounter); + this.testWaiter().performNotify(); + } + + @Override + public void handleAborted(GlobalSession globalSession, String reason) { + this.calledAborted = true; + this.testWaiter().performNotify(); + } + + @Override + public void handleError(GlobalSession globalSession, Exception ex) { + this.calledError = true; + this.calledErrorException = ex; + this.testWaiter().performNotify(); + } + + @Override + public void handleStageCompleted(Stage currentState, + GlobalSession globalSession) { + stageCounter--; + } + + @Override + public void requestBackoff(long backoff) { + this.calledRequestBackoff = true; + this.weaveBackoff = backoff; + } + + @Override + public void informUnauthorizedResponse(GlobalSession session, URI clusterURL) { + this.calledInformUnauthorizedResponse = true; + this.calledInformUnauthorizedResponseClusterURL = clusterURL; + } + + @Override + public void informUpgradeRequiredResponse(GlobalSession session) { + this.calledInformUpgradeRequiredResponse = true; + } + + @Override + public void informMigrated(GlobalSession session) { + this.calledInformMigrated = true; + } + + @Override + public boolean shouldBackOffStorage() { + return false; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockResourceDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockResourceDelegate.java new file mode 100644 index 000000000..2cac07904 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockResourceDelegate.java @@ -0,0 +1,85 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import ch.boye.httpclientandroidlib.HttpResponse; +import ch.boye.httpclientandroidlib.client.ClientProtocolException; +import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase; +import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.net.ResourceDelegate; + +import java.io.IOException; +import java.security.GeneralSecurityException; + +import static org.junit.Assert.assertEquals; + +public class MockResourceDelegate implements ResourceDelegate { + public WaitHelper waitHelper = null; + public static String USER_PASS = "john:password"; + public static String EXPECT_BASIC = "Basic am9objpwYXNzd29yZA=="; + + public boolean handledHttpResponse = false; + public HttpResponse httpResponse = null; + + public MockResourceDelegate(WaitHelper waitHelper) { + this.waitHelper = waitHelper; + } + + public MockResourceDelegate() { + this.waitHelper = WaitHelper.getTestWaiter(); + } + + @Override + public String getUserAgent() { + return null; + } + + @Override + public void addHeaders(HttpRequestBase request, DefaultHttpClient client) { + } + + @Override + public int connectionTimeout() { + return 0; + } + + @Override + public int socketTimeout() { + return 0; + } + + @Override + public AuthHeaderProvider getAuthHeaderProvider() { + return new BasicAuthHeaderProvider(USER_PASS); + } + + @Override + public void handleHttpProtocolException(ClientProtocolException e) { + waitHelper.performNotify(e); + } + + @Override + public void handleHttpIOException(IOException e) { + waitHelper.performNotify(e); + } + + @Override + public void handleTransportException(GeneralSecurityException e) { + waitHelper.performNotify(e); + } + + @Override + public void handleHttpResponse(HttpResponse response) { + handledHttpResponse = true; + httpResponse = response; + + assertEquals(response.getStatusLine().getStatusCode(), 200); + BaseResource.consumeEntity(response); + waitHelper.performNotify(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockServer.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockServer.java new file mode 100644 index 000000000..4e1d6d7ad --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockServer.java @@ -0,0 +1,73 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.sync.Utils; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; +import org.simpleframework.http.core.Container; + +import java.io.IOException; +import java.io.PrintStream; + +import static org.junit.Assert.assertEquals; + +public class MockServer implements Container { + public static final String LOG_TAG = "MockServer"; + + public int statusCode = 200; + public String body = "Hello World"; + + public MockServer() { + } + + public MockServer(int statusCode, String body) { + this.statusCode = statusCode; + this.body = body; + } + + public String expectedBasicAuthHeader; + + protected PrintStream handleBasicHeaders(Request request, Response response, int code, String contentType) throws IOException { + return this.handleBasicHeaders(request, response, code, contentType, System.currentTimeMillis()); + } + + protected PrintStream handleBasicHeaders(Request request, Response response, int code, String contentType, long time) throws IOException { + Logger.debug(LOG_TAG, "< Auth header: " + request.getValue("Authorization")); + + PrintStream bodyStream = response.getPrintStream(); + response.setCode(code); + response.setValue("Content-Type", contentType); + response.setValue("Server", "HelloWorld/1.0 (Simple 4.0)"); + response.setDate("Date", time); + response.setDate("Last-Modified", time); + + final String timestampHeader = Utils.millisecondsToDecimalSecondsString(time); + response.setValue("X-Weave-Timestamp", timestampHeader); + Logger.debug(LOG_TAG, "> X-Weave-Timestamp header: " + timestampHeader); + response.setValue("X-Last-Modified", "12345678"); + return bodyStream; + } + + protected void handle(Request request, Response response, int code, String body) { + try { + Logger.debug(LOG_TAG, "Handling request..."); + PrintStream bodyStream = this.handleBasicHeaders(request, response, code, "application/json"); + + if (expectedBasicAuthHeader != null) { + Logger.debug(LOG_TAG, "Expecting auth header " + expectedBasicAuthHeader); + assertEquals(request.getValue("Authorization"), expectedBasicAuthHeader); + } + + bodyStream.println(body); + bodyStream.close(); + } catch (IOException e) { + Logger.error(LOG_TAG, "Oops."); + } + } + public void handle(Request request, Response response) { + this.handle(request, response, statusCode, body); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockSyncClientsEngineStage.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockSyncClientsEngineStage.java new file mode 100644 index 000000000..efd379e13 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockSyncClientsEngineStage.java @@ -0,0 +1,71 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers; + +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.mozilla.gecko.sync.stage.SyncClientsEngineStage; + +import static org.junit.Assert.assertTrue; + +public class MockSyncClientsEngineStage extends SyncClientsEngineStage { + public class MockClientUploadDelegate extends ClientUploadDelegate { + HTTPServerTestHelper data; + + public MockClientUploadDelegate(HTTPServerTestHelper data) { + this.data = data; + } + + @Override + public void handleRequestSuccess(SyncStorageResponse response) { + assertTrue(response.wasSuccessful()); + data.stopHTTPServer(); + super.handleRequestSuccess(response); + } + + @Override + public void handleRequestFailure(SyncStorageResponse response) { + BaseResource.consumeEntity(response); + data.stopHTTPServer(); + super.handleRequestFailure(response); + } + + @Override + public void handleRequestError(Exception ex) { + ex.printStackTrace(); + data.stopHTTPServer(); + super.handleRequestError(ex); + } + } + + public class TestClientDownloadDelegate extends ClientDownloadDelegate { + HTTPServerTestHelper data; + + public TestClientDownloadDelegate(HTTPServerTestHelper data) { + this.data = data; + } + + @Override + public void handleRequestSuccess(SyncStorageResponse response) { + assertTrue(response.wasSuccessful()); + BaseResource.consumeEntity(response); + data.stopHTTPServer(); + super.handleRequestSuccess(response); + } + + @Override + public void handleRequestFailure(SyncStorageResponse response) { + BaseResource.consumeEntity(response); + super.handleRequestFailure(response); + data.stopHTTPServer(); + } + + @Override + public void handleRequestError(Exception ex) { + ex.printStackTrace(); + super.handleRequestError(ex); + data.stopHTTPServer(); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockWBOServer.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockWBOServer.java new file mode 100644 index 000000000..164274bac --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/MockWBOServer.java @@ -0,0 +1,28 @@ +package org.mozilla.android.sync.test.helpers; + +import org.simpleframework.http.Path; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.util.HashMap; + +/** + * A trivial server that collects and returns WBOs. + * + * @author rnewman + * + */ +public class MockWBOServer extends MockServer { + public HashMap > collections; + + public MockWBOServer() { + collections = new HashMap >(); + } + + @Override + public void handle(Request request, Response response) { + Path path = request.getPath(); + path.getPath(0); + // TODO + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/test/TestHTTPServerTestHelper.java b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/test/TestHTTPServerTestHelper.java new file mode 100644 index 000000000..d79998cc9 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/android/sync/test/helpers/test/TestHTTPServerTestHelper.java @@ -0,0 +1,102 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.android.sync.test.helpers.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper.HTTPServerAlreadyRunningError; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestHTTPServerTestHelper { + public static final int TEST_PORT = HTTPServerTestHelper.getTestPort(); + + protected MockServer mockServer = new MockServer(); + + @Test + public void testStartStop() { + // Need to be able to start and stop multiple times. + for (int i = 0; i < 2; i++) { + HTTPServerTestHelper httpServer = new HTTPServerTestHelper(); + + assertNull(httpServer.connection); + httpServer.startHTTPServer(mockServer); + + assertNotNull(httpServer.connection); + httpServer.stopHTTPServer(); + } + } + + public void startAgain() { + HTTPServerTestHelper httpServer = new HTTPServerTestHelper(); + httpServer.startHTTPServer(mockServer); + } + + @Test + public void testStartTwice() { + HTTPServerTestHelper httpServer = new HTTPServerTestHelper(); + + httpServer.startHTTPServer(mockServer); + assertNotNull(httpServer.connection); + + // Should not be able to start multiple times. + try { + try { + startAgain(); + + fail("Expected exception."); + } catch (Throwable e) { + assertEquals(HTTPServerAlreadyRunningError.class, e.getClass()); + + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + String s = sw.toString(); + + // Ensure we get a useful stack trace. + // We should have the method trying to start the server the second time... + assertTrue(s.contains("startAgain")); + // ... as well as the the method that started the server the first time. + assertTrue(s.contains("testStartTwice")); + } + } finally { + httpServer.stopHTTPServer(); + } + } + + protected static class LeakyHTTPServerTestHelper extends HTTPServerTestHelper { + // Make this constructor public, just for this test. + public LeakyHTTPServerTestHelper(int port) { + super(port); + } + } + + @Test + public void testForceStartTwice() { + HTTPServerTestHelper httpServer1 = new HTTPServerTestHelper(); + HTTPServerTestHelper httpServer2 = new LeakyHTTPServerTestHelper(httpServer1.port + 1); + + // Should be able to start multiple times if we specify it. + try { + httpServer1.startHTTPServer(mockServer); + assertNotNull(httpServer1.connection); + + httpServer2.startHTTPServer(mockServer, true); + assertNotNull(httpServer2.connection); + } finally { + httpServer1.stopHTTPServer(); + httpServer2.stopHTTPServer(); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/GeckoNetworkManagerTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/GeckoNetworkManagerTest.java new file mode 100644 index 000000000..8b07d7448 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/GeckoNetworkManagerTest.java @@ -0,0 +1,51 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.GeckoNetworkManager.ManagerState; +import org.mozilla.gecko.GeckoNetworkManager.ManagerEvent; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class GeckoNetworkManagerTest { + /** + * Tests the transition matrix. + */ + @Test + public void testGetNextState() { + ManagerState testingState; + + testingState = ManagerState.OffNoListeners; + assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.disableNotifications)); + assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.stop)); + assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.receivedUpdate)); + assertEquals(ManagerState.OnNoListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.start)); + assertEquals(ManagerState.OffWithListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.enableNotifications)); + + testingState = ManagerState.OnNoListeners; + assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.start)); + assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.disableNotifications)); + assertEquals(ManagerState.OnWithListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.enableNotifications)); + assertEquals(ManagerState.OffNoListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.stop)); + assertEquals(ManagerState.OnNoListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.receivedUpdate)); + + testingState = ManagerState.OnWithListeners; + assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.start)); + assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.enableNotifications)); + assertEquals(ManagerState.OffWithListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.stop)); + assertEquals(ManagerState.OnNoListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.disableNotifications)); + assertEquals(ManagerState.OnWithListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.receivedUpdate)); + + testingState = ManagerState.OffWithListeners; + assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.stop)); + assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.enableNotifications)); + assertNull(GeckoNetworkManager.getNextState(testingState, ManagerEvent.receivedUpdate)); + assertEquals(ManagerState.OnWithListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.start)); + assertEquals(ManagerState.OffNoListeners, GeckoNetworkManager.getNextState(testingState, ManagerEvent.disableNotifications)); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/GlobalPageMetadataTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/GlobalPageMetadataTest.java new file mode 100644 index 000000000..f30ee7a2c --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/GlobalPageMetadataTest.java @@ -0,0 +1,174 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko; + +import android.content.ContentProviderClient; +import android.content.ContentValues; +import android.database.Cursor; +import android.os.RemoteException; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.db.DelegatingTestContentProvider; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.db.BrowserContract.PageMetadata; +import org.mozilla.gecko.db.BrowserDB; +import org.mozilla.gecko.db.BrowserProvider; +import org.mozilla.gecko.db.LocalBrowserDB; +import org.robolectric.shadows.ShadowContentResolver; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class GlobalPageMetadataTest { + @Test + public void testQueueing() throws Exception { + BrowserDB db = new LocalBrowserDB("default"); + + BrowserProvider provider = new BrowserProvider(); + try { + provider.onCreate(); + ShadowContentResolver.registerProvider(BrowserContract.AUTHORITY, new DelegatingTestContentProvider(provider)); + + ShadowContentResolver cr = new ShadowContentResolver(); + ContentProviderClient pageMetadataClient = cr.acquireContentProviderClient(PageMetadata.CONTENT_URI); + + assertEquals(0, GlobalPageMetadata.getInstance().getMetadataQueueSize()); + + // There's not history record for this uri, so test that queueing works. + GlobalPageMetadata.getInstance().doAddOrQueue(db, pageMetadataClient, "https://mozilla.org", false, "{type: 'article'}"); + + assertPageMetadataCountForGUID(0, "guid1", pageMetadataClient); + assertEquals(1, GlobalPageMetadata.getInstance().getMetadataQueueSize()); + + // Test that queue doesn't duplicate metadata for the same history item. + GlobalPageMetadata.getInstance().doAddOrQueue(db, pageMetadataClient, "https://mozilla.org", false, "{type: 'article'}"); + assertEquals(1, GlobalPageMetadata.getInstance().getMetadataQueueSize()); + + // Test that queue is limited to 15 metadata items. + for (int i = 0; i < 20; i++) { + GlobalPageMetadata.getInstance().doAddOrQueue(db, pageMetadataClient, "https://mozilla.org/" + i, false, "{type: 'article'}"); + } + assertEquals(15, GlobalPageMetadata.getInstance().getMetadataQueueSize()); + } finally { + provider.shutdown(); + } + } + + @Test + public void testInsertingMetadata() throws Exception { + BrowserDB db = new LocalBrowserDB("default"); + + // Start listening for events. + GlobalPageMetadata.getInstance().init(); + + BrowserProvider provider = new BrowserProvider(); + try { + provider.onCreate(); + ShadowContentResolver.registerProvider(BrowserContract.AUTHORITY, new DelegatingTestContentProvider(provider)); + + ShadowContentResolver cr = new ShadowContentResolver(); + ContentProviderClient historyClient = cr.acquireContentProviderClient(BrowserContract.History.CONTENT_URI); + ContentProviderClient pageMetadataClient = cr.acquireContentProviderClient(PageMetadata.CONTENT_URI); + + // Insert required history item... + ContentValues cv = new ContentValues(); + cv.put(BrowserContract.History.GUID, "guid1"); + cv.put(BrowserContract.History.URL, "https://mozilla.org"); + historyClient.insert(BrowserContract.History.CONTENT_URI, cv); + + // TODO: Main test runner thread finishes before EventDispatcher events are processed... + // Fire off a message saying that history has been inserted. + // Bundle message = new Bundle(); + // message.putString(GlobalHistory.EVENT_PARAM_URI, "https://mozilla.org"); + // EventDispatcher.getInstance().dispatch(GlobalHistory.EVENT_URI_AVAILABLE_IN_HISTORY, message); + + // For now, let's just try inserting again. + GlobalPageMetadata.getInstance().doAddOrQueue(db, pageMetadataClient, "https://mozilla.org", false, "{type: 'article', description: 'test article'}"); + + assertPageMetadataCountForGUID(1, "guid1", pageMetadataClient); + assertPageMetadataValues(pageMetadataClient, "guid1", false, "{\"type\":\"article\",\"description\":\"test article\"}"); + + // Test that inserting empty metadata deletes existing metadata record. + GlobalPageMetadata.getInstance().doAddOrQueue(db, pageMetadataClient, "https://mozilla.org", false, "{}"); + assertPageMetadataCountForGUID(0, "guid1", pageMetadataClient); + + // Test that inserting new metadata overrides existing metadata record. + GlobalPageMetadata.getInstance().doAddOrQueue(db, pageMetadataClient, "https://mozilla.org", true, "{type: 'article', description: 'test article', image_url: 'https://example.com/test.png'}"); + assertPageMetadataValues(pageMetadataClient, "guid1", true, "{\"type\":\"article\",\"description\":\"test article\",\"image_url\":\"https:\\/\\/example.com\\/test.png\"}"); + + // Insert another history item... + cv = new ContentValues(); + cv.put(BrowserContract.History.GUID, "guid2"); + cv.put(BrowserContract.History.URL, "https://planet.mozilla.org"); + historyClient.insert(BrowserContract.History.CONTENT_URI, cv); + // Test that empty metadata doesn't get inserted for a new history. + GlobalPageMetadata.getInstance().doAddOrQueue(db, pageMetadataClient, "https://planet.mozilla.org", false, "{}"); + + assertPageMetadataCountForGUID(0, "guid2", pageMetadataClient); + + } finally { + provider.shutdown(); + } + } + + /** + * Expects cursor to be at the correct position. + */ + private void assertCursorValues(Cursor cursor, String json, int hasImage, String guid) { + assertNotNull(cursor); + assertEquals(json, cursor.getString(cursor.getColumnIndexOrThrow(PageMetadata.JSON))); + assertEquals(hasImage, cursor.getInt(cursor.getColumnIndexOrThrow(PageMetadata.HAS_IMAGE))); + assertEquals(guid, cursor.getString(cursor.getColumnIndexOrThrow(PageMetadata.HISTORY_GUID))); + } + + private void assertPageMetadataValues(ContentProviderClient client, String guid, boolean hasImage, String json) { + final Cursor cursor; + + try { + cursor = client.query(PageMetadata.CONTENT_URI, new String[]{ + PageMetadata.HISTORY_GUID, + PageMetadata.HAS_IMAGE, + PageMetadata.JSON, + PageMetadata.DATE_CREATED + }, PageMetadata.HISTORY_GUID + " = ?", new String[]{guid}, null); + } catch (RemoteException e) { + fail(); + return; + } + + assertNotNull(cursor); + try { + assertEquals(1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + assertCursorValues(cursor, json, hasImage ? 1 : 0, guid); + } finally { + cursor.close(); + } + } + + private void assertPageMetadataCountForGUID(int expected, String guid, ContentProviderClient client) { + final Cursor cursor; + + try { + cursor = client.query(PageMetadata.CONTENT_URI, new String[]{ + PageMetadata.HISTORY_GUID, + PageMetadata.HAS_IMAGE, + PageMetadata.JSON, + PageMetadata.DATE_CREATED + }, PageMetadata.HISTORY_GUID + " = ?", new String[]{guid}, null); + } catch (RemoteException e) { + fail(); + return; + } + + assertNotNull(cursor); + try { + assertEquals(expected, cursor.getCount()); + } finally { + cursor.close(); + } + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/TestGeckoProfile.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/TestGeckoProfile.java new file mode 100644 index 000000000..c01c2d21a --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/TestGeckoProfile.java @@ -0,0 +1,254 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko; + +import android.content.Context; + +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.util.FileUtils; +import org.robolectric.RuntimeEnvironment; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +import static org.junit.Assert.*; + +/** + * Unit test methods of the GeckoProfile class. + */ +@RunWith(TestRunner.class) +public class TestGeckoProfile { + private static final String PROFILE_NAME = "profileName"; + + private static final String CLIENT_ID_JSON_ATTR = "clientID"; + private static final String PROFILE_CREATION_DATE_JSON_ATTR = "created"; + + @Rule + public TemporaryFolder dirContainingProfile = new TemporaryFolder(); + + private File profileDir; + private GeckoProfile profile; + + private File clientIdFile; + private File timesFile; + + @Before + public void setUp() throws IOException { + final Context context = RuntimeEnvironment.application; + profileDir = dirContainingProfile.newFolder(); + profile = GeckoProfile.get(context, PROFILE_NAME, profileDir); + + clientIdFile = new File(profileDir, "datareporting/state.json"); + timesFile = new File(profileDir, "times.json"); + } + + public void assertValidClientId(final String clientId) { + // This isn't the method we use in the main GeckoProfile code, but it should be equivalent. + UUID.fromString(clientId); // assert: will throw if null or invalid UUID. + } + + @Test + public void testGetDir() { + assertEquals("Profile dir argument during construction and returned value are equal", + profileDir, profile.getDir()); + } + + @Test + public void testGetClientIdFreshProfile() throws Exception { + assertFalse("client ID file does not exist", clientIdFile.exists()); + + // No existing client ID file: we're expected to create one. + final String clientId = profile.getClientId(); + assertValidClientId(clientId); + assertTrue("client ID file exists", clientIdFile.exists()); + + assertEquals("Returned client ID is the same as the one previously returned", clientId, profile.getClientId()); + assertEquals("clientID file format matches expectations", clientId, readClientIdFromFile(clientIdFile)); + } + + @Test + public void testGetClientIdFileAlreadyExists() throws Exception { + final String validClientId = "905de1c0-0ea6-4a43-95f9-6170035f5a82"; + assertTrue("Created the parent dirs of the client ID file", clientIdFile.getParentFile().mkdirs()); + writeClientIdToFile(clientIdFile, validClientId); + + final String clientIdFromProfile = profile.getClientId(); + assertEquals("Client ID from method matches ID written to disk", validClientId, clientIdFromProfile); + } + + @Test + public void testGetClientIdMigrateFromFHR() throws Exception { + final File fhrClientIdFile = new File(profileDir, "healthreport/state.json"); + final String fhrClientId = "905de1c0-0ea6-4a43-95f9-6170035f5a82"; + + assertFalse("client ID file does not exist", clientIdFile.exists()); + assertTrue("Created FHR data directory", new File(profileDir, "healthreport").mkdirs()); + writeClientIdToFile(fhrClientIdFile, fhrClientId); + assertEquals("Migrated Client ID equals FHR client ID", fhrClientId, profile.getClientId()); + + // Verify migration wrote to contemporary client ID file. + assertTrue("Client ID file created during migration", clientIdFile.exists()); + assertEquals("Migrated client ID on disk equals value returned from method", + fhrClientId, readClientIdFromFile(clientIdFile)); + + assertTrue("Deleted FHR clientID file", fhrClientIdFile.delete()); + assertEquals("Ensure method calls read from newly created client ID file & not FHR client ID file", + fhrClientId, profile.getClientId()); + } + + @Test + public void testGetClientIdInvalidIdOnDisk() throws Exception { + assertTrue("Created the parent dirs of the client ID file", clientIdFile.getParentFile().mkdirs()); + writeClientIdToFile(clientIdFile, ""); + final String clientIdForEmptyString = profile.getClientId(); + assertValidClientId(clientIdForEmptyString); + assertNotEquals("A new client ID was created when the empty String was written to disk", "", clientIdForEmptyString); + + writeClientIdToFile(clientIdFile, "invalidClientId"); + final String clientIdForInvalidClientId = profile.getClientId(); + assertValidClientId(clientIdForInvalidClientId); + assertNotEquals("A new client ID was created when an invalid client ID was written to disk", + "invalidClientId", clientIdForInvalidClientId); + } + + @Test + public void testGetClientIdMissingClientIdJSONAttr() throws Exception { + final String validClientId = "905de1c0-0ea6-4a43-95f9-6170035f5a82"; + final JSONObject objMissingClientId = new JSONObject(); + objMissingClientId.put("irrelevantKey", validClientId); + assertTrue("Created the parent dirs of the client ID file", clientIdFile.getParentFile().mkdirs()); + FileUtils.writeJSONObjectToFile(clientIdFile, objMissingClientId); + + final String clientIdForMissingAttr = profile.getClientId(); + assertValidClientId(clientIdForMissingAttr); + assertNotEquals("Did not use other attr when JSON attr was missing", validClientId, clientIdForMissingAttr); + } + + @Test + public void testGetClientIdInvalidIdFileFormat() throws Exception { + final String validClientId = "905de1c0-0ea6-4a43-95f9-6170035f5a82"; + assertTrue("Created the parent dirs of the client ID file", clientIdFile.getParentFile().mkdirs()); + FileUtils.writeStringToFile(clientIdFile, "clientID: \"" + validClientId + "\""); + + final String clientIdForInvalidFormat = profile.getClientId(); + assertValidClientId(clientIdForInvalidFormat); + assertNotEquals("Created new ID when file format was invalid", validClientId, clientIdForInvalidFormat); + } + + @Test + public void testEnsureParentDirs() { + final File grandParentDir = new File(profileDir, "grandParent"); + final File parentDir = new File(grandParentDir, "parent"); + final File childFile = new File(parentDir, "child"); + + // Assert initial state. + assertFalse("Topmost parent dir should not exist yet", grandParentDir.exists()); + assertFalse("Bottommost parent dir should not exist yet", parentDir.exists()); + assertFalse("Child file should not exist", childFile.exists()); + + final String fakeFullPath = "grandParent/parent/child"; + assertTrue("Parent directories should be created", profile.ensureParentDirs(fakeFullPath)); + assertTrue("Topmost parent dir should have been created", grandParentDir.exists()); + assertTrue("Bottommost parent dir should have been created", parentDir.exists()); + assertFalse("Child file should not have been created", childFile.exists()); + + // Parents already exist because this is the second time we're calling ensureParentDirs. + assertTrue("Expect true if parent directories already exist", profile.ensureParentDirs(fakeFullPath)); + + // Assert error condition. + assertTrue("Ensure we can change permissions on profile dir for testing", profileDir.setReadOnly()); + assertFalse("Expect false if the parent dir could not be created", profile.ensureParentDirs("unwritableDir/child")); + } + + @Test + public void testIsClientIdValid() { + final String[] validClientIds = new String[] { + "905de1c0-0ea6-4a43-95f9-6170035f5a82", + "905de1c0-0ea6-4a43-95f9-6170035f5a83", + "57472f82-453d-4c55-b59c-d3c0e97b76a1", + "895745d1-f31e-46c3-880e-b4dd72963d4f", + }; + for (final String validClientId : validClientIds) { + assertTrue("Client ID, " + validClientId + ", is valid", profile.isClientIdValid(validClientId)); + } + + final String[] invalidClientIds = new String[] { + null, + "", + "a", + "anInvalidClientId", + "905de1c0-0ea6-4a43-95f9-6170035f5a820", // too long (last section) + "905de1c0-0ea6-4a43-95f9-6170035f5a8", // too short (last section) + "05de1c0-0ea6-4a43-95f9-6170035f5a82", // too short (first section) + "905de1c0-0ea6-4a43-95f9-6170035f5a8!", // contains a symbol + }; + for (final String invalidClientId : invalidClientIds) { + assertFalse("Client ID, " + invalidClientId + ", is invalid", profile.isClientIdValid(invalidClientId)); + } + + // We generate client IDs using UUID - better make sure they're valid. + for (int i = 0; i < 30; ++i) { + final String generatedClientId = UUID.randomUUID().toString(); + assertTrue("Generated client ID from UUID, " + generatedClientId + ", is valid", + profile.isClientIdValid(generatedClientId)); + } + } + + @Test + public void testGetProfileCreationDateFromTimesFile() throws Exception { + final long expectedDate = System.currentTimeMillis(); + final JSONObject expectedObj = new JSONObject(); + expectedObj.put(PROFILE_CREATION_DATE_JSON_ATTR, expectedDate); + FileUtils.writeJSONObjectToFile(timesFile, expectedObj); + + final Context context = RuntimeEnvironment.application; + final long actualDate = profile.getAndPersistProfileCreationDate(context); + assertEquals("Date from disk equals date inserted to disk", expectedDate, actualDate); + + final long actualDateFromDisk = readProfileCreationDateFromFile(timesFile); + assertEquals("Date in times.json has not changed after accessing profile creation date", + expectedDate, actualDateFromDisk); + } + + @Test + public void testGetProfileCreationDateTimesFileDoesNotExist() throws Exception { + assertFalse("Times.json does not already exist", timesFile.exists()); + + final Context context = RuntimeEnvironment.application; + final long actualDate = profile.getAndPersistProfileCreationDate(context); + // I'd prefer to mock so we can return and verify a specific value but we can't mock + // GeckoProfile because it's final. Instead, we check if the value is at least reasonable. + assertTrue("Date from method is positive", actualDate >= 0); + assertTrue("Date from method is less than current time", actualDate < System.currentTimeMillis()); + + assertTrue("Times.json exists after getting profile", timesFile.exists()); + final long actualDateFromDisk = readProfileCreationDateFromFile(timesFile); + assertEquals("Date from disk equals returned value", actualDate, actualDateFromDisk); + } + + private static long readProfileCreationDateFromFile(final File file) throws Exception { + final JSONObject actualObj = FileUtils.readJSONObjectFromFile(file); + return actualObj.getLong(PROFILE_CREATION_DATE_JSON_ATTR); + } + + private String readClientIdFromFile(final File file) throws Exception { + final JSONObject obj = FileUtils.readJSONObjectFromFile(file); + return obj.getString(CLIENT_ID_JSON_ATTR); + } + + private void writeClientIdToFile(final File file, final String clientId) throws Exception { + final JSONObject obj = new JSONObject(); + obj.put(CLIENT_ID_JSON_ATTR, clientId); + FileUtils.writeJSONObjectToFile(file, obj); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/activitystream/TestActivityStream.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/activitystream/TestActivityStream.java new file mode 100644 index 000000000..71f01b437 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/activitystream/TestActivityStream.java @@ -0,0 +1,85 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.activitystream; + +import android.os.SystemClock; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.robolectric.Robolectric; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.shadows.ShadowLooper; + +import static org.junit.Assert.assertEquals; + +@RunWith(TestRunner.class) +public class TestActivityStream { + /** + * Unit tests for ActivityStream.extractLabel(). + * + * Most test cases are based on this list: + * https://gist.github.com/nchapman/36502ad115e8825d522a66549971a3f0 + */ + @Test + public void testExtractLabelWithPath() { + // Empty values + assertLabelEquals("", "", true); + assertLabelEquals("", null, true); + + // Without path + assertLabelEquals("news.ycombinator", "https://news.ycombinator.com/", true); + assertLabelEquals("sql.telemetry.mozilla", "https://sql.telemetry.mozilla.org/", true); + assertLabelEquals("sso.mozilla", "http://sso.mozilla.com/", true); + assertLabelEquals("youtube", "http://youtube.com/", true); + assertLabelEquals("images.google", "http://images.google.com/", true); + assertLabelEquals("smile.amazon", "http://smile.amazon.com/", true); + assertLabelEquals("localhost", "http://localhost:5000/", true); + assertLabelEquals("independent", "http://www.independent.co.uk/", true); + + // With path + assertLabelEquals("firefox", "https://addons.mozilla.org/en-US/firefox/", true); + assertLabelEquals("activity-stream", "https://trello.com/b/KX3hV8XS/activity-stream", true); + assertLabelEquals("activity-stream", "https://github.com/mozilla/activity-stream", true); + assertLabelEquals("sidekiq", "https://dispatch-news.herokuapp.com/sidekiq", true); + assertLabelEquals("nchapman", "https://github.com/nchapman/", true); + + // Unusable paths + assertLabelEquals("phonebook.mozilla","https://phonebook.mozilla.org/mellon/login?ReturnTo=https%3A%2F%2Fphonebook.mozilla.org%2F&IdP=http%3A%2F%2Fwww.okta.com", true); + assertLabelEquals("ipay.adp", "https://ipay.adp.com/iPay/index.jsf", true); + assertLabelEquals("calendar.google", "https://calendar.google.com/calendar/render?pli=1#main_7", true); + assertLabelEquals("myworkday", "https://www.myworkday.com/vhr_mozilla/d/home.htmld", true); + assertLabelEquals("mail.google", "https://mail.google.com/mail/u/1/#inbox", true); + assertLabelEquals("docs.google", "https://docs.google.com/presentation/d/11cyrcwhKTmBdEBIZ3szLO0-_Imrx2CGV2B9_LZHDrds/edit#slide=id.g15d41bb0f3_0_82", true); + + // Special cases + assertLabelEquals("irccloud.mozilla", "https://irccloud.mozilla.com/#!/ircs://irc1.dmz.scl3.mozilla.com:6697/%23universal-search", true); + } + + @Test + public void testExtractLabelWithoutPath() { + assertLabelEquals("addons.mozilla", "https://addons.mozilla.org/en-US/firefox/", false); + assertLabelEquals("trello", "https://trello.com/b/KX3hV8XS/activity-stream", false); + assertLabelEquals("github", "https://github.com/mozilla/activity-stream", false); + assertLabelEquals("dispatch-news", "https://dispatch-news.herokuapp.com/sidekiq", false); + assertLabelEquals("github", "https://github.com/nchapman/", false); + } + + private void assertLabelEquals(String expectedLabel, String url, boolean usePath) { + final String[] actualLabel = new String[1]; + + ActivityStream.LabelCallback callback = new ActivityStream.LabelCallback() { + @Override + public void onLabelExtracted(String label) { + actualLabel[0] = label; + } + }; + + ActivityStream.extractLabel(RuntimeEnvironment.application, url, usePath, callback); + + ShadowLooper.runUiThreadTasks(); + + assertEquals(expectedLabel, actualLabel[0]); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/common/log/writers/test/TestLogWriters.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/common/log/writers/test/TestLogWriters.java new file mode 100644 index 000000000..61dd33965 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/common/log/writers/test/TestLogWriters.java @@ -0,0 +1,179 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.common.log.writers.test; + +import android.util.Log; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.common.log.writers.LevelFilteringLogWriter; +import org.mozilla.gecko.background.common.log.writers.LogWriter; +import org.mozilla.gecko.background.common.log.writers.PrintLogWriter; +import org.mozilla.gecko.background.common.log.writers.SimpleTagLogWriter; +import org.mozilla.gecko.background.common.log.writers.StringLogWriter; +import org.mozilla.gecko.background.common.log.writers.ThreadLocalTagLogWriter; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.CountDownLatch; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestLogWriters { + + public static final String TEST_LOG_TAG_1 = "TestLogTag1"; + public static final String TEST_LOG_TAG_2 = "TestLogTag2"; + + public static final String TEST_MESSAGE_1 = "LOG TEST MESSAGE one"; + public static final String TEST_MESSAGE_2 = "LOG TEST MESSAGE two"; + public static final String TEST_MESSAGE_3 = "LOG TEST MESSAGE three"; + + @Before + public void setUp() { + Logger.stopLoggingToAll(); + } + + @After + public void tearDown() { + Logger.stopLoggingToAll(); + } + + @Test + public void testStringLogWriter() { + StringLogWriter lw = new StringLogWriter(); + + Logger.error(TEST_LOG_TAG_1, TEST_MESSAGE_1, new RuntimeException()); + Logger.startLoggingTo(lw); + Logger.error(TEST_LOG_TAG_1, TEST_MESSAGE_2); + Logger.warn(TEST_LOG_TAG_1, TEST_MESSAGE_2); + Logger.info(TEST_LOG_TAG_1, TEST_MESSAGE_2); + Logger.debug(TEST_LOG_TAG_1, TEST_MESSAGE_2); + Logger.trace(TEST_LOG_TAG_1, TEST_MESSAGE_2); + Logger.stopLoggingTo(lw); + Logger.error(TEST_LOG_TAG_2, TEST_MESSAGE_3, new RuntimeException()); + + String s = lw.toString(); + assertFalse(s.contains("RuntimeException")); + assertFalse(s.contains(".java")); + assertTrue(s.contains(TEST_LOG_TAG_1)); + assertFalse(s.contains(TEST_LOG_TAG_2)); + assertFalse(s.contains(TEST_MESSAGE_1)); + assertTrue(s.contains(TEST_MESSAGE_2)); + assertFalse(s.contains(TEST_MESSAGE_3)); + } + + @Test + public void testSingleTagLogWriter() { + final String SINGLE_TAG = "XXX"; + StringLogWriter lw = new StringLogWriter(); + + Logger.startLoggingTo(new SimpleTagLogWriter(SINGLE_TAG, lw)); + Logger.error(TEST_LOG_TAG_1, TEST_MESSAGE_1); + Logger.warn(TEST_LOG_TAG_2, TEST_MESSAGE_2); + + String s = lw.toString(); + for (String line : s.split("\n")) { + assertTrue(line.startsWith(SINGLE_TAG)); + } + assertTrue(s.startsWith(SINGLE_TAG + " :: E :: " + TEST_LOG_TAG_1)); + } + + @Test + public void testLevelFilteringLogWriter() { + StringLogWriter lw = new StringLogWriter(); + + assertFalse(new LevelFilteringLogWriter(Log.WARN, lw).shouldLogVerbose(TEST_LOG_TAG_1)); + assertTrue(new LevelFilteringLogWriter(Log.VERBOSE, lw).shouldLogVerbose(TEST_LOG_TAG_1)); + + Logger.startLoggingTo(new LevelFilteringLogWriter(Log.WARN, lw)); + Logger.error(TEST_LOG_TAG_1, TEST_MESSAGE_2); + Logger.warn(TEST_LOG_TAG_1, TEST_MESSAGE_2); + Logger.info(TEST_LOG_TAG_1, TEST_MESSAGE_2); + Logger.debug(TEST_LOG_TAG_1, TEST_MESSAGE_2); + Logger.trace(TEST_LOG_TAG_1, TEST_MESSAGE_2); + + String s = lw.toString(); + assertTrue(s.contains(PrintLogWriter.ERROR)); + assertTrue(s.contains(PrintLogWriter.WARN)); + assertFalse(s.contains(PrintLogWriter.INFO)); + assertFalse(s.contains(PrintLogWriter.DEBUG)); + assertFalse(s.contains(PrintLogWriter.VERBOSE)); + } + + @Test + public void testThreadLocalLogWriter() throws InterruptedException { + final InheritableThreadLocal logTag = new InheritableThreadLocal() { + @Override + protected String initialValue() { + return "PARENT"; + } + }; + + final StringLogWriter stringLogWriter = new StringLogWriter(); + final LogWriter logWriter = new ThreadLocalTagLogWriter(logTag, stringLogWriter); + + try { + Logger.startLoggingTo(logWriter); + + Logger.info("parent tag before", "parent message before"); + + int threads = 3; + final CountDownLatch latch = new CountDownLatch(threads); + + for (int thread = 0; thread < threads; thread++) { + final int threadNumber = thread; + + new Thread(new Runnable() { + @Override + public void run() { + try { + logTag.set("CHILD" + threadNumber); + Logger.info("child tag " + threadNumber, "child message " + threadNumber); + } finally { + latch.countDown(); + } + } + }).start(); + } + + latch.await(); + + Logger.info("parent tag after", "parent message after"); + + String s = stringLogWriter.toString(); + List lines = Arrays.asList(s.split("\n")); + + // Because tests are run in a multi-threaded environment, we get + // additional logs that are not generated by this test. So we test that we + // get all the messages in a reasonable order. + try { + int parent1 = lines.indexOf("PARENT :: I :: parent tag before :: parent message before"); + int parent2 = lines.indexOf("PARENT :: I :: parent tag after :: parent message after"); + + assertTrue(parent1 >= 0); + assertTrue(parent2 >= 0); + assertTrue(parent1 < parent2); + + for (int thread = 0; thread < threads; thread++) { + int child = lines.indexOf("CHILD" + thread + " :: I :: child tag " + thread + " :: child message " + thread); + assertTrue(child >= 0); + assertTrue(parent1 < child); + assertTrue(child < parent2); + } + } catch (Throwable e) { + // Shouldn't happen. Let's dump to aid debugging. + e.printStackTrace(); + assertEquals("\0", s); + } + } finally { + Logger.stopLoggingTo(logWriter); + } + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/DelegatingTestContentProvider.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/DelegatingTestContentProvider.java new file mode 100644 index 000000000..91a36f7d1 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/DelegatingTestContentProvider.java @@ -0,0 +1,86 @@ +/* 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 org.mozilla.gecko.background.db; + +import android.content.ContentProvider; +import android.content.ContentProviderOperation; +import android.content.ContentProviderResult; +import android.content.ContentValues; +import android.content.OperationApplicationException; +import android.database.Cursor; +import android.net.Uri; + +import org.mozilla.gecko.db.BrowserContract; + +import java.util.ArrayList; + +/** + * Wrap a ContentProvider, appending &test=1 to all queries. + */ +public class DelegatingTestContentProvider extends ContentProvider { + protected final ContentProvider mTargetProvider; + + protected static Uri appendUriParam(Uri uri, String param, String value) { + return uri.buildUpon().appendQueryParameter(param, value).build(); + } + + public DelegatingTestContentProvider(ContentProvider targetProvider) { + super(); + mTargetProvider = targetProvider; + } + + private Uri appendTestParam(Uri uri) { + return appendUriParam(uri, BrowserContract.PARAM_IS_TEST, "1"); + } + + @Override + public boolean onCreate() { + return mTargetProvider.onCreate(); + } + + @Override + public String getType(Uri uri) { + return mTargetProvider.getType(uri); + } + + @Override + public int delete(Uri uri, String selection, String[] selectionArgs) { + return mTargetProvider.delete(appendTestParam(uri), selection, selectionArgs); + } + + @Override + public Uri insert(Uri uri, ContentValues values) { + return mTargetProvider.insert(appendTestParam(uri), values); + } + + @Override + public int update(Uri uri, ContentValues values, String selection, + String[] selectionArgs) { + return mTargetProvider.update(appendTestParam(uri), values, + selection, selectionArgs); + } + + @Override + public Cursor query(Uri uri, String[] projection, String selection, + String[] selectionArgs, String sortOrder) { + return mTargetProvider.query(appendTestParam(uri), projection, selection, + selectionArgs, sortOrder); + } + + @Override + public ContentProviderResult[] applyBatch(ArrayList operations) + throws OperationApplicationException { + return mTargetProvider.applyBatch(operations); + } + + @Override + public int bulkInsert(Uri uri, ContentValues[] values) { + return mTargetProvider.bulkInsert(appendTestParam(uri), values); + } + + public ContentProvider getTargetProvider() { + return mTargetProvider; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/TestTabsProvider.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/TestTabsProvider.java new file mode 100644 index 000000000..f0d468e07 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/TestTabsProvider.java @@ -0,0 +1,338 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import android.content.ContentProviderClient; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; +import android.os.RemoteException; + +import org.json.simple.JSONArray; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.db.TabsProvider; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; +import org.mozilla.gecko.sync.repositories.android.FennecTabsRepository; +import org.mozilla.gecko.sync.repositories.domain.TabsRecord; +import org.robolectric.shadows.ShadowContentResolver; + +@RunWith(TestRunner.class) +public class TestTabsProvider { + public static final String TEST_CLIENT_GUID = "test guid"; // Real GUIDs never contain spaces. + public static final String TEST_CLIENT_NAME = "test client name"; + + public static final String CLIENTS_GUID_IS = BrowserContract.Clients.GUID + " = ?"; + public static final String TABS_CLIENT_GUID_IS = BrowserContract.Tabs.CLIENT_GUID + " = ?"; + + protected Tab testTab1; + protected Tab testTab2; + protected Tab testTab3; + + protected TabsProvider provider; + + @Before + public void setUp() { + provider = new TabsProvider(); + provider.onCreate(); + ShadowContentResolver.registerProvider(BrowserContract.TABS_AUTHORITY, new DelegatingTestContentProvider(provider)); + } + + @After + public void tearDown() throws Exception { + provider.shutdown(); + provider = null; + } + + protected ContentProviderClient getClientsClient() { + final ShadowContentResolver cr = new ShadowContentResolver(); + return cr.acquireContentProviderClient(BrowserContractHelpers.CLIENTS_CONTENT_URI); + } + + protected ContentProviderClient getTabsClient() { + final ShadowContentResolver cr = new ShadowContentResolver(); + return cr.acquireContentProviderClient(BrowserContractHelpers.TABS_CONTENT_URI); + } + + protected int deleteTestClient(final ContentProviderClient clientsClient) throws RemoteException { + if (clientsClient == null) { + throw new IllegalStateException("Provided ContentProviderClient is null"); + } + return clientsClient.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, CLIENTS_GUID_IS, new String[] { TEST_CLIENT_GUID }); + } + + protected int deleteAllTestTabs(final ContentProviderClient tabsClient) throws RemoteException { + if (tabsClient == null) { + throw new IllegalStateException("Provided ContentProviderClient is null"); + } + return tabsClient.delete(BrowserContractHelpers.TABS_CONTENT_URI, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }); + } + + protected void insertTestClient(final ContentProviderClient clientsClient) throws RemoteException { + ContentValues cv = new ContentValues(); + cv.put(BrowserContract.Clients.GUID, TEST_CLIENT_GUID); + cv.put(BrowserContract.Clients.NAME, TEST_CLIENT_NAME); + clientsClient.insert(BrowserContractHelpers.CLIENTS_CONTENT_URI, cv); + } + + @SuppressWarnings("unchecked") + protected void insertSomeTestTabs(ContentProviderClient tabsClient) throws RemoteException { + final JSONArray history1 = new JSONArray(); + history1.add("http://test.com/test1.html"); + testTab1 = new Tab("test title 1", "http://test.com/test1.png", history1, 1000); + + final JSONArray history2 = new JSONArray(); + history2.add("http://test.com/test2.html#1"); + history2.add("http://test.com/test2.html#2"); + history2.add("http://test.com/test2.html#3"); + testTab2 = new Tab("test title 2", "http://test.com/test2.png", history2, 2000); + + final JSONArray history3 = new JSONArray(); + history3.add("http://test.com/test3.html#1"); + history3.add("http://test.com/test3.html#2"); + testTab3 = new Tab("test title 3", "http://test.com/test3.png", history3, 3000); + + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab1.toContentValues(TEST_CLIENT_GUID, 0)); + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab2.toContentValues(TEST_CLIENT_GUID, 1)); + tabsClient.insert(BrowserContractHelpers.TABS_CONTENT_URI, testTab3.toContentValues(TEST_CLIENT_GUID, 2)); + } + + // Sanity. + @Test + public void testObtainCP() { + final ContentProviderClient clientsClient = getClientsClient(); + Assert.assertNotNull(clientsClient); + clientsClient.release(); + + final ContentProviderClient tabsClient = getTabsClient(); + Assert.assertNotNull(tabsClient); + tabsClient.release(); + } + + @Test + public void testDeleteEmptyClients() throws RemoteException { + final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI; + final ContentProviderClient clientsClient = getClientsClient(); + + // Have to ensure that it's empty… + clientsClient.delete(uri, null, null); + + int deleted = clientsClient.delete(uri, null, null); + Assert.assertEquals(0, deleted); + } + + @Test + public void testDeleteEmptyTabs() throws RemoteException { + final ContentProviderClient tabsClient = getTabsClient(); + + // Have to ensure that it's empty… + deleteAllTestTabs(tabsClient); + + int deleted = deleteAllTestTabs(tabsClient); + Assert.assertEquals(0, deleted); + } + + @Test + public void testStoreAndRetrieveClients() throws RemoteException { + final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI; + final ContentProviderClient clientsClient = getClientsClient(); + + // Have to ensure that it's empty… + clientsClient.delete(uri, null, null); + + final long now = System.currentTimeMillis(); + final ContentValues first = new ContentValues(); + final ContentValues second = new ContentValues(); + first.put(BrowserContract.Clients.GUID, "abcdefghijkl"); + first.put(BrowserContract.Clients.NAME, "Frist Psot"); + first.put(BrowserContract.Clients.LAST_MODIFIED, now + 1); + second.put(BrowserContract.Clients.GUID, "mnopqrstuvwx"); + second.put(BrowserContract.Clients.NAME, "Second!!1!"); + second.put(BrowserContract.Clients.LAST_MODIFIED, now + 2); + + ContentValues[] values = new ContentValues[] { first, second }; + final int inserted = clientsClient.bulkInsert(uri, values); + Assert.assertEquals(2, inserted); + + final String since = BrowserContract.Clients.LAST_MODIFIED + " >= ?"; + final String[] nowArg = new String[] { String.valueOf(now) }; + final String guidAscending = BrowserContract.Clients.GUID + " ASC"; + Cursor cursor = clientsClient.query(uri, null, since, nowArg, guidAscending); + + Assert.assertNotNull(cursor); + try { + Assert.assertTrue(cursor.moveToFirst()); + Assert.assertEquals(2, cursor.getCount()); + + final String g1 = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Clients.GUID)); + final String n1 = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Clients.NAME)); + final long m1 = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Clients.LAST_MODIFIED)); + Assert.assertEquals(first.get(BrowserContract.Clients.GUID), g1); + Assert.assertEquals(first.get(BrowserContract.Clients.NAME), n1); + Assert.assertEquals(now + 1, m1); + + Assert.assertTrue(cursor.moveToNext()); + final String g2 = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Clients.GUID)); + final String n2 = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Clients.NAME)); + final long m2 = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Clients.LAST_MODIFIED)); + Assert.assertEquals(second.get(BrowserContract.Clients.GUID), g2); + Assert.assertEquals(second.get(BrowserContract.Clients.NAME), n2); + Assert.assertEquals(now + 2, m2); + + Assert.assertFalse(cursor.moveToNext()); + } finally { + cursor.close(); + } + + int deleted = clientsClient.delete(uri, null, null); + Assert.assertEquals(2, deleted); + } + + @Test + public void testTabFromCursor() throws Exception { + final ContentProviderClient tabsClient = getTabsClient(); + final ContentProviderClient clientsClient = getClientsClient(); + + deleteAllTestTabs(tabsClient); + deleteTestClient(clientsClient); + insertTestClient(clientsClient); + insertSomeTestTabs(tabsClient); + + final String positionAscending = BrowserContract.Tabs.POSITION + " ASC"; + Cursor cursor = null; + try { + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending); + Assert.assertEquals(3, cursor.getCount()); + + cursor.moveToFirst(); + final Tab parsed1 = Tab.fromCursor(cursor); + Assert.assertEquals(testTab1, parsed1); + + cursor.moveToNext(); + final Tab parsed2 = Tab.fromCursor(cursor); + Assert.assertEquals(testTab2, parsed2); + + cursor.moveToPosition(2); + final Tab parsed3 = Tab.fromCursor(cursor); + Assert.assertEquals(testTab3, parsed3); + } finally { + cursor.close(); + } + } + + @Test + public void testDeletingClientDeletesTabs() throws Exception { + final ContentProviderClient tabsClient = getTabsClient(); + final ContentProviderClient clientsClient = getClientsClient(); + + deleteAllTestTabs(tabsClient); + deleteTestClient(clientsClient); + insertTestClient(clientsClient); + insertSomeTestTabs(tabsClient); + + // Delete just the client... + clientsClient.delete(BrowserContractHelpers.CLIENTS_CONTENT_URI, CLIENTS_GUID_IS, new String [] { TEST_CLIENT_GUID }); + + Cursor cursor = null; + try { + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, null); + // ... and all that client's tabs should be removed. + Assert.assertEquals(0, cursor.getCount()); + } finally { + cursor.close(); + } + } + + @Test + public void testTabsRecordFromCursor() throws Exception { + final ContentProviderClient tabsClient = getTabsClient(); + + deleteAllTestTabs(tabsClient); + insertTestClient(getClientsClient()); + insertSomeTestTabs(tabsClient); + + final String positionAscending = BrowserContract.Tabs.POSITION + " ASC"; + Cursor cursor = null; + try { + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending); + Assert.assertEquals(3, cursor.getCount()); + + cursor.moveToPosition(1); + + final TabsRecord tabsRecord = FennecTabsRepository.tabsRecordFromCursor(cursor, TEST_CLIENT_GUID, TEST_CLIENT_NAME); + + // Make sure we clean up after ourselves. + Assert.assertEquals(1, cursor.getPosition()); + + Assert.assertEquals(TEST_CLIENT_GUID, tabsRecord.guid); + Assert.assertEquals(TEST_CLIENT_NAME, tabsRecord.clientName); + + Assert.assertEquals(3, tabsRecord.tabs.size()); + Assert.assertEquals(testTab1, tabsRecord.tabs.get(0)); + Assert.assertEquals(testTab2, tabsRecord.tabs.get(1)); + Assert.assertEquals(testTab3, tabsRecord.tabs.get(2)); + + Assert.assertEquals(Math.max(Math.max(testTab1.lastUsed, testTab2.lastUsed), testTab3.lastUsed), tabsRecord.lastModified); + } finally { + cursor.close(); + } + } + + // Verify that we can fetch a record when there are no local tabs at all. + @Test + public void testEmptyTabsRecordFromCursor() throws Exception { + final ContentProviderClient tabsClient = getTabsClient(); + + deleteAllTestTabs(tabsClient); + + final String positionAscending = BrowserContract.Tabs.POSITION + " ASC"; + Cursor cursor = null; + try { + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, TABS_CLIENT_GUID_IS, new String[] { TEST_CLIENT_GUID }, positionAscending); + Assert.assertEquals(0, cursor.getCount()); + + final TabsRecord tabsRecord = FennecTabsRepository.tabsRecordFromCursor(cursor, TEST_CLIENT_GUID, TEST_CLIENT_NAME); + + Assert.assertEquals(TEST_CLIENT_GUID, tabsRecord.guid); + Assert.assertEquals(TEST_CLIENT_NAME, tabsRecord.clientName); + + Assert.assertNotNull(tabsRecord.tabs); + Assert.assertEquals(0, tabsRecord.tabs.size()); + + Assert.assertEquals(0, tabsRecord.lastModified); + } finally { + cursor.close(); + } + } + + // Not much of a test, but verifies the tabs record at least agrees with the + // disk data and doubles as a database inspector. + @Test + public void testLocalTabs() throws Exception { + final ContentProviderClient tabsClient = getTabsClient(); + + final String positionAscending = BrowserContract.Tabs.POSITION + " ASC"; + Cursor cursor = null; + try { + // Keep this in sync with the Fennec schema. + cursor = tabsClient.query(BrowserContractHelpers.TABS_CONTENT_URI, null, BrowserContract.Tabs.CLIENT_GUID + " IS NULL", null, positionAscending); + CursorDumper.dumpCursor(cursor); + + final TabsRecord tabsRecord = FennecTabsRepository.tabsRecordFromCursor(cursor, TEST_CLIENT_GUID, TEST_CLIENT_NAME); + + Assert.assertEquals(TEST_CLIENT_GUID, tabsRecord.guid); + Assert.assertEquals(TEST_CLIENT_NAME, tabsRecord.clientName); + + Assert.assertNotNull(tabsRecord.tabs); + Assert.assertEquals(cursor.getCount(), tabsRecord.tabs.size()); + } finally { + cursor.close(); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/TestTabsProviderRemoteTabs.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/TestTabsProviderRemoteTabs.java new file mode 100644 index 000000000..e63cb9b46 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/db/TestTabsProviderRemoteTabs.java @@ -0,0 +1,244 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.db; + +import android.content.ContentProviderClient; +import android.content.ContentResolver; +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.net.Uri; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.GeckoProfile; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.db.LocalTabsAccessor; +import org.mozilla.gecko.db.RemoteClient; +import org.mozilla.gecko.db.TabsProvider; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.internal.runtime.RuntimeAdapter; +import org.robolectric.shadows.ShadowContentResolver; + +import java.util.List; + +@RunWith(TestRunner.class) +public class TestTabsProviderRemoteTabs { + private static final long ONE_DAY_IN_MILLISECONDS = 1000 * 60 * 60 * 24; + private static final long ONE_WEEK_IN_MILLISECONDS = 7 * ONE_DAY_IN_MILLISECONDS; + private static final long THREE_WEEKS_IN_MILLISECONDS = 3 * ONE_WEEK_IN_MILLISECONDS; + + protected TabsProvider provider; + + @Before + public void setUp() { + provider = new TabsProvider(); + provider.onCreate(); + ShadowContentResolver.registerProvider(BrowserContract.TABS_AUTHORITY, new DelegatingTestContentProvider(provider)); + } + + @After + public void tearDown() throws Exception { + provider.shutdown(); + provider = null; + } + + protected ContentProviderClient getClientsClient() { + final ShadowContentResolver cr = new ShadowContentResolver(); + return cr.acquireContentProviderClient(BrowserContractHelpers.CLIENTS_CONTENT_URI); + } + + @Test + public void testGetClientsWithoutTabsByRecencyFromCursor() throws Exception { + final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI; + final ContentProviderClient cpc = getClientsClient(); + final LocalTabsAccessor accessor = new LocalTabsAccessor("test"); // The profile name given doesn't matter. + + try { + // Delete all tabs to begin with. + cpc.delete(uri, null, null); + Cursor allClients = cpc.query(uri, null, null, null, null); + try { + Assert.assertEquals(0, allClients.getCount()); + } finally { + allClients.close(); + } + + // Insert a local and remote1 client record, neither with tabs. + final long now = System.currentTimeMillis(); + // Local client has GUID = null. + final ContentValues local = new ContentValues(); + local.put(BrowserContract.Clients.NAME, "local"); + local.put(BrowserContract.Clients.LAST_MODIFIED, now + 1); + // Remote clients have GUID != null. + final ContentValues remote1 = new ContentValues(); + remote1.put(BrowserContract.Clients.GUID, "guid1"); + remote1.put(BrowserContract.Clients.NAME, "remote1"); + remote1.put(BrowserContract.Clients.LAST_MODIFIED, now + 2); + + final ContentValues remote2 = new ContentValues(); + remote2.put(BrowserContract.Clients.GUID, "guid2"); + remote2.put(BrowserContract.Clients.NAME, "remote2"); + remote2.put(BrowserContract.Clients.LAST_MODIFIED, now + 3); + + ContentValues[] values = new ContentValues[]{local, remote1, remote2}; + int inserted = cpc.bulkInsert(uri, values); + Assert.assertEquals(3, inserted); + + allClients = cpc.query(BrowserContract.Clients.CONTENT_RECENCY_URI, null, null, null, null); + try { + CursorDumper.dumpCursor(allClients); + // The local client is not ignored. + Assert.assertEquals(3, allClients.getCount()); + final List clients = accessor.getClientsWithoutTabsByRecencyFromCursor(allClients); + Assert.assertEquals(3, clients.size()); + for (RemoteClient client : clients) { + // Each client should not have any tabs. + Assert.assertNotNull(client.tabs); + Assert.assertEquals(0, client.tabs.size()); + } + // Since there are no tabs, the order should be based on last_modified. + Assert.assertEquals("guid2", clients.get(0).guid); + Assert.assertEquals("guid1", clients.get(1).guid); + Assert.assertEquals(null, clients.get(2).guid); + } finally { + allClients.close(); + } + + // Now let's add a few tabs to one client. The times are chosen so that one tab's + // last used is not relevant, and the other tab is the most recent used. + final ContentValues remoteTab1 = new ContentValues(); + remoteTab1.put(BrowserContract.Tabs.CLIENT_GUID, "guid1"); + remoteTab1.put(BrowserContract.Tabs.TITLE, "title1"); + remoteTab1.put(BrowserContract.Tabs.URL, "http://test.com/test1"); + remoteTab1.put(BrowserContract.Tabs.HISTORY, "[\"http://test.com/test1\"]"); + remoteTab1.put(BrowserContract.Tabs.LAST_USED, now); + remoteTab1.put(BrowserContract.Tabs.POSITION, 0); + + final ContentValues remoteTab2 = new ContentValues(); + remoteTab2.put(BrowserContract.Tabs.CLIENT_GUID, "guid1"); + remoteTab2.put(BrowserContract.Tabs.TITLE, "title2"); + remoteTab2.put(BrowserContract.Tabs.URL, "http://test.com/test2"); + remoteTab2.put(BrowserContract.Tabs.HISTORY, "[\"http://test.com/test2\"]"); + remoteTab2.put(BrowserContract.Tabs.LAST_USED, now + 5); + remoteTab2.put(BrowserContract.Tabs.POSITION, 1); + + values = new ContentValues[]{remoteTab1, remoteTab2}; + inserted = cpc.bulkInsert(BrowserContract.Tabs.CONTENT_URI, values); + Assert.assertEquals(2, inserted); + + allClients = cpc.query(BrowserContract.Clients.CONTENT_RECENCY_URI, null, BrowserContract.Clients.GUID + " IS NOT NULL", null, null); + try { + CursorDumper.dumpCursor(allClients); + // The local client is ignored. + Assert.assertEquals(2, allClients.getCount()); + final List clients = accessor.getClientsWithoutTabsByRecencyFromCursor(allClients); + Assert.assertEquals(2, clients.size()); + for (RemoteClient client : clients) { + // Each client should be remote and should not have any tabs. + Assert.assertNotNull(client.guid); + Assert.assertNotNull(client.tabs); + Assert.assertEquals(0, client.tabs.size()); + } + // Since now there is a tab attached to the remote2 client more recent than the + // remote1 client modified time, it should be first. + Assert.assertEquals("guid1", clients.get(0).guid); + Assert.assertEquals("guid2", clients.get(1).guid); + } finally { + allClients.close(); + } + } finally { + cpc.release(); + } + } + + @Test + public void testGetRecentRemoteClientsUpToOneWeekOld() throws Exception { + final Uri uri = BrowserContractHelpers.CLIENTS_CONTENT_URI; + final ContentProviderClient cpc = getClientsClient(); + final LocalTabsAccessor accessor = new LocalTabsAccessor("test"); // The profile name given doesn't matter. + final Context context = RuntimeEnvironment.application.getApplicationContext(); + + try { + // Start Clean + cpc.delete(uri, null, null); + final Cursor allClients = cpc.query(uri, null, null, null, null); + try { + Assert.assertEquals(0, allClients.getCount()); + } finally { + allClients.close(); + } + + // Insert a local and remote1 client record, neither with tabs. + final long now = System.currentTimeMillis(); + // Local client has GUID = null. + final ContentValues local = new ContentValues(); + local.put(BrowserContract.Clients.NAME, "local"); + local.put(BrowserContract.Clients.LAST_MODIFIED, now + 1); + // Remote clients have GUID != null. + final ContentValues remote1 = new ContentValues(); + remote1.put(BrowserContract.Clients.GUID, "guid1"); + remote1.put(BrowserContract.Clients.NAME, "remote1"); + remote1.put(BrowserContract.Clients.LAST_MODIFIED, now + 2); + + // Insert a Remote Client that is 6 days old. + final ContentValues remote2 = new ContentValues(); + remote2.put(BrowserContract.Clients.GUID, "guid2"); + remote2.put(BrowserContract.Clients.NAME, "remote2"); + remote2.put(BrowserContract.Clients.LAST_MODIFIED, now - ONE_WEEK_IN_MILLISECONDS + ONE_DAY_IN_MILLISECONDS); + + // Insert a Remote Client with the same name as previous but with more than 3 weeks old + final ContentValues remote3 = new ContentValues(); + remote3.put(BrowserContract.Clients.GUID, "guid21"); + remote3.put(BrowserContract.Clients.NAME, "remote2"); + remote3.put(BrowserContract.Clients.LAST_MODIFIED, now - THREE_WEEKS_IN_MILLISECONDS - ONE_DAY_IN_MILLISECONDS); + + // Insert another remote client with the same name as previous but with 3 weeks - 1 day old. + final ContentValues remote4 = new ContentValues(); + remote4.put(BrowserContract.Clients.GUID, "guid22"); + remote4.put(BrowserContract.Clients.NAME, "remote2"); + remote4.put(BrowserContract.Clients.LAST_MODIFIED, now - THREE_WEEKS_IN_MILLISECONDS + ONE_DAY_IN_MILLISECONDS); + + // Insert a Remote Client that is exactly one week old. + final ContentValues remote5 = new ContentValues(); + remote5.put(BrowserContract.Clients.GUID, "guid3"); + remote5.put(BrowserContract.Clients.NAME, "remote3"); + remote5.put(BrowserContract.Clients.LAST_MODIFIED, now - ONE_WEEK_IN_MILLISECONDS); + + ContentValues[] values = new ContentValues[]{local, remote1, remote2, remote3, remote4, remote5}; + int inserted = cpc.bulkInsert(uri, values); + Assert.assertEquals(values.length, inserted); + + final Cursor remoteClients = + accessor.getRemoteClientsByRecencyCursor(context); + + try { + CursorDumper.dumpCursor(remoteClients); + // Local client is not included. + // (remote1, guid1), (remote2, guid2), (remote3, guid3) are expected. + Assert.assertEquals(3, remoteClients.getCount()); + + // Check the inner data, according to recency. + List recentRemoteClientsList = + accessor.getClientsWithoutTabsByRecencyFromCursor(remoteClients); + Assert.assertEquals(3, recentRemoteClientsList.size()); + Assert.assertEquals("remote1", recentRemoteClientsList.get(0).name); + Assert.assertEquals("guid1", recentRemoteClientsList.get(0).guid); + Assert.assertEquals("remote2", recentRemoteClientsList.get(1).name); + Assert.assertEquals("guid2", recentRemoteClientsList.get(1).guid); + Assert.assertEquals("remote3", recentRemoteClientsList.get(2).name); + Assert.assertEquals("guid3", recentRemoteClientsList.get(2).guid); + } finally { + remoteClients.close(); + } + } finally { + cpc.release(); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/fxa/test/TestFxAccountClient20.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/fxa/test/TestFxAccountClient20.java new file mode 100644 index 000000000..d075cc0ec --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/fxa/test/TestFxAccountClient20.java @@ -0,0 +1,41 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.fxa.test; + +import junit.framework.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.fxa.FxAccountClient20; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.net.BaseResource; + +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +@RunWith(TestRunner.class) +public class TestFxAccountClient20 { + protected static class MockFxAccountClient20 extends FxAccountClient20 { + public MockFxAccountClient20(String serverURI, Executor executor) { + super(serverURI, executor); + } + + // Public for testing. + @Override + public BaseResource getBaseResource(final String path, final String... queryParameters) throws UnsupportedEncodingException, URISyntaxException { + return super.getBaseResource(path, queryParameters); + } + } + + @Test + public void testGetCreateAccountURI() throws Exception { + final String TEST_SERVER = "https://test.com:4430/inner/v1/"; + final MockFxAccountClient20 client = new MockFxAccountClient20(TEST_SERVER, Executors.newSingleThreadExecutor()); + Assert.assertEquals(TEST_SERVER + "account/create", client.getBaseResource("account/create").getURIString()); + Assert.assertEquals(TEST_SERVER + "account/create?service=sync&keys=true", client.getBaseResource("account/create", "service", "sync", "keys", "true").getURIString()); + Assert.assertEquals(TEST_SERVER + "account/create?service=two+words", client.getBaseResource("account/create", "service", "two words").getURIString()); + Assert.assertEquals(TEST_SERVER + "account/create?service=symbols%2F%3A%3F%2B", client.getBaseResource("account/create", "service", "symbols/:?+").getURIString()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/fxa/test/TestFxAccountUtils.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/fxa/test/TestFxAccountUtils.java new file mode 100644 index 000000000..e6461776e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/fxa/test/TestFxAccountUtils.java @@ -0,0 +1,131 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.fxa.test; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.apache.commons.codec.binary.Base64; +import org.mozilla.gecko.background.fxa.FxAccountUtils; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.net.SRPConstants; + +import java.math.BigInteger; + +/** + * Test vectors from + * https://wiki.mozilla.org/Identity/AttachedServices/KeyServerProtocol#stretch-KDF + * and + * https://github.com/mozilla/fxa-auth-server/wiki/onepw-protocol/5a9bc81e499306d769ca19b40b50fa60123df15d. + */ +@RunWith(TestRunner.class) +public class TestFxAccountUtils { + protected static void assertEncoding(String base16String, String utf8String) throws Exception { + Assert.assertEquals(base16String, FxAccountUtils.bytes(utf8String)); + } + + @Test + public void testUTF8Encoding() throws Exception { + assertEncoding("616e6472c3a9406578616d706c652e6f7267", "andré@example.org"); + assertEncoding("70c3a4737377c3b67264", "pässwörd"); + } + + @Test + public void testHexModN() { + BigInteger N = BigInteger.valueOf(14); + Assert.assertEquals(4, N.bitLength()); + Assert.assertEquals(1, (N.bitLength() + 7)/8); + Assert.assertEquals("00", FxAccountUtils.hexModN(BigInteger.valueOf(0), N)); + Assert.assertEquals("05", FxAccountUtils.hexModN(BigInteger.valueOf(5), N)); + Assert.assertEquals("0b", FxAccountUtils.hexModN(BigInteger.valueOf(11), N)); + Assert.assertEquals("00", FxAccountUtils.hexModN(BigInteger.valueOf(14), N)); + Assert.assertEquals("01", FxAccountUtils.hexModN(BigInteger.valueOf(15), N)); + Assert.assertEquals("02", FxAccountUtils.hexModN(BigInteger.valueOf(16), N)); + Assert.assertEquals("02", FxAccountUtils.hexModN(BigInteger.valueOf(30), N)); + + N = BigInteger.valueOf(260); + Assert.assertEquals("00ff", FxAccountUtils.hexModN(BigInteger.valueOf(255), N)); + Assert.assertEquals("0100", FxAccountUtils.hexModN(BigInteger.valueOf(256), N)); + Assert.assertEquals("0101", FxAccountUtils.hexModN(BigInteger.valueOf(257), N)); + Assert.assertEquals("0001", FxAccountUtils.hexModN(BigInteger.valueOf(261), N)); + } + + @Test + public void testSRPVerifierFunctions() throws Exception { + byte[] emailUTF8Bytes = Utils.hex2Byte("616e6472c3a9406578616d706c652e6f7267"); + byte[] srpPWBytes = Utils.hex2Byte("00f9b71800ab5337d51177d8fbc682a3653fa6dae5b87628eeec43a18af59a9d", 32); + byte[] srpSaltBytes = Utils.hex2Byte("00f1000000000000000000000000000000000000000000000000000000000179", 32); + + String expectedX = "81925186909189958012481408070938147619474993903899664126296984459627523279550"; + BigInteger x = FxAccountUtils.srpVerifierLowercaseX(emailUTF8Bytes, srpPWBytes, srpSaltBytes); + Assert.assertEquals(expectedX, x.toString(10)); + + String expectedV = "11464957230405843056840989945621595830717843959177257412217395741657995431613430369165714029818141919887853709633756255809680435884948698492811770122091692817955078535761033207000504846365974552196983218225819721112680718485091921646083608065626264424771606096544316730881455897489989950697705196721477608178869100211706638584538751009854562396937282582855620488967259498367841284829152987988548996842770025110751388952323221706639434861071834212055174768483159061566055471366772641252573641352721966728239512914666806496255304380341487975080159076396759492553066357163103546373216130193328802116982288883318596822"; + BigInteger v = FxAccountUtils.srpVerifierLowercaseV(emailUTF8Bytes, srpPWBytes, srpSaltBytes, SRPConstants._2048.g, SRPConstants._2048.N); + Assert.assertEquals(expectedV, v.toString(10)); + + String expectedVHex = "00173ffa0263e63ccfd6791b8ee2a40f048ec94cd95aa8a3125726f9805e0c8283c658dc0b607fbb25db68e68e93f2658483049c68af7e8214c49fde2712a775b63e545160d64b00189a86708c69657da7a1678eda0cd79f86b8560ebdb1ffc221db360eab901d643a75bf1205070a5791230ae56466b8c3c1eb656e19b794f1ea0d2a077b3a755350208ea0118fec8c4b2ec344a05c66ae1449b32609ca7189451c259d65bd15b34d8729afdb5faff8af1f3437bbdc0c3d0b069a8ab2a959c90c5a43d42082c77490f3afcc10ef5648625c0605cdaace6c6fdc9e9a7e6635d619f50af7734522470502cab26a52a198f5b00a279858916507b0b4e9ef9524d6"; + Assert.assertEquals(expectedVHex, FxAccountUtils.hexModN(v, SRPConstants._2048.N)); + } + + @Test + public void testGenerateSyncKeyBundle() throws Exception { + byte[] kB = Utils.hex2Byte("d02d8fe39f28b601159c543f2deeb8f72bdf2043e8279aa08496fbd9ebaea361"); + KeyBundle bundle = FxAccountUtils.generateSyncKeyBundle(kB); + Assert.assertEquals("rsLwECkgPYeGbYl92e23FskfIbgld9TgeifEaB9ZwTI=", Base64.encodeBase64String(bundle.getEncryptionKey())); + Assert.assertEquals("fs75EseCD/VOLodlIGmwNabBjhTYBHFCe7CGIf0t8Tw=", Base64.encodeBase64String(bundle.getHMACKey())); + } + + @Test + public void testGeneration() throws Exception { + byte[] quickStretchedPW = FxAccountUtils.generateQuickStretchedPW( + Utils.hex2Byte("616e6472c3a9406578616d706c652e6f7267"), + Utils.hex2Byte("70c3a4737377c3b67264")); + Assert.assertEquals("e4e8889bd8bd61ad6de6b95c059d56e7b50dacdaf62bd84644af7e2add84345d", + Utils.byte2Hex(quickStretchedPW)); + Assert.assertEquals("247b675ffb4c46310bc87e26d712153abe5e1c90ef00a4784594f97ef54f2375", + Utils.byte2Hex(FxAccountUtils.generateAuthPW(quickStretchedPW))); + byte[] unwrapkB = FxAccountUtils.generateUnwrapBKey(quickStretchedPW); + Assert.assertEquals("de6a2648b78284fcb9ffa81ba95803309cfba7af583c01a8a1a63e567234dd28", + Utils.byte2Hex(unwrapkB)); + byte[] wrapkB = Utils.hex2Byte("7effe354abecbcb234a8dfc2d7644b4ad339b525589738f2d27341bb8622ecd8"); + Assert.assertEquals("a095c51c1c6e384e8d5777d97e3c487a4fc2128a00ab395a73d57fedf41631f0", + Utils.byte2Hex(FxAccountUtils.unwrapkB(unwrapkB, wrapkB))); + } + + @Test + public void testClientState() throws Exception { + final String hexKB = "fd5c747806c07ce0b9d69dcfea144663e630b65ec4963596a22f24910d7dd15d"; + final byte[] byteKB = Utils.hex2Byte(hexKB); + final String clientState = FxAccountUtils.computeClientState(byteKB); + final String expected = "6ae94683571c7a7c54dab4700aa3995f"; + Assert.assertEquals(expected, clientState); + } + + @Test + public void testGetAudienceForURL() throws Exception { + // Sub-domains and path components. + Assert.assertEquals("http://sub.test.com", FxAccountUtils.getAudienceForURL("http://sub.test.com")); + Assert.assertEquals("http://test.com", FxAccountUtils.getAudienceForURL("http://test.com/")); + Assert.assertEquals("http://test.com", FxAccountUtils.getAudienceForURL("http://test.com/path/component")); + Assert.assertEquals("http://test.com", FxAccountUtils.getAudienceForURL("http://test.com/path/component/")); + + // No port and default port. + Assert.assertEquals("http://test.com", FxAccountUtils.getAudienceForURL("http://test.com")); + Assert.assertEquals("http://test.com:80", FxAccountUtils.getAudienceForURL("http://test.com:80")); + + Assert.assertEquals("https://test.com", FxAccountUtils.getAudienceForURL("https://test.com")); + Assert.assertEquals("https://test.com:443", FxAccountUtils.getAudienceForURL("https://test.com:443")); + + // Ports that are the default ports for a different scheme. + Assert.assertEquals("https://test.com:80", FxAccountUtils.getAudienceForURL("https://test.com:80")); + Assert.assertEquals("http://test.com:443", FxAccountUtils.getAudienceForURL("http://test.com:443")); + + // Arbitrary ports. + Assert.assertEquals("http://test.com:8080", FxAccountUtils.getAudienceForURL("http://test.com:8080")); + Assert.assertEquals("https://test.com:4430", FxAccountUtils.getAudienceForURL("https://test.com:4430")); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/test/EntityTestHelper.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/test/EntityTestHelper.java new file mode 100644 index 000000000..976a8eda1 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/test/EntityTestHelper.java @@ -0,0 +1,34 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.test; + +import ch.boye.httpclientandroidlib.HttpEntity; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +public class EntityTestHelper { + private static final int DEFAULT_SIZE = 1024; + + public static byte[] bytesFromEntity(final HttpEntity entity) throws IOException { + final InputStream is = entity.getContent(); + + if (is instanceof ByteArrayInputStream) { + final int size = is.available(); + final byte[] buffer = new byte[size]; + is.read(buffer, 0, size); + return buffer; + } + + final ByteArrayOutputStream bos = new ByteArrayOutputStream(); + final byte[] buffer = new byte[DEFAULT_SIZE]; + int len; + while ((len = is.read(buffer, 0, DEFAULT_SIZE)) != -1) { + bos.write(buffer, 0, len); + } + return bos.toByteArray(); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/BaseMockServerSyncStage.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/BaseMockServerSyncStage.java new file mode 100644 index 000000000..d9aa936f0 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/BaseMockServerSyncStage.java @@ -0,0 +1,72 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.NoCollectionKeysSetException; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.SynchronizerConfiguration; +import org.mozilla.gecko.sync.repositories.RecordFactory; +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.stage.ServerSyncStage; + +import java.io.IOException; +import java.net.URISyntaxException; + +/** + * A stage that joins two Repositories with no wrapping. + */ +public abstract class BaseMockServerSyncStage extends ServerSyncStage { + + public Repository local; + public Repository remote; + public String name; + public String collection; + public int version = 1; + + @Override + public boolean isEnabled() { + return true; + } + + @Override + protected String getCollection() { + return collection; + } + + @Override + protected Repository getLocalRepository() { + return local; + } + + @Override + protected Repository getRemoteRepository() throws URISyntaxException { + return remote; + } + + @Override + protected String getEngineName() { + return name; + } + + @Override + public Integer getStorageVersion() { + return version; + } + + @Override + protected RecordFactory getRecordFactory() { + return null; + } + + @Override + protected Repository wrappedServerRepo() + throws NoCollectionKeysSetException, URISyntaxException { + return getRemoteRepository(); + } + + public SynchronizerConfiguration leakConfig() + throws NonObjectJSONException, IOException { + return this.getConfig(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/CommandHelpers.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/CommandHelpers.java new file mode 100644 index 000000000..48217f1b0 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/CommandHelpers.java @@ -0,0 +1,40 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.json.simple.JSONArray; +import org.mozilla.gecko.sync.CommandProcessor.Command; + +public class CommandHelpers { + + @SuppressWarnings("unchecked") + public static Command getCommand1() { + JSONArray args = new JSONArray(); + args.add("argsA"); + return new Command("displayURI", args); + } + + @SuppressWarnings("unchecked") + public static Command getCommand2() { + JSONArray args = new JSONArray(); + args.add("argsB"); + return new Command("displayURI", args); + } + + @SuppressWarnings("unchecked") + public static Command getCommand3() { + JSONArray args = new JSONArray(); + args.add("argsC"); + return new Command("displayURI", args); + } + + @SuppressWarnings("unchecked") + public static Command getCommand4() { + JSONArray args = new JSONArray(); + args.add("URI of Page"); + args.add("Sender ID"); + args.add("Title of Page"); + return new Command("displayURI", args); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/DefaultGlobalSessionCallback.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/DefaultGlobalSessionCallback.java new file mode 100644 index 000000000..373dd4eab --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/DefaultGlobalSessionCallback.java @@ -0,0 +1,51 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; + +import java.net.URI; + +public class DefaultGlobalSessionCallback implements GlobalSessionCallback { + + @Override + public void requestBackoff(long backoff) { + } + + @Override + public void informUnauthorizedResponse(GlobalSession globalSession, + URI oldClusterURL) { + } + @Override + public void informUpgradeRequiredResponse(GlobalSession session) { + } + + @Override + public void informMigrated(GlobalSession globalSession) { + } + + @Override + public void handleAborted(GlobalSession globalSession, String reason) { + } + + @Override + public void handleError(GlobalSession globalSession, Exception ex) { + } + + @Override + public void handleSuccess(GlobalSession globalSession) { + } + + @Override + public void handleStageCompleted(Stage currentState, + GlobalSession globalSession) { + } + + @Override + public boolean shouldBackOffStorage() { + return false; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockAbstractNonRepositorySyncStage.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockAbstractNonRepositorySyncStage.java new file mode 100644 index 000000000..d8380df97 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockAbstractNonRepositorySyncStage.java @@ -0,0 +1,13 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.stage.AbstractNonRepositorySyncStage; + +public class MockAbstractNonRepositorySyncStage extends AbstractNonRepositorySyncStage { + @Override + public void execute() { + session.advance(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockClientsDataDelegate.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockClientsDataDelegate.java new file mode 100644 index 000000000..f4af51f64 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockClientsDataDelegate.java @@ -0,0 +1,66 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; + +public class MockClientsDataDelegate implements ClientsDataDelegate { + private String accountGUID; + private String clientName; + private int clientsCount; + private long clientDataTimestamp = 0; + + @Override + public synchronized String getAccountGUID() { + if (accountGUID == null) { + accountGUID = Utils.generateGuid(); + } + return accountGUID; + } + + @Override + public synchronized String getDefaultClientName() { + return "Default client"; + } + + @Override + public synchronized void setClientName(String clientName, long now) { + this.clientName = clientName; + this.clientDataTimestamp = now; + } + + @Override + public synchronized String getClientName() { + if (clientName == null) { + setClientName(getDefaultClientName(), System.currentTimeMillis()); + } + return clientName; + } + + @Override + public synchronized void setClientsCount(int clientsCount) { + this.clientsCount = clientsCount; + } + + @Override + public synchronized int getClientsCount() { + return clientsCount; + } + + @Override + public synchronized boolean isLocalGUID(String guid) { + return getAccountGUID().equals(guid); + } + + @Override + public synchronized long getLastModifiedTimestamp() { + return clientDataTimestamp; + } + + @Override + public String getFormFactor() { + return "phone"; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockClientsDatabaseAccessor.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockClientsDatabaseAccessor.java new file mode 100644 index 000000000..b1aeb7cd1 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockClientsDatabaseAccessor.java @@ -0,0 +1,76 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.CommandProcessor.Command; +import org.mozilla.gecko.sync.repositories.NullCursorException; +import org.mozilla.gecko.sync.repositories.android.ClientsDatabaseAccessor; +import org.mozilla.gecko.sync.repositories.domain.ClientRecord; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +public class MockClientsDatabaseAccessor extends ClientsDatabaseAccessor { + public boolean storedRecord = false; + public boolean dbWiped = false; + public boolean clientsTableWiped = false; + public boolean closed = false; + public boolean storedArrayList = false; + public boolean storedCommand; + + @Override + public void store(ClientRecord record) { + storedRecord = true; + } + + @Override + public void store(Collection records) { + storedArrayList = false; + } + + @Override + public void store(String accountGUID, Command command) throws NullCursorException { + storedCommand = true; + } + + @Override + public ClientRecord fetchClient(String profileID) throws NullCursorException { + return null; + } + + @Override + public Map fetchAllClients() throws NullCursorException { + return null; + } + + @Override + public List fetchCommandsForClient(String accountGUID) throws NullCursorException { + return null; + } + + @Override + public int clientsCount() { + return 0; + } + + @Override + public void wipeDB() { + dbWiped = true; + } + + @Override + public void wipeClientsTable() { + clientsTableWiped = true; + } + + @Override + public void close() { + closed = true; + } + + public void resetVars() { + storedRecord = dbWiped = clientsTableWiped = closed = storedArrayList = false; + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockGlobalSession.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockGlobalSession.java new file mode 100644 index 000000000..63afdd1ac --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockGlobalSession.java @@ -0,0 +1,57 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.EngineSettings; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.SyncConfiguration; +import org.mozilla.gecko.sync.SyncConfigurationException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; +import org.mozilla.gecko.sync.stage.CompletedStage; +import org.mozilla.gecko.sync.stage.GlobalSyncStage; +import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; + +import java.io.IOException; +import java.util.HashMap; + + +public class MockGlobalSession extends MockPrefsGlobalSession { + + public MockGlobalSession(String username, String password, KeyBundle keyBundle, GlobalSessionCallback callback) throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException { + this(new SyncConfiguration(username, new BasicAuthHeaderProvider(username, password), new MockSharedPreferences(), keyBundle), callback); + } + + public MockGlobalSession(SyncConfiguration config, GlobalSessionCallback callback) + throws SyncConfigurationException, IllegalArgumentException, IOException, NonObjectJSONException { + super(config, callback, null, null); + } + + @Override + public boolean isEngineRemotelyEnabled(String engine, EngineSettings engineSettings) { + return false; + } + + @Override + protected void prepareStages() { + super.prepareStages(); + HashMap newStages = new HashMap(this.stages); + + for (Stage stage : this.stages.keySet()) { + newStages.put(stage, new MockServerSyncStage()); + } + + // This signals that the global session is complete. + newStages.put(Stage.completed, new CompletedStage()); + + this.stages = newStages; + } + + public MockGlobalSession withStage(Stage stage, GlobalSyncStage syncStage) { + stages.put(stage, syncStage); + + return this; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockPrefsGlobalSession.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockPrefsGlobalSession.java new file mode 100644 index 000000000..c864cdf80 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockPrefsGlobalSession.java @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import android.content.Context; +import android.content.SharedPreferences; + +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.SyncConfiguration; +import org.mozilla.gecko.sync.SyncConfigurationException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.delegates.ClientsDataDelegate; +import org.mozilla.gecko.sync.delegates.GlobalSessionCallback; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; + +import java.io.IOException; + +/** + * GlobalSession touches the Android prefs system. Stub that out. + */ +public class MockPrefsGlobalSession extends GlobalSession { + + public MockSharedPreferences prefs; + + public MockPrefsGlobalSession( + SyncConfiguration config, GlobalSessionCallback callback, Context context, + ClientsDataDelegate clientsDelegate) + throws SyncConfigurationException, IllegalArgumentException, IOException, NonObjectJSONException { + super(config, callback, context, clientsDelegate); + } + + public static MockPrefsGlobalSession getSession( + String username, String password, + KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context, + ClientsDataDelegate clientsDelegate) + throws SyncConfigurationException, IllegalArgumentException, IOException, NonObjectJSONException { + return getSession(username, new BasicAuthHeaderProvider(username, password), null, + syncKeyBundle, callback, context, clientsDelegate); + } + + public static MockPrefsGlobalSession getSession( + String username, AuthHeaderProvider authHeaderProvider, String prefsPath, + KeyBundle syncKeyBundle, GlobalSessionCallback callback, Context context, + ClientsDataDelegate clientsDelegate) + throws SyncConfigurationException, IllegalArgumentException, IOException, NonObjectJSONException { + + final SharedPreferences prefs = new MockSharedPreferences(); + final SyncConfiguration config = new SyncConfiguration(username, authHeaderProvider, prefs); + config.syncKeyBundle = syncKeyBundle; + return new MockPrefsGlobalSession(config, callback, context, clientsDelegate); + } + + @Override + public Context getContext() { + return null; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockRecord.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockRecord.java new file mode 100644 index 000000000..9876b7867 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockRecord.java @@ -0,0 +1,51 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import java.util.Random; + +public class MockRecord extends Record { + private final int payloadByteCount; + public MockRecord(String guid, String collection, long lastModified, boolean deleted) { + super(guid, collection, lastModified, deleted); + // Payload used to be "foo", so let's not stray too far. + // Perhaps some tests "depend" on that payload size. + payloadByteCount = 3; + } + + public MockRecord(String guid, String collection, long lastModified, boolean deleted, int payloadByteCount) { + super(guid, collection, lastModified, deleted); + this.payloadByteCount = payloadByteCount; + } + + @Override + protected void populatePayload(ExtendedJSONObject payload) { + } + + @Override + protected void initFromPayload(ExtendedJSONObject payload) { + } + + @Override + public Record copyWithIDs(String guid, long androidID) { + MockRecord r = new MockRecord(guid, this.collection, this.lastModified, this.deleted); + r.androidID = androidID; + return r; + } + + @Override + public String toJSONString() { + // Build up a randomish payload string based on the length we were asked for. + final Random random = new Random(); + final char[] payloadChars = new char[payloadByteCount]; + for (int i = 0; i < payloadByteCount; i++) { + payloadChars[i] = (char) (random.nextInt(26) + 'a'); + } + final String payloadString = new String(payloadChars); + return "{\"id\":\"" + guid + "\", \"payload\": \"" + payloadString+ "\"}"; + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockServerSyncStage.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockServerSyncStage.java new file mode 100644 index 000000000..28a4e58b9 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockServerSyncStage.java @@ -0,0 +1,11 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +public class MockServerSyncStage extends BaseMockServerSyncStage { + @Override + public void execute() { + session.advance(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockSharedPreferences.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockSharedPreferences.java new file mode 100644 index 000000000..bc49fa7fb --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/MockSharedPreferences.java @@ -0,0 +1,137 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import android.content.SharedPreferences; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +/** + * A programmable mock content provider. + */ +public class MockSharedPreferences implements SharedPreferences, SharedPreferences.Editor { + private HashMap mValues; + private HashMap mTempValues; + + public MockSharedPreferences() { + mValues = new HashMap(); + mTempValues = new HashMap(); + } + + public Editor edit() { + return this; + } + + public boolean contains(String key) { + return mValues.containsKey(key); + } + + public Map getAll() { + return new HashMap(mValues); + } + + public boolean getBoolean(String key, boolean defValue) { + if (mValues.containsKey(key)) { + return ((Boolean)mValues.get(key)).booleanValue(); + } + return defValue; + } + + public float getFloat(String key, float defValue) { + if (mValues.containsKey(key)) { + return ((Float)mValues.get(key)).floatValue(); + } + return defValue; + } + + public int getInt(String key, int defValue) { + if (mValues.containsKey(key)) { + return ((Integer)mValues.get(key)).intValue(); + } + return defValue; + } + + public long getLong(String key, long defValue) { + if (mValues.containsKey(key)) { + return ((Long)mValues.get(key)).longValue(); + } + return defValue; + } + + public String getString(String key, String defValue) { + if (mValues.containsKey(key)) + return (String)mValues.get(key); + return defValue; + } + + @SuppressWarnings("unchecked") + public Set getStringSet(String key, Set defValues) { + if (mValues.containsKey(key)) { + return (Set) mValues.get(key); + } + return defValues; + } + + public void registerOnSharedPreferenceChangeListener( + OnSharedPreferenceChangeListener listener) { + throw new UnsupportedOperationException(); + } + + public void unregisterOnSharedPreferenceChangeListener( + OnSharedPreferenceChangeListener listener) { + throw new UnsupportedOperationException(); + } + + public Editor putBoolean(String key, boolean value) { + mTempValues.put(key, Boolean.valueOf(value)); + return this; + } + + public Editor putFloat(String key, float value) { + mTempValues.put(key, value); + return this; + } + + public Editor putInt(String key, int value) { + mTempValues.put(key, value); + return this; + } + + public Editor putLong(String key, long value) { + mTempValues.put(key, value); + return this; + } + + public Editor putString(String key, String value) { + mTempValues.put(key, value); + return this; + } + + public Editor putStringSet(String key, Set values) { + mTempValues.put(key, values); + return this; + } + + public Editor remove(String key) { + mTempValues.remove(key); + return this; + } + + public Editor clear() { + mTempValues.clear(); + return this; + } + + @SuppressWarnings("unchecked") + public boolean commit() { + mValues = (HashMap)mTempValues.clone(); + return true; + } + + public void apply() { + commit(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/TestRunner.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/TestRunner.java new file mode 100644 index 000000000..ccb5276ed --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/TestRunner.java @@ -0,0 +1,125 @@ +/** + * The MIT License + * + * Copyright (c) 2010 Xtreme Labs and Pivotal Labs + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package org.mozilla.gecko.background.testhelpers; + +import org.junit.runners.model.InitializationError; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; +import org.robolectric.manifest.AndroidManifest; +import org.robolectric.res.FileFsFile; +import org.robolectric.res.FsFile; +import org.robolectric.util.Logger; +import org.robolectric.util.ReflectionHelpers; + +/** + * Test runner customized for running unit tests either through the Gradle CLI or + * Android Studio. The runner uses the build type and build flavor to compute the + * resource, asset, and AndroidManifest paths. + * + * This test runner requires that you set the 'constants' field on the @Config + * annotation (or the org.robolectric.Config.properties file) for your tests. + * + * This is a modified version of + * https://github.com/robolectric/robolectric/blob/8676da2daa4c140679fb5903696b8191415cec8f/robolectric/src/main/java/org/robolectric/RobolectricGradleTestRunner.java + * that uses a Gradle `buildConfigField` to find build outputs. + * See https://github.com/robolectric/robolectric/issues/1648#issuecomment-113731011. + */ +public class TestRunner extends RobolectricTestRunner { + private FsFile buildFolder; + + public TestRunner(Class klass) throws InitializationError { + super(klass); + } + + @Override + protected AndroidManifest getAppManifest(Config config) { + if (config.constants() == Void.class) { + Logger.error("Field 'constants' not specified in @Config annotation"); + Logger.error("This is required when using RobolectricGradleTestRunner!"); + throw new RuntimeException("No 'constants' field in @Config annotation!"); + } + + buildFolder = FileFsFile.from(getBuildDir(config)).join("intermediates"); + + final String type = getType(config); + final String flavor = getFlavor(config); + final String packageName = getPackageName(config); + + final FsFile assets = buildFolder.join("assets", flavor, type);; + final FsFile manifest = buildFolder.join("manifests", "full", flavor, type, "AndroidManifest.xml"); + + final FsFile res; + if (buildFolder.join("res", "merged").exists()) { + res = buildFolder.join("res", "merged", flavor, type); + } else if(buildFolder.join("res").exists()) { + res = buildFolder.join("res", flavor, type); + } else { + throw new IllegalStateException("No resource folder found"); + } + + Logger.debug("Robolectric assets directory: " + assets.getPath()); + Logger.debug(" Robolectric res directory: " + res.getPath()); + Logger.debug(" Robolectric manifest path: " + manifest.getPath()); + Logger.debug(" Robolectric package name: " + packageName); + return new AndroidManifest(manifest, res, assets, packageName); + } + + private static String getType(Config config) { + try { + return ReflectionHelpers.getStaticField(config.constants(), "BUILD_TYPE"); + } catch (Throwable e) { + return null; + } + } + + private static String getFlavor(Config config) { + try { + return ReflectionHelpers.getStaticField(config.constants(), "FLAVOR"); + } catch (Throwable e) { + return null; + } + } + + private static String getPackageName(Config config) { + try { + final String packageName = config.packageName(); + if (packageName != null && !packageName.isEmpty()) { + return packageName; + } else { + return ReflectionHelpers.getStaticField(config.constants(), "APPLICATION_ID"); + } + } catch (Throwable e) { + return null; + } + } + + private String getBuildDir(Config config) { + try { + return ReflectionHelpers.getStaticField(config.constants(), "BUILD_DIR"); + } catch (Throwable e) { + return null; + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WBORepository.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WBORepository.java new file mode 100644 index 000000000..672b0a602 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WBORepository.java @@ -0,0 +1,230 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import android.content.Context; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; +import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; +import org.mozilla.gecko.sync.repositories.RecordFilter; +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.repositories.StoreTrackingRepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionBeginDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFinishDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionGuidsSinceDelegate; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionWipeDelegate; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class WBORepository extends Repository { + + public class WBORepositoryStats { + public long created = -1; + public long begun = -1; + public long fetchBegan = -1; + public long fetchCompleted = -1; + public long storeBegan = -1; + public long storeCompleted = -1; + public long finished = -1; + } + + public static final String LOG_TAG = "WBORepository"; + + // Access to stats is not guarded. + public WBORepositoryStats stats; + + // Whether or not to increment the timestamp of stored records. + public final boolean bumpTimestamps; + + public class WBORepositorySession extends StoreTrackingRepositorySession { + + protected WBORepository wboRepository; + protected ExecutorService delegateExecutor = Executors.newSingleThreadExecutor(); + public ConcurrentHashMap wbos; + + public WBORepositorySession(WBORepository repository) { + super(repository); + + wboRepository = repository; + wbos = new ConcurrentHashMap(); + stats = new WBORepositoryStats(); + stats.created = now(); + } + + @Override + protected synchronized void trackGUID(String guid) { + if (wboRepository.shouldTrack()) { + super.trackGUID(guid); + } + } + + @Override + public void guidsSince(long timestamp, + RepositorySessionGuidsSinceDelegate delegate) { + throw new RuntimeException("guidsSince not implemented."); + } + + @Override + public void fetchSince(long timestamp, + RepositorySessionFetchRecordsDelegate delegate) { + long fetchBegan = now(); + stats.fetchBegan = fetchBegan; + RecordFilter filter = storeTracker.getFilter(); + + for (Entry entry : wbos.entrySet()) { + Record record = entry.getValue(); + if (record.lastModified >= timestamp) { + if (filter != null && + filter.excludeRecord(record)) { + Logger.debug(LOG_TAG, "Excluding record " + record.guid); + continue; + } + delegate.deferredFetchDelegate(delegateExecutor).onFetchedRecord(record); + } + } + long fetchCompleted = now(); + stats.fetchCompleted = fetchCompleted; + delegate.deferredFetchDelegate(delegateExecutor).onFetchCompleted(fetchCompleted); + } + + @Override + public void fetch(final String[] guids, + final RepositorySessionFetchRecordsDelegate delegate) { + long fetchBegan = now(); + stats.fetchBegan = fetchBegan; + for (String guid : guids) { + if (wbos.containsKey(guid)) { + delegate.deferredFetchDelegate(delegateExecutor).onFetchedRecord(wbos.get(guid)); + } + } + long fetchCompleted = now(); + stats.fetchCompleted = fetchCompleted; + delegate.deferredFetchDelegate(delegateExecutor).onFetchCompleted(fetchCompleted); + } + + @Override + public void fetchAll(final RepositorySessionFetchRecordsDelegate delegate) { + long fetchBegan = now(); + stats.fetchBegan = fetchBegan; + for (Entry entry : wbos.entrySet()) { + Record record = entry.getValue(); + delegate.deferredFetchDelegate(delegateExecutor).onFetchedRecord(record); + } + long fetchCompleted = now(); + stats.fetchCompleted = fetchCompleted; + delegate.deferredFetchDelegate(delegateExecutor).onFetchCompleted(fetchCompleted); + } + + @Override + public void store(final Record record) throws NoStoreDelegateException { + if (delegate == null) { + throw new NoStoreDelegateException(); + } + final long now = now(); + if (stats.storeBegan < 0) { + stats.storeBegan = now; + } + Record existing = wbos.get(record.guid); + Logger.debug(LOG_TAG, "Existing record is " + (existing == null ? "" : (existing.guid + ", " + existing))); + if (existing != null && + existing.lastModified > record.lastModified) { + Logger.debug(LOG_TAG, "Local record is newer. Not storing."); + delegate.deferredStoreDelegate(delegateExecutor).onRecordStoreSucceeded(record.guid); + return; + } + if (existing != null) { + Logger.debug(LOG_TAG, "Replacing local record."); + } + + // Store a copy of the record with an updated modified time. + Record toStore = record.copyWithIDs(record.guid, record.androidID); + if (bumpTimestamps) { + toStore.lastModified = now; + } + wbos.put(record.guid, toStore); + + trackRecord(toStore); + delegate.deferredStoreDelegate(delegateExecutor).onRecordStoreSucceeded(record.guid); + } + + @Override + public void wipe(final RepositorySessionWipeDelegate delegate) { + if (!isActive()) { + delegate.onWipeFailed(new InactiveSessionException(null)); + return; + } + + Logger.info(LOG_TAG, "Wiping WBORepositorySession."); + this.wbos = new ConcurrentHashMap(); + + // Wipe immediately for the convenience of test code. + wboRepository.wbos = new ConcurrentHashMap(); + delegate.deferredWipeDelegate(delegateExecutor).onWipeSucceeded(); + } + + @Override + public void finish(RepositorySessionFinishDelegate delegate) throws InactiveSessionException { + Logger.info(LOG_TAG, "Finishing WBORepositorySession: handing back " + this.wbos.size() + " WBOs."); + wboRepository.wbos = this.wbos; + stats.finished = now(); + super.finish(delegate); + } + + @Override + public void begin(RepositorySessionBeginDelegate delegate) throws InvalidSessionTransitionException { + this.wbos = wboRepository.cloneWBOs(); + stats.begun = now(); + super.begin(delegate); + } + + @Override + public void storeDone(long end) { + // TODO: this is not guaranteed to be called after all of the record + // store callbacks have completed! + if (stats.storeBegan < 0) { + stats.storeBegan = end; + } + stats.storeCompleted = end; + delegate.deferredStoreDelegate(delegateExecutor).onStoreCompleted(end); + } + } + + public ConcurrentHashMap wbos; + + public WBORepository(boolean bumpTimestamps) { + super(); + this.bumpTimestamps = bumpTimestamps; + this.wbos = new ConcurrentHashMap(); + } + + public WBORepository() { + this(false); + } + + public synchronized boolean shouldTrack() { + return false; + } + + @Override + public void createSession(RepositorySessionCreationDelegate delegate, + Context context) { + delegate.deferredCreationDelegate().onSessionCreated(new WBORepositorySession(this)); + } + + public ConcurrentHashMap cloneWBOs() { + ConcurrentHashMap out = new ConcurrentHashMap(); + for (Entry entry : wbos.entrySet()) { + out.put(entry.getKey(), entry.getValue()); // Assume that records are + // immutable. + } + return out; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java new file mode 100644 index 000000000..dad748df1 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/background/testhelpers/WaitHelper.java @@ -0,0 +1,172 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.background.testhelpers; + +import org.mozilla.gecko.background.common.log.Logger; + +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; + +/** + * Implements waiting for asynchronous test events. + * + * Call WaitHelper.getTestWaiter() to get the unique instance. + * + * Call performWait(runnable) to execute runnable synchronously. + * runnable *must* call performNotify() on all exit paths to signal to + * the TestWaiter that the runnable has completed. + * + * @author rnewman + * @author nalexander + */ +public class WaitHelper { + + public static final String LOG_TAG = "WaitHelper"; + + public static class Result { + public Throwable error; + public Result() { + error = null; + } + + public Result(Throwable error) { + this.error = error; + } + } + + public static abstract class WaitHelperError extends Error { + private static final long serialVersionUID = 7074690961681883619L; + } + + /** + * Immutable. + * + * @author rnewman + */ + public static class TimeoutError extends WaitHelperError { + private static final long serialVersionUID = 8591672555848651736L; + public final int waitTimeInMillis; + + public TimeoutError(int waitTimeInMillis) { + this.waitTimeInMillis = waitTimeInMillis; + } + } + + public static class MultipleNotificationsError extends WaitHelperError { + private static final long serialVersionUID = -9072736521571635495L; + } + + public static class InterruptedError extends WaitHelperError { + private static final long serialVersionUID = 8383948170038639308L; + } + + public static class InnerError extends WaitHelperError { + private static final long serialVersionUID = 3008502618576773778L; + public Throwable innerError; + + public InnerError(Throwable e) { + innerError = e; + if (e != null) { + // Eclipse prints the stack trace of the cause. + this.initCause(e); + } + } + } + + public BlockingQueue queue = new ArrayBlockingQueue(1); + + /** + * How long performWait should wait for, in milliseconds, with the + * convention that a negative value means "wait forever". + */ + public static int defaultWaitTimeoutInMillis = -1; + + public void performWait(Runnable action) throws WaitHelperError { + this.performWait(defaultWaitTimeoutInMillis, action); + } + + public void performWait(int waitTimeoutInMillis, Runnable action) throws WaitHelperError { + Logger.debug(LOG_TAG, "performWait called."); + + Result result = null; + + try { + if (action != null) { + try { + action.run(); + Logger.debug(LOG_TAG, "Action done."); + } catch (Exception ex) { + Logger.debug(LOG_TAG, "Performing action threw: " + ex.getMessage()); + throw new InnerError(ex); + } + } + + if (waitTimeoutInMillis < 0) { + result = queue.take(); + } else { + result = queue.poll(waitTimeoutInMillis, TimeUnit.MILLISECONDS); + } + Logger.debug(LOG_TAG, "Got result from queue: " + result); + } catch (InterruptedException e) { + // We were interrupted. + Logger.debug(LOG_TAG, "performNotify interrupted with InterruptedException " + e); + final InterruptedError interruptedError = new InterruptedError(); + interruptedError.initCause(e); + throw interruptedError; + } + + if (result == null) { + // We timed out. + throw new TimeoutError(waitTimeoutInMillis); + } else if (result.error != null) { + Logger.debug(LOG_TAG, "Notified with error: " + result.error.getMessage()); + + // Rethrow any assertion with which we were notified. + InnerError innerError = new InnerError(result.error); + throw innerError; + } + // Success! + } + + public void performNotify(final Throwable e) { + if (e != null) { + Logger.debug(LOG_TAG, "performNotify called with Throwable: " + e.getMessage()); + } else { + Logger.debug(LOG_TAG, "performNotify called."); + } + + if (!queue.offer(new Result(e))) { + // This could happen if performNotify is called multiple times (which is an error). + throw new MultipleNotificationsError(); + } + } + + public void performNotify() { + this.performNotify(null); + } + + public static Runnable onThreadRunnable(final Runnable r) { + return new Runnable() { + @Override + public void run() { + new Thread(r).start(); + } + }; + } + + private static WaitHelper singleWaiter = new WaitHelper(); + public static WaitHelper getTestWaiter() { + return singleWaiter; + } + + public static void resetTestWaiter() { + singleWaiter = new WaitHelper(); + } + + public boolean isIdle() { + return queue.isEmpty(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestASNUtils.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestASNUtils.java new file mode 100644 index 000000000..f0b1f98b5 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestASNUtils.java @@ -0,0 +1,45 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.browserid.test; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.browserid.ASNUtils; +import org.mozilla.gecko.sync.Utils; + +import java.math.BigInteger; + +@RunWith(TestRunner.class) +public class TestASNUtils { + public void doTestEncodeDecodeArrays(int length1, int length2) { + if (4 + length1 + length2 > 127) { + throw new IllegalArgumentException("Total length must be < 128 - 4."); + } + byte[] first = Utils.generateRandomBytes(length1); + byte[] second = Utils.generateRandomBytes(length2); + byte[] encoded = ASNUtils.encodeTwoArraysToASN1(first, second); + byte[][] arrays = ASNUtils.decodeTwoArraysFromASN1(encoded); + Assert.assertArrayEquals(first, arrays[0]); + Assert.assertArrayEquals(second, arrays[1]); + } + + @Test + public void testEncodeDecodeArrays() { + doTestEncodeDecodeArrays(0, 0); + doTestEncodeDecodeArrays(0, 10); + doTestEncodeDecodeArrays(10, 0); + doTestEncodeDecodeArrays(10, 10); + } + + @Test + public void testEncodeDecodeRandomSizeArrays() { + for (int i = 0; i < 10; i++) { + int length1 = Utils.generateBigIntegerLessThan(BigInteger.valueOf(50)).intValue() + 10; + int length2 = Utils.generateBigIntegerLessThan(BigInteger.valueOf(50)).intValue() + 10; + doTestEncodeDecodeArrays(length1, length2); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestDSACryptoImplementation.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestDSACryptoImplementation.java new file mode 100644 index 000000000..62427e5e1 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestDSACryptoImplementation.java @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.browserid.test; + +import junit.framework.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.browserid.BrowserIDKeyPair; +import org.mozilla.gecko.browserid.DSACryptoImplementation; +import org.mozilla.gecko.sync.ExtendedJSONObject; + +import java.math.BigInteger; + +@RunWith(TestRunner.class) +public class TestDSACryptoImplementation { + @Test + public void testToJSONObject() throws Exception { + BigInteger p = new BigInteger("fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17", 16); + BigInteger q = new BigInteger("962eddcc369cba8ebb260ee6b6a126d9346e38c5", 16); + BigInteger g = new BigInteger("678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd73da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4", 16); + BigInteger x = new BigInteger("9516d860392003db5a4f168444903265467614db", 16); + BigInteger y = new BigInteger("455152a0e499f5c9d11f9f1868c8b868b1443ca853843226a5a9552dd909b4bdba879acc504acb690df0348d60e63ea37e8c7f075302e0df5bcdc76a383888a0", 16); + + BrowserIDKeyPair keyPair = new BrowserIDKeyPair( + DSACryptoImplementation.createPrivateKey(x, p, q, g), + DSACryptoImplementation.createPublicKey(y, p, q, g)); + + ExtendedJSONObject o = new ExtendedJSONObject("{\"publicKey\":{\"g\":\"678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd73da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4\",\"q\":\"962eddcc369cba8ebb260ee6b6a126d9346e38c5\",\"p\":\"fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17\",\"y\":\"455152a0e499f5c9d11f9f1868c8b868b1443ca853843226a5a9552dd909b4bdba879acc504acb690df0348d60e63ea37e8c7f075302e0df5bcdc76a383888a0\",\"algorithm\":\"DS\"},\"privateKey\":{\"g\":\"678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd73da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4\",\"q\":\"962eddcc369cba8ebb260ee6b6a126d9346e38c5\",\"p\":\"fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17\",\"x\":\"9516d860392003db5a4f168444903265467614db\",\"algorithm\":\"DS\"}}"); + Assert.assertEquals(o.getObject("privateKey"), keyPair.toJSONObject().getObject("privateKey")); + Assert.assertEquals(o.getObject("publicKey"), keyPair.toJSONObject().getObject("publicKey")); + } + + @Test + public void testFromJSONObject() throws Exception { + BigInteger p = new BigInteger("fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17", 16); + BigInteger q = new BigInteger("962eddcc369cba8ebb260ee6b6a126d9346e38c5", 16); + BigInteger g = new BigInteger("678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd73da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4", 16); + BigInteger x = new BigInteger("9516d860392003db5a4f168444903265467614db", 16); + BigInteger y = new BigInteger("455152a0e499f5c9d11f9f1868c8b868b1443ca853843226a5a9552dd909b4bdba879acc504acb690df0348d60e63ea37e8c7f075302e0df5bcdc76a383888a0", 16); + + BrowserIDKeyPair keyPair = new BrowserIDKeyPair( + DSACryptoImplementation.createPrivateKey(x, p, q, g), + DSACryptoImplementation.createPublicKey(y, p, q, g)); + + ExtendedJSONObject o = new ExtendedJSONObject("{\"publicKey\":{\"g\":\"678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd73da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4\",\"q\":\"962eddcc369cba8ebb260ee6b6a126d9346e38c5\",\"p\":\"fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17\",\"y\":\"455152a0e499f5c9d11f9f1868c8b868b1443ca853843226a5a9552dd909b4bdba879acc504acb690df0348d60e63ea37e8c7f075302e0df5bcdc76a383888a0\",\"algorithm\":\"DS\"},\"privateKey\":{\"g\":\"678471b27a9cf44ee91a49c5147db1a9aaf244f05a434d6486931d2d14271b9e35030b71fd73da179069b32e2935630e1c2062354d0da20a6c416e50be794ca4\",\"q\":\"962eddcc369cba8ebb260ee6b6a126d9346e38c5\",\"p\":\"fca682ce8e12caba26efccf7110e526db078b05edecbcd1eb4a208f3ae1617ae01f35b91a47e6df63413c5e12ed0899bcd132acd50d99151bdc43ee737592e17\",\"x\":\"9516d860392003db5a4f168444903265467614db\",\"algorithm\":\"DS\"}}"); + + Assert.assertEquals(keyPair.getPublic().toJSONObject(), DSACryptoImplementation.createPublicKey(o.getObject("publicKey")).toJSONObject()); + Assert.assertEquals(keyPair.getPrivate().toJSONObject(), DSACryptoImplementation.createPrivateKey(o.getObject("privateKey")).toJSONObject()); + } + + @Test + public void testRoundTrip() throws Exception { + BrowserIDKeyPair keyPair = DSACryptoImplementation.generateKeyPair(512); + ExtendedJSONObject o = keyPair.toJSONObject(); + BrowserIDKeyPair keyPair2 = DSACryptoImplementation.fromJSONObject(o); + Assert.assertEquals(o, keyPair2.toJSONObject()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestJSONWebTokenUtils.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestJSONWebTokenUtils.java new file mode 100644 index 000000000..7e1f9287e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestJSONWebTokenUtils.java @@ -0,0 +1,151 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.browserid.test; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.browserid.BrowserIDKeyPair; +import org.mozilla.gecko.browserid.DSACryptoImplementation; +import org.mozilla.gecko.browserid.JSONWebTokenUtils; +import org.mozilla.gecko.browserid.RSACryptoImplementation; +import org.mozilla.gecko.browserid.SigningPrivateKey; +import org.mozilla.gecko.browserid.VerifyingPublicKey; +import org.mozilla.gecko.sync.ExtendedJSONObject; + +import java.math.BigInteger; +import java.security.GeneralSecurityException; + +@RunWith(TestRunner.class) +public class TestJSONWebTokenUtils { + public void doTestEncodeDecode(BrowserIDKeyPair keyPair) throws Exception { + SigningPrivateKey privateKey = keyPair.getPrivate(); + VerifyingPublicKey publicKey = keyPair.getPublic(); + + ExtendedJSONObject o = new ExtendedJSONObject(); + o.put("key", "value"); + + String token = JSONWebTokenUtils.encode(o.toJSONString(), privateKey); + Assert.assertNotNull(token); + + String payload = JSONWebTokenUtils.decode(token, publicKey); + Assert.assertEquals(o.toJSONString(), payload); + + try { + JSONWebTokenUtils.decode(token + "x", publicKey); + Assert.fail("Expected exception."); + } catch (GeneralSecurityException e) { + // Do nothing. + } + } + + @Test + public void testEncodeDecodeSuccessRSA() throws Exception { + doTestEncodeDecode(RSACryptoImplementation.generateKeyPair(1024)); + doTestEncodeDecode(RSACryptoImplementation.generateKeyPair(2048)); + } + + @Test + public void testEncodeDecodeSuccessDSA() throws Exception { + doTestEncodeDecode(DSACryptoImplementation.generateKeyPair(512)); + doTestEncodeDecode(DSACryptoImplementation.generateKeyPair(1024)); + } + + public static String TEST_ASSERTION_ISSUER = "127.0.0.1"; + public static String TEST_AUDIENCE = "http://localhost:8080"; + + @Test + public void testRSAGeneration() throws Exception { + // This test uses (now out-dated) MockMyID RSA data but doesn't rely on this + // data actually being MockMyID's data. + final BigInteger MOCKMYID_MODULUS = new BigInteger("15498874758090276039465094105837231567265546373975960480941122651107772824121527483107402353899846252489837024870191707394743196399582959425513904762996756672089693541009892030848825079649783086005554442490232900875792851786203948088457942416978976455297428077460890650409549242124655536986141363719589882160081480785048965686285142002320767066674879737238012064156675899512503143225481933864507793118457805792064445502834162315532113963746801770187685650408560424682654937744713813773896962263709692724630650952159596951348264005004375017610441835956073275708740239518011400991972811669493356682993446554779893834303"); + final BigInteger MOCKMYID_PUBLIC_EXPONENT = new BigInteger("65537"); + final BigInteger MOCKMYID_PRIVATE_EXPONENT = new BigInteger("6539906961872354450087244036236367269804254381890095841127085551577495913426869112377010004955160417265879626558436936025363204803913318582680951558904318308893730033158178650549970379367915856087364428530828396795995781364659413467784853435450762392157026962694408807947047846891301466649598749901605789115278274397848888140105306063608217776127549926721544215720872305194645129403056801987422794114703255989202755511523434098625000826968430077091984351410839837395828971692109391386427709263149504336916566097901771762648090880994773325283207496645630792248007805177873532441314470502254528486411726581424522838833"); + + BigInteger n = new BigInteger("20332459213245328760269530796942625317006933400814022542511832260333163206808672913301254872114045771215470352093046136365629411384688395020388553744886954869033696089099714200452682590914843971683468562019706059388121176435204818734091361033445697933682779095713376909412972373727850278295874361806633955236862180792787906413536305117030045164276955491725646610368132167655556353974515423042221261732084368978523747789654468953860772774078384556028728800902433401131226904244661160767916883680495122225202542023841606998867411022088440946301191503335932960267228470933599974787151449279465703844493353175088719018221"); + BigInteger e = new BigInteger("65537"); + BigInteger d = new BigInteger("9362542596354998418106014928820888151984912891492829581578681873633736656469965533631464203894863562319612803232737938923691416707617473868582415657005943574434271946791143554652502483003923911339605326222297167404896789026986450703532494518628015811567189641735787240372075015553947628033216297520493759267733018808392882741098489889488442349031883643894014316243251108104684754879103107764521172490019661792943030921873284592436328217485953770574054344056638447333651425231219150676837203185544359148474983670261712939626697233692596362322419559401320065488125670905499610998631622562652935873085671353890279911361"); + + long iat = 1352995809210L; + long dur = 60 * 60 * 1000; + long exp = iat + dur; + + VerifyingPublicKey mockMyIdPublicKey = RSACryptoImplementation.createPublicKey(MOCKMYID_MODULUS, MOCKMYID_PUBLIC_EXPONENT);; + SigningPrivateKey mockMyIdPrivateKey = RSACryptoImplementation.createPrivateKey(MOCKMYID_MODULUS, MOCKMYID_PRIVATE_EXPONENT); + VerifyingPublicKey publicKeyToSign = RSACryptoImplementation.createPublicKey(n, e); + SigningPrivateKey privateKeyToSignWith = RSACryptoImplementation.createPrivateKey(n, d); + + String certificate = JSONWebTokenUtils.createCertificate(publicKeyToSign, "test@mockmyid.com", "mockmyid.com", iat, exp, mockMyIdPrivateKey); + String assertion = JSONWebTokenUtils.createAssertion(privateKeyToSignWith, certificate, TEST_AUDIENCE, TEST_ASSERTION_ISSUER, iat, exp); + String payload = JSONWebTokenUtils.decode(certificate, mockMyIdPublicKey); + + String EXPECTED_PAYLOAD = "{\"exp\":1352999409210,\"iat\":1352995809210,\"iss\":\"mockmyid.com\",\"principal\":{\"email\":\"test@mockmyid.com\"},\"public-key\":{\"e\":\"65537\",\"n\":\"20332459213245328760269530796942625317006933400814022542511832260333163206808672913301254872114045771215470352093046136365629411384688395020388553744886954869033696089099714200452682590914843971683468562019706059388121176435204818734091361033445697933682779095713376909412972373727850278295874361806633955236862180792787906413536305117030045164276955491725646610368132167655556353974515423042221261732084368978523747789654468953860772774078384556028728800902433401131226904244661160767916883680495122225202542023841606998867411022088440946301191503335932960267228470933599974787151449279465703844493353175088719018221\",\"algorithm\":\"RS\"}}"; + Assert.assertEquals(EXPECTED_PAYLOAD, payload); + + // Really(!) brittle tests below. The RSA signature algorithm is deterministic, so we can test the actual signature. + String EXPECTED_CERTIFICATE = "eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjEzNTI5OTk0MDkyMTAsImlhdCI6MTM1Mjk5NTgwOTIxMCwiaXNzIjoibW9ja215aWQuY29tIiwicHJpbmNpcGFsIjp7ImVtYWlsIjoidGVzdEBtb2NrbXlpZC5jb20ifSwicHVibGljLWtleSI6eyJlIjoiNjU1MzciLCJuIjoiMjAzMzI0NTkyMTMyNDUzMjg3NjAyNjk1MzA3OTY5NDI2MjUzMTcwMDY5MzM0MDA4MTQwMjI1NDI1MTE4MzIyNjAzMzMxNjMyMDY4MDg2NzI5MTMzMDEyNTQ4NzIxMTQwNDU3NzEyMTU0NzAzNTIwOTMwNDYxMzYzNjU2Mjk0MTEzODQ2ODgzOTUwMjAzODg1NTM3NDQ4ODY5NTQ4NjkwMzM2OTYwODkwOTk3MTQyMDA0NTI2ODI1OTA5MTQ4NDM5NzE2ODM0Njg1NjIwMTk3MDYwNTkzODgxMjExNzY0MzUyMDQ4MTg3MzQwOTEzNjEwMzM0NDU2OTc5MzM2ODI3NzkwOTU3MTMzNzY5MDk0MTI5NzIzNzM3Mjc4NTAyNzgyOTU4NzQzNjE4MDY2MzM5NTUyMzY4NjIxODA3OTI3ODc5MDY0MTM1MzYzMDUxMTcwMzAwNDUxNjQyNzY5NTU0OTE3MjU2NDY2MTAzNjgxMzIxNjc2NTU1NTYzNTM5NzQ1MTU0MjMwNDIyMjEyNjE3MzIwODQzNjg5Nzg1MjM3NDc3ODk2NTQ0Njg5NTM4NjA3NzI3NzQwNzgzODQ1NTYwMjg3Mjg4MDA5MDI0MzM0MDExMzEyMjY5MDQyNDQ2NjExNjA3Njc5MTY4ODM2ODA0OTUxMjIyMjUyMDI1NDIwMjM4NDE2MDY5OTg4Njc0MTEwMjIwODg0NDA5NDYzMDExOTE1MDMzMzU5MzI5NjAyNjcyMjg0NzA5MzM1OTk5NzQ3ODcxNTE0NDkyNzk0NjU3MDM4NDQ0OTMzNTMxNzUwODg3MTkwMTgyMjEiLCJhbGdvcml0aG0iOiJSUyJ9fQ.ZgT0ezITaE6rRQCxEA6OHkjwAsFdE-R8943UEmiCvKKpsbxlSlI1Iya1Oho2wrhet5bjBGM77EffzC2YwzD5qa7SrVpNwSCIW6AwnlJ6YePoNblkn0y7NQ_qThvLoaP4Vlk_XM0LbK_QPHqaWU7ldm8LF5Zp4oHgayMP4YhiyKYS2TwWWcvswT2g9IhU6YdYcF0TwT2YkJ4t3h7_sVn-OmQQu4k1KKGFLpT6HOj2EGaKmw-mzayHL0r7L3-5g_7Q83RMBe_k_4YeLG8InxO3M3GreqcaImv4XO5D-C__txfFuaLJjTzKBLrIIosckaNwp4JmN1Nf8x9t5RXHLCsrjw"; + Assert.assertEquals(EXPECTED_CERTIFICATE, certificate); + + String EXPECTED_ASSERTION = "eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjEzNTI5OTk0MDkyMTAsImlhdCI6MTM1Mjk5NTgwOTIxMCwiaXNzIjoibW9ja215aWQuY29tIiwicHJpbmNpcGFsIjp7ImVtYWlsIjoidGVzdEBtb2NrbXlpZC5jb20ifSwicHVibGljLWtleSI6eyJlIjoiNjU1MzciLCJuIjoiMjAzMzI0NTkyMTMyNDUzMjg3NjAyNjk1MzA3OTY5NDI2MjUzMTcwMDY5MzM0MDA4MTQwMjI1NDI1MTE4MzIyNjAzMzMxNjMyMDY4MDg2NzI5MTMzMDEyNTQ4NzIxMTQwNDU3NzEyMTU0NzAzNTIwOTMwNDYxMzYzNjU2Mjk0MTEzODQ2ODgzOTUwMjAzODg1NTM3NDQ4ODY5NTQ4NjkwMzM2OTYwODkwOTk3MTQyMDA0NTI2ODI1OTA5MTQ4NDM5NzE2ODM0Njg1NjIwMTk3MDYwNTkzODgxMjExNzY0MzUyMDQ4MTg3MzQwOTEzNjEwMzM0NDU2OTc5MzM2ODI3NzkwOTU3MTMzNzY5MDk0MTI5NzIzNzM3Mjc4NTAyNzgyOTU4NzQzNjE4MDY2MzM5NTUyMzY4NjIxODA3OTI3ODc5MDY0MTM1MzYzMDUxMTcwMzAwNDUxNjQyNzY5NTU0OTE3MjU2NDY2MTAzNjgxMzIxNjc2NTU1NTYzNTM5NzQ1MTU0MjMwNDIyMjEyNjE3MzIwODQzNjg5Nzg1MjM3NDc3ODk2NTQ0Njg5NTM4NjA3NzI3NzQwNzgzODQ1NTYwMjg3Mjg4MDA5MDI0MzM0MDExMzEyMjY5MDQyNDQ2NjExNjA3Njc5MTY4ODM2ODA0OTUxMjIyMjUyMDI1NDIwMjM4NDE2MDY5OTg4Njc0MTEwMjIwODg0NDA5NDYzMDExOTE1MDMzMzU5MzI5NjAyNjcyMjg0NzA5MzM1OTk5NzQ3ODcxNTE0NDkyNzk0NjU3MDM4NDQ0OTMzNTMxNzUwODg3MTkwMTgyMjEiLCJhbGdvcml0aG0iOiJSUyJ9fQ.ZgT0ezITaE6rRQCxEA6OHkjwAsFdE-R8943UEmiCvKKpsbxlSlI1Iya1Oho2wrhet5bjBGM77EffzC2YwzD5qa7SrVpNwSCIW6AwnlJ6YePoNblkn0y7NQ_qThvLoaP4Vlk_XM0LbK_QPHqaWU7ldm8LF5Zp4oHgayMP4YhiyKYS2TwWWcvswT2g9IhU6YdYcF0TwT2YkJ4t3h7_sVn-OmQQu4k1KKGFLpT6HOj2EGaKmw-mzayHL0r7L3-5g_7Q83RMBe_k_4YeLG8InxO3M3GreqcaImv4XO5D-C__txfFuaLJjTzKBLrIIosckaNwp4JmN1Nf8x9t5RXHLCsrjw~eyJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODA4MCIsImV4cCI6MTM1Mjk5OTQwOTIxMCwiaWF0IjoxMzUyOTk1ODA5MjEwLCJpc3MiOiIxMjcuMC4wLjEifQ.gj5Q9KXR_mPEltn3SXKAjIHMOpQq0FP6NdPOB-Zu149LKhQrfXS90woVJYg8WpaasmiS6gjBFni3urq3adPktzw4RoMm1qVMvSRXXIRZzgsV_vHlSenIY0KlAk4140pAlAPcdJhB2bvKUPPDq0TLzlWHgQpheAAFMGPY1OGgwgHtsCQC_vyE2wFi8M58IGYQ-05KmWc6Zo33CJG6LjVvkTPvPTEzQKFYKwDQGc4NTkqZbCNZE6iRq4mlX9LGFddzEDiSUDmS53SwR4nfFzPQE6Q1xnU4a_BLhfNpdfOc-uHGoJGbm0ZJpLdKf7zadp34ImFA9IUBhjegingZhm2i5g"; + Assert.assertEquals(EXPECTED_ASSERTION, assertion); + } + + @Test + public void testDSAGeneration() throws Exception { + // This test uses MockMyID DSA data but doesn't rely on this data actually + // being MockMyID's data. + final BigInteger MOCKMYID_x = new BigInteger("385cb3509f086e110c5e24bdd395a84b335a09ae", 16); + final BigInteger MOCKMYID_y = new BigInteger("738ec929b559b604a232a9b55a5295afc368063bb9c20fac4e53a74970a4db7956d48e4c7ed523405f629b4cc83062f13029c4d615bbacb8b97f5e56f0c7ac9bc1d4e23809889fa061425c984061fca1826040c399715ce7ed385c4dd0d402256912451e03452d3c961614eb458f188e3e8d2782916c43dbe2e571251ce38262", 16); + final BigInteger MOCKMYID_p = new BigInteger("ff600483db6abfc5b45eab78594b3533d550d9f1bf2a992a7a8daa6dc34f8045ad4e6e0c429d334eeeaaefd7e23d4810be00e4cc1492cba325ba81ff2d5a5b305a8d17eb3bf4a06a349d392e00d329744a5179380344e82a18c47933438f891e22aeef812d69c8f75e326cb70ea000c3f776dfdbd604638c2ef717fc26d02e17", 16); + final BigInteger MOCKMYID_q = new BigInteger("e21e04f911d1ed7991008ecaab3bf775984309c3", 16); + final BigInteger MOCKMYID_g = new BigInteger("c52a4a0ff3b7e61fdf1867ce84138369a6154f4afa92966e3c827e25cfa6cf508b90e5de419e1337e07a2e9e2a3cd5dea704d175f8ebf6af397d69e110b96afb17c7a03259329e4829b0d03bbc7896b15b4ade53e130858cc34d96269aa89041f409136c7242a38895c9d5bccad4f389af1d7a4bd1398bd072dffa896233397a", 16); + + BigInteger g = new BigInteger("f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a", 16); + BigInteger q = new BigInteger("9760508f15230bccb292b982a2eb840bf0581cf5", 16); + BigInteger p = new BigInteger("fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7", 16); + BigInteger x = new BigInteger("b137fc5b8faaa53b170563eb03c18b46b657bb6", 16); + BigInteger y = new BigInteger("ea809be508bc94485553efac8ef2a8debdcdb3545ce433e8bd5889ec9d0880a13b2a8af35451161e58229d1e2be69e74a7251465a394913e8e64b0c33fde39a637b6047d7370178cf4404c0a7b4c2ed31d9cfe03ab79dbcc64667e6e7bc244eb1c127c28d725db94aff29b858bdb636f1307bdf48b3c91f387c2ab588086b6c8", 16); + + long iat = 1380070362995L; + long dur = 60 * 60 * 1000; + long exp = iat + dur; + + VerifyingPublicKey mockMyIdPublicKey = DSACryptoImplementation.createPublicKey(MOCKMYID_y, MOCKMYID_p, MOCKMYID_q, MOCKMYID_g); + SigningPrivateKey mockMyIdPrivateKey = DSACryptoImplementation.createPrivateKey(MOCKMYID_x, MOCKMYID_p, MOCKMYID_q, MOCKMYID_g); + VerifyingPublicKey publicKeyToSign = DSACryptoImplementation.createPublicKey(y, p, q, g); + SigningPrivateKey privateKeyToSignWith = DSACryptoImplementation.createPrivateKey(x, p, q, g); + + String certificate = JSONWebTokenUtils.createCertificate(publicKeyToSign, "test@mockmyid.com", "mockmyid.com", iat, exp, mockMyIdPrivateKey); + String assertion = JSONWebTokenUtils.createAssertion(privateKeyToSignWith, certificate, TEST_AUDIENCE, TEST_ASSERTION_ISSUER, iat, exp); + String payload = JSONWebTokenUtils.decode(certificate, mockMyIdPublicKey); + + String EXPECTED_PAYLOAD = "{\"exp\":1380073962995,\"iat\":1380070362995,\"iss\":\"mockmyid.com\",\"principal\":{\"email\":\"test@mockmyid.com\"},\"public-key\":{\"g\":\"f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a\",\"q\":\"9760508f15230bccb292b982a2eb840bf0581cf5\",\"p\":\"fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7\",\"y\":\"ea809be508bc94485553efac8ef2a8debdcdb3545ce433e8bd5889ec9d0880a13b2a8af35451161e58229d1e2be69e74a7251465a394913e8e64b0c33fde39a637b6047d7370178cf4404c0a7b4c2ed31d9cfe03ab79dbcc64667e6e7bc244eb1c127c28d725db94aff29b858bdb636f1307bdf48b3c91f387c2ab588086b6c8\",\"algorithm\":\"DS\"}}"; + Assert.assertEquals(EXPECTED_PAYLOAD, payload); + + // Really(!) brittle tests below. The DSA signature algorithm is not deterministic, so we can't test the actual signature. + String EXPECTED_CERTIFICATE_PREFIX = "eyJhbGciOiJEUzEyOCJ9.eyJleHAiOjEzODAwNzM5NjI5OTUsImlhdCI6MTM4MDA3MDM2Mjk5NSwiaXNzIjoibW9ja215aWQuY29tIiwicHJpbmNpcGFsIjp7ImVtYWlsIjoidGVzdEBtb2NrbXlpZC5jb20ifSwicHVibGljLWtleSI6eyJnIjoiZjdlMWEwODVkNjliM2RkZWNiYmNhYjVjMzZiODU3Yjk3OTk0YWZiYmZhM2FlYTgyZjk1NzRjMGIzZDA3ODI2NzUxNTk1NzhlYmFkNDU5NGZlNjcxMDcxMDgxODBiNDQ5MTY3MTIzZTg0YzI4MTYxM2I3Y2YwOTMyOGNjOGE2ZTEzYzE2N2E4YjU0N2M4ZDI4ZTBhM2FlMWUyYmIzYTY3NTkxNmVhMzdmMGJmYTIxMzU2MmYxZmI2MjdhMDEyNDNiY2NhNGYxYmVhODUxOTA4OWE4ODNkZmUxNWFlNTlmMDY5MjhiNjY1ZTgwN2I1NTI1NjQwMTRjM2JmZWNmNDkyYSIsInEiOiI5NzYwNTA4ZjE1MjMwYmNjYjI5MmI5ODJhMmViODQwYmYwNTgxY2Y1IiwicCI6ImZkN2Y1MzgxMWQ3NTEyMjk1MmRmNGE5YzJlZWNlNGU3ZjYxMWI3NTIzY2VmNDQwMGMzMWUzZjgwYjY1MTI2Njk0NTVkNDAyMjUxZmI1OTNkOGQ1OGZhYmZjNWY1YmEzMGY2Y2I5YjU1NmNkNzgxM2I4MDFkMzQ2ZmYyNjY2MGI3NmI5OTUwYTVhNDlmOWZlODA0N2IxMDIyYzI0ZmJiYTlkN2ZlYjdjNjFiZjgzYjU3ZTdjNmE4YTYxNTBmMDRmYjgzZjZkM2M1MWVjMzAyMzU1NDEzNWExNjkxMzJmNjc1ZjNhZTJiNjFkNzJhZWZmMjIyMDMxOTlkZDE0ODAxYzciLCJ5IjoiZWE4MDliZTUwOGJjOTQ0ODU1NTNlZmFjOGVmMmE4ZGViZGNkYjM1NDVjZTQzM2U4YmQ1ODg5ZWM5ZDA4ODBhMTNiMmE4YWYzNTQ1MTE2MWU1ODIyOWQxZTJiZTY5ZTc0YTcyNTE0NjVhMzk0OTEzZThlNjRiMGMzM2ZkZTM5YTYzN2I2MDQ3ZDczNzAxNzhjZjQ0MDRjMGE3YjRjMmVkMzFkOWNmZTAzYWI3OWRiY2M2NDY2N2U2ZTdiYzI0NGViMWMxMjdjMjhkNzI1ZGI5NGFmZjI5Yjg1OGJkYjYzNmYxMzA3YmRmNDhiM2M5MWYzODdjMmFiNTg4MDg2YjZjOCIsImFsZ29yaXRobSI6IkRTIn19"; + String[] expectedCertificateParts = EXPECTED_CERTIFICATE_PREFIX.split("\\."); + String[] certificateParts = certificate.split("\\."); + Assert.assertEquals(expectedCertificateParts[0], certificateParts[0]); + Assert.assertEquals(expectedCertificateParts[1], certificateParts[1]); + + String EXPECTED_ASSERTION_FRAGMENT = "eyJhbGciOiJEUzEyOCJ9.eyJhdWQiOiJodHRwOlwvXC9sb2NhbGhvc3Q6ODA4MCIsImV4cCI6MTM4MDA3Mzk2Mjk5NSwiaWF0IjoxMzgwMDcwMzYyOTk1LCJpc3MiOiIxMjcuMC4wLjEifQ"; + String[] expectedAssertionParts = EXPECTED_ASSERTION_FRAGMENT.split("\\."); + String[] assertionParts = assertion.split("~")[1].split("\\."); + Assert.assertEquals(expectedAssertionParts[0], assertionParts[0]); + Assert.assertEquals(expectedAssertionParts[1], assertionParts[1]); + } + + @Test + public void testGetPayloadString() throws Exception { + String s; + s = JSONWebTokenUtils.getPayloadString("{}", "audience", "issuer", 1L, 2L); + Assert.assertEquals("{\"aud\":\"audience\",\"exp\":2,\"iat\":1,\"iss\":\"issuer\"}", s); + + // Make sure we don't include null issuedAt. + s = JSONWebTokenUtils.getPayloadString("{}", "audience", "issuer", null, 3L); + Assert.assertEquals("{\"aud\":\"audience\",\"exp\":3,\"iss\":\"issuer\"}", s); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestRSACryptoImplementation.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestRSACryptoImplementation.java new file mode 100644 index 000000000..6dfa88ebf --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/browserid/test/TestRSACryptoImplementation.java @@ -0,0 +1,56 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.browserid.test; + +import junit.framework.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.browserid.BrowserIDKeyPair; +import org.mozilla.gecko.browserid.RSACryptoImplementation; +import org.mozilla.gecko.sync.ExtendedJSONObject; + +import java.math.BigInteger; + +@RunWith(TestRunner.class) +public class TestRSACryptoImplementation { + @Test + public void testToJSONObject() throws Exception { + BigInteger n = new BigInteger("7042170764319402120473546823641395184140303948430445023576085129538272863656735924617881022040465877164076593767104512065359975488480629290310209335113577"); + BigInteger e = new BigInteger("65537"); + BigInteger d = new BigInteger("2050102629239206449128199335463237235732683202345308155771672920433658970744825199440426256856862541525088288448769859770132714705204296375901885294992205"); + + BrowserIDKeyPair keyPair = new BrowserIDKeyPair( + RSACryptoImplementation.createPrivateKey(n, d), + RSACryptoImplementation.createPublicKey(n, e)); + + ExtendedJSONObject o = new ExtendedJSONObject("{\"publicKey\":{\"e\":\"65537\",\"n\":\"7042170764319402120473546823641395184140303948430445023576085129538272863656735924617881022040465877164076593767104512065359975488480629290310209335113577\",\"algorithm\":\"RS\"},\"privateKey\":{\"d\":\"2050102629239206449128199335463237235732683202345308155771672920433658970744825199440426256856862541525088288448769859770132714705204296375901885294992205\",\"n\":\"7042170764319402120473546823641395184140303948430445023576085129538272863656735924617881022040465877164076593767104512065359975488480629290310209335113577\",\"algorithm\":\"RS\"}}"); + Assert.assertEquals(o.getObject("privateKey"), keyPair.toJSONObject().getObject("privateKey")); + Assert.assertEquals(o.getObject("publicKey"), keyPair.toJSONObject().getObject("publicKey")); + } + + @Test + public void testFromJSONObject() throws Exception { + BigInteger n = new BigInteger("7042170764319402120473546823641395184140303948430445023576085129538272863656735924617881022040465877164076593767104512065359975488480629290310209335113577"); + BigInteger e = new BigInteger("65537"); + BigInteger d = new BigInteger("2050102629239206449128199335463237235732683202345308155771672920433658970744825199440426256856862541525088288448769859770132714705204296375901885294992205"); + + BrowserIDKeyPair keyPair = new BrowserIDKeyPair( + RSACryptoImplementation.createPrivateKey(n, d), + RSACryptoImplementation.createPublicKey(n, e)); + + ExtendedJSONObject o = new ExtendedJSONObject("{\"publicKey\":{\"e\":\"65537\",\"n\":\"7042170764319402120473546823641395184140303948430445023576085129538272863656735924617881022040465877164076593767104512065359975488480629290310209335113577\",\"algorithm\":\"RS\"},\"privateKey\":{\"d\":\"2050102629239206449128199335463237235732683202345308155771672920433658970744825199440426256856862541525088288448769859770132714705204296375901885294992205\",\"n\":\"7042170764319402120473546823641395184140303948430445023576085129538272863656735924617881022040465877164076593767104512065359975488480629290310209335113577\",\"algorithm\":\"RS\"}}"); + + Assert.assertEquals(keyPair.getPublic().toJSONObject(), RSACryptoImplementation.createPublicKey(o.getObject("publicKey")).toJSONObject()); + Assert.assertEquals(keyPair.getPrivate().toJSONObject(), RSACryptoImplementation.createPrivateKey(o.getObject("privateKey")).toJSONObject()); + } + + @Test + public void testRoundTrip() throws Exception { + BrowserIDKeyPair keyPair = RSACryptoImplementation.generateKeyPair(512); + ExtendedJSONObject o = keyPair.toJSONObject(); + BrowserIDKeyPair keyPair2 = RSACryptoImplementation.fromJSONObject(o); + Assert.assertEquals(o, keyPair2.toJSONObject()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/cleanup/TestFileCleanupController.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/cleanup/TestFileCleanupController.java new file mode 100644 index 000000000..6858b65a7 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/cleanup/TestFileCleanupController.java @@ -0,0 +1,92 @@ +/* + * 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 org.mozilla.gecko.cleanup; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.robolectric.RuntimeEnvironment; + +import java.util.ArrayList; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.atMost; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +/** + * Tests functionality of the {@link FileCleanupController}. + */ +@RunWith(TestRunner.class) +public class TestFileCleanupController { + + @Test + public void testStartIfReadyEmptySharedPrefsRunsCleanup() { + final Context context = mock(Context.class); + FileCleanupController.startIfReady(context, getSharedPreferences(), ""); + verify(context).startService(any(Intent.class)); + } + + @Test + public void testStartIfReadyLastRunNowDoesNotRun() { + final SharedPreferences sharedPrefs = getSharedPreferences(); + sharedPrefs.edit() + .putLong(FileCleanupController.PREF_LAST_CLEANUP_MILLIS, System.currentTimeMillis()) + .commit(); // synchronous to finish before test runs. + + final Context context = mock(Context.class); + FileCleanupController.startIfReady(context, sharedPrefs, ""); + + verify(context, never()).startService((any(Intent.class))); + } + + /** + * Depends on {@link #testStartIfReadyEmptySharedPrefsRunsCleanup()} success – + * i.e. we expect the cleanup to run with empty prefs. + */ + @Test + public void testStartIfReadyDoesNotRunTwiceInSuccession() { + final Context context = mock(Context.class); + final SharedPreferences sharedPrefs = getSharedPreferences(); + + FileCleanupController.startIfReady(context, sharedPrefs, ""); + verify(context).startService(any(Intent.class)); + + // Note: the Controller relies on SharedPrefs.apply, but + // robolectric made this a synchronous call. Yay! + FileCleanupController.startIfReady(context, sharedPrefs, ""); + verify(context, atMost(1)).startService(any(Intent.class)); + } + + @Test + public void testGetFilesToCleanupContainsProfilePath() { + final String profilePath = "/a/profile/path"; + final ArrayList fileList = FileCleanupController.getFilesToCleanup(profilePath); + assertNotNull("Returned file list is non-null", fileList); + + boolean atLeastOneStartsWithProfilePath = false; + final String pathToCheck = profilePath + "/"; // Ensure the calling code adds a slash to divide the path. + for (final String path : fileList) { + if (path.startsWith(pathToCheck)) { + // It'd be great if we could assert these individually so + // we could display the Strings in console output. + atLeastOneStartsWithProfilePath = true; + } + } + assertTrue("At least one returned String starts with a profile path", atLeastOneStartsWithProfilePath); + } + + private SharedPreferences getSharedPreferences() { + return RuntimeEnvironment.application.getSharedPreferences("TestFileCleanupController", 0); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/cleanup/TestFileCleanupService.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/cleanup/TestFileCleanupService.java new file mode 100644 index 000000000..0326adb6a --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/cleanup/TestFileCleanupService.java @@ -0,0 +1,106 @@ +/* + * 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 org.mozilla.gecko.cleanup; + +import android.content.Intent; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.*; + +/** + * Tests the methods of {@link FileCleanupService}. + */ +@RunWith(TestRunner.class) +public class TestFileCleanupService { + @Rule + public final TemporaryFolder tempFolder = new TemporaryFolder(); + + private void assertAllFilesExist(final List fileList) { + for (final File file : fileList) { + assertTrue("File exists", file.exists()); + } + } + + private void assertAllFilesDoNotExist(final List fileList) { + for (final File file : fileList) { + assertFalse("File does not exist", file.exists()); + } + } + + private void onHandleIntent(final ArrayList filePaths) { + final FileCleanupService service = new FileCleanupService(); + final Intent intent = new Intent(FileCleanupService.ACTION_DELETE_FILES); + intent.putExtra(FileCleanupService.EXTRA_FILE_PATHS_TO_DELETE, filePaths); + service.onHandleIntent(intent); + } + + @Test + public void testOnHandleIntentDeleteSpecifiedFiles() throws Exception { + final int fileListCount = 3; + final ArrayList filesToDelete = generateFileList(fileListCount); + + final ArrayList pathsToDelete = new ArrayList<>(fileListCount); + for (final File file : filesToDelete) { + pathsToDelete.add(file.getAbsolutePath()); + } + + assertAllFilesExist(filesToDelete); + onHandleIntent(pathsToDelete); + assertAllFilesDoNotExist(filesToDelete); + } + + @Test + public void testOnHandleIntentDoesNotDeleteUnrelatedFiles() throws Exception { + final ArrayList filesShouldNotBeDeleted = generateFileList(3); + assertAllFilesExist(filesShouldNotBeDeleted); + onHandleIntent(new ArrayList()); + assertAllFilesExist(filesShouldNotBeDeleted); + } + + @Test + public void testOnHandleIntentDeletesEmptyDirectory() throws Exception { + final File dir = tempFolder.newFolder(); + final ArrayList filesToDelete = new ArrayList<>(1); + filesToDelete.add(dir.getAbsolutePath()); + + assertTrue("Empty directory exists", dir.exists()); + onHandleIntent(filesToDelete); + assertFalse("Empty directory deleted by service", dir.exists()); + } + + @Test + public void testOnHandleIntentDoesNotDeleteNonEmptyDirectory() throws Exception { + final File dir = tempFolder.newFolder(); + final ArrayList filesCannotDelete = new ArrayList<>(1); + filesCannotDelete.add(dir.getAbsolutePath()); + assertTrue("Directory exists", dir.exists()); + + final File fileInDir = new File(dir, "file_in_dir"); + assertTrue("File in dir created", fileInDir.createNewFile()); + + onHandleIntent(filesCannotDelete); + assertTrue("Non-empty directory not deleted", dir.exists()); + assertTrue("File in directory not deleted", fileInDir.exists()); + } + + private ArrayList generateFileList(final int size) throws IOException { + final ArrayList fileList = new ArrayList<>(size); + for (int i = 0; i < size; ++i) { + fileList.add(tempFolder.newFile()); + } + return fileList; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserContractTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserContractTest.java new file mode 100644 index 000000000..e36153d0e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserContractTest.java @@ -0,0 +1,67 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.db; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class BrowserContractTest { + @Test + /** + * Test that bookmark and sorting order clauses are set correctly + */ + public void testGetCombinedFrecencySortOrder() throws Exception { + String sqlNoBookmarksDesc = BrowserContract.getCombinedFrecencySortOrder(false, false); + String sqlNoBookmarksAsc = BrowserContract.getCombinedFrecencySortOrder(false, true); + String sqlBookmarksDesc = BrowserContract.getCombinedFrecencySortOrder(true, false); + String sqlBookmarksAsc = BrowserContract.getCombinedFrecencySortOrder(true, true); + + assertTrue(sqlBookmarksAsc.endsWith(" ASC")); + assertTrue(sqlBookmarksDesc.endsWith(" DESC")); + assertTrue(sqlNoBookmarksAsc.endsWith(" ASC")); + assertTrue(sqlNoBookmarksDesc.endsWith(" DESC")); + + assertTrue(sqlBookmarksAsc.startsWith("(CASE WHEN bookmark_id > -1 THEN 100 ELSE 0 END) + ")); + assertTrue(sqlBookmarksDesc.startsWith("(CASE WHEN bookmark_id > -1 THEN 100 ELSE 0 END) + ")); + } + + @Test + /** + * Test that calculation string is correct for remote visits + * maxFrecency=1, scaleConst=110, correct sql params for visit count and last date + * and that time is converted to microseconds. + */ + public void testGetRemoteFrecencySQL() throws Exception { + long now = 1; + String sql = BrowserContract.getRemoteFrecencySQL(now); + String ageExpr = "(" + now * 1000 + " - remoteDateLastVisited) / 86400000000"; + + assertEquals( + "remoteVisitCount * MAX(1, 100 * 110 / (" + ageExpr + " * " + ageExpr + " + 110))", + sql + ); + } + + @Test + /** + * Test that calculation string is correct for remote visits + * maxFrecency=2, scaleConst=225, correct sql params for visit count and last date + * and that time is converted to microseconds. + */ + public void testGetLocalFrecencySQL() throws Exception { + long now = 1; + String sql = BrowserContract.getLocalFrecencySQL(now); + String ageExpr = "(" + now * 1000 + " - localDateLastVisited) / 86400000000"; + String visitCountExpr = "(localVisitCount + 2) * (localVisitCount + 2)"; + + assertEquals( + visitCountExpr + " * MAX(2, 100 * 225 / (" + ageExpr + " * " + ageExpr + " + 225))", + sql + ); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHighlightsTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHighlightsTest.java new file mode 100644 index 000000000..f8af41e32 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHighlightsTest.java @@ -0,0 +1,438 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.db; + +import android.content.ContentProviderClient; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; +import android.os.RemoteException; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; +import org.mozilla.gecko.sync.setup.Constants; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import static org.mozilla.gecko.db.BrowserContract.PARAM_PROFILE; + +/** + * Unit tests for the highlights query (Activity Stream). + */ +@RunWith(TestRunner.class) +public class BrowserProviderHighlightsTest extends BrowserProviderHistoryVisitsTestBase { + private ContentProviderClient highlightsClient; + private ContentProviderClient activityStreamBlocklistClient; + private ContentProviderClient bookmarksClient; + + private Uri highlightsTestUri; + private Uri activityStreamBlocklistTestUri; + private Uri bookmarksTestUri; + + private Uri expireHistoryNormalUri; + + @Before + public void setUp() throws Exception { + super.setUp(); + + final Uri highlightsClientUri = BrowserContract.Highlights.CONTENT_URI.buildUpon() + .appendQueryParameter(PARAM_PROFILE, Constants.DEFAULT_PROFILE) + .build(); + + final Uri activityStreamBlocklistClientUri = BrowserContract.ActivityStreamBlocklist.CONTENT_URI.buildUpon() + .appendQueryParameter(PARAM_PROFILE, Constants.DEFAULT_PROFILE) + .build(); + + highlightsClient = contentResolver.acquireContentProviderClient(highlightsClientUri); + activityStreamBlocklistClient = contentResolver.acquireContentProviderClient(activityStreamBlocklistClientUri); + bookmarksClient = contentResolver.acquireContentProviderClient(BrowserContractHelpers.BOOKMARKS_CONTENT_URI); + + highlightsTestUri = testUri(BrowserContract.Highlights.CONTENT_URI); + activityStreamBlocklistTestUri = testUri(BrowserContract.ActivityStreamBlocklist.CONTENT_URI); + bookmarksTestUri = testUri(BrowserContract.Bookmarks.CONTENT_URI); + + expireHistoryNormalUri = testUri(BrowserContract.History.CONTENT_OLD_URI).buildUpon() + .appendQueryParameter( + BrowserContract.PARAM_EXPIRE_PRIORITY, + BrowserContract.ExpirePriority.NORMAL.toString() + ).build(); + } + + @After + public void tearDown() { + highlightsClient.release(); + activityStreamBlocklistClient.release(); + bookmarksClient.release(); + + super.tearDown(); + } + + /** + * Scenario: Empty database, no history, no bookmarks. + * + * Assert that: + * - Empty cursor (not null) is returned. + */ + @Test + public void testEmptyDatabase() throws Exception { + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + + Assert.assertEquals(0, cursor.getCount()); + + cursor.close(); + } + + /** + * Scenario: The database only contains very recent history (now, 5 minutes ago, 20 minutes). + * + * Assert that: + * - No highlight is returned from recent history. + */ + @Test + public void testOnlyRecentHistory() throws Exception { + final long now = System.currentTimeMillis(); + final long fiveMinutesAgo = now - 1000 * 60 * 5; + final long twentyMinutes = now - 1000 * 60 * 20; + + insertHistoryItem(createUniqueUrl(), createGUID(), now, 1, createUniqueTitle()); + insertHistoryItem(createUniqueUrl(), createGUID(), fiveMinutesAgo, 1, createUniqueTitle()); + insertHistoryItem(createUniqueUrl(), createGUID(), twentyMinutes, 1, createUniqueTitle()); + + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + + Assert.assertNotNull(cursor); + + Assert.assertEquals(0, cursor.getCount()); + + cursor.close(); + } + + /** + * Scenario: The database contains recent (but not too fresh) history (1 hour, 5 days). + * + * Assert that: + * - Highlights are returned from history. + */ + @Test + public void testHighlightsArePickedFromHistory() throws Exception { + final String url1 = createUniqueUrl(); + final String url2 = createUniqueUrl(); + final String title1 = createUniqueTitle(); + final String title2 = createUniqueTitle(); + + final long oneHourAgo = System.currentTimeMillis() - 1000 * 60 * 60; + final long fiveDaysAgo = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 5; + + insertHistoryItem(url1, createGUID(), oneHourAgo, 1, title1); + insertHistoryItem(url2, createGUID(), fiveDaysAgo, 1, title2); + + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + + Assert.assertEquals(2, cursor.getCount()); + + assertCursorContainsEntry(cursor, url1, title1); + assertCursorContainsEntry(cursor, url2, title2); + + cursor.close(); + } + + /** + * Scenario: The database contains history that is visited frequently and rarely. + * + * Assert that: + * - Highlights are picked from rarely visited websites. + * - Highlights are not picked from frequently visited websites. + */ + @Test + public void testOftenVisitedPagesAreNotPicked() throws Exception { + final String url1 = createUniqueUrl(); + final String title1 = createUniqueTitle(); + + final long oneHourAgo = System.currentTimeMillis() - 1000 * 60 * 60; + final long fiveDaysAgo = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 5; + + insertHistoryItem(url1, createGUID(), oneHourAgo, 2, title1); + insertHistoryItem(createUniqueUrl(), createGUID(), fiveDaysAgo, 25, createUniqueTitle()); + + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + + // Verify that only the first URL (with one visit) is picked and the second URL with 25 visits is ignored. + + Assert.assertEquals(1, cursor.getCount()); + + cursor.moveToNext(); + assertCursor(cursor, url1, title1); + + cursor.close(); + } + + /** + * Scenario: The database contains history with and without titles. + * + * Assert that: + * - History without titles is not picked for highlights. + */ + @Test + public void testHistoryWithoutTitlesIsNotPicked() throws Exception { + final String url1 = createUniqueUrl(); + final String url2 = createUniqueUrl(); + final String title1 = ""; + final String title2 = createUniqueTitle(); + + final long oneHourAgo = System.currentTimeMillis() - 1000 * 60 * 60; + final long fiveDaysAgo = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 5; + + insertHistoryItem(url1, createGUID(), oneHourAgo, 1, title1); + insertHistoryItem(url2, createGUID(), fiveDaysAgo, 1, title2); + + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + + // Only one bookmark will be picked for highlights + Assert.assertEquals(1, cursor.getCount()); + + cursor.moveToNext(); + assertCursor(cursor, url2, title2); + + cursor.close(); + } + + /** + * Scenario: Database contains two bookmarks (unvisited). + * + * Assert that: + * - One bookmark is picked for highlights. + */ + @Test + public void testPickingBookmarkForHighlights() throws Exception { + final long oneHourAgo = System.currentTimeMillis() - 1000 * 60 * 60; + final long fiveDaysAgo = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 5; + + final String url1 = createUniqueUrl(); + final String url2 = createUniqueUrl(); + final String title1 = createUniqueTitle(); + final String title2 = createUniqueTitle(); + + insertBookmarkItem(url1, title1, oneHourAgo); + insertBookmarkItem(url2, title2, fiveDaysAgo); + + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + + Assert.assertEquals(1, cursor.getCount()); + + cursor.moveToNext(); + assertCursor(cursor, url1, title1); + + cursor.close(); + } + + /** + * Scenario: Database contains an often visited bookmark. + * + * Assert that: + * - Bookmark is not selected for highlights. + */ + @Test + public void testOftenVisitedBookmarksWillNotBePicked() throws Exception { + final String url = createUniqueUrl(); + final long oneHourAgo = System.currentTimeMillis() - 1000 * 60 * 60; + + insertBookmarkItem(url, createUniqueTitle(), oneHourAgo); + insertHistoryItem(url, createGUID(), oneHourAgo, 25, createUniqueTitle()); + + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + + Assert.assertEquals(0, cursor.getCount()); + + cursor.close(); + } + + /** + * Scenario: Database contains URL as bookmark and in history (not visited often). + * + * Assert that: + * - URL is not picked twice (as bookmark and from history) + */ + @Test + public void testSameUrlIsNotPickedFromHistoryAndBookmarks() throws Exception { + final String url = createUniqueUrl(); + + final long oneHourAgo = System.currentTimeMillis() - 1000 * 60 * 60; + + // Insert bookmark that is picked for highlights + insertBookmarkItem(url, createUniqueTitle(), oneHourAgo); + // Insert history for same URL that would be picked for highlights too + insertHistoryItem(url, createGUID(), oneHourAgo, 2, createUniqueTitle()); + + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + + Assert.assertEquals(1, cursor.getCount()); + + cursor.close(); + } + + /** + * Scenario: Database contains only old bookmarks. + * + * Assert that: + * - Old bookmarks are not selected as highlight. + */ + @Test + public void testVeryOldBookmarksAreNotSelected() throws Exception { + final long oneWeekAgo = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7); + final long oneMonthAgo = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(31); + final long oneYearAgo = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(365); + + insertBookmarkItem(createUniqueUrl(), createUniqueTitle(), oneWeekAgo); + insertBookmarkItem(createUniqueUrl(), createUniqueTitle(), oneMonthAgo); + insertBookmarkItem(createUniqueUrl(), createUniqueTitle(), oneYearAgo); + + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + + Assert.assertEquals(0, cursor.getCount()); + + cursor.close(); + } + + @Test + public void testBlocklistItemsAreNotSelected() throws Exception { + final long oneDayAgo = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1); + + final String blockURL = createUniqueUrl(); + + insertBookmarkItem(blockURL, createUniqueTitle(), oneDayAgo); + + Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + Assert.assertEquals(1, cursor.getCount()); + cursor.close(); + + insertBlocklistItem(blockURL); + + cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + Assert.assertEquals(0, cursor.getCount()); + cursor.close(); + } + + @Test + public void testBlocklistItemsExpire() throws Exception { + final long oneDayAgo = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1); + + final String blockURL = createUniqueUrl(); + final String blockTitle = createUniqueTitle(); + + insertBookmarkItem(blockURL, blockTitle, oneDayAgo); + insertBlocklistItem(blockURL); + + { + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + Assert.assertEquals(0, cursor.getCount()); + cursor.close(); + } + + // Add (2000 / 10) items in the loop -> 201 items total + int itemsNeeded = BrowserProvider.DEFAULT_EXPIRY_RETAIN_COUNT / BrowserProvider.ACTIVITYSTREAM_BLOCKLIST_EXPIRY_FACTOR; + for (int i = 0; i < itemsNeeded; i++) { + insertBlocklistItem(createUniqueUrl()); + } + + // We still have zero highlights: the item is still blocked + { + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + Assert.assertEquals(0, cursor.getCount()); + cursor.close(); + } + + // expire the original blocked URL - only most recent 200 items are retained + historyClient.delete(expireHistoryNormalUri, null, null); + + // And the original URL is now in highlights again (note: this shouldn't happen in real life, + // since the URL will no longer be eligible for highlights by the time we expire it) + { + final Cursor cursor = highlightsClient.query(highlightsTestUri, null, null, null, null); + Assert.assertNotNull(cursor); + Assert.assertEquals(1, cursor.getCount()); + + cursor.moveToFirst(); + assertCursor(cursor, blockURL, blockTitle); + cursor.close(); + } + } + + private void insertBookmarkItem(String url, String title, long createdAt) throws RemoteException { + ContentValues values = new ContentValues(); + + values.put(BrowserContract.Bookmarks.URL, url); + values.put(BrowserContract.Bookmarks.TITLE, title); + values.put(BrowserContract.Bookmarks.PARENT, 0); + values.put(BrowserContract.Bookmarks.TYPE, BrowserContract.Bookmarks.TYPE_BOOKMARK); + values.put(BrowserContract.Bookmarks.DATE_CREATED, createdAt); + + bookmarksClient.insert(bookmarksTestUri, values); + } + + private void insertBlocklistItem(String url) throws RemoteException { + final ContentValues values = new ContentValues(); + values.put(BrowserContract.ActivityStreamBlocklist.URL, url); + + activityStreamBlocklistClient.insert(activityStreamBlocklistTestUri, values); + } + + private void assertCursor(Cursor cursor, String url, String title) { + final String actualTitle = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.TITLE)); + Assert.assertEquals(title, actualTitle); + + final String actualUrl = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.URL)); + Assert.assertEquals(url, actualUrl); + } + + private void assertCursorContainsEntry(Cursor cursor, String url, String title) { + cursor.moveToFirst(); + + do { + final String actualTitle = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.TITLE)); + final String actualUrl = cursor.getString(cursor.getColumnIndexOrThrow(BrowserContract.Combined.URL)); + + if (actualTitle.equals(title) && actualUrl.equals(url)) { + return; + } + } while (cursor.moveToNext()); + + Assert.fail("Could not find entry title=" + title + ", url=" + url); + } + + private String createUniqueUrl() { + return new Uri.Builder() + .scheme("https") + .authority(UUID.randomUUID().toString() + ".example.org") + .appendPath(UUID.randomUUID().toString()) + .appendPath(UUID.randomUUID().toString()) + .build() + .toString(); + } + + private String createUniqueTitle() { + return "Title " + UUID.randomUUID().toString(); + } + + private String createGUID() { + return UUID.randomUUID().toString(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryTest.java new file mode 100644 index 000000000..850841432 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryTest.java @@ -0,0 +1,341 @@ +/* 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 org.mozilla.gecko.db; + +import android.content.ContentProviderClient; +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; +import android.os.RemoteException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.robolectric.shadows.ShadowContentResolver; + +import static org.junit.Assert.*; + +/** + * Testing functionality exposed by BrowserProvider ContentProvider (history, bookmarks, etc). + * This is WIP junit4 port of robocop tests at org.mozilla.gecko.tests.testBrowserProvider. + * See Bug 1269492 + */ +@RunWith(TestRunner.class) +public class BrowserProviderHistoryTest extends BrowserProviderHistoryVisitsTestBase { + private ContentProviderClient thumbnailClient; + private Uri thumbnailTestUri; + private Uri expireHistoryNormalUri; + private Uri expireHistoryAggressiveUri; + + private static final long THREE_MONTHS = 1000L * 60L * 60L * 24L * 30L * 3L; + + @Before + @Override + public void setUp() throws Exception { + super.setUp(); + final ShadowContentResolver cr = new ShadowContentResolver(); + thumbnailClient = cr.acquireContentProviderClient(BrowserContract.Thumbnails.CONTENT_URI); + thumbnailTestUri = testUri(BrowserContract.Thumbnails.CONTENT_URI); + expireHistoryNormalUri = testUri(BrowserContract.History.CONTENT_OLD_URI).buildUpon() + .appendQueryParameter( + BrowserContract.PARAM_EXPIRE_PRIORITY, + BrowserContract.ExpirePriority.NORMAL.toString() + ).build(); + expireHistoryAggressiveUri = testUri(BrowserContract.History.CONTENT_OLD_URI).buildUpon() + .appendQueryParameter( + BrowserContract.PARAM_EXPIRE_PRIORITY, + BrowserContract.ExpirePriority.AGGRESSIVE.toString() + ).build(); + } + + @After + @Override + public void tearDown() { + thumbnailClient.release(); + super.tearDown(); + } + + /** + * Test aggressive expiration on new (recent) history items + */ + @Test + public void testHistoryExpirationAggressiveNew() throws Exception { + final int historyItemsCount = 3000; + insertHistory(historyItemsCount, System.currentTimeMillis()); + + historyClient.delete(expireHistoryAggressiveUri, null, null); + + /** + * Aggressive expiration should leave 500 history items + * See {@link BrowserProvider.AGGRESSIVE_EXPIRY_RETAIN_COUNT} + */ + assertRowCount(historyClient, historyTestUri, 500); + + /** + * Aggressive expiration should leave 15 thumbnails + * See {@link BrowserProvider.DEFAULT_EXPIRY_THUMBNAIL_COUNT} + */ + assertRowCount(thumbnailClient, thumbnailTestUri, 15); + } + + /** + * Test normal expiration on new (recent) history items + */ + @Test + public void testHistoryExpirationNormalNew() throws Exception { + final int historyItemsCount = 3000; + insertHistory(historyItemsCount, System.currentTimeMillis()); + + historyClient.delete(expireHistoryNormalUri, null, null); + + // Normal expiration shouldn't expire new items + assertRowCount(historyClient, historyTestUri, 3000); + + /** + * Normal expiration should leave 15 thumbnails + * See {@link BrowserProvider.DEFAULT_EXPIRY_THUMBNAIL_COUNT} + */ + assertRowCount(thumbnailClient, thumbnailTestUri, 15); + } + + /** + * Test aggressive expiration on old history items + */ + @Test + public void testHistoryExpirationAggressiveOld() throws Exception { + final int historyItemsCount = 3000; + insertHistory(historyItemsCount, System.currentTimeMillis() - THREE_MONTHS); + + historyClient.delete(expireHistoryAggressiveUri, null, null); + + /** + * Aggressive expiration should leave 500 history items + * See {@link BrowserProvider.AGGRESSIVE_EXPIRY_RETAIN_COUNT} + */ + assertRowCount(historyClient, historyTestUri, 500); + + /** + * Aggressive expiration should leave 15 thumbnails + * See {@link BrowserProvider.DEFAULT_EXPIRY_THUMBNAIL_COUNT} + */ + assertRowCount(thumbnailClient, thumbnailTestUri, 15); + } + + /** + * Test normal expiration on old history items + */ + @Test + public void testHistoryExpirationNormalOld() throws Exception { + final int historyItemsCount = 3000; + insertHistory(historyItemsCount, System.currentTimeMillis() - THREE_MONTHS); + + historyClient.delete(expireHistoryNormalUri, null, null); + + /** + * Normal expiration of old items should retain at most 2000 items + * See {@link BrowserProvider.DEFAULT_EXPIRY_RETAIN_COUNT} + */ + assertRowCount(historyClient, historyTestUri, 2000); + + /** + * Normal expiration should leave 15 thumbnails + * See {@link BrowserProvider.DEFAULT_EXPIRY_THUMBNAIL_COUNT} + */ + assertRowCount(thumbnailClient, thumbnailTestUri, 15); + } + + /** + * Test that we update aggregates at the appropriate times. Local visit aggregates are only updated + * when updating history record with PARAM_INCREMENT_VISITS=true. Remote aggregate values are updated + * only if set directly. Aggregate values are not set when inserting a new history record via insertHistory. + * Local aggregate values are set when inserting a new history record via update. + * @throws Exception + */ + @Test + public void testHistoryVisitAggregates() throws Exception { + final long baseDate = System.currentTimeMillis(); + final String url = "https://www.mozilla.org"; + final Uri historyIncrementVisitsUri = historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true") + .appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build(); + + // Test default values + insertHistoryItem(url, null, baseDate, null); + assertHistoryAggregates(BrowserContract.History.URL + " = ?", new String[] {url}, + 0, 0, 0, 0, 0); + + // Test setting visit count on new history item creation + final String url2 = "https://www.eff.org"; + insertHistoryItem(url2, null, baseDate, 17); + assertHistoryAggregates(BrowserContract.History.URL + " = ?", new String[] {url2}, + 17, 0, 0, 0, 0); + + // Test setting visit count on new history item creation via .update + final String url3 = "https://www.torproject.org"; + final ContentValues cv = new ContentValues(); + cv.put(BrowserContract.History.URL, url3); + cv.put(BrowserContract.History.VISITS, 13); + cv.put(BrowserContract.History.DATE_LAST_VISITED, baseDate); + historyClient.update(historyIncrementVisitsUri, cv, BrowserContract.History.URL + " = ?", new String[] {url3}); + assertHistoryAggregates(BrowserContract.History.URL + " = ?", new String[] {url3}, + 13, 13, baseDate, 0, 0); + + // Test that updating meta doesn't touch aggregates + cv.clear(); + cv.put(BrowserContract.History.TITLE, "New title"); + historyClient.update(historyTestUri, cv, BrowserContract.History.URL + " = ?", new String[] {url}); + assertHistoryAggregates(BrowserContract.History.URL + " = ?", new String[] {url}, + 0, 0, 0, 0, 0); + + // Test that incrementing visits without specifying visit count updates local aggregate values + final long lastVisited = System.currentTimeMillis(); + cv.clear(); + cv.put(BrowserContract.History.DATE_LAST_VISITED, lastVisited); + historyClient.update(historyIncrementVisitsUri, + cv, BrowserContract.History.URL + " = ?", new String[] {url}); + assertHistoryAggregates(BrowserContract.History.URL + " = ?", new String[] {url}, + 1, 1, lastVisited, 0, 0); + + // Test that incrementing visits by a specified visit count updates local aggregate values + // We don't support bumping visit count by more than 1. This doesn't make sense when we keep + // detailed information about our individual visits. + final long lastVisited2 = System.currentTimeMillis(); + cv.clear(); + cv.put(BrowserContract.History.DATE_LAST_VISITED, lastVisited2); + cv.put(BrowserContract.History.VISITS, 10); + historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(), + cv, BrowserContract.History.URL + " = ?", new String[] {url}); + assertHistoryAggregates(BrowserContract.History.URL + " = ?", new String[] {url}, + 2, 2, lastVisited2, 0, 0); + + // Test that we can directly update aggregate values + // NB: visits is unchanged (2) + final long lastVisited3 = System.currentTimeMillis(); + cv.clear(); + cv.put(BrowserContract.History.LOCAL_DATE_LAST_VISITED, lastVisited3); + cv.put(BrowserContract.History.LOCAL_VISITS, 19); + cv.put(BrowserContract.History.REMOTE_DATE_LAST_VISITED, lastVisited3 - 100); + cv.put(BrowserContract.History.REMOTE_VISITS, 3); + historyClient.update(historyTestUri, cv, BrowserContract.History.URL + " = ?", new String[] {url}); + assertHistoryAggregates(BrowserContract.History.URL + " = ?", new String[] {url}, + 2, 19, lastVisited3, 3, lastVisited3 - 100); + + // Test that we can set remote aggregate count to a specific value + cv.clear(); + cv.put(BrowserContract.History.REMOTE_VISITS, 5); + historyClient.update(historyTestUri, cv, BrowserContract.History.URL + " = ?", new String[] {url}); + assertHistoryAggregates(BrowserContract.History.URL + " = ?", new String[] {url}, + 2, 19, lastVisited3, 5, lastVisited3 - 100); + + // Test that we can increment remote aggregate value by setting a query param in the URI + final Uri historyIncrementRemoteAggregateUri = historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_REMOTE_AGGREGATES, "true") + .build(); + cv.clear(); + cv.put(BrowserContract.History.REMOTE_DATE_LAST_VISITED, lastVisited3); + cv.put(BrowserContract.History.REMOTE_VISITS, 3); + historyClient.update(historyIncrementRemoteAggregateUri, cv, BrowserContract.History.URL + " = ?", new String[] {url}); + // NB: remoteVisits=8. Previous value was 5, and we're incrementing by 3. + assertHistoryAggregates(BrowserContract.History.URL + " = ?", new String[] {url}, + 2, 19, lastVisited3, 8, lastVisited3); + + // Test that we throw when trying to increment REMOTE_VISITS without passing in "increment by" value + cv.clear(); + try { + historyClient.update(historyIncrementRemoteAggregateUri, cv, BrowserContract.History.URL + " = ?", new String[]{url}); + assertTrue("Expected to throw IllegalArgumentException", false); + } catch (IllegalArgumentException e) { + assertTrue(true); + + // NB: same values as above, to ensure throwing update didn't actually change anything. + assertHistoryAggregates(BrowserContract.History.URL + " = ?", new String[] {url}, + 2, 19, lastVisited3, 8, lastVisited3); + } + } + + private void assertHistoryAggregates(String selection, String[] selectionArg, int visits, int localVisits, long localLastVisited, int remoteVisits, long remoteLastVisited) throws Exception { + final Cursor c = historyClient.query(historyTestUri, new String[] { + BrowserContract.History.VISITS, + BrowserContract.History.LOCAL_VISITS, + BrowserContract.History.REMOTE_VISITS, + BrowserContract.History.LOCAL_DATE_LAST_VISITED, + BrowserContract.History.REMOTE_DATE_LAST_VISITED + }, selection, selectionArg, null); + + assertNotNull(c); + try { + assertTrue(c.moveToFirst()); + + final int visitsCol = c.getColumnIndexOrThrow(BrowserContract.History.VISITS); + final int localVisitsCol = c.getColumnIndexOrThrow(BrowserContract.History.LOCAL_VISITS); + final int remoteVisitsCol = c.getColumnIndexOrThrow(BrowserContract.History.REMOTE_VISITS); + final int localDateLastVisitedCol = c.getColumnIndexOrThrow(BrowserContract.History.LOCAL_DATE_LAST_VISITED); + final int remoteDateLastVisitedCol = c.getColumnIndexOrThrow(BrowserContract.History.REMOTE_DATE_LAST_VISITED); + + assertEquals(visits, c.getInt(visitsCol)); + + assertEquals(localVisits, c.getInt(localVisitsCol)); + assertEquals(localLastVisited, c.getLong(localDateLastVisitedCol)); + + assertEquals(remoteVisits, c.getInt(remoteVisitsCol)); + assertEquals(remoteLastVisited, c.getLong(remoteDateLastVisitedCol)); + } finally { + c.close(); + } + } + + /** + * Insert count history records with thumbnails, and for a third of records insert a visit. + * Inserting visits only for some of the history records is in order to ensure we're correctly JOIN-ing + * History and Visits tables in the Combined view. + * Will ensure that date_created and date_modified for new records are the same as last visited date. + * + * @param count number of history records to insert + * @param baseTime timestamp which will be used as a basis for last visited date + * @throws RemoteException + */ + private void insertHistory(int count, long baseTime) throws RemoteException { + Uri incrementUri = historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(); + + for (int i = 0; i < count; i++) { + final String url = "https://www.mozilla" + i + ".org"; + insertHistoryItem(url, "testGUID" + i, baseTime - i, null); + if (i % 3 == 0) { + assertEquals(1, historyClient.update(incrementUri, new ContentValues(), BrowserContract.History.URL + " = ?", new String[]{url})); + } + + // inserting a new entry sets the date created and modified automatically, so let's reset them + ContentValues cv = new ContentValues(); + cv.put(BrowserContract.History.DATE_CREATED, baseTime - i); + cv.put(BrowserContract.History.DATE_MODIFIED, baseTime - i); + assertEquals(1, historyClient.update(historyTestUri, cv, BrowserContract.History.URL + " = ?", + new String[] { "https://www.mozilla" + i + ".org" })); + } + + // insert thumbnails for history items + ContentValues[] thumbs = new ContentValues[count]; + for (int i = 0; i < count; i++) { + thumbs[i] = new ContentValues(); + thumbs[i].put(BrowserContract.Thumbnails.DATA, i); + thumbs[i].put(BrowserContract.Thumbnails.URL, "https://www.mozilla" + i + ".org"); + } + assertEquals(count, thumbnailClient.bulkInsert(thumbnailTestUri, thumbs)); + } + + private void assertRowCount(final ContentProviderClient client, final Uri uri, final int count) throws RemoteException { + final Cursor c = client.query(uri, null, null, null, null); + assertNotNull(c); + try { + assertEquals(count, c.getCount()); + } finally { + c.close(); + } + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryVisitsTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryVisitsTest.java new file mode 100644 index 000000000..71c21166d --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryVisitsTest.java @@ -0,0 +1,338 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.db; + +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import org.mozilla.gecko.db.BrowserContract.History; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +/** + * Testing insertion/deletion of visits as by-product of updating history records through BrowserProvider + */ +public class BrowserProviderHistoryVisitsTest extends BrowserProviderHistoryVisitsTestBase { + @Test + /** + * Testing updating history records without affecting visits + */ + public void testUpdateNoVisit() throws Exception { + insertHistoryItem("https://www.mozilla.org", "testGUID"); + + Cursor cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(0, cursor.getCount()); + cursor.close(); + + ContentValues historyUpdate = new ContentValues(); + historyUpdate.put(History.TITLE, "Mozilla!"); + assertEquals(1, + historyClient.update( + historyTestUri, historyUpdate, History.URL + " = ?", new String[] {"https://www.mozilla.org"} + ) + ); + + cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(0, cursor.getCount()); + cursor.close(); + + ContentValues historyToInsert = new ContentValues(); + historyToInsert.put(History.URL, "https://www.eff.org"); + assertEquals(1, + historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build(), + historyToInsert, null, null + ) + ); + + cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(0, cursor.getCount()); + cursor.close(); + } + + @Test + /** + * Testing INCREMENT_VISITS flag for multiple history records at once + */ + public void testUpdateMultipleHistoryIncrementVisit() throws Exception { + insertHistoryItem("https://www.mozilla.org", "testGUID"); + insertHistoryItem("https://www.mozilla.org", "testGUID2"); + + // test that visits get inserted when updating existing history records + assertEquals(2, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(), + new ContentValues(), History.URL + " = ?", new String[] {"https://www.mozilla.org"} + )); + + Cursor cursor = visitsClient.query( + visitsTestUri, new String[] {BrowserContract.Visits.HISTORY_GUID}, null, null, null); + assertNotNull(cursor); + assertEquals(2, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + + String guid1 = cursor.getString(cursor.getColumnIndex(BrowserContract.Visits.HISTORY_GUID)); + cursor.moveToNext(); + String guid2 = cursor.getString(cursor.getColumnIndex(BrowserContract.Visits.HISTORY_GUID)); + cursor.close(); + + assertNotEquals(guid1, guid2); + + assertTrue(guid1.equals("testGUID") || guid1.equals("testGUID2")); + } + + @Test + /** + * Testing INCREMENT_VISITS flag and its interplay with INSERT_IF_NEEDED + */ + public void testUpdateHistoryIncrementVisit() throws Exception { + insertHistoryItem("https://www.mozilla.org", "testGUID"); + + // test that visit gets inserted when updating an existing histor record + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(), + new ContentValues(), History.URL + " = ?", new String[] {"https://www.mozilla.org"} + )); + + Cursor cursor = visitsClient.query( + visitsTestUri, new String[] {BrowserContract.Visits.HISTORY_GUID}, null, null, null); + assertNotNull(cursor); + assertEquals(1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + assertEquals( + "testGUID", + cursor.getString(cursor.getColumnIndex(BrowserContract.Visits.HISTORY_GUID)) + ); + cursor.close(); + + // test that visit gets inserted when updatingOrInserting a new history record + ContentValues historyItem = new ContentValues(); + historyItem.put(History.URL, "https://www.eff.org"); + + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true") + .appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build(), + historyItem, null, null + )); + + cursor = historyClient.query( + historyTestUri, + new String[] {History.GUID}, History.URL + " = ?", new String[] {"https://www.eff.org"}, null + ); + assertNotNull(cursor); + assertEquals(1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + String insertedGUID = cursor.getString(cursor.getColumnIndex(History.GUID)); + cursor.close(); + + cursor = visitsClient.query( + visitsTestUri, new String[] {BrowserContract.Visits.HISTORY_GUID}, null, null, null); + assertNotNull(cursor); + assertEquals(2, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + assertEquals(insertedGUID, + cursor.getString(cursor.getColumnIndex(BrowserContract.Visits.HISTORY_GUID)) + ); + cursor.close(); + } + + @Test + /** + * Test that for locally generated visits, we store their timestamps in microseconds, and not in + * milliseconds like history does. + */ + public void testTimestampConversionOnInsertion() throws Exception { + insertHistoryItem("https://www.mozilla.org", "testGUID"); + + Long lastVisited = System.currentTimeMillis(); + ContentValues updatedVisitedTime = new ContentValues(); + updatedVisitedTime.put(History.DATE_LAST_VISITED, lastVisited); + + // test with last visited date passed in + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(), + updatedVisitedTime, History.URL + " = ?", new String[] {"https://www.mozilla.org"} + )); + + Cursor cursor = visitsClient.query(visitsTestUri, new String[] {BrowserContract.Visits.DATE_VISITED}, null, null, null); + assertNotNull(cursor); + assertEquals(1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + + assertEquals(lastVisited * 1000, cursor.getLong(cursor.getColumnIndex(BrowserContract.Visits.DATE_VISITED))); + cursor.close(); + + // test without last visited date + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(), + new ContentValues(), History.URL + " = ?", new String[] {"https://www.mozilla.org"} + )); + + cursor = visitsClient.query(visitsTestUri, new String[] {BrowserContract.Visits.DATE_VISITED}, null, null, null); + assertNotNull(cursor); + assertEquals(2, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + + // CP should generate time off of current time upon insertion and convert to microseconds. + // This also tests correct ordering (DESC on date). + assertTrue(lastVisited * 1000 < cursor.getLong(cursor.getColumnIndex(BrowserContract.Visits.DATE_VISITED))); + cursor.close(); + } + + @Test + /** + * This should perform `DELETE FROM visits WHERE history_guid in IN (?, ?, ?, ..., ?)` sort of statement + * SQLite has a variable count limit (999 by default), so we're testing here that our deletion + * code does the right thing and chunks deletes to account for this limitation. + */ + public void testDeletingLotsOfHistory() throws Exception { + Uri incrementUri = historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(); + + // insert bunch of history records, and for each insert a visit + for (int i = 0; i < 2100; i++) { + final String url = "https://www.mozilla" + i + ".org"; + insertHistoryItem(url, "testGUID" + i); + assertEquals(1, historyClient.update(incrementUri, new ContentValues(), History.URL + " = ?", new String[] {url})); + } + + // sanity check + Cursor cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(2100, cursor.getCount()); + cursor.close(); + + // delete all of the history items - this will trigger chunked deletion of visits as well + assertEquals(2100, + historyClient.delete(historyTestUri, null, null) + ); + + // check that all visits where deleted + cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(0, cursor.getCount()); + cursor.close(); + } + + @Test + /** + * Test visit deletion as by-product of history deletion - both explicit (from outside of Sync), + * and implicit (cascaded, from Sync). + */ + public void testDeletingHistory() throws Exception { + insertHistoryItem("https://www.mozilla.org", "testGUID"); + insertHistoryItem("https://www.eff.org", "testGUID2"); + + // insert some visits + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(), + new ContentValues(), History.URL + " = ?", new String[] {"https://www.mozilla.org"} + )); + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(), + new ContentValues(), History.URL + " = ?", new String[] {"https://www.mozilla.org"} + )); + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(), + new ContentValues(), History.URL + " = ?", new String[] {"https://www.eff.org"} + )); + + Cursor cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(3, cursor.getCount()); + cursor.close(); + + // test that corresponding visit records are deleted if Sync isn't involved + assertEquals(1, + historyClient.delete(historyTestUri, History.URL + " = ?", new String[] {"https://www.mozilla.org"}) + ); + + cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(1, cursor.getCount()); + cursor.close(); + + // test that corresponding visit records are deleted if Sync is involved + // insert some more visits + ContentValues moz = new ContentValues(); + moz.put(History.URL, "https://www.mozilla.org"); + moz.put(History.GUID, "testGUID3"); + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true") + .appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build(), + moz, History.URL + " = ?", new String[] {"https://www.mozilla.org"} + )); + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true") + .appendQueryParameter(BrowserContract.PARAM_INSERT_IF_NEEDED, "true").build(), + new ContentValues(), History.URL + " = ?", new String[] {"https://www.eff.org"} + )); + + assertEquals(1, + historyClient.delete( + historyTestUri.buildUpon().appendQueryParameter(BrowserContract.PARAM_IS_SYNC, "true").build(), + History.URL + " = ?", new String[] {"https://www.eff.org"}) + ); + + cursor = visitsClient.query(visitsTestUri, new String[] {BrowserContract.Visits.HISTORY_GUID}, null, null, null); + assertNotNull(cursor); + assertEquals(1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + assertEquals("testGUID3", cursor.getString(cursor.getColumnIndex(BrowserContract.Visits.HISTORY_GUID))); + cursor.close(); + } + + @Test + /** + * Test that changes to History GUID are cascaded to individual visits. + * See UPDATE CASCADED on Visit's HISTORY_GUID foreign key. + */ + public void testHistoryGUIDUpdate() throws Exception { + insertHistoryItem("https://www.mozilla.org", "testGUID"); + insertHistoryItem("https://www.eff.org", "testGUID2"); + + // insert some visits + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(), + new ContentValues(), History.URL + " = ?", new String[] {"https://www.mozilla.org"} + )); + assertEquals(1, historyClient.update( + historyTestUri.buildUpon() + .appendQueryParameter(BrowserContract.PARAM_INCREMENT_VISITS, "true").build(), + new ContentValues(), History.URL + " = ?", new String[] {"https://www.mozilla.org"} + )); + + // change testGUID -> testGUIDNew + ContentValues newGuid = new ContentValues(); + newGuid.put(History.GUID, "testGUIDNew"); + assertEquals(1, historyClient.update( + historyTestUri, newGuid, History.URL + " = ?", new String[] {"https://www.mozilla.org"} + )); + + Cursor cursor = visitsClient.query(visitsTestUri, null, BrowserContract.Visits.HISTORY_GUID + " = ?", new String[] {"testGUIDNew"}, null); + assertNotNull(cursor); + assertEquals(2, cursor.getCount()); + cursor.close(); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryVisitsTestBase.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryVisitsTestBase.java new file mode 100644 index 000000000..b8ee0bb36 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderHistoryVisitsTestBase.java @@ -0,0 +1,77 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.db; + +import android.content.ContentProviderClient; +import android.content.ContentValues; +import android.net.Uri; +import android.os.RemoteException; + +import org.junit.After; +import org.junit.Before; +import org.mozilla.gecko.background.db.DelegatingTestContentProvider; +import org.mozilla.gecko.sync.repositories.android.BrowserContractHelpers; +import org.robolectric.shadows.ShadowContentResolver; + +import java.util.UUID; + +public class BrowserProviderHistoryVisitsTestBase { + /* package-private */ ShadowContentResolver contentResolver; + /* package-private */ ContentProviderClient historyClient; + /* package-private */ ContentProviderClient visitsClient; + /* package-private */ Uri historyTestUri; + /* package-private */ Uri visitsTestUri; + + private BrowserProvider provider; + + @Before + public void setUp() throws Exception { + provider = new BrowserProvider(); + provider.onCreate(); + ShadowContentResolver.registerProvider(BrowserContract.AUTHORITY, new DelegatingTestContentProvider(provider)); + + contentResolver = new ShadowContentResolver(); + historyClient = contentResolver.acquireContentProviderClient(BrowserContractHelpers.HISTORY_CONTENT_URI); + visitsClient = contentResolver.acquireContentProviderClient(BrowserContractHelpers.VISITS_CONTENT_URI); + + historyTestUri = testUri(BrowserContract.History.CONTENT_URI); + visitsTestUri = testUri(BrowserContract.Visits.CONTENT_URI); + } + + @After + public void tearDown() { + historyClient.release(); + visitsClient.release(); + provider.shutdown(); + } + + /* package-private */ Uri testUri(Uri baseUri) { + return baseUri.buildUpon().appendQueryParameter(BrowserContract.PARAM_IS_TEST, "1").build(); + } + + /* package-private */ Uri insertHistoryItem(String url, String guid) throws RemoteException { + return insertHistoryItem(url, guid, System.currentTimeMillis(), null, null); + } + + /* package-private */ Uri insertHistoryItem(String url, String guid, Long lastVisited, Integer visitCount) throws RemoteException { + return insertHistoryItem(url, guid, lastVisited, visitCount, null); + } + + /* package-private */ Uri insertHistoryItem(String url, String guid, Long lastVisited, Integer visitCount, String title) throws RemoteException { + ContentValues historyItem = new ContentValues(); + historyItem.put(BrowserContract.History.URL, url); + if (guid != null) { + historyItem.put(BrowserContract.History.GUID, guid); + } + if (visitCount != null) { + historyItem.put(BrowserContract.History.VISITS, visitCount); + } + historyItem.put(BrowserContract.History.DATE_LAST_VISITED, lastVisited); + if (title != null) { + historyItem.put(BrowserContract.History.TITLE, title); + } + + return historyClient.insert(historyTestUri, historyItem); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderVisitsTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderVisitsTest.java new file mode 100644 index 000000000..928657e82 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/db/BrowserProviderVisitsTest.java @@ -0,0 +1,301 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.db; + +import android.content.ContentValues; +import android.database.Cursor; +import android.net.Uri; +import android.os.RemoteException; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.db.BrowserContract.Visits; + +@RunWith(TestRunner.class) +/** + * Testing direct interactions with visits through BrowserProvider + */ +public class BrowserProviderVisitsTest extends BrowserProviderHistoryVisitsTestBase { + @Test + /** + * Test that default visit parameters are set on insert. + */ + public void testDefaultVisit() throws RemoteException { + String url = "https://www.mozilla.org"; + String guid = "testGuid"; + + assertNotNull(insertHistoryItem(url, guid)); + + ContentValues visitItem = new ContentValues(); + Long visitedDate = System.currentTimeMillis(); + visitItem.put(Visits.HISTORY_GUID, guid); + visitItem.put(Visits.DATE_VISITED, visitedDate); + Uri insertedVisitUri = visitsClient.insert(visitsTestUri, visitItem); + assertNotNull(insertedVisitUri); + + Cursor cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + try { + assertTrue(cursor.moveToFirst()); + String insertedGuid = cursor.getString(cursor.getColumnIndex(Visits.HISTORY_GUID)); + assertEquals(guid, insertedGuid); + + Long insertedDate = cursor.getLong(cursor.getColumnIndex(Visits.DATE_VISITED)); + assertEquals(visitedDate, insertedDate); + + Integer insertedType = cursor.getInt(cursor.getColumnIndex(Visits.VISIT_TYPE)); + assertEquals(insertedType, Integer.valueOf(1)); + + Integer insertedIsLocal = cursor.getInt(cursor.getColumnIndex(Visits.IS_LOCAL)); + assertEquals(insertedIsLocal, Integer.valueOf(1)); + } finally { + cursor.close(); + } + } + + @Test + /** + * Test that we can't insert visit for non-existing GUID. + */ + public void testMissingHistoryGuid() throws RemoteException { + ContentValues visitItem = new ContentValues(); + visitItem.put(Visits.HISTORY_GUID, "blah"); + visitItem.put(Visits.DATE_VISITED, System.currentTimeMillis()); + assertNull(visitsClient.insert(visitsTestUri, visitItem)); + } + + @Test + /** + * Test that visit insert uses non-conflict insert. + */ + public void testNonConflictInsert() throws RemoteException { + String url = "https://www.mozilla.org"; + String guid = "testGuid"; + + assertNotNull(insertHistoryItem(url, guid)); + + ContentValues visitItem = new ContentValues(); + Long visitedDate = System.currentTimeMillis(); + visitItem.put(Visits.HISTORY_GUID, guid); + visitItem.put(Visits.DATE_VISITED, visitedDate); + Uri insertedVisitUri = visitsClient.insert(visitsTestUri, visitItem); + assertNotNull(insertedVisitUri); + + Uri insertedVisitUri2 = visitsClient.insert(visitsTestUri, visitItem); + assertEquals(insertedVisitUri, insertedVisitUri2); + } + + @Test + /** + * Test that non-default visit parameters won't get overridden. + */ + public void testNonDefaultInsert() throws RemoteException { + assertNotNull(insertHistoryItem("https://www.mozilla.org", "testGuid")); + + Integer typeToInsert = 5; + Integer isLocalToInsert = 0; + + ContentValues visitItem = new ContentValues(); + visitItem.put(Visits.HISTORY_GUID, "testGuid"); + visitItem.put(Visits.DATE_VISITED, System.currentTimeMillis()); + visitItem.put(Visits.VISIT_TYPE, typeToInsert); + visitItem.put(Visits.IS_LOCAL, isLocalToInsert); + + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + Cursor cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + try { + assertTrue(cursor.moveToFirst()); + + Integer insertedVisitType = cursor.getInt(cursor.getColumnIndex(Visits.VISIT_TYPE)); + assertEquals(typeToInsert, insertedVisitType); + + Integer insertedIsLocal = cursor.getInt(cursor.getColumnIndex(Visits.IS_LOCAL)); + assertEquals(isLocalToInsert, insertedIsLocal); + } finally { + cursor.close(); + } + } + + @Test + /** + * Test that default sorting order (DATE_VISITED DESC) is set if we don't specify any sorting params + */ + public void testDefaultSortingOrder() throws RemoteException { + assertNotNull(insertHistoryItem("https://www.mozilla.org", "testGuid")); + + Long time1 = System.currentTimeMillis(); + Long time2 = time1 + 100; + Long time3 = time1 + 200; + + ContentValues visitItem = new ContentValues(); + visitItem.put(Visits.DATE_VISITED, time1); + visitItem.put(Visits.HISTORY_GUID, "testGuid"); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + visitItem.put(Visits.DATE_VISITED, time3); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + visitItem.put(Visits.DATE_VISITED, time2); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + Cursor cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + try { + assertEquals(3, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + + Long timeInserted = cursor.getLong(cursor.getColumnIndex(Visits.DATE_VISITED)); + assertEquals(time3, timeInserted); + + cursor.moveToNext(); + + timeInserted = cursor.getLong(cursor.getColumnIndex(Visits.DATE_VISITED)); + assertEquals(time2, timeInserted); + + cursor.moveToNext(); + + timeInserted = cursor.getLong(cursor.getColumnIndex(Visits.DATE_VISITED)); + assertEquals(time1, timeInserted); + } finally { + cursor.close(); + } + } + + @Test + /** + * Test that if we pass sorting params, they're not overridden + */ + public void testNonDefaultSortingOrder() throws RemoteException { + assertNotNull(insertHistoryItem("https://www.mozilla.org", "testGuid")); + + Long time1 = System.currentTimeMillis(); + Long time2 = time1 + 100; + Long time3 = time1 + 200; + + ContentValues visitItem = new ContentValues(); + visitItem.put(Visits.DATE_VISITED, time1); + visitItem.put(Visits.HISTORY_GUID, "testGuid"); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + visitItem.put(Visits.DATE_VISITED, time3); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + visitItem.put(Visits.DATE_VISITED, time2); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + Cursor cursor = visitsClient.query(visitsTestUri, null, null, null, Visits.DATE_VISITED + " ASC"); + assertNotNull(cursor); + assertEquals(3, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + + Long timeInserted = cursor.getLong(cursor.getColumnIndex(Visits.DATE_VISITED)); + assertEquals(time1, timeInserted); + + cursor.moveToNext(); + + timeInserted = cursor.getLong(cursor.getColumnIndex(Visits.DATE_VISITED)); + assertEquals(time2, timeInserted); + + cursor.moveToNext(); + + timeInserted = cursor.getLong(cursor.getColumnIndex(Visits.DATE_VISITED)); + assertEquals(time3, timeInserted); + + cursor.close(); + } + + @Test + /** + * Tests deletion of all visits, and by some selection (GUID, IS_LOCAL) + */ + public void testVisitDeletion() throws RemoteException { + assertNotNull(insertHistoryItem("https://www.mozilla.org", "testGuid")); + assertNotNull(insertHistoryItem("https://www.eff.org", "testGuid2")); + + Long time1 = System.currentTimeMillis(); + + ContentValues visitItem = new ContentValues(); + visitItem.put(Visits.DATE_VISITED, time1); + visitItem.put(Visits.HISTORY_GUID, "testGuid"); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + visitItem = new ContentValues(); + visitItem.put(Visits.DATE_VISITED, time1 + 100); + visitItem.put(Visits.HISTORY_GUID, "testGuid"); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + ContentValues visitItem2 = new ContentValues(); + visitItem2.put(Visits.DATE_VISITED, time1); + visitItem2.put(Visits.HISTORY_GUID, "testGuid2"); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem2)); + + Cursor cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(3, cursor.getCount()); + cursor.close(); + + assertEquals(3, visitsClient.delete(visitsTestUri, null, null)); + + cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(0, cursor.getCount()); + cursor.close(); + + // test selective deletion - by IS_LOCAL + visitItem = new ContentValues(); + visitItem.put(Visits.DATE_VISITED, time1); + visitItem.put(Visits.HISTORY_GUID, "testGuid"); + visitItem.put(Visits.IS_LOCAL, 0); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + visitItem = new ContentValues(); + visitItem.put(Visits.DATE_VISITED, time1 + 100); + visitItem.put(Visits.HISTORY_GUID, "testGuid"); + visitItem.put(Visits.IS_LOCAL, 1); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem)); + + visitItem2 = new ContentValues(); + visitItem2.put(Visits.DATE_VISITED, time1); + visitItem2.put(Visits.HISTORY_GUID, "testGuid2"); + visitItem2.put(Visits.IS_LOCAL, 0); + assertNotNull(visitsClient.insert(visitsTestUri, visitItem2)); + + cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(3, cursor.getCount()); + cursor.close(); + + assertEquals(2, + visitsClient.delete(visitsTestUri, Visits.IS_LOCAL + " = ?", new String[]{"0"})); + cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + assertEquals(time1 + 100, cursor.getLong(cursor.getColumnIndex(Visits.DATE_VISITED))); + assertEquals("testGuid", cursor.getString(cursor.getColumnIndex(Visits.HISTORY_GUID))); + assertEquals(1, cursor.getInt(cursor.getColumnIndex(Visits.IS_LOCAL))); + cursor.close(); + + // test selective deletion - by HISTORY_GUID + assertNotNull(visitsClient.insert(visitsTestUri, visitItem2)); + cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(2, cursor.getCount()); + cursor.close(); + + assertEquals(1, + visitsClient.delete(visitsTestUri, Visits.HISTORY_GUID + " = ?", new String[]{"testGuid"})); + cursor = visitsClient.query(visitsTestUri, null, null, null, null); + assertNotNull(cursor); + assertEquals(1, cursor.getCount()); + assertTrue(cursor.moveToFirst()); + assertEquals("testGuid2", cursor.getString(cursor.getColumnIndex(Visits.HISTORY_GUID))); + cursor.close(); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/distribution/TestReferrerDescriptor.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/distribution/TestReferrerDescriptor.java new file mode 100644 index 000000000..9e553cf44 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/distribution/TestReferrerDescriptor.java @@ -0,0 +1,33 @@ +/* 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 org.mozilla.gecko.distribution; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +@RunWith(TestRunner.class) +public class TestReferrerDescriptor { + @Test + public void testReferrerDescriptor() { + String referrerString1 = "utm_source%3Dsource%26utm_content%3Dcontent%26utm_campaign%3Dcampaign%26utm_medium%3Dmedium%26utm_term%3Dterm"; + String referrerString2 = "utm_source=source&utm_content=content&utm_campaign=campaign&utm_medium=medium&utm_term=term"; + ReferrerDescriptor referrer1 = new ReferrerDescriptor(referrerString1); + Assert.assertNotNull(referrer1); + Assert.assertEquals(referrer1.source, "source"); + Assert.assertEquals(referrer1.content, "content"); + Assert.assertEquals(referrer1.campaign, "campaign"); + Assert.assertEquals(referrer1.medium, "medium"); + Assert.assertEquals(referrer1.term, "term"); + ReferrerDescriptor referrer2 = new ReferrerDescriptor(referrerString2); + Assert.assertNotNull(referrer2); + Assert.assertEquals(referrer2.source, "source"); + Assert.assertEquals(referrer2.content, "content"); + Assert.assertEquals(referrer2.campaign, "campaign"); + Assert.assertEquals(referrer2.medium, "medium"); + Assert.assertEquals(referrer2.term, "term"); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestDownloadAction.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestDownloadAction.java new file mode 100644 index 000000000..2252c90c8 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestDownloadAction.java @@ -0,0 +1,607 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.dlc; + +import android.content.Context; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.dlc.catalog.DownloadContent; +import org.mozilla.gecko.dlc.catalog.DownloadContentBuilder; +import org.mozilla.gecko.dlc.catalog.DownloadContentCatalog; +import org.robolectric.RuntimeEnvironment; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.util.Arrays; +import java.util.Collections; + +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.*; + +/** + * DownloadAction: Download content that has been scheduled during "study" or "verify". + */ +@RunWith(TestRunner.class) +public class TestDownloadAction { + private static final String TEST_URL = "http://example.org"; + + private static final int STATUS_OK = 200; + private static final int STATUS_PARTIAL_CONTENT = 206; + + /** + * Scenario: The current network is metered. + * + * Verify that: + * * No download is performed on a metered network + */ + @Test + public void testNothingIsDoneOnMeteredNetwork() throws Exception { + DownloadAction action = spy(new DownloadAction(null)); + doReturn(true).when(action).isActiveNetworkMetered(RuntimeEnvironment.application); + + action.perform(RuntimeEnvironment.application, null); + + verify(action, never()).buildHttpURLConnection(anyString()); + verify(action, never()).download(anyString(), any(File.class)); + } + + /** + * Scenario: No (connected) network is available. + * + * Verify that: + * * No download is performed + */ + @Test + public void testNothingIsDoneIfNoNetworkIsAvailable() throws Exception { + DownloadAction action = spy(new DownloadAction(null)); + doReturn(false).when(action).isConnectedToNetwork(RuntimeEnvironment.application); + + action.perform(RuntimeEnvironment.application, null); + + verify(action, never()).isActiveNetworkMetered(any(Context.class)); + verify(action, never()).buildHttpURLConnection(anyString()); + verify(action, never()).download(anyString(), any(File.class)); + } + + /** + * Scenario: Content is scheduled for download but already exists locally (with correct checksum). + * + * Verify that: + * * No download is performed for existing file + * * Content is marked as downloaded in the catalog + */ + @Test + public void testExistingAndVerifiedFilesAreNotDownloadedAgain() throws Exception { + DownloadContent content = new DownloadContentBuilder().build(); + + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + doReturn(Collections.singletonList(content)).when(catalog).getScheduledDownloads(); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application); + + File file = mock(File.class); + doReturn(true).when(file).exists(); + doReturn(file).when(action).createTemporaryFile(RuntimeEnvironment.application, content); + doReturn(file).when(action).getDestinationFile(RuntimeEnvironment.application, content); + doReturn(true).when(action).verify(eq(file), anyString()); + + action.perform(RuntimeEnvironment.application, catalog); + + verify(action, never()).download(anyString(), any(File.class)); + verify(catalog).markAsDownloaded(content); + } + + /** + * Scenario: Server returns a server error (HTTP 500). + * + * Verify that: + * * Situation is treated as recoverable (RecoverableDownloadContentException) + */ + @Test(expected=BaseAction.RecoverableDownloadContentException.class) + public void testServerErrorsAreRecoverable() throws Exception { + HttpURLConnection connection = mockHttpURLConnection(500, ""); + + File temporaryFile = mock(File.class); + doReturn(false).when(temporaryFile).exists(); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(connection).when(action).buildHttpURLConnection(anyString()); + action.download(TEST_URL, temporaryFile); + + verify(connection).getInputStream(); + } + + /** + * Scenario: Server returns a client error (HTTP 404). + * + * Verify that: + * * Situation is treated as unrecoverable (UnrecoverableDownloadContentException) + */ + @Test(expected=BaseAction.UnrecoverableDownloadContentException.class) + public void testClientErrorsAreUnrecoverable() throws Exception { + HttpURLConnection connection = mockHttpURLConnection(404, ""); + + File temporaryFile = mock(File.class); + doReturn(false).when(temporaryFile).exists(); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(connection).when(action).buildHttpURLConnection(anyString()); + action.download(TEST_URL, temporaryFile); + + verify(connection).getInputStream(); + } + + /** + * Scenario: A successful download has been performed. + * + * Verify that: + * * The content will be extracted to the destination + * * The content is marked as downloaded in the catalog + */ + @Test + public void testSuccessfulDownloadsAreMarkedAsDownloaded() throws Exception { + DownloadContent content = new DownloadContentBuilder() + .setKind(DownloadContent.KIND_FONT) + .setType(DownloadContent.TYPE_ASSET_ARCHIVE) + .build(); + + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + doReturn(Collections.singletonList(content)).when(catalog).getScheduledDownloads(); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application); + + File file = mockNotExistingFile(); + doReturn(file).when(action).createTemporaryFile(RuntimeEnvironment.application, content); + doReturn(file).when(action).getDestinationFile(RuntimeEnvironment.application, content); + + doReturn(false).when(action).verify(eq(file), anyString()); + doNothing().when(action).download(anyString(), eq(file)); + doReturn(true).when(action).verify(eq(file), anyString()); + doNothing().when(action).extract(eq(file), eq(file), anyString()); + + action.perform(RuntimeEnvironment.application, catalog); + + verify(action).download(anyString(), eq(file)); + verify(action).extract(eq(file), eq(file), anyString()); + verify(catalog).markAsDownloaded(content); + } + + /** + * Scenario: Pretend a partially downloaded file already exists. + * + * Verify that: + * * Range header is set in request + * * Content will be appended to existing file + * * Content will be marked as downloaded in catalog + */ + @Test + public void testResumingDownloadFromExistingFile() throws Exception { + DownloadContent content = new DownloadContentBuilder() + .setKind(DownloadContent.KIND_FONT) + .setType(DownloadContent.TYPE_ASSET_ARCHIVE) + .setSize(4223) + .build(); + + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + doReturn(Collections.singletonList(content)).when(catalog).getScheduledDownloads(); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application); + + File temporaryFile = mockFileWithSize(1337L); + doReturn(temporaryFile).when(action).createTemporaryFile(RuntimeEnvironment.application, content); + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + doReturn(outputStream).when(action).openFile(eq(temporaryFile), anyBoolean()); + + HttpURLConnection connection = mockHttpURLConnection(STATUS_PARTIAL_CONTENT, "HelloWorld"); + doReturn(connection).when(action).buildHttpURLConnection(anyString()); + + File destinationFile = mockNotExistingFile(); + doReturn(destinationFile).when(action).getDestinationFile(RuntimeEnvironment.application, content); + + doReturn(true).when(action).verify(eq(temporaryFile), anyString()); + doNothing().when(action).extract(eq(temporaryFile), eq(destinationFile), anyString()); + + action.perform(RuntimeEnvironment.application, catalog); + + verify(connection).getInputStream(); + verify(connection).setRequestProperty("Range", "bytes=1337-"); + + Assert.assertEquals("HelloWorld", new String(outputStream.toByteArray(), "UTF-8")); + + verify(action).openFile(eq(temporaryFile), eq(true)); + verify(catalog).markAsDownloaded(content); + verify(temporaryFile).delete(); + } + + /** + * Scenario: Download fails with IOException. + * + * Verify that: + * * Partially downloaded file will not be deleted + * * Content will not be marked as downloaded in catalog + */ + @Test + public void testTemporaryFileIsNotDeletedAfterDownloadAborted() throws Exception { + DownloadContent content = new DownloadContentBuilder() + .setKind(DownloadContent.KIND_FONT) + .setType(DownloadContent.TYPE_ASSET_ARCHIVE) + .setSize(4223) + .build(); + + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + doReturn(Collections.singletonList(content)).when(catalog).getScheduledDownloads(); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application); + + File temporaryFile = mockFileWithSize(1337L); + doReturn(temporaryFile).when(action).createTemporaryFile(RuntimeEnvironment.application, content); + + ByteArrayOutputStream outputStream = spy(new ByteArrayOutputStream()); + doReturn(outputStream).when(action).openFile(eq(temporaryFile), anyBoolean()); + doThrow(IOException.class).when(outputStream).write(any(byte[].class), anyInt(), anyInt()); + + HttpURLConnection connection = mockHttpURLConnection(STATUS_PARTIAL_CONTENT, "HelloWorld"); + doReturn(connection).when(action).buildHttpURLConnection(anyString()); + + doReturn(mockNotExistingFile()).when(action).getDestinationFile(RuntimeEnvironment.application, content); + + action.perform(RuntimeEnvironment.application, catalog); + + verify(catalog, never()).markAsDownloaded(content); + verify(action, never()).verify(any(File.class), anyString()); + verify(temporaryFile, never()).delete(); + } + + /** + * Scenario: Partially downloaded file is already complete. + * + * Verify that: + * * No download request is made + * * File is treated as completed and will be verified and extracted + * * Content is marked as downloaded in catalog + */ + @Test + public void testNoRequestIsSentIfFileIsAlreadyComplete() throws Exception { + DownloadContent content = new DownloadContentBuilder() + .setKind(DownloadContent.KIND_FONT) + .setType(DownloadContent.TYPE_ASSET_ARCHIVE) + .setSize(1337L) + .build(); + + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + doReturn(Collections.singletonList(content)).when(catalog).getScheduledDownloads(); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application); + + File temporaryFile = mockFileWithSize(1337L); + doReturn(temporaryFile).when(action).createTemporaryFile(RuntimeEnvironment.application, content); + + File destinationFile = mockNotExistingFile(); + doReturn(destinationFile).when(action).getDestinationFile(RuntimeEnvironment.application, content); + + doReturn(true).when(action).verify(eq(temporaryFile), anyString()); + doNothing().when(action).extract(eq(temporaryFile), eq(destinationFile), anyString()); + + action.perform(RuntimeEnvironment.application, catalog); + + verify(action, never()).download(anyString(), eq(temporaryFile)); + verify(action).verify(eq(temporaryFile), anyString()); + verify(action).extract(eq(temporaryFile), eq(destinationFile), anyString()); + verify(catalog).markAsDownloaded(content); + } + + /** + * Scenario: Download is completed but verification (checksum) failed. + * + * Verify that: + * * Downloaded file is deleted + * * File will not be extracted + * * Content is not marked as downloaded in the catalog + */ + @Test + public void testTemporaryFileWillBeDeletedIfVerificationFails() throws Exception { + DownloadContent content = new DownloadContentBuilder() + .setKind(DownloadContent.KIND_FONT) + .setType(DownloadContent.TYPE_ASSET_ARCHIVE) + .setSize(1337L) + .build(); + + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + doReturn(Collections.singletonList(content)).when(catalog).getScheduledDownloads(); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application); + doNothing().when(action).download(anyString(), any(File.class)); + doReturn(false).when(action).verify(any(File.class), anyString()); + + File temporaryFile = mockNotExistingFile(); + doReturn(temporaryFile).when(action).createTemporaryFile(RuntimeEnvironment.application, content); + + File destinationFile = mockNotExistingFile(); + doReturn(destinationFile).when(action).getDestinationFile(RuntimeEnvironment.application, content); + + action.perform(RuntimeEnvironment.application, catalog); + + verify(temporaryFile).delete(); + verify(action, never()).extract(any(File.class), any(File.class), anyString()); + verify(catalog, never()).markAsDownloaded(content); + } + + /** + * Scenario: Not enough storage space for content is available. + * + * Verify that: + * * No download will per performed + */ + @Test + public void testNoDownloadIsPerformedIfNotEnoughStorageIsAvailable() throws Exception { + DownloadContent content = createFontWithSize(1337L); + DownloadContentCatalog catalog = mockCatalogWithScheduledDownloads(content); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application); + doReturn(true).when(action).isConnectedToNetwork(RuntimeEnvironment.application); + + File temporaryFile = mockNotExistingFile(); + doReturn(temporaryFile).when(action).createTemporaryFile(RuntimeEnvironment.application, content); + + File destinationFile = mockNotExistingFile(); + doReturn(destinationFile).when(action).getDestinationFile(RuntimeEnvironment.application, content); + + doReturn(true).when(action).hasEnoughDiskSpace(content, destinationFile, temporaryFile); + + verify(action, never()).buildHttpURLConnection(anyString()); + verify(action, never()).download(anyString(), any(File.class)); + verify(action, never()).verify(any(File.class), anyString()); + verify(catalog, never()).markAsDownloaded(content); + } + + /** + * Scenario: Not enough storage space for temporary file available. + * + * Verify that: + * * hasEnoughDiskSpace() returns false + */ + @Test + public void testWithNotEnoughSpaceForTemporaryFile() throws Exception{ + DownloadContent content = createFontWithSize(2048); + File destinationFile = mockNotExistingFile(); + File temporaryFile = mockNotExistingFileWithUsableSpace(1024); + + DownloadAction action = new DownloadAction(null); + Assert.assertFalse(action.hasEnoughDiskSpace(content, destinationFile, temporaryFile)); + } + + /** + * Scenario: Not enough storage space for destination file available. + * + * Verify that: + * * hasEnoughDiskSpace() returns false + */ + @Test + public void testWithNotEnoughSpaceForDestinationFile() throws Exception { + DownloadContent content = createFontWithSize(2048); + File destinationFile = mockNotExistingFileWithUsableSpace(1024); + File temporaryFile = mockNotExistingFile(); + + DownloadAction action = new DownloadAction(null); + Assert.assertFalse(action.hasEnoughDiskSpace(content, destinationFile, temporaryFile)); + } + + /** + * Scenario: Enough storage space for temporary and destination file available. + * + * Verify that: + * * hasEnoughDiskSpace() returns true + */ + @Test + public void testWithEnoughSpaceForEverything() throws Exception { + DownloadContent content = createFontWithSize(2048); + File destinationFile = mockNotExistingFileWithUsableSpace(4096); + File temporaryFile = mockNotExistingFileWithUsableSpace(4096); + + DownloadAction action = new DownloadAction(null); + Assert.assertTrue(action.hasEnoughDiskSpace(content, destinationFile, temporaryFile)); + } + + /** + * Scenario: Download failed with network I/O error. + * + * Verify that: + * * Error is not counted as failure + */ + @Test + public void testNetworkErrorIsNotCountedAsFailure() throws Exception { + DownloadContent content = createFont(); + DownloadContentCatalog catalog = mockCatalogWithScheduledDownloads(content); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(true).when(action).isConnectedToNetwork(RuntimeEnvironment.application); + doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application); + doReturn(mockNotExistingFile()).when(action).createTemporaryFile(RuntimeEnvironment.application, content); + doReturn(mockNotExistingFile()).when(action).getDestinationFile(RuntimeEnvironment.application, content); + doReturn(true).when(action).hasEnoughDiskSpace(eq(content), any(File.class), any(File.class)); + + HttpURLConnection connection = mockHttpURLConnection(STATUS_OK, ""); + doThrow(IOException.class).when(connection).getInputStream(); + doReturn(connection).when(action).buildHttpURLConnection(anyString()); + + action.perform(RuntimeEnvironment.application, catalog); + + verify(catalog, never()).rememberFailure(eq(content), anyInt()); + verify(catalog, never()).markAsDownloaded(content); + } + + /** + * Scenario: Disk IO Error when extracting file. + * + * Verify that: + * * Error is counted as failure + * * After multiple errors the content is marked as permanently failed + */ + @Test + public void testDiskIOErrorIsCountedAsFailure() throws Exception { + DownloadContent content = createFont(); + DownloadContentCatalog catalog = mockCatalogWithScheduledDownloads(content); + doCallRealMethod().when(catalog).rememberFailure(eq(content), anyInt()); + doCallRealMethod().when(catalog).markAsPermanentlyFailed(content); + + Assert.assertEquals(DownloadContent.STATE_NONE, content.getState()); + + DownloadAction action = spy(new DownloadAction(null)); + doReturn(true).when(action).isConnectedToNetwork(RuntimeEnvironment.application); + doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application); + doReturn(mockNotExistingFile()).when(action).createTemporaryFile(RuntimeEnvironment.application, content); + doReturn(mockNotExistingFile()).when(action).getDestinationFile(RuntimeEnvironment.application, content); + doReturn(true).when(action).hasEnoughDiskSpace(eq(content), any(File.class), any(File.class)); + doNothing().when(action).download(anyString(), any(File.class)); + doReturn(true).when(action).verify(any(File.class), anyString()); + + File destinationFile = mock(File.class); + doReturn(false).when(destinationFile).exists(); + File parentFile = mock(File.class); + doReturn(false).when(parentFile).mkdirs(); + doReturn(false).when(parentFile).exists(); + doReturn(parentFile).when(destinationFile).getParentFile(); + doReturn(destinationFile).when(action).getDestinationFile(RuntimeEnvironment.application, content); + + for (int i = 0; i < 10; i++) { + action.perform(RuntimeEnvironment.application, catalog); + + Assert.assertEquals(DownloadContent.STATE_NONE, content.getState()); + } + + action.perform(RuntimeEnvironment.application, catalog); + + Assert.assertEquals(DownloadContent.STATE_FAILED, content.getState()); + verify(catalog, times(11)).rememberFailure(eq(content), anyInt()); + } + + /** + * Scenario: If the file to be downloaded is of kind - "hyphenation" + * + * Verify that: + * * isHyphenationDictionary returns true for a download content with kind "hyphenation" + * * isHyphenationDictionary returns false for a download content with unknown/different kind like "Font" + */ + @Test + public void testIsHyphenationDictionary() throws Exception { + DownloadContent hyphenationContent = createHyphenationDictionary(); + Assert.assertTrue(hyphenationContent.isHyphenationDictionary()); + DownloadContent fontContent = createFont(); + Assert.assertFalse(fontContent.isHyphenationDictionary()); + DownloadContent unknownContent = createUnknownContent(1024L); + Assert.assertFalse(unknownContent.isHyphenationDictionary()); + } + + /** + * Scenario: If the content to be downloaded is known + * + * Verify that: + * * isKnownContent returns true for a downloadable content with a known kind and type. + * * isKnownContent returns false for a downloadable content with unknown kind and type. + */ + @Test + public void testIsKnownContent() throws Exception { + DownloadContent fontContent = createFontWithSize(1024L); + DownloadContent hyphenationContent = createHyphenationDictionaryWithSize(1024L); + DownloadContent unknownContent = createUnknownContent(1024L); + DownloadContent contentWithUnknownType = createContentWithoutType(1024L); + + Assert.assertTrue(fontContent.isKnownContent()); + Assert.assertTrue(hyphenationContent.isKnownContent()); + Assert.assertFalse(unknownContent.isKnownContent()); + Assert.assertFalse(contentWithUnknownType.isKnownContent()); + } + + private DownloadContent createUnknownContent(long size) { + return new DownloadContentBuilder() + .setSize(size) + .build(); + } + + private DownloadContent createContentWithoutType(long size) { + return new DownloadContentBuilder() + .setKind(DownloadContent.KIND_HYPHENATION_DICTIONARY) + .setSize(size) + .build(); + } + + private DownloadContent createFont() { + return createFontWithSize(102400L); + } + + private DownloadContent createFontWithSize(long size) { + return new DownloadContentBuilder() + .setKind(DownloadContent.KIND_FONT) + .setType(DownloadContent.TYPE_ASSET_ARCHIVE) + .setSize(size) + .build(); + } + + private DownloadContent createHyphenationDictionary() { + return createHyphenationDictionaryWithSize(102400L); + } + + private DownloadContent createHyphenationDictionaryWithSize(long size) { + return new DownloadContentBuilder() + .setKind(DownloadContent.KIND_HYPHENATION_DICTIONARY) + .setType(DownloadContent.TYPE_ASSET_ARCHIVE) + .setSize(size) + .build(); + } + + private DownloadContentCatalog mockCatalogWithScheduledDownloads(DownloadContent... content) { + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + doReturn(Arrays.asList(content)).when(catalog).getScheduledDownloads(); + return catalog; + } + + private static File mockNotExistingFile() { + return mockFileWithUsableSpace(false, 0, Long.MAX_VALUE); + } + + private static File mockNotExistingFileWithUsableSpace(long usableSpace) { + return mockFileWithUsableSpace(false, 0, usableSpace); + } + + private static File mockFileWithSize(long length) { + return mockFileWithUsableSpace(true, length, Long.MAX_VALUE); + } + + private static File mockFileWithUsableSpace(boolean exists, long length, long usableSpace) { + File file = mock(File.class); + doReturn(exists).when(file).exists(); + doReturn(length).when(file).length(); + + File parentFile = mock(File.class); + doReturn(usableSpace).when(parentFile).getUsableSpace(); + doReturn(parentFile).when(file).getParentFile(); + + return file; + } + + private static HttpURLConnection mockHttpURLConnection(int statusCode, String content) throws Exception { + HttpURLConnection connection = mock(HttpURLConnection.class); + + doReturn(statusCode).when(connection).getResponseCode(); + doReturn(new ByteArrayInputStream(content.getBytes("UTF-8"))).when(connection).getInputStream(); + + return connection; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestStudyAction.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestStudyAction.java new file mode 100644 index 000000000..6b2ce83df --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestStudyAction.java @@ -0,0 +1,119 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.dlc; + +import android.content.Context; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.dlc.catalog.DownloadContent; +import org.mozilla.gecko.dlc.catalog.DownloadContentBuilder; +import org.mozilla.gecko.dlc.catalog.DownloadContentCatalog; +import org.robolectric.RuntimeEnvironment; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; + +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * StudyAction: Scan the catalog for "new" content available for download. + */ +@RunWith(TestRunner.class) +public class TestStudyAction { + /** + * Scenario: Catalog is empty. + * + * Verify that: + * * No download is scheduled + * * Download action is not started + */ + @Test + public void testPerformWithEmptyCatalog() { + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + when(catalog.getContentToStudy()).thenReturn(new ArrayList()); + + StudyAction action = spy(new StudyAction()); + action.perform(RuntimeEnvironment.application, catalog); + + verify(catalog).getContentToStudy(); + verify(catalog, never()).markAsDownloaded(any(DownloadContent.class)); + verify(action, never()).startDownloads(any(Context.class)); + } + + /** + * Scenario: Catalog contains two items that have not been downloaded yet. + * + * Verify that: + * * Both items are scheduled to be downloaded + */ + @Test + public void testPerformWithNewContent() { + DownloadContent content1 = new DownloadContentBuilder() + .setType(DownloadContent.TYPE_ASSET_ARCHIVE) + .setKind(DownloadContent.KIND_FONT) + .build(); + DownloadContent content2 = new DownloadContentBuilder() + .setType(DownloadContent.TYPE_ASSET_ARCHIVE) + .setKind(DownloadContent.KIND_FONT) + .build(); + + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + when(catalog.getContentToStudy()).thenReturn(Arrays.asList(content1, content2)); + + StudyAction action = spy(new StudyAction()); + action.perform(RuntimeEnvironment.application, catalog); + + verify(catalog).scheduleDownload(content1); + verify(catalog).scheduleDownload(content2); + } + + /** + * Scenario: Catalog contains item that are scheduled for download. + * + * Verify that: + * * Download action is started + */ + @Test + public void testStartingDownloadsAfterScheduling() { + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + when(catalog.hasScheduledDownloads()).thenReturn(true); + + StudyAction action = spy(new StudyAction()); + action.perform(RuntimeEnvironment.application, catalog); + + verify(action).startDownloads(any(Context.class)); + } + + /** + * Scenario: Catalog contains unknown content. + * + * Verify that: + * * Unknown content is not scheduled for download. + */ + @Test + public void testPerformWithUnknownContent() { + DownloadContent content = new DownloadContentBuilder() + .setType("Unknown-Type") + .setKind("Unknown-Kind") + .build(); + + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + when(catalog.getContentToStudy()).thenReturn(Collections.singletonList(content)); + + StudyAction action = spy(new StudyAction()); + action.perform(RuntimeEnvironment.application, catalog); + + verify(catalog, never()).scheduleDownload(content); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestSyncAction.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestSyncAction.java new file mode 100644 index 000000000..1e494975e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestSyncAction.java @@ -0,0 +1,276 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.dlc; + +import android.content.Context; +import android.support.v4.util.ArrayMap; +import android.support.v4.util.AtomicFile; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.dlc.catalog.DownloadContent; +import org.mozilla.gecko.dlc.catalog.DownloadContentBuilder; +import org.mozilla.gecko.dlc.catalog.DownloadContentCatalog; +import org.mozilla.gecko.util.IOUtils; +import org.robolectric.RuntimeEnvironment; + +import java.io.BufferedInputStream; +import java.io.ByteArrayOutputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.List; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyLong; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +/** + * SyncAction: Synchronize catalog from a (mocked) Kinto instance. + */ +@RunWith(TestRunner.class) +public class TestSyncAction { + /** + * Scenario: The server returns an empty record set. + */ + @Test + public void testEmptyResult() throws Exception { + SyncAction action = spy(new SyncAction()); + doReturn(true).when(action).isSyncEnabledForClient(RuntimeEnvironment.application); + doReturn(new JSONArray()).when(action).fetchRawCatalog(anyLong()); + + action.perform(RuntimeEnvironment.application, mockCatalog()); + + verify(action, never()).createContent(anyCatalog(), anyJSONObject()); + verify(action, never()).updateContent(anyCatalog(), anyJSONObject(), anyContent()); + verify(action, never()).deleteContent(anyCatalog(), anyString()); + + verify(action, never()).startStudyAction(anyContext()); + } + + /** + * Scenario: The server returns an item that is not in the catalog yet. + */ + @Test + public void testAddingNewContent() throws Exception { + SyncAction action = spy(new SyncAction()); + doReturn(true).when(action).isSyncEnabledForClient(RuntimeEnvironment.application); + doReturn(fromFile("dlc_sync_single_font.json")).when(action).fetchRawCatalog(anyLong()); + + DownloadContentCatalog catalog = mockCatalog(); + + action.perform(RuntimeEnvironment.application, catalog); + + // A new content item has been created + verify(action).createContent(anyCatalog(), anyJSONObject()); + + // No content item has been updated or deleted + verify(action, never()).updateContent(anyCatalog(), anyJSONObject(), anyContent()); + verify(action, never()).deleteContent(anyCatalog(), anyString()); + + // A new item has been added to the catalog + ArgumentCaptor captor = ArgumentCaptor.forClass(DownloadContent.class); + verify(catalog).add(captor.capture()); + + // The item matches the values from the server response + DownloadContent content = captor.getValue(); + Assert.assertEquals("c906275c-3747-fe27-426f-6187526a6f06", content.getId()); + Assert.assertEquals("4ed509317f1bb441b185ea13bf1c9d19d1a0b396962efa3b5dc3190ad88f2067", content.getChecksum()); + Assert.assertEquals("960be4fc5a92c1dc488582b215d5d75429fd4ffbee463105d29992cd792a912e", content.getDownloadChecksum()); + Assert.assertEquals("CharisSILCompact-R.ttf", content.getFilename()); + Assert.assertEquals(DownloadContent.KIND_FONT, content.getKind()); + Assert.assertEquals("/attachments/0d28a72d-a51f-46f8-9e5a-f95c61de904e.gz", content.getLocation()); + Assert.assertEquals(DownloadContent.TYPE_ASSET_ARCHIVE, content.getType()); + Assert.assertEquals(1455710632607L, content.getLastModified()); + Assert.assertEquals(1727656L, content.getSize()); + Assert.assertEquals(DownloadContent.STATE_NONE, content.getState()); + } + + /** + * Scenario: The catalog is using the old format, we want to make sure we abort cleanly. + */ + @Test + public void testUpdatingWithOldCatalog() throws Exception{ + SyncAction action = spy(new SyncAction()); + doReturn(true).when(action).isSyncEnabledForClient(RuntimeEnvironment.application); + doReturn(fromFile("dlc_sync_old_format.json")).when(action).fetchRawCatalog(anyLong()); + + DownloadContent existingContent = createTestContent("c906275c-3747-fe27-426f-6187526a6f06"); + DownloadContentCatalog catalog = spy(new MockedContentCatalog(existingContent)); + + action.perform(RuntimeEnvironment.application, catalog); + + // make sure nothing was done + verify(action, never()).createContent(anyCatalog(), anyJSONObject()); + verify(action, never()).updateContent(anyCatalog(), anyJSONObject(), anyContent()); + verify(action, never()).deleteContent(anyCatalog(), anyString()); + verify(action, never()).startStudyAction(anyContext()); + } + + + /** + * Scenario: The catalog contains one item and the server returns a new version. + */ + @Test + public void testUpdatingExistingContent() throws Exception{ + SyncAction action = spy(new SyncAction()); + doReturn(true).when(action).isSyncEnabledForClient(RuntimeEnvironment.application); + doReturn(fromFile("dlc_sync_single_font.json")).when(action).fetchRawCatalog(anyLong()); + + DownloadContent existingContent = createTestContent("c906275c-3747-fe27-426f-6187526a6f06"); + DownloadContentCatalog catalog = spy(new MockedContentCatalog(existingContent)); + + action.perform(RuntimeEnvironment.application, catalog); + + // A content item has been updated + verify(action).updateContent(anyCatalog(), anyJSONObject(), eq(existingContent)); + + // No content item has been created or deleted + verify(action, never()).createContent(anyCatalog(), anyJSONObject()); + verify(action, never()).deleteContent(anyCatalog(), anyString()); + + // An item has been updated in the catalog + ArgumentCaptor captor = ArgumentCaptor.forClass(DownloadContent.class); + verify(catalog).update(captor.capture()); + + // The item has the new values from the sever response + DownloadContent content = captor.getValue(); + Assert.assertEquals("c906275c-3747-fe27-426f-6187526a6f06", content.getId()); + Assert.assertEquals("4ed509317f1bb441b185ea13bf1c9d19d1a0b396962efa3b5dc3190ad88f2067", content.getChecksum()); + Assert.assertEquals("960be4fc5a92c1dc488582b215d5d75429fd4ffbee463105d29992cd792a912e", content.getDownloadChecksum()); + Assert.assertEquals("CharisSILCompact-R.ttf", content.getFilename()); + Assert.assertEquals(DownloadContent.KIND_FONT, content.getKind()); + Assert.assertEquals("/attachments/0d28a72d-a51f-46f8-9e5a-f95c61de904e.gz", content.getLocation()); + Assert.assertEquals(DownloadContent.TYPE_ASSET_ARCHIVE, content.getType()); + Assert.assertEquals(1455710632607L, content.getLastModified()); + Assert.assertEquals(1727656L, content.getSize()); + Assert.assertEquals(DownloadContent.STATE_UPDATED, content.getState()); + } + + /** + * Scenario: Catalog contains one item and the server returns that it has been deleted. + */ + @Test + public void testDeletingExistingContent() throws Exception { + SyncAction action = spy(new SyncAction()); + doReturn(true).when(action).isSyncEnabledForClient(RuntimeEnvironment.application); + doReturn(fromFile("dlc_sync_deleted_item.json")).when(action).fetchRawCatalog(anyLong()); + + final String id = "c906275c-3747-fe27-426f-6187526a6f06"; + DownloadContent existingContent = createTestContent(id); + DownloadContentCatalog catalog = spy(new MockedContentCatalog(existingContent)); + + action.perform(RuntimeEnvironment.application, catalog); + + // A content item has been deleted + verify(action).deleteContent(anyCatalog(), eq(id)); + + // No content item has been created or updated + verify(action, never()).createContent(anyCatalog(), anyJSONObject()); + verify(action, never()).updateContent(anyCatalog(), anyJSONObject(), anyContent()); + + // An item has been marked for deletion in the catalog + ArgumentCaptor captor = ArgumentCaptor.forClass(DownloadContent.class); + verify(catalog).markAsDeleted(captor.capture()); + + DownloadContent content = captor.getValue(); + Assert.assertEquals(id, content.getId()); + + List contentToDelete = catalog.getContentToDelete(); + Assert.assertEquals(1, contentToDelete.size()); + Assert.assertEquals(id, contentToDelete.get(0).getId()); + } + + /** + * Create a DownloadContent object with arbitrary data. + */ + private DownloadContent createTestContent(String id) { + return new DownloadContentBuilder() + .setId(id) + .setLocation("/somewhere/something") + .setFilename("some.file") + .setChecksum("Some-checksum") + .setDownloadChecksum("Some-download-checksum") + .setLastModified(4223) + .setType("Some-type") + .setKind("Some-kind") + .setSize(27) + .setState(DownloadContent.STATE_SCHEDULED) + .build(); + } + + /** + * Create a Kinto response from a JSON file. + */ + private JSONArray fromFile(String fileName) throws IOException, JSONException { + URL url = getClass().getResource("/" + fileName); + if (url == null) { + throw new FileNotFoundException(fileName); + } + + InputStream inputStream = null; + ByteArrayOutputStream outputStream = null; + + try { + inputStream = new BufferedInputStream(new FileInputStream(url.getPath())); + outputStream = new ByteArrayOutputStream(); + + IOUtils.copy(inputStream, outputStream); + + JSONObject object = new JSONObject(outputStream.toString()); + + return object.getJSONArray("data"); + } finally { + IOUtils.safeStreamClose(inputStream); + IOUtils.safeStreamClose(outputStream); + } + } + + private static class MockedContentCatalog extends DownloadContentCatalog { + public MockedContentCatalog(DownloadContent content) { + super(mock(AtomicFile.class)); + + ArrayMap map = new ArrayMap<>(); + map.put(content.getId(), content); + + onCatalogLoaded(map); + } + } + + private DownloadContentCatalog mockCatalog() { + return mock(DownloadContentCatalog.class); + } + + private DownloadContentCatalog anyCatalog() { + return any(DownloadContentCatalog.class); + } + + private JSONObject anyJSONObject() { + return any(JSONObject.class); + } + + private DownloadContent anyContent() { + return any(DownloadContent.class); + } + + private Context anyContext() { + return any(Context.class); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestVerifyAction.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestVerifyAction.java new file mode 100644 index 000000000..6a347376e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/TestVerifyAction.java @@ -0,0 +1,123 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.dlc; + +import android.content.Context; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.dlc.catalog.DownloadContent; +import org.mozilla.gecko.dlc.catalog.DownloadContentBuilder; +import org.mozilla.gecko.dlc.catalog.DownloadContentCatalog; +import org.robolectric.RuntimeEnvironment; + +import java.io.File; +import java.util.Collections; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +/** + * VerifyAction: Validate downloaded content. Does it still exist and does it have the correct checksum? + */ +@RunWith(TestRunner.class) +public class TestVerifyAction { + /** + * Scenario: Downloaded file does not exist anymore. + * + * Verify that: + * * Content is re-scheduled for download. + */ + @Test + public void testReschedulingIfFileDoesNotExist() throws Exception { + DownloadContent content = new DownloadContentBuilder().build(); + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + when(catalog.getDownloadedContent()).thenReturn(Collections.singletonList(content)); + + File file = mock(File.class); + when(file.exists()).thenReturn(false); + + VerifyAction action = spy(new VerifyAction()); + doReturn(file).when(action).getDestinationFile(RuntimeEnvironment.application, content); + + action.perform(RuntimeEnvironment.application, catalog); + + verify(catalog).scheduleDownload(content); + } + + /** + * Scenario: Content has been scheduled for download. + * + * Verify that: + * * Download action is started + */ + @Test + public void testStartingDownloadsAfterScheduling() { + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + when(catalog.hasScheduledDownloads()).thenReturn(true); + + VerifyAction action = spy(new VerifyAction()); + action.perform(RuntimeEnvironment.application, catalog); + + verify(action).startDownloads(any(Context.class)); + } + + /** + * Scenario: Checksum of existing file does not match expectation. + * + * Verify that: + * * Content is re-scheduled for download. + */ + @Test + public void testReschedulingIfVerificationFailed() throws Exception { + DownloadContent content = new DownloadContentBuilder().build(); + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + when(catalog.getDownloadedContent()).thenReturn(Collections.singletonList(content)); + + File file = mock(File.class); + when(file.exists()).thenReturn(true); + + VerifyAction action = spy(new VerifyAction()); + doReturn(file).when(action).getDestinationFile(RuntimeEnvironment.application, content); + doReturn(false).when(action).verify(eq(file), anyString()); + + action.perform(RuntimeEnvironment.application, catalog); + + verify(catalog).scheduleDownload(content); + } + + /** + * Scenario: Downloaded file exists and has the correct checksum. + * + * Verify that: + * * No download is scheduled + * * Download action is not started + */ + @Test + public void testSuccessfulVerification() throws Exception { + DownloadContent content = new DownloadContentBuilder().build(); + DownloadContentCatalog catalog = mock(DownloadContentCatalog.class); + when(catalog.getDownloadedContent()).thenReturn(Collections.singletonList(content)); + + File file = mock(File.class); + when(file.exists()).thenReturn(true); + + VerifyAction action = spy(new VerifyAction()); + doReturn(file).when(action).getDestinationFile(RuntimeEnvironment.application, content); + doReturn(true).when(action).verify(eq(file), anyString()); + + verify(catalog, never()).scheduleDownload(content); + verify(action, never()).startDownloads(RuntimeEnvironment.application); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/catalog/TestDownloadContentBuilder.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/catalog/TestDownloadContentBuilder.java new file mode 100644 index 000000000..147b5da5b --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/catalog/TestDownloadContentBuilder.java @@ -0,0 +1,69 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.dlc.catalog; + +import org.json.JSONException; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +@RunWith(TestRunner.class) +public class TestDownloadContentBuilder { + /** + * Verify that the values passed to the builder are all set on the DownloadContent object. + */ + @Test + public void testBuilder() { + DownloadContent content = createTestContent(); + + Assert.assertEquals("Some-ID", content.getId()); + Assert.assertEquals("/somewhere/something", content.getLocation()); + Assert.assertEquals("some.file", content.getFilename()); + Assert.assertEquals("Some-checksum", content.getChecksum()); + Assert.assertEquals("Some-download-checksum", content.getDownloadChecksum()); + Assert.assertEquals(4223, content.getLastModified()); + Assert.assertEquals("Some-type", content.getType()); + Assert.assertEquals("Some-kind", content.getKind()); + Assert.assertEquals(27, content.getSize()); + Assert.assertEquals(DownloadContent.STATE_SCHEDULED, content.getState()); + } + + /** + * Verify that a DownloadContent object exported to JSON and re-imported from JSON does not change. + */ + public void testJSONSerializationAndDeserialization() throws JSONException { + DownloadContent content = DownloadContentBuilder.fromJSON(DownloadContentBuilder.toJSON(createTestContent())); + + Assert.assertEquals("Some-ID", content.getId()); + Assert.assertEquals("/somewhere/something", content.getLocation()); + Assert.assertEquals("some.file", content.getFilename()); + Assert.assertEquals("Some-checksum", content.getChecksum()); + Assert.assertEquals("Some-download-checksum", content.getDownloadChecksum()); + Assert.assertEquals(4223, content.getLastModified()); + Assert.assertEquals("Some-type", content.getType()); + Assert.assertEquals("Some-kind", content.getKind()); + Assert.assertEquals(27, content.getSize()); + Assert.assertEquals(DownloadContent.STATE_SCHEDULED, content.getState()); + } + + /** + * Create a DownloadContent object with arbitrary data. + */ + private DownloadContent createTestContent() { + return new DownloadContentBuilder() + .setId("Some-ID") + .setLocation("/somewhere/something") + .setFilename("some.file") + .setChecksum("Some-checksum") + .setDownloadChecksum("Some-download-checksum") + .setLastModified(4223) + .setType("Some-type") + .setKind("Some-kind") + .setSize(27) + .setState(DownloadContent.STATE_SCHEDULED) + .build(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/catalog/TestDownloadContentCatalog.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/catalog/TestDownloadContentCatalog.java new file mode 100644 index 000000000..5b5912cdd --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/dlc/catalog/TestDownloadContentCatalog.java @@ -0,0 +1,262 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.dlc.catalog; + +import android.support.v4.util.ArrayMap; +import android.support.v4.util.AtomicFile; + +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.AppConstants; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import java.io.FileNotFoundException; +import java.io.FileOutputStream; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +@RunWith(TestRunner.class) +public class TestDownloadContentCatalog { + /** + * Scenario: Create a new, fresh catalog. + * + * Verify that: + * * Catalog has not changed + * * Unchanged catalog will not be saved to disk + */ + @Test + public void testUntouchedCatalogHasNotChangedAndWillNotBePersisted() throws Exception { + AtomicFile file = mock(AtomicFile.class); + doReturn("{content:[]}".getBytes("UTF-8")).when(file).readFully(); + + DownloadContentCatalog catalog = spy(new DownloadContentCatalog(file)); + catalog.loadFromDisk(); + + Assert.assertFalse("Catalog has not changed", catalog.hasCatalogChanged()); + + catalog.writeToDisk(); + + Assert.assertFalse("Catalog has not changed", catalog.hasCatalogChanged()); + + verify(file, never()).startWrite(); + } + + /** + * Scenario: Create a new, fresh catalog. + * + * Verify that: + * * Catalog is bootstrapped with items. + */ + @Test + public void testCatalogIsBootstrappedIfFileDoesNotExist() throws Exception { + // The catalog is only bootstrapped if fonts are excluded from the build. If this is a build + // with fonts included then ignore this test. + Assume.assumeTrue("Fonts are excluded from build", AppConstants.MOZ_ANDROID_EXCLUDE_FONTS); + + AtomicFile file = mock(AtomicFile.class); + doThrow(FileNotFoundException.class).when(file).readFully(); + + DownloadContentCatalog catalog = spy(new DownloadContentCatalog(file)); + catalog.loadFromDisk(); + + Assert.assertTrue("Catalog is not empty", catalog.getContentToStudy().size() > 0); + } + + /** + * Scenario: Schedule downloading an item from the catalog. + * + * Verify that: + * * Catalog has changed + */ + @Test + public void testCatalogHasChangedWhenDownloadIsScheduled() throws Exception { + DownloadContentCatalog catalog = spy(new DownloadContentCatalog(mock(AtomicFile.class))); + DownloadContent content = new DownloadContentBuilder().build(); + catalog.onCatalogLoaded(createMapOfContent(content)); + + Assert.assertFalse("Catalog has not changed", catalog.hasCatalogChanged()); + + catalog.scheduleDownload(content); + + Assert.assertTrue("Catalog has changed", catalog.hasCatalogChanged()); + } + + /** + * Scenario: Mark an item in the catalog as downloaded. + * + * Verify that: + * * Catalog has changed + */ + @Test + public void testCatalogHasChangedWhenContentIsDownloaded() throws Exception { + DownloadContentCatalog catalog = spy(new DownloadContentCatalog(mock(AtomicFile.class))); + DownloadContent content = new DownloadContentBuilder().build(); + catalog.onCatalogLoaded(createMapOfContent(content)); + + Assert.assertFalse("Catalog has not changed", catalog.hasCatalogChanged()); + + catalog.markAsDownloaded(content); + + Assert.assertTrue("Catalog has changed", catalog.hasCatalogChanged()); + } + + /** + * Scenario: Mark an item in the catalog as permanently failed. + * + * Verify that: + * * Catalog has changed + */ + @Test + public void testCatalogHasChangedIfDownloadHasFailedPermanently() throws Exception { + DownloadContentCatalog catalog = spy(new DownloadContentCatalog(mock(AtomicFile.class))); + DownloadContent content = new DownloadContentBuilder().build(); + catalog.onCatalogLoaded(createMapOfContent(content)); + + Assert.assertFalse("Catalog has not changed", catalog.hasCatalogChanged()); + + catalog.markAsPermanentlyFailed(content); + + Assert.assertTrue("Catalog has changed", catalog.hasCatalogChanged()); + } + + /** + * Scenario: A changed catalog is written to disk. + * + * Verify that: + * * Before write: Catalog has changed + * * After write: Catalog has not changed. + */ + @Test + public void testCatalogHasNotChangedAfterWritingToDisk() throws Exception { + AtomicFile file = mock(AtomicFile.class); + doReturn(mock(FileOutputStream.class)).when(file).startWrite(); + + DownloadContentCatalog catalog = spy(new DownloadContentCatalog(file)); + DownloadContent content = new DownloadContentBuilder().build(); + catalog.onCatalogLoaded(createMapOfContent(content)); + + catalog.scheduleDownload(content); + + Assert.assertTrue("Catalog has changed", catalog.hasCatalogChanged()); + + catalog.writeToDisk(); + + Assert.assertFalse("Catalog has not changed", catalog.hasCatalogChanged()); + } + + /** + * Scenario: A catalog with multiple items in different states. + * + * Verify that: + * * getContentWithoutState(), getDownloadedContent() and getScheduledDownloads() returns + * the correct items depenending on their state. + */ + @Test + public void testContentClassification() { + DownloadContentCatalog catalog = spy(new DownloadContentCatalog(mock(AtomicFile.class))); + + DownloadContent content1 = new DownloadContentBuilder().setId("A").setState(DownloadContent.STATE_NONE).build(); + DownloadContent content2 = new DownloadContentBuilder().setId("B").setState(DownloadContent.STATE_NONE).build(); + DownloadContent content3 = new DownloadContentBuilder().setId("C").setState(DownloadContent.STATE_SCHEDULED).build(); + DownloadContent content4 = new DownloadContentBuilder().setId("D").setState(DownloadContent.STATE_SCHEDULED).build(); + DownloadContent content5 = new DownloadContentBuilder().setId("E").setState(DownloadContent.STATE_SCHEDULED).build(); + DownloadContent content6 = new DownloadContentBuilder().setId("F").setState(DownloadContent.STATE_DOWNLOADED).build(); + DownloadContent content7 = new DownloadContentBuilder().setId("G").setState(DownloadContent.STATE_FAILED).build(); + DownloadContent content8 = new DownloadContentBuilder().setId("H").setState(DownloadContent.STATE_UPDATED).build(); + DownloadContent content9 = new DownloadContentBuilder().setId("I").setState(DownloadContent.STATE_DELETED).build(); + DownloadContent content10 = new DownloadContentBuilder().setId("J").setState(DownloadContent.STATE_DELETED).build(); + + catalog.onCatalogLoaded(createMapOfContent(content1, content2, content3, content4, content5, content6, + content7, content8, content9, content10)); + + Assert.assertTrue(catalog.hasScheduledDownloads()); + + Assert.assertEquals(3, catalog.getContentToStudy().size()); + Assert.assertEquals(1, catalog.getDownloadedContent().size()); + Assert.assertEquals(3, catalog.getScheduledDownloads().size()); + Assert.assertEquals(2, catalog.getContentToDelete().size()); + + Assert.assertTrue(catalog.getContentToStudy().contains(content1)); + Assert.assertTrue(catalog.getContentToStudy().contains(content2)); + Assert.assertTrue(catalog.getContentToStudy().contains(content8)); + + Assert.assertTrue(catalog.getDownloadedContent().contains(content6)); + + Assert.assertTrue(catalog.getScheduledDownloads().contains(content3)); + Assert.assertTrue(catalog.getScheduledDownloads().contains(content4)); + Assert.assertTrue(catalog.getScheduledDownloads().contains(content5)); + + Assert.assertTrue(catalog.getContentToDelete().contains(content9)); + Assert.assertTrue(catalog.getContentToDelete().contains(content10)); + } + + /** + * Scenario: Calling rememberFailure() on a catalog with varying values + */ + @Test + public void testRememberingFailures() { + DownloadContentCatalog catalog = new DownloadContentCatalog(mock(AtomicFile.class)); + Assert.assertFalse(catalog.hasCatalogChanged()); + + DownloadContent content = new DownloadContentBuilder().build(); + Assert.assertEquals(0, content.getFailures()); + + catalog.rememberFailure(content, 42); + Assert.assertEquals(1, content.getFailures()); + Assert.assertTrue(catalog.hasCatalogChanged()); + + catalog.rememberFailure(content, 42); + Assert.assertEquals(2, content.getFailures()); + + // Failure counter is reset if different failure has been reported + catalog.rememberFailure(content, 23); + Assert.assertEquals(1, content.getFailures()); + + // Failure counter is reset after successful download + catalog.markAsDownloaded(content); + Assert.assertEquals(0, content.getFailures()); + } + + /** + * Scenario: Content has failed multiple times with the same failure type. + * + * Verify that: + * * Content is marked as permanently failed + */ + @Test + public void testContentWillBeMarkedAsPermanentlyFailedAfterMultipleFailures() { + DownloadContentCatalog catalog = new DownloadContentCatalog(mock(AtomicFile.class)); + + DownloadContent content = new DownloadContentBuilder().build(); + Assert.assertEquals(DownloadContent.STATE_NONE, content.getState()); + + for (int i = 0; i < 10; i++) { + catalog.rememberFailure(content, 42); + + Assert.assertEquals(i + 1, content.getFailures()); + Assert.assertEquals(DownloadContent.STATE_NONE, content.getState()); + } + + catalog.rememberFailure(content, 42); + Assert.assertEquals(10, content.getFailures()); + Assert.assertEquals(DownloadContent.STATE_FAILED, content.getState()); + } + + private ArrayMap createMapOfContent(DownloadContent... content) { + ArrayMap map = new ArrayMap<>(); + for (DownloadContent currentContent : content) { + map.put(currentContent.getId(), currentContent); + } + return map; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteBlogger.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteBlogger.java new file mode 100644 index 000000000..628b572ce --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteBlogger.java @@ -0,0 +1,74 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.feeds.knownsites; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.helpers.AssertUtil; + +@RunWith(TestRunner.class) +public class TestKnownSiteBlogger { + /** + * Test that the search string is a substring of some known URLs. + */ + @Test + public void testURLSearchString() { + final KnownSite blogger = new KnownSiteBlogger(); + final String searchString = blogger.getURLSearchString(); + + AssertUtil.assertContains( + "http://mykzilla.blogspot.com/", + searchString); + + AssertUtil.assertContains( + "http://example.blogspot.com", + searchString); + + AssertUtil.assertContains( + "https://mykzilla.blogspot.com/2015/06/introducing-pluotsorbet.html", + searchString); + + AssertUtil.assertContains( + "http://android-developers.blogspot.com/2016/02/android-support-library-232.html", + searchString); + + AssertUtil.assertContainsNot( + "http://www.mozilla.org", + searchString); + } + + /** + * Test that we get a feed URL for valid Blogger URLs. + */ + @Test + public void testGettingFeedFromURL() { + final KnownSite blogger = new KnownSiteBlogger(); + + Assert.assertEquals( + "https://mykzilla.blogspot.com/feeds/posts/default", + blogger.getFeedFromURL("http://mykzilla.blogspot.com/")); + + Assert.assertEquals( + "https://example.blogspot.com/feeds/posts/default", + blogger.getFeedFromURL("http://example.blogspot.com")); + + Assert.assertEquals( + "https://mykzilla.blogspot.com/feeds/posts/default", + blogger.getFeedFromURL("https://mykzilla.blogspot.com/2015/06/introducing-pluotsorbet.html")); + + Assert.assertEquals( + "https://android-developers.blogspot.com/feeds/posts/default", + blogger.getFeedFromURL("http://android-developers.blogspot.com/2016/02/android-support-library-232.html")); + + Assert.assertEquals( + "https://example.blogspot.com/feeds/posts/default", + blogger.getFeedFromURL("http://example.blogspot.com/2016/03/i-moved-to-example.blogspot.com")); + + Assert.assertNull(blogger.getFeedFromURL("http://www.mozilla.org")); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteMedium.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteMedium.java new file mode 100644 index 000000000..77f05e0d0 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteMedium.java @@ -0,0 +1,66 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.feeds.knownsites; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.helpers.AssertUtil; + +@RunWith(TestRunner.class) +public class TestKnownSiteMedium { + /** + * Test that the search string is a substring of some known URLs. + */ + @Test + public void testURLSearchString() { + final KnownSite medium = new KnownSiteMedium(); + final String searchString = medium.getURLSearchString(); + + AssertUtil.assertContains( + "https://medium.com/@Antlam/", + searchString); + + AssertUtil.assertContains( + "https://medium.com/google-developers", + searchString); + + AssertUtil.assertContains( + "http://medium.com/@brandonshin/how-slackbot-forced-us-to-workout-7b4741a2de73", + searchString + ); + + AssertUtil.assertContainsNot( + "http://www.mozilla.org", + searchString); + } + + /** + * Test that we get a feed URL for valid Medium URLs. + */ + @Test + public void testGettingFeedFromURL() { + final KnownSite medium = new KnownSiteMedium(); + + Assert.assertEquals( + "https://medium.com/feed/@Antlam", + medium.getFeedFromURL("https://medium.com/@Antlam/") + ); + + Assert.assertEquals( + "https://medium.com/feed/google-developers", + medium.getFeedFromURL("https://medium.com/google-developers") + ); + + Assert.assertEquals( + "https://medium.com/feed/@brandonshin", + medium.getFeedFromURL("http://medium.com/@brandonshin/how-slackbot-forced-us-to-workout-7b4741a2de73") + ); + + Assert.assertNull(medium.getFeedFromURL("http://www.mozilla.org")); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteTumblr.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteTumblr.java new file mode 100644 index 000000000..f83272f82 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/knownsites/TestKnownSiteTumblr.java @@ -0,0 +1,62 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.feeds.knownsites; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.helpers.AssertUtil; + +@RunWith(TestRunner.class) +public class TestKnownSiteTumblr { + /** + * Test that the search string is a substring of some known URLs. + */ + @Test + public void testURLSearchString() { + final KnownSite tumblr = new KnownSiteTumblr(); + final String searchString = tumblr.getURLSearchString(); + + AssertUtil.assertContains( + "http://contentnotifications.tumblr.com/", + searchString); + + AssertUtil.assertContains( + "https://contentnotifications.tumblr.com", + searchString); + + AssertUtil.assertContains( + "http://contentnotifications.tumblr.com/post/142684202402/content-notification-firefox-for-android-480", + searchString); + + AssertUtil.assertContainsNot( + "http://www.mozilla.org", + searchString); + } + + /** + * Test that we get a feed URL for valid Medium URLs. + */ + @Test + public void testGettingFeedFromURL() { + final KnownSite tumblr = new KnownSiteTumblr(); + + Assert.assertEquals( + "http://contentnotifications.tumblr.com/rss", + tumblr.getFeedFromURL("http://contentnotifications.tumblr.com/") + ); + + Assert.assertEquals( + "http://staff.tumblr.com/rss", + tumblr.getFeedFromURL("https://staff.tumblr.com/post/141928246566/replies-are-back-and-the-sun-is-shining-on-the") + ); + + Assert.assertNull(tumblr.getFeedFromURL("https://www.tumblr.com")); + + Assert.assertNull(tumblr.getFeedFromURL("http://www.mozilla.org")); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/parser/TestSimpleFeedParser.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/parser/TestSimpleFeedParser.java new file mode 100644 index 000000000..fa2fffbad --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/feeds/parser/TestSimpleFeedParser.java @@ -0,0 +1,323 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.feeds.parser; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.UnsupportedEncodingException; +import java.net.URISyntaxException; +import java.net.URL; +import java.text.SimpleDateFormat; +import java.util.Locale; + +@RunWith(TestRunner.class) +public class TestSimpleFeedParser { + /** + * Parse and verify the RSS example from Wikipedia: + * https://en.wikipedia.org/wiki/RSS#Example + */ + @Test + public void testRSSExample() throws Exception { + InputStream stream = openFeed("feed_rss_wikipedia.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("RSS Title", feed.getTitle()); + Assert.assertEquals("http://www.example.com/main.html", feed.getWebsiteURL()); + Assert.assertNull(feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("Example entry", item.getTitle()); + Assert.assertEquals("http://www.example.com/blog/post/1", item.getURL()); + Assert.assertEquals(1252254000000L, item.getTimestamp()); + } + + /** + * Parse and verify the ATOM example from Wikipedia: + * https://en.wikipedia.org/wiki/Atom_%28standard%29#Example_of_an_Atom_1.0_feed + */ + @Test + public void testATOMExample() throws Exception { + InputStream stream = openFeed("feed_atom_wikipedia.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("Example Feed", feed.getTitle()); + Assert.assertEquals("http://example.org/", feed.getWebsiteURL()); + Assert.assertEquals("http://example.org/feed/", feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("Atom-Powered Robots Run Amok", item.getTitle()); + Assert.assertEquals("http://example.org/2003/12/13/atom03.html", item.getURL()); + Assert.assertEquals(1071340202000L, item.getTimestamp()); + } + + /** + * Parse and verify a snapshot of a Medium feed. + */ + @Test + public void testMediumFeed() throws Exception { + InputStream stream = openFeed("feed_rss_medium.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("Anthony Lam on Medium", feed.getTitle()); + Assert.assertEquals("https://medium.com/@antlam?source=rss-59f49b9e4b19------2", feed.getWebsiteURL()); + Assert.assertEquals("https://medium.com/feed/@antlam", feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("UX thoughts for 2016", item.getTitle()); + Assert.assertEquals("https://medium.com/@antlam/ux-thoughts-for-2016-1fc1d6e515e8?source=rss-59f49b9e4b19------2", item.getURL()); + Assert.assertEquals(1452537838000L, item.getTimestamp()); + } + + /** + * Parse and verify a snapshot of planet.mozilla.org ATOM feed. + */ + @Test + public void testPlanetMozillaATOMFeed() throws Exception { + InputStream stream = openFeed("feed_atom_planetmozilla.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("Planet Mozilla", feed.getTitle()); + Assert.assertEquals("http://planet.mozilla.org/", feed.getWebsiteURL()); + Assert.assertEquals("http://planet.mozilla.org/atom.xml", feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("Firefox 45.0 Beta 3 Testday, February 5th", item.getTitle()); + Assert.assertEquals("https://quality.mozilla.org/2016/01/firefox-45-0-beta-3-testday-february-5th/", item.getURL()); + Assert.assertEquals(1453819255000L, item.getTimestamp()); + } + + /** + * Parse and verify a snapshot of planet.mozilla.org RSS 2.0 feed. + */ + @Test + public void testPlanetMozillaRSS20Feed() throws Exception { + InputStream stream = openFeed("feed_rss20_planetmozilla.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("Planet Mozilla", feed.getTitle()); + Assert.assertEquals("http://planet.mozilla.org/", feed.getWebsiteURL()); + Assert.assertEquals("http://planet.mozilla.org/rss20.xml", feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("Aaron Klotz: Announcing Mozdbgext", item.getTitle()); + Assert.assertEquals("http://dblohm7.ca/blog/2016/01/26/announcing-mozdbgext/", item.getURL()); + Assert.assertEquals(1453837500000L, item.getTimestamp()); + } + + /** + * Parse and verify a snapshot of planet.mozilla.org RSS 1.0 feed. + */ + @Test + public void testPlanetMozillaRSS10Feed() throws Exception { + InputStream stream = openFeed("feed_rss10_planetmozilla.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("Planet Mozilla", feed.getTitle()); + Assert.assertEquals("http://planet.mozilla.org/", feed.getWebsiteURL()); + Assert.assertEquals("http://planet.mozilla.org/rss10.xml", feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("Aaron Klotz: Announcing Mozdbgext", item.getTitle()); + Assert.assertEquals("http://dblohm7.ca/blog/2016/01/26/announcing-mozdbgext/", item.getURL()); + Assert.assertEquals(1453837500000L, item.getTimestamp()); + } + + /** + * Parse an verify a snapshot of a feedburner ATOM feed. + */ + @Test + public void testFeedburnerAtomFeed() throws Exception { + InputStream stream = openFeed("feed_atom_feedburner.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("Android Zeitgeist", feed.getTitle()); + Assert.assertEquals("http://www.androidzeitgeist.com/", feed.getWebsiteURL()); + Assert.assertEquals("http://feeds.feedburner.com/AndroidZeitgeist", feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("Support for restricted profiles in Firefox 42", item.getTitle()); + Assert.assertEquals("http://feedproxy.google.com/~r/AndroidZeitgeist/~3/xaSicfGuwOU/support-restricted-profiles-firefox.html", item.getURL()); + Assert.assertEquals(1442511968239L, item.getTimestamp()); + } + + /** + * Parse and verify a snapshot of a Tumblr RSS feed. + */ + @Test + public void testTumblrRssFeed() throws Exception { + InputStream stream = openFeed("feed_rss_tumblr.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("Tumblr Staff", feed.getTitle()); + Assert.assertEquals("http://staff.tumblr.com/", feed.getWebsiteURL()); + Assert.assertNull(feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("hardyboyscovers: Can Nancy Drew see things through and solve...", item.getTitle()); + Assert.assertEquals("http://staff.tumblr.com/post/138124026275", item.getURL()); + Assert.assertEquals(1453861812000L, item.getTimestamp()); + } + + /** + * Parse and verify a snapshot of a Spiegel (German news magazine) RSS feed. + */ + @Test + public void testSpiegelRssFeed() throws Exception { + InputStream stream = openFeed("feed_rss_spon.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("SPIEGEL ONLINE - Schlagzeilen", feed.getTitle()); + Assert.assertEquals("http://www.spiegel.de", feed.getWebsiteURL()); + Assert.assertNull(feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("Angebliche Vergewaltigung einer 13-Jährigen: Steinmeier kanzelt russischen Minister Lawrow ab", item.getTitle()); + Assert.assertEquals("http://www.spiegel.de/politik/ausland/steinmeier-kanzelt-lawrow-ab-aerger-um-angebliche-vergewaltigung-a-1074292.html#ref=rss", item.getURL()); + Assert.assertEquals(1453914976000L, item.getTimestamp()); + } + + /** + * Parse and verify a snapshot of a Heise (German tech news) RSS feed. + */ + @Test + public void testHeiseRssFeed() throws Exception { + InputStream stream = openFeed("feed_rss_heise.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("heise online News", feed.getTitle()); + Assert.assertEquals("http://www.heise.de/newsticker/", feed.getWebsiteURL()); + Assert.assertNull(feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("Google: “Dramatische Verbesserungen” für Chrome in iOS", item.getTitle()); + Assert.assertEquals("http://www.heise.de/newsticker/meldung/Google-Dramatische-Verbesserungen-fuer-Chrome-in-iOS-3085808.html?wt_mc=rss.ho.beitrag.atom", item.getURL()); + Assert.assertEquals(1453915920000L, item.getTimestamp()); + } + + @Test + public void testWordpressFeed() throws Exception { + InputStream stream = openFeed("feed_rss_wordpress.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("justasimpletest2016", feed.getTitle()); + Assert.assertEquals("https://justasimpletest2016.wordpress.com", feed.getWebsiteURL()); + Assert.assertEquals("https://justasimpletest2016.wordpress.com/feed/", feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("Hello World!", item.getTitle()); + Assert.assertEquals("https://justasimpletest2016.wordpress.com/2016/02/26/hello-world/", item.getURL()); + Assert.assertEquals(1456524466000L, item.getTimestamp()); + } + + /** + * Parse and test a snapshot of mykzilla.blogspot.com + */ + @Test + public void testBloggerFeed() throws Exception { + InputStream stream = openFeed("feed_atom_blogger.xml"); + + SimpleFeedParser parser = new SimpleFeedParser(); + Feed feed = parser.parse(stream); + + Assert.assertNotNull(feed); + Assert.assertEquals("mykzilla", feed.getTitle()); + Assert.assertEquals("http://mykzilla.blogspot.com/", feed.getWebsiteURL()); + Assert.assertEquals("http://www.blogger.com/feeds/18929277/posts/default", feed.getFeedURL()); + Assert.assertTrue(feed.isSufficientlyComplete()); + + Item item = feed.getLastItem(); + + Assert.assertNotNull(item); + Assert.assertEquals("URL Has Been Changed", item.getTitle()); + Assert.assertEquals("http://mykzilla.blogspot.com/2016/01/url-has-been-changed.html", item.getURL()); + Assert.assertEquals(1452531451366L, item.getTimestamp()); + } + + private InputStream openFeed(String fileName) throws URISyntaxException, FileNotFoundException, UnsupportedEncodingException { + URL url = getClass().getResource("/" + fileName); + if (url == null) { + throw new FileNotFoundException(fileName); + } + + return new BufferedInputStream(new FileInputStream(url.getPath())); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/TestSkewHandler.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/TestSkewHandler.java new file mode 100644 index 000000000..2b4fe3e03 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/TestSkewHandler.java @@ -0,0 +1,70 @@ +/* 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 org.mozilla.gecko.fxa; + +import ch.boye.httpclientandroidlib.impl.cookie.DateUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.fxa.SkewHandler; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.net.BaseResource; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestSkewHandler { + public TestSkewHandler() { + } + + @Test + public void testSkewUpdating() throws Throwable { + SkewHandler h = new SkewHandler("foo.com"); + assertEquals(0L, h.getSkewInSeconds()); + assertEquals(0L, h.getSkewInMillis()); + + long server = 1390101197865L; + long local = server - 4500L; + h.updateSkewFromServerMillis(server, local); + assertEquals(4500L, h.getSkewInMillis()); + assertEquals(4L, h.getSkewInSeconds()); + + local = server; + h.updateSkewFromServerMillis(server, local); + assertEquals(0L, h.getSkewInMillis()); + assertEquals(0L, h.getSkewInSeconds()); + + local = server + 500L; + h.updateSkewFromServerMillis(server, local); + assertEquals(-500L, h.getSkewInMillis()); + assertEquals(0L, h.getSkewInSeconds()); + + String date = "Sat, 18 Jan 2014 19:16:52 PST"; + long dateInMillis = 1390101412000L; // Obviously this can differ somewhat due to precision. + long parsed = DateUtils.parseDate(date).getTime(); + assertEquals(parsed, dateInMillis); + + h.updateSkewFromHTTPDateString(date, dateInMillis); + assertEquals(0L, h.getSkewInMillis()); + assertEquals(0L, h.getSkewInSeconds()); + + h.updateSkewFromHTTPDateString(date, dateInMillis + 1100L); + assertEquals(-1100L, h.getSkewInMillis()); + assertEquals(Math.round(-1100L / 1000L), h.getSkewInSeconds()); + } + + @Test + public void testSkewSingleton() throws Exception { + SkewHandler h1 = SkewHandler.getSkewHandlerFromEndpointString("http://foo.com/bar"); + SkewHandler h2 = SkewHandler.getSkewHandlerForHostname("foo.com"); + SkewHandler h3 = SkewHandler.getSkewHandlerForResource(new BaseResource("http://foo.com/baz")); + assertTrue(h1 == h2); + assertTrue(h1 == h3); + + SkewHandler.getSkewHandlerForHostname("foo.com").updateSkewFromServerMillis(1390101412000L, 1390001412000L); + final long actual = SkewHandler.getSkewHandlerForHostname("foo.com").getSkewInMillis(); + assertEquals(100000000L, actual); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java new file mode 100644 index 000000000..868e90cd2 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java @@ -0,0 +1,226 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.fxa.login; + +import android.text.TextUtils; + +import org.mozilla.gecko.background.fxa.FxAccountClient; +import org.mozilla.gecko.background.fxa.FxAccountClient20; +import org.mozilla.gecko.background.fxa.FxAccountClient20.AccountStatusResponse; +import org.mozilla.gecko.background.fxa.FxAccountClient20.RequestDelegate; +import org.mozilla.gecko.background.fxa.FxAccountClient20.RecoveryEmailStatusResponse; +import org.mozilla.gecko.background.fxa.FxAccountClient20.TwoKeys; +import org.mozilla.gecko.background.fxa.FxAccountClient20.LoginResponse; +import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException; +import org.mozilla.gecko.background.fxa.FxAccountRemoteError; +import org.mozilla.gecko.background.fxa.FxAccountUtils; +import org.mozilla.gecko.fxa.FxAccountDevice; +import org.mozilla.gecko.browserid.MockMyIDTokenFactory; +import org.mozilla.gecko.browserid.RSACryptoImplementation; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.Utils; + +import java.io.UnsupportedEncodingException; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import ch.boye.httpclientandroidlib.HttpStatus; +import ch.boye.httpclientandroidlib.ProtocolVersion; +import ch.boye.httpclientandroidlib.entity.StringEntity; +import ch.boye.httpclientandroidlib.message.BasicHttpResponse; + +public class MockFxAccountClient implements FxAccountClient { + protected static MockMyIDTokenFactory mockMyIdTokenFactory = new MockMyIDTokenFactory(); + + public final String serverURI = "http://testServer.com"; + + public final Map users = new HashMap(); + public final Map sessionTokens = new HashMap(); + public final Map keyFetchTokens = new HashMap(); + + public static class User { + public final String email; + public final byte[] quickStretchedPW; + public final String uid; + public boolean verified; + public final byte[] kA; + public final byte[] wrapkB; + public final Map devices; + + public User(String email, byte[] quickStretchedPW) { + this.email = email; + this.quickStretchedPW = quickStretchedPW; + this.uid = "uid/" + this.email; + this.verified = false; + this.kA = Utils.generateRandomBytes(FxAccountUtils.CRYPTO_KEY_LENGTH_BYTES); + this.wrapkB = Utils.generateRandomBytes(FxAccountUtils.CRYPTO_KEY_LENGTH_BYTES); + this.devices = new HashMap(); + } + } + + protected LoginResponse addLogin(User user, byte[] sessionToken, byte[] keyFetchToken) { + // byte[] sessionToken = Utils.generateRandomBytes(8); + if (sessionToken != null) { + sessionTokens.put(Utils.byte2Hex(sessionToken), user.email); + } + // byte[] keyFetchToken = Utils.generateRandomBytes(8); + if (keyFetchToken != null) { + keyFetchTokens.put(Utils.byte2Hex(keyFetchToken), user.email); + } + return new LoginResponse(user.email, user.uid, user.verified, sessionToken, keyFetchToken); + } + + public void addUser(String email, byte[] quickStretchedPW, boolean verified, byte[] sessionToken, byte[] keyFetchToken) { + User user = new User(email, quickStretchedPW); + users.put(email, user); + if (verified) { + verifyUser(email); + } + addLogin(user, sessionToken, keyFetchToken); + } + + public void verifyUser(String email) { + users.get(email).verified = true; + } + + public void clearAllUserTokens() throws UnsupportedEncodingException { + sessionTokens.clear(); + keyFetchTokens.clear(); + } + + protected BasicHttpResponse makeHttpResponse(int statusCode, String body) { + BasicHttpResponse httpResponse = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), statusCode, body); + httpResponse.setEntity(new StringEntity(body, "UTF-8")); + return httpResponse; + } + + protected void handleFailure(RequestDelegate requestDelegate, int code, int errno, String message) { + requestDelegate.handleFailure(new FxAccountClientRemoteException(makeHttpResponse(code, message), + code, errno, "Bad authorization", message, null, new ExtendedJSONObject())); + } + + @Override + public void accountStatus(String uid, RequestDelegate requestDelegate) { + boolean userFound = false; + for (User user : users.values()) { + if (user.uid.equals(uid)) { + userFound = true; + break; + } + } + requestDelegate.handleSuccess(new AccountStatusResponse(userFound)); + } + + @Override + public void recoveryEmailStatus(byte[] sessionToken, RequestDelegate requestDelegate) { + String email = sessionTokens.get(Utils.byte2Hex(sessionToken)); + User user = users.get(email); + if (email == null || user == null) { + handleFailure(requestDelegate, HttpStatus.SC_UNAUTHORIZED, FxAccountRemoteError.INVALID_AUTHENTICATION_TOKEN, "invalid sessionToken"); + return; + } + requestDelegate.handleSuccess(new RecoveryEmailStatusResponse(email, user.verified)); + } + + @Override + public void keys(byte[] keyFetchToken, RequestDelegate requestDelegate) { + String email = keyFetchTokens.get(Utils.byte2Hex(keyFetchToken)); + User user = users.get(email); + if (email == null || user == null) { + handleFailure(requestDelegate, HttpStatus.SC_UNAUTHORIZED, FxAccountRemoteError.INVALID_AUTHENTICATION_TOKEN, "invalid keyFetchToken"); + return; + } + if (!user.verified) { + handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.ATTEMPT_TO_OPERATE_ON_AN_UNVERIFIED_ACCOUNT, "user is unverified"); + return; + } + requestDelegate.handleSuccess(new TwoKeys(user.kA, user.wrapkB)); + } + + @Override + public void sign(byte[] sessionToken, ExtendedJSONObject publicKey, long certificateDurationInMilliseconds, RequestDelegate requestDelegate) { + String email = sessionTokens.get(Utils.byte2Hex(sessionToken)); + User user = users.get(email); + if (email == null || user == null) { + handleFailure(requestDelegate, HttpStatus.SC_UNAUTHORIZED, FxAccountRemoteError.INVALID_AUTHENTICATION_TOKEN, "invalid sessionToken"); + return; + } + if (!user.verified) { + handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.ATTEMPT_TO_OPERATE_ON_AN_UNVERIFIED_ACCOUNT, "user is unverified"); + return; + } + try { + final long iat = System.currentTimeMillis(); + final long dur = certificateDurationInMilliseconds; + final long exp = iat + dur; + String certificate = mockMyIdTokenFactory.createMockMyIDCertificate(RSACryptoImplementation.createPublicKey(publicKey), "test", iat, exp); + requestDelegate.handleSuccess(certificate); + } catch (Exception e) { + requestDelegate.handleError(e); + } + } + + @Override + public void registerOrUpdateDevice(byte[] sessionToken, FxAccountDevice deviceToRegister, RequestDelegate requestDelegate) { + String email = sessionTokens.get(Utils.byte2Hex(sessionToken)); + User user = users.get(email); + if (email == null || user == null) { + handleFailure(requestDelegate, HttpStatus.SC_UNAUTHORIZED, FxAccountRemoteError.INVALID_AUTHENTICATION_TOKEN, "invalid sessionToken"); + return; + } + if (!user.verified) { + handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.ATTEMPT_TO_OPERATE_ON_AN_UNVERIFIED_ACCOUNT, "user is unverified"); + return; + } + try { + String deviceId = deviceToRegister.id; + if (TextUtils.isEmpty(deviceId)) { // Create + deviceId = UUID.randomUUID().toString(); + FxAccountDevice device = new FxAccountDevice(deviceToRegister.name, deviceId, deviceToRegister.type, null, null, null, null); + requestDelegate.handleSuccess(device); + } else { // Update + FxAccountDevice existingDevice = user.devices.get(deviceId); + if (existingDevice != null) { + String deviceName = existingDevice.name; + if (!TextUtils.isEmpty(deviceToRegister.name)) { + deviceName = deviceToRegister.name; + } // We could also update the other fields.. + FxAccountDevice device = new FxAccountDevice(deviceName, existingDevice.id, existingDevice.type, + existingDevice.isCurrentDevice, existingDevice.pushCallback, existingDevice.pushPublicKey,existingDevice.pushAuthKey); + requestDelegate.handleSuccess(device); + } else { // Device unknown + handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.UNKNOWN_DEVICE, "device is unknown"); + return; + } + } + } catch (Exception e) { + requestDelegate.handleError(e); + } + } + + @Override + public void deviceList(byte[] sessionToken, RequestDelegate requestDelegate) { + String email = sessionTokens.get(Utils.byte2Hex(sessionToken)); + User user = users.get(email); + if (email == null || user == null) { + handleFailure(requestDelegate, HttpStatus.SC_UNAUTHORIZED, FxAccountRemoteError.INVALID_AUTHENTICATION_TOKEN, "invalid sessionToken"); + return; + } + if (!user.verified) { + handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.ATTEMPT_TO_OPERATE_ON_AN_UNVERIFIED_ACCOUNT, "user is unverified"); + return; + } + Collection devices = user.devices.values(); + FxAccountDevice[] devicesArray = devices.toArray(new FxAccountDevice[devices.size()]); + requestDelegate.handleSuccess(devicesArray); + } + + @Override + public void notifyDevices(byte[] sessionToken, List deviceIds, ExtendedJSONObject payload, Long TTL, RequestDelegate requestDelegate) { + requestDelegate.handleSuccess(new ExtendedJSONObject()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/TestFxAccountLoginStateMachine.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/TestFxAccountLoginStateMachine.java new file mode 100644 index 000000000..1496f6d79 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/TestFxAccountLoginStateMachine.java @@ -0,0 +1,205 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.fxa.login; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.fxa.FxAccountClient; +import org.mozilla.gecko.background.fxa.FxAccountUtils; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.browserid.BrowserIDKeyPair; +import org.mozilla.gecko.browserid.RSACryptoImplementation; +import org.mozilla.gecko.fxa.login.FxAccountLoginStateMachine.LoginStateMachineDelegate; +import org.mozilla.gecko.fxa.login.FxAccountLoginTransition.Transition; +import org.mozilla.gecko.fxa.login.State.StateLabel; +import org.mozilla.gecko.sync.Utils; + +import java.security.NoSuchAlgorithmException; +import java.util.LinkedList; + +@RunWith(TestRunner.class) +public class TestFxAccountLoginStateMachine { + // private static final String TEST_AUDIENCE = "http://testAudience.com"; + private static final String TEST_EMAIL = "test@test.com"; + private static byte[] TEST_EMAIL_UTF8; + private static final String TEST_PASSWORD = "testtest"; + private static byte[] TEST_PASSWORD_UTF8; + private static byte[] TEST_QUICK_STRETCHED_PW; + private static byte[] TEST_UNWRAPKB; + private static final byte[] TEST_SESSION_TOKEN = Utils.generateRandomBytes(32); + private static final byte[] TEST_KEY_FETCH_TOKEN = Utils.generateRandomBytes(32); + + protected MockFxAccountClient client; + protected FxAccountLoginStateMachine sm; + + @Before + public void setUp() throws Exception { + if (TEST_EMAIL_UTF8 == null) { + TEST_EMAIL_UTF8 = TEST_EMAIL.getBytes("UTF-8"); + } + if (TEST_PASSWORD_UTF8 == null) { + TEST_PASSWORD_UTF8 = TEST_PASSWORD.getBytes("UTF-8"); + } + if (TEST_QUICK_STRETCHED_PW == null) { + TEST_QUICK_STRETCHED_PW = FxAccountUtils.generateQuickStretchedPW(TEST_EMAIL_UTF8, TEST_PASSWORD_UTF8); + } + if (TEST_UNWRAPKB == null) { + TEST_UNWRAPKB = FxAccountUtils.generateUnwrapBKey(TEST_QUICK_STRETCHED_PW); + } + client = new MockFxAccountClient(); + sm = new FxAccountLoginStateMachine(); + } + + protected static class Trace { + public final LinkedList states; + public final LinkedList transitions; + + public Trace(LinkedList states, LinkedList transitions) { + this.states = states; + this.transitions = transitions; + } + + public void assertEquals(String string) { + Assert.assertArrayEquals(string.split(", "), toString().split(", ")); + } + + @Override + public String toString() { + final LinkedList states = new LinkedList(this.states); + final LinkedList transitions = new LinkedList(this.transitions); + LinkedList names = new LinkedList(); + State state; + while ((state = states.pollFirst()) != null) { + names.add(state.getStateLabel().name()); + Transition transition = transitions.pollFirst(); + if (transition != null) { + names.add(">" + transition.toString()); + } + } + return names.toString(); + } + + public String stateString() { + LinkedList names = new LinkedList(); + for (State state : states) { + names.add(state.getStateLabel().name()); + } + return names.toString(); + } + + public String transitionString() { + LinkedList names = new LinkedList(); + for (Transition transition : transitions) { + names.add(transition.toString()); + } + return names.toString(); + } + } + + protected Trace trace(final State initialState, final StateLabel desiredState) { + final LinkedList transitions = new LinkedList(); + final LinkedList states = new LinkedList(); + states.add(initialState); + + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + sm.advance(initialState, desiredState, new LoginStateMachineDelegate() { + @Override + public void handleTransition(Transition transition, State state) { + transitions.add(transition); + states.add(state); + } + + @Override + public void handleFinal(State state) { + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public FxAccountClient getClient() { + return client; + } + + @Override + public long getCertificateDurationInMilliseconds() { + return 30 * 1000; + } + + @Override + public long getAssertionDurationInMilliseconds() { + return 10 * 1000; + } + + @Override + public BrowserIDKeyPair generateKeyPair() throws NoSuchAlgorithmException { + return RSACryptoImplementation.generateKeyPair(512); + } + }); + } + }); + + return new Trace(states, transitions); + } + + @Test + public void testEnagedUnverified() throws Exception { + client.addUser(TEST_EMAIL, TEST_QUICK_STRETCHED_PW, false, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN); + Trace trace = trace(new Engaged(TEST_EMAIL, "uid", true, TEST_UNWRAPKB, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN), StateLabel.Married); + trace.assertEquals("[Engaged, >AccountNeedsVerification, Engaged]"); + } + + @Test + public void testEngagedTransitionToAccountVerified() throws Exception { + client.addUser(TEST_EMAIL, TEST_QUICK_STRETCHED_PW, true, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN); + Trace trace = trace(new Engaged(TEST_EMAIL, "uid", false, TEST_UNWRAPKB, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN), StateLabel.Married); + trace.assertEquals("[Engaged, >AccountVerified, Cohabiting, >LogMessage('sign succeeded'), Married]"); + } + + @Test + public void testEngagedVerified() throws Exception { + client.addUser(TEST_EMAIL, TEST_QUICK_STRETCHED_PW, true, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN); + Trace trace = trace(new Engaged(TEST_EMAIL, "uid", true, TEST_UNWRAPKB, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN), StateLabel.Married); + trace.assertEquals("[Engaged, >LogMessage('keys succeeded'), Cohabiting, >LogMessage('sign succeeded'), Married]"); + } + + @Test + public void testPartial() throws Exception { + client.addUser(TEST_EMAIL, TEST_QUICK_STRETCHED_PW, true, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN); + // What if we stop at Cohabiting? + Trace trace = trace(new Engaged(TEST_EMAIL, "uid", true, TEST_UNWRAPKB, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN), StateLabel.Cohabiting); + trace.assertEquals("[Engaged, >LogMessage('keys succeeded'), Cohabiting]"); + } + + @Test + public void testBadSessionToken() throws Exception { + client.addUser(TEST_EMAIL, TEST_QUICK_STRETCHED_PW, true, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN); + client.sessionTokens.clear(); + Trace trace = trace(new Engaged(TEST_EMAIL, "uid", true, TEST_UNWRAPKB, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN), StateLabel.Married); + trace.assertEquals("[Engaged, >LogMessage('keys succeeded'), Cohabiting, >Log(), Separated, >PasswordRequired, Separated]"); + } + + @Test + public void testBadKeyFetchToken() throws Exception { + client.addUser(TEST_EMAIL, TEST_QUICK_STRETCHED_PW, true, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN); + client.keyFetchTokens.clear(); + Trace trace = trace(new Engaged(TEST_EMAIL, "uid", true, TEST_UNWRAPKB, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN), StateLabel.Married); + trace.assertEquals("[Engaged, >Log(), Separated, >PasswordRequired, Separated]"); + } + + @Test + public void testMarried() throws Exception { + client.addUser(TEST_EMAIL, TEST_QUICK_STRETCHED_PW, true, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN); + Trace trace = trace(new Engaged(TEST_EMAIL, "uid", true, TEST_UNWRAPKB, TEST_SESSION_TOKEN, TEST_KEY_FETCH_TOKEN), StateLabel.Married); + trace.assertEquals("[Engaged, >LogMessage('keys succeeded'), Cohabiting, >LogMessage('sign succeeded'), Married]"); + // What if we're already in the desired state? + State married = trace.states.getLast(); + Assert.assertEquals(StateLabel.Married, married.getStateLabel()); + trace = trace(married, StateLabel.Married); + trace.assertEquals("[Married]"); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/TestStateFactory.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/TestStateFactory.java new file mode 100644 index 000000000..80d7d7f9f --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/TestStateFactory.java @@ -0,0 +1,91 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.fxa.login; + +import junit.framework.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.browserid.BrowserIDKeyPair; +import org.mozilla.gecko.browserid.DSACryptoImplementation; +import org.mozilla.gecko.fxa.login.State.StateLabel; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.Utils; + +@RunWith(TestRunner.class) +public class TestStateFactory { + @Test + public void testGetStateV3() throws Exception { + MigratedFromSync11 migrated = new MigratedFromSync11("email", "uid", true, "password"); + + // For the current version, we expect to read back what we wrote. + ExtendedJSONObject o; + State state; + + o = migrated.toJSONObject(); + Assert.assertEquals(3, o.getLong("version").intValue()); + state = StateFactory.fromJSONObject(migrated.stateLabel, o); + Assert.assertEquals(StateLabel.MigratedFromSync11, state.stateLabel); + Assert.assertEquals(o, state.toJSONObject()); + + // Null passwords are OK. + MigratedFromSync11 migratedNullPassword = new MigratedFromSync11("email", "uid", true, null); + + o = migratedNullPassword.toJSONObject(); + Assert.assertEquals(3, o.getLong("version").intValue()); + state = StateFactory.fromJSONObject(migratedNullPassword.stateLabel, o); + Assert.assertEquals(StateLabel.MigratedFromSync11, state.stateLabel); + Assert.assertEquals(o, state.toJSONObject()); + } + + @Test + public void testGetStateV2() throws Exception { + byte[] sessionToken = Utils.generateRandomBytes(32); + byte[] kA = Utils.generateRandomBytes(32); + byte[] kB = Utils.generateRandomBytes(32); + BrowserIDKeyPair keyPair = DSACryptoImplementation.generateKeyPair(512); + Cohabiting cohabiting = new Cohabiting("email", "uid", sessionToken, kA, kB, keyPair); + String certificate = "certificate"; + Married married = new Married("email", "uid", sessionToken, kA, kB, keyPair, certificate); + + // For the current version, we expect to read back what we wrote. + ExtendedJSONObject o; + State state; + + o = married.toJSONObject(); + Assert.assertEquals(3, o.getLong("version").intValue()); + state = StateFactory.fromJSONObject(married.stateLabel, o); + Assert.assertEquals(StateLabel.Married, state.stateLabel); + Assert.assertEquals(o, state.toJSONObject()); + + o = cohabiting.toJSONObject(); + Assert.assertEquals(3, o.getLong("version").intValue()); + state = StateFactory.fromJSONObject(cohabiting.stateLabel, o); + Assert.assertEquals(StateLabel.Cohabiting, state.stateLabel); + Assert.assertEquals(o, state.toJSONObject()); + } + + @Test + public void testGetStateV1() throws Exception { + // We can't rely on generating correct V1 objects (since the generation code + // may change); so we hard code a few test examples here. These examples + // have RSA key pairs; when they're parsed, we return DSA key pairs. + ExtendedJSONObject o = new ExtendedJSONObject("{\"uid\":\"uid\",\"sessionToken\":\"4e2830da6ce466ddb401fbca25b96a621209eea83851254800f84cc4069ef011\",\"certificate\":\"certificate\",\"keyPair\":{\"publicKey\":{\"e\":\"65537\",\"n\":\"7598360104379019497828904063491254083855849024432238665262988260947462372141971045236693389494635158997975098558915846889960089362159921622822266839560631\",\"algorithm\":\"RS\"},\"privateKey\":{\"d\":\"6807533330618101360064115400338014782301295929300445938471117364691566605775022173055292460962170873583673516346599808612503093914221141089102289381448225\",\"n\":\"7598360104379019497828904063491254083855849024432238665262988260947462372141971045236693389494635158997975098558915846889960089362159921622822266839560631\",\"algorithm\":\"RS\"}},\"email\":\"email\",\"verified\":true,\"kB\":\"0b048f285c19067f200da7bfbe734ed213cefcd8f543f0fdd4a8ccab48cbbc89\",\"kA\":\"59a9edf2d41de8b24e69df9133bc88e96913baa75421882f4c55d842d18fc8a1\",\"version\":1}"); + // A Married state is regressed to a Cohabited state. + Cohabiting state = (Cohabiting) StateFactory.fromJSONObject(StateLabel.Married, o); + + Assert.assertEquals(StateLabel.Cohabiting, state.stateLabel); + Assert.assertEquals("uid", state.uid); + Assert.assertEquals("4e2830da6ce466ddb401fbca25b96a621209eea83851254800f84cc4069ef011", Utils.byte2Hex(state.sessionToken)); + Assert.assertEquals("DS128", state.keyPair.getPrivate().getAlgorithm()); + + o = new ExtendedJSONObject("{\"uid\":\"uid\",\"sessionToken\":\"4e2830da6ce466ddb401fbca25b96a621209eea83851254800f84cc4069ef011\",\"keyPair\":{\"publicKey\":{\"e\":\"65537\",\"n\":\"7598360104379019497828904063491254083855849024432238665262988260947462372141971045236693389494635158997975098558915846889960089362159921622822266839560631\",\"algorithm\":\"RS\"},\"privateKey\":{\"d\":\"6807533330618101360064115400338014782301295929300445938471117364691566605775022173055292460962170873583673516346599808612503093914221141089102289381448225\",\"n\":\"7598360104379019497828904063491254083855849024432238665262988260947462372141971045236693389494635158997975098558915846889960089362159921622822266839560631\",\"algorithm\":\"RS\"}},\"email\":\"email\",\"verified\":true,\"kB\":\"0b048f285c19067f200da7bfbe734ed213cefcd8f543f0fdd4a8ccab48cbbc89\",\"kA\":\"59a9edf2d41de8b24e69df9133bc88e96913baa75421882f4c55d842d18fc8a1\",\"version\":1}"); + state = (Cohabiting) StateFactory.fromJSONObject(StateLabel.Cohabiting, o); + + Assert.assertEquals(StateLabel.Cohabiting, state.stateLabel); + Assert.assertEquals("uid", state.uid); + Assert.assertEquals("4e2830da6ce466ddb401fbca25b96a621209eea83851254800f84cc4069ef011", Utils.byte2Hex(state.sessionToken)); + Assert.assertEquals("DS128", state.keyPair.getPrivate().getAlgorithm()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/helpers/AssertUtil.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/helpers/AssertUtil.java new file mode 100644 index 000000000..8102bf1ee --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/helpers/AssertUtil.java @@ -0,0 +1,29 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.helpers; + +import org.junit.Assert; + +/** + * Some additional assert methods on top of org.junit.Assert. + */ +public class AssertUtil { + /** + * Asserts that the String {@code text} contains the String {@code sequence}. If it doesn't then + * an {@link AssertionError} will be thrown. + */ + public static void assertContains(String text, String sequence) { + Assert.assertTrue(text.contains(sequence)); + } + + /** + * Asserts that the String {@code text} contains not the String {@code sequence}. If it does + * then an {@link AssertionError} will be thrown. + */ + public static void assertContainsNot(String text, String sequence) { + Assert.assertFalse(text.contains(sequence)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/home/TestHomeConfigPrefsBackendMigration.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/home/TestHomeConfigPrefsBackendMigration.java new file mode 100644 index 000000000..b6f12a05e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/home/TestHomeConfigPrefsBackendMigration.java @@ -0,0 +1,264 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.home; + +import android.content.Context; +import android.util.Pair; +import android.util.SparseArray; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.home.HomeConfig.PanelConfig; +import org.mozilla.gecko.home.HomeConfig.PanelType; +import org.robolectric.RuntimeEnvironment; + +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class TestHomeConfigPrefsBackendMigration { + + // Each Pair consists of a list of panels that exist going into a given migration, and a list containing + // the expected default output panel corresponding to each given input panel in the list of existing panels. + // E.g. if a given N->N+1 migration starts with panels Foo and Bar, and removes Bar, the two lists would + // be {Foo, Bar} and {Foo, Foo}. + // Note: the index where each pair is inserted corresponds to the HomeConfig version before the migration. + // The final item in this list denotes the current HomeCOnfig version, and therefore only needs to contain + // the list of panel types that are expected by default (but no list for after the non-existent migration). + final SparseArray> migrationConstellations = new SparseArray<>(); + { + // 6->7: the recent tabs panel was merged into the combined history panel + migrationConstellations.put(6, new Pair<>( + /* Panels that are expected to exist before this migration happens */ + new PanelType[] { + PanelType.TOP_SITES, + PanelType.BOOKMARKS, + PanelType.COMBINED_HISTORY, + PanelType.DEPRECATED_RECENT_TABS + }, + /* The expected default panel that is expected after the migration */ + new PanelType[] { + PanelType.TOP_SITES, /* TOP_SITES remains the default if it was previously the default */ + PanelType.BOOKMARKS, /* same as TOP_SITES */ + PanelType.COMBINED_HISTORY, /* same as TOP_SITES */ + PanelType.COMBINED_HISTORY /* DEPRECATED_RECENT_TABS is replaced by COMBINED_HISTORY during this migration and is therefore the new default */ + } + )); + + // 7->8: no changes, this was a fixup migration since 6->7 was previously botched + migrationConstellations.put(7, new Pair<>( + new PanelType[] { + PanelType.TOP_SITES, + PanelType.BOOKMARKS, + PanelType.COMBINED_HISTORY, + }, + new PanelType[] { + PanelType.TOP_SITES, + PanelType.BOOKMARKS, + PanelType.COMBINED_HISTORY, + } + )); + + migrationConstellations.put(8, new Pair<>( + new PanelType[] { + PanelType.TOP_SITES, + PanelType.BOOKMARKS, + PanelType.COMBINED_HISTORY, + }, + new PanelType[] { + // Last version: no migration exists yet, we only need to define a list + // of expected panels. + } + )); + } + + private JSONArray createDisabledConfigsForList(Context context, + PanelType[] panels) throws JSONException { + final JSONArray jsonPanels = new JSONArray(); + + for (int i = 0; i < panels.length; i++) { + final PanelType panel = panels[i]; + + jsonPanels.put(HomeConfig.createBuiltinPanelConfig(context, panel, + EnumSet.of(PanelConfig.Flags.DISABLED_PANEL)).toJSON()); + } + + return jsonPanels; + + } + + + private JSONArray createConfigsForList(Context context, PanelType[] panels, + int defaultIndex) throws JSONException { + if (defaultIndex < 0 || defaultIndex >= panels.length) { + throw new IllegalArgumentException("defaultIndex must point to panel in the array"); + } + + final JSONArray jsonPanels = new JSONArray(); + + for (int i = 0; i < panels.length; i++) { + final PanelType panel = panels[i]; + final PanelConfig config; + + if (i == defaultIndex) { + config = HomeConfig.createBuiltinPanelConfig(context, panel, + EnumSet.of(PanelConfig.Flags.DEFAULT_PANEL)); + } else { + config = HomeConfig.createBuiltinPanelConfig(context, panel); + } + + jsonPanels.put(config.toJSON()); + } + + return jsonPanels; + } + + private PanelType getDefaultPanel(final JSONArray jsonPanels) throws JSONException { + assertTrue("panel list must not be empty", jsonPanels.length() > 0); + + for (int i = 0; i < jsonPanels.length(); i++) { + final JSONObject jsonPanelConfig = jsonPanels.getJSONObject(i); + final PanelConfig panelConfig = new PanelConfig(jsonPanelConfig); + + if (panelConfig.isDefault()) { + return panelConfig.getType(); + } + } + + return null; + } + + private void checkAllPanelsAreDisabled(JSONArray jsonPanels) throws JSONException { + for (int i = 0; i < jsonPanels.length(); i++) { + final JSONObject jsonPanelConfig = jsonPanels.getJSONObject(i); + final PanelConfig config = new PanelConfig(jsonPanelConfig); + + assertTrue("Non disabled panel \"" + config.getType().name() + "\" found in list, excpected all panels to be disabled", config.isDisabled()); + } + } + + private void checkListContainsExpectedPanels(JSONArray jsonPanels, + PanelType[] expected) throws JSONException { + // Given the short lists we have here an ArraySet might be more appropriate, but it requires API >= 23. + final Set expectedSet = new HashSet<>(); + for (PanelType panelType : expected) { + expectedSet.add(panelType); + } + + for (int i = 0; i < jsonPanels.length(); i++) { + final JSONObject jsonPanelConfig = jsonPanels.getJSONObject(i); + final PanelType panelType = new PanelConfig(jsonPanelConfig).getType(); + + assertTrue("Unexpected panel of type " + panelType.name() + " found in list", + expectedSet.contains(panelType)); + + expectedSet.remove(panelType); + } + + assertEquals("Expected panels not contained in list", + 0, expectedSet.size()); + } + + @Test + public void testMigrationRetainsDefaultAfter6() throws JSONException { + final Context context = RuntimeEnvironment.application; + + final Pair finalConstellation = migrationConstellations.get(HomeConfigPrefsBackend.VERSION); + assertNotNull("It looks like you added a HomeConfig migration, please add an appropriate entry to migrationConstellations", + finalConstellation); + + // We want to calculate the number of iterations here to make sure we cover all provided constellations. + // Iterating over the array and manually checking for each version could result in constellations + // being skipped if there are any gaps in the array + final int firstTestedVersion = HomeConfigPrefsBackend.VERSION - (migrationConstellations.size() - 1); + + // The last constellation is only used for the counts / expected outputs, hence we start + // with the second-last constellation + for (int testVersion = HomeConfigPrefsBackend.VERSION - 1; testVersion >= firstTestedVersion; testVersion--) { + + final Pair currentConstellation = migrationConstellations.get(testVersion); + assertNotNull("No constellation for version " + testVersion + " - you must provide a constellation for every version upgrade in the list", + currentConstellation); + + final PanelType[] inputList = currentConstellation.first; + final PanelType[] expectedDefaults = currentConstellation.second; + + for (int i = 0; i < inputList.length; i++) { + JSONArray jsonPanels = createConfigsForList(context, inputList, i); + + + // Verify that we still have a default panel, and that it is the expected default panel + + // No need to pass in the prefsEditor since that is only used for the 0->1 migration + jsonPanels = HomeConfigPrefsBackend.migratePrefsFromVersionToVersion(context, testVersion, testVersion + 1, jsonPanels, null); + + final PanelType oldDefaultPanelType = inputList[i]; + final PanelType expectedNewDefaultPanelType = expectedDefaults[i]; + final PanelType newDefaultPanelType = getDefaultPanel(jsonPanels); + + assertNotNull("No default panel set when migrating from " + testVersion + " to " + testVersion + 1 + ", with previous default as " + oldDefaultPanelType.name(), + newDefaultPanelType); + + assertEquals("Migration changed to unexpected default panel - migrating from " + oldDefaultPanelType.name() + ", expected " + expectedNewDefaultPanelType.name() + " but got " + newDefaultPanelType.name(), + newDefaultPanelType, expectedNewDefaultPanelType); + + + // Verify that the panels remaining after the migration correspond to the input panels + // for the next migration + final PanelType[] expectedOutputList = migrationConstellations.get(testVersion + 1).first; + + assertEquals("Number of panels after migration doesn't match expected count", + jsonPanels.length(), expectedOutputList.length); + + checkListContainsExpectedPanels(jsonPanels, expectedOutputList); + } + } + } + + // Test that if all panels are disabled, the migration retains all panels as being disabled + // (in addition to correctly removing panels as necessary). + @Test + public void testMigrationRetainsAllPanelsHiddenAfter6() throws JSONException { + final Context context = RuntimeEnvironment.application; + + final Pair finalConstellation = migrationConstellations.get(HomeConfigPrefsBackend.VERSION); + assertNotNull("It looks like you added a HomeConfig migration, please add an appropriate entry to migrationConstellations", + finalConstellation); + + final int firstTestedVersion = HomeConfigPrefsBackend.VERSION - (migrationConstellations.size() - 1); + + for (int testVersion = HomeConfigPrefsBackend.VERSION - 1; testVersion >= firstTestedVersion; testVersion--) { + final Pair currentConstellation = migrationConstellations.get(testVersion); + assertNotNull("No constellation for version " + testVersion + " - you must provide a constellation for every version upgrade in the list", + currentConstellation); + + final PanelType[] inputList = currentConstellation.first; + + JSONArray jsonPanels = createDisabledConfigsForList(context, inputList); + + jsonPanels = HomeConfigPrefsBackend.migratePrefsFromVersionToVersion(context, testVersion, testVersion + 1, jsonPanels, null); + + // All panels should remain disabled after the migration + checkAllPanelsAreDisabled(jsonPanels); + + // Duplicated from previous test: + // Verify that the panels remaining after the migration correspond to the input panels + // for the next migration + final PanelType[] expectedOutputList = migrationConstellations.get(testVersion + 1).first; + + assertEquals("Number of panels after migration doesn't match expected count", + jsonPanels.length(), expectedOutputList.length); + + checkListContainsExpectedPanels(jsonPanels, expectedOutputList); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconDescriptor.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconDescriptor.java new file mode 100644 index 000000000..05e4576e5 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconDescriptor.java @@ -0,0 +1,56 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +@RunWith(TestRunner.class) +public class TestIconDescriptor { + private static final String ICON_URL = "https://www.mozilla.org/favicon.ico"; + private static final String MIME_TYPE = "image/png"; + private static final int ICON_SIZE = 64; + + @Test + public void testGenericIconDescriptor() { + final IconDescriptor descriptor = IconDescriptor.createGenericIcon(ICON_URL); + + Assert.assertEquals(ICON_URL, descriptor.getUrl()); + Assert.assertNull(descriptor.getMimeType()); + Assert.assertEquals(0, descriptor.getSize()); + Assert.assertEquals(IconDescriptor.TYPE_GENERIC, descriptor.getType()); + } + + @Test + public void testFaviconIconDescriptor() { + final IconDescriptor descriptor = IconDescriptor.createFavicon(ICON_URL, ICON_SIZE, MIME_TYPE); + + Assert.assertEquals(ICON_URL, descriptor.getUrl()); + Assert.assertEquals(MIME_TYPE, descriptor.getMimeType()); + Assert.assertEquals(ICON_SIZE, descriptor.getSize()); + Assert.assertEquals(IconDescriptor.TYPE_FAVICON, descriptor.getType()); + } + + @Test + public void testTouchIconDescriptor() { + final IconDescriptor descriptor = IconDescriptor.createTouchicon(ICON_URL, ICON_SIZE, MIME_TYPE); + + Assert.assertEquals(ICON_URL, descriptor.getUrl()); + Assert.assertEquals(MIME_TYPE, descriptor.getMimeType()); + Assert.assertEquals(ICON_SIZE, descriptor.getSize()); + Assert.assertEquals(IconDescriptor.TYPE_TOUCHICON, descriptor.getType()); + } + + @Test + public void testLookupIconDescriptor() { + final IconDescriptor descriptor = IconDescriptor.createLookupIcon(ICON_URL); + + Assert.assertEquals(ICON_URL, descriptor.getUrl()); + Assert.assertNull(descriptor.getMimeType()); + Assert.assertEquals(0, descriptor.getSize()); + Assert.assertEquals(IconDescriptor.TYPE_LOOKUP, descriptor.getType()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconDescriptorComparator.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconDescriptorComparator.java new file mode 100644 index 000000000..1f4664d08 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconDescriptorComparator.java @@ -0,0 +1,152 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons; + +import org.junit.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import java.util.TreeSet; + +@RunWith(TestRunner.class) +public class TestIconDescriptorComparator { + private static final String TEST_ICON_URL_1 = "http://www.mozilla.org/favicon.ico"; + private static final String TEST_ICON_URL_2 = "http://www.example.org/favicon.ico"; + private static final String TEST_ICON_URL_3 = "http://www.example.com/favicon.ico"; + + private static final String TEST_MIME_TYPE = "image/png"; + private static final int TEST_SIZE = 32; + + @Test + public void testIconsWithTheSameUrlAreTreatedAsEqual() { + final IconDescriptor descriptor1 = IconDescriptor.createGenericIcon(TEST_ICON_URL_1); + final IconDescriptor descriptor2 = IconDescriptor.createGenericIcon(TEST_ICON_URL_1); + + final IconDescriptorComparator comparator = new IconDescriptorComparator(); + + Assert.assertEquals(0, comparator.compare(descriptor1, descriptor2)); + Assert.assertEquals(0, comparator.compare(descriptor2, descriptor1)); + } + + @Test + public void testTouchIconsAreRankedHigherThanFavicons() { + final IconDescriptor faviconDescriptor = IconDescriptor.createFavicon(TEST_ICON_URL_1, TEST_SIZE, TEST_MIME_TYPE); + final IconDescriptor touchIconDescriptor = IconDescriptor.createTouchicon(TEST_ICON_URL_2, TEST_SIZE, TEST_MIME_TYPE); + + final IconDescriptorComparator comparator = new IconDescriptorComparator(); + + Assert.assertEquals(1, comparator.compare(faviconDescriptor, touchIconDescriptor)); + Assert.assertEquals(-1, comparator.compare(touchIconDescriptor, faviconDescriptor)); + } + + @Test + public void testFaviconsAndTouchIconsAreRankedHigherThanGenericIcons() { + final IconDescriptor genericDescriptor = IconDescriptor.createGenericIcon(TEST_ICON_URL_1); + + final IconDescriptor faviconDescriptor = IconDescriptor.createFavicon(TEST_ICON_URL_2, TEST_SIZE, TEST_MIME_TYPE); + final IconDescriptor touchIconDescriptor = IconDescriptor.createTouchicon(TEST_ICON_URL_3, TEST_SIZE, TEST_MIME_TYPE); + + final IconDescriptorComparator comparator = new IconDescriptorComparator(); + + Assert.assertEquals(1, comparator.compare(genericDescriptor, faviconDescriptor)); + Assert.assertEquals(-1, comparator.compare(faviconDescriptor, genericDescriptor)); + + Assert.assertEquals(1, comparator.compare(genericDescriptor, touchIconDescriptor)); + Assert.assertEquals(-1, comparator.compare(touchIconDescriptor, genericDescriptor)); + } + + @Test + public void testLookupIconsAreRankedHigherThanGenericIcons() { + final IconDescriptor genericDescriptor = IconDescriptor.createGenericIcon(TEST_ICON_URL_1); + final IconDescriptor lookupDescriptor = IconDescriptor.createLookupIcon(TEST_ICON_URL_2); + + final IconDescriptorComparator comparator = new IconDescriptorComparator(); + + Assert.assertEquals(1, comparator.compare(genericDescriptor, lookupDescriptor)); + Assert.assertEquals(-1, comparator.compare(lookupDescriptor, genericDescriptor)); + } + + @Test + public void testFaviconsAndTouchIconsAreRankedHigherThanLookupIcons() { + final IconDescriptor lookupDescriptor = IconDescriptor.createLookupIcon(TEST_ICON_URL_1); + + final IconDescriptor faviconDescriptor = IconDescriptor.createFavicon(TEST_ICON_URL_2, TEST_SIZE, TEST_MIME_TYPE); + final IconDescriptor touchIconDescriptor = IconDescriptor.createTouchicon(TEST_ICON_URL_3, TEST_SIZE, TEST_MIME_TYPE); + + final IconDescriptorComparator comparator = new IconDescriptorComparator(); + + Assert.assertEquals(1, comparator.compare(lookupDescriptor, faviconDescriptor)); + Assert.assertEquals(-1, comparator.compare(faviconDescriptor, lookupDescriptor)); + + Assert.assertEquals(1, comparator.compare(lookupDescriptor, touchIconDescriptor)); + Assert.assertEquals(-1, comparator.compare(touchIconDescriptor, lookupDescriptor)); + } + + @Test + public void testLargestIconOfSameTypeIsSelected() { + final IconDescriptor smallDescriptor = IconDescriptor.createFavicon(TEST_ICON_URL_1, 16, TEST_MIME_TYPE); + final IconDescriptor largeDescriptor = IconDescriptor.createFavicon(TEST_ICON_URL_2, 128, TEST_MIME_TYPE); + + final IconDescriptorComparator comparator = new IconDescriptorComparator(); + + Assert.assertEquals(1, comparator.compare(smallDescriptor, largeDescriptor)); + Assert.assertEquals(-1, comparator.compare(largeDescriptor, smallDescriptor)); + } + + @Test + public void testContainerTypesArePreferred() { + final IconDescriptor containerDescriptor = IconDescriptor.createFavicon(TEST_ICON_URL_1, TEST_SIZE, "image/x-icon"); + final IconDescriptor faviconDescriptor = IconDescriptor.createFavicon(TEST_ICON_URL_2, TEST_SIZE, "image/png"); + + final IconDescriptorComparator comparator = new IconDescriptorComparator(); + + Assert.assertEquals(1, comparator.compare(faviconDescriptor, containerDescriptor)); + Assert.assertEquals(-1, comparator.compare(containerDescriptor, faviconDescriptor)); + } + + @Test + public void testWithNoDifferences() { + final IconDescriptor descriptor1 = IconDescriptor.createFavicon(TEST_ICON_URL_1, TEST_SIZE, TEST_MIME_TYPE); + final IconDescriptor descriptor2 = IconDescriptor.createFavicon(TEST_ICON_URL_2, TEST_SIZE, TEST_MIME_TYPE); + + final IconDescriptorComparator comparator = new IconDescriptorComparator(); + + Assert.assertNotEquals(0, comparator.compare(descriptor1, descriptor2)); + Assert.assertNotEquals(0, comparator.compare(descriptor2, descriptor1)); + } + + @Test + public void testWithSameObject() { + final IconDescriptor descriptor = IconDescriptor.createTouchicon(TEST_ICON_URL_1, TEST_SIZE, TEST_MIME_TYPE); + + final IconDescriptorComparator comparator = new IconDescriptorComparator(); + Assert.assertEquals(0, comparator.compare(descriptor, descriptor)); + } + + /** + * This test reconstructs the scenario from bug 1331808. A comparator implementation that does + * not return a consistent order can break the implementation of remove() of the TreeSet class. + */ + @Test + public void testBug1331808() { + TreeSet set = new TreeSet<>(new IconDescriptorComparator()); + + set.add(IconDescriptor.createFavicon("http://example.org/new-logo32.jpg", 0, "")); + set.add(IconDescriptor.createTouchicon("http://example.org/new-logo57.jpg", 0, "")); + set.add(IconDescriptor.createTouchicon("http://example.org/new-logo76.jpg", 76, "")); + set.add(IconDescriptor.createTouchicon("http://example.org/new-logo120.jpg", 120, "")); + set.add(IconDescriptor.createTouchicon("http://example.org/new-logo152.jpg", 114, "")); + set.add(IconDescriptor.createFavicon("http://example.org/02.png", 32, "")); + set.add(IconDescriptor.createFavicon("http://example.org/01.png", 192, "")); + set.add(IconDescriptor.createTouchicon("http://example.org/03.png", 0, "")); + + for (int i = 8; i > 0; i--) { + Assert.assertEquals("items in set before deleting: " + i, i, set.size()); + Assert.assertTrue("item removed successfully: " + i, set.remove(set.first())); + Assert.assertEquals("items in set after deleting: " + i, i - 1, set.size()); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequest.java new file mode 100644 index 000000000..d77ad6a53 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequest.java @@ -0,0 +1,81 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.robolectric.RuntimeEnvironment; + +import java.util.TreeSet; + +import static org.hamcrest.Matchers.any; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +@RunWith(TestRunner.class) +public class TestIconRequest { + private static final String TEST_PAGE_URL = "http://www.mozilla.org"; + private static final String TEST_ICON_URL_1 = "http://www.mozilla.org/favicon.ico"; + private static final String TEST_ICON_URL_2 = "http://www.example.org/favicon.ico"; + + @Test + public void testIconHandling() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .build(); + + Assert.assertEquals(0, request.getIconCount()); + Assert.assertFalse(request.hasIconDescriptors()); + + request.modify() + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL_1)) + .deferBuild(); + + Assert.assertEquals(1, request.getIconCount()); + Assert.assertTrue(request.hasIconDescriptors()); + + request.modify() + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL_2)) + .deferBuild(); + + Assert.assertEquals(2, request.getIconCount()); + Assert.assertTrue(request.hasIconDescriptors()); + + Assert.assertEquals(TEST_ICON_URL_2, request.getBestIcon().getUrl()); + + request.moveToNextIcon(); + + Assert.assertEquals(1, request.getIconCount()); + Assert.assertTrue(request.hasIconDescriptors()); + + Assert.assertEquals(TEST_ICON_URL_1, request.getBestIcon().getUrl()); + + request.moveToNextIcon(); + + Assert.assertEquals(0, request.getIconCount()); + Assert.assertFalse(request.hasIconDescriptors()); + } + + /** + * If removing an icon from the internal set failed then we want to throw an exception. + */ + @Test(expected = IllegalStateException.class) + public void testMoveToNextIconThrowsException() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .build(); + + //noinspection unchecked - Creating a mock of a generic type + request.icons = (TreeSet) mock(TreeSet.class); + + //noinspection SuspiciousMethodCalls + doReturn(false).when(request.icons).remove(anyObject()); + + request.moveToNextIcon(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequestBuilder.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequestBuilder.java new file mode 100644 index 000000000..0743b42d8 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconRequestBuilder.java @@ -0,0 +1,159 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons; + +import org.junit.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.GeckoAppShell; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestIconRequestBuilder { + private static final String TEST_PAGE_URL_1 = "http://www.mozilla.org"; + private static final String TEST_PAGE_URL_2 = "http://www.example.org"; + private static final String TEST_ICON_URL_1 = "http://www.mozilla.org/favicon.ico"; + private static final String TEST_ICON_URL_2 = "http://www.example.org/favicon.ico"; + + @Test + public void testPrivileged() { + IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL_1) + .build(); + + Assert.assertFalse(request.isPrivileged()); + + request.modify() + .privileged(true) + .deferBuild(); + + Assert.assertTrue(request.isPrivileged()); + } + + @Test + public void testPageUrl() { + IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL_1) + .build(); + + Assert.assertEquals(TEST_PAGE_URL_1, request.getPageUrl()); + + request.modify() + .pageUrl(TEST_PAGE_URL_2) + .deferBuild(); + + Assert.assertEquals(TEST_PAGE_URL_2, request.getPageUrl()); + } + + @Test + public void testIcons() { + // Initially a request is empty. + IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL_1) + .build(); + + Assert.assertEquals(0, request.getIconCount()); + + // Adding one icon URL. + request.modify() + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL_1)) + .deferBuild(); + + Assert.assertEquals(1, request.getIconCount()); + + // Adding the same icon URL again is ignored. + request.modify() + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL_1)) + .deferBuild(); + + Assert.assertEquals(1, request.getIconCount()); + + // Adding another new icon URL. + request.modify() + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL_2)) + .deferBuild(); + + Assert.assertEquals(2, request.getIconCount()); + } + + @Test + public void testSkipNetwork() { + IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL_1) + .build(); + + Assert.assertFalse(request.shouldSkipNetwork()); + + request.modify() + .skipNetwork() + .deferBuild(); + + Assert.assertTrue(request.shouldSkipNetwork()); + } + + @Test + public void testSkipDisk() { + IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL_1) + .build(); + + Assert.assertFalse(request.shouldSkipDisk()); + + request.modify() + .skipDisk() + .deferBuild(); + + Assert.assertTrue(request.shouldSkipDisk()); + } + + @Test + public void testSkipMemory() { + IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL_1) + .build(); + + Assert.assertFalse(request.shouldSkipMemory()); + + request.modify() + .skipMemory() + .deferBuild(); + + Assert.assertTrue(request.shouldSkipMemory()); + } + + @Test + public void testExecutionOnBackgroundThread() { + IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL_1) + .build(); + + Assert.assertFalse(request.shouldRunOnBackgroundThread()); + + request.modify() + .executeCallbackOnBackgroundThread() + .deferBuild(); + + Assert.assertTrue(request.shouldRunOnBackgroundThread()); + } + + @Test + public void testForLauncherIcon() { + // This code will call into GeckoAppShell to determine the launcher icon size for this configuration + GeckoAppShell.setApplicationContext(RuntimeEnvironment.application); + + IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL_1) + .build(); + + Assert.assertEquals(32, request.getTargetSize()); + + request.modify() + .forLauncherIcon() + .deferBuild(); + + Assert.assertEquals(48, request.getTargetSize()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconResponse.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconResponse.java new file mode 100644 index 000000000..4c7faa4f8 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconResponse.java @@ -0,0 +1,148 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons; + +import android.graphics.Bitmap; +import android.graphics.Color; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import static org.mockito.Mockito.mock; + +@RunWith(TestRunner.class) +public class TestIconResponse { + private static final String ICON_URL = "http://www.mozilla.org/favicon.ico"; + + @Test + public void testDefaultResponse() { + final Bitmap bitmap = mock(Bitmap.class); + + final IconResponse response = IconResponse.create(bitmap); + + Assert.assertEquals(bitmap, response.getBitmap()); + Assert.assertFalse(response.hasUrl()); + Assert.assertNull(response.getUrl()); + + Assert.assertFalse(response.hasColor()); + Assert.assertEquals(0, response.getColor()); + + Assert.assertFalse(response.isGenerated()); + Assert.assertFalse(response.isFromNetwork()); + Assert.assertFalse(response.isFromDisk()); + Assert.assertFalse(response.isFromMemory()); + } + + @Test + public void testNetworkResponse() { + final Bitmap bitmap = mock(Bitmap.class); + + final IconResponse response = IconResponse.createFromNetwork(bitmap, ICON_URL); + + Assert.assertEquals(bitmap, response.getBitmap()); + Assert.assertTrue(response.hasUrl()); + Assert.assertEquals(ICON_URL, response.getUrl()); + + Assert.assertFalse(response.hasColor()); + Assert.assertEquals(0, response.getColor()); + + Assert.assertFalse(response.isGenerated()); + Assert.assertTrue(response.isFromNetwork()); + Assert.assertFalse(response.isFromDisk()); + Assert.assertFalse(response.isFromMemory()); + } + + @Test + public void testGeneratedResponse() { + final Bitmap bitmap = mock(Bitmap.class); + + final IconResponse response = IconResponse.createGenerated(bitmap, Color.CYAN); + + Assert.assertEquals(bitmap, response.getBitmap()); + Assert.assertFalse(response.hasUrl()); + Assert.assertNull(response.getUrl()); + + Assert.assertTrue(response.hasColor()); + Assert.assertEquals(Color.CYAN, response.getColor()); + + Assert.assertTrue(response.isGenerated()); + Assert.assertFalse(response.isFromNetwork()); + Assert.assertFalse(response.isFromDisk()); + Assert.assertFalse(response.isFromMemory()); + } + + @Test + public void testMemoryResponse() { + final Bitmap bitmap = mock(Bitmap.class); + + final IconResponse response = IconResponse.createFromMemory(bitmap, ICON_URL, Color.CYAN); + + Assert.assertEquals(bitmap, response.getBitmap()); + Assert.assertTrue(response.hasUrl()); + Assert.assertEquals(ICON_URL, response.getUrl()); + + Assert.assertTrue(response.hasColor()); + Assert.assertEquals(Color.CYAN, response.getColor()); + + Assert.assertFalse(response.isGenerated()); + Assert.assertFalse(response.isFromNetwork()); + Assert.assertFalse(response.isFromDisk()); + Assert.assertTrue(response.isFromMemory()); + } + + @Test + public void testDiskResponse() { + final Bitmap bitmap = mock(Bitmap.class); + + final IconResponse response = IconResponse.createFromDisk(bitmap, ICON_URL); + + Assert.assertEquals(bitmap, response.getBitmap()); + Assert.assertTrue(response.hasUrl()); + Assert.assertEquals(ICON_URL, response.getUrl()); + + Assert.assertFalse(response.hasColor()); + Assert.assertEquals(0, response.getColor()); + + Assert.assertFalse(response.isGenerated()); + Assert.assertFalse(response.isFromNetwork()); + Assert.assertTrue(response.isFromDisk()); + Assert.assertFalse(response.isFromMemory()); + } + + @Test + public void testUpdatingColor() { + final IconResponse response = IconResponse.create(mock(Bitmap.class)); + + Assert.assertFalse(response.hasColor()); + Assert.assertEquals(0, response.getColor()); + + response.updateColor(Color.YELLOW); + + Assert.assertTrue(response.hasColor()); + Assert.assertEquals(Color.YELLOW, response.getColor()); + + response.updateColor(Color.MAGENTA); + + Assert.assertTrue(response.hasColor()); + Assert.assertEquals(Color.MAGENTA, response.getColor()); + } + + @Test + public void testUpdatingBitmap() { + final Bitmap originalBitmap = mock(Bitmap.class); + final Bitmap updatedBitmap = mock(Bitmap.class); + + final IconResponse response = IconResponse.create(originalBitmap); + + Assert.assertEquals(originalBitmap, response.getBitmap()); + Assert.assertNotEquals(updatedBitmap, response.getBitmap()); + + response.updateBitmap(updatedBitmap); + + Assert.assertNotEquals(originalBitmap, response.getBitmap()); + Assert.assertEquals(updatedBitmap, response.getBitmap()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconTask.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconTask.java new file mode 100644 index 000000000..77a801988 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconTask.java @@ -0,0 +1,575 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons; + +import android.graphics.Bitmap; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.loader.IconLoader; +import org.mozilla.gecko.icons.preparation.Preparer; +import org.mozilla.gecko.icons.processing.Processor; +import org.robolectric.RuntimeEnvironment; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +@RunWith(TestRunner.class) +public class TestIconTask { + @Test + public void testGeneratorIsInvokedIfAllLoadersFail() { + final List loaders = Arrays.asList( + createFailingLoader(), + createFailingLoader(), + createFailingLoader()); + + final Bitmap bitmap = mock(Bitmap.class); + final IconLoader generator = createSuccessfulLoader(bitmap); + + final IconRequest request = createIconRequest(); + + final IconTask task = new IconTask( + request, + Collections.emptyList(), + loaders, + Collections.emptyList(), + generator); + + final IconResponse response = task.call(); + + // Verify all loaders have been tried + for (IconLoader loader : loaders) { + verify(loader).load(request); + } + + // Verify generator was called + verify(generator).load(request); + + // Verify response contains generated bitmap + Assert.assertEquals(bitmap, response.getBitmap()); + } + + @Test + public void testGeneratorIsNotCalledIfOneLoaderWasSuccessful() { + final List loaders = Collections.singletonList( + createSuccessfulLoader(mock(Bitmap.class))); + + final IconLoader generator = createSuccessfulLoader(mock(Bitmap.class)); + + final IconRequest request = createIconRequest(); + + final IconTask task = new IconTask( + request, + Collections.emptyList(), + loaders, + Collections.emptyList(), + generator); + + final IconResponse response = task.call(); + + // Verify all loaders have been tried + for (IconLoader loader : loaders) { + verify(loader).load(request); + } + + // Verify generator was NOT called + verify(generator, never()).load(request); + + Assert.assertNotNull(response); + } + + @Test + public void testNoLoaderIsInvokedForRequestWithoutUrls() { + final List loaders = Collections.singletonList( + createSuccessfulLoader(mock(Bitmap.class))); + + final Bitmap bitmap = mock(Bitmap.class); + final IconLoader generator = createSuccessfulLoader(bitmap); + + final IconRequest request = createIconRequestWithoutUrls(); + + final IconTask task = new IconTask( + request, + Collections.emptyList(), + loaders, + Collections.emptyList(), + generator); + + final IconResponse response = task.call(); + + // Verify NO loaders have been called + for (IconLoader loader : loaders) { + verify(loader, never()).load(request); + } + + // Verify generator was called + verify(generator).load(request); + + // Verify response contains generated bitmap + Assert.assertEquals(bitmap, response.getBitmap()); + } + + @Test + public void testAllPreparersAreCalledBeforeLoading() { + final List preparers = Arrays.asList( + mock(Preparer.class), + mock(Preparer.class), + mock(Preparer.class), + mock(Preparer.class), + mock(Preparer.class), + mock(Preparer.class)); + + final IconRequest request = createIconRequest(); + + final IconTask task = new IconTask( + request, + preparers, + createListWithSuccessfulLoader(), + Collections.emptyList(), + createGenerator()); + + task.call(); + + // Verify all preparers have been called + for (Preparer preparer : preparers) { + verify(preparer).prepare(request); + } + } + + @Test + public void testSubsequentLoadersAreNotCalledAfterSuccessfulLoad() { + final Bitmap bitmap = mock(Bitmap.class); + + final List loaders = Arrays.asList( + createFailingLoader(), + createFailingLoader(), + createSuccessfulLoader(bitmap), + createSuccessfulLoader(mock(Bitmap.class)), + createFailingLoader(), + createSuccessfulLoader(mock(Bitmap.class))); + + final IconRequest request = createIconRequest(); + + final IconTask task = new IconTask( + request, + Collections.emptyList(), + loaders, + Collections.emptyList(), + createGenerator()); + + final IconResponse response = task.call(); + + // First loaders are called + verify(loaders.get(0)).load(request); + verify(loaders.get(1)).load(request); + verify(loaders.get(2)).load(request); + + // Loaders after successful load are not called + verify(loaders.get(3), never()).load(request); + verify(loaders.get(4), never()).load(request); + verify(loaders.get(5), never()).load(request); + + Assert.assertNotNull(response); + Assert.assertEquals(bitmap, response.getBitmap()); + } + + @Test + public void testNoProcessorIsCalledForUnsuccessfulLoads() { + final IconRequest request = createIconRequest(); + + final List loaders = createListWithFailingLoaders(); + + final List processors = Arrays.asList( + createProcessor(), + createProcessor(), + createProcessor()); + + final IconTask task = new IconTask( + request, + Collections.emptyList(), + loaders, + processors, + createFailingLoader()); + + task.call(); + + // Verify all loaders have been tried + for (IconLoader loader : loaders) { + verify(loader).load(request); + } + + // Verify no processor was called + for (Processor processor : processors) { + verify(processor, never()).process(any(IconRequest.class), any(IconResponse.class)); + } + } + + @Test + public void testAllProcessorsAreCalledAfterSuccessfulLoad() { + final IconRequest request = createIconRequest(); + + final List processors = Arrays.asList( + createProcessor(), + createProcessor(), + createProcessor()); + + final IconTask task = new IconTask( + request, + Collections.emptyList(), + createListWithSuccessfulLoader(), + processors, + createGenerator()); + + IconResponse response = task.call(); + + Assert.assertNotNull(response); + + // Verify that all processors have been called + for (Processor processor : processors) { + verify(processor).process(request, response); + } + } + + @Test + public void testCallbackIsExecutedForSuccessfulLoads() { + final IconCallback callback = mock(IconCallback.class); + + final IconRequest request = createIconRequest(); + request.setCallback(callback); + + final IconTask task = new IconTask( + request, + Collections.emptyList(), + createListWithSuccessfulLoader(), + Collections.emptyList(), + createGenerator()); + + final IconResponse response = task.call(); + + verify(callback).onIconResponse(response); + } + + @Test + public void testCallbackIsNotExecutedIfLoadingFailed() { + final IconCallback callback = mock(IconCallback.class); + + final IconRequest request = createIconRequest(); + request.setCallback(callback); + + final IconTask task = new IconTask( + request, + Collections.emptyList(), + createListWithFailingLoaders(), + Collections.emptyList(), + createFailingLoader()); + + task.call(); + + verify(callback, never()).onIconResponse(any(IconResponse.class)); + } + + @Test + public void testCallbackIsExecutedWithGeneratorResult() { + final IconCallback callback = mock(IconCallback.class); + + final IconRequest request = createIconRequest(); + request.setCallback(callback); + + final IconTask task = new IconTask( + request, + Collections.emptyList(), + createListWithFailingLoaders(), + Collections.emptyList(), + createGenerator()); + + final IconResponse response = task.call(); + + verify(callback).onIconResponse(response); + } + + @Test + public void testTaskCancellationWhileLoading() { + // We simulate the cancellation by injecting a loader that interrupts the thread. + final IconLoader cancellingLoader = spy(new IconLoader() { + @Override + public IconResponse load(IconRequest request) { + Thread.currentThread().interrupt(); + return null; + } + }); + + final List preparers = createListOfPreparers(); + final List processors = createListOfProcessors(); + + final List loaders = Arrays.asList( + createFailingLoader(), + createFailingLoader(), + cancellingLoader, + createFailingLoader(), + createSuccessfulLoader(mock(Bitmap.class))); + + final IconRequest request = createIconRequest(); + + final IconTask task = new IconTask( + request, + preparers, + loaders, + processors, + createGenerator()); + + final IconResponse response = task.call(); + Assert.assertNull(response); + + // Verify that all preparers are called + for (Preparer preparer : preparers) { + verify(preparer).prepare(request); + } + + // Verify that first loaders are called + verify(loaders.get(0)).load(request); + verify(loaders.get(1)).load(request); + + // Verify that our loader that interrupts the thread is called + verify(loaders.get(2)).load(request); + + // Verify that all other loaders are not called + verify(loaders.get(3), never()).load(request); + verify(loaders.get(4), never()).load(request); + + // Verify that no processors are called + for (Processor processor : processors) { + verify(processor, never()).process(eq(request), any(IconResponse.class)); + } + } + + @Test + public void testTaskCancellationWhileProcessing() { + final Processor cancellingProcessor = spy(new Processor() { + @Override + public void process(IconRequest request, IconResponse response) { + Thread.currentThread().interrupt(); + } + }); + + final List preparers = createListOfPreparers(); + + final List loaders = Arrays.asList( + createFailingLoader(), + createFailingLoader(), + createSuccessfulLoader(mock(Bitmap.class))); + + final List processors = Arrays.asList( + createProcessor(), + createProcessor(), + cancellingProcessor, + createProcessor(), + createProcessor()); + + final IconRequest request = createIconRequest(); + + final IconTask task = new IconTask( + request, + preparers, + loaders, + processors, + createGenerator()); + + final IconResponse response = task.call(); + Assert.assertNull(response); + + // Verify that all preparers are called + for (Preparer preparer : preparers) { + verify(preparer).prepare(request); + } + + // Verify that all loaders are called + for (IconLoader loader : loaders) { + verify(loader).load(request); + } + + // Verify that first processors are called + verify(processors.get(0)).process(eq(request), any(IconResponse.class)); + verify(processors.get(1)).process(eq(request), any(IconResponse.class)); + + // Verify that cancelling processor is called + verify(processors.get(2)).process(eq(request), any(IconResponse.class)); + + // Verify that subsequent processors are not called + verify(processors.get(3), never()).process(eq(request), any(IconResponse.class)); + verify(processors.get(4), never()).process(eq(request), any(IconResponse.class)); + } + + @Test + public void testTaskCancellationWhilePerparing() { + final Preparer failingPreparer = spy(new Preparer() { + @Override + public void prepare(IconRequest request) { + Thread.currentThread().interrupt(); + } + }); + + final List preparers = Arrays.asList( + mock(Preparer.class), + mock(Preparer.class), + failingPreparer, + mock(Preparer.class), + mock(Preparer.class)); + + final List loaders = createListWithSuccessfulLoader(); + final List processors = createListOfProcessors(); + + final IconRequest request = createIconRequest(); + + final IconTask task = new IconTask( + request, + preparers, + loaders, + processors, + createGenerator()); + + final IconResponse response = task.call(); + Assert.assertNull(response); + + // Verify that first preparers are called + verify(preparers.get(0)).prepare(request); + verify(preparers.get(1)).prepare(request); + + // Verify that cancelling preparer is called + verify(preparers.get(2)).prepare(request); + + // Verify that subsequent preparers are not called + verify(preparers.get(3), never()).prepare(request); + verify(preparers.get(4), never()).prepare(request); + + // Verify that no loaders are called + for (IconLoader loader : loaders) { + verify(loader, never()).load(request); + } + + // Verify that no processors are called + for (Processor processor : processors) { + verify(processor, never()).process(eq(request), any(IconResponse.class)); + } + } + + @Test + public void testNoLoadersOrProcessorsAreExecutedForPrepareOnlyTasks() { + final List preparers = createListOfPreparers(); + final List loaders = createListWithSuccessfulLoader(); + final List processors = createListOfProcessors(); + final IconLoader generator = createGenerator(); + + final IconRequest request = createIconRequest() + .modify() + .prepareOnly() + .build(); + + final IconTask task = new IconTask( + request, + preparers, + loaders, + processors, + generator); + + IconResponse response = task.call(); + + Assert.assertNull(response); + + // Verify that all preparers are called + for (Preparer preparer : preparers) { + verify(preparer).prepare(request); + } + + // Verify that no loaders are called + for (IconLoader loader : loaders) { + verify(loader, never()).load(request); + } + + // Verify that no processors are called + for (Processor processor : processors) { + verify(processor, never()).process(eq(request), any(IconResponse.class)); + } + } + + public List createListWithSuccessfulLoader() { + return Arrays.asList( + createFailingLoader(), + createFailingLoader(), + createSuccessfulLoader(mock(Bitmap.class)), + createFailingLoader()); + } + + public List createListWithFailingLoaders() { + return Arrays.asList( + createFailingLoader(), + createFailingLoader(), + createFailingLoader(), + createFailingLoader(), + createFailingLoader()); + } + + public List createListOfPreparers() { + return Arrays.asList( + mock(Preparer.class), + mock(Preparer.class), + mock(Preparer.class), + mock(Preparer.class), + mock(Preparer.class)); + } + + public IconLoader createFailingLoader() { + final IconLoader loader = mock(IconLoader.class); + doReturn(null).when(loader).load(any(IconRequest.class)); + return loader; + } + + public IconLoader createSuccessfulLoader(Bitmap bitmap) { + IconResponse response = IconResponse.create(bitmap); + + final IconLoader loader = mock(IconLoader.class); + doReturn(response).when(loader).load(any(IconRequest.class)); + return loader; + } + + public List createListOfProcessors() { + return Arrays.asList( + mock(Processor.class), + mock(Processor.class), + mock(Processor.class), + mock(Processor.class), + mock(Processor.class)); + } + + public IconRequest createIconRequest() { + return Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createGenericIcon("http://www.mozilla.org/favicon.ico")) + .build(); + } + + public IconRequest createIconRequestWithoutUrls() { + return Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .build(); + } + + public IconLoader createGenerator() { + return createSuccessfulLoader(mock(Bitmap.class)); + } + + public Processor createProcessor() { + return mock(Processor.class); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconsHelper.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconsHelper.java new file mode 100644 index 000000000..f40e2f629 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/TestIconsHelper.java @@ -0,0 +1,139 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons; + +import android.annotation.SuppressLint; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.util.GeckoJarReader; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestIconsHelper { + @SuppressLint("AuthLeak") // Lint and Android Studio try to prevent developers from writing code + // with credentials in the URL (user:password@host). But in this case + // we explicitly want to do that, so we suppress the warnings. + @Test + public void testGuessDefaultFaviconURL() { + // Empty values + + Assert.assertNull(IconsHelper.guessDefaultFaviconURL(null)); + Assert.assertNull(IconsHelper.guessDefaultFaviconURL("")); + Assert.assertNull(IconsHelper.guessDefaultFaviconURL(" ")); + + // Special about: URLs. + + Assert.assertEquals( + "about:home", + IconsHelper.guessDefaultFaviconURL("about:home")); + + Assert.assertEquals( + "about:", + IconsHelper.guessDefaultFaviconURL("about:")); + + Assert.assertEquals( + "about:addons", + IconsHelper.guessDefaultFaviconURL("about:addons")); + + // Non http(s) URLS + + final String jarUrl = GeckoJarReader.getJarURL(RuntimeEnvironment.application, "chrome/chrome/content/branding/favicon64.png"); + Assert.assertEquals(jarUrl, IconsHelper.guessDefaultFaviconURL(jarUrl)); + + Assert.assertNull(IconsHelper.guessDefaultFaviconURL("content://some.random.provider/icons")); + + Assert.assertNull(IconsHelper.guessDefaultFaviconURL("ftp://ftp.public.mozilla.org/this/is/made/up")); + + Assert.assertNull(IconsHelper.guessDefaultFaviconURL("file:///")); + + Assert.assertNull(IconsHelper.guessDefaultFaviconURL("file:///system/path")); + + // Various http(s) URLs + + Assert.assertEquals("http://www.mozilla.org/favicon.ico", + IconsHelper.guessDefaultFaviconURL("http://www.mozilla.org/")); + + Assert.assertEquals("https://www.mozilla.org/favicon.ico", + IconsHelper.guessDefaultFaviconURL("https://www.mozilla.org/en-US/firefox/products/")); + + Assert.assertEquals("https://example.org/favicon.ico", + IconsHelper.guessDefaultFaviconURL("https://example.org")); + + Assert.assertEquals("http://user:password@example.org:9991/favicon.ico", + IconsHelper.guessDefaultFaviconURL("http://user:password@example.org:9991/status/760492829949001728")); + + Assert.assertEquals("https://localhost:8888/favicon.ico", + IconsHelper.guessDefaultFaviconURL("https://localhost:8888/path/folder/file?some=query¶ms=none")); + + Assert.assertEquals("http://192.168.0.1/favicon.ico", + IconsHelper.guessDefaultFaviconURL("http://192.168.0.1/local/action.cgi")); + + Assert.assertEquals("https://medium.com/favicon.ico", + IconsHelper.guessDefaultFaviconURL("https://medium.com/firefox-mobile-engineering/firefox-for-android-hack-week-recap-f1ab12f5cc44#.rpmzz15ia")); + + // Some broken, partial URLs + + Assert.assertNull(IconsHelper.guessDefaultFaviconURL("http:")); + Assert.assertNull(IconsHelper.guessDefaultFaviconURL("http://")); + Assert.assertNull(IconsHelper.guessDefaultFaviconURL("https:/")); + } + + @Test + public void testIsContainerType() { + // Empty values + Assert.assertFalse(IconsHelper.isContainerType(null)); + Assert.assertFalse(IconsHelper.isContainerType("")); + Assert.assertFalse(IconsHelper.isContainerType(" ")); + + // Values that don't make any sense. + Assert.assertFalse(IconsHelper.isContainerType("Hello World")); + Assert.assertFalse(IconsHelper.isContainerType("no/no/no")); + Assert.assertFalse(IconsHelper.isContainerType("42")); + + // Actual image MIME types that are not container types + Assert.assertFalse(IconsHelper.isContainerType("image/png")); + Assert.assertFalse(IconsHelper.isContainerType("application/bmp")); + Assert.assertFalse(IconsHelper.isContainerType("image/gif")); + Assert.assertFalse(IconsHelper.isContainerType("image/x-windows-bitmap")); + Assert.assertFalse(IconsHelper.isContainerType("image/jpeg")); + Assert.assertFalse(IconsHelper.isContainerType("application/x-png")); + + // MIME types of image container + Assert.assertTrue(IconsHelper.isContainerType("image/vnd.microsoft.icon")); + Assert.assertTrue(IconsHelper.isContainerType("image/ico")); + Assert.assertTrue(IconsHelper.isContainerType("image/icon")); + Assert.assertTrue(IconsHelper.isContainerType("image/x-icon")); + Assert.assertTrue(IconsHelper.isContainerType("text/ico")); + Assert.assertTrue(IconsHelper.isContainerType("application/ico")); + } + + @Test + public void testCanDecodeType() { + // Empty values + Assert.assertFalse(IconsHelper.canDecodeType(null)); + Assert.assertFalse(IconsHelper.canDecodeType("")); + Assert.assertFalse(IconsHelper.canDecodeType(" ")); + + // Some things we can't decode (or that just aren't images) + Assert.assertFalse(IconsHelper.canDecodeType("image/svg+xml")); + Assert.assertFalse(IconsHelper.canDecodeType("video/avi")); + Assert.assertFalse(IconsHelper.canDecodeType("text/plain")); + Assert.assertFalse(IconsHelper.canDecodeType("image/x-quicktime")); + Assert.assertFalse(IconsHelper.canDecodeType("image/tiff")); + Assert.assertFalse(IconsHelper.canDecodeType("application/zip")); + + // Some image MIME types we definitely can decode + Assert.assertTrue(IconsHelper.canDecodeType("image/bmp")); + Assert.assertTrue(IconsHelper.canDecodeType("image/x-icon")); + Assert.assertTrue(IconsHelper.canDecodeType("image/png")); + Assert.assertTrue(IconsHelper.canDecodeType("image/jpg")); + Assert.assertTrue(IconsHelper.canDecodeType("image/jpeg")); + Assert.assertTrue(IconsHelper.canDecodeType("image/ico")); + Assert.assertTrue(IconsHelper.canDecodeType("image/icon")); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestContentProviderLoader.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestContentProviderLoader.java new file mode 100644 index 000000000..58bb3ddf9 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestContentProviderLoader.java @@ -0,0 +1,31 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.loader; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestContentProviderLoader { + @Test + public void testNothingIsLoadedForHttpUrls() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createGenericIcon( + "https://www.mozilla.org/media/img/favicon/apple-touch-icon-180x180.00050c5b754e.png")) + .build(); + + IconLoader loader = new ContentProviderLoader(); + IconResponse response = loader.load(request); + + Assert.assertNull(response); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestDataUriLoader.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestDataUriLoader.java new file mode 100644 index 000000000..1fe6ad1a7 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestDataUriLoader.java @@ -0,0 +1,46 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.loader; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestDataUriLoader { + @Test + public void testNothingIsLoadedForHttpUrls() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createGenericIcon( + "https://www.mozilla.org/media/img/favicon/apple-touch-icon-180x180.00050c5b754e.png")) + .build(); + + IconLoader loader = new DataUriLoader(); + IconResponse response = loader.load(request); + + Assert.assertNull(response); + } + + @Test + public void testIconIsLoadedFromDataUri() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createGenericIcon( + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAEklEQVR4AWP4z8AAxCDiP8N/AB3wBPxcBee7AAAAAElFTkSuQmCC")) + .build(); + + IconLoader loader = new DataUriLoader(); + IconResponse response = loader.load(request); + + Assert.assertNotNull(response); + Assert.assertNotNull(response.getBitmap()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestDiskLoader.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestDiskLoader.java new file mode 100644 index 000000000..809c35102 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestDiskLoader.java @@ -0,0 +1,94 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.loader; + +import android.graphics.Bitmap; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.mozilla.gecko.icons.storage.DiskStorage; +import org.robolectric.RuntimeEnvironment; + +import java.io.OutputStream; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +@RunWith(TestRunner.class) +public class TestDiskLoader { + private static final String TEST_PAGE_URL = "http://www.mozilla.org"; + private static final String TEST_ICON_URL = "https://example.org/favicon.ico"; + + @Test + public void testLoadingFromEmptyCache() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .build(); + + final IconLoader loader = new DiskLoader(); + final IconResponse response = loader.load(request); + + Assert.assertNull(response); + } + + @Test + public void testLoadingAfterAddingEntry() { + final Bitmap bitmap = createMockedBitmap(); + final IconResponse originalResponse = IconResponse.createFromNetwork(bitmap, TEST_ICON_URL); + + DiskStorage.get(RuntimeEnvironment.application) + .putIcon(originalResponse); + + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .build(); + + final IconLoader loader = new DiskLoader(); + final IconResponse loadedResponse = loader.load(request); + + Assert.assertNotNull(loadedResponse); + + // The responses are not the same: The original response was stored to disk and loaded from + // disk again. It's a copy effectively. + Assert.assertNotEquals(originalResponse, loadedResponse); + } + + @Test + public void testNothingIsLoadedIfDiskShouldBeSkipped() { + final Bitmap bitmap = createMockedBitmap(); + final IconResponse originalResponse = IconResponse.createFromNetwork(bitmap, TEST_ICON_URL); + + DiskStorage.get(RuntimeEnvironment.application) + .putIcon(originalResponse); + + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .skipDisk() + .build(); + + final IconLoader loader = new DiskLoader(); + final IconResponse loadedResponse = loader.load(request); + + Assert.assertNull(loadedResponse); + } + + private Bitmap createMockedBitmap() { + final Bitmap bitmap = mock(Bitmap.class); + + doReturn(true).when(bitmap).compress(any(Bitmap.CompressFormat.class), anyInt(), any(OutputStream.class)); + + return bitmap; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestIconDownloader.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestIconDownloader.java new file mode 100644 index 000000000..533f14395 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestIconDownloader.java @@ -0,0 +1,112 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.loader; + +import android.content.Context; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.mozilla.gecko.icons.storage.FailureCache; +import org.robolectric.RuntimeEnvironment; + +import java.net.HttpURLConnection; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +@RunWith(TestRunner.class) +public class TestIconDownloader { + /** + * Scenario: A request with a non HTTP URL (data:image/*) is executed. + * + * Verify that: + * * No download is performed. + */ + @Test + public void testDownloaderDoesNothingForNonHttpUrls() throws Exception { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createGenericIcon( + "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAEklEQVR4AWP4z8AAxCDiP8N/AB3wBPxcBee7AAAAAElFTkSuQmCC")) + .build(); + + final IconDownloader downloader = spy(new IconDownloader()); + IconResponse response = downloader.load(request); + + Assert.assertNull(response); + + verify(downloader, never()).downloadAndDecodeImage(any(Context.class), anyString()); + verify(downloader, never()).connectTo(anyString()); + } + + /** + * Scenario: Request contains an URL and server returns 301 with location header (always the same URL). + * + * Verify that: + * * Download code stops and does not loop forever. + */ + @Test + public void testRedirectsAreFollowedButNotInCircles() throws Exception { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createFavicon( + "https://www.mozilla.org/media/img/favicon.52506929be4c.ico", + 32, + "image/x-icon")) + .build(); + + HttpURLConnection mockedConnection = mock(HttpURLConnection.class); + doReturn(301).when(mockedConnection).getResponseCode(); + doReturn("http://example.org/favicon.ico").when(mockedConnection).getHeaderField("Location"); + + final IconDownloader downloader = spy(new IconDownloader()); + doReturn(mockedConnection).when(downloader).connectTo(anyString()); + IconResponse response = downloader.load(request); + + Assert.assertNull(response); + + verify(downloader).connectTo("https://www.mozilla.org/media/img/favicon.52506929be4c.ico"); + verify(downloader).connectTo("http://example.org/favicon.ico"); + } + + /** + * Scenario: Request contains an URL and server returns HTTP 404. + * + * Verify that: + * * URL is added to failure cache. + */ + @Test + public void testUrlIsAddedToFailureCacheIfServerReturnsClientError() throws Exception { + final String faviconUrl = "https://www.mozilla.org/404.ico"; + + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createFavicon(faviconUrl, 32, "image/x-icon")) + .build(); + + HttpURLConnection mockedConnection = mock(HttpURLConnection.class); + doReturn(404).when(mockedConnection).getResponseCode(); + + Assert.assertFalse(FailureCache.get().isKnownFailure(faviconUrl)); + + final IconDownloader downloader = spy(new IconDownloader()); + doReturn(mockedConnection).when(downloader).connectTo(anyString()); + IconResponse response = downloader.load(request); + + Assert.assertNull(response); + + Assert.assertTrue(FailureCache.get().isKnownFailure(faviconUrl)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestIconGenerator.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestIconGenerator.java new file mode 100644 index 000000000..70e341365 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestIconGenerator.java @@ -0,0 +1,128 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.loader; + +import android.graphics.Bitmap; + +import org.junit.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.R; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestIconGenerator { + @Test + public void testNoIconIsGeneratorIfThereAreIconUrlsToLoadFrom() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createGenericIcon( + "https://www.mozilla.org/media/img/favicon/apple-touch-icon-180x180.00050c5b754e.png")) + .icon(IconDescriptor.createGenericIcon( + "https://www.mozilla.org/media/img/favicon.52506929be4c.ico")) + .build(); + + IconLoader loader = new IconGenerator(); + IconResponse response = loader.load(request); + + Assert.assertNull(response); + } + + @Test + public void testIconIsGeneratedForLastUrl() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createGenericIcon( + "https://www.mozilla.org/media/img/favicon/apple-touch-icon-180x180.00050c5b754e.png")) + .build(); + + IconLoader loader = new IconGenerator(); + IconResponse response = loader.load(request); + + Assert.assertNotNull(response); + Assert.assertNotNull(response.getBitmap()); + } + + @Test + public void testRepresentativeCharacter() { + Assert.assertEquals("M", IconGenerator.getRepresentativeCharacter("https://mozilla.org")); + Assert.assertEquals("W", IconGenerator.getRepresentativeCharacter("http://wikipedia.org")); + Assert.assertEquals("P", IconGenerator.getRepresentativeCharacter("http://plus.google.com")); + Assert.assertEquals("E", IconGenerator.getRepresentativeCharacter("https://en.m.wikipedia.org/wiki/Main_Page")); + + // Stripping common prefixes + Assert.assertEquals("T", IconGenerator.getRepresentativeCharacter("http://www.theverge.com")); + Assert.assertEquals("F", IconGenerator.getRepresentativeCharacter("https://m.facebook.com")); + Assert.assertEquals("T", IconGenerator.getRepresentativeCharacter("https://mobile.twitter.com")); + + // Special urls + Assert.assertEquals("?", IconGenerator.getRepresentativeCharacter("file:///")); + Assert.assertEquals("S", IconGenerator.getRepresentativeCharacter("file:///system/")); + Assert.assertEquals("P", IconGenerator.getRepresentativeCharacter("ftp://people.mozilla.org/test")); + + // No values + Assert.assertEquals("?", IconGenerator.getRepresentativeCharacter("")); + Assert.assertEquals("?", IconGenerator.getRepresentativeCharacter(null)); + + // Rubbish + Assert.assertEquals("Z", IconGenerator.getRepresentativeCharacter("zZz")); + Assert.assertEquals("Ö", IconGenerator.getRepresentativeCharacter("ölkfdpou3rkjaslfdköasdfo8")); + Assert.assertEquals("?", IconGenerator.getRepresentativeCharacter("_*+*'##")); + Assert.assertEquals("ツ", IconGenerator.getRepresentativeCharacter("¯\\_(ツ)_/¯")); + Assert.assertEquals("ಠ", IconGenerator.getRepresentativeCharacter("ಠ_ಠ Look of Disapproval")); + + // Non-ASCII + Assert.assertEquals("Ä", IconGenerator.getRepresentativeCharacter("http://www.ätzend.de")); + Assert.assertEquals("名", IconGenerator.getRepresentativeCharacter("http://名がドメイン.com")); + Assert.assertEquals("C", IconGenerator.getRepresentativeCharacter("http://√.com")); + Assert.assertEquals("ß", IconGenerator.getRepresentativeCharacter("http://ß.de")); + Assert.assertEquals("Ԛ", IconGenerator.getRepresentativeCharacter("http://ԛәлп.com/")); // cyrillic + + // Punycode + Assert.assertEquals("X", IconGenerator.getRepresentativeCharacter("http://xn--tzend-fra.de")); // ätzend.de + Assert.assertEquals("X", IconGenerator.getRepresentativeCharacter("http://xn--V8jxj3d1dzdz08w.com")); // 名がドメイン.com + + // Numbers + Assert.assertEquals("1", IconGenerator.getRepresentativeCharacter("https://www.1and1.com/")); + + // IP + Assert.assertEquals("1", IconGenerator.getRepresentativeCharacter("https://192.168.0.1")); + } + + @Test + public void testPickColor() { + final int color = IconGenerator.pickColor("http://m.facebook.com"); + + // Color does not change + for (int i = 0; i < 100; i++) { + Assert.assertEquals(color, IconGenerator.pickColor("http://m.facebook.com")); + } + + // Color is stable for "similar" hosts. + Assert.assertEquals(color, IconGenerator.pickColor("https://m.facebook.com")); + Assert.assertEquals(color, IconGenerator.pickColor("http://facebook.com")); + Assert.assertEquals(color, IconGenerator.pickColor("http://www.facebook.com")); + Assert.assertEquals(color, IconGenerator.pickColor("http://www.facebook.com/foo/bar/foobar?mobile=1")); + } + + @Test + public void testGeneratingFavicon() { + final IconResponse response = IconGenerator.generate(RuntimeEnvironment.application, "http://m.facebook.com"); + final Bitmap bitmap = response.getBitmap(); + + Assert.assertNotNull(bitmap); + + final int size = RuntimeEnvironment.application.getResources().getDimensionPixelSize(R.dimen.favicon_bg); + Assert.assertEquals(size, bitmap.getWidth()); + Assert.assertEquals(size, bitmap.getHeight()); + + Assert.assertEquals(Bitmap.Config.ARGB_8888, bitmap.getConfig()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestJarLoader.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestJarLoader.java new file mode 100644 index 000000000..48f0c26eb --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestJarLoader.java @@ -0,0 +1,31 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.loader; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestJarLoader { + @Test + public void testNothingIsLoadedForHttpUrls() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createGenericIcon( + "https://www.mozilla.org/media/img/favicon/apple-touch-icon-180x180.00050c5b754e.png")) + .build(); + + IconLoader loader = new JarLoader(); + IconResponse response = loader.load(request); + + Assert.assertNull(response); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestLegacyLoader.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestLegacyLoader.java new file mode 100644 index 000000000..eecf76788 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestLegacyLoader.java @@ -0,0 +1,152 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.loader; + +import android.graphics.Bitmap; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.GeckoProfile; +import org.mozilla.gecko.background.db.DelegatingTestContentProvider; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.db.BrowserDB; +import org.mozilla.gecko.db.BrowserProvider; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.shadows.ShadowContentResolver; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Iterator; +import java.util.concurrent.ConcurrentHashMap; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +@RunWith(TestRunner.class) +public class TestLegacyLoader { + private static final String TEST_PAGE_URL = "http://www.mozilla.org"; + private static final String TEST_ICON_URL = "https://example.org/favicon.ico"; + private static final String TEST_ICON_URL_2 = "https://example.com/page/favicon.ico"; + private static final String TEST_ICON_URL_3 = "https://example.net/icon/favicon.ico"; + + @Test + public void testDatabaseIsQueriesForNormalRequestsWithNetworkSkipped() { + // We're going to query BrowserProvider via LegacyLoader, and will access a database. + // We need to ensure we close our db connection properly. + // This is the only test in this class that actually accesses a database. If that changes, + // move BrowserProvider registration into a @Before method, and provider.shutdown into @After. + final BrowserProvider provider = new BrowserProvider(); + provider.onCreate(); + ShadowContentResolver.registerProvider(BrowserContract.AUTHORITY, new DelegatingTestContentProvider(provider)); + try { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .skipNetwork() + .build(); + + final LegacyLoader loader = spy(new LegacyLoader()); + final IconResponse response = loader.load(request); + + verify(loader).loadBitmapFromDatabase(request); + Assert.assertNull(response); + // Close any open db connections. + } finally { + provider.shutdown(); + } + } + + @Test + public void testNothingIsLoadedIfNetworkIsNotSkipped() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .build(); + + final LegacyLoader loader = spy(new LegacyLoader()); + final IconResponse response = loader.load(request); + + verify(loader, never()).loadBitmapFromDatabase(request); + + Assert.assertNull(response); + } + + @Test + public void testNothingIsLoadedIfDiskSHouldBeSkipped() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .skipDisk() + .build(); + + final LegacyLoader loader = spy(new LegacyLoader()); + final IconResponse response = loader.load(request); + + verify(loader, never()).loadBitmapFromDatabase(request); + + Assert.assertNull(response); + } + + @Test + public void testLoadedBitmapIsReturnedAsResponse() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .skipNetwork() + .build(); + + final Bitmap bitmap = mock(Bitmap.class); + + final LegacyLoader loader = spy(new LegacyLoader()); + doReturn(bitmap).when(loader).loadBitmapFromDatabase(request); + + final IconResponse response = loader.load(request); + + Assert.assertNotNull(response); + Assert.assertEquals(bitmap, response.getBitmap()); + } + + @Test + public void testLoaderOnlyLoadsIfThereIsOneIconLeft() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL_2)) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL_3)) + .skipNetwork() + .build(); + + final LegacyLoader loader = spy(new LegacyLoader()); + doReturn(mock(Bitmap.class)).when(loader).loadBitmapFromDatabase(request); + + // First load doesn't load an icon. + Assert.assertNull(loader.load(request)); + + // Second load doesn't load an icon. + removeFirstIcon(request); + Assert.assertNull(loader.load(request)); + + // Now only one icon is left and a response will be returned. + removeFirstIcon(request); + Assert.assertNotNull(loader.load(request)); + } + + private void removeFirstIcon(IconRequest request) { + final Iterator iterator = request.getIconIterator(); + if (iterator.hasNext()) { + iterator.next(); + iterator.remove(); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestMemoryLoader.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestMemoryLoader.java new file mode 100644 index 000000000..414ac8cc7 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/loader/TestMemoryLoader.java @@ -0,0 +1,78 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.loader; + +import android.graphics.Bitmap; +import android.graphics.Color; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.mozilla.gecko.icons.storage.MemoryStorage; +import org.robolectric.RuntimeEnvironment; + +import static org.mockito.Mockito.mock; + +@RunWith(TestRunner.class) +public class TestMemoryLoader { + private static final String TEST_PAGE_URL = "http://www.mozilla.org"; + private static final String TEST_ICON_URL = "https://example.org/favicon.ico"; + + @Before + public void setUp() { + // Make sure to start with an empty memory cache. + MemoryStorage.get().evictAll(); + } + + @Test + public void testStoringAndLoadingFromMemory() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .build(); + + final IconLoader loader = new MemoryLoader(); + + Assert.assertNull(loader.load(request)); + + final Bitmap bitmap = mock(Bitmap.class); + final IconResponse response = IconResponse.create(bitmap); + response.updateColor(Color.MAGENTA); + + MemoryStorage.get().putIcon(TEST_ICON_URL, response); + + final IconResponse loadedResponse = loader.load(request); + + Assert.assertNotNull(loadedResponse); + Assert.assertEquals(bitmap, loadedResponse.getBitmap()); + Assert.assertEquals(Color.MAGENTA, loadedResponse.getColor()); + } + + @Test + public void testNothingIsLoadedIfMemoryShouldBeSkipped() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .skipMemory() + .build(); + + final IconLoader loader = new MemoryLoader(); + + Assert.assertNull(loader.load(request)); + + final Bitmap bitmap = mock(Bitmap.class); + final IconResponse response = IconResponse.create(bitmap); + + MemoryStorage.get().putIcon(TEST_ICON_URL, response); + + Assert.assertNull(loader.load(request)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestAboutPagesPreparer.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestAboutPagesPreparer.java new file mode 100644 index 000000000..f0d4cb7e2 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestAboutPagesPreparer.java @@ -0,0 +1,73 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ +package org.mozilla.gecko.icons.preparation; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.AboutPages; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.Icons; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestAboutPagesPreparer { + private static final String[] ABOUT_PAGES = { + AboutPages.ACCOUNTS, + AboutPages.ADDONS, + AboutPages.CONFIG, + AboutPages.DOWNLOADS, + AboutPages.FIREFOX, + AboutPages.HEALTHREPORT, + AboutPages.HOME, + AboutPages.UPDATER + }; + + @Test + public void testPreparerAddsUrlsForAllAboutPages() { + final Preparer preparer = new AboutPagesPreparer(); + + for (String url : ABOUT_PAGES) { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(url) + .build(); + + Assert.assertEquals(0, request.getIconCount()); + + preparer.prepare(request); + + Assert.assertEquals("Added icon URL for URL: " + url, 1, request.getIconCount()); + } + } + + @Test + public void testPrepareDoesNotAddUrlForGenericHttpUrl() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .build(); + + Assert.assertEquals(0, request.getIconCount()); + + final Preparer preparer = new AboutPagesPreparer(); + preparer.prepare(request); + + Assert.assertEquals(0, request.getIconCount()); + } + + @Test + public void testAddedUrlHasJarScheme() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(AboutPages.DOWNLOADS) + .build(); + + final Preparer preparer = new AboutPagesPreparer(); + preparer.prepare(request); + + Assert.assertEquals(1, request.getIconCount()); + + final String url = request.getBestIcon().getUrl(); + Assert.assertNotNull(url); + Assert.assertTrue(url.startsWith("jar:jar:")); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestAddDefaultIconUrl.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestAddDefaultIconUrl.java new file mode 100644 index 000000000..ce5e82d0b --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestAddDefaultIconUrl.java @@ -0,0 +1,79 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.preparation; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.Icons; +import org.robolectric.RuntimeEnvironment; + +import java.util.Iterator; + +@RunWith(TestRunner.class) +public class TestAddDefaultIconUrl { + @Test + public void testAddingDefaultUrl() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createTouchicon( + "https://www.mozilla.org/media/img/favicon/apple-touch-icon-180x180.00050c5b754e.png", + 180, + "image/png")) + .icon(IconDescriptor.createFavicon( + "https://www.mozilla.org/media/img/favicon.52506929be4c.ico", + 32, + "image/x-icon")) + .icon(IconDescriptor.createFavicon( + "jar:jar:wtf.png", + 16, + "image/png")) + .build(); + + + Assert.assertEquals(3, request.getIconCount()); + Assert.assertFalse(containsUrl(request, "http://www.mozilla.org/favicon.ico")); + + Preparer preparer = new AddDefaultIconUrl(); + preparer.prepare(request); + + Assert.assertEquals(4, request.getIconCount()); + Assert.assertTrue(containsUrl(request, "http://www.mozilla.org/favicon.ico")); + } + + @Test + public void testDefaultUrlIsNotAddedIfItAlreadyExists() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl("http://www.mozilla.org") + .icon(IconDescriptor.createFavicon( + "http://www.mozilla.org/favicon.ico", + 32, + "image/x-icon")) + .build(); + + Assert.assertEquals(1, request.getIconCount()); + + Preparer preparer = new AddDefaultIconUrl(); + preparer.prepare(request); + + Assert.assertEquals(1, request.getIconCount()); + } + + private boolean containsUrl(IconRequest request, String url) { + final Iterator iterator = request.getIconIterator(); + + while (iterator.hasNext()) { + IconDescriptor descriptor = iterator.next(); + + if (descriptor.getUrl().equals(url)) { + return true; + } + } + + return false; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterKnownFailureUrls.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterKnownFailureUrls.java new file mode 100644 index 000000000..67584c4cf --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterKnownFailureUrls.java @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.preparation; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.Icons; +import org.mozilla.gecko.icons.storage.FailureCache; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestFilterKnownFailureUrls { + private static final String TEST_PAGE_URL = "http://www.mozilla.org"; + private static final String TEST_ICON_URL = "https://example.org/favicon.ico"; + + @Before + public void setUp() { + // Make sure we always start with an empty cache. + FailureCache.get().evictAll(); + } + + @Test + public void testFilterDoesNothingByDefault() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .build(); + + Assert.assertEquals(1, request.getIconCount()); + + final Preparer preparer = new FilterKnownFailureUrls(); + preparer.prepare(request); + + Assert.assertEquals(1, request.getIconCount()); + } + + @Test + public void testFilterKnownFailureUrls() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .build(); + + Assert.assertEquals(1, request.getIconCount()); + + FailureCache.get().rememberFailure(TEST_ICON_URL); + + final Preparer preparer = new FilterKnownFailureUrls(); + preparer.prepare(request); + + Assert.assertEquals(0, request.getIconCount()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterMimeTypes.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterMimeTypes.java new file mode 100644 index 000000000..e8339b4e9 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterMimeTypes.java @@ -0,0 +1,67 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.preparation; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.Icons; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestFilterMimeTypes { + private static final String TEST_PAGE_URL = "http://www.mozilla.org"; + private static final String TEST_ICON_URL = "https://example.org/favicon.ico"; + private static final String TEST_ICON_URL_2 = "https://mozilla.org/favicon.ico"; + + @Test + public void testUrlsWithoutMimeTypesAreNotFiltered() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_URL)) + .build(); + + Assert.assertEquals(1, request.getIconCount()); + + final Preparer preparer = new FilterMimeTypes(); + preparer.prepare(request); + + Assert.assertEquals(1, request.getIconCount()); + } + + @Test + public void testUnknownMimeTypesAreFiltered() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createFavicon(TEST_ICON_URL, 256, "image/zaphod")) + .icon(IconDescriptor.createFavicon(TEST_ICON_URL_2, 128, "audio/mpeg")) + .build(); + + Assert.assertEquals(2, request.getIconCount()); + + final Preparer preparer = new FilterMimeTypes(); + preparer.prepare(request); + + Assert.assertEquals(0, request.getIconCount()); + } + + @Test + public void testKnownMimeTypesAreNotFiltered() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createFavicon(TEST_ICON_URL, 256, "image/x-icon")) + .icon(IconDescriptor.createFavicon(TEST_ICON_URL_2, 128, "image/png")) + .build(); + + Assert.assertEquals(2, request.getIconCount()); + + final Preparer preparer = new FilterMimeTypes(); + preparer.prepare(request); + + Assert.assertEquals(2, request.getIconCount()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterPrivilegedUrls.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterPrivilegedUrls.java new file mode 100644 index 000000000..53fcbd05a --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestFilterPrivilegedUrls.java @@ -0,0 +1,86 @@ +package org.mozilla.gecko.icons.preparation; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.Icons; +import org.robolectric.RuntimeEnvironment; + +import java.util.Iterator; + +@RunWith(TestRunner.class) +public class TestFilterPrivilegedUrls { + private static final String TEST_PAGE_URL = "http://www.mozilla.org"; + + private static final String TEST_ICON_HTTP_URL = "https://www.mozilla.org/media/img/favicon/apple-touch-icon-180x180.00050c5b754e.png"; + private static final String TEST_ICON_HTTP_URL_2 = "https://www.mozilla.org/media/img/favicon.52506929be4c.ico"; + private static final String TEST_ICON_JAR_URL = "jar:jar:wtf.png"; + + @Test + public void testFiltering() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_HTTP_URL)) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_HTTP_URL_2)) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_JAR_URL)) + .build(); + + Assert.assertEquals(3, request.getIconCount()); + + Assert.assertTrue(containsUrl(request, TEST_ICON_HTTP_URL)); + Assert.assertTrue(containsUrl(request, TEST_ICON_HTTP_URL_2)); + Assert.assertTrue(containsUrl(request, TEST_ICON_JAR_URL)); + + Preparer preparer = new FilterPrivilegedUrls(); + preparer.prepare(request); + + Assert.assertEquals(2, request.getIconCount()); + + Assert.assertTrue(containsUrl(request, TEST_ICON_HTTP_URL)); + Assert.assertTrue(containsUrl(request, TEST_ICON_HTTP_URL_2)); + Assert.assertFalse(containsUrl(request, TEST_ICON_JAR_URL)); + } + + @Test + public void testNothingIsFilteredForPrivilegedRequests() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_HTTP_URL)) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_HTTP_URL_2)) + .icon(IconDescriptor.createGenericIcon(TEST_ICON_JAR_URL)) + .privileged(true) + .build(); + + Assert.assertEquals(3, request.getIconCount()); + + Assert.assertTrue(containsUrl(request, TEST_ICON_HTTP_URL)); + Assert.assertTrue(containsUrl(request, TEST_ICON_HTTP_URL_2)); + Assert.assertTrue(containsUrl(request, TEST_ICON_JAR_URL)); + + Preparer preparer = new FilterPrivilegedUrls(); + preparer.prepare(request); + + Assert.assertEquals(3, request.getIconCount()); + + Assert.assertTrue(containsUrl(request, TEST_ICON_HTTP_URL)); + Assert.assertTrue(containsUrl(request, TEST_ICON_HTTP_URL_2)); + Assert.assertTrue(containsUrl(request, TEST_ICON_JAR_URL)); + } + + private boolean containsUrl(IconRequest request, String url) { + final Iterator iterator = request.getIconIterator(); + + while (iterator.hasNext()) { + IconDescriptor descriptor = iterator.next(); + + if (descriptor.getUrl().equals(url)) { + return true; + } + } + + return false; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestLookupIconUrl.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestLookupIconUrl.java new file mode 100644 index 000000000..99bac076b --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/preparation/TestLookupIconUrl.java @@ -0,0 +1,101 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.preparation; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.Icons; +import org.mozilla.gecko.icons.storage.DiskStorage; +import org.mozilla.gecko.icons.storage.MemoryStorage; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestLookupIconUrl { + private static final String TEST_PAGE_URL = "http://www.mozilla.org"; + + private static final String TEST_ICON_URL_1 = "http://www.mozilla.org/favicon.ico"; + private static final String TEST_ICON_URL_2 = "http://example.org/favicon.ico"; + private static final String TEST_ICON_URL_3 = "http://example.com/favicon.ico"; + private static final String TEST_ICON_URL_4 = "http://example.net/favicon.ico"; + + + @Before + public void setUp() { + MemoryStorage.get().evictAll(); + } + + @Test + public void testNoIconUrlIsAddedByDefault() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .build(); + + Assert.assertEquals(0, request.getIconCount()); + + Preparer preparer = new LookupIconUrl(); + preparer.prepare(request); + + Assert.assertEquals(0, request.getIconCount()); + } + + @Test + public void testIconUrlIsAddedFromMemory() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .build(); + + MemoryStorage.get().putMapping(request, TEST_ICON_URL_1); + + Assert.assertEquals(0, request.getIconCount()); + + Preparer preparer = new LookupIconUrl(); + preparer.prepare(request); + + Assert.assertEquals(1, request.getIconCount()); + + Assert.assertEquals(TEST_ICON_URL_1, request.getBestIcon().getUrl()); + } + + @Test + public void testIconUrlIsAddedFromDisk() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .build(); + + DiskStorage.get(RuntimeEnvironment.application).putMapping(request, TEST_ICON_URL_2); + + Assert.assertEquals(0, request.getIconCount()); + + Preparer preparer = new LookupIconUrl(); + preparer.prepare(request); + + Assert.assertEquals(1, request.getIconCount()); + + Assert.assertEquals(TEST_ICON_URL_2, request.getBestIcon().getUrl()); + } + + @Test + public void testIconUrlIsAddedFromMemoryBeforeUsingDiskStorage() { + final IconRequest request = Icons.with(RuntimeEnvironment.application) + .pageUrl(TEST_PAGE_URL) + .build(); + + MemoryStorage.get().putMapping(request, TEST_ICON_URL_3); + DiskStorage.get(RuntimeEnvironment.application).putMapping(request, TEST_ICON_URL_4); + + Assert.assertEquals(0, request.getIconCount()); + + Preparer preparer = new LookupIconUrl(); + preparer.prepare(request); + + Assert.assertEquals(1, request.getIconCount()); + + Assert.assertEquals(TEST_ICON_URL_3, request.getBestIcon().getUrl()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestColorProcessor.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestColorProcessor.java new file mode 100644 index 000000000..6057c0776 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestColorProcessor.java @@ -0,0 +1,59 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.processing; + +import android.graphics.Bitmap; +import android.graphics.Color; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconResponse; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +@RunWith(TestRunner.class) +public class TestColorProcessor { + @Test + public void testExtractingColor() { + final IconResponse response = IconResponse.create(createRedBitmapMock()); + + Assert.assertFalse(response.hasColor()); + Assert.assertEquals(0, response.getColor()); + + final Processor processor = new ColorProcessor(); + processor.process(null, response); + + Assert.assertTrue(response.hasColor()); + Assert.assertEquals(Color.RED, response.getColor()); + } + + private Bitmap createRedBitmapMock() { + final Bitmap bitmap = mock(Bitmap.class); + + doReturn(1).when(bitmap).getWidth(); + doReturn(1).when(bitmap).getHeight(); + + doAnswer(new Answer() { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + Object[] args = invocation.getArguments(); + int[] pixels = (int[]) args[0]; + for (int i = 0; i < pixels.length; i++) { + pixels[i] = Color.RED; + } + return null; + } + }).when(bitmap).getPixels(any(int[].class), anyInt(), anyInt(), anyInt(), anyInt(), anyInt(), anyInt()); + + return bitmap; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestDiskProcessor.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestDiskProcessor.java new file mode 100644 index 000000000..eea5c9bf6 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestDiskProcessor.java @@ -0,0 +1,100 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.processing; + +import android.graphics.Bitmap; +import android.graphics.Color; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.mozilla.gecko.icons.storage.DiskStorage; +import org.robolectric.RuntimeEnvironment; + +import java.io.OutputStream; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +@RunWith(TestRunner.class) +public class TestDiskProcessor { + private static final String PAGE_URL = "https://www.mozilla.org"; + private static final String ICON_URL = "https://www.mozilla.org/favicon.ico"; + + @Test + public void testNetworkResponseIsStoredInCache() { + final IconRequest request = createTestRequest(); + final IconResponse response = createTestNetworkResponse(); + + final DiskStorage storage = DiskStorage.get(RuntimeEnvironment.application); + Assert.assertNull(storage.getIcon(ICON_URL)); + + final Processor processor = new DiskProcessor(); + processor.process(request, response); + + Assert.assertNotNull(storage.getIcon(ICON_URL)); + } + + @Test + public void testGeneratedResponseIsNotStored() { + final IconRequest request = createTestRequest(); + final IconResponse response = createGeneratedResponse(); + + final DiskStorage storage = DiskStorage.get(RuntimeEnvironment.application); + Assert.assertNull(storage.getIcon(ICON_URL)); + + final Processor processor = new DiskProcessor(); + processor.process(request, response); + + Assert.assertNull(storage.getIcon(ICON_URL)); + } + + @Test + public void testNothingIsStoredIfDiskShouldBeSkipped() { + final IconRequest request = createTestRequest() + .modify() + .skipDisk() + .build(); + final IconResponse response = createTestNetworkResponse(); + + final DiskStorage storage = DiskStorage.get(RuntimeEnvironment.application); + Assert.assertNull(storage.getIcon(ICON_URL)); + + final Processor processor = new DiskProcessor(); + processor.process(request, response); + + Assert.assertNull(storage.getIcon(ICON_URL)); + } + + private IconRequest createTestRequest() { + return Icons.with(RuntimeEnvironment.application) + .pageUrl(PAGE_URL) + .icon(IconDescriptor.createGenericIcon(ICON_URL)) + .build(); + } + + public IconResponse createTestNetworkResponse() { + return IconResponse.createFromNetwork(createMockedBitmap(), ICON_URL); + } + + public IconResponse createGeneratedResponse() { + return IconResponse.createGenerated(createMockedBitmap(), Color.WHITE); + } + + private Bitmap createMockedBitmap() { + final Bitmap bitmap = mock(Bitmap.class); + + doReturn(true).when(bitmap).compress(any(Bitmap.CompressFormat.class), anyInt(), any(OutputStream.class)); + + return bitmap; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestMemoryProcessor.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestMemoryProcessor.java new file mode 100644 index 000000000..fbc1e0baf --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestMemoryProcessor.java @@ -0,0 +1,134 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.processing; + +import android.graphics.Bitmap; +import android.graphics.Color; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.mozilla.gecko.icons.storage.MemoryStorage; +import org.robolectric.RuntimeEnvironment; + +import static org.mockito.Mockito.mock; + +@RunWith(TestRunner.class) +public class TestMemoryProcessor { + private static final String PAGE_URL = "https://www.mozilla.org"; + private static final String ICON_URL = "https://www.mozilla.org/favicon.ico"; + private static final String DATA_URL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAEklEQVR4AWP4z8AAxCDiP8N/AB3wBPxcBee7AAAAAElFTkSuQmCC"; + + @Before + public void setUp() { + MemoryStorage.get().evictAll(); + } + + @Test + public void testResponsesAreStoredInMemory() { + final IconRequest request = createTestRequest(); + + Assert.assertNull(MemoryStorage.get().getIcon(ICON_URL)); + Assert.assertNull(MemoryStorage.get().getMapping(PAGE_URL)); + + final Processor processor = new MemoryProcessor(); + processor.process(request, createTestResponse()); + + Assert.assertNotNull(MemoryStorage.get().getIcon(ICON_URL)); + Assert.assertNotNull(MemoryStorage.get().getMapping(PAGE_URL)); + } + + @Test + public void testNothingIsStoredIfMemoryShouldBeSkipped() { + final IconRequest request = createTestRequest() + .modify() + .skipMemory() + .build(); + + Assert.assertNull(MemoryStorage.get().getIcon(ICON_URL)); + Assert.assertNull(MemoryStorage.get().getMapping(PAGE_URL)); + + final Processor processor = new MemoryProcessor(); + processor.process(request, createTestResponse()); + + Assert.assertNull(MemoryStorage.get().getIcon(ICON_URL)); + Assert.assertNull(MemoryStorage.get().getMapping(PAGE_URL)); + } + + @Test + public void testNothingIsStoredForRequestsWithoutUrl() { + final IconRequest request = createTestRequestWithoutIconUrl(); + + Assert.assertNull(MemoryStorage.get().getIcon(ICON_URL)); + Assert.assertNull(MemoryStorage.get().getMapping(PAGE_URL)); + + final Processor processor = new MemoryProcessor(); + processor.process(request, createTestResponse()); + + Assert.assertNull(MemoryStorage.get().getIcon(ICON_URL)); + Assert.assertNull(MemoryStorage.get().getMapping(PAGE_URL)); + } + + @Test + public void testNothingIsStoredForGeneratedResponses() { + final IconRequest request = createTestRequest(); + + Assert.assertNull(MemoryStorage.get().getIcon(ICON_URL)); + Assert.assertNull(MemoryStorage.get().getMapping(PAGE_URL)); + + final Processor processor = new MemoryProcessor(); + processor.process(request, createGeneratedTestResponse()); + + Assert.assertNull(MemoryStorage.get().getIcon(ICON_URL)); + Assert.assertNull(MemoryStorage.get().getMapping(PAGE_URL)); + } + + @Test + public void testNothingIsStoredForDataUris() { + final IconRequest request = createDataUriTestRequest(); + + Assert.assertNull(MemoryStorage.get().getIcon(DATA_URL)); + Assert.assertNull(MemoryStorage.get().getMapping(PAGE_URL)); + + final Processor processor = new MemoryProcessor(); + processor.process(request, createTestResponse()); + + Assert.assertNull(MemoryStorage.get().getIcon(DATA_URL)); + Assert.assertNull(MemoryStorage.get().getMapping(PAGE_URL)); + } + + private IconRequest createTestRequest() { + return Icons.with(RuntimeEnvironment.application) + .pageUrl(PAGE_URL) + .icon(IconDescriptor.createGenericIcon(ICON_URL)) + .build(); + } + + private IconRequest createTestRequestWithoutIconUrl() { + return Icons.with(RuntimeEnvironment.application) + .pageUrl(PAGE_URL) + .build(); + } + + private IconRequest createDataUriTestRequest() { + return Icons.with(RuntimeEnvironment.application) + .pageUrl(PAGE_URL) + .icon(IconDescriptor.createGenericIcon(DATA_URL)) + .build(); + } + + private IconResponse createTestResponse() { + return IconResponse.create(mock(Bitmap.class)); + } + + private IconResponse createGeneratedTestResponse() { + return IconResponse.createGenerated(mock(Bitmap.class), Color.GREEN); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestResizingProcessor.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestResizingProcessor.java new file mode 100644 index 000000000..dbcb4e2ee --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/icons/processing/TestResizingProcessor.java @@ -0,0 +1,111 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.icons.processing; + +import android.graphics.Bitmap; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.icons.IconDescriptor; +import org.mozilla.gecko.icons.IconRequest; +import org.mozilla.gecko.icons.IconResponse; +import org.mozilla.gecko.icons.Icons; +import org.robolectric.RuntimeEnvironment; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyInt; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; + +@RunWith(TestRunner.class) +public class TestResizingProcessor { + private static final String PAGE_URL = "https://www.mozilla.org"; + private static final String ICON_URL = "https://www.mozilla.org/favicon.ico"; + + @Test + public void testBitmapIsNotResizedIfItAlreadyHasTheTargetSize() { + final IconRequest request = createTestRequest(); + + final Bitmap bitmap = createBitmapMock(request.getTargetSize()); + final IconResponse response = spy(IconResponse.create(bitmap)); + + final ResizingProcessor processor = spy(new ResizingProcessor()); + processor.process(request, response); + + verify(processor, never()).resize(any(Bitmap.class), anyInt()); + verify(bitmap, never()).recycle(); + verify(response, never()).updateBitmap(any(Bitmap.class)); + } + + @Test + public void testLargerBitmapsAreResized() { + final IconRequest request = createTestRequest(); + + final Bitmap bitmap = createBitmapMock(request.getTargetSize() * 2); + final IconResponse response = spy(IconResponse.create(bitmap)); + + final ResizingProcessor processor = spy(new ResizingProcessor()); + final Bitmap resizedBitmap = mock(Bitmap.class); + doReturn(resizedBitmap).when(processor).resize(any(Bitmap.class), anyInt()); + processor.process(request, response); + + verify(processor).resize(bitmap, request.getTargetSize()); + verify(bitmap).recycle(); + verify(response).updateBitmap(resizedBitmap); + } + + @Test + public void testBitmapIsUpscaledToTargetSize() { + final IconRequest request = createTestRequest(); + + final Bitmap bitmap = createBitmapMock(request.getTargetSize() / 2 + 1); + final IconResponse response = spy(IconResponse.create(bitmap)); + + final ResizingProcessor processor = spy(new ResizingProcessor()); + final Bitmap resizedBitmap = mock(Bitmap.class); + doReturn(resizedBitmap).when(processor).resize(any(Bitmap.class), anyInt()); + processor.process(request, response); + + verify(processor).resize(bitmap, request.getTargetSize()); + verify(bitmap).recycle(); + verify(response).updateBitmap(resizedBitmap); + } + + @Test + public void testBitmapIsNotScaledMoreThanTwoTimesTheSize() { + final IconRequest request = createTestRequest(); + + final Bitmap bitmap = createBitmapMock(5); + final IconResponse response = spy(IconResponse.create(bitmap)); + + final ResizingProcessor processor = spy(new ResizingProcessor()); + final Bitmap resizedBitmap = mock(Bitmap.class); + doReturn(resizedBitmap).when(processor).resize(any(Bitmap.class), anyInt()); + processor.process(request, response); + + verify(processor).resize(bitmap, 10); + verify(bitmap).recycle(); + verify(response).updateBitmap(resizedBitmap); + } + + private IconRequest createTestRequest() { + return Icons.with(RuntimeEnvironment.application) + .pageUrl(PAGE_URL) + .icon(IconDescriptor.createGenericIcon(ICON_URL)) + .build(); + } + + private Bitmap createBitmapMock(int size) { + final Bitmap bitmap = mock(Bitmap.class); + + doReturn(size).when(bitmap).getWidth(); + doReturn(size).when(bitmap).getHeight(); + + return bitmap; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/permissions/TestPermissions.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/permissions/TestPermissions.java new file mode 100644 index 000000000..07fbab493 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/permissions/TestPermissions.java @@ -0,0 +1,253 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.permissions; + +import android.Manifest; +import android.app.Activity; +import android.content.Context; +import android.content.pm.PackageManager; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; + +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import static org.mockito.Mockito.*; + +@RunWith(TestRunner.class) +public class TestPermissions { + @Test + public void testSuccessRunnableIsExecutedIfPermissionsAreGranted() { + Permissions.setPermissionHelper(mockGrantingHelper()); + + Runnable onPermissionsGranted = mock(Runnable.class); + Runnable onPermissionsDenied = mock(Runnable.class); + + Permissions.from(mockActivity()) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .andFallback(onPermissionsDenied) + .run(onPermissionsGranted); + + verify(onPermissionsDenied, never()).run(); + verify(onPermissionsGranted).run(); + } + + @Test + public void testFallbackRunnableIsExecutedIfPermissionsAreDenied() { + Permissions.setPermissionHelper(mockDenyingHelper()); + + Runnable onPermissionsGranted = mock(Runnable.class); + Runnable onPermissionsDenied = mock(Runnable.class); + + Activity activity = mockActivity(); + + Permissions.from(activity) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .andFallback(onPermissionsDenied) + .run(onPermissionsGranted); + + Permissions.onRequestPermissionsResult(activity, new String[]{ + Manifest.permission.WRITE_EXTERNAL_STORAGE + }, new int[]{ + PackageManager.PERMISSION_DENIED + }); + + verify(onPermissionsDenied).run(); + verify(onPermissionsGranted, never()).run(); + } + + @Test + public void testPromptingForNotGrantedPermissions() { + Activity activity = mockActivity(); + + PermissionsHelper helper = mockDenyingHelper(); + Permissions.setPermissionHelper(helper); + + Permissions.from(activity) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .andFallback(mock(Runnable.class)) + .run(mock(Runnable.class)); + + verify(helper).prompt(anyActivity(), any(String[].class)); + + Permissions.onRequestPermissionsResult(activity, new String[0], new int[0]); + } + + @Test + public void testMultipleRequestsAreQueuedAndDispatchedSequentially() { + Activity activity = mockActivity(); + + PermissionsHelper helper = mockDenyingHelper(); + Permissions.setPermissionHelper(helper); + + Runnable onFirstPermissionGranted = mock(Runnable.class); + Runnable onSecondPermissionDenied = mock(Runnable.class); + + Permissions.from(activity) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .andFallback(mock(Runnable.class)) + .run(onFirstPermissionGranted); + + Permissions.from(activity) + .withPermissions(Manifest.permission.CAMERA) + .andFallback(onSecondPermissionDenied) + .run(mock(Runnable.class)); + + + Permissions.onRequestPermissionsResult(activity, new String[] { + Manifest.permission.WRITE_EXTERNAL_STORAGE + }, new int[] { + PackageManager.PERMISSION_GRANTED + }); + + verify(onFirstPermissionGranted).run(); + verify(onSecondPermissionDenied, never()).run(); // Second request is queued but not executed yet + + Permissions.onRequestPermissionsResult(activity, new String[]{ + Manifest.permission.CAMERA + }, new int[]{ + PackageManager.PERMISSION_DENIED + }); + + verify(onFirstPermissionGranted).run(); + verify(onSecondPermissionDenied).run(); + + verify(helper, times(2)).prompt(anyActivity(), any(String[].class)); + } + + @Test + public void testSecondRequestWillNotPromptIfPermissionHasBeenGranted() { + Activity activity = mockActivity(); + + PermissionsHelper helper = mock(PermissionsHelper.class); + Permissions.setPermissionHelper(helper); + when(helper.hasPermissions(anyContext(), anyPermissions())) + .thenReturn(false) + .thenReturn(false) + .thenReturn(true); // Revaluation is successful + + Permissions.from(activity) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .andFallback(mock(Runnable.class)) + .run(mock(Runnable.class)); + + Permissions.from(activity) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .andFallback(mock(Runnable.class)) + .run(mock(Runnable.class)); + + Permissions.onRequestPermissionsResult(activity, new String[]{ + Manifest.permission.WRITE_EXTERNAL_STORAGE + }, new int[]{ + PackageManager.PERMISSION_GRANTED + }); + + verify(helper, times(1)).prompt(anyActivity(), any(String[].class)); + } + + @Test + public void testEmptyPermissionsArrayWillExecuteRunnableAndNotTryToPrompt() { + PermissionsHelper helper = spy(new PermissionsHelper()); + Permissions.setPermissionHelper(helper); + + Runnable onPermissionGranted = mock(Runnable.class); + Runnable onPermissionDenied = mock(Runnable.class); + + Permissions.from(mockActivity()) + .withPermissions() + .andFallback(onPermissionDenied) + .run(onPermissionGranted); + + verify(onPermissionGranted).run(); + verify(onPermissionDenied, never()).run(); + verify(helper, never()).prompt(anyActivity(), any(String[].class)); + } + + @Test + public void testDoNotPromptBehavior() { + PermissionsHelper helper = mockDenyingHelper(); + Permissions.setPermissionHelper(helper); + + Permissions.from(mockActivity()) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .doNotPrompt() + .andFallback(mock(Runnable.class)) + .run(mock(Runnable.class)); + + verify(helper, never()).prompt(anyActivity(), any(String[].class)); + } + + @Test(expected = IllegalStateException.class) + public void testThrowsExceptionIfNeedstoPromptWithNonActivityContext() { + Permissions.setPermissionHelper(mockDenyingHelper()); + + Permissions.from(mock(Context.class)) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .andFallback(mock(Runnable.class)) + .run(mock(Runnable.class)); + } + + @Test + public void testDoNotPromptIfFalse() { + Activity activity = mockActivity(); + + PermissionsHelper helper = mockDenyingHelper(); + Permissions.setPermissionHelper(helper); + + Permissions.from(activity) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .doNotPromptIf(false) + .andFallback(mock(Runnable.class)) + .run(mock(Runnable.class)); + + verify(helper).prompt(anyActivity(), any(String[].class)); + + Permissions.onRequestPermissionsResult(activity, new String[0], new int[0]); + } + + @Test + public void testDoNotPromptIfTrue() { + PermissionsHelper helper = mockDenyingHelper(); + Permissions.setPermissionHelper(helper); + + Permissions.from(mockActivity()) + .withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE) + .doNotPromptIf(true) + .andFallback(mock(Runnable.class)) + .run(mock(Runnable.class)); + + verify(helper, never()).prompt(anyActivity(), any(String[].class)); + } + + private Activity mockActivity() { + return mock(Activity.class); + } + + private PermissionsHelper mockGrantingHelper() { + PermissionsHelper helper = mock(PermissionsHelper.class); + doReturn(true).when(helper).hasPermissions(any(Context.class), anyPermissions()); + return helper; + } + + private PermissionsHelper mockDenyingHelper() { + PermissionsHelper helper = mock(PermissionsHelper.class); + doReturn(false).when(helper).hasPermissions(any(Context.class), anyPermissions()); + return helper; + } + + private String anyPermissions() { + return Matchers.anyVararg(); + } + + private Activity anyActivity() { + return any(Activity.class); + } + + private Context anyContext() { + return any(Context.class); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/TestPushManager.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/TestPushManager.java new file mode 100644 index 000000000..42ae0f543 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/TestPushManager.java @@ -0,0 +1,238 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.push; + +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.AppConstants; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.gcm.GcmTokenClient; +import org.robolectric.RuntimeEnvironment; + +import java.util.UUID; + +import static org.mockito.Matchers.anyBoolean; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + + +@RunWith(TestRunner.class) +public class TestPushManager { + private PushState state; + private GcmTokenClient gcmTokenClient; + private PushClient pushClient; + private PushManager manager; + + @Before + public void setUp() throws Exception { + state = new PushState(RuntimeEnvironment.application, "test.json"); + gcmTokenClient = mock(GcmTokenClient.class); + doReturn(new Fetched("opaque-gcm-token", System.currentTimeMillis())).when(gcmTokenClient).getToken(anyString(), anyBoolean()); + + // Configure a mock PushClient. + pushClient = mock(PushClient.class); + doReturn(new RegisterUserAgentResponse("opaque-uaid", "opaque-secret")) + .when(pushClient) + .registerUserAgent(anyString()); + + doReturn(new SubscribeChannelResponse("opaque-chid", "https://localhost:8085/opaque-push-endpoint")) + .when(pushClient) + .subscribeChannel(anyString(), anyString(), isNull(String.class)); + + PushManager.PushClientFactory pushClientFactory = mock(PushManager.PushClientFactory.class); + doReturn(pushClient).when(pushClientFactory).getPushClient(anyString(), anyBoolean()); + + manager = new PushManager(state, gcmTokenClient, pushClientFactory); + } + + private void assertOnlyConfigured(PushRegistration registration, String endpoint, boolean debug) { + Assert.assertNotNull(registration); + Assert.assertEquals(registration.autopushEndpoint, endpoint); + Assert.assertEquals(registration.debug, debug); + Assert.assertNull(registration.uaid.value); + } + + private void assertRegistered(PushRegistration registration, String endpoint, boolean debug) { + Assert.assertNotNull(registration); + Assert.assertEquals(registration.autopushEndpoint, endpoint); + Assert.assertEquals(registration.debug, debug); + Assert.assertNotNull(registration.uaid.value); + } + + private void assertSubscribed(PushSubscription subscription) { + Assert.assertNotNull(subscription); + Assert.assertNotNull(subscription.chid); + } + + @Test + public void testConfigure() throws Exception { + PushRegistration registration = manager.configure("default", "http://localhost:8081", false, System.currentTimeMillis()); + assertOnlyConfigured(registration, "http://localhost:8081", false); + + registration = manager.configure("default", "http://localhost:8082", true, System.currentTimeMillis()); + assertOnlyConfigured(registration, "http://localhost:8082", true); + } + + @Test(expected=PushManager.ProfileNeedsConfigurationException.class) + public void testRegisterBeforeConfigure() throws Exception { + PushRegistration registration = state.getRegistration("default"); + Assert.assertNull(registration); + + // Trying to register a User Agent fails before configuration. + manager.registerUserAgent("default", System.currentTimeMillis()); + } + + @Test + public void testRegister() throws Exception { + PushRegistration registration = manager.configure("default", "http://localhost:8082", false, System.currentTimeMillis()); + assertOnlyConfigured(registration, "http://localhost:8082", false); + + // Let's register a User Agent, so that we can witness unregistration. + registration = manager.registerUserAgent("default", System.currentTimeMillis()); + assertRegistered(registration, "http://localhost:8082", false); + + // Changing the debug flag should update but not try to unregister the User Agent. + registration = manager.configure("default", "http://localhost:8082", true, System.currentTimeMillis()); + assertRegistered(registration, "http://localhost:8082", true); + + // Changing the configuration endpoint should update and try to unregister the User Agent. + registration = manager.configure("default", "http://localhost:8083", true, System.currentTimeMillis()); + assertOnlyConfigured(registration, "http://localhost:8083", true); + } + + @Test + public void testRegisterMultipleProfiles() throws Exception { + PushRegistration registration1 = manager.configure("default1", "http://localhost:8081", true, System.currentTimeMillis()); + PushRegistration registration2 = manager.configure("default2", "http://localhost:8082", true, System.currentTimeMillis()); + assertOnlyConfigured(registration1, "http://localhost:8081", true); + assertOnlyConfigured(registration2, "http://localhost:8082", true); + verify(gcmTokenClient, times(0)).getToken(anyString(), anyBoolean()); + + registration1 = manager.registerUserAgent("default1", System.currentTimeMillis()); + assertRegistered(registration1, "http://localhost:8081", true); + + registration2 = manager.registerUserAgent("default2", System.currentTimeMillis()); + assertRegistered(registration2, "http://localhost:8082", true); + + // Just the debug flag should not unregister the User Agent. + registration1 = manager.configure("default1", "http://localhost:8081", false, System.currentTimeMillis()); + assertRegistered(registration1, "http://localhost:8081", false); + + // But the configuration endpoint should unregister the correct User Agent. + registration2 = manager.configure("default2", "http://localhost:8083", false, System.currentTimeMillis()); + } + + @Test + public void testSubscribeChannel() throws Exception { + manager.configure("default", "http://localhost:8080", false, System.currentTimeMillis()); + PushRegistration registration = manager.registerUserAgent("default", System.currentTimeMillis()); + assertRegistered(registration, "http://localhost:8080", false); + + // We should be able to register with non-null serviceData. + final JSONObject webpushData = new JSONObject(); + webpushData.put("version", 5); + PushSubscription subscription = manager.subscribeChannel("default", "webpush", webpushData, null, System.currentTimeMillis()); + assertSubscribed(subscription); + + subscription = manager.registrationForSubscription(subscription.chid).getSubscription(subscription.chid); + Assert.assertNotNull(subscription); + Assert.assertEquals(5, subscription.serviceData.get("version")); + + // We should be able to register with null serviceData. + subscription = manager.subscribeChannel("default", "sync", null, null, System.currentTimeMillis()); + assertSubscribed(subscription); + + subscription = manager.registrationForSubscription(subscription.chid).getSubscription(subscription.chid); + Assert.assertNotNull(subscription); + Assert.assertNull(subscription.serviceData); + } + + @Test + public void testUnsubscribeChannel() throws Exception { + manager.configure("default", "http://localhost:8080", false, System.currentTimeMillis()); + PushRegistration registration = manager.registerUserAgent("default", System.currentTimeMillis()); + assertRegistered(registration, "http://localhost:8080", false); + + // We should be able to register with non-null serviceData. + final JSONObject webpushData = new JSONObject(); + webpushData.put("version", 5); + PushSubscription subscription = manager.subscribeChannel("default", "webpush", webpushData, null, System.currentTimeMillis()); + assertSubscribed(subscription); + + // No exception is success. + manager.unsubscribeChannel(subscription.chid); + } + + public void testUnsubscribeUnknownChannel() throws Exception { + manager.configure("default", "http://localhost:8080", false, System.currentTimeMillis()); + PushRegistration registration = manager.registerUserAgent("default", System.currentTimeMillis()); + assertRegistered(registration, "http://localhost:8080", false); + + doThrow(new RuntimeException()) + .when(pushClient) + .unsubscribeChannel(anyString(), anyString(), anyString()); + + // Un-subscribing from an unknown channel succeeds: we just ignore the request. + manager.unsubscribeChannel(UUID.randomUUID().toString()); + } + + @Test + public void testStartupBeforeConfiguration() throws Exception { + verify(gcmTokenClient, never()).getToken(anyString(), anyBoolean()); + manager.startup(System.currentTimeMillis()); + verify(gcmTokenClient, times(1)).getToken(AppConstants.MOZ_ANDROID_GCM_SENDERID, false); + } + + @Test + public void testStartupBeforeRegistration() throws Exception { + PushRegistration registration = manager.configure("default", "http://localhost:8080", true, System.currentTimeMillis()); + assertOnlyConfigured(registration, "http://localhost:8080", true); + + manager.startup(System.currentTimeMillis()); + verify(gcmTokenClient, times(1)).getToken(anyString(), anyBoolean()); + } + + @Test + public void testStartupAfterRegistration() throws Exception { + PushRegistration registration = manager.configure("default", "http://localhost:8080", true, System.currentTimeMillis()); + assertOnlyConfigured(registration, "http://localhost:8080", true); + + registration = manager.registerUserAgent("default", System.currentTimeMillis()); + assertRegistered(registration, "http://localhost:8080", true); + + manager.startup(System.currentTimeMillis()); + + // Rather tautological. + PushRegistration updatedRegistration = manager.state.getRegistration("default"); + Assert.assertEquals(registration.uaid, updatedRegistration.uaid); + } + + @Test + public void testStartupAfterSubscription() throws Exception { + PushRegistration registration = manager.configure("default", "http://localhost:8080", true, System.currentTimeMillis()); + assertOnlyConfigured(registration, "http://localhost:8080", true); + + registration = manager.registerUserAgent("default", System.currentTimeMillis()); + assertRegistered(registration, "http://localhost:8080", true); + + PushSubscription subscription = manager.subscribeChannel("default", "webpush", null, null, System.currentTimeMillis()); + assertSubscribed(subscription); + + manager.startup(System.currentTimeMillis()); + + // Rather tautological. + registration = manager.registrationForSubscription(subscription.chid); + PushSubscription updatedSubscription = registration.getSubscription(subscription.chid); + Assert.assertEquals(subscription.chid, updatedSubscription.chid); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/TestPushState.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/TestPushState.java new file mode 100644 index 000000000..cb7c7ec68 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/TestPushState.java @@ -0,0 +1,70 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.push; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.robolectric.RuntimeEnvironment; + +import java.io.File; +import java.io.FileOutputStream; + +@RunWith(TestRunner.class) +public class TestPushState { + @Test + public void testRoundTrip() throws Exception { + final PushState state = new PushState(RuntimeEnvironment.application, "test.json"); + // Fresh state should have no registrations (and no subscriptions). + Assert.assertTrue(state.registrations.isEmpty()); + + final PushRegistration registration = new PushRegistration("endpoint", true, Fetched.now("uaid"), "secret"); + final PushSubscription subscription = new PushSubscription("chid", "profileName", "webpushEndpoint", "service", null); + registration.putSubscription("chid", subscription); + state.putRegistration("profileName", registration); + Assert.assertEquals(1, state.registrations.size()); + state.checkpoint(); + + final PushState readState = new PushState(RuntimeEnvironment.application, "test.json"); + Assert.assertEquals(1, readState.registrations.size()); + final PushRegistration storedRegistration = readState.getRegistration("profileName"); + Assert.assertEquals(registration, storedRegistration); + + Assert.assertEquals(1, storedRegistration.subscriptions.size()); + final PushSubscription storedSubscription = storedRegistration.getSubscription("chid"); + Assert.assertEquals(subscription, storedSubscription); + } + + @Test + public void testMissingRegistration() throws Exception { + final PushState state = new PushState(RuntimeEnvironment.application, "testMissingRegistration.json"); + Assert.assertNull(state.getRegistration("missingProfileName")); + } + + @Test + public void testMissingSubscription() throws Exception { + final PushRegistration registration = new PushRegistration("endpoint", true, Fetched.now("uaid"), "secret"); + Assert.assertNull(registration.getSubscription("missingChid")); + } + + @Test + public void testCorruptedJSON() throws Exception { + // Write some malformed JSON. + // TODO: use mcomella's helpers! + final File file = new File(RuntimeEnvironment.application.getApplicationInfo().dataDir, "testCorruptedJSON.json"); + FileOutputStream fos = null; + try { + fos = new FileOutputStream(file); + fos.write("}".getBytes("UTF-8")); + } finally { + if (fos != null) { + fos.close(); + } + } + + final PushState state = new PushState(RuntimeEnvironment.application, "testCorruptedJSON.json"); + Assert.assertTrue(state.getRegistrations().isEmpty()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestAutopushClient.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestAutopushClient.java new file mode 100644 index 000000000..93e0d14e5 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestAutopushClient.java @@ -0,0 +1,30 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.push.autopush.test; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.push.autopush.AutopushClient; +import org.mozilla.gecko.push.autopush.AutopushClientException; +import org.mozilla.gecko.sync.Utils; + +@RunWith(TestRunner.class) +public class TestAutopushClient { + @Test + public void testGetSenderID() throws Exception { + final AutopushClient client = new AutopushClient("https://updates-autopush-dev.stage.mozaws.net/v1/gcm/829133274407", + Utils.newSynchronousExecutor()); + Assert.assertEquals("829133274407", client.getSenderIDFromServerURI()); + } + + @Test(expected=AutopushClientException.class) + public void testGetNoSenderID() throws Exception { + final AutopushClient client = new AutopushClient("https://updates-autopush-dev.stage.mozaws.net/v1/gcm", + Utils.newSynchronousExecutor()); + client.getSenderIDFromServerURI(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestLiveAutopushClient.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestLiveAutopushClient.java new file mode 100644 index 000000000..102ea34e4 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/push/autopush/test/TestLiveAutopushClient.java @@ -0,0 +1,171 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.push.autopush.test; + +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.PublicKey; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mozilla.apache.commons.codec.binary.Base64; +import org.mozilla.gecko.background.fxa.FxAccountUtils; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.push.RegisterUserAgentResponse; +import org.mozilla.gecko.push.SubscribeChannelResponse; +import org.mozilla.gecko.push.autopush.AutopushClient; +import org.mozilla.gecko.push.autopush.AutopushClient.RequestDelegate; +import org.mozilla.gecko.push.autopush.AutopushClientException; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.net.BaseResource; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.startsWith; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +/** + * This test straddles an awkward line: it uses Mockito, but doesn't actually mock the service + * endpoint. That's why it's a live test: most of its value is checking that the client + * implementation and the upstream server implementation are corresponding correctly. + */ +@RunWith(TestRunner.class) +@Ignore("Live test that requires network connection -- remove this line to run this test.") +public class TestLiveAutopushClient { + final String serverURL = "https://updates-autopush.stage.mozaws.net/v1/gcm/829133274407"; + + protected AutopushClient client; + + @Before + public void setUp() throws Exception { + BaseResource.rewriteLocalhost = false; + client = new AutopushClient(serverURL, Utils.newSynchronousExecutor()); + } + + protected T assertSuccess(RequestDelegate delegate, Class klass) { + verify(delegate, never()).handleError(any(Exception.class)); + verify(delegate, never()).handleFailure(any(AutopushClientException.class)); + + final ArgumentCaptor register = ArgumentCaptor.forClass(klass); + verify(delegate).handleSuccess(register.capture()); + + return register.getValue(); + } + + protected AutopushClientException assertFailure(RequestDelegate delegate, Class klass) { + verify(delegate, never()).handleError(any(Exception.class)); + verify(delegate, never()).handleSuccess(any(klass)); + + final ArgumentCaptor failure = ArgumentCaptor.forClass(AutopushClientException.class); + verify(delegate).handleFailure(failure.capture()); + + return failure.getValue(); + } + + @Test + public void testUserAgent() throws Exception { + final RequestDelegate registerDelegate = mock(RequestDelegate.class); + client.registerUserAgent(Utils.generateGuid(), registerDelegate); + + final RegisterUserAgentResponse registerResponse = assertSuccess(registerDelegate, RegisterUserAgentResponse.class); + Assert.assertNotNull(registerResponse); + Assert.assertNotNull(registerResponse.uaid); + Assert.assertNotNull(registerResponse.secret); + + // Reregistering with a new GUID should succeed. + final RequestDelegate reregisterDelegate = mock(RequestDelegate.class); + client.reregisterUserAgent(registerResponse.uaid, registerResponse.secret, Utils.generateGuid(), reregisterDelegate); + + Assert.assertNull(assertSuccess(reregisterDelegate, Void.class)); + + // Unregistering should succeed. + final RequestDelegate unregisterDelegate = mock(RequestDelegate.class); + client.unregisterUserAgent(registerResponse.uaid, registerResponse.secret, unregisterDelegate); + + Assert.assertNull(assertSuccess(unregisterDelegate, Void.class)); + + // Trying to unregister a second time should give a 404. + final RequestDelegate reunregisterDelegate = mock(RequestDelegate.class); + client.unregisterUserAgent(registerResponse.uaid, registerResponse.secret, reunregisterDelegate); + + final AutopushClientException failureException = assertFailure(reunregisterDelegate, Void.class); + Assert.assertThat(failureException, instanceOf(AutopushClientException.AutopushClientRemoteException.class)); + Assert.assertTrue(((AutopushClientException.AutopushClientRemoteException) failureException).isGone()); + } + + @Test + public void testChannel() throws Exception { + final RequestDelegate registerDelegate = mock(RequestDelegate.class); + client.registerUserAgent(Utils.generateGuid(), registerDelegate); + + final RegisterUserAgentResponse registerResponse = assertSuccess(registerDelegate, RegisterUserAgentResponse.class); + Assert.assertNotNull(registerResponse); + Assert.assertNotNull(registerResponse.uaid); + Assert.assertNotNull(registerResponse.secret); + + // We should be able to subscribe to a channel. + final RequestDelegate subscribeDelegate = mock(RequestDelegate.class); + client.subscribeChannel(registerResponse.uaid, registerResponse.secret, null, subscribeDelegate); + + final SubscribeChannelResponse subscribeResponse = assertSuccess(subscribeDelegate, SubscribeChannelResponse.class); + Assert.assertNotNull(subscribeResponse); + Assert.assertNotNull(subscribeResponse.channelID); + Assert.assertNotNull(subscribeResponse.endpoint); + Assert.assertThat(subscribeResponse.endpoint, startsWith(FxAccountUtils.getAudienceForURL(serverURL))); + Assert.assertThat(subscribeResponse.endpoint, containsString("/v1/")); + + // And we should be able to unsubscribe. + final RequestDelegate unsubscribeDelegate = mock(RequestDelegate.class); + client.unsubscribeChannel(registerResponse.uaid, registerResponse.secret, subscribeResponse.channelID, unsubscribeDelegate); + + Assert.assertNull(assertSuccess(unsubscribeDelegate, Void.class)); + + // We should be able to create a restricted subscription by specifying + // an ECDSA public key using the P-256 curve. + final RequestDelegate subscribeWithKeyDelegate = mock(RequestDelegate.class); + final KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("ECDSA"); + keyPairGenerator.initialize(256); + final KeyPair keyPair = keyPairGenerator.generateKeyPair(); + final PublicKey publicKey = keyPair.getPublic(); + String appServerKey = Base64.encodeBase64URLSafeString(publicKey.getEncoded()); + client.subscribeChannel(registerResponse.uaid, registerResponse.secret, appServerKey, subscribeWithKeyDelegate); + + final SubscribeChannelResponse subscribeWithKeyResponse = assertSuccess(subscribeWithKeyDelegate, SubscribeChannelResponse.class); + Assert.assertNotNull(subscribeWithKeyResponse); + Assert.assertNotNull(subscribeWithKeyResponse.channelID); + Assert.assertNotNull(subscribeWithKeyResponse.endpoint); + Assert.assertThat(subscribeWithKeyResponse.endpoint, startsWith(FxAccountUtils.getAudienceForURL(serverURL))); + Assert.assertThat(subscribeWithKeyResponse.endpoint, containsString("/v2/")); + + // And we should be able to drop the restricted subscription. + final RequestDelegate unsubscribeWithKeyDelegate = mock(RequestDelegate.class); + client.unsubscribeChannel(registerResponse.uaid, registerResponse.secret, subscribeWithKeyResponse.channelID, unsubscribeWithKeyDelegate); + + Assert.assertNull(assertSuccess(unsubscribeWithKeyDelegate, Void.class)); + + // Trying to unsubscribe a second time should give a 410. + final RequestDelegate reunsubscribeDelegate = mock(RequestDelegate.class); + client.unsubscribeChannel(registerResponse.uaid, registerResponse.secret, subscribeResponse.channelID, reunsubscribeDelegate); + + final AutopushClientException reunsubscribeFailureException = assertFailure(reunsubscribeDelegate, Void.class); + Assert.assertThat(reunsubscribeFailureException, instanceOf(AutopushClientException.AutopushClientRemoteException.class)); + Assert.assertTrue(((AutopushClientException.AutopushClientRemoteException) reunsubscribeFailureException).isGone()); + + // Trying to unsubscribe from a non-existent channel should give a 404. Right now it gives a 401! + final RequestDelegate badUnsubscribeDelegate = mock(RequestDelegate.class); + client.unsubscribeChannel(registerResponse.uaid + "BAD", registerResponse.secret, subscribeResponse.channelID, badUnsubscribeDelegate); + + final AutopushClientException badUnsubscribeFailureException = assertFailure(badUnsubscribeDelegate, Void.class); + Assert.assertThat(badUnsubscribeFailureException, instanceOf(AutopushClientException.AutopushClientRemoteException.class)); + Assert.assertTrue(((AutopushClientException.AutopushClientRemoteException) badUnsubscribeFailureException).isInvalidAuthentication()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestBase32.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestBase32.java new file mode 100644 index 000000000..7047d67d3 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestBase32.java @@ -0,0 +1,53 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.crypto.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.apache.commons.codec.binary.Base32; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.Utils; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestBase32 { + + public static void assertSame(byte[] arrayOne, byte[] arrayTwo) { + assertTrue(Arrays.equals(arrayOne, arrayTwo)); + } + + @Test + public void testBase32() throws UnsupportedEncodingException { + byte[] decoded = new Base32().decode("MZXW6YTBOI======"); + byte[] expected = "foobar".getBytes(); + assertSame(decoded, expected); + + byte[] encoded = new Base32().encode("fooba".getBytes()); + expected = "MZXW6YTB".getBytes(); + assertSame(encoded, expected); + } + + @Test + public void testFriendlyBase32() { + // These checks are drawn from Firefox, test_utils_encodeBase32.js. + byte[] decoded = Utils.decodeFriendlyBase32("mzxw6ytb9jrgcztpn5rgc4tcme"); + byte[] expected = "foobarbafoobarba".getBytes(); + assertEquals(decoded.length, 16); + assertSame(decoded, expected); + + // These are real values extracted from the Service object in a Firefox profile. + String base32Key = "6m8mv8ex2brqnrmsb9fjuvfg7y"; + String expectedHex = "f316caac97d06306c5920b8a9a54a6fe"; + + byte[] computedBytes = Utils.decodeFriendlyBase32(base32Key); + byte[] expectedBytes = Utils.hex2Byte(expectedHex); + + assertSame(computedBytes, expectedBytes); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestCryptoInfo.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestCryptoInfo.java new file mode 100644 index 000000000..3e8d90e2f --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestCryptoInfo.java @@ -0,0 +1,144 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.crypto.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.apache.commons.codec.binary.Base64; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.crypto.CryptoInfo; +import org.mozilla.gecko.sync.crypto.KeyBundle; + +import java.io.UnsupportedEncodingException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestCryptoInfo { + + @Test + public void testEncryptedHMACIsSet() throws CryptoException, UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException { + KeyBundle kb = KeyBundle.withRandomKeys(); + CryptoInfo encrypted = CryptoInfo.encrypt("plaintext".getBytes("UTF-8"), kb); + assertSame(kb, encrypted.getKeys()); + assertTrue(encrypted.generatedHMACIsHMAC()); + } + + @Test + public void testRandomEncryptedDecrypted() throws CryptoException, UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException { + KeyBundle kb = KeyBundle.withRandomKeys(); + byte[] plaintext = "plaintext".getBytes("UTF-8"); + CryptoInfo info = CryptoInfo.encrypt(plaintext, kb); + byte[] iv = info.getIV(); + info.decrypt(); + assertArrayEquals(plaintext, info.getMessage()); + assertSame(null, info.getHMAC()); + assertArrayEquals(iv, info.getIV()); + assertSame(kb, info.getKeys()); + } + + @Test + public void testDecrypt() throws CryptoException { + String base64CipherText = "NMsdnRulLwQsVcwxKW9XwaUe7ouJk5Wn" + + "80QhbD80l0HEcZGCynh45qIbeYBik0lg" + + "cHbKmlIxTJNwU+OeqipN+/j7MqhjKOGI" + + "lvbpiPQQLC6/ffF2vbzL0nzMUuSyvaQz" + + "yGGkSYM2xUFt06aNivoQTvU2GgGmUK6M" + + "vadoY38hhW2LCMkoZcNfgCqJ26lO1O0s" + + "EO6zHsk3IVz6vsKiJ2Hq6VCo7hu123wN" + + "egmujHWQSGyf8JeudZjKzfi0OFRRvvm4" + + "QAKyBWf0MgrW1F8SFDnVfkq8amCB7Nhd" + + "whgLWbN+21NitNwWYknoEWe1m6hmGZDg" + + "DT32uxzWxCV8QqqrpH/ZggViEr9uMgoy" + + "4lYaWqP7G5WKvvechc62aqnsNEYhH26A" + + "5QgzmlNyvB+KPFvPsYzxDnSCjOoRSLx7" + + "GG86wT59QZw="; + String base64IV = "GX8L37AAb2FZJMzIoXlX8w=="; + String base16Hmac = "b1e6c18ac30deb70236bc0d65a46f7a4" + + "dce3b8b0e02cf92182b914e3afa5eebc"; + String base64EncryptionKey = "9K/wLdXdw+nrTtXo4ZpECyHFNr4d7aYH" + + "qeg3KW9+m6Q="; + String base64HmacKey = "MMntEfutgLTc8FlTLQFms8/xMPmCldqP" + + "lq/QQXEjx70="; + String base64ExpectedBytes = "eyJpZCI6IjVxUnNnWFdSSlpYciIsImhp" + + "c3RVcmkiOiJmaWxlOi8vL1VzZXJzL2ph" + + "c29uL0xpYnJhcnkvQXBwbGljYXRpb24l" + + "MjBTdXBwb3J0L0ZpcmVmb3gvUHJvZmls" + + "ZXMva3NnZDd3cGsuTG9jYWxTeW5jU2Vy" + + "dmVyL3dlYXZlL2xvZ3MvIiwidGl0bGUi" + + "OiJJbmRleCBvZiBmaWxlOi8vL1VzZXJz" + + "L2phc29uL0xpYnJhcnkvQXBwbGljYXRp" + + "b24gU3VwcG9ydC9GaXJlZm94L1Byb2Zp" + + "bGVzL2tzZ2Q3d3BrLkxvY2FsU3luY1Nl" + + "cnZlci93ZWF2ZS9sb2dzLyIsInZpc2l0" + + "cyI6W3siZGF0ZSI6MTMxOTE0OTAxMjM3" + + "MjQyNSwidHlwZSI6MX1dfQ=="; + + CryptoInfo decrypted = CryptoInfo.decrypt( + Base64.decodeBase64(base64CipherText), + Base64.decodeBase64(base64IV), + Utils.hex2Byte(base16Hmac), + new KeyBundle( + Base64.decodeBase64(base64EncryptionKey), + Base64.decodeBase64(base64HmacKey)) + ); + + assertArrayEquals(decrypted.getMessage(), Base64.decodeBase64(base64ExpectedBytes)); + } + + @Test + public void testEncrypt() throws CryptoException { + String base64CipherText = "NMsdnRulLwQsVcwxKW9XwaUe7ouJk5Wn" + + "80QhbD80l0HEcZGCynh45qIbeYBik0lg" + + "cHbKmlIxTJNwU+OeqipN+/j7MqhjKOGI" + + "lvbpiPQQLC6/ffF2vbzL0nzMUuSyvaQz" + + "yGGkSYM2xUFt06aNivoQTvU2GgGmUK6M" + + "vadoY38hhW2LCMkoZcNfgCqJ26lO1O0s" + + "EO6zHsk3IVz6vsKiJ2Hq6VCo7hu123wN" + + "egmujHWQSGyf8JeudZjKzfi0OFRRvvm4" + + "QAKyBWf0MgrW1F8SFDnVfkq8amCB7Nhd" + + "whgLWbN+21NitNwWYknoEWe1m6hmGZDg" + + "DT32uxzWxCV8QqqrpH/ZggViEr9uMgoy" + + "4lYaWqP7G5WKvvechc62aqnsNEYhH26A" + + "5QgzmlNyvB+KPFvPsYzxDnSCjOoRSLx7" + + "GG86wT59QZw="; + String base64IV = "GX8L37AAb2FZJMzIoXlX8w=="; + String base16Hmac = "b1e6c18ac30deb70236bc0d65a46f7a4" + + "dce3b8b0e02cf92182b914e3afa5eebc"; + String base64EncryptionKey = "9K/wLdXdw+nrTtXo4ZpECyHFNr4d7aYH" + + "qeg3KW9+m6Q="; + String base64HmacKey = "MMntEfutgLTc8FlTLQFms8/xMPmCldqP" + + "lq/QQXEjx70="; + String base64ExpectedBytes = "eyJpZCI6IjVxUnNnWFdSSlpYciIsImhp" + + "c3RVcmkiOiJmaWxlOi8vL1VzZXJzL2ph" + + "c29uL0xpYnJhcnkvQXBwbGljYXRpb24l" + + "MjBTdXBwb3J0L0ZpcmVmb3gvUHJvZmls" + + "ZXMva3NnZDd3cGsuTG9jYWxTeW5jU2Vy" + + "dmVyL3dlYXZlL2xvZ3MvIiwidGl0bGUi" + + "OiJJbmRleCBvZiBmaWxlOi8vL1VzZXJz" + + "L2phc29uL0xpYnJhcnkvQXBwbGljYXRp" + + "b24gU3VwcG9ydC9GaXJlZm94L1Byb2Zp" + + "bGVzL2tzZ2Q3d3BrLkxvY2FsU3luY1Nl" + + "cnZlci93ZWF2ZS9sb2dzLyIsInZpc2l0" + + "cyI6W3siZGF0ZSI6MTMxOTE0OTAxMjM3" + + "MjQyNSwidHlwZSI6MX1dfQ=="; + + CryptoInfo encrypted = CryptoInfo.encrypt( + Base64.decodeBase64(base64ExpectedBytes), + Base64.decodeBase64(base64IV), + new KeyBundle( + Base64.decodeBase64(base64EncryptionKey), + Base64.decodeBase64(base64HmacKey)) + ); + + assertArrayEquals(Base64.decodeBase64(base64CipherText), encrypted.getMessage()); + assertArrayEquals(Utils.hex2Byte(base16Hmac), encrypted.getHMAC()); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestHKDF.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestHKDF.java new file mode 100644 index 000000000..09973eeff --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestHKDF.java @@ -0,0 +1,143 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.crypto.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.apache.commons.codec.binary.Base64; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.crypto.HKDF; +import org.mozilla.gecko.sync.crypto.KeyBundle; + +import java.util.Arrays; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/* + * This class tests the HKDF.java class. + * The tests are the 3 HMAC-based test cases + * from the RFC 5869 specification. + */ +@RunWith(TestRunner.class) +public class TestHKDF { + @Test + public void testCase1() { + String IKM = "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"; + String salt = "000102030405060708090a0b0c"; + String info = "f0f1f2f3f4f5f6f7f8f9"; + int L = 42; + String PRK = "077709362c2e32df0ddc3f0dc47bba63" + + "90b6c73bb50f9c3122ec844ad7c2b3e5"; + String OKM = "3cb25f25faacd57a90434f64d0362f2a" + + "2d2d0a90cf1a5a4c5db02d56ecc4c5bf" + + "34007208d5b887185865"; + + assertTrue(doStep1(IKM, salt, PRK)); + assertTrue(doStep2(PRK, info, L, OKM)); + } + + @Test + public void testCase2() { + String IKM = "000102030405060708090a0b0c0d0e0f" + + "101112131415161718191a1b1c1d1e1f" + + "202122232425262728292a2b2c2d2e2f" + + "303132333435363738393a3b3c3d3e3f" + + "404142434445464748494a4b4c4d4e4f"; + String salt = "606162636465666768696a6b6c6d6e6f" + + "707172737475767778797a7b7c7d7e7f" + + "808182838485868788898a8b8c8d8e8f" + + "909192939495969798999a9b9c9d9e9f" + + "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf"; + String info = "b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" + + "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" + + "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" + + "e0e1e2e3e4e5e6e7e8e9eaebecedeeef" + + "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"; + int L = 82; + String PRK = "06a6b88c5853361a06104c9ceb35b45c" + + "ef760014904671014a193f40c15fc244"; + String OKM = "b11e398dc80327a1c8e7f78c596a4934" + + "4f012eda2d4efad8a050cc4c19afa97c" + + "59045a99cac7827271cb41c65e590e09" + + "da3275600c2f09b8367793a9aca3db71" + + "cc30c58179ec3e87c14c01d5c1f3434f" + + "1d87"; + + assertTrue(doStep1(IKM, salt, PRK)); + assertTrue(doStep2(PRK, info, L, OKM)); + } + + @Test + public void testCase3() { + String IKM = "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b"; + String salt = ""; + String info = ""; + int L = 42; + String PRK = "19ef24a32c717b167f33a91d6f648bdf" + + "96596776afdb6377ac434c1c293ccb04"; + String OKM = "8da4e775a563c18f715f802a063c5a31" + + "b8a11f5c5ee1879ec3454e5f3c738d2d" + + "9d201395faa4b61a96c8"; + + assertTrue(doStep1(IKM, salt, PRK)); + assertTrue(doStep2(PRK, info, L, OKM)); + } + + /* + * Tests the code for getting the keys necessary to + * decrypt the crypto keys bundle for Mozilla Sync. + * + * This operation is just a tailored version of the + * standard to get only the 2 keys we need. + */ + @Test + public void testGetCryptoKeysBundleKeys() { + String username = "smqvooxj664hmrkrv6bw4r4vkegjhkns"; + String friendlyBase32SyncKey = "gbh7teqqcgyzd65svjgibd7tqy"; + String base64EncryptionKey = "069EnS3EtDK4y1tZ1AyKX+U7WEsWRp9bRIKLdW/7aoE="; + String base64HmacKey = "LF2YCS1QCgSNCf0BCQvQ06SGH8jqJDi9dKj0O+b0fwI="; + + KeyBundle bundle = null; + try { + bundle = new KeyBundle(username, friendlyBase32SyncKey); + } catch (Exception e) { + fail("Unexpected exception " + e); + } + + byte[] expectedEncryptionKey = Base64.decodeBase64(base64EncryptionKey); + byte[] expectedHMACKey = Base64.decodeBase64(base64HmacKey); + assertTrue(Arrays.equals(bundle.getEncryptionKey(), expectedEncryptionKey)); + assertTrue(Arrays.equals(bundle.getHMACKey(), expectedHMACKey)); + } + + /* + * Helper to do step 1 of RFC 5869. + */ + private boolean doStep1(String IKM, String salt, String PRK) { + try { + byte[] prkResult = HKDF.hkdfExtract(Utils.hex2Byte(salt), Utils.hex2Byte(IKM)); + byte[] prkExpect = Utils.hex2Byte(PRK); + return Arrays.equals(prkResult, prkExpect); + } catch (Exception e) { + fail("Unexpected exception " + e); + } + return false; + } + + /* + * Helper to do step 2 of RFC 5869. + */ + private boolean doStep2(String PRK, String info, int L, String OKM) { + try { + byte[] okmResult = HKDF.hkdfExpand(Utils.hex2Byte(PRK), Utils.hex2Byte(info), L); + byte[] okmExpect = Utils.hex2Byte(OKM); + return Arrays.equals(okmResult, okmExpect); + } catch (Exception e) { + fail("Unexpected exception " + e); + } + return false; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestKeyBundle.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestKeyBundle.java new file mode 100644 index 000000000..3c3edb9f8 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestKeyBundle.java @@ -0,0 +1,65 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.crypto.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.apache.commons.codec.binary.Base64; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.crypto.KeyBundle; + +import java.io.UnsupportedEncodingException; +import java.util.Arrays; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestKeyBundle { + @Test + public void testCreateKeyBundle() throws UnsupportedEncodingException, CryptoException { + String username = "smqvooxj664hmrkrv6bw4r4vkegjhkns"; + String friendlyBase32SyncKey = "gbh7teqqcgyzd65svjgibd7tqy"; + String base64EncryptionKey = "069EnS3EtDK4y1tZ1AyKX+U7WEsWRp9b" + + "RIKLdW/7aoE="; + String base64HmacKey = "LF2YCS1QCgSNCf0BCQvQ06SGH8jqJDi9" + + "dKj0O+b0fwI="; + + KeyBundle keys = new KeyBundle(username, friendlyBase32SyncKey); + assertArrayEquals(keys.getEncryptionKey(), Base64.decodeBase64(base64EncryptionKey.getBytes("UTF-8"))); + assertArrayEquals(keys.getHMACKey(), Base64.decodeBase64(base64HmacKey.getBytes("UTF-8"))); + } + + /* + * Basic sanity check to make sure length of keys is correct (32 bytes). + * Also make sure that the two keys are different. + */ + @Test + public void testGenerateRandomKeys() throws CryptoException { + KeyBundle keys = KeyBundle.withRandomKeys(); + + assertEquals(32, keys.getEncryptionKey().length); + assertEquals(32, keys.getHMACKey().length); + + boolean equal = Arrays.equals(keys.getEncryptionKey(), keys.getHMACKey()); + assertEquals(false, equal); + } + + @Test + public void testEquals() throws CryptoException { + KeyBundle k = KeyBundle.withRandomKeys(); + KeyBundle o = KeyBundle.withRandomKeys(); + assertFalse(k.equals("test")); + assertFalse(k.equals(o)); + assertTrue(k.equals(k)); + assertTrue(o.equals(o)); + o.setHMACKey(k.getHMACKey()); + assertFalse(o.equals(k)); + o.setEncryptionKey(k.getEncryptionKey()); + assertTrue(o.equals(k)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestPBKDF2.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestPBKDF2.java new file mode 100644 index 000000000..d2d1d8271 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestPBKDF2.java @@ -0,0 +1,124 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.crypto.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.crypto.PBKDF2; + +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * Test PBKDF2 implementations against vectors from + *

+ *
SHA-256
+ *
https://github.com/ircmaxell/PHP-PasswordLib/blob/master/test/Data/Vectors/pbkdf2-draft-josefsson-sha256.test-vectors
+ *
https://gitorious.org/scrypt/nettle-scrypt/blobs/37c0d5288e991604fe33dba2f1724986a8dddf56/testsuite/pbkdf2-test.c
+ *
+ */ +@RunWith(TestRunner.class) +public class TestPBKDF2 { + + @Test + public final void testPBKDF2SHA256A() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "password"; + String s = "salt"; + int dkLen = 32; + + checkPBKDF2SHA256(p, s, 1, dkLen, "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b"); + checkPBKDF2SHA256(p, s, 4096, dkLen, "c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a"); + } + + @Test + public final void testPBKDF2SHA256B() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "passwordPASSWORDpassword"; + String s = "saltSALTsaltSALTsaltSALTsaltSALTsalt"; + int dkLen = 40; + + checkPBKDF2SHA256(p, s, 4096, dkLen, "348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1c635518c7dac47e9"); + } + + @Test + public final void testPBKDF2SHA256scryptA() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "passwd"; + String s = "salt"; + int dkLen = 64; + + checkPBKDF2SHA256(p, s, 1, dkLen, "55ac046e56e3089fec1691c22544b605f94185216dde0465e68b9d57c20dacbc49ca9cccf179b645991664b39d77ef317c71b845b1e30bd509112041d3a19783"); + } + + /* + // This test takes eight seconds or so to run, so we don't run it. + @Test + public final void testPBKDF2SHA256scryptB() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "Password"; + String s = "NaCl"; + int dkLen = 64; + + checkPBKDF2SHA256(p, s, 80000, dkLen, "4ddcd8f60b98be21830cee5ef22701f9641a4418d04c0414aeff08876b34ab56a1d425a1225833549adb841b51c9b3176a272bdebba1d078478f62b397f33c8d"); + } + */ + + @Test + public final void testPBKDF2SHA256C() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "pass\0word"; + String s = "sa\0lt"; + int dkLen = 16; + + checkPBKDF2SHA256(p, s, 4096, dkLen, "89b69d0516f829893c696226650a8687"); + } + + /* + // This test takes two or three minutes to run, so we don't run it. + public final void testPBKDF2SHA256D() throws UnsupportedEncodingException, GeneralSecurityException { + String p = "password"; + String s = "salt"; + int dkLen = 32; + + checkPBKDF2SHA256(p, s, 16777216, dkLen, "cf81c66fe8cfc04d1f31ecb65dab4089f7f179e89b3b0bcb17ad10e3ac6eba46"); + } + */ + + /* + // This test takes eight seconds or so to run, so we don't run it. + @Test + public final void testTimePBKDF2SHA256() throws UnsupportedEncodingException, GeneralSecurityException { + checkPBKDF2SHA256("password", "salt", 80000, 32, null); + } + */ + + private void checkPBKDF2SHA256(String p, String s, int c, int dkLen, + final String expectedStr) + throws GeneralSecurityException, UnsupportedEncodingException { + long start = System.currentTimeMillis(); + byte[] key = PBKDF2.pbkdf2SHA256(p.getBytes("US-ASCII"), s.getBytes("US-ASCII"), c, dkLen); + assertNotNull(key); + + long end = System.currentTimeMillis(); + + System.err.println("SHA-256 " + c + " took " + (end - start) + "ms"); + if (expectedStr == null) { + return; + } + + assertEquals(dkLen, Utils.hex2Byte(expectedStr).length); + assertExpectedBytes(expectedStr, key); + } + + public static void assertExpectedBytes(final String expectedStr, byte[] key) { + assertEquals(expectedStr, Utils.byte2Hex(key)); + byte[] expected = Utils.hex2Byte(expectedStr); + + assertEquals(expected.length, key.length); + for (int i = 0; i < key.length; i++) { + assertEquals(expected[i], key[i]); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestPersistedCrypto5Keys.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestPersistedCrypto5Keys.java new file mode 100644 index 000000000..f5ffc5a8a --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestPersistedCrypto5Keys.java @@ -0,0 +1,83 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.crypto.test; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.MockSharedPreferences; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.CollectionKeys; +import org.mozilla.gecko.sync.NoCollectionKeysSetException; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.crypto.PersistedCrypto5Keys; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +@RunWith(TestRunner.class) +public class TestPersistedCrypto5Keys { + MockSharedPreferences prefs = null; + + @Before + public void setUp() { + prefs = new MockSharedPreferences(); + } + + @Test + public void testPersistLastModified() throws CryptoException, NoCollectionKeysSetException { + long LAST_MODIFIED = System.currentTimeMillis(); + KeyBundle syncKeyBundle = KeyBundle.withRandomKeys(); + PersistedCrypto5Keys persisted = new PersistedCrypto5Keys(prefs, syncKeyBundle); + + // Test fresh start. + assertEquals(-1, persisted.lastModified()); + + // Test persisting. + persisted.persistLastModified(LAST_MODIFIED); + assertEquals(LAST_MODIFIED, persisted.lastModified()); + + // Test clearing. + persisted.persistLastModified(0); + assertEquals(-1, persisted.lastModified()); + } + + @Test + public void testPersistKeys() throws CryptoException, NoCollectionKeysSetException { + KeyBundle syncKeyBundle = KeyBundle.withRandomKeys(); + KeyBundle testKeyBundle = KeyBundle.withRandomKeys(); + + PersistedCrypto5Keys persisted = new PersistedCrypto5Keys(prefs, syncKeyBundle); + + // Test fresh start. + assertNull(persisted.keys()); + + // Test persisting. + CollectionKeys keys = new CollectionKeys(); + keys.setDefaultKeyBundle(syncKeyBundle); + keys.setKeyBundleForCollection("test", testKeyBundle); + persisted.persistKeys(keys); + + CollectionKeys persistedKeys = persisted.keys(); + assertNotNull(persistedKeys); + assertArrayEquals(syncKeyBundle.getEncryptionKey(), persistedKeys.defaultKeyBundle().getEncryptionKey()); + assertArrayEquals(syncKeyBundle.getHMACKey(), persistedKeys.defaultKeyBundle().getHMACKey()); + assertArrayEquals(testKeyBundle.getEncryptionKey(), persistedKeys.keyBundleForCollection("test").getEncryptionKey()); + assertArrayEquals(testKeyBundle.getHMACKey(), persistedKeys.keyBundleForCollection("test").getHMACKey()); + + // Test clearing. + persisted.persistKeys(null); + assertNull(persisted.keys()); + + // Test loading a persisted bundle with wrong syncKeyBundle. + persisted.persistKeys(keys); + assertNotNull(persisted.keys()); + + persisted = new PersistedCrypto5Keys(prefs, testKeyBundle); + assertNull(persisted.keys()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestSRPConstants.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestSRPConstants.java new file mode 100644 index 000000000..9188bba24 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/crypto/test/TestSRPConstants.java @@ -0,0 +1,45 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.crypto.test; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.net.SRPConstants; + +import java.math.BigInteger; + +@RunWith(TestRunner.class) +public class TestSRPConstants extends SRPConstants { + public void assertSRPConstants(SRPConstants.Parameters params, int bitLength) { + Assert.assertNotNull(params.g); + Assert.assertNotNull(params.N); + Assert.assertEquals(bitLength, bitLength); + Assert.assertEquals(bitLength / 8, params.byteLength); + Assert.assertEquals(bitLength / 4, params.hexLength); + BigInteger N = params.N; + BigInteger g = params.g; + // Each prime N is of the form 2*q + 1, with q also prime. + BigInteger q = N.subtract(new BigInteger("1")).divide(new BigInteger("2")); + // Check that g is a generator: the order of g is exactly 2*q (not 2, not q). + Assert.assertFalse(new BigInteger("1").equals(g.modPow(new BigInteger("2"), N))); + Assert.assertFalse(new BigInteger("1").equals(g.modPow(q, N))); + Assert.assertTrue(new BigInteger("1").equals(g.modPow((N.subtract(new BigInteger("1"))), N))); + // Even probable primality checking is too expensive to do here. + // Assert.assertTrue(N.isProbablePrime(3)); + // Assert.assertTrue(q.isProbablePrime(3)); + } + + @Test + public void testConstants() { + assertSRPConstants(SRPConstants._1024, 1024); + assertSRPConstants(SRPConstants._1536, 1536); + assertSRPConstants(SRPConstants._2048, 2048); + assertSRPConstants(SRPConstants._3072, 3072); + assertSRPConstants(SRPConstants._4096, 4096); + assertSRPConstants(SRPConstants._6144, 6144); + assertSRPConstants(SRPConstants._8192, 8192); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/middleware/test/TestCrypto5MiddlewareRepositorySession.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/middleware/test/TestCrypto5MiddlewareRepositorySession.java new file mode 100644 index 000000000..d38a4caf2 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/middleware/test/TestCrypto5MiddlewareRepositorySession.java @@ -0,0 +1,291 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.middleware.test; + +import junit.framework.AssertionFailedError; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionBeginDelegate; +import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionCreationDelegate; +import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFetchRecordsDelegate; +import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionFinishDelegate; +import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositorySessionStoreDelegate; +import org.mozilla.android.sync.test.helpers.ExpectSuccessRepositoryWipeDelegate; +import org.mozilla.gecko.background.testhelpers.MockRecord; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WBORepository; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepository; +import org.mozilla.gecko.sync.middleware.Crypto5MiddlewareRepositorySession; +import org.mozilla.gecko.sync.repositories.InactiveSessionException; +import org.mozilla.gecko.sync.repositories.InvalidSessionTransitionException; +import org.mozilla.gecko.sync.repositories.NoStoreDelegateException; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestCrypto5MiddlewareRepositorySession { + public static WaitHelper getTestWaiter() { + return WaitHelper.getTestWaiter(); + } + + public static void performWait(Runnable runnable) { + getTestWaiter().performWait(runnable); + } + + protected static void performNotify(InactiveSessionException e) { + final AssertionFailedError failed = new AssertionFailedError("Inactive session."); + failed.initCause(e); + getTestWaiter().performNotify(failed); + } + + protected static void performNotify(InvalidSessionTransitionException e) { + final AssertionFailedError failed = new AssertionFailedError("Invalid session transition."); + failed.initCause(e); + getTestWaiter().performNotify(failed); + } + + public Runnable onThreadRunnable(Runnable runnable) { + return WaitHelper.onThreadRunnable(runnable); + } + + public WBORepository wboRepo; + public KeyBundle keyBundle; + public Crypto5MiddlewareRepository cmwRepo; + public Crypto5MiddlewareRepositorySession cmwSession; + + @Before + public void setUp() throws CryptoException { + wboRepo = new WBORepository(); + keyBundle = KeyBundle.withRandomKeys(); + cmwRepo = new Crypto5MiddlewareRepository(wboRepo, keyBundle); + cmwSession = null; + } + + /** + * Run `runnable` in performWait(... onBeginSucceeded { } ). + * + * The Crypto5MiddlewareRepositorySession is available in self.cmwSession. + * + * @param runnable + */ + public void runInOnBeginSucceeded(final Runnable runnable) { + final TestCrypto5MiddlewareRepositorySession self = this; + performWait(onThreadRunnable(new Runnable() { + @Override + public void run() { + cmwRepo.createSession(new ExpectSuccessRepositorySessionCreationDelegate(getTestWaiter()) { + @Override + public void onSessionCreated(RepositorySession session) { + self.cmwSession = (Crypto5MiddlewareRepositorySession)session; + assertSame(RepositorySession.SessionStatus.UNSTARTED, cmwSession.getStatus()); + + try { + session.begin(new ExpectSuccessRepositorySessionBeginDelegate(getTestWaiter()) { + @Override + public void onBeginSucceeded(RepositorySession _session) { + assertSame(self.cmwSession, _session); + runnable.run(); + } + }); + } catch (InvalidSessionTransitionException e) { + TestCrypto5MiddlewareRepositorySession.performNotify(e); + } + } + }, null); + } + })); + } + + @Test + /** + * Verify that the status is actually being advanced. + */ + public void testStatus() { + runInOnBeginSucceeded(new Runnable() { + @Override public void run() { + assertSame(RepositorySession.SessionStatus.ACTIVE, cmwSession.getStatus()); + try { + cmwSession.finish(new ExpectSuccessRepositorySessionFinishDelegate(getTestWaiter())); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + }); + assertSame(RepositorySession.SessionStatus.DONE, cmwSession.getStatus()); + } + + @Test + /** + * Verify that wipe is actually wiping the underlying repository. + */ + public void testWipe() { + Record record = new MockRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false); + wboRepo.wbos.put(record.guid, record); + assertEquals(1, wboRepo.wbos.size()); + + runInOnBeginSucceeded(new Runnable() { + @Override public void run() { + cmwSession.wipe(new ExpectSuccessRepositoryWipeDelegate(getTestWaiter())); + } + }); + performWait(onThreadRunnable(new Runnable() { + @Override public void run() { + try { + cmwSession.finish(new ExpectSuccessRepositorySessionFinishDelegate(getTestWaiter())); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + })); + assertEquals(0, wboRepo.wbos.size()); + } + + @Test + /** + * Verify that store is actually writing encrypted data to the underlying repository. + */ + public void testStoreEncrypts() throws NonObjectJSONException, CryptoException, IOException { + final BookmarkRecord record = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false); + record.title = "unencrypted title"; + + runInOnBeginSucceeded(new Runnable() { + @Override public void run() { + try { + try { + cmwSession.setStoreDelegate(new ExpectSuccessRepositorySessionStoreDelegate(getTestWaiter())); + cmwSession.store(record); + } catch (NoStoreDelegateException e) { + getTestWaiter().performNotify(new AssertionFailedError("Should not happen.")); + } + cmwSession.storeDone(); + cmwSession.finish(new ExpectSuccessRepositorySessionFinishDelegate(getTestWaiter())); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + }); + assertEquals(1, wboRepo.wbos.size()); + assertTrue(wboRepo.wbos.containsKey(record.guid)); + + Record storedRecord = wboRepo.wbos.get(record.guid); + CryptoRecord cryptoRecord = (CryptoRecord)storedRecord; + assertSame(cryptoRecord.keyBundle, keyBundle); + + cryptoRecord = cryptoRecord.decrypt(); + BookmarkRecord decryptedRecord = new BookmarkRecord(); + decryptedRecord.initFromEnvelope(cryptoRecord); + assertEquals(record.title, decryptedRecord.title); + } + + @Test + /** + * Verify that fetch is actually retrieving encrypted data from the underlying repository and is correctly decrypting it. + */ + public void testFetchDecrypts() throws UnsupportedEncodingException, CryptoException { + final BookmarkRecord record1 = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false); + record1.title = "unencrypted title"; + final BookmarkRecord record2 = new BookmarkRecord("XXXXXXXXXXXX", "coll", System.currentTimeMillis(), false); + record2.title = "unencrypted second title"; + + CryptoRecord encryptedRecord1 = record1.getEnvelope(); + encryptedRecord1.keyBundle = keyBundle; + encryptedRecord1 = encryptedRecord1.encrypt(); + wboRepo.wbos.put(record1.guid, encryptedRecord1); + + CryptoRecord encryptedRecord2 = record2.getEnvelope(); + encryptedRecord2.keyBundle = keyBundle; + encryptedRecord2 = encryptedRecord2.encrypt(); + wboRepo.wbos.put(record2.guid, encryptedRecord2); + + final ExpectSuccessRepositorySessionFetchRecordsDelegate fetchRecordsDelegate = new ExpectSuccessRepositorySessionFetchRecordsDelegate(getTestWaiter()); + runInOnBeginSucceeded(new Runnable() { + @Override public void run() { + try { + cmwSession.fetch(new String[] { record1.guid }, fetchRecordsDelegate); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + }); + performWait(onThreadRunnable(new Runnable() { + @Override public void run() { + try { + cmwSession.finish(new ExpectSuccessRepositorySessionFinishDelegate(getTestWaiter())); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + })); + + assertEquals(1, fetchRecordsDelegate.fetchedRecords.size()); + BookmarkRecord decryptedRecord = new BookmarkRecord(); + decryptedRecord.initFromEnvelope((CryptoRecord)fetchRecordsDelegate.fetchedRecords.get(0)); + assertEquals(record1.title, decryptedRecord.title); + } + + @Test + /** + * Verify that fetchAll is actually retrieving encrypted data from the underlying repository and is correctly decrypting it. + */ + public void testFetchAllDecrypts() throws UnsupportedEncodingException, CryptoException { + final BookmarkRecord record1 = new BookmarkRecord("nncdefghiaaa", "coll", System.currentTimeMillis(), false); + record1.title = "unencrypted title"; + final BookmarkRecord record2 = new BookmarkRecord("XXXXXXXXXXXX", "coll", System.currentTimeMillis(), false); + record2.title = "unencrypted second title"; + + CryptoRecord encryptedRecord1 = record1.getEnvelope(); + encryptedRecord1.keyBundle = keyBundle; + encryptedRecord1 = encryptedRecord1.encrypt(); + wboRepo.wbos.put(record1.guid, encryptedRecord1); + + CryptoRecord encryptedRecord2 = record2.getEnvelope(); + encryptedRecord2.keyBundle = keyBundle; + encryptedRecord2 = encryptedRecord2.encrypt(); + wboRepo.wbos.put(record2.guid, encryptedRecord2); + + final ExpectSuccessRepositorySessionFetchRecordsDelegate fetchAllRecordsDelegate = new ExpectSuccessRepositorySessionFetchRecordsDelegate(getTestWaiter()); + runInOnBeginSucceeded(new Runnable() { + @Override public void run() { + cmwSession.fetchAll(fetchAllRecordsDelegate); + } + }); + performWait(onThreadRunnable(new Runnable() { + @Override public void run() { + try { + cmwSession.finish(new ExpectSuccessRepositorySessionFinishDelegate(getTestWaiter())); + } catch (InactiveSessionException e) { + performNotify(e); + } + } + })); + + assertEquals(2, fetchAllRecordsDelegate.fetchedRecords.size()); + BookmarkRecord decryptedRecord1 = new BookmarkRecord(); + decryptedRecord1.initFromEnvelope((CryptoRecord)fetchAllRecordsDelegate.fetchedRecords.get(0)); + BookmarkRecord decryptedRecord2 = new BookmarkRecord(); + decryptedRecord2.initFromEnvelope((CryptoRecord)fetchAllRecordsDelegate.fetchedRecords.get(1)); + + // We should get two different decrypted records + assertFalse(decryptedRecord1.guid.equals(decryptedRecord2.guid)); + assertFalse(decryptedRecord1.title.equals(decryptedRecord2.title)); + // And we should know about both. + assertTrue(record1.title.equals(decryptedRecord1.title) || record1.title.equals(decryptedRecord2.title)); + assertTrue(record2.title.equals(decryptedRecord1.title) || record2.title.equals(decryptedRecord2.title)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestHMACAuthHeaderProvider.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestHMACAuthHeaderProvider.java new file mode 100644 index 000000000..675351be9 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestHMACAuthHeaderProvider.java @@ -0,0 +1,165 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.net.test; + +import ch.boye.httpclientandroidlib.client.methods.HttpGet; +import ch.boye.httpclientandroidlib.client.methods.HttpPost; +import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase; +import ch.boye.httpclientandroidlib.client.methods.HttpUriRequest; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.net.HMACAuthHeaderProvider; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +import static org.junit.Assert.assertEquals; + +@RunWith(TestRunner.class) +public class TestHMACAuthHeaderProvider { + // Expose a few protected static member functions as public for testing. + protected static class LeakyHMACAuthHeaderProvider extends HMACAuthHeaderProvider { + public LeakyHMACAuthHeaderProvider(String identifier, String key) { + super(identifier, key); + } + + public static String getRequestString(HttpUriRequest request, long timestampInSeconds, String nonce, String extra) { + return HMACAuthHeaderProvider.getRequestString(request, timestampInSeconds, nonce, extra); + } + + public static String getSignature(String requestString, String key) + throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException { + return HMACAuthHeaderProvider.getSignature(requestString, key); + } + } + + @Test + public void testGetRequestStringSpecExample1() throws Exception { + long timestamp = 1336363200; + String nonceString = "dj83hs9s"; + String extra = ""; + URI uri = new URI("http://example.com/resource/1?b=1&a=2"); + + HttpUriRequest req = new HttpGet(uri); + + String expected = "1336363200\n" + + "dj83hs9s\n" + + "GET\n" + + "/resource/1?b=1&a=2\n" + + "example.com\n" + + "80\n" + + "\n"; + + assertEquals(expected, LeakyHMACAuthHeaderProvider.getRequestString(req, timestamp, nonceString, extra)); + } + + @Test + public void testGetRequestStringSpecExample2() throws Exception { + long timestamp = 264095; + String nonceString = "7d8f3e4a"; + String extra = "a,b,c"; + URI uri = new URI("http://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b&c2&a3=2+q"); + + HttpUriRequest req = new HttpPost(uri); + + String expected = "264095\n" + + "7d8f3e4a\n" + + "POST\n" + + "/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b&c2&a3=2+q\n" + + "example.com\n" + + "80\n" + + "a,b,c\n"; + + assertEquals(expected, LeakyHMACAuthHeaderProvider.getRequestString(req, timestamp, nonceString, extra)); + } + + @Test + public void testPort() throws Exception { + long timestamp = 264095; + String nonceString = "7d8f3e4a"; + String extra = "a,b,c"; + URI uri = new URI("http://example.com:88/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b&c2&a3=2+q"); + + HttpUriRequest req = new HttpPost(uri); + + String expected = "264095\n" + + "7d8f3e4a\n" + + "POST\n" + + "/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b&c2&a3=2+q\n" + + "example.com\n" + + "88\n" + + "a,b,c\n"; + + assertEquals(expected, LeakyHMACAuthHeaderProvider.getRequestString(req, timestamp, nonceString, extra)); + } + + @Test + public void testHTTPS() throws Exception { + long timestamp = 264095; + String nonceString = "7d8f3e4a"; + String extra = "a,b,c"; + URI uri = new URI("https://example.com/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b&c2&a3=2+q"); + + HttpUriRequest req = new HttpPost(uri); + + String expected = "264095\n" + + "7d8f3e4a\n" + + "POST\n" + + "/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b&c2&a3=2+q\n" + + "example.com\n" + + "443\n" + + "a,b,c\n"; + + assertEquals(expected, LeakyHMACAuthHeaderProvider.getRequestString(req, timestamp, nonceString, extra)); + } + + @Test + public void testSpecSignatureExample() throws Exception { + String extra = ""; + long timestampInSeconds = 1336363200; + String nonceString = "dj83hs9s"; + + URI uri = new URI("http://example.com/resource/1?b=1&a=2"); + HttpRequestBase req = new HttpGet(uri); + + String requestString = LeakyHMACAuthHeaderProvider.getRequestString(req, timestampInSeconds, nonceString, extra); + + String expected = "1336363200\n" + + "dj83hs9s\n" + + "GET\n" + + "/resource/1?b=1&a=2\n" + + "example.com\n" + + "80\n" + + "\n"; + + assertEquals(expected, requestString); + + // There appears to be an error in the current spec. + // Spec is at https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01#section-1.1 + // Error is reported at http://www.ietf.org/mail-archive/web/oauth/current/msg09741.html + // assertEquals("bhCQXTVyfj5cmA9uKkPFx1zeOXM=", HMACAuthHeaderProvider.getSignature(requestString, keyString)); + } + + @Test + public void testCompatibleWithDesktopFirefox() throws Exception { + // These are test values used in the FF Sync Client testsuite. + + // String identifier = "vmo1txkttblmn51u2p3zk2xiy16hgvm5ok8qiv1yyi86ffjzy9zj0ez9x6wnvbx7"; + String keyString = "b8u1cc5iiio5o319og7hh8faf2gi5ym4aq0zwf112cv1287an65fudu5zj7zo7dz"; + + String extra = ""; + long timestampInSeconds = 1329181221; + String nonceString = "wGX71"; + + URI uri = new URI("http://10.250.2.176/alias/"); + HttpRequestBase req = new HttpGet(uri); + + String requestString = LeakyHMACAuthHeaderProvider.getRequestString(req, timestampInSeconds, nonceString, extra); + + assertEquals("jzh5chjQc2zFEvLbyHnPdX11Yck=", LeakyHMACAuthHeaderProvider.getSignature(requestString, keyString)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestHawkAuthHeaderProvider.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestHawkAuthHeaderProvider.java new file mode 100644 index 000000000..3dab313a0 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestHawkAuthHeaderProvider.java @@ -0,0 +1,145 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.net.test; + +import ch.boye.httpclientandroidlib.Header; +import ch.boye.httpclientandroidlib.client.methods.HttpGet; +import ch.boye.httpclientandroidlib.client.methods.HttpPost; +import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase; +import ch.boye.httpclientandroidlib.client.methods.HttpUriRequest; +import ch.boye.httpclientandroidlib.entity.StringEntity; +import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; +import ch.boye.httpclientandroidlib.message.BasicHeader; +import ch.boye.httpclientandroidlib.protocol.BasicHttpContext; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.net.HawkAuthHeaderProvider; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; + +import static org.junit.Assert.assertEquals; + +/** + * These test vectors were taken from + * https://github.com/hueniverse/hawk/blob/871cc597973110900467bd3dfb84a3c892f678fb/README.md. + */ +@RunWith(TestRunner.class) +public class TestHawkAuthHeaderProvider { + // Expose a few protected static member functions as public for testing. + protected static class LeakyHawkAuthHeaderProvider extends HawkAuthHeaderProvider { + public LeakyHawkAuthHeaderProvider(String tokenId, byte[] reqHMACKey) { + // getAuthHeader takes includePayloadHash as a parameter. + super(tokenId, reqHMACKey, false, 0L); + } + + // Public for testing. + public static String getRequestString(HttpUriRequest request, String type, long timestamp, String nonce, String hash, String extra, String app, String dlg) { + return HawkAuthHeaderProvider.getRequestString(request, type, timestamp, nonce, hash, extra, app, dlg); + } + + // Public for testing. + public static String getSignature(String requestString, String key) + throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException { + return HawkAuthHeaderProvider.getSignature(requestString.getBytes("UTF-8"), key.getBytes("UTF-8")); + } + + // Public for testing. + @Override + public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client, + long timestamp, String nonce, String extra, boolean includePayloadHash) + throws InvalidKeyException, NoSuchAlgorithmException, IOException { + return super.getAuthHeader(request, context, client, timestamp, nonce, extra, includePayloadHash); + } + + // Public for testing. + public static String getBaseContentType(Header contentTypeHeader) { + return HawkAuthHeaderProvider.getBaseContentType(contentTypeHeader); + } + } + + @Test + public void testSpecRequestString() throws Exception { + long timestamp = 1353832234; + String nonce = "j4h3g2"; + String extra = "some-app-ext-data"; + String hash = null; + String app = null; + String dlg = null; + + URI uri = new URI("http://example.com:8000/resource/1?b=1&a=2"); + HttpUriRequest req = new HttpGet(uri); + + String expected = "hawk.1.header\n" + + "1353832234\n" + + "j4h3g2\n" + + "GET\n" + + "/resource/1?b=1&a=2\n" + + "example.com\n" + + "8000\n" + + "\n" + + "some-app-ext-data\n"; + + // LeakyHawkAuthHeaderProvider. + assertEquals(expected, LeakyHawkAuthHeaderProvider.getRequestString(req, "header", timestamp, nonce, hash, extra, app, dlg)); + } + + @Test + public void testSpecSignatureExample() throws Exception { + String input = "hawk.1.header\n" + + "1353832234\n" + + "j4h3g2\n" + + "GET\n" + + "/resource/1?b=1&a=2\n" + + "example.com\n" + + "8000\n" + + "\n" + + "some-app-ext-data\n"; + + assertEquals("6R4rV5iE+NPoym+WwjeHzjAGXUtLNIxmo1vpMofpLAE=", LeakyHawkAuthHeaderProvider.getSignature(input, "werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn")); + } + + @Test + public void testSpecPayloadExample() throws Exception { + LeakyHawkAuthHeaderProvider provider = new LeakyHawkAuthHeaderProvider("dh37fgj492je", "werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn".getBytes("UTF-8")); + URI uri = new URI("http://example.com:8000/resource/1?b=1&a=2"); + HttpPost req = new HttpPost(uri); + String body = "Thank you for flying Hawk"; + req.setEntity(new StringEntity(body)); + Header header = provider.getAuthHeader(req, null, null, 1353832234L, "j4h3g2", "some-app-ext-data", true); + String expected = "Hawk id=\"dh37fgj492je\", ts=\"1353832234\", nonce=\"j4h3g2\", hash=\"Yi9LfIIFRtBEPt74PVmbTF/xVAwPn7ub15ePICfgnuY=\", ext=\"some-app-ext-data\", mac=\"aSe1DERmZuRl3pI36/9BdZmnErTw3sNzOOAUlfeKjVw=\""; + assertEquals("Authorization", header.getName()); + assertEquals(expected, header.getValue()); + } + + @Test + public void testSpecAuthorizationHeader() throws Exception { + LeakyHawkAuthHeaderProvider provider = new LeakyHawkAuthHeaderProvider("dh37fgj492je", "werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn".getBytes("UTF-8")); + URI uri = new URI("http://example.com:8000/resource/1?b=1&a=2"); + HttpGet req = new HttpGet(uri); + Header header = provider.getAuthHeader(req, null, null, 1353832234L, "j4h3g2", "some-app-ext-data", false); + String expected = "Hawk id=\"dh37fgj492je\", ts=\"1353832234\", nonce=\"j4h3g2\", ext=\"some-app-ext-data\", mac=\"6R4rV5iE+NPoym+WwjeHzjAGXUtLNIxmo1vpMofpLAE=\""; + assertEquals("Authorization", header.getName()); + assertEquals(expected, header.getValue()); + + // For a non-POST, non-PUT request, a request to include the payload verification hash is silently ignored. + header = provider.getAuthHeader(req, null, null, 1353832234L, "j4h3g2", "some-app-ext-data", true); + assertEquals("Authorization", header.getName()); + assertEquals(expected, header.getValue()); + } + + @Test + public void testGetBaseContentType() throws Exception { + assertEquals("text/plain", LeakyHawkAuthHeaderProvider.getBaseContentType(new BasicHeader("Content-Type", "text/plain"))); + assertEquals("text/plain", LeakyHawkAuthHeaderProvider.getBaseContentType(new BasicHeader("Content-Type", "text/plain;one"))); + assertEquals("text/plain", LeakyHawkAuthHeaderProvider.getBaseContentType(new BasicHeader("Content-Type", "text/plain;one;two"))); + assertEquals("text/html", LeakyHawkAuthHeaderProvider.getBaseContentType(new BasicHeader("Content-Type", "text/html;charset=UTF-8"))); + assertEquals("text/html", LeakyHawkAuthHeaderProvider.getBaseContentType(new BasicHeader("Content-Type", "text/html; charset=UTF-8"))); + assertEquals("text/html", LeakyHawkAuthHeaderProvider.getBaseContentType(new BasicHeader("Content-Type", "text/html ;charset=UTF-8"))); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestLiveHawkAuth.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestLiveHawkAuth.java new file mode 100644 index 000000000..8f136e3d0 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestLiveHawkAuth.java @@ -0,0 +1,181 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.net.test; + +import ch.boye.httpclientandroidlib.Header; +import ch.boye.httpclientandroidlib.HttpResponse; +import ch.boye.httpclientandroidlib.client.ClientProtocolException; +import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase; +import ch.boye.httpclientandroidlib.entity.StringEntity; +import ch.boye.httpclientandroidlib.impl.client.DefaultHttpClient; +import ch.boye.httpclientandroidlib.message.BasicHeader; +import ch.boye.httpclientandroidlib.protocol.BasicHttpContext; +import org.junit.Assert; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.BaseResourceDelegate; +import org.mozilla.gecko.sync.net.HawkAuthHeaderProvider; +import org.mozilla.gecko.sync.net.Resource; +import org.mozilla.gecko.sync.net.SyncResponse; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.GeneralSecurityException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + + +public class TestLiveHawkAuth { + /** + * Hawk comes with an example/usage.js server. Modify it to serve indefinitely, + * un-comment the following line, and verify that the port and credentials + * have not changed; then the following test should pass. + */ + // @org.junit.Test + public void testHawkUsage() throws Exception { + // Id and credentials are hard-coded in example/usage.js. + final String id = "dh37fgj492je"; + final byte[] key = "werxhqb98rpaxn39848xrunpaw3489ruxnpa98w4rxn".getBytes("UTF-8"); + final BaseResource resource = new BaseResource("http://localhost:8000/", false); + + // Basic GET. + resource.delegate = new TestBaseResourceDelegate(resource, new HawkAuthHeaderProvider(id, key, false, 0L)); + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + resource.get(); + } + }); + + // PUT with payload verification. + resource.delegate = new TestBaseResourceDelegate(resource, new HawkAuthHeaderProvider(id, key, true, 0L)); + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + try { + resource.put(new StringEntity("Thank you for flying Hawk")); + } catch (UnsupportedEncodingException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + }); + + // PUT with a large (32k or so) body and payload verification. + final StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 16000; i++) { + sb.append(Integer.valueOf(i % 100).toString()); + } + resource.delegate = new TestBaseResourceDelegate(resource, new HawkAuthHeaderProvider(id, key, true, 0L)); + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + try { + resource.put(new StringEntity(sb.toString())); + } catch (UnsupportedEncodingException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + }); + + // PUT without payload verification. + resource.delegate = new TestBaseResourceDelegate(resource, new HawkAuthHeaderProvider(id, key, false, 0L)); + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + try { + resource.put(new StringEntity("Thank you for flying Hawk")); + } catch (UnsupportedEncodingException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + }); + + // PUT with *bad* payload verification. + HawkAuthHeaderProvider provider = new HawkAuthHeaderProvider(id, key, true, 0L) { + @Override + public Header getAuthHeader(HttpRequestBase request, BasicHttpContext context, DefaultHttpClient client) throws GeneralSecurityException { + Header header = super.getAuthHeader(request, context, client); + // Here's a cheap way of breaking the hash. + String newValue = header.getValue().replaceAll("hash=\"....", "hash=\"XXXX"); + return new BasicHeader(header.getName(), newValue); + } + }; + + resource.delegate = new TestBaseResourceDelegate(resource, provider); + try { + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + try { + resource.put(new StringEntity("Thank you for flying Hawk")); + } catch (UnsupportedEncodingException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + }); + fail("Expected assertion after 401 response."); + } catch (WaitHelper.InnerError e) { + assertTrue(e.innerError instanceof AssertionError); + assertEquals("expected:<200> but was:<401>", ((AssertionError) e.innerError).getMessage()); + } + } + + protected final class TestBaseResourceDelegate extends BaseResourceDelegate { + protected final HawkAuthHeaderProvider provider; + + protected TestBaseResourceDelegate(Resource resource, HawkAuthHeaderProvider provider) throws UnsupportedEncodingException { + super(resource); + this.provider = provider; + } + + @Override + public AuthHeaderProvider getAuthHeaderProvider() { + return provider; + } + + @Override + public int connectionTimeout() { + return 1000; + } + + @Override + public int socketTimeout() { + return 1000; + } + + @Override + public void handleHttpResponse(HttpResponse response) { + SyncResponse res = new SyncResponse(response); + try { + Assert.assertEquals(200, res.getStatusCode()); + WaitHelper.getTestWaiter().performNotify(); + } catch (Throwable e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + + @Override + public void handleTransportException(GeneralSecurityException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + + @Override + public void handleHttpProtocolException(ClientProtocolException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + + @Override + public void handleHttpIOException(IOException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + + @Override + public String getUserAgent() { + return null; + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestUserAgentHeaders.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestUserAgentHeaders.java new file mode 100644 index 000000000..30b8a38ec --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/net/test/TestUserAgentHeaders.java @@ -0,0 +1,131 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.net.test; + +import ch.boye.httpclientandroidlib.protocol.HTTP; +import junit.framework.Assert; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.fxa.FxAccountClient20; +import org.mozilla.gecko.background.fxa.FxAccountClient20.RequestDelegate; +import org.mozilla.gecko.background.fxa.FxAccountClient20.RecoveryEmailStatusResponse; +import org.mozilla.gecko.background.fxa.FxAccountClientException.FxAccountClientRemoteException; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.fxa.FxAccountConstants; +import org.mozilla.gecko.sync.SyncConstants; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.SyncStorageRecordRequest; +import org.mozilla.gecko.sync.net.SyncStorageRequestDelegate; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.util.concurrent.Executors; + +@RunWith(TestRunner.class) +public class TestUserAgentHeaders { + private static final int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private static final String TEST_SERVER = "http://localhost:" + TEST_PORT; + + protected final HTTPServerTestHelper data = new HTTPServerTestHelper(); + + protected class UserAgentServer extends MockServer { + public String lastUserAgent = null; + + @Override + public void handle(Request request, Response response) { + lastUserAgent = request.getValue(HTTP.USER_AGENT); + super.handle(request, response); + } + } + + protected final UserAgentServer userAgentServer = new UserAgentServer(); + + @Before + public void setUp() { + BaseResource.rewriteLocalhost = false; + data.startHTTPServer(userAgentServer); + } + + @After + public void tearDown() { + data.stopHTTPServer(); + } + + @Test + public void testSyncUserAgent() throws Exception { + final SyncStorageRecordRequest request = new SyncStorageRecordRequest(TEST_SERVER); + request.delegate = new SyncStorageRequestDelegate() { + @Override + public String ifUnmodifiedSince() { + return null; + } + + @Override + public void handleRequestSuccess(SyncStorageResponse response) { + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void handleRequestFailure(SyncStorageResponse response) { + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void handleRequestError(Exception ex) { + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public AuthHeaderProvider getAuthHeaderProvider() { + return null; + } + }; + + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + request.get(); + } + }); + + // Verify that we're getting the value from the correct place. + Assert.assertEquals(SyncConstants.USER_AGENT, userAgentServer.lastUserAgent); + } + + @Test + public void testFxAccountClientUserAgent() throws Exception { + final FxAccountClient20 client = new FxAccountClient20(TEST_SERVER, Executors.newSingleThreadExecutor()); + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + client.recoveryEmailStatus(new byte[] { 0 }, new RequestDelegate() { + @Override + public void handleSuccess(RecoveryEmailStatusResponse result) { + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void handleFailure(FxAccountClientRemoteException e) { + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void handleError(Exception e) { + WaitHelper.getTestWaiter().performNotify(); + } + }); + } + }); + + // Verify that we're getting the value from the correct place. + Assert.assertEquals(FxAccountConstants.USER_AGENT, userAgentServer.lastUserAgent); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/BrowserContractHelpersTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/BrowserContractHelpersTest.java new file mode 100644 index 000000000..eecfa8dc2 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/BrowserContractHelpersTest.java @@ -0,0 +1,33 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.android; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class BrowserContractHelpersTest { + @Test + public void testBookmarkCodes() { + final String[] strings = { + // Observe omissions: "microsummary", "item". + "folder", "bookmark", "separator", "livemark", "query" + }; + for (int i = 0; i < strings.length; ++i) { + assertEquals(strings[i], BrowserContractHelpers.typeStringForCode(i)); + assertEquals(i, BrowserContractHelpers.typeCodeForString(strings[i])); + } + assertEquals(null, BrowserContractHelpers.typeStringForCode(-1)); + assertEquals(null, BrowserContractHelpers.typeStringForCode(100)); + + assertEquals(-1, BrowserContractHelpers.typeCodeForString(null)); + assertEquals(-1, BrowserContractHelpers.typeCodeForString("folder ")); + assertEquals(-1, BrowserContractHelpers.typeCodeForString("FOLDER")); + assertEquals(-1, BrowserContractHelpers.typeCodeForString("")); + assertEquals(-1, BrowserContractHelpers.typeCodeForString("nope")); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/VisitsHelperTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/VisitsHelperTest.java new file mode 100644 index 000000000..67bbca089 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/VisitsHelperTest.java @@ -0,0 +1,144 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.android; + +import android.content.ContentProviderClient; +import android.content.ContentValues; +import android.net.Uri; + +import junit.framework.Assert; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.db.DelegatingTestContentProvider; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.db.BrowserContract; +import org.mozilla.gecko.db.BrowserProvider; +import org.robolectric.shadows.ShadowContentResolver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class VisitsHelperTest { + @Test + public void testBulkInsertRemoteVisits() throws Exception { + JSONArray toInsert = new JSONArray(); + Assert.assertEquals(0, VisitsHelper.getVisitsContentValues("testGUID", toInsert).length); + + JSONObject visit = new JSONObject(); + Long date = Long.valueOf(123432552344l); + visit.put("date", date); + visit.put("type", 2l); + toInsert.add(visit); + + JSONObject visit2 = new JSONObject(); + visit2.put("date", date + 1000); + visit2.put("type", 5l); + toInsert.add(visit2); + + ContentValues[] cvs = VisitsHelper.getVisitsContentValues("testGUID", toInsert); + Assert.assertEquals(2, cvs.length); + ContentValues cv1 = cvs[0]; + ContentValues cv2 = cvs[1]; + Assert.assertEquals(Integer.valueOf(2), cv1.getAsInteger(BrowserContract.Visits.VISIT_TYPE)); + Assert.assertEquals(Integer.valueOf(5), cv2.getAsInteger(BrowserContract.Visits.VISIT_TYPE)); + + Assert.assertEquals(date, cv1.getAsLong("date")); + Assert.assertEquals(Long.valueOf(date + 1000), cv2.getAsLong(BrowserContract.Visits.DATE_VISITED)); + } + + @Test + public void testGetRecentHistoryVisitsForGUID() throws Exception { + Uri historyTestUri = testUri(BrowserContract.History.CONTENT_URI); + Uri visitsTestUri = testUri(BrowserContract.Visits.CONTENT_URI); + + BrowserProvider provider = new BrowserProvider(); + try { + provider.onCreate(); + ShadowContentResolver.registerProvider(BrowserContract.AUTHORITY, new DelegatingTestContentProvider(provider)); + + final ShadowContentResolver cr = new ShadowContentResolver(); + ContentProviderClient historyClient = cr.acquireContentProviderClient(BrowserContractHelpers.HISTORY_CONTENT_URI); + ContentProviderClient visitsClient = cr.acquireContentProviderClient(BrowserContractHelpers.VISITS_CONTENT_URI); + + ContentValues historyItem = new ContentValues(); + historyItem.put(BrowserContract.History.URL, "https://www.mozilla.org"); + historyItem.put(BrowserContract.History.GUID, "testGUID"); + historyClient.insert(historyTestUri, historyItem); + + Long baseDate = System.currentTimeMillis(); + for (int i = 0; i < 30; i++) { + ContentValues visitItem = new ContentValues(); + visitItem.put(BrowserContract.Visits.HISTORY_GUID, "testGUID"); + visitItem.put(BrowserContract.Visits.DATE_VISITED, baseDate - i * 100); + visitItem.put(BrowserContract.Visits.VISIT_TYPE, 1); + visitItem.put(BrowserContract.Visits.IS_LOCAL, 1); + visitsClient.insert(visitsTestUri, visitItem); + } + + // test that limit worked, that sorting is correct, and that both date and type are present + JSONArray recentVisits = VisitsHelper.getRecentHistoryVisitsForGUID(visitsClient, "testGUID", 10); + Assert.assertEquals(10, recentVisits.size()); + for (int i = 0; i < recentVisits.size(); i++) { + JSONObject v = (JSONObject) recentVisits.get(i); + Long date = (Long) v.get("date"); + Long type = (Long) v.get("type"); + Assert.assertEquals(Long.valueOf(baseDate - i * 100), date); + Assert.assertEquals(Long.valueOf(1), type); + } + } finally { + provider.shutdown(); + } + } + + @Test + public void testGetVisitContentValues() throws Exception { + JSONObject visit = new JSONObject(); + Long date = Long.valueOf(123432552344l); + visit.put("date", date); + visit.put("type", Long.valueOf(2)); + + ContentValues cv = VisitsHelper.getVisitContentValues("testGUID", visit, true); + assertTrue(cv.containsKey(BrowserContract.Visits.VISIT_TYPE)); + assertTrue(cv.containsKey(BrowserContract.Visits.DATE_VISITED)); + assertTrue(cv.containsKey(BrowserContract.Visits.HISTORY_GUID)); + assertTrue(cv.containsKey(BrowserContract.Visits.IS_LOCAL)); + assertEquals(4, cv.size()); + + assertEquals(date, cv.getAsLong(BrowserContract.Visits.DATE_VISITED)); + assertEquals(Long.valueOf(2), cv.getAsLong(BrowserContract.Visits.VISIT_TYPE)); + assertEquals("testGUID", cv.getAsString(BrowserContract.Visits.HISTORY_GUID)); + assertEquals(Integer.valueOf(1), cv.getAsInteger(BrowserContract.Visits.IS_LOCAL)); + + cv = VisitsHelper.getVisitContentValues("testGUID", visit, false); + assertEquals(Integer.valueOf(0), cv.getAsInteger(BrowserContract.Visits.IS_LOCAL)); + + try { + JSONObject visit2 = new JSONObject(); + visit.put("date", date); + VisitsHelper.getVisitContentValues("testGUID", visit2, false); + assertTrue("Must check that visit type key is present", false); + } catch (IllegalArgumentException e) {} + + try { + JSONObject visit3 = new JSONObject(); + visit.put("type", Long.valueOf(2)); + VisitsHelper.getVisitContentValues("testGUID", visit3, false); + assertTrue("Must check that visit date key is present", false); + } catch (IllegalArgumentException e) {} + + try { + JSONObject visit4 = new JSONObject(); + VisitsHelper.getVisitContentValues("testGUID", visit4, false); + assertTrue("Must check that visit type and date keys are present", false); + } catch (IllegalArgumentException e) {} + } + + private Uri testUri(Uri baseUri) { + return baseUri.buildUpon().appendQueryParameter(BrowserContract.PARAM_IS_TEST, "1").build(); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/test/TestBookmarksInsertionManager.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/test/TestBookmarksInsertionManager.java new file mode 100644 index 000000000..cbf5c37d3 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/android/test/TestBookmarksInsertionManager.java @@ -0,0 +1,221 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.android.test; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.android.BookmarksInsertionManager; +import org.mozilla.gecko.sync.repositories.domain.BookmarkRecord; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestBookmarksInsertionManager { + public BookmarksInsertionManager manager; + public ArrayList insertions; + + @Before + public void setUp() { + insertions = new ArrayList(); + Set writtenFolders = new HashSet(); + writtenFolders.add("mobile"); + + BookmarksInsertionManager.BookmarkInserter inserter = new BookmarksInsertionManager.BookmarkInserter() { + @Override + public boolean insertFolder(BookmarkRecord record) { + if (record.guid == "fail") { + return false; + } + Logger.debug(BookmarksInsertionManager.LOG_TAG, "Inserted folder (" + record.guid + ")."); + insertions.add(new String[] { record.guid }); + return true; + } + + @Override + public void bulkInsertNonFolders(Collection records) { + ArrayList guids = new ArrayList(); + for (BookmarkRecord record : records) { + guids.add(record.guid); + } + String[] guidList = guids.toArray(new String[guids.size()]); + insertions.add(guidList); + Logger.debug(BookmarksInsertionManager.LOG_TAG, "Inserted non-folders (" + Utils.toCommaSeparatedString(guids) + ")."); + } + }; + manager = new BookmarksInsertionManager(3, writtenFolders, inserter); + BookmarksInsertionManager.DEBUG = true; + } + + protected static BookmarkRecord bookmark(String guid, String parent) { + BookmarkRecord bookmark = new BookmarkRecord(guid); + bookmark.type = "bookmark"; + bookmark.parentID = parent; + return bookmark; + } + + protected static BookmarkRecord folder(String guid, String parent) { + BookmarkRecord bookmark = new BookmarkRecord(guid); + bookmark.type = "folder"; + bookmark.parentID = parent; + return bookmark; + } + + @Test + public void testChildrenBeforeFolder() { + BookmarkRecord folder = folder("folder", "mobile"); + BookmarkRecord child1 = bookmark("child1", "folder"); + BookmarkRecord child2 = bookmark("child2", "folder"); + + manager.enqueueRecord(child1); + assertTrue(insertions.isEmpty()); + manager.enqueueRecord(child2); + assertTrue(insertions.isEmpty()); + manager.enqueueRecord(folder); + assertEquals(1, insertions.size()); + manager.finishUp(); + assertTrue(manager.isClear()); + assertEquals(2, insertions.size()); + assertArrayEquals(new String[] { "folder" }, insertions.get(0)); + assertArrayEquals(new String[] { "child1", "child2" }, insertions.get(1)); + } + + @Test + public void testChildAfterFolder() { + BookmarkRecord folder = folder("folder", "mobile"); + BookmarkRecord child1 = bookmark("child1", "folder"); + BookmarkRecord child2 = bookmark("child2", "folder"); + + manager.enqueueRecord(child1); + assertTrue(insertions.isEmpty()); + manager.enqueueRecord(folder); + assertEquals(1, insertions.size()); + manager.enqueueRecord(child2); + assertEquals(1, insertions.size()); + manager.finishUp(); + assertTrue(manager.isClear()); + assertEquals(2, insertions.size()); + assertArrayEquals(new String[] { "folder" }, insertions.get(0)); + assertArrayEquals(new String[] { "child1", "child2" }, insertions.get(1)); + } + + @Test + public void testFolderAfterFolder() { + manager.enqueueRecord(bookmark("child1", "folder1")); + assertEquals(0, insertions.size()); + manager.enqueueRecord(folder("folder1", "mobile")); + assertEquals(1, insertions.size()); + manager.enqueueRecord(bookmark("child2", "folder2")); + assertEquals(1, insertions.size()); + manager.enqueueRecord(folder("folder2", "folder1")); + assertEquals(2, insertions.size()); + manager.enqueueRecord(bookmark("child3", "folder1")); + manager.enqueueRecord(bookmark("child4", "folder2")); + assertEquals(3, insertions.size()); + + manager.finishUp(); + assertTrue(manager.isClear()); + assertEquals(4, insertions.size()); + assertArrayEquals(new String[] { "folder1" }, insertions.get(0)); + assertArrayEquals(new String[] { "folder2" }, insertions.get(1)); + assertArrayEquals(new String[] { "child1", "child2", "child3" }, insertions.get(2)); + assertArrayEquals(new String[] { "child4" }, insertions.get(3)); + } + + @Test + public void testFolderRecursion() { + manager.enqueueRecord(folder("1", "mobile")); + manager.enqueueRecord(folder("2", "1")); + assertEquals(2, insertions.size()); + manager.enqueueRecord(bookmark("3a", "3")); + manager.enqueueRecord(bookmark("3b", "3")); + manager.enqueueRecord(bookmark("3c", "3")); + manager.enqueueRecord(bookmark("4a", "4")); + manager.enqueueRecord(bookmark("4b", "4")); + manager.enqueueRecord(bookmark("4c", "4")); + assertEquals(2, insertions.size()); + manager.enqueueRecord(folder("3", "2")); + assertEquals(4, insertions.size()); + manager.enqueueRecord(folder("4", "2")); + assertEquals(6, insertions.size()); + + assertTrue(manager.isClear()); + manager.finishUp(); + assertTrue(manager.isClear()); + // Folders in order. + assertArrayEquals(new String[] { "1" }, insertions.get(0)); + assertArrayEquals(new String[] { "2" }, insertions.get(1)); + assertArrayEquals(new String[] { "3" }, insertions.get(2)); + // Then children in batches of 3. + assertArrayEquals(new String[] { "3a", "3b", "3c" }, insertions.get(3)); + // Then last folder. + assertArrayEquals(new String[] { "4" }, insertions.get(4)); + assertArrayEquals(new String[] { "4a", "4b", "4c" }, insertions.get(5)); + } + + @Test + public void testFailedFolderInsertion() { + manager.enqueueRecord(bookmark("failA", "fail")); + manager.enqueueRecord(bookmark("failB", "fail")); + assertEquals(0, insertions.size()); + manager.enqueueRecord(folder("fail", "mobile")); + assertEquals(0, insertions.size()); + manager.enqueueRecord(bookmark("failC", "fail")); + assertEquals(0, insertions.size()); + manager.finishUp(); // Children inserted at the end; they will be treated as orphans. + assertTrue(manager.isClear()); + assertEquals(1, insertions.size()); + assertArrayEquals(new String[] { "failA", "failB", "failC" }, insertions.get(0)); + } + + @Test + public void testIncrementalFlush() { + manager.enqueueRecord(bookmark("a", "1")); + manager.enqueueRecord(bookmark("b", "1")); + manager.enqueueRecord(folder("1", "mobile")); + assertEquals(1, insertions.size()); + manager.enqueueRecord(bookmark("c", "1")); + assertEquals(2, insertions.size()); + manager.enqueueRecord(bookmark("d", "1")); + manager.enqueueRecord(bookmark("e", "1")); + manager.enqueueRecord(bookmark("f", "1")); + assertEquals(3, insertions.size()); + manager.enqueueRecord(bookmark("g", "1")); // Start of new batch. + assertEquals(3, insertions.size()); + manager.finishUp(); // Children inserted at the end; they will be treated as orphans. + assertTrue(manager.isClear()); + assertEquals(4, insertions.size()); + assertArrayEquals(new String[] { "1" }, insertions.get(0)); + assertArrayEquals(new String[] { "a", "b", "c"}, insertions.get(1)); + assertArrayEquals(new String[] { "d", "e", "f"}, insertions.get(2)); + assertArrayEquals(new String[] { "g" }, insertions.get(3)); + } + + @Test + public void testFinishUp() { + manager.enqueueRecord(bookmark("a", "1")); + manager.enqueueRecord(bookmark("b", "1")); + manager.enqueueRecord(folder("2", "1")); + manager.enqueueRecord(bookmark("c", "1")); + manager.enqueueRecord(bookmark("d", "1")); + manager.enqueueRecord(folder("3", "1")); + assertEquals(0, insertions.size()); + manager.finishUp(); // Children inserted at the end; they will be treated as orphans. + assertTrue(manager.isClear()); + assertEquals(3, insertions.size()); + assertArrayEquals(new String[] { "2" }, insertions.get(0)); + assertArrayEquals(new String[] { "3" }, insertions.get(1)); + assertArrayEquals(new String[] { "a", "b", "c", "d" }, insertions.get(2)); // Last insertion could be big. + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/domain/TestClientRecord.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/domain/TestClientRecord.java new file mode 100644 index 000000000..790d47620 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/domain/TestClientRecord.java @@ -0,0 +1,103 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.domain; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.Utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestClientRecord { + + @Test + public void testEnsureDefaults() { + // Ensure defaults. + ClientRecord record = new ClientRecord(); + assertEquals(ClientRecord.COLLECTION_NAME, record.collection); + assertEquals(0, record.lastModified); + assertEquals(false, record.deleted); + assertEquals("Default Name", record.name); + assertEquals(ClientRecord.CLIENT_TYPE, record.type); + assertTrue(null == record.os); + assertTrue(null == record.device); + assertTrue(null == record.application); + assertTrue(null == record.appPackage); + assertTrue(null == record.formfactor); + } + + @Test + public void testGetPayload() { + // Test ClientRecord.getPayload(). + ClientRecord record = new ClientRecord(); + CryptoRecord cryptoRecord = record.getEnvelope(); + assertEquals(record.guid, cryptoRecord.payload.get("id")); + assertEquals(null, cryptoRecord.payload.get("collection")); + assertEquals(null, cryptoRecord.payload.get("lastModified")); + assertEquals(null, cryptoRecord.payload.get("deleted")); + assertEquals(null, cryptoRecord.payload.get("version")); + assertEquals(record.name, cryptoRecord.payload.get("name")); + assertEquals(record.type, cryptoRecord.payload.get("type")); + } + + @Test + public void testInitFromPayload() { + // Test ClientRecord.initFromPayload() in ClientRecordFactory. + ClientRecord record1 = new ClientRecord(); + CryptoRecord cryptoRecord = record1.getEnvelope(); + ClientRecordFactory factory = new ClientRecordFactory(); + ClientRecord record2 = (ClientRecord) factory.createRecord(cryptoRecord); + assertEquals(cryptoRecord.payload.get("id"), record2.guid); + assertEquals(ClientRecord.COLLECTION_NAME, record2.collection); + assertEquals(0, record2.lastModified); + assertEquals(false, record2.deleted); + assertEquals(cryptoRecord.payload.get("name"), record2.name); + assertEquals(cryptoRecord.payload.get("type"), record2.type); + } + + @Test + public void testCopyWithIDs() { + // Test ClientRecord.copyWithIDs. + ClientRecord record1 = new ClientRecord(); + record1.version = "20"; + String newGUID = Utils.generateGuid(); + ClientRecord record2 = (ClientRecord) record1.copyWithIDs(newGUID, 0); + assertEquals(newGUID, record2.guid); + assertEquals(0, record2.androidID); + assertEquals(record1.collection, record2.collection); + assertEquals(record1.lastModified, record2.lastModified); + assertEquals(record1.deleted, record2.deleted); + assertEquals(record1.name, record2.name); + assertEquals(record1.type, record2.type); + assertEquals(record1.version, record2.version); + } + + @Test + public void testEquals() { + // Test ClientRecord.equals(). + ClientRecord record1 = new ClientRecord(); + ClientRecord record2 = new ClientRecord(); + record2.guid = record1.guid; + record2.version = "20"; + record1.version = null; + + ClientRecord record3 = new ClientRecord(Utils.generateGuid()); + record3.name = "New Name"; + + ClientRecord record4 = new ClientRecord(Utils.generateGuid()); + record4.name = ClientRecord.DEFAULT_CLIENT_NAME; + record4.type = "desktop"; + + assertTrue(record2.equals(record1)); + assertFalse(record3.equals(record1)); + assertFalse(record3.equals(record2)); + assertFalse(record4.equals(record1)); + assertFalse(record4.equals(record2)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/domain/test/TestFormHistoryRecord.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/domain/test/TestFormHistoryRecord.java new file mode 100644 index 000000000..c0682e90e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/domain/test/TestFormHistoryRecord.java @@ -0,0 +1,92 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.domain.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.domain.FormHistoryRecord; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestFormHistoryRecord { + public static FormHistoryRecord withIdFieldNameAndValue(long id, String fieldName, String value) { + FormHistoryRecord fr = new FormHistoryRecord(); + fr.androidID = id; + fr.fieldName = fieldName; + fr.fieldValue = value; + + return fr; + } + + @Test + public void testCollection() { + FormHistoryRecord fr = new FormHistoryRecord(); + assertEquals("forms", fr.collection); + } + + @Test + public void testGetPayload() { + FormHistoryRecord fr = withIdFieldNameAndValue(0, "username", "aUsername"); + CryptoRecord rec = fr.getEnvelope(); + assertEquals("username", rec.payload.get("name")); + assertEquals("aUsername", rec.payload.get("value")); + } + + @Test + public void testCopyWithIDs() { + FormHistoryRecord fr = withIdFieldNameAndValue(0, "username", "aUsername"); + String guid = Utils.generateGuid(); + FormHistoryRecord fr2 = (FormHistoryRecord)fr.copyWithIDs(guid, 9999); + assertEquals(guid, fr2.guid); + assertEquals(9999, fr2.androidID); + assertEquals(fr.fieldName, fr2.fieldName); + assertEquals(fr.fieldValue, fr2.fieldValue); + } + + @Test + public void testEquals() { + FormHistoryRecord fr1a = withIdFieldNameAndValue(0, "username1", "Alice"); + FormHistoryRecord fr1b = withIdFieldNameAndValue(0, "username1", "Bob"); + FormHistoryRecord fr2a = withIdFieldNameAndValue(0, "username2", "Alice"); + FormHistoryRecord fr2b = withIdFieldNameAndValue(0, "username2", "Bob"); + + assertFalse(fr1a.equals(fr1b)); + assertFalse(fr1a.equals(fr2a)); + assertFalse(fr1a.equals(fr2b)); + assertFalse(fr1b.equals(fr2a)); + assertFalse(fr1b.equals(fr2b)); + assertFalse(fr2a.equals(fr2b)); + + assertFalse(fr1a.equals(withIdFieldNameAndValue(fr1a.androidID, fr1a.fieldName, fr1b.fieldValue))); + assertFalse(fr1a.equals(fr1a.copyWithIDs(fr2a.guid, 9999))); + assertTrue(fr1a.equals(fr1a)); + } + + @Test + public void testEqualsForDeleted() { + FormHistoryRecord fr1 = withIdFieldNameAndValue(0, "username1", "Alice"); + FormHistoryRecord fr2 = (FormHistoryRecord)fr1.copyWithIDs(fr1.guid, fr1.androidID); + assertTrue(fr1.equals(fr2)); + fr1.deleted = true; + assertFalse(fr1.equals(fr2)); + fr2.deleted = true; + assertTrue(fr1.equals(fr2)); + FormHistoryRecord fr3 = (FormHistoryRecord)fr2.copyWithIDs(Utils.generateGuid(), 9999); + assertFalse(fr2.equals(fr3)); + } + + @Test + public void testTTL() { + FormHistoryRecord fr = withIdFieldNameAndValue(0, "username", "aUsername"); + assertEquals(FormHistoryRecord.FORMS_TTL, fr.ttl); + CryptoRecord rec = fr.getEnvelope(); + assertEquals(FormHistoryRecord.FORMS_TTL, rec.ttl); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java new file mode 100644 index 000000000..da2bbac18 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderDelegateTest.java @@ -0,0 +1,186 @@ +/* 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 org.mozilla.gecko.sync.repositories.downloaders; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.HTTPFailureException; +import org.mozilla.gecko.sync.InfoCollections; +import org.mozilla.gecko.sync.InfoConfiguration; +import org.mozilla.gecko.sync.net.SyncResponse; +import org.mozilla.gecko.sync.net.SyncStorageCollectionRequest; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.mozilla.gecko.sync.repositories.Server11Repository; +import org.mozilla.gecko.sync.repositories.Server11RepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import java.net.URI; +import java.util.concurrent.ExecutorService; + +import ch.boye.httpclientandroidlib.ProtocolVersion; +import ch.boye.httpclientandroidlib.client.ClientProtocolException; +import ch.boye.httpclientandroidlib.message.BasicHttpResponse; +import ch.boye.httpclientandroidlib.message.BasicStatusLine; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class BatchingDownloaderDelegateTest { + private Server11Repository server11Repository; + private Server11RepositorySession repositorySession; + private MockDownloader mockDownloader; + private String DEFAULT_COLLECTION_URL = "http://dummy.url/"; + + class MockDownloader extends BatchingDownloader { + public boolean isSuccess = false; + public boolean isFetched = false; + public boolean isFailure = false; + public Exception ex; + + public MockDownloader(Server11Repository repository, Server11RepositorySession repositorySession) { + super(repository, repositorySession); + } + + @Override + public void onFetchCompleted(SyncStorageResponse response, + final RepositorySessionFetchRecordsDelegate fetchRecordsDelegate, + final SyncStorageCollectionRequest request, + long l, long newerTimestamp, boolean full, String sort, String ids) { + this.isSuccess = true; + } + + @Override + public void onFetchFailed(final Exception ex, + final RepositorySessionFetchRecordsDelegate fetchRecordsDelegate, + final SyncStorageCollectionRequest request) { + this.isFailure = true; + this.ex = ex; + } + + @Override + public void onFetchedRecord(CryptoRecord record, + RepositorySessionFetchRecordsDelegate fetchRecordsDelegate) { + this.isFetched = true; + } + } + + class SimpleSessionFetchRecordsDelegate implements RepositorySessionFetchRecordsDelegate { + @Override + public void onFetchFailed(Exception ex, Record record) { + + } + + @Override + public void onFetchedRecord(Record record) { + + } + + @Override + public void onFetchCompleted(long fetchEnd) { + + } + + @Override + public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) { + return null; + } + } + + @Before + public void setUp() throws Exception { + server11Repository = new Server11Repository( + "dummyCollection", + DEFAULT_COLLECTION_URL, + null, + new InfoCollections(), + new InfoConfiguration()); + repositorySession = new Server11RepositorySession(server11Repository); + mockDownloader = new MockDownloader(server11Repository, repositorySession); + } + + @Test + public void testIfUnmodifiedSince() throws Exception { + BatchingDownloader downloader = new BatchingDownloader(server11Repository, repositorySession); + RepositorySessionFetchRecordsDelegate delegate = new SimpleSessionFetchRecordsDelegate(); + BatchingDownloaderDelegate downloaderDelegate = new BatchingDownloaderDelegate(downloader, delegate, + new SyncStorageCollectionRequest(new URI(DEFAULT_COLLECTION_URL)), 0, 0, true, null, null); + String lastModified = "12345678"; + SyncStorageResponse response = makeSyncStorageResponse(200, lastModified); + downloaderDelegate.handleRequestSuccess(response); + assertEquals(lastModified, downloaderDelegate.ifUnmodifiedSince()); + } + + @Test + public void testSuccess() throws Exception { + BatchingDownloaderDelegate downloaderDelegate = new BatchingDownloaderDelegate(mockDownloader, null, + new SyncStorageCollectionRequest(new URI(DEFAULT_COLLECTION_URL)), 0, 0, true, null, null); + SyncStorageResponse response = makeSyncStorageResponse(200, "12345678"); + downloaderDelegate.handleRequestSuccess(response); + assertTrue(mockDownloader.isSuccess); + assertFalse(mockDownloader.isFailure); + assertFalse(mockDownloader.isFetched); + } + + @Test + public void testFailureMissingLMHeader() throws Exception { + BatchingDownloaderDelegate downloaderDelegate = new BatchingDownloaderDelegate(mockDownloader, null, + new SyncStorageCollectionRequest(new URI(DEFAULT_COLLECTION_URL)), 0, 0, true, null, null); + SyncStorageResponse response = makeSyncStorageResponse(200, null); + downloaderDelegate.handleRequestSuccess(response); + assertTrue(mockDownloader.isFailure); + assertEquals(IllegalStateException.class, mockDownloader.ex.getClass()); + assertFalse(mockDownloader.isSuccess); + assertFalse(mockDownloader.isFetched); + } + + @Test + public void testFailureHTTPException() throws Exception { + BatchingDownloaderDelegate downloaderDelegate = new BatchingDownloaderDelegate(mockDownloader, null, + new SyncStorageCollectionRequest(new URI(DEFAULT_COLLECTION_URL)), 0, 0, true, null, null); + SyncStorageResponse response = makeSyncStorageResponse(400, null); + downloaderDelegate.handleRequestFailure(response); + assertTrue(mockDownloader.isFailure); + assertEquals(HTTPFailureException.class, mockDownloader.ex.getClass()); + assertFalse(mockDownloader.isSuccess); + assertFalse(mockDownloader.isFetched); + } + + @Test + public void testFailureRequestError() throws Exception { + BatchingDownloaderDelegate downloaderDelegate = new BatchingDownloaderDelegate(mockDownloader, null, + new SyncStorageCollectionRequest(new URI(DEFAULT_COLLECTION_URL)), 0, 0, true, null, null); + downloaderDelegate.handleRequestError(new ClientProtocolException()); + assertTrue(mockDownloader.isFailure); + assertEquals(ClientProtocolException.class, mockDownloader.ex.getClass()); + assertFalse(mockDownloader.isSuccess); + assertFalse(mockDownloader.isFetched); + } + + @Test + public void testFetchRecord() throws Exception { + BatchingDownloaderDelegate downloaderDelegate = new BatchingDownloaderDelegate(mockDownloader, null, + new SyncStorageCollectionRequest(new URI(DEFAULT_COLLECTION_URL)), 0, 0, true, null, null); + CryptoRecord record = new CryptoRecord(); + downloaderDelegate.handleWBO(record); + assertTrue(mockDownloader.isFetched); + assertFalse(mockDownloader.isSuccess); + assertFalse(mockDownloader.isFailure); + } + + private SyncStorageResponse makeSyncStorageResponse(int code, String lastModified) { + BasicHttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), code, null)); + + if (lastModified != null) { + response.addHeader(SyncResponse.X_LAST_MODIFIED, lastModified); + } + + return new SyncStorageResponse(response); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java new file mode 100644 index 000000000..fbbd9cae9 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/downloaders/BatchingDownloaderTest.java @@ -0,0 +1,543 @@ +/* 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 org.mozilla.gecko.sync.repositories.downloaders; + +import android.support.annotation.NonNull; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.InfoCollections; +import org.mozilla.gecko.sync.InfoConfiguration; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.SyncResponse; +import org.mozilla.gecko.sync.net.SyncStorageCollectionRequest; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.mozilla.gecko.sync.repositories.Repository; +import org.mozilla.gecko.sync.repositories.Server11Repository; +import org.mozilla.gecko.sync.repositories.Server11RepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionFetchRecordsDelegate; +import org.mozilla.gecko.sync.repositories.domain.Record; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.concurrent.ExecutorService; + +import ch.boye.httpclientandroidlib.ProtocolVersion; +import ch.boye.httpclientandroidlib.message.BasicHttpResponse; +import ch.boye.httpclientandroidlib.message.BasicStatusLine; + +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + +@RunWith(TestRunner.class) +public class BatchingDownloaderTest { + private MockSever11Repository serverRepository; + private Server11RepositorySession repositorySession; + private MockSessionFetchRecordsDelegate sessionFetchRecordsDelegate; + private MockDownloader mockDownloader; + private String DEFAULT_COLLECTION_NAME = "dummyCollection"; + private String DEFAULT_COLLECTION_URL = "http://dummy.url/"; + private long DEFAULT_NEWER = 1; + private String DEFAULT_SORT = "index"; + private String DEFAULT_IDS = "1"; + private String DEFAULT_LMHEADER = "12345678"; + + class MockSessionFetchRecordsDelegate implements RepositorySessionFetchRecordsDelegate { + public boolean isFailure; + public boolean isFetched; + public boolean isSuccess; + public Exception ex; + public Record record; + + @Override + public void onFetchFailed(Exception ex, Record record) { + this.isFailure = true; + this.ex = ex; + this.record = record; + } + + @Override + public void onFetchedRecord(Record record) { + this.isFetched = true; + this.record = record; + } + + @Override + public void onFetchCompleted(long fetchEnd) { + this.isSuccess = true; + } + + @Override + public RepositorySessionFetchRecordsDelegate deferredFetchDelegate(ExecutorService executor) { + return null; + } + } + + class MockRequest extends SyncStorageCollectionRequest { + + public MockRequest(URI uri) { + super(uri); + } + + @Override + public void get() { + + } + } + + class MockDownloader extends BatchingDownloader { + public long newer; + public long limit; + public boolean full; + public String sort; + public String ids; + public String offset; + public boolean abort; + + public MockDownloader(Server11Repository repository, Server11RepositorySession repositorySession) { + super(repository, repositorySession); + } + + @Override + public void fetchWithParameters(long newer, + long batchLimit, + boolean full, + String sort, + String ids, + SyncStorageCollectionRequest request, + RepositorySessionFetchRecordsDelegate fetchRecordsDelegate) + throws UnsupportedEncodingException, URISyntaxException { + this.newer = newer; + this.limit = batchLimit; + this.full = full; + this.sort = sort; + this.ids = ids; + MockRequest mockRequest = new MockRequest(new URI(DEFAULT_COLLECTION_URL)); + super.fetchWithParameters(newer, batchLimit, full, sort, ids, mockRequest, fetchRecordsDelegate); + } + + @Override + public void abortRequests() { + this.abort = true; + } + + @Override + public SyncStorageCollectionRequest makeSyncStorageCollectionRequest(long newer, + long batchLimit, + boolean full, + String sort, + String ids, + String offset) + throws URISyntaxException, UnsupportedEncodingException { + this.offset = offset; + return super.makeSyncStorageCollectionRequest(newer, batchLimit, full, sort, ids, offset); + } + } + + class MockSever11Repository extends Server11Repository { + public MockSever11Repository(@NonNull String collection, @NonNull String storageURL, + AuthHeaderProvider authHeaderProvider, @NonNull InfoCollections infoCollections, + @NonNull InfoConfiguration infoConfiguration) throws URISyntaxException { + super(collection, storageURL, authHeaderProvider, infoCollections, infoConfiguration); + } + + @Override + public long getDefaultTotalLimit() { + return 200; + } + } + + class MockRepositorySession extends Server11RepositorySession { + public boolean abort; + + public MockRepositorySession(Repository repository) { + super(repository); + } + + @Override + public void abort() { + this.abort = true; + } + } + + @Before + public void setUp() throws Exception { + sessionFetchRecordsDelegate = new MockSessionFetchRecordsDelegate(); + + serverRepository = new MockSever11Repository(DEFAULT_COLLECTION_NAME, DEFAULT_COLLECTION_URL, null, + new InfoCollections(), new InfoConfiguration()); + repositorySession = new Server11RepositorySession(serverRepository); + mockDownloader = new MockDownloader(serverRepository, repositorySession); + } + + @Test + public void testFlattenId() { + String[] emptyGuid = new String[]{}; + String flatten = BatchingDownloader.flattenIDs(emptyGuid); + assertEquals("", flatten); + + String guid0 = "123456789abc"; + String[] singleGuid = new String[1]; + singleGuid[0] = guid0; + flatten = BatchingDownloader.flattenIDs(singleGuid); + assertEquals("123456789abc", flatten); + + String guid1 = "456789abc"; + String guid2 = "789abc"; + String[] multiGuid = new String[3]; + multiGuid[0] = guid0; + multiGuid[1] = guid1; + multiGuid[2] = guid2; + flatten = BatchingDownloader.flattenIDs(multiGuid); + assertEquals("123456789abc,456789abc,789abc", flatten); + } + + @Test + public void testEncodeParam() throws Exception { + String param = "123&123"; + String encodedParam = mockDownloader.encodeParam(param); + assertEquals("123%26123", encodedParam); + } + + @Test(expected=IllegalArgumentException.class) + public void testOverTotalLimit() throws Exception { + // Per-batch limits exceed total. + Server11Repository repository = new Server11Repository(DEFAULT_COLLECTION_NAME, DEFAULT_COLLECTION_URL, + null, new InfoCollections(), new InfoConfiguration()) { + @Override + public long getDefaultTotalLimit() { + return 100; + } + @Override + public long getDefaultBatchLimit() { + return 200; + } + }; + MockDownloader mockDownloader = new MockDownloader(repository, repositorySession); + + assertNull(mockDownloader.getLastModified()); + mockDownloader.fetchSince(DEFAULT_NEWER, sessionFetchRecordsDelegate); + } + + @Test + public void testTotalLimit() throws Exception { + // Total and per-batch limits are the same. + Server11Repository repository = new Server11Repository(DEFAULT_COLLECTION_NAME, DEFAULT_COLLECTION_URL, + null, new InfoCollections(), new InfoConfiguration()) { + @Override + public long getDefaultTotalLimit() { + return 100; + } + @Override + public long getDefaultBatchLimit() { + return 100; + } + }; + MockDownloader mockDownloader = new MockDownloader(repository, repositorySession); + + assertNull(mockDownloader.getLastModified()); + mockDownloader.fetchSince(DEFAULT_NEWER, sessionFetchRecordsDelegate); + + SyncStorageResponse response = makeSyncStorageResponse(200, DEFAULT_LMHEADER, "100", "100"); + SyncStorageCollectionRequest request = new SyncStorageCollectionRequest(new URI(DEFAULT_COLLECTION_URL)); + long limit = repository.getDefaultBatchLimit(); + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, + DEFAULT_NEWER, limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertEquals(DEFAULT_LMHEADER, mockDownloader.getLastModified()); + assertTrue(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isFailure); + } + + @Test + public void testOverHalfOfTotalLimit() throws Exception { + // Per-batch limit is just a bit lower than total. + Server11Repository repository = new Server11Repository(DEFAULT_COLLECTION_NAME, DEFAULT_COLLECTION_URL, + null, new InfoCollections(), new InfoConfiguration()) { + @Override + public long getDefaultTotalLimit() { + return 100; + } + @Override + public long getDefaultBatchLimit() { + return 75; + } + }; + MockDownloader mockDownloader = new MockDownloader(repository, repositorySession); + + assertNull(mockDownloader.getLastModified()); + mockDownloader.fetchSince(DEFAULT_NEWER, sessionFetchRecordsDelegate); + + String offsetHeader = "75"; + String recordsHeader = "75"; + SyncStorageResponse response = makeSyncStorageResponse(200, DEFAULT_LMHEADER, offsetHeader, recordsHeader); + SyncStorageCollectionRequest request = new SyncStorageCollectionRequest(new URI(DEFAULT_COLLECTION_URL)); + long limit = repository.getDefaultBatchLimit(); + + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertEquals(DEFAULT_LMHEADER, mockDownloader.getLastModified()); + // Verify the same parameters are used in the next fetch. + assertSameParameters(mockDownloader, limit); + assertEquals(offsetHeader, mockDownloader.offset); + assertFalse(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isFailure); + + // The next batch, we still have an offset token but we complete our fetch since we have reached the total limit. + offsetHeader = "150"; + response = makeSyncStorageResponse(200, DEFAULT_LMHEADER, offsetHeader, recordsHeader); + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertEquals(DEFAULT_LMHEADER, mockDownloader.getLastModified()); + assertTrue(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isFailure); + } + + @Test + public void testHalfOfTotalLimit() throws Exception { + // Per-batch limit is half of total. + Server11Repository repository = new Server11Repository(DEFAULT_COLLECTION_NAME, DEFAULT_COLLECTION_URL, + null, new InfoCollections(), new InfoConfiguration()) { + @Override + public long getDefaultTotalLimit() { + return 100; + } + @Override + public long getDefaultBatchLimit() { + return 50; + } + }; + mockDownloader = new MockDownloader(repository, repositorySession); + + assertNull(mockDownloader.getLastModified()); + mockDownloader.fetchSince(DEFAULT_NEWER, sessionFetchRecordsDelegate); + + String offsetHeader = "50"; + String recordsHeader = "50"; + SyncStorageResponse response = makeSyncStorageResponse(200, DEFAULT_LMHEADER, offsetHeader, recordsHeader); + SyncStorageCollectionRequest request = new SyncStorageCollectionRequest(new URI(DEFAULT_COLLECTION_URL)); + long limit = repository.getDefaultBatchLimit(); + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertEquals(DEFAULT_LMHEADER, mockDownloader.getLastModified()); + // Verify the same parameters are used in the next fetch. + assertSameParameters(mockDownloader, limit); + assertEquals(offsetHeader, mockDownloader.offset); + assertFalse(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isFailure); + + // The next batch, we still have an offset token but we complete our fetch since we have reached the total limit. + offsetHeader = "100"; + response = makeSyncStorageResponse(200, DEFAULT_LMHEADER, offsetHeader, recordsHeader); + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertEquals(DEFAULT_LMHEADER, mockDownloader.getLastModified()); + assertTrue(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isFailure); + } + + @Test + public void testFractionOfTotalLimit() throws Exception { + // Per-batch limit is a small fraction of the total. + Server11Repository repository = new Server11Repository(DEFAULT_COLLECTION_NAME, DEFAULT_COLLECTION_URL, + null, new InfoCollections(), new InfoConfiguration()) { + @Override + public long getDefaultTotalLimit() { + return 100; + } + @Override + public long getDefaultBatchLimit() { + return 25; + } + }; + mockDownloader = new MockDownloader(repository, repositorySession); + + assertNull(mockDownloader.getLastModified()); + mockDownloader.fetchSince(DEFAULT_NEWER, sessionFetchRecordsDelegate); + + String offsetHeader = "25"; + String recordsHeader = "25"; + SyncStorageResponse response = makeSyncStorageResponse(200, DEFAULT_LMHEADER, offsetHeader, recordsHeader); + SyncStorageCollectionRequest request = new SyncStorageCollectionRequest(new URI(DEFAULT_COLLECTION_URL)); + long limit = repository.getDefaultBatchLimit(); + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertEquals(DEFAULT_LMHEADER, mockDownloader.getLastModified()); + // Verify the same parameters are used in the next fetch. + assertSameParameters(mockDownloader, limit); + assertEquals(offsetHeader, mockDownloader.offset); + assertFalse(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isFailure); + + // The next batch, we still have an offset token and has not exceed the total limit. + offsetHeader = "50"; + response = makeSyncStorageResponse(200, DEFAULT_LMHEADER, offsetHeader, recordsHeader); + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertEquals(DEFAULT_LMHEADER, mockDownloader.getLastModified()); + // Verify the same parameters are used in the next fetch. + assertSameParameters(mockDownloader, limit); + assertEquals(offsetHeader, mockDownloader.offset); + assertFalse(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isFailure); + + // The next batch, we still have an offset token and has not exceed the total limit. + offsetHeader = "75"; + response = makeSyncStorageResponse(200, DEFAULT_LMHEADER, offsetHeader, recordsHeader); + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertEquals(DEFAULT_LMHEADER, mockDownloader.getLastModified()); + // Verify the same parameters are used in the next fetch. + assertSameParameters(mockDownloader, limit); + assertEquals(offsetHeader, mockDownloader.offset); + assertFalse(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isFailure); + + // The next batch, we still have an offset token but we complete our fetch since we have reached the total limit. + offsetHeader = "100"; + response = makeSyncStorageResponse(200, DEFAULT_LMHEADER, offsetHeader, recordsHeader); + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertEquals(DEFAULT_LMHEADER, mockDownloader.getLastModified()); + assertTrue(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isFailure); + } + + @Test + public void testFailureLMChangedMultiBatch() throws Exception { + assertNull(mockDownloader.getLastModified()); + + String lmHeader = "12345678"; + String offsetHeader = "100"; + SyncStorageResponse response = makeSyncStorageResponse(200, lmHeader, offsetHeader, null); + SyncStorageCollectionRequest request = new SyncStorageCollectionRequest(new URI("http://dummy.url")); + long limit = 1; + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertEquals(lmHeader, mockDownloader.getLastModified()); + // Verify the same parameters are used in the next fetch. + assertEquals(DEFAULT_NEWER, mockDownloader.newer); + assertEquals(limit, mockDownloader.limit); + assertTrue(mockDownloader.full); + assertEquals(DEFAULT_SORT, mockDownloader.sort); + assertEquals(DEFAULT_IDS, mockDownloader.ids); + assertEquals(offsetHeader, mockDownloader.offset); + assertFalse(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isFailure); + + // Last modified header somehow changed. + lmHeader = "10000000"; + response = makeSyncStorageResponse(200, lmHeader, offsetHeader, null); + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + limit, true, DEFAULT_SORT, DEFAULT_IDS); + + assertNotEquals(lmHeader, mockDownloader.getLastModified()); + assertTrue(mockDownloader.abort); + assertFalse(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertTrue(sessionFetchRecordsDelegate.isFailure); + } + + @Test + public void testFailureMissingLMMultiBatch() throws Exception { + assertNull(mockDownloader.getLastModified()); + + String offsetHeader = "100"; + SyncStorageResponse response = makeSyncStorageResponse(200, null, offsetHeader, null); + SyncStorageCollectionRequest request = new SyncStorageCollectionRequest(new URI("http://dummy.url")); + mockDownloader.onFetchCompleted(response, sessionFetchRecordsDelegate, request, DEFAULT_NEWER, + 1, true, DEFAULT_SORT, DEFAULT_IDS); + + // Last modified header somehow missing from response. + assertNull(null, mockDownloader.getLastModified()); + assertTrue(mockDownloader.abort); + assertFalse(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertTrue(sessionFetchRecordsDelegate.isFailure); + } + + @Test + public void testFailureException() throws Exception { + Exception ex = new IllegalStateException(); + SyncStorageCollectionRequest request = new SyncStorageCollectionRequest(new URI("http://dummy.url")); + mockDownloader.onFetchFailed(ex, sessionFetchRecordsDelegate, request); + + assertFalse(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFetched); + assertTrue(sessionFetchRecordsDelegate.isFailure); + assertEquals(ex.getClass(), sessionFetchRecordsDelegate.ex.getClass()); + assertNull(sessionFetchRecordsDelegate.record); + } + + @Test + public void testFetchRecord() { + CryptoRecord record = new CryptoRecord(); + mockDownloader.onFetchedRecord(record, sessionFetchRecordsDelegate); + + assertTrue(sessionFetchRecordsDelegate.isFetched); + assertFalse(sessionFetchRecordsDelegate.isSuccess); + assertFalse(sessionFetchRecordsDelegate.isFailure); + assertEquals(record, sessionFetchRecordsDelegate.record); + } + + @Test + public void testAbortRequests() { + MockRepositorySession mockRepositorySession = new MockRepositorySession(serverRepository); + BatchingDownloader downloader = new BatchingDownloader(serverRepository, mockRepositorySession); + assertFalse(mockRepositorySession.abort); + downloader.abortRequests(); + assertTrue(mockRepositorySession.abort); + } + + private void assertSameParameters(MockDownloader mockDownloader, long limit) { + assertEquals(DEFAULT_NEWER, mockDownloader.newer); + assertEquals(limit, mockDownloader.limit); + assertTrue(mockDownloader.full); + assertEquals(DEFAULT_SORT, mockDownloader.sort); + assertEquals(DEFAULT_IDS, mockDownloader.ids); + } + + private SyncStorageResponse makeSyncStorageResponse(int code, String lastModified, String offset, String records) { + BasicHttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), code, null)); + + if (lastModified != null) { + response.addHeader(SyncResponse.X_LAST_MODIFIED, lastModified); + } + + if (offset != null) { + response.addHeader(SyncResponse.X_WEAVE_NEXT_OFFSET, offset); + } + + if (records != null) { + response.addHeader(SyncResponse.X_WEAVE_RECORDS, records); + } + + return new SyncStorageResponse(response); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/test/TestRepositorySessionBundle.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/test/TestRepositorySessionBundle.java new file mode 100644 index 000000000..e81d13640 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/test/TestRepositorySessionBundle.java @@ -0,0 +1,47 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.repositories.RepositorySessionBundle; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(TestRunner.class) +public class TestRepositorySessionBundle { + @Test + public void testSetGetTimestamp() { + RepositorySessionBundle bundle = new RepositorySessionBundle(-1); + assertEquals(-1, bundle.getTimestamp()); + + bundle.setTimestamp(10); + assertEquals(10, bundle.getTimestamp()); + } + + @Test + public void testBumpTimestamp() { + RepositorySessionBundle bundle = new RepositorySessionBundle(50); + assertEquals(50, bundle.getTimestamp()); + + bundle.bumpTimestamp(20); + assertEquals(50, bundle.getTimestamp()); + + bundle.bumpTimestamp(80); + assertEquals(80, bundle.getTimestamp()); + } + + @Test + public void testSerialize() throws Exception { + RepositorySessionBundle bundle = new RepositorySessionBundle(50); + + String json = bundle.toJSONString(); + assertNotNull(json); + + RepositorySessionBundle read = new RepositorySessionBundle(json); + assertEquals(50, read.getTimestamp()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/test/TestSafeConstrainedServer11Repository.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/test/TestSafeConstrainedServer11Repository.java new file mode 100644 index 000000000..249a7831a --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/test/TestSafeConstrainedServer11Repository.java @@ -0,0 +1,144 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.test; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.InfoCollections; +import org.mozilla.gecko.sync.InfoConfiguration; +import org.mozilla.gecko.sync.JSONRecordFetcher; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.repositories.RepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionCreationDelegate; +import org.mozilla.gecko.sync.stage.SafeConstrainedServer11Repository; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.net.URISyntaxException; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +@RunWith(TestRunner.class) +public class TestSafeConstrainedServer11Repository { + private static final int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private static final String TEST_SERVER = "http://localhost:" + TEST_PORT + "/"; + private static final String TEST_USERNAME = "c6o7dvmr2c4ud2fyv6woz2u4zi22bcyd"; + private static final String TEST_BASE_PATH = "/1.1/" + TEST_USERNAME + "/"; + + public AuthHeaderProvider getAuthHeaderProvider() { + return null; + } + + protected final InfoCollections infoCollections = new InfoCollections(); + protected final InfoConfiguration infoConfiguration = new InfoConfiguration(); + + private class CountsMockServer extends MockServer { + public final AtomicInteger count = new AtomicInteger(0); + public final AtomicBoolean error = new AtomicBoolean(false); + + @Override + public void handle(Request request, Response response) { + final String path = request.getPath().getPath(); + if (error.get()) { + super.handle(request, response, 503, "Unavailable."); + return; + } + + if (!path.startsWith(TEST_BASE_PATH)) { + super.handle(request, response, 404, "Not Found"); + return; + } + + if (path.endsWith("info/collections")) { + super.handle(request, response, 200, "{\"rotary\": 123456789}"); + return; + } + + if (path.endsWith("info/collection_counts")) { + super.handle(request, response, 200, "{\"rotary\": " + count.get() + "}"); + return; + } + + super.handle(request, response); + } + } + + /** + * Ensure that a {@link SafeConstrainedServer11Repository} will advise + * skipping if the reported collection counts are higher than its limit. + */ + @Test + public void testShouldSkip() throws URISyntaxException { + final HTTPServerTestHelper data = new HTTPServerTestHelper(); + final CountsMockServer server = new CountsMockServer(); + data.startHTTPServer(server); + + try { + String countsURL = TEST_SERVER + TEST_BASE_PATH + "info/collection_counts"; + JSONRecordFetcher countFetcher = new JSONRecordFetcher(countsURL, getAuthHeaderProvider()); + String sort = "sortindex"; + String collection = "rotary"; + + final int TEST_LIMIT = 1000; + final SafeConstrainedServer11Repository repo = new SafeConstrainedServer11Repository( + collection, getCollectionURL(collection), null, infoCollections, infoConfiguration, + TEST_LIMIT, TEST_LIMIT, sort, countFetcher); + + final AtomicBoolean shouldSkipLots = new AtomicBoolean(false); + final AtomicBoolean shouldSkipFew = new AtomicBoolean(true); + final AtomicBoolean shouldSkip503 = new AtomicBoolean (false); + + WaitHelper.getTestWaiter().performWait(2000, new Runnable() { + @Override + public void run() { + repo.createSession(new RepositorySessionCreationDelegate() { + @Override + public void onSessionCreated(RepositorySession session) { + // Try with too many items. + server.count.set(TEST_LIMIT + 1); + shouldSkipLots.set(session.shouldSkip()); + + // … and few enough that we should sync. + server.count.set(TEST_LIMIT - 1); + shouldSkipFew.set(session.shouldSkip()); + + // Now try with an error response. We advise skipping if we can't + // fetch counts, because we'll try again later. + server.error.set(true); + shouldSkip503.set(session.shouldSkip()); + + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void onSessionCreateFailed(Exception ex) { + WaitHelper.getTestWaiter().performNotify(ex); + } + + @Override + public RepositorySessionCreationDelegate deferredCreationDelegate() { + return this; + } + }, null); + } + }); + + Assert.assertTrue(shouldSkipLots.get()); + Assert.assertFalse(shouldSkipFew.get()); + Assert.assertTrue(shouldSkip503.get()); + + } finally { + data.stopHTTPServer(); + } + } + + protected String getCollectionURL(String collection) { + return TEST_BASE_PATH + "/storage/" + collection; + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/BatchMetaTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/BatchMetaTest.java new file mode 100644 index 000000000..2e136c117 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/BatchMetaTest.java @@ -0,0 +1,282 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.uploaders; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class BatchMetaTest { + private BatchMeta batchMeta; + private long byteLimit = 1024; + private long recordLimit = 5; + private Object lock = new Object(); + private Long collectionLastModified = 123L; + + @Before + public void setUp() throws Exception { + batchMeta = new BatchMeta(lock, byteLimit, recordLimit, collectionLastModified); + } + + @Test + public void testConstructor() { + assertEquals(batchMeta.collectionLastModified, collectionLastModified); + + BatchMeta otherBatchMeta = new BatchMeta(lock, byteLimit, recordLimit, null); + assertNull(otherBatchMeta.collectionLastModified); + } + + @Test + public void testGetLastModified() { + // Defaults to collection L-M + assertEquals(batchMeta.getLastModified(), Long.valueOf(123L)); + + try { + batchMeta.setLastModified(333L, true); + } catch (BatchingUploader.LastModifiedChangedUnexpectedly e) { + } catch (BatchingUploader.LastModifiedDidNotChange e) {} + + assertEquals(batchMeta.getLastModified(), Long.valueOf(333L)); + } + + @Test + public void testSetLastModified() { + assertEquals(batchMeta.getLastModified(), collectionLastModified); + + try { + batchMeta.setLastModified(123L, true); + assertEquals(batchMeta.getLastModified(), Long.valueOf(123L)); + } catch (BatchingUploader.LastModifiedChangedUnexpectedly e) { + fail("Should not check for modifications on first L-M set"); + } catch (BatchingUploader.LastModifiedDidNotChange e) { + fail("Should not check for modifications on first L-M set"); + } + + // Now the same, but passing in 'false' for "expecting to change". + batchMeta.reset(); + assertEquals(batchMeta.getLastModified(), collectionLastModified); + + try { + batchMeta.setLastModified(123L, false); + assertEquals(batchMeta.getLastModified(), Long.valueOf(123L)); + } catch (BatchingUploader.LastModifiedChangedUnexpectedly e) { + fail("Should not check for modifications on first L-M set"); + } catch (BatchingUploader.LastModifiedDidNotChange e) { + fail("Should not check for modifications on first L-M set"); + } + + // Test that we can't modify L-M when we're not expecting to + try { + batchMeta.setLastModified(333L, false); + } catch (BatchingUploader.LastModifiedChangedUnexpectedly e) { + assertTrue("Must throw when L-M changes unexpectedly", true); + } catch (BatchingUploader.LastModifiedDidNotChange e) { + fail("Not expecting did-not-change throw"); + } + assertEquals(batchMeta.getLastModified(), Long.valueOf(123L)); + + // Test that we can modify L-M when we're expecting to + try { + batchMeta.setLastModified(333L, true); + } catch (BatchingUploader.LastModifiedChangedUnexpectedly e) { + fail("Not expecting changed-unexpectedly throw"); + } catch (BatchingUploader.LastModifiedDidNotChange e) { + fail("Not expecting did-not-change throw"); + } + assertEquals(batchMeta.getLastModified(), Long.valueOf(333L)); + + // Test that we catch L-M modifications that expect to change but actually don't + try { + batchMeta.setLastModified(333L, true); + } catch (BatchingUploader.LastModifiedChangedUnexpectedly e) { + fail("Not expecting changed-unexpectedly throw"); + } catch (BatchingUploader.LastModifiedDidNotChange e) { + assertTrue("Expected-to-change-but-did-not-change didn't throw", true); + } + assertEquals(batchMeta.getLastModified(), Long.valueOf(333)); + } + + @Test + public void testSetToken() { + assertNull(batchMeta.getToken()); + + try { + batchMeta.setToken("MTIzNA", false); + } catch (BatchingUploader.TokenModifiedException e) { + fail("Should be able to set token for the first time"); + } + assertEquals("MTIzNA", batchMeta.getToken()); + + try { + batchMeta.setToken("XYCvNA", false); + } catch (BatchingUploader.TokenModifiedException e) { + assertTrue("Should not be able to modify a token", true); + } + assertEquals("MTIzNA", batchMeta.getToken()); + + try { + batchMeta.setToken("XYCvNA", true); + } catch (BatchingUploader.TokenModifiedException e) { + assertTrue("Should catch non-null tokens during onCommit sets", true); + } + assertEquals("MTIzNA", batchMeta.getToken()); + + try { + batchMeta.setToken(null, true); + } catch (BatchingUploader.TokenModifiedException e) { + fail("Should be able to set token to null during onCommit set"); + } + assertNull(batchMeta.getToken()); + } + + @Test + public void testRecordSucceeded() { + assertTrue(batchMeta.getSuccessRecordGuids().isEmpty()); + + batchMeta.recordSucceeded("guid1"); + + assertTrue(batchMeta.getSuccessRecordGuids().size() == 1); + assertTrue(batchMeta.getSuccessRecordGuids().contains("guid1")); + + try { + batchMeta.recordSucceeded(null); + fail(); + } catch (IllegalStateException e) { + assertTrue("Should not be able to 'succeed' a null guid", true); + } + } + + @Test + public void testByteLimits() { + assertTrue(batchMeta.canFit(0)); + + // Should just fit + assertTrue(batchMeta.canFit(byteLimit - BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT)); + + // Can't fit a record due to payload overhead. + assertFalse(batchMeta.canFit(byteLimit)); + + assertFalse(batchMeta.canFit(byteLimit + BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT)); + assertFalse(batchMeta.canFit(byteLimit * 1000)); + + long recordDelta = byteLimit / 2; + assertFalse(batchMeta.addAndEstimateIfFull(recordDelta)); + + // Record delta shouldn't fit due to payload overhead. + assertFalse(batchMeta.canFit(recordDelta)); + } + + @Test + public void testCountLimits() { + // Our record limit is 5, let's add 4. + assertFalse(batchMeta.addAndEstimateIfFull(1)); + assertFalse(batchMeta.addAndEstimateIfFull(1)); + assertFalse(batchMeta.addAndEstimateIfFull(1)); + assertFalse(batchMeta.addAndEstimateIfFull(1)); + + // 5th record still fits in + assertTrue(batchMeta.canFit(1)); + + // Add the 5th record + assertTrue(batchMeta.addAndEstimateIfFull(1)); + + // 6th record won't fit + assertFalse(batchMeta.canFit(1)); + } + + @Test + public void testNeedCommit() { + assertFalse(batchMeta.needToCommit()); + + assertFalse(batchMeta.addAndEstimateIfFull(1)); + + assertTrue(batchMeta.needToCommit()); + + assertFalse(batchMeta.addAndEstimateIfFull(1)); + assertFalse(batchMeta.addAndEstimateIfFull(1)); + assertFalse(batchMeta.addAndEstimateIfFull(1)); + + assertTrue(batchMeta.needToCommit()); + + batchMeta.reset(); + + assertFalse(batchMeta.needToCommit()); + } + + @Test + public void testAdd() { + // Ensure we account for payload overhead twice when the batch is empty. + // Payload overhead is either RECORDS_START or RECORDS_END, and for an empty payload + // we need both. + assertTrue(batchMeta.getByteCount() == 2 * BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT); + assertTrue(batchMeta.getRecordCount() == 0); + + assertFalse(batchMeta.addAndEstimateIfFull(1)); + + assertTrue(batchMeta.getByteCount() == (1 + BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT)); + assertTrue(batchMeta.getRecordCount() == 1); + + assertFalse(batchMeta.addAndEstimateIfFull(1)); + assertFalse(batchMeta.addAndEstimateIfFull(1)); + assertFalse(batchMeta.addAndEstimateIfFull(1)); + + assertTrue(batchMeta.getByteCount() == (4 + BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT)); + assertTrue(batchMeta.getRecordCount() == 4); + + assertTrue(batchMeta.addAndEstimateIfFull(1)); + + try { + assertTrue(batchMeta.addAndEstimateIfFull(1)); + fail("BatchMeta should not let us insert records that won't fit"); + } catch (IllegalStateException e) { + assertTrue(true); + } + } + + @Test + public void testReset() { + assertTrue(batchMeta.getByteCount() == 2 * BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT); + assertTrue(batchMeta.getRecordCount() == 0); + assertTrue(batchMeta.getSuccessRecordGuids().isEmpty()); + + // Shouldn't throw even if already empty + batchMeta.reset(); + assertTrue(batchMeta.getByteCount() == 2 * BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT); + assertTrue(batchMeta.getRecordCount() == 0); + assertTrue(batchMeta.getSuccessRecordGuids().isEmpty()); + + assertFalse(batchMeta.addAndEstimateIfFull(1)); + batchMeta.recordSucceeded("guid1"); + try { + batchMeta.setToken("MTIzNA", false); + } catch (BatchingUploader.TokenModifiedException e) {} + try { + batchMeta.setLastModified(333L, true); + } catch (BatchingUploader.LastModifiedChangedUnexpectedly e) { + } catch (BatchingUploader.LastModifiedDidNotChange e) {} + assertEquals(Long.valueOf(333L), batchMeta.getLastModified()); + assertEquals("MTIzNA", batchMeta.getToken()); + assertTrue(batchMeta.getSuccessRecordGuids().size() == 1); + + batchMeta.reset(); + + // Counts must be reset + assertTrue(batchMeta.getByteCount() == 2 * BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT); + assertTrue(batchMeta.getRecordCount() == 0); + assertTrue(batchMeta.getSuccessRecordGuids().isEmpty()); + + // Collection L-M shouldn't change + assertEquals(batchMeta.collectionLastModified, collectionLastModified); + + // Token must be reset + assertNull(batchMeta.getToken()); + + // L-M must be reverted to collection L-M + assertEquals(batchMeta.getLastModified(), collectionLastModified); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/BatchingUploaderTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/BatchingUploaderTest.java new file mode 100644 index 000000000..5ce94b222 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/BatchingUploaderTest.java @@ -0,0 +1,441 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.uploaders; + +import android.support.annotation.NonNull; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.MockRecord; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.InfoCollections; +import org.mozilla.gecko.sync.InfoConfiguration; +import org.mozilla.gecko.sync.Utils; +import org.mozilla.gecko.sync.repositories.Server11Repository; +import org.mozilla.gecko.sync.repositories.Server11RepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; + +import java.net.URISyntaxException; +import java.util.Random; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; + +@RunWith(TestRunner.class) +public class BatchingUploaderTest { + class MockExecutorService implements Executor { + public int totalPayloads = 0; + public int commitPayloads = 0; + + @Override + public void execute(@NonNull Runnable command) { + ++totalPayloads; + if (((RecordUploadRunnable) command).isCommit) { + ++commitPayloads; + } + } + } + + class MockStoreDelegate implements RepositorySessionStoreDelegate { + public int storeFailed = 0; + public int storeSucceeded = 0; + public int storeCompleted = 0; + + @Override + public void onRecordStoreFailed(Exception ex, String recordGuid) { + ++storeFailed; + } + + @Override + public void onRecordStoreSucceeded(String guid) { + ++storeSucceeded; + } + + @Override + public void onStoreCompleted(long storeEnd) { + ++storeCompleted; + } + + @Override + public RepositorySessionStoreDelegate deferredStoreDelegate(ExecutorService executor) { + return null; + } + } + + private Executor workQueue; + private RepositorySessionStoreDelegate storeDelegate; + + @Before + public void setUp() throws Exception { + workQueue = new MockExecutorService(); + storeDelegate = new MockStoreDelegate(); + } + + @Test + public void testProcessEvenPayloadBatch() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + MockRecord record = new MockRecord(Utils.generateGuid(), null, 0, false); + // 1st + uploader.process(record); + assertEquals(0, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + // 2nd -> payload full + uploader.process(record); + assertEquals(1, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + // 3rd + uploader.process(record); + assertEquals(1, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + // 4th -> batch & payload full + uploader.process(record); + assertEquals(2, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + // 5th + uploader.process(record); + assertEquals(2, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + // 6th -> payload full + uploader.process(record); + assertEquals(3, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + // 7th + uploader.process(record); + assertEquals(3, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + // 8th -> batch & payload full + uploader.process(record); + assertEquals(4, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(2, ((MockExecutorService) workQueue).commitPayloads); + // 9th + uploader.process(record); + assertEquals(4, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(2, ((MockExecutorService) workQueue).commitPayloads); + // 10th -> payload full + uploader.process(record); + assertEquals(5, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(2, ((MockExecutorService) workQueue).commitPayloads); + // 11th + uploader.process(record); + assertEquals(5, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(2, ((MockExecutorService) workQueue).commitPayloads); + // 12th -> batch & payload full + uploader.process(record); + assertEquals(6, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(3, ((MockExecutorService) workQueue).commitPayloads); + // 13th + uploader.process(record); + assertEquals(6, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(3, ((MockExecutorService) workQueue).commitPayloads); + } + + @Test + public void testProcessUnevenPayloadBatch() { + BatchingUploader uploader = makeConstrainedUploader(2, 5); + + MockRecord record = new MockRecord(Utils.generateGuid(), null, 0, false); + // 1st + uploader.process(record); + assertEquals(0, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + // 2nd -> payload full + uploader.process(record); + assertEquals(1, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + // 3rd + uploader.process(record); + assertEquals(1, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + // 4th -> payload full + uploader.process(record); + assertEquals(2, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + // 5th -> batch full + uploader.process(record); + assertEquals(3, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + // 6th -> starts new batch + uploader.process(record); + assertEquals(3, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + // 7th -> payload full + uploader.process(record); + assertEquals(4, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + // 8th + uploader.process(record); + assertEquals(4, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + // 9th -> payload full + uploader.process(record); + assertEquals(5, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + // 10th -> batch full + uploader.process(record); + assertEquals(6, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(2, ((MockExecutorService) workQueue).commitPayloads); + // 11th -> starts new batch + uploader.process(record); + assertEquals(6, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(2, ((MockExecutorService) workQueue).commitPayloads); + } + + @Test + public void testNonBatchingOptimization() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + MockRecord record = new MockRecord(Utils.generateGuid(), null, 0, false); + // 1st + uploader.process(record); + assertEquals(0, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + // 2nd + uploader.process(record); + assertEquals(1, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + // 3rd + uploader.process(record); + assertEquals(1, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + // 4th + uploader.process(record); + assertEquals(2, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + + // 5th + uploader.process(record); + assertEquals(2, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + + // And now we tell uploader that batching isn't supported. + // It shouldn't bother with batches from now on, just payloads. + uploader.setInBatchingMode(false); + + // 6th + uploader.process(record); + assertEquals(3, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + + // 7th + uploader.process(record); + assertEquals(3, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + + // 8th + uploader.process(record); + assertEquals(4, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + + // 9th + uploader.process(record); + assertEquals(4, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + + // 10th + uploader.process(record); + assertEquals(5, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + } + + @Test + public void testPreemtiveUploadByteCounts() { + // While processing a record, if we know for sure that another one won't fit, + // we upload the payload. + BatchingUploader uploader = makeConstrainedUploader(3, 6); + + // Payload byte max: 1024; batch byte max: 4096 + MockRecord record = new MockRecord(Utils.generateGuid(), null, 0, false, 400); + + uploader.process(record); + assertEquals(0, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + + // After 2nd record, byte count is at 800+overhead. Our payload max is 1024, so it's unlikely + // we can fit another record at this pace. Expect payload to be uploaded. + uploader.process(record); + assertEquals(1, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + + // After this record, we'll have less than 124 bytes of room left in the payload. Expect upload. + record = new MockRecord(Utils.generateGuid(), null, 0, false, 970); + uploader.process(record); + assertEquals(2, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + + uploader.process(record); + assertEquals(3, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + + // At this point our byte count for the batch is at 3600+overhead; + // since we have just 496 bytes left in the batch, it's unlikely we'll fit another record. + // Expect a batch commit + uploader.process(record); + assertEquals(4, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + } + + @Test + public void testRandomPayloadSizesBatching() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + final Random random = new Random(); + for (int i = 0; i < 15000; i++) { + uploader.process(new MockRecord(Utils.generateGuid(), null, 0, false, random.nextInt(15000))); + } + } + + @Test + public void testRandomPayloadSizesNonBatching() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + final Random random = new Random(); + uploader.setInBatchingMode(false); + for (int i = 0; i < 15000; i++) { + uploader.process(new MockRecord(Utils.generateGuid(), null, 0, false, random.nextInt(15000))); + } + } + + @Test + public void testRandomPayloadSizesNonBatchingDelayed() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + final Random random = new Random(); + // Delay telling uploader that batching isn't supported. + // Randomize how many records we wait for. + final int delay = random.nextInt(20); + for (int i = 0; i < 15000; i++) { + if (delay == i) { + uploader.setInBatchingMode(false); + } + uploader.process(new MockRecord(Utils.generateGuid(), null, 0, false, random.nextInt(15000))); + } + } + + @Test + public void testNoMoreRecordsAfterPayloadPost() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + // Process two records (payload limit is also two, batch is four), + // and ensure that 'no more records' commits. + MockRecord record = new MockRecord(Utils.generateGuid(), null, 0, false); + uploader.process(record); + uploader.process(record); + uploader.setInBatchingMode(true); + uploader.commitIfNecessaryAfterLastPayload(); + // One will be a payload post, the other one is batch commit (empty payload) + assertEquals(2, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + } + + @Test + public void testNoMoreRecordsAfterPayloadPostWithOneRecordLeft() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + // Process two records (payload limit is also two, batch is four), + // and ensure that 'no more records' commits. + MockRecord record = new MockRecord(Utils.generateGuid(), null, 0, false); + uploader.process(record); + uploader.process(record); + uploader.process(record); + uploader.commitIfNecessaryAfterLastPayload(); + // One will be a payload post, the other one is batch commit (one record payload) + assertEquals(2, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + } + + @Test + public void testNoMoreRecordsNoOp() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + uploader.commitIfNecessaryAfterLastPayload(); + assertEquals(0, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + } + + @Test + public void testNoMoreRecordsNoOpAfterCommit() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + MockRecord record = new MockRecord(Utils.generateGuid(), null, 0, false); + uploader.process(record); + uploader.process(record); + uploader.process(record); + uploader.process(record); + assertEquals(2, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + + uploader.commitIfNecessaryAfterLastPayload(); + assertEquals(2, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + } + + @Test + public void testNoMoreRecordsEvenNonBatching() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + // Process two records (payload limit is also two, batch is four), + // set non-batching mode, and ensure that 'no more records' doesn't commit. + MockRecord record = new MockRecord(Utils.generateGuid(), null, 0, false); + uploader.process(record); + uploader.process(record); + uploader.setInBatchingMode(false); + uploader.commitIfNecessaryAfterLastPayload(); + // One will be a payload post, the other one is batch commit (one record payload) + assertEquals(1, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(0, ((MockExecutorService) workQueue).commitPayloads); + } + + @Test + public void testNoMoreRecordsIncompletePayload() { + BatchingUploader uploader = makeConstrainedUploader(2, 4); + + // We have one record (payload limit is 2), and "no-more-records" signal should commit it. + MockRecord record = new MockRecord(Utils.generateGuid(), null, 0, false); + uploader.process(record); + + uploader.commitIfNecessaryAfterLastPayload(); + assertEquals(1, ((MockExecutorService) workQueue).totalPayloads); + assertEquals(1, ((MockExecutorService) workQueue).commitPayloads); + } + + private BatchingUploader makeConstrainedUploader(long maxPostRecords, long maxTotalRecords) { + Server11RepositorySession server11RepositorySession = new Server11RepositorySession( + makeCountConstrainedRepository(maxPostRecords, maxTotalRecords) + ); + server11RepositorySession.setStoreDelegate(storeDelegate); + return new BatchingUploader(server11RepositorySession, workQueue, storeDelegate); + } + + private Server11Repository makeCountConstrainedRepository(long maxPostRecords, long maxTotalRecords) { + return makeConstrainedRepository(1024, 1024, maxPostRecords, 4096, maxTotalRecords); + } + + private Server11Repository makeConstrainedRepository(long maxRequestBytes, long maxPostBytes, long maxPostRecords, long maxTotalBytes, long maxTotalRecords) { + ExtendedJSONObject infoConfigurationJSON = new ExtendedJSONObject(); + infoConfigurationJSON.put(InfoConfiguration.MAX_TOTAL_BYTES, maxTotalBytes); + infoConfigurationJSON.put(InfoConfiguration.MAX_TOTAL_RECORDS, maxTotalRecords); + infoConfigurationJSON.put(InfoConfiguration.MAX_POST_RECORDS, maxPostRecords); + infoConfigurationJSON.put(InfoConfiguration.MAX_POST_BYTES, maxPostBytes); + infoConfigurationJSON.put(InfoConfiguration.MAX_REQUEST_BYTES, maxRequestBytes); + + InfoConfiguration infoConfiguration = new InfoConfiguration(infoConfigurationJSON); + + try { + return new Server11Repository( + "dummyCollection", + "http://dummy.url/", + null, + new InfoCollections(), + infoConfiguration + ); + } catch (URISyntaxException e) { + // Won't throw, and this won't happen. + return null; + } + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/PayloadTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/PayloadTest.java new file mode 100644 index 000000000..b1d6dd9d0 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/PayloadTest.java @@ -0,0 +1,137 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.uploaders; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class PayloadTest { + private Payload payload; + private long byteLimit = 1024; + private long recordLimit = 5; + private Object lock = new Object(); + + @Before + public void setUp() throws Exception { + payload = new Payload(lock, byteLimit, recordLimit); + } + + @Test + public void testByteLimits() { + assertTrue(payload.canFit(0)); + + // Should just fit + assertTrue(payload.canFit(byteLimit - BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT)); + + // Can't fit a record due to payload overhead. + assertFalse(payload.canFit(byteLimit)); + + assertFalse(payload.canFit(byteLimit + BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT)); + assertFalse(payload.canFit(byteLimit * 1000)); + + long recordDelta = byteLimit / 2; + assertFalse(payload.addAndEstimateIfFull(recordDelta, new byte[0], null)); + + // Record delta shouldn't fit due to payload overhead. + assertFalse(payload.canFit(recordDelta)); + } + + @Test + public void testCountLimits() { + byte[] bytes = new byte[0]; + + // Our record limit is 5, let's add 4. + assertFalse(payload.addAndEstimateIfFull(1, bytes, null)); + assertFalse(payload.addAndEstimateIfFull(1, bytes, null)); + assertFalse(payload.addAndEstimateIfFull(1, bytes, null)); + assertFalse(payload.addAndEstimateIfFull(1, bytes, null)); + + // 5th record still fits in + assertTrue(payload.canFit(1)); + + // Add the 5th record + assertTrue(payload.addAndEstimateIfFull(1, bytes, null)); + + // 6th record won't fit + assertFalse(payload.canFit(1)); + } + + @Test + public void testAdd() { + assertTrue(payload.getByteCount() == 2 * BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT); + assertTrue(payload.getRecordCount() == 0); + assertTrue(payload.isEmpty()); + assertTrue(payload.getRecordsBuffer().isEmpty()); + assertTrue(payload.getRecordGuidsBuffer().isEmpty()); + + try { + payload.addAndEstimateIfFull(1024); + fail("Simple add is not supported"); + } catch (UnsupportedOperationException e) { + assertTrue(true); + } + + byte[] recordBytes1 = new byte[100]; + assertFalse(payload.addAndEstimateIfFull(1, recordBytes1, "guid1")); + + assertTrue(payload.getRecordsBuffer().size() == 1); + assertTrue(payload.getRecordGuidsBuffer().size() == 1); + assertTrue(payload.getRecordGuidsBuffer().contains("guid1")); + assertTrue(payload.getRecordsBuffer().contains(recordBytes1)); + + assertTrue(payload.getByteCount() == (1 + BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT)); + assertTrue(payload.getRecordCount() == 1); + + assertFalse(payload.isEmpty()); + + assertFalse(payload.addAndEstimateIfFull(1, recordBytes1, "guid2")); + assertFalse(payload.addAndEstimateIfFull(1, recordBytes1, "guid3")); + assertFalse(payload.addAndEstimateIfFull(1, recordBytes1, "guid4")); + + assertTrue(payload.getByteCount() == (4 + BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT)); + assertTrue(payload.getRecordCount() == 4); + + assertTrue(payload.addAndEstimateIfFull(1, recordBytes1, "guid5")); + + try { + assertTrue(payload.addAndEstimateIfFull(1, recordBytes1, "guid6")); + fail("Payload should not let us insert records that won't fit"); + } catch (IllegalStateException e) { + assertTrue(true); + } + } + + @Test + public void testReset() { + assertTrue(payload.getByteCount() == 2 * BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT); + assertTrue(payload.getRecordCount() == 0); + assertTrue(payload.getRecordsBuffer().isEmpty()); + assertTrue(payload.getRecordGuidsBuffer().isEmpty()); + assertTrue(payload.isEmpty()); + + // Shouldn't throw even if already empty + payload.reset(); + assertTrue(payload.getByteCount() == 2 * BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT); + assertTrue(payload.getRecordCount() == 0); + assertTrue(payload.getRecordsBuffer().isEmpty()); + assertTrue(payload.getRecordGuidsBuffer().isEmpty()); + assertTrue(payload.isEmpty()); + + byte[] recordBytes1 = new byte[100]; + assertFalse(payload.addAndEstimateIfFull(1, recordBytes1, "guid1")); + assertFalse(payload.isEmpty()); + payload.reset(); + + assertTrue(payload.getByteCount() == 2 * BatchingUploader.PER_PAYLOAD_OVERHEAD_BYTE_COUNT); + assertTrue(payload.getRecordCount() == 0); + assertTrue(payload.getRecordsBuffer().isEmpty()); + assertTrue(payload.getRecordGuidsBuffer().isEmpty()); + assertTrue(payload.isEmpty()); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/PayloadUploadDelegateTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/PayloadUploadDelegateTest.java new file mode 100644 index 000000000..fc43c2f5e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/PayloadUploadDelegateTest.java @@ -0,0 +1,404 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.uploaders; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.HTTPFailureException; +import org.mozilla.gecko.sync.InfoCollections; +import org.mozilla.gecko.sync.InfoConfiguration; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.net.SyncResponse; +import org.mozilla.gecko.sync.net.SyncStorageResponse; +import org.mozilla.gecko.sync.repositories.Server11Repository; +import org.mozilla.gecko.sync.repositories.Server11RepositorySession; +import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; + +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.Executor; + +import ch.boye.httpclientandroidlib.HttpResponse; +import ch.boye.httpclientandroidlib.ProtocolVersion; +import ch.boye.httpclientandroidlib.entity.BasicHttpEntity; +import ch.boye.httpclientandroidlib.message.BasicHttpResponse; +import ch.boye.httpclientandroidlib.message.BasicStatusLine; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class PayloadUploadDelegateTest { + private BatchingUploader batchingUploader; + + class MockUploader extends BatchingUploader { + public final ArrayList successRecords = new ArrayList<>(); + public final HashMap failedRecords = new HashMap<>(); + public boolean didLastPayloadFail = false; + + public ArrayList successResponses = new ArrayList<>(); + public int commitPayloadsSucceeded = 0; + public int lastPayloadsSucceeded = 0; + + public MockUploader(final Server11RepositorySession repositorySession, final Executor workQueue, final RepositorySessionStoreDelegate sessionStoreDelegate) { + super(repositorySession, workQueue, sessionStoreDelegate); + } + + @Override + public void payloadSucceeded(final SyncStorageResponse response, final boolean isCommit, final boolean isLastPayload) { + successResponses.add(response); + if (isCommit) { + ++commitPayloadsSucceeded; + } + if (isLastPayload) { + ++lastPayloadsSucceeded; + } + } + + @Override + public void recordSucceeded(final String recordGuid) { + successRecords.add(recordGuid); + } + + @Override + public void recordFailed(final String recordGuid) { + recordFailed(new Exception(), recordGuid); + } + + @Override + public void recordFailed(final Exception e, final String recordGuid) { + failedRecords.put(recordGuid, e); + } + + @Override + public void lastPayloadFailed() { + didLastPayloadFail = true; + } + } + + @Before + public void setUp() throws Exception { + Server11Repository server11Repository = new Server11Repository( + "dummyCollection", + "http://dummy.url/", + null, + new InfoCollections(), + new InfoConfiguration() + ); + batchingUploader = new MockUploader( + new Server11RepositorySession(server11Repository), + null, + null + ); + } + + @Test + public void testHandleRequestSuccessNonSuccess() { + ArrayList postedGuids = new ArrayList<>(2); + postedGuids.add("testGuid1"); + postedGuids.add("testGuid2"); + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, false); + + // Test that non-2* responses aren't processed + payloadUploadDelegate.handleRequestSuccess(makeSyncStorageResponse(404, null, null)); + assertEquals(2, ((MockUploader) batchingUploader).failedRecords.size()); + assertFalse(((MockUploader) batchingUploader).didLastPayloadFail); + assertEquals(IllegalStateException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid1").getClass()); + assertEquals(IllegalStateException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid2").getClass()); + } + + @Test + public void testHandleRequestSuccessNoHeaders() { + ArrayList postedGuids = new ArrayList<>(2); + postedGuids.add("testGuid1"); + postedGuids.add("testGuid2"); + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, false); + + // Test that responses without X-Last-Modified header aren't processed + payloadUploadDelegate.handleRequestSuccess(makeSyncStorageResponse(200, null, null)); + assertEquals(2, ((MockUploader) batchingUploader).failedRecords.size()); + assertFalse(((MockUploader) batchingUploader).didLastPayloadFail); + assertEquals(IllegalStateException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid1").getClass()); + assertEquals(IllegalStateException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid2").getClass()); + } + + @Test + public void testHandleRequestSuccessBadBody() { + ArrayList postedGuids = new ArrayList<>(2); + postedGuids.add("testGuid1"); + postedGuids.add("testGuid2"); + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, true); + + // Test that we catch json processing errors + payloadUploadDelegate.handleRequestSuccess(makeSyncStorageResponse(200, "non json body", "123")); + assertEquals(2, ((MockUploader) batchingUploader).failedRecords.size()); + assertTrue(((MockUploader) batchingUploader).didLastPayloadFail); + assertEquals(NonObjectJSONException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid1").getClass()); + assertEquals(NonObjectJSONException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid2").getClass()); + } + + @Test + public void testHandleRequestSuccess202NoToken() { + ArrayList postedGuids = new ArrayList<>(1); + postedGuids.add("testGuid1"); + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, true); + + // Test that we catch absent tokens in 202 responses + payloadUploadDelegate.handleRequestSuccess(makeSyncStorageResponse(202, "{\"success\": []}", "123")); + assertEquals(1, ((MockUploader) batchingUploader).failedRecords.size()); + assertEquals(IllegalStateException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid1").getClass()); + } + + @Test + public void testHandleRequestSuccessBad200() { + ArrayList postedGuids = new ArrayList<>(1); + postedGuids.add("testGuid1"); + + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, false); + + // Test that if in batching mode and saw the token, 200 must be a response to a commit + try { + batchingUploader.getCurrentBatch().setToken("MTIzNA", true); + } catch (BatchingUploader.BatchingUploaderException e) {} + batchingUploader.setInBatchingMode(true); + + // not a commit, so should fail + payloadUploadDelegate.handleRequestSuccess(makeSyncStorageResponse(200, "{\"success\": []}", "123")); + assertEquals(1, ((MockUploader) batchingUploader).failedRecords.size()); + assertEquals(IllegalStateException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid1").getClass()); + } + + @Test + public void testHandleRequestSuccessNonBatchingFailedLM() { + ArrayList postedGuids = new ArrayList<>(1); + postedGuids.add("guid1"); + postedGuids.add("guid2"); + postedGuids.add("guid3"); + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, false); + + payloadUploadDelegate.handleRequestSuccess( + makeSyncStorageResponse(200, "{\"success\": [\"guid1\", \"guid2\", \"guid3\"]}", "123")); + assertEquals(0, ((MockUploader) batchingUploader).failedRecords.size()); + assertEquals(3, ((MockUploader) batchingUploader).successRecords.size()); + assertFalse(((MockUploader) batchingUploader).didLastPayloadFail); + assertEquals(1, ((MockUploader) batchingUploader).successResponses.size()); + assertEquals(0, ((MockUploader) batchingUploader).commitPayloadsSucceeded); + assertEquals(0, ((MockUploader) batchingUploader).lastPayloadsSucceeded); + + // These should fail, because we're returning a non-changed L-M in a non-batching mode + postedGuids.add("guid4"); + postedGuids.add("guid6"); + payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, false); + payloadUploadDelegate.handleRequestSuccess( + makeSyncStorageResponse(200, "{\"success\": [\"guid4\", 5, \"guid6\"]}", "123")); + assertEquals(5, ((MockUploader) batchingUploader).failedRecords.size()); + assertEquals(3, ((MockUploader) batchingUploader).successRecords.size()); + assertFalse(((MockUploader) batchingUploader).didLastPayloadFail); + assertEquals(1, ((MockUploader) batchingUploader).successResponses.size()); + assertEquals(0, ((MockUploader) batchingUploader).commitPayloadsSucceeded); + assertEquals(0, ((MockUploader) batchingUploader).lastPayloadsSucceeded); + assertEquals(BatchingUploader.LastModifiedDidNotChange.class, + ((MockUploader) batchingUploader).failedRecords.get("guid4").getClass()); + } + + @Test + public void testHandleRequestSuccessNonBatching() { + ArrayList postedGuids = new ArrayList<>(); + postedGuids.add("guid1"); + postedGuids.add("guid2"); + postedGuids.add("guid3"); + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, false); + payloadUploadDelegate.handleRequestSuccess( + makeSyncStorageResponse(200, "{\"success\": [\"guid1\", \"guid2\", \"guid3\"], \"failed\": {}}", "123")); + + postedGuids = new ArrayList<>(); + postedGuids.add("guid4"); + postedGuids.add("guid5"); + payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, false); + payloadUploadDelegate.handleRequestSuccess( + makeSyncStorageResponse(200, "{\"success\": [\"guid4\", \"guid5\"], \"failed\": {}}", "333")); + + postedGuids = new ArrayList<>(); + postedGuids.add("guid6"); + payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, true); + payloadUploadDelegate.handleRequestSuccess( + makeSyncStorageResponse(200, "{\"success\": [\"guid6\"], \"failed\": {}}", "444")); + + assertEquals(0, ((MockUploader) batchingUploader).failedRecords.size()); + assertEquals(6, ((MockUploader) batchingUploader).successRecords.size()); + assertFalse(((MockUploader) batchingUploader).didLastPayloadFail); + assertEquals(3, ((MockUploader) batchingUploader).successResponses.size()); + assertEquals(0, ((MockUploader) batchingUploader).commitPayloadsSucceeded); + assertEquals(1, ((MockUploader) batchingUploader).lastPayloadsSucceeded); + assertFalse(batchingUploader.getInBatchingMode()); + + postedGuids = new ArrayList<>(); + postedGuids.add("guid7"); + postedGuids.add("guid8"); + payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, true); + payloadUploadDelegate.handleRequestSuccess( + makeSyncStorageResponse(200, "{\"success\": [\"guid8\"], \"failed\": {\"guid7\": \"reason\"}}", "555")); + assertEquals(1, ((MockUploader) batchingUploader).failedRecords.size()); + assertTrue(((MockUploader) batchingUploader).failedRecords.containsKey("guid7")); + assertEquals(7, ((MockUploader) batchingUploader).successRecords.size()); + assertFalse(((MockUploader) batchingUploader).didLastPayloadFail); + assertEquals(4, ((MockUploader) batchingUploader).successResponses.size()); + assertEquals(0, ((MockUploader) batchingUploader).commitPayloadsSucceeded); + assertEquals(2, ((MockUploader) batchingUploader).lastPayloadsSucceeded); + assertFalse(batchingUploader.getInBatchingMode()); + } + + @Test + public void testHandleRequestSuccessBatching() { + ArrayList postedGuids = new ArrayList<>(); + postedGuids.add("guid1"); + postedGuids.add("guid2"); + postedGuids.add("guid3"); + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, false); + payloadUploadDelegate.handleRequestSuccess( + makeSyncStorageResponse(202, "{\"batch\": \"MTIzNA\", \"success\": [\"guid1\", \"guid2\", \"guid3\"], \"failed\": {}}", "123")); + + assertTrue(batchingUploader.getInBatchingMode()); + assertEquals("MTIzNA", batchingUploader.getCurrentBatch().getToken()); + + postedGuids = new ArrayList<>(); + postedGuids.add("guid4"); + postedGuids.add("guid5"); + postedGuids.add("guid6"); + payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, false, false); + payloadUploadDelegate.handleRequestSuccess( + makeSyncStorageResponse(202, "{\"batch\": \"MTIzNA\", \"success\": [\"guid4\", \"guid5\", \"guid6\"], \"failed\": {}}", "123")); + + assertTrue(batchingUploader.getInBatchingMode()); + assertEquals("MTIzNA", batchingUploader.getCurrentBatch().getToken()); + + postedGuids = new ArrayList<>(); + postedGuids.add("guid7"); + payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, true, false); + payloadUploadDelegate.handleRequestSuccess( + makeSyncStorageResponse(200, "{\"success\": [\"guid6\"], \"failed\": {}}", "222")); + + // Even though everything indicates we're not in a batching, we were, so test that + // we don't reset the flag. + assertTrue(batchingUploader.getInBatchingMode()); + assertNull(batchingUploader.getCurrentBatch().getToken()); + + postedGuids = new ArrayList<>(); + postedGuids.add("guid8"); + payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, postedGuids, true, true); + payloadUploadDelegate.handleRequestSuccess( + makeSyncStorageResponse(200, "{\"success\": [\"guid7\"], \"failed\": {}}", "333")); + + assertEquals(0, ((MockUploader) batchingUploader).failedRecords.size()); + assertEquals(8, ((MockUploader) batchingUploader).successRecords.size()); + assertFalse(((MockUploader) batchingUploader).didLastPayloadFail); + assertEquals(4, ((MockUploader) batchingUploader).successResponses.size()); + assertEquals(2, ((MockUploader) batchingUploader).commitPayloadsSucceeded); + assertEquals(1, ((MockUploader) batchingUploader).lastPayloadsSucceeded); + assertTrue(batchingUploader.getInBatchingMode()); + } + + @Test + public void testHandleRequestError() { + ArrayList postedGuids = new ArrayList<>(3); + postedGuids.add("testGuid1"); + postedGuids.add("testGuid2"); + postedGuids.add("testGuid3"); + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate(batchingUploader, postedGuids, false, false); + + IllegalStateException e = new IllegalStateException(); + payloadUploadDelegate.handleRequestError(e); + + assertEquals(3, ((MockUploader) batchingUploader).failedRecords.size()); + assertEquals(e, ((MockUploader) batchingUploader).failedRecords.get("testGuid1")); + assertEquals(e, ((MockUploader) batchingUploader).failedRecords.get("testGuid2")); + assertEquals(e, ((MockUploader) batchingUploader).failedRecords.get("testGuid3")); + assertFalse(((MockUploader) batchingUploader).didLastPayloadFail); + + payloadUploadDelegate = new PayloadUploadDelegate(batchingUploader, postedGuids, false, true); + payloadUploadDelegate.handleRequestError(e); + assertEquals(3, ((MockUploader) batchingUploader).failedRecords.size()); + assertTrue(((MockUploader) batchingUploader).didLastPayloadFail); + } + + @Test + public void testHandleRequestFailure() { + ArrayList postedGuids = new ArrayList<>(3); + postedGuids.add("testGuid1"); + postedGuids.add("testGuid2"); + postedGuids.add("testGuid3"); + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate(batchingUploader, postedGuids, false, false); + + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 503, "Illegal method/protocol")); + payloadUploadDelegate.handleRequestFailure(new SyncStorageResponse(response)); + assertEquals(3, ((MockUploader) batchingUploader).failedRecords.size()); + assertEquals(HTTPFailureException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid1").getClass()); + assertEquals(HTTPFailureException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid2").getClass()); + assertEquals(HTTPFailureException.class, + ((MockUploader) batchingUploader).failedRecords.get("testGuid3").getClass()); + + payloadUploadDelegate = new PayloadUploadDelegate(batchingUploader, postedGuids, false, true); + payloadUploadDelegate.handleRequestFailure(new SyncStorageResponse(response)); + assertEquals(3, ((MockUploader) batchingUploader).failedRecords.size()); + assertTrue(((MockUploader) batchingUploader).didLastPayloadFail); + } + + @Test + public void testIfUnmodifiedSince() { + PayloadUploadDelegate payloadUploadDelegate = new PayloadUploadDelegate( + batchingUploader, new ArrayList(), false, false); + + assertNull(payloadUploadDelegate.ifUnmodifiedSince()); + + try { + batchingUploader.getCurrentBatch().setLastModified(1471645412480L, true); + } catch (BatchingUploader.BatchingUploaderException e) {} + + assertEquals("1471645412.480", payloadUploadDelegate.ifUnmodifiedSince()); + } + + private SyncStorageResponse makeSyncStorageResponse(int code, String body, String lastModified) { + BasicHttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), code, null)); + + if (body != null) { + BasicHttpEntity entity = new BasicHttpEntity(); + entity.setContent(new ByteArrayInputStream(body.getBytes())); + response.setEntity(entity); + } + + if (lastModified != null) { + response.addHeader(SyncResponse.X_LAST_MODIFIED, lastModified); + } + return new SyncStorageResponse(response); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/RecordUploadRunnableTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/RecordUploadRunnableTest.java new file mode 100644 index 000000000..269c25362 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/uploaders/RecordUploadRunnableTest.java @@ -0,0 +1,38 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.repositories.uploaders; + +import android.net.Uri; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import java.net.URI; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class RecordUploadRunnableTest { + @Test + public void testBuildPostURI() throws Exception { + BatchMeta batchMeta = new BatchMeta(new Object(), 1, 1, null); + URI postURI = RecordUploadRunnable.buildPostURI( + false, batchMeta, Uri.parse("http://example.com/")); + assertEquals("http://example.com/?batch=true", postURI.toString()); + + postURI = RecordUploadRunnable.buildPostURI( + true, batchMeta, Uri.parse("http://example.com/")); + assertEquals("http://example.com/?batch=true&commit=true", postURI.toString()); + + batchMeta.setToken("MTIzNA", false); + postURI = RecordUploadRunnable.buildPostURI( + false, batchMeta, Uri.parse("http://example.com/")); + assertEquals("http://example.com/?batch=MTIzNA", postURI.toString()); + + postURI = RecordUploadRunnable.buildPostURI( + true, batchMeta, Uri.parse("http://example.com/")); + assertEquals("http://example.com/?batch=MTIzNA&commit=true", postURI.toString()); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestEnsureCrypto5KeysStage.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestEnsureCrypto5KeysStage.java new file mode 100644 index 000000000..cb74b427b --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestEnsureCrypto5KeysStage.java @@ -0,0 +1,237 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.stage.test; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockGlobalSessionCallback; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.testhelpers.MockGlobalSession; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.AlreadySyncingException; +import org.mozilla.gecko.sync.CollectionKeys; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.InfoCollections; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.stage.EnsureCrypto5KeysStage; +import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestEnsureCrypto5KeysStage { + private int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private final String TEST_CLUSTER_URL = "http://localhost:" + TEST_PORT; + private final String TEST_USERNAME = "johndoe"; + private final String TEST_PASSWORD = "password"; + private final String TEST_SYNC_KEY = "abcdeabcdeabcdeabcdeabcdea"; + + private final String TEST_JSON_NO_CRYPTO = + "{\"history\":1.3319567131E9}"; + private final String TEST_JSON_OLD_CRYPTO = + "{\"history\":1.3319567131E9,\"crypto\":1.1E9}"; + private final String TEST_JSON_NEW_CRYPTO = + "{\"history\":1.3319567131E9,\"crypto\":3.1E9}"; + + private HTTPServerTestHelper data = new HTTPServerTestHelper(); + + private KeyBundle syncKeyBundle; + private MockGlobalSessionCallback callback; + private GlobalSession session; + + private boolean calledResetStages; + private Collection stagesReset; + + @Before + public void setUp() throws Exception { + syncKeyBundle = new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY); + callback = new MockGlobalSessionCallback(); + session = new MockGlobalSession(TEST_USERNAME, TEST_PASSWORD, + syncKeyBundle, callback) { + @Override + protected void prepareStages() { + super.prepareStages(); + withStage(Stage.ensureKeysStage, new EnsureCrypto5KeysStage()); + } + + @Override + public void resetStagesByEnum(Collection stages) { + calledResetStages = true; + stagesReset = new ArrayList(); + for (Stage stage : stages) { + stagesReset.add(stage.name()); + } + } + + @Override + public void resetStagesByName(Collection names) { + calledResetStages = true; + stagesReset = names; + } + }; + session.config.setClusterURL(new URI(TEST_CLUSTER_URL)); + + // Set info collections to not have crypto. + final ExtendedJSONObject noCrypto = new ExtendedJSONObject(TEST_JSON_NO_CRYPTO); + session.config.infoCollections = new InfoCollections(noCrypto); + calledResetStages = false; + stagesReset = null; + } + + public void doSession(MockServer server) { + data.startHTTPServer(server); + try { + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + try { + session.start(); + } catch (AlreadySyncingException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + }); + } finally { + data.stopHTTPServer(); + } + } + + @Test + public void testDownloadUsesPersisted() throws Exception { + session.config.infoCollections = new InfoCollections(new ExtendedJSONObject + (TEST_JSON_OLD_CRYPTO)); + session.config.persistedCryptoKeys().persistLastModified(System.currentTimeMillis()); + + assertNull(session.config.collectionKeys); + final CollectionKeys keys = CollectionKeys.generateCollectionKeys(); + keys.setDefaultKeyBundle(syncKeyBundle); + session.config.persistedCryptoKeys().persistKeys(keys); + + MockServer server = new MockServer() { + public void handle(Request request, Response response) { + this.handle(request, response, 404, "should not be called!"); + } + }; + + doSession(server); + + assertTrue(callback.calledSuccess); + assertNotNull(session.config.collectionKeys); + assertTrue(CollectionKeys.differences(session.config.collectionKeys, keys).isEmpty()); + } + + @Test + public void testDownloadFetchesNew() throws Exception { + session.config.infoCollections = new InfoCollections(new ExtendedJSONObject(TEST_JSON_NEW_CRYPTO)); + session.config.persistedCryptoKeys().persistLastModified(System.currentTimeMillis()); + + assertNull(session.config.collectionKeys); + final CollectionKeys keys = CollectionKeys.generateCollectionKeys(); + keys.setDefaultKeyBundle(syncKeyBundle); + session.config.persistedCryptoKeys().persistKeys(keys); + + MockServer server = new MockServer() { + public void handle(Request request, Response response) { + try { + CryptoRecord rec = keys.asCryptoRecord(); + rec.keyBundle = syncKeyBundle; + rec.encrypt(); + this.handle(request, response, 200, rec.toJSONString()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }; + + doSession(server); + + assertTrue(callback.calledSuccess); + assertNotNull(session.config.collectionKeys); + assertTrue(session.config.collectionKeys.equals(keys)); + } + + /** + * Change the default key but keep one collection key the same. Should reset + * all but that one collection. + */ + @Test + public void testDownloadResetsOnDifferentDefaultKey() throws Exception { + String TEST_COLLECTION = "bookmarks"; + + session.config.infoCollections = new InfoCollections(new ExtendedJSONObject(TEST_JSON_NEW_CRYPTO)); + session.config.persistedCryptoKeys().persistLastModified(System.currentTimeMillis()); + + KeyBundle keyBundle = KeyBundle.withRandomKeys(); + assertNull(session.config.collectionKeys); + final CollectionKeys keys = CollectionKeys.generateCollectionKeys(); + keys.setKeyBundleForCollection(TEST_COLLECTION, keyBundle); + session.config.persistedCryptoKeys().persistKeys(keys); + keys.setDefaultKeyBundle(syncKeyBundle); // Change the default key bundle, but keep "bookmarks" the same. + + MockServer server = new MockServer() { + public void handle(Request request, Response response) { + try { + CryptoRecord rec = keys.asCryptoRecord(); + rec.keyBundle = syncKeyBundle; + rec.encrypt(); + this.handle(request, response, 200, rec.toJSONString()); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + }; + + doSession(server); + + assertTrue(calledResetStages); + Collection allButCollection = new ArrayList(); + for (Stage stage : Stage.getNamedStages()) { + allButCollection.add(stage.getRepositoryName()); + } + allButCollection.remove(TEST_COLLECTION); + assertTrue(stagesReset.containsAll(allButCollection)); + assertTrue(allButCollection.containsAll(stagesReset)); + assertTrue(callback.calledError); + } + + @Test + public void testDownloadResetsEngineOnDifferentKey() throws Exception { + final String TEST_COLLECTION = "history"; + + session.config.infoCollections = new InfoCollections(new ExtendedJSONObject(TEST_JSON_NEW_CRYPTO)); + session.config.persistedCryptoKeys().persistLastModified(System.currentTimeMillis()); + + assertNull(session.config.collectionKeys); + final CollectionKeys keys = CollectionKeys.generateCollectionKeys(); + session.config.persistedCryptoKeys().persistKeys(keys); + keys.setKeyBundleForCollection(TEST_COLLECTION, syncKeyBundle); // Change one key bundle. + + CryptoRecord rec = keys.asCryptoRecord(); + rec.keyBundle = syncKeyBundle; + rec.encrypt(); + MockServer server = new MockServer(200, rec.toJSONString()); + + doSession(server); + + assertTrue(calledResetStages); + assertNotNull(stagesReset); + assertEquals(1, stagesReset.size()); + assertTrue(stagesReset.contains(TEST_COLLECTION)); + assertTrue(callback.calledError); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestFetchMetaGlobalStage.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestFetchMetaGlobalStage.java new file mode 100644 index 000000000..f7ed7a559 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestFetchMetaGlobalStage.java @@ -0,0 +1,391 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.stage.test; + +import org.json.simple.JSONArray; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.android.sync.net.test.TestMetaGlobal; +import org.mozilla.android.sync.test.helpers.HTTPServerTestHelper; +import org.mozilla.android.sync.test.helpers.MockGlobalSessionCallback; +import org.mozilla.android.sync.test.helpers.MockServer; +import org.mozilla.gecko.background.testhelpers.MockGlobalSession; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.AlreadySyncingException; +import org.mozilla.gecko.sync.CollectionKeys; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.GlobalSession; +import org.mozilla.gecko.sync.InfoCollections; +import org.mozilla.gecko.sync.MetaGlobal; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.SyncConfigurationException; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.crypto.KeyBundle; +import org.mozilla.gecko.sync.delegates.FreshStartDelegate; +import org.mozilla.gecko.sync.delegates.KeyUploadDelegate; +import org.mozilla.gecko.sync.delegates.WipeServerDelegate; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.stage.FetchMetaGlobalStage; +import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; +import org.simpleframework.http.Request; +import org.simpleframework.http.Response; + +import java.io.IOException; +import java.net.URI; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestFetchMetaGlobalStage { + @SuppressWarnings("unused") + private static final String LOG_TAG = "TestMetaGlobalStage"; + + private static final int TEST_PORT = HTTPServerTestHelper.getTestPort(); + private static final String TEST_SERVER = "http://localhost:" + TEST_PORT + "/"; + private static final String TEST_CLUSTER_URL = TEST_SERVER + "cluster/"; + private HTTPServerTestHelper data = new HTTPServerTestHelper(); + + private final String TEST_USERNAME = "johndoe"; + private final String TEST_PASSWORD = "password"; + private final String TEST_SYNC_KEY = "abcdeabcdeabcdeabcdeabcdea"; + + private final String TEST_INFO_COLLECTIONS_JSON = "{}"; + + private static final String TEST_SYNC_ID = "testSyncID"; + private static final long TEST_STORAGE_VERSION = GlobalSession.STORAGE_VERSION; + + private InfoCollections infoCollections; + private KeyBundle syncKeyBundle; + private MockGlobalSessionCallback callback; + private GlobalSession session; + + private boolean calledRequiresUpgrade = false; + private boolean calledProcessMissingMetaGlobal = false; + private boolean calledFreshStart = false; + private boolean calledWipeServer = false; + private boolean calledUploadKeys = false; + private boolean calledResetAllStages = false; + + private static void assertSameContents(JSONArray expected, Set actual) { + assertEquals(expected.size(), actual.size()); + for (Object o : expected) { + assertTrue(actual.contains(o)); + } + } + + @Before + public void setUp() throws Exception { + calledRequiresUpgrade = false; + calledProcessMissingMetaGlobal = false; + calledFreshStart = false; + calledWipeServer = false; + calledUploadKeys = false; + calledResetAllStages = false; + + // Set info collections to not have crypto. + infoCollections = new InfoCollections(new ExtendedJSONObject(TEST_INFO_COLLECTIONS_JSON)); + + syncKeyBundle = new KeyBundle(TEST_USERNAME, TEST_SYNC_KEY); + callback = new MockGlobalSessionCallback(); + session = new MockGlobalSession(TEST_USERNAME, TEST_PASSWORD, + syncKeyBundle, callback) { + @Override + protected void prepareStages() { + super.prepareStages(); + withStage(Stage.fetchMetaGlobal, new FetchMetaGlobalStage()); + } + + @Override + public void requiresUpgrade() { + calledRequiresUpgrade = true; + this.abort(null, "Requires upgrade"); + } + + @Override + public void processMissingMetaGlobal(MetaGlobal mg) { + calledProcessMissingMetaGlobal = true; + this.abort(null, "Missing meta/global"); + } + + // Don't really uploadKeys. + @Override + public void uploadKeys(CollectionKeys keys, KeyUploadDelegate keyUploadDelegate) { + calledUploadKeys = true; + keyUploadDelegate.onKeysUploaded(); + } + + // On fresh start completed, just stop. + @Override + public void freshStart() { + calledFreshStart = true; + freshStart(this, new FreshStartDelegate() { + @Override + public void onFreshStartFailed(Exception e) { + WaitHelper.getTestWaiter().performNotify(e); + } + + @Override + public void onFreshStart() { + WaitHelper.getTestWaiter().performNotify(); + } + }); + } + + // Don't really wipeServer. + @Override + protected void wipeServer(final AuthHeaderProvider authHeaderProvider, final WipeServerDelegate wipeDelegate) { + calledWipeServer = true; + wipeDelegate.onWiped(System.currentTimeMillis()); + } + + // Don't really resetAllStages. + @Override + public void resetAllStages() { + calledResetAllStages = true; + } + }; + session.config.setClusterURL(new URI(TEST_CLUSTER_URL)); + session.config.infoCollections = infoCollections; + } + + protected void doSession(MockServer server) { + data.startHTTPServer(server); + WaitHelper.getTestWaiter().performWait(WaitHelper.onThreadRunnable(new Runnable() { + @Override + public void run() { + try { + session.start(); + } catch (AlreadySyncingException e) { + WaitHelper.getTestWaiter().performNotify(e); + } + } + })); + data.stopHTTPServer(); + } + + @Test + public void testFetchRequiresUpgrade() throws Exception { + MetaGlobal mg = new MetaGlobal(null, null); + mg.setSyncID(TEST_SYNC_ID); + mg.setStorageVersion(Long.valueOf(TEST_STORAGE_VERSION + 1)); + + MockServer server = new MockServer(200, mg.asCryptoRecord().toJSONString()); + doSession(server); + + assertEquals(true, callback.calledError); + assertTrue(calledRequiresUpgrade); + } + + @SuppressWarnings("unchecked") + private JSONArray makeTestDeclinedArray() { + final JSONArray declined = new JSONArray(); + declined.add("foobar"); + return declined; + } + + /** + * Verify that a fetched meta/global with remote syncID == local syncID does + * not reset. + * + * @throws Exception + */ + @Test + public void testFetchSuccessWithSameSyncID() throws Exception { + session.config.syncID = TEST_SYNC_ID; + + MetaGlobal mg = new MetaGlobal(null, null); + mg.setSyncID(TEST_SYNC_ID); + mg.setStorageVersion(Long.valueOf(TEST_STORAGE_VERSION)); + + // Set declined engines in the server object. + final JSONArray testingDeclinedEngines = makeTestDeclinedArray(); + mg.setDeclinedEngineNames(testingDeclinedEngines); + + MockServer server = new MockServer(200, mg.asCryptoRecord().toJSONString()); + doSession(server); + + assertTrue(callback.calledSuccess); + assertFalse(calledProcessMissingMetaGlobal); + assertFalse(calledResetAllStages); + assertEquals(TEST_SYNC_ID, session.config.metaGlobal.getSyncID()); + assertEquals(TEST_STORAGE_VERSION, session.config.metaGlobal.getStorageVersion().longValue()); + assertEquals(TEST_SYNC_ID, session.config.syncID); + + // Declined engines propagate from the server meta/global. + final Set actual = session.config.metaGlobal.getDeclinedEngineNames(); + assertSameContents(testingDeclinedEngines, actual); + } + + /** + * Verify that a fetched meta/global with remote syncID != local syncID resets + * local and retains remote syncID. + * + * @throws Exception + */ + @Test + public void testFetchSuccessWithDifferentSyncID() throws Exception { + session.config.syncID = "NOT TEST SYNC ID"; + + MetaGlobal mg = new MetaGlobal(null, null); + mg.setSyncID(TEST_SYNC_ID); + mg.setStorageVersion(Long.valueOf(TEST_STORAGE_VERSION)); + + // Set declined engines in the server object. + final JSONArray testingDeclinedEngines = makeTestDeclinedArray(); + mg.setDeclinedEngineNames(testingDeclinedEngines); + + MockServer server = new MockServer(200, mg.asCryptoRecord().toJSONString()); + doSession(server); + + assertEquals(true, callback.calledSuccess); + assertFalse(calledProcessMissingMetaGlobal); + assertTrue(calledResetAllStages); + assertEquals(TEST_SYNC_ID, session.config.metaGlobal.getSyncID()); + assertEquals(TEST_STORAGE_VERSION, session.config.metaGlobal.getStorageVersion().longValue()); + assertEquals(TEST_SYNC_ID, session.config.syncID); + + // Declined engines propagate from the server meta/global. + final Set actual = session.config.metaGlobal.getDeclinedEngineNames(); + assertSameContents(testingDeclinedEngines, actual); + } + + /** + * Verify that a fetched meta/global does not merge declined engines. + * TODO: eventually it should! + */ + @SuppressWarnings("unchecked") + @Test + public void testFetchSuccessWithDifferentSyncIDMergesDeclined() throws Exception { + session.config.syncID = "NOT TEST SYNC ID"; + + // Fake the local declined engine names. + session.config.declinedEngineNames = new HashSet(); + session.config.declinedEngineNames.add("baznoo"); + + MetaGlobal mg = new MetaGlobal(null, null); + mg.setSyncID(TEST_SYNC_ID); + mg.setStorageVersion(Long.valueOf(TEST_STORAGE_VERSION)); + + // Set declined engines in the server object. + final JSONArray testingDeclinedEngines = makeTestDeclinedArray(); + mg.setDeclinedEngineNames(testingDeclinedEngines); + + MockServer server = new MockServer(200, mg.asCryptoRecord().toJSONString()); + doSession(server); + + // Declined engines propagate from the server meta/global, and are NOT merged. + final Set expected = new HashSet(testingDeclinedEngines); + // expected.add("baznoo"); // Not until we merge. Local is lost. + + final Set newDeclined = session.config.metaGlobal.getDeclinedEngineNames(); + assertEquals(expected, newDeclined); + } + + @Test + public void testFetchMissing() throws Exception { + MockServer server = new MockServer(404, "missing"); + doSession(server); + + assertEquals(true, callback.calledError); + assertTrue(calledProcessMissingMetaGlobal); + } + + /** + * Empty payload object has no syncID or storageVersion and should call freshStart. + * @throws Exception + */ + @Test + public void testFetchEmptyPayload() throws Exception { + MockServer server = new MockServer(200, TestMetaGlobal.TEST_META_GLOBAL_EMPTY_PAYLOAD_RESPONSE); + doSession(server); + + assertTrue(calledFreshStart); + } + + /** + * No payload means no syncID or storageVersion and therefore we should call freshStart. + * @throws Exception + */ + @Test + public void testFetchNoPayload() throws Exception { + MockServer server = new MockServer(200, TestMetaGlobal.TEST_META_GLOBAL_NO_PAYLOAD_RESPONSE); + doSession(server); + + assertTrue(calledFreshStart); + } + + /** + * Malformed payload is a server response issue, not a meta/global record + * issue. This should error out of the sync. + * @throws Exception + */ + @Test + public void testFetchMalformedPayload() throws Exception { + MockServer server = new MockServer(200, TestMetaGlobal.TEST_META_GLOBAL_MALFORMED_PAYLOAD_RESPONSE); + doSession(server); + + assertEquals(true, callback.calledError); + assertEquals(NonObjectJSONException.class, callback.calledErrorException.getClass()); + } + + protected void doFreshStart(MockServer server) { + data.startHTTPServer(server); + WaitHelper.getTestWaiter().performWait(WaitHelper.onThreadRunnable(new Runnable() { + @Override + public void run() { + session.freshStart(); + } + })); + data.stopHTTPServer(); + } + + @Test + public void testFreshStart() throws SyncConfigurationException, IllegalArgumentException, NonObjectJSONException, IOException, CryptoException { + final AtomicBoolean mgUploaded = new AtomicBoolean(false); + final AtomicBoolean mgDownloaded = new AtomicBoolean(false); + final MetaGlobal uploadedMg = new MetaGlobal(null, null); + + MockServer server = new MockServer() { + @Override + public void handle(Request request, Response response) { + if (request.getMethod().equals("PUT")) { + try { + ExtendedJSONObject body = new ExtendedJSONObject(request.getContent()); + assertTrue(body.containsKey("payload")); + assertFalse(body.containsKey("default")); + + CryptoRecord rec = CryptoRecord.fromJSONRecord(body); + uploadedMg.setFromRecord(rec); + mgUploaded.set(true); + } catch (Exception e) { + throw new RuntimeException(e); + } + this.handle(request, response, 200, "success"); + return; + } + if (mgUploaded.get()) { + // We shouldn't be trying to download anything after uploading meta/global. + mgDownloaded.set(true); + } + this.handle(request, response, 404, "missing"); + } + }; + doFreshStart(server); + + assertTrue(this.calledFreshStart); + assertTrue(this.calledWipeServer); + assertTrue(this.calledUploadKeys); + assertTrue(mgUploaded.get()); + assertFalse(mgDownloaded.get()); + assertEquals(GlobalSession.STORAGE_VERSION, uploadedMg.getStorageVersion().longValue()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestStageLookup.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestStageLookup.java new file mode 100644 index 000000000..86829844f --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/stage/test/TestStageLookup.java @@ -0,0 +1,41 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.stage.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.stage.GlobalSyncStage.Stage; + +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertEquals; + +@RunWith(TestRunner.class) +public class TestStageLookup { + + @Test + public void testStageLookupByName() { + Set namedStages = new HashSet(Stage.getNamedStages()); + Set expected = new HashSet(); + expected.add(Stage.syncClientsEngine); + expected.add(Stage.syncBookmarks); + expected.add(Stage.syncTabs); + expected.add(Stage.syncFormHistory); + expected.add(Stage.syncHistory); + expected.add(Stage.syncPasswords); + + assertEquals(expected, namedStages); + assertEquals(Stage.syncClientsEngine, Stage.byName("clients")); + assertEquals(Stage.syncTabs, Stage.byName("tabs")); + assertEquals(Stage.syncBookmarks, Stage.byName("bookmarks")); + assertEquals(Stage.syncFormHistory, Stage.byName("forms")); + assertEquals(Stage.syncHistory, Stage.byName("history")); + assertEquals(Stage.syncPasswords, Stage.byName("passwords")); + + assertEquals(null, Stage.byName("foobar")); + assertEquals(null, Stage.byName(null)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestExtendedJSONObject.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestExtendedJSONObject.java new file mode 100644 index 000000000..cff9287df --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestExtendedJSONObject.java @@ -0,0 +1,203 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.test; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.NonArrayJSONException; +import org.mozilla.gecko.sync.NonObjectJSONException; +import org.mozilla.gecko.sync.UnexpectedJSONException.BadRequiredFieldJSONException; + +import java.io.IOException; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestExtendedJSONObject { + public static String exampleJSON = "{\"modified\":1233702554.25,\"success\":[\"{GXS58IDC}12\",\"{GXS58IDC}13\",\"{GXS58IDC}15\",\"{GXS58IDC}16\",\"{GXS58IDC}18\",\"{GXS58IDC}19\"],\"failed\":{\"{GXS58IDC}11\":[\"invalid parentid\"],\"{GXS58IDC}14\":[\"invalid parentid\"],\"{GXS58IDC}17\":[\"invalid parentid\"],\"{GXS58IDC}20\":[\"invalid parentid\"]}}"; + public static String exampleIntegral = "{\"modified\":1233702554,}"; + + @Test + public void testFractional() throws IOException, NonObjectJSONException { + ExtendedJSONObject o = new ExtendedJSONObject(exampleJSON); + assertTrue(o.containsKey("modified")); + assertTrue(o.containsKey("success")); + assertTrue(o.containsKey("failed")); + assertFalse(o.containsKey(" ")); + assertFalse(o.containsKey("")); + assertFalse(o.containsKey("foo")); + assertTrue(o.get("modified") instanceof Number); + assertTrue(o.get("modified").equals(Double.parseDouble("1233702554.25"))); + assertEquals(Long.valueOf(1233702554250L), o.getTimestamp("modified")); + assertEquals(null, o.getTimestamp("foo")); + } + + @Test + public void testIntegral() throws IOException, NonObjectJSONException { + ExtendedJSONObject o = new ExtendedJSONObject(exampleIntegral); + assertTrue(o.containsKey("modified")); + assertFalse(o.containsKey("success")); + assertTrue(o.get("modified") instanceof Number); + assertTrue(o.get("modified").equals(Long.parseLong("1233702554"))); + assertEquals(Long.valueOf(1233702554000L), o.getTimestamp("modified")); + assertEquals(null, o.getTimestamp("foo")); + } + + @Test + public void testSafeInteger() { + ExtendedJSONObject o = new ExtendedJSONObject(); + o.put("integer", Integer.valueOf(5)); + o.put("string", "66"); + o.put("object", new ExtendedJSONObject()); + o.put("null", (JSONArray) null); + + assertEquals(Integer.valueOf(5), o.getIntegerSafely("integer")); + assertEquals(Integer.valueOf(66), o.getIntegerSafely("string")); + assertNull(o.getIntegerSafely(null)); + } + + @Test + public void testParseJSONArray() throws Exception { + JSONArray result = ExtendedJSONObject.parseJSONArray("[0, 1, {\"test\": 2}]"); + assertNotNull(result); + + assertThat((Long) result.get(0), is(equalTo(0L))); + assertThat((Long) result.get(1), is(equalTo(1L))); + assertThat((Long) ((JSONObject) result.get(2)).get("test"), is(equalTo(2L))); + } + + @Test + public void testBadParseJSONArray() throws Exception { + try { + ExtendedJSONObject.parseJSONArray("[0, "); + fail(); + } catch (NonArrayJSONException e) { + // Do nothing. + } + + try { + ExtendedJSONObject.parseJSONArray("{}"); + fail(); + } catch (NonArrayJSONException e) { + // Do nothing. + } + } + + @Test + public void testParseUTF8AsJSONObject() throws Exception { + String TEST = "{\"key\":\"value\"}"; + + ExtendedJSONObject o = ExtendedJSONObject.parseUTF8AsJSONObject(TEST.getBytes("UTF-8")); + assertNotNull(o); + assertEquals("value", o.getString("key")); + } + + @Test + public void testBadParseUTF8AsJSONObject() throws Exception { + try { + ExtendedJSONObject.parseUTF8AsJSONObject("{}".getBytes("UTF-16")); + fail(); + } catch (NonObjectJSONException e) { + // Do nothing. + } + + try { + ExtendedJSONObject.parseUTF8AsJSONObject("{".getBytes("UTF-8")); + fail(); + } catch (NonObjectJSONException e) { + // Do nothing. + } + } + + @Test + public void testHashCode() throws Exception { + ExtendedJSONObject o = new ExtendedJSONObject(exampleJSON); + assertEquals(o.hashCode(), o.hashCode()); + ExtendedJSONObject p = new ExtendedJSONObject(exampleJSON); + assertEquals(o.hashCode(), p.hashCode()); + + ExtendedJSONObject q = new ExtendedJSONObject(exampleJSON); + q.put("modified", 0); + assertNotSame(o.hashCode(), q.hashCode()); + } + + @Test + public void testEquals() throws Exception { + ExtendedJSONObject o = new ExtendedJSONObject(exampleJSON); + ExtendedJSONObject p = new ExtendedJSONObject(exampleJSON); + assertEquals(o, p); + + ExtendedJSONObject q = new ExtendedJSONObject(exampleJSON); + q.put("modified", 0); + assertNotSame(o, q); + assertNotEquals(o, q); + } + + @Test + public void testGetBoolean() throws Exception { + ExtendedJSONObject o = new ExtendedJSONObject("{\"truekey\":true, \"falsekey\":false, \"stringkey\":\"string\"}"); + assertEquals(true, o.getBoolean("truekey")); + assertEquals(false, o.getBoolean("falsekey")); + try { + o.getBoolean("stringkey"); + fail(); + } catch (Exception e) { + assertTrue(e instanceof ClassCastException); + } + assertEquals(null, o.getBoolean("missingkey")); + } + + @Test + public void testNullLong() throws Exception { + ExtendedJSONObject o = new ExtendedJSONObject("{\"x\": null}"); + Long x = o.getLong("x"); + assertNull(x); + + long y = o.getLong("x", 5L); + assertEquals(5L, y); + } + + protected void assertException(ExtendedJSONObject o, String[] requiredFields, Class requiredFieldClass) { + try { + o.throwIfFieldsMissingOrMisTyped(requiredFields, requiredFieldClass); + fail(); + } catch (Exception e) { + assertTrue(e instanceof BadRequiredFieldJSONException); + } + } + + @Test + public void testThrow() throws Exception { + ExtendedJSONObject o = new ExtendedJSONObject("{\"true\":true, \"false\":false, \"string\":\"string\", \"long\":40000000000, \"int\":40, \"nested\":{\"inner\":10}}"); + o.throwIfFieldsMissingOrMisTyped(new String[] { "true", "false" }, Boolean.class); + o.throwIfFieldsMissingOrMisTyped(new String[] { "string" }, String.class); + o.throwIfFieldsMissingOrMisTyped(new String[] { "long" }, Long.class); + o.throwIfFieldsMissingOrMisTyped(new String[] { "int" }, Long.class); + o.throwIfFieldsMissingOrMisTyped(new String[] { "int" }, null); + + // Perhaps a bit unexpected, but we'll document it here. + o.throwIfFieldsMissingOrMisTyped(new String[] { "nested" }, JSONObject.class); + + // Should fail. + assertException(o, new String[] { "int" }, Integer.class); // Irritating, but... + assertException(o, new String[] { "long" }, Integer.class); // Ditto. + assertException(o, new String[] { "missing" }, String.class); + assertException(o, new String[] { "missing" }, null); + assertException(o, new String[] { "string", "int" }, String.class); // Irritating, but... + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestInfoCollections.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestInfoCollections.java new file mode 100644 index 000000000..d850ccc56 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestInfoCollections.java @@ -0,0 +1,101 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.test; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.InfoCollections; +import org.mozilla.gecko.sync.InfoCounts; +import org.mozilla.gecko.sync.Utils; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + * Test both info/collections and info/collection_counts. + */ +@RunWith(TestRunner.class) +public class TestInfoCollections { + public static final String TEST_COLLECTIONS_JSON = + "{\"history\":1.3319567131E9, " + + " \"bookmarks\":1.33195669592E9, " + + " \"prefs\":1.33115408641E9, " + + " \"crypto\":1.32046063664E9, " + + " \"meta\":1.321E9, " + + " \"forms\":1.33136685374E9, " + + " \"clients\":1.3313667619E9, " + + " \"tabs\":1.35E9" + + "}"; + + + public static final String TEST_COUNTS_JSON = + "{\"passwords\": 390, " + + " \"clients\": 2, " + + " \"crypto\": 1, " + + " \"forms\": 1019, " + + " \"bookmarks\": 766, " + + " \"prefs\": 1, " + + " \"history\": 9278" + + "}"; + + @SuppressWarnings("static-method") + @Test + public void testSetCountsFromRecord() throws Exception { + InfoCounts infoCountsEmpty = new InfoCounts(new ExtendedJSONObject("{}")); + assertEquals(null, infoCountsEmpty.getCount("bookmarks")); + + ExtendedJSONObject record = new ExtendedJSONObject(TEST_COUNTS_JSON); + InfoCounts infoCountsFull = new InfoCounts(record); + assertEquals(Integer.valueOf(766), infoCountsFull.getCount("bookmarks")); + assertEquals(null, infoCountsFull.getCount("notpresent")); + } + + + @SuppressWarnings("static-method") + @Test + public void testSetCollectionsFromRecord() throws Exception { + ExtendedJSONObject record = new ExtendedJSONObject(TEST_COLLECTIONS_JSON); + InfoCollections infoCollections = new InfoCollections(record); + + assertEquals(Utils.decimalSecondsToMilliseconds(1.3319567131E9), infoCollections.getTimestamp("history").longValue()); + assertEquals(Utils.decimalSecondsToMilliseconds(1.321E9), infoCollections.getTimestamp("meta").longValue()); + assertEquals(Utils.decimalSecondsToMilliseconds(1.35E9), infoCollections.getTimestamp("tabs").longValue()); + assertNull(infoCollections.getTimestamp("missing")); + } + + @SuppressWarnings("static-method") + @Test + public void testUpdateNeeded() throws Exception { + ExtendedJSONObject record = new ExtendedJSONObject(TEST_COLLECTIONS_JSON); + InfoCollections infoCollections = new InfoCollections(record); + + long none = -1; + long past = Utils.decimalSecondsToMilliseconds(1.3E9); + long same = Utils.decimalSecondsToMilliseconds(1.35E9); + long future = Utils.decimalSecondsToMilliseconds(1.4E9); + + + // Test with no local timestamp set. + assertTrue(infoCollections.updateNeeded("tabs", none)); + + // Test with local timestamp set in the past. + assertTrue(infoCollections.updateNeeded("tabs", past)); + + // Test with same timestamp. + assertFalse(infoCollections.updateNeeded("tabs", same)); + + // Test with local timestamp set in the future. + assertFalse(infoCollections.updateNeeded("tabs", future)); + + // Test with no collection. + assertTrue(infoCollections.updateNeeded("missing", none)); + assertTrue(infoCollections.updateNeeded("missing", past)); + assertTrue(infoCollections.updateNeeded("missing", same)); + assertTrue(infoCollections.updateNeeded("missing", future)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestPersistedMetaGlobal.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestPersistedMetaGlobal.java new file mode 100644 index 000000000..d1b6cadef --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/test/TestPersistedMetaGlobal.java @@ -0,0 +1,105 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.sync.test; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.MockSharedPreferences; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.CryptoRecord; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.MetaGlobal; +import org.mozilla.gecko.sync.NoCollectionKeysSetException; +import org.mozilla.gecko.sync.PersistedMetaGlobal; +import org.mozilla.gecko.sync.crypto.CryptoException; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BasicAuthHeaderProvider; + +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestPersistedMetaGlobal { + MockSharedPreferences prefs = null; + private final String TEST_META_URL = "metaURL"; + private final String TEST_CREDENTIALS = "credentials"; + + @Before + public void setUp() { + prefs = new MockSharedPreferences(); + } + + @Test + public void testPersistLastModified() throws CryptoException, NoCollectionKeysSetException { + long LAST_MODIFIED = System.currentTimeMillis(); + PersistedMetaGlobal persisted = new PersistedMetaGlobal(prefs); + + // Test fresh start. + assertEquals(-1, persisted.lastModified()); + + // Test persisting. + persisted.persistLastModified(LAST_MODIFIED); + assertEquals(LAST_MODIFIED, persisted.lastModified()); + + // Test clearing. + persisted.persistLastModified(0); + assertEquals(-1, persisted.lastModified()); + } + + @Test + public void testPersistMetaGlobal() throws Exception { + PersistedMetaGlobal persisted = new PersistedMetaGlobal(prefs); + AuthHeaderProvider authHeaderProvider = new BasicAuthHeaderProvider(TEST_CREDENTIALS); + + // Test fresh start. + assertNull(persisted.metaGlobal(TEST_META_URL, authHeaderProvider)); + + // Test persisting. + String body = "{\"id\":\"global\",\"payload\":\"{\\\"syncID\\\":\\\"zPSQTm7WBVWB\\\",\\\"storageVersion\\\":5,\\\"engines\\\":{\\\"clients\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"fDg0MS5bDtV7\\\"},\\\"bookmarks\\\":{\\\"version\\\":2,\\\"syncID\\\":\\\"NNaQr6_F-9dm\\\"},\\\"forms\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"GXF29AFprnvc\\\"},\\\"history\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"av75g4vm-_rp\\\"},\\\"passwords\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"LT_ACGpuKZ6a\\\"},\\\"prefs\\\":{\\\"version\\\":2,\\\"syncID\\\":\\\"-3nsksP9wSAs\\\"},\\\"tabs\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"W4H5lOMChkYA\\\"}}}\",\"username\":\"5817483\",\"modified\":1.32046073744E9}"; + MetaGlobal mg = new MetaGlobal(TEST_META_URL, authHeaderProvider); + mg.setFromRecord(CryptoRecord.fromJSONRecord(body)); + persisted.persistMetaGlobal(mg); + + MetaGlobal persistedGlobal = persisted.metaGlobal(TEST_META_URL, authHeaderProvider); + assertNotNull(persistedGlobal); + assertEquals("zPSQTm7WBVWB", persistedGlobal.getSyncID()); + assertTrue(persistedGlobal.getEngines() instanceof ExtendedJSONObject); + assertEquals(Long.valueOf(5), persistedGlobal.getStorageVersion()); + + // Test clearing. + persisted.persistMetaGlobal(null); + assertNull(persisted.metaGlobal(null, null)); + } + + @Test + public void testPersistDeclinedEngines() throws Exception { + PersistedMetaGlobal persisted = new PersistedMetaGlobal(prefs); + AuthHeaderProvider authHeaderProvider = new BasicAuthHeaderProvider(TEST_CREDENTIALS); + + // Test fresh start. + assertNull(persisted.metaGlobal(TEST_META_URL, authHeaderProvider)); + + // Test persisting. + String body = "{\"id\":\"global\",\"payload\":\"{\\\"declined\\\":[\\\"bookmarks\\\",\\\"addons\\\"],\\\"syncID\\\":\\\"zPSQTm7WBVWB\\\",\\\"storageVersion\\\":5,\\\"engines\\\":{\\\"clients\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"fDg0MS5bDtV7\\\"},,\\\"forms\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"GXF29AFprnvc\\\"},\\\"history\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"av75g4vm-_rp\\\"},\\\"passwords\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"LT_ACGpuKZ6a\\\"},\\\"prefs\\\":{\\\"version\\\":2,\\\"syncID\\\":\\\"-3nsksP9wSAs\\\"},\\\"tabs\\\":{\\\"version\\\":1,\\\"syncID\\\":\\\"W4H5lOMChkYA\\\"}}}\",\"username\":\"5817483\",\"modified\":1.32046073744E9}"; + MetaGlobal mg = new MetaGlobal(TEST_META_URL, authHeaderProvider); + mg.setFromRecord(CryptoRecord.fromJSONRecord(body)); + persisted.persistMetaGlobal(mg); + + MetaGlobal persistedGlobal = persisted.metaGlobal(TEST_META_URL, authHeaderProvider); + assertNotNull(persistedGlobal); + Set declined = persistedGlobal.getDeclinedEngineNames(); + assertEquals(2, declined.size()); + assertTrue(declined.contains("bookmarks")); + assertTrue(declined.contains("addons")); + + // Test clearing. + persisted.persistMetaGlobal(null); + assertNull(persisted.metaGlobal(null, null)); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/measurements/TestSearchCountMeasurements.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/measurements/TestSearchCountMeasurements.java new file mode 100644 index 000000000..058461f8e --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/measurements/TestSearchCountMeasurements.java @@ -0,0 +1,161 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.telemetry.measurements; + +import android.content.Context; +import android.content.SharedPreferences; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.robolectric.RuntimeEnvironment; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.*; + +/** + * Tests for the class that stores search count measurements. + */ +@RunWith(TestRunner.class) +public class TestSearchCountMeasurements { + + private SharedPreferences sharedPrefs; + + @Before + public void setUp() throws Exception { + sharedPrefs = RuntimeEnvironment.application.getSharedPreferences( + TestSearchCountMeasurements.class.getSimpleName(), Context.MODE_PRIVATE); + } + + private void assertNewValueInsertedNoIncrementedValues(final int expectedKeyCount) { + assertEquals("Shared prefs key count has incremented", expectedKeyCount, sharedPrefs.getAll().size()); + assertTrue("Shared prefs still contains non-incremented initial value", sharedPrefs.getAll().containsValue(1)); + assertFalse("Shared prefs has not incremented any values", sharedPrefs.getAll().containsValue(2)); + } + + @Test + public void testIncrementSearchCanRecreateEngineAndWhere() throws Exception { + final String expectedIdentifier = "google"; + final String expectedWhere = "suggestbar"; + + SearchCountMeasurements.incrementSearch(sharedPrefs, expectedIdentifier, expectedWhere); + assertFalse("Shared prefs has some values", sharedPrefs.getAll().isEmpty()); + assertTrue("Shared prefs contains initial value", sharedPrefs.getAll().containsValue(1)); + + boolean foundEngine = false; + for (final String key : sharedPrefs.getAll().keySet()) { + // We could try to match the exact key, but that's more fragile. + if (key.contains(expectedIdentifier) && key.contains(expectedWhere)) { + foundEngine = true; + } + } + assertTrue("SharedPrefs keyset contains enough info to recreate engine & where", foundEngine); + } + + @Test + public void testIncrementSearchCalledMultipleTimesSameEngine() throws Exception { + final String engineIdentifier = "whatever"; + final String where = "wherever"; + + SearchCountMeasurements.incrementSearch(sharedPrefs, engineIdentifier, where); + assertFalse("Shared prefs has some values", sharedPrefs.getAll().isEmpty()); + assertTrue("Shared prefs contains initial value", sharedPrefs.getAll().containsValue(1)); + + // The initial key count storage saves metadata so we can't verify the number of keys is only 1. However, + // we assume subsequent calls won't add additional metadata and use it to verify the key count. + final int keyCountAfterFirst = sharedPrefs.getAll().size(); + for (int i = 2; i <= 3; ++i) { + SearchCountMeasurements.incrementSearch(sharedPrefs, engineIdentifier, where); + assertEquals("Shared prefs key count has not changed", keyCountAfterFirst, sharedPrefs.getAll().size()); + assertTrue("Shared prefs incremented", sharedPrefs.getAll().containsValue(i)); + } + } + + @Test + public void testIncrementSearchCalledMultipleTimesSameEngineDifferentWhere() throws Exception { + final String engineIdenfitier = "whatever"; + + SearchCountMeasurements.incrementSearch(sharedPrefs, engineIdenfitier, "one place"); + assertFalse("Shared prefs has some values", sharedPrefs.getAll().isEmpty()); + assertTrue("Shared prefs contains initial value", sharedPrefs.getAll().containsValue(1)); + + // The initial key count storage saves metadata so we can't verify the number of keys is only 1. However, + // we assume subsequent calls won't add additional metadata and use it to verify the key count. + final int keyCountAfterFirst = sharedPrefs.getAll().size(); + for (int i = 1; i <= 2; ++i) { + SearchCountMeasurements.incrementSearch(sharedPrefs, engineIdenfitier, "another place " + i); + assertNewValueInsertedNoIncrementedValues(keyCountAfterFirst + i); + } + } + + @Test + public void testIncrementSearchCalledMultipleTimesDifferentEngines() throws Exception { + final String where = "wherever"; + + SearchCountMeasurements.incrementSearch(sharedPrefs, "steam engine", where); + assertFalse("Shared prefs has some values", sharedPrefs.getAll().isEmpty()); + assertTrue("Shared prefs contains initial value", sharedPrefs.getAll().containsValue(1)); + + // The initial key count storage saves metadata so we can't verify the number of keys is only 1. However, + // we assume subsequent calls won't add additional metadata and use it to verify the key count. + final int keyCountAfterFirst = sharedPrefs.getAll().size(); + for (int i = 1; i <= 2; ++i) { + SearchCountMeasurements.incrementSearch(sharedPrefs, "combustion engine" + i, where); + assertNewValueInsertedNoIncrementedValues(keyCountAfterFirst + i); + } + } + + @Test // assumes the format saved in SharedPrefs to store test data + public void testGetAndZeroSearchDeletesPrefs() throws Exception { + assertTrue("Shared prefs is empty", sharedPrefs.getAll().isEmpty()); + + final SharedPreferences.Editor editor = sharedPrefs.edit(); + final Set engineKeys = new HashSet<>(Arrays.asList("whatever.yeah", "lol.what")); + editor.putStringSet(SearchCountMeasurements.PREF_SEARCH_KEYSET, engineKeys); + for (final String key : engineKeys) { + editor.putInt(getEngineSearchCountKey(key), 1); + } + editor.apply(); + assertFalse("Shared prefs is not empty after test data inserted", sharedPrefs.getAll().isEmpty()); + + SearchCountMeasurements.getAndZeroSearch(sharedPrefs); + assertTrue("Shared prefs is empty after zero", sharedPrefs.getAll().isEmpty()); + } + + @Test // assumes the format saved in SharedPrefs to store test data + public void testGetAndZeroSearchVerifyReturnedData() throws Exception { + final HashMap expected = new HashMap<>(); + expected.put("steamengine.here", 1337); + expected.put("combustionengine.there", 10); + + final SharedPreferences.Editor editor = sharedPrefs.edit(); + editor.putStringSet(SearchCountMeasurements.PREF_SEARCH_KEYSET, expected.keySet()); + for (final String key : expected.keySet()) { + editor.putInt(SearchCountMeasurements.getEngineSearchCountKey(key), expected.get(key)); + } + editor.apply(); + assertFalse("Shared prefs is not empty after test data inserted", sharedPrefs.getAll().isEmpty()); + + final ExtendedJSONObject actual = SearchCountMeasurements.getAndZeroSearch(sharedPrefs); + assertEquals("Returned JSON contains number of items inserted", expected.size(), actual.size()); + for (final String key : expected.keySet()) { + assertEquals("Returned JSON contains inserted value", expected.get(key), (Integer) actual.getIntegerSafely(key)); + } + } + + @Test + public void testGetAndZeroSearchNoData() throws Exception { + final ExtendedJSONObject actual = SearchCountMeasurements.getAndZeroSearch(sharedPrefs); + assertEquals("Returned json is empty", 0, actual.size()); + } + + private String getEngineSearchCountKey(final String engineWhereStr) { + return SearchCountMeasurements.getEngineSearchCountKey(engineWhereStr); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/measurements/TestSessionMeasurements.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/measurements/TestSessionMeasurements.java new file mode 100644 index 000000000..a5d3ce551 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/measurements/TestSessionMeasurements.java @@ -0,0 +1,124 @@ +/* + * 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 org.mozilla.gecko.telemetry.measurements; + +import android.content.Context; +import android.content.SharedPreferences; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.telemetry.measurements.SessionMeasurements.SessionMeasurementsContainer; +import org.robolectric.RuntimeEnvironment; + +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +/** + * Tests the session measurements class. + */ +@RunWith(TestRunner.class) +public class TestSessionMeasurements { + + private SessionMeasurements testMeasurements; + private SharedPreferences sharedPrefs; + private Context context; + + @Before + public void setUp() throws Exception { + testMeasurements = spy(SessionMeasurements.class); + sharedPrefs = RuntimeEnvironment.application.getSharedPreferences( + TestSessionMeasurements.class.getSimpleName(), Context.MODE_PRIVATE); + doReturn(sharedPrefs).when(testMeasurements).getSharedPreferences(any(Context.class)); + + context = RuntimeEnvironment.application; + } + + private void assertSessionCount(final String postfix, final int expectedSessionCount) { + final int actual = sharedPrefs.getInt(SessionMeasurements.PREF_SESSION_COUNT, -1); + assertEquals("Expected number of sessions occurred " + postfix, expectedSessionCount, actual); + } + + private void assertSessionDuration(final String postfix, final long expectedSessionDuration) { + final long actual = sharedPrefs.getLong(SessionMeasurements.PREF_SESSION_DURATION, -1); + assertEquals("Expected session duration received " + postfix, expectedSessionDuration, actual); + } + + private void mockGetSystemTimeNanosToReturn(final long value) { + doReturn(value).when(testMeasurements).getSystemTimeNano(); + } + + @Test + public void testRecordSessionStartAndEndCalledOnce() throws Exception { + final long expectedElapsedSeconds = 4; + mockGetSystemTimeNanosToReturn(0); + testMeasurements.recordSessionStart(); + mockGetSystemTimeNanosToReturn(TimeUnit.SECONDS.toNanos(expectedElapsedSeconds)); + testMeasurements.recordSessionEnd(context); + + final String postfix = "after recordSessionStart/End called once"; + assertSessionCount(postfix, 1); + assertSessionDuration(postfix, expectedElapsedSeconds); + } + + @Test + public void testRecordSessionStartAndEndCalledTwice() throws Exception { + final long expectedElapsedSeconds = 100; + mockGetSystemTimeNanosToReturn(0L); + for (int i = 1; i <= 2; ++i) { + testMeasurements.recordSessionStart(); + mockGetSystemTimeNanosToReturn(TimeUnit.SECONDS.toNanos((expectedElapsedSeconds / 2) * i)); + testMeasurements.recordSessionEnd(context); + } + + final String postfix = "after recordSessionStart/End called twice"; + assertSessionCount(postfix, 2); + assertSessionDuration(postfix, expectedElapsedSeconds); + } + + @Test(expected = IllegalStateException.class) + public void testRecordSessionStartThrowsIfSessionAlreadyStarted() throws Exception { + // First call will start the session, next expected to throw. + for (int i = 0; i < 2; ++i) { + testMeasurements.recordSessionStart(); + } + } + + @Test(expected = IllegalStateException.class) + public void testRecordSessionEndThrowsIfCalledBeforeSessionStarted() { + testMeasurements.recordSessionEnd(context); + } + + @Test // assumes the underlying format in SessionMeasurements + public void testGetAndResetSessionMeasurementsReturnsSetData() throws Exception { + final int expectedSessionCount = 42; + final long expectedSessionDuration = 1234567890; + sharedPrefs.edit() + .putInt(SessionMeasurements.PREF_SESSION_COUNT, expectedSessionCount) + .putLong(SessionMeasurements.PREF_SESSION_DURATION, expectedSessionDuration) + .apply(); + + final SessionMeasurementsContainer actual = testMeasurements.getAndResetSessionMeasurements(context); + assertEquals("Returned session count matches expected", expectedSessionCount, actual.sessionCount); + assertEquals("Returned session duration matches expected", expectedSessionDuration, actual.elapsedSeconds); + } + + @Test + public void testGetAndResetSessionMeasurementsResetsData() throws Exception { + sharedPrefs.edit() + .putInt(SessionMeasurements.PREF_SESSION_COUNT, 10) + .putLong(SessionMeasurements.PREF_SESSION_DURATION, 10) + .apply(); + + testMeasurements.getAndResetSessionMeasurements(context); + final String postfix = "is reset after retrieval"; + assertSessionCount(postfix, 0); + assertSessionDuration(postfix, 0); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/pingbuilders/TestTelemetryPingBuilder.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/pingbuilders/TestTelemetryPingBuilder.java new file mode 100644 index 000000000..ca0124121 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/pingbuilders/TestTelemetryPingBuilder.java @@ -0,0 +1,84 @@ +/* + * 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 org.mozilla.gecko.telemetry.pingbuilders; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import static org.junit.Assert.*; + +/** + * Unit test methods of the {@link TelemetryPingBuilder} class. + */ +@RunWith(TestRunner.class) +public class TestTelemetryPingBuilder { + @Test + public void testMandatoryFieldsNone() { + final NoMandatoryFieldsBuilder builder = new NoMandatoryFieldsBuilder(); + builder.setNonMandatoryField(); + assertNotNull("Builder does not throw and returns a non-null value", builder.build()); + } + + @Test(expected = IllegalArgumentException.class) + public void testMandatoryFieldsMissing() { + final MandatoryFieldsBuilder builder = new MandatoryFieldsBuilder(); + builder.setNonMandatoryField() + .build(); // should throw + } + + @Test + public void testMandatoryFieldsIncluded() { + final MandatoryFieldsBuilder builder = new MandatoryFieldsBuilder(); + builder.setNonMandatoryField() + .setMandatoryField(); + assertNotNull("Builder does not throw and returns non-null value", builder.build()); + } + + private static class NoMandatoryFieldsBuilder extends TelemetryPingBuilder { + @Override + public String getDocType() { + return ""; + } + + @Override + public String[] getMandatoryFields() { + return new String[0]; + } + + public NoMandatoryFieldsBuilder setNonMandatoryField() { + payload.put("non-mandatory", true); + return this; + } + } + + private static class MandatoryFieldsBuilder extends TelemetryPingBuilder { + private static final String MANDATORY_FIELD = "mandatory-field"; + + @Override + public String getDocType() { + return ""; + } + + @Override + public String[] getMandatoryFields() { + return new String[] { + MANDATORY_FIELD, + }; + } + + public MandatoryFieldsBuilder setNonMandatoryField() { + payload.put("non-mandatory", true); + return this; + } + + public MandatoryFieldsBuilder setMandatoryField() { + payload.put(MANDATORY_FIELD, true); + return this; + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/schedulers/TestTelemetryUploadAllPingsImmediatelyScheduler.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/schedulers/TestTelemetryUploadAllPingsImmediatelyScheduler.java new file mode 100644 index 000000000..8093040ee --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/schedulers/TestTelemetryUploadAllPingsImmediatelyScheduler.java @@ -0,0 +1,59 @@ +/* + * 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 org.mozilla.gecko.telemetry.schedulers; + +import android.content.Context; +import android.content.Intent; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.telemetry.TelemetryUploadService; +import org.mozilla.gecko.telemetry.stores.TelemetryPingStore; + +import static junit.framework.Assert.*; +import static org.mockito.Mockito.*; + +/** + * Unit tests for the upload immediately scheduler. + * + * When we add more schedulers, we'll likely change the interface + * (e.g. pass in current time) and these tests will be more useful. + */ +@RunWith(TestRunner.class) +public class TestTelemetryUploadAllPingsImmediatelyScheduler { + + private TelemetryUploadAllPingsImmediatelyScheduler testScheduler; + private TelemetryPingStore testStore; + + @Before + public void setUp() { + testScheduler = new TelemetryUploadAllPingsImmediatelyScheduler(); + testStore = mock(TelemetryPingStore.class); + } + + @Test + public void testReadyToUpload() { + assertTrue("Scheduler is always ready to upload", testScheduler.isReadyToUpload(testStore)); + } + + @Test + public void testScheduleUpload() { + final Context context = mock(Context.class); + + testScheduler.scheduleUpload(context, testStore); + + final ArgumentCaptor intentCaptor = ArgumentCaptor.forClass(Intent.class); + verify(context).startService(intentCaptor.capture()); + final Intent actualIntent = intentCaptor.getValue(); + assertEquals("Intent action is upload", TelemetryUploadService.ACTION_UPLOAD, actualIntent.getAction()); + assertTrue("Intent contains store", actualIntent.hasExtra(TelemetryUploadService.EXTRA_STORE)); + assertEquals("Intent class target is upload service", + TelemetryUploadService.class.getName(), actualIntent.getComponent().getClassName()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/stores/TestTelemetryJSONFilePingStore.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/stores/TestTelemetryJSONFilePingStore.java new file mode 100644 index 000000000..a95a8b292 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/telemetry/stores/TestTelemetryJSONFilePingStore.java @@ -0,0 +1,250 @@ +/* + * 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 org.mozilla.gecko.telemetry.stores; + +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.telemetry.TelemetryPing; +import org.mozilla.gecko.util.FileUtils; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import static org.junit.Assert.*; + +/** + * Unit test methods of the {@link TelemetryJSONFilePingStore} class. + */ +@RunWith(TestRunner.class) +public class TestTelemetryJSONFilePingStore { + + @Rule + public TemporaryFolder tempDir = new TemporaryFolder(); + private File testDir; + private TelemetryJSONFilePingStore testStore; + + @Before + public void setUp() throws Exception { + testDir = tempDir.newFolder(); + testStore = new TelemetryJSONFilePingStore(testDir, ""); + } + + private ExtendedJSONObject generateTelemetryPayload() { + final ExtendedJSONObject out = new ExtendedJSONObject(); + out.put("str", "a String"); + out.put("int", 42); + out.put("null", (ExtendedJSONObject) null); + return out; + } + + private void assertIsGeneratedPayload(final ExtendedJSONObject actual) throws Exception { + assertNull("Null field is null", actual.getObject("null")); + assertEquals("int field is correct", 42, (int) actual.getIntegerSafely("int")); + assertEquals("str field is correct", "a String", actual.getString("str")); + } + + private void assertStoreFileCount(final int expectedCount) { + assertEquals("Store contains " + expectedCount + " item(s)", expectedCount, testDir.list().length); + } + + @Test + public void testConstructorOnlyWritesToGivenDir() throws Exception { + // Constructor is called in @Before method + assertTrue("Store dir exists", testDir.exists()); + assertEquals("Temp dir contains one dir (the store dir)", 1, tempDir.getRoot().list().length); + } + + @Test(expected = IllegalStateException.class) + public void testConstructorStoreAlreadyExistsAsNonDirectory() throws Exception { + final File file = tempDir.newFile(); + new TelemetryJSONFilePingStore(file, "profileName"); // expected to throw. + } + + @Test(expected = IllegalStateException.class) + public void testConstructorDirIsNotReadable() throws Exception { + final File dir = tempDir.newFolder(); + dir.setReadable(false); + new TelemetryJSONFilePingStore(dir, "profileName"); // expected to throw. + } + + @Test(expected = IllegalStateException.class) + public void testConstructorDirIsNotWritable() throws Exception { + final File dir = tempDir.newFolder(); + dir.setWritable(false); + new TelemetryJSONFilePingStore(dir, "profileName"); // expected to throw. + } + + @Test(expected = IllegalStateException.class) + public void testConstructorDirIsNotExecutable() throws Exception { + final File dir = tempDir.newFolder(); + dir.setExecutable(false); + new TelemetryJSONFilePingStore(dir, "profileName"); // expected to throw. + } + + @Test + public void testStorePingStoresCorrectData() throws Exception { + assertStoreFileCount(0); + + final String expectedID = getDocID(); + final TelemetryPing expectedPing = new TelemetryPing("a/server/url", generateTelemetryPayload(), expectedID); + testStore.storePing(expectedPing); + + assertStoreFileCount(1); + final String filename = testDir.list()[0]; + assertTrue("Filename contains expected ID", filename.equals(expectedID)); + final JSONObject actual = FileUtils.readJSONObjectFromFile(new File(testDir, filename)); + assertEquals("Ping url paths are equal", expectedPing.getURLPath(), actual.getString(TelemetryJSONFilePingStore.KEY_URL_PATH)); + assertIsGeneratedPayload(new ExtendedJSONObject(actual.getString(TelemetryJSONFilePingStore.KEY_PAYLOAD))); + } + + @Test + public void testStorePingMultiplePingsStoreSeparateFiles() throws Exception { + assertStoreFileCount(0); + for (int i = 1; i < 10; ++i) { + testStore.storePing(new TelemetryPing("server", generateTelemetryPayload(), getDocID())); + assertStoreFileCount(i); + } + } + + @Test + public void testStorePingReleasesFileLock() throws Exception { + assertStoreFileCount(0); + testStore.storePing(new TelemetryPing("server", generateTelemetryPayload(), getDocID())); + assertStoreFileCount(1); + final File file = new File(testDir, testDir.list()[0]); + final FileOutputStream stream = new FileOutputStream(file); + try { + assertNotNull("File lock is released after store write", stream.getChannel().tryLock()); + } finally { + stream.close(); // releases lock + } + } + + @Test + public void testGetAllPingsSavesData() throws Exception { + final String urlPrefix = "url"; + writeTestPingsToStore(3, urlPrefix); + + final ArrayList pings = testStore.getAllPings(); + for (final TelemetryPing ping : pings) { + assertEquals("Expected url path value received", urlPrefix + ping.getDocID(), ping.getURLPath()); + assertIsGeneratedPayload(ping.getPayload()); + } + } + + @Test + public void testGetAllPingsIsSorted() throws Exception { + final List storedDocIDs = writeTestPingsToStore(3, "urlPrefix"); + + final ArrayList pings = testStore.getAllPings(); + for (int i = 0; i < pings.size(); ++i) { + final String expectedDocID = storedDocIDs.get(i); + final TelemetryPing ping = pings.get(i); + + assertEquals("Stored ping " + i + " retrieved in order", expectedDocID, ping.getDocID()); + } + } + + @Test // regression test: bug 1272817 + public void testGetAllPingsHandlesEmptyFiles() throws Exception { + final int expectedPingCount = 3; + writeTestPingsToStore(expectedPingCount, "whatever"); + assertTrue("Empty file is created", testStore.getPingFile(getDocID()).createNewFile()); + assertEquals("Returned pings only contains valid files", expectedPingCount, testStore.getAllPings().size()); + } + + @Test + public void testMaybePrunePingsDoesNothingIfAtMax() throws Exception { + final int pingCount = TelemetryJSONFilePingStore.MAX_PING_COUNT; + writeTestPingsToStore(pingCount, "whatever"); + assertStoreFileCount(pingCount); + testStore.maybePrunePings(); + assertStoreFileCount(pingCount); + } + + @Test + public void testMaybePrunePingsPrunesIfAboveMax() throws Exception { + final int pingCount = TelemetryJSONFilePingStore.MAX_PING_COUNT + 1; + final List expectedDocIDs = writeTestPingsToStore(pingCount, "whatever"); + assertStoreFileCount(pingCount); + testStore.maybePrunePings(); + assertStoreFileCount(TelemetryJSONFilePingStore.MAX_PING_COUNT); + + final HashSet existingIDs = new HashSet<>(Arrays.asList(testDir.list())); + assertFalse("Oldest ping was removed", existingIDs.contains(expectedDocIDs.get(0))); + } + + @Test + public void testOnUploadAttemptCompleted() throws Exception { + final List savedDocIDs = writeTestPingsToStore(10, "url"); + final int halfSize = savedDocIDs.size() / 2; + final Set unuploadedPingIDs = new HashSet<>(savedDocIDs.subList(0, halfSize)); + final Set removedPingIDs = new HashSet<>(savedDocIDs.subList(halfSize, savedDocIDs.size())); + testStore.onUploadAttemptComplete(removedPingIDs); + + for (final String unuploadedDocID : testDir.list()) { + assertFalse("Unuploaded ID is not in removed ping IDs", removedPingIDs.contains(unuploadedDocID)); + assertTrue("Unuploaded ID is in unuploaded ping IDs", unuploadedPingIDs.contains(unuploadedDocID)); + unuploadedPingIDs.remove(unuploadedDocID); + } + assertTrue("All non-successful-upload ping IDs were matched", unuploadedPingIDs.isEmpty()); + } + + @Test + public void testGetPingFileIsDocID() throws Exception { + final String docID = getDocID(); + final File file = testStore.getPingFile(docID); + assertTrue("Ping filename contains ID", file.getName().equals(docID)); + } + + /** + * Writes pings to store without using store API with: + * server = urlPrefix + docID + * payload = generated payload + * + * The docID is stored as the filename. + * + * Note: assumes {@link TelemetryJSONFilePingStore#getPingFile(String)} works. + * + * @return a list of doc IDs saved to disk in ascending order of last modified date + */ + private List writeTestPingsToStore(final int count, final String urlPrefix) throws Exception { + final List savedDocIDs = new ArrayList<>(count); + final long now = System.currentTimeMillis(); + for (int i = 1; i <= count; ++i) { + final String docID = getDocID(); + final JSONObject obj = new JSONObject() + .put(TelemetryJSONFilePingStore.KEY_URL_PATH, urlPrefix + docID) + .put(TelemetryJSONFilePingStore.KEY_PAYLOAD, generateTelemetryPayload()); + final File pingFile = testStore.getPingFile(docID); + FileUtils.writeJSONObjectToFile(pingFile, obj); + + // If we don't set an explicit time, the modified times are all equal. + // Also, last modified times are rounded by second. + assertTrue("Able to set last modified time", pingFile.setLastModified(now - (count * 10_000) + i * 10_000)); + savedDocIDs.add(docID); + } + return savedDocIDs; + } + + private String getDocID() { + return UUID.randomUUID().toString(); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/tokenserver/test/TestTokenServerClient.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/tokenserver/test/TestTokenServerClient.java new file mode 100644 index 000000000..03fe67794 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/tokenserver/test/TestTokenServerClient.java @@ -0,0 +1,335 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.tokenserver.test; + +import ch.boye.httpclientandroidlib.Header; +import ch.boye.httpclientandroidlib.HttpResponse; +import ch.boye.httpclientandroidlib.ProtocolVersion; +import ch.boye.httpclientandroidlib.client.methods.HttpGet; +import ch.boye.httpclientandroidlib.client.methods.HttpRequestBase; +import ch.boye.httpclientandroidlib.entity.StringEntity; +import ch.boye.httpclientandroidlib.message.BasicHeader; +import ch.boye.httpclientandroidlib.message.BasicHttpResponse; +import ch.boye.httpclientandroidlib.message.BasicStatusLine; +import junit.framework.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.common.log.Logger; +import org.mozilla.gecko.background.common.log.writers.StringLogWriter; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.background.testhelpers.WaitHelper; +import org.mozilla.gecko.sync.ExtendedJSONObject; +import org.mozilla.gecko.sync.net.AuthHeaderProvider; +import org.mozilla.gecko.sync.net.BaseResource; +import org.mozilla.gecko.sync.net.SyncResponse; +import org.mozilla.gecko.tokenserver.TokenServerClient; +import org.mozilla.gecko.tokenserver.TokenServerClient.TokenFetchResourceDelegate; +import org.mozilla.gecko.tokenserver.TokenServerClientDelegate; +import org.mozilla.gecko.tokenserver.TokenServerException; +import org.mozilla.gecko.tokenserver.TokenServerException.TokenServerConditionsRequiredException; +import org.mozilla.gecko.tokenserver.TokenServerException.TokenServerInvalidCredentialsException; +import org.mozilla.gecko.tokenserver.TokenServerException.TokenServerMalformedRequestException; +import org.mozilla.gecko.tokenserver.TokenServerException.TokenServerMalformedResponseException; +import org.mozilla.gecko.tokenserver.TokenServerException.TokenServerUnknownServiceException; +import org.mozilla.gecko.tokenserver.TokenServerToken; + +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@RunWith(TestRunner.class) +public class TestTokenServerClient { + public static final String JSON = "application/json"; + public static final String TEXT = "text/plain"; + + public static final String TEST_TOKEN_RESPONSE = "{\"api_endpoint\": \"https://stage-aitc1.services.mozilla.com/1.0/1659259\"," + + "\"duration\": 300," + + "\"id\": \"eySHORTENED\"," + + "\"key\": \"-plSHORTENED\"," + + "\"uid\": 1659259}"; + + public static final String TEST_CONDITIONS_RESPONSE = "{\"errors\":[{" + + "\"location\":\"header\"," + + "\"description\":\"Need to accept conditions\"," + + "\"condition_urls\":{\"tos\":\"http://url-to-tos.com\"}," + + "\"name\":\"X-Conditions-Accepted\"}]," + + "\"status\":\"error\"}"; + + public static final String TEST_ERROR_RESPONSE = "{\"status\": \"error\"," + + "\"errors\": [{\"location\": \"body\", \"name\": \"\", \"description\": \"Unauthorized EXTENDED\"}]}"; + + public static final String TEST_INVALID_TIMESTAMP_RESPONSE = "{\"status\": \"invalid-timestamp\", " + + "\"errors\": [{\"location\": \"body\", \"name\": \"\", \"description\": \"Unauthorized\"}]}"; + + protected TokenServerClient client; + + @Before + public void setUp() throws Exception { + this.client = new TokenServerClient(new URI("http://unused.com"), Executors.newSingleThreadExecutor()); + } + + protected TokenServerToken doProcessResponse(int statusCode, String contentType, Object token) + throws UnsupportedEncodingException, TokenServerException { + final HttpResponse response = new BasicHttpResponse( + new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), statusCode, "OK")); + + StringEntity stringEntity = new StringEntity(token.toString()); + stringEntity.setContentType(contentType); + response.setEntity(stringEntity); + + return client.processResponse(new SyncResponse(response)); + } + + @SuppressWarnings("rawtypes") + protected TokenServerException expectProcessResponseFailure(int statusCode, String contentType, Object token, Class klass) + throws TokenServerException, UnsupportedEncodingException { + try { + doProcessResponse(statusCode, contentType, token.toString()); + fail("Expected exception of type " + klass + "."); + + return null; + } catch (TokenServerException e) { + assertEquals(klass, e.getClass()); + + return e; + } + } + + @SuppressWarnings("rawtypes") + protected TokenServerException expectProcessResponseFailure(Object token, Class klass) + throws UnsupportedEncodingException, TokenServerException { + return expectProcessResponseFailure(200, "application/json", token, klass); + } + + @Test + public void testProcessResponseSuccess() throws Exception { + TokenServerToken token = doProcessResponse(200, "application/json", TEST_TOKEN_RESPONSE); + + assertEquals("eySHORTENED", token.id); + assertEquals("-plSHORTENED", token.key); + assertEquals("1659259", token.uid); + assertEquals("https://stage-aitc1.services.mozilla.com/1.0/1659259", token.endpoint); + } + + @Test + public void testProcessResponseFailure() throws Exception { + // Wrong Content-Type. + expectProcessResponseFailure(200, TEXT, new ExtendedJSONObject(), TokenServerMalformedResponseException.class); + + // Not valid JSON. + expectProcessResponseFailure("#!", TokenServerMalformedResponseException.class); + + // Status code 400. + expectProcessResponseFailure(400, JSON, new ExtendedJSONObject(), TokenServerMalformedRequestException.class); + + // Status code 401. + expectProcessResponseFailure(401, JSON, new ExtendedJSONObject(), TokenServerInvalidCredentialsException.class); + expectProcessResponseFailure(401, JSON, TEST_INVALID_TIMESTAMP_RESPONSE, TokenServerInvalidCredentialsException.class); + + // Status code 404. + expectProcessResponseFailure(404, JSON, new ExtendedJSONObject(), TokenServerUnknownServiceException.class); + + // Status code 406, which is not specially handled, but with errors. We take + // care that errors are actually printed because we're going to want this to + // work when things go wrong. + StringLogWriter logWriter = new StringLogWriter(); + + Logger.startLoggingTo(logWriter); + try { + expectProcessResponseFailure(406, JSON, TEST_ERROR_RESPONSE, TokenServerException.class); + + assertTrue(logWriter.toString().contains("Unauthorized EXTENDED")); + } finally { + Logger.stopLoggingTo(logWriter); + } + + // Status code 503. + expectProcessResponseFailure(503, JSON, new ExtendedJSONObject(), TokenServerException.class); + } + + @Test + public void testProcessResponseConditionsRequired() throws Exception { + + // Status code 403: conditions need to be accepted, but malformed (no urls). + expectProcessResponseFailure(403, JSON, new ExtendedJSONObject(), TokenServerMalformedResponseException.class); + + // Status code 403, with urls. + TokenServerConditionsRequiredException e = (TokenServerConditionsRequiredException) + expectProcessResponseFailure(403, JSON, TEST_CONDITIONS_RESPONSE, TokenServerConditionsRequiredException.class); + + ExtendedJSONObject expectedUrls = new ExtendedJSONObject(); + expectedUrls.put("tos", "http://url-to-tos.com"); + assertEquals(expectedUrls.toString(), e.conditionUrls.toString()); + } + + @Test + public void testProcessResponseMalformedToken() throws Exception { + ExtendedJSONObject token; + + // Missing key. + token = new ExtendedJSONObject(TEST_TOKEN_RESPONSE); + token.remove("api_endpoint"); + expectProcessResponseFailure(token, TokenServerMalformedResponseException.class); + + // Key has wrong type; expected String. + token = new ExtendedJSONObject(TEST_TOKEN_RESPONSE); + token.put("api_endpoint", new ExtendedJSONObject()); + expectProcessResponseFailure(token, TokenServerMalformedResponseException.class); + + // Key has wrong type; expected number. + token = new ExtendedJSONObject(TEST_TOKEN_RESPONSE); + token.put("uid", "NON NUMERIC"); + expectProcessResponseFailure(token, TokenServerMalformedResponseException.class); + } + + private class MockBaseResource extends BaseResource { + public MockBaseResource(String uri) throws URISyntaxException { + super(uri); + this.request = new HttpGet(this.uri); + } + + public HttpRequestBase prepareHeadersAndReturn() throws Exception { + super.prepareClient(); + return request; + } + } + + @Test + public void testClientStateHeader() throws Exception { + String assertion = "assertion"; + String clientState = "abcdef"; + MockBaseResource resource = new MockBaseResource("http://unused.local/"); + + TokenServerClientDelegate delegate = new TokenServerClientDelegate() { + @Override + public void handleSuccess(TokenServerToken token) { + } + + @Override + public void handleFailure(TokenServerException e) { + } + + @Override + public void handleError(Exception e) { + } + + @Override + public void handleBackoff(int backoffSeconds) { + } + + @Override + public String getUserAgent() { + return null; + } + }; + + resource.delegate = new TokenServerClient.TokenFetchResourceDelegate(client, resource, delegate, assertion, clientState , true) { + @Override + public AuthHeaderProvider getAuthHeaderProvider() { + return null; + } + }; + + HttpRequestBase request = resource.prepareHeadersAndReturn(); + Assert.assertEquals("abcdef", request.getFirstHeader("X-Client-State").getValue()); + Assert.assertEquals("1", request.getFirstHeader("X-Conditions-Accepted").getValue()); + } + + public static class MockTokenServerClient extends TokenServerClient { + public MockTokenServerClient(URI uri, Executor executor) { + super(uri, executor); + } + } + + public static final class MockTokenServerClientDelegate implements + TokenServerClientDelegate { + public volatile boolean backoffCalled; + public volatile boolean succeeded; + public volatile int backoff; + + @Override + public String getUserAgent() { + return null; + } + + @Override + public void handleSuccess(TokenServerToken token) { + succeeded = true; + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void handleFailure(TokenServerException e) { + succeeded = false; + WaitHelper.getTestWaiter().performNotify(); + } + + @Override + public void handleError(Exception e) { + succeeded = false; + WaitHelper.getTestWaiter().performNotify(e); + } + + @Override + public void handleBackoff(int backoffSeconds) { + backoffCalled = true; + backoff = backoffSeconds; + } + } + + private void expectDelegateCalls(URI uri, MockTokenServerClient client, int code, Header header, String body, boolean succeeded, long backoff, boolean expectBackoff) throws UnsupportedEncodingException { + final BaseResource resource = new BaseResource(uri); + final String assertion = "someassertion"; + final String clientState = "abcdefabcdefabcdefabcdefabcdefab"; + final boolean conditionsAccepted = true; + + MockTokenServerClientDelegate delegate = new MockTokenServerClientDelegate(); + + final TokenFetchResourceDelegate tokenFetchResourceDelegate = new TokenServerClient.TokenFetchResourceDelegate(client, resource, delegate, assertion, clientState, conditionsAccepted); + + final BasicStatusLine statusline = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), code, "Whatever"); + final HttpResponse response = new BasicHttpResponse(statusline); + response.setHeader(header); + if (body != null) { + final StringEntity entity = new StringEntity(body); + entity.setContentType("application/json"); + response.setEntity(entity); + } + + WaitHelper.getTestWaiter().performWait(new Runnable() { + @Override + public void run() { + tokenFetchResourceDelegate.handleHttpResponse(response); + } + }); + + assertEquals(expectBackoff, delegate.backoffCalled); + assertEquals(backoff, delegate.backoff); + assertEquals(succeeded, delegate.succeeded); + } + + @Test + public void testBackoffHandling() throws URISyntaxException, UnsupportedEncodingException { + final URI uri = new URI("http://unused.com"); + final MockTokenServerClient client = new MockTokenServerClient(uri, Executors.newSingleThreadExecutor()); + + // Even the 200 code here is false because the body is malformed. + expectDelegateCalls(uri, client, 200, new BasicHeader("x-backoff", "13"), "baaaa", false, 13, true); + expectDelegateCalls(uri, client, 400, new BasicHeader("X-Weave-Backoff", "15"), null, false, 15, true); + expectDelegateCalls(uri, client, 503, new BasicHeader("retry-after", "3"), null, false, 3, true); + + // Retry-After is only processed on 503. + expectDelegateCalls(uri, client, 200, new BasicHeader("retry-after", "13"), null, false, 0, false); + + // Now let's try one with a valid body. + expectDelegateCalls(uri, client, 200, new BasicHeader("X-Backoff", "1234"), TEST_TOKEN_RESPONSE, true, 1234, true); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/NetworkUtilsTest.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/NetworkUtilsTest.java new file mode 100644 index 000000000..fb2cffc92 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/NetworkUtilsTest.java @@ -0,0 +1,185 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +package org.mozilla.gecko.util; + +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.telephony.TelephonyManager; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.util.NetworkUtils.*; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.internal.ShadowExtractor; +import org.robolectric.shadows.ShadowConnectivityManager; +import org.robolectric.shadows.ShadowNetworkInfo; + +import static org.junit.Assert.*; + +@RunWith(TestRunner.class) +public class NetworkUtilsTest { + private ConnectivityManager connectivityManager; + private ShadowConnectivityManager shadowConnectivityManager; + + @Before + public void setUp() { + connectivityManager = (ConnectivityManager) RuntimeEnvironment.application.getSystemService(Context.CONNECTIVITY_SERVICE); + + // Not using Shadows.shadowOf(connectivityManager) because of Robolectric bug when using API23+ + // See: https://github.com/robolectric/robolectric/issues/1862 + shadowConnectivityManager = (ShadowConnectivityManager) ShadowExtractor.extract(connectivityManager); + } + + @Test + public void testIsConnected() throws Exception { + assertFalse(NetworkUtils.isConnected((ConnectivityManager) null)); + + shadowConnectivityManager.setActiveNetworkInfo(null); + assertFalse(NetworkUtils.isConnected(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_WIFI, 0, true, true) + ); + assertTrue(NetworkUtils.isConnected(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.DISCONNECTED, ConnectivityManager.TYPE_WIFI, 0, true, false) + ); + assertFalse(NetworkUtils.isConnected(connectivityManager)); + } + + @Test + public void testGetConnectionSubType() throws Exception { + assertEquals(ConnectionSubType.UNKNOWN, NetworkUtils.getConnectionSubType(null)); + + shadowConnectivityManager.setActiveNetworkInfo(null); + assertEquals(ConnectionSubType.UNKNOWN, NetworkUtils.getConnectionSubType(connectivityManager)); + + // We don't seem to care about figuring out all connection types. So... + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_VPN, 0, true, true) + ); + assertEquals(ConnectionSubType.UNKNOWN, NetworkUtils.getConnectionSubType(connectivityManager)); + + // But anything below we should recognize. + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_ETHERNET, 0, true, true) + ); + assertEquals(ConnectionSubType.ETHERNET, NetworkUtils.getConnectionSubType(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_WIFI, 0, true, true) + ); + assertEquals(ConnectionSubType.WIFI, NetworkUtils.getConnectionSubType(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_WIMAX, 0, true, true) + ); + assertEquals(ConnectionSubType.WIMAX, NetworkUtils.getConnectionSubType(connectivityManager)); + + // Unknown mobile + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_UNKNOWN, true, true) + ); + assertEquals(ConnectionSubType.UNKNOWN, NetworkUtils.getConnectionSubType(connectivityManager)); + + // 2G mobile types + int[] cell2gTypes = new int[] { + TelephonyManager.NETWORK_TYPE_GPRS, + TelephonyManager.NETWORK_TYPE_EDGE, + TelephonyManager.NETWORK_TYPE_CDMA, + TelephonyManager.NETWORK_TYPE_1xRTT, + TelephonyManager.NETWORK_TYPE_IDEN + }; + for (int i = 0; i < cell2gTypes.length; i++) { + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_MOBILE, cell2gTypes[i], true, true) + ); + assertEquals(ConnectionSubType.CELL_2G, NetworkUtils.getConnectionSubType(connectivityManager)); + } + + // 3G mobile types + int[] cell3gTypes = new int[] { + TelephonyManager.NETWORK_TYPE_UMTS, + TelephonyManager.NETWORK_TYPE_EVDO_0, + TelephonyManager.NETWORK_TYPE_EVDO_A, + TelephonyManager.NETWORK_TYPE_HSDPA, + TelephonyManager.NETWORK_TYPE_HSUPA, + TelephonyManager.NETWORK_TYPE_HSPA, + TelephonyManager.NETWORK_TYPE_EVDO_B, + TelephonyManager.NETWORK_TYPE_EHRPD, + TelephonyManager.NETWORK_TYPE_HSPAP + }; + for (int i = 0; i < cell3gTypes.length; i++) { + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_MOBILE, cell3gTypes[i], true, true) + ); + assertEquals(ConnectionSubType.CELL_3G, NetworkUtils.getConnectionSubType(connectivityManager)); + } + + // 4G mobile type + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_MOBILE, TelephonyManager.NETWORK_TYPE_LTE, true, true) + ); + assertEquals(ConnectionSubType.CELL_4G, NetworkUtils.getConnectionSubType(connectivityManager)); + } + + @Test + public void testGetConnectionType() { + shadowConnectivityManager.setActiveNetworkInfo(null); + assertEquals(ConnectionType.NONE, NetworkUtils.getConnectionType(connectivityManager)); + assertEquals(ConnectionType.NONE, NetworkUtils.getConnectionType(null)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_VPN, 0, true, true) + ); + assertEquals(ConnectionType.OTHER, NetworkUtils.getConnectionType(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_WIFI, 0, true, true) + ); + assertEquals(ConnectionType.WIFI, NetworkUtils.getConnectionType(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_MOBILE, 0, true, true) + ); + assertEquals(ConnectionType.CELLULAR, NetworkUtils.getConnectionType(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_ETHERNET, 0, true, true) + ); + assertEquals(ConnectionType.ETHERNET, NetworkUtils.getConnectionType(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_BLUETOOTH, 0, true, true) + ); + assertEquals(ConnectionType.BLUETOOTH, NetworkUtils.getConnectionType(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_WIMAX, 0, true, true) + ); + assertEquals(ConnectionType.CELLULAR, NetworkUtils.getConnectionType(connectivityManager)); + } + + @Test + public void testGetNetworkStatus() { + assertEquals(NetworkStatus.UNKNOWN, NetworkUtils.getNetworkStatus(null)); + + shadowConnectivityManager.setActiveNetworkInfo(null); + assertEquals(NetworkStatus.DOWN, NetworkUtils.getNetworkStatus(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTING, ConnectivityManager.TYPE_MOBILE, 0, true, false) + ); + assertEquals(NetworkStatus.DOWN, NetworkUtils.getNetworkStatus(connectivityManager)); + + shadowConnectivityManager.setActiveNetworkInfo( + ShadowNetworkInfo.newInstance(NetworkInfo.DetailedState.CONNECTED, ConnectivityManager.TYPE_MOBILE, 0, true, true) + ); + assertEquals(NetworkStatus.UP, NetworkUtils.getNetworkStatus(connectivityManager)); + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestContextUtils.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestContextUtils.java new file mode 100644 index 000000000..56b69b684 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestContextUtils.java @@ -0,0 +1,38 @@ +/* + * 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 org.mozilla.gecko.util; + +import android.content.Context; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.robolectric.RuntimeEnvironment; + +import static org.junit.Assert.*; + +/** + * Unit test methods of the ContextUtils class. + */ +@RunWith(TestRunner.class) +public class TestContextUtils { + + private Context context; + + @Before + public void setUp() { + context = RuntimeEnvironment.application; + } + + @Test + public void testGetPackageInstallTimeReturnsReasonableValue() throws Exception { + // At the time of writing, Robolectric's value is 0, which is reasonable. + final long installTime = ContextUtils.getCurrentPackageInfo(context).firstInstallTime; + assertTrue("Package install time is positive", installTime >= 0); + assertTrue("Package install time is less than current time", installTime < System.currentTimeMillis()); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestDateUtil.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestDateUtil.java new file mode 100644 index 000000000..a93c81ef0 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestDateUtil.java @@ -0,0 +1,89 @@ +/* + * 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 org.mozilla.gecko.util; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.Locale; +import java.util.TimeZone; + +import static org.junit.Assert.assertEquals; + +/** + * Unit tests for date utilities. + */ +@RunWith(TestRunner.class) +public class TestDateUtil { + @Test + public void testGetDateInHTTPFormatGMT() { + final TimeZone gmt = TimeZone.getTimeZone("GMT"); + final GregorianCalendar calendar = new GregorianCalendar(gmt, Locale.US); + calendar.set(2011, Calendar.FEBRUARY, 1, 14, 0, 0); + final String expectedDate = "Tue, 01 Feb 2011 14:00:00 GMT"; + + final String actualDate = DateUtil.getDateInHTTPFormat(calendar.getTime()); + assertEquals("Returned date is expected", expectedDate, actualDate); + } + + @Test + public void testGetDateInHTTPFormatNonGMT() { + final TimeZone kst = TimeZone.getTimeZone("Asia/Seoul"); // no daylight savings time. + final GregorianCalendar calendar = new GregorianCalendar(kst, Locale.US); + calendar.set(2011, Calendar.FEBRUARY, 1, 14, 0, 0); + final String expectedDate = "Tue, 01 Feb 2011 05:00:00 GMT"; + + final String actualDate = DateUtil.getDateInHTTPFormat(calendar.getTime()); + assertEquals("Returned date is expected", expectedDate, actualDate); + } + + @Test + public void testGetTimezoneOffsetInMinutes() { + assertEquals("GMT has no offset", 0, DateUtil.getTimezoneOffsetInMinutes(TimeZone.getTimeZone("GMT"))); + + // We use custom timezones because they don't have daylight savings time. + assertEquals("Offset for GMT-8 is correct", + -480, DateUtil.getTimezoneOffsetInMinutes(TimeZone.getTimeZone("GMT-8"))); + assertEquals("Offset for GMT+12:45 is correct", + 765, DateUtil.getTimezoneOffsetInMinutes(TimeZone.getTimeZone("GMT+12:45"))); + + // We use a non-custom timezone without DST. + assertEquals("Offset for KST is correct", + 540, DateUtil.getTimezoneOffsetInMinutes(TimeZone.getTimeZone("Asia/Seoul"))); + } + + @Test + public void testGetTimezoneOffsetInMinutesForGivenDateNoDaylightSavingsTime() { + final TimeZone kst = TimeZone.getTimeZone("Asia/Seoul"); + final Calendar[] calendars = + new Calendar[] { getCalendarForMonth(Calendar.DECEMBER), getCalendarForMonth(Calendar.AUGUST) }; + for (final Calendar cal : calendars) { + cal.setTimeZone(kst); + assertEquals("Offset for KST does not change with daylight savings time", + 540, DateUtil.getTimezoneOffsetInMinutesForGivenDate(cal)); + } + } + + @Test + public void testGetTimezoneOffsetInMinutesForGivenDateDaylightSavingsTime() { + final TimeZone pacificTimeZone = TimeZone.getTimeZone("America/Los_Angeles"); + final Calendar pstCalendar = getCalendarForMonth(Calendar.DECEMBER); + final Calendar pdtCalendar = getCalendarForMonth(Calendar.AUGUST); + pstCalendar.setTimeZone(pacificTimeZone); + pdtCalendar.setTimeZone(pacificTimeZone); + assertEquals("Offset for PST is correct", -480, DateUtil.getTimezoneOffsetInMinutesForGivenDate(pstCalendar)); + assertEquals("Offset for PDT is correct", -420, DateUtil.getTimezoneOffsetInMinutesForGivenDate(pdtCalendar)); + + } + + private Calendar getCalendarForMonth(final int month) { + return new GregorianCalendar(2000, month, 1); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestFileUtils.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestFileUtils.java new file mode 100644 index 000000000..88fa7307d --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestFileUtils.java @@ -0,0 +1,339 @@ +/* + * 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 org.mozilla.gecko.util; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.util.FileUtils.FileLastModifiedComparator; +import org.mozilla.gecko.util.FileUtils.FilenameRegexFilter; +import org.mozilla.gecko.util.FileUtils.FilenameWhitelistFilter; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Pattern; + +import static junit.framework.Assert.*; +import static org.mockito.Mockito.*; + +/** + * Tests the utilities in {@link FileUtils}. + */ +@RunWith(TestRunner.class) +public class TestFileUtils { + + private static final Charset CHARSET = Charset.forName("UTF-8"); + + @Rule + public TemporaryFolder tempDir = new TemporaryFolder(); + public File testFile; + public File nonExistentFile; + + @Before + public void setUp() throws Exception { + testFile = tempDir.newFile(); + nonExistentFile = new File(tempDir.getRoot(), "non-existent-file"); + } + + @Test + public void testReadJSONObjectFromFile() throws Exception { + final JSONObject expected = new JSONObject("{\"str\": \"some str\"}"); + writeStringToFile(testFile, expected.toString()); + + final JSONObject actual = FileUtils.readJSONObjectFromFile(testFile); + assertEquals("JSON contains expected str", expected.getString("str"), actual.getString("str")); + } + + @Test(expected=IOException.class) + public void testReadJSONObjectFromFileEmptyFile() throws Exception { + assertEquals("Test file is empty", 0, testFile.length()); + FileUtils.readJSONObjectFromFile(testFile); // expected to throw + } + + @Test(expected=JSONException.class) + public void testReadJSONObjectFromFileInvalidJSON() throws Exception { + writeStringToFile(testFile, "not a json str"); + FileUtils.readJSONObjectFromFile(testFile); // expected to throw + } + + @Test + public void testReadStringFromFileReadsData() throws Exception { + final String expected = "String to write contains hard characters: !\n \\s..\"'\u00f1"; + writeStringToFile(testFile, expected); + + final String actual = FileUtils.readStringFromFile(testFile); + assertEquals("Read content matches written content", expected, actual); + } + + @Test + public void testReadStringFromFileEmptyFile() throws Exception { + assertEquals("Test file is empty", 0, testFile.length()); + + final String actual = FileUtils.readStringFromFile(testFile); + assertEquals("Read content is empty", "", actual); + } + + @Test(expected=FileNotFoundException.class) + public void testReadStringFromNonExistentFile() throws Exception { + assertFalse("File does not exist", nonExistentFile.exists()); + FileUtils.readStringFromFile(nonExistentFile); + } + + @Test + public void testReadStringFromInputStreamAndCloseStreamBufferLenIsFileLen() throws Exception { + final String expected = "String to write contains hard characters: !\n \\s..\"'\u00f1"; + writeStringToFile(testFile, expected); + + final FileInputStream stream = new FileInputStream(testFile); + final String actual = FileUtils.readStringFromInputStreamAndCloseStream(stream, expected.length()); + assertEquals("Read content matches written content", expected, actual); + } + + @Test + public void testReadStringFromInputStreamAndCloseStreamBufferLenIsBiggerThanFile() throws Exception { + final String expected = "aoeuhtns"; + writeStringToFile(testFile, expected); + + final FileInputStream stream = new FileInputStream(testFile); + final String actual = FileUtils.readStringFromInputStreamAndCloseStream(stream, expected.length() + 1024); + assertEquals("Read content matches written content", expected, actual); + } + + @Test + public void testReadStringFromInputStreamAndCloseStreamBufferLenIsSmallerThanFile() throws Exception { + final String expected = "aoeuhtns aoeusth aoeusth aoeusnth aoeusth aoeusnth aoesuth"; + writeStringToFile(testFile, expected); + + final FileInputStream stream = new FileInputStream(testFile); + final String actual = FileUtils.readStringFromInputStreamAndCloseStream(stream, 8); + assertEquals("Read content matches written content", expected, actual); + } + + @Test(expected=IllegalArgumentException.class) + public void testReadStringFromInputStreamAndCloseStreamBufferLenIsZero() throws Exception { + final String expected = "aoeuhtns aoeusth aoeusth aoeusnth aoeusth aoeusnth aoesuth"; + writeStringToFile(testFile, expected); + + final FileInputStream stream = new FileInputStream(testFile); + FileUtils.readStringFromInputStreamAndCloseStream(stream, 0); // expected to throw. + } + + @Test + public void testReadStringFromInputStreamAndCloseStreamIsEmptyStream() throws Exception { + assertTrue("Test file exists", testFile.exists()); + assertEquals("Test file is empty", 0, testFile.length()); + + final FileInputStream stream = new FileInputStream(testFile); + final String actual = FileUtils.readStringFromInputStreamAndCloseStream(stream, 8); + assertEquals("Read content from stream is empty", "", actual); + } + + @Test(expected=IOException.class) + public void testReadStringFromInputStreamAndCloseStreamClosesStream() throws Exception { + final String expected = "String to write contains hard characters: !\n \\s..\"'\u00f1"; + writeStringToFile(testFile, expected); + + final FileInputStream stream = new FileInputStream(testFile); + try { + stream.read(); // should not throw because stream is open. + FileUtils.readStringFromInputStreamAndCloseStream(stream, expected.length()); + } catch (final IOException e) { + fail("Did not expect method to throw when writing file: " + e); + } + + stream.read(); // expected to throw because stream is closed. + } + + @Test + public void testWriteStringToOutputStreamAndCloseStreamWritesData() throws Exception { + final String expected = "A string with some data in it! \u00f1 \n"; + final FileOutputStream fos = new FileOutputStream(testFile, false); + FileUtils.writeStringToOutputStreamAndCloseStream(fos, expected); + + assertTrue("Written file exists", testFile.exists()); + assertEquals("Read data equals written data", expected, readStringFromFile(testFile, expected.length())); + } + + @Test(expected=IOException.class) + public void testWriteStringToOutputStreamAndCloseStreamClosesStream() throws Exception { + final FileOutputStream fos = new FileOutputStream(testFile, false); + try { + fos.write('c'); // should not throw because stream is open. + FileUtils.writeStringToOutputStreamAndCloseStream(fos, "some string with data"); + } catch (final IOException e) { + fail("Did not expect method to throw when writing file: " + e); + } + + fos.write('c'); // expected to throw because stream is closed. + } + + /** + * The Writer we wrap our stream in can throw in .close(), preventing the underlying stream from closing. + * I added code to prevent ensure we close if the writer .close() throws. + * + * I wrote this test to test that code, however, we'd have to mock the writer [1] and that isn't straight-forward. + * I left this test around because it's a good test of other code. + * + * [1]: We thought we could mock FileOutputStream.flush but it's only flushed if the Writer thinks it should be + * flushed. We can write directly to the Stream, but that doesn't change the Writer state and doesn't affect whether + * it thinks it should be flushed. + */ + @Test(expected=IOException.class) + public void testWriteStringToOutputStreamAndCloseStreamClosesStreamIfWriterThrows() throws Exception { + final FileOutputStream fos = mock(FileOutputStream.class); + doThrow(IOException.class).when(fos).write(any(byte[].class), anyInt(), anyInt()); + doThrow(IOException.class).when(fos).write(anyInt()); + doThrow(IOException.class).when(fos).write(any(byte[].class)); + + boolean exceptionCaught = false; + try { + FileUtils.writeStringToOutputStreamAndCloseStream(fos, "some string with data"); + } catch (final IOException e) { + exceptionCaught = true; + } + assertTrue("Exception caught during tested method", exceptionCaught); // not strictly necessary but documents assumptions + + fos.write('c'); // expected to throw because stream is closed. + } + + @Test + public void testWriteStringToFile() throws Exception { + final String expected = "String to write contains hard characters: !\n \\s..\"'\u00f1"; + FileUtils.writeStringToFile(testFile, expected); + + assertTrue("Written file exists", testFile.exists()); + assertEquals("Read data equals written data", expected, readStringFromFile(testFile, expected.length())); + } + + @Test + public void testWriteStringToFileEmptyString() throws Exception { + final String expected = ""; + FileUtils.writeStringToFile(testFile, expected); + + assertTrue("Written file exists", testFile.exists()); + assertEquals("Written file is empty", 0, testFile.length()); + assertEquals("Read data equals written (empty) data", expected, readStringFromFile(testFile, expected.length())); + } + + @Test + public void testWriteStringToFileCreatesNewFile() throws Exception { + final String expected = "some str to write"; + assertFalse("Non existent file does not exist", nonExistentFile.exists()); + FileUtils.writeStringToFile(nonExistentFile, expected); // expected to create file + + assertTrue("Written file was created", nonExistentFile.exists()); + assertEquals("Read data equals written data", expected, readStringFromFile(nonExistentFile, (int) nonExistentFile.length())); + } + + @Test + public void testWriteStringToFileOverwritesFile() throws Exception { + writeStringToFile(testFile, "data"); + + final String expected = "some str to write"; + FileUtils.writeStringToFile(testFile, expected); + + assertTrue("Written file was created", testFile.exists()); + assertEquals("Read data equals written data", expected, readStringFromFile(testFile, (int) testFile.length())); + } + + @Test + public void testWriteJSONObjectToFile() throws Exception { + final JSONObject expected = new JSONObject() + .put("int", 1) + .put("str", "1") + .put("bool", true) + .put("null", JSONObject.NULL) + .put("raw null", null); + FileUtils.writeJSONObjectToFile(testFile, expected); + + assertTrue("Written file exists", testFile.exists()); + + // JSONObject.equals compares references so we have to assert each key individually. >:( + final JSONObject actual = new JSONObject(readStringFromFile(testFile, (int) testFile.length())); + assertEquals(1, actual.getInt("int")); + assertEquals("1", actual.getString("str")); + assertEquals(true, actual.getBoolean("bool")); + assertEquals(JSONObject.NULL, actual.get("null")); + assertFalse(actual.has("raw null")); + } + + // Since the read methods may not be tested yet. + private static String readStringFromFile(final File file, final int bufferLen) throws IOException { + final char[] buffer = new char[bufferLen]; + try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"))) { + reader.read(buffer, 0, buffer.length); + } + return new String(buffer); + } + + // Since the write methods may not be tested yet. + private static void writeStringToFile(final File file, final String str) throws IOException { + try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file, false), CHARSET)) { + writer.write(str); + } + assertTrue("Written file from helper method exists", file.exists()); + } + + @Test + public void testFilenameWhitelistFilter() { + final String[] expectedToAccept = new String[] { "one", "two", "three" }; + final Set whitelist = new HashSet<>(Arrays.asList(expectedToAccept)); + final FilenameWhitelistFilter testFilter = new FilenameWhitelistFilter(whitelist); + for (final String str : expectedToAccept) { + assertTrue("Filename, " + str + ", in whitelist is accepted", testFilter.accept(testFile, str)); + } + + final String[] notExpectedToAccept = new String[] { "not-in-whitelist", "meh", "whatever" }; + for (final String str : notExpectedToAccept) { + assertFalse("Filename, " + str + ", not in whitelist is not accepted", testFilter.accept(testFile, str)); + } + } + + @Test + public void testFilenameRegexFilter() { + final Pattern pattern = Pattern.compile("[a-z]{1,6}"); + final FilenameRegexFilter testFilter = new FilenameRegexFilter(pattern); + final String[] expectedToAccept = new String[] { "duckie", "goes", "quack" }; + for (final String str : expectedToAccept) { + assertTrue("Filename, " + str + ", matching regex expected to accept", testFilter.accept(testFile, str)); + } + + final String[] notExpectedToAccept = new String[] { "DUCKIE", "1337", "2fast" }; + for (final String str : notExpectedToAccept) { + assertFalse("Filename, " + str + ", not matching regex not expected to accept", testFilter.accept(testFile, str)); + } + } + + @Test + public void testFileLastModifiedComparator() { + final FileLastModifiedComparator testComparator = new FileLastModifiedComparator(); + final File oldFile = mock(File.class); + final File newFile = mock(File.class); + final File equallyNewFile = mock(File.class); + when(oldFile.lastModified()).thenReturn(10L); + when(newFile.lastModified()).thenReturn(100L); + when(equallyNewFile.lastModified()).thenReturn(100L); + + assertTrue("Old file is less than new file", testComparator.compare(oldFile, newFile) < 0); + assertTrue("New file is greater than old file", testComparator.compare(newFile, oldFile) > 0); + assertTrue("New files are equal", testComparator.compare(newFile, equallyNewFile) == 0); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestIntentUtils.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestIntentUtils.java new file mode 100644 index 000000000..186821451 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestIntentUtils.java @@ -0,0 +1,73 @@ +/* + * 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 org.mozilla.gecko.util; + +import android.content.Intent; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.mozilla.gecko.mozglue.SafeIntent; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +/** + * Tests for the Intent utilities. + */ +@RunWith(TestRunner.class) +public class TestIntentUtils { + + private static final Map TEST_ENV_VAR_MAP; + static { + final HashMap tempMap = new HashMap<>(); + tempMap.put("ZERO", "0"); + tempMap.put("ONE", "1"); + tempMap.put("STRING", "TEXT"); + tempMap.put("L_WHITESPACE", " LEFT"); + tempMap.put("R_WHITESPACE", "RIGHT "); + tempMap.put("ALL_WHITESPACE", " ALL "); + tempMap.put("WHITESPACE_IN_VALUE", "IN THE MIDDLE"); + tempMap.put("WHITESPACE IN KEY", "IS_PROBABLY_NOT_VALID_ANYWAY"); + tempMap.put("BLANK_VAL", ""); + TEST_ENV_VAR_MAP = Collections.unmodifiableMap(tempMap); + } + + private Intent testIntent; + + @Before + public void setUp() throws Exception { + testIntent = getIntentWithTestData(); + } + + private static Intent getIntentWithTestData() { + final Intent out = new Intent(Intent.ACTION_VIEW); + int i = 0; + for (final String key : TEST_ENV_VAR_MAP.keySet()) { + final String value = key + "=" + TEST_ENV_VAR_MAP.get(key); + out.putExtra("env" + i, value); + i += 1; + } + return out; + } + + @Test + public void testGetEnvVarMap() throws Exception { + final HashMap actual = IntentUtils.getEnvVarMap(new SafeIntent(testIntent)); + for (final String actualEnvVarName : actual.keySet()) { + assertTrue("Actual key exists in test data: " + actualEnvVarName, + TEST_ENV_VAR_MAP.containsKey(actualEnvVarName)); + + final String expectedValue = TEST_ENV_VAR_MAP.get(actualEnvVarName); + final String actualValue = actual.get(actualEnvVarName); + assertEquals("Actual env var value matches test data", expectedValue, actualValue); + } + } +} \ No newline at end of file diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestStringUtils.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestStringUtils.java new file mode 100644 index 000000000..ee0a705c7 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestStringUtils.java @@ -0,0 +1,122 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * 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 org.mozilla.gecko.util; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import java.util.Arrays; +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith(TestRunner.class) +public class TestStringUtils { + @Test + public void testIsHttpOrHttps() { + // No value + assertFalse(StringUtils.isHttpOrHttps(null)); + assertFalse(StringUtils.isHttpOrHttps("")); + + // Garbage + assertFalse(StringUtils.isHttpOrHttps("lksdjflasuf")); + + // URLs with http/https + assertTrue(StringUtils.isHttpOrHttps("https://www.google.com")); + assertTrue(StringUtils.isHttpOrHttps("http://www.facebook.com")); + assertTrue(StringUtils.isHttpOrHttps("https://mozilla.org/en-US/firefox/products/")); + + // IP addresses + assertTrue(StringUtils.isHttpOrHttps("https://192.168.0.1")); + assertTrue(StringUtils.isHttpOrHttps("http://63.245.215.20/en-US/firefox/products")); + + // Other protocols + assertFalse(StringUtils.isHttpOrHttps("ftp://people.mozilla.org")); + assertFalse(StringUtils.isHttpOrHttps("javascript:window.google.com")); + assertFalse(StringUtils.isHttpOrHttps("tel://1234567890")); + + // No scheme + assertFalse(StringUtils.isHttpOrHttps("google.com")); + assertFalse(StringUtils.isHttpOrHttps("git@github.com:mozilla/gecko-dev.git")); + } + + @Test + public void testStripRef() { + assertEquals(StringUtils.stripRef(null), null); + assertEquals(StringUtils.stripRef(""), ""); + + assertEquals(StringUtils.stripRef("??AAABBBCCC"), "??AAABBBCCC"); + assertEquals(StringUtils.stripRef("https://mozilla.org"), "https://mozilla.org"); + assertEquals(StringUtils.stripRef("https://mozilla.org#BBBB"), "https://mozilla.org"); + assertEquals(StringUtils.stripRef("https://mozilla.org/#BBBB"), "https://mozilla.org/"); + } + + @Test + public void testStripScheme() { + assertEquals("mozilla.org", StringUtils.stripScheme("http://mozilla.org")); + assertEquals("mozilla.org", StringUtils.stripScheme("http://mozilla.org/")); + assertEquals("https://mozilla.org", StringUtils.stripScheme("https://mozilla.org")); + assertEquals("https://mozilla.org", StringUtils.stripScheme("https://mozilla.org/")); + assertEquals("mozilla.org", StringUtils.stripScheme("https://mozilla.org/", StringUtils.UrlFlags.STRIP_HTTPS)); + assertEquals("mozilla.org", StringUtils.stripScheme("https://mozilla.org", StringUtils.UrlFlags.STRIP_HTTPS)); + assertEquals("", StringUtils.stripScheme("http://")); + assertEquals("", StringUtils.stripScheme("https://", StringUtils.UrlFlags.STRIP_HTTPS)); + // This edge case is not handled properly yet +// assertEquals(StringUtils.stripScheme("https://"), ""); + assertEquals(null, StringUtils.stripScheme(null)); + } + + @Test + public void testIsRTL() { + assertFalse(StringUtils.isRTL("mozilla.org")); + assertFalse(StringUtils.isRTL("something.عربي")); + + assertTrue(StringUtils.isRTL("عربي")); + assertTrue(StringUtils.isRTL("عربي.org")); + + // Text with LTR mark + assertFalse(StringUtils.isRTL("\u200EHello")); + assertFalse(StringUtils.isRTL("\u200Eعربي")); + } + + @Test + public void testForceLTR() { + assertFalse(StringUtils.isRTL(StringUtils.forceLTR("عربي"))); + assertFalse(StringUtils.isRTL(StringUtils.forceLTR("عربي.org"))); + + // Strings that are already LTR are not modified + final String someLtrString = "HelloWorld"; + assertEquals(someLtrString, StringUtils.forceLTR(someLtrString)); + + // We add the LTR mark only once + final String someRtlString = "عربي"; + assertEquals(4, someRtlString.length()); + final String forcedLtrString = StringUtils.forceLTR(someRtlString); + assertEquals(5, forcedLtrString.length()); + final String forcedAgainLtrString = StringUtils.forceLTR(forcedLtrString); + assertEquals(5, forcedAgainLtrString.length()); + } + + @Test + public void testJoin() { + assertEquals("", StringUtils.join("", Collections.emptyList())); + assertEquals("", StringUtils.join("-", Collections.emptyList())); + assertEquals("", StringUtils.join("", Collections.singletonList(""))); + assertEquals("", StringUtils.join(".", Collections.singletonList(""))); + + assertEquals("192.168.0.1", StringUtils.join(".", Arrays.asList("192", "168", "0", "1"))); + assertEquals("www.mozilla.org", StringUtils.join(".", Arrays.asList("www", "mozilla", "org"))); + + assertEquals("hello", StringUtils.join("", Collections.singletonList("hello"))); + assertEquals("helloworld", StringUtils.join("", Arrays.asList("hello", "world"))); + assertEquals("hello world", StringUtils.join(" ", Arrays.asList("hello", "world"))); + + assertEquals("m::o::z::i::l::l::a", StringUtils.join("::", Arrays.asList("m", "o", "z", "i", "l", "l", "a"))); + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestUUIDUtil.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestUUIDUtil.java new file mode 100644 index 000000000..732dd21b9 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/TestUUIDUtil.java @@ -0,0 +1,51 @@ +/* + * 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 org.mozilla.gecko.util; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; + +import static org.junit.Assert.*; + +/** + * Tests for uuid utils. + */ +@RunWith(TestRunner.class) +public class TestUUIDUtil { + private static final String[] validUUIDs = { + "904cd9f8-af63-4525-8ce0-b9127e5364fa", + "8d584bd2-00ea-4043-a617-ed4ce7018ed0", + "3abad327-2669-4f68-b9ef-7ace8c5314d6", + }; + + private static final String[] invalidUUIDs = { + "its-not-a-uuid-mate", + "904cd9f8-af63-4525-8ce0-b9127e5364falol", + "904cd9f8-af63-4525-8ce0-b9127e5364f", + }; + + @Test + public void testUUIDRegex() { + for (final String uuid : validUUIDs) { + assertTrue("Valid UUID matches UUID-regex", uuid.matches(UUIDUtil.UUID_REGEX)); + } + for (final String uuid : invalidUUIDs) { + assertFalse("Invalid UUID does not match UUID-regex", uuid.matches(UUIDUtil.UUID_REGEX)); + } + } + + @Test + public void testUUIDPattern() { + for (final String uuid : validUUIDs) { + assertTrue("Valid UUID matches UUID-regex", UUIDUtil.UUID_PATTERN.matcher(uuid).matches()); + } + for (final String uuid : invalidUUIDs) { + assertFalse("Invalid UUID does not match UUID-regex", UUIDUtil.UUID_PATTERN.matcher(uuid).matches()); + } + } +} diff --git a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/publicsuffix/TestPublicSuffix.java b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/publicsuffix/TestPublicSuffix.java new file mode 100644 index 000000000..e47d361c0 --- /dev/null +++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/util/publicsuffix/TestPublicSuffix.java @@ -0,0 +1,62 @@ +package org.mozilla.gecko.util.publicsuffix; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mozilla.gecko.background.testhelpers.TestRunner; +import org.robolectric.RuntimeEnvironment; + +@RunWith(TestRunner.class) +public class TestPublicSuffix { + @Test + public void testStripPublicSuffix() { + // Test empty value + Assert.assertEquals("", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "")); + + // Test domains with public suffix + Assert.assertEquals("www.mozilla", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "www.mozilla.org")); + Assert.assertEquals("www.google", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "www.google.com")); + Assert.assertEquals("foobar", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "foobar.blogspot.com")); + Assert.assertEquals("independent", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "independent.co.uk")); + Assert.assertEquals("biz", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "biz.com.ua")); + Assert.assertEquals("example", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "example.org")); + Assert.assertEquals("example", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "example.pvt.k12.ma.us")); + + // Test domain without public suffix + Assert.assertEquals("localhost", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "localhost")); + Assert.assertEquals("firefox.mozilla", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "firefox.mozilla")); + + // IDN domains + Assert.assertEquals("ουτοπία.δπθ", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "ουτοπία.δπθ.gr")); + Assert.assertEquals("a网络A", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "a网络A.网络.Cn")); + + // Other non-domain values + Assert.assertEquals("192.168.0.1", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "192.168.0.1")); + Assert.assertEquals("asdflkj9uahsd", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "asdflkj9uahsd")); + + // Other trailing and other types of dots + Assert.assertEquals("www.mozilla。home.example", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "www.mozilla。home.example。org")); + Assert.assertEquals("example", + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, "example.org")); + } + + @Test(expected = NullPointerException.class) + public void testStripPublicSuffixThrowsException() { + PublicSuffix.stripPublicSuffix(RuntimeEnvironment.application, null); + } +} diff --git a/mobile/android/tests/background/moz.build b/mobile/android/tests/background/moz.build new file mode 100644 index 000000000..891477f32 --- /dev/null +++ b/mobile/android/tests/background/moz.build @@ -0,0 +1,9 @@ +# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*- +# vim: set filetype=python: +# 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/. + +TEST_DIRS += [ + 'junit3', +] -- cgit v1.2.3