Example #1
0
  /** Ensure WebappActivities can't be launched without proper security checks. */
  @MediumTest
  @Feature({"Webapps"})
  public void testWebappRequiresValidMac() throws Exception {
    // Try to start a WebappActivity.  Fail because the Intent is insecure.
    fireWebappIntent(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON, false);
    CriteriaHelper.pollUiThread(
        new Criteria() {
          @Override
          public boolean isSatisfied() {
            Activity lastActivity = ApplicationStatus.getLastTrackedFocusedActivity();
            return lastActivity instanceof ChromeTabbedActivity;
          }
        });
    ChromeActivity chromeActivity =
        (ChromeActivity) ApplicationStatus.getLastTrackedFocusedActivity();
    waitForFullLoad(chromeActivity, WEBAPP_1_TITLE);

    // Firing a correct Intent should start a WebappActivity instance instead of the browser.
    fireWebappIntent(WEBAPP_2_ID, WEBAPP_2_URL, WEBAPP_2_TITLE, WEBAPP_ICON, true);
    CriteriaHelper.pollUiThread(
        new Criteria() {
          @Override
          public boolean isSatisfied() {
            return isWebappActivityReady(ApplicationStatus.getLastTrackedFocusedActivity());
          }
        });
  }
Example #2
0
  /** Tests that WebappActivities are started properly. */
  @MediumTest
  public void testWebappLaunches() throws Exception {
    final Activity firstActivity =
        startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON);
    assertTrue(isNumberOfRunningActivitiesCorrect(1));

    // Firing a different Intent should start a new WebappActivity instance.
    fireWebappIntent(WEBAPP_2_ID, WEBAPP_2_URL, WEBAPP_2_TITLE, WEBAPP_ICON, true);
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                Activity lastActivity = ApplicationStatus.getLastTrackedFocusedActivity();
                return isWebappActivityReady(lastActivity) && lastActivity != firstActivity;
              }
            }));
    assertTrue(isNumberOfRunningActivitiesCorrect(2));

    // Firing the first Intent should bring back the first WebappActivity instance.
    fireWebappIntent(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON, true);
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                Activity lastActivity = ApplicationStatus.getLastTrackedFocusedActivity();
                return isWebappActivityReady(lastActivity) && lastActivity == firstActivity;
              }
            }));
    assertTrue(isNumberOfRunningActivitiesCorrect(2));
  }
Example #3
0
  private void waitForNewTabToStabilize(final int numTabsAfterNewTab) throws InterruptedException {
    // Wait until we have a new tab first. This should be called before checking the active
    // layout because the active layout changes StaticLayout --> SimpleAnimationLayout
    // --> (tab added) --> StaticLayout.
    assertTrue(
        "Actual tab count: " + getActivity().getCurrentTabModel().getCount(),
        CriteriaHelper.pollForUIThreadCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                return getActivity().getCurrentTabModel().getCount() >= numTabsAfterNewTab;
              }
            }));

    // Now wait until the new tab animation finishes. Something wonky happens
    // if we try to go to the new tab before this.
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                CompositorViewHolder compositorViewHolder =
                    (CompositorViewHolder) getActivity().findViewById(R.id.compositor_view_holder);
                LayoutManager layoutManager = compositorViewHolder.getLayoutManager();

                return layoutManager.getActiveLayout() instanceof StaticLayout;
              }
            }));
  }
Example #4
0
  /** Ensure WebappActivities can't be launched without proper security checks. */
  @MediumTest
  public void testWebappRequiresValidMac() throws Exception {
    // Try to start a WebappActivity.  Fail because the Intent is insecure.
    fireWebappIntent(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON, false);
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                Activity lastActivity = ApplicationStatus.getLastTrackedFocusedActivity();
                if (!lastActivity.findViewById(android.R.id.content).hasWindowFocus()) return false;
                return lastActivity instanceof ChromeTabbedActivity
                    || lastActivity instanceof DocumentActivity;
              }
            }));
    final Activity firstActivity = ApplicationStatus.getLastTrackedFocusedActivity();

    // Firing a correct Intent should start a new WebappActivity instance.
    fireWebappIntent(WEBAPP_2_ID, WEBAPP_2_URL, WEBAPP_2_TITLE, WEBAPP_ICON, true);
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                Activity lastActivity = ApplicationStatus.getLastTrackedFocusedActivity();
                return isWebappActivityReady(lastActivity) && lastActivity != firstActivity;
              }
            }));
  }
