Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 "base/path_service.h" | |
| 6 #include "chrome/browser/extensions/extension_host.h" | |
| 7 #include "chrome/browser/extensions/extension_service.h" | |
| 8 #include "chrome/browser/ui/browser.h" | |
| 9 #include "chrome/common/chrome_paths.h" | |
| 10 #include "chrome/test/ui_test_utils.h" | |
| 11 #include "content/browser/debugger/devtools_sanity_unittest.h" | |
| 12 #include "content/common/notification_service.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const char kPageWithContentScript[] = | |
| 17 "files/devtools/page_with_content_script.html"; | |
| 18 | |
| 19 // Base class for DevTools tests that test devtools functionality for | |
| 20 // extensions and content scripts. | |
| 21 class DevToolsExtensionDebugTest : public DevToolsSanityTest, | |
| 22 public NotificationObserver { | |
| 23 public: | |
| 24 DevToolsExtensionDebugTest() : DevToolsSanityTest() { | |
| 25 PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_); | |
| 26 test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools"); | |
| 27 test_extensions_dir_ = test_extensions_dir_.AppendASCII("extensions"); | |
| 28 } | |
| 29 | |
| 30 protected: | |
| 31 // Load an extention from test\data\devtools\extensions\<extension_name> | |
| 32 void LoadExtension(const char* extension_name) { | |
| 33 FilePath path = test_extensions_dir_.AppendASCII(extension_name); | |
| 34 ASSERT_TRUE(LoadExtensionFromPath(path)) << "Failed to load extension."; | |
| 35 } | |
| 36 | |
| 37 private: | |
| 38 bool LoadExtensionFromPath(const FilePath& path) { | |
| 39 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 40 size_t num_before = service->extensions()->size(); | |
| 41 { | |
| 42 NotificationRegistrar registrar; | |
| 43 registrar.Add(this, NotificationType::EXTENSION_LOADED, | |
| 44 NotificationService::AllSources()); | |
| 45 CancelableQuitTask* delayed_quit = | |
| 46 new CancelableQuitTask("Extension load timed out."); | |
| 47 MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, | |
| 48 4*1000); | |
|
brettw
2011/07/06 16:15:39
What's this magic number? Can you have a named con
Jói
2011/07/06 16:38:57
Changed to:
MessageLoop::current()->PostDel
| |
| 49 service->LoadExtension(path); | |
| 50 ui_test_utils::RunMessageLoop(); | |
| 51 delayed_quit->cancel(); | |
| 52 } | |
| 53 size_t num_after = service->extensions()->size(); | |
| 54 if (num_after != (num_before + 1)) | |
| 55 return false; | |
| 56 | |
| 57 return WaitForExtensionHostsToLoad(); | |
| 58 } | |
| 59 | |
| 60 bool WaitForExtensionHostsToLoad() { | |
| 61 // Wait for all the extension hosts that exist to finish loading. | |
| 62 // NOTE: This assumes that the extension host list is not changing while | |
| 63 // this method is running. | |
| 64 | |
| 65 NotificationRegistrar registrar; | |
| 66 registrar.Add(this, NotificationType::EXTENSION_HOST_DID_STOP_LOADING, | |
| 67 NotificationService::AllSources()); | |
| 68 CancelableQuitTask* delayed_quit = | |
| 69 new CancelableQuitTask("Extension host load timed out."); | |
| 70 MessageLoop::current()->PostDelayedTask(FROM_HERE, delayed_quit, | |
| 71 4*1000); | |
|
brettw
2011/07/06 16:15:39
Ditto
Jói
2011/07/06 16:38:57
Done.
| |
| 72 | |
| 73 ExtensionProcessManager* manager = | |
| 74 browser()->profile()->GetExtensionProcessManager(); | |
| 75 for (ExtensionProcessManager::const_iterator iter = manager->begin(); | |
| 76 iter != manager->end();) { | |
| 77 if ((*iter)->did_stop_loading()) | |
| 78 ++iter; | |
| 79 else | |
| 80 ui_test_utils::RunMessageLoop(); | |
| 81 } | |
| 82 | |
| 83 delayed_quit->cancel(); | |
| 84 return true; | |
| 85 } | |
| 86 | |
| 87 void Observe(NotificationType type, | |
| 88 const NotificationSource& source, | |
| 89 const NotificationDetails& details) { | |
| 90 switch (type.value) { | |
| 91 case NotificationType::EXTENSION_LOADED: | |
| 92 case NotificationType::EXTENSION_HOST_DID_STOP_LOADING: | |
| 93 MessageLoopForUI::current()->Quit(); | |
| 94 break; | |
| 95 default: | |
| 96 NOTREACHED(); | |
| 97 break; | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 FilePath test_extensions_dir_; | |
| 102 }; | |
| 103 | |
| 104 // Tests that a content script is in the scripts list. | |
| 105 // This test is disabled, see bug 28961. | |
| 106 IN_PROC_BROWSER_TEST_F(DevToolsExtensionDebugTest, | |
| 107 TestContentScriptIsPresent) { | |
| 108 LoadExtension("simple_content_script"); | |
| 109 RunTest("testContentScriptIsPresent", kPageWithContentScript); | |
| 110 } | |
| 111 | |
| 112 } // namespace | |
| OLD | NEW |