summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 15:31:30 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 15:31:30 +0000
commit1b91f510fdda3d6e764e0476df5a82c64ae2975e (patch)
tree33b5121a765629445cfb312e76a859f7d0c9f2c5 /chrome/browser
parentb045a67113c1d3c511aed76d618732d6a251919a (diff)
downloadchromium_src-1b91f510fdda3d6e764e0476df5a82c64ae2975e.zip
chromium_src-1b91f510fdda3d6e764e0476df5a82c64ae2975e.tar.gz
chromium_src-1b91f510fdda3d6e764e0476df5a82c64ae2975e.tar.bz2
DevTools: restore sanity test suite.
BUG=11533 Review URL: http://codereview.chromium.org/119355 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17941 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/debugger/devtools_sanity_unittest.cc62
-rw-r--r--chrome/browser/debugger/devtools_window.cc49
-rw-r--r--chrome/browser/debugger/devtools_window.h5
3 files changed, 75 insertions, 41 deletions
diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc
index 60e31ad..fd78e3f 100644
--- a/chrome/browser/debugger/devtools_sanity_unittest.cc
+++ b/chrome/browser/debugger/devtools_sanity_unittest.cc
@@ -11,11 +11,33 @@
#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/common/notification_registrar.h"
+#include "chrome/common/notification_service.h"
#include "chrome/test/in_process_browser_test.h"
#include "chrome/test/ui_test_utils.h"
namespace {
+// Used to block until a dev tools client window's browser is closed.
+class BrowserClosedObserver : public NotificationObserver {
+ public:
+ BrowserClosedObserver(Browser* browser) {
+ registrar_.Add(this, NotificationType::BROWSER_CLOSED,
+ Source<Browser>(browser));
+ ui_test_utils::RunMessageLoop();
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ MessageLoopForUI::current()->Quit();
+ }
+
+ private:
+ NotificationRegistrar registrar_;
+ DISALLOW_COPY_AND_ASSIGN(BrowserClosedObserver);
+};
+
// The delay waited in some cases where we don't have a notifications for an
// action we take.
const int kActionDelayMs = 500;
@@ -29,24 +51,30 @@ class DevToolsSanityTest : public InProcessBrowserTest {
EnableDOMAutomation();
}
- void OpenWebInspector(const std::wstring& page_url) {
+ void OpenDevToolsWindow() {
HTTPTestServer* server = StartHTTPServer();
- GURL url = server->TestServerPageW(page_url);
+ GURL url = server->TestServerPageW(kSimplePage);
ui_test_utils::NavigateToURL(browser(), url);
- TabContents* tab = browser()->GetSelectedTabContents();
- RenderViewHost* inspected_rvh = tab->render_view_host();
+ TabContents* tab = browser()->GetTabContentsAt(0);
+ inspected_rvh_ = tab->render_view_host();
DevToolsManager* devtools_manager = g_browser_process->devtools_manager();
- devtools_manager->OpenDevToolsWindow(inspected_rvh);
+ devtools_manager->OpenDevToolsWindow(inspected_rvh_);
DevToolsClientHost* client_host =
- devtools_manager->GetDevToolsClientHostFor(inspected_rvh);
- DevToolsWindow* window = client_host->AsDevToolsWindow();
- RenderViewHost* client_rvh = window->GetRenderViewHost();
+ devtools_manager->GetDevToolsClientHostFor(inspected_rvh_);
+ window_ = client_host->AsDevToolsWindow();
+ RenderViewHost* client_rvh = window_->GetRenderViewHost();
client_contents_ = client_rvh->delegate()->GetAsTabContents();
ui_test_utils::WaitForNavigation(&client_contents_->controller());
}
+ void CloseDevToolsWindow() {
+ DevToolsManager* devtools_manager = g_browser_process->devtools_manager();
+ devtools_manager->UnregisterDevToolsClientHostFor(inspected_rvh_);
+ BrowserClosedObserver close_observer(window_->browser());
+ }
+
void AssertTrue(const std::string& expr) {
AssertEquals("true", expr);
}
@@ -55,7 +83,6 @@ class DevToolsSanityTest : public InProcessBrowserTest {
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) {"
@@ -73,35 +100,40 @@ class DevToolsSanityTest : public InProcessBrowserTest {
protected:
TabContents* client_contents_;
+ DevToolsWindow* window_;
+ RenderViewHost* inspected_rvh_;
};
// WebInspector opens.
-IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_OpenWebInspector) {
- OpenWebInspector(kSimplePage);
+IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, OpenWebInspector) {
+ OpenDevToolsWindow();
AssertTrue("typeof DevToolsHost == 'object' && !DevToolsHost.isStub");
AssertTrue("!!doc.documentElement");
+ CloseDevToolsWindow();
}
// Tests elements panel basics.
-IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_ElementsPanel) {
- OpenWebInspector(kSimplePage);
+IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, ElementsPanel) {
+ OpenDevToolsWindow();
AssertEquals("HTML", "doc.documentElement.nodeName");
AssertTrue("doc.documentElement.hasChildNodes()");
+ CloseDevToolsWindow();
}
// Tests resources panel basics.
IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, DISABLED_ResourcesPanel) {
- OpenWebInspector(kSimplePage);
+ OpenDevToolsWindow();
std::string func =
"function() {"
" var tokens = [];"
" var resources = WebInspector.resources;"
" for (var id in resources) {"
- " tokens.push(resources[id].lastPathComponent);"
+ " tokens.push(resources[id]);"
" }"
" return tokens.join(',');"
"}()";
AssertEquals("simple_page.html", func);
+ CloseDevToolsWindow();
}
} // namespace
diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc
index 572e493..5dfa557 100644
--- a/chrome/browser/debugger/devtools_window.cc
+++ b/chrome/browser/debugger/devtools_window.cc
@@ -24,30 +24,30 @@
DevToolsWindow::DevToolsWindow(Profile* profile)
: TabStripModelObserver(),
inspected_tab_closing_(false) {
- static std::wstring g_wp_key = L"";
- if (g_wp_key.empty()) {
- // TODO(pfeldman): Make browser's getter for this key static.
- g_wp_key.append(prefs::kBrowserWindowPlacement);
- g_wp_key.append(L"_");
- g_wp_key.append(L"DevToolsApp");
- PrefService* prefs = g_browser_process->local_state();
- prefs->RegisterDictionaryPref(g_wp_key.c_str());
+ // TODO(pfeldman): Make browser's getter for this key static.
+ std::wstring wp_key = L"";
+ wp_key.append(prefs::kBrowserWindowPlacement);
+ wp_key.append(L"_");
+ wp_key.append(L"DevToolsApp");
- const DictionaryValue* wp_pref = prefs->GetDictionary(g_wp_key.c_str());
- if (!wp_pref) {
- DictionaryValue* defaults = prefs->GetMutableDictionary(
- g_wp_key.c_str());
- defaults->SetInteger(L"left", 100);
- defaults->SetInteger(L"top", 100);
- defaults->SetInteger(L"right", 740);
- defaults->SetInteger(L"bottom", 740);
- defaults->SetBoolean(L"maximized", false);
- defaults->SetBoolean(L"always_on_top", false);
- }
+ PrefService* prefs = g_browser_process->local_state();
+ if (!prefs->FindPreference(wp_key.c_str())) {
+ prefs->RegisterDictionaryPref(wp_key.c_str());
}
- browser_.reset(Browser::CreateForApp(L"DevToolsApp", profile, false));
+ const DictionaryValue* wp_pref = prefs->GetDictionary(wp_key.c_str());
+ if (!wp_pref) {
+ DictionaryValue* defaults = prefs->GetMutableDictionary(wp_key.c_str());
+ defaults->SetInteger(L"left", 100);
+ defaults->SetInteger(L"top", 100);
+ defaults->SetInteger(L"right", 740);
+ defaults->SetInteger(L"bottom", 740);
+ defaults->SetBoolean(L"maximized", false);
+ defaults->SetBoolean(L"always_on_top", false);
+ }
+
+ browser_ = Browser::CreateForApp(L"DevToolsApp", profile, false);
GURL contents(std::string(chrome::kChromeUIDevToolsURL) + "devtools.html");
browser_->AddTabWithURL(contents, GURL(), PageTransition::START_PAGE, true,
-1, false, NULL);
@@ -93,9 +93,8 @@ void DevToolsWindow::TabClosingAt(TabContents* contents, int index) {
// Notify manager that this DevToolsClientHost no longer exists.
NotifyCloseListener();
}
- if (browser_->tabstrip_model()->empty()) {
- // We are removing the last tab. Delete browser along with the
- // tabstrip_model and its listeners.
- delete this;
- }
+}
+
+void DevToolsWindow::TabStripEmpty() {
+ delete this;
}
diff --git a/chrome/browser/debugger/devtools_window.h b/chrome/browser/debugger/devtools_window.h
index 99d4e36..db6c246 100644
--- a/chrome/browser/debugger/devtools_window.h
+++ b/chrome/browser/debugger/devtools_window.h
@@ -40,9 +40,12 @@ class DevToolsWindow : public DevToolsClientHost,
// TabStripModelObserver implementation
virtual void TabClosingAt(TabContents* contents, int index);
+ virtual void TabStripEmpty();
+
+ Browser* browser() { return browser_; }
private:
- scoped_ptr<Browser> browser_;
+ Browser* browser_;
TabContents* tab_contents_;
std::string inspected_url_;
bool inspected_tab_closing_;