chromium/components/dom_distiller/core/distiller_unittest.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/dom_distiller/core/distiller.h"

#include <stddef.h>

#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/current_thread.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/task_environment.h"
#include "base/values.h"
#include "components/dom_distiller/core/article_distillation_update.h"
#include "components/dom_distiller/core/distiller_page.h"
#include "components/dom_distiller/core/fake_distiller_page.h"
#include "components/dom_distiller/core/proto/distilled_article.pb.h"
#include "components/dom_distiller/core/proto/distilled_page.pb.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/dom_distiller_js/dom_distiller.pb.h"
#include "third_party/dom_distiller_js/dom_distiller_json_converter.h"

_;
Invoke;
Return;

DomDistillerOptions;
DomDistillerResult;
DomDistillerResult_ContentImage;
TimingEntry;

namespace {
const char kTitle[] =;
const char kContent[] =;
const char kURL[] =;
const char kOtherURL[] =;
const size_t kTotalGoodImages =;
const size_t kTotalImages =;
// Good images need to be in the front.
const char* kImageURLs[kTotalImages] =;
const char* kImageData[kTotalImages] =;
const char kDebugLog[] =;

const std::string GetImageName(int page_num, int image_num) {}

base::Value CreateDistilledValueReturnedFromJS(
    const std::string& title,
    const std::string& content,
    const std::vector<int>& image_indices,
    const std::string& next_page_url,
    const std::string& prev_page_url = "") {}

// Return the sequence in which Distiller will distill pages.
// Note: ignores any delays due to fetching images etc.
std::vector<int> GetPagesInSequence(int start_page_num, int num_pages) {}

struct MultipageDistillerData {};

void VerifyIncrementalUpdatesMatch(
    const MultipageDistillerData* distiller_data,
    int num_pages_in_article,
    const std::vector<dom_distiller::ArticleDistillationUpdate>&
        incremental_updates,
    int start_page_num) {}

std::string GenerateNextPageUrl(const std::string& url_prefix,
                                size_t page_num,
                                size_t pages_size) {}

std::string GeneratePrevPageUrl(const std::string& url_prefix,
                                size_t page_num) {}

std::unique_ptr<MultipageDistillerData> CreateMultipageDistillerDataWithImages(
    const std::vector<std::vector<int>>& image_ids) {}

std::unique_ptr<MultipageDistillerData>
CreateMultipageDistillerDataWithoutImages(size_t pages_size) {}

void VerifyArticleProtoMatchesMultipageData(
    const dom_distiller::DistilledArticleProto* article_proto,
    const MultipageDistillerData* distiller_data,
    size_t distilled_pages_size,
    size_t total_pages_size,
    size_t start_page_offset = 0) {}

}  // namespace

namespace dom_distiller {

MockDistillerPage;
MockDistillerPageFactory;

class TestDistillerURLFetcher : public DistillerURLFetcher {};

class TestDistillerURLFetcherFactory : public DistillerURLFetcherFactory {};

class MockDistillerURLFetcherFactory : public DistillerURLFetcherFactory {};

class DistillerTest : public testing::Test {};

ACTION_P3(DistillerPageOnDistillationDone, distiller_page, url, result) {}

std::unique_ptr<DistillerPage> CreateMockDistillerPage(
    const base::Value* result,
    const GURL& url) {}

std::unique_ptr<DistillerPage> CreateMockDistillerPageWithPendingJSCallback(
    MockDistillerPage** distiller_page_ptr,
    const GURL& url) {}

std::unique_ptr<DistillerPage> CreateMockDistillerPagesWithSequence(
    MultipageDistillerData* distiller_data,
    const std::vector<int>& page_num_sequence) {}

std::unique_ptr<DistillerPage> CreateMockDistillerPages(
    MultipageDistillerData* distiller_data,
    size_t pages_size,
    int start_page_num) {}

TEST_F(DistillerTest, DistillPage) {}

TEST_F(DistillerTest, DistillPageWithDebugInfo) {}

void SetTimingEntry(TimingEntry* entry, const std::string& name, double time) {}

TEST_F(DistillerTest, DistillPageWithImages) {}

TEST_F(DistillerTest, DistillMultiplePages) {}

TEST_F(DistillerTest, DistillLinkLoop) {}

TEST_F(DistillerTest, CheckMaxPageLimitExtraPage) {}

TEST_F(DistillerTest, CheckMaxPageLimitExactLimit) {}

TEST_F(DistillerTest, SinglePageDistillationFailure) {}

TEST_F(DistillerTest, MultiplePagesDistillationFailure) {}

TEST_F(DistillerTest, DistillMultiplePagesFirstEmpty) {}

TEST_F(DistillerTest, DistillMultiplePagesSecondEmpty) {}

TEST_F(DistillerTest, DistillMultiplePagesNextDifferingOrigin) {}

TEST_F(DistillerTest, DistillMultiplePagesPrevDifferingOrigin) {}

TEST_F(DistillerTest, DistillPreviousPage) {}

TEST_F(DistillerTest, IncrementalUpdates) {}

TEST_F(DistillerTest, IncrementalUpdatesDoNotDeleteFinalArticle) {}

TEST_F(DistillerTest, DeletingArticleDoesNotInterfereWithUpdates) {}

TEST_F(DistillerTest, CancelWithDelayedImageFetchCallback) {}

TEST_F(DistillerTest, CancelWithDelayedJSCallback) {}

}  // namespace dom_distiller