#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/app_service/browser_app_launcher.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/web_applications/test/test_server_redirect_handle.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_browsertest_base.h"
#include "chrome/browser/web_applications/os_integration/os_integration_manager.h"
#include "chrome/browser/web_applications/os_integration/web_app_file_handler_manager.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_registry_update.h"
#include "chrome/browser/web_applications/web_app_sync_bridge.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "chrome/common/chrome_features.h"
#include "components/embedder_support/switches.h"
#include "components/permissions/test/permission_request_observer.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/policy_constants.h"
#include "components/services/app_service/public/cpp/app_launch_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_launcher.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/url_loader_interceptor.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/features.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/file_manager/file_manager_test_util.h"
#include "chrome/browser/ash/file_manager/volume.h"
#endif
namespace web_app {
class WebAppFileHandlingTestBase : public WebAppBrowserTestBase { … };
namespace {
void AttachTestConsumer(content::WebContents* web_contents) { … }
}
class WebAppFileHandlingBrowserTest : public WebAppFileHandlingTestBase { … };
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest,
PWAsCanReceiveFileLaunchParams) { … }
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest,
FileExtensionCaseInsensitive) { … }
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest,
PWAsCanReceiveFileLaunchParamsInTab) { … }
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest,
PWAsDispatchOnCorrectFileHandlingURL) { … }
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest,
LaunchQueueSetOnRedirect) { … }
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest, LaunchQueueSetOnReload) { … }
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest,
LaunchQueueSetOnReloadAfterPushState) { … }
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest,
LaunchQueueNotSetOnCrossOriginRedirect) { … }
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest,
LaunchQueueNotSetOnNavigate) { … }
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest,
SometimesResetPermission) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest, IsFileHandlerOnChromeOS) {
InstallFileHandlingPWA();
base::FilePath test_file_path = CreateTestFileWithExtension("txt");
std::vector<file_manager::file_tasks::FullTaskDescriptor> tasks =
file_manager::test::GetTasksForFile(profile(), test_file_path);
ASSERT_EQ(1u, tasks.size());
EXPECT_EQ(tasks[0].task_descriptor.app_id, app_id());
}
IN_PROC_BROWSER_TEST_F(WebAppFileHandlingBrowserTest,
HandlerForNonNativeFiles) {
InstallFileHandlingPWA();
base::WeakPtr<file_manager::Volume> fsp_volume =
file_manager::test::InstallFileSystemProviderChromeApp(profile());
base::FilePath test_file_path =
fsp_volume->mount_path().AppendASCII("readonly.txt");
std::vector<file_manager::file_tasks::FullTaskDescriptor> tasks =
file_manager::test::GetTasksForFile(profile(), test_file_path);
ASSERT_EQ(1u, tasks.size());
EXPECT_EQ(tasks[0].task_descriptor.app_id, app_id());
}
#endif
class WebAppFileHandlingIconBrowserTest
: public WebAppBrowserTestBase,
public testing::WithParamInterface<bool> { … };
IN_PROC_BROWSER_TEST_P(WebAppFileHandlingIconBrowserTest, Basic) { … }
INSTANTIATE_TEST_SUITE_P(…);
}