#include "chrome/browser/ui/webui/devtools/devtools_ui_data_source.h"
#include <memory>
#include <string_view>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/memory/ref_counted_memory.h"
#include "base/memory/scoped_refptr.h"
#include "base/strings/strcat.h"
#include "base/test/bind.h"
#include "build/build_config.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/url_data_source.h"
#include "content/public/test/browser_task_environment.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_shared_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
constexpr char kDevToolsUITestFrontEndUrl[] = …;
constexpr char kDevToolsUITest404Response[] = …;
GURL DevToolsUrl() { … }
std::string DevToolsBundledPath(const std::string& path) { … }
std::string DevToolsRemotePath(const std::string& path) { … }
std::string DevToolsCustomPath(const std::string& path) { … }
}
class TestDevToolsDataSource : public DevToolsDataSource { … };
class DevToolsUIDataSourceTest : public testing::Test { … };
TEST_F(DevToolsUIDataSourceTest, TestDevToolsBundledURL) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsBundledURLWithQueryParam) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsBundledFileURLWithSwitch) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsBundledRemoteURLWithSwitch) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsInvalidBundledURL) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsInvalidBundledURLWithQueryParam) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsBlankURL) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsBlankURLWithQueryParam) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsRemoteURLWithSwitch) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsRemoteFileURLWithSwitch) { … }
TEST_F(DevToolsUIDataSourceTest,
TestDevToolsRemoteFileURLWithSwitchAndServeRevParameters) { … }
TEST_F(DevToolsUIDataSourceTest,
TestDevToolsRemoteFileURLWithSwitchAndServeFileParameters) { … }
TEST_F(DevToolsUIDataSourceTest,
TestDevToolsRemoteFileURLWithSwitchAndServeInternalFileParameters) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsRemoteURL) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsRemoteURLWithQueryParam) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsCustomURLWithNoSwitch) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsCustomURLWithSwitch) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsCustomURLWithSwitchAndQueryParam) { … }
#if !DCHECK_IS_ON()
TEST_F(DevToolsUIDataSourceTest,
TestDevToolsCustomURLWithSwitchAndInvalidServerURL) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kCustomDevtoolsFrontend, "invalid-server-url");
const GURL path =
DevToolsUrl().Resolve(DevToolsCustomPath(kDevToolsUITestFrontEndUrl));
StartRequest(path.path());
EXPECT_TRUE(data_received());
ASSERT_TRUE(base::StartsWith(data(), kDevToolsUITest404Response,
base::CompareCase::SENSITIVE));
}
#endif
TEST_F(DevToolsUIDataSourceTest, TestDevToolsNoRoute) { … }
TEST_F(DevToolsUIDataSourceTest, TestDevToolsNoRouteWithSwitch) { … }
class DevToolsUIDataSourceWithTaskEnvTest : public testing::Test { … };
TEST_F(DevToolsUIDataSourceWithTaskEnvTest,
GotDataCallbackOwnsDevToolsDataSource) { … }