Commit 27d02bcc authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

Adapt ScopedKeyWindow to scene API

This fixes OverlayPresentationContextViewControllerTest.* tests

Change-Id: I406440441707273077c32f3a2cf971504b4f10f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2403364
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806109}
parent 5006fac8
......@@ -34,6 +34,7 @@ source_set("test_support") {
"root_view_controller_test.h",
"root_view_controller_test.mm",
"scoped_key_window.h",
"scoped_key_window.mm",
"testing_application_context.h",
"testing_application_context.mm",
]
......@@ -55,6 +56,7 @@ source_set("test_support") {
"//ios/chrome/browser/content_settings",
"//ios/chrome/browser/prefs:browser_prefs",
"//ios/chrome/browser/safe_browsing:test_support",
"//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/components/webui:url_constants",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser:test_support",
......
......@@ -11,14 +11,9 @@
// key window and restores it on destruction.
class ScopedKeyWindow {
public:
explicit ScopedKeyWindow()
: current_key_window_(
[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]),
original_key_window_([UIApplication sharedApplication].keyWindow) {
[current_key_window_ makeKeyAndVisible];
}
~ScopedKeyWindow() { [original_key_window_ makeKeyAndVisible]; }
UIWindow* Get() { return current_key_window_; }
explicit ScopedKeyWindow();
~ScopedKeyWindow();
UIWindow* Get();
private:
__strong UIWindow* current_key_window_;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/test/scoped_key_window.h"
#include "base/check_op.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
ScopedKeyWindow::ScopedKeyWindow() {
if (IsSceneStartupSupported()) {
if (@available(iOS 13, *)) {
NSSet<UIScene*>* scenes =
([[UIApplication sharedApplication] connectedScenes]);
// Only one scene is supported in unittests at the moment.
DCHECK_EQ([scenes count], 1u);
UIScene* scene =
[[[UIApplication sharedApplication] connectedScenes] anyObject];
DCHECK([scene isKindOfClass:[UIWindowScene class]]);
UIWindowScene* windowScene = static_cast<UIWindowScene*>(scene);
for (UIWindow* window in windowScene.windows) {
if ([window isKeyWindow]) {
original_key_window_ = window;
}
}
DCHECK(original_key_window_);
current_key_window_ = [[UIWindow alloc] initWithWindowScene:windowScene];
}
}
if (!current_key_window_) {
current_key_window_ =
[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
original_key_window_ = [UIApplication sharedApplication].keyWindow;
}
[current_key_window_ makeKeyAndVisible];
}
ScopedKeyWindow::~ScopedKeyWindow() {
[original_key_window_ makeKeyAndVisible];
}
UIWindow* ScopedKeyWindow::Get() {
return current_key_window_;
}
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