summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_apitest.cc
diff options
context:
space:
mode:
authorerikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 20:26:05 +0000
committererikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-28 20:26:05 +0000
commit86c008e8a7da9c00c5a676eb201ba5d0c976748e (patch)
tree8e58aeeab8564a396ccf67807d5bddfcdaa05807 /chrome/browser/extensions/extension_apitest.cc
parent5ec8d59c7e79d1a7aae4137051ffc184ec51096c (diff)
downloadchromium_src-86c008e8a7da9c00c5a676eb201ba5d0c976748e.zip
chromium_src-86c008e8a7da9c00c5a676eb201ba5d0c976748e.tar.gz
chromium_src-86c008e8a7da9c00c5a676eb201ba5d0c976748e.tar.bz2
override chrome:// URLs via extensions.
Overrides are declared in an extension's manifest. The last one installed wins. However, we keep a list of those installed per page so that priority is preserved and so that uninstall will revert to a previous state. Review URL: http://codereview.chromium.org/174277 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24791 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_apitest.cc')
-rw-r--r--chrome/browser/extensions/extension_apitest.cc55
1 files changed, 34 insertions, 21 deletions
diff --git a/chrome/browser/extensions/extension_apitest.cc b/chrome/browser/extensions/extension_apitest.cc
index 3c45524..415d1c9 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;