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