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 #include "extensions/test/result_catcher.h"
7 #include "content/public/browser/notification_service.h"
8 #include "content/public/test/test_utils.h"
9 #include "extensions/browser/notification_types.h"
11 namespace extensions
{
13 ResultCatcher::ResultCatcher()
14 : browser_context_restriction_(NULL
), waiting_(false) {
16 extensions::NOTIFICATION_EXTENSION_TEST_PASSED
,
17 content::NotificationService::AllSources());
19 extensions::NOTIFICATION_EXTENSION_TEST_FAILED
,
20 content::NotificationService::AllSources());
23 ResultCatcher::~ResultCatcher() {
26 bool ResultCatcher::GetNextResult() {
27 // Depending on the tests, multiple results can come in from a single call
28 // to RunMessageLoop(), so we maintain a queue of results and just pull them
29 // off as the test calls this, going to the run loop only when the queue is
31 if (results_
.empty()) {
33 content::RunMessageLoop();
37 if (!results_
.empty()) {
38 bool ret
= results_
.front();
40 message_
= messages_
.front();
41 messages_
.pop_front();
49 void ResultCatcher::Observe(int type
,
50 const content::NotificationSource
& source
,
51 const content::NotificationDetails
& details
) {
52 if (browser_context_restriction_
&&
53 content::Source
<content::BrowserContext
>(source
).ptr() !=
54 browser_context_restriction_
) {
59 case extensions::NOTIFICATION_EXTENSION_TEST_PASSED
:
60 VLOG(1) << "Got EXTENSION_TEST_PASSED notification.";
61 results_
.push_back(true);
62 messages_
.push_back(std::string());
64 base::MessageLoopForUI::current()->Quit();
67 case extensions::NOTIFICATION_EXTENSION_TEST_FAILED
:
68 VLOG(1) << "Got EXTENSION_TEST_FAILED notification.";
69 results_
.push_back(false);
70 messages_
.push_back(*(content::Details
<std::string
>(details
).ptr()));
72 base::MessageLoopForUI::current()->Quit();
80 } // namespace extensions