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 "chrome/browser/extensions/browser_action_test_util.h" | 5 #include "chrome/browser/extensions/browser_action_test_util.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/browser/extensions/extension_test_message_listener.h" | 8 #include "chrome/browser/extensions/extension_test_message_listener.h" |
9 #include "chrome/browser/extensions/user_script_master.h" | 9 #include "chrome/browser/extensions/user_script_master.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.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 using content::WebContents; | 21 using content::WebContents; |
21 | 22 |
22 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) { | 23 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) { |
23 ASSERT_TRUE(StartTestServer()); | 24 ASSERT_TRUE(StartTestServer()); |
24 | 25 |
25 // Loads a simple extension which attempts to change the title of every page | 26 // Loads a simple extension which attempts to change the title of every page |
26 // that loads to "modified". | 27 // that loads to "modified". |
27 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito") | 28 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito") |
28 .AppendASCII("content_scripts"))); | 29 .AppendASCII("content_scripts"))); |
29 | 30 |
30 // Open incognito window and navigate to test page. | 31 // Open incognito window and navigate to test page. |
31 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( | 32 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( |
32 browser()->profile(), | 33 browser()->profile(), |
33 test_server()->GetURL("files/extensions/test_file.html")); | 34 embedded_test_server()->GetURL("/extensions/test_file.html")); |
34 | 35 |
35 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); | 36 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); |
36 | 37 |
37 // Verify the script didn't run. | 38 // Verify the script didn't run. |
38 bool result = false; | 39 bool result = false; |
39 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 40 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
40 tab, | 41 tab, |
41 "window.domAutomationController.send(document.title == 'Unmodified')", | 42 "window.domAutomationController.send(document.title == 'Unmodified')", |
42 &result)); | 43 &result)); |
43 EXPECT_TRUE(result); | 44 EXPECT_TRUE(result); |
(...skipping 21 matching lines...) Expand all Loading... |
65 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 66 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
66 .AppendASCII("incognito").AppendASCII("content_scripts"))); | 67 .AppendASCII("incognito").AppendASCII("content_scripts"))); |
67 | 68 |
68 // Dummy extension #2. | 69 // Dummy extension #2. |
69 ASSERT_TRUE(LoadExtension(test_data_dir_ | 70 ASSERT_TRUE(LoadExtension(test_data_dir_ |
70 .AppendASCII("content_scripts").AppendASCII("isolated_world1"))); | 71 .AppendASCII("content_scripts").AppendASCII("isolated_world1"))); |
71 | 72 |
72 // Open incognito window and navigate to test page. | 73 // Open incognito window and navigate to test page. |
73 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( | 74 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( |
74 browser()->profile(), | 75 browser()->profile(), |
75 test_server()->GetURL("files/extensions/test_file.html")); | 76 embedded_test_server()->GetURL("/extensions/test_file.html")); |
76 | 77 |
77 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); | 78 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); |
78 | 79 |
79 // Verify the script ran. | 80 // Verify the script ran. |
80 bool result = false; | 81 bool result = false; |
81 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 82 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
82 tab, | 83 tab, |
83 "window.domAutomationController.send(document.title == 'modified')", | 84 "window.domAutomationController.send(document.title == 'modified')", |
84 &result)); | 85 &result)); |
85 EXPECT_TRUE(result); | 86 EXPECT_TRUE(result); |
(...skipping 16 matching lines...) Expand all Loading... |
102 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) { | 103 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) { |
103 #endif | 104 #endif |
104 host_resolver()->AddRule("*", "127.0.0.1"); | 105 host_resolver()->AddRule("*", "127.0.0.1"); |
105 ASSERT_TRUE(StartTestServer()); | 106 ASSERT_TRUE(StartTestServer()); |
106 | 107 |
107 ResultCatcher catcher; | 108 ResultCatcher catcher; |
108 | 109 |
109 // Open incognito window and navigate to test page. | 110 // Open incognito window and navigate to test page. |
110 ui_test_utils::OpenURLOffTheRecord( | 111 ui_test_utils::OpenURLOffTheRecord( |
111 browser()->profile(), | 112 browser()->profile(), |
112 test_server()->GetURL("files/extensions/test_file.html")); | 113 embedded_test_server()->GetURL("/extensions/test_file.html")); |
113 | 114 |
114 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 115 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
115 .AppendASCII("incognito").AppendASCII("apis"))); | 116 .AppendASCII("incognito").AppendASCII("apis"))); |
116 | 117 |
117 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 118 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
118 } | 119 } |
119 | 120 |
120 // Tests that the APIs in an incognito-enabled split-mode extension work | 121 // Tests that the APIs in an incognito-enabled split-mode extension work |
121 // properly. | 122 // properly. |
122 #if defined(OS_WIN) | 123 #if defined(OS_WIN) |
(...skipping 12 matching lines...) Expand all Loading... |
135 ResultCatcher catcher_incognito; | 136 ResultCatcher catcher_incognito; |
136 catcher_incognito.RestrictToProfile( | 137 catcher_incognito.RestrictToProfile( |
137 browser()->profile()->GetOffTheRecordProfile()); | 138 browser()->profile()->GetOffTheRecordProfile()); |
138 | 139 |
139 ExtensionTestMessageListener listener("waiting", true); | 140 ExtensionTestMessageListener listener("waiting", true); |
140 ExtensionTestMessageListener listener_incognito("waiting_incognito", true); | 141 ExtensionTestMessageListener listener_incognito("waiting_incognito", true); |
141 | 142 |
142 // Open incognito window and navigate to test page. | 143 // Open incognito window and navigate to test page. |
143 ui_test_utils::OpenURLOffTheRecord( | 144 ui_test_utils::OpenURLOffTheRecord( |
144 browser()->profile(), | 145 browser()->profile(), |
145 test_server()->GetURL("files/extensions/test_file.html")); | 146 embedded_test_server()->GetURL("/extensions/test_file.html")); |
146 | 147 |
147 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 148 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
148 .AppendASCII("incognito").AppendASCII("split"))); | 149 .AppendASCII("incognito").AppendASCII("split"))); |
149 | 150 |
150 // Wait for both extensions to be ready before telling them to proceed. | 151 // Wait for both extensions to be ready before telling them to proceed. |
151 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 152 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
152 EXPECT_TRUE(listener_incognito.WaitUntilSatisfied()); | 153 EXPECT_TRUE(listener_incognito.WaitUntilSatisfied()); |
153 listener.Reply("go"); | 154 listener.Reply("go"); |
154 listener_incognito.Reply("go"); | 155 listener_incognito.Reply("go"); |
155 | 156 |
(...skipping 10 matching lines...) Expand all Loading... |
166 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) { | 167 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) { |
167 #endif | 168 #endif |
168 host_resolver()->AddRule("*", "127.0.0.1"); | 169 host_resolver()->AddRule("*", "127.0.0.1"); |
169 ASSERT_TRUE(StartTestServer()); | 170 ASSERT_TRUE(StartTestServer()); |
170 | 171 |
171 ResultCatcher catcher; | 172 ResultCatcher catcher; |
172 | 173 |
173 // Open incognito window and navigate to test page. | 174 // Open incognito window and navigate to test page. |
174 ui_test_utils::OpenURLOffTheRecord( | 175 ui_test_utils::OpenURLOffTheRecord( |
175 browser()->profile(), | 176 browser()->profile(), |
176 test_server()->GetURL("files/extensions/test_file.html")); | 177 embedded_test_server()->GetURL("/extensions/test_file.html")); |
177 | 178 |
178 ASSERT_TRUE(LoadExtension(test_data_dir_ | 179 ASSERT_TRUE(LoadExtension(test_data_dir_ |
179 .AppendASCII("incognito").AppendASCII("apis_disabled"))); | 180 .AppendASCII("incognito").AppendASCII("apis_disabled"))); |
180 | 181 |
181 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 182 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
182 } | 183 } |
183 | 184 |
184 #if defined(OS_WIN) || defined(OS_MACOSX) | 185 #if defined(OS_WIN) || defined(OS_MACOSX) |
185 // http://crbug.com/104438. | 186 // http://crbug.com/104438. |
186 #define MAYBE_IncognitoPopup DISABLED_IncognitoPopup | 187 #define MAYBE_IncognitoPopup DISABLED_IncognitoPopup |
187 #else | 188 #else |
188 #define MAYBE_IncognitoPopup IncognitoPopup | 189 #define MAYBE_IncognitoPopup IncognitoPopup |
189 #endif | 190 #endif |
190 // Test that opening a popup from an incognito browser window works properly. | 191 // Test that opening a popup from an incognito browser window works properly. |
191 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_IncognitoPopup) { | 192 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_IncognitoPopup) { |
192 host_resolver()->AddRule("*", "127.0.0.1"); | 193 host_resolver()->AddRule("*", "127.0.0.1"); |
193 ASSERT_TRUE(StartTestServer()); | 194 ASSERT_TRUE(StartTestServer()); |
194 | 195 |
195 ResultCatcher catcher; | 196 ResultCatcher catcher; |
196 | 197 |
197 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 198 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
198 .AppendASCII("incognito").AppendASCII("popup"))); | 199 .AppendASCII("incognito").AppendASCII("popup"))); |
199 | 200 |
200 // Open incognito window and navigate to test page. | 201 // Open incognito window and navigate to test page. |
201 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 202 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( |
202 browser()->profile(), | 203 browser()->profile(), |
203 test_server()->GetURL("files/extensions/test_file.html")); | 204 embedded_test_server()->GetURL("/extensions/test_file.html")); |
204 | 205 |
205 // Simulate the incognito's browser action being clicked. | 206 // Simulate the incognito's browser action being clicked. |
206 BrowserActionTestUtil(incognito_browser).Press(0); | 207 BrowserActionTestUtil(incognito_browser).Press(0); |
207 | 208 |
208 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 209 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
209 } | 210 } |
OLD | NEW |