Chromium Code Reviews| 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(browser()->profile(), embedded_test_server()->GetURL( |
| 113 browser()->profile(), | 113 "/extensions/test_file.html")); |
|
James Hawkins
2015/07/13 18:22:23
Indentation is off.
erikchen
2015/07/13 19:39:21
That was the output from clang format. I've manual
| |
| 114 embedded_test_server()->GetURL("/extensions/test_file.html")); | |
| 115 | 114 |
| 116 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 115 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
| 117 .AppendASCII("incognito").AppendASCII("apis"))); | 116 .AppendASCII("incognito").AppendASCII("apis"))); |
| 118 | 117 |
| 119 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 118 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 120 } | 119 } |
| 121 | 120 |
| 122 // 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 |
| 123 // properly. | 122 // properly. |
| 124 // http://crbug.com/120484 | 123 // http://crbug.com/120484 |
| 125 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoSplitMode) { | 124 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoSplitMode) { |
| 126 host_resolver()->AddRule("*", "127.0.0.1"); | 125 host_resolver()->AddRule("*", "127.0.0.1"); |
| 127 ASSERT_TRUE(StartEmbeddedTestServer()); | 126 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 128 | 127 |
| 129 // 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 |
| 130 // regular and incognito mode. | 129 // regular and incognito mode. |
| 131 ResultCatcher catcher; | 130 ResultCatcher catcher; |
| 132 catcher.RestrictToBrowserContext(browser()->profile()); | 131 catcher.RestrictToBrowserContext(browser()->profile()); |
| 133 ResultCatcher catcher_incognito; | 132 ResultCatcher catcher_incognito; |
| 134 catcher_incognito.RestrictToBrowserContext( | 133 catcher_incognito.RestrictToBrowserContext( |
| 135 browser()->profile()->GetOffTheRecordProfile()); | 134 browser()->profile()->GetOffTheRecordProfile()); |
| 136 | 135 |
| 137 ExtensionTestMessageListener listener("waiting", true); | 136 ExtensionTestMessageListener listener("waiting", true); |
| 138 ExtensionTestMessageListener listener_incognito("waiting_incognito", true); | 137 ExtensionTestMessageListener listener_incognito("waiting_incognito", true); |
| 139 | 138 |
| 140 // Open incognito window and navigate to test page. | 139 // Open incognito window and navigate to test page. |
| 141 ui_test_utils::OpenURLOffTheRecord( | 140 OpenURLOffTheRecord(browser()->profile(), embedded_test_server()->GetURL( |
| 142 browser()->profile(), | 141 "/extensions/test_file.html")); |
| 143 embedded_test_server()->GetURL("/extensions/test_file.html")); | |
| 144 | 142 |
| 145 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 143 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
| 146 .AppendASCII("incognito").AppendASCII("split"))); | 144 .AppendASCII("incognito").AppendASCII("split"))); |
| 147 | 145 |
| 148 // Wait for both extensions to be ready before telling them to proceed. | 146 // Wait for both extensions to be ready before telling them to proceed. |
| 149 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 147 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 150 EXPECT_TRUE(listener_incognito.WaitUntilSatisfied()); | 148 EXPECT_TRUE(listener_incognito.WaitUntilSatisfied()); |
| 151 listener.Reply("go"); | 149 listener.Reply("go"); |
| 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(ExtensionApiTest, DISABLED_IncognitoDisabled) { |
| 163 #else | 161 #else |
| 164 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) { | 162 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, IncognitoDisabled) { |
| 165 #endif | 163 #endif |
| 166 host_resolver()->AddRule("*", "127.0.0.1"); | 164 host_resolver()->AddRule("*", "127.0.0.1"); |
| 167 ASSERT_TRUE(StartEmbeddedTestServer()); | 165 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 168 | 166 |
| 169 ResultCatcher catcher; | 167 ResultCatcher catcher; |
| 170 ExtensionTestMessageListener listener("createIncognitoTab", true); | 168 ExtensionTestMessageListener listener("createIncognitoTab", true); |
| 171 | 169 |
| 172 // Open incognito window and navigate to test page. | 170 // Open incognito window and navigate to test page. |
| 173 ui_test_utils::OpenURLOffTheRecord( | 171 OpenURLOffTheRecord(browser()->profile(), embedded_test_server()->GetURL( |
| 174 browser()->profile(), | 172 "/extensions/test_file.html")); |
| 175 embedded_test_server()->GetURL("/extensions/test_file.html")); | |
| 176 | 173 |
| 177 ASSERT_TRUE(LoadExtension(test_data_dir_ | 174 ASSERT_TRUE(LoadExtension(test_data_dir_ |
| 178 .AppendASCII("incognito").AppendASCII("apis_disabled"))); | 175 .AppendASCII("incognito").AppendASCII("apis_disabled"))); |
| 179 | 176 |
| 180 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 177 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 181 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), | 178 OpenURLOffTheRecord(browser()->profile(), GURL("about:blank")); |
| 182 GURL("about:blank")); | |
| 183 listener.Reply("created"); | 179 listener.Reply("created"); |
| 184 | 180 |
| 185 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 181 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 186 } | 182 } |
| 187 | 183 |
| 188 // Test that opening a popup from an incognito browser window works properly. | 184 // Test that opening a popup from an incognito browser window works properly. |
| 189 // http://crbug.com/180759. | 185 // http://crbug.com/180759. |
| 190 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoPopup) { | 186 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_IncognitoPopup) { |
| 191 host_resolver()->AddRule("*", "127.0.0.1"); | 187 host_resolver()->AddRule("*", "127.0.0.1"); |
| 192 ASSERT_TRUE(StartEmbeddedTestServer()); | 188 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 193 | 189 |
| 194 ResultCatcher catcher; | 190 ResultCatcher catcher; |
| 195 | 191 |
| 196 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 192 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
| 197 .AppendASCII("incognito").AppendASCII("popup"))); | 193 .AppendASCII("incognito").AppendASCII("popup"))); |
| 198 | 194 |
| 199 // Open incognito window and navigate to test page. | 195 // Open incognito window and navigate to test page. |
| 200 Browser* incognito_browser = ui_test_utils::OpenURLOffTheRecord( | 196 Browser* incognito_browser = OpenURLOffTheRecord( |
| 201 browser()->profile(), | 197 browser()->profile(), |
| 202 embedded_test_server()->GetURL("/extensions/test_file.html")); | 198 embedded_test_server()->GetURL("/extensions/test_file.html")); |
| 203 | 199 |
| 204 // Simulate the incognito's browser action being clicked. | 200 // Simulate the incognito's browser action being clicked. |
| 205 BrowserActionTestUtil(incognito_browser).Press(0); | 201 BrowserActionTestUtil(incognito_browser).Press(0); |
| 206 | 202 |
| 207 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 203 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 208 } | 204 } |
| OLD | NEW |