Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1193)

Unified Diff: chrome/browser/debugger/devtools_extension_debug_unittest.cc

Issue 7309011: Remove dependencies on extensions from content/browser/debugger. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..1e6d47b657cf7f76a7b093a329e8e6fbe71c12d4
--- /dev/null
+++ b/chrome/browser/debugger/devtools_extension_debug_unittest.cc
@@ -0,0 +1,137 @@
+// 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 "base/test/test_timeouts.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 {
+
+class CancelableQuitTask : public Task {
+ public:
+ explicit 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_;
+};
+
+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, 2 * TestTimeouts::action_timeout_ms());
+ 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, 2 * TestTimeouts::action_timeout_ms());
+
+ 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
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/debugger/extension_ports_remote_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698