Commit 64cdab61 authored by Dan Harrington's avatar Dan Harrington Committed by Commit Bot

offline_items: Add operator<< for some types used in tests

This makes some test output more readable. I've added the implementations
to the test_support library so we don't accidentally link these
functions into Chrome. The definitions are included alongside the types
being printed, opposed to a test support header file, to avoid ODR violations

Change-Id: Ica0aa9629f9cf745b0a4e42b3536d9537b34bfc7
Reviewed-on: https://chromium-review.googlesource.com/1101472
Commit-Queue: Dan H <harringtond@chromium.org>
Reviewed-by: default avatarCarlos Knippschild <carlosk@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575666}
parent 12c659f0
...@@ -966,6 +966,7 @@ test("browser_tests") { ...@@ -966,6 +966,7 @@ test("browser_tests") {
"//components/dom_distiller/core:test_support", "//components/dom_distiller/core:test_support",
"//components/download/quarantine", "//components/download/quarantine",
"//components/feature_engagement/test:test_support", "//components/feature_engagement/test:test_support",
"//components/offline_items_collection/core/test_support",
"//components/optimization_guide:test_support", "//components/optimization_guide:test_support",
"//components/policy:chrome_settings_proto_generated_compile", "//components/policy:chrome_settings_proto_generated_compile",
"//components/resources", "//components/resources",
......
...@@ -17,6 +17,9 @@ enum class FailState { ...@@ -17,6 +17,9 @@ enum class FailState {
// connection. // connection.
}; };
// Implemented for testing only. See test_support/offline_item_test_support.cc.
std::ostream& operator<<(std::ostream& os, FailState state);
} // namespace offline_items_collection } // namespace offline_items_collection
#endif // COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_FAIL_STATE_H_ #endif // COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_FAIL_STATE_H_
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <map> #include <map>
#include "base/test/bind_test_util.h"
#include "base/test/test_mock_time_task_runner.h" #include "base/test/test_mock_time_task_runner.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "components/offline_items_collection/core/offline_item.h" #include "components/offline_items_collection/core/offline_item.h"
...@@ -117,7 +118,6 @@ TEST_F(OfflineContentAggregatorTest, QueryingItemsWith2Providers) { ...@@ -117,7 +118,6 @@ TEST_F(OfflineContentAggregatorTest, QueryingItemsWith2Providers) {
ScopedMockOfflineContentProvider provider1("1", &aggregator_); ScopedMockOfflineContentProvider provider1("1", &aggregator_);
ScopedMockOfflineContentProvider provider2("2", &aggregator_); ScopedMockOfflineContentProvider provider2("2", &aggregator_);
OfflineContentProvider::OfflineItemList empty;
OfflineContentProvider::OfflineItemList items1; OfflineContentProvider::OfflineItemList items1;
items1.push_back(OfflineItem(ContentId("1", "A"))); items1.push_back(OfflineItem(ContentId("1", "A")));
items1.push_back(OfflineItem(ContentId("1", "B"))); items1.push_back(OfflineItem(ContentId("1", "B")));
......
...@@ -86,6 +86,9 @@ struct OfflineItem { ...@@ -86,6 +86,9 @@ struct OfflineItem {
bool operator==(const OfflineItem& offline_item) const; bool operator==(const OfflineItem& offline_item) const;
// Note: please update test_support/offline_item_test_support.cc
// when adding members here.
// The id of this OfflineItem. Used to identify this item across all relevant // The id of this OfflineItem. Used to identify this item across all relevant
// systems. // systems.
ContentId id; ContentId id;
...@@ -186,6 +189,9 @@ struct OfflineItem { ...@@ -186,6 +189,9 @@ struct OfflineItem {
bool is_dangerous; bool is_dangerous;
}; };
// Implemented for test-only. See test_support/offline_item_test_support.cc.
std::ostream& operator<<(std::ostream& os, const OfflineItem& item);
// This struct holds any potentially expensive visuals for an OfflineItem. If // This struct holds any potentially expensive visuals for an OfflineItem. If
// the front end requires the visuals it will ask for them through the // the front end requires the visuals it will ask for them through the
// OfflineContentProvider interface asynchronously to give the backend time to // OfflineContentProvider interface asynchronously to give the backend time to
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_FILTER_H_ #ifndef COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_FILTER_H_
#define COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_FILTER_H_ #define COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_FILTER_H_
#include <iosfwd>
namespace offline_items_collection { namespace offline_items_collection {
// A Java counterpart will be generated for this enum. // A Java counterpart will be generated for this enum.
...@@ -21,6 +23,9 @@ enum OfflineItemFilter { ...@@ -21,6 +23,9 @@ enum OfflineItemFilter {
FILTER_BOUNDARY, FILTER_BOUNDARY,
}; };
// Implemented for test-only. See test_support/offline_item_test_support.cc.
std::ostream& operator<<(std::ostream& os, OfflineItemFilter state);
} // namespace offline_items_collection } // namespace offline_items_collection
#endif // COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_FILTER_H_ #endif // COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_FILTER_H_
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_STATE_H_ #ifndef COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_STATE_H_
#define COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_STATE_H_ #define COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_STATE_H_
#include <iosfwd>
namespace offline_items_collection { namespace offline_items_collection {
// A Java counterpart will be generated for this enum. // A Java counterpart will be generated for this enum.
...@@ -21,6 +23,9 @@ enum OfflineItemState { ...@@ -21,6 +23,9 @@ enum OfflineItemState {
MAX_DOWNLOAD_STATE, MAX_DOWNLOAD_STATE,
}; };
// Implemented for testing only. See test_support/offline_item_test_support.cc.
std::ostream& operator<<(std::ostream& os, const OfflineItemState& state);
} // namespace offline_items_collection } // namespace offline_items_collection
#endif // COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_STATE_H_ #endif // COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_OFFLINE_ITEM_STATE_H_
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_PENDING_STATE_H_ #ifndef COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_PENDING_STATE_H_
#define COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_PENDING_STATE_H_ #define COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_PENDING_STATE_H_
#include <iosfwd>
namespace offline_items_collection { namespace offline_items_collection {
// A Java counterpart will be generated for this enum. // A Java counterpart will be generated for this enum.
...@@ -17,6 +19,9 @@ enum class PendingState { ...@@ -17,6 +19,9 @@ enum class PendingState {
// is currently being downloaded. // is currently being downloaded.
}; };
// Implemented for testing only. See test_support/offline_item_test_support.cc.
std::ostream& operator<<(std::ostream& os, PendingState state);
} // namespace offline_items_collection } // namespace offline_items_collection
#endif // COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_PENDING_STATE_H_ #endif // COMPONENTS_OFFLINE_ITEMS_COLLECTION_CORE_PENDING_STATE_H_
...@@ -2,14 +2,13 @@ ...@@ -2,14 +2,13 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
source_set("test_support") { static_library("test_support") {
visibility = [ "//components/offline_items_collection/core:unit_tests" ]
testonly = true testonly = true
sources = [ sources = [
"mock_offline_content_provider.cc", "mock_offline_content_provider.cc",
"mock_offline_content_provider.h", "mock_offline_content_provider.h",
"offline_item_test_support.cc",
"scoped_mock_offline_content_provider.cc", "scoped_mock_offline_content_provider.cc",
"scoped_mock_offline_content_provider.h", "scoped_mock_offline_content_provider.h",
] ]
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/offline_items_collection/core/offline_item.h"
#include <iostream>
namespace offline_items_collection {
// All of these methods are not provided in core so that they can't be
// accidentally called and linked into Chrome. The declarations are provided
// in the core headers to avoid ODR violation that can occur if, for instance,
// one test includes these operators and one test does not.
std::ostream& operator<<(std::ostream& os, const OfflineItem& item) {
os << "OfflineItem(";
os << "id: " << item.id.name_space << "." << item.id.id;
os << ", title: " << item.title;
os << ", description: " << item.description;
os << ", filter: " << item.filter;
os << ", is_transient: " << item.is_transient;
os << ", is_suggested: " << item.is_suggested;
os << ", is_accelerated: " << item.is_accelerated;
os << ", total_size_bytes: " << item.total_size_bytes;
os << ", externally_removed: " << item.externally_removed;
os << ", creation_time: " << item.creation_time;
os << ", last_accessed_time: " << item.last_accessed_time;
os << ", is_openable: " << item.is_openable;
os << ", file_path: " << item.file_path;
os << ", mime_type: " << item.mime_type;
os << ", page_url: " << item.page_url;
os << ", original_url: " << item.original_url;
os << ", is_off_the_record: " << item.is_off_the_record;
os << ", state: " << item.state;
os << ", fail_state: " << item.fail_state;
os << ", pending_state: " << item.pending_state;
os << ", is_resumable: " << item.is_resumable;
os << ", allow_metered: " << item.allow_metered;
os << ", received_bytes: " << item.received_bytes;
os << ", progress: " << item.progress.value;
if (item.progress.max)
os << "/" << item.progress.max.value();
os << ", time_remaining_ms: " << item.time_remaining_ms;
os << ", is_dangerous: " << item.is_dangerous;
os << ")";
return os;
}
std::ostream& operator<<(std::ostream& os, const OfflineItemState& state) {
switch (state) {
case IN_PROGRESS:
return os << "IN_PROGRESS";
case PENDING:
return os << "PENDING";
case COMPLETE:
return os << "COMPLETE";
case CANCELLED:
return os << "CANCELLED";
case INTERRUPTED:
return os << "INTERRUPTED";
case FAILED:
return os << "FAILED";
case PAUSED:
return os << "PAUSED";
case MAX_DOWNLOAD_STATE:
return os << "MAX_DOWNLOAD_STATE";
}
CHECK(false) << "state=" << static_cast<int>(state);
return os;
}
std::ostream& operator<<(std::ostream& os, FailState state) {
switch (state) {
case FailState::NO_FAILURE:
return os << "NO_FAILURE";
case FailState::CANNOT_DOWNLOAD:
return os << "CANNOT_DOWNLOAD";
case FailState::NETWORK_INSTABILITY:
return os << "NETWORK_INSTABILITY";
}
CHECK(false) << "state=" << static_cast<int>(state);
return os;
}
std::ostream& operator<<(std::ostream& os, PendingState state) {
switch (state) {
case PendingState::NOT_PENDING:
return os << "NOT_PENDING";
case PendingState::PENDING_NETWORK:
return os << "PENDING_NETWORK";
case PendingState::PENDING_ANOTHER_DOWNLOAD:
return os << "PENDING_ANOTHER_DOWNLOAD";
}
CHECK(false) << "state=" << static_cast<int>(state);
return os;
}
std::ostream& operator<<(std::ostream& os, OfflineItemFilter state) {
switch (state) {
case FILTER_PAGE:
return os << "FILTER_PAGE";
case FILTER_VIDEO:
return os << "FILTER_VIDEO";
case FILTER_AUDIO:
return os << "FILTER_AUDIO";
case FILTER_IMAGE:
return os << "FILTER_IMAGE";
case FILTER_DOCUMENT:
return os << "FILTER_DOCUMENT";
case FILTER_OTHER:
return os << "FILTER_OTHER";
case FILTER_BOUNDARY:
return os << "FILTER_BOUNDARY";
}
CHECK(false) << "state=" << static_cast<int>(state);
return os;
}
} // namespace offline_items_collection
...@@ -90,6 +90,7 @@ static_library("test_support") { ...@@ -90,6 +90,7 @@ static_library("test_support") {
deps = [ deps = [
":background_offliner", ":background_offliner",
"//base", "//base",
"//components/offline_items_collection/core/test_support",
"//components/offline_pages/core", "//components/offline_pages/core",
"//net", "//net",
] ]
......
...@@ -37,6 +37,7 @@ source_set("unit_tests") { ...@@ -37,6 +37,7 @@ source_set("unit_tests") {
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/offline_items_collection/core", "//components/offline_items_collection/core",
"//components/offline_items_collection/core/test_support",
"//components/offline_pages/core", "//components/offline_pages/core",
"//components/offline_pages/core:switches", "//components/offline_pages/core:switches",
"//components/offline_pages/core:test_support", "//components/offline_pages/core:test_support",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment