Skip to content

Commit

Permalink
Content Shell: LayoutTestJavaScriptDialogManager
Browse files Browse the repository at this point in the history
This moves the DRT-specific parts of ShellJavaScriptDialogManager to a
new, layout-test-only class.

BUG=420994
R=jochen@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#298709}
  • Loading branch information
mikewest authored and Commit bot committed Oct 8, 2014
1 parent 4856559 commit 6efe7f2
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 12 deletions.
2 changes: 2 additions & 0 deletions content/content_shell.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
'shell/app/webkit_test_platform_support_win.cc',
'shell/browser/ipc_echo_message_filter.cc',
'shell/browser/ipc_echo_message_filter.h',
'shell/browser/layout_test/layout_test_javascript_dialog_manager.cc',
'shell/browser/layout_test/layout_test_javascript_dialog_manager.h',
'shell/browser/notify_done_forwarder.cc',
'shell/browser/notify_done_forwarder.h',
'shell/browser/shell_android.cc',
Expand Down
2 changes: 2 additions & 0 deletions content/shell/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ static_library("content_shell_lib") {
"app/webkit_test_platform_support_win.cc",
"browser/ipc_echo_message_filter.cc",
"browser/ipc_echo_message_filter.h",
"browser/layout_test/layout_test_javascript_dialog_manager.cc",
"browser/layout_test/layout_test_javascript_dialog_manager.h",
"browser/notify_done_forwarder.cc",
"browser/notify_done_forwarder.h",
"browser/shell_android.cc",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/shell/browser/layout_test/layout_test_javascript_dialog_manager.h"

#include "base/command_line.h"
#include "base/logging.h"
#include "base/strings/utf_string_conversions.h"
#include "content/public/browser/web_contents.h"
#include "content/shell/browser/shell_javascript_dialog.h"
#include "content/shell/browser/webkit_test_controller.h"
#include "content/shell/common/shell_switches.h"
#include "net/base/net_util.h"

namespace content {

LayoutTestJavaScriptDialogManager::LayoutTestJavaScriptDialogManager() {
}

LayoutTestJavaScriptDialogManager::~LayoutTestJavaScriptDialogManager() {
}

void LayoutTestJavaScriptDialogManager::RunJavaScriptDialog(
WebContents* web_contents,
const GURL& origin_url,
const std::string& accept_lang,
JavaScriptMessageType javascript_message_type,
const base::string16& message_text,
const base::string16& default_prompt_text,
const DialogClosedCallback& callback,
bool* did_suppress_message) {
callback.Run(true, base::string16());
return;
}

void LayoutTestJavaScriptDialogManager::RunBeforeUnloadDialog(
WebContents* web_contents,
const base::string16& message_text,
bool is_reload,
const DialogClosedCallback& callback) {
callback.Run(true, base::string16());
return;
}

} // namespace content
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_JAVASCRIPT_DIALOG_MANAGER_H_
#define CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_JAVASCRIPT_DIALOG_MANAGER_H_

#include "base/callback_forward.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "content/shell/browser/shell_javascript_dialog_manager.h"

namespace content {

class LayoutTestJavaScriptDialogManager : public ShellJavaScriptDialogManager {
public:
LayoutTestJavaScriptDialogManager();
virtual ~LayoutTestJavaScriptDialogManager();

// JavaScriptDialogManager:
virtual void RunJavaScriptDialog(
WebContents* web_contents,
const GURL& origin_url,
const std::string& accept_lang,
JavaScriptMessageType javascript_message_type,
const base::string16& message_text,
const base::string16& default_prompt_text,
const DialogClosedCallback& callback,
bool* did_suppress_message) override;

virtual void RunBeforeUnloadDialog(
WebContents* web_contents,
const base::string16& message_text,
bool is_reload,
const DialogClosedCallback& callback) override;

private:
DISALLOW_COPY_AND_ASSIGN(LayoutTestJavaScriptDialogManager);
};

} // namespace content

#endif // CONTENT_SHELL_BROWSER_LAYOUT_TEST_LAYOUT_TEST_JAVASCRIPT_DIALOG_MANAGER_H_
9 changes: 7 additions & 2 deletions content/shell/browser/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/renderer_preferences.h"
#include "content/shell/browser/layout_test/layout_test_javascript_dialog_manager.h"
#include "content/shell/browser/notify_done_forwarder.h"
#include "content/shell/browser/shell_browser_main_parts.h"
#include "content/shell/browser/shell_content_browser_client.h"
Expand Down Expand Up @@ -329,8 +330,12 @@ void Shell::DidNavigateMainFramePostCommit(WebContents* web_contents) {
}

JavaScriptDialogManager* Shell::GetJavaScriptDialogManager() {
if (!dialog_manager_)
dialog_manager_.reset(new ShellJavaScriptDialogManager());
if (!dialog_manager_) {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
dialog_manager_.reset(command_line.HasSwitch(switches::kDumpRenderTree)
? new LayoutTestJavaScriptDialogManager
: new ShellJavaScriptDialogManager);
}
return dialog_manager_.get();
}

Expand Down
10 changes: 0 additions & 10 deletions content/shell/browser/shell_javascript_dialog_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ void ShellJavaScriptDialogManager::RunJavaScriptDialog(
const base::string16& default_prompt_text,
const DialogClosedCallback& callback,
bool* did_suppress_message) {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
callback.Run(true, base::string16());
return;
}

if (!dialog_request_callback_.is_null()) {
dialog_request_callback_.Run();
callback.Run(true, base::string16());
Expand Down Expand Up @@ -74,11 +69,6 @@ void ShellJavaScriptDialogManager::RunBeforeUnloadDialog(
const base::string16& message_text,
bool is_reload,
const DialogClosedCallback& callback) {
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) {
callback.Run(true, base::string16());
return;
}

if (!dialog_request_callback_.is_null()) {
dialog_request_callback_.Run();
callback.Run(true, base::string16());
Expand Down

0 comments on commit 6efe7f2

Please sign in to comment.