| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/json/json_file_value_serializer.h" | 6 #include "base/json/json_file_value_serializer.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/management_policy.h" | 11 #include "chrome/browser/extensions/management_policy.h" |
| 12 #include "chrome/browser/extensions/test_extension_system.h" | 12 #include "chrome/browser/extensions/test_extension_system.h" |
| 13 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" | 13 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" |
| 14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 using extensions::Extension; | 20 using extensions::Extension; |
| 21 | 21 |
| 22 class ExtensionUITest : public testing::Test { | 22 class ExtensionUITest : public testing::Test { |
| 23 public: | 23 public: |
| 24 ExtensionUITest() : ui_thread_(content::BrowserThread::UI, &message_loop_) { | 24 ExtensionUITest() |
| 25 } | 25 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 26 file_thread_(content::BrowserThread::FILE, &message_loop_) {} |
| 26 | 27 |
| 27 protected: | 28 protected: |
| 28 void SetUp() { | 29 virtual void SetUp() OVERRIDE { |
| 29 // Create an ExtensionService and ManagementPolicy to inject into the | 30 // Create an ExtensionService and ManagementPolicy to inject into the |
| 30 // ExtensionSettingsHandler. | 31 // ExtensionSettingsHandler. |
| 32 profile_.reset(new TestingProfile()); |
| 31 extensions::TestExtensionSystem* system = | 33 extensions::TestExtensionSystem* system = |
| 32 static_cast<extensions::TestExtensionSystem*>( | 34 static_cast<extensions::TestExtensionSystem*>( |
| 33 extensions::ExtensionSystem::Get(&profile_)); | 35 extensions::ExtensionSystem::Get(profile_.get())); |
| 34 extension_service_ = system->CreateExtensionService( | 36 extension_service_ = system->CreateExtensionService( |
| 35 CommandLine::ForCurrentProcess(), FilePath(), false); | 37 CommandLine::ForCurrentProcess(), FilePath(), false); |
| 36 management_policy_ = system->CreateManagementPolicy(); | 38 management_policy_ = system->CreateManagementPolicy(); |
| 37 | 39 |
| 38 handler_.reset(new ExtensionSettingsHandler(extension_service_, | 40 handler_.reset(new ExtensionSettingsHandler(extension_service_, |
| 39 management_policy_)); | 41 management_policy_)); |
| 40 } | 42 } |
| 41 | 43 |
| 44 virtual void TearDown() OVERRIDE { |
| 45 handler_.reset(); |
| 46 profile_.reset(); |
| 47 // Execute any pending deletion tasks. |
| 48 message_loop_.RunAllPending(); |
| 49 } |
| 50 |
| 42 static DictionaryValue* DeserializeJSONTestData(const FilePath& path, | 51 static DictionaryValue* DeserializeJSONTestData(const FilePath& path, |
| 43 std::string *error) { | 52 std::string *error) { |
| 44 Value* value; | 53 Value* value; |
| 45 | 54 |
| 46 JSONFileValueSerializer serializer(path); | 55 JSONFileValueSerializer serializer(path); |
| 47 value = serializer.Deserialize(NULL, error); | 56 value = serializer.Deserialize(NULL, error); |
| 48 | 57 |
| 49 return static_cast<DictionaryValue*>(value); | 58 return static_cast<DictionaryValue*>(value); |
| 50 } | 59 } |
| 51 | 60 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 EXPECT_EQ(NULL, actual_value) << *key + paths_details; | 112 EXPECT_EQ(NULL, actual_value) << *key + paths_details; |
| 104 } else { | 113 } else { |
| 105 EXPECT_TRUE(expected_value->Equals(actual_value)) << *key + | 114 EXPECT_TRUE(expected_value->Equals(actual_value)) << *key + |
| 106 paths_details; | 115 paths_details; |
| 107 } | 116 } |
| 108 } | 117 } |
| 109 } | 118 } |
| 110 | 119 |
| 111 MessageLoop message_loop_; | 120 MessageLoop message_loop_; |
| 112 content::TestBrowserThread ui_thread_; | 121 content::TestBrowserThread ui_thread_; |
| 113 TestingProfile profile_; | 122 content::TestBrowserThread file_thread_; |
| 123 scoped_ptr<TestingProfile> profile_; |
| 114 ExtensionService* extension_service_; | 124 ExtensionService* extension_service_; |
| 115 extensions::ManagementPolicy* management_policy_; | 125 extensions::ManagementPolicy* management_policy_; |
| 116 scoped_ptr<ExtensionSettingsHandler> handler_; | 126 scoped_ptr<ExtensionSettingsHandler> handler_; |
| 117 }; | 127 }; |
| 118 | 128 |
| 119 TEST_F(ExtensionUITest, GenerateExtensionsJSONData) { | 129 TEST_F(ExtensionUITest, GenerateExtensionsJSONData) { |
| 120 FilePath data_test_dir_path, extension_path, expected_output_path; | 130 FilePath data_test_dir_path, extension_path, expected_output_path; |
| 121 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); | 131 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); |
| 122 | 132 |
| 123 // Test Extension1 | 133 // Test Extension1 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 265 |
| 256 scoped_ptr<DictionaryValue> extension_details( | 266 scoped_ptr<DictionaryValue> extension_details( |
| 257 CreateExtensionDetailViewFromPath( | 267 CreateExtensionDetailViewFromPath( |
| 258 extension_path, pages, Extension::LOAD)); | 268 extension_path, pages, Extension::LOAD)); |
| 259 | 269 |
| 260 FilePath::StringType ui_path; | 270 FilePath::StringType ui_path; |
| 261 | 271 |
| 262 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); | 272 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); |
| 263 EXPECT_EQ(extension_path, FilePath(ui_path)); | 273 EXPECT_EQ(extension_path, FilePath(ui_path)); |
| 264 } | 274 } |
| OLD | NEW |