Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Unified Diff: content/browser/devtools/protocol/devtools_protocol_browsertest.cc

Issue 2226323002: Resize DevTools target frames. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename, add tests, fix comments/style, add support in shell. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/devtools/protocol/devtools_protocol_browsertest.cc
diff --git a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
index 0c577b651df47ac9e6df319f0b71e1cd4f610cc1..0fbd298d146008e97037202ac80915ba272d1dc8 100644
--- a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
+++ b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
@@ -19,6 +19,7 @@
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/browser_test_utils.h"
@@ -33,6 +34,12 @@
#include "ui/compositor/compositor_switches.h"
#include "ui/gfx/codec/png_codec.h"
+#define EXPECT_SIZE_EQ(expected, actual) \
alex clarke (OOO till 29th) 2016/08/10 12:39:48 Consider doing this instead: std::ostream& operat
Eric Seckler 2016/08/10 12:57:06 I like this better, since it avoids the conversion
+ do { \
+ EXPECT_EQ((expected).width(), (actual).width()); \
+ EXPECT_EQ((expected).height(), (actual).height()); \
+ } while (false)
+
using testing::ElementsAre;
namespace content {
@@ -685,14 +692,91 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, JavaScriptDialogNotifications) {
dialog_manager.Handle();
}
-IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserCreateTarget) {
+IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserCreateAndCloseTarget) {
NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
Attach();
EXPECT_EQ(1u, shell()->windows().size());
+
+ // Create target with default size.
std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
params->SetString("url", "about:blank");
SendCommand("Browser.createTarget", std::move(params), true);
- EXPECT_EQ(2u, shell()->windows().size());
+ std::string target_id1;
+ EXPECT_TRUE(result_->GetString("targetId", &target_id1));
+ gfx::Size expected_size = (shell()->web_contents())
+ ->GetRenderWidgetHostView()
+ ->GetViewBounds()
+ .size();
+ gfx::Size actual_size = (shell()->windows().back()->web_contents())
+ ->GetRenderWidgetHostView()
+ ->GetViewBounds()
+ .size();
+ EXPECT_SIZE_EQ(expected_size, actual_size);
+
+ // Create target with custom frame size.
+ params.reset(new base::DictionaryValue());
+ params->SetString("url", "about:blank");
+ params->SetInteger("width", 200);
+ params->SetInteger("height", 400);
+ SendCommand("Browser.createTarget", std::move(params), true);
+ std::string target_id2;
+ EXPECT_TRUE(result_->GetString("targetId", &target_id2));
+ EXPECT_EQ(3u, shell()->windows().size());
+ actual_size = (shell()->windows().back()->web_contents())
+ ->GetRenderWidgetHostView()
+ ->GetViewBounds()
+ .size();
+ EXPECT_SIZE_EQ(gfx::Size(200, 400), actual_size);
+
+ // Close targets.
+ // TODO(eseckler): Since closing RenderViews may happen asynchronously, we
+ // currently don't verify that the commands actually close the shells.
+ bool success;
+ params.reset(new base::DictionaryValue());
+ params->SetString("targetId", target_id1);
+ SendCommand("Browser.closeTarget", std::move(params), true);
+ EXPECT_TRUE(result_->GetBoolean("success", &success));
+ EXPECT_TRUE(success);
+ params.reset(new base::DictionaryValue());
+ params->SetString("targetId", target_id2);
+ SendCommand("Browser.closeTarget", std::move(params), true);
+ EXPECT_TRUE(result_->GetBoolean("success", &success));
+ EXPECT_TRUE(success);
+}
+
+IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserGetAndSetFrameSize) {
+ NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
+ Attach();
+ EXPECT_EQ(1u, shell()->windows().size());
+ int width, height = 0;
+
+ // Get default size.
+ std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
+ params->SetString("targetId", agent_host_->GetId());
+ SendCommand("Browser.getFrameSize", std::move(params), true);
+ EXPECT_TRUE(result_->GetInteger("width", &width));
+ EXPECT_TRUE(result_->GetInteger("height", &height));
+ EXPECT_SIZE_EQ(shell()->GetShellDefaultSize(), gfx::Size(width, height));
+
+ // Resize frame.
+ gfx::Size new_size(200, 400);
+ params.reset(new base::DictionaryValue());
+ params->SetString("targetId", agent_host_->GetId());
+ params->SetInteger("width", new_size.width());
+ params->SetInteger("height", new_size.height());
+ SendCommand("Browser.setFrameSize", std::move(params), true);
+ EXPECT_SIZE_EQ(new_size, (shell()->web_contents())
+ ->GetRenderWidgetHostView()
+ ->GetViewBounds()
+ .size());
+
+ // Get updated size.
+ params.reset(new base::DictionaryValue());
+ params->SetString("targetId", agent_host_->GetId());
+ SendCommand("Browser.getFrameSize", std::move(params), true);
+ EXPECT_TRUE(result_->GetInteger("width", &width));
+ EXPECT_TRUE(result_->GetInteger("height", &height));
+ EXPECT_SIZE_EQ(new_size, gfx::Size(width, height));
}
namespace {

Powered by Google App Engine
This is Rietveld 408576698