OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/extensions/api/permissions/permissions_api.h" | 6 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/extensions/extension.h" | 13 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
18 #include "net/dns/mock_host_resolver.h" | 18 #include "net/dns/mock_host_resolver.h" |
| 19 #include "net/test/embedded_test_server/embedded_test_server.h" |
19 | 20 |
20 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAllFrames) { | 21 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAllFrames) { |
21 ASSERT_TRUE(StartTestServer()); | 22 ASSERT_TRUE(StartEmbeddedTestServer()); |
22 ASSERT_TRUE(RunExtensionTest("content_scripts/all_frames")) << message_; | 23 ASSERT_TRUE(RunExtensionTest("content_scripts/all_frames")) << message_; |
23 } | 24 } |
24 | 25 |
25 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAboutBlankIframes) { | 26 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAboutBlankIframes) { |
26 ASSERT_TRUE(StartTestServer()); | 27 ASSERT_TRUE(StartEmbeddedTestServer()); |
27 ASSERT_TRUE( | 28 ASSERT_TRUE( |
28 RunExtensionTest("content_scripts/about_blank_iframes")) << message_; | 29 RunExtensionTest("content_scripts/about_blank_iframes")) << message_; |
29 } | 30 } |
30 | 31 |
31 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionIframe) { | 32 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionIframe) { |
32 ASSERT_TRUE(StartTestServer()); | 33 ASSERT_TRUE(StartEmbeddedTestServer()); |
33 ASSERT_TRUE(RunExtensionTest("content_scripts/extension_iframe")) << message_; | 34 ASSERT_TRUE(RunExtensionTest("content_scripts/extension_iframe")) << message_; |
34 } | 35 } |
35 | 36 |
36 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionProcess) { | 37 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionProcess) { |
37 ASSERT_TRUE(StartTestServer()); | 38 ASSERT_TRUE(StartEmbeddedTestServer()); |
38 ASSERT_TRUE( | 39 ASSERT_TRUE( |
39 RunExtensionTest("content_scripts/extension_process")) << message_; | 40 RunExtensionTest("content_scripts/extension_process")) << message_; |
40 } | 41 } |
41 | 42 |
42 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptFragmentNavigation) { | 43 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptFragmentNavigation) { |
43 ASSERT_TRUE(StartTestServer()); | 44 ASSERT_TRUE(StartEmbeddedTestServer()); |
44 const char* extension_name = "content_scripts/fragment"; | 45 const char* extension_name = "content_scripts/fragment"; |
45 ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; | 46 ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; |
46 } | 47 } |
47 | 48 |
48 // Times out on Linux: http://crbug.com/163097 | 49 // Times out on Linux: http://crbug.com/163097 |
49 #if defined(OS_LINUX) | 50 #if defined(OS_LINUX) |
50 #define MAYBE_ContentScriptIsolatedWorlds DISABLED_ContentScriptIsolatedWorlds | 51 #define MAYBE_ContentScriptIsolatedWorlds DISABLED_ContentScriptIsolatedWorlds |
51 #else | 52 #else |
52 #define MAYBE_ContentScriptIsolatedWorlds ContentScriptIsolatedWorlds | 53 #define MAYBE_ContentScriptIsolatedWorlds ContentScriptIsolatedWorlds |
53 #endif | 54 #endif |
54 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ContentScriptIsolatedWorlds) { | 55 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ContentScriptIsolatedWorlds) { |
55 // This extension runs various bits of script and tests that they all run in | 56 // This extension runs various bits of script and tests that they all run in |
56 // the same isolated world. | 57 // the same isolated world. |
57 ASSERT_TRUE(StartTestServer()); | 58 ASSERT_TRUE(StartEmbeddedTestServer()); |
58 ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world1")) << message_; | 59 ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world1")) << message_; |
59 | 60 |
60 // Now load a different extension, inject into same page, verify worlds aren't | 61 // Now load a different extension, inject into same page, verify worlds aren't |
61 // shared. | 62 // shared. |
62 ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world2")) << message_; | 63 ASSERT_TRUE(RunExtensionTest("content_scripts/isolated_world2")) << message_; |
63 } | 64 } |
64 | 65 |
65 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptIgnoreHostPermissions) { | 66 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptIgnoreHostPermissions) { |
66 host_resolver()->AddRule("a.com", "127.0.0.1"); | 67 host_resolver()->AddRule("a.com", "127.0.0.1"); |
67 host_resolver()->AddRule("b.com", "127.0.0.1"); | 68 host_resolver()->AddRule("b.com", "127.0.0.1"); |
68 ASSERT_TRUE(StartTestServer()); | 69 ASSERT_TRUE(StartEmbeddedTestServer()); |
69 ASSERT_TRUE(RunExtensionTest( | 70 ASSERT_TRUE(RunExtensionTest( |
70 "content_scripts/dont_match_host_permissions")) << message_; | 71 "content_scripts/dont_match_host_permissions")) << message_; |
71 } | 72 } |
72 | 73 |
73 // crbug.com/39249 -- content scripts js should not run on view source. | 74 // crbug.com/39249 -- content scripts js should not run on view source. |
74 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptViewSource) { | 75 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptViewSource) { |
75 ASSERT_TRUE(StartTestServer()); | 76 ASSERT_TRUE(StartEmbeddedTestServer()); |
76 ASSERT_TRUE(RunExtensionTest("content_scripts/view_source")) << message_; | 77 ASSERT_TRUE(RunExtensionTest("content_scripts/view_source")) << message_; |
77 } | 78 } |
78 | 79 |
79 // crbug.com/126257 -- content scripts should not get injected into other | 80 // crbug.com/126257 -- content scripts should not get injected into other |
80 // extensions. | 81 // extensions. |
81 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptOtherExtensions) { | 82 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptOtherExtensions) { |
82 host_resolver()->AddRule("a.com", "127.0.0.1"); | 83 host_resolver()->AddRule("a.com", "127.0.0.1"); |
83 ASSERT_TRUE(StartTestServer()); | 84 ASSERT_TRUE(StartEmbeddedTestServer()); |
84 // First, load extension that sets up content script. | 85 // First, load extension that sets up content script. |
85 ASSERT_TRUE(RunExtensionTest("content_scripts/other_extensions/injector")) | 86 ASSERT_TRUE(RunExtensionTest("content_scripts/other_extensions/injector")) |
86 << message_; | 87 << message_; |
87 // Then load targeted extension to make sure its content isn't changed. | 88 // Then load targeted extension to make sure its content isn't changed. |
88 ASSERT_TRUE(RunExtensionTest("content_scripts/other_extensions/victim")) | 89 ASSERT_TRUE(RunExtensionTest("content_scripts/other_extensions/victim")) |
89 << message_; | 90 << message_; |
90 } | 91 } |
91 | 92 |
92 // crbug.com/120762 | 93 // crbug.com/120762 |
93 IN_PROC_BROWSER_TEST_F( | 94 IN_PROC_BROWSER_TEST_F( |
94 ExtensionApiTest, | 95 ExtensionApiTest, |
95 DISABLED_ContentScriptStylesInjectedIntoExistingRenderers) { | 96 DISABLED_ContentScriptStylesInjectedIntoExistingRenderers) { |
96 ASSERT_TRUE(StartTestServer()); | 97 ASSERT_TRUE(StartEmbeddedTestServer()); |
97 | 98 |
98 content::WindowedNotificationObserver signal( | 99 content::WindowedNotificationObserver signal( |
99 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, | 100 chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, |
100 content::Source<Profile>(browser()->profile())); | 101 content::Source<Profile>(browser()->profile())); |
101 | 102 |
102 // Start with a renderer already open at a URL. | 103 // Start with a renderer already open at a URL. |
103 GURL url(test_server()->GetURL("file/extensions/test_file.html")); | 104 GURL url(test_server()->GetURL("file/extensions/test_file.html")); |
104 ui_test_utils::NavigateToURL(browser(), url); | 105 ui_test_utils::NavigateToURL(browser(), url); |
105 | 106 |
106 LoadExtension( | 107 LoadExtension( |
107 test_data_dir_.AppendASCII("content_scripts/existing_renderers")); | 108 test_data_dir_.AppendASCII("content_scripts/existing_renderers")); |
108 | 109 |
109 signal.Wait(); | 110 signal.Wait(); |
110 | 111 |
111 // And check that its styles were affected by the styles that just got loaded. | 112 // And check that its styles were affected by the styles that just got loaded. |
112 bool styles_injected; | 113 bool styles_injected; |
113 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 114 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
114 browser()->tab_strip_model()->GetActiveWebContents(), | 115 browser()->tab_strip_model()->GetActiveWebContents(), |
115 "window.domAutomationController.send(" | 116 "window.domAutomationController.send(" |
116 " document.defaultView.getComputedStyle(document.body, null)." | 117 " document.defaultView.getComputedStyle(document.body, null)." |
117 " getPropertyValue('background-color') == 'rgb(255, 0, 0)')", | 118 " getPropertyValue('background-color') == 'rgb(255, 0, 0)')", |
118 &styles_injected)); | 119 &styles_injected)); |
119 ASSERT_TRUE(styles_injected); | 120 ASSERT_TRUE(styles_injected); |
120 } | 121 } |
121 | 122 |
122 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, | 123 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, |
123 ContentScriptCSSLocalization) { | 124 ContentScriptCSSLocalization) { |
124 ASSERT_TRUE(StartTestServer()); | 125 ASSERT_TRUE(StartEmbeddedTestServer()); |
125 ASSERT_TRUE(RunExtensionTest("content_scripts/css_l10n")) << message_; | 126 ASSERT_TRUE(RunExtensionTest("content_scripts/css_l10n")) << message_; |
126 } | 127 } |
127 | 128 |
128 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionAPIs) { | 129 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptExtensionAPIs) { |
129 ASSERT_TRUE(StartTestServer()); | 130 ASSERT_TRUE(StartEmbeddedTestServer()); |
130 | 131 |
131 const extensions::Extension* extension = LoadExtension( | 132 const extensions::Extension* extension = LoadExtension( |
132 test_data_dir_.AppendASCII("content_scripts/extension_api")); | 133 test_data_dir_.AppendASCII("content_scripts/extension_api")); |
133 | 134 |
134 ResultCatcher catcher; | 135 ResultCatcher catcher; |
135 ui_test_utils::NavigateToURL( | 136 ui_test_utils::NavigateToURL( |
136 browser(), test_server()->GetURL("functions.html")); | 137 browser(), |
| 138 embedded_test_server()->GetURL( |
| 139 "/extensions/api_test/content_scripts/extension_api/functions.html")); |
137 EXPECT_TRUE(catcher.GetNextResult()); | 140 EXPECT_TRUE(catcher.GetNextResult()); |
138 | 141 |
139 // Navigate to a page that will cause a content script to run that starts | 142 // Navigate to a page that will cause a content script to run that starts |
140 // listening for an extension event. | 143 // listening for an extension event. |
141 ui_test_utils::NavigateToURL( | 144 ui_test_utils::NavigateToURL( |
142 browser(), test_server()->GetURL("events.html")); | 145 browser(), |
| 146 embedded_test_server()->GetURL( |
| 147 "/extensions/api_test/content_scripts/extension_api/events.html")); |
143 | 148 |
144 // Navigate to an extension page that will fire the event events.js is | 149 // Navigate to an extension page that will fire the event events.js is |
145 // listening for. | 150 // listening for. |
146 ui_test_utils::NavigateToURLWithDisposition( | 151 ui_test_utils::NavigateToURLWithDisposition( |
147 browser(), extension->GetResourceURL("fire_event.html"), | 152 browser(), extension->GetResourceURL("fire_event.html"), |
148 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_NONE); | 153 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_NONE); |
149 EXPECT_TRUE(catcher.GetNextResult()); | 154 EXPECT_TRUE(catcher.GetNextResult()); |
150 } | 155 } |
151 | 156 |
152 // Flaky on Windows. http://crbug.com/248418 | 157 // Flaky on Windows. http://crbug.com/248418 |
153 #if defined(OS_WIN) | 158 #if defined(OS_WIN) |
154 #define MAYBE_ContentScriptPermissionsApi DISABLED_ContentScriptPermissionsApi | 159 #define MAYBE_ContentScriptPermissionsApi DISABLED_ContentScriptPermissionsApi |
155 #else | 160 #else |
156 #define MAYBE_ContentScriptPermissionsApi ContentScriptPermissionsApi | 161 #define MAYBE_ContentScriptPermissionsApi ContentScriptPermissionsApi |
157 #endif | 162 #endif |
158 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ContentScriptPermissionsApi) { | 163 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_ContentScriptPermissionsApi) { |
159 extensions::PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); | 164 extensions::PermissionsRequestFunction::SetIgnoreUserGestureForTests(true); |
160 extensions::PermissionsRequestFunction::SetAutoConfirmForTests(true); | 165 extensions::PermissionsRequestFunction::SetAutoConfirmForTests(true); |
161 host_resolver()->AddRule("*.com", "127.0.0.1"); | 166 host_resolver()->AddRule("*.com", "127.0.0.1"); |
162 ASSERT_TRUE(StartTestServer()); | 167 ASSERT_TRUE(StartEmbeddedTestServer()); |
163 ASSERT_TRUE(RunExtensionTest("content_scripts/permissions")) << message_; | 168 ASSERT_TRUE(RunExtensionTest("content_scripts/permissions")) << message_; |
164 } | 169 } |
165 | 170 |
166 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBypassPageCSP) { | 171 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptBypassPageCSP) { |
167 ASSERT_TRUE(StartTestServer()); | 172 ASSERT_TRUE(StartEmbeddedTestServer()); |
168 ASSERT_TRUE(RunExtensionTest("content_scripts/bypass_page_csp")) << message_; | 173 ASSERT_TRUE(RunExtensionTest("content_scripts/bypass_page_csp")) << message_; |
169 } | 174 } |
OLD | NEW |