| 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_page_web_contents.h" | 10 #include "components/dom_distiller/content/distiller_page_web_contents.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle, | 154 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle, |
| 155 bool expect_new_web_contents) | 155 bool expect_new_web_contents) |
| 156 : DistillerPageWebContents(browser_context, render_view_size, | 156 : DistillerPageWebContents(browser_context, render_view_size, |
| 157 optional_web_contents_handle.Pass()), | 157 optional_web_contents_handle.Pass()), |
| 158 expect_new_web_contents_(expect_new_web_contents), | 158 expect_new_web_contents_(expect_new_web_contents), |
| 159 new_web_contents_created_(false) {} | 159 new_web_contents_created_(false) {} |
| 160 | 160 |
| 161 void CreateNewWebContents(const GURL& url) override { | 161 void CreateNewWebContents(const GURL& url) override { |
| 162 ASSERT_EQ(true, expect_new_web_contents_); | 162 ASSERT_EQ(true, expect_new_web_contents_); |
| 163 new_web_contents_created_ = true; | 163 new_web_contents_created_ = true; |
| 164 // DistillerPageWebContents::CreateNewWebContents resets the scoped_ptr to | |
| 165 // the WebContents, so intentionally leak WebContents here, since it is | |
| 166 // owned by the shell. | |
| 167 content::WebContents* web_contents = web_contents_.release(); | |
| 168 web_contents->GetLastCommittedURL(); | |
| 169 DistillerPageWebContents::CreateNewWebContents(url); | 164 DistillerPageWebContents::CreateNewWebContents(url); |
| 170 } | 165 } |
| 171 | 166 |
| 172 ~TestDistillerPageWebContents() override { | |
| 173 if (!expect_new_web_contents_) { | |
| 174 // Intentionally leaking WebContents, since it is owned by the shell. | |
| 175 content::WebContents* web_contents = web_contents_.release(); | |
| 176 web_contents->GetLastCommittedURL(); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 bool new_web_contents_created() { return new_web_contents_created_; } | 167 bool new_web_contents_created() { return new_web_contents_created_; } |
| 181 | 168 |
| 182 private: | 169 private: |
| 183 bool expect_new_web_contents_; | 170 bool expect_new_web_contents_; |
| 184 bool new_web_contents_created_; | 171 bool new_web_contents_created_; |
| 185 }; | 172 }; |
| 186 | 173 |
| 187 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, BasicDistillationWorks) { | 174 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, BasicDistillationWorks) { |
| 188 DistillerPageWebContents distiller_page( | 175 DistillerPageWebContents distiller_page( |
| 189 shell()->web_contents()->GetBrowserContext(), | 176 shell()->web_contents()->GetBrowserContext(), |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 WebContentsMainFrameHelper main_frame_loaded(current_web_contents, | 340 WebContentsMainFrameHelper main_frame_loaded(current_web_contents, |
| 354 url_loaded_runner.QuitClosure(), | 341 url_loaded_runner.QuitClosure(), |
| 355 wait_for_document_loaded); | 342 wait_for_document_loaded); |
| 356 current_web_contents->GetController().LoadURL( | 343 current_web_contents->GetController().LoadURL( |
| 357 embedded_test_server()->GetURL(url), | 344 embedded_test_server()->GetURL(url), |
| 358 content::Referrer(), | 345 content::Referrer(), |
| 359 ui::PAGE_TRANSITION_TYPED, | 346 ui::PAGE_TRANSITION_TYPED, |
| 360 std::string()); | 347 std::string()); |
| 361 url_loaded_runner.Run(); | 348 url_loaded_runner.Run(); |
| 362 | 349 |
| 363 scoped_ptr<content::WebContents> old_web_contents_sptr(current_web_contents); | |
| 364 scoped_ptr<SourcePageHandleWebContents> source_page_handle( | 350 scoped_ptr<SourcePageHandleWebContents> source_page_handle( |
| 365 new SourcePageHandleWebContents(old_web_contents_sptr.Pass())); | 351 new SourcePageHandleWebContents(current_web_contents, false)); |
| 366 | 352 |
| 367 TestDistillerPageWebContents distiller_page( | 353 TestDistillerPageWebContents distiller_page( |
| 368 shell()->web_contents()->GetBrowserContext(), | 354 shell()->web_contents()->GetBrowserContext(), |
| 369 shell()->web_contents()->GetContainerBounds().size(), | 355 shell()->web_contents()->GetContainerBounds().size(), |
| 370 source_page_handle.Pass(), | 356 source_page_handle.Pass(), |
| 371 expect_new_web_contents); | 357 expect_new_web_contents); |
| 372 distiller_page_ = &distiller_page; | 358 distiller_page_ = &distiller_page; |
| 373 | 359 |
| 374 base::RunLoop run_loop; | 360 base::RunLoop run_loop; |
| 375 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); | 361 DistillPage(run_loop.QuitClosure(), kSimpleArticlePath); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 ASSERT_TRUE(js_result_); | 504 ASSERT_TRUE(js_result_); |
| 519 ASSERT_TRUE(js_result_->GetAsDictionary(&dict)); | 505 ASSERT_TRUE(js_result_->GetAsDictionary(&dict)); |
| 520 | 506 |
| 521 ASSERT_TRUE(dict->HasKey("success")); | 507 ASSERT_TRUE(dict->HasKey("success")); |
| 522 bool success; | 508 bool success; |
| 523 ASSERT_TRUE(dict->GetBoolean("success", &success)); | 509 ASSERT_TRUE(dict->GetBoolean("success", &success)); |
| 524 EXPECT_TRUE(success); | 510 EXPECT_TRUE(success); |
| 525 } | 511 } |
| 526 | 512 |
| 527 } // namespace dom_distiller | 513 } // namespace dom_distiller |
| OLD | NEW |