Skip to content

Commit

Permalink
Merge to 2743 "[DevTools] Flush when sending javascript dialog notifi…
Browse files Browse the repository at this point in the history
…cations."

> [DevTools] Flush when sending javascript dialog notifications.
>
> Notifications are sync IPCs, so we have to flush instead of
> relying on task being finished.
>
> BUG=chromedriver:1381
>
> Review-Url: https://codereview.chromium.org/2002223002
> Cr-Commit-Position: refs/heads/master@{#395465}
(cherry picked from commit d876a64)
[email protected]

Review URL: https://codereview.chromium.org/2028313002 .

Cr-Commit-Position: refs/branch-heads/2743@{crosswalk-project#172}
Cr-Branched-From: 2b3ae3b-refs/heads/master@{#394939}
  • Loading branch information
dgozman committed Jun 1, 2016
1 parent e8af869 commit c36b378
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
72 changes: 72 additions & 0 deletions content/browser/devtools/protocol/devtools_protocol_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "base/values.h"
#include "build/build_config.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
Expand All @@ -34,6 +35,64 @@ const char kIdParam[] = "id";
const char kMethodParam[] = "method";
const char kParamsParam[] = "params";

class TestJavaScriptDialogManager : public JavaScriptDialogManager,
public WebContentsDelegate {
public:
TestJavaScriptDialogManager() : handle_(false) {}
~TestJavaScriptDialogManager() override {}

void Handle()
{
if (!callback_.is_null()) {
callback_.Run(true, base::string16());
callback_.Reset();
} else {
handle_ = true;
}
}

// WebContentsDelegate
JavaScriptDialogManager* GetJavaScriptDialogManager(
WebContents* source) override {
return this;
}

// JavaScriptDialogManager
void RunJavaScriptDialog(WebContents* web_contents,
const GURL& origin_url,
JavaScriptMessageType javascript_message_type,
const base::string16& message_text,
const base::string16& default_prompt_text,
const DialogClosedCallback& callback,
bool* did_suppress_message) override {
if (handle_) {
handle_ = false;
callback.Run(true, base::string16());
} else {
callback_ = callback;
}
};

void RunBeforeUnloadDialog(WebContents* web_contents,
bool is_reload,
const DialogClosedCallback& callback) override {}

bool HandleJavaScriptDialog(WebContents* web_contents,
bool accept,
const base::string16* prompt_override) override {
return true;
}

void CancelActiveAndPendingDialogs(WebContents* web_contents) override {}

void ResetDialogState(WebContents* web_contents) override {}

private:
DialogClosedCallback callback_;
bool handle_;
DISALLOW_COPY_AND_ASSIGN(TestJavaScriptDialogManager);
};

}

class DevToolsProtocolTest : public ContentBrowserTest,
Expand Down Expand Up @@ -515,4 +574,17 @@ IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest,
EXPECT_FALSE(wasThrown);
}

IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, JavaScriptDialogNotifications) {
NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1);
Attach();
TestJavaScriptDialogManager dialog_manager;
shell()->web_contents()->SetDelegate(&dialog_manager);
SendCommand("Page.enable", nullptr, true);
std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue());
params->SetString("expression", "alert('alert')");
SendCommand("Runtime.evaluate", std::move(params), false);
WaitForNotification("Page.javascriptDialogOpening");
dialog_manager.Handle();
}

} // namespace content
Original file line number Diff line number Diff line change
Expand Up @@ -651,11 +651,13 @@ void InspectorPageAgent::frameClearedScheduledNavigation(LocalFrame* frame)
void InspectorPageAgent::willRunJavaScriptDialog(const String& message, ChromeClient::DialogType dialogType)
{
frontend()->javascriptDialogOpening(message, dialogTypeToProtocol(dialogType));
frontend()->flush();
}

void InspectorPageAgent::didRunJavaScriptDialog(bool result)
{
frontend()->javascriptDialogClosed(result);
frontend()->flush();
}

void InspectorPageAgent::didUpdateLayout()
Expand Down

0 comments on commit c36b378

Please sign in to comment.