Chromium Code Reviews| Index: components/dom_distiller/content/distiller_page_web_contents_browsertest.cc |
| diff --git a/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc b/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc |
| index dadefe77dc17f73cb700930bb85f945a23db2f50..b438f9e152361a8752a89f71f4a4d15db034aba7 100644 |
| --- a/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc |
| +++ b/components/dom_distiller/content/distiller_page_web_contents_browsertest.cc |
| @@ -5,6 +5,7 @@ |
| #include "base/memory/weak_ptr.h" |
| #include "base/path_service.h" |
| #include "base/run_loop.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "base/values.h" |
| #include "components/dom_distiller/content/distiller_page_web_contents.h" |
| #include "components/dom_distiller/content/web_contents_main_frame_observer.h" |
| @@ -60,6 +61,11 @@ class DistillerPageWebContentsTest : public ContentBrowserTest { |
| quit_closure_.Run(); |
| } |
| + void OnJsExecutionDone(const base::Value* value) { |
| + js_result_ = value->DeepCopy(); |
| + callback_.Run(); |
| + } |
| + |
| private: |
| void AddComponentsResources() { |
| base::FilePath pak_file; |
| @@ -88,6 +94,8 @@ class DistillerPageWebContentsTest : public ContentBrowserTest { |
| DistillerPageWebContents* distiller_page_; |
| base::Closure quit_closure_; |
| scoped_ptr<proto::DomDistillerResult> distiller_result_; |
| + base::Closure callback_; |
| + const base::Value* js_result_; |
| }; |
| // Use this class to be able to leak the WebContents, which is needed for when |
| @@ -519,4 +527,41 @@ IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, |
| } |
| } |
| +IN_PROC_BROWSER_TEST_F(DistillerPageWebContentsTest, |
| + TestPinch) { |
| + // Load the test file in content shell and wait until it has fully loaded. |
| + content::WebContents* web_contents = shell()->web_contents(); |
| + dom_distiller::WebContentsMainFrameObserver::CreateForWebContents( |
| + web_contents); |
| + base::RunLoop url_loaded_runner; |
| + WebContentsMainFrameHelper main_frame_loaded(web_contents, |
| + url_loaded_runner.QuitClosure(), |
| + true); |
| + web_contents->GetController().LoadURL( |
| + embedded_test_server()->GetURL("pinch_tester.html"), |
| + content::Referrer(), |
| + ui::PAGE_TRANSITION_TYPED, |
| + std::string()); |
| + url_loaded_runner.Run(); |
| + |
| + // Execute the JS to run the tests, and wait until it has finished. |
| + base::RunLoop run_loop; |
| + callback_ = run_loop.QuitClosure(); |
|
jdduke (slow)
2015/03/23 15:42:06
To avoid confusion with the existing quit_closure_
wychen
2015/03/24 22:52:08
Done.
|
| + web_contents->GetMainFrame()->ExecuteJavaScript( |
| + base::UTF8ToUTF16("(function() {return pinchtest.run();})();"), |
| + base::Bind(&DistillerPageWebContentsTest::OnJsExecutionDone, |
| + base::Unretained(this))); |
| + run_loop.Run(); |
| + |
| + // Convert to dictionary and parse the results. |
| + const base::DictionaryValue* dict; |
| + js_result_->GetAsDictionary(&dict); |
| + ASSERT_TRUE(js_result_->GetAsDictionary(&dict)); |
| + |
| + ASSERT_TRUE(dict->HasKey("success")); |
| + bool success; |
| + ASSERT_TRUE(dict->GetBoolean("success", &success)); |
| + EXPECT_TRUE(success); |
| +} |
| + |
| } // namespace dom_distiller |