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

Side by Side 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 unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "content/public/browser/devtools_agent_host.h" 17 #include "content/public/browser/devtools_agent_host.h"
18 #include "content/public/browser/javascript_dialog_manager.h" 18 #include "content/public/browser/javascript_dialog_manager.h"
19 #include "content/public/browser/navigation_handle.h" 19 #include "content/public/browser/navigation_handle.h"
20 #include "content/public/browser/render_frame_host.h" 20 #include "content/public/browser/render_frame_host.h"
21 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/browser/web_contents.h" 23 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/url_constants.h" 24 #include "content/public/common/url_constants.h"
24 #include "content/public/test/browser_test_utils.h" 25 #include "content/public/test/browser_test_utils.h"
25 #include "content/public/test/content_browser_test.h" 26 #include "content/public/test/content_browser_test.h"
26 #include "content/public/test/content_browser_test_utils.h" 27 #include "content/public/test/content_browser_test_utils.h"
27 #include "content/public/test/test_navigation_observer.h" 28 #include "content/public/test/test_navigation_observer.h"
28 #include "content/shell/browser/shell.h" 29 #include "content/shell/browser/shell.h"
29 #include "net/dns/mock_host_resolver.h" 30 #include "net/dns/mock_host_resolver.h"
30 #include "net/test/embedded_test_server/embedded_test_server.h" 31 #include "net/test/embedded_test_server/embedded_test_server.h"
31 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
32 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
33 #include "ui/compositor/compositor_switches.h" 34 #include "ui/compositor/compositor_switches.h"
34 #include "ui/gfx/codec/png_codec.h" 35 #include "ui/gfx/codec/png_codec.h"
35 36
37 #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
38 do { \
39 EXPECT_EQ((expected).width(), (actual).width()); \
40 EXPECT_EQ((expected).height(), (actual).height()); \
41 } while (false)
42
36 using testing::ElementsAre; 43 using testing::ElementsAre;
37 44
38 namespace content { 45 namespace content {
39 46
40 namespace { 47 namespace {
41 48
42 const char kIdParam[] = "id"; 49 const char kIdParam[] = "id";
43 const char kMethodParam[] = "method"; 50 const char kMethodParam[] = "method";
44 const char kParamsParam[] = "params"; 51 const char kParamsParam[] = "params";
45 52
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 TestJavaScriptDialogManager dialog_manager; 685 TestJavaScriptDialogManager dialog_manager;
679 shell()->web_contents()->SetDelegate(&dialog_manager); 686 shell()->web_contents()->SetDelegate(&dialog_manager);
680 SendCommand("Page.enable", nullptr, true); 687 SendCommand("Page.enable", nullptr, true);
681 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); 688 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
682 params->SetString("expression", "alert('alert')"); 689 params->SetString("expression", "alert('alert')");
683 SendCommand("Runtime.evaluate", std::move(params), false); 690 SendCommand("Runtime.evaluate", std::move(params), false);
684 WaitForNotification("Page.javascriptDialogOpening"); 691 WaitForNotification("Page.javascriptDialogOpening");
685 dialog_manager.Handle(); 692 dialog_manager.Handle();
686 } 693 }
687 694
688 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserCreateTarget) { 695 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserCreateAndCloseTarget) {
689 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); 696 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
690 Attach(); 697 Attach();
691 EXPECT_EQ(1u, shell()->windows().size()); 698 EXPECT_EQ(1u, shell()->windows().size());
699
700 // Create target with default size.
692 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); 701 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
693 params->SetString("url", "about:blank"); 702 params->SetString("url", "about:blank");
694 SendCommand("Browser.createTarget", std::move(params), true); 703 SendCommand("Browser.createTarget", std::move(params), true);
695 EXPECT_EQ(2u, shell()->windows().size()); 704 std::string target_id1;
705 EXPECT_TRUE(result_->GetString("targetId", &target_id1));
706 gfx::Size expected_size = (shell()->web_contents())
707 ->GetRenderWidgetHostView()
708 ->GetViewBounds()
709 .size();
710 gfx::Size actual_size = (shell()->windows().back()->web_contents())
711 ->GetRenderWidgetHostView()
712 ->GetViewBounds()
713 .size();
714 EXPECT_SIZE_EQ(expected_size, actual_size);
715
716 // Create target with custom frame size.
717 params.reset(new base::DictionaryValue());
718 params->SetString("url", "about:blank");
719 params->SetInteger("width", 200);
720 params->SetInteger("height", 400);
721 SendCommand("Browser.createTarget", std::move(params), true);
722 std::string target_id2;
723 EXPECT_TRUE(result_->GetString("targetId", &target_id2));
724 EXPECT_EQ(3u, shell()->windows().size());
725 actual_size = (shell()->windows().back()->web_contents())
726 ->GetRenderWidgetHostView()
727 ->GetViewBounds()
728 .size();
729 EXPECT_SIZE_EQ(gfx::Size(200, 400), actual_size);
730
731 // Close targets.
732 // TODO(eseckler): Since closing RenderViews may happen asynchronously, we
733 // currently don't verify that the commands actually close the shells.
734 bool success;
735 params.reset(new base::DictionaryValue());
736 params->SetString("targetId", target_id1);
737 SendCommand("Browser.closeTarget", std::move(params), true);
738 EXPECT_TRUE(result_->GetBoolean("success", &success));
739 EXPECT_TRUE(success);
740 params.reset(new base::DictionaryValue());
741 params->SetString("targetId", target_id2);
742 SendCommand("Browser.closeTarget", std::move(params), true);
743 EXPECT_TRUE(result_->GetBoolean("success", &success));
744 EXPECT_TRUE(success);
745 }
746
747 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, BrowserGetAndSetFrameSize) {
748 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
749 Attach();
750 EXPECT_EQ(1u, shell()->windows().size());
751 int width, height = 0;
752
753 // Get default size.
754 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
755 params->SetString("targetId", agent_host_->GetId());
756 SendCommand("Browser.getFrameSize", std::move(params), true);
757 EXPECT_TRUE(result_->GetInteger("width", &width));
758 EXPECT_TRUE(result_->GetInteger("height", &height));
759 EXPECT_SIZE_EQ(shell()->GetShellDefaultSize(), gfx::Size(width, height));
760
761 // Resize frame.
762 gfx::Size new_size(200, 400);
763 params.reset(new base::DictionaryValue());
764 params->SetString("targetId", agent_host_->GetId());
765 params->SetInteger("width", new_size.width());
766 params->SetInteger("height", new_size.height());
767 SendCommand("Browser.setFrameSize", std::move(params), true);
768 EXPECT_SIZE_EQ(new_size, (shell()->web_contents())
769 ->GetRenderWidgetHostView()
770 ->GetViewBounds()
771 .size());
772
773 // Get updated size.
774 params.reset(new base::DictionaryValue());
775 params->SetString("targetId", agent_host_->GetId());
776 SendCommand("Browser.getFrameSize", std::move(params), true);
777 EXPECT_TRUE(result_->GetInteger("width", &width));
778 EXPECT_TRUE(result_->GetInteger("height", &height));
779 EXPECT_SIZE_EQ(new_size, gfx::Size(width, height));
696 } 780 }
697 781
698 namespace { 782 namespace {
699 class NavigationFinishedObserver : public content::WebContentsObserver { 783 class NavigationFinishedObserver : public content::WebContentsObserver {
700 public: 784 public:
701 explicit NavigationFinishedObserver(WebContents* web_contents) 785 explicit NavigationFinishedObserver(WebContents* web_contents)
702 : WebContentsObserver(web_contents), 786 : WebContentsObserver(web_contents),
703 num_finished_(0), 787 num_finished_(0),
704 num_to_wait_for_(0) {} 788 num_to_wait_for_(0) {}
705 789
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 params->SetString("policy", "advance"); 965 params->SetString("policy", "advance");
882 params->SetInteger("budget", 1000); 966 params->SetInteger("budget", 1000);
883 SendCommand("Emulation.setVirtualTimePolicy", std::move(params), true); 967 SendCommand("Emulation.setVirtualTimePolicy", std::move(params), true);
884 968
885 WaitForNotification("Emulation.virtualTimeBudgetExpired"); 969 WaitForNotification("Emulation.virtualTimeBudgetExpired");
886 970
887 EXPECT_THAT(console_messages_, ElementsAre("before", "done", "after")); 971 EXPECT_THAT(console_messages_, ElementsAre("before", "done", "after"));
888 } 972 }
889 973
890 } // namespace content 974 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698