diff options
4 files changed, 125 insertions, 8 deletions
diff --git a/chrome/browser/debugger/devtools_sanity_unittest.cc b/chrome/browser/debugger/devtools_sanity_unittest.cc index c257da2..726d192 100644 --- a/chrome/browser/debugger/devtools_sanity_unittest.cc +++ b/chrome/browser/debugger/devtools_sanity_unittest.cc @@ -7,8 +7,11 @@ #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/extensions/extensions_service.h" +#include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" @@ -58,6 +61,8 @@ const wchar_t kDebuggerIntrinsicPropertiesPage[] = L"files/devtools/debugger_intrinsic_properties.html"; const wchar_t kCompletionOnPause[] = L"files/devtools/completion_on_pause.html"; +const wchar_t kPageWithContentScript[] = + L"files/devtools/page_with_content_script.html"; class DevToolsSanityTest : public InProcessBrowserTest { @@ -130,6 +135,61 @@ class DevToolsSanityTest : public InProcessBrowserTest { RenderViewHost* inspected_rvh_; }; + +// Base class for DevTools tests that test devtools functionality for +// extensions and content scripts. +class DevToolsExtensionDebugTest : public DevToolsSanityTest, + public NotificationObserver { + public: + DevToolsExtensionDebugTest() : DevToolsSanityTest() { + PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_); + test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools"); + test_extensions_dir_ = test_extensions_dir_.AppendASCII("extensions"); + } + + protected: + // Load an extention from test\data\devtools\extensions\<extension_name> + void LoadExtension(const char* extension_name) { + FilePath path = test_extensions_dir_.AppendASCII(extension_name); + ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension."; + } + + private: + bool LoadExtensionFromPath(const FilePath& path) { + ExtensionsService* service = browser()->profile()->GetExtensionsService(); + size_t num_before = service->extensions()->size(); + { + NotificationRegistrar registrar; + registrar.Add(this, NotificationType::EXTENSION_LOADED, + NotificationService::AllSources()); + MessageLoop::current()->PostDelayedTask( + FROM_HERE, new MessageLoop::QuitTask, 5*1000); + service->LoadExtension(path); + ui_test_utils::RunMessageLoop(); + } + size_t num_after = service->extensions()->size(); + return (num_after == (num_before + 1)); + } + + void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type.value) { + case NotificationType::EXTENSION_LOADED: + std::cout << "Got EXTENSION_LOADED notification.\n"; + MessageLoopForUI::current()->Quit(); + break; + + default: + NOTREACHED(); + break; + } + } + + FilePath test_extensions_dir_; +}; + + // WebInspector opens. IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestHostIsPresent) { RunTest("testHostIsPresent", kSimplePage); @@ -165,6 +225,13 @@ IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestShowScriptsTab) { RunTest("testShowScriptsTab", kDebuggerTestPage); } +// Tests that a content script is in the scripts list. +IN_PROC_BROWSER_TEST_F(DevToolsExtensionDebugTest, + TestContentScriptIsPresent) { + LoadExtension("simple_content_script"); + RunTest("testContentScriptIsPresent", kPageWithContentScript); +} + // Tests that scripts are not duplicated after Scripts Panel switch. IN_PROC_BROWSER_TEST_F(DevToolsSanityTest, TestNoScriptDuplicatesOnPanelSwitch) { diff --git a/chrome/test/data/devtools/extensions/simple_content_script/manifest.json b/chrome/test/data/devtools/extensions/simple_content_script/manifest.json new file mode 100644 index 0000000..2904385 --- /dev/null +++ b/chrome/test/data/devtools/extensions/simple_content_script/manifest.json @@ -0,0 +1,10 @@ +{ + "content_scripts": [ { + "js": [ "simple_content_script.js" ], + "matches": [ "http://*/*" ] + } ], + "description": "Simple content script.", + "name": "Simple content script", + "version": "0.1" + +} diff --git a/chrome/test/data/devtools/extensions/simple_content_script/simple_content_script.js b/chrome/test/data/devtools/extensions/simple_content_script/simple_content_script.js new file mode 100644 index 0000000..e8e1adf --- /dev/null +++ b/chrome/test/data/devtools/extensions/simple_content_script/simple_content_script.js @@ -0,0 +1,10 @@ +function buttonClickListener(e) { + var localVar = e + 'a'; + debugger; +} + + +var button = document.getElementById('btn'); +if (button) { + button.addEventListener('click', buttonClickListener, false); +} diff --git a/webkit/glue/devtools/js/tests.js b/webkit/glue/devtools/js/tests.js index 4253078..5c44afb 100644 --- a/webkit/glue/devtools/js/tests.js +++ b/webkit/glue/devtools/js/tests.js @@ -394,6 +394,24 @@ TestSuite.prototype.testShowScriptsTab = function() { /** + * Tests that scripts list contains content scripts. + */ +TestSuite.prototype.testContentScriptIsPresent = function() { + this.showPanel('scripts'); + var test = this; + + test._waitUntilScriptsAreParsed( + ['page_with_content_script.html$', 'simple_content_script.js$'], + function() { + test.releaseControl(); + }); + + // Wait until all scripts are added to the debugger. + this.takeControl(); +}; + + +/** * Tests that scripts are not duplicaed on Scripts tab switch. */ TestSuite.prototype.testNoScriptDuplicatesOnPanelSwitch = function() { @@ -920,14 +938,6 @@ TestSuite.prototype._executeCodeWhenScriptsAreParsed = function( code, expectedScripts) { var test = this; - function waitForAllScripts() { - if (test._scriptsAreParsed(expectedScripts)) { - executeFunctionInInspectedPage(); - } else { - test.addSniffer(WebInspector, 'parsedScriptSource', waitForAllScripts); - } - } - function executeFunctionInInspectedPage() { // Since breakpoints are ignored in evals' calculate() function is // execute after zero-timeout so that the breakpoint is hit. @@ -939,6 +949,26 @@ TestSuite.prototype._executeCodeWhenScriptsAreParsed = function( }); } + test._waitUntilScriptsAreParsed( + expectedScripts, executeFunctionInInspectedPage); +}; + + +/** + * Waits until all the scripts are parsed and invokes the callback. + */ +TestSuite.prototype._waitUntilScriptsAreParsed = function( + expectedScripts, callback) { + var test = this; + + function waitForAllScripts() { + if (test._scriptsAreParsed(expectedScripts)) { + callback(); + } else { + test.addSniffer(WebInspector, 'parsedScriptSource', waitForAllScripts); + } + } + waitForAllScripts(); }; |