| 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/browser_window.h" | 7 #include "chrome/browser/browser_window.h" |
| 8 #include "chrome/browser/location_bar.h" | 8 #include "chrome/browser/location_bar.h" |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/extensions/extensions_service.h" | 10 #include "chrome/browser/extensions/extensions_service.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 command_line->AppendSwitch(switches::kEnableExtensions); | 36 command_line->AppendSwitch(switches::kEnableExtensions); |
| 37 | 37 |
| 38 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | 38 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); |
| 39 test_data_dir_ = test_data_dir_.AppendASCII("extensions"); | 39 test_data_dir_ = test_data_dir_.AppendASCII("extensions"); |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool ExtensionBrowserTest::LoadExtension(const FilePath& path) { | 42 bool ExtensionBrowserTest::LoadExtension(const FilePath& path) { |
| 43 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 43 ExtensionsService* service = browser()->profile()->GetExtensionsService(); |
| 44 size_t num_before = service->extensions()->size(); | 44 size_t num_before = service->extensions()->size(); |
| 45 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, | 45 { |
| 46 NotificationService::AllSources()); | 46 NotificationRegistrar registrar; |
| 47 service->LoadExtension(path); | 47 registrar.Add(this, NotificationType::EXTENSIONS_LOADED, |
| 48 MessageLoop::current()->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, | 48 NotificationService::AllSources()); |
| 49 kTimeoutMs); | 49 service->LoadExtension(path); |
| 50 ui_test_utils::RunMessageLoop(); | 50 MessageLoop::current()->PostDelayedTask( |
| 51 registrar_.Remove(this, NotificationType::EXTENSIONS_LOADED, | 51 FROM_HERE, new MessageLoop::QuitTask, kTimeoutMs); |
| 52 NotificationService::AllSources()); | 52 ui_test_utils::RunMessageLoop(); |
| 53 } |
| 53 size_t num_after = service->extensions()->size(); | 54 size_t num_after = service->extensions()->size(); |
| 54 if (num_after != (num_before + 1)) | 55 if (num_after != (num_before + 1)) |
| 55 return false; | 56 return false; |
| 56 | 57 |
| 57 return WaitForExtensionHostsToLoad(); | 58 return WaitForExtensionHostsToLoad(); |
| 58 } | 59 } |
| 59 | 60 |
| 60 bool ExtensionBrowserTest::InstallExtension(const FilePath& path) { | 61 bool ExtensionBrowserTest::InstallExtension(const FilePath& path, |
| 62 int expected_change) { |
| 61 ExtensionsService* service = browser()->profile()->GetExtensionsService(); | 63 ExtensionsService* service = browser()->profile()->GetExtensionsService(); |
| 62 service->set_show_extensions_prompts(false); | 64 service->set_show_extensions_prompts(false); |
| 63 size_t num_before = service->extensions()->size(); | 65 size_t num_before = service->extensions()->size(); |
| 64 | 66 |
| 65 registrar_.Add(this, NotificationType::EXTENSIONS_LOADED, | 67 { |
| 66 NotificationService::AllSources()); | 68 NotificationRegistrar registrar; |
| 67 service->InstallExtension(path); | 69 registrar.Add(this, NotificationType::EXTENSIONS_LOADED, |
| 68 MessageLoop::current()->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, | 70 NotificationService::AllSources()); |
| 69 kTimeoutMs); | 71 registrar.Add(this, NotificationType::EXTENSION_LOAD_DISABLED, |
| 70 ui_test_utils::RunMessageLoop(); | 72 NotificationService::AllSources()); |
| 71 registrar_.Remove(this, NotificationType::EXTENSIONS_LOADED, | 73 service->InstallExtension(path); |
| 72 NotificationService::AllSources()); | 74 MessageLoop::current()->PostDelayedTask( |
| 75 FROM_HERE, new MessageLoop::QuitTask, kTimeoutMs); |
| 76 ui_test_utils::RunMessageLoop(); |
| 77 } |
| 78 |
| 73 size_t num_after = service->extensions()->size(); | 79 size_t num_after = service->extensions()->size(); |
| 74 if (num_after != (num_before + 1)) { | 80 if (num_after != (num_before + expected_change)) { |
| 75 std::cout << "Num extensions before: " << IntToString(num_before) << " " | 81 std::cout << "Num extensions before: " << IntToString(num_before) << " " |
| 76 << "num after: " << IntToString(num_after) << " " | 82 << "num after: " << IntToString(num_after) << " " |
| 77 << "Installed extensions follow:\n"; | 83 << "Installed extensions follow:\n"; |
| 78 | 84 |
| 79 for (size_t i = 0; i < service->extensions()->size(); ++i) | 85 for (size_t i = 0; i < service->extensions()->size(); ++i) |
| 80 std::cout << " " << service->extensions()->at(i)->id() << "\n"; | 86 std::cout << " " << service->extensions()->at(i)->id() << "\n"; |
| 81 | 87 |
| 82 std::cout << "Errors follow:\n"; | 88 std::cout << "Errors follow:\n"; |
| 83 const std::vector<std::string>* errors = | 89 const std::vector<std::string>* errors = |
| 84 ExtensionErrorReporter::GetInstance()->GetErrors(); | 90 ExtensionErrorReporter::GetInstance()->GetErrors(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 146 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 141 new MessageLoop::QuitTask, 200); | 147 new MessageLoop::QuitTask, 200); |
| 142 ui_test_utils::RunMessageLoop(); | 148 ui_test_utils::RunMessageLoop(); |
| 143 } | 149 } |
| 144 } | 150 } |
| 145 | 151 |
| 146 return true; | 152 return true; |
| 147 } | 153 } |
| 148 | 154 |
| 149 void ExtensionBrowserTest::Observe(NotificationType type, | 155 void ExtensionBrowserTest::Observe(NotificationType type, |
| 150 const NotificationSource& source, | 156 const NotificationSource& source, |
| 151 const NotificationDetails& details) { | 157 const NotificationDetails& details) { |
| 152 switch (type.value) { | 158 switch (type.value) { |
| 153 case NotificationType::EXTENSIONS_LOADED: | 159 case NotificationType::EXTENSIONS_LOADED: |
| 154 std::cout << "Got EXTENSION_LOADED notification.\n"; | 160 std::cout << "Got EXTENSION_LOADED notification.\n"; |
| 155 MessageLoopForUI::current()->Quit(); | 161 MessageLoopForUI::current()->Quit(); |
| 156 break; | 162 break; |
| 157 | 163 |
| 164 case NotificationType::EXTENSION_LOAD_DISABLED: |
| 165 std::cout << "Got EXTENSIONS_DISABLED_LOAD notification.\n"; |
| 166 MessageLoopForUI::current()->Quit(); |
| 167 break; |
| 168 |
| 158 default: | 169 default: |
| 159 NOTREACHED(); | 170 NOTREACHED(); |
| 160 break; | 171 break; |
| 161 } | 172 } |
| 162 } | 173 } |
| OLD | NEW |