コード例 #1
0
ファイル: NavigateTest.java プロジェクト: xar369/chromium
  /**
   * Types the passed text in the omnibox to trigger a navigation. You can pass a URL or a search
   * term. This code triggers suggestions and prerendering; unless you are testing these features
   * specifically, you should use loadUrl() which is less prone to flakyness.
   *
   * @param url The URL to navigate to.
   * @return the URL in the omnibox.
   * @throws InterruptedException
   */
  private String typeInOmniboxAndNavigate(final String url) throws InterruptedException {
    final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar);
    assertNotNull("urlBar is null", urlBar);
    ThreadUtils.runOnUiThreadBlocking(
        new Runnable() {
          @Override
          public void run() {
            urlBar.requestFocus();
            urlBar.setText(url);
          }
        });
    final LocationBarLayout locationBar =
        (LocationBarLayout) getActivity().findViewById(R.id.location_bar);
    OmniboxTestUtils.waitForOmniboxSuggestions(locationBar);

    Tab currentTab = getActivity().getActivityTab();
    final CallbackHelper loadedCallback = new CallbackHelper();
    final AtomicBoolean tabCrashReceived = new AtomicBoolean();
    currentTab.addObserver(
        new EmptyTabObserver() {
          @Override
          public void onPageLoadFinished(Tab tab) {
            loadedCallback.notifyCalled();
            tab.removeObserver(this);
          }

          @Override
          public void onCrash(Tab tab, boolean sadTabShown) {
            tabCrashReceived.set(true);
            tab.removeObserver(this);
          }
        });

    // Loads the url.
    KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEvent.KEYCODE_ENTER);

    boolean pageLoadReceived = true;
    try {
      loadedCallback.waitForCallback(0);
    } catch (TimeoutException ex) {
      pageLoadReceived = false;
    }

    assertTrue(
        "Neither PAGE_LOAD_FINISHED nor a TAB_CRASHED event was received",
        pageLoadReceived || tabCrashReceived.get());
    getInstrumentation().waitForIdleSync();

    // The URL has been set before the page notification was broadcast, so it is safe to access.
    return urlBar.getText().toString();
  }
コード例 #2
0
  @Override
  public void updateVisualsForState() {
    Resources resources = getResources();
    updateSecurityIcon(getSecurityLevel());
    ColorStateList colorStateList =
        resources.getColorStateList(
            mUseDarkColors ? R.color.dark_mode_tint : R.color.light_mode_tint);
    mMenuButton.setTint(colorStateList);
    if (mCloseButton.getDrawable() instanceof TintedDrawable) {
      ((TintedDrawable) mCloseButton.getDrawable()).setTint(colorStateList);
    }
    if (mCustomActionButton.getDrawable() instanceof TintedDrawable) {
      ((TintedDrawable) mCustomActionButton.getDrawable()).setTint(colorStateList);
    }
    mUrlBar.setUseDarkTextColors(mUseDarkColors);

    int titleTextColor =
        mUseDarkColors
            ? resources.getColor(R.color.url_emphasis_default_text)
            : resources.getColor(R.color.url_emphasis_light_default_text);
    mTitleBar.setTextColor(titleTextColor);

    if (getProgressBar() != null) {
      int progressBarResource =
          !mUseDarkColors ? R.drawable.progress_bar_white : R.drawable.progress_bar;
      getProgressBar()
          .setProgressDrawable(
              ApiCompatibilityUtils.getDrawable(getResources(), progressBarResource));
    }
  }
コード例 #3
0
  @Override
  public void updateSecurityIcon(int securityLevel) {
    if (mSecurityIconType == securityLevel) return;
    mSecurityIconType = securityLevel;

    if (securityLevel == ConnectionSecurityLevel.NONE) {
      mAnimDelegate.hideSecurityButton();
    } else {
      // ImageView#setImageResource is no-op if given resource is the current one.
      mSecurityButton.setImageResource(
          LocationBarLayout.getSecurityIconResource(securityLevel, !shouldEmphasizeHttpsScheme()));
      mAnimDelegate.showSecurityButton();
    }
    mUrlBar.emphasizeUrl();
    mUrlBar.invalidate();
  }
