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/values.h" | 9 #include "base/values.h" |
9 #include "components/dom_distiller/content/distiller_page_web_contents.h" | 10 #include "components/dom_distiller/content/distiller_page_web_contents.h" |
10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" | 11 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" |
11 #include "components/dom_distiller/core/distiller_page.h" | 12 #include "components/dom_distiller/core/distiller_page.h" |
12 #include "components/dom_distiller/core/proto/distilled_article.pb.h" | 13 #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
13 #include "components/dom_distiller/core/proto/distilled_page.pb.h" | 14 #include "components/dom_distiller/core/proto/distilled_page.pb.h" |
14 #include "components/dom_distiller/core/viewer.h" | 15 #include "components/dom_distiller/core/viewer.h" |
15 #include "content/public/browser/browser_context.h" | 16 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/render_frame_host.h" | 18 #include "content/public/browser/render_frame_host.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 this)); | 54 this)); |
54 } | 55 } |
55 | 56 |
56 void OnPageDistillationFinished( | 57 void OnPageDistillationFinished( |
57 scoped_ptr<proto::DomDistillerResult> distiller_result, | 58 scoped_ptr<proto::DomDistillerResult> distiller_result, |
58 bool distillation_successful) { | 59 bool distillation_successful) { |
59 distiller_result_ = distiller_result.Pass(); | 60 distiller_result_ = distiller_result.Pass(); |
60 quit_closure_.Run(); | 61 quit_closure_.Run(); |
61 } | 62 } |
62 | 63 |
64 void OnJsExecutionDone(base::Closure callback, const base::Value* value) { | |
65 js_result_ = value->DeepCopy(); | |
66 callback.Run(); | |
67 } | |
68 | |
63 private: | 69 private: |
64 void AddComponentsResources() { | 70 void AddComponentsResources() { |
65 base::FilePath pak_file; | 71 base::FilePath pak_file; |
66 base::FilePath pak_dir; | 72 base::FilePath pak_dir; |
67 PathService::Get(base::DIR_MODULE, &pak_dir); | 73 PathService::Get(base::DIR_MODULE, &pak_dir); |
68 pak_file = | 74 pak_file = |
69 pak_dir.Append(FILE_PATH_LITERAL("components_tests_resources.pak")); | 75 pak_dir.Append(FILE_PATH_LITERAL("components_tests_resources.pak")); |
70 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( | 76 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( |
71 pak_file, ui::SCALE_FACTOR_NONE); | 77 pak_file, ui::SCALE_FACTOR_NONE); |
72 } | 78 } |
73 | 79 |
74 void SetUpTestServer() { | 80 void SetUpTestServer() { |
75 base::FilePath path; | 81 base::FilePath path; |
76 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 82 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
77 path = path.AppendASCII("components/test/data/dom_distiller"); | 83 path = path.AppendASCII("components/test/data/dom_distiller"); |
78 embedded_test_server()->ServeFilesFromDirectory(path); | 84 embedded_test_server()->ServeFilesFromDirectory(path); |
79 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 85 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
80 } | 86 } |
81 | 87 |
82 protected: | 88 protected: |
83 void RunUseCurrentWebContentsTest(const std::string& url, | 89 void RunUseCurrentWebContentsTest(const std::string& url, |
84 bool expect_new_web_contents, | 90 bool expect_new_web_contents, |
85 bool setup_main_frame_observer, | 91 bool setup_main_frame_observer, |
86 bool wait_for_document_loaded); | 92 bool wait_for_document_loaded); |
87 | 93 |
88 DistillerPageWebContents* distiller_page_; | 94 DistillerPageWebContents* distiller_page_; |
89 base::Closure quit_closure_; | 95 base::Closure quit_closure_; |
90 scoped_ptr<proto::DomDistillerResult> distiller_result_; | 96 scoped_ptr<proto::DomDistillerResult> distiller_result_; |
97 const base::Value* js_result_; | |
jdduke (slow)
2015/04/02 23:34:22
Shouldn't this be |scoped_ptr<base::Value> js_resu
wychen
2015/04/03 07:04:39
Done.
| |
91 }; | 98 }; |
92 | 99 |
93 // Use this class to be able to leak the WebContents, which is needed for when | 100 // Use this class to be able to leak the WebContents, which is needed for when |
94 // the current WebContents is used for distillation. | 101 // the current WebContents is used for distillation. |
95 class TestDistillerPageWebContents : public DistillerPageWebContents { | 102 class TestDistillerPageWebContents : public DistillerPageWebContents { |
96 public: | 103 public: |
97 TestDistillerPageWebContents( | 104 TestDistillerPageWebContents( |
98 content::BrowserContext* browser_context, | 105 content::BrowserContext* browser_context, |
99 const gfx::Size& render_view_size, | 106 const gfx::Size& render_view_size, |
100 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle, | 107 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle, |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
512 page_proto->set_title(some_title); | 519 page_proto->set_title(some_title); |
513 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), | 520 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), |
514 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); | 521 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); |
515 EXPECT_THAT(html, HasSubstr(some_title)); | 522 EXPECT_THAT(html, HasSubstr(some_title)); |
516 EXPECT_THAT(html, HasSubstr(no_content)); | 523 EXPECT_THAT(html, HasSubstr(no_content)); |
517 EXPECT_THAT(html, Not(HasSubstr(no_title))); | 524 EXPECT_THAT(html, Not(HasSubstr(no_title))); |
518 EXPECT_THAT(html, Not(HasSubstr(some_content))); | 525 EXPECT_THAT(html, Not(HasSubstr(some_content))); |
519 } | 526 } |
520 } | 527 } |
521 | 528 |
529 IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, | |
530 TestPinch) { | |
531 // Load the test file in content shell and wait until it has fully loaded. | |
532 content::WebContents* web_contents = shell()->web_contents(); | |
533 dom_distiller::WebContentsMainFrameObserver::CreateForWebContents( | |
534 web_contents); | |
535 base::RunLoop url_loaded_runner; | |
536 WebContentsMainFrameHelper main_frame_loaded(web_contents, | |
537 url_loaded_runner.QuitClosure(), | |
538 true); | |
539 web_contents->GetController().LoadURL( | |
540 embedded_test_server()->GetURL("pinch_tester.html"), | |
541 content::Referrer(), | |
542 ui::PAGE_TRANSITION_TYPED, | |
543 std::string()); | |
544 url_loaded_runner.Run(); | |
545 | |
546 // Execute the JS to run the tests, and wait until it has finished. | |
547 base::RunLoop run_loop; | |
548 web_contents->GetMainFrame()->ExecuteJavaScript( | |
549 base::UTF8ToUTF16("(function() {return pinchtest.run();})();"), | |
550 base::Bind(&DistillerPageWebContentsTest::OnJsExecutionDone, | |
551 base::Unretained(this), run_loop.QuitClosure())); | |
552 run_loop.Run(); | |
553 | |
554 // Convert to dictionary and parse the results. | |
555 const base::DictionaryValue* dict; | |
jdduke (slow)
2015/04/02 23:34:22
ASSERT_TRUE(js_result_);
wychen
2015/04/03 07:04:39
Done.
| |
556 js_result_->GetAsDictionary(&dict); | |
557 ASSERT_TRUE(js_result_->GetAsDictionary(&dict)); | |
558 | |
559 ASSERT_TRUE(dict->HasKey("success")); | |
560 bool success; | |
561 ASSERT_TRUE(dict->GetBoolean("success", &success)); | |
562 EXPECT_TRUE(success); | |
563 } | |
564 | |
522 } // namespace dom_distiller | 565 } // namespace dom_distiller |
OLD | NEW |