| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "components/dom_distiller/content/distiller_javascript_utils.h" | 10 #include "components/dom_distiller/content/distiller_javascript_utils.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 void SetUpOnMainThread() override { | 84 void SetUpOnMainThread() override { |
| 85 if (!DistillerJavaScriptWorldIdIsSet()) { | 85 if (!DistillerJavaScriptWorldIdIsSet()) { |
| 86 SetDistillerJavaScriptWorldId(content::ISOLATED_WORLD_ID_CONTENT_END); | 86 SetDistillerJavaScriptWorldId(content::ISOLATED_WORLD_ID_CONTENT_END); |
| 87 } | 87 } |
| 88 AddComponentsResources(); | 88 AddComponentsResources(); |
| 89 SetUpTestServer(); | 89 SetUpTestServer(); |
| 90 ContentBrowserTest::SetUpOnMainThread(); | 90 ContentBrowserTest::SetUpOnMainThread(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void DistillPage(const base::Closure& quit_closure, const std::string& url) { | 93 void DistillPage(const base::Closure& quit_closure, const std::string& url) { |
| 94 quit_closure_ = quit_closure; | |
| 95 distiller_page_->DistillPage( | 94 distiller_page_->DistillPage( |
| 96 embedded_test_server()->GetURL(url), | 95 embedded_test_server()->GetURL(url), |
| 97 dom_distiller::proto::DomDistillerOptions(), | 96 dom_distiller::proto::DomDistillerOptions(), |
| 98 base::Bind(&DistillerPageWebContentsTest::OnPageDistillationFinished, | 97 base::Bind(&DistillerPageWebContentsTest::OnPageDistillationFinished, |
| 99 this)); | 98 this, quit_closure)); |
| 100 } | 99 } |
| 101 | 100 |
| 102 void OnPageDistillationFinished( | 101 void OnPageDistillationFinished( |
| 102 base::Closure quit_closure, |
| 103 scoped_ptr<proto::DomDistillerResult> distiller_result, | 103 scoped_ptr<proto::DomDistillerResult> distiller_result, |
| 104 bool distillation_successful) { | 104 bool distillation_successful) { |
| 105 distiller_result_ = distiller_result.Pass(); | 105 distiller_result_ = distiller_result.Pass(); |
| 106 quit_closure_.Run(); | 106 quit_closure.Run(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void OnJsExecutionDone(base::Closure callback, const base::Value* value) { | 109 void OnJsExecutionDone(base::Closure callback, const base::Value* value) { |
| 110 js_result_.reset(value->DeepCopy()); | 110 js_result_.reset(value->DeepCopy()); |
| 111 callback.Run(); | 111 callback.Run(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 private: | 114 private: |
| 115 void AddComponentsResources() { | 115 void AddComponentsResources() { |
| 116 base::FilePath pak_file; | 116 base::FilePath pak_file; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 137 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 137 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 138 } | 138 } |
| 139 | 139 |
| 140 protected: | 140 protected: |
| 141 void RunUseCurrentWebContentsTest(const std::string& url, | 141 void RunUseCurrentWebContentsTest(const std::string& url, |
| 142 bool expect_new_web_contents, | 142 bool expect_new_web_contents, |
| 143 bool setup_main_frame_observer, | 143 bool setup_main_frame_observer, |
| 144 bool wait_for_document_loaded); | 144 bool wait_for_document_loaded); |
| 145 | 145 |
| 146 DistillerPageWebContents* distiller_page_; | 146 DistillerPageWebContents* distiller_page_; |
| 147 base::Closure quit_closure_; | |
| 148 scoped_ptr<proto::DomDistillerResult> distiller_result_; | 147 scoped_ptr<proto::DomDistillerResult> distiller_result_; |
| 149 scoped_ptr<base::Value> js_result_; | 148 scoped_ptr<base::Value> js_result_; |
| 150 }; | 149 }; |
| 151 | 150 |
| 152 // Use this class to be able to leak the WebContents, which is needed for when | 151 // Use this class to be able to leak the WebContents, which is needed for when |
| 153 // the current WebContents is used for distillation. | 152 // the current WebContents is used for distillation. |
| 154 class TestDistillerPageWebContents : public DistillerPageWebContents { | 153 class TestDistillerPageWebContents : public DistillerPageWebContents { |
| 155 public: | 154 public: |
| 156 TestDistillerPageWebContents( | 155 TestDistillerPageWebContents( |
| 157 content::BrowserContext* browser_context, | 156 content::BrowserContext* browser_context, |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 ASSERT_TRUE(js_result_); | 515 ASSERT_TRUE(js_result_); |
| 517 ASSERT_TRUE(js_result_->GetAsDictionary(&dict)); | 516 ASSERT_TRUE(js_result_->GetAsDictionary(&dict)); |
| 518 | 517 |
| 519 ASSERT_TRUE(dict->HasKey("success")); | 518 ASSERT_TRUE(dict->HasKey("success")); |
| 520 bool success; | 519 bool success; |
| 521 ASSERT_TRUE(dict->GetBoolean("success", &success)); | 520 ASSERT_TRUE(dict->GetBoolean("success", &success)); |
| 522 EXPECT_TRUE(success); | 521 EXPECT_TRUE(success); |
| 523 } | 522 } |
| 524 | 523 |
| 525 } // namespace dom_distiller | 524 } // namespace dom_distiller |
| OLD | NEW |