| 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 <XCTest/XCTest.h> | 6 #import <XCTest/XCTest.h> |
| 7 | 7 |
| 8 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "components/metrics/metrics_pref_names.h" | 10 #include "components/metrics/metrics_pref_names.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 // Returns a fake identity. | 35 // Returns a fake identity. |
| 36 ChromeIdentity* GetFakeIdentity() { | 36 ChromeIdentity* GetFakeIdentity() { |
| 37 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" | 37 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" |
| 38 gaiaID:@"fooID" | 38 gaiaID:@"fooID" |
| 39 name:@"Fake Foo"]; | 39 name:@"Fake Foo"]; |
| 40 } | 40 } |
| 41 | 41 |
| 42 // Taps the button with accessibility labelId |message_id|. | 42 // Taps the button with accessibility labelId |message_id|. |
| 43 void TapButtonWithLabelId(int message_id) { | 43 void TapButtonWithLabelId(int message_id) { |
| 44 id<GREYMatcher> matcher = chrome_test_util::buttonWithAccessibilityLabel( | 44 id<GREYMatcher> matcher = chrome_test_util::ButtonWithAccessibilityLabel( |
| 45 l10n_util::GetNSString(message_id)); | 45 l10n_util::GetNSString(message_id)); |
| 46 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; | 46 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Asserts that |identity| is actually signed in to the active profile. | 49 // Asserts that |identity| is actually signed in to the active profile. |
| 50 void AssertAuthenticatedIdentityInActiveProfile(ChromeIdentity* identity) { | 50 void AssertAuthenticatedIdentityInActiveProfile(ChromeIdentity* identity) { |
| 51 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 51 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 52 | 52 |
| 53 ios::ChromeBrowserState* browser_state = | 53 ios::ChromeBrowserState* browser_state = |
| 54 chrome_test_util::GetOriginalBrowserState(); | 54 chrome_test_util::GetOriginalBrowserState(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Toggle the UMA checkbox. | 126 // Toggle the UMA checkbox. |
| 127 - (void)testToggleMetricsOn { | 127 - (void)testToggleMetricsOn { |
| 128 [chrome_test_util::GetMainController() showFirstRunUI]; | 128 [chrome_test_util::GetMainController() showFirstRunUI]; |
| 129 | 129 |
| 130 id<GREYMatcher> metrics = | 130 id<GREYMatcher> metrics = |
| 131 grey_accessibilityID(kUMAMetricsButtonAccessibilityIdentifier); | 131 grey_accessibilityID(kUMAMetricsButtonAccessibilityIdentifier); |
| 132 [[EarlGrey selectElementWithMatcher:metrics] performAction:grey_tap()]; | 132 [[EarlGrey selectElementWithMatcher:metrics] performAction:grey_tap()]; |
| 133 | 133 |
| 134 id<GREYMatcher> optInAccept = chrome_test_util::buttonWithAccessibilityLabel( | 134 id<GREYMatcher> optInAccept = chrome_test_util::ButtonWithAccessibilityLabel( |
| 135 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON)); | 135 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON)); |
| 136 [[EarlGrey selectElementWithMatcher:optInAccept] performAction:grey_tap()]; | 136 [[EarlGrey selectElementWithMatcher:optInAccept] performAction:grey_tap()]; |
| 137 | 137 |
| 138 BOOL metricsOptIn = GetApplicationContext()->GetLocalState()->GetBoolean( | 138 BOOL metricsOptIn = GetApplicationContext()->GetLocalState()->GetBoolean( |
| 139 metrics::prefs::kMetricsReportingEnabled); | 139 metrics::prefs::kMetricsReportingEnabled); |
| 140 GREYAssert( | 140 GREYAssert( |
| 141 metricsOptIn != [WelcomeToChromeViewController defaultStatsCheckboxValue], | 141 metricsOptIn != [WelcomeToChromeViewController defaultStatsCheckboxValue], |
| 142 @"Metrics reporting pref is incorrect."); | 142 @"Metrics reporting pref is incorrect."); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Dismisses the first run screens. | 145 // Dismisses the first run screens. |
| 146 - (void)testDismissFirstRun { | 146 - (void)testDismissFirstRun { |
| 147 [chrome_test_util::GetMainController() showFirstRunUI]; | 147 [chrome_test_util::GetMainController() showFirstRunUI]; |
| 148 | 148 |
| 149 id<GREYMatcher> optInAccept = chrome_test_util::buttonWithAccessibilityLabel( | 149 id<GREYMatcher> optInAccept = chrome_test_util::ButtonWithAccessibilityLabel( |
| 150 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON)); | 150 l10n_util::GetNSString(IDS_IOS_FIRSTRUN_OPT_IN_ACCEPT_BUTTON)); |
| 151 [[EarlGrey selectElementWithMatcher:optInAccept] performAction:grey_tap()]; | 151 [[EarlGrey selectElementWithMatcher:optInAccept] performAction:grey_tap()]; |
| 152 | 152 |
| 153 PrefService* preferences = GetApplicationContext()->GetLocalState(); | 153 PrefService* preferences = GetApplicationContext()->GetLocalState(); |
| 154 GREYAssert( | 154 GREYAssert( |
| 155 preferences->GetBoolean(metrics::prefs::kMetricsReportingEnabled) == | 155 preferences->GetBoolean(metrics::prefs::kMetricsReportingEnabled) == |
| 156 [WelcomeToChromeViewController defaultStatsCheckboxValue], | 156 [WelcomeToChromeViewController defaultStatsCheckboxValue], |
| 157 @"Metrics reporting does not match."); | 157 @"Metrics reporting does not match."); |
| 158 | 158 |
| 159 id<GREYMatcher> skipSignIn = | 159 id<GREYMatcher> skipSignIn = |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 @"Sync shouldn't have finished its original setup yet"); | 215 @"Sync shouldn't have finished its original setup yet"); |
| 216 | 216 |
| 217 // Close Settings, user is still signed in and sync is now starting. | 217 // Close Settings, user is still signed in and sync is now starting. |
| 218 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); | 218 TapButtonWithLabelId(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON); |
| 219 AssertAuthenticatedIdentityInActiveProfile(identity); | 219 AssertAuthenticatedIdentityInActiveProfile(identity); |
| 220 GREYAssertTrue(sync_service->HasFinishedInitialSetup(), | 220 GREYAssertTrue(sync_service->HasFinishedInitialSetup(), |
| 221 @"Sync should have finished its original setup"); | 221 @"Sync should have finished its original setup"); |
| 222 } | 222 } |
| 223 | 223 |
| 224 @end | 224 @end |
| OLD | NEW |