summaryrefslogtreecommitdiffstats
path: root/chrome/browser/devtools
diff options
context:
space:
mode:
authordgozman@chromium.org <dgozman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-18 10:38:21 +0000
committerdgozman@chromium.org <dgozman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-18 10:38:21 +0000
commit1ffb1c808855bfc51b726d6a1a4b15fd585845af (patch)
tree3be7c8e2a115597675c556b4851c886a8710dea2 /chrome/browser/devtools
parente61ba7dc904723b093bc7f17bc926d6bfc43ef97 (diff)
downloadchromium_src-1ffb1c808855bfc51b726d6a1a4b15fd585845af.zip
chromium_src-1ffb1c808855bfc51b726d6a1a4b15fd585845af.tar.gz
chromium_src-1ffb1c808855bfc51b726d6a1a4b15fd585845af.tar.bz2
[DevTools] Move DevToolsWindow testing code to a separate class.
This change: - allows for proper docking testing (including toolbox); - removes all test friends from DevToolsWindow; - unifies testing approach to use load callback instead of notifications; - adds simple toolbox tests. BUG=393566 Review URL: https://codereview.chromium.org/395783002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284050 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/devtools')
-rw-r--r--chrome/browser/devtools/devtools_sanity_browsertest.cc170
-rw-r--r--chrome/browser/devtools/devtools_window.cc87
-rw-r--r--chrome/browser/devtools/devtools_window.h24
-rw-r--r--chrome/browser/devtools/devtools_window_testing.cc151
-rw-r--r--chrome/browser/devtools/devtools_window_testing.h60
5 files changed, 329 insertions, 163 deletions
diff --git a/chrome/browser/devtools/devtools_sanity_browsertest.cc b/chrome/browser/devtools/devtools_sanity_browsertest.cc
index 6d5a6fc..764eeac 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.h"
+#include "chrome/browser/devtools/devtools_window_testing.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/extensions/extension_service.h"
@@ -84,19 +84,21 @@ const char kReloadSharedWorkerTestPage[] =
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(
- window->web_contents_for_test()->GetRenderViewHost(),
+ rvh,
"window.domAutomationController.send("
" '' + (window.uiTests && (typeof uiTests.runTest)));",
&result));
ASSERT_EQ("function", result) << "DevTools front-end is broken.";
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
- window->web_contents_for_test()->GetRenderViewHost(),
+ rvh,
base::StringPrintf("uiTests.runTest('%s')", test_name),
&result));
EXPECT_EQ("[OK]", result);
@@ -127,38 +129,24 @@ class DevToolsSanityTest : public InProcessBrowserTest {
LoadTestPage(test_page);
inspected_rvh_ = GetInspectedTab()->GetRenderViewHost();
- window_ =
- DevToolsWindow::OpenDevToolsWindowForTest(inspected_rvh_, is_docked);
- ui_test_utils::WaitUntilDevToolsWindowLoaded(window_);
+ window_ = DevToolsWindowTesting::OpenDevToolsWindowSync(
+ inspected_rvh_, is_docked);
}
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 CloseDevToolsWindow() {
+ DevToolsWindowTesting::CloseDevToolsWindowSync(window_);
}
- void ToggleDevToolsWindowDontWait() {
- DevToolsWindow::ToggleDevToolsWindow(inspected_rvh_, false,
- DevToolsToggleAction::Toggle());
+ WebContents* main_web_contents() {
+ return DevToolsWindowTesting::Get(window_)->main_web_contents();
}
- void CloseDevToolsWindow() {
- 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();
+ WebContents* toolbox_web_contents() {
+ return DevToolsWindowTesting::Get(window_)->toolbox_web_contents();
}
DevToolsWindow* window_;
@@ -182,7 +170,8 @@ class DevToolsWindowBeforeUnloadObserver
DevToolsWindowBeforeUnloadObserver::DevToolsWindowBeforeUnloadObserver(
DevToolsWindow* devtools_window)
- : WebContentsObserver(devtools_window->web_contents_for_test()),
+ : WebContentsObserver(
+ DevToolsWindowTesting::Get(devtools_window)->main_web_contents()),
m_fired(false) {
}
@@ -212,17 +201,14 @@ class DevToolsBeforeUnloadTest: public DevToolsSanityTest {
TabStripModel::CLOSE_NONE);
}
- void CloseDockedDevTools() {
- ToggleDevToolsWindowDontWait();
- }
-
- void CloseUndockedDevTools() {
- chrome::CloseWindow(window_->browser_for_test());
+ void CloseDevToolsWindowAsync() {
+ DevToolsWindowTesting::CloseDevToolsWindow(window_);
}
void CloseInspectedBrowser() {
chrome::CloseWindow(browser());
}
+
protected:
void InjectBeforeUnloadListener(content::WebContents* web_contents) {
ASSERT_TRUE(content::ExecuteScript(web_contents->GetRenderViewHost(),
@@ -234,11 +220,11 @@ class DevToolsBeforeUnloadTest: public DevToolsSanityTest {
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_for_test()));
- InjectBeforeUnloadListener(window_->web_contents_for_test());
+ scoped_refptr<content::MessageLoopRunner> runner =
+ new content::MessageLoopRunner;
+ DevToolsWindowTesting::Get(window_)->
+ SetCloseCallback(runner->QuitClosure());
+ InjectBeforeUnloadListener(main_web_contents());
{
DevToolsWindowBeforeUnloadObserver before_unload_observer(window_);
close_method.Run();
@@ -254,14 +240,13 @@ class DevToolsBeforeUnloadTest: public DevToolsSanityTest {
if (wait_for_browser_close)
close_observer.Wait();
}
- devtools_close_observer.Wait();
+ runner->Run();
}
DevToolsWindow* OpenDevToolWindowOnWebContents(
content::WebContents* contents, bool is_docked) {
- DevToolsWindow* window = DevToolsWindow::OpenDevToolsWindowForTest(
+ DevToolsWindow* window = DevToolsWindowTesting::OpenDevToolsWindowSync(
contents->GetRenderViewHost(), is_docked);
- ui_test_utils::WaitUntilDevToolsWindowLoaded(window);
return window;
}
@@ -270,29 +255,14 @@ class DevToolsBeforeUnloadTest: public DevToolsSanityTest {
content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
ASSERT_TRUE(content::ExecuteScript(
- devtools_window->web_contents_for_test()->GetRenderViewHost(),
+ DevToolsWindowTesting::Get(devtools_window)->
+ main_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_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();
+ DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window);
}
void AcceptModalDialog() {
@@ -541,18 +511,12 @@ class WorkerDevToolsSanityTest : public InProcessBrowserTest {
DevToolsAgentHost::GetForWorker(
worker_data->worker_process_id,
worker_data->worker_route_id));
- window_ = DevToolsWindow::OpenDevToolsWindowForWorker(profile, agent_host);
- content::WaitForLoadStop(window_->web_contents_for_test());
+ window_ = DevToolsWindowTesting::OpenDevToolsWindowForWorkerSync(
+ profile, agent_host);
}
void CloseDevToolsWindow() {
- 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();
+ DevToolsWindowTesting::CloseDevToolsWindowSync(window_);
}
DevToolsWindow* window_;
@@ -562,7 +526,7 @@ class WorkerDevToolsSanityTest : public InProcessBrowserTest {
// we try to close them.
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestDockedDevToolsClose) {
RunBeforeUnloadSanityTest(true, base::Bind(
- &DevToolsBeforeUnloadTest::CloseDockedDevTools, this), false);
+ &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, this), false);
}
// Tests that BeforeUnload event gets called on docked devtools if
@@ -585,7 +549,7 @@ IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
// we try to close them.
IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest, TestUndockedDevToolsClose) {
RunBeforeUnloadSanityTest(false, base::Bind(
- &DevToolsBeforeUnloadTest::CloseUndockedDevTools, this), false);
+ &DevToolsBeforeUnloadTest::CloseDevToolsWindowAsync, this), false);
}
// Tests that BeforeUnload event gets called on undocked devtools if
@@ -621,17 +585,19 @@ IN_PROC_BROWSER_TEST_F(DevToolsUnresponsiveBeforeUnloadTest,
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()));
+
+ scoped_refptr<content::MessageLoopRunner> runner =
+ new content::MessageLoopRunner;
+ DevToolsWindowTesting::Get(devtools_window)->SetCloseCallback(
+ runner->QuitClosure());
ASSERT_TRUE(content::ExecuteScript(
- devtools_window->web_contents_for_test()->GetRenderViewHost(),
+ DevToolsWindowTesting::Get(devtools_window)->main_web_contents()->
+ GetRenderViewHost(),
"window.addEventListener('beforeunload',"
"function(event) { while (true); });"));
CloseInspectedTab();
- devtools_close_observer.Wait();
+ runner->Run();
}
// Tests that closing worker inspector window does not cause browser crash
@@ -642,10 +608,6 @@ IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
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);
@@ -669,19 +631,23 @@ IN_PROC_BROWSER_TEST_F(DevToolsBeforeUnloadTest,
new content::WindowedNotificationObserver(
content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
content::Source<content::WebContents>(
- devtools_window->web_contents_for_test()));
+ DevToolsWindowTesting::Get(devtools_window)->
+ main_web_contents()));
close_observers.push_back(close_observer);
- inspected_web_contents = devtools_window->web_contents_for_test();
+ inspected_web_contents =
+ DevToolsWindowTesting::Get(devtools_window)->main_web_contents();
}
- InjectBeforeUnloadListener(windows[0]->web_contents_for_test());
- InjectBeforeUnloadListener(windows[2]->web_contents_for_test());
+ InjectBeforeUnloadListener(
+ DevToolsWindowTesting::Get(windows[0])->main_web_contents());
+ InjectBeforeUnloadListener(
+ DevToolsWindowTesting::Get(windows[2])->main_web_contents());
// Try to close second devtools.
{
content::WindowedNotificationObserver cancel_browser(
chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
content::NotificationService::AllSources());
- chrome::CloseWindow(windows[1]->browser_for_test());
+ chrome::CloseWindow(DevToolsWindowTesting::Get(windows[1])->browser());
CancelModalDialog();
cancel_browser.Wait();
}
@@ -839,25 +805,41 @@ IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDeviceEmulation) {
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestDevToolsExternalNavigation) {
OpenDevToolsWindow(kDebuggerTestPage, true);
GURL url = test_server()->GetURL(kNavigateBackTestPage);
- // 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,
+ ui_test_utils::UrlLoadObserver observer(url,
content::NotificationService::AllSources());
ASSERT_TRUE(content::ExecuteScript(
- window_->web_contents_for_test(),
+ main_web_contents(),
std::string("window.location = \"") + url.spec() + "\""));
observer.Wait();
- ASSERT_TRUE(window_->web_contents_for_test()->GetURL().
+ ASSERT_TRUE(main_web_contents()->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();
+}
+
// Tests that inspector will reattach to inspected page when it is reloaded
// after a crash. See http://crbug.com/101952
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestReattachAfterCrash) {
@@ -869,7 +851,7 @@ IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestPageWithNoJavaScript) {
std::string result;
ASSERT_TRUE(
content::ExecuteScriptAndExtractString(
- window_->web_contents_for_test()->GetRenderViewHost(),
+ main_web_contents()->GetRenderViewHost(),
"window.domAutomationController.send("
" '' + (window.uiTests && (typeof uiTests.runTest)));",
&result));
diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc
index 608ac7a..c47389d 100644
--- a/chrome/browser/devtools/devtools_window.cc
+++ b/chrome/browser/devtools/devtools_window.cc
@@ -39,7 +39,6 @@
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
@@ -49,7 +48,6 @@
#include "content/public/common/content_client.h"
#include "content/public/common/page_transition_types.h"
#include "content/public/common/url_constants.h"
-#include "content/public/test/test_utils.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/events/keycodes/keyboard_codes.h"
@@ -318,6 +316,11 @@ DevToolsWindow::~DevToolsWindow() {
std::find(instances->begin(), instances->end(), this));
DCHECK(it != instances->end());
instances->erase(it);
+
+ if (!close_callback_.is_null()) {
+ close_callback_.Run();
+ close_callback_ = base::Closure();
+ }
}
// static
@@ -403,7 +406,16 @@ DevToolsWindow* DevToolsWindow::GetInstanceForInspectedWebContents(
// static
bool DevToolsWindow::IsDevToolsWindow(content::WebContents* web_contents) {
- return AsDevToolsWindow(web_contents) != NULL;
+ if (!web_contents || g_instances == NULL)
+ return false;
+ DevToolsWindows* instances = g_instances.Pointer();
+ for (DevToolsWindows::iterator it(instances->begin()); it != instances->end();
+ ++it) {
+ if ((*it)->main_web_contents_ == web_contents ||
+ (*it)->toolbox_web_contents_ == web_contents)
+ return true;
+ }
+ return false;
}
// static
@@ -425,40 +437,21 @@ DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForWorker(
DevToolsWindow* DevToolsWindow::CreateDevToolsWindowForWorker(
Profile* profile) {
content::RecordAction(base::UserMetricsAction("DevTools_InspectWorker"));
- return Create(profile, GURL(), NULL, true, false, false);
+ return Create(profile, GURL(), NULL, true, false, false, "");
}
// static
DevToolsWindow* DevToolsWindow::OpenDevToolsWindow(
content::RenderViewHost* inspected_rvh) {
return ToggleDevToolsWindow(
- inspected_rvh, true, DevToolsToggleAction::Show());
+ inspected_rvh, true, DevToolsToggleAction::Show(), "");
}
// static
DevToolsWindow* DevToolsWindow::OpenDevToolsWindow(
content::RenderViewHost* inspected_rvh,
const DevToolsToggleAction& action) {
- return ToggleDevToolsWindow(
- inspected_rvh, true, action);
-}
-
-// static
-DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForTest(
- content::RenderViewHost* inspected_rvh,
- bool is_docked) {
- DevToolsWindow* window = OpenDevToolsWindow(inspected_rvh);
- window->SetIsDockedAndShowImmediatelyForTest(is_docked);
- return window;
-}
-
-// static
-DevToolsWindow* DevToolsWindow::OpenDevToolsWindowForTest(
- Browser* browser,
- bool is_docked) {
- return OpenDevToolsWindowForTest(
- browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(),
- is_docked);
+ return ToggleDevToolsWindow(inspected_rvh, true, action, "");
}
// static
@@ -473,7 +466,7 @@ DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
return ToggleDevToolsWindow(
browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(),
- action.type() == DevToolsToggleAction::kInspect, action);
+ action.type() == DevToolsToggleAction::kInspect, action, "");
}
// static
@@ -484,7 +477,7 @@ void DevToolsWindow::OpenExternalFrontend(
DevToolsWindow* window = FindDevToolsWindow(agent_host);
if (!window) {
window = Create(profile, DevToolsUI::GetProxyURL(frontend_url), NULL,
- false, true, false);
+ false, true, false, "");
content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(
agent_host, window->bindings_->frontend_host());
}
@@ -495,7 +488,8 @@ void DevToolsWindow::OpenExternalFrontend(
DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
content::RenderViewHost* inspected_rvh,
bool force_open,
- const DevToolsToggleAction& action) {
+ const DevToolsToggleAction& action,
+ const std::string& settings) {
scoped_refptr<DevToolsAgentHost> agent(
DevToolsAgentHost::GetOrCreateFor(inspected_rvh));
content::DevToolsManager* manager = content::DevToolsManager::GetInstance();
@@ -506,7 +500,8 @@ DevToolsWindow* DevToolsWindow::ToggleDevToolsWindow(
inspected_rvh->GetProcess()->GetBrowserContext());
content::RecordAction(
base::UserMetricsAction("DevTools_InspectRenderer"));
- window = Create(profile, GURL(), inspected_rvh, false, false, true);
+ window = Create(
+ profile, GURL(), inspected_rvh, false, false, true, settings);
manager->RegisterDevToolsClientHostFor(agent.get(),
window->bindings_->frontend_host());
do_open = true;
@@ -700,7 +695,6 @@ DevToolsWindow::DevToolsWindow(Profile* profile,
// Passing "dockSide=undocked" parameter ensures proper UI.
life_stage_(can_dock ? kNotLoaded : kIsDockedSet),
action_on_load_(DevToolsToggleAction::NoOp()),
- ignore_set_is_docked_(false),
intercepted_page_beforeunload_(false) {
// Set up delegate, so we get fully-functional window immediately.
// It will not appear in UI though until |life_stage_ == kLoadCompleted|.
@@ -732,7 +726,8 @@ DevToolsWindow* DevToolsWindow::Create(
content::RenderViewHost* inspected_rvh,
bool shared_worker_frontend,
bool external_frontend,
- bool can_dock) {
+ bool can_dock,
+ const std::string& settings) {
if (inspected_rvh) {
// Check for a place to dock.
Browser* browser = NULL;
@@ -751,7 +746,7 @@ DevToolsWindow* DevToolsWindow::Create(
GURL url(GetDevToolsURL(profile, frontend_url,
shared_worker_frontend,
external_frontend,
- can_dock));
+ can_dock, settings));
return new DevToolsWindow(profile, url, inspected_rvh, can_dock);
}
@@ -760,7 +755,8 @@ GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
const GURL& base_url,
bool shared_worker_frontend,
bool external_frontend,
- bool can_dock) {
+ bool can_dock,
+ const std::string& settings) {
// Compatibility errors are encoded with data urls, pass them
// through with no decoration.
if (base_url.SchemeIs("data"))
@@ -777,6 +773,8 @@ GURL DevToolsWindow::GetDevToolsURL(Profile* profile,
url_string += "&remoteFrontend=true";
if (can_dock)
url_string += "&can_dock=true";
+ if (settings.size())
+ url_string += "&settings=" + settings;
return GURL(url_string);
}
@@ -1030,27 +1028,8 @@ void DevToolsWindow::MoveWindow(int x, int y) {
}
}
-void DevToolsWindow::SetIsDockedAndShowImmediatelyForTest(bool is_docked) {
- DCHECK(!is_docked || can_dock_);
- DCHECK(life_stage_ != kClosing);
- if (life_stage_ == kLoadCompleted) {
- SetIsDocked(is_docked);
- } else {
- is_docked_ = is_docked;
- // Load is completed when both kIsDockedSet and kOnLoadFired happened.
- // Note that kIsDockedSet may be already set when can_dock_ is false.
- life_stage_ = life_stage_ == kOnLoadFired ? kLoadCompleted : kIsDockedSet;
- // Note that action_on_load_ will be performed after the load is actually
- // completed. For now, just show the window.
- Show(DevToolsToggleAction::Show());
- if (life_stage_ == kLoadCompleted)
- LoadCompleted();
- }
- ignore_set_is_docked_ = true;
-}
-
void DevToolsWindow::SetIsDocked(bool dock_requested) {
- if (ignore_set_is_docked_ || life_stage_ == kClosing)
+ if (life_stage_ == kClosing)
return;
DCHECK(can_dock_ || !dock_requested);
@@ -1261,7 +1240,7 @@ void DevToolsWindow::LoadCompleted() {
}
void DevToolsWindow::SetLoadCompletedCallback(const base::Closure& closure) {
- if (life_stage_ == kLoadCompleted) {
+ if (life_stage_ == kLoadCompleted || life_stage_ == kClosing) {
if (!closure.is_null())
closure.Run();
return;
diff --git a/chrome/browser/devtools/devtools_window.h b/chrome/browser/devtools/devtools_window.h
index 2bfa5f0..5cf23b1 100644
--- a/chrome/browser/devtools/devtools_window.h
+++ b/chrome/browser/devtools/devtools_window.h
@@ -13,6 +13,7 @@
class Browser;
class BrowserWindow;
+class DevToolsWindowTesting;
class DevToolsEventForwarder;
namespace content {
@@ -71,11 +72,6 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
static DevToolsWindow* OpenDevToolsWindow(
content::RenderViewHost* inspected_rvh);
- static DevToolsWindow* OpenDevToolsWindowForTest(
- content::RenderViewHost* inspected_rvh, bool is_docked);
- static DevToolsWindow* OpenDevToolsWindowForTest(
- Browser* browser, bool is_docked);
-
// Perform specified action for current WebContents inside a |browser|.
// This may close currently open DevTools window.
static DevToolsWindow* ToggleDevToolsWindow(
@@ -96,9 +92,6 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
static void InspectElement(
content::RenderViewHost* inspected_rvh, int x, int y);
- Browser* browser_for_test() { return browser_; }
- content::WebContents* web_contents_for_test() { return main_web_contents_; }
-
// Sets closure to be called after load is done. If already loaded, calls
// closure immediately.
void SetLoadCompletedCallback(const base::Closure& closure);
@@ -181,8 +174,7 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
static void OnPageCloseCanceled(content::WebContents* contents);
private:
- friend class DevToolsSanityTest;
- friend class BrowserWindowControllerTest;
+ friend class DevToolsWindowTesting;
// DevTools lifecycle typically follows this way:
// - Toggle/Open: client call;
@@ -215,19 +207,22 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
content::RenderViewHost* inspected_rvh,
bool shared_worker_frontend,
bool external_frontend,
- bool can_dock);
+ bool can_dock,
+ const std::string& settings);
static GURL GetDevToolsURL(Profile* profile,
const GURL& base_url,
bool shared_worker_frontend,
bool external_frontend,
- bool can_dock);
+ bool can_dock,
+ const std::string& settings);
static DevToolsWindow* FindDevToolsWindow(content::DevToolsAgentHost*);
static DevToolsWindow* AsDevToolsWindow(content::WebContents*);
static DevToolsWindow* CreateDevToolsWindowForWorker(Profile* profile);
static DevToolsWindow* ToggleDevToolsWindow(
content::RenderViewHost* inspected_rvh,
bool force_open,
- const DevToolsToggleAction& action);
+ const DevToolsToggleAction& action,
+ const std::string& settings);
static std::string GetDevToolsWindowPlacementPrefKey();
@@ -295,7 +290,6 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
void Show(const DevToolsToggleAction& action);
void DoAction(const DevToolsToggleAction& action);
void LoadCompleted();
- void SetIsDockedAndShowImmediatelyForTest(bool is_docked);
void UpdateBrowserToolbar();
void UpdateBrowserWindow();
content::WebContents* GetInspectedWebContents();
@@ -311,12 +305,12 @@ class DevToolsWindow : public DevToolsUIBindings::Delegate,
const bool can_dock_;
LifeStage life_stage_;
DevToolsToggleAction action_on_load_;
- bool ignore_set_is_docked_;
DevToolsContentsResizingStrategy contents_resizing_strategy_;
// True if we're in the process of handling a beforeunload event originating
// from the inspected webcontents, see InterceptPageBeforeUnload for details.
bool intercepted_page_beforeunload_;
base::Closure load_completed_callback_;
+ base::Closure close_callback_;
base::TimeTicks inspect_element_start_time_;
scoped_ptr<DevToolsEventForwarder> event_forwarder_;
diff --git a/chrome/browser/devtools/devtools_window_testing.cc b/chrome/browser/devtools/devtools_window_testing.cc
new file mode 100644
index 0000000..aa1ee4b
--- /dev/null
+++ b/chrome/browser/devtools/devtools_window_testing.cc
@@ -0,0 +1,151 @@
+// 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 "chrome/browser/devtools/devtools_window_testing.h"
+
+#include "base/lazy_instance.h"
+#include "chrome/browser/devtools/devtools_window.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "content/public/browser/devtools_agent_host.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/test/test_utils.h"
+
+namespace {
+
+typedef std::vector<DevToolsWindowTesting*> DevToolsWindowTestings;
+base::LazyInstance<DevToolsWindowTestings>::Leaky g_instances =
+ LAZY_INSTANCE_INITIALIZER;
+
+}
+
+DevToolsWindowTesting::DevToolsWindowTesting(DevToolsWindow* window)
+ : devtools_window_(window) {
+ DCHECK(window);
+ window->close_callback_ =
+ base::Bind(&DevToolsWindowTesting::WindowClosed, window);
+ g_instances.Get().push_back(this);
+}
+
+DevToolsWindowTesting::~DevToolsWindowTesting() {
+ DevToolsWindowTestings* instances = g_instances.Pointer();
+ DevToolsWindowTestings::iterator it(
+ std::find(instances->begin(), instances->end(), this));
+ DCHECK(it != instances->end());
+ instances->erase(it);
+ if (!close_callback_.is_null()) {
+ close_callback_.Run();
+ close_callback_ = base::Closure();
+ }
+}
+
+// static
+DevToolsWindowTesting* DevToolsWindowTesting::Get(DevToolsWindow* window) {
+ DevToolsWindowTesting* testing = DevToolsWindowTesting::Find(window);
+ if (!testing)
+ testing = new DevToolsWindowTesting(window);
+ return testing;
+}
+
+// static
+DevToolsWindowTesting* DevToolsWindowTesting::Find(DevToolsWindow* window) {
+ if (g_instances == NULL)
+ return NULL;
+ DevToolsWindowTestings* instances = g_instances.Pointer();
+ for (DevToolsWindowTestings::iterator it(instances->begin());
+ it != instances->end();
+ ++it) {
+ if ((*it)->devtools_window_ == window)
+ return *it;
+ }
+ return NULL;
+}
+
+Browser* DevToolsWindowTesting::browser() {
+ return devtools_window_->browser_;
+}
+
+content::WebContents* DevToolsWindowTesting::main_web_contents() {
+ return devtools_window_->main_web_contents_;
+}
+
+content::WebContents* DevToolsWindowTesting::toolbox_web_contents() {
+ return devtools_window_->toolbox_web_contents_;
+}
+
+void DevToolsWindowTesting::SetInspectedPageBounds(const gfx::Rect& bounds) {
+ devtools_window_->SetInspectedPageBounds(bounds);
+}
+
+void DevToolsWindowTesting::SetCloseCallback(const base::Closure& closure) {
+ close_callback_ = closure;
+}
+
+// static
+void DevToolsWindowTesting::WindowClosed(DevToolsWindow* window) {
+ DevToolsWindowTesting* testing = DevToolsWindowTesting::Find(window);
+ if (testing)
+ delete testing;
+}
+
+// static
+void DevToolsWindowTesting::WaitForDevToolsWindowLoad(DevToolsWindow* window) {
+ scoped_refptr<content::MessageLoopRunner> runner =
+ new content::MessageLoopRunner;
+ window->SetLoadCompletedCallback(runner->QuitClosure());
+ runner->Run();
+}
+
+// static
+DevToolsWindow* DevToolsWindowTesting::OpenDevToolsWindowSync(
+ content::RenderViewHost* inspected_rvh,
+ bool is_docked) {
+ std::string settings = is_docked ?
+ "{\"currentDockState\":\"\\\"bottom\\\"\"}" :
+ "{\"currentDockState\":\"\\\"undocked\\\"\"}";
+ DevToolsWindow* window = DevToolsWindow::ToggleDevToolsWindow(
+ inspected_rvh, true, DevToolsToggleAction::Show(), settings);
+ WaitForDevToolsWindowLoad(window);
+ return window;
+}
+
+// static
+DevToolsWindow* DevToolsWindowTesting::OpenDevToolsWindowSync(
+ Browser* browser,
+ bool is_docked) {
+ return OpenDevToolsWindowSync(
+ browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(),
+ is_docked);
+}
+
+// static
+DevToolsWindow* DevToolsWindowTesting::OpenDevToolsWindowForWorkerSync(
+ Profile* profile, content::DevToolsAgentHost* worker_agent) {
+ DevToolsWindow* window = DevToolsWindow::OpenDevToolsWindowForWorker(
+ profile, worker_agent);
+ WaitForDevToolsWindowLoad(window);
+ return window;
+}
+
+// static
+void DevToolsWindowTesting::CloseDevToolsWindow(
+ DevToolsWindow* window) {
+ if (window->is_docked_) {
+ window->CloseWindow();
+ } else {
+ window->browser_->window()->Close();
+ }
+}
+
+// static
+void DevToolsWindowTesting::CloseDevToolsWindowSync(
+ DevToolsWindow* window) {
+ scoped_refptr<content::MessageLoopRunner> runner =
+ new content::MessageLoopRunner;
+ DevToolsWindowTesting::Get(window)->SetCloseCallback(runner->QuitClosure());
+ CloseDevToolsWindow(window);
+ runner->Run();
+}
diff --git a/chrome/browser/devtools/devtools_window_testing.h b/chrome/browser/devtools/devtools_window_testing.h
new file mode 100644
index 0000000..38e5e73
--- /dev/null
+++ b/chrome/browser/devtools/devtools_window_testing.h
@@ -0,0 +1,60 @@
+// 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 CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_TESTING_H_
+#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_TESTING_H_
+
+#include "base/callback.h"
+#include "chrome/browser/devtools/devtools_window.h"
+#include "ui/gfx/rect.h"
+
+class Browser;
+class Profile;
+
+namespace content {
+class DevToolsAgentHost;
+class RenderViewHost;
+class WebContents;
+}
+
+class DevToolsWindowTesting {
+ public:
+ virtual ~DevToolsWindowTesting();
+
+ // The following methods block until DevToolsWindow is completely loaded.
+ static DevToolsWindow* OpenDevToolsWindowSync(
+ content::RenderViewHost* inspected_rvh, bool is_docked);
+ static DevToolsWindow* OpenDevToolsWindowSync(
+ Browser* browser, bool is_docked);
+ static DevToolsWindow* OpenDevToolsWindowForWorkerSync(
+ Profile* profile, content::DevToolsAgentHost* worker_agent);
+
+ // Closes the window like it was user-initiated.
+ static void CloseDevToolsWindow(DevToolsWindow* window);
+ // Blocks until window is closed.
+ static void CloseDevToolsWindowSync(DevToolsWindow* window);
+
+ static DevToolsWindowTesting* Get(DevToolsWindow* window);
+
+ Browser* browser();
+ content::WebContents* main_web_contents();
+ content::WebContents* toolbox_web_contents();
+ void SetInspectedPageBounds(const gfx::Rect& bounds);
+ void SetCloseCallback(const base::Closure& closure);
+
+ private:
+ friend class DevToolsWindow;
+
+ explicit DevToolsWindowTesting(DevToolsWindow* window);
+ static void WaitForDevToolsWindowLoad(DevToolsWindow* window);
+ static void WindowClosed(DevToolsWindow* window);
+ static DevToolsWindowTesting* Find(DevToolsWindow* window);
+
+ DevToolsWindow* devtools_window_;
+ base::Closure close_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(DevToolsWindowTesting);
+};
+
+#endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_WINDOW_TESTING_H_