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 "base/ref_counted.h" |
| 6 #include "chrome/browser/browser.h" |
| 7 #include "chrome/browser/browser_list.h" |
| 8 #include "chrome/browser/renderer_host/render_view_host.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" |
| 11 #include "chrome/browser/extensions/extension_process_manager.h" |
| 12 #include "chrome/browser/extensions/extensions_service.h" |
| 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/browser/renderer_host/site_instance.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents.h" |
| 16 #include "chrome/browser/views/extensions/extension_shelf.h" |
| 17 #include "chrome/browser/views/frame/browser_view.h" |
| 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/extensions/extension_error_reporter.h" |
| 20 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/test/ui_test_utils.h" |
| 22 |
| 23 // Tests that toolstrips initializes properly and can run basic extension js. |
| 24 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, Toolstrip) { |
| 25 ASSERT_TRUE(LoadExtension( |
| 26 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 27 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 28 .AppendASCII("1.0.0.0"))); |
| 29 |
| 30 // At this point, there should be two ExtensionHosts loaded because this |
| 31 // extension has two toolstrips. Find the one that is hosting toolstrip1.html. |
| 32 ExtensionProcessManager* manager = |
| 33 browser()->profile()->GetExtensionProcessManager(); |
| 34 ExtensionHost* host = NULL; |
| 35 int num_hosts = 0; |
| 36 for (ExtensionProcessManager::const_iterator iter = manager->begin(); |
| 37 iter != manager->end(); ++iter) { |
| 38 if ((*iter)->GetURL().path() == "/toolstrip1.html") { |
| 39 ASSERT_FALSE(host); |
| 40 host = *iter; |
| 41 } |
| 42 num_hosts++; |
| 43 } |
| 44 EXPECT_EQ(2, num_hosts); |
| 45 |
| 46 // Tell it to run some JavaScript that tests that basic extension code works. |
| 47 bool result = false; |
| 48 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 49 host->render_view_host(), L"", L"testTabsAPI()", &result); |
| 50 EXPECT_TRUE(result); |
| 51 } |
| 52 |
| 53 // Tests that the ExtensionShelf initializes properly, notices that |
| 54 // an extension loaded and has a view available, and then sets that up |
| 55 // properly. |
| 56 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, Shelf) { |
| 57 // When initialized, there are no extension views and the preferred height |
| 58 // should be zero. |
| 59 BrowserView* browser_view = static_cast<BrowserView*>(browser()->window()); |
| 60 ExtensionShelf* shelf = browser_view->extension_shelf(); |
| 61 ASSERT_TRUE(shelf); |
| 62 EXPECT_EQ(shelf->GetChildViewCount(), 0); |
| 63 EXPECT_EQ(shelf->GetPreferredSize().height(), 0); |
| 64 |
| 65 ASSERT_TRUE(LoadExtension( |
| 66 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 67 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 68 .AppendASCII("1.0.0.0"))); |
| 69 |
| 70 // There should now be two extension views and preferred height of the view |
| 71 // should be non-zero. |
| 72 EXPECT_EQ(shelf->GetChildViewCount(), 2); |
| 73 EXPECT_NE(shelf->GetPreferredSize().height(), 0); |
| 74 } |
| 75 |
| 76 // Tests that installing and uninstalling extensions don't crash with an |
| 77 // incognito window open. |
| 78 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, Incognito) { |
| 79 // Open an incognito window to the extensions management page. We just |
| 80 // want to make sure that we don't crash while playing with extensions when |
| 81 // this guy is around. |
| 82 Browser::OpenURLOffTheRecord(browser()->profile(), |
| 83 GURL(chrome::kChromeUIExtensionsURL)); |
| 84 |
| 85 ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("good.crx"))); |
| 86 UninstallExtension("ldnnhddmnhbkjipkidpdiheffobcpfmf"); |
| 87 } |
| 88 |
| 89 // Tests that we can load extension pages into the tab area and they can call |
| 90 // extension APIs. |
| 91 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TabContents) { |
| 92 ASSERT_TRUE(LoadExtension( |
| 93 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 94 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 95 .AppendASCII("1.0.0.0"))); |
| 96 |
| 97 ui_test_utils::NavigateToURL( |
| 98 browser(), |
| 99 GURL("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html")); |
| 100 |
| 101 bool result = false; |
| 102 ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 103 browser()->GetSelectedTabContents()->render_view_host(), L"", |
| 104 L"testTabsAPI()", &result); |
| 105 EXPECT_TRUE(result); |
| 106 } |
OLD | NEW |