| Index: chrome/browser/devtools/devtools_sanity_browsertest.cc
|
| diff --git a/chrome/browser/devtools/devtools_sanity_browsertest.cc b/chrome/browser/devtools/devtools_sanity_browsertest.cc
|
| index 764eeacc797b94a2748ffb5e2980e89c5cbb8c18..6d5a6fcd54eb4ac40af4efa648be560cffe8c454 100644
|
| --- a/chrome/browser/devtools/devtools_sanity_browsertest.cc
|
| +++ b/chrome/browser/devtools/devtools_sanity_browsertest.cc
|
| @@ -14,7 +14,7 @@
|
| #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_testing.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"
|
| @@ -84,21 +84,19 @@
|
| void RunTestFunction(DevToolsWindow* window, const char* test_name) {
|
| std::string result;
|
|
|
| - RenderViewHost* rvh = DevToolsWindowTesting::Get(window)->
|
| - main_web_contents()->GetRenderViewHost();
|
| // At first check that JavaScript part of the front-end is loaded by
|
| // checking that global variable uiTests exists(it's created after all js
|
| // files have been loaded) and has runTest method.
|
| ASSERT_TRUE(
|
| content::ExecuteScriptAndExtractString(
|
| - rvh,
|
| + window->web_contents_for_test()->GetRenderViewHost(),
|
| "window.domAutomationController.send("
|
| " '' + (window.uiTests && (typeof uiTests.runTest)));",
|
| &result));
|
|
|
| ASSERT_EQ("function", result) << "DevTools front-end is broken.";
|
| ASSERT_TRUE(content::ExecuteScriptAndExtractString(
|
| - rvh,
|
| + window->web_contents_for_test()->GetRenderViewHost(),
|
| base::StringPrintf("uiTests.runTest('%s')", test_name),
|
| &result));
|
| EXPECT_EQ("[OK]", result);
|
| @@ -129,24 +127,38 @@
|
| LoadTestPage(test_page);
|
|
|
| inspected_rvh_ = GetInspectedTab()->GetRenderViewHost();
|
| - window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| - inspected_rvh_, is_docked);
|
| + 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_for_test()));
|
| + DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false,
|
| + DevToolsToggleAction::Toggle());
|
| + close_observer.Wait();
|
| + }
|
| +
|
| + void ToggleDevToolsWindowDontWait() {
|
| + DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false,
|
| + DevToolsToggleAction::Toggle());
|
| + }
|
| +
|
| void CloseDevToolsWindow() {
|
| - DevToolsWindowTesting::CloseDevToolsWindowSync(window_);
|
| - }
|
| -
|
| - WebContents* main_web_contents() {
|
| - return DevToolsWindowTesting::Get(window_)->main_web_contents();
|
| - }
|
| -
|
| - WebContents* toolbox_web_contents() {
|
| - return DevToolsWindowTesting::Get(window_)->toolbox_web_contents();
|
| + DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
|
| + content::WindowedNotificationObserver close_observer(
|
| + content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
|
| + content::Source<content::WebContents>(
|
| + window_->web_contents_for_test()));
|
| + devtools_manager->CloseAllClientHosts();
|
| + close_observer.Wait();
|
| }
|
|
|
| DevToolsWindow* window_;
|
| @@ -170,8 +182,7 @@
|
|
|
| DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver(
|
| DevToolsWindow* devtools_window)
|
| - : WebContentsObserver(
|
| - DevToolsWindowTesting::Get(devtools_window)->main_web_contents()),
|
| + : WebContentsObserver(devtools_window->web_contents_for_test()),
|
| m_fired(false) {
|
| }
|
|
|
| @@ -201,14 +212,17 @@
|
| TabStripModel::CLOSE_NONE);
|
| }
|
|
|
| - void CloseDevToolsWindowAsync() {
|
| - DevToolsWindowTesting::CloseDevToolsWindow(window_);
|
| + void CloseDockedDevTools() {
|
| + ToggleDevToolsWindowDontWait();
|
| + }
|
| +
|
| + void CloseUndockedDevTools() {
|
| + chrome::CloseWindow(window_->browser_for_test());
|
| }
|
|
|
| void CloseInspectedBrowser() {
|
| chrome::CloseWindow(browser());
|
| }
|
| -
|
| protected:
|
| void InjectBeforeUnloadListener(content::WebContents* web_contents) {
|
| ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(),
|
| @@ -220,11 +234,11 @@
|
| base::Callback<void(void)> close_method,
|
| bool wait_for_browser_close = true) {
|
| OpenDevToolsWindow(kDebuggerTestPage, is_docked);
|
| - scoped_refptr<content::MessageLoopRunner> runner =
|
| - new content::MessageLoopRunner;
|
| - DevToolsWindowTesting::Get(window_)->
|
| - SetCloseCallback(runner->QuitClosure());
|
| - InjectBeforeUnloadListener(main_web_contents());
|
| + content::WindowedNotificationObserver devtools_close_observer(
|
| + content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
|
| + content::Source<content::WebContents>(
|
| + window_->web_contents_for_test()));
|
| + InjectBeforeUnloadListener(window_->web_contents_for_test());
|
| {
|
| DevToolsWindowBeforeUnloadObserver before_unload_observer(window_);
|
| close_method.Run();
|
| @@ -240,13 +254,14 @@
|
| if (wait_for_browser_close)
|
| close_observer.Wait();
|
| }
|
| - runner->Run();
|
| + devtools_close_observer.Wait();
|
| }
|
|
|
| DevToolsWindow* OpenDevToolWindowOnWebContents(
|
| content::WebContents* contents, bool is_docked) {
|
| - DevToolsWindow* window = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| + DevToolsWindow* window = DevToolsWindow::OpenDevToolsWindowForTest(
|
| contents->GetRenderViewHost(), is_docked);
|
| + ui_test_utils::WaitUntilDevToolsWindowLoaded(window);
|
| return window;
|
| }
|
|
|
| @@ -255,14 +270,29 @@
|
| content::NOTIFICATION_LOAD_STOP,
|
| content::NotificationService::AllSources());
|
| ASSERT_TRUE(content::ExecuteScript(
|
| - DevToolsWindowTesting::Get(devtools_window)->
|
| - main_web_contents()->GetRenderViewHost(),
|
| + devtools_window->web_contents_for_test()->GetRenderViewHost(),
|
| "window.open(\"\", \"\", \"location=0\");"));
|
| observer.Wait();
|
| }
|
|
|
| void CloseDevToolsPopupWindow(DevToolsWindow* devtools_window) {
|
| - DevToolsWindowTesting::CloseDevToolsWindowSync(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_for_test() != 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() {
|
| @@ -511,12 +541,18 @@
|
| DevToolsAgentHost::GetForWorker(
|
| worker_data->worker_process_id,
|
| worker_data->worker_route_id));
|
| - window_ = DevToolsWindowTesting::OpenDevToolsWindowForWorkerSync(
|
| - profile, agent_host);
|
| + window_ = DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host);
|
| + content::WaitForLoadStop(window_->web_contents_for_test());
|
| }
|
|
|
| void CloseDevToolsWindow() {
|
| - DevToolsWindowTesting::CloseDevToolsWindowSync(window_);
|
| + Browser* browser = window_->browser_for_test();
|
| + content::WindowedNotificationObserver close_observer(
|
| + content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
|
| + content::Source<content::WebContents>(
|
| + window_->web_contents_for_test()));
|
| + browser->tab_strip_model()->CloseAllTabs();
|
| + close_observer.Wait();
|
| }
|
|
|
| DevToolsWindow* window_;
|
| @@ -526,7 +562,7 @@
|
| // we try to close them.
|
| IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) {
|
| RunBeforeUnloadSanityTest(true, base::Bind(
|
| - &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, this), false);
|
| + &DevToolsBeforeUnloadTest::CloseDockedDevTools, this), false);
|
| }
|
|
|
| // Tests that BeforeUnload event gets called on docked devtools if
|
| @@ -549,7 +585,7 @@
|
| // we try to close them.
|
| IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) {
|
| RunBeforeUnloadSanityTest(false, base::Bind(
|
| - &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, this), false);
|
| + &DevToolsBeforeUnloadTest::CloseUndockedDevTools, this), false);
|
| }
|
|
|
| // Tests that BeforeUnload event gets called on undocked devtools if
|
| @@ -585,19 +621,17 @@
|
| LoadTestPage(kDebuggerTestPage);
|
| DevToolsWindow* devtools_window = OpenDevToolWindowOnWebContents(
|
| GetInspectedTab(), false);
|
| -
|
| - scoped_refptr<content::MessageLoopRunner> runner =
|
| - new content::MessageLoopRunner;
|
| - DevToolsWindowTesting::Get(devtools_window)->SetCloseCallback(
|
| - runner->QuitClosure());
|
| + content::WindowedNotificationObserver devtools_close_observer(
|
| + content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
|
| + content::Source<content::WebContents>(
|
| + devtools_window->web_contents_for_test()));
|
|
|
| ASSERT_TRUE(content::ExecuteScript(
|
| - DevToolsWindowTesting::Get(devtools_window)->main_web_contents()->
|
| - GetRenderViewHost(),
|
| + devtools_window->web_contents_for_test()->GetRenderViewHost(),
|
| "window.addEventListener('beforeunload',"
|
| "function(event) { while (true); });"));
|
| CloseInspectedTab();
|
| - runner->Run();
|
| + devtools_close_observer.Wait();
|
| }
|
|
|
| // Tests that closing worker inspector window does not cause browser crash
|
| @@ -608,6 +642,10 @@
|
| 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_for_test()));
|
|
|
| OpenDevToolsPopupWindow(devtools_window);
|
| CloseDevToolsPopupWindow(devtools_window);
|
| @@ -631,23 +669,19 @@
|
| new content::WindowedNotificationObserver(
|
| content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
|
| content::Source<content::WebContents>(
|
| - DevToolsWindowTesting::Get(devtools_window)->
|
| - main_web_contents()));
|
| + devtools_window->web_contents_for_test()));
|
| close_observers.push_back(close_observer);
|
| - inspected_web_contents =
|
| - DevToolsWindowTesting::Get(devtools_window)->main_web_contents();
|
| - }
|
| -
|
| - InjectBeforeUnloadListener(
|
| - DevToolsWindowTesting::Get(windows[0])->main_web_contents());
|
| - InjectBeforeUnloadListener(
|
| - DevToolsWindowTesting::Get(windows[2])->main_web_contents());
|
| + inspected_web_contents = devtools_window->web_contents_for_test();
|
| + }
|
| +
|
| + InjectBeforeUnloadListener(windows[0]->web_contents_for_test());
|
| + InjectBeforeUnloadListener(windows[2]->web_contents_for_test());
|
| // Try to close second devtools.
|
| {
|
| content::WindowedNotificationObserver cancel_browser(
|
| chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
|
| content::NotificationService::AllSources());
|
| - chrome::CloseWindow(DevToolsWindowTesting::Get(windows[1])->browser());
|
| + chrome::CloseWindow(windows[1]->browser_for_test());
|
| CancelModalDialog();
|
| cancel_browser.Wait();
|
| }
|
| @@ -805,38 +839,22 @@
|
| IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsExternalNavigation) {
|
| OpenDevToolsWindow(kDebuggerTestPage, true);
|
| GURL url = test_server()->GetURL(kNavigateBackTestPage);
|
| - ui_test_utils::UrlLoadObserver observer(url,
|
| + // TODO(dgozman): remove this once notifications are gone.
|
| + // Right now notifications happen after observers, so DevTools window is
|
| + // already loaded, but we still catch it's notification when looking for
|
| + // all sources.
|
| + content::WaitForLoadStop(window_->web_contents_for_test());
|
| + content::WindowedNotificationObserver observer(
|
| + content::NOTIFICATION_LOAD_STOP,
|
| content::NotificationService::AllSources());
|
| ASSERT_TRUE(content::ExecuteScript(
|
| - main_web_contents(),
|
| + window_->web_contents_for_test(),
|
| std::string("window.location = \"") + url.spec() + "\""));
|
| observer.Wait();
|
|
|
| - ASSERT_TRUE(main_web_contents()->GetURL().
|
| + ASSERT_TRUE(window_->web_contents_for_test()->GetURL().
|
| SchemeIs(content::kChromeDevToolsScheme));
|
| ASSERT_EQ(url, GetInspectedTab()->GetURL());
|
| - CloseDevToolsWindow();
|
| -}
|
| -
|
| -// Tests that toolbox window is loaded when DevTools window is undocked.
|
| -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxLoadedUndocked) {
|
| - OpenDevToolsWindow(kDebuggerTestPage, false);
|
| - ASSERT_TRUE(toolbox_web_contents());
|
| - DevToolsWindow* on_self = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| - main_web_contents()->GetRenderViewHost(), false);
|
| - ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents());
|
| - DevToolsWindowTesting::CloseDevToolsWindowSync(on_self);
|
| - CloseDevToolsWindow();
|
| -}
|
| -
|
| -// Tests that toolbox window is not loaded when DevTools window is docked.
|
| -IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestToolboxNotLoadedDocked) {
|
| - OpenDevToolsWindow(kDebuggerTestPage, true);
|
| - ASSERT_FALSE(toolbox_web_contents());
|
| - DevToolsWindow* on_self = DevToolsWindowTesting::OpenDevToolsWindowSync(
|
| - main_web_contents()->GetRenderViewHost(), false);
|
| - ASSERT_FALSE(DevToolsWindowTesting::Get(on_self)->toolbox_web_contents());
|
| - DevToolsWindowTesting::CloseDevToolsWindowSync(on_self);
|
| CloseDevToolsWindow();
|
| }
|
|
|
| @@ -851,7 +869,7 @@
|
| std::string result;
|
| ASSERT_TRUE(
|
| content::ExecuteScriptAndExtractString(
|
| - main_web_contents()->GetRenderViewHost(),
|
| + window_->web_contents_for_test()->GetRenderViewHost(),
|
| "window.domAutomationController.send("
|
| " '' + (window.uiTests && (typeof uiTests.runTest)));",
|
| &result));
|
|
|