DevTools: kill codeschool extension from whitelist
[chromium-blink-merge.git] / extensions / test / result_catcher.h
blob71d0fdfa93255a340776129c5a1c9b7aed0782b8
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_TEST_RESULT_CATCHER_H_
6 #define EXTENSIONS_TEST_RESULT_CATCHER_H_
8 #include <deque>
9 #include <string>
11 #include "base/compiler_specific.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
15 namespace content {
16 class BrowserContext;
17 } // namespace content
19 namespace extensions {
21 // Helper class that observes tests failing or passing. Observation starts
22 // when the class is constructed. Get the next result by calling
23 // GetNextResult() and message() if GetNextResult() return false. If there
24 // are no results, this method will pump the UI message loop until one is
25 // received.
26 class ResultCatcher : public content::NotificationObserver {
27 public:
28 ResultCatcher();
29 ~ResultCatcher() override;
31 // Pumps the UI loop until a notification is received that an API test
32 // succeeded or failed. Returns true if the test succeeded, false otherwise.
33 bool GetNextResult();
35 void RestrictToBrowserContext(content::BrowserContext* context) {
36 browser_context_restriction_ = context;
39 const std::string& message() { return message_; }
41 private:
42 // content::NotificationObserver:
43 void Observe(int type,
44 const content::NotificationSource& source,
45 const content::NotificationDetails& details) override;
47 content::NotificationRegistrar registrar_;
49 // A sequential list of pass/fail notifications from the test extension(s).
50 std::deque<bool> results_;
52 // If it failed, what was the error message?
53 std::deque<std::string> messages_;
54 std::string message_;
56 // If non-NULL, we will listen to events from this BrowserContext only.
57 content::BrowserContext* browser_context_restriction_;
59 // True if we're in a nested message loop waiting for results from
60 // the extension.
61 bool waiting_;
64 } // namespace extensions
66 #endif // EXTENSIONS_TEST_RESULT_CATCHER_H_