| 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 "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" | 6 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" |
| 7 #include "chrome/browser/extensions/extension_function_test_utils.h" | 7 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/browser/extensions/extension_service_test_base.h" | 9 #include "chrome/browser/extensions/extension_service_test_base.h" |
| 10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| 11 #include "chrome/browser/extensions/test_extension_dir.h" | 11 #include "chrome/browser/extensions/test_extension_dir.h" |
| 12 #include "chrome/browser/extensions/unpacked_installer.h" | 12 #include "chrome/browser/extensions/unpacked_installer.h" |
| 13 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/host_desktop.h" | 15 #include "chrome/browser/ui/host_desktop.h" |
| 15 #include "chrome/test/base/test_browser_window.h" | 16 #include "chrome/test/base/test_browser_window.h" |
| 16 #include "extensions/browser/extension_prefs.h" | 17 #include "extensions/browser/extension_prefs.h" |
| 17 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
| 18 #include "extensions/browser/extension_system.h" | 19 #include "extensions/browser/extension_system.h" |
| 19 #include "extensions/browser/test_extension_registry_observer.h" | 20 #include "extensions/browser/test_extension_registry_observer.h" |
| 20 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 21 #include "extensions/common/extension_set.h" | 22 #include "extensions/common/extension_set.h" |
| 22 #include "extensions/common/test_util.h" | 23 #include "extensions/common/test_util.h" |
| 23 | 24 |
| 24 namespace extensions { | 25 namespace extensions { |
| 25 | 26 |
| 26 class DeveloperPrivateApiUnitTest : public ExtensionServiceTestBase { | 27 class DeveloperPrivateApiUnitTest : public ExtensionServiceTestBase { |
| 27 protected: | 28 protected: |
| 28 DeveloperPrivateApiUnitTest() {} | 29 DeveloperPrivateApiUnitTest() {} |
| 29 ~DeveloperPrivateApiUnitTest() override {} | 30 ~DeveloperPrivateApiUnitTest() override {} |
| 30 | 31 |
| 32 static void SetUpTestCase(); |
| 33 static void TearDownTestCase(); |
| 34 |
| 31 // A wrapper around extension_function_test_utils::RunFunction that runs with | 35 // A wrapper around extension_function_test_utils::RunFunction that runs with |
| 32 // the associated browser, no flags, and can take stack-allocated arguments. | 36 // the associated browser, no flags, and can take stack-allocated arguments. |
| 33 bool RunFunction(const scoped_refptr<UIThreadExtensionFunction>& function, | 37 bool RunFunction(const scoped_refptr<UIThreadExtensionFunction>& function, |
| 34 const base::ListValue& args); | 38 const base::ListValue& args); |
| 35 | 39 |
| 36 Browser* browser() { return browser_.get(); } | 40 Browser* browser() { return browser_.get(); } |
| 37 | 41 |
| 38 private: | 42 private: |
| 39 // ExtensionServiceTestBase: | 43 // ExtensionServiceTestBase: |
| 40 void SetUp() override; | 44 void SetUp() override; |
| 41 void TearDown() override; | 45 void TearDown() override; |
| 42 | 46 |
| 43 // The browser (and accompanying window). | 47 // The browser (and accompanying window). |
| 44 scoped_ptr<TestBrowserWindow> browser_window_; | 48 scoped_ptr<TestBrowserWindow> browser_window_; |
| 45 scoped_ptr<Browser> browser_; | 49 scoped_ptr<Browser> browser_; |
| 46 | 50 |
| 47 DISALLOW_COPY_AND_ASSIGN(DeveloperPrivateApiUnitTest); | 51 DISALLOW_COPY_AND_ASSIGN(DeveloperPrivateApiUnitTest); |
| 48 }; | 52 }; |
| 49 | 53 |
| 54 void DeveloperPrivateApiUnitTest::SetUpTestCase() { |
| 55 ExtensionServiceTestBase::SetUpTestCase(); |
| 56 // Creating a browser requires platform parental controls initialization. |
| 57 IncognitoModePrefs::InitializePlatformParentalControls(); |
| 58 } |
| 59 |
| 60 void DeveloperPrivateApiUnitTest::TearDownTestCase() { |
| 61 IncognitoModePrefs::UninitializePlatformParentalControls(); |
| 62 ExtensionServiceTestBase::TearDownTestCase(); |
| 63 } |
| 64 |
| 50 bool DeveloperPrivateApiUnitTest::RunFunction( | 65 bool DeveloperPrivateApiUnitTest::RunFunction( |
| 51 const scoped_refptr<UIThreadExtensionFunction>& function, | 66 const scoped_refptr<UIThreadExtensionFunction>& function, |
| 52 const base::ListValue& args) { | 67 const base::ListValue& args) { |
| 53 return extension_function_test_utils::RunFunction( | 68 return extension_function_test_utils::RunFunction( |
| 54 function.get(), | 69 function.get(), |
| 55 make_scoped_ptr(args.DeepCopy()), | 70 make_scoped_ptr(args.DeepCopy()), |
| 56 browser(), | 71 browser(), |
| 57 extension_function_test_utils::NONE); | 72 extension_function_test_utils::NONE); |
| 58 } | 73 } |
| 59 | 74 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 131 |
| 117 base::ListValue disable_args; | 132 base::ListValue disable_args; |
| 118 disable_args.AppendString(extension_id); | 133 disable_args.AppendString(extension_id); |
| 119 disable_args.AppendBoolean(false); | 134 disable_args.AppendBoolean(false); |
| 120 function = new api::DeveloperPrivateAllowIncognitoFunction(); | 135 function = new api::DeveloperPrivateAllowIncognitoFunction(); |
| 121 EXPECT_TRUE(RunFunction(function, disable_args)); | 136 EXPECT_TRUE(RunFunction(function, disable_args)); |
| 122 EXPECT_FALSE(util::IsIncognitoEnabled(extension_id, profile())); | 137 EXPECT_FALSE(util::IsIncognitoEnabled(extension_id, profile())); |
| 123 } | 138 } |
| 124 | 139 |
| 125 } // namespace extensions | 140 } // namespace extensions |
| OLD | NEW |