[email protected] | d874814 | 2012-05-16 21:13:43 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f83773f | 2011-03-02 19:15:21 | [diff] [blame] | 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/logging.h" |
| 6 | #include "chrome/browser/extensions/extension_apitest.h" |
[email protected] | ff8efd31 | 2011-03-21 17:33:59 | [diff] [blame] | 7 | #include "chrome/browser/extensions/extension_service.h" |
| 8 | #include "chrome/browser/profiles/profile.h" |
[email protected] | f83773f | 2011-03-02 19:15:21 | [diff] [blame] | 9 | #include "chrome/browser/ui/browser.h" |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 10 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | 39daa02 | 2011-12-07 21:16:22 | [diff] [blame] | 11 | #include "chrome/common/chrome_switches.h" |
[email protected] | af44e7fb | 2011-07-29 18:32:32 | [diff] [blame] | 12 | #include "chrome/test/base/ui_test_utils.h" |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 13 | #include "content/public/browser/web_contents.h" |
[email protected] | 7d478cb | 2012-07-24 17:19:42 | [diff] [blame] | 14 | #include "content/public/test/browser_test_utils.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 15 | #include "net/dns/mock_host_resolver.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame^] | 16 | #include "url/gurl.h" |
[email protected] | f83773f | 2011-03-02 19:15:21 | [diff] [blame] | 17 | |
| 18 | class ExtensionIconSourceTest : public ExtensionApiTest { |
[email protected] | 39daa02 | 2011-12-07 21:16:22 | [diff] [blame] | 19 | protected: |
| 20 | virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 21 | ExtensionApiTest::SetUpCommandLine(command_line); |
| 22 | command_line->AppendSwitch(switches::kAllowLegacyExtensionManifests); |
| 23 | } |
[email protected] | f83773f | 2011-03-02 19:15:21 | [diff] [blame] | 24 | }; |
| 25 | |
[email protected] | 04e51aa | 2013-05-07 17:46:37 | [diff] [blame] | 26 | // Times out on Mac and Win. http://crbug.com/238705 |
| 27 | #if defined(OS_WIN) || defined(OS_MACOSX) |
| 28 | #define MAYBE_IconsLoaded DISABLED_IconsLoaded |
| 29 | #else |
| 30 | #define MAYBE_IconsLoaded IconsLoaded |
| 31 | #endif |
| 32 | |
| 33 | IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, MAYBE_IconsLoaded) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 34 | base::FilePath basedir = test_data_dir_.AppendASCII("icons"); |
[email protected] | f83773f | 2011-03-02 19:15:21 | [diff] [blame] | 35 | ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_with_permission"))); |
| 36 | ASSERT_TRUE(LoadExtension(basedir.AppendASCII("extension_no_permission"))); |
| 37 | std::string result; |
| 38 | |
| 39 | // Test that the icons are loaded and that the chrome://extension-icon |
| 40 | // parameters work correctly. |
| 41 | ui_test_utils::NavigateToURL( |
| 42 | browser(), |
| 43 | GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html")); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 44 | ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 45 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 46 | "window.domAutomationController.send(document.title)", |
[email protected] | f83773f | 2011-03-02 19:15:21 | [diff] [blame] | 47 | &result)); |
| 48 | EXPECT_EQ(result, "Loaded"); |
| 49 | |
| 50 | // Verify that the an extension can't load chrome://extension-icon icons |
| 51 | // without the management permission. |
| 52 | ui_test_utils::NavigateToURL( |
| 53 | browser(), |
| 54 | GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html")); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 55 | ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 56 | browser()->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 57 | "window.domAutomationController.send(document.title)", |
[email protected] | f83773f | 2011-03-02 19:15:21 | [diff] [blame] | 58 | &result)); |
| 59 | EXPECT_EQ(result, "Not Loaded"); |
| 60 | } |
[email protected] | ff8efd31 | 2011-03-21 17:33:59 | [diff] [blame] | 61 | |
[email protected] | 7029cb74 | 2013-01-30 02:06:55 | [diff] [blame] | 62 | IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, InvalidURL) { |
| 63 | std::string result; |
| 64 | |
| 65 | // Test that navigation to an invalid url works. |
| 66 | ui_test_utils::NavigateToURL( |
| 67 | browser(), |
| 68 | GURL("chrome://extension-icon/invalid")); |
| 69 | |
| 70 | ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 71 | browser()->tab_strip_model()->GetActiveWebContents(), |
| 72 | "window.domAutomationController.send(document.title)", |
| 73 | &result)); |
| 74 | EXPECT_EQ(result, "invalid (96\xC3\x97""96)"); |
| 75 | } |
| 76 | |
[email protected] | 04e51aa | 2013-05-07 17:46:37 | [diff] [blame] | 77 | // Times out on Mac and Win. http://crbug.com/238705 |
| 78 | #if defined(OS_WIN) || defined(OS_MACOSX) |
| 79 | #define MAYBE_IconsLoadedIncognito DISABLED_IconsLoadedIncognito |
| 80 | #else |
| 81 | #define MAYBE_IconsLoadedIncognito IconsLoadedIncognito |
| 82 | #endif |
| 83 | |
| 84 | IN_PROC_BROWSER_TEST_F(ExtensionIconSourceTest, MAYBE_IconsLoadedIncognito) { |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 85 | base::FilePath basedir = test_data_dir_.AppendASCII("icons"); |
[email protected] | ff8efd31 | 2011-03-21 17:33:59 | [diff] [blame] | 86 | ASSERT_TRUE(LoadExtensionIncognito( |
| 87 | basedir.AppendASCII("extension_with_permission"))); |
| 88 | ASSERT_TRUE(LoadExtensionIncognito( |
| 89 | basedir.AppendASCII("extension_no_permission"))); |
| 90 | std::string result; |
| 91 | |
| 92 | // Test that the icons are loaded and that the chrome://extension-icon |
| 93 | // parameters work correctly. |
[email protected] | 979ad59 | 2012-07-12 16:42:19 | [diff] [blame] | 94 | Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( |
[email protected] | ff8efd31 | 2011-03-21 17:33:59 | [diff] [blame] | 95 | browser()->profile(), |
| 96 | GURL("chrome-extension://gbmgkahjioeacddebbnengilkgbkhodg/index.html")); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 97 | ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 98 | otr_browser->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 99 | "window.domAutomationController.send(document.title)", |
[email protected] | ff8efd31 | 2011-03-21 17:33:59 | [diff] [blame] | 100 | &result)); |
| 101 | EXPECT_EQ(result, "Loaded"); |
| 102 | |
| 103 | // Verify that the an extension can't load chrome://extension-icon icons |
| 104 | // without the management permission. |
| 105 | ui_test_utils::OpenURLOffTheRecord( |
| 106 | browser()->profile(), |
| 107 | GURL("chrome-extension://apocjbpjpkghdepdngjlknfpmabcmlao/index.html")); |
[email protected] | b6987e0 | 2013-01-04 18:30:43 | [diff] [blame] | 108 | ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
[email protected] | 47ae2337 | 2013-01-29 01:50:48 | [diff] [blame] | 109 | otr_browser->tab_strip_model()->GetActiveWebContents(), |
[email protected] | 06bc5d9 | 2013-01-02 22:44:13 | [diff] [blame] | 110 | "window.domAutomationController.send(document.title)", |
[email protected] | ff8efd31 | 2011-03-21 17:33:59 | [diff] [blame] | 111 | &result)); |
| 112 | EXPECT_EQ(result, "Not Loaded"); |
| 113 | } |