Example #5
0
  private <T extends ChromeActivity> void triggerWindowOpenAndWaitForLoad(
      Class<T> classToWaitFor, String linkHtml, boolean checkContents) throws Exception {
    final WebappActivity webappActivity =
        startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON);
    assertTrue(isNumberOfRunningActivitiesCorrect(1));

    // Load up the test page.
    assertTrue(
        CriteriaHelper.pollForCriteria(
            new TabLoadObserver(webappActivity.getActivityTab(), linkHtml)));

    // Do a plain click to make the link open in the main browser via a window.open().
    // If the window is opened successfully, javascript on the first page triggers and changes
    // its URL as a signal for this test.
    Runnable fgTrigger =
        new Runnable() {
          @Override
          public void run() {
            ThreadUtils.runOnUiThreadBlocking(
                new Runnable() {
                  @Override
                  public void run() {
                    View view = webappActivity.findViewById(android.R.id.content).getRootView();
                    TouchCommon.singleClickView(view);
                  }
                });
          }
        };
    ChromeActivity secondActivity =
        ActivityUtils.waitForActivity(getInstrumentation(), classToWaitFor, fgTrigger);
    waitForFullLoad(secondActivity, "Page 4");
    if (checkContents) {
      assertEquals(
          "New WebContents was not created", SUCCESS_URL, webappActivity.getActivityTab().getUrl());
    }
    assertNotSame(
        "Wrong Activity in foreground",
        webappActivity,
        ApplicationStatus.getLastTrackedFocusedActivity());

    // Close the child window to kick the user back to the WebappActivity.
    JavaScriptUtils.executeJavaScript(
        secondActivity.getActivityTab().getWebContents(), "window.close()");
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                return webappActivity == ApplicationStatus.getLastTrackedFocusedActivity();
              }
            }));
    ApplicationTestUtils.waitUntilChromeInForeground();
  }
