Beispiel #1
0
  protected void doTestJavascript() throws Exception {
    // We want to be waiting for Robocop messages before the page is loaded
    // because the test harness runs each test in the suite (and possibly
    // completes testing) before the page load event is fired.
    final Actions.EventExpecter expecter =
        mActions.expectGlobalEvent(Actions.EventType.GECKO, EVENT_TYPE);
    mAsserter.dumpLog("Registered listener for " + EVENT_TYPE);

    final String url = getAbsoluteUrl(mStringHelper.getHarnessUrlForJavascript(javascriptUrl));
    mAsserter.dumpLog("Loading JavaScript test from " + url);
    loadUrl(url);

    final JavascriptMessageParser testMessageParser = new JavascriptMessageParser(mAsserter, false);
    try {
      while (!testMessageParser.isTestFinished()) {
        if (logVerbose) {
          Log.v(LOGTAG, "Waiting for " + EVENT_TYPE);
        }
        final GeckoBundle o = expecter.blockForBundle();
        if (logVerbose) {
          Log.v(LOGTAG, "Got event with data '" + o + "'");
        }

        String innerType = o.getString("innerType");
        if (!"progress".equals(innerType)) {
          throw new Exception("Unexpected event innerType " + innerType);
        }

        String message = o.getString("message");
        if (message == null) {
          throw new Exception("Progress message must not be null");
        }
        testMessageParser.logMessage(message);
      }

      if (logDebug) {
        Log.d(LOGTAG, "Got test finished message");
      }
    } finally {
      expecter.unregisterListener();
      mAsserter.dumpLog("Unregistered listener for " + EVENT_TYPE);
    }
  }
  /**
   * Configure this Preference object from the Gecko search engine object.
   *
   * @param geckoEngine The Gecko-formatted object representing the search engine.
   */
  public void setSearchEngineFromBundle(GeckoBundle geckoEngine) {
    mIdentifier = geckoEngine.getString("identifier");

    // A null JS value gets converted into a string.
    if (mIdentifier == null || mIdentifier.equals("null")) {
      mIdentifier = "other";
    }

    final String engineName = geckoEngine.getString("name");
    final SpannableString titleSpannable = new SpannableString(engineName);

    setTitle(titleSpannable);

    final String iconURI = geckoEngine.getString("iconURI");
    // Keep a reference to the bitmap - we'll need it later in onBindView.
    try {
      Icons.with(getContext())
          .pageUrl(mIdentifier)
          .icon(IconDescriptor.createGenericIcon(iconURI))
          .privileged(true)
          .build()
          .execute(
              new IconCallback() {
                @Override
                public void onIconResponse(IconResponse response) {
                  mIconBitmap = response.getBitmap();

                  if (mFaviconView != null) {
                    mFaviconView.updateAndScaleImage(response);
                  }
                }
              });
    } catch (IllegalArgumentException e) {
      Log.e(
          LOGTAG, "IllegalArgumentException creating Bitmap. Most likely a zero-length bitmap.", e);
    } catch (NullPointerException e) {
      Log.e(LOGTAG, "NullPointerException creating Bitmap. Most likely a zero-length bitmap.", e);
    }
  }