コード例 #4
0
 @Override
 public void setShowTitle(boolean showTitle) {
   int titleVisibility = showTitle ? VISIBLE : GONE;
   int urlTextSizeId =
       showTitle ? R.dimen.custom_tabs_url_text_size : R.dimen.location_bar_url_text_size;
   mTitleBar.setVisibility(titleVisibility);
   mUrlBar.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(urlTextSizeId));
 }
コード例 #5
0
 @Override
 protected void onFinishInflate() {
   super.onFinishInflate();
   setBackground(new ColorDrawable(getResources().getColor(R.color.default_primary_color)));
   mUrlBar = (UrlBar) findViewById(R.id.url_bar);
   mUrlBar.setHint("");
   mUrlBar.setDelegate(this);
   mUrlBar.setEnabled(false);
   mUrlBar.setAllowFocus(false);
   mTitleBar = (TextView) findViewById(R.id.title_bar);
   mLocationBarFrameLayout = findViewById(R.id.location_bar_frame_layout);
   mTitleUrlContainer = findViewById(R.id.title_url_container);
   mSecurityButton = (ImageButton) findViewById(R.id.security_button);
   mSecurityIconType = ConnectionSecurityLevel.NONE;
   mCustomActionButton = (ImageButton) findViewById(R.id.action_button);
   mCloseButton = (ImageButton) findViewById(R.id.close_button);
   mCloseButton.setOnLongClickListener(this);
   mCustomActionButton.setOnLongClickListener(this);
   populateToolbarAnimations();
 }
コード例 #6
0
  @Override
  public void updateSecurityIcon(int securityLevel) {
    // ImageView#setImageResource is no-op if given resource is the current one.
    mSecurityButton.setImageResource(
        LocationBarLayout.getSecurityIconResource(securityLevel, !shouldEmphasizeHttpsScheme()));

    if (mSecurityIconType == securityLevel) return;
    mSecurityIconType = securityLevel;

    if (securityLevel == ConnectionSecurityLevel.NONE) {
      // TODO(yusufo): Add an animator for hiding as well.
      mSecurityButton.setVisibility(GONE);
    } else if (mSecurityButton.getVisibility() != View.VISIBLE) {
      if (mSecurityButtonShowAnimator.isRunning()) mSecurityButtonShowAnimator.cancel();
      mSecurityButtonShowAnimator.start();
      mUrlBar.deEmphasizeUrl();
    }
    mUrlBar.emphasizeUrl();
    mUrlBar.invalidate();
  }
コード例 #7
0
  @Override
  public void setUrlToPageUrl() {
    if (getCurrentTab() == null) {
      mUrlBar.setUrl("", null);
      return;
    }

    String url = getCurrentTab().getUrl().trim();

    if (NativePageFactory.isNativePageUrl(url, getCurrentTab().isIncognito())) {
      // Don't show anything for Chrome URLs.
      mUrlBar.setUrl("", null);
      return;
    }
    String displayText = getToolbarDataProvider().getText();
    Pair<String, String> urlText = LocationBarLayout.splitPathFromUrlDisplayText(displayText);
    displayText = urlText.first;

    if (DomDistillerUrlUtils.isDistilledPage(url)) {
      if (isStoredArticle(url)) {
        Profile profile = getCurrentTab().getProfile();
        DomDistillerService domDistillerService = DomDistillerServiceFactory.getForProfile(profile);
        String originalUrl =
            domDistillerService.getUrlForEntry(
                DomDistillerUrlUtils.getValueForKeyInUrl(url, "entry_id"));
        displayText = DomDistillerTabUtils.getFormattedUrlFromOriginalDistillerUrl(originalUrl);
      } else if (DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url) != null) {
        String originalUrl = DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(url);
        displayText = DomDistillerTabUtils.getFormattedUrlFromOriginalDistillerUrl(originalUrl);
      }
    }

    if (mUrlBar.setUrl(url, displayText)) {
      mUrlBar.deEmphasizeUrl();
      mUrlBar.emphasizeUrl();
    }
  }
コード例 #8
0
 @Override
 public void setDefaultTextEditActionModeCallback(CustomSelectionActionModeCallback callback) {
   mUrlBar.setCustomSelectionActionModeCallback(callback);
 }