Example #6
0
  /**
   * Tests that a WebappActivity can be brought forward by firing an Intent with
   * TabOpenType.BRING_TAB_TO_FRONT.
   */
  @MediumTest
  @Feature({"Webapps"})
  public void testBringTabToFront() throws Exception {
    // Start the WebappActivity.
    final WebappActivity firstActivity =
        startWebappActivity(WEBAPP_1_ID, WEBAPP_1_URL, WEBAPP_1_TITLE, WEBAPP_ICON);
    final int webappTabId = firstActivity.getActivityTab().getId();

    // Return home.
    final Context context = getInstrumentation().getTargetContext();
    ApplicationTestUtils.fireHomeScreenIntent(context);
    getInstrumentation().waitForIdleSync();

    // Bring the WebappActivity back via an Intent.
    Intent intent = Tab.createBringTabToFrontIntent(webappTabId);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intent);

    // When Chrome is back in the foreground, confirm that the correct Activity was restored.
    // Because of Android killing Activities willy-nilly, it may not be the same Activity, but
    // it should have the same Tab ID.
    getInstrumentation().waitForIdleSync();
    ApplicationTestUtils.waitUntilChromeInForeground();
    CriteriaHelper.pollInstrumentationThread(
        new Criteria() {
          @Override
          public boolean isSatisfied() {
            Activity lastActivity = ApplicationStatus.getLastTrackedFocusedActivity();
            if (!isWebappActivityReady(lastActivity)) return false;

            WebappActivity webappActivity = (WebappActivity) lastActivity;
            return webappActivity.getActivityTab().getId() == webappTabId;
          }
        });
  }
  @SmallTest
  @Feature({"Webapps"})
  @TargetApi(Build.VERSION_CODES.LOLLIPOP)
  public void testThemeColorNotUsedIfPagesHasOne() throws InterruptedException {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;

    ThreadUtils.runOnUiThread(
        new Runnable() {
          @Override
          public void run() {
            TabTestUtils.simulateChangeThemeColor(getActivity().getActivityTab(), Color.GREEN);
          }
        });

    // Waits for theme-color to change so the test doesn't rely on system timing.
    assertTrue(
        CriteriaHelper.pollForCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                return getActivity().getWindow().getStatusBarColor()
                    == ColorUtils.getDarkenedColorForStatusBar(Color.GREEN);
              }
            }));
  }
  @Override
  public void setUp() throws Exception {
    super.setUp();

    mObserver = new MockOrientationObserver();
    OrientationChangeObserverCriteria criteria = new OrientationChangeObserverCriteria(mObserver);

    final ContentShellActivity activity = launchContentShellWithUrl(DEFAULT_URL);
    waitForActiveShellToBeDoneLoading();

    ThreadUtils.runOnUiThreadBlocking(
        new Runnable() {
          @Override
          public void run() {
            ScreenOrientationListener.getInstance().addObserver(mObserver, activity);
            ScreenOrientationProvider.startAccurateListening();
          }
        });

    // Make sure we start all the tests with the same orientation.
    lockOrientationAndWait(ScreenOrientationValues.PORTRAIT_PRIMARY);

    // Make sure mObserver is updated before we start the tests.
    CriteriaHelper.pollForCriteria(criteria);
  }
 @SmallTest
 @Feature({"TextSelection", "TextInput"})
 public void testCursorPositionAfterHidingActionMode() throws Exception {
   DOMUtils.longPressNode(this, mContentViewCore, "textarea");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertNotNull(mContentViewCore.getSelectActionHandler());
   selectActionBarSelectAll();
   assertTrue(mContentViewCore.hasSelection());
   assertWaitForSelectActionBarVisible(true);
   assertEquals(mContentViewCore.getSelectedText(), "SampleTextArea");
   hideSelectActionMode();
   assertWaitForSelectActionBarVisible(false);
   assertTrue(
       CriteriaHelper.pollForUIThreadCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return "SampleTextArea"
                   .equals(
                       mContentViewCore
                           .getImeAdapterForTest()
                           .getInputConnectionForTest()
                           .getTextBeforeCursor(50, 0));
             }
           }));
 }
  /** Verify Geolocation creates an InfoBar and that it's destroyed when navigating back. */
  @MediumTest
  @Feature({"Browser"})
  public void testInfoBarForGeolocationDisappearsOnBack() throws InterruptedException {
    LocationSettingsTestUtil.setSystemLocationSettingEnabled(true);
    loadUrl(HELLO_WORLD_URL);
    loadUrl(mTestServer.getURL(GEOLOCATION_PAGE));
    assertTrue("InfoBar not added.", mListener.addInfoBarAnimationFinished());

    assertEquals("Wrong infobar count", 1, getInfoBars().size());

    // Navigate back and ensure the InfoBar has been removed.
    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                getActivity().getActivityTab().goBack();
              }
            });
    CriteriaHelper.pollForCriteria(
        new Criteria() {
          @Override
          public boolean isSatisfied() {
            return getInfoBars().isEmpty();
          }
        },
        MAX_TIMEOUT,
        CHECK_INTERVAL);
    assertTrue("InfoBar not removed.", mListener.removeInfoBarAnimationFinished());
  }
 private void ensureGeolocationRunning(final boolean running) throws Exception {
   CriteriaHelper.pollForCriteria(
       new Criteria() {
         @Override
         public boolean isSatisfied() {
           return mMockLocationProvider.isRunning() == running;
         }
       });
 }
 private boolean waitUntilNoInfoBarsExist() throws Exception {
   return CriteriaHelper.pollForUIThreadCriteria(
       new Criteria() {
         @Override
         public boolean isSatisfied() {
           InfoBarContainer container = getActivity().getActivityTab().getInfoBarContainer();
           return container.getInfoBars().size() == 0;
         }
       });
 }
 private void assertWaitForSelectionEditableEquals(final boolean expected) throws Throwable {
   assertTrue(
       CriteriaHelper.pollForCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return getContentViewCore().isSelectionEditable() == expected;
             }
           }));
 }
