#include <stddef.h>
#include <memory>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/scoped_observation.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/chrome_browser_main_extra_parts_nacl_deprecation.h"
#include "chrome/browser/devtools/chrome_devtools_manager_delegate.h"
#include "chrome/browser/devtools/devtools_window_testing.h"
#include "chrome/browser/extensions/api/developer_private/developer_private_api.h"
#include "chrome/browser/extensions/extension_action_test_util.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/extension_action_test_helper.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/tabs/tab_enums.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/tabs.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/javascript_dialogs/app_modal_dialog_controller.h"
#include "components/nacl/common/buildflags.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/content_features.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/api_test_utils.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_action_manager.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_host_test_helper.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_registry_observer.h"
#include "extensions/browser/process_manager.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/common/mojom/view_type.mojom.h"
#include "extensions/common/switches.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
BookmarkModel;
BookmarkNode;
namespace extensions {
namespace {
class LoadedIncognitoObserver : public ExtensionRegistryObserver { … };
}
class LazyBackgroundPageApiTest : public ExtensionApiTest { … };
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BrowserActionCreateTab) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
BrowserActionCreateTabAfterCallback) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, BroadcastEvent) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, Filters) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnInstalled) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForDialog) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
DevToolsWindowCreationObserver) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, WaitForView) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, DISABLED_WaitForRequest) { … }
#if BUILDFLAG(ENABLE_NACL)
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, NaClInBackgroundPage) {
{
base::FilePath extdir;
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(base::PathService::Get(chrome::DIR_GEN_TEST_DATA, &extdir));
extdir = extdir.AppendASCII("ppapi/tests/extensions/load_unload/newlib");
ExtensionHostTestHelper host_helper(profile());
host_helper.RestrictToType(mojom::ViewType::kExtensionBackgroundPage);
ASSERT_TRUE(LoadExtension(extdir));
host_helper.WaitForDocumentElementAvailable();
host_helper.WaitForHostDestroyed();
}
{
ExtensionTestMessageListener nacl_module_loaded("nacl_module_loaded");
ExtensionActionTestHelper::Create(browser())->Press(
last_loaded_extension_id());
EXPECT_TRUE(nacl_module_loaded.WaitUntilSatisfied());
content::RunAllTasksUntilIdle();
EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
}
{
ExtensionHostTestHelper host_helper(profile());
host_helper.RestrictToType(mojom::ViewType::kExtensionBackgroundPage);
ExtensionActionTestHelper::Create(browser())->Press(
last_loaded_extension_id());
host_helper.WaitForHostDestroyed();
}
EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
}
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, NaClInView) {
{
base::FilePath extdir;
base::ScopedAllowBlockingForTesting allow_blocking;
ASSERT_TRUE(base::PathService::Get(chrome::DIR_GEN_TEST_DATA, &extdir));
extdir = extdir.AppendASCII("ppapi/tests/extensions/popup/newlib");
ResultCatcher catcher;
const Extension* extension = LoadExtension(extdir);
ASSERT_TRUE(extension);
EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
EXPECT_EQ(extension->GetResourceURL("popup.html"),
browser()
->tab_strip_model()
->GetActiveWebContents()
->GetLastCommittedURL());
EXPECT_TRUE(IsBackgroundPageAlive(last_loaded_extension_id()));
}
{
ExtensionHostTestHelper host_helper(profile(), last_loaded_extension_id());
host_helper.RestrictToType(mojom::ViewType::kExtensionBackgroundPage);
browser()->tab_strip_model()->CloseWebContentsAt(
browser()->tab_strip_model()->active_index(),
TabCloseTypes::CLOSE_NONE);
host_helper.WaitForHostDestroyed();
}
EXPECT_FALSE(IsBackgroundPageAlive(last_loaded_extension_id()));
}
#endif
#if BUILDFLAG(IS_MAC)
#define MAYBE_WaitForNTP …
#else
#define MAYBE_WaitForNTP …
#endif
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, MAYBE_WaitForNTP) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, DISABLED_IncognitoSplitMode) { … }
enum class BackForwardCacheParam { … };
class LazyBackgroundPageApiWithBFCacheParamTest
: public LazyBackgroundPageApiTest,
public testing::WithParamInterface<BackForwardCacheParam> { … };
INSTANTIATE_TEST_SUITE_P(…);
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_CHROMEOS)
#define MAYBE_Messaging …
#else
#define MAYBE_Messaging …
#endif
IN_PROC_BROWSER_TEST_P(LazyBackgroundPageApiWithBFCacheParamTest,
MAYBE_Messaging) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnUnload) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, EventDispatchToTab) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, OnSuspendUseStorageApi) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, EventProcessCleanup) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest, EventListenerCleanup) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
DISABLED_FetchFileSchemeURLWithFileAccess) { … }
IN_PROC_BROWSER_TEST_F(LazyBackgroundPageApiTest,
DISABLED_FetchFileSchemeURLWithNoFileAccess) { … }
class PictureInPictureLazyBackgroundPageApiTest
: public LazyBackgroundPageApiTest { … };
IN_PROC_BROWSER_TEST_F(PictureInPictureLazyBackgroundPageApiTest,
PictureInPictureInBackgroundPage) { … }
}