コード例 #1
0
ファイル: NavigateTest.java プロジェクト: xar369/chromium
  /** Test Opening a link and verify that the desired page is loaded. */
  @MediumTest
  @Feature({"Navigation"})
  public void testOpenLink() throws InterruptedException, TimeoutException {
    String url1 = TestHttpServerClient.getUrl("chrome/test/data/android/google.html");
    String url2 = TestHttpServerClient.getUrl("chrome/test/data/android/about.html");

    navigateAndObserve(url1, url1);
    assertWaitForPageScaleFactorMatch(0.5f);

    Tab tab = getActivity().getActivityTab();

    DOMUtils.clickNode(this, tab.getContentViewCore(), "aboutLink");
    ChromeTabUtils.waitForTabPageLoaded(tab, url2);
    assertEquals("Desired Link not open", url2, getActivity().getActivityTab().getUrl());
  }
  /**
   * Ensures correctness of the visibilityDetermined() calls, that should be always preceded by
   * setInForeground().
   */
  @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
  @LargeTest
  @Feature({"ProcessManagement"})
  public void testVisibilityDetermined() throws Exception {
    // Create a tab in foreground and wait until it is loaded.
    final Tab fgTab =
        ChromeApplication.getDocumentTabModelSelector()
            .getTabById(launchViaViewIntent(false, URL_1, "Page 1"));
    int initialNavigationPid = fgTab.getContentViewCore().getCurrentRenderProcessId();
    // Ensure the following calls happened:
    //  - FG - setInForeground(true) - when the tab is created in the foreground
    //  - DETERMINED - visibilityDetermined() - after the initial navigation is committed
    assertEquals("FG;DETERMINED;", mBindingManager.getVisibilityCalls(initialNavigationPid));

    // Navigate to about:version which requires a different renderer.
    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                fgTab.loadUrl(new LoadUrlParams(ABOUT_VERSION_PATH));
              }
            });
    ChromeTabUtils.waitForTabPageLoaded(fgTab, ABOUT_VERSION_PATH);
    int secondNavigationPid = fgTab.getContentViewCore().getCurrentRenderProcessId();
    assertTrue(secondNavigationPid != initialNavigationPid);
    // Ensure the following calls happened:
    //  - BG - setInForeground(false) - when the renderer is created for uncommited frame
    //  - FG - setInForeground(true) - when the frame is swapped in on commit
    //  - DETERMINED - visibilityDetermined() - after the navigation is committed
    assertEquals("BG;FG;DETERMINED;", mBindingManager.getVisibilityCalls(secondNavigationPid));

    // Open a tab in the background and load it.
    final Tab bgTab =
        ChromeApplication.getDocumentTabModelSelector()
            .getTabById(launchViaLaunchDocumentInstanceInBackground(false, URL_2, "Page 2"));
    int bgNavigationPid = bgTab.getContentViewCore().getCurrentRenderProcessId();
    // Ensure the following calls happened:
    //  - BG - setInForeground(false) - when tab is created in the background
    //  - DETERMINED - visibilityDetermined() - after the navigation is committed
    assertEquals("BG;DETERMINED;", mBindingManager.getVisibilityCalls(bgNavigationPid));
  }
コード例 #3
0
ファイル: NavigateTest.java プロジェクト: xar369/chromium
  /**
   * Test Opening a link and verify that TabObserver#onPageLoadStarted gives the old and new URL.
   */
  @MediumTest
  @Feature({"Navigation"})
  public void testTabObserverOnPageLoadStarted() throws InterruptedException, TimeoutException {
    final String url1 = TestHttpServerClient.getUrl("chrome/test/data/android/google.html");
    final String url2 = TestHttpServerClient.getUrl("chrome/test/data/android/about.html");

    navigateAndObserve(url1, url1);
    assertWaitForPageScaleFactorMatch(0.5f);

    TabObserver onPageLoadStartedObserver =
        new EmptyTabObserver() {
          @Override
          public void onPageLoadStarted(Tab tab, String newUrl) {
            tab.removeObserver(this);
            assertEquals(url1, tab.getUrl());
            assertEquals(url2, newUrl);
          }
        };
    Tab tab = getActivity().getActivityTab();
    tab.addObserver(onPageLoadStartedObserver);
    DOMUtils.clickNode(this, tab.getContentViewCore(), "aboutLink");
    ChromeTabUtils.waitForTabPageLoaded(tab, url2);
    assertEquals("Desired Link not open", url2, getActivity().getActivityTab().getUrl());
  }
コード例 #4
0
  /**
   * Ensures correctness of the visibilityDetermined() calls, that should be always preceded by
   * setInForeground().
   *
   * <p>Bug: https://crbug.com/474543 @LargeTest @Feature({"ProcessManagement"})
   */
  @FlakyTest
  public void testVisibilityDetermined() throws InterruptedException {
    // Create a tab in foreground and wait until it is loaded.
    final Tab fgTab =
        ThreadUtils.runOnUiThreadBlockingNoException(
            new Callable<Tab>() {
              @Override
              public Tab call() {
                TabCreator tabCreator = getActivity().getCurrentTabCreator();
                return tabCreator.createNewTab(
                    new LoadUrlParams(TestHttpServerClient.getUrl(FILE_PATH)),
                    TabLaunchType.FROM_KEYBOARD,
                    null);
              }
            });
    ChromeTabUtils.waitForTabPageLoaded(fgTab, TestHttpServerClient.getUrl(FILE_PATH));
    int initialNavigationPid = fgTab.getContentViewCore().getCurrentRenderProcessId();
    // Ensure the following calls happened:
    //  - FG - setInForeground(true) - when the tab is created in the foreground
    //  - DETERMINED - visibilityDetermined() - after the initial navigation is committed
    assertEquals("FG;DETERMINED;", mBindingManager.getVisibilityCalls(initialNavigationPid));

    // Navigate to about:version which requires a different renderer.
    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                fgTab.loadUrl(new LoadUrlParams(ABOUT_VERSION_PATH));
              }
            });
    ChromeTabUtils.waitForTabPageLoaded(fgTab, ABOUT_VERSION_PATH);
    int secondNavigationPid = fgTab.getContentViewCore().getCurrentRenderProcessId();
    assertTrue(secondNavigationPid != initialNavigationPid);
    // Ensure the following calls happened:
    //  - BG - setInForeground(false) - when the renderer is created for uncommited frame
    //  - FG - setInForeground(true) - when the frame is swapped in on commit
    //  - DETERMINED - visibilityDetermined() - after the navigation is committed
    assertEquals("BG;FG;DETERMINED;", mBindingManager.getVisibilityCalls(secondNavigationPid));

    // Open a tab in the background and load it.
    final Tab bgTab =
        ThreadUtils.runOnUiThreadBlockingNoException(
            new Callable<Tab>() {
              @Override
              public Tab call() {
                TabCreator tabCreator = getActivity().getCurrentTabCreator();
                Tab tab =
                    tabCreator.createNewTab(
                        new LoadUrlParams(TestHttpServerClient.getUrl(FILE_PATH)),
                        TabLaunchType.FROM_LONGPRESS_BACKGROUND,
                        null);
                // On Svelte devices the background tab would not be loaded automatically,
                // so trigger the load manually.
                tab.show(TabSelectionType.FROM_USER);
                tab.hide();
                return tab;
              }
            });
    ChromeTabUtils.waitForTabPageLoaded(bgTab, TestHttpServerClient.getUrl(FILE_PATH));
    int bgNavigationPid = bgTab.getContentViewCore().getCurrentRenderProcessId();
    // Ensure the following calls happened:
    //  - BG - setInForeground(false) - when tab is created in the background
    //  - DETERMINED - visibilityDetermined() - after the navigation is committed
    assertEquals("BG;DETERMINED;", mBindingManager.getVisibilityCalls(bgNavigationPid));
  }
コード例 #5
0
  /**
   * Verifies that a renderer that crashes in foreground has the correct visibility when recreated.
   */
  @LargeTest
  @Feature({"ProcessManagement"})
  public void testCrashInForeground() throws InterruptedException {
    // Create a tab in foreground and wait until it is loaded.
    final Tab tab =
        ThreadUtils.runOnUiThreadBlockingNoException(
            new Callable<Tab>() {
              @Override
              public Tab call() throws Exception {
                TabCreator tabCreator = getActivity().getCurrentTabCreator();
                return tabCreator.createNewTab(
                    new LoadUrlParams(TestHttpServerClient.getUrl(FILE_PATH)),
                    TabLaunchType.FROM_KEYBOARD,
                    null);
              }
            });
    ChromeTabUtils.waitForTabPageLoaded(tab, TestHttpServerClient.getUrl(FILE_PATH));
    getInstrumentation().waitForIdleSync();

    // Kill the renderer and wait for the crash to be noted by the browser process.
    assertTrue(
        ChildProcessLauncher.crashProcessForTesting(
            tab.getContentViewCore().getCurrentRenderProcessId()));

    assertTrue(
        "Renderer crash wasn't noticed by the browser.",
        CriteriaHelper.pollForCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                return tab.getContentViewCore().getCurrentRenderProcessId() == 0;
              }
            }));

    // Reload the tab, respawning the renderer.
    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                tab.reload();
              }
            });

    // Wait until the process is spawned and its visibility is determined.
    assertTrue(
        "Process for the crashed tab was not respawned.",
        CriteriaHelper.pollForCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                return tab.getContentViewCore().getCurrentRenderProcessId() != 0;
              }
            }));

    assertTrue(
        "isInForeground() was not called for the process.",
        CriteriaHelper.pollForCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                return mBindingManager.setInForegroundWasCalled(
                    tab.getContentViewCore().getCurrentRenderProcessId());
              }
            }));

    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                // Verify the visibility of the renderer.
                assertTrue(
                    mBindingManager.isInForeground(
                        tab.getContentViewCore().getCurrentRenderProcessId()));
              }
            });
  }
コード例 #6
0
  /**
   * Verifies that the .setProcessInForeground() signal is called correctly when a tab that crashed
   * in background is restored in foreground. This is a regression test for http://crbug.com/399521.
   */
  @LargeTest
  @Feature({"ProcessManagement"})
  public void testCrashInBackground() throws InterruptedException {
    // Create two tabs and wait until they are loaded, so that their renderers are around.
    final Tab[] tabs = new Tab[2];
    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                // Foreground tab.
                TabCreator tabCreator = getActivity().getCurrentTabCreator();
                tabs[0] =
                    tabCreator.createNewTab(
                        new LoadUrlParams(TestHttpServerClient.getUrl(FILE_PATH)),
                        TabLaunchType.FROM_KEYBOARD,
                        null);
                // Background tab.
                tabs[1] =
                    tabCreator.createNewTab(
                        new LoadUrlParams(TestHttpServerClient.getUrl(FILE_PATH)),
                        TabLaunchType.FROM_LONGPRESS_BACKGROUND,
                        null);
                // On Svelte devices the background tab would not be loaded automatically, so
                // trigger the load manually.
                tabs[1].show(TabSelectionType.FROM_USER);
                tabs[1].hide();
              }
            });
    ChromeTabUtils.waitForTabPageLoaded(tabs[0], TestHttpServerClient.getUrl(FILE_PATH));
    ChromeTabUtils.waitForTabPageLoaded(tabs[1], TestHttpServerClient.getUrl(FILE_PATH));

    // Wait for the new tab animations on phones to finish.
    if (!DeviceFormFactor.isTablet(getActivity()) && getActivity() instanceof ChromeActivity) {
      final ChromeActivity activity = (ChromeActivity) getActivity();
      assertTrue(
          "Did not finish animation",
          CriteriaHelper.pollForUIThreadCriteria(
              new Criteria() {
                @Override
                public boolean isSatisfied() {
                  Layout layout =
                      activity.getCompositorViewHolder().getLayoutManager().getActiveLayout();
                  return !layout.isLayoutAnimating();
                }
              }));
    }
    getInstrumentation().waitForIdleSync();

    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                // Make sure that the renderers were spawned.
                assertTrue(tabs[0].getContentViewCore().getCurrentRenderProcessId() > 0);
                assertTrue(tabs[1].getContentViewCore().getCurrentRenderProcessId() > 0);

                // Verify that the renderer of the foreground tab was signalled as visible.
                assertTrue(
                    mBindingManager.isInForeground(
                        tabs[0].getContentViewCore().getCurrentRenderProcessId()));
                // Verify that the renderer of the tab loaded in background was signalled as not
                // visible.
                assertTrue(
                    mBindingManager.isInBackground(
                        tabs[1].getContentViewCore().getCurrentRenderProcessId()));
              }
            });

    // Kill the renderer and wait for the crash to be noted by the browser process.
    assertTrue(
        ChildProcessLauncher.crashProcessForTesting(
            tabs[1].getContentViewCore().getCurrentRenderProcessId()));

    assertTrue(
        "Renderer crash wasn't noticed by the browser.",
        CriteriaHelper.pollForCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                return tabs[1].getContentViewCore().getCurrentRenderProcessId() == 0;
              }
            }));

    // Switch to the tab that crashed in background.
    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                TabModelUtils.setIndex(getActivity().getCurrentTabModel(), indexOf(tabs[1]));
              }
            });

    // Wait until the process is spawned and its visibility is determined.
    assertTrue(
        "Process for the crashed tab was not respawned.",
        CriteriaHelper.pollForCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                return tabs[1].getContentViewCore().getCurrentRenderProcessId() != 0;
              }
            }));

    assertTrue(
        "isInForeground() was not called for the process.",
        CriteriaHelper.pollForCriteria(
            new Criteria() {
              @Override
              public boolean isSatisfied() {
                return mBindingManager.setInForegroundWasCalled(
                    tabs[1].getContentViewCore().getCurrentRenderProcessId());
              }
            }));

    getInstrumentation()
        .runOnMainSync(
            new Runnable() {
              @Override
              public void run() {
                // Verify the visibility of the renderers.
                assertTrue(
                    mBindingManager.isInBackground(
                        tabs[0].getContentViewCore().getCurrentRenderProcessId()));
                assertTrue(
                    mBindingManager.isInForeground(
                        tabs[1].getContentViewCore().getCurrentRenderProcessId()));
              }
            });
  }