From 1c81633de4ada680ed83c31bbe0c23bc92177360 Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Tue, 22 Jul 2014 21:41:54 -0700 Subject: [PATCH] Bug 948465 - Part 2: Tests. r=mfinkle --- mobile/android/base/tests/robocop.ini | 1 + .../base/tests/testResourceSubstitutions.java | 9 ++++ .../base/tests/testResourceSubstitutions.js | 47 +++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 mobile/android/base/tests/testResourceSubstitutions.java create mode 100644 mobile/android/base/tests/testResourceSubstitutions.js diff --git a/mobile/android/base/tests/robocop.ini b/mobile/android/base/tests/robocop.ini index a0d6b8164f2d..0112f9b28130 100644 --- a/mobile/android/base/tests/robocop.ini +++ b/mobile/android/base/tests/robocop.ini @@ -105,6 +105,7 @@ skip-if = android_version == "10" [testJNI] # [testMozPay] # see bug 945675 [testOrderedBroadcast] +[testResourceSubstitutions] [testSharedPreferences] [testSimpleDiscovery] [testUITelemetry] diff --git a/mobile/android/base/tests/testResourceSubstitutions.java b/mobile/android/base/tests/testResourceSubstitutions.java new file mode 100644 index 000000000000..8da26a331476 --- /dev/null +++ b/mobile/android/base/tests/testResourceSubstitutions.java @@ -0,0 +1,9 @@ +package org.mozilla.gecko.tests; + + + +public class testResourceSubstitutions extends JavascriptTest { + public testResourceSubstitutions() { + super("testResourceSubstitutions.js"); + } +} diff --git a/mobile/android/base/tests/testResourceSubstitutions.js b/mobile/android/base/tests/testResourceSubstitutions.js new file mode 100644 index 000000000000..0a2b19603f53 --- /dev/null +++ b/mobile/android/base/tests/testResourceSubstitutions.js @@ -0,0 +1,47 @@ +// -*- indent-tabs-mode: nil; js-indent-level: 2 -*- +/* 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/. */ + +const { classes: Cc, interfaces: Ci, utils: Cu } = Components; + +Cu.import("resource://gre/modules/Promise.jsm"); /*global Promise */ +Cu.import("resource://gre/modules/Services.jsm"); /*global Services */ +Cu.import("resource://gre/modules/NetUtil.jsm"); /*global NetUtil */ + +function readChannel(url) { + let deferred = Promise.defer(); + + let channel = NetUtil.newChannel(url); + channel.contentType = "text/plain"; + + NetUtil.asyncFetch(channel, function(inputStream, status) { + if (!Components.isSuccessCode(status)) { + deferred.reject(); + return; + } + + let content = NetUtil.readInputStreamToString(inputStream, inputStream.available()); + deferred.resolve(content); + }); + + return deferred.promise; +} + +add_task(function test_Android() { + let protocolHandler = Services.io + .getProtocolHandler("resource") + .QueryInterface(Ci.nsIResProtocolHandler); + + do_check_true(protocolHandler.hasSubstitution("android")); + + // This can be any file that we know exists in the root of every APK. + let packageName = yield readChannel("resource://android/package-name.txt"); + + // It's difficult to fish ANDROID_PACKAGE_NAME from JavaScript, so we test the + // following weaker condition. + let expectedPrefix = "org.mozilla."; + do_check_eq(packageName.substring(0, expectedPrefix.length), expectedPrefix); +}); + +run_next_test();