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

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

Powered by Google App Engine
This is Rietveld 408576698