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(StartEmbeddedTestServer()); |
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); |
44 } | 45 } |
45 | 46 |
46 #if defined(OS_WIN) | 47 #if defined(OS_WIN) |
47 // This test is very flaky on XP. http://crbug.com/248821 | 48 // This test is very flaky on XP. http://crbug.com/248821 |
48 #define MAYBE_IncognitoYesScript DISABLED_IncognitoYesScript | 49 #define MAYBE_IncognitoYesScript DISABLED_IncognitoYesScript |
49 #else | 50 #else |
50 #define MAYBE_IncognitoYesScript IncognitoYesScript | 51 #define MAYBE_IncognitoYesScript IncognitoYesScript |
51 #endif | 52 #endif |
52 | 53 |
53 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_IncognitoYesScript) { | 54 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_IncognitoYesScript) { |
54 host_resolver()->AddRule("*", "127.0.0.1"); | 55 host_resolver()->AddRule("*", "127.0.0.1"); |
55 ASSERT_TRUE(StartTestServer()); | 56 ASSERT_TRUE(StartEmbeddedTestServer()); |
56 | 57 |
57 // Load a dummy extension. This just tests that we don't regress a | 58 // Load a dummy extension. This just tests that we don't regress a |
58 // crash fix when multiple incognito- and non-incognito-enabled extensions | 59 // crash fix when multiple incognito- and non-incognito-enabled extensions |
59 // are mixed. | 60 // are mixed. |
60 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts") | 61 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts") |
61 .AppendASCII("all_frames"))); | 62 .AppendASCII("all_frames"))); |
62 | 63 |
63 // Loads a simple extension which attempts to change the title of every page | 64 // Loads a simple extension which attempts to change the title of every page |
64 // that loads to "modified". | 65 // that loads to "modified". |
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); |
86 } | 87 } |
87 | 88 |
88 // Tests that an extension which is enabled for incognito mode doesn't | 89 // Tests that an extension which is enabled for incognito mode doesn't |
89 // accidentially create and incognito profile. | 90 // accidentially create and incognito profile. |
90 // Test disabled due to http://crbug.com/89054. | 91 // Test disabled due to http://crbug.com/89054. |
91 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_DontCreateIncognitoProfile) { | 92 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_DontCreateIncognitoProfile) { |
92 ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile()); | 93 ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile()); |
93 ASSERT_TRUE(RunExtensionTestIncognito( | 94 ASSERT_TRUE(RunExtensionTestIncognito( |
94 "incognito/dont_create_profile")) << message_; | 95 "incognito/dont_create_profile")) << message_; |
95 ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile()); | 96 ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile()); |
96 } | 97 } |
97 | 98 |
98 #if defined(OS_WIN) || defined(OS_MACOSX) | 99 #if defined(OS_WIN) || defined(OS_MACOSX) |
99 // http://crbug.com/120484 | 100 // http://crbug.com/120484 |
100 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Incognito) { | 101 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Incognito) { |
101 #else | 102 #else |
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(StartEmbeddedTestServer()); |
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) |
123 // http://crbug.com/120484 | 124 // http://crbug.com/120484 |
124 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoSplitMode) { | 125 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoSplitMode) { |
125 #else | 126 #else |
126 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoSplitMode) { | 127 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoSplitMode) { |
127 #endif | 128 #endif |
128 host_resolver()->AddRule("*", "127.0.0.1"); | 129 host_resolver()->AddRule("*", "127.0.0.1"); |
129 ASSERT_TRUE(StartTestServer()); | 130 ASSERT_TRUE(StartEmbeddedTestServer()); |
130 | 131 |
131 // We need 2 ResultCatchers because we'll be running the same test in both | 132 // We need 2 ResultCatchers because we'll be running the same test in both |
132 // regular and incognito mode. | 133 // regular and incognito mode. |
133 ResultCatcher catcher; | 134 ResultCatcher catcher; |
134 catcher.RestrictToProfile(browser()->profile()); | 135 catcher.RestrictToProfile(browser()->profile()); |
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 |
156 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 157 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
157 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); | 158 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); |
158 } | 159 } |
159 | 160 |
160 // Tests that the APIs in an incognito-disabled extension don't see incognito | 161 // Tests that the APIs in an incognito-disabled extension don't see incognito |
161 // events or callbacks. | 162 // events or callbacks. |
162 #if defined(OS_WIN) | 163 #if defined(OS_WIN) |
163 // http://crbug.com/120484 | 164 // http://crbug.com/120484 |
164 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoDisabled) { | 165 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoDisabled) { |
165 #else | 166 #else |
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(StartEmbeddedTestServer()); |
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(StartEmbeddedTestServer()); |
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 |