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

[iOS] Request Mobile version of SRP when flag is enabled

This CL makes sure that, when the desktop version is requested by
default, when the flag to force the mobile version of the SRP is
enabled, the mobile version is actually requested.

Fixed: 1043637
Change-Id: Ie2f267583c88bbfc63d14383f3d87da00da73c20
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050264Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Auto-Submit: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740325}
parent abe2d750
......@@ -302,6 +302,7 @@ source_set("unit_tests_internal") {
"java_script_console/java_script_console_tab_helper_unittest.mm",
]
deps = [
":feature_flags",
":test_support",
":web_internal",
"//base",
......
......@@ -61,7 +61,8 @@ class ChromeWebClient : public web::WebClient {
base::OnceCallback<void(NSString*)> callback) override;
UIView* GetWindowedContainer() override;
bool ForceMobileVersionByDefault(const GURL& url) override;
web::UserAgentType GetDefaultUserAgent(UIView* web_view) override;
web::UserAgentType GetDefaultUserAgent(UIView* web_view,
const GURL& url) override;
private:
// Returns a string describing the product name and version, of the
......
......@@ -272,9 +272,12 @@ bool ChromeWebClient::ForceMobileVersionByDefault(const GURL& url) {
return false;
}
web::UserAgentType ChromeWebClient::GetDefaultUserAgent(UIView* web_view) {
web::UserAgentType ChromeWebClient::GetDefaultUserAgent(UIView* web_view,
const GURL& url) {
DCHECK(base::FeatureList::IsEnabled(
web::features::kUseDefaultUserAgentInWebClient));
if (ForceMobileVersionByDefault(url))
return web::UserAgentType::MOBILE;
BOOL isRegularRegular = web_view.traitCollection.horizontalSizeClass ==
UIUserInterfaceSizeClassRegular &&
web_view.traitCollection.verticalSizeClass ==
......
......@@ -19,6 +19,7 @@
#include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/passwords/password_manager_features.h"
#import "ios/chrome/browser/web/error_page_util.h"
#include "ios/chrome/browser/web/features.h"
#include "ios/web/common/features.h"
#import "ios/web/common/web_view_creation_util.h"
#import "ios/web/public/test/error_test_util.h"
......@@ -324,10 +325,13 @@ TEST_F(ChromeWebClientTest, PrepareErrorPageWithSSLInfo) {
// Tests the default user agent for different views.
TEST_F(ChromeWebClientTest, DefaultUserAgent) {
base::test::ScopedFeatureList scoped_feature_list;
scoped_feature_list.InitAndEnableFeature(
web::features::kUseDefaultUserAgentInWebClient);
scoped_feature_list.InitWithFeatures(
{web::features::kUseDefaultUserAgentInWebClient, web::kMobileGoogleSRP},
{});
ChromeWebClient web_client;
const GURL google_url = GURL("https://www.google.com/search?q=test");
const GURL non_google_url = GURL("http://wikipedia.org");
UITraitCollection* regular_vertical_size_class = [UITraitCollection
traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassRegular];
......@@ -362,29 +366,39 @@ TEST_F(ChromeWebClientTest, DefaultUserAgent) {
compact_horizontal_size_class
]];
// Check that desktop is returned for Regular x Regular.
// Check that desktop is returned for Regular x Regular on non-Google URLs.
id mock_regular_regular_view = OCMClassMock([UIView class]);
OCMStub([mock_regular_regular_view traitCollection])
.andReturn(regular_regular);
EXPECT_EQ(web::UserAgentType::DESKTOP,
web_client.GetDefaultUserAgent(mock_regular_regular_view));
web_client.GetDefaultUserAgent(mock_regular_regular_view,
non_google_url));
EXPECT_EQ(
web::UserAgentType::MOBILE,
web_client.GetDefaultUserAgent(mock_regular_regular_view, google_url));
// Check that mobile is returned for all other combinations.
id mock_regular_compact_view = OCMClassMock([UIView class]);
OCMStub([mock_regular_compact_view traitCollection])
.andReturn(regular_compact);
EXPECT_EQ(web::UserAgentType::MOBILE,
web_client.GetDefaultUserAgent(mock_regular_compact_view));
web_client.GetDefaultUserAgent(mock_regular_compact_view,
non_google_url));
EXPECT_EQ(
web::UserAgentType::MOBILE,
web_client.GetDefaultUserAgent(mock_regular_regular_view, google_url));
id mock_compact_regular_view = OCMClassMock([UIView class]);
OCMStub([mock_compact_regular_view traitCollection])
.andReturn(compact_regular);
EXPECT_EQ(web::UserAgentType::MOBILE,
web_client.GetDefaultUserAgent(mock_compact_regular_view));
web_client.GetDefaultUserAgent(mock_compact_regular_view,
non_google_url));
id mock_compact_compact_view = OCMClassMock([UIView class]);
OCMStub([mock_compact_compact_view traitCollection])
.andReturn(compact_compact);
EXPECT_EQ(web::UserAgentType::MOBILE,
web_client.GetDefaultUserAgent(mock_compact_compact_view));
web_client.GetDefaultUserAgent(mock_compact_compact_view,
non_google_url));
}
......@@ -176,7 +176,8 @@ void ReportOutOfSyncURLInDidStartProvisionalNavigation(
}
}
if (userAgentType == web::UserAgentType::AUTOMATIC) {
userAgentType = web::GetWebClient()->GetDefaultUserAgent(webView);
userAgentType = web::GetWebClient()->GetDefaultUserAgent(
webView, net::GURLWithNSURL(navigationAction.request.URL));
}
}
......
......@@ -196,8 +196,8 @@ class WebClient {
virtual bool ForceMobileVersionByDefault(const GURL& url);
// Returns the UserAgentType that should be used by default for the web
// content, based on the size class of |web_view|.
virtual UserAgentType GetDefaultUserAgent(UIView* web_view);
// content, based on the size class of |web_view| and the |url|.
virtual UserAgentType GetDefaultUserAgent(UIView* web_view, const GURL& url);
};
} // namespace web
......
......@@ -120,7 +120,8 @@ bool WebClient::ForceMobileVersionByDefault(const GURL&) {
return false;
}
UserAgentType WebClient::GetDefaultUserAgent(UIView* web_view) {
UserAgentType WebClient::GetDefaultUserAgent(UIView* web_view,
const GURL& url) {
return UserAgentType::MOBILE;
}
......
......@@ -569,7 +569,8 @@ enum class BackForwardNavigationType {
if (itemUserAgentType == web::UserAgentType::AUTOMATIC) {
DCHECK(base::FeatureList::IsEnabled(
web::features::kUseDefaultUserAgentInWebClient));
itemUserAgentType = web::GetWebClient()->GetDefaultUserAgent(self.webView);
itemUserAgentType = web::GetWebClient()->GetDefaultUserAgent(
self.webView, self.currentNavItem->GetURL());
self.currentNavItem->SetUserAgentType(
itemUserAgentType, /*update_inherited_user_agent =*/false);
} else if (itemUserAgentType == web::UserAgentType::NONE &&
......
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