| 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/extensions/test_extension_service.h" | 13 #include "chrome/browser/extensions/test_extension_service.h" |
| 14 #include "chrome/browser/intents/default_web_intent_service.h" | 14 #include "chrome/browser/intents/default_web_intent_service.h" |
| 15 #include "chrome/browser/intents/web_intents_registry.h" | 15 #include "chrome/browser/intents/web_intents_registry.h" |
| 16 #include "chrome/browser/webdata/web_data_service.h" | 16 #include "chrome/browser/webdata/web_data_service.h" |
| 17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 18 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/extensions/extension_manifest_constants.h" | 19 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 19 #include "chrome/common/extensions/extension_set.h" | 20 #include "chrome/common/extensions/extension_set.h" |
| 21 #include "chrome/common/extensions/manifest.h" |
| 20 #include "chrome/common/extensions/manifest_handler.h" | 22 #include "chrome/common/extensions/manifest_handler.h" |
| 21 #include "chrome/common/extensions/web_intents_handler.h" | 23 #include "chrome/common/extensions/web_intents_handler.h" |
| 22 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 25 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 27 |
| 26 using content::BrowserThread; | 28 using content::BrowserThread; |
| 27 using extensions::Extension; | 29 using extensions::Extension; |
| 30 using extensions::Manifest; |
| 28 using webkit_glue::WebIntentServiceData; | 31 using webkit_glue::WebIntentServiceData; |
| 29 | 32 |
| 30 class MockExtensionService: public TestExtensionService { | 33 class MockExtensionService: public TestExtensionService { |
| 31 public: | 34 public: |
| 32 virtual ~MockExtensionService() {} | 35 virtual ~MockExtensionService() {} |
| 33 MOCK_CONST_METHOD0(extensions, const ExtensionSet*()); | 36 MOCK_CONST_METHOD0(extensions, const ExtensionSet*()); |
| 34 MOCK_CONST_METHOD2(GetExtensionById, | 37 MOCK_CONST_METHOD2(GetExtensionById, |
| 35 const Extension*(const std::string&, bool)); | 38 const Extension*(const std::string&, bool)); |
| 36 MOCK_CONST_METHOD1(GetInstalledExtension, | 39 MOCK_CONST_METHOD1(GetInstalledExtension, |
| 37 const Extension*(const std::string& id)); | 40 const Extension*(const std::string& id)); |
| 38 }; | 41 }; |
| 39 | 42 |
| 40 namespace { | 43 namespace { |
| 41 | 44 |
| 42 // TODO(groby): Unify loading functions with extension_manifest_unittest code. | 45 // TODO(groby): Unify loading functions with extension_manifest_unittest code. |
| 43 DictionaryValue* LoadManifestFile(const FilePath& path, | 46 DictionaryValue* LoadManifestFile(const FilePath& path, |
| 44 std::string* error) { | 47 std::string* error) { |
| 45 EXPECT_TRUE(file_util::PathExists(path)); | 48 EXPECT_TRUE(file_util::PathExists(path)); |
| 46 JSONFileValueSerializer serializer(path); | 49 JSONFileValueSerializer serializer(path); |
| 47 return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error)); | 50 return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error)); |
| 48 } | 51 } |
| 49 | 52 |
| 50 scoped_refptr<Extension> LoadExtensionWithLocation( | 53 scoped_refptr<Extension> LoadExtensionWithLocation( |
| 51 const std::string& name, | 54 const std::string& name, |
| 52 Extension::Location location, | 55 Manifest::Location location, |
| 53 std::string* error) { | 56 std::string* error) { |
| 54 FilePath path; | 57 FilePath path; |
| 55 PathService::Get(chrome::DIR_TEST_DATA, &path); | 58 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 56 path = path.AppendASCII("extensions") | 59 path = path.AppendASCII("extensions") |
| 57 .AppendASCII("manifest_tests") | 60 .AppendASCII("manifest_tests") |
| 58 .AppendASCII(name.c_str()); | 61 .AppendASCII(name.c_str()); |
| 59 scoped_ptr<DictionaryValue> value(LoadManifestFile(path, error)); | 62 scoped_ptr<DictionaryValue> value(LoadManifestFile(path, error)); |
| 60 if (!value.get()) | 63 if (!value.get()) |
| 61 return NULL; | 64 return NULL; |
| 62 return Extension::Create(path.DirName(), | 65 return Extension::Create(path.DirName(), |
| 63 location, | 66 location, |
| 64 *value, | 67 *value, |
| 65 Extension::NO_FLAGS, | 68 Extension::NO_FLAGS, |
| 66 Extension::GenerateIdForPath(path), | 69 Extension::GenerateIdForPath(path), |
| 67 error); | 70 error); |
| 68 } | 71 } |
| 69 | 72 |
| 70 scoped_refptr<Extension> LoadExtension(const std::string& name, | 73 scoped_refptr<Extension> LoadExtension(const std::string& name, |
| 71 std::string* error) { | 74 std::string* error) { |
| 72 return LoadExtensionWithLocation(name, Extension::INTERNAL, error); | 75 return LoadExtensionWithLocation(name, Manifest::INTERNAL, error); |
| 73 } | 76 } |
| 74 | 77 |
| 75 scoped_refptr<Extension> LoadAndExpectSuccess(const std::string& name) { | 78 scoped_refptr<Extension> LoadAndExpectSuccess(const std::string& name) { |
| 76 std::string error; | 79 std::string error; |
| 77 scoped_refptr<Extension> extension = LoadExtension(name, &error); | 80 scoped_refptr<Extension> extension = LoadExtension(name, &error); |
| 78 EXPECT_TRUE(extension) << name; | 81 EXPECT_TRUE(extension) << name; |
| 79 EXPECT_EQ("", error) << name; | 82 EXPECT_EQ("", error) << name; |
| 80 return extension; | 83 return extension; |
| 81 } | 84 } |
| 82 | 85 |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 | 797 |
| 795 registry_.GetAllDefaultIntentServices( | 798 registry_.GetAllDefaultIntentServices( |
| 796 base::Bind(&DefaultServiceListConsumer::Accept, | 799 base::Bind(&DefaultServiceListConsumer::Accept, |
| 797 base::Unretained(&consumer))); | 800 base::Unretained(&consumer))); |
| 798 | 801 |
| 799 consumer.WaitForData(); | 802 consumer.WaitForData(); |
| 800 | 803 |
| 801 ASSERT_EQ(1U, consumer.services_.size()); | 804 ASSERT_EQ(1U, consumer.services_.size()); |
| 802 EXPECT_EQ(service_url_1.spec(), consumer.services_[0].service_url); | 805 EXPECT_EQ(service_url_1.spec(), consumer.services_[0].service_url); |
| 803 } | 806 } |
| OLD | NEW |