mobile/android/base/tests/testOrderedBroadcast.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 package org.mozilla.gecko.tests;
michael@0 2
michael@0 3 import org.json.JSONException;
michael@0 4 import org.json.JSONObject;
michael@0 5
michael@0 6 import android.app.Activity;
michael@0 7 import android.content.BroadcastReceiver;
michael@0 8 import android.content.Context;
michael@0 9 import android.content.Intent;
michael@0 10 import android.content.IntentFilter;
michael@0 11
michael@0 12
michael@0 13 public class testOrderedBroadcast extends JavascriptTest {
michael@0 14 protected BroadcastReceiver mReceiver;
michael@0 15
michael@0 16 public testOrderedBroadcast() {
michael@0 17 super("testOrderedBroadcast.js");
michael@0 18 }
michael@0 19
michael@0 20 @Override
michael@0 21 public void setUp() throws Exception {
michael@0 22 super.setUp();
michael@0 23
michael@0 24 mAsserter.dumpLog("Registering org.mozilla.gecko.test.receiver broadcast receiver");
michael@0 25
michael@0 26 IntentFilter filter = new IntentFilter();
michael@0 27 filter.addAction("org.mozilla.gecko.test.receiver");
michael@0 28
michael@0 29 mReceiver = new BroadcastReceiver() {
michael@0 30 @Override
michael@0 31 public void onReceive(Context context, Intent intent) {
michael@0 32 try {
michael@0 33 JSONObject o = new JSONObject();
michael@0 34 o.put("c", "efg");
michael@0 35 o.put("d", 456);
michael@0 36 // Feed the received token back to the sender.
michael@0 37 o.put("token", intent.getStringExtra("token"));
michael@0 38 String data = o.toString();
michael@0 39
michael@0 40 setResultCode(Activity.RESULT_OK);
michael@0 41 setResultData(data);
michael@0 42 } catch (JSONException e) {
michael@0 43 setResultCode(Activity.RESULT_CANCELED);
michael@0 44 setResultData(null);
michael@0 45 }
michael@0 46 }
michael@0 47 };
michael@0 48
michael@0 49 // We must register the receiver in a Fennec context to avoid a
michael@0 50 // SecurityException.
michael@0 51 getActivity().getApplicationContext().registerReceiver(mReceiver, filter);
michael@0 52 }
michael@0 53
michael@0 54 @Override
michael@0 55 public void tearDown() throws Exception {
michael@0 56 super.tearDown();
michael@0 57
michael@0 58 mAsserter.dumpLog("Unregistering org.mozilla.gecko.test.receiver broadcast receiver");
michael@0 59
michael@0 60 if (mReceiver != null) {
michael@0 61 getActivity().getApplicationContext().unregisterReceiver(mReceiver);
michael@0 62 mReceiver = null;
michael@0 63 }
michael@0 64 }
michael@0 65 }

mercurial