Commit dfd26881 authored by rohitrao's avatar rohitrao Committed by Commit bot

[ios] Restore the original key window at the end of unittests.

Some tests were setting a new key window but failing to restore the original
window after the test concluded.  Leaving the app without a key window breaks
subsequent tests on iOS 9.0, including ContextualSearchJsTest.

BUG=None

Review-Url: https://codereview.chromium.org/2588223002
Cr-Commit-Position: refs/heads/master@{#439679}
parent 3be61861
...@@ -23,12 +23,16 @@ ...@@ -23,12 +23,16 @@
class AlertCoordinatorTest : public PlatformTest { class AlertCoordinatorTest : public PlatformTest {
protected: protected:
AlertCoordinatorTest() { AlertCoordinatorTest() {
// Save the current key window and restore it after the test.
previous_key_window_ = [[UIApplication sharedApplication] keyWindow];
window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window_ makeKeyAndVisible]; [window_ makeKeyAndVisible];
view_controller_ = [[UIViewController alloc] init]; view_controller_ = [[UIViewController alloc] init];
[window_ setRootViewController:view_controller_]; [window_ setRootViewController:view_controller_];
} }
~AlertCoordinatorTest() override { [previous_key_window_ makeKeyAndVisible]; }
void startAlertCoordinator() { [alert_coordinator_ start]; } void startAlertCoordinator() { [alert_coordinator_ start]; }
UIViewController* getViewController() { return view_controller_; } UIViewController* getViewController() { return view_controller_; }
...@@ -48,6 +52,7 @@ class AlertCoordinatorTest : public PlatformTest { ...@@ -48,6 +52,7 @@ class AlertCoordinatorTest : public PlatformTest {
} }
private: private:
UIWindow* previous_key_window_;
AlertCoordinator* alert_coordinator_; AlertCoordinator* alert_coordinator_;
UIWindow* window_; UIWindow* window_;
UIViewController* view_controller_; UIViewController* view_controller_;
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
class ContextMenuCoordinatorTest : public PlatformTest { class ContextMenuCoordinatorTest : public PlatformTest {
public: public:
ContextMenuCoordinatorTest() { ContextMenuCoordinatorTest() {
// Save the current key window and restore it after the test.
previous_key_window_.reset(
[[[UIApplication sharedApplication] keyWindow] retain]);
window_.reset( window_.reset(
[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]); [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]);
[window_ makeKeyAndVisible]; [window_ makeKeyAndVisible];
...@@ -23,7 +26,12 @@ class ContextMenuCoordinatorTest : public PlatformTest { ...@@ -23,7 +26,12 @@ class ContextMenuCoordinatorTest : public PlatformTest {
[window_ setRootViewController:view_controller_]; [window_ setRootViewController:view_controller_];
} }
~ContextMenuCoordinatorTest() override {
[previous_key_window_ makeKeyAndVisible];
}
protected: protected:
base::scoped_nsobject<UIWindow> previous_key_window_;
base::scoped_nsobject<ContextMenuCoordinator> menu_coordinator_; base::scoped_nsobject<ContextMenuCoordinator> menu_coordinator_;
base::scoped_nsobject<UIWindow> window_; base::scoped_nsobject<UIWindow> window_;
base::scoped_nsobject<UIViewController> view_controller_; base::scoped_nsobject<UIViewController> view_controller_;
......
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