| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if (requests.empty()) { | 202 if (requests.empty()) { |
| 203 ADD_FAILURE() << "No valid url provided"; | 203 ADD_FAILURE() << "No valid url provided"; |
| 204 } | 204 } |
| 205 | 205 |
| 206 return requests.Pass(); | 206 return requests.Pass(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 private: | 209 private: |
| 210 ContentExtractionRequest(const GURL& url) : url_(url) {} | 210 ContentExtractionRequest(const GURL& url) : url_(url) {} |
| 211 | 211 |
| 212 virtual void OnArticleUpdated(ArticleDistillationUpdate article_update) | 212 void OnArticleUpdated(ArticleDistillationUpdate article_update) override {} |
| 213 override {} | |
| 214 | 213 |
| 215 virtual void OnArticleReady(const DistilledArticleProto* article_proto) | 214 void OnArticleReady(const DistilledArticleProto* article_proto) override { |
| 216 override { | |
| 217 article_proto_ = article_proto; | 215 article_proto_ = article_proto; |
| 218 CHECK(article_proto->pages_size()) << "Failed extracting " << url_; | 216 CHECK(article_proto->pages_size()) << "Failed extracting " << url_; |
| 219 base::MessageLoop::current()->PostTask( | 217 base::MessageLoop::current()->PostTask( |
| 220 FROM_HERE, | 218 FROM_HERE, |
| 221 finished_callback_); | 219 finished_callback_); |
| 222 } | 220 } |
| 223 | 221 |
| 224 const DistilledArticleProto* article_proto_; | 222 const DistilledArticleProto* article_proto_; |
| 225 scoped_ptr<ViewerHandle> viewer_handle_; | 223 scoped_ptr<ViewerHandle> viewer_handle_; |
| 226 GURL url_; | 224 GURL url_; |
| 227 base::Closure finished_callback_; | 225 base::Closure finished_callback_; |
| 228 }; | 226 }; |
| 229 | 227 |
| 230 class ContentExtractor : public ContentBrowserTest { | 228 class ContentExtractor : public ContentBrowserTest { |
| 231 public: | 229 public: |
| 232 ContentExtractor() | 230 ContentExtractor() |
| 233 : pending_tasks_(0), | 231 : pending_tasks_(0), |
| 234 max_tasks_(kMaxExtractorTasks), | 232 max_tasks_(kMaxExtractorTasks), |
| 235 next_request_(0), | 233 next_request_(0), |
| 236 output_data_(), | 234 output_data_(), |
| 237 protobuf_output_stream_( | 235 protobuf_output_stream_( |
| 238 new google::protobuf::io::StringOutputStream(&output_data_)) {} | 236 new google::protobuf::io::StringOutputStream(&output_data_)) {} |
| 239 | 237 |
| 240 // Change behavior of the default host resolver to avoid DNS lookup errors, so | 238 // Change behavior of the default host resolver to avoid DNS lookup errors, so |
| 241 // we can make network calls. | 239 // we can make network calls. |
| 242 virtual void SetUpOnMainThread() override { | 240 void SetUpOnMainThread() override { |
| 243 if (!CommandLine::ForCurrentProcess()->HasSwitch(kDisableDnsSwitch)) { | 241 if (!CommandLine::ForCurrentProcess()->HasSwitch(kDisableDnsSwitch)) { |
| 244 EnableDNSLookupForThisTest(); | 242 EnableDNSLookupForThisTest(); |
| 245 } | 243 } |
| 246 CHECK(db_dir_.CreateUniqueTempDir()); | 244 CHECK(db_dir_.CreateUniqueTempDir()); |
| 247 AddComponentsResources(); | 245 AddComponentsResources(); |
| 248 } | 246 } |
| 249 | 247 |
| 250 virtual void TearDownOnMainThread() override { | 248 void TearDownOnMainThread() override { DisableDNSLookupForThisTest(); } |
| 251 DisableDNSLookupForThisTest(); | |
| 252 } | |
| 253 | 249 |
| 254 protected: | 250 protected: |
| 255 // Creates the DomDistillerService and creates and starts the extraction | 251 // Creates the DomDistillerService and creates and starts the extraction |
| 256 // request. | 252 // request. |
| 257 void Start() { | 253 void Start() { |
| 258 content::BrowserContext* context = | 254 content::BrowserContext* context = |
| 259 shell()->web_contents()->GetBrowserContext(); | 255 shell()->web_contents()->GetBrowserContext(); |
| 260 service_ = CreateDomDistillerService(context, | 256 service_ = CreateDomDistillerService(context, |
| 261 db_dir_.path()); | 257 db_dir_.path()); |
| 262 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 258 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 std::string output_data_; | 338 std::string output_data_; |
| 343 scoped_ptr<google::protobuf::io::StringOutputStream> protobuf_output_stream_; | 339 scoped_ptr<google::protobuf::io::StringOutputStream> protobuf_output_stream_; |
| 344 }; | 340 }; |
| 345 | 341 |
| 346 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { | 342 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { |
| 347 Start(); | 343 Start(); |
| 348 base::RunLoop().Run(); | 344 base::RunLoop().Run(); |
| 349 } | 345 } |
| 350 | 346 |
| 351 } // namespace dom_distiller | 347 } // namespace dom_distiller |
| OLD | NEW |