Chromium Code Reviews| Index: chrome/browser/debugger/devtools_extension_debug_unittest.cc |
| diff --git a/chrome/browser/debugger/devtools_extension_debug_unittest.cc b/chrome/browser/debugger/devtools_extension_debug_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a9a393efe7590eb0141421a5a8e8b1f6eeb977ef |
| --- /dev/null |
| +++ b/chrome/browser/debugger/devtools_extension_debug_unittest.cc |
| @@ -0,0 +1,112 @@ |
| +// Copyright (c) 2011 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/path_service.h" |
| +#include "chrome/browser/extensions/extension_host.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "chrome/test/ui_test_utils.h" |
| +#include "content/browser/debugger/devtools_sanity_unittest.h" |
| +#include "content/common/notification_service.h" |
| + |
| +namespace { |
| + |
| +const char kPageWithContentScript[] = |
| + "files/devtools/page_with_content_script.html"; |
| + |
| +// 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) { |
| + ExtensionService* service = browser()->profile()->GetExtensionService(); |
| + size_t num_before = service->extensions()->size(); |
| + { |
| + NotificationRegistrar registrar; |
| + registrar.Add(this, NotificationType::EXTENSION_LOADED, |
| + NotificationService::AllSources()); |
| + CancelableQuitTask* delayed_quit = |
| + new CancelableQuitTask("Extension load timed out."); |
| + MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, |
| + 4*1000); |
|
brettw
2011/07/06 16:15:39
What's this magic number? Can you have a named con
Jói
2011/07/06 16:38:57
Changed to:
MessageLoop::current()->PostDel
|
| + service->LoadExtension(path); |
| + ui_test_utils::RunMessageLoop(); |
| + delayed_quit->cancel(); |
| + } |
| + size_t num_after = service->extensions()->size(); |
| + 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); |
|
brettw
2011/07/06 16:15:39
Ditto
Jói
2011/07/06 16:38:57
Done.
|
| + |
| + 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, |
| + const NotificationSource& source, |
| + const NotificationDetails& details) { |
| + switch (type.value) { |
| + case NotificationType::EXTENSION_LOADED: |
| + case NotificationType::EXTENSION_HOST_DID_STOP_LOADING: |
| + MessageLoopForUI::current()->Quit(); |
| + break; |
| + default: |
| + NOTREACHED(); |
| + break; |
| + } |
| + } |
| + |
| + FilePath test_extensions_dir_; |
| +}; |
| + |
| +// Tests that a content script is in the scripts list. |
| +// This test is disabled, see bug 28961. |
| +IN_PROC_BROWSER_TEST_F(DevToolsExtensionDebugTest, |
| + TestContentScriptIsPresent) { |
| + LoadExtension("simple_content_script"); |
| + RunTest("testContentScriptIsPresent", kPageWithContentScript); |
| +} |
| + |
| +} // namespace |