namespace {
+// The url to distill.
const char* kUrlSwitch = "url";
+// Indicates that DNS resolution should be disabled for this test.
+const char* kDisableDnsSwitch = "disable-dns";
+
+// Will write the distilled output to the given file instead of to stdout.
+const char* kOutputFile = "output-file";
+
+// Indicates to output a serialized protocol buffer instead of human-readable
+// output.
+const char* kShouldOutputBinary = "output-binary";
+
scoped_ptr<DomDistillerService> CreateDomDistillerService(
content::BrowserContext* context,
const base::FilePath& db_path) {
new DistillerPageWebContentsFactory(context));
scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory(
new DistillerURLFetcherFactory(context->GetRequestContext()));
- scoped_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl(
- distiller_page_factory.Pass(), distiller_url_fetcher_factory.Pass()));
+ scoped_ptr<DistillerFactory> distiller_factory(
+ new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass()));
return scoped_ptr<DomDistillerService>(new DomDistillerService(
dom_distiller_store.PassAs<DomDistillerStoreInterface>(),
- distiller_factory.Pass()));
+ distiller_factory.Pass(),
+ distiller_page_factory.Pass()));
}
void AddComponentsResources() {
void LogArticle(const DistilledArticleProto& article_proto) {
std::stringstream output;
- output << "Article Title: " << article_proto.title() << std::endl;
- output << "# of pages: " << article_proto.pages_size() << std::endl;
- for (int i = 0; i < article_proto.pages_size(); ++i) {
- const DistilledPageProto& page = article_proto.pages(i);
- output << "Page " << i << std::endl;
- output << "URL: " << page.url() << std::endl;
- output << "Content: " << page.html() << std::endl;
+ if (CommandLine::ForCurrentProcess()->HasSwitch(kShouldOutputBinary)) {
+ output << article_proto.SerializeAsString();
+ } else {
+ output << "Article Title: " << article_proto.title() << std::endl;
+ output << "# of pages: " << article_proto.pages_size() << std::endl;
+ for (int i = 0; i < article_proto.pages_size(); ++i) {
+ const DistilledPageProto& page = article_proto.pages(i);
+ output << "Page " << i << std::endl;
+ output << "URL: " << page.url() << std::endl;
+ output << "Content: " << page.html() << std::endl;
+ }
+ }
+
+ std::string data = output.str();
+ if (CommandLine::ForCurrentProcess()->HasSwitch(kOutputFile)) {
+ base::FilePath filename =
+ CommandLine::ForCurrentProcess()->GetSwitchValuePath(kOutputFile);
+ base::WriteFile(filename, data.c_str(), data.size());
+ } else {
+ VLOG(0) << data;
}
- VLOG(0) << output.str();
}
} // namespace
public:
void Start(DomDistillerService* service, base::Closure finished_callback) {
finished_callback_ = finished_callback;
- viewer_handle_ = service->ViewUrl(this, url_);
+ viewer_handle_ =
+ service->ViewUrl(this, service->CreateDefaultDistillerPage(), url_);
}
DistilledArticleProto GetArticleCopy() {
// Change behavior of the default host resolver to avoid DNS lookup errors, so
// we can make network calls.
virtual void SetUpOnMainThread() OVERRIDE {
- EnableDNSLookupForThisTest();
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(kDisableDnsSwitch)) {
+ EnableDNSLookupForThisTest();
+ }
CHECK(db_dir_.CreateUniqueTempDir());
AddComponentsResources();
}