| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_apitest.h" |
| 6 |
| 7 #include "chrome/browser/browser.h" |
| 8 #include "chrome/common/notification_registrar.h" |
| 9 #include "chrome/test/ui_test_utils.h" |
| 10 |
| 11 namespace { |
| 12 static const int kTimeoutMs = 60 * 1000; // 1 minute |
| 13 }; |
| 14 |
| 15 // Load an extension and wait for it to notify of PASSED or FAILED. |
| 16 bool ExtensionApiTest::RunExtensionTest(const char* extension_name) { |
| 17 bool result; |
| 18 completed_ = false; |
| 19 { |
| 20 NotificationRegistrar registrar; |
| 21 registrar.Add(this, NotificationType::EXTENSION_TEST_PASSED, |
| 22 NotificationService::AllSources()); |
| 23 registrar.Add(this, NotificationType::EXTENSION_TEST_FAILED, |
| 24 NotificationService::AllSources()); |
| 25 result = LoadExtension(test_data_dir_.AppendASCII(extension_name)); |
| 26 |
| 27 // If the test runs quickly, we may get the notification while waiting |
| 28 // for the Load to finish. |
| 29 if (completed_) { |
| 30 result = passed_; |
| 31 } else { |
| 32 result = WaitForPassFail(); |
| 33 } |
| 34 } |
| 35 return result; |
| 36 } |
| 37 |
| 38 bool ExtensionApiTest::WaitForPassFail() { |
| 39 completed_ = false; |
| 40 passed_ = false; |
| 41 MessageLoop::current()->PostDelayedTask( |
| 42 FROM_HERE, new MessageLoop::QuitTask, kTimeoutMs); |
| 43 ui_test_utils::RunMessageLoop(); |
| 44 return passed_; |
| 45 } |
| 46 |
| 47 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { |
| 48 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 49 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); |
| 50 } |
| 51 |
| 52 void ExtensionApiTest::Observe(NotificationType type, |
| 53 const NotificationSource& source, |
| 54 const NotificationDetails& details) { |
| 55 switch (type.value) { |
| 56 case NotificationType::EXTENSION_TEST_PASSED: |
| 57 std::cout << "Got EXTENSION_TEST_PASSED notification.\n"; |
| 58 completed_ = true; |
| 59 passed_ = true; |
| 60 MessageLoopForUI::current()->Quit(); |
| 61 break; |
| 62 |
| 63 case NotificationType::EXTENSION_TEST_FAILED: |
| 64 std::cout << "Got EXTENSION_TEST_FAILED notification.\n"; |
| 65 completed_ = true; |
| 66 passed_ = false; |
| 67 message_ = *(Details<std::string>(details).ptr()); |
| 68 MessageLoopForUI::current()->Quit(); |
| 69 break; |
| 70 |
| 71 default: |
| 72 ExtensionBrowserTest::Observe(type, source, details); |
| 73 } |
| 74 } |
| OLD | NEW |