Commit c1b16b70 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Additional fixes for UserAgent tests

This is making sure that the tests are passing when the flag to use the
UserAgent of the WebClients is enabled or disabled.

Bug: none
Change-Id: If61994b6c6ec13327475e4f2f525a93ea121ed1a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332606
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795482}
parent b1f0c857
......@@ -124,32 +124,26 @@ class UserAgentResponseProvider : public web::DataResponseProvider {
#pragma mark - Helpers
- (BOOL)isMobileByDefault {
return web::features::UseWebClientDefaultUserAgent()
? ![ChromeEarlGrey isIPadIdiom]
: YES;
}
- (GREYElementInteraction*)defaultRequestButton {
if ([self isMobileByDefault])
if ([ChromeEarlGrey isMobileModeByDefault])
return RequestDesktopButton();
return RequestMobileButton();
}
- (GREYElementInteraction*)nonDefaultRequestButton {
if ([self isMobileByDefault])
if ([ChromeEarlGrey isMobileModeByDefault])
return RequestMobileButton();
return RequestDesktopButton();
}
- (std::string)defaultLabel {
if ([self isMobileByDefault])
if ([ChromeEarlGrey isMobileModeByDefault])
return kMobileSiteLabel;
return kDesktopSiteLabel;
}
- (std::string)nonDefaultLabel {
if ([self isMobileByDefault])
if ([ChromeEarlGrey isMobileModeByDefault])
return kDesktopSiteLabel;
return kMobileSiteLabel;
}
......@@ -416,7 +410,7 @@ class UserAgentResponseProvider : public web::DataResponseProvider {
std::string defaultPlatform;
std::string nonDefaultPlatform;
if ([self isMobileByDefault]) {
if ([ChromeEarlGrey isMobileModeByDefault]) {
defaultPlatform = base::SysNSStringToUTF8([[UIDevice currentDevice] model]);
if (@available(iOS 13, *)) {
nonDefaultPlatform = kDesktopPlatformLabel;
......
......@@ -80,10 +80,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
// Returns the platform name of the current device.
std::string platform() {
BOOL isMobileByDefault = web::features::UseWebClientDefaultUserAgent()
? ![ChromeEarlGrey isIPadIdiom]
: YES;
return isMobileByDefault
return [ChromeEarlGrey isMobileModeByDefault]
? base::SysNSStringToUTF8([[UIDevice currentDevice] model])
: "MacIntel";
}
......
......@@ -520,6 +520,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// with custom WebKit frameworks.
- (BOOL)isCustomWebKitLoadedIfRequested WARN_UNUSED_RESULT;
// Returns whether the mobile version of the websites are requested by default.
- (BOOL)isMobileModeByDefault WARN_UNUSED_RESULT;
#pragma mark - Popup Blocking
// Gets the current value of the popup content setting preference for the
......
......@@ -928,6 +928,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return [ChromeEarlGreyAppInterface isCustomWebKitLoadedIfRequested];
}
- (BOOL)isMobileModeByDefault {
return [ChromeEarlGreyAppInterface isMobileModeByDefault];
}
#pragma mark - ScopedBlockPopupsPref
- (ContentSetting)popupPrefValue {
......
......@@ -427,6 +427,9 @@
// Returns YES if collections are presented in cards.
+ (BOOL)isCollectionsCardPresentationStyleEnabled WARN_UNUSED_RESULT;
// Returns whether the mobile version of the websites are requested by default.
+ (BOOL)isMobileModeByDefault WARN_UNUSED_RESULT;
#pragma mark - Popup Blocking
// Gets the current value of the popup content setting preference for the
......
......@@ -751,6 +751,17 @@ NSString* SerializedPref(const PrefService::Preference* pref) {
return IsCollectionsCardPresentationStyleEnabled();
}
+ (BOOL)isMobileModeByDefault {
if (!web::features::UseWebClientDefaultUserAgent())
return YES;
web::UserAgentType webClientUserAgent =
web::GetWebClient()->GetDefaultUserAgent(
chrome_test_util::GetCurrentWebState()->GetView(), GURL());
return webClientUserAgent == web::UserAgentType::MOBILE;
}
#pragma mark - ScopedBlockPopupsPref
+ (ContentSetting)popupPrefValue {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment