Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <UIKit/UIKit.h> | 6 #import <UIKit/UIKit.h> |
| 7 #import <XCTest/XCTest.h> | 7 #import <XCTest/XCTest.h> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 - (void)openPasswordSettings { | 456 - (void)openPasswordSettings { |
| 457 // Open settings and verify data in the view controller. | 457 // Open settings and verify data in the view controller. |
| 458 [ChromeEarlGreyUI openToolsMenu]; | 458 [ChromeEarlGreyUI openToolsMenu]; |
| 459 [[EarlGrey | 459 [[EarlGrey |
| 460 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)] | 460 selectElementWithMatcher:grey_accessibilityID(kToolsMenuSettingsId)] |
| 461 performAction:grey_tap()]; | 461 performAction:grey_tap()]; |
| 462 [[EarlGrey selectElementWithMatcher:PasswordsButton()] | 462 [[EarlGrey selectElementWithMatcher:PasswordsButton()] |
| 463 performAction:grey_tap()]; | 463 performAction:grey_tap()]; |
| 464 } | 464 } |
| 465 | 465 |
| 466 - (void)setMetricsReportingEnabled:(BOOL)reportingEnabled | |
| 467 wifiOnly:(BOOL)wifiOnly { | |
| 468 chrome_test_util::SetBooleanLocalStatePref( | |
| 469 metrics::prefs::kMetricsReportingEnabled, reportingEnabled); | |
| 470 chrome_test_util::SetBooleanLocalStatePref(prefs::kMetricsReportingWifiOnly, | |
| 471 wifiOnly); | |
| 472 // Breakpad uses dispatch_async to update its state. Wait to get to a | |
| 473 // consistent state. | |
| 474 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | |
| 475 } | |
| 476 | |
| 466 // Checks for a given service that it is both recording and uploading, where | 477 // Checks for a given service that it is both recording and uploading, where |
| 467 // appropriate. | 478 // appropriate. |
| 468 - (void)assertMetricsServiceEnabled:(MetricsServiceType)serviceType { | 479 - (void)assertMetricsServiceEnabled:(MetricsServiceType)serviceType { |
| 469 switch (serviceType) { | 480 switch (serviceType) { |
| 470 case kMetrics: | 481 case kMetrics: |
| 471 GREYAssertTrue(chrome_test_util::IsMetricsRecordingEnabled(), | 482 GREYAssertTrue(chrome_test_util::IsMetricsRecordingEnabled(), |
| 472 @"Metrics recording should be enabled."); | 483 @"Metrics recording should be enabled."); |
| 473 GREYAssertTrue(chrome_test_util::IsMetricsReportingEnabled(), | 484 GREYAssertTrue(chrome_test_util::IsMetricsReportingEnabled(), |
| 474 @"Metrics reporting should be enabled."); | 485 @"Metrics reporting should be enabled."); |
| 475 break; | 486 break; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly ON | 562 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly ON |
| 552 // - Services record data and upload data only when the device is using | 563 // - Services record data and upload data only when the device is using |
| 553 // a wifi connection. Note: rather than checking for wifi, the code | 564 // a wifi connection. Note: rather than checking for wifi, the code |
| 554 // checks for a cellular network (wwan). wwan != wifi. So if wwan is | 565 // checks for a cellular network (wwan). wwan != wifi. So if wwan is |
| 555 // true, services do not upload any data. | 566 // true, services do not upload any data. |
| 556 | 567 |
| 557 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly OFF | 568 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly OFF |
| 558 // - Services record data and upload data. | 569 // - Services record data and upload data. |
| 559 | 570 |
| 560 // kMetricsReportingEnabled OFF and kMetricsReportingWifiOnly OFF | 571 // kMetricsReportingEnabled OFF and kMetricsReportingWifiOnly OFF |
| 561 chrome_test_util::SetBooleanLocalStatePref( | 572 [self setMetricsReportingEnabled:NO wifiOnly:NO]; |
| 562 metrics::prefs::kMetricsReportingEnabled, NO); | |
| 563 chrome_test_util::SetBooleanLocalStatePref(prefs::kMetricsReportingWifiOnly, | |
| 564 NO); | |
| 565 // Service should be completely disabled. | 573 // Service should be completely disabled. |
| 566 // I.e. no recording of data, and no uploading of what's been recorded. | 574 // I.e. no recording of data, and no uploading of what's been recorded. |
| 567 [self assertMetricsServiceDisabled:serviceType]; | 575 [self assertMetricsServiceDisabled:serviceType]; |
| 568 | 576 |
| 569 // kMetricsReportingEnabled OFF and kMetricsReportingWifiOnly ON | 577 // kMetricsReportingEnabled OFF and kMetricsReportingWifiOnly ON |
| 570 chrome_test_util::SetBooleanLocalStatePref( | 578 [self setMetricsReportingEnabled:NO wifiOnly:YES]; |
| 571 metrics::prefs::kMetricsReportingEnabled, NO); | |
| 572 chrome_test_util::SetBooleanLocalStatePref(prefs::kMetricsReportingWifiOnly, | |
| 573 YES); | |
| 574 // If kMetricsReportingEnabled is OFF, any service should remain completely | 579 // If kMetricsReportingEnabled is OFF, any service should remain completely |
| 575 // disabled, i.e. no uploading even if kMetricsReportingWifiOnly is ON. | 580 // disabled, i.e. no uploading even if kMetricsReportingWifiOnly is ON. |
| 576 [self assertMetricsServiceDisabled:serviceType]; | 581 [self assertMetricsServiceDisabled:serviceType]; |
| 577 | 582 |
| 578 // Split here: Official build vs. Development build. | 583 // Split here: Official build vs. Development build. |
| 579 // Official builds allow recording and uploading of data, honoring the | 584 // Official builds allow recording and uploading of data, honoring the |
| 580 // metrics prefs. Development builds should never record or upload data. | 585 // metrics prefs. Development builds should never record or upload data. |
| 581 #if defined(GOOGLE_CHROME_BUILD) | 586 #if defined(GOOGLE_CHROME_BUILD) |
| 582 // Official build. | 587 // Official build. |
| 583 // The values of the prefs and the wwan vs wifi state should be honored by | 588 // The values of the prefs and the wwan vs wifi state should be honored by |
| 584 // the services, turning on and off according to the rules laid out above. | 589 // the services, turning on and off according to the rules laid out above. |
| 585 | 590 |
| 586 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly ON. | 591 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly ON. |
| 587 chrome_test_util::SetBooleanLocalStatePref( | 592 [self setMetricsReportingEnabled:YES wifiOnly:YES]; |
| 588 metrics::prefs::kMetricsReportingEnabled, YES); | |
| 589 chrome_test_util::SetBooleanLocalStatePref(prefs::kMetricsReportingWifiOnly, | |
| 590 YES); | |
| 591 // Service should be enabled. | 593 // Service should be enabled. |
| 592 [self assertMetricsServiceEnabled:serviceType]; | 594 [self assertMetricsServiceEnabled:serviceType]; |
| 593 | 595 |
| 594 // Set the network to use a cellular network, which should disable uploading | 596 // Set the network to use a cellular network, which should disable uploading |
| 595 // when the wifi-only flag is set. | 597 // when the wifi-only flag is set. |
| 596 chrome_test_util::SetWWANStateTo(YES); | 598 chrome_test_util::SetWWANStateTo(YES); |
|
Olivier
2017/03/24 16:18:23
Should we drainUntilIdle here too?
lpromero
2017/03/24 17:48:17
No because under the hood this is synchronous, unl
lpromero
2017/03/28 13:31:41
Ooops… Yes this is needed as SetWWANStateTo calls
| |
| 597 [self assertMetricsServiceEnabledButNotUploading:serviceType]; | 599 [self assertMetricsServiceEnabledButNotUploading:serviceType]; |
| 598 | 600 |
| 599 // Turn off cellular network usage, which should enable uploading. | 601 // Turn off cellular network usage, which should enable uploading. |
| 600 chrome_test_util::SetWWANStateTo(NO); | 602 chrome_test_util::SetWWANStateTo(NO); |
| 601 [self assertMetricsServiceEnabled:serviceType]; | 603 [self assertMetricsServiceEnabled:serviceType]; |
| 602 | 604 |
| 603 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly OFF | 605 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly OFF |
| 604 chrome_test_util::SetBooleanLocalStatePref( | 606 [self setMetricsReportingEnabled:YES wifiOnly:NO]; |
| 605 metrics::prefs::kMetricsReportingEnabled, YES); | |
| 606 chrome_test_util::SetBooleanLocalStatePref(prefs::kMetricsReportingWifiOnly, | |
| 607 NO); | |
| 608 [self assertMetricsServiceEnabled:serviceType]; | 607 [self assertMetricsServiceEnabled:serviceType]; |
| 609 #else | 608 #else |
| 610 // Development build. Do not allow any recording or uploading of data. | 609 // Development build. Do not allow any recording or uploading of data. |
| 611 // Specifically, the kMetricsReportingEnabled preference is completely | 610 // Specifically, the kMetricsReportingEnabled preference is completely |
| 612 // disregarded for non-official builds, and checking its value always returns | 611 // disregarded for non-official builds, and checking its value always returns |
| 613 // false (NO). | 612 // false (NO). |
| 614 // This tests that no matter the state change, pref or network connection, | 613 // This tests that no matter the state change, pref or network connection, |
| 615 // services remain disabled. | 614 // services remain disabled. |
| 616 | 615 |
| 617 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly ON | 616 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly ON |
| 618 chrome_test_util::SetBooleanLocalStatePref( | 617 [self setMetricsReportingEnabled:YES wifiOnly:YES]; |
| 619 metrics::prefs::kMetricsReportingEnabled, YES); | |
| 620 chrome_test_util::SetBooleanLocalStatePref(prefs::kMetricsReportingWifiOnly, | |
| 621 YES); | |
| 622 // Service should remain disabled. | 618 // Service should remain disabled. |
| 623 [self assertMetricsServiceDisabled:serviceType]; | 619 [self assertMetricsServiceDisabled:serviceType]; |
| 624 | 620 |
| 625 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly OFF | 621 // kMetricsReportingEnabled ON and kMetricsReportingWifiOnly OFF |
| 626 chrome_test_util::SetBooleanLocalStatePref( | 622 [self setMetricsReportingEnabled:YES wifiOnly:NO]; |
| 627 metrics::prefs::kMetricsReportingEnabled, YES); | |
| 628 chrome_test_util::SetBooleanLocalStatePref(prefs::kMetricsReportingWifiOnly, | |
| 629 NO); | |
| 630 // Service should remain disabled. | 623 // Service should remain disabled. |
| 631 [self assertMetricsServiceDisabled:serviceType]; | 624 [self assertMetricsServiceDisabled:serviceType]; |
| 632 #endif | 625 #endif |
| 633 } | 626 } |
| 634 | 627 |
| 635 #pragma mark Tests | 628 #pragma mark Tests |
| 636 | 629 |
| 637 // Tests that clearing the cookies through the UI does clear all of them. Use a | 630 // Tests that clearing the cookies through the UI does clear all of them. Use a |
| 638 // local server to navigate to a page that sets then tests a cookie, and then | 631 // local server to navigate to a page that sets then tests a cookie, and then |
| 639 // clears the cookie and tests it is not set. | 632 // clears the cookie and tests it is not set. |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1034 performAction:grey_tap()]; | 1027 performAction:grey_tap()]; |
| 1035 [[EarlGrey selectElementWithMatcher:PrivacyButton()] | 1028 [[EarlGrey selectElementWithMatcher:PrivacyButton()] |
| 1036 performAction:grey_tap()]; | 1029 performAction:grey_tap()]; |
| 1037 [[EarlGrey selectElementWithMatcher:SendUsageDataButton()] | 1030 [[EarlGrey selectElementWithMatcher:SendUsageDataButton()] |
| 1038 performAction:grey_tap()]; | 1031 performAction:grey_tap()]; |
| 1039 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 1032 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 1040 [self closeSubSettingsMenu]; | 1033 [self closeSubSettingsMenu]; |
| 1041 } | 1034 } |
| 1042 | 1035 |
| 1043 @end | 1036 @end |
| OLD | NEW |