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/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) { | 24 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) { |
25 ASSERT_TRUE(StartEmbeddedTestServer()); | 25 ASSERT_TRUE(StartEmbeddedTestServer()); |
26 | 26 |
27 // Loads a simple extension which attempts to change the title of every page | 27 // Loads a simple extension which attempts to change the title of every page |
28 // that loads to "modified". | 28 // that loads to "modified". |
29 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito") | 29 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito") |
30 .AppendASCII("content_scripts"))); | 30 .AppendASCII("content_scripts"))); |
31 | 31 |
32 // Open incognito window and navigate to test page. | 32 // Open incognito window and navigate to test page. |
33 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( | 33 Browser* otr_browser = OpenURLOffTheRecord( |
34 browser()->profile(), | 34 browser()->profile(), |
35 embedded_test_server()->GetURL("/extensions/test_file.html")); | 35 embedded_test_server()->GetURL("/extensions/test_file.html")); |
36 | 36 |
37 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); | 37 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); |
38 | 38 |
39 // Verify the script didn't run. | 39 // Verify the script didn't run. |
40 bool result = false; | 40 bool result = false; |
41 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 41 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
42 tab, | 42 tab, |
43 "window.domAutomationController.send(document.title == 'Unmodified')", | 43 "window.domAutomationController.send(document.title == 'Unmodified')", |
(...skipping 21 matching lines...) Expand all Loading... |
65 // Loads a simple extension which attempts to change the title of every page | 65 // Loads a simple extension which attempts to change the title of every page |
66 // that loads to "modified". | 66 // that loads to "modified". |
67 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 67 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
68 .AppendASCII("incognito").AppendASCII("content_scripts"))); | 68 .AppendASCII("incognito").AppendASCII("content_scripts"))); |
69 | 69 |
70 // Dummy extension #2. | 70 // Dummy extension #2. |
71 ASSERT_TRUE(LoadExtension(test_data_dir_ | 71 ASSERT_TRUE(LoadExtension(test_data_dir_ |
72 .AppendASCII("content_scripts").AppendASCII("isolated_world1"))); | 72 .AppendASCII("content_scripts").AppendASCII("isolated_world1"))); |
73 | 73 |
74 // Open incognito window and navigate to test page. | 74 // Open incognito window and navigate to test page. |
75 Browser* otr_browser = ui_test_utils::OpenURLOffTheRecord( | 75 Browser* otr_browser = OpenURLOffTheRecord( |
76 browser()->profile(), | 76 browser()->profile(), |
77 embedded_test_server()->GetURL("/extensions/test_file.html")); | 77 embedded_test_server()->GetURL("/extensions/test_file.html")); |
78 | 78 |
79 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); | 79 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); |
80 | 80 |
81 // Verify the script ran. | 81 // Verify the script ran. |
82 bool result = false; | 82 bool result = false; |
83 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 83 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
84 tab, | 84 tab, |
85 "window.domAutomationController.send(document.title == 'modified')", | 85 "window.domAutomationController.send(document.title == 'modified')", |
(...skipping 16 matching lines...) Expand all Loading... |
102 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Incognito) { | 102 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Incognito) { |
103 #else | 103 #else |
104 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) { | 104 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) { |
105 #endif | 105 #endif |
106 host_resolver()->AddRule("*", "127.0.0.1"); | 106 host_resolver()->AddRule("*", "127.0.0.1"); |
107 ASSERT_TRUE(StartEmbeddedTestServer()); | 107 ASSERT_TRUE(StartEmbeddedTestServer()); |
108 | 108 |
109 ResultCatcher catcher; | 109 ResultCatcher catcher; |
110 | 110 |
111 // Open incognito window and navigate to test page. | 111 // Open incognito window and navigate to test page. |
112 ui_test_utils::OpenURLOffTheRecord( | 112 OpenURLOffTheRecord( |
113 browser()->profile(), | 113 browser()->profile(), |
114 embedded_test_server()->GetURL("/extensions/test_file.html")); | 114 embedded_test_server()->GetURL("/extensions/test_file.html")); |
115 | 115 |
116 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 116 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
117 .AppendASCII("incognito").AppendASCII("apis"))); | 117 .AppendASCII("incognito").AppendASCII("apis"))); |
118 | 118 |
119 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 119 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
120 } | 120 } |
121 | 121 |
122 // Tests that the APIs in an incognito-enabled split-mode extension work | 122 // Tests that the APIs in an incognito-enabled split-mode extension work |
123 // properly. | 123 // properly. |
124 // http://crbug.com/120484 | 124 // http://crbug.com/120484 |
125 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoSplitMode) { | 125 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoSplitMode) { |
126 host_resolver()->AddRule("*", "127.0.0.1"); | 126 host_resolver()->AddRule("*", "127.0.0.1"); |
127 ASSERT_TRUE(StartEmbeddedTestServer()); | 127 ASSERT_TRUE(StartEmbeddedTestServer()); |
128 | 128 |
129 // We need 2 ResultCatchers because we'll be running the same test in both | 129 // We need 2 ResultCatchers because we'll be running the same test in both |
130 // regular and incognito mode. | 130 // regular and incognito mode. |
131 ResultCatcher catcher; | 131 ResultCatcher catcher; |
132 catcher.RestrictToBrowserContext(browser()->profile()); | 132 catcher.RestrictToBrowserContext(browser()->profile()); |
133 ResultCatcher catcher_incognito; | 133 ResultCatcher catcher_incognito; |
134 catcher_incognito.RestrictToBrowserContext( | 134 catcher_incognito.RestrictToBrowserContext( |
135 browser()->profile()->GetOffTheRecordProfile()); | 135 browser()->profile()->GetOffTheRecordProfile()); |
136 | 136 |
137 ExtensionTestMessageListener listener("waiting", true); | 137 ExtensionTestMessageListener listener("waiting", true); |
138 ExtensionTestMessageListener listener_incognito("waiting_incognito", true); | 138 ExtensionTestMessageListener listener_incognito("waiting_incognito", true); |
139 | 139 |
140 // Open incognito window and navigate to test page. | 140 // Open incognito window and navigate to test page. |
141 ui_test_utils::OpenURLOffTheRecord( | 141 OpenURLOffTheRecord(browser()->profile(), embedded_test_server()->GetURL( |
142 browser()->profile(), | 142 "/extensions/test_file.html")); |
143 embedded_test_server()->GetURL("/extensions/test_file.html")); | |
144 | 143 |
145 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 144 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
146 .AppendASCII("incognito").AppendASCII("split"))); | 145 .AppendASCII("incognito").AppendASCII("split"))); |
147 | 146 |
148 // Wait for both extensions to be ready before telling them to proceed. | 147 // Wait for both extensions to be ready before telling them to proceed. |
149 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 148 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
150 EXPECT_TRUE(listener_incognito.WaitUntilSatisfied()); | 149 EXPECT_TRUE(listener_incognito.WaitUntilSatisfied()); |
151 listener.Reply("go"); | 150 listener.Reply("go"); |
152 listener_incognito.Reply("go"); | 151 listener_incognito.Reply("go"); |
153 | 152 |
154 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 153 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
155 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); | 154 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); |
156 } | 155 } |
157 | 156 |
158 // Tests that the APIs in an incognito-disabled extension don't see incognito | 157 // Tests that the APIs in an incognito-disabled extension don't see incognito |
159 // events or callbacks. | 158 // events or callbacks. |
160 #if defined(OS_WIN) | 159 #if defined(OS_WIN) |
161 // http://crbug.com/120484 | 160 // http://crbug.com/120484 |
162 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoDisabled) { | 161 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoDisabled) { |
163 #else | 162 #else |
164 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) { | 163 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) { |
165 #endif | 164 #endif |
166 host_resolver()->AddRule("*", "127.0.0.1"); | 165 host_resolver()->AddRule("*", "127.0.0.1"); |
167 ASSERT_TRUE(StartEmbeddedTestServer()); | 166 ASSERT_TRUE(StartEmbeddedTestServer()); |
168 | 167 |
169 ResultCatcher catcher; | 168 ResultCatcher catcher; |
170 ExtensionTestMessageListener listener("createIncognitoTab", true); | 169 ExtensionTestMessageListener listener("createIncognitoTab", true); |
171 | 170 |
172 // Open incognito window and navigate to test page. | 171 // Open incognito window and navigate to test page. |
173 ui_test_utils::OpenURLOffTheRecord( | 172 OpenURLOffTheRecord(browser()->profile(), embedded_test_server()->GetURL( |
174 browser()->profile(), | 173 "/extensions/test_file.html")); |
175 embedded_test_server()->GetURL("/extensions/test_file.html")); | |
176 | 174 |
177 ASSERT_TRUE(LoadExtension(test_data_dir_ | 175 ASSERT_TRUE(LoadExtension(test_data_dir_ |
178 .AppendASCII("incognito").AppendASCII("apis_disabled"))); | 176 .AppendASCII("incognito").AppendASCII("apis_disabled"))); |
179 | 177 |
180 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 178 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
181 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), | 179 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
182 GURL("about:blank")); | |
183 listener.Reply("created"); | 180 listener.Reply("created"); |
184 | 181 |
185 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 182 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
186 } | 183 } |
187 | 184 |
188 // Test that opening a popup from an incognito browser window works properly. | 185 // Test that opening a popup from an incognito browser window works properly. |
189 // http://crbug.com/180759. | 186 // http://crbug.com/180759. |
190 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoPopup) { | 187 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoPopup) { |
191 host_resolver()->AddRule("*", "127.0.0.1"); | 188 host_resolver()->AddRule("*", "127.0.0.1"); |
192 ASSERT_TRUE(StartEmbeddedTestServer()); | 189 ASSERT_TRUE(StartEmbeddedTestServer()); |
193 | 190 |
194 ResultCatcher catcher; | 191 ResultCatcher catcher; |
195 | 192 |
196 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 193 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
197 .AppendASCII("incognito").AppendASCII("popup"))); | 194 .AppendASCII("incognito").AppendASCII("popup"))); |
198 | 195 |
199 // Open incognito window and navigate to test page. | 196 // Open incognito window and navigate to test page. |
200 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 197 Browser* incognito_browser = OpenURLOffTheRecord( |
201 browser()->profile(), | 198 browser()->profile(), |
202 embedded_test_server()->GetURL("/extensions/test_file.html")); | 199 embedded_test_server()->GetURL("/extensions/test_file.html")); |
203 | 200 |
204 // Simulate the incognito's browser action being clicked. | 201 // Simulate the incognito's browser action being clicked. |
205 BrowserActionTestUtil(incognito_browser).Press(0); | 202 BrowserActionTestUtil(incognito_browser).Press(0); |
206 | 203 |
207 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 204 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
208 } | 205 } |
OLD | NEW |