| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/ref_counted.h" | 5 #include "base/ref_counted.h" |
| 6 #include "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
| 7 #include "chrome/browser/browser_list.h" | 7 #include "chrome/browser/browser_list.h" |
| 8 #include "chrome/browser/renderer_host/render_view_host.h" | 8 #include "chrome/browser/renderer_host/render_view_host.h" |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
| 11 #include "chrome/browser/extensions/extensions_service.h" | 11 #include "chrome/browser/extensions/extensions_service.h" |
| 12 #include "chrome/browser/extensions/test_extension_loader.h" | 12 #include "chrome/browser/extensions/test_extension_loader.h" |
| 13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/browser/tab_contents/site_instance.h" | 14 #include "chrome/browser/tab_contents/site_instance.h" |
| 15 #include "chrome/browser/views/extensions/extension_shelf.h" | 15 #include "chrome/browser/views/extensions/extension_shelf.h" |
| 16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/extensions/extension_error_reporter.h" | 18 #include "chrome/common/extensions/extension_error_reporter.h" |
| 19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 20 #include "chrome/test/in_process_browser_test.h" | 20 #include "chrome/test/in_process_browser_test.h" |
| 21 #include "chrome/test/ui_test_utils.h" | 21 #include "chrome/test/ui_test_utils.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // How long to wait for the extension to put up a javascript alert before giving | 25 // How long to wait for the extension to put up a javascript alert before giving |
| 26 // up. | 26 // up. |
| 27 const int kAlertTimeoutMs = 20000; | 27 const int kAlertTimeoutMs = 20000; |
| 28 | 28 |
| 29 // The extensions we're using as our test case. | 29 // The extensions we're using as our test case. |
| 30 const char* kGoodExtension1Id = "00123456789abcdef0123456789abcdef0123456"; | 30 const char* kGoodExtension1Id = "behllobkkfkfnphdnhnkndlbkcpglgmj"; |
| 31 const char* kGoodCrxId = "00123456789abcdef0123456789abcdef0123456"; | 31 const char* kGoodCrxId = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 32 | 32 |
| 33 }; // namespace | 33 }; // namespace |
| 34 | 34 |
| 35 // This class starts up an extension process and waits until it tries to put | 35 // This class starts up an extension process and waits until it tries to put |
| 36 // up a javascript alert. | 36 // up a javascript alert. |
| 37 class MockExtensionHost : public ExtensionHost { | 37 class MockExtensionHost : public ExtensionHost { |
| 38 public: | 38 public: |
| 39 MockExtensionHost(Extension* extension, const GURL& url, | 39 MockExtensionHost(Extension* extension, const GURL& url, |
| 40 SiteInstance* instance) | 40 SiteInstance* instance) |
| 41 : ExtensionHost(extension, instance, url, NULL), | 41 : ExtensionHost(extension, instance, url, NULL), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 bool got_message_; | 73 bool got_message_; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 class ExtensionViewTest : public InProcessBrowserTest { | 76 class ExtensionViewTest : public InProcessBrowserTest { |
| 77 public: | 77 public: |
| 78 virtual void SetUp() { | 78 virtual void SetUp() { |
| 79 // Initialize the error reporter here, otherwise BrowserMain will create it | 79 // Initialize the error reporter here, otherwise BrowserMain will create it |
| 80 // with the wrong MessageLoop. | 80 // with the wrong MessageLoop. |
| 81 ExtensionErrorReporter::Init(false); | 81 ExtensionErrorReporter::Init(false); |
| 82 | 82 |
| 83 // Use single-process in an attempt to speed it up and make it less flaky. | |
| 84 //EnableSingleProcess(); | |
| 85 | |
| 86 InProcessBrowserTest::SetUp(); | 83 InProcessBrowserTest::SetUp(); |
| 87 } | 84 } |
| 88 virtual void SetUpCommandLine(CommandLine* command_line) { | 85 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 89 command_line->AppendSwitch(switches::kEnableExtensions); | 86 command_line->AppendSwitch(switches::kEnableExtensions); |
| 90 } | 87 } |
| 91 }; | 88 }; |
| 92 | 89 |
| 93 // Tests that ExtensionView starts an extension process and runs the script | 90 // Tests that ExtensionView starts an extension process and runs the script |
| 94 // contained in the extension's toolstrip. | 91 // contained in the extension's toolstrip. |
| 95 // TODO(mpcomplete): http://crbug.com/15081 Disabled because it fails. | 92 // TODO(mpcomplete): http://crbug.com/15081 Disabled because it fails. |
| 96 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, DISABLED_Toolstrip) { | 93 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, DISABLED_Toolstrip) { |
| 97 // Get the path to our extension. | 94 // Get the path to our extension. |
| 98 FilePath path; | 95 FilePath path; |
| 99 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); | 96 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 100 path = path.AppendASCII("extensions"). | 97 path = path.AppendASCII("extensions") |
| 101 AppendASCII("good").AppendASCII("extension1").AppendASCII("1"); | 98 .AppendASCII("good") |
| 99 .AppendASCII("Extensions") |
| 100 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 101 .AppendASCII("1.0.0.0"); |
| 102 ASSERT_TRUE(file_util::DirectoryExists(path)); // sanity check | 102 ASSERT_TRUE(file_util::DirectoryExists(path)); // sanity check |
| 103 | 103 |
| 104 // Wait for the extension to load and grab a pointer to it. | 104 // Wait for the extension to load and grab a pointer to it. |
| 105 TestExtensionLoader loader(browser()->profile()); | 105 TestExtensionLoader loader(browser()->profile()); |
| 106 Extension* extension = loader.Load(kGoodExtension1Id, path); | 106 Extension* extension = loader.Load(kGoodExtension1Id, path); |
| 107 ASSERT_TRUE(extension); | 107 ASSERT_TRUE(extension); |
| 108 GURL url = Extension::GetResourceURL(extension->url(), "toolstrip1.html"); | 108 GURL url = Extension::GetResourceURL(extension->url(), "toolstrip1.html"); |
| 109 | 109 |
| 110 // Start the extension process and wait for it to show a javascript alert. | 110 // Start the extension process and wait for it to show a javascript alert. |
| 111 MockExtensionHost host(extension, url, | 111 MockExtensionHost host(extension, url, |
| 112 browser()->profile()->GetExtensionProcessManager()-> | 112 browser()->profile()->GetExtensionProcessManager()-> |
| 113 GetSiteInstanceForURL(url)); | 113 GetSiteInstanceForURL(url)); |
| 114 EXPECT_TRUE(host.got_message()); | 114 EXPECT_TRUE(host.got_message()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 // Tests that the ExtensionShelf initializes properly, notices that | 117 // Tests that the ExtensionShelf initializes properly, notices that |
| 118 // an extension loaded and has a view available, and then sets that up | 118 // an extension loaded and has a view available, and then sets that up |
| 119 // properly. | 119 // properly. |
| 120 // TODO(mpcomplete): http://crbug.com/15081 Disabled because it fails. | 120 // TODO(mpcomplete): http://crbug.com/15081 Disabled because it fails. |
| 121 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, DISABLED_Shelf) { | 121 IN_PROC_BROWSER_TEST_F(ExtensionViewTest, DISABLED_Shelf) { |
| 122 // When initialized, there are no extension views and the preferred height | 122 // When initialized, there are no extension views and the preferred height |
| 123 // should be zero. | 123 // should be zero. |
| 124 scoped_ptr<ExtensionShelf> shelf(new ExtensionShelf(browser())); | 124 scoped_ptr<ExtensionShelf> shelf(new ExtensionShelf(browser())); |
| 125 EXPECT_EQ(shelf->GetChildViewCount(), 0); | 125 EXPECT_EQ(shelf->GetChildViewCount(), 0); |
| 126 EXPECT_EQ(shelf->GetPreferredSize().height(), 0); | 126 EXPECT_EQ(shelf->GetPreferredSize().height(), 0); |
| 127 | 127 |
| 128 // Get the path to our extension. | 128 // Get the path to our extension. |
| 129 FilePath path; | 129 FilePath path; |
| 130 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); | 130 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); |
| 131 path = path.AppendASCII("extensions"). | 131 path = path.AppendASCII("extensions") |
| 132 AppendASCII("good").AppendASCII("extension1").AppendASCII("1"); | 132 .AppendASCII("good") |
| 133 .AppendASCII("Extensions") |
| 134 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 135 .AppendASCII("1.0.0.0"); |
| 133 ASSERT_TRUE(file_util::DirectoryExists(path)); // sanity check | 136 ASSERT_TRUE(file_util::DirectoryExists(path)); // sanity check |
| 134 | 137 |
| 135 // Wait for the extension to load and grab a pointer to it. | 138 // Wait for the extension to load and grab a pointer to it. |
| 136 TestExtensionLoader loader(browser()->profile()); | 139 TestExtensionLoader loader(browser()->profile()); |
| 137 Extension* extension = loader.Load(kGoodExtension1Id, path); | 140 Extension* extension = loader.Load(kGoodExtension1Id, path); |
| 138 ASSERT_TRUE(extension); | 141 ASSERT_TRUE(extension); |
| 139 | 142 |
| 140 // There should now be two extension views and preferred height of the view | 143 // There should now be two extension views and preferred height of the view |
| 141 // should be non-zero. | 144 // should be non-zero. |
| 142 EXPECT_EQ(shelf->GetChildViewCount(), 2); | 145 EXPECT_EQ(shelf->GetChildViewCount(), 2); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 161 | 164 |
| 162 // Wait for the extension to load and grab a pointer to it. | 165 // Wait for the extension to load and grab a pointer to it. |
| 163 TestExtensionLoader loader(browser()->profile()); | 166 TestExtensionLoader loader(browser()->profile()); |
| 164 Extension* extension = loader.Install(kGoodCrxId, path); | 167 Extension* extension = loader.Install(kGoodCrxId, path); |
| 165 ASSERT_TRUE(extension); | 168 ASSERT_TRUE(extension); |
| 166 | 169 |
| 167 // TODO(mpcomplete): wait for uninstall to complete? | 170 // TODO(mpcomplete): wait for uninstall to complete? |
| 168 browser()->profile()->GetExtensionsService()-> | 171 browser()->profile()->GetExtensionsService()-> |
| 169 UninstallExtension(kGoodCrxId, false); | 172 UninstallExtension(kGoodCrxId, false); |
| 170 } | 173 } |
| OLD | NEW |