This source file includes following definitions.
- RunTestFunction
- inspected_rvh_
- RunTest
- LoadTestPage
- OpenDevToolsWindow
- GetInspectedTab
- ToggleDevToolsWindow
- ToggleDevToolsWindowDontWait
- CloseDevToolsWindow
- m_fired
- Wait
- BeforeUnloadFired
- SetUpCommandLine
- CloseInspectedTab
- CloseDockedDevTools
- CloseUndockedDevTools
- CloseInspectedBrowser
- InjectBeforeUnloadListener
- RunBeforeUnloadSanityTest
- OpenDevToolWindowOnWebContents
- OpenDevToolsPopupWindow
- CloseDevToolsPopupWindow
- AcceptModalDialog
- CancelModalDialog
- GetDialog
- SetUpCommandLine
- TimeoutCallback
- LoadExtension
- LoadExtensionFromPath
- WaitForExtensionViewsToLoad
- Observe
- SetUpCommandLine
- worker_route_id
- WorkerCreated
- WorkerDestroyed
- RunTest
- TerminateWorkerOnIOThread
- TerminateWorker
- WaitForFirstSharedWorkerOnIOThread
- WaitForFirstSharedWorker
- OpenDevToolsWindowForSharedWorker
- CloseDevToolsWindow
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- SetUpCommandLine
- IN_PROC_BROWSER_TEST_F
#include "base/bind.h"
#include "base/cancelable_callback.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/test_timeouts.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/devtools/browser_list_tabcontents_provider.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/unpacked_installer.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
#include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_iterator.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/test_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/devtools_client_host.h"
#include "content/public/browser/devtools_http_handler.h"
#include "content/public/browser/devtools_manager.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/worker_service.h"
#include "content/public/browser/worker_service_observer.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test_utils.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/switches.h"
#include "net/socket/tcp_listen_socket.h"
#include "net/test/spawned_test_server/spawned_test_server.h"
using content::BrowserThread;
using content::DevToolsManager;
using content::DevToolsAgentHost;
using content::NavigationController;
using content::RenderViewHost;
using content::WebContents;
using content::WorkerService;
using content::WorkerServiceObserver;
namespace {
const char kDebuggerTestPage[] = "files/devtools/debugger_test_page.html";
const char kPauseWhenLoadingDevTools[] =
"files/devtools/pause_when_loading_devtools.html";
const char kPauseWhenScriptIsRunning[] =
"files/devtools/pause_when_script_is_running.html";
const char kPageWithContentScript[] =
"files/devtools/page_with_content_script.html";
const char kNavigateBackTestPage[] =
"files/devtools/navigate_back.html";
const char kChunkedTestPage[] = "chunked";
const char kSlowTestPage[] =
"chunked?waitBeforeHeaders=100&waitBetweenChunks=100&chunksNumber=2";
const char kSharedWorkerTestPage[] =
"files/workers/workers_ui_shared_worker.html";
const char kReloadSharedWorkerTestPage[] =
"files/workers/debug_shared_worker_initialization.html";
void RunTestFunction(DevToolsWindow* window, const char* test_name) {
std::string result;
ASSERT_TRUE(
content::ExecuteScriptAndExtractString(
window->GetRenderViewHost(),
"window.domAutomationController.send("
" '' + (window.uiTests && (typeof uiTests.runTest)));",
&result));
ASSERT_EQ("function", result) << "DevTools front-end is broken.";
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
window->GetRenderViewHost(),
base::StringPrintf("uiTests.runTest('%s')", test_name),
&result));
EXPECT_EQ("[OK]", result);
}
}
class DevToolsSanityTest : public InProcessBrowserTest {
public:
DevToolsSanityTest()
: window_(NULL),
inspected_rvh_(NULL) {}
protected:
void RunTest(const std::string& test_name, const std::string& test_page) {
OpenDevToolsWindow(test_page, false);
RunTestFunction(window_, test_name.c_str());
CloseDevToolsWindow();
}
void LoadTestPage(const std::string& test_page) {
GURL url = test_server()->GetURL(test_page);
ui_test_utils::NavigateToURL(browser(), url);
}
void OpenDevToolsWindow(const std::string& test_page, bool is_docked) {
ASSERT_TRUE(test_server()->Start());
LoadTestPage(test_page);
inspected_rvh_ = GetInspectedTab()->GetRenderViewHost();
window_ =
DevToolsWindow::OpenDevToolsWindowForTest(inspected_rvh_, is_docked);
ui_test_utils::WaitUntilDevToolsWindowLoaded(window_);
}
WebContents* GetInspectedTab() {
return browser()->tab_strip_model()->GetWebContentsAt(0);
}
void ToggleDevToolsWindow() {
content::WindowedNotificationObserver close_observer(
content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<content::WebContents>(window_->web_contents()));
DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false,
DevToolsToggleAction::Toggle());
close_observer.Wait();
}
void ToggleDevToolsWindowDontWait() {
DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false,
DevToolsToggleAction::Toggle());
}
void CloseDevToolsWindow() {
DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
content::WindowedNotificationObserver close_observer(
content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<content::WebContents>(window_->web_contents()));
devtools_manager->CloseAllClientHosts();
close_observer.Wait();
}
DevToolsWindow* window_;
RenderViewHost* inspected_rvh_;
};
class DevToolsWindowBeforeUnloadObserver
: public content::WebContentsObserver {
public:
explicit DevToolsWindowBeforeUnloadObserver(DevToolsWindow*);
void Wait();
private:
virtual void BeforeUnloadFired(const base::TimeTicks& proceed_time) OVERRIDE;
bool m_fired;
scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(DevToolsWindowBeforeUnloadObserver);
};
DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver(
DevToolsWindow* devtools_window)
: WebContentsObserver(devtools_window->web_contents()),
m_fired(false) {
}
void DevToolsWindowBeforeUnloadObserver::Wait() {
if (m_fired)
return;
message_loop_runner_ = new content::MessageLoopRunner;
message_loop_runner_->Run();
}
void DevToolsWindowBeforeUnloadObserver::BeforeUnloadFired(
const base::TimeTicks& proceed_time) {
m_fired = true;
if (message_loop_runner_.get())
message_loop_runner_->Quit();
}
class DevToolsBeforeUnloadTest: public DevToolsSanityTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(
switches::kDisableHangMonitor);
}
void CloseInspectedTab() {
browser()->tab_strip_model()->CloseWebContentsAt(0,
TabStripModel::CLOSE_NONE);
}
void CloseDockedDevTools() {
ToggleDevToolsWindowDontWait();
}
void CloseUndockedDevTools() {
chrome::CloseWindow(window_->browser());
}
void CloseInspectedBrowser() {
chrome::CloseWindow(browser());
}
protected:
void InjectBeforeUnloadListener(content::WebContents* web_contents) {
ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(),
"window.addEventListener('beforeunload',"
"function(event) { event.returnValue = 'Foo'; });"));
}
void RunBeforeUnloadSanityTest(bool is_docked,
base::Callback<void(void)> close_method,
bool wait_for_browser_close = true) {
OpenDevToolsWindow(kDebuggerTestPage, is_docked);
content::WindowedNotificationObserver devtools_close_observer(
content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<content::WebContents>(window_->web_contents()));
InjectBeforeUnloadListener(window_->web_contents());
{
DevToolsWindowBeforeUnloadObserver before_unload_observer(window_);
close_method.Run();
CancelModalDialog();
before_unload_observer.Wait();
}
{
content::WindowedNotificationObserver close_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
content::Source<Browser>(browser()));
close_method.Run();
AcceptModalDialog();
if (wait_for_browser_close)
close_observer.Wait();
}
devtools_close_observer.Wait();
}
DevToolsWindow* OpenDevToolWindowOnWebContents(
content::WebContents* contents, bool is_docked) {
DevToolsWindow* window = DevToolsWindow::OpenDevToolsWindowForTest(
contents->GetRenderViewHost(), is_docked);
ui_test_utils::WaitUntilDevToolsWindowLoaded(window);
return window;
}
void OpenDevToolsPopupWindow(DevToolsWindow* devtools_window) {
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
ASSERT_TRUE(content::ExecuteScript(
devtools_window->web_contents()->GetRenderViewHost(),
"window.open(\"\", \"\", \"location=0\");"));
observer.Wait();
}
void CloseDevToolsPopupWindow(DevToolsWindow* devtools_window) {
Browser* popup_browser = NULL;
for (chrome::BrowserIterator it; !it.done(); it.Next()) {
if (it->is_devtools()) {
content::WebContents* contents =
it->tab_strip_model()->GetWebContentsAt(0);
if (devtools_window->web_contents() != contents) {
popup_browser = *it;
break;
}
}
}
ASSERT_FALSE(popup_browser == NULL);
content::WindowedNotificationObserver close_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
content::Source<Browser>(popup_browser));
chrome::CloseWindow(popup_browser);
close_observer.Wait();
}
void AcceptModalDialog() {
NativeAppModalDialog* native_dialog = GetDialog();
native_dialog->AcceptAppModalDialog();
}
void CancelModalDialog() {
NativeAppModalDialog* native_dialog = GetDialog();
native_dialog->CancelAppModalDialog();
}
NativeAppModalDialog* GetDialog() {
AppModalDialog* dialog = ui_test_utils::WaitForAppModalDialog();
EXPECT_TRUE(dialog->IsJavaScriptModalDialog());
JavaScriptAppModalDialog* js_dialog =
static_cast<JavaScriptAppModalDialog*>(dialog);
NativeAppModalDialog* native_dialog = js_dialog->native_dialog();
EXPECT_TRUE(native_dialog);
return native_dialog;
}
};
class DevToolsUnresponsiveBeforeUnloadTest: public DevToolsBeforeUnloadTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {}
};
void TimeoutCallback(const std::string& timeout_message) {
ADD_FAILURE() << timeout_message;
base::MessageLoop::current()->Quit();
}
class DevToolsExtensionTest : public DevToolsSanityTest,
public content::NotificationObserver {
public:
DevToolsExtensionTest() : DevToolsSanityTest() {
PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_);
test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools");
test_extensions_dir_ = test_extensions_dir_.AppendASCII("extensions");
}
protected:
void LoadExtension(const char* extension_name) {
base::FilePath path = test_extensions_dir_.AppendASCII(extension_name);
ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension.";
}
private:
bool LoadExtensionFromPath(const base::FilePath& path) {
ExtensionService* service = extensions::ExtensionSystem::Get(
browser()->profile())->extension_service();
size_t num_before = service->extensions()->size();
{
content::NotificationRegistrar registrar;
registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
content::NotificationService::AllSources());
base::CancelableClosure timeout(
base::Bind(&TimeoutCallback, "Extension load timed out."));
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE, timeout.callback(), TestTimeouts::action_timeout());
extensions::UnpackedInstaller::Create(service)->Load(path);
content::RunMessageLoop();
timeout.Cancel();
}
size_t num_after = service->extensions()->size();
if (num_after != (num_before + 1))
return false;
return WaitForExtensionViewsToLoad();
}
bool WaitForExtensionViewsToLoad() {
content::NotificationRegistrar registrar;
registrar.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
content::NotificationService::AllSources());
base::CancelableClosure timeout(
base::Bind(&TimeoutCallback, "Extension host load timed out."));
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE, timeout.callback(), TestTimeouts::action_timeout());
extensions::ProcessManager* manager =
extensions::ExtensionSystem::Get(browser()->profile())->
process_manager();
extensions::ProcessManager::ViewSet all_views = manager->GetAllViews();
for (extensions::ProcessManager::ViewSet::const_iterator iter =
all_views.begin();
iter != all_views.end();) {
if (!(*iter)->IsLoading())
++iter;
else
content::RunMessageLoop();
}
timeout.Cancel();
return true;
}
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE {
switch (type) {
case chrome::NOTIFICATION_EXTENSION_LOADED:
case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING:
base::MessageLoopForUI::current()->Quit();
break;
default:
NOTREACHED();
break;
}
}
base::FilePath test_extensions_dir_;
};
class DevToolsExperimentalExtensionTest : public DevToolsExtensionTest {
public:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
command_line->AppendSwitch(
extensions::switches::kEnableExperimentalExtensionApis);
}
};
class WorkerDevToolsSanityTest : public InProcessBrowserTest {
public:
WorkerDevToolsSanityTest() : window_(NULL) {}
protected:
class WorkerData : public base::RefCountedThreadSafe<WorkerData> {
public:
WorkerData() : worker_process_id(0), worker_route_id(0) {}
int worker_process_id;
int worker_route_id;
private:
friend class base::RefCountedThreadSafe<WorkerData>;
~WorkerData() {}
};
class WorkerCreationObserver : public WorkerServiceObserver {
public:
explicit WorkerCreationObserver(WorkerData* worker_data)
: worker_data_(worker_data) {
}
private:
virtual ~WorkerCreationObserver() {}
virtual void WorkerCreated (
const GURL& url,
const base::string16& name,
int process_id,
int route_id) OVERRIDE {
worker_data_->worker_process_id = process_id;
worker_data_->worker_route_id = route_id;
WorkerService::GetInstance()->RemoveObserver(this);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::MessageLoop::QuitClosure());
delete this;
}
scoped_refptr<WorkerData> worker_data_;
};
class WorkerTerminationObserver : public WorkerServiceObserver {
public:
explicit WorkerTerminationObserver(WorkerData* worker_data)
: worker_data_(worker_data) {
}
private:
virtual ~WorkerTerminationObserver() {}
virtual void WorkerDestroyed(int process_id, int route_id) OVERRIDE {
ASSERT_EQ(worker_data_->worker_process_id, process_id);
ASSERT_EQ(worker_data_->worker_route_id, route_id);
WorkerService::GetInstance()->RemoveObserver(this);
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::MessageLoop::QuitClosure());
delete this;
}
scoped_refptr<WorkerData> worker_data_;
};
void RunTest(const char* test_name, const char* test_page) {
ASSERT_TRUE(test_server()->Start());
GURL url = test_server()->GetURL(test_page);
ui_test_utils::NavigateToURL(browser(), url);
scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker();
OpenDevToolsWindowForSharedWorker(worker_data.get());
RunTestFunction(window_, test_name);
CloseDevToolsWindow();
}
static void TerminateWorkerOnIOThread(scoped_refptr<WorkerData> worker_data) {
if (!WorkerService::GetInstance()->TerminateWorker(
worker_data->worker_process_id, worker_data->worker_route_id))
FAIL() << "Failed to terminate worker.\n";
WorkerService::GetInstance()->AddObserver(
new WorkerTerminationObserver(worker_data.get()));
}
static void TerminateWorker(scoped_refptr<WorkerData> worker_data) {
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&TerminateWorkerOnIOThread, worker_data));
content::RunMessageLoop();
}
static void WaitForFirstSharedWorkerOnIOThread(
scoped_refptr<WorkerData> worker_data) {
std::vector<WorkerService::WorkerInfo> worker_info =
WorkerService::GetInstance()->GetWorkers();
if (!worker_info.empty()) {
worker_data->worker_process_id = worker_info[0].process_id;
worker_data->worker_route_id = worker_info[0].route_id;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::MessageLoop::QuitClosure());
return;
}
WorkerService::GetInstance()->AddObserver(
new WorkerCreationObserver(worker_data.get()));
}
static scoped_refptr<WorkerData> WaitForFirstSharedWorker() {
scoped_refptr<WorkerData> worker_data(new WorkerData());
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&WaitForFirstSharedWorkerOnIOThread, worker_data));
content::RunMessageLoop();
return worker_data;
}
void OpenDevToolsWindowForSharedWorker(WorkerData* worker_data) {
Profile* profile = browser()->profile();
scoped_refptr<DevToolsAgentHost> agent_host(
DevToolsAgentHost::GetForWorker(
worker_data->worker_process_id,
worker_data->worker_route_id));
window_ = DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host);
RenderViewHost* client_rvh = window_->GetRenderViewHost();
WebContents* client_contents = WebContents::FromRenderViewHost(client_rvh);
content::WaitForLoadStop(client_contents);
}
void CloseDevToolsWindow() {
Browser* browser = window_->browser();
content::WindowedNotificationObserver close_observer(
content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<content::WebContents>(window_->web_contents()));
browser->tab_strip_model()->CloseAllTabs();
close_observer.Wait();
}
DevToolsWindow* window_;
};
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) {
RunBeforeUnloadSanityTest(true, base::Bind(
&DevToolsBeforeUnloadTest::CloseDockedDevTools, this), false);
}
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
TestDockedDevToolsInspectedTabClose) {
RunBeforeUnloadSanityTest(true, base::Bind(
&DevToolsBeforeUnloadTest::CloseInspectedTab, this));
}
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
TestDockedDevToolsInspectedBrowserClose) {
RunBeforeUnloadSanityTest(true, base::Bind(
&DevToolsBeforeUnloadTest::CloseInspectedBrowser, this));
}
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) {
RunBeforeUnloadSanityTest(false, base::Bind(
&DevToolsBeforeUnloadTest::CloseUndockedDevTools, this), false);
}
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
TestUndockedDevToolsInspectedTabClose) {
RunBeforeUnloadSanityTest(false, base::Bind(
&DevToolsBeforeUnloadTest::CloseInspectedTab, this));
}
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
TestUndockedDevToolsInspectedBrowserClose) {
RunBeforeUnloadSanityTest(false, base::Bind(
&DevToolsBeforeUnloadTest::CloseInspectedBrowser, this));
}
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
TestUndockedDevToolsApplicationClose) {
RunBeforeUnloadSanityTest(false, base::Bind(
&chrome::CloseAllBrowsers));
}
IN_PROC_BROWSER_TEST_F(DevToolsUnresponsiveBeforeUnloadTest,
TestUndockedDevToolsUnresponsive) {
ASSERT_TRUE(test_server()->Start());
LoadTestPage(kDebuggerTestPage);
DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents(
GetInspectedTab(), false);
content::WindowedNotificationObserver devtools_close_observer(
content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<content::WebContents>(
devtools_window->web_contents()));
ASSERT_TRUE(content::ExecuteScript(
devtools_window->web_contents()->GetRenderViewHost(),
"window.addEventListener('beforeunload',"
"function(event) { while (true); });"));
CloseInspectedTab();
devtools_close_observer.Wait();
}
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
TestWorkerWindowClosing) {
ASSERT_TRUE(test_server()->Start());
LoadTestPage(kDebuggerTestPage);
DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents(
GetInspectedTab(), false);
content::WindowedNotificationObserver devtools_close_observer(
content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<content::WebContents>(
devtools_window->web_contents()));
OpenDevToolsPopupWindow(devtools_window);
CloseDevToolsPopupWindow(devtools_window);
}
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
TestDevToolsOnDevTools) {
ASSERT_TRUE(test_server()->Start());
LoadTestPage(kDebuggerTestPage);
std::vector<DevToolsWindow*> windows;
std::vector<content::WindowedNotificationObserver*> close_observers;
content::WebContents* inspected_web_contents = GetInspectedTab();
for (int i = 0; i < 3; ++i) {
DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents(
inspected_web_contents, i == 0);
windows.push_back(devtools_window);
content::WindowedNotificationObserver* close_observer =
new content::WindowedNotificationObserver(
content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<content::WebContents>(
devtools_window->web_contents()));
close_observers.push_back(close_observer);
inspected_web_contents = devtools_window->web_contents();
}
InjectBeforeUnloadListener(windows[0]->web_contents());
InjectBeforeUnloadListener(windows[2]->web_contents());
{
content::WindowedNotificationObserver cancel_browser(
chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
content::NotificationService::AllSources());
chrome::CloseWindow(windows[1]->browser());
CancelModalDialog();
cancel_browser.Wait();
}
{
content::WindowedNotificationObserver cancel_browser(
chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
content::NotificationService::AllSources());
chrome::CloseWindow(browser());
AcceptModalDialog();
CancelModalDialog();
cancel_browser.Wait();
}
{
content::WindowedNotificationObserver close_observer(
chrome::NOTIFICATION_BROWSER_CLOSED,
content::Source<Browser>(browser()));
chrome::IncrementKeepAliveCount();
chrome::CloseAllBrowsers();
AcceptModalDialog();
AcceptModalDialog();
close_observer.Wait();
}
for (size_t i = 0; i < close_observers.size(); ++i) {
close_observers[i]->Wait();
delete close_observers[i];
}
}
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_TestShowScriptsTab) {
RunTest("testShowScriptsTab", kDebuggerTestPage);
}
IN_PROC_BROWSER_TEST_F(
DevToolsSanityTest,
TestScriptsTabIsPopulatedOnInspectedPageRefresh) {
content::BrowserContext* browser_context =
GetInspectedTab()->GetBrowserContext();
Profile::FromBrowserContext(browser_context)->GetPrefs()->
ClearPref(prefs::kWebKitInspectorSettings);
RunTest("testScriptsTabIsPopulatedOnInspectedPageRefresh",
kDebuggerTestPage);
}
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
TestDevToolsExtensionAPI) {
LoadExtension("devtools_extension");
RunTest("waitForTestResultsInConsole", std::string());
}
#if defined(OS_WIN)
#define MAYBE_TestDevToolsExtensionMessaging DISABLED_TestDevToolsExtensionMessaging
#else
#define MAYBE_TestDevToolsExtensionMessaging TestDevToolsExtensionMessaging
#endif
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
MAYBE_TestDevToolsExtensionMessaging) {
LoadExtension("devtools_messaging");
RunTest("waitForTestResultsInConsole", std::string());
}
IN_PROC_BROWSER_TEST_F(DevToolsExperimentalExtensionTest,
TestDevToolsExperimentalExtensionAPI) {
LoadExtension("devtools_experimental");
RunTest("waitForTestResultsInConsole", std::string());
}
IN_PROC_BROWSER_TEST_F(DevToolsExtensionTest,
DISABLED_TestContentScriptIsPresent) {
LoadExtension("simple_content_script");
RunTest("testContentScriptIsPresent", kPageWithContentScript);
}
#if defined(OS_WIN) || defined(OS_MACOSX)
#define MAYBE_TestNoScriptDuplicatesOnPanelSwitch \
DISABLED_TestNoScriptDuplicatesOnPanelSwitch
#else
#define MAYBE_TestNoScriptDuplicatesOnPanelSwitch \
TestNoScriptDuplicatesOnPanelSwitch
#endif
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
MAYBE_TestNoScriptDuplicatesOnPanelSwitch) {
RunTest("testNoScriptDuplicatesOnPanelSwitch", kDebuggerTestPage);
}
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
DISABLED_TestPauseWhenLoadingDevTools) {
RunTest("testPauseWhenLoadingDevTools", kPauseWhenLoadingDevTools);
}
#if defined(OS_WIN)
#define MAYBE_TestPauseWhenScriptIsRunning DISABLED_TestPauseWhenScriptIsRunning
#elif defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(ARCH_CPU_ARM_FAMILY)
#define MAYBE_TestPauseWhenScriptIsRunning DISABLED_TestPauseWhenScriptIsRunning
#else
#define MAYBE_TestPauseWhenScriptIsRunning TestPauseWhenScriptIsRunning
#endif
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest,
MAYBE_TestPauseWhenScriptIsRunning) {
RunTest("testPauseWhenScriptIsRunning", kPauseWhenScriptIsRunning);
}
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkTiming) {
RunTest("testNetworkTiming", kSlowTestPage);
}
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSize) {
RunTest("testNetworkSize", kChunkedTestPage);
}
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkSyncSize) {
RunTest("testNetworkSyncSize", kChunkedTestPage);
}
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNetworkRawHeadersText) {
RunTest("testNetworkRawHeadersText", kChunkedTestPage);
}
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestConsoleOnNavigateBack) {
RunTest("testConsoleOnNavigateBack", kNavigateBackTestPage);
}
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsExternalNavigation) {
OpenDevToolsWindow(kDebuggerTestPage, true);
GURL url = test_server()->GetURL(kNavigateBackTestPage);
content::WaitForLoadStop(window_->web_contents());
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
ASSERT_TRUE(content::ExecuteScript(
window_->web_contents(),
std::string("window.location = \"") + url.spec() + "\""));
observer.Wait();
ASSERT_TRUE(window_->web_contents()->GetURL().
SchemeIs(content::kChromeDevToolsScheme));
ASSERT_EQ(url, GetInspectedTab()->GetURL());
CloseDevToolsWindow();
}
#if defined(OS_WIN) || defined(OS_MACOSX)
#define MAYBE_TestReattachAfterCrash DISABLED_TestReattachAfterCrash
#else
#define MAYBE_TestReattachAfterCrash TestReattachAfterCrash
#endif
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, MAYBE_TestReattachAfterCrash) {
OpenDevToolsWindow(kDebuggerTestPage, false);
content::CrashTab(GetInspectedTab());
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
&browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
chrome::Reload(browser(), CURRENT_TAB);
observer.Wait();
RunTestFunction(window_, "testReattachAfterCrash");
CloseDevToolsWindow();
}
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) {
OpenDevToolsWindow("about:blank", false);
std::string result;
ASSERT_TRUE(
content::ExecuteScriptAndExtractString(
window_->GetRenderViewHost(),
"window.domAutomationController.send("
" '' + (window.uiTests && (typeof uiTests.runTest)));",
&result));
ASSERT_EQ("function", result) << "DevTools front-end is broken.";
CloseDevToolsWindow();
}
#if defined(OS_MACOSX)
#define MAYBE_InspectSharedWorker DISABLED_InspectSharedWorker
#else
#define MAYBE_InspectSharedWorker InspectSharedWorker
#endif
IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest, MAYBE_InspectSharedWorker) {
#if defined(OS_WIN) && defined(USE_ASH)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
RunTest("testSharedWorker", kSharedWorkerTestPage);
}
#if defined(OS_MACOSX) || defined(OS_WIN)
#define MAYBE_PauseInSharedWorkerInitialization DISABLED_PauseInSharedWorkerInitialization
#else
#define MAYBE_PauseInSharedWorkerInitialization PauseInSharedWorkerInitialization
#endif
IN_PROC_BROWSER_TEST_F(WorkerDevToolsSanityTest,
MAYBE_PauseInSharedWorkerInitialization) {
ASSERT_TRUE(test_server()->Start());
GURL url = test_server()->GetURL(kReloadSharedWorkerTestPage);
ui_test_utils::NavigateToURL(browser(), url);
scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker();
OpenDevToolsWindowForSharedWorker(worker_data.get());
TerminateWorker(worker_data);
ui_test_utils::NavigateToURL(browser(), url);
RunTestFunction(window_, "testPauseInSharedWorkerInitialization");
CloseDevToolsWindow();
}
class DevToolsAgentHostTest : public InProcessBrowserTest {};
IN_PROC_BROWSER_TEST_F(DevToolsAgentHostTest, TestAgentHostReleased) {
ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
RenderViewHost* rvh = browser()->tab_strip_model()->GetWebContentsAt(0)->
GetRenderViewHost();
DevToolsAgentHost* agent_raw = DevToolsAgentHost::GetOrCreateFor(rvh).get();
const std::string agent_id = agent_raw->GetId();
ASSERT_EQ(agent_raw, DevToolsAgentHost::GetForId(agent_id)) <<
"DevToolsAgentHost cannot be found by id";
browser()->tab_strip_model()->
CloseWebContentsAt(0, TabStripModel::CLOSE_NONE);
ASSERT_FALSE(DevToolsAgentHost::GetForId(agent_id).get())
<< "DevToolsAgentHost is not released when the tab is closed";
}
class RemoteDebuggingTest: public ExtensionApiTest {
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
ExtensionApiTest::SetUpCommandLine(command_line);
command_line->AppendSwitchASCII(switches::kRemoteDebuggingPort, "9222");
PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
test_data_dir_ = test_data_dir_.AppendASCII("devtools");
}
};
IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) {
#if defined(OS_WIN) && defined(USE_ASH)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
return;
#endif
ASSERT_TRUE(RunExtensionTest("target_list")) << message_;
}