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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "chrome/browser/extensions/api/web_request/web_request_api.h" | 6 #include "chrome/browser/extensions/api/web_request/web_request_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/extensions/extension_test_message_listener.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_tabstrip.h" | 12 #include "chrome/browser/ui/browser_tabstrip.h" |
12 #include "chrome/browser/ui/login/login_prompt.h" | 13 #include "chrome/browser/ui/login/login_prompt.h" |
13 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
16 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 public: | 56 public: |
56 virtual void SetUpInProcessBrowserTestFixture() { | 57 virtual void SetUpInProcessBrowserTestFixture() { |
57 // TODO(battre): remove this when declarative webRequest API becomes stable. | 58 // TODO(battre): remove this when declarative webRequest API becomes stable. |
58 CommandLine::ForCurrentProcess()->AppendSwitch( | 59 CommandLine::ForCurrentProcess()->AppendSwitch( |
59 switches::kEnableExperimentalExtensionApis); | 60 switches::kEnableExperimentalExtensionApis); |
60 | 61 |
61 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 62 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
62 host_resolver()->AddRule("*", "127.0.0.1"); | 63 host_resolver()->AddRule("*", "127.0.0.1"); |
63 ASSERT_TRUE(StartTestServer()); | 64 ASSERT_TRUE(StartTestServer()); |
64 } | 65 } |
| 66 |
| 67 void RunPermissionTest( |
| 68 const char* extension_directory, |
| 69 bool load_extension_with_incognito_permission, |
| 70 bool wait_for_extension_loaded_in_incognito, |
| 71 const char* expected_content_regular_window, |
| 72 const char* exptected_content_incognito_window); |
65 }; | 73 }; |
66 | 74 |
67 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, WebRequestApi) { | 75 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, WebRequestApi) { |
68 ASSERT_TRUE(RunExtensionSubtest("webrequest", "test_api.html")) << message_; | 76 ASSERT_TRUE(RunExtensionSubtest("webrequest", "test_api.html")) << message_; |
69 } | 77 } |
70 | 78 |
71 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, WebRequestSimple) { | 79 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, WebRequestSimple) { |
72 ASSERT_TRUE(RunExtensionSubtest("webrequest", "test_simple.html")) << | 80 ASSERT_TRUE(RunExtensionSubtest("webrequest", "test_simple.html")) << |
73 message_; | 81 message_; |
74 } | 82 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 mouse_event.type = WebKit::WebInputEvent::MouseUp; | 133 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
126 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); | 134 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
127 | 135 |
128 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); | 136 ASSERT_TRUE(catcher.GetNextResult()) << catcher.message(); |
129 } | 137 } |
130 | 138 |
131 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, WebRequestDeclarative) { | 139 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, WebRequestDeclarative) { |
132 ASSERT_TRUE(RunExtensionSubtest("webrequest", "test_declarative.html")) << | 140 ASSERT_TRUE(RunExtensionSubtest("webrequest", "test_declarative.html")) << |
133 message_; | 141 message_; |
134 } | 142 } |
| 143 |
| 144 void ExtensionWebRequestApiTest::RunPermissionTest( |
| 145 const char* extension_directory, |
| 146 bool load_extension_with_incognito_permission, |
| 147 bool wait_for_extension_loaded_in_incognito, |
| 148 const char* expected_content_regular_window, |
| 149 const char* exptected_content_incognito_window) { |
| 150 ResultCatcher catcher; |
| 151 catcher.RestrictToProfile(browser()->profile()); |
| 152 ResultCatcher catcher_incognito; |
| 153 catcher_incognito.RestrictToProfile( |
| 154 browser()->profile()->GetOffTheRecordProfile()); |
| 155 |
| 156 ExtensionTestMessageListener listener("done", true); |
| 157 ExtensionTestMessageListener listener_incognito("done_incognito", true); |
| 158 |
| 159 ASSERT_TRUE(LoadExtensionWithOptions( |
| 160 test_data_dir_.AppendASCII("webrequest_permissions") |
| 161 .AppendASCII(extension_directory), |
| 162 load_extension_with_incognito_permission, |
| 163 false)); |
| 164 |
| 165 // Test that navigation in regular window is properly redirected. |
| 166 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 167 |
| 168 // This navigation should be redirected. |
| 169 ui_test_utils::NavigateToURL( |
| 170 browser(), |
| 171 test_server()->GetURL("files/extensions/test_file.html")); |
| 172 |
| 173 std::string body; |
| 174 WebContents* tab = chrome::GetActiveWebContents(browser()); |
| 175 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 176 tab->GetRenderViewHost(), L"", |
| 177 L"window.domAutomationController.send(document.body.textContent)", |
| 178 &body)); |
| 179 EXPECT_EQ(expected_content_regular_window, body); |
| 180 |
| 181 // Test that navigation in OTR window is properly redirected. |
| 182 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( |
| 183 browser()->profile(), GURL("about:blank")); |
| 184 |
| 185 if (wait_for_extension_loaded_in_incognito) |
| 186 EXPECT_TRUE(listener_incognito.WaitUntilSatisfied()); |
| 187 |
| 188 // This navigation should be redirected if |
| 189 // load_extension_with_incognito_permission is true. |
| 190 ui_test_utils::NavigateToURL( |
| 191 otr_browser, |
| 192 test_server()->GetURL("files/extensions/test_file.html")); |
| 193 |
| 194 body.clear(); |
| 195 WebContents* otr_tab = chrome::GetActiveWebContents(otr_browser); |
| 196 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString( |
| 197 otr_tab->GetRenderViewHost(), L"", |
| 198 L"window.domAutomationController.send(document.body.textContent)", |
| 199 &body)); |
| 200 EXPECT_EQ(exptected_content_incognito_window, body); |
| 201 } |
| 202 |
| 203 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, |
| 204 WebRequestDeclarativePermissionSpanning1) { |
| 205 // Test spanning with incognito permission. |
| 206 RunPermissionTest("spanning", true, false, "redirected1", "redirected1"); |
| 207 } |
| 208 |
| 209 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, |
| 210 WebRequestDeclarativePermissionSpanning2) { |
| 211 // Test spanning without incognito permission. |
| 212 RunPermissionTest("spanning", false, false, "redirected1", ""); |
| 213 } |
| 214 |
| 215 |
| 216 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, |
| 217 WebRequestDeclarativePermissionSplit1) { |
| 218 // Test split with incognito permission. |
| 219 RunPermissionTest("split", true, true, "redirected1", "redirected2"); |
| 220 } |
| 221 |
| 222 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, |
| 223 WebRequestDeclarativePermissionSplit2) { |
| 224 // Test split without incognito permission. |
| 225 RunPermissionTest("split", false, false, "redirected1", ""); |
| 226 } |
| 227 |
OLD | NEW |