| 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/extension_apitest.h" | 5 #include "chrome/browser/extensions/extension_apitest.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_test_api.h" | 10 #include "chrome/browser/extensions/extension_test_api.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return RunExtensionTestImpl(extension_name, "", kFlagNone); | 125 return RunExtensionTestImpl(extension_name, "", kFlagNone); |
| 126 } | 126 } |
| 127 | 127 |
| 128 bool ExtensionApiTest::RunExtensionTestIncognitoNoFileAccess( | 128 bool ExtensionApiTest::RunExtensionTestIncognitoNoFileAccess( |
| 129 const char* extension_name) { | 129 const char* extension_name) { |
| 130 return RunExtensionTestImpl(extension_name, "", kFlagEnableIncognito); | 130 return RunExtensionTestImpl(extension_name, "", kFlagEnableIncognito); |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool ExtensionApiTest::RunExtensionSubtest(const char* extension_name, | 133 bool ExtensionApiTest::RunExtensionSubtest(const char* extension_name, |
| 134 const std::string& page_url) { | 134 const std::string& page_url) { |
| 135 DCHECK(!page_url.empty()) << "Argument page_url is required."; | 135 return RunExtensionSubtest(extension_name, page_url, kFlagEnableFileAccess); |
| 136 return RunExtensionTestImpl(extension_name, page_url, kFlagEnableFileAccess); | |
| 137 } | 136 } |
| 138 | 137 |
| 139 bool ExtensionApiTest::RunComponentExtensionSubtest( | 138 bool ExtensionApiTest::RunExtensionSubtest(const char* extension_name, |
| 140 const char* extension_name, | 139 const std::string& page_url, |
| 141 const std::string& page_url) { | 140 int flags) { |
| 142 DCHECK(!page_url.empty()) << "Argument page_url is required."; | 141 DCHECK(!page_url.empty()) << "Argument page_url is required."; |
| 143 return RunExtensionTestImpl( | 142 return RunExtensionTestImpl(extension_name, page_url, flags); |
| 144 extension_name, page_url, kFlagEnableFileAccess | kFlagLoadAsComponent); | |
| 145 } | 143 } |
| 146 | 144 |
| 147 bool ExtensionApiTest::RunExtensionSubtestNoFileAccess( | |
| 148 const char* extension_name, | |
| 149 const std::string& page_url) { | |
| 150 DCHECK(!page_url.empty()) << "Argument page_url is required."; | |
| 151 return RunExtensionTestImpl(extension_name, page_url, kFlagNone); | |
| 152 } | |
| 153 | |
| 154 bool ExtensionApiTest::RunExtensionSubtestIncognito( | |
| 155 const char* extension_name, | |
| 156 const std::string& page_url) { | |
| 157 DCHECK(!page_url.empty()) << "Argument page_url is required."; | |
| 158 return RunExtensionTestImpl(extension_name, page_url, | |
| 159 kFlagEnableIncognito | kFlagEnableFileAccess); | |
| 160 } | |
| 161 | |
| 162 bool ExtensionApiTest::RunExtensionSubtestIncognitoNoFileAccess( | |
| 163 const char* extension_name, | |
| 164 const std::string& page_url) { | |
| 165 DCHECK(!page_url.empty()) << "Argument page_url is required."; | |
| 166 return RunExtensionTestImpl(extension_name, page_url, kFlagEnableIncognito); | |
| 167 } | |
| 168 | 145 |
| 169 bool ExtensionApiTest::RunPageTest(const std::string& page_url) { | 146 bool ExtensionApiTest::RunPageTest(const std::string& page_url) { |
| 170 return RunExtensionSubtest("", page_url); | 147 return RunExtensionSubtest("", page_url); |
| 171 } | 148 } |
| 172 | 149 |
| 173 bool ExtensionApiTest::RunPlatformAppTest(const char* extension_name) { | 150 bool ExtensionApiTest::RunPlatformAppTest(const char* extension_name) { |
| 174 return RunExtensionTestImpl(extension_name, "", kFlagLaunchAppShell); | 151 return RunExtensionTestImpl(extension_name, "", kFlagLaunchAppShell); |
| 175 } | 152 } |
| 176 | 153 |
| 177 // Load |extension_name| extension and/or |page_url| and wait for | 154 // Load |extension_name| extension and/or |page_url| and wait for |
| 178 // PASSED or FAILED notification. | 155 // PASSED or FAILED notification. |
| 179 bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name, | 156 bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name, |
| 180 const std::string& page_url, | 157 const std::string& page_url, |
| 181 int flags) { | 158 int flags) { |
| 182 bool enable_incognito = (flags & kFlagEnableIncognito) != 0; | 159 bool enable_incognito = (flags & kFlagEnableIncognito) != 0; |
| 183 bool enable_fileaccess = (flags & kFlagEnableFileAccess) != 0; | 160 bool enable_fileaccess = (flags & kFlagEnableFileAccess) != 0; |
| 184 bool load_as_component = (flags & kFlagLoadAsComponent) != 0; | 161 bool load_as_component = (flags & kFlagLoadAsComponent) != 0; |
| 185 bool launch_shell = (flags & kFlagLaunchAppShell) != 0; | 162 bool launch_shell = (flags & kFlagLaunchAppShell) != 0; |
| 163 bool use_incognito = (flags & kFlagUseIncognito) != 0; |
| 186 | 164 |
| 187 ResultCatcher catcher; | 165 ResultCatcher catcher; |
| 188 DCHECK(!std::string(extension_name).empty() || !page_url.empty()) << | 166 DCHECK(!std::string(extension_name).empty() || !page_url.empty()) << |
| 189 "extension_name and page_url cannot both be empty"; | 167 "extension_name and page_url cannot both be empty"; |
| 190 | 168 |
| 191 const Extension* extension = NULL; | 169 const Extension* extension = NULL; |
| 192 if (!std::string(extension_name).empty()) { | 170 if (!std::string(extension_name).empty()) { |
| 193 FilePath extension_path = test_data_dir_.AppendASCII(extension_name); | 171 FilePath extension_path = test_data_dir_.AppendASCII(extension_name); |
| 194 if (load_as_component) { | 172 if (load_as_component) { |
| 195 extension = LoadExtensionAsComponent(extension_path); | 173 extension = LoadExtensionAsComponent(extension_path); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 210 // Note: We use is_valid() here in the expectation that the provided url | 188 // Note: We use is_valid() here in the expectation that the provided url |
| 211 // may lack a scheme & host and thus be a relative url within the loaded | 189 // may lack a scheme & host and thus be a relative url within the loaded |
| 212 // extension. | 190 // extension. |
| 213 if (!url.is_valid()) { | 191 if (!url.is_valid()) { |
| 214 DCHECK(!std::string(extension_name).empty()) << | 192 DCHECK(!std::string(extension_name).empty()) << |
| 215 "Relative page_url given with no extension_name"; | 193 "Relative page_url given with no extension_name"; |
| 216 | 194 |
| 217 url = extension->GetResourceURL(page_url); | 195 url = extension->GetResourceURL(page_url); |
| 218 } | 196 } |
| 219 | 197 |
| 220 ui_test_utils::NavigateToURL(browser(), url); | 198 if (use_incognito) |
| 199 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), url); |
| 200 else |
| 201 ui_test_utils::NavigateToURL(browser(), url); |
| 221 | 202 |
| 222 } else if (launch_shell) { | 203 } else if (launch_shell) { |
| 223 Browser::OpenApplication( | 204 Browser::OpenApplication( |
| 224 browser()->profile(), | 205 browser()->profile(), |
| 225 extension, | 206 extension, |
| 226 extension_misc::LAUNCH_SHELL, | 207 extension_misc::LAUNCH_SHELL, |
| 227 GURL(), | 208 GURL(), |
| 228 NEW_WINDOW); | 209 NEW_WINDOW); |
| 229 } | 210 } |
| 230 | 211 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 return false; | 267 return false; |
| 287 | 268 |
| 288 test_config_->SetInteger(kTestWebSocketPort, port); | 269 test_config_->SetInteger(kTestWebSocketPort, port); |
| 289 return true; | 270 return true; |
| 290 } | 271 } |
| 291 | 272 |
| 292 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { | 273 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { |
| 293 ExtensionBrowserTest::SetUpCommandLine(command_line); | 274 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 294 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); | 275 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); |
| 295 } | 276 } |
| OLD | NEW |