diff options
Diffstat (limited to 'chrome/browser/extensions/extension_apitest.cc')
-rw-r--r-- | chrome/browser/extensions/extension_apitest.cc | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc index 0a8875d..65f1058 100644 --- a/chrome/browser/extensions/extension_apitest.cc +++ b/chrome/browser/extensions/extension_apitest.cc @@ -12,35 +12,14 @@ 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) { - // Note the inner scope here. The |registrar| will fall out of scope and - // remove listeners *before* the call to WaitForPassFail() below. - { - LOG(INFO) << "Running ExtensionApiTest with: " << extension_name; - NotificationRegistrar registrar; - registrar.Add(this, NotificationType::EXTENSION_TEST_PASSED, - NotificationService::AllSources()); - registrar.Add(this, NotificationType::EXTENSION_TEST_FAILED, - NotificationService::AllSources()); - - if (!LoadExtension(test_data_dir_.AppendASCII(extension_name))) { - message_ = "Failed to load extension."; - return false; - } - } - - // TODO(erikkay) perhaps we shouldn't do this implicitly. - return WaitForPassFail(); +ExtensionApiTest::ResultCatcher::ResultCatcher() { + registrar_.Add(this, NotificationType::EXTENSION_TEST_PASSED, + NotificationService::AllSources()); + registrar_.Add(this, NotificationType::EXTENSION_TEST_FAILED, + NotificationService::AllSources()); } -bool ExtensionApiTest::WaitForPassFail() { - NotificationRegistrar registrar; - registrar.Add(this, NotificationType::EXTENSION_TEST_PASSED, - NotificationService::AllSources()); - registrar.Add(this, NotificationType::EXTENSION_TEST_FAILED, - NotificationService::AllSources()); - +bool ExtensionApiTest::ResultCatcher::GetNextResult() { // 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 @@ -61,14 +40,9 @@ bool ExtensionApiTest::WaitForPassFail() { return false; } -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) { +void ExtensionApiTest::ResultCatcher::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"; @@ -85,6 +59,29 @@ void ExtensionApiTest::Observe(NotificationType type, break; default: - ExtensionBrowserTest::Observe(type, source, details); + NOTREACHED(); + } +} + +// Load an extension and wait for it to notify of PASSED or FAILED. +bool ExtensionApiTest::RunExtensionTest(const char* extension_name) { + ResultCatcher catcher; + + LOG(INFO) << "Running ExtensionApiTest with: " << extension_name; + if (!LoadExtension(test_data_dir_.AppendASCII(extension_name))) { + message_ = "Failed to load extension."; + return false; + } + + if (!catcher.GetNextResult()) { + message_ = catcher.message(); + return false; + } else { + return true; } } + +void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { + ExtensionBrowserTest::SetUpCommandLine(command_line); + test_data_dir_ = test_data_dir_.AppendASCII("api_test"); +} |