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

Unified Diff: content/browser/devtools/protocol/devtools_protocol_browsertest.cc

Issue 2185033002: Emulation.setVirtualTimePolicy to have an optional virtual time budge (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename parameter 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/inspector/browser_protocol.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/devtools/protocol/devtools_protocol_browsertest.cc
diff --git a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
index 99f9ee59cb173a0cf1c4e581c0448b4a537e72b9..0c577b651df47ac9e6df319f0b71e1cd4f610cc1 100644
--- a/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
+++ b/content/browser/devtools/protocol/devtools_protocol_browsertest.cc
@@ -11,6 +11,7 @@
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
+#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "content/public/browser/devtools_agent_host.h"
@@ -103,7 +104,8 @@ class TestJavaScriptDialogManager : public JavaScriptDialogManager,
}
class DevToolsProtocolTest : public ContentBrowserTest,
- public DevToolsAgentHostClient {
+ public DevToolsAgentHostClient,
+ public WebContentsDelegate {
public:
DevToolsProtocolTest()
: last_sent_id_(0),
@@ -112,6 +114,16 @@ class DevToolsProtocolTest : public ContentBrowserTest,
}
protected:
+ // WebContentsDelegate method:
+ bool AddMessageToConsole(WebContents* source,
+ int32_t level,
+ const base::string16& message,
+ int32_t line_no,
+ const base::string16& source_id) override {
+ console_messages_.push_back(base::UTF16ToUTF8(message));
+ return true;
+ }
+
void SendCommand(const std::string& method,
std::unique_ptr<base::DictionaryValue> params) {
SendCommand(method, std::move(params), true);
@@ -167,6 +179,7 @@ class DevToolsProtocolTest : public ContentBrowserTest,
void Attach() {
agent_host_ = DevToolsAgentHost::GetOrCreateFor(shell()->web_contents());
agent_host_->AttachClient(this);
+ shell()->web_contents()->SetDelegate(this);
}
void TearDownOnMainThread() override {
@@ -257,6 +270,7 @@ class DevToolsProtocolTest : public ContentBrowserTest,
int last_sent_id_;
std::vector<int> result_ids_;
std::vector<std::string> notifications_;
+ std::vector<std::string> console_messages_;
std::unique_ptr<base::DictionaryValue> requested_notification_params_;
private:
@@ -832,4 +846,45 @@ IN_PROC_BROWSER_TEST_F(IsolatedDevToolsProtocolTest,
"http://b.com/devtools/control_navigations/meta_tag.html"));
}
+IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, VirtualTimeTest) {
+ NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
+ Attach();
+
+ std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
+ params->SetString("policy", "pause");
+ SendCommand("Emulation.setVirtualTimePolicy", std::move(params), true);
+
+ params.reset(new base::DictionaryValue());
+ params->SetString("expression",
+ "setTimeout(function(){console.log('before')}, 1000);"
+ "setTimeout(function(){console.log('after')}, 1001);");
+ SendCommand("Runtime.evaluate", std::move(params), true);
+
+ // Let virtual time advance for one second.
+ params.reset(new base::DictionaryValue());
+ params->SetString("policy", "advance");
+ params->SetInteger("budget", 1000);
+ SendCommand("Emulation.setVirtualTimePolicy", std::move(params), true);
+
+ WaitForNotification("Emulation.virtualTimeBudgetExpired");
+
+ params.reset(new base::DictionaryValue());
+ params->SetString("expression", "console.log('done')");
+ SendCommand("Runtime.evaluate", std::move(params), true);
+
+ // The second timer shold not fire.
+ EXPECT_THAT(console_messages_, ElementsAre("before", "done"));
+
+ // Let virtual time advance for another second, which should make the second
+ // timer fire.
+ params.reset(new base::DictionaryValue());
+ params->SetString("policy", "advance");
+ params->SetInteger("budget", 1000);
+ SendCommand("Emulation.setVirtualTimePolicy", std::move(params), true);
+
+ WaitForNotification("Emulation.virtualTimeBudgetExpired");
+
+ EXPECT_THAT(console_messages_, ElementsAre("before", "done", "after"));
+}
+
} // namespace content
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/inspector/browser_protocol.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698