chromium/chrome/browser/preloading/prefetch/search_prefetch/search_preload_test_response_utils.h

// 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.

#ifndef CHROME_BROWSER_PRELOADING_PREFETCH_SEARCH_PREFETCH_SEARCH_PRELOAD_TEST_RESPONSE_UTILS_H_
#define CHROME_BROWSER_PRELOADING_PREFETCH_SEARCH_PREFETCH_SEARCH_PRELOAD_TEST_RESPONSE_UTILS_H_

#include <queue>

#include "base/functional/callback_forward.h"
#include "base/thread_annotations.h"
#include "net/test/embedded_test_server/embedded_test_server.h"

// Used by SearchPreloadDeferrableResponse and related testing code, to indicate
// whether and what to defer during testing.
enum class SearchPreloadTestResponseDeferralType {};

// A test base that allows test fixtures to control when and what to respond.
// For a test class that wants to defer response, it can derive this class, and
// implement its method to utilize the delayed response.
// Sample Usage:
// Define test fixtures:
// Class FooBrowserTest: public SearchPreloadResponseController {
//   ...
//     std::unique_ptr<net::test_server::HttpResponse>
//     HandleSearchRequest(const net::test_server::HttpRequest& request) {
//       // Construct a delayed response.
// ..... Figure out headers, response code, response body, etc.
//       return CreateDeferrableResponse(args);
//     }
//
// };
// For tests:
//  step 1: sets deferral type:
//  set_deferral_type();
//  step 2: make chrome send a request to the server, so then
//  HandleSearchRequest would be executed.
//  step 3: do something
//  step 4: dispatch the delayed part of response by calling
//  DispatchDelayedResponseTask.
// TODO(crbug.com/40219294): This class should be a part of
// SearchPrefetchBaseBrowserTest. Eliminate the differences between
// SearchPreloadUnifiedBrowserTest and SearchPrefetchBaseBrowserTest, such as
// removing duplicated methods from SearchPreloadUnifiedBrowserTest and making
// search prefetch tests run on Android (blocked by Android UI support), so as
// to get rid of this workaround.
class SearchPreloadResponseController {};

class SearchPreloadDeferrableResponse final
    : public net::test_server::BasicHttpResponse {};

#endif  // CHROME_BROWSER_PRELOADING_PREFETCH_SEARCH_PREFETCH_SEARCH_PRELOAD_TEST_RESPONSE_UTILS_H_