| OLD | NEW |
| 1 #include "chrome/browser/extensions/extension_browsertest.h" | 1 #include "chrome/browser/extensions/extension_browsertest.h" |
| 2 | 2 |
| 3 #include "base/command_line.h" | 3 #include "base/command_line.h" |
| 4 #include "base/file_path.h" | 4 #include "base/file_path.h" |
| 5 #include "base/path_service.h" | 5 #include "base/path_service.h" |
| 6 #include "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
| 7 #include "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
| 8 #include "chrome/browser/extensions/extensions_service.h" | 8 #include "chrome/browser/extensions/extensions_service.h" |
| 9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, | 62 registrar_.Add(this, NotificationType::EXTENSION_INSTALLED, |
| 63 NotificationService::AllSources()); | 63 NotificationService::AllSources()); |
| 64 service->InstallExtension(path); | 64 service->InstallExtension(path); |
| 65 MessageLoop::current()->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, | 65 MessageLoop::current()->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, |
| 66 kTimeoutMs); | 66 kTimeoutMs); |
| 67 ui_test_utils::RunMessageLoop(); | 67 ui_test_utils::RunMessageLoop(); |
| 68 registrar_.Remove(this, NotificationType::EXTENSION_INSTALLED, | 68 registrar_.Remove(this, NotificationType::EXTENSION_INSTALLED, |
| 69 NotificationService::AllSources()); | 69 NotificationService::AllSources()); |
| 70 size_t num_after = service->extensions()->size(); | 70 size_t num_after = service->extensions()->size(); |
| 71 if (num_after != (num_before + 1)) | 71 if (num_after != (num_before + 1)) { |
| 72 std::cout << "Num extensions before: " << IntToString(num_before) |
| 73 << "num after: " << IntToString(num_after) |
| 74 << "Installed extensions are:\n"; |
| 75 for (size_t i = 0; i < service->extensions()->size(); ++i) |
| 76 std::cout << " " << service->extensions()->at(i)->id() << "\n"; |
| 72 return false; | 77 return false; |
| 78 } |
| 73 | 79 |
| 74 return WaitForExtensionHostsToLoad(); | 80 return WaitForExtensionHostsToLoad(); |
| 75 } | 81 } |
| 76 | 82 |
| 77 void ExtensionBrowserTest::UninstallExtension(const std::string& extension_id) { | 83 void ExtensionBrowserTest::UninstallExtension(const std::string& extension_id) { |
| 78 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 84 ExtensionsService* service = browser()->profile()->GetExtensionsService(); |
| 79 service->UninstallExtension(extension_id, false); | 85 service->UninstallExtension(extension_id, false); |
| 80 } | 86 } |
| 81 | 87 |
| 82 bool ExtensionBrowserTest::WaitForExtensionHostsToLoad() { | 88 bool ExtensionBrowserTest::WaitForExtensionHostsToLoad() { |
| 83 // Wait for all the extension hosts that exist to finish loading. | 89 // Wait for all the extension hosts that exist to finish loading. |
| 84 // NOTE: This assumes that the extension host list is not changing while | 90 // NOTE: This assumes that the extension host list is not changing while |
| 85 // this method is running. | 91 // this method is running. |
| 86 ExtensionProcessManager* manager = | 92 ExtensionProcessManager* manager = |
| 87 browser()->profile()->GetExtensionProcessManager(); | 93 browser()->profile()->GetExtensionProcessManager(); |
| 88 base::Time start_time = base::Time::Now(); | 94 base::Time start_time = base::Time::Now(); |
| 89 for (ExtensionProcessManager::const_iterator iter = manager->begin(); | 95 for (ExtensionProcessManager::const_iterator iter = manager->begin(); |
| 90 iter != manager->end(); ++iter) { | 96 iter != manager->end(); ++iter) { |
| 91 while (!(*iter)->did_stop_loading()) { | 97 while (!(*iter)->did_stop_loading()) { |
| 92 if ((base::Time::Now() - start_time).InMilliseconds() > kTimeoutMs) | 98 if ((base::Time::Now() - start_time).InMilliseconds() > kTimeoutMs) { |
| 99 std::cout << "Extension host did not load for URL: " |
| 100 << (*iter)->GetURL().spec(); |
| 93 return false; | 101 return false; |
| 102 } |
| 94 | 103 |
| 95 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 104 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 96 new MessageLoop::QuitTask, 200); | 105 new MessageLoop::QuitTask, 200); |
| 97 ui_test_utils::RunMessageLoop(); | 106 ui_test_utils::RunMessageLoop(); |
| 98 } | 107 } |
| 99 } | 108 } |
| 100 | 109 |
| 101 return true; | 110 return true; |
| 102 } | 111 } |
| 103 | 112 |
| 104 void ExtensionBrowserTest::Observe(NotificationType type, | 113 void ExtensionBrowserTest::Observe(NotificationType type, |
| 105 const NotificationSource& source, | 114 const NotificationSource& source, |
| 106 const NotificationDetails& details) { | 115 const NotificationDetails& details) { |
| 107 switch (type.value) { | 116 switch (type.value) { |
| 108 case NotificationType::EXTENSION_INSTALLED: | 117 case NotificationType::EXTENSION_INSTALLED: |
| 109 case NotificationType::EXTENSIONS_LOADED: | 118 case NotificationType::EXTENSIONS_LOADED: |
| 110 MessageLoopForUI::current()->Quit(); | 119 MessageLoopForUI::current()->Quit(); |
| 111 break; | 120 break; |
| 112 default: | 121 default: |
| 113 NOTREACHED(); | 122 NOTREACHED(); |
| 114 break; | 123 break; |
| 115 } | 124 } |
| 116 } | 125 } |
| OLD | NEW |