| Index: ash/common/devtools/ash_devtools_unittest.cc
|
| diff --git a/ash/common/devtools/ash_devtools_unittest.cc b/ash/common/devtools/ash_devtools_unittest.cc
|
| index 4bdcb034d756fc6d0cd081d6054616e722f78b93..c67c83128606c99009378e6b39c8abffa5aa6787 100644
|
| --- a/ash/common/devtools/ash_devtools_unittest.cc
|
| +++ b/ash/common/devtools/ash_devtools_unittest.cc
|
| @@ -27,6 +27,38 @@ class TestView : public views::View {
|
| DISALLOW_COPY_AND_ASSIGN(TestView);
|
| };
|
|
|
| +class FakeFrontendChannel : public FrontendChannel {
|
| + public:
|
| + FakeFrontendChannel() {}
|
| + ~FakeFrontendChannel() override {}
|
| +
|
| + int CountProtocolNotificationMessageStartsWith(const std::string& message) {
|
| + int count = 0;
|
| + for (const std::string& s : protocol_notification_messages_) {
|
| + if (base::StartsWith(s, message, base::CompareCase::SENSITIVE))
|
| + count++;
|
| + }
|
| + return count;
|
| + }
|
| +
|
| + int CountProtocolNotificationMessage(const std::string& message) {
|
| + return std::count(protocol_notification_messages_.begin(),
|
| + protocol_notification_messages_.end(), message);
|
| + }
|
| +
|
| + // FrontendChannel
|
| + void sendProtocolResponse(int callId, const std::string& message) override {}
|
| + void flushProtocolNotifications() override {}
|
| + void sendProtocolNotification(const std::string& message) override {
|
| + protocol_notification_messages_.push_back(message);
|
| + }
|
| +
|
| + private:
|
| + std::vector<std::string> protocol_notification_messages_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FakeFrontendChannel);
|
| +};
|
| +
|
| std::string GetAttributeValue(const std::string& attribute, DOM::Node* node) {
|
| EXPECT_TRUE(node->hasAttributes());
|
| Array<std::string>* attributes = node->getAttributes(nullptr);
|
| @@ -99,18 +131,46 @@ class AshDevToolsTest : public AshTest {
|
|
|
| void SetUp() override {
|
| AshTest::SetUp();
|
| + fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>();
|
| + uber_dispatcher_ =
|
| + base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get());
|
| dom_agent_ =
|
| base::MakeUnique<devtools::AshDevToolsDOMAgent>(WmShell::Get());
|
| + dom_agent_->Init(uber_dispatcher_.get());
|
| }
|
|
|
| void TearDown() override {
|
| dom_agent_.reset();
|
| + uber_dispatcher_.reset();
|
| + fake_frontend_channel_.reset();
|
| AshTest::TearDown();
|
| }
|
|
|
| + void ExpectChildNodeInserted(int parent_id, int prev_sibling_id) {
|
| + EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessageStartsWith(
|
| + base::StringPrintf("{\"method\":\"DOM.childNodeInserted\","
|
| + "\"params\":{\"parentNodeId\":%d,"
|
| + "\"previousNodeId\":%d",
|
| + parent_id, prev_sibling_id)));
|
| + }
|
| +
|
| + void ExpectChildNodeRemoved(int parent_id, int node_id) {
|
| + EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessage(
|
| + base::StringPrintf(
|
| + "{\"method\":\"DOM.childNodeRemoved\",\"params\":{"
|
| + "\"parentNodeId\":%d,\"nodeId\":%d}}",
|
| + parent_id, node_id)));
|
| + }
|
| +
|
| + FakeFrontendChannel* frontend_channel() {
|
| + return fake_frontend_channel_.get();
|
| + }
|
| +
|
| devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); }
|
|
|
| private:
|
| + std::unique_ptr<UberDispatcher> uber_dispatcher_;
|
| + std::unique_ptr<FakeFrontendChannel> fake_frontend_channel_;
|
| std::unique_ptr<devtools::AshDevToolsDOMAgent> dom_agent_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(AshDevToolsTest);
|
| @@ -129,25 +189,92 @@ TEST_F(AshDevToolsTest, GetDocumentWithWindowWidgetView) {
|
| widget->GetRootView()->AddChildView(child_view);
|
|
|
| std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| -
|
| dom_agent()->getDocument(&root);
|
| +
|
| DOM::Node* parent_node = FindInRoot(parent_window, root.get());
|
| DOM::Node* widget_node = FindInRoot(widget.get(), root.get());
|
| -
|
| ASSERT_TRUE(parent_node);
|
| ASSERT_TRUE(widget_node);
|
| - Array<DOM::Node>* default_children = nullptr;
|
| - ASSERT_TRUE(parent_node->getChildren(default_children));
|
| - Compare(child_window, parent_node->getChildren(default_children)->get(0));
|
| - Array<DOM::Node>* widget_children =
|
| - widget_node->getChildren(default_children);
|
| + ASSERT_TRUE(parent_node->getChildren(nullptr));
|
| + Compare(child_window, parent_node->getChildren(nullptr)->get(0));
|
| + Array<DOM::Node>* widget_children = widget_node->getChildren(nullptr);
|
| ASSERT_TRUE(widget_children);
|
| Compare(widget->GetRootView(), widget_children->get(0));
|
| - ASSERT_TRUE(widget_children->get(0)->getChildren(default_children));
|
| - Compare(child_view,
|
| - widget_children->get(0)->getChildren(default_children)->get(1));
|
| - // TODO(mhashmi): Remove this call and mock FrontendChannel
|
| - dom_agent()->disable();
|
| + ASSERT_TRUE(widget_children->get(0)->getChildren(nullptr));
|
| + Compare(child_view, widget_children->get(0)->getChildren(nullptr)->get(1));
|
| +}
|
| +
|
| +TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) {
|
| + // Initialize DOMAgent
|
| + std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| + dom_agent()->getDocument(&root);
|
| +
|
| + WmWindow* parent_window = WmShell::Get()->GetPrimaryRootWindow();
|
| + DOM::Node* parent_node = root->getChildren(nullptr)->get(0);
|
| + Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr);
|
| + DOM::Node* sibling_node =
|
| + parent_node_children->get(parent_node_children->length() - 1);
|
| +
|
| + std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window));
|
| + ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId());
|
| +}
|
| +
|
| +TEST_F(AshDevToolsTest, WindowDestroyedChildNodeRemoved) {
|
| + // Initialize DOMAgent
|
| + std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| + dom_agent()->getDocument(&root);
|
| +
|
| + WmWindow* parent_window =
|
| + WmShell::Get()->GetPrimaryRootWindow()->GetChildren()[0];
|
| + WmWindow* child_window = parent_window->GetChildren()[0];
|
| + DOM::Node* root_node = root->getChildren(nullptr)->get(0);
|
| + DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0);
|
| + DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0);
|
| +
|
| + child_window->Destroy();
|
| + ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
|
| +}
|
| +
|
| +TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) {
|
| + // Initialize DOMAgent
|
| + std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| + dom_agent()->getDocument(&root);
|
| +
|
| + WmWindow* root_window = WmShell::Get()->GetPrimaryRootWindow();
|
| + WmWindow* target_window = root_window->GetChildren()[1];
|
| + WmWindow* child_window = root_window->GetChildren()[0]->GetChildren()[0];
|
| +
|
| + DOM::Node* root_node = root->getChildren(nullptr)->get(0);
|
| + DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0);
|
| + DOM::Node* target_node = root_node->getChildren(nullptr)->get(1);
|
| + Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr);
|
| + DOM::Node* sibling_node =
|
| + target_node_children->get(target_node_children->length() - 1);
|
| + DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0);
|
| +
|
| + target_window->AddChild(child_window);
|
| + ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
|
| + ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId());
|
| +}
|
| +
|
| +TEST_F(AshDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) {
|
| + // Initialize DOMAgent
|
| + std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| + dom_agent()->getDocument(&root);
|
| +
|
| + WmWindow* parent_window = WmShell::Get()->GetPrimaryRootWindow();
|
| + WmWindow* child_window = parent_window->GetChildren()[0];
|
| + WmWindow* target_window = parent_window->GetChildren()[1];
|
| +
|
| + DOM::Node* parent_node = root->getChildren(nullptr)->get(0);
|
| + Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr);
|
| + DOM::Node* child_node = parent_node_children->get(0);
|
| + DOM::Node* sibling_node = parent_node_children->get(1);
|
| + int parent_id = parent_node->getNodeId();
|
| +
|
| + parent_window->StackChildAbove(child_window, target_window);
|
| + ExpectChildNodeRemoved(parent_id, child_node->getNodeId());
|
| + ExpectChildNodeInserted(parent_id, sibling_node->getNodeId());
|
| }
|
|
|
| } // namespace ash
|
|
|