| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.webapps; | 5 package org.chromium.chrome.browser.webapps; |
| 6 | 6 |
| 7 import android.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.DialogInterface; | 8 import android.content.DialogInterface; |
| 9 import android.support.test.filters.SmallTest; | 9 import android.support.test.filters.SmallTest; |
| 10 import android.support.v7.app.AlertDialog; | 10 import android.support.v7.app.AlertDialog; |
| 11 | 11 |
| 12 import org.junit.Assert; |
| 13 import org.junit.Before; |
| 14 import org.junit.Rule; |
| 15 import org.junit.Test; |
| 16 import org.junit.runner.RunWith; |
| 17 |
| 12 import org.chromium.base.ThreadUtils; | 18 import org.chromium.base.ThreadUtils; |
| 19 import org.chromium.base.test.util.CommandLineFlags; |
| 13 import org.chromium.base.test.util.Feature; | 20 import org.chromium.base.test.util.Feature; |
| 14 import org.chromium.base.test.util.RetryOnFailure; | 21 import org.chromium.base.test.util.RetryOnFailure; |
| 15 import org.chromium.chrome.R; | 22 import org.chromium.chrome.R; |
| 16 import org.chromium.chrome.browser.ChromeActivity; | 23 import org.chromium.chrome.browser.ChromeActivity; |
| 24 import org.chromium.chrome.browser.ChromeSwitches; |
| 17 import org.chromium.chrome.browser.tab.Tab; | 25 import org.chromium.chrome.browser.tab.Tab; |
| 18 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 26 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 27 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 19 | 28 |
| 20 /** | 29 /** |
| 21 * Tests org.chromium.chrome.browser.webapps.AddToHomescreenDialog by verifying | 30 * Tests org.chromium.chrome.browser.webapps.AddToHomescreenDialog by verifying |
| 22 * that the calling the show() method actually shows the dialog and checks that | 31 * that the calling the show() method actually shows the dialog and checks that |
| 23 * some expected elements inside the dialog are present. | 32 * some expected elements inside the dialog are present. |
| 24 * | 33 * |
| 25 * This is mostly intended as a smoke test. | 34 * This is mostly intended as a smoke test. |
| 26 */ | 35 */ |
| 27 public class AddToHomescreenDialogTest extends ChromeActivityTestCaseBase<Chrome
Activity> { | 36 @RunWith(ChromeJUnit4ClassRunner.class) |
| 37 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| 38 // Preconnect causes issues with the single-threaded Java test server. |
| 39 "--disable-features=NetworkPrediction"}) |
| 40 public class AddToHomescreenDialogTest { |
| 41 @Rule |
| 42 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
| 43 new ChromeActivityTestRule<>(ChromeActivity.class); |
| 44 |
| 28 private static class MockAddToHomescreenManager extends AddToHomescreenManag
er { | 45 private static class MockAddToHomescreenManager extends AddToHomescreenManag
er { |
| 29 public MockAddToHomescreenManager(Activity activity, Tab tab) { | 46 public MockAddToHomescreenManager(Activity activity, Tab tab) { |
| 30 super(activity, tab); | 47 super(activity, tab); |
| 31 } | 48 } |
| 32 | 49 |
| 33 @Override | 50 @Override |
| 34 public void addShortcut(String userRequestedTitle) {} | 51 public void addShortcut(String userRequestedTitle) {} |
| 35 @Override | 52 @Override |
| 36 public void onFinished() {} | 53 public void onFinished() {} |
| 37 } | 54 } |
| 38 | 55 |
| 39 public AddToHomescreenDialogTest() { | 56 @Before |
| 40 super(ChromeActivity.class); | 57 public void setUp() throws InterruptedException { |
| 58 mActivityTestRule.startMainActivityOnBlankPage(); |
| 41 } | 59 } |
| 42 | 60 |
| 43 @Override | 61 @Test |
| 44 public void startMainActivity() throws InterruptedException { | |
| 45 startMainActivityOnBlankPage(); | |
| 46 } | |
| 47 | |
| 48 @SmallTest | 62 @SmallTest |
| 49 @Feature("{Webapp}") | 63 @Feature("{Webapp}") |
| 50 @RetryOnFailure | 64 @RetryOnFailure |
| 51 public void testSmoke() throws InterruptedException { | 65 public void testSmoke() throws InterruptedException { |
| 52 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 66 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 53 @Override | 67 @Override |
| 54 public void run() { | 68 public void run() { |
| 55 AddToHomescreenDialog dialog = | 69 AddToHomescreenDialog dialog = new AddToHomescreenDialog( |
| 56 new AddToHomescreenDialog(new MockAddToHomescreenManager
( | 70 new MockAddToHomescreenManager(mActivityTestRule.getActi
vity(), |
| 57 getActivity(), getActivity().getActivityTab())); | 71 mActivityTestRule.getActivity().getActivityTab()
)); |
| 58 dialog.show(getActivity()); | 72 dialog.show(mActivityTestRule.getActivity()); |
| 59 | 73 |
| 60 AlertDialog alertDialog = dialog.getAlertDialogForTesting(); | 74 AlertDialog alertDialog = dialog.getAlertDialogForTesting(); |
| 61 assertNotNull(alertDialog); | 75 Assert.assertNotNull(alertDialog); |
| 62 | 76 |
| 63 assertTrue(alertDialog.isShowing()); | 77 Assert.assertTrue(alertDialog.isShowing()); |
| 64 | 78 |
| 65 assertNotNull(alertDialog.findViewById(R.id.spinny)); | 79 Assert.assertNotNull(alertDialog.findViewById(R.id.spinny)); |
| 66 assertNotNull(alertDialog.findViewById(R.id.icon)); | 80 Assert.assertNotNull(alertDialog.findViewById(R.id.icon)); |
| 67 assertNotNull(alertDialog.findViewById(R.id.text)); | 81 Assert.assertNotNull(alertDialog.findViewById(R.id.text)); |
| 68 assertNotNull(alertDialog.getButton(DialogInterface.BUTTON_POSIT
IVE)); | 82 Assert.assertNotNull(alertDialog.getButton(DialogInterface.BUTTO
N_POSITIVE)); |
| 69 assertNotNull(alertDialog.getButton(DialogInterface.BUTTON_NEGAT
IVE)); | 83 Assert.assertNotNull(alertDialog.getButton(DialogInterface.BUTTO
N_NEGATIVE)); |
| 70 } | 84 } |
| 71 }); | 85 }); |
| 72 } | 86 } |
| 73 } | 87 } |
| OLD | NEW |