summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/debugger/devtools_manager.cc12
-rw-r--r--chrome/browser/debugger/devtools_sanity_unittest.cc107
-rw-r--r--chrome/browser/debugger/devtools_view.cc6
-rw-r--r--chrome/browser/debugger/devtools_view.h2
-rw-r--r--chrome/browser/debugger/devtools_window.h2
-rw-r--r--chrome/browser/debugger/devtools_window_win.cc6
-rw-r--r--chrome/browser/debugger/devtools_window_win.h2
-rw-r--r--chrome/test/data/devtools/simple_page.html6
-rw-r--r--chrome/test/unit/unittests.vcproj4
9 files changed, 137 insertions, 10 deletions
diff --git a/chrome/browser/debugger/devtools_manager.cc b/chrome/browser/debugger/devtools_manager.cc
index d1a1da3..94d2868 100644
--- a/chrome/browser/debugger/devtools_manager.cc
+++ b/chrome/browser/debugger/devtools_manager.cc
@@ -7,6 +7,9 @@
#include "chrome/browser/debugger/devtools_window.h"
#include "chrome/browser/debugger/devtools_client_host.h"
#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/tab_contents/navigation_controller.h"
+#include "chrome/browser/tab_contents/navigation_entry.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/devtools_messages.h"
#include "googleurl/src/gurl.h"
@@ -51,7 +54,7 @@ void DevToolsManager::ForwardToDevToolsAgent(
if (!win) {
continue;
}
- if (win->HasRenderViewHost(*client_rvh)) {
+ if (client_rvh == win->GetRenderViewHost()) {
ForwardToDevToolsAgent(win, message);
return;
}
@@ -89,6 +92,13 @@ void DevToolsManager::OpenDevToolsWindow(RenderViewHost* inspected_rvh) {
host = DevToolsWindow::Create();
RegisterDevToolsClientHostFor(inspected_rvh, host);
}
+ TabContents* tab_contents = inspected_rvh->delegate()->GetAsTabContents();
+ if (tab_contents) {
+ NavigationEntry* entry = tab_contents->controller().GetActiveEntry();
+ if (entry) {
+ host->SetInspectedTabUrl(entry->url().possibly_invalid_spec());
+ }
+ }
DevToolsWindow* window = host->AsDevToolsWindow();
if (window)
window->Show();
diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc
new file mode 100644
index 0000000..7bd969e
--- /dev/null
+++ b/chrome/browser/debugger/devtools_sanity_unittest.cc
@@ -0,0 +1,107 @@
+// Copyright (c) 2009 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 "base/command_line.h"
+#include "chrome/browser/automation/ui_controls.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/debugger/devtools_client_host.h"
+#include "chrome/browser/debugger/devtools_manager.h"
+#include "chrome/browser/debugger/devtools_window.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+
+namespace {
+
+// The delay waited in some cases where we don't have a notifications for an
+// action we take.
+const int kActionDelayMs = 500;
+
+const wchar_t kSimplePage[] = L"files/devtools/simple_page.html";
+
+class DevToolsSanityTest : public InProcessBrowserTest {
+ public:
+ DevToolsSanityTest() {
+ set_show_window(true);
+ EnableDOMAutomation();
+ }
+
+ void OpenWebInspector(const std::wstring& page_url) {
+ HTTPTestServer* server = StartHTTPServer();
+ GURL url = server->TestServerPageW(page_url);
+ ui_test_utils::NavigateToURL(browser(), url);
+
+ TabContents* tab = browser()->GetSelectedTabContents();
+ RenderViewHost* inspected_rvh = tab->render_view_host();
+ DevToolsManager* devtools_manager = g_browser_process->devtools_manager();
+ devtools_manager->OpenDevToolsWindow(inspected_rvh);
+
+ DevToolsClientHost* client_host =
+ devtools_manager->GetDevToolsClientHostFor(inspected_rvh);
+ DevToolsWindow* window = client_host->AsDevToolsWindow();
+ RenderViewHost* client_rvh = window->GetRenderViewHost();
+ client_contents_ = client_rvh->delegate()->GetAsTabContents();
+ ui_test_utils::WaitForNavigation(&client_contents_->controller());
+ }
+
+ void AssertTrue(const std::string& expr) {
+ AssertEquals("true", expr);
+ }
+
+ void AssertEquals(const std::string& expected, const std::string& expr) {
+ std::string call = StringPrintf(
+ "try {"
+ " var domAgent = devtools.tools.getDomAgent();"
+ " var netAgent = devtools.tools.getNetAgent();"
+ " var doc = domAgent.getDocument();"
+ " window.domAutomationController.send((%s) + '');"
+ "} catch(e) {"
+ " window.domAutomationController.send(e.toString());"
+ "}", expr.c_str());
+ std::string result;
+ ASSERT_TRUE(
+ ui_test_utils::ExecuteJavaScriptAndExtractString(
+ client_contents_,
+ L"",
+ UTF8ToWide(call),
+ &result));
+ ASSERT_EQ(expected, result);
+ }
+
+ protected:
+ TabContents* client_contents_;
+};
+
+// WebInspector opens.
+IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_OpenWebInspector) {
+ OpenWebInspector(kSimplePage);
+ AssertTrue("typeof DevToolsHost == 'object' && !DevToolsHost.isStub");
+ AssertTrue("!!doc.documentElement");
+}
+
+// Tests elements panel basics.
+IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_ElementsPanel) {
+ OpenWebInspector(kSimplePage);
+ AssertEquals("HTML", "doc.documentElement.nodeName");
+ AssertTrue("doc.documentElement.hasChildNodes()");
+}
+
+// Tests resources panel basics.
+IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_ResourcesPanel) {
+ OpenWebInspector(kSimplePage);
+ std::string func =
+ "function() {"
+ " var tokens = [];"
+ " var resources = netAgent.resources_;"
+ " for (var id in resources) {"
+ " tokens.push(resources[id].lastPathComponent);"
+ " }"
+ " return tokens.join(',');"
+ "}()";
+ AssertEquals("simple_page.html", func);
+}
+
+} // namespace
diff --git a/chrome/browser/debugger/devtools_view.cc b/chrome/browser/debugger/devtools_view.cc
index d391139..46ee9fc 100644
--- a/chrome/browser/debugger/devtools_view.cc
+++ b/chrome/browser/debugger/devtools_view.cc
@@ -112,11 +112,11 @@ void DevToolsView::SendMessageToClient(const IPC::Message& message) {
}
}
-bool DevToolsView::HasRenderViewHost(const RenderViewHost& rvh) const {
+RenderViewHost* DevToolsView::GetRenderViewHost() const {
if (tab_contents_) {
- return (&rvh == tab_contents_->render_view_host());
+ return tab_contents_->render_view_host();
}
- return false;
+ return NULL;
}
void DevToolsView::OpenURLFromTab(TabContents* source,
diff --git a/chrome/browser/debugger/devtools_view.h b/chrome/browser/debugger/devtools_view.h
index 5fe90e3..3762f2e 100644
--- a/chrome/browser/debugger/devtools_view.h
+++ b/chrome/browser/debugger/devtools_view.h
@@ -29,7 +29,7 @@ class DevToolsView : public views::View,
// Destroy content views when the window is closing.
void OnWindowClosing();
void SendMessageToClient(const IPC::Message& message);
- bool HasRenderViewHost(const RenderViewHost& rvh) const;
+ RenderViewHost* GetRenderViewHost() const;
private:
// Overridden from TabContentsDelegate:
diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h
index da13ae2..3a911f4 100644
--- a/chrome/browser/debugger/devtools_window.h
+++ b/chrome/browser/debugger/devtools_window.h
@@ -19,7 +19,7 @@ class DevToolsWindow : public DevToolsClientHost {
// Show this window.
virtual void Show() = 0;
- virtual bool HasRenderViewHost(const RenderViewHost& rvh) const = 0;
+ virtual RenderViewHost* GetRenderViewHost() const = 0;
// DevToolsClientHost override.
virtual DevToolsWindow* AsDevToolsWindow() { return this; }
diff --git a/chrome/browser/debugger/devtools_window_win.cc b/chrome/browser/debugger/devtools_window_win.cc
index 463f1cfe..9e4cbfe 100644
--- a/chrome/browser/debugger/devtools_window_win.cc
+++ b/chrome/browser/debugger/devtools_window_win.cc
@@ -36,11 +36,11 @@ void DevToolsWindowWin::Show() {
}
}
-bool DevToolsWindowWin::HasRenderViewHost(const RenderViewHost& rvh) const {
+RenderViewHost* DevToolsWindowWin::GetRenderViewHost() const {
if (tools_view_) {
- return tools_view_->HasRenderViewHost(rvh);
+ return tools_view_->GetRenderViewHost();
}
- return false;
+ return NULL;
}
void DevToolsWindowWin::InspectedTabClosing() {
diff --git a/chrome/browser/debugger/devtools_window_win.h b/chrome/browser/debugger/devtools_window_win.h
index 03889a4..a208224 100644
--- a/chrome/browser/debugger/devtools_window_win.h
+++ b/chrome/browser/debugger/devtools_window_win.h
@@ -22,7 +22,7 @@ class DevToolsWindowWin : public DevToolsWindow,
// DevToolsWindow implementation.
virtual void Show();
- virtual bool HasRenderViewHost(const RenderViewHost& rvh) const;
+ virtual RenderViewHost* GetRenderViewHost() const;
virtual void InspectedTabClosing();
virtual void SetInspectedTabUrl(const std::string& url);
diff --git a/chrome/test/data/devtools/simple_page.html b/chrome/test/data/devtools/simple_page.html
new file mode 100644
index 0000000..f8b6c17
--- /dev/null
+++ b/chrome/test/data/devtools/simple_page.html
@@ -0,0 +1,6 @@
+<html>
+ <head>
+ </head>
+ <body>
+ </body>
+</html>
diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj
index 08943c8..f36c673 100644
--- a/chrome/test/unit/unittests.vcproj
+++ b/chrome/test/unit/unittests.vcproj
@@ -480,6 +480,10 @@
>
</File>
<File
+ RelativePath="..\..\browser\debugger\devtools_sanity_unittest.cc"
+ >
+ </File>
+ <File
RelativePath="..\..\browser\net\dns_host_info_unittest.cc"
>
</File>