Example #14
0
 private void assertWaitForSelectActionBarStatus(final boolean show) throws InterruptedException {
   assertTrue(
       CriteriaHelper.pollForCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return show == mContentViewCore.isSelectActionBarShowing();
             }
           }));
 }
 private void assertWaitForPastePopupStatus(final boolean show) throws InterruptedException {
   assertTrue(
       CriteriaHelper.pollForUIThreadCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return show == mContentViewCore.isPastePopupShowing();
             }
           }));
 }
 private void waitForInterstitial(final boolean shouldBeShown) throws InterruptedException {
   CriteriaHelper.pollUiThread(
       Criteria.equals(
           shouldBeShown,
           new Callable<Boolean>() {
             @Override
             public Boolean call() {
               return getWebContents().isShowingInterstitialPage();
             }
           }));
 }
 /**
  * Waits for the UrlBar to have the expected focus state.
  *
  * @param urlBar The UrlBar whose focus is being inspected.
  * @param active Whether the UrlBar is expected to have focus or not.
  */
 public static void waitForFocusAndKeyboardActive(final UrlBar urlBar, final boolean active)
     throws InterruptedException {
   CriteriaHelper.pollForCriteria(
       new Criteria() {
         @Override
         public boolean isSatisfied() {
           return (doesUrlBarHaveFocus(urlBar) == active)
               && (isKeyboardActiveForView(urlBar) == active);
         }
       });
 }
 private void waitForAutofillPopopShow(final AutofillPopup popup) throws InterruptedException {
   assertTrue(
       "Autofill Popup anchor view was never added.",
       CriteriaHelper.pollForCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return popup.isShowing();
             }
           }));
 }
