Skip to content

Commit

Permalink
[iOS] Add +[ChromeEarlGreyAppInterface setIntegerValue:forUserPref:]
Browse files Browse the repository at this point in the history
This change is needed for crrev.com/c/3059688.

Bug: 1232071
Change-Id: I88152341ce5e02932ee877be892dabd60eeecf4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3063972
Commit-Queue: Jérôme <jlebel@chromium.org>
Reviewed-by: Olivier Robin <olivierrobin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#907981}
  • Loading branch information
jlebel authored and Chromium LUCI CQ committed Aug 3, 2021
1 parent 1db90f6 commit 7846260
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ios/chrome/test/app/chrome_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ void SetBooleanUserPref(ChromeBrowserState* browser_state,
const char* pref_name,
bool value);

// Sets the value of an integer user pref in the given browser state.
void SetIntegerUserPref(ChromeBrowserState* browser_state,
const char* pref_name,
int value);

// Sets the state of using cellular network.
void SetWWANStateTo(bool value);

Expand Down
10 changes: 10 additions & 0 deletions ios/chrome/test/app/chrome_test_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ void SetBooleanUserPref(ChromeBrowserState* browser_state,
pref.SetValue(value);
}

void SetIntegerUserPref(ChromeBrowserState* browser_state,
const char* pref_name,
int value) {
DCHECK(browser_state);
DCHECK(browser_state->GetPrefs());
IntegerPrefMember pref;
pref.Init(pref_name, browser_state->GetPrefs());
pref.SetValue(value);
}

void SetWWANStateTo(bool value) {
MainController* mainController = chrome_test_util::GetMainController();
net::NetworkChangeNotifier::ConnectionType connectionType =
Expand Down
3 changes: 2 additions & 1 deletion ios/chrome/test/earl_grey/chrome_earl_grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,8 +682,9 @@ UIWindow* GetAnyKeyWindow();
- (int)userIntegerPref:(const std::string&)prefName;
- (std::string)userStringPref:(const std::string&)prefName;

// Sets the value of a boolean user pref in the original browser state.
// Sets the value of a user pref in the original browser state.
- (void)setBoolValue:(BOOL)value forUserPref:(const std::string&)UTF8PrefName;
- (void)setIntegerValue:(int)value forUserPref:(const std::string&)UTF8PrefName;

// Resets the BrowsingDataPrefs, which defines if its selected or not when
// clearing Browsing data.
Expand Down
7 changes: 7 additions & 0 deletions ios/chrome/test/earl_grey/chrome_earl_grey.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,13 @@ - (void)setBoolValue:(BOOL)value forUserPref:(const std::string&)UTF8PrefName {
return [ChromeEarlGreyAppInterface setBoolValue:value forUserPref:prefName];
}

- (void)setIntegerValue:(int)value
forUserPref:(const std::string&)UTF8PrefName {
NSString* prefName = base::SysUTF8ToNSString(UTF8PrefName);
return [ChromeEarlGreyAppInterface setIntegerValue:value
forUserPref:prefName];
}

- (void)resetBrowsingDataPrefs {
return [ChromeEarlGreyAppInterface resetBrowsingDataPrefs];
}
Expand Down
3 changes: 3 additions & 0 deletions ios/chrome/test/earl_grey/chrome_earl_grey_app_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,9 @@
// Sets the value of a boolean user pref in the original browser state.
+ (void)setBoolValue:(BOOL)value forUserPref:(NSString*)prefName;

// Sets the value of a integer user pref in the original browser state.
+ (void)setIntegerValue:(int)value forUserPref:(NSString*)prefName;

// Resets the BrowsingDataPrefs, which defines if its selected or not when
// clearing Browsing data.
+ (void)resetBrowsingDataPrefs;
Expand Down
6 changes: 6 additions & 0 deletions ios/chrome/test/earl_grey/chrome_earl_grey_app_interface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,12 @@ + (void)setBoolValue:(BOOL)value forUserPref:(NSString*)prefName {
base::SysNSStringToUTF8(prefName).c_str(), value);
}

+ (void)setIntegerValue:(int)value forUserPref:(NSString*)prefName {
chrome_test_util::SetIntegerUserPref(
chrome_test_util::GetOriginalBrowserState(),
base::SysNSStringToUTF8(prefName).c_str(), value);
}

+ (void)resetBrowsingDataPrefs {
PrefService* prefs = chrome_test_util::GetOriginalBrowserState()->GetPrefs();
prefs->ClearPref(browsing_data::prefs::kDeleteBrowsingHistory);
Expand Down

0 comments on commit 7846260

Please sign in to comment.