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 { ...@@ -124,32 +124,26 @@ class UserAgentResponseProvider : public web::DataResponseProvider {
#pragma mark - Helpers #pragma mark - Helpers
- (BOOL)isMobileByDefault {
return web::features::UseWebClientDefaultUserAgent()
? ![ChromeEarlGrey isIPadIdiom]
: YES;
}
- (GREYElementInteraction*)defaultRequestButton { - (GREYElementInteraction*)defaultRequestButton {
if ([self isMobileByDefault]) if ([ChromeEarlGrey isMobileModeByDefault])
return RequestDesktopButton(); return RequestDesktopButton();
return RequestMobileButton(); return RequestMobileButton();
} }
- (GREYElementInteraction*)nonDefaultRequestButton { - (GREYElementInteraction*)nonDefaultRequestButton {
if ([self isMobileByDefault]) if ([ChromeEarlGrey isMobileModeByDefault])
return RequestMobileButton(); return RequestMobileButton();
return RequestDesktopButton(); return RequestDesktopButton();
} }
- (std::string)defaultLabel { - (std::string)defaultLabel {
if ([self isMobileByDefault]) if ([ChromeEarlGrey isMobileModeByDefault])
return kMobileSiteLabel; return kMobileSiteLabel;
return kDesktopSiteLabel; return kDesktopSiteLabel;
} }
- (std::string)nonDefaultLabel { - (std::string)nonDefaultLabel {
if ([self isMobileByDefault]) if ([ChromeEarlGrey isMobileModeByDefault])
return kDesktopSiteLabel; return kDesktopSiteLabel;
return kMobileSiteLabel; return kMobileSiteLabel;
} }
...@@ -416,7 +410,7 @@ class UserAgentResponseProvider : public web::DataResponseProvider { ...@@ -416,7 +410,7 @@ class UserAgentResponseProvider : public web::DataResponseProvider {
std::string defaultPlatform; std::string defaultPlatform;
std::string nonDefaultPlatform; std::string nonDefaultPlatform;
if ([self isMobileByDefault]) { if ([ChromeEarlGrey isMobileModeByDefault]) {
defaultPlatform = base::SysNSStringToUTF8([[UIDevice currentDevice] model]); defaultPlatform = base::SysNSStringToUTF8([[UIDevice currentDevice] model]);
if (@available(iOS 13, *)) { if (@available(iOS 13, *)) {
nonDefaultPlatform = kDesktopPlatformLabel; nonDefaultPlatform = kDesktopPlatformLabel;
......
...@@ -80,10 +80,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest( ...@@ -80,10 +80,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleRequest(
// Returns the platform name of the current device. // Returns the platform name of the current device.
std::string platform() { std::string platform() {
BOOL isMobileByDefault = web::features::UseWebClientDefaultUserAgent() return [ChromeEarlGrey isMobileModeByDefault]
? ![ChromeEarlGrey isIPadIdiom]
: YES;
return isMobileByDefault
? base::SysNSStringToUTF8([[UIDevice currentDevice] model]) ? base::SysNSStringToUTF8([[UIDevice currentDevice] model])
: "MacIntel"; : "MacIntel";
} }
......
...@@ -520,6 +520,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -520,6 +520,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// with custom WebKit frameworks. // with custom WebKit frameworks.
- (BOOL)isCustomWebKitLoadedIfRequested WARN_UNUSED_RESULT; - (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 #pragma mark - Popup Blocking
// Gets the current value of the popup content setting preference for the // Gets the current value of the popup content setting preference for the
......
...@@ -928,6 +928,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -928,6 +928,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return [ChromeEarlGreyAppInterface isCustomWebKitLoadedIfRequested]; return [ChromeEarlGreyAppInterface isCustomWebKitLoadedIfRequested];
} }
- (BOOL)isMobileModeByDefault {
return [ChromeEarlGreyAppInterface isMobileModeByDefault];
}
#pragma mark - ScopedBlockPopupsPref #pragma mark - ScopedBlockPopupsPref
- (ContentSetting)popupPrefValue { - (ContentSetting)popupPrefValue {
......
...@@ -427,6 +427,9 @@ ...@@ -427,6 +427,9 @@
// Returns YES if collections are presented in cards. // Returns YES if collections are presented in cards.
+ (BOOL)isCollectionsCardPresentationStyleEnabled WARN_UNUSED_RESULT; + (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 #pragma mark - Popup Blocking
// Gets the current value of the popup content setting preference for the // Gets the current value of the popup content setting preference for the
......
...@@ -751,6 +751,17 @@ NSString* SerializedPref(const PrefService::Preference* pref) { ...@@ -751,6 +751,17 @@ NSString* SerializedPref(const PrefService::Preference* pref) {
return IsCollectionsCardPresentationStyleEnabled(); 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 #pragma mark - ScopedBlockPopupsPref
+ (ContentSetting)popupPrefValue { + (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