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

Unified Diff: extensions/test/result_catcher.h

Issue 529293003: Extract ResultCatcher from ExtensionApiTest. Use it in ShellApiTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: deprecate Created 6 years, 3 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
« no previous file with comments | « extensions/test/data/api_test/dns/api/manifest.json ('k') | extensions/test/result_catcher.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/test/result_catcher.h
diff --git a/extensions/test/result_catcher.h b/extensions/test/result_catcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..43ebc27cc03b224b1541d5be4ca48729c82c9ffd
--- /dev/null
+++ b/extensions/test/result_catcher.h
@@ -0,0 +1,67 @@
+// Copyright 2014 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.
+
+#ifndef EXTENSIONS_TEST_RESULT_CATCHER_H_
+#define EXTENSIONS_TEST_RESULT_CATCHER_H_
+
+#include <deque>
+#include <string>
+
+#include "base/compiler_specific.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+
+namespace content {
+class BrowserContext;
+} // namespace content
+
+namespace extensions {
+
+// Helper class that observes tests failing or passing. Observation starts
+// when the class is constructed. Get the next result by calling
+// GetNextResult() and message() if GetNextResult() return false. If there
+// are no results, this method will pump the UI message loop until one is
+// received.
+// TODO(yoz): Replace the version in ExtensionApiTest with this.
+class ResultCatcher : public content::NotificationObserver {
+ public:
+ ResultCatcher();
+ virtual ~ResultCatcher();
+
+ // Pumps the UI loop until a notification is received that an API test
+ // succeeded or failed. Returns true if the test succeeded, false otherwise.
+ bool GetNextResult();
+
+ void RestrictToBrowserContext(content::BrowserContext* context) {
+ browser_context_restriction_ = context;
+ }
+
+ const std::string& message() { return message_; }
+
+ private:
+ // content::NotificationObserver:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ content::NotificationRegistrar registrar_;
+
+ // A sequential list of pass/fail notifications from the test extension(s).
+ std::deque<bool> results_;
+
+ // If it failed, what was the error message?
+ std::deque<std::string> messages_;
+ std::string message_;
+
+ // If non-NULL, we will listen to events from this BrowserContext only.
+ content::BrowserContext* browser_context_restriction_;
+
+ // True if we're in a nested message loop waiting for results from
+ // the extension.
+ bool waiting_;
+};
+
+} // namespace extensions
+
+#endif // EXTENSIONS_TEST_RESULT_CATCHER_H_
« no previous file with comments | « extensions/test/data/api_test/dns/api/manifest.json ('k') | extensions/test/result_catcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698