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

[iOS] Fix tests for fullscreen refactoring

This CL fixes the tests so they can run with the fullscreen refactoring
flags enabled by default.
It also fixes an issue with the ntp_util functions.

Bug:none

Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: Iec703052548d3f7c024d47c30d7a429162144d85
Reviewed-on: https://chromium-review.googlesource.com/c/1261523Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600737}
parent 735437bf
......@@ -107,6 +107,8 @@ class SnapshotTabHelperTest : public PlatformTest {
CGRect frame = {CGPointZero, kWebStateViewSize};
UIView* view = [[UIView alloc] initWithFrame:frame];
view.backgroundColor = [UIColor redColor];
web_state_superview_ = [[UIView alloc] initWithFrame:frame];
[web_state_superview_ addSubview:view];
web_state_.SetView(view);
}
......@@ -139,6 +141,8 @@ class SnapshotTabHelperTest : public PlatformTest {
TabHelperSnapshotGeneratorDelegate* delegate_ = nil;
NSString* snapshot_session_id_ = nil;
web::TestWebState web_state_;
// The webState's view needs a superview so a snapshot can be taken.
UIView* web_state_superview_;
private:
DISALLOW_COPY_AND_ASSIGN(SnapshotTabHelperTest);
......
......@@ -27,6 +27,8 @@ class ChromeActivityItemThumbnailGeneratorTest : public PlatformTest {
CGRect frame = {CGPointZero, CGSizeMake(400, 300)};
UIView* view = [[UIView alloc] initWithFrame:frame];
view.backgroundColor = [UIColor redColor];
web_state_superview_ = [[UIView alloc] initWithFrame:frame];
[web_state_superview_ addSubview:view];
test_web_state_.SetView(view);
SnapshotTabHelper::CreateForWebState(&test_web_state_,
......@@ -47,6 +49,8 @@ class ChromeActivityItemThumbnailGeneratorTest : public PlatformTest {
base::test::ScopedTaskEnvironment task_environment_;
std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
web::TestWebState test_web_state_;
// The webState's view needs a superview so a snapshot can be taken.
UIView* web_state_superview_;
};
TEST_F(ChromeActivityItemThumbnailGeneratorTest, ThumbnailForNonIncognitoTab) {
......
......@@ -85,6 +85,8 @@ class ShareToDataBuilderTest : public PlatformTest {
CGRect frame = {CGPointZero, CGSizeMake(300, 400)};
UIView* view = [[UIView alloc] initWithFrame:frame];
view.backgroundColor = [UIColor blueColor];
web_state_superview_ = [[UIView alloc] initWithFrame:frame];
[web_state_superview_ addSubview:view];
web_state->SetView(view);
// Attach SnapshotTabHelper to allow snapshot generation.
......@@ -115,6 +117,8 @@ class ShareToDataBuilderTest : public PlatformTest {
web::TestWebThreadBundle thread_bundle_;
std::unique_ptr<ios::ChromeBrowserState> chrome_browser_state_;
ShareToDataBuilderTestTabMock* tab_;
// The webState's view needs a superview so a snapshot can be taken.
UIView* web_state_superview_;
DISALLOW_COPY_AND_ASSIGN(ShareToDataBuilderTest);
};
......
......@@ -21,12 +21,14 @@
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/web/public/features.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#import "ios/web/public/test/http_server/error_page_response_provider.h"
#import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h"
#import "ios/web/public/test/web_view_interaction_test_util.h"
#import "ios/web/public/web_client.h"
#import "ios/web/public/web_state/web_state.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -106,6 +108,16 @@ void AssertURLIs(const GURL& expectedURL) {
yOffset = -56.0;
}
}
if (base::FeatureList::IsEnabled(
web::features::kBrowserContainerFullscreen) &&
base::FeatureList::IsEnabled(web::features::kOutOfWebFullscreen)) {
if (@available(iOS 11, *)) {
yOffset -=
chrome_test_util::GetCurrentWebState()->GetView().safeAreaInsets.top;
} else {
yOffset -= StatusBarHeight();
}
}
DCHECK_LT(yOffset, 0);
[[EarlGrey
selectElementWithMatcher:web::WebViewScrollView(
......
......@@ -110,6 +110,15 @@
id<CRWWebViewProxy> webViewProxy = self.webState->GetWebViewProxy();
CRWWebViewScrollViewProxy* scrollViewProxy = webViewProxy.scrollViewProxy;
if (self.webState->GetContentsMimeType() == "application/pdf") {
scrollViewProxy.contentInset = insets;
if (!CGRectEqualToRect(webView.frame, webView.superview.bounds)) {
webView.frame = webView.superview.bounds;
}
return;
}
CGRect newFrame = UIEdgeInsetsInsetRect(webView.superview.bounds, insets);
// Make sure the frame has changed to avoid a loop as the frame property is
......
......@@ -13,6 +13,8 @@
#endif
bool IsVisibleUrlNewTabPage(web::WebState* web_state) {
if (!web_state)
return false;
web::NavigationItem* item =
web_state->GetNavigationManager()->GetVisibleItem();
return item && item->GetURL().GetOrigin() == kChromeUINewTabURL;
......
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