| 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 "content/public/test/browser_test.h" | 7 #include "content/public/test/browser_test.h" |
| 8 #include "headless/public/domains/page.h" | 8 #include "headless/public/domains/page.h" |
| 9 #include "headless/public/domains/runtime.h" | 9 #include "headless/public/domains/runtime.h" |
| 10 #include "headless/public/headless_browser.h" | 10 #include "headless/public/headless_browser.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 int value; | 103 int value; |
| 104 EXPECT_TRUE(result->GetResult()->HasValue()); | 104 EXPECT_TRUE(result->GetResult()->HasValue()); |
| 105 EXPECT_TRUE(result->GetResult()->GetValue()->GetAsInteger(&value)); | 105 EXPECT_TRUE(result->GetResult()->GetValue()->GetAsInteger(&value)); |
| 106 EXPECT_EQ(168, value); | 106 EXPECT_EQ(168, value); |
| 107 FinishAsynchronousTest(); | 107 FinishAsynchronousTest(); |
| 108 } | 108 } |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 DEVTOOLS_CLIENT_TEST_F(HeadlessDevToolsClientEvalTest); | 111 DEVTOOLS_CLIENT_TEST_F(HeadlessDevToolsClientEvalTest); |
| 112 | 112 |
| 113 class HeadlessDevToolsClientCallbackTest : public HeadlessDevToolsClientTest { |
| 114 public: |
| 115 HeadlessDevToolsClientCallbackTest() : first_result_received_(false) {} |
| 116 |
| 117 void RunDevToolsClientTest() override { |
| 118 // Null callback without parameters. |
| 119 devtools_client_->GetRuntime()->Run(); |
| 120 // Null callback with parameters. |
| 121 devtools_client_->GetRuntime()->Evaluate("true"); |
| 122 // Non-null callback without parameters. |
| 123 devtools_client_->GetRuntime()->Disable( |
| 124 base::Bind(&HeadlessDevToolsClientCallbackTest::OnFirstResult, |
| 125 base::Unretained(this))); |
| 126 // Non-null callback with parameters. |
| 127 devtools_client_->GetRuntime()->Evaluate( |
| 128 "true", base::Bind(&HeadlessDevToolsClientCallbackTest::OnSecondResult, |
| 129 base::Unretained(this))); |
| 130 } |
| 131 |
| 132 void OnFirstResult() { |
| 133 EXPECT_FALSE(first_result_received_); |
| 134 first_result_received_ = true; |
| 135 } |
| 136 |
| 137 void OnSecondResult(std::unique_ptr<runtime::EvaluateResult> result) { |
| 138 EXPECT_TRUE(first_result_received_); |
| 139 FinishAsynchronousTest(); |
| 140 } |
| 141 |
| 142 private: |
| 143 bool first_result_received_; |
| 144 }; |
| 145 |
| 146 DEVTOOLS_CLIENT_TEST_F(HeadlessDevToolsClientCallbackTest); |
| 147 |
| 113 } // namespace headless | 148 } // namespace headless |
| OLD | NEW |