Example #19
0
 private void assertWaitForKeyboardStatus(final boolean show) throws InterruptedException {
   assertTrue(
       CriteriaHelper.pollForCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return show == getImeAdapter().mIsShowWithoutHideOutstanding
                   && (!show || getAdapterInputConnection() != null);
             }
           }));
 }
 public void waitForFocusStateChange(int focusType) throws InterruptedException {
   CriteriaHelper.pollInstrumentationThread(
       Criteria.equals(
           focusType,
           new Callable<Integer>() {
             @Override
             public Integer call() {
               return getAudioFocusState();
             }
           }));
 }
 private void assertWaitForHandleNear(final HandleView handle, final int x, final int y)
     throws Throwable {
   assertTrue(
       CriteriaHelper.pollForCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return isHandleNear(handle, x, y);
             }
           }));
 }
 private void waitForAnchorViewAdd(final ContentView view) throws InterruptedException {
   assertTrue(
       "Autofill Popup anchor view was never added.",
       CriteriaHelper.pollForCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return view.findViewById(R.id.autofill_popup_window) != null;
             }
           }));
 }
 public boolean waitForCallback() throws InterruptedException {
   return CriteriaHelper.pollForCriteria(
       new Criteria() {
         @Override
         public boolean isSatisfied() {
           return mGotPopupSelection.get();
         }
       },
       CALLBACK_TIMEOUT_MS,
       CHECK_INTERVAL_MS);
 }
  @MediumTest
  @Feature({"AppBanners"})
  public void testBitmapFetchersCanOverlapWithoutCrashing() throws Exception {
    // Visit a site that requests a banner rapidly and repeatedly.
    for (int i = 1; i <= 10; i++) {
      assertTrue(
          CriteriaHelper.pollForUIThreadCriteria(
              new TabLoadObserver(getActivity().getActivityTab(), NATIVE_APP_URL)));

      final Integer iteration = Integer.valueOf(i);
      assertTrue(
          CriteriaHelper.pollForUIThreadCriteria(
              new Criteria() {
                @Override
                public boolean isSatisfied() {
                  return mDetailsDelegate.mNumRetrieved == iteration;
                }
              }));
    }
  }
 private void assertWaitForSelectActionBarVisible(final boolean visible)
     throws InterruptedException {
   assertTrue(
       CriteriaHelper.pollForUIThreadCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return visible == mContentViewCore.isSelectActionBarShowing();
             }
           }));
 }
  @MediumTest
  @Feature({"AppBanners"})
  public void testBannerAppearsThenDoesNotAppearAgainForMonths() throws Exception {
    // Visit a site that requests a banner.
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new TabLoadObserver(getActivity().getActivityTab(), NATIVE_APP_URL)));
    assertTrue(waitUntilAppDetailsRetrieved(1));
    assertTrue(waitUntilNoInfoBarsExist());

    // Indicate a day has passed, then revisit the page.
    AppBannerManager.setTimeDeltaForTesting(1);
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new TabLoadObserver(getActivity().getActivityTab(), NATIVE_APP_URL)));
    assertTrue(waitUntilAppDetailsRetrieved(2));
    assertTrue(waitUntilAppBannerInfoBarAppears(NATIVE_APP_TITLE));

    // Revisit the page to make the banner go away, but don't explicitly dismiss it.
    // This hides the banner for a few months.
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new TabLoadObserver(getActivity().getActivityTab(), NATIVE_APP_URL)));
    assertTrue(waitUntilAppDetailsRetrieved(3));
    assertTrue(waitUntilNoInfoBarsExist());

    // Wait a month until revisiting the page.
    AppBannerManager.setTimeDeltaForTesting(31);
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new TabLoadObserver(getActivity().getActivityTab(), NATIVE_APP_URL)));
    assertTrue(waitUntilAppDetailsRetrieved(4));
    assertTrue(waitUntilNoInfoBarsExist());

    AppBannerManager.setTimeDeltaForTesting(32);
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new TabLoadObserver(getActivity().getActivityTab(), NATIVE_APP_URL)));
    assertTrue(waitUntilAppDetailsRetrieved(5));
    assertTrue(waitUntilNoInfoBarsExist());

    // Wait two months until revisiting the page, which should pop up the banner.
    AppBannerManager.setTimeDeltaForTesting(61);
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new TabLoadObserver(getActivity().getActivityTab(), NATIVE_APP_URL)));
    assertTrue(waitUntilAppDetailsRetrieved(6));
    assertTrue(waitUntilNoInfoBarsExist());

    AppBannerManager.setTimeDeltaForTesting(62);
    assertTrue(
        CriteriaHelper.pollForUIThreadCriteria(
            new TabLoadObserver(getActivity().getActivityTab(), NATIVE_APP_URL)));
    assertTrue(waitUntilAppDetailsRetrieved(7));
    assertTrue(waitUntilAppBannerInfoBarAppears(NATIVE_APP_TITLE));
  }
 private boolean waitUntilAppDetailsRetrieved(final int numExpected) throws Exception {
   return CriteriaHelper.pollForUIThreadCriteria(
       new Criteria() {
         @Override
         public boolean isSatisfied() {
           AppBannerManager manager =
               getActivity().getActivityTab().getAppBannerManagerForTesting();
           return mDetailsDelegate.mNumRetrieved == numExpected
               && !manager.isFetcherActiveForTesting();
         }
       });
 }
 private void assertWaitForEitherHandleNear(final int x, final int y) throws Throwable {
   final HandleView startHandle = getStartHandle();
   final HandleView endHandle = getEndHandle();
   assertTrue(
       CriteriaHelper.pollForCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return isHandleNear(startHandle, x, y) || isHandleNear(endHandle, x, y);
             }
           }));
 }
Example #29
0
 /**
  * Wait until info bar size becomes the given size and the last info bar becomes ready if there is
  * one more more.
  *
  * @param size The size of info bars to poll for.
  */
 private void assertPollForInfoBarSize(final int size) throws InterruptedException {
   final InfoBarContainer container = getActivity().getActivityTab().getInfoBarContainer();
   assertTrue(
       "There should be " + size + " infobar but there are " + getInfoBars().size() + " infobars.",
       CriteriaHelper.pollForUIThreadCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return getInfoBars().size() == size && !container.isAnimating();
             }
           }));
 }
 private void waitForKeyboardShowRequest(final TestInputMethodManagerWrapper immw, final int count)
     throws InterruptedException {
   assertTrue(
       "Keyboard was never requested to be shown.",
       CriteriaHelper.pollForCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return immw.getShowSoftInputCounter() == count;
             }
           }));
 }