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

Unified Diff: chrome/browser/extensions/extension_apitest.cc

Issue 171032: end-to-end extension API tests (Closed)
Patch Set: a bit of refactoring and review feedback Created 11 years, 4 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/extensions/extension_apitest.cc
diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3c455240f8e3ebfecee80a78f80c367bb99b876e
--- /dev/null
+++ b/chrome/browser/extensions/extension_apitest.cc
@@ -0,0 +1,74 @@
+// Copyright (c) 2009 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 "chrome/browser/extensions/extension_apitest.h"
+
+#include "chrome/browser/browser.h"
+#include "chrome/common/notification_registrar.h"
+#include "chrome/test/ui_test_utils.h"
+
+namespace {
+static const int kTimeoutMs = 60 * 1000; // 1 minute
+};
+
+// Load an extension and wait for it to notify of PASSED or FAILED.
+bool ExtensionApiTest::RunExtensionTest(const char* extension_name) {
+ bool result;
+ completed_ = false;
+ {
+ NotificationRegistrar registrar;
+ registrar.Add(this, NotificationType::EXTENSION_TEST_PASSED,
+ NotificationService::AllSources());
+ registrar.Add(this, NotificationType::EXTENSION_TEST_FAILED,
+ NotificationService::AllSources());
+ result = LoadExtension(test_data_dir_.AppendASCII(extension_name));
+
+ // If the test runs quickly, we may get the notification while waiting
+ // for the Load to finish.
+ if (completed_) {
+ result = passed_;
+ } else {
+ result = WaitForPassFail();
+ }
+ }
+ return result;
+}
+
+bool ExtensionApiTest::WaitForPassFail() {
+ completed_ = false;
+ passed_ = false;
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, new MessageLoop::QuitTask, kTimeoutMs);
+ ui_test_utils::RunMessageLoop();
+ return passed_;
+}
+
+void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) {
+ ExtensionBrowserTest::SetUpCommandLine(command_line);
+ test_data_dir_ = test_data_dir_.AppendASCII("api_test");
+}
+
+void ExtensionApiTest::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type.value) {
+ case NotificationType::EXTENSION_TEST_PASSED:
+ std::cout << "Got EXTENSION_TEST_PASSED notification.\n";
+ completed_ = true;
+ passed_ = true;
+ MessageLoopForUI::current()->Quit();
+ break;
+
+ case NotificationType::EXTENSION_TEST_FAILED:
+ std::cout << "Got EXTENSION_TEST_FAILED notification.\n";
+ completed_ = true;
+ passed_ = false;
+ message_ = *(Details<std::string>(details).ptr());
+ MessageLoopForUI::current()->Quit();
+ break;
+
+ default:
+ ExtensionBrowserTest::Observe(type, source, details);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698