blob: e8e181e3c92bbe7f8171129ae80e746ff17342ed [file] [log] [blame]
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/extensions/extension_install_prompt_show_params.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/browser_test.h"
#include "ui/aura/test/test_windows.h"
using ExtensionInstallPromptShowParamsTest = InProcessBrowserTest;
IN_PROC_BROWSER_TEST_F(ExtensionInstallPromptShowParamsTest,
WasParentDestroyedOutsideOfRoot) {
aura::Window* context_window = browser()->window()->GetNativeWindow();
ExtensionInstallPromptShowParams params(browser()->profile(), context_window);
ASSERT_TRUE(context_window->GetRootWindow());
// As the context window is parented to a root, the parent is valid.
EXPECT_FALSE(params.WasParentDestroyed());
std::unique_ptr<aura::Window> window_with_no_root_ancestor(
aura::test::CreateTestWindowWithId(11, nullptr));
ExtensionInstallPromptShowParams params2(browser()->profile(),
window_with_no_root_ancestor.get());
// As `window_with_no_root_ancestor` is not parented to a root, it should
// return true from WasParentDestroyed().
EXPECT_TRUE(params2.WasParentDestroyed());
}