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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/appmenu/DataSaverAppMenuTest.java

Issue 2853423003: Revert of Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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.appmenu; 5 package org.chromium.chrome.browser.appmenu;
6 6
7 import android.app.Activity; 7 import android.app.Activity;
8 import android.support.test.filters.SmallTest; 8 import android.support.test.filters.SmallTest;
9 9 import android.test.UiThreadTest;
10 import org.junit.Assert;
11 import org.junit.Before;
12 import org.junit.Rule;
13 import org.junit.Test;
14 import org.junit.runner.RunWith;
15 10
16 import org.chromium.base.ContextUtils; 11 import org.chromium.base.ContextUtils;
17 import org.chromium.base.test.util.CommandLineFlags; 12 import org.chromium.base.test.util.CommandLineFlags;
18 import org.chromium.base.test.util.Feature; 13 import org.chromium.base.test.util.Feature;
19 import org.chromium.base.test.util.RetryOnFailure; 14 import org.chromium.base.test.util.RetryOnFailure;
20 import org.chromium.chrome.R; 15 import org.chromium.chrome.R;
21 import org.chromium.chrome.browser.ChromeActivity;
22 import org.chromium.chrome.browser.ChromeSwitches;
23 import org.chromium.chrome.browser.ChromeTabbedActivity; 16 import org.chromium.chrome.browser.ChromeTabbedActivity;
24 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; 17 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings;
25 import org.chromium.chrome.test.ChromeActivityTestRule; 18 import org.chromium.chrome.test.ChromeActivityTestCaseBase;
26 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
27 19
28 /** 20 /**
29 * Tests the Data Saver AppMenu footer 21 * Tests the Data Saver AppMenu footer
30 */ 22 */
31 @RunWith(ChromeJUnit4ClassRunner.class)
32 @RetryOnFailure 23 @RetryOnFailure
33 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, 24 public class DataSaverAppMenuTest extends ChromeActivityTestCaseBase<ChromeTabbe dActivity> {
34 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
35 public class DataSaverAppMenuTest {
36 @Rule
37 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
38 new ChromeActivityTestRule<>(ChromeActivity.class);
39
40 private AppMenuHandlerForTest mAppMenuHandler; 25 private AppMenuHandlerForTest mAppMenuHandler;
41 26
42 /** 27 /**
43 * AppMenuHandler that will be used to intercept the delegate for testing. 28 * AppMenuHandler that will be used to intercept the delegate for testing.
44 */ 29 */
45 public static class AppMenuHandlerForTest extends AppMenuHandler { 30 public static class AppMenuHandlerForTest extends AppMenuHandler {
46 AppMenuPropertiesDelegate mDelegate; 31 AppMenuPropertiesDelegate mDelegate;
47 32
48 /** 33 /**
49 * AppMenuHandler for intercepting options item selections. 34 * AppMenuHandler for intercepting options item selections.
50 */ 35 */
51 public AppMenuHandlerForTest( 36 public AppMenuHandlerForTest(
52 Activity activity, AppMenuPropertiesDelegate delegate, int menuR esourceId) { 37 Activity activity, AppMenuPropertiesDelegate delegate, int menuR esourceId) {
53 super(activity, delegate, menuResourceId); 38 super(activity, delegate, menuResourceId);
54 mDelegate = delegate; 39 mDelegate = delegate;
55 } 40 }
56 41
57 public AppMenuPropertiesDelegate getDelegate() { 42 public AppMenuPropertiesDelegate getDelegate() {
58 return mDelegate; 43 return mDelegate;
59 } 44 }
60 } 45 }
61 46
62 @Before 47 public DataSaverAppMenuTest() {
63 public void setUp() throws Exception { 48 super(ChromeTabbedActivity.class);
49 }
50
51 @Override
52 public void startMainActivity() throws InterruptedException {
53 startMainActivityOnBlankPage();
54 }
55
56 @Override
57 protected void setUp() throws Exception {
64 ChromeTabbedActivity.setAppMenuHandlerFactoryForTesting( 58 ChromeTabbedActivity.setAppMenuHandlerFactoryForTesting(
65 new ChromeTabbedActivity.AppMenuHandlerFactory() { 59 new ChromeTabbedActivity.AppMenuHandlerFactory() {
66 @Override 60 @Override
67 public AppMenuHandler get(Activity activity, AppMenuProperti esDelegate delegate, 61 public AppMenuHandler get(Activity activity, AppMenuProperti esDelegate delegate,
68 int menuResourceId) { 62 int menuResourceId) {
69 mAppMenuHandler = 63 mAppMenuHandler =
70 new AppMenuHandlerForTest(activity, delegate, me nuResourceId); 64 new AppMenuHandlerForTest(activity, delegate, me nuResourceId);
71 return mAppMenuHandler; 65 return mAppMenuHandler;
72 } 66 }
73 }); 67 });
74 68
75 mActivityTestRule.startMainActivityOnBlankPage(); 69 super.setUp();
76 } 70 }
77 71
78 /** 72 /**
79 * Verify the Data Saver item does not show when the feature isn't on, and t he proxy is enabled. 73 * Verify the Data Saver item does not show when the feature isn't on, and t he proxy is enabled.
80 */ 74 */
81 @Test
82 @SmallTest 75 @SmallTest
76 @UiThreadTest
83 @CommandLineFlags.Add("disable-field-trial-config") 77 @CommandLineFlags.Add("disable-field-trial-config")
84 @Feature({"Browser", "Main"}) 78 @Feature({"Browser", "Main"})
85 public void testMenuDataSaverNoFeature() throws Throwable { 79 public void testMenuDataSaverNoFeature() {
86 mActivityTestRule.runOnUiThread(new Runnable() { 80 ContextUtils.getAppSharedPreferences().edit().clear().apply();
87 @Override 81 assertEquals(0, mAppMenuHandler.getDelegate().getFooterResourceId());
88 public void run() { 82 DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
89 ContextUtils.getAppSharedPreferences().edit().clear().apply(); 83 getActivity().getApplicationContext(), true);
90 Assert.assertEquals(0, mAppMenuHandler.getDelegate().getFooterRe sourceId()); 84 assertEquals(0, mAppMenuHandler.getDelegate().getFooterResourceId());
91 DataReductionProxySettings.getInstance().setDataReductionProxyEn abled(
92 mActivityTestRule.getActivity().getApplicationContext(), true);
93 Assert.assertEquals(0, mAppMenuHandler.getDelegate().getFooterRe sourceId());
94 }
95 });
96 } 85 }
97 86
98 /** 87 /**
99 * Verify the Data Saver footer shows with the flag when the proxy is on. 88 * Verify the Data Saver footer shows with the flag when the proxy is on.
100 */ 89 */
101 @Test
102 @SmallTest 90 @SmallTest
91 @UiThreadTest
103 @CommandLineFlags.Add({"enable-features=DataReductionProxyMainMenu", 92 @CommandLineFlags.Add({"enable-features=DataReductionProxyMainMenu",
104 "disable-field-trial-config"}) 93 "disable-field-trial-config"})
105 @Feature({"Browser", "Main"}) 94 @Feature({"Browser", "Main"})
106 public void testMenuDataSaver() throws Throwable { 95 public void testMenuDataSaver() {
107 mActivityTestRule.runOnUiThread(new Runnable() { 96 ContextUtils.getAppSharedPreferences().edit().clear().apply();
108 @Override 97 // Data Saver hasn't been turned on, the footer shouldn't show.
109 public void run() { 98 assertEquals(0, mAppMenuHandler.getDelegate().getFooterResourceId());
110 ContextUtils.getAppSharedPreferences().edit().clear().apply();
111 // Data Saver hasn't been turned on, the footer shouldn't show.
112 Assert.assertEquals(0, mAppMenuHandler.getDelegate().getFooterRe sourceId());
113 99
114 // Turn Data Saver on, the footer should show. 100 // Turn Data Saver on, the footer should show.
115 DataReductionProxySettings.getInstance().setDataReductionProxyEn abled( 101 DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
116 mActivityTestRule.getActivity().getApplicationContext(), true); 102 getActivity().getApplicationContext(), true);
117 Assert.assertEquals(R.layout.data_reduction_main_menu_footer, 103 assertEquals(R.layout.data_reduction_main_menu_footer,
118 mAppMenuHandler.getDelegate().getFooterResourceId()); 104 mAppMenuHandler.getDelegate().getFooterResourceId());
119 105
120 // Ensure the footer is removed if the proxy is turned off. 106 // Ensure the footer is removed if the proxy is turned off.
121 DataReductionProxySettings.getInstance().setDataReductionProxyEn abled( 107 DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
122 mActivityTestRule.getActivity().getApplicationContext(), false); 108 getActivity().getApplicationContext(), false);
123 Assert.assertEquals(0, mAppMenuHandler.getDelegate().getFooterRe sourceId()); 109 assertEquals(0, mAppMenuHandler.getDelegate().getFooterResourceId());
124 }
125 });
126 } 110 }
127 111
128 /** 112 /**
129 * Verify the Data Saver footer shows with the flag when the proxy turns on and remains in the 113 * Verify the Data Saver footer shows with the flag when the proxy turns on and remains in the
130 * main menu. 114 * main menu.
131 */ 115 */
132 @Test
133 @SmallTest 116 @SmallTest
117 @UiThreadTest
134 @CommandLineFlags.Add({"enable-features=DataReductionProxyMainMenu<DataReduc tionProxyMainMenu", 118 @CommandLineFlags.Add({"enable-features=DataReductionProxyMainMenu<DataReduc tionProxyMainMenu",
135 "force-fieldtrials=DataReductionProxyMainMenu/Enabled", 119 "force-fieldtrials=DataReductionProxyMainMenu/Enabled",
136 "force-fieldtrial-params=DataReductionProxyMainMenu.Enabled:" 120 "force-fieldtrial-params=DataReductionProxyMainMenu.Enabled:"
137 + "persistent_menu_item_enabled/true", 121 + "persistent_menu_item_enabled/true",
138 "disable-field-trial-config"}) 122 "disable-field-trial-config"})
139 @Feature({"Browser", "Main"}) 123 @Feature({"Browser", "Main"})
140 public void testMenuDataSaverPersistent() throws Throwable { 124 public void testMenuDataSaverPersistent() {
141 mActivityTestRule.runOnUiThread(new Runnable() { 125 ContextUtils.getAppSharedPreferences().edit().clear().apply();
142 @Override 126 // Data Saver hasn't been turned on, the footer shouldn't show.
143 public void run() { 127 assertEquals(0, mAppMenuHandler.getDelegate().getFooterResourceId());
144 ContextUtils.getAppSharedPreferences().edit().clear().apply();
145 // Data Saver hasn't been turned on, the footer shouldn't show.
146 Assert.assertEquals(0, mAppMenuHandler.getDelegate().getFooterRe sourceId());
147 128
148 // Turn Data Saver on, the footer should show. 129 // Turn Data Saver on, the footer should show.
149 DataReductionProxySettings.getInstance().setDataReductionProxyEn abled( 130 DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
150 mActivityTestRule.getActivity().getApplicationContext(), true); 131 getActivity().getApplicationContext(), true);
151 Assert.assertEquals(R.layout.data_reduction_main_menu_footer, 132 assertEquals(R.layout.data_reduction_main_menu_footer,
152 mAppMenuHandler.getDelegate().getFooterResourceId()); 133 mAppMenuHandler.getDelegate().getFooterResourceId());
153 134
154 // Ensure the footer remains if the proxy is turned off. 135 // Ensure the footer remains if the proxy is turned off.
155 DataReductionProxySettings.getInstance().setDataReductionProxyEn abled( 136 DataReductionProxySettings.getInstance().setDataReductionProxyEnabled(
156 mActivityTestRule.getActivity().getApplicationContext(), false); 137 getActivity().getApplicationContext(), false);
157 Assert.assertEquals(R.layout.data_reduction_main_menu_footer, 138 assertEquals(R.layout.data_reduction_main_menu_footer,
158 mAppMenuHandler.getDelegate().getFooterResourceId()); 139 mAppMenuHandler.getDelegate().getFooterResourceId());
159 }
160 });
161 } 140 }
162 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698