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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 #include "chrome/browser/extensions/browser_action_test_util.h" | 6 #include "chrome/browser/extensions/browser_action_test_util.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/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.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 "extensions/test/extension_test_message_listener.h" | 17 #include "extensions/test/extension_test_message_listener.h" |
18 #include "extensions/test/result_catcher.h" | 18 #include "extensions/test/result_catcher.h" |
19 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
20 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
21 | 21 |
22 using content::WebContents; | 22 using content::WebContents; |
23 using extensions::ResultCatcher; | 23 using extensions::ResultCatcher; |
24 | 24 |
25 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoNoScript) { | 25 class IncognitoApiTest : public ExtensionApiTest { |
26 ASSERT_TRUE(StartEmbeddedTestServer()); | 26 public: |
| 27 void SetUpOnMainThread() override { |
| 28 ExtensionApiTest::SetUpOnMainThread(); |
| 29 host_resolver()->AddRule("*", "127.0.0.1"); |
| 30 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 31 } |
| 32 }; |
27 | 33 |
| 34 IN_PROC_BROWSER_TEST_F(IncognitoApiTest, IncognitoNoScript) { |
28 // Loads a simple extension which attempts to change the title of every page | 35 // Loads a simple extension which attempts to change the title of every page |
29 // that loads to "modified". | 36 // that loads to "modified". |
30 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito") | 37 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("incognito") |
31 .AppendASCII("content_scripts"))); | 38 .AppendASCII("content_scripts"))); |
32 | 39 |
33 // Open incognito window and navigate to test page. | 40 // Open incognito window and navigate to test page. |
34 Browser* otr_browser = OpenURLOffTheRecord( | 41 Browser* otr_browser = OpenURLOffTheRecord( |
35 browser()->profile(), | 42 browser()->profile(), |
36 embedded_test_server()->GetURL("/extensions/test_file.html")); | 43 embedded_test_server()->GetURL("/extensions/test_file.html")); |
37 | 44 |
38 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); | 45 WebContents* tab = otr_browser->tab_strip_model()->GetActiveWebContents(); |
39 | 46 |
40 // Verify the script didn't run. | 47 // Verify the script didn't run. |
41 bool result = false; | 48 bool result = false; |
42 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 49 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
43 tab, | 50 tab, |
44 "window.domAutomationController.send(document.title == 'Unmodified')", | 51 "window.domAutomationController.send(document.title == 'Unmodified')", |
45 &result)); | 52 &result)); |
46 EXPECT_TRUE(result); | 53 EXPECT_TRUE(result); |
47 } | 54 } |
48 | 55 |
49 #if defined(OS_WIN) | 56 #if defined(OS_WIN) |
50 // This test is very flaky on XP. http://crbug.com/248821 | 57 // This test is very flaky on XP. http://crbug.com/248821 |
51 #define MAYBE_IncognitoYesScript DISABLED_IncognitoYesScript | 58 #define MAYBE_IncognitoYesScript DISABLED_IncognitoYesScript |
52 #else | 59 #else |
53 #define MAYBE_IncognitoYesScript IncognitoYesScript | 60 #define MAYBE_IncognitoYesScript IncognitoYesScript |
54 #endif | 61 #endif |
55 | 62 |
56 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_IncognitoYesScript) { | 63 IN_PROC_BROWSER_TEST_F(IncognitoApiTest, MAYBE_IncognitoYesScript) { |
57 host_resolver()->AddRule("*", "127.0.0.1"); | |
58 ASSERT_TRUE(StartEmbeddedTestServer()); | |
59 | |
60 // Load a dummy extension. This just tests that we don't regress a | 64 // Load a dummy extension. This just tests that we don't regress a |
61 // crash fix when multiple incognito- and non-incognito-enabled extensions | 65 // crash fix when multiple incognito- and non-incognito-enabled extensions |
62 // are mixed. | 66 // are mixed. |
63 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts") | 67 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("content_scripts") |
64 .AppendASCII("all_frames"))); | 68 .AppendASCII("all_frames"))); |
65 | 69 |
66 // Loads a simple extension which attempts to change the title of every page | 70 // Loads a simple extension which attempts to change the title of every page |
67 // that loads to "modified". | 71 // that loads to "modified". |
68 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 72 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
69 .AppendASCII("incognito").AppendASCII("content_scripts"))); | 73 .AppendASCII("incognito").AppendASCII("content_scripts"))); |
(...skipping 14 matching lines...) Expand all Loading... |
84 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( | 88 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
85 tab, | 89 tab, |
86 "window.domAutomationController.send(document.title == 'modified')", | 90 "window.domAutomationController.send(document.title == 'modified')", |
87 &result)); | 91 &result)); |
88 EXPECT_TRUE(result); | 92 EXPECT_TRUE(result); |
89 } | 93 } |
90 | 94 |
91 // Tests that an extension which is enabled for incognito mode doesn't | 95 // Tests that an extension which is enabled for incognito mode doesn't |
92 // accidentially create and incognito profile. | 96 // accidentially create and incognito profile. |
93 // Test disabled due to http://crbug.com/89054. | 97 // Test disabled due to http://crbug.com/89054. |
94 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_DontCreateIncognitoProfile) { | 98 IN_PROC_BROWSER_TEST_F(IncognitoApiTest, DISABLED_DontCreateIncognitoProfile) { |
95 ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile()); | 99 ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile()); |
96 ASSERT_TRUE(RunExtensionTestIncognito( | 100 ASSERT_TRUE(RunExtensionTestIncognito( |
97 "incognito/dont_create_profile")) << message_; | 101 "incognito/dont_create_profile")) << message_; |
98 ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile()); | 102 ASSERT_FALSE(browser()->profile()->HasOffTheRecordProfile()); |
99 } | 103 } |
100 | 104 |
101 #if defined(OS_WIN) || defined(OS_MACOSX) | 105 #if defined(OS_WIN) || defined(OS_MACOSX) |
102 // http://crbug.com/120484 | 106 // http://crbug.com/120484 |
103 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Incognito) { | 107 IN_PROC_BROWSER_TEST_F(IncognitoApiTest, DISABLED_Incognito) { |
104 #else | 108 #else |
105 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, Incognito) { | 109 IN_PROC_BROWSER_TEST_F(IncognitoApiTest, Incognito) { |
106 #endif | 110 #endif |
107 host_resolver()->AddRule("*", "127.0.0.1"); | |
108 ASSERT_TRUE(StartEmbeddedTestServer()); | |
109 | |
110 ResultCatcher catcher; | 111 ResultCatcher catcher; |
111 | 112 |
112 // Open incognito window and navigate to test page. | 113 // Open incognito window and navigate to test page. |
113 OpenURLOffTheRecord( | 114 OpenURLOffTheRecord( |
114 browser()->profile(), | 115 browser()->profile(), |
115 embedded_test_server()->GetURL("/extensions/test_file.html")); | 116 embedded_test_server()->GetURL("/extensions/test_file.html")); |
116 | 117 |
117 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 118 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
118 .AppendASCII("incognito").AppendASCII("apis"))); | 119 .AppendASCII("incognito").AppendASCII("apis"))); |
119 | 120 |
120 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 121 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
121 } | 122 } |
122 | 123 |
123 // Tests that the APIs in an incognito-enabled split-mode extension work | 124 // Tests that the APIs in an incognito-enabled split-mode extension work |
124 // properly. | 125 // properly. |
125 // http://crbug.com/120484 | 126 // http://crbug.com/120484 |
126 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoSplitMode) { | 127 IN_PROC_BROWSER_TEST_F(IncognitoApiTest, DISABLED_IncognitoSplitMode) { |
127 host_resolver()->AddRule("*", "127.0.0.1"); | |
128 ASSERT_TRUE(StartEmbeddedTestServer()); | |
129 | |
130 // We need 2 ResultCatchers because we'll be running the same test in both | 128 // We need 2 ResultCatchers because we'll be running the same test in both |
131 // regular and incognito mode. | 129 // regular and incognito mode. |
132 ResultCatcher catcher; | 130 ResultCatcher catcher; |
133 catcher.RestrictToBrowserContext(browser()->profile()); | 131 catcher.RestrictToBrowserContext(browser()->profile()); |
134 ResultCatcher catcher_incognito; | 132 ResultCatcher catcher_incognito; |
135 catcher_incognito.RestrictToBrowserContext( | 133 catcher_incognito.RestrictToBrowserContext( |
136 browser()->profile()->GetOffTheRecordProfile()); | 134 browser()->profile()->GetOffTheRecordProfile()); |
137 | 135 |
138 ExtensionTestMessageListener listener("waiting", true); | 136 ExtensionTestMessageListener listener("waiting", true); |
139 ExtensionTestMessageListener listener_incognito("waiting_incognito", true); | 137 ExtensionTestMessageListener listener_incognito("waiting_incognito", true); |
(...skipping 12 matching lines...) Expand all Loading... |
152 listener_incognito.Reply("go"); | 150 listener_incognito.Reply("go"); |
153 | 151 |
154 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 152 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
155 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); | 153 EXPECT_TRUE(catcher_incognito.GetNextResult()) << catcher.message(); |
156 } | 154 } |
157 | 155 |
158 // Tests that the APIs in an incognito-disabled extension don't see incognito | 156 // Tests that the APIs in an incognito-disabled extension don't see incognito |
159 // events or callbacks. | 157 // events or callbacks. |
160 #if defined(OS_WIN) | 158 #if defined(OS_WIN) |
161 // http://crbug.com/120484 | 159 // http://crbug.com/120484 |
162 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoDisabled) { | 160 IN_PROC_BROWSER_TEST_F(IncognitoApiTest, DISABLED_IncognitoDisabled) { |
163 #else | 161 #else |
164 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) { | 162 IN_PROC_BROWSER_TEST_F(IncognitoApiTest, IncognitoDisabled) { |
165 #endif | 163 #endif |
166 host_resolver()->AddRule("*", "127.0.0.1"); | |
167 ASSERT_TRUE(StartEmbeddedTestServer()); | |
168 | |
169 ResultCatcher catcher; | 164 ResultCatcher catcher; |
170 ExtensionTestMessageListener listener("createIncognitoTab", true); | 165 ExtensionTestMessageListener listener("createIncognitoTab", true); |
171 | 166 |
172 // Open incognito window and navigate to test page. | 167 // Open incognito window and navigate to test page. |
173 OpenURLOffTheRecord(browser()->profile(), embedded_test_server()->GetURL( | 168 OpenURLOffTheRecord(browser()->profile(), embedded_test_server()->GetURL( |
174 "/extensions/test_file.html")); | 169 "/extensions/test_file.html")); |
175 | 170 |
176 ASSERT_TRUE(LoadExtension(test_data_dir_ | 171 ASSERT_TRUE(LoadExtension(test_data_dir_ |
177 .AppendASCII("incognito").AppendASCII("apis_disabled"))); | 172 .AppendASCII("incognito").AppendASCII("apis_disabled"))); |
178 | 173 |
179 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 174 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
180 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); | 175 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
181 listener.Reply("created"); | 176 listener.Reply("created"); |
182 | 177 |
183 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 178 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
184 } | 179 } |
185 | 180 |
186 // Test that opening a popup from an incognito browser window works properly. | 181 // Test that opening a popup from an incognito browser window works properly. |
187 // http://crbug.com/180759. | 182 // http://crbug.com/180759. |
188 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoPopup) { | 183 IN_PROC_BROWSER_TEST_F(IncognitoApiTest, DISABLED_IncognitoPopup) { |
189 host_resolver()->AddRule("*", "127.0.0.1"); | |
190 ASSERT_TRUE(StartEmbeddedTestServer()); | |
191 | |
192 ResultCatcher catcher; | 184 ResultCatcher catcher; |
193 | 185 |
194 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 186 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
195 .AppendASCII("incognito").AppendASCII("popup"))); | 187 .AppendASCII("incognito").AppendASCII("popup"))); |
196 | 188 |
197 // Open incognito window and navigate to test page. | 189 // Open incognito window and navigate to test page. |
198 Browser* incognito_browser = OpenURLOffTheRecord( | 190 Browser* incognito_browser = OpenURLOffTheRecord( |
199 browser()->profile(), | 191 browser()->profile(), |
200 embedded_test_server()->GetURL("/extensions/test_file.html")); | 192 embedded_test_server()->GetURL("/extensions/test_file.html")); |
201 | 193 |
202 // Simulate the incognito's browser action being clicked. | 194 // Simulate the incognito's browser action being clicked. |
203 BrowserActionTestUtil(incognito_browser).Press(0); | 195 BrowserActionTestUtil(incognito_browser).Press(0); |
204 | 196 |
205 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 197 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
206 } | 198 } |
OLD | NEW |