Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/test/android/javatests/src/org/chromium/chrome/test/MultiActivityTestCommon.java

Issue 2847933002: Convert MultiActivityTestBase children to JUnit4 (Closed)
Patch Set: Add imports and rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.test;
6
7 import android.app.Instrumentation;
8 import android.content.Context;
9 import android.text.TextUtils;
10
11 import org.chromium.base.metrics.RecordHistogram;
12 import org.chromium.chrome.browser.ChromeActivity;
13 import org.chromium.chrome.browser.tab.Tab;
14 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelSelector;
15 import org.chromium.chrome.test.util.ApplicationTestUtils;
16 import org.chromium.chrome.test.util.browser.tabmodel.document.MockStorageDelega te;
17 import org.chromium.content.browser.test.util.Criteria;
18 import org.chromium.content.browser.test.util.CriteriaHelper;
19
20 // TODO(yolandyan): move this class to its test rule once JUnit4 migration is ov er
21 final class MultiActivityTestCommon {
22 private final MultiActivityTestCommonCallback mCallback;
23 MockStorageDelegate mStorageDelegate;
24 Context mContext;
25
26 MultiActivityTestCommon(MultiActivityTestCommonCallback callback) {
27 mCallback = callback;
28 }
29
30 void setUp() throws Exception {
31 RecordHistogram.setDisabledForTests(true);
32 mContext = mCallback.getInstrumentation().getTargetContext();
33 ApplicationTestUtils.setUp(mContext, true);
34
35 // Make the DocumentTabModelSelector use a mocked out directory so that test runs don't
36 // interfere with each other.
37 mStorageDelegate = new MockStorageDelegate(mContext.getCacheDir());
38 DocumentTabModelSelector.setStorageDelegateForTests(mStorageDelegate);
39 }
40
41 void tearDown() throws Exception {
42 mStorageDelegate.ensureDirectoryDestroyed();
43 ApplicationTestUtils.tearDown(mContext);
44 RecordHistogram.setDisabledForTests(false);
45 }
46
47 void waitForFullLoad(final ChromeActivity activity, final String expectedTit le) {
48 waitForFullLoad(activity, expectedTitle, false);
49 }
50
51 void waitForFullLoad(
52 final ChromeActivity activity, final String expectedTitle, boolean w aitLongerForLoad) {
53 ApplicationTestUtils.assertWaitForPageScaleFactorMatch(activity, 0.5f, w aitLongerForLoad);
54 final Tab tab = activity.getActivityTab();
55 assert tab != null;
56
57 CriteriaHelper.pollUiThread(new Criteria() {
58 @Override
59 public boolean isSatisfied() {
60 if (!tab.isLoadingAndRenderingDone()) return false;
61 if (!TextUtils.equals(expectedTitle, tab.getTitle())) return fal se;
62 return true;
63 }
64 });
65 }
66
67 public interface MultiActivityTestCommonCallback { Instrumentation getInstru mentation(); }
68 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698