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/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" | 
| 11 #include "chrome/browser/extensions/unpacked_installer.h" | |
| 12 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" | 
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" | 
| 13 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" | 
| 16 #include "chrome/common/chrome_switches.h" | |
| 14 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" | 
| 15 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" | 
| 16 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" | 
| 17 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" | 
| 18 | 21 | 
| 19 namespace { | 22 namespace { | 
| 20 | 23 | 
| 21 const char kTestServerPort[] = "testServer.port"; | 24 const char kTestServerPort[] = "testServer.port"; | 
| 22 const char kTestDataDirectory[] = "testDataDirectory"; | 25 const char kTestDataDirectory[] = "testDataDirectory"; | 
| 23 const char kTestWebSocketPort[] = "testWebSocketPort"; | 26 const char kTestWebSocketPort[] = "testWebSocketPort"; | 
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 return false; | 270 return false; | 
| 268 | 271 | 
| 269 test_config_->SetInteger(kTestWebSocketPort, port); | 272 test_config_->SetInteger(kTestWebSocketPort, port); | 
| 270 return true; | 273 return true; | 
| 271 } | 274 } | 
| 272 | 275 | 
| 273 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { | 276 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { | 
| 274 ExtensionBrowserTest::SetUpCommandLine(command_line); | 277 ExtensionBrowserTest::SetUpCommandLine(command_line); | 
| 275 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); | 278 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); | 
| 276 } | 279 } | 
| 280 | |
| 281 PlatformAppApiTest::PlatformAppApiTest() | |
| 282 : previous_command_line_(CommandLine::NO_PROGRAM) {} | |
| 283 | |
| 284 PlatformAppApiTest::~PlatformAppApiTest() {} | |
| 285 | |
| 286 void PlatformAppApiTest::SetUpCommandLine(CommandLine* command_line) { | |
| 287 ExtensionApiTest::SetUpCommandLine(command_line); | |
| 288 | |
| 289 // If someone is using this class, we're going to insist on management of the | |
| 290 // relevant flags. If these flags are already set, die. | |
| 291 DCHECK(!command_line->HasSwitch(switches::kEnablePlatformApps)); | |
| 292 DCHECK(!command_line->HasSwitch(switches::kEnableExperimentalExtensionApis)); | |
| 293 | |
| 294 // Squirrel away for potential use in VerifyPermissions. | |
| 295 // | |
| 296 // TODO(miket): I _could_ just call VerifyPermissions here instead of | |
| 297 // requiring everyone who inherits from PlatformAppApiTest to explicitly call | |
| 298 // it within a test, but that feels overbearing. | |
| 299 previous_command_line_ = *command_line; | |
| 300 | |
| 301 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | |
| 302 command_line->AppendSwitch(switches::kEnablePlatformApps); | |
| 303 } | |
| 304 | |
| 305 void PlatformAppApiTest::VerifyPermissions(const FilePath& extension_path) { | |
| 306 #if defined(OS_WIN) | |
| 307 // See http://code.google.com/p/chromium/issues/detail?id=119758. | |
| 308 // | |
| 309 // TODO(miket): investigate why WaitForExtensionLoadError() doesn't receive | |
| 310 // the expected notification on XP/Vista, but succeeds on other platforms. | |
| 311 #else | |
| 312 CommandLine old_command_line(*CommandLine::ForCurrentProcess()); | |
| 313 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 314 | |
| 315 // Neither experimental nor platform-app flag. | |
| 316 *CommandLine::ForCurrentProcess() = previous_command_line_; | |
| 
 
jstritar
2012/03/27 15:16:09
Think this is okay to do? The documentation says t
 
 | |
| 317 extensions::UnpackedInstaller::Create(service)->Load(extension_path); | |
| 318 ASSERT_TRUE(WaitForExtensionLoadError()); | |
| 
 
jstritar
2012/03/27 15:16:09
How about using extension_file_util::LoadExtension
 
 | |
| 319 | |
| 320 // Only experimental flag. | |
| 321 *CommandLine::ForCurrentProcess() = previous_command_line_; | |
| 322 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 323 switches::kEnableExperimentalExtensionApis); | |
| 324 extensions::UnpackedInstaller::Create(service)->Load(extension_path); | |
| 325 ASSERT_TRUE(WaitForExtensionLoadError()); | |
| 326 | |
| 327 // Only platform-app flag. | |
| 328 *CommandLine::ForCurrentProcess() = previous_command_line_; | |
| 329 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 330 switches::kEnablePlatformApps); | |
| 331 extensions::UnpackedInstaller::Create(service)->Load(extension_path); | |
| 332 ASSERT_TRUE(WaitForExtensionLoadError()); | |
| 333 | |
| 334 *CommandLine::ForCurrentProcess() = old_command_line; | |
| 335 #endif | |
| 336 } | |
| OLD | NEW |