diff options
Diffstat (limited to 'content/browser/devtools/protocol/devtools_protocol_browsertest.cc')
-rw-r--r-- | content/browser/devtools/protocol/devtools_protocol_browsertest.cc | 134 |
1 files changed, 130 insertions, 4 deletions
diff --git a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc index cbbd46a..cbae682 100644 --- a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc +++ b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc @@ -6,10 +6,12 @@ #include "base/command_line.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" +#include "base/values.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/web_contents.h" #include "content/public/test/browser_test_utils.h" #include "content/public/test/content_browser_test.h" +#include "content/public/test/content_browser_test_utils.h" #include "content/shell/browser/shell.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/compositor/compositor_switches.h" @@ -67,10 +69,6 @@ class DevToolsProtocolTest : public ContentBrowserTest, return false; } - scoped_ptr<base::DictionaryValue> result_; - scoped_refptr<DevToolsAgentHost> agent_host_; - - private: void SetUpOnMainThread() override { agent_host_ = DevToolsAgentHost::GetOrCreateFor(shell()->web_contents()); agent_host_->AttachClient(this); @@ -81,6 +79,10 @@ class DevToolsProtocolTest : public ContentBrowserTest, agent_host_ = NULL; } + scoped_ptr<base::DictionaryValue> result_; + scoped_refptr<DevToolsAgentHost> agent_host_; + + private: void DispatchProtocolMessage(DevToolsAgentHost* agent_host, const std::string& message) override { scoped_ptr<base::DictionaryValue> root( @@ -135,4 +137,128 @@ IN_PROC_BROWSER_TEST_F(CaptureScreenshotTest, MAYBE_CaptureScreenshot) { EXPECT_TRUE(std::abs(0x56-(int)SkColorGetB(color)) <= 1); } +class SyntheticGestureTest : public DevToolsProtocolTest { +#if !defined(OS_ANDROID) + protected: + void SetUpOnMainThread() override { + DevToolsProtocolTest::SetUpOnMainThread(); + + scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); + params->SetInteger("width", 384); + params->SetInteger("height", 640); + params->SetDouble("deviceScaleFactor", 2.0); + params->SetBoolean("mobile", true); + params->SetBoolean("fitWindow", false); + params->SetBoolean("textAutosizing", true); + SendCommand("Page.setDeviceMetricsOverride", params.Pass()); + + params.reset(new base::DictionaryValue()); + params->SetBoolean("enabled", true); + params->SetString("configuration", "mobile"); + SendCommand("Page.setTouchEmulationEnabled", params.Pass()); + } +#endif +}; + +#if defined(OS_ANDROID) +// crbug.com/469947 +#define MAYBE_SynthesizePinchGesture DISABLED_SynthesizePinchGesture +#else +// crbug.com/460128 +#define MAYBE_SynthesizePinchGesture DISABLED_SynthesizePinchGesture +#endif +IN_PROC_BROWSER_TEST_F(SyntheticGestureTest, MAYBE_SynthesizePinchGesture) { + GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); + NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); + + int old_width; + ASSERT_TRUE(content::ExecuteScriptAndExtractInt( + shell()->web_contents(), + "domAutomationController.send(window.innerWidth)", &old_width)); + + int old_height; + ASSERT_TRUE(content::ExecuteScriptAndExtractInt( + shell()->web_contents(), + "domAutomationController.send(window.innerHeight)", &old_height)); + + scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); + params->SetInteger("x", old_width / 2); + params->SetInteger("y", old_height / 2); + params->SetDouble("scaleFactor", 2.0); + SendCommand("Input.synthesizePinchGesture", params.Pass()); + + int new_width; + ASSERT_TRUE(content::ExecuteScriptAndExtractInt( + shell()->web_contents(), + "domAutomationController.send(window.innerWidth)", &new_width)); + ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_width) / new_width); + + int new_height; + ASSERT_TRUE(content::ExecuteScriptAndExtractInt( + shell()->web_contents(), + "domAutomationController.send(window.innerHeight)", &new_height)); + ASSERT_DOUBLE_EQ(2.0, static_cast<double>(old_height) / new_height); +} + +#if defined(OS_ANDROID) +#define MAYBE_SynthesizeScrollGesture SynthesizeScrollGesture +#else +// crbug.com/460128 +#define MAYBE_SynthesizeScrollGesture DISABLED_SynthesizeScrollGesture +#endif +IN_PROC_BROWSER_TEST_F(SyntheticGestureTest, MAYBE_SynthesizeScrollGesture) { + GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); + NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); + + int scroll_top; + ASSERT_TRUE(content::ExecuteScriptAndExtractInt( + shell()->web_contents(), + "domAutomationController.send(document.body.scrollTop)", &scroll_top)); + ASSERT_EQ(0, scroll_top); + + scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); + params->SetInteger("x", 0); + params->SetInteger("y", 0); + params->SetInteger("xDistance", 0); + params->SetInteger("yDistance", -100); + SendCommand("Input.synthesizeScrollGesture", params.Pass()); + + ASSERT_TRUE(content::ExecuteScriptAndExtractInt( + shell()->web_contents(), + "domAutomationController.send(document.body.scrollTop)", &scroll_top)); + ASSERT_EQ(100, scroll_top); +} + +#if defined(OS_ANDROID) +#define MAYBE_SynthesizeTapGesture SynthesizeTapGesture +#else +// crbug.com/460128 +#define MAYBE_SynthesizeTapGesture DISABLED_SynthesizeTapGesture +#endif +IN_PROC_BROWSER_TEST_F(SyntheticGestureTest, MAYBE_SynthesizeTapGesture) { + GURL test_url = GetTestUrl("devtools", "synthetic_gesture_tests.html"); + NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); + + int scroll_top; + ASSERT_TRUE(content::ExecuteScriptAndExtractInt( + shell()->web_contents(), + "domAutomationController.send(document.body.scrollTop)", &scroll_top)); + ASSERT_EQ(0, scroll_top); + + scoped_ptr<base::DictionaryValue> params(new base::DictionaryValue()); + params->SetInteger("x", 16); + params->SetInteger("y", 16); + params->SetString("gestureSourceType", "touch"); + SendCommand("Input.synthesizeTapGesture", params.Pass()); + + // The link that we just tapped should take us to the bottom of the page. The + // new value of |document.body.scrollTop| will depend on the screen dimensions + // of the device that we're testing on, but in any case it should be greater + // than 0. + ASSERT_TRUE(content::ExecuteScriptAndExtractInt( + shell()->web_contents(), + "domAutomationController.send(document.body.scrollTop)", &scroll_top)); + ASSERT_GT(scroll_top, 0); +} + } // namespace content |