0

Make sure that NSApplication subclasses are correctly instantiated.

If NSApp is used prior to instantiation of the NSApplication subclass, then the
subclass will never be instantiated.

This CL adds a CHECK to confirm that the subclass is correctly instantiated.

This CL found several tests which were unnecessarily instantiating a UI Message
Loop during the constructor of the gtest subclass, which ends up calling NSApp
prior to NSApplication subclass instantiation.


Change-Id: Ie1d1a2b498623d29578848a18938dc03521940ef
Reviewed-on: https://chromium-review.googlesource.com/1240515
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593913}
This commit is contained in:
erikchen
2018-09-25 13:26:02 +00:00
committed by Commit Bot
parent 1ecd5b10d9
commit 49d56b0a5c
7 changed files with 23 additions and 7 deletions

@ -39,6 +39,11 @@ namespace mock_cr_app {
void RegisterMockCrApp() {
[MockCrApp sharedApplication];
// If there was an invocation to NSApp prior to this method, then the NSApp
// will not be a MockCrApp, but will instead be an NSApplication.
// This is undesirable and we must enforce that this doesn't happen.
CHECK([NSApp isKindOfClass:[MockCrApp class]]);
}
} // namespace mock_cr_app

@ -28,6 +28,11 @@ namespace chrome_browser_application_mac {
void RegisterBrowserCrApp() {
[BrowserCrApplication sharedApplication];
// If there was an invocation to NSApp prior to this method, then the NSApp
// will not be a BrowserCrApplication, but will instead be an NSApplication.
// This is undesirable and we must enforce that this doesn't happen.
CHECK([NSApp isKindOfClass:[BrowserCrApplication class]]);
};
void Terminate() {

@ -199,9 +199,6 @@ class AutofillRiskFingerprintTest : public content::ContentBrowserTest {
const gfx::Rect unavailable_screen_bounds_;
std::unique_ptr<device::ScopedGeolocationOverrider> geolocation_overrider_;
// A message loop to block on the asynchronous loading of the fingerprint.
base::MessageLoopForUI message_loop_;
};
// Test that getting a fingerprint works on some basic level.

@ -151,7 +151,7 @@ class TracingRenderWidgetHostFactory : public RenderWidgetHostFactory {
class MouseLatencyBrowserTest : public ContentBrowserTest {
public:
MouseLatencyBrowserTest() : loop_(base::MessageLoop::TYPE_UI) {}
MouseLatencyBrowserTest() {}
~MouseLatencyBrowserTest() override {}
RenderWidgetHostImpl* GetWidgetHost() {
@ -306,7 +306,6 @@ class MouseLatencyBrowserTest : public ContentBrowserTest {
}
private:
base::MessageLoop loop_;
std::unique_ptr<base::RunLoop> runner_;
base::Value trace_data_;
TracingRenderWidgetHostFactory widget_factory_;

@ -62,7 +62,7 @@ namespace content {
class ScrollLatencyBrowserTest : public ContentBrowserTest {
public:
ScrollLatencyBrowserTest() : loop_(base::MessageLoop::TYPE_UI) {}
ScrollLatencyBrowserTest() {}
~ScrollLatencyBrowserTest() override {}
RenderWidgetHostImpl* GetWidgetHost() {
@ -140,7 +140,6 @@ class ScrollLatencyBrowserTest : public ContentBrowserTest {
private:
base::HistogramTester histogram_tester_;
base::MessageLoop loop_;
std::unique_ptr<MainThreadFrameObserver> frame_observer_;
DISALLOW_COPY_AND_ASSIGN(ScrollLatencyBrowserTest);

@ -62,6 +62,11 @@ void OverrideBundleID() {
void RegisterShellCrApp() {
// Force the NSApplication subclass to be used.
[ShellCrApplication sharedApplication];
// If there was an invocation to NSApp prior to this method, then the NSApp
// will not be a ShellCrApplication, but will instead be an NSApplication.
// This is undesirable and we must enforce that this doesn't happen.
CHECK([NSApp isKindOfClass:[ShellCrApplication class]]);
}
} // namespace content

@ -11,6 +11,12 @@ namespace headless {
void HeadlessContentMainDelegate::PreCreateMainMessageLoop() {
// Force the NSApplication subclass to be used.
[HeadlessShellCrApplication sharedApplication];
// If there was an invocation to NSApp prior to this method, then the NSApp
// will not be a HeadlessShellCrApplication, but will instead be an
// NSApplication. This is undesirable and we must enforce that this doesn't
// happen.
CHECK([NSApp isKindOfClass:[HeadlessShellCrApplication class]]);
}
} // namespace headless