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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/infobar/SearchGeolocationDisclosureInfoBarTest.java

Issue 2621983003: Fix flaky Android Search Geolocation Disclosure tests. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.infobar; 5 package org.chromium.chrome.browser.infobar;
6 6
7 import android.support.test.filters.SmallTest; 7 import android.support.test.filters.SmallTest;
8 8
9 import org.chromium.base.test.util.CommandLineFlags; 9 import org.chromium.base.test.util.CommandLineFlags;
10 import org.chromium.base.test.util.Feature; 10 import org.chromium.base.test.util.Feature;
11 import org.chromium.base.test.util.FlakyTest;
12 import org.chromium.chrome.browser.ChromeActivity; 11 import org.chromium.chrome.browser.ChromeActivity;
13 import org.chromium.chrome.browser.SearchGeolocationDisclosureTabHelper; 12 import org.chromium.chrome.browser.SearchGeolocationDisclosureTabHelper;
14 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 13 import org.chromium.chrome.test.ChromeActivityTestCaseBase;
15 import org.chromium.chrome.test.util.InfoBarTestAnimationListener; 14 import org.chromium.chrome.test.util.InfoBarTestAnimationListener;
16 import org.chromium.chrome.test.util.InfoBarUtil; 15 import org.chromium.chrome.test.util.InfoBarUtil;
16 import org.chromium.content.browser.test.util.Criteria;
17 import org.chromium.content.browser.test.util.CriteriaHelper;
17 import org.chromium.net.test.EmbeddedTestServer; 18 import org.chromium.net.test.EmbeddedTestServer;
18 19
19 import java.util.concurrent.TimeoutException; 20 import java.util.concurrent.TimeoutException;
20 21
21 /** Tests for the SearchGeolocationDisclosureInfobar. */ 22 /** Tests for the SearchGeolocationDisclosureInfobar. */
22 public class SearchGeolocationDisclosureInfoBarTest 23 public class SearchGeolocationDisclosureInfoBarTest
23 extends ChromeActivityTestCaseBase<ChromeActivity> { 24 extends ChromeActivityTestCaseBase<ChromeActivity> {
24 private static final String SEARCH_PAGE = "/chrome/test/data/empty.html"; 25 private static final String SEARCH_PAGE = "/chrome/test/data/empty.html";
25 private static final String ENABLE_NEW_DISCLOSURE_FEATURE = 26 private static final String ENABLE_NEW_DISCLOSURE_FEATURE =
26 "enable-features=ConsistentOmniboxGeolocation"; 27 "enable-features=ConsistentOmniboxGeolocation";
(...skipping 16 matching lines...) Expand all
43 super.setUp(); 44 super.setUp();
44 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation ().getContext()); 45 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation ().getContext());
45 } 46 }
46 47
47 @Override 48 @Override
48 protected void tearDown() throws Exception { 49 protected void tearDown() throws Exception {
49 mTestServer.stopAndDestroyServer(); 50 mTestServer.stopAndDestroyServer();
50 super.tearDown(); 51 super.tearDown();
51 } 52 }
52 53
53 @FlakyTest(message = "https://crbug.com/678210") 54 private void waitUntilNoInfoBarsExist() {
gone 2017/01/11 18:15:42 Pull this and the other two copies into InfoBarUti
benwells 2017/01/13 05:01:26 Done.
55 CriteriaHelper.pollUiThread(new Criteria() {
56 @Override
57 public boolean isSatisfied() {
58 return getInfoBars().isEmpty();
59 }
60 });
61 }
62
54 @SmallTest 63 @SmallTest
55 @Feature({"Browser", "Main"}) 64 @Feature({"Browser", "Main"})
56 @CommandLineFlags.Add(ENABLE_NEW_DISCLOSURE_FEATURE) 65 @CommandLineFlags.Add(ENABLE_NEW_DISCLOSURE_FEATURE)
57 public void testInfoBarAppears() throws InterruptedException, TimeoutExcepti on { 66 public void testInfoBarAppears() throws InterruptedException, TimeoutExcepti on {
58 SearchGeolocationDisclosureTabHelper.setIgnoreUrlChecksForTesting(); 67 SearchGeolocationDisclosureTabHelper.setIgnoreUrlChecksForTesting();
59 assertEquals("Wrong starting infobar count", 0, getInfoBars().size()); 68 assertEquals("Wrong starting infobar count", 0, getInfoBars().size());
60 69
61 // Infobar should appear when doing the first search. 70 // Infobar should appear when doing the first search.
62 InfoBarContainer container = getActivity().getActivityTab().getInfoBarCo ntainer(); 71 InfoBarContainer container = getActivity().getActivityTab().getInfoBarCo ntainer();
63 InfoBarTestAnimationListener listener = new InfoBarTestAnimationListener (); 72 InfoBarTestAnimationListener listener = new InfoBarTestAnimationListener ();
64 container.setAnimationListener(listener); 73 container.setAnimationListener(listener);
65 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 74 loadUrl(mTestServer.getURL(SEARCH_PAGE));
66 // Note: the number of infobars is checked immediately after the URL is loaded, unlike in 75 // Note: the number of infobars is checked immediately after the URL is loaded, unlike in
67 // other infobar tests where it is checked after animations have complet ed. This is because 76 // other infobar tests where it is checked after animations have complet ed. This is because
68 // (a) in this case it should work, as these infobars are added as part of the URL loading 77 // (a) in this case it should work, as these infobars are added as part of the URL loading
69 // process, and 78 // process, and
70 // (b) if this doesn't work, it is important to catch it as otherwise th e checks that 79 // (b) if this doesn't work, it is important to catch it as otherwise th e checks that
71 // infobars haven't being shown are invalid. 80 // infobars haven't being shown are invalid.
72 assertEquals("Wrong infobar count after search", 1, getInfoBars().size() ); 81 assertEquals("Wrong infobar count after search", 1, getInfoBars().size() );
73 listener.addInfoBarAnimationFinished("InfoBar not added."); 82 listener.addInfoBarAnimationFinished("InfoBar not added.");
74 83
75 // Infobar should not appear again on the same day. 84 // Infobar should not appear again on the same day.
76 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 85 loadUrl(mTestServer.getURL(SEARCH_PAGE));
86 // There can be a delay from infobars being removed in the native Infoba rManager and them
87 // being removed in the Java container, so wait until the infobar has re ally gone.
88 waitUntilNoInfoBarsExist();
77 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() ); 89 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() );
78 90
79 // Infobar should appear again the next day. 91 // Infobar should appear again the next day.
80 SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(1); 92 SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(1);
81 listener = new InfoBarTestAnimationListener(); 93 listener = new InfoBarTestAnimationListener();
82 container.setAnimationListener(listener); 94 container.setAnimationListener(listener);
83 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 95 loadUrl(mTestServer.getURL(SEARCH_PAGE));
84 assertEquals("Wrong infobar count after search", 1, getInfoBars().size() ); 96 assertEquals("Wrong infobar count after search", 1, getInfoBars().size() );
85 listener.addInfoBarAnimationFinished("InfoBar not added."); 97 listener.addInfoBarAnimationFinished("InfoBar not added.");
86 98
87 // Infobar should not appear again on the same day. 99 // Infobar should not appear again on the same day.
88 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 100 loadUrl(mTestServer.getURL(SEARCH_PAGE));
101 waitUntilNoInfoBarsExist();
89 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() ); 102 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() );
90 103
91 // Infobar should appear again the next day. 104 // Infobar should appear again the next day.
92 SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(2); 105 SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(2);
93 listener = new InfoBarTestAnimationListener(); 106 listener = new InfoBarTestAnimationListener();
94 container.setAnimationListener(listener); 107 container.setAnimationListener(listener);
95 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 108 loadUrl(mTestServer.getURL(SEARCH_PAGE));
96 assertEquals("Wrong infobar count after search", 1, getInfoBars().size() ); 109 assertEquals("Wrong infobar count after search", 1, getInfoBars().size() );
97 listener.addInfoBarAnimationFinished("InfoBar not added."); 110 listener.addInfoBarAnimationFinished("InfoBar not added.");
98 111
99 // Infobar should not appear again on the same day. 112 // Infobar should not appear again on the same day.
100 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 113 loadUrl(mTestServer.getURL(SEARCH_PAGE));
114 waitUntilNoInfoBarsExist();
101 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() ); 115 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() );
102 116
103 // Infobar has appeared three times now, it should not appear again. 117 // Infobar has appeared three times now, it should not appear again.
104 SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(3); 118 SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(3);
105 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 119 loadUrl(mTestServer.getURL(SEARCH_PAGE));
106 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() ); 120 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() );
107 } 121 }
108 122
109 @SmallTest 123 @SmallTest
110 @Feature({"Browser", "Main"}) 124 @Feature({"Browser", "Main"})
111 @CommandLineFlags.Add(ENABLE_NEW_DISCLOSURE_FEATURE) 125 @CommandLineFlags.Add(ENABLE_NEW_DISCLOSURE_FEATURE)
112 public void testInfoBarDismiss() throws InterruptedException, TimeoutExcepti on { 126 public void testInfoBarDismiss() throws InterruptedException, TimeoutExcepti on {
113 SearchGeolocationDisclosureTabHelper.setIgnoreUrlChecksForTesting(); 127 SearchGeolocationDisclosureTabHelper.setIgnoreUrlChecksForTesting();
114 assertEquals("Wrong starting infobar count", 0, getInfoBars().size()); 128 assertEquals("Wrong starting infobar count", 0, getInfoBars().size());
115 129
116 // Infobar should appear when doing the first search. 130 // Infobar should appear when doing the first search.
117 InfoBarContainer container = getActivity().getActivityTab().getInfoBarCo ntainer(); 131 InfoBarContainer container = getActivity().getActivityTab().getInfoBarCo ntainer();
118 InfoBarTestAnimationListener listener = new InfoBarTestAnimationListener (); 132 InfoBarTestAnimationListener listener = new InfoBarTestAnimationListener ();
119 container.setAnimationListener(listener); 133 container.setAnimationListener(listener);
120 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 134 loadUrl(mTestServer.getURL(SEARCH_PAGE));
121 assertEquals("Wrong infobar count after search", 1, getInfoBars().size() ); 135 assertEquals("Wrong infobar count after search", 1, getInfoBars().size() );
122 listener.addInfoBarAnimationFinished("InfoBar not added."); 136 listener.addInfoBarAnimationFinished("InfoBar not added.");
123 137
124 // Dismiss the infobar. 138 // Dismiss the infobar.
125 assertTrue(InfoBarUtil.clickCloseButton(getInfoBars().get(0))); 139 assertTrue(InfoBarUtil.clickCloseButton(getInfoBars().get(0)));
126 140
127 // Infobar should not appear again on the same day. 141 // Infobar should not appear again on the same day.
128 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 142 loadUrl(mTestServer.getURL(SEARCH_PAGE));
143 waitUntilNoInfoBarsExist();
129 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() ); 144 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() );
130 145
131 // Infobar should not appear the next day either, as it has been dismiss ed. 146 // Infobar should not appear the next day either, as it has been dismiss ed.
132 SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(1); 147 SearchGeolocationDisclosureTabHelper.setDayOffsetForTesting(1);
133 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 148 loadUrl(mTestServer.getURL(SEARCH_PAGE));
134 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() ); 149 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() );
135 } 150 }
136 151
137 @SmallTest 152 @SmallTest
138 @Feature({"Browser", "Main"}) 153 @Feature({"Browser", "Main"})
(...skipping 22 matching lines...) Expand all
161 @CommandLineFlags.Add(DISABLE_NEW_DISCLOSURE_FEATURE) 176 @CommandLineFlags.Add(DISABLE_NEW_DISCLOSURE_FEATURE)
162 public void testInfoBarAppearsDoesntAppearWithoutFeature() 177 public void testInfoBarAppearsDoesntAppearWithoutFeature()
163 throws InterruptedException, TimeoutException { 178 throws InterruptedException, TimeoutException {
164 SearchGeolocationDisclosureTabHelper.setIgnoreUrlChecksForTesting(); 179 SearchGeolocationDisclosureTabHelper.setIgnoreUrlChecksForTesting();
165 assertEquals("Wrong starting infobar count", 0, getInfoBars().size()); 180 assertEquals("Wrong starting infobar count", 0, getInfoBars().size());
166 181
167 loadUrl(mTestServer.getURL(SEARCH_PAGE)); 182 loadUrl(mTestServer.getURL(SEARCH_PAGE));
168 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() ); 183 assertEquals("Wrong infobar count after search", 0, getInfoBars().size() );
169 } 184 }
170 } 185 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698