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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 return false; | 289 return false; |
| 287 | 290 |
| 288 test_config_->SetInteger(kTestWebSocketPort, port); | 291 test_config_->SetInteger(kTestWebSocketPort, port); |
| 289 return true; | 292 return true; |
| 290 } | 293 } |
| 291 | 294 |
| 292 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { | 295 void ExtensionApiTest::SetUpCommandLine(CommandLine* command_line) { |
| 293 ExtensionBrowserTest::SetUpCommandLine(command_line); | 296 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 294 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); | 297 test_data_dir_ = test_data_dir_.AppendASCII("api_test"); |
| 295 } | 298 } |
| 299 | |
| 300 PlatformAppApiTest::PlatformAppApiTest() | |
| 301 : previous_command_line_(CommandLine::NO_PROGRAM) {} | |
| 302 | |
| 303 PlatformAppApiTest::~PlatformAppApiTest() {} | |
| 304 | |
| 305 void PlatformAppApiTest::SetUpCommandLine(CommandLine* command_line) { | |
| 306 ExtensionApiTest::SetUpCommandLine(command_line); | |
| 307 | |
| 308 // If someone is using this class, we're going to insist on management of the | |
| 309 // relevant flags. If these flags are already set, die. | |
| 310 DCHECK(!command_line->HasSwitch(switches::kEnablePlatformApps)); | |
| 311 DCHECK(!command_line->HasSwitch(switches::kEnableExperimentalExtensionApis)); | |
| 312 | |
| 313 // Squirrel away for potential use in VerifyPermissions. | |
| 314 // | |
| 315 // TODO(miket): I _could_ just call VerifyPermissions here instead of | |
| 316 // requiring everyone who inherits from PlatformAppApiTest to explicitly call | |
| 317 // it within a test, but that feels overbearing. | |
| 318 previous_command_line_ = *command_line; | |
|
asargent_no_longer_on_chrome
2012/03/22 20:21:12
FYI, I vaguely recall seeing some kind of "scoped
| |
| 319 | |
| 320 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | |
| 321 command_line->AppendSwitch(switches::kEnablePlatformApps); | |
| 322 } | |
| 323 | |
| 324 void PlatformAppApiTest::VerifyPermissions(const FilePath& extension_path) { | |
| 325 CommandLine old_command_line(*CommandLine::ForCurrentProcess()); | |
| 326 ExtensionService* service = browser()->profile()->GetExtensionService(); | |
| 327 | |
| 328 // Neither experimental nor platform-app flag. | |
| 329 *CommandLine::ForCurrentProcess() = previous_command_line_; | |
| 330 extensions::UnpackedInstaller::Create(service)->Load(extension_path); | |
| 331 ASSERT_TRUE(WaitForExtensionLoadError()); | |
| 332 | |
| 333 // Only experimental flag. | |
| 334 *CommandLine::ForCurrentProcess() = previous_command_line_; | |
| 335 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 336 switches::kEnableExperimentalExtensionApis); | |
| 337 extensions::UnpackedInstaller::Create(service)->Load(extension_path); | |
| 338 ASSERT_TRUE(WaitForExtensionLoadError()); | |
| 339 | |
| 340 // Only platform-app flag. | |
| 341 *CommandLine::ForCurrentProcess() = previous_command_line_; | |
| 342 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 343 switches::kEnablePlatformApps); | |
| 344 extensions::UnpackedInstaller::Create(service)->Load(extension_path); | |
| 345 ASSERT_TRUE(WaitForExtensionLoadError()); | |
| 346 | |
| 347 *CommandLine::ForCurrentProcess() = old_command_line; | |
| 348 } | |
| OLD | NEW |