diff options
author | yurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-27 10:46:22 +0000 |
---|---|---|
committer | yurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-27 10:46:22 +0000 |
commit | 680bc22edef68385990c180f1cb7bd9e5a44de93 (patch) | |
tree | edca64d0bdcaa8996dd084995d5116840fd58c5d | |
parent | 9978ea8613e2571b37714bd3cf08e0313fb117a6 (diff) | |
download | chromium_src-680bc22edef68385990c180f1cb7bd9e5a44de93.zip chromium_src-680bc22edef68385990c180f1cb7bd9e5a44de93.tar.gz chromium_src-680bc22edef68385990c180f1cb7bd9e5a44de93.tar.bz2 |
DevTools: fix and enable DevToolsExtensionDebugTest.TestContentScriptIsPresent.
Review URL: http://codereview.chromium.org/328029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30179 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/debugger/devtools_sanity_unittest.cc | 69 | ||||
-rw-r--r-- | chrome/test/data/devtools/page_with_content_script.html | 13 | ||||
-rw-r--r-- | chrome/test/ui_test_utils.cc | 2 |
3 files changed, 77 insertions, 7 deletions
diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc index c21866a..a3fb609 100644 --- a/chrome/browser/debugger/devtools_sanity_unittest.cc +++ b/chrome/browser/debugger/devtools_sanity_unittest.cc @@ -136,6 +136,31 @@ class DevToolsSanityTest : public InProcessBrowserTest { }; +class CancelableQuitTask : public Task { + public: + CancelableQuitTask(const std::string& timeout_message) + : timeout_message_(timeout_message), + cancelled_(false) { + } + + void cancel() { + cancelled_ = true; + } + + virtual void Run() { + if (cancelled_) { + return; + } + FAIL() << timeout_message_; + MessageLoop::current()->Quit(); + } + + private: + std::string timeout_message_; + bool cancelled_; +}; + + // Base class for DevTools tests that test devtools functionality for // extensions and content scripts. class DevToolsExtensionDebugTest : public DevToolsSanityTest, @@ -162,13 +187,46 @@ class DevToolsExtensionDebugTest : public DevToolsSanityTest, NotificationRegistrar registrar; registrar.Add(this, NotificationType::EXTENSION_LOADED, NotificationService::AllSources()); - MessageLoop::current()->PostDelayedTask( - FROM_HERE, new MessageLoop::QuitTask, 5*1000); + CancelableQuitTask* delayed_quit = + new CancelableQuitTask("Extension load timed out."); + MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, + 4*1000); service->LoadExtension(path); ui_test_utils::RunMessageLoop(); + delayed_quit->cancel(); } size_t num_after = service->extensions()->size(); - return (num_after == (num_before + 1)); + if (num_after != (num_before + 1)) + return false; + + return WaitForExtensionHostsToLoad(); + } + + bool WaitForExtensionHostsToLoad() { + // Wait for all the extension hosts that exist to finish loading. + // NOTE: This assumes that the extension host list is not changing while + // this method is running. + + NotificationRegistrar registrar; + registrar.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, + NotificationService::AllSources()); + CancelableQuitTask* delayed_quit = + new CancelableQuitTask("Extension host load timed out."); + MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, + 4*1000); + + ExtensionProcessManager* manager = + browser()->profile()->GetExtensionProcessManager(); + for (ExtensionProcessManager::const_iterator iter = manager->begin(); + iter != manager->end();) { + if ((*iter)->did_stop_loading()) + ++iter; + else + ui_test_utils::RunMessageLoop(); + } + + delayed_quit->cancel(); + return true; } void Observe(NotificationType type, @@ -176,10 +234,9 @@ class DevToolsExtensionDebugTest : public DevToolsSanityTest, const NotificationDetails& details) { switch (type.value) { case NotificationType::EXTENSION_LOADED: - std::cout << "Got EXTENSION_LOADED notification.\n"; + case NotificationType::EXTENSION_HOST_DID_STOP_LOADING: MessageLoopForUI::current()->Quit(); break; - default: NOTREACHED(); break; @@ -227,7 +284,7 @@ IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestShowScriptsTab) { // Tests that a content script is in the scripts list. IN_PROC_BROWSER_TEST_F(DevToolsExtensionDebugTest, - DISABLED_TestContentScriptIsPresent) { + TestContentScriptIsPresent) { LoadExtension("simple_content_script"); RunTest("testContentScriptIsPresent", kPageWithContentScript); } diff --git a/chrome/test/data/devtools/page_with_content_script.html b/chrome/test/data/devtools/page_with_content_script.html new file mode 100644 index 0000000..d38591e --- /dev/null +++ b/chrome/test/data/devtools/page_with_content_script.html @@ -0,0 +1,13 @@ +<html> +<head> +<script> + + +function handleClick() { +} +</script> +</head> +<body> +<input id='btn' type='button' onclick='handleClick()' value='Test'/> +</body> +</html>
\ No newline at end of file diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc index 4a0ef2a..c9348b3 100644 --- a/chrome/test/ui_test_utils.cc +++ b/chrome/test/ui_test_utils.cc @@ -83,7 +83,7 @@ class DOMOperationObserver : public NotificationObserver { explicit DOMOperationObserver(RenderViewHost* render_view_host) { registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE, Source<RenderViewHost>(render_view_host)); - RunMessageLoop(); + ui_test_utils::RunMessageLoop(); } virtual void Observe(NotificationType type, |