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

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

Issue 174277: override chrome:// URLs via extensions. (Closed)
Patch Set: fix linux errors 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
« no previous file with comments | « chrome/browser/extensions/extension_apitest.h ('k') | chrome/browser/extensions/extension_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_apitest.cc
diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc
index 3c455240f8e3ebfecee80a78f80c367bb99b876e..415d1c9e6b48d5b713f1385f3134f3612cdbe27d 100644
--- a/chrome/browser/extensions/extension_apitest.cc
+++ b/chrome/browser/extensions/extension_apitest.cc
@@ -14,34 +14,48 @@ 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();
+ if (!LoadExtension(test_data_dir_.AppendASCII(extension_name))) {
+ message_ = "Failed to load extension.";
+ return false;
}
}
- return result;
+
+ // TODO(erikkay) perhaps we shouldn't do this implicitly.
+ return WaitForPassFail();
}
bool ExtensionApiTest::WaitForPassFail() {
- completed_ = false;
- passed_ = false;
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE, new MessageLoop::QuitTask, kTimeoutMs);
- ui_test_utils::RunMessageLoop();
- return passed_;
+ NotificationRegistrar registrar;
+ registrar.Add(this, NotificationType::EXTENSION_TEST_PASSED,
+ NotificationService::AllSources());
+ registrar.Add(this, NotificationType::EXTENSION_TEST_FAILED,
+ NotificationService::AllSources());
+
+ // Depending on the tests, multiple results can come in from a single call
+ // to RunMessageLoop(), so we maintain a queue of results and just pull them
+ // off as the test calls this, going to the run loop only when the queue is
+ // empty.
+ if (!results_.size()) {
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, new MessageLoop::QuitTask, kTimeoutMs);
+ ui_test_utils::RunMessageLoop();
+ }
+ if (results_.size()) {
+ bool ret = results_.front();
+ results_.pop_front();
+ message_ = messages_.front();
+ messages_.pop_front();
+ return ret;
+ }
+ message_ = "No response from message loop.";
+ return false;
}
void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) {
@@ -55,16 +69,15 @@ void ExtensionApiTest::Observe(NotificationType type,
switch (type.value) {
case NotificationType::EXTENSION_TEST_PASSED:
std::cout << "Got EXTENSION_TEST_PASSED notification.\n";
- completed_ = true;
- passed_ = true;
+ results_.push_back(true);
+ messages_.push_back("");
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());
+ results_.push_back(false);
+ messages_.push_back(*(Details<std::string>(details).ptr()));
MessageLoopForUI::current()->Quit();
break;
« no previous file with comments | « chrome/browser/extensions/extension_apitest.h ('k') | chrome/browser/extensions/extension_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698