OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "content/public/browser/render_widget_host_view.h" | 8 #include "content/public/browser/render_widget_host_view.h" |
9 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 | 680 |
681 // Make sure we don't fail because the renderer crashed! | 681 // Make sure we don't fail because the renderer crashed! |
682 void RenderProcessExited(base::TerminationStatus status, | 682 void RenderProcessExited(base::TerminationStatus status, |
683 int exit_code) override { | 683 int exit_code) override { |
684 EXPECT_EQ(base::TERMINATION_STATUS_ABNORMAL_TERMINATION, status); | 684 EXPECT_EQ(base::TERMINATION_STATUS_ABNORMAL_TERMINATION, status); |
685 } | 685 } |
686 }; | 686 }; |
687 | 687 |
688 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessCrashObserverTest); | 688 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessCrashObserverTest); |
689 | 689 |
| 690 class HeadlessDevToolsClientAttachTest |
| 691 : public HeadlessAsyncDevTooledBrowserTest { |
| 692 public: |
| 693 void RunDevTooledTest() override { |
| 694 other_devtools_client_ = HeadlessDevToolsClient::Create(); |
| 695 HeadlessDevToolsTarget* devtools_target = |
| 696 web_contents_->GetDevToolsTarget(); |
| 697 |
| 698 // Try attaching: there's already a client attached. |
| 699 EXPECT_FALSE(devtools_target->AttachClient(other_devtools_client_.get())); |
| 700 EXPECT_TRUE(devtools_target->IsAttached()); |
| 701 // Detach the existing client, attach the other client. |
| 702 devtools_target->DetachClient(devtools_client_.get()); |
| 703 EXPECT_FALSE(devtools_target->IsAttached()); |
| 704 EXPECT_TRUE(devtools_target->AttachClient(other_devtools_client_.get())); |
| 705 EXPECT_TRUE(devtools_target->IsAttached()); |
| 706 |
| 707 // Now, let's make sure this devtools client works. |
| 708 other_devtools_client_->GetRuntime()->Evaluate( |
| 709 "24 * 7", base::Bind(&HeadlessDevToolsClientAttachTest::OnFirstResult, |
| 710 base::Unretained(this))); |
| 711 } |
| 712 |
| 713 void OnFirstResult(std::unique_ptr<runtime::EvaluateResult> result) { |
| 714 int value; |
| 715 EXPECT_TRUE(result->GetResult()->HasValue()); |
| 716 EXPECT_TRUE(result->GetResult()->GetValue()->GetAsInteger(&value)); |
| 717 EXPECT_EQ(24 * 7, value); |
| 718 |
| 719 HeadlessDevToolsTarget* devtools_target = |
| 720 web_contents_->GetDevToolsTarget(); |
| 721 |
| 722 // Try attach, then force-attach the original client. |
| 723 EXPECT_FALSE(devtools_target->AttachClient(devtools_client_.get())); |
| 724 devtools_target->ForceAttachClient(devtools_client_.get()); |
| 725 EXPECT_TRUE(devtools_target->IsAttached()); |
| 726 |
| 727 devtools_client_->GetRuntime()->Evaluate( |
| 728 "27 * 4", base::Bind(&HeadlessDevToolsClientAttachTest::OnSecondResult, |
| 729 base::Unretained(this))); |
| 730 } |
| 731 |
| 732 void OnSecondResult(std::unique_ptr<runtime::EvaluateResult> result) { |
| 733 int value; |
| 734 EXPECT_TRUE(result->GetResult()->HasValue()); |
| 735 EXPECT_TRUE(result->GetResult()->GetValue()->GetAsInteger(&value)); |
| 736 EXPECT_EQ(27 * 4, value); |
| 737 |
| 738 // If everything worked, this call will not crash, since it |
| 739 // detaches devtools_client_. |
| 740 FinishAsynchronousTest(); |
| 741 } |
| 742 |
| 743 protected: |
| 744 std::unique_ptr<HeadlessDevToolsClient> other_devtools_client_; |
| 745 }; |
| 746 |
| 747 HEADLESS_ASYNC_DEVTOOLED_TEST_F(HeadlessDevToolsClientAttachTest); |
| 748 |
690 } // namespace headless | 749 } // namespace headless |
OLD | NEW |