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

Side by Side Diff: ios/chrome/browser/metrics/tab_usage_recorder_egtest.mm

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: mistake 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #import <EarlGrey/EarlGrey.h> 5 #import <EarlGrey/EarlGrey.h>
6 #import <XCTest/XCTest.h> 6 #import <XCTest/XCTest.h>
7 7
8 #include "base/mac/bind_objc_block.h" 8 #include "base/mac/bind_objc_block.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; 79 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
80 } 80 }
81 81
82 // Creates a new main tab and load |url|. Wait until |word| is visible on the 82 // Creates a new main tab and load |url|. Wait until |word| is visible on the
83 // page. 83 // page.
84 void NewMainTabWithURL(const GURL& url, const std::string& word) { 84 void NewMainTabWithURL(const GURL& url, const std::string& word) {
85 int number_of_tabs = chrome_test_util::GetMainTabCount(); 85 int number_of_tabs = chrome_test_util::GetMainTabCount();
86 chrome_test_util::OpenNewTab(); 86 chrome_test_util::OpenNewTab();
87 [ChromeEarlGrey loadURL:url]; 87 [ChromeEarlGrey loadURL:url];
88 [[EarlGrey 88 [[EarlGrey
89 selectElementWithMatcher:chrome_test_util::webViewContainingText(word)] 89 selectElementWithMatcher:chrome_test_util::WebViewContainingText(word)]
90 assertWithMatcher:grey_notNil()]; 90 assertWithMatcher:grey_notNil()];
91 chrome_test_util::AssertMainTabCount(number_of_tabs + 1); 91 chrome_test_util::AssertMainTabCount(number_of_tabs + 1);
92 } 92 }
93 93
94 // Opens 2 new tabs with different URLs. 94 // Opens 2 new tabs with different URLs.
95 void OpenTwoTabs() { 95 void OpenTwoTabs() {
96 chrome_test_util::CloseAllTabsInCurrentMode(); 96 chrome_test_util::CloseAllTabsInCurrentMode();
97 97
98 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); 98 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1);
99 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2); 99 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 ConditionBlock condition = ^{ 140 ConditionBlock condition = ^{
141 return chrome_test_util::GetMainTabCount() == (nb_main_tab - 1); 141 return chrome_test_util::GetMainTabCount() == (nb_main_tab - 1);
142 }; 142 };
143 GREYAssert( 143 GREYAssert(
144 testing::WaitUntilConditionOrTimeout(kWaitElementTimeout, condition), 144 testing::WaitUntilConditionOrTimeout(kWaitElementTimeout, condition),
145 @"Waiting for tab to close"); 145 @"Waiting for tab to close");
146 } 146 }
147 147
148 // Closes the tabs switcher. 148 // Closes the tabs switcher.
149 void CloseTabSwitcher() { 149 void CloseTabSwitcher() {
150 id<GREYMatcher> matcher = chrome_test_util::buttonWithAccessibilityLabelId( 150 id<GREYMatcher> matcher = chrome_test_util::ButtonWithAccessibilityLabelId(
151 IDS_IOS_TAB_STRIP_LEAVE_TAB_SWITCHER); 151 IDS_IOS_TAB_STRIP_LEAVE_TAB_SWITCHER);
152 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; 152 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()];
153 } 153 }
154 154
155 // Swithches to normal mode using swith button (iPad) or stack view (iPhone). 155 // Swithches to normal mode using swith button (iPad) or stack view (iPhone).
156 // Assumes current mode is Incognito. 156 // Assumes current mode is Incognito.
157 void SwitchToNormalMode() { 157 void SwitchToNormalMode() {
158 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), 158 GREYAssertTrue(chrome_test_util::IsIncognitoMode(),
159 @"Switching to normal mode is only allowed from Incognito."); 159 @"Switching to normal mode is only allowed from Incognito.");
160 if (IsIPadIdiom()) { 160 if (IsIPadIdiom()) {
161 if (experimental_flags::IsTabSwitcherEnabled()) { 161 if (experimental_flags::IsTabSwitcherEnabled()) {
162 // Enter the tab switcher. 162 // Enter the tab switcher.
163 id<GREYMatcher> tabSwitcherEnterButton = 163 id<GREYMatcher> tabSwitcherEnterButton =
164 grey_accessibilityLabel(l10n_util::GetNSStringWithFixup( 164 grey_accessibilityLabel(l10n_util::GetNSStringWithFixup(
165 IDS_IOS_TAB_STRIP_ENTER_TAB_SWITCHER)); 165 IDS_IOS_TAB_STRIP_ENTER_TAB_SWITCHER));
166 [[EarlGrey selectElementWithMatcher:tabSwitcherEnterButton] 166 [[EarlGrey selectElementWithMatcher:tabSwitcherEnterButton]
167 performAction:grey_tap()]; 167 performAction:grey_tap()];
168 168
169 // Select the non incognito panel. 169 // Select the non incognito panel.
170 id<GREYMatcher> tabSwitcherHeaderPanelButton = 170 id<GREYMatcher> tabSwitcherHeaderPanelButton =
171 grey_accessibilityLabel(l10n_util::GetNSStringWithFixup( 171 grey_accessibilityLabel(l10n_util::GetNSStringWithFixup(
172 IDS_IOS_TAB_SWITCHER_HEADER_NON_INCOGNITO_TABS)); 172 IDS_IOS_TAB_SWITCHER_HEADER_NON_INCOGNITO_TABS));
173 [[EarlGrey selectElementWithMatcher:tabSwitcherHeaderPanelButton] 173 [[EarlGrey selectElementWithMatcher:tabSwitcherHeaderPanelButton]
174 performAction:grey_tap()]; 174 performAction:grey_tap()];
175 175
176 // Leave the tab switcher. 176 // Leave the tab switcher.
177 CloseTabSwitcher(); 177 CloseTabSwitcher();
178 } else { 178 } else {
179 [[EarlGrey selectElementWithMatcher: 179 [[EarlGrey selectElementWithMatcher:
180 chrome_test_util::buttonWithAccessibilityLabelId( 180 chrome_test_util::ButtonWithAccessibilityLabelId(
181 IDS_IOS_SWITCH_BROWSER_MODE_LEAVE_INCOGNITO)] 181 IDS_IOS_SWITCH_BROWSER_MODE_LEAVE_INCOGNITO)]
182 performAction:grey_tap()]; 182 performAction:grey_tap()];
183 } 183 }
184 } else { 184 } else {
185 [[EarlGrey selectElementWithMatcher: 185 [[EarlGrey selectElementWithMatcher:
186 chrome_test_util::buttonWithAccessibilityLabelId( 186 chrome_test_util::ButtonWithAccessibilityLabelId(
187 IDS_IOS_TOOLBAR_SHOW_TABS)] performAction:grey_tap()]; 187 IDS_IOS_TOOLBAR_SHOW_TABS)] performAction:grey_tap()];
188 [[EarlGrey selectElementWithMatcher: 188 [[EarlGrey selectElementWithMatcher:
189 chrome_test_util::buttonWithAccessibilityLabelId( 189 chrome_test_util::ButtonWithAccessibilityLabelId(
190 IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB)] 190 IDS_IOS_TOOLS_MENU_NEW_INCOGNITO_TAB)]
191 performAction:grey_swipeSlowInDirection(kGREYDirectionRight)]; 191 performAction:grey_swipeSlowInDirection(kGREYDirectionRight)];
192 [[EarlGrey selectElementWithMatcher: 192 [[EarlGrey selectElementWithMatcher:
193 chrome_test_util::buttonWithAccessibilityLabelId( 193 chrome_test_util::ButtonWithAccessibilityLabelId(
194 IDS_IOS_TOOLBAR_SHOW_TABS)] performAction:grey_tap()]; 194 IDS_IOS_TOOLBAR_SHOW_TABS)] performAction:grey_tap()];
195 } 195 }
196 ConditionBlock condition = ^bool { 196 ConditionBlock condition = ^bool {
197 return !chrome_test_util::IsIncognitoMode(); 197 return !chrome_test_util::IsIncognitoMode();
198 }; 198 };
199 GREYAssert( 199 GREYAssert(
200 testing::WaitUntilConditionOrTimeout(kWaitElementTimeout, condition), 200 testing::WaitUntilConditionOrTimeout(kWaitElementTimeout, condition),
201 @"Waiting switch to normal mode."); 201 @"Waiting switch to normal mode.");
202 } 202 }
203 203
204 // Check that the error page is visible. 204 // Check that the error page is visible.
205 void CheckErrorPageIsVisible() { 205 void CheckErrorPageIsVisible() {
206 // The DNS error page is static HTML content, so it isn't part of the webview 206 // The DNS error page is static HTML content, so it isn't part of the webview
207 // owned by the webstate. 207 // owned by the webstate.
208 [[EarlGrey selectElementWithMatcher:chrome_test_util:: 208 [[EarlGrey selectElementWithMatcher:chrome_test_util::
209 webViewBelongingToWebController()] 209 WebViewBelongingToWebController()]
Eugene But (OOO till 7-30) 2017/01/23 19:39:03 Please use WebViewInWebState instead. WebViewBelon
baxley 2017/01/24 22:18:48 Done.
210 assertWithMatcher:grey_nil()]; 210 assertWithMatcher:grey_nil()];
211 NSString* const kError = 211 NSString* const kError =
212 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); 212 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE);
213 [[EarlGrey 213 [[EarlGrey
214 selectElementWithMatcher:chrome_test_util::staticHtmlViewContainingText( 214 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText(
215 kError)] assertWithMatcher:grey_notNil()]; 215 kError)] assertWithMatcher:grey_notNil()];
216 } 216 }
217 217
218 // Open the settings submenu. Assumes that settings menu is visible. 218 // Open the settings submenu. Assumes that settings menu is visible.
219 void OpenSettingsSubMenuUnsynced(int submenu) { 219 void OpenSettingsSubMenuUnsynced(int submenu) {
220 id<GREYMatcher> settings_button_matcher = 220 id<GREYMatcher> settings_button_matcher =
221 grey_text(l10n_util::GetNSString(submenu)); 221 grey_text(l10n_util::GetNSString(submenu));
222 [[[EarlGrey selectElementWithMatcher:settings_button_matcher] 222 [[[EarlGrey selectElementWithMatcher:settings_button_matcher]
223 usingSearchAction:grey_swipeSlowInDirection(kGREYDirectionUp) 223 usingSearchAction:grey_swipeSlowInDirection(kGREYDirectionUp)
224 onElementWithMatcher:grey_accessibilityID(kSettingsCollectionViewId)] 224 onElementWithMatcher:grey_accessibilityID(kSettingsCollectionViewId)]
(...skipping 10 matching lines...) Expand all
235 grey_accessibilityID(kToolsMenuSettingsId); 235 grey_accessibilityID(kToolsMenuSettingsId);
236 236
237 WaitAndTap(settings_button_matcher, @"Settings menu"); 237 WaitAndTap(settings_button_matcher, @"Settings menu");
238 Wait(grey_accessibilityID(kSettingsCollectionViewId), @"Setting view"); 238 Wait(grey_accessibilityID(kSettingsCollectionViewId), @"Setting view");
239 } 239 }
240 240
241 // Select the tab with title |title| using UI (tab strip on iPad, stack view on 241 // Select the tab with title |title| using UI (tab strip on iPad, stack view on
242 // iPhone). 242 // iPhone).
243 void SelectTabUsingUI(NSString* title) { 243 void SelectTabUsingUI(NSString* title) {
244 if (IsCompact()) { 244 if (IsCompact()) {
245 WaitAndTap(chrome_test_util::buttonWithAccessibilityLabelId( 245 WaitAndTap(chrome_test_util::ButtonWithAccessibilityLabelId(
246 IDS_IOS_TOOLBAR_SHOW_TABS), 246 IDS_IOS_TOOLBAR_SHOW_TABS),
247 @"Tab switcher"); 247 @"Tab switcher");
248 } 248 }
249 WaitAndTap(grey_text(title), 249 WaitAndTap(grey_text(title),
250 [NSString stringWithFormat:@"tab with title %@", title]); 250 [NSString stringWithFormat:@"tab with title %@", title]);
251 } 251 }
252 } // namespace 252 } // namespace
253 253
254 // Test for the TabUsageRecorder class. 254 // Test for the TabUsageRecorder class.
255 @interface TabUsageRecorderTestCase : ChromeTestCase 255 @interface TabUsageRecorderTestCase : ChromeTestCase
(...skipping 29 matching lines...) Expand all
285 histogramTester.ExpectUniqueSample( 285 histogramTester.ExpectUniqueSample(
286 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock); 286 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock);
287 287
288 // Evict the tab. 288 // Evict the tab.
289 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); 289 OpenNewIncognitoTabUsingUIAndEvictMainTabs();
290 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), 290 GREYAssertTrue(chrome_test_util::IsIncognitoMode(),
291 @"Failed to switch to incognito mode"); 291 @"Failed to switch to incognito mode");
292 292
293 // Switch back to the normal tabs. Should be on tab one. 293 // Switch back to the normal tabs. Should be on tab one.
294 SwitchToNormalMode(); 294 SwitchToNormalMode();
295 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 295 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
296 kURL1FirstWord)] 296 kURL1FirstWord)]
297 assertWithMatcher:grey_notNil()]; 297 assertWithMatcher:grey_notNil()];
298 298
299 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 2, failureBlock); 299 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 2, failureBlock);
300 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, 300 histogramTester.ExpectBucketCount(kSelectedTabHistogramName,
301 TabUsageRecorder::EVICTED, 1, failureBlock); 301 TabUsageRecorder::EVICTED, 1, failureBlock);
302 } 302 }
303 303
304 // Verifies the UMA metric for page loads before a tab eviction by loading 304 // Verifies the UMA metric for page loads before a tab eviction by loading
305 // some tabs, forcing a tab eviction, then checking the histogram. 305 // some tabs, forcing a tab eviction, then checking the histogram.
306 - (void)testPageLoadCountBeforeEvictedTab { 306 - (void)testPageLoadCountBeforeEvictedTab {
307 web::test::SetUpFileBasedHttpServer(); 307 web::test::SetUpFileBasedHttpServer();
308 chrome_test_util::HistogramTester histogramTester; 308 chrome_test_util::HistogramTester histogramTester;
309 ResetTabUsageRecorder(); 309 ResetTabUsageRecorder();
310 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); 310 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1);
311 FailureBlock failureBlock = ^(NSString* error) { 311 FailureBlock failureBlock = ^(NSString* error) {
312 GREYFail(error); 312 GREYFail(error);
313 }; 313 };
314 314
315 // This test opens three tabs. 315 // This test opens three tabs.
316 const int numberOfTabs = 3; 316 const int numberOfTabs = 3;
317 chrome_test_util::CloseAllTabsInCurrentMode(); 317 chrome_test_util::CloseAllTabsInCurrentMode();
318 // Open three tabs with http:// urls. 318 // Open three tabs with http:// urls.
319 for (NSUInteger i = 0; i < numberOfTabs; i++) { 319 for (NSUInteger i = 0; i < numberOfTabs; i++) {
320 chrome_test_util::OpenNewTab(); 320 chrome_test_util::OpenNewTab();
321 [ChromeEarlGrey loadURL:url1]; 321 [ChromeEarlGrey loadURL:url1];
322 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 322 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
323 kURL1FirstWord)] 323 kURL1FirstWord)]
324 assertWithMatcher:grey_notNil()]; 324 assertWithMatcher:grey_notNil()];
325 } 325 }
326 chrome_test_util::AssertMainTabCount(numberOfTabs); 326 chrome_test_util::AssertMainTabCount(numberOfTabs);
327 327
328 // Switch between the tabs. They are currently in memory. 328 // Switch between the tabs. They are currently in memory.
329 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 329 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
330 330
331 // Verify that no page-load count has been recorded. 331 // Verify that no page-load count has been recorded.
332 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 0, 332 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 0,
333 failureBlock); 333 failureBlock);
334 334
335 // Reload each tab. 335 // Reload each tab.
336 for (NSUInteger i = 0; i < numberOfTabs; i++) { 336 for (NSUInteger i = 0; i < numberOfTabs; i++) {
337 chrome_test_util::SelectTabAtIndexInCurrentMode(i); 337 chrome_test_util::SelectTabAtIndexInCurrentMode(i);
338 // Clear the page so that we can check when pade reload is complete. 338 // Clear the page so that we can check when pade reload is complete.
339 __block bool finished = false; 339 __block bool finished = false;
340 chrome_test_util::GetCurrentWebState()->ExecuteJavaScript( 340 chrome_test_util::GetCurrentWebState()->ExecuteJavaScript(
341 base::UTF8ToUTF16(kClearPageScript), 341 base::UTF8ToUTF16(kClearPageScript),
342 base::BindBlock(^(const base::Value*) { 342 base::BindBlock(^(const base::Value*) {
343 finished = true; 343 finished = true;
344 })); 344 }));
345 345
346 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, 346 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0,
347 ^{ 347 ^{
348 return finished; 348 return finished;
349 }), 349 }),
350 @"JavaScript to reload each tab did not finish"); 350 @"JavaScript to reload each tab did not finish");
351 [ChromeEarlGreyUI reload]; 351 [ChromeEarlGreyUI reload];
352 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 352 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
353 kURL1FirstWord)] 353 kURL1FirstWord)]
354 assertWithMatcher:grey_notNil()]; 354 assertWithMatcher:grey_notNil()];
355 } 355 }
356 356
357 // Evict the tab. Create a dummy tab so that switching back to normal mode 357 // Evict the tab. Create a dummy tab so that switching back to normal mode
358 // does not trigger a reload immediatly. 358 // does not trigger a reload immediatly.
359 chrome_test_util::OpenNewTab(); 359 chrome_test_util::OpenNewTab();
360 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); 360 OpenNewIncognitoTabUsingUIAndEvictMainTabs();
361 chrome_test_util::AssertIncognitoTabCount(1); 361 chrome_test_util::AssertIncognitoTabCount(1);
362 362
363 // Switch back to the normal tabs. Should be on tab one. 363 // Switch back to the normal tabs. Should be on tab one.
364 SwitchToNormalMode(); 364 SwitchToNormalMode();
365 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 365 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
366 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 366 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
367 kURL1FirstWord)] 367 kURL1FirstWord)]
368 assertWithMatcher:grey_notNil()]; 368 assertWithMatcher:grey_notNil()];
369 369
370 // Verify that one page-load count has been recorded. It should contain two 370 // Verify that one page-load count has been recorded. It should contain two
371 // page loads for each tab created. 371 // page loads for each tab created.
372 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1, 372 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1,
373 failureBlock); 373 failureBlock);
374 374
375 std::unique_ptr<base::HistogramSamples> samples = 375 std::unique_ptr<base::HistogramSamples> samples =
376 histogramTester.GetHistogramSamplesSinceCreation( 376 histogramTester.GetHistogramSamplesSinceCreation(
(...skipping 19 matching lines...) Expand all
396 GREYAssertTrue(chrome_test_util::SetCurrentTabsToBeColdStartTabs(), 396 GREYAssertTrue(chrome_test_util::SetCurrentTabsToBeColdStartTabs(),
397 @"Fail to state tabs as cold start tabs"); 397 @"Fail to state tabs as cold start tabs");
398 398
399 // Open two incognito tabs with urls, clearing normal tabs from memory. 399 // Open two incognito tabs with urls, clearing normal tabs from memory.
400 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); 400 OpenNewIncognitoTabUsingUIAndEvictMainTabs();
401 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); 401 OpenNewIncognitoTabUsingUIAndEvictMainTabs();
402 chrome_test_util::AssertIncognitoTabCount(2); 402 chrome_test_util::AssertIncognitoTabCount(2);
403 403
404 // Switch back to the normal tabs. 404 // Switch back to the normal tabs.
405 SwitchToNormalMode(); 405 SwitchToNormalMode();
406 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 406 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
407 kURL2FirstWord)] 407 kURL2FirstWord)]
408 assertWithMatcher:grey_notNil()]; 408 assertWithMatcher:grey_notNil()];
409 409
410 // Select the other one so it also reloads. 410 // Select the other one so it also reloads.
411 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 411 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
412 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 412 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
413 kURL1FirstWord)] 413 kURL1FirstWord)]
414 assertWithMatcher:grey_notNil()]; 414 assertWithMatcher:grey_notNil()];
415 415
416 FailureBlock failureBlock = ^(NSString* error) { 416 FailureBlock failureBlock = ^(NSString* error) {
417 GREYFail(error); 417 GREYFail(error);
418 }; 418 };
419 // Make sure that one of the 2 tab loads (excluding the selected tab) is 419 // Make sure that one of the 2 tab loads (excluding the selected tab) is
420 // counted as a cold start eviction. 420 // counted as a cold start eviction.
421 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, 421 histogramTester.ExpectBucketCount(kSelectedTabHistogramName,
422 TabUsageRecorder::EVICTED_DUE_TO_COLD_START, 422 TabUsageRecorder::EVICTED_DUE_TO_COLD_START,
423 1, failureBlock); 423 1, failureBlock);
424 424
425 histogramTester.ExpectBucketCount( 425 histogramTester.ExpectBucketCount(
426 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 0, failureBlock); 426 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 0, failureBlock);
427 // Re-select the same tab and make sure it is not counted again as evicted. 427 // Re-select the same tab and make sure it is not counted again as evicted.
428 chrome_test_util::SelectTabAtIndexInCurrentMode(1); 428 chrome_test_util::SelectTabAtIndexInCurrentMode(1);
429 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 429 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
430 430
431 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 431 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
432 kURL1FirstWord)] 432 kURL1FirstWord)]
433 assertWithMatcher:grey_notNil()]; 433 assertWithMatcher:grey_notNil()];
434 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, 434 histogramTester.ExpectBucketCount(kSelectedTabHistogramName,
435 TabUsageRecorder::EVICTED_DUE_TO_COLD_START, 435 TabUsageRecorder::EVICTED_DUE_TO_COLD_START,
436 1, failureBlock); 436 1, failureBlock);
437 437
438 histogramTester.ExpectBucketCount( 438 histogramTester.ExpectBucketCount(
439 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 2, failureBlock); 439 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 2, failureBlock);
440 } 440 }
441 441
(...skipping 15 matching lines...) Expand all
457 @"Fail to simulate tab backgrounding."); 457 @"Fail to simulate tab backgrounding.");
458 458
459 // Open incognito and clear normal tabs from memory. 459 // Open incognito and clear normal tabs from memory.
460 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); 460 OpenNewIncognitoTabUsingUIAndEvictMainTabs();
461 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), 461 GREYAssertTrue(chrome_test_util::IsIncognitoMode(),
462 @"Failed to switch to incognito mode"); 462 @"Failed to switch to incognito mode");
463 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 0, failureBlock); 463 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 0, failureBlock);
464 464
465 // Switch back to the normal tabs. 465 // Switch back to the normal tabs.
466 SwitchToNormalMode(); 466 SwitchToNormalMode();
467 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 467 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
468 kURL2FirstWord)] 468 kURL2FirstWord)]
469 assertWithMatcher:grey_notNil()]; 469 assertWithMatcher:grey_notNil()];
470 470
471 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); 471 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1);
472 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2); 472 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2);
473 [[EarlGrey 473 [[EarlGrey
474 selectElementWithMatcher:chrome_test_util::omniboxText(url2.GetContent())] 474 selectElementWithMatcher:chrome_test_util::OmniboxText(url2.GetContent())]
475 assertWithMatcher:grey_notNil()]; 475 assertWithMatcher:grey_notNil()];
476 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock); 476 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock);
477 477
478 chrome_test_util::SelectTabAtIndexInCurrentMode(0); 478 chrome_test_util::SelectTabAtIndexInCurrentMode(0);
479 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 479 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
480 kURL1FirstWord)] 480 kURL1FirstWord)]
481 assertWithMatcher:grey_notNil()]; 481 assertWithMatcher:grey_notNil()];
482 [[EarlGrey 482 [[EarlGrey
483 selectElementWithMatcher:chrome_test_util::omniboxText(url1.GetContent())] 483 selectElementWithMatcher:chrome_test_util::OmniboxText(url1.GetContent())]
484 assertWithMatcher:grey_notNil()]; 484 assertWithMatcher:grey_notNil()];
485 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 2, failureBlock); 485 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 2, failureBlock);
486 } 486 }
487 487
488 // Verify correct recording of metrics when the reloading of an evicted tab 488 // Verify correct recording of metrics when the reloading of an evicted tab
489 // succeeds. 489 // succeeds.
490 - (void)testEvictedTabReloadSuccess { 490 - (void)testEvictedTabReloadSuccess {
491 web::test::SetUpFileBasedHttpServer(); 491 web::test::SetUpFileBasedHttpServer();
492 chrome_test_util::HistogramTester histogramTester; 492 chrome_test_util::HistogramTester histogramTester;
493 FailureBlock failureBlock = ^(NSString* error) { 493 FailureBlock failureBlock = ^(NSString* error) {
494 GREYFail(error); 494 GREYFail(error);
495 }; 495 };
496 496
497 GURL URL = web::test::HttpServer::MakeUrl(kTestUrl1); 497 GURL URL = web::test::HttpServer::MakeUrl(kTestUrl1);
498 NewMainTabWithURL(URL, kURL1FirstWord); 498 NewMainTabWithURL(URL, kURL1FirstWord);
499 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); 499 OpenNewIncognitoTabUsingUIAndEvictMainTabs();
500 SwitchToNormalMode(); 500 SwitchToNormalMode();
501 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 501 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
502 kURL1FirstWord)] 502 kURL1FirstWord)]
503 assertWithMatcher:grey_notNil()]; 503 assertWithMatcher:grey_notNil()];
504 504
505 histogramTester.ExpectUniqueSample(kEvictedTabReloadSuccessRate, 505 histogramTester.ExpectUniqueSample(kEvictedTabReloadSuccessRate,
506 TabUsageRecorder::LOAD_SUCCESS, 1, 506 TabUsageRecorder::LOAD_SUCCESS, 1,
507 failureBlock); 507 failureBlock);
508 histogramTester.ExpectUniqueSample(kDidUserWaitForEvictedTabReload, 508 histogramTester.ExpectUniqueSample(kDidUserWaitForEvictedTabReload,
509 TabUsageRecorder::USER_WAITED, 1, 509 TabUsageRecorder::USER_WAITED, 1,
510 failureBlock); 510 failureBlock);
511 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock); 511 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 forConfigKey:kGREYConfigKeySynchronizationEnabled]; 646 forConfigKey:kGREYConfigKeySynchronizationEnabled];
647 OpenSettingsMenuUnsynced(); 647 OpenSettingsMenuUnsynced();
648 OpenSettingsSubMenuUnsynced(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); 648 OpenSettingsSubMenuUnsynced(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY);
649 Wait(grey_accessibilityID(kPrivacyCollectionViewId), 649 Wait(grey_accessibilityID(kPrivacyCollectionViewId),
650 @"Privacy settings view."); 650 @"Privacy settings view.");
651 651
652 WaitAndTap(grey_accessibilityLabel( 652 WaitAndTap(grey_accessibilityLabel(
653 l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)), 653 l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON)),
654 @"Close settings"); 654 @"Close settings");
655 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; 655 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
656 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 656 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
657 responses[slowURL])] 657 responses[slowURL])]
658 assertWithMatcher:grey_notNil()]; 658 assertWithMatcher:grey_notNil()];
659 659
660 [[GREYConfiguration sharedInstance] 660 [[GREYConfiguration sharedInstance]
661 setValue:@(YES) 661 setValue:@(YES)
662 forConfigKey:kGREYConfigKeySynchronizationEnabled]; 662 forConfigKey:kGREYConfigKeySynchronizationEnabled];
663 663
664 histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload, 664 histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload,
665 TabUsageRecorder::USER_DID_NOT_WAIT, 0, 665 TabUsageRecorder::USER_DID_NOT_WAIT, 0,
666 failureBlock); 666 failureBlock);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 GURL redirectURL = web::test::HttpServer::MakeUrl( 750 GURL redirectURL = web::test::HttpServer::MakeUrl(
751 "http://ios/testing/data/http_server_files/redirect_refresh.html"); 751 "http://ios/testing/data/http_server_files/redirect_refresh.html");
752 GURL destinationURL = web::test::HttpServer::MakeUrl( 752 GURL destinationURL = web::test::HttpServer::MakeUrl(
753 "http://ios/testing/data/http_server_files/destination.html"); 753 "http://ios/testing/data/http_server_files/destination.html");
754 web::test::SetUpFileBasedHttpServer(); 754 web::test::SetUpFileBasedHttpServer();
755 chrome_test_util::HistogramTester histogramTester; 755 chrome_test_util::HistogramTester histogramTester;
756 ResetTabUsageRecorder(); 756 ResetTabUsageRecorder();
757 757
758 NewMainTabWithURL(redirectURL, "arrived"); 758 NewMainTabWithURL(redirectURL, "arrived");
759 759
760 [[EarlGrey selectElementWithMatcher:chrome_test_util::omniboxText( 760 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
761 destinationURL.GetContent())] 761 destinationURL.GetContent())]
762 assertWithMatcher:grey_notNil()]; 762 assertWithMatcher:grey_notNil()];
763 763
764 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; 764 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1;
765 chrome_test_util::OpenNewTab(); 765 chrome_test_util::OpenNewTab();
766 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); 766 OpenNewIncognitoTabUsingUIAndEvictMainTabs();
767 SwitchToNormalMode(); 767 SwitchToNormalMode();
768 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); 768 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex);
769 [[EarlGrey selectElementWithMatcher:chrome_test_util::webViewContainingText( 769 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
770 "arrived")] 770 "arrived")]
771 assertWithMatcher:grey_notNil()]; 771 assertWithMatcher:grey_notNil()];
772 772
773 FailureBlock failureBlock = ^(NSString* error) { 773 FailureBlock failureBlock = ^(NSString* error) {
774 GREYFail(error); 774 GREYFail(error);
775 }; 775 };
776 // Verify that one page-load count has been recorded. It should contain a 776 // Verify that one page-load count has been recorded. It should contain a
777 // sum of 1 - one sample with 1 page load. 777 // sum of 1 - one sample with 1 page load.
778 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1, 778 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1,
779 failureBlock); 779 failureBlock);
(...skipping 24 matching lines...) Expand all
804 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); 804 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses));
805 chrome_test_util::HistogramTester histogramTester; 805 chrome_test_util::HistogramTester histogramTester;
806 ResetTabUsageRecorder(); 806 ResetTabUsageRecorder();
807 807
808 // Open a tab with a link to click. 808 // Open a tab with a link to click.
809 NewMainTabWithURL(initialURL, "link"); 809 NewMainTabWithURL(initialURL, "link");
810 // Click the link. 810 // Click the link.
811 chrome_test_util::TapWebViewElementWithId("link"); 811 chrome_test_util::TapWebViewElementWithId("link");
812 812
813 [[EarlGrey 813 [[EarlGrey
814 selectElementWithMatcher:chrome_test_util::webViewContainingText("Whee")] 814 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")]
815 assertWithMatcher:grey_notNil()]; 815 assertWithMatcher:grey_notNil()];
816 816
817 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; 817 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1;
818 chrome_test_util::OpenNewTab(); 818 chrome_test_util::OpenNewTab();
819 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); 819 OpenNewIncognitoTabUsingUIAndEvictMainTabs();
820 SwitchToNormalMode(); 820 SwitchToNormalMode();
821 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); 821 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex);
822 [[EarlGrey 822 [[EarlGrey
823 selectElementWithMatcher:chrome_test_util::webViewContainingText("Whee")] 823 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")]
824 assertWithMatcher:grey_notNil()]; 824 assertWithMatcher:grey_notNil()];
825 825
826 // Verify that the page-load count has been recorded. It should contain a 826 // Verify that the page-load count has been recorded. It should contain a
827 // sum of 2 - one sample with 2 page loads. 827 // sum of 2 - one sample with 2 page loads.
828 std::unique_ptr<base::HistogramSamples> samples = 828 std::unique_ptr<base::HistogramSamples> samples =
829 histogramTester.GetHistogramSamplesSinceCreation( 829 histogramTester.GetHistogramSamplesSinceCreation(
830 kPageLoadsBeforeEvictedTabSelected); 830 kPageLoadsBeforeEvictedTabSelected);
831 int sampleSum = samples->sum(); 831 int sampleSum = samples->sum();
832 GREYAssertEqual( 832 GREYAssertEqual(
833 sampleSum, 2, 833 sampleSum, 2,
(...skipping 27 matching lines...) Expand all
861 responses[destinationURL] = "Whee!"; 861 responses[destinationURL] = "Whee!";
862 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); 862 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses));
863 chrome_test_util::HistogramTester histogramTester; 863 chrome_test_util::HistogramTester histogramTester;
864 ResetTabUsageRecorder(); 864 ResetTabUsageRecorder();
865 865
866 // Open a tab with a link to click. 866 // Open a tab with a link to click.
867 NewMainTabWithURL(initialURL, "link"); 867 NewMainTabWithURL(initialURL, "link");
868 868
869 int numberOfTabs = chrome_test_util::GetMainTabCount(); 869 int numberOfTabs = chrome_test_util::GetMainTabCount();
870 [[EarlGrey 870 [[EarlGrey
871 selectElementWithMatcher:chrome_test_util::webViewContainingText("link")] 871 selectElementWithMatcher:chrome_test_util::WebViewContainingText("link")]
872 performAction:grey_longPress()]; 872 performAction:grey_longPress()];
873 873
874 [[EarlGrey 874 [[EarlGrey
875 selectElementWithMatcher:grey_text(l10n_util::GetNSString( 875 selectElementWithMatcher:grey_text(l10n_util::GetNSString(
876 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB))] 876 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB))]
877 performAction:grey_tap()]; 877 performAction:grey_tap()];
878 chrome_test_util::AssertMainTabCount(numberOfTabs + 1); 878 chrome_test_util::AssertMainTabCount(numberOfTabs + 1);
879 879
880 SelectTabUsingUI(base::SysUTF8ToNSString(destinationURL.GetContent())); 880 SelectTabUsingUI(base::SysUTF8ToNSString(destinationURL.GetContent()));
881 881
882 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; 882 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
883 [[EarlGrey 883 [[EarlGrey
884 selectElementWithMatcher:chrome_test_util::webViewContainingText("Whee")] 884 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")]
885 assertWithMatcher:grey_notNil()]; 885 assertWithMatcher:grey_notNil()];
886 886
887 FailureBlock failureBlock = ^(NSString* error) { 887 FailureBlock failureBlock = ^(NSString* error) {
888 GREYFail(error); 888 GREYFail(error);
889 }; 889 };
890 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 1, failureBlock); 890 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 1, failureBlock);
891 histogramTester.ExpectBucketCount( 891 histogramTester.ExpectBucketCount(
892 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock); 892 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock);
893 } 893 }
894 894
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; 956 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
957 } 957 }
958 // The deleted tabs are purged during foregrounding and backgrounding. 958 // The deleted tabs are purged during foregrounding and backgrounding.
959 chrome_test_util::SimulateTabsBackgrounding(); 959 chrome_test_util::SimulateTabsBackgrounding();
960 // Make sure |evicted_tabs_| purged the deleted tabs. 960 // Make sure |evicted_tabs_| purged the deleted tabs.
961 int evicted = chrome_test_util::GetEvictedMainTabCount(); 961 int evicted = chrome_test_util::GetEvictedMainTabCount();
962 GREYAssertEqual(evicted, 0, @"Check number of evicted tabs"); 962 GREYAssertEqual(evicted, 0, @"Check number of evicted tabs");
963 } 963 }
964 964
965 @end 965 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698