| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_function_test_utils.h" | 5 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 6 #include "chrome/browser/extensions/extension_service.h" | 6 #include "chrome/browser/extensions/extension_service.h" |
| 7 #include "chrome/browser/extensions/extension_service_test_base.h" | 7 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 8 #include "chrome/browser/extensions/test_extension_system.h" | 8 #include "chrome/browser/extensions/test_extension_system.h" |
| 9 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/host_desktop.h" | 11 #include "chrome/browser/ui/host_desktop.h" |
| 11 #include "chrome/test/base/test_browser_window.h" | 12 #include "chrome/test/base/test_browser_window.h" |
| 12 #include "extensions/browser/api/management/management_api.h" | 13 #include "extensions/browser/api/management/management_api.h" |
| 13 #include "extensions/browser/api/management/management_api_constants.h" | 14 #include "extensions/browser/api/management/management_api_constants.h" |
| 14 #include "extensions/browser/extension_prefs.h" | 15 #include "extensions/browser/extension_prefs.h" |
| 15 #include "extensions/browser/extension_registry.h" | 16 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/browser/extension_system.h" | 17 #include "extensions/browser/extension_system.h" |
| 17 #include "extensions/browser/management_policy.h" | 18 #include "extensions/browser/management_policy.h" |
| 18 #include "extensions/browser/test_management_policy.h" | 19 #include "extensions/browser/test_management_policy.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 40 ManagementApiUnitTest() {} | 41 ManagementApiUnitTest() {} |
| 41 ~ManagementApiUnitTest() override {} | 42 ~ManagementApiUnitTest() override {} |
| 42 | 43 |
| 43 // A wrapper around extension_function_test_utils::RunFunction that runs with | 44 // A wrapper around extension_function_test_utils::RunFunction that runs with |
| 44 // the associated browser, no flags, and can take stack-allocated arguments. | 45 // the associated browser, no flags, and can take stack-allocated arguments. |
| 45 bool RunFunction(const scoped_refptr<UIThreadExtensionFunction>& function, | 46 bool RunFunction(const scoped_refptr<UIThreadExtensionFunction>& function, |
| 46 const base::ListValue& args); | 47 const base::ListValue& args); |
| 47 | 48 |
| 48 Browser* browser() { return browser_.get(); } | 49 Browser* browser() { return browser_.get(); } |
| 49 | 50 |
| 51 static void SetUpTestCase(); |
| 52 static void TearDownTestCase(); |
| 53 |
| 50 private: | 54 private: |
| 51 // ExtensionServiceTestBase: | 55 // ExtensionServiceTestBase: |
| 52 void SetUp() override; | 56 void SetUp() override; |
| 53 void TearDown() override; | 57 void TearDown() override; |
| 54 | 58 |
| 55 // The browser (and accompanying window). | 59 // The browser (and accompanying window). |
| 56 scoped_ptr<TestBrowserWindow> browser_window_; | 60 scoped_ptr<TestBrowserWindow> browser_window_; |
| 57 scoped_ptr<Browser> browser_; | 61 scoped_ptr<Browser> browser_; |
| 58 | 62 |
| 59 DISALLOW_COPY_AND_ASSIGN(ManagementApiUnitTest); | 63 DISALLOW_COPY_AND_ASSIGN(ManagementApiUnitTest); |
| 60 }; | 64 }; |
| 61 | 65 |
| 62 bool ManagementApiUnitTest::RunFunction( | 66 bool ManagementApiUnitTest::RunFunction( |
| 63 const scoped_refptr<UIThreadExtensionFunction>& function, | 67 const scoped_refptr<UIThreadExtensionFunction>& function, |
| 64 const base::ListValue& args) { | 68 const base::ListValue& args) { |
| 65 return extension_function_test_utils::RunFunction( | 69 return extension_function_test_utils::RunFunction( |
| 66 function.get(), | 70 function.get(), |
| 67 make_scoped_ptr(args.DeepCopy()), | 71 make_scoped_ptr(args.DeepCopy()), |
| 68 browser(), | 72 browser(), |
| 69 extension_function_test_utils::NONE); | 73 extension_function_test_utils::NONE); |
| 70 } | 74 } |
| 71 | 75 |
| 76 void ManagementApiUnitTest::SetUpTestCase() { |
| 77 ExtensionServiceTestBase::SetUpTestCase(); |
| 78 // Creating a browser requires platform parental controls initialization. |
| 79 IncognitoModePrefs::InitializePlatformParentalControls(); |
| 80 } |
| 81 |
| 82 void ManagementApiUnitTest::TearDownTestCase() { |
| 83 IncognitoModePrefs::UninitializePlatformParentalControls(); |
| 84 ExtensionServiceTestBase::TearDownTestCase(); |
| 85 } |
| 86 |
| 72 void ManagementApiUnitTest::SetUp() { | 87 void ManagementApiUnitTest::SetUp() { |
| 73 ExtensionServiceTestBase::SetUp(); | 88 ExtensionServiceTestBase::SetUp(); |
| 74 InitializeEmptyExtensionService(); | 89 InitializeEmptyExtensionService(); |
| 75 ManagementAPI::GetFactoryInstance()->SetTestingFactory(profile(), | 90 ManagementAPI::GetFactoryInstance()->SetTestingFactory(profile(), |
| 76 &BuildManagementApi); | 91 &BuildManagementApi); |
| 77 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))-> | 92 static_cast<TestExtensionSystem*>(ExtensionSystem::Get(profile()))-> |
| 78 SetEventRouter(make_scoped_ptr( | 93 SetEventRouter(make_scoped_ptr( |
| 79 new EventRouter(profile(), ExtensionPrefs::Get(profile())))); | 94 new EventRouter(profile(), ExtensionPrefs::Get(profile())))); |
| 80 | 95 |
| 81 browser_window_.reset(new TestBrowserWindow()); | 96 browser_window_.reset(new TestBrowserWindow()); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 uninstall_args.Remove(0u, nullptr); | 214 uninstall_args.Remove(0u, nullptr); |
| 200 function = new ManagementUninstallSelfFunction(); | 215 function = new ManagementUninstallSelfFunction(); |
| 201 function->set_extension(extension); | 216 function->set_extension(extension); |
| 202 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); | 217 EXPECT_TRUE(registry()->enabled_extensions().Contains(extension_id)); |
| 203 EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError(); | 218 EXPECT_TRUE(RunFunction(function, uninstall_args)) << function->GetError(); |
| 204 EXPECT_FALSE(registry()->GetExtensionById( | 219 EXPECT_FALSE(registry()->GetExtensionById( |
| 205 extension_id, ExtensionRegistry::EVERYTHING)); | 220 extension_id, ExtensionRegistry::EVERYTHING)); |
| 206 } | 221 } |
| 207 | 222 |
| 208 } // namespace extensions | 223 } // namespace extensions |
| OLD | NEW |