Chromium Code Reviews| Index: ash/devtools/ash_devtools_unittest.cc |
| diff --git a/ash/devtools/ash_devtools_unittest.cc b/ash/devtools/ash_devtools_unittest.cc |
| index a1ecc40126c8b139172f36b413355bd1f2e49b9a..f8f14340839f5115abbe8c4559a480b5d2a8fd18 100644 |
| --- a/ash/devtools/ash_devtools_unittest.cc |
| +++ b/ash/devtools/ash_devtools_unittest.cc |
| @@ -7,12 +7,12 @@ |
| #include "ash/devtools/ui_element.h" |
| #include "ash/devtools/window_element.h" |
| #include "ash/public/cpp/shell_window_ids.h" |
| -#include "ash/root_window_controller.h" |
| #include "ash/shell.h" |
| #include "ash/test/ash_test_base.h" |
| #include "ash/wm/widget_finder.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/strings/stringprintf.h" |
| +#include "ui/aura/window_tree_host.h" |
| #include "ui/display/display.h" |
| #include "ui/views/background.h" |
| #include "ui/views/widget/native_widget_private.h" |
| @@ -138,11 +138,8 @@ int GetPropertyByName(const std::string& name, |
| return -1; |
| } |
| -aura::Window* GetHighlightingWindow(int root_window_index) { |
| - const aura::Window::Windows& overlay_windows = |
| - Shell::GetAllRootWindows()[root_window_index] |
| - ->GetChildById(kShellWindowId_OverlayContainer) |
| - ->children(); |
| +aura::Window* GetHighlightingWindow(aura::Window* root_window) { |
| + const aura::Window::Windows& overlay_windows = root_window->children(); |
| for (aura::Window* window : overlay_windows) { |
| if (window->GetName() == "HighlightingWidget") |
| return window; |
| @@ -169,8 +166,8 @@ std::unique_ptr<DOM::HighlightConfig> CreateHighlightConfig( |
| .build(); |
| } |
| -void ExpectHighlighted(const gfx::Rect& bounds, int root_window_index) { |
| - aura::Window* highlighting_window = GetHighlightingWindow(root_window_index); |
| +void ExpectHighlighted(const gfx::Rect& bounds, aura::Window* root_window) { |
| + aura::Window* highlighting_window = GetHighlightingWindow(root_window); |
| EXPECT_TRUE(highlighting_window->IsVisible()); |
| EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen()); |
| EXPECT_EQ(kBackgroundColor, GetInternalWidgetForWindow(highlighting_window) |
| @@ -179,10 +176,6 @@ void ExpectHighlighted(const gfx::Rect& bounds, int root_window_index) { |
| ->get_color()); |
| } |
| -aura::Window* GetPrimaryRootWindow() { |
| - return Shell::Get()->GetPrimaryRootWindow(); |
| -} |
| - |
| } // namespace |
| class AshDevToolsTest : public test::AshTestBase { |
| @@ -194,9 +187,9 @@ class AshDevToolsTest : public test::AshTestBase { |
| views::Widget* widget = new views::Widget; |
| views::Widget::InitParams params; |
| params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; |
| - Shell::GetPrimaryRootWindowController() |
| - ->ConfigureWidgetInitParamsForContainer( |
| - widget, kShellWindowId_DefaultContainer, ¶ms); |
| + DCHECK(dom_agent()->root_windows().size()); |
|
sadrul
2017/05/25 04:21:03
This DCHECK is not needed.
thanhph
2017/05/28 00:04:25
Done.
|
| + params.parent = |
| + GetPrimaryRootWindow()->GetChildById(kShellWindowId_DefaultContainer); |
|
sadrul
2017/05/25 04:21:03
Remove this.
thanhph
2017/05/28 00:04:25
Done.
|
| widget->Init(params); |
| return widget->native_widget_private(); |
| } |
| @@ -207,7 +200,6 @@ class AshDevToolsTest : public test::AshTestBase { |
| } |
| void SetUp() override { |
| - AshTestBase::SetUp(); |
| fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>(); |
| uber_dispatcher_ = |
| base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get()); |
| @@ -217,6 +209,7 @@ class AshDevToolsTest : public test::AshTestBase { |
| base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_agent_.get()); |
| css_agent_->Init(uber_dispatcher_.get()); |
| css_agent_->enable(); |
| + AshTestBase::SetUp(); |
|
sadrul
2017/05/25 04:21:03
Add a comment explaining why this needs to happen
thanhph
2017/05/28 00:04:25
Done.
|
| } |
| void TearDown() override { |
| @@ -287,13 +280,23 @@ class AshDevToolsTest : public test::AshTestBase { |
| void HideHighlight(int root_window_index) { |
| dom_agent_->hideHighlight(); |
| - ASSERT_FALSE(GetHighlightingWindow(root_window_index)->IsVisible()); |
| + DCHECK_GE(root_window_index, 0); |
| + DCHECK_LE(root_window_index, |
| + static_cast<int>(dom_agent()->root_windows().size())); |
| + ASSERT_FALSE( |
| + GetHighlightingWindow(dom_agent()->root_windows()[root_window_index]) |
| + ->IsVisible()); |
| } |
| FakeFrontendChannel* frontend_channel() { |
| return fake_frontend_channel_.get(); |
| } |
| + aura::Window* GetPrimaryRootWindow() { |
| + DCHECK(dom_agent()->root_windows().size()); |
| + return dom_agent()->root_windows()[0]; |
| + } |
| + |
| devtools::AshDevToolsCSSAgent* css_agent() { return css_agent_.get(); } |
| devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); } |
| @@ -634,23 +637,23 @@ TEST_F(AshDevToolsTest, WindowWidgetViewHighlight) { |
| DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0); |
| HighlightNode(window_node->getNodeId()); |
| - ExpectHighlighted(window->GetBoundsInScreen(), 0); |
| + ExpectHighlighted(window->GetBoundsInScreen(), GetPrimaryRootWindow()); |
| HideHighlight(0); |
| HighlightNode(widget_node->getNodeId()); |
| - ExpectHighlighted(widget->GetWindowBoundsInScreen(), 0); |
| + ExpectHighlighted(widget->GetWindowBoundsInScreen(), GetPrimaryRootWindow()); |
| HideHighlight(0); |
| HighlightNode(root_view_node->getNodeId()); |
| - ExpectHighlighted(root_view->GetBoundsInScreen(), 0); |
| + ExpectHighlighted(root_view->GetBoundsInScreen(), GetPrimaryRootWindow()); |
| HideHighlight(0); |
| // Highlight non-existent node |
| HighlightNode(10000); |
| - EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); |
| + EXPECT_FALSE(GetHighlightingWindow(GetPrimaryRootWindow())->IsVisible()); |
| } |
| int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) { |
| @@ -670,27 +673,9 @@ int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) { |
| return 0; |
| } |
| -TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { |
| - UpdateDisplay("300x400,500x500"); |
| - |
| - aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| - std::unique_ptr<aura::Window> window( |
| - CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); |
| - |
| - std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| - dom_agent()->getDocument(&root); |
| - |
| - EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| - HighlightNode( |
| - GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get())); |
| - ExpectHighlighted(window->GetBoundsInScreen(), 0); |
| - |
| - window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay()); |
| - EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| - HighlightNode( |
| - GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get())); |
| - ExpectHighlighted(window->GetBoundsInScreen(), 1); |
| -} |
| +// TODO(thanhph): Make test AshDevToolsTest.MultipleDisplayHighlight work with |
| +// multiple displays by updating params.parent in |
| +// InitializeHighlightingWidget(). |
|
sadrul
2017/05/25 04:21:03
Can you file a bug to fix highlighting widget for
thanhph
2017/05/28 00:04:25
Done.
|
| TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { |
| std::unique_ptr<views::Widget> widget( |