| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 DCHECK(!page_url.empty()) << "Argument page_url is required."; | 144 DCHECK(!page_url.empty()) << "Argument page_url is required."; |
| 145 return RunExtensionTestImpl(extension_name, page_url, flags); | 145 return RunExtensionTestImpl(extension_name, page_url, flags); |
| 146 } | 146 } |
| 147 | 147 |
| 148 | 148 |
| 149 bool ExtensionApiTest::RunPageTest(const std::string& page_url) { | 149 bool ExtensionApiTest::RunPageTest(const std::string& page_url) { |
| 150 return RunExtensionSubtest("", page_url); | 150 return RunExtensionSubtest("", page_url); |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool ExtensionApiTest::RunPlatformAppTest(const char* extension_name) { | 153 bool ExtensionApiTest::RunPlatformAppTest(const char* extension_name) { |
| 154 return RunExtensionTestImpl(extension_name, "", kFlagLaunchAppShell); | 154 return RunExtensionTestImpl(extension_name, "", kFlagLaunchPlatformApp); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Load |extension_name| extension and/or |page_url| and wait for | 157 // Load |extension_name| extension and/or |page_url| and wait for |
| 158 // PASSED or FAILED notification. | 158 // PASSED or FAILED notification. |
| 159 bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name, | 159 bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name, |
| 160 const std::string& page_url, | 160 const std::string& page_url, |
| 161 int flags) { | 161 int flags) { |
| 162 bool enable_incognito = (flags & kFlagEnableIncognito) != 0; | 162 bool enable_incognito = (flags & kFlagEnableIncognito) != 0; |
| 163 bool enable_fileaccess = (flags & kFlagEnableFileAccess) != 0; | 163 bool enable_fileaccess = (flags & kFlagEnableFileAccess) != 0; |
| 164 bool load_as_component = (flags & kFlagLoadAsComponent) != 0; | 164 bool load_as_component = (flags & kFlagLoadAsComponent) != 0; |
| 165 bool launch_shell = (flags & kFlagLaunchAppShell) != 0; | 165 bool launch_platform_app = (flags & kFlagLaunchPlatformApp) != 0; |
| 166 bool use_incognito = (flags & kFlagUseIncognito) != 0; | 166 bool use_incognito = (flags & kFlagUseIncognito) != 0; |
| 167 | 167 |
| 168 ResultCatcher catcher; | 168 ResultCatcher catcher; |
| 169 DCHECK(!std::string(extension_name).empty() || !page_url.empty()) << | 169 DCHECK(!std::string(extension_name).empty() || !page_url.empty()) << |
| 170 "extension_name and page_url cannot both be empty"; | 170 "extension_name and page_url cannot both be empty"; |
| 171 | 171 |
| 172 const Extension* extension = NULL; | 172 const Extension* extension = NULL; |
| 173 if (!std::string(extension_name).empty()) { | 173 if (!std::string(extension_name).empty()) { |
| 174 FilePath extension_path = test_data_dir_.AppendASCII(extension_name); | 174 FilePath extension_path = test_data_dir_.AppendASCII(extension_name); |
| 175 if (load_as_component) { | 175 if (load_as_component) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 196 "Relative page_url given with no extension_name"; | 196 "Relative page_url given with no extension_name"; |
| 197 | 197 |
| 198 url = extension->GetResourceURL(page_url); | 198 url = extension->GetResourceURL(page_url); |
| 199 } | 199 } |
| 200 | 200 |
| 201 if (use_incognito) | 201 if (use_incognito) |
| 202 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), url); | 202 ui_test_utils::OpenURLOffTheRecord(browser()->profile(), url); |
| 203 else | 203 else |
| 204 ui_test_utils::NavigateToURL(browser(), url); | 204 ui_test_utils::NavigateToURL(browser(), url); |
| 205 | 205 |
| 206 } else if (launch_shell) { | 206 } else if (launch_platform_app) { |
| 207 Browser::OpenApplication( | 207 Browser::OpenApplication( |
| 208 browser()->profile(), | 208 browser()->profile(), |
| 209 extension, | 209 extension, |
| 210 extension_misc::LAUNCH_SHELL, | 210 extension_misc::LAUNCH_NONE, |
| 211 GURL(), | 211 GURL(), |
| 212 NEW_WINDOW); | 212 NEW_WINDOW); |
| 213 } | 213 } |
| 214 | 214 |
| 215 if (!catcher.GetNextResult()) { | 215 if (!catcher.GetNextResult()) { |
| 216 message_ = catcher.message(); | 216 message_ = catcher.message(); |
| 217 return false; | 217 return false; |
| 218 } else { | 218 } else { |
| 219 return true; | 219 return true; |
| 220 } | 220 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 ExtensionApiTest::SetUpCommandLine(command_line); | 286 ExtensionApiTest::SetUpCommandLine(command_line); |
| 287 | 287 |
| 288 // If someone is using this class, we're going to insist on management of the | 288 // If someone is using this class, we're going to insist on management of the |
| 289 // relevant flags. If these flags are already set, die. | 289 // relevant flags. If these flags are already set, die. |
| 290 DCHECK(!command_line->HasSwitch(switches::kEnablePlatformApps)); | 290 DCHECK(!command_line->HasSwitch(switches::kEnablePlatformApps)); |
| 291 DCHECK(!command_line->HasSwitch(switches::kEnableExperimentalExtensionApis)); | 291 DCHECK(!command_line->HasSwitch(switches::kEnableExperimentalExtensionApis)); |
| 292 | 292 |
| 293 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 293 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 294 command_line->AppendSwitch(switches::kEnablePlatformApps); | 294 command_line->AppendSwitch(switches::kEnablePlatformApps); |
| 295 } | 295 } |
| OLD